Linux-file-data structure

The Linux kernel uses the file structure file and the file table file_talbe[] to manage operational access to files.

The file data structure is as follows:

    // file structure (used to establish a relationship between file handles and i -nodes)

 struct file {

         unsigned shortf_mode; // file operation mode ( RW bit)

         unsigned shortf_flags; // File open and control flags.

         unsigned shortf_count; // Corresponding file reference count value.

         struct m_inode * f_inode; // Point to the corresponding i node.

         off_t f_pos; //File position (read and write offset value).

 };


    // This is the inode structure in memory . The first 7 items are exactly the same as d_inode .

 struct m_inode {

         unsigned short i_mode; // File type and attributes (rwx bits ) .

         unsigned shorti_uid; // User id (file owner identifier).

         unsigned longi_size; // File size (bytes).

         unsigned longi_mtime; // Modification time (since 1970.1.1:0 , seconds).

         unsigned chari_gid; // Group id ( group of the file owner ) .

         unsigned chari_nlinks; // Number of file directory item links.

         unsigned shorti_zone[9]; // Direct (0-6) , indirect (7) or double indirect (8) logical block number.

 /* these are in memory also */

         struct task_struct * i_wait; // The process waiting for the i node.

         struct task_struct * i_wait2;   /* forpipes */

         unsigned longi_atime; // Last access time.

        unsigned long i_ctime; // The modification time of the i-node itself.

         unsigned shorti_dev; // The device number where the i node is located.

         unsigned shorti_num; // i node number.

        unsigned shorti_count; // The number of times the i-node is used, 0 means the i - node is idle.

         unsigned chari_lock; // Lock flag.

         unsigned chari_dirt; // Modified ( dirty ) flag.

         unsigned chari_pipe; // Pipe flag.

         unsigned chari_mount; // mount flag.

         unsigned chari_seek; // Search sign ( when lseek ) .

         unsigned chari_update; // Update flag.

 };



A super block is a structure that stores the metadata of the corresponding file system. The stored metadata includes the file system size, block size,
And information such as the number of free and used blocks, the university and the location of the inode table.

    // In-memory disk superblock structure.

struct super_block {

         unsigned shorts_ninodes; //Number of nodes.

         unsigned shorts_nzones; // Number of logical blocks.

         unsigned shorts_imap_blocks; // The number of data blocks occupied by the i-node bitmap.

         unsigned shorts_zmap_blocks; // Number of data blocks occupied by the logical block bitmap.

         unsigned shorts_firstdatazone; // The first data logical block number.

         unsigned shorts_log_zone_size; // log( number of data blocks / logical blocks ) . (Based on 2 ).

         unsigned longs_max_size; //The maximum length of the file.

         unsigned shorts_magic; // The magic number of the file system.

/* These are only in memory */

         struct buffer_head * s_imap[8]; // i -node bitmap buffer block pointer array ( occupies 8 blocks, can represent 64M ) .

         struct buffer_head * s_zmap[8]; // Logical block bitmap buffer block pointer array (occupies 8 blocks).

         unsigned shorts_dev; // The device number where the super block is located.

         struct m_inode * s_isup; // The i - node of the root directory of the mounted file system . (isup-superi)

         struct m_inode * s_imount; // The i - node to be mounted to .

         unsigned long s_time; // Modify time.

         struct task_struct * s_wait; // The process waiting for the superblock.

         unsigned chars_lock; // Locked flag.

         unsigned chars_rd_only; // read-only flag.

         unsigned chars_dirt; // Modified ( dirty ) flag.

};

    // Superblock structure on disk. Lines 125-132 above are exactly the same.

struct d_super_block {

        unsigned shorts_ninodes; //Number of nodes.

         unsigned shorts_nzones; // Number of logical blocks.

         unsigned shorts_imap_blocks; // The number of data blocks occupied by the i-node bitmap.

         unsigned short s_zmap_blocks; // Number of data blocks occupied by the logical block bitmap.

         unsigned shorts_firstdatazone; // The first data logical block.

        unsigned shorts_log_zone_size; // log( number of data blocks / logical blocks ) . (Based on 2 ).

         unsigned longs_max_size; //The maximum length of the file.

         unsigned shorts_magic; // The magic number of the file system.

};

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325618430&siteId=291194637