Ordinary files can be created with open or create, FIFO files can be created with pipe, Mknod is mainly used for the creation of device files.In the kernel, Mknod is implemented by Sys_mknod, with the following code:Asmlinkage Long Sys_mknod (const char * filename, int mode, dev_t dev)//For example filename for/tmp/server_socket,dev is the device number {int error = 0;char * tmp;struct dentry * dentry;struc
physical devices (possibly disks, disk partitions, network storage entities, memory, or other media that can store information-even temporarily).
In addition to the details of abstracting file operations from the underlying file system, the VFS binds the underlying block device to the available file system. Let's look at the internal structure of the VFS and how it works.
The internal structure of the VFS
Before looking at the overall architecture of the VFS subsystem, let's look at the main
system, VFS also binds underlying Block devices to available file systems. Let's take a look at the internal structure of VFS and its working principles.
Internal Structure of VFS
Before viewing the overall architecture of the VFS subsystem, let's take a look at the main objects used. This section explores superblocks, index nodes (or inode), directory entries (or dentry), and file objects. Here, other components are also important, such as cache. H
There is a d_alloc function in the kernel that allocates a dentry structure and initializes it.
/*** D_alloc-allocate a Dcache entry* @parent: Parent of entry to allocate* @name: Qstr of the name** Allocates a dentry. It returns%null if there is insufficient memory* Available. On a success the Dentry is returned. The name passed in* Copied and the copy passed in
Tags: work process hash table using data class cannot integer BubukoInode Management: Inode-cache hash table inode_hashtable Index node cacheManagement of Dentry:We know that several dentry depict a tree-like directory structure, which is the directory structure that the user sees, and each dentry points to an index node (INODE) Structure However, these dentry st
module */_ U32 I _generation;/* index node version number */Union {Void * generic_ip;/* Special file information */} U;};/** Inode_operations of index nodes are defined in Linux/fs. h.*/Struct inode_operations {INT (* Create) (struct inode *, struct dentry *, INT );/* VFS calls this function by calling CREATE () and open () to create a new index node for the dentry object. Use mode to set the initial mode
system, such as file system type, size, all inode objects, Dirty inode lists, and so on.The inode and Super block are actually mapped in the storage medium, where there are also super blocks and inodein the storage medium. However, because of different types of file system differences, the structure of the Super block and the inode varies. The role of VFS is to obtain a super block and inode node in a file system through a specific device driver, and then populate the information in the kernel
not need to make any changes to the kernel part of the API provided by it.Debugfs developers first need to create a directory in the file system. The following function is used to create a directory in the debugfs File System:
struct dentry *debugfs_create_dir(const char *name, struct dentry *parent);
The parameter name is the name of the directory to be created. The parameter parent specifies t
Kernel File System API d_delete, kernel apid_delete
D_delete of Kernel File System API
Void d_delete (struct dentry * dentry) is used to delete a dentry. The source code analysis is as follows: void d_delete (struct dentry * dentry) {struct inode * inode; int isdir = 0; /*
use.
The super block is represented by the struct super_block struct:
1400 struct super_block {1401 struct list_head s_list;/* keep this first pointer to the super block linked list */1402 dev_t s_dev;/* search index; _ not _ kdev_t device identifier */1403 unsigned char s_dirt;/* modify (dirty) identifier */1404 unsigned char s_blocksize_bits; /* block size unit bits */1405 unsigned long s_blocksize;/* block size unit bytes */1406 loff_t s_maxbytes;/* max file size */1407 struct file_system_ty
process of calling the program through the system is as follows:Open ()->/* user space */-> System Call->/* Through System Call, program process Kernel Status */Sys_open ()-> filp_open ()-> dentry_open ()-> file_operations-> open ()/* kernel space */Different file systems call different file_operations-> open (), which is sysfs_open_file () under sysfs ().We use different file systems to abstract their respective file information to dentry and inode.
call Sysfs_inode_init (/3.1.10/FS/INODE.C)
Sysfs_inode_init calls Bdi_init (sysfs_backing_dev_info) to initialize Backing_dev (...). )
Sysfs_init calls Register_filesystem (sysfs_fs_type) (/3.1.10/FS/FILESYSTEM.C) to register a file system of type "SYSFS"
Register_filesystem adds sysfs_fs_type to the global list of File_systems
Sysfs_init call Kern_mount (/3.1.10/fs/namespace.c) to bind Sysfs_fs_type
Kern_mount_data Call Vfs_kern_mount
Vfs_kern_mount Call Alloc_vfsmnt Assign a mount to the data
PROCFS is an abbreviation for the process filesystem (file system) and contains a pseudo-file system for accessing process information through the kernelThis file system is usually mounted to the/proc directory. Since/proc is not a real file system, it does not occupy storage space, but consumes limited memory
pseudo File SystemUsers and applications can get system information through proc, and can change certain parameters of the kernel. The proc file system dynamically reads the required infor
I. scenario 1. obtain the absolute path of the file. This is obtained by FD. 2. obtain the absolute path of the process. two data structures related to the Linux kernel and Path: 1. the struct dentry file name is stored in the struct prototype:
Struct dentry {int d_mounted; struct inode * d_inode;/* Where the name belongs to-null is negative */struct hlist_node d_hash;/* lookup hash list */struct
cache:It then logs memory usage, primarily recording free memory and slab use of memory:+++++++++++++++++++++++++++++++++++++++++++++suse11x64-001:~ # Cat/proc/meminfomemtotal:1989340 KBmemfree:1495368 KB......slab:37752 KB......+++++++++++++++++++++++++++++++++++++++++++++Then wait 3 days (just over the weekend), using the same method as above to view the current free memory and slab use memory, and finally found that 3 days to consume about 300M of memory, just about slab growth of memory. Th
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.