|
Project: Linux Howtos
Virtual File System - Part 2
By Vans Information <content@vansinfo.com>
Posted: ( 2001-03-28 06:44:48 EST by )
The second part in this series looks at some more structures used by Virtual File System (VFS).
The Inode An inode contains the management information for a particular file. The information contained includes owner id, size of file, access time, access rights, and the allocation of data to blocks on the physical media. The inode already contains a few block numbers to ensure efficient access to small files. Access to larger files is provided via indirect blocks that contain block numbers. The indirect blocks come in three flavors: *Indirect reference *Double indirect reference *Triple indirect reference The definition of the inode structure is as follows: struct inode { dev_t i_dev; /* file device number */ unsigned long i_ino; /* inode number */ umode_t i_mode; /* file type and access rights */ nlink_t i_nlink; /* number of hard links */ uid_t i_uid; /* owner */ gid_t i_gid; /* owner group */ dev_t i_rdev; /* device, if device file */ off_t i_size; /* size of file */ time_t i_atime; /* time of last access */ time_t i_mtime; /* time of last modification */ time_t i_ctime; /* time of creation */ unsigned long i_blksize; /* block size */ unsigned long i_blocks; /* number of blocks */ unsigned long i_version; /* DCache version management */ struct semaphore i_sem; /* access control */ struct inode_operations *i_op; /* inode operations */ struct super_block *i_sb; /* superblock */ struct wait_queue *i_wait; /* wait queue */ struct file_lock *i_flock; /* file locks */ struct vm_area_struct *i_mmap; /* memory areas */ struct inode *i_next; /* inode linking */ struct inode *i_prev; /* inode linking */ struct inode *i_hash_next; /* for hashing */ struct inode *i_hash_prev;/* for hashing */ struct inode *i_mount; /* root inode of mounted File System */ unsigned short i_count; /* reference counter */ unsigned short i_flags; /* flags */ unsigned char i_lock; /* lock */ unsigned char i_dirt; /* inode has been modified */ unsigned char i_pipe; /* inode represents a pipe */ unsigned char i_sock; /* it represents a socket */ unsigned char i_seek; /* not used */ unsigned char i_update; /* inode is current */ union { struct pipe_inode_info pipe_i; struct ext2_inode_info ext2_i; struct msdos_inode_info msdos_i; ........... ........... ........... void * generic_ip; } u; /* File System specific info */ }; When a File System is mounted, the superblock is generated and the root inode for the file system is entered in the field 'i_mount' of the inode corresponding to the appropriate mount point.
The inodes are maintained in two structures in the memory: * A doubly linked circular list starting with first_inode. This list also includes the free, unused inodes. * An open hash table hash_table[ ], for faster access. The inodes are managed using the functions: * iget (to procure an inode) * namei (to get an inode corresponding to the filename passed as parameter) * iput (to release an inode after use) Inode Operations
The inode structure contains a pointer to an inode_operations structure, which in turn contains pointers to functions needed for file management. These functions are usually called directly from appropriate system calls. struct inode_operations { struct file_operations *default_file_ops; int (*create) (struct inode *dir, const char *filename, int len, int mode, struct inode **result_inode); int (*lookup) (struct inode *dir, const char *filename, int len, struct inode **result_inode); int (*link) (struct inode *oldinode, struct inode *dir, const char *filename, int len); int (*unlink) (struct inode *dir, const char *filename, int len); int (*symlink) (struct inode *dir, const char *filename, int len, const char *destname); int (*mkdir) (struct inode *dir, const char *filename, int len, int mode); int (*rmdir) (struct inode *dir, const char *filename, int len); int (*mknod) (struct inode *dir, const char *filename, int len, int mode, int rdev); int (*rename) (struct inode *olddir, const char *oldname, int oldlen, struct inode *newdir, const char *newname, int newlen); int (*readlink) (struct inode *inode1, char *buf, int size); int (*follow_link) (struct inode *dir, struct inode *inode1, int flag, int mode, struct inode **result_inode); int (*bmap) (struct inode *inode1, int block); void (*truncate) (struct inode *inode1); int (*permission) (struct inode *inode1, int flag); int (*smap) (struct inode *inode1, int sector); }; NOTE: the parameters have been given names here in order to co-relate with them during the following discussion. * default_file_ops It points to a file operations structure, which is an interface for various operations on files, like open, read etc. * create It extracts a free inode from the complete list of inodes and fills it with the file-system-specific data. After this, it enters the 'filename' in the directory specified by the parameter dir. * lookup This function searches for the inode corresponding to the file 'filename' and returns it in the parameter 'result_inode'. * link This function sets up a hard link between the oldinode and the filename specified by 'filename' present in the directory 'dir'. Before this routine is called, a check is made to ensure that both the inodes 'oldinode' and 'dir' reside on the same device. * unlink This function deletes the file 'filename' present in the directory 'dir'. * symlink It creates a symbolic link under the name 'filename' in the directory 'dir' and makes it point to the file specified by 'destname'. * mkdir This function sets up a subdirectory with name 'filename' under the directory 'dir' and sets the access rights for the subdirectory as specified by the parameter 'mode'. * rmdir This function deletes the subdirectory 'filename' present in the directory 'dir', after checking that the subdirectory is empty and performing some other validations. * mknod This function creates a new file with name 'filename' under the directory 'dir' and sets up the access rights for the inode to those specified by the parameter 'mode'. If the inode points to a device file, then the device number is given by the parameter 'rdev'. * rename This function changes the name of a file, by removing the old name 'oldname' from the old directory 'olddir' and making an entry for 'newname' under the directory 'newdir'. * readlink This function reads symbolic links and copies the pathname for the link to which it points in the buffer 'buf' passed as a parameter. If the buffer is small, then the pathname is truncated to fit into the buffer. * follow_link It is used to resolve symbolic links, by returning the inode to which the 'inode1' points. The result is passed back via the paramter result_inode. * bmap This function enables memory mapping of files. It maps a block from the file to an address in the user address space. * truncate This function is used to change the size of the file corresponding to 'inode1'. Normally it shortens the length of the file, but if the implementation allows, the length of the file can even be increased. The new length of the file is specified in the 'i_size' field of the inode 'inode1' before a call is made to this routine. * permission This function checks the inode 'inode1' to confirm the access rights to the file as specified by the parameter 'flag'. * smap This function allows swap files to be created on a UMSDOS file system.
Other articles by Vans Information
Current Rating: [ 5.75 / 10 ]
Number of Times Rated: [ 44 ]
|