sock_map_fd
-----------sock_alloc_file
-----------fd_install
sock_alloc(**void**) //return socket *
static const struct file_operations socket_file_ops = {
.owner = THIS_MODULE,
.llseek = no_llseek,
.read_iter = sock_read_iter,
.write_iter = sock_write_iter,
.poll = sock_poll,
.unlocked_ioctl = sock_ioctl,
#ifdef CONFIG_COMPAT
.compat_ioctl = compat_sock_ioctl,
#endif
.mmap = sock_mmap,
.release = sock_close,
.fasync = sock_fasync,
.sendpage = sock_sendpage,
.splice_write = generic_splice_sendpage,
.splice_read = sock_splice_read,
};
/linux-2.6.38.8/net/ipv4/tcp.c
int sock_map_fd(struct socket *sock, int flags)
{
struct file *newfile;
int fd = sock_alloc_file(sock, &newfile, flags);
if (likely(fd >= 0))
fd_install(fd, newfile);
return fd;
}
static int sock_alloc_file(struct socket *sock, struct file **f, int flags){
struct file *file;
..............
file = alloc_file(&path, FMODE_READ | FMODE_WRITE,
&socket_file_ops);
sock->file = file;
file->private_data = sock;
}
网友评论