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