Private_data in the file structure

Source: Internet
Author: User

Private_data is a core data structure between the Linux connection VFS file system framework and the underlying implementations of different file/file systems, although it is just a pointer, but a pointer can solve all problems.

Because file is a basic concept of the VFS framework, it supports the operation of files, such as interfaces such as Open/read/write/release, and even poll, which can be incorporated into the VFS family only with these structures. But for different device files, they are just the equipment that wears the file coat, so he has to have his own unique structure to communicate with the equipment, and this private_data is the link of this connection. This may be more abstract, and finally a little more to see some code feeling may be deeper.

In essence, the Private_data pointer of device devices is pointed to the structure of its own definition. Increased reusability.

Here are some files that use Private_data:

1. TTY Devices
Static ssize_t tty_read (struct file * file, char __user * buf, size_t count,
loff_t *ppos)
{
int i;
struct tty_struct * TTY;
struct Inode *inode;
struct Tty_ldisc *ld;
TTY = (struct tty_struct *) file->private_data;
2. Tun/tap Equipment
Static ssize_t tun_chr_aio_read (struct KIOCB *iocb, const struct IOVEC *iv,
unsigned long count, loff_t POS)
{
struct File *file = iocb->ki_filp;
struct Tun_struct *tun = file->private_data;
3. Set of interface files
Static ssize_t do_sock_read (struct msghdr *msg, struct KIOCB *IOCB,
struct file *file, const struct IOVEC *iov,
unsigned long Nr_segs)
{
struct Socket *sock = file->private_data;
size_t size = 0;
4. epoll file
static int ep_eventpoll_close (struct inode *inode, struct file *file)
{
struct Eventpoll *ep = file->private_data;
5. shm file
Long Do_shmat (int shmid, char __user *shmaddr, int shmflg, ULONG *raddr)
{
......
File->private_data = SFD;

Reference

[1].http://blog.csdn.net/ywh147/article/details/8684486

Private_data in the file structure

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.