Linux under C programming: Linux File Organization information

Source: Internet
Author: User

There are three of information related to files in the Linux system. They are the directory structure of the files, the index nodes, and the data itself of the file.

1. Directory Structure of files

Each directory of the system is in a certain directory structure that contains a list of all the entries in the directory, each containing a name and index node. By name, an application can access the contents of a directory entry. The index node number, however, provides information about the required reference file itself.

2. Index node

In a Linux system, all files have a linked index node (inode). The index node is used to hold the file information. The index node contains the following information.

The stat structure is defined in linux2.6.39/include/asm-generic/stat.h to hold this information. The stat structure is defined as follows.

struct stat     
         
{     
dev_t st_dev; 
         
/*device*/ino_t st_inl;/*inode*/mode_t; st_mode nlink_t St_nlink; /number of hard links*/     
         
uid_t st_uid/*user ID of owner*/gid_t; 
         
st_gid ID of/*group owner*/; 
         
/*device type (if inode device)/ 
         
off_t st_size;/*total size,in bytes*/unsigned 
         
long st_blksize;/*blocksize fo R filesystem*/ 
         
unsigned long st_blocks/*number of blocks allocated*/time_t 
         
, St_atime c13/>time_t St_mtime; /*time of modification*/ 
         
time_t st_ctime/*time of last change*/ 
         
};

The stat structure can be accessed through system calls to obtain information about the index nodes.

Note: From the information contained in the index node, you can see two parameters St_dev and St_rdev. They have different meanings. St_dev corresponds to each file name, representing the device number of the file system that contains the file name and corresponding index node. St_rdev is only a character device file or block device file that represents the device number of the actual device.

3. Data

Typically, a file contains a certain amount of data. Both normal and directory files have a corresponding hard disk area to store data. The data is stored at the location specified by the index node. Other special files, such as device files, do not have such a storage area on the hard disk.

View a full set of articles: Http://www.bianceng.cn/Programming/C/201212/34807.htm

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.