Because of the network, and file system, read and write data interface compared to use the network to send and receive data interface The most abstract concept is the socket. Network Transceiver Interface is a set of BSD defined interface, file system is open and close of the corresponding.
The first thing to understand is the initialization of the network file system:
static int __init sock_init (void)
{
/*
* Initialize sock Slab cache.
*/
Sk_init ();
/*
* Initialize Skbuff Slab Cache
*/
Skb_init ();
/*
* */
Init_inodecache ();
Register_filesystem (&sock_fs_type);
Sock_mnt = Kern_mount (&sock_fs_type);
/* The real protocol initialization are performed in later initcalls.
*/
#ifdef Config_netfilter
Netfilter_init ();
#endif
return 0;
}
Core_initcall (Sock_init); /* Early Initcall * *
Core_initcall can access the relevant information, the process is the machine in the initialization of the sock_init call function.
The network file system is special, the file system mount does not install the normal file system practices to achieve:
1, first did not find the global file system linked list to obtain file system type
2. Network file system types are not actually mounted in the directory tree of the VFS, but are used by global variables. That
static struct Vfsmount *sock_mnt __read_mostly;//is saved as a global variable and is used directly when needed
Sock_mnt = Kern_mount (&sock_fs_type);
This means that the file system can not be used through the regular file system interface to use, but also through the CD, LS and other commands to view.
Then the registration of the file system is still required. This is not necessary for the functionality of the network file system itself, but it is necessary to ensure that no other process can repeat the mounting of the network file system.
Register_filesystem (&sock_fs_type);
File system registration guarantees that the network file system has been added to the global file system list.
The file system Mount process can view the related source code. Highlight the Sock_fs_type structure that represents the type of network file system:
static struct File_system_type Sock_fs_type = {
. Name = "Sockfs",
. GET_SB = SOCKFS_GET_SB,
. KILL_SB = Kill_anon_super,
};
Go on:
static int sockfs_get_sb (struct file_system_type *fs_type,
int flags, const char *dev_name, void *data,
struct Vfsmount *mnt)
{
Return Get_sb_pseudo (Fs_type, "socket:", &sockfs_ops, sockfs_magic,mnt);
}
In the process of getting the file system Super block, Get_sb_pseudo through
S->s_op = Ops? OPS: &simple_super_operations;
Assign the Sockfs_ops to S->s_op.
Go on:
static const struct Super_operations Sockfs_ops = {
. Alloc_inode = Sock_alloc_inode,
. Destroy_inode =sock_destroy_inode,
. Statfs = Simple_statfs,
};
Go on:
static struct Inode *sock_alloc_inode (struct super_block *sb)
{
struct Socket_alloc *ei;
ei = kmem_cache_alloc (Sock_inode_cachep, Gfp_kernel);
if (!ei)
return NULL;
Init_waitqueue_head (&ei->socket.wait);
Ei->socket.fasync_list = NULL;
Ei->socket.state = ss_unconnected;
ei->socket.flags = 0;
Ei->socket.ops = NULL;
ei->socket.sk = NULL;
Ei->socket.file = NULL;
Return &ei->vfs_inode;
}
summed up as three global variables: Sock_mnt,sock_fs_type,sockfs_ops.
Sock_inode_cachep is the global variable declared by the Init_inodecache () in Sock_init:
static struct Kmem_cache *sock_inode_cachep __read_mostly;