Linux file system

Source: Internet
Author: User

The file system refers to the physical space in which a file exists, and each partition in a Linux system is a file system with its own directory hierarchy.
1. Common File system types: upgraded version of EXT3:EXT2 with logging capability
EXT4: A new file system, also now commonly used, forward compatible ext2 and ext3, Max 1EB (1,048,576TB) partition, support for single 16TB files. The maximum number of subdirectories supports 64,000, andext3 only supports 32,000.    NFS: Network File system, invented by sun, primarily for remote file sharingFat:windows the file system used by the XP operating system
Ntfs:windows file system used by NT/XP operating systemISO9660: The file system used by most discs
UDF: rewritable data Disc File system 2. File system Features:The disk partition is also formatted (format) and is formatted to allow the operating system to use the file system format before the operating system can use the partition. for a disk partition, after being designated as the appropriate file system, it can be divided into:
    1. Super Block (Superblock): This is the first block of space for the entire file system. This includes information about the entire file system, such as the block size, total amount of inode/block, usage, remaining amount, pointers to spatial inode and data blocks, and so on. The size is 1024 bytes, just like a book with cover, table of contents, and body text. In the file system, the Super block is equivalent to the cover, from the cover can know the basic information of the book;
    2. Inode block (file index node): A file system index that records the properties of a file. It is the most basic unit of the file system and is the bridge of any subdirectory or file connected to the file system. Each subdirectory and file has only one inode block. It contains information about the basic properties of files in the file system (length of file, creation and modification time, permissions, affiliation), location of the data stored, and so on. Under Linux, you can view the Inode information for a file by using the "Ls-li" command. The size is 2048 bytes, the Inode block is equivalent to the directory, from the table of contents can know the location of each chapter;
    3. Block: The actual record of the contents of the file, if the file is too large, will occupy more than block. In order to improve the efficiency of directory Access, Linux also provides the dentry structure of the corresponding relationship between the expression path and the inode. It describes the path information and connects to the node Inode, which includes various directory information, and also points to inode and super blocks. The size is 4096 bytes, and the data block is equivalent to the text of the book, recording the specific content.
When you view a file, the file attributes and data points are isolated from the Inode table and the data is read from the data block.
because the Linux system has inode, recorded the actual location of the file data, that is, the number of data block (block), if there are 1,3,5,7 four numbers to store content, the operating system can be arranged according to the reading order of the disk, can be a breath of four Block content read out , which is like a parallelization process. However, the FAT file system does not exist in this format, so fat has no way to read all blocks of this file from the beginning. Assuming that the file's data is written sequentially to the 1->3->5->7 number four block numbers, he had to read the block one at a time before he knew where the next block was, just like a single-linked list in a data structure, each pointer field holds a pointer to the next node. If the block of the same file data is too fragmented, then our disk read head will not be able to go to all the data on the disk, so the disk will be more than a few laps to complete the contents of the file, slow, sometimes need to defragment the reason is the file write block is too discrete, this time the file read performance will be very poor result. This can be done by defragmenting the blocks that belong to the same file, so that the data is read more easily.   If you want to copy the contents of a file, you can use the LN command to create a new connection to an already existing file without copying the contents of the file. The connection has the soft connection and the hard connection cent, the soft connection is also called the symbolic connection. Each of them is characterized by:
hard Connect: with the ln source target command , Both the original file name and the connection file name point to the same physical address, which means that the hard connection and the source file have the same inode. The directory can not have a hard connection, hard connections can not cross the file system (not across different partitions), the file on the disk only one copy, can save hard disk space; because deleting a file is successful when the same index node belongs to a unique connection, it prevents unnecessary accidental deletions.
Symbolic Connection: Use the ln-s source Target command to establish a symbolic connection to a file, which is one of the Linux special files, as a file whose data is the pathname of the file it is connected to. Like a shortcut under Windows.

3. File system representation in the kernelKernel data Structure

File and IO: Each process maintains a file descriptor table in the PCB (process Control Block), which is the index of the list, each table entry has a pointer to the open file. Now let's be clear: The opened file is represented in the kernel with the file struct, and the pointer in the document descriptor table points to the file structure body.

maintains the file Status Flag (member f_flags of the file struct) and the current read and write location in the file structure (member F_pos of the file struct). In, Process 1 and Process 2 both open the same file, but correspond to different file structure bodies, so you can have different file Status flags and read and write locations. The more important members of the file struct also have f_count, which means that the reference count (Reference count) is like a smart pointer to C + +, and later we will say that system calls such as DUP and fork cause multiple file descriptors to point to the same file struct. For example, FD1 and FD2 both refer to the same file struct, then its reference count is 2, when close (FD1) does not release the file structure, but only the reference count to 1, if close (FD2), the reference count will be reduced to 0 while releasing the file structure, This really closed the file.  

 

Each file struct has a pointer to the dentry struct, and "Dentry" is an abbreviation for the directory entry (directory entry). The arguments we pass to the open, stat, and other functions are a path, such as/home/akaedu/a, where the inode of the file needs to be found based on the path. To reduce the number of reads, the kernel caches the tree structure of the directory, called the Dentry cache, where each node is a dentry struct, as long as the dentry is searched along the parts of the path, from the root directory/to the home directory, then to the akaedu directory, and then to the file a. Dentry cache saves only recently accessed directory entries, and if the directory entry you are looking for is not in the cache, it will be read from disk to memory.

Each dentry struct has a pointer pointing to the INODE structure. The INODE structure holds the information read from the disk inode. In the example, there are two dentry, representing/home/akaedu/a and/home/akaedu/b, each pointing to the same inode, stating that the two files are mutually hard links. The inode structure holds information that is read from the inode in the partition, such as owner, file size, file type, and permission bit. Each inode struct has a pointer to the inode_operations struct, which is a set of function pointers that point to some kernel functions that complete the file directory operation. Unlike File_operations, inode_operations points to a function that does not operate on a file, but functions that affect the layout of files and directories, such as adding deleted files and directories, tracking symbolic links, and so on. Each inode structure that belongs to the same file system can point to the same inode_operations struct.

the inode struct has a pointer to the Super_block struct. The Super_block structure holds information that is read from a super block on a disk partition, such as file system type, block size, and so on. The S_root member of the Super_block struct is a pointer to Dentry, indicating where the root directory of the filesystem is being mount, in which case the partition is mount to the/home directory.  

The structure of file, Dentry, inode and Super_block constitute the core concept of VFS. For ext2 file systems, there is also the concept of inode and Super block on disk storage layouts, so it is easy to establish correspondence with the concepts in VFS. Other file system formats from non-UNIX systems (such as Windows FAT32, NTFS), may not have inode or Super block concept, but in order to mount to the Linux system, but also in the driver hard to gather, Looking at FAT32 and NTFS partitions under Linux will find that the permission bits are wrong, and all files are rwxrwxrwx, because they do not have the concept of inode and permission bit, which is hard to come out of.

Mount File SystemEach partition in a Linux system is a file system with its own directory hierarchy. Linux will form the overall directory hierarchy of a system in a way that is divided into separate file systems that belong to different partitions. The word "in a certain way" means the mount. Hang the top-level directory of one file system on a subdirectory of another file system, making them a whole, called mounts. Refer to this subdirectory as a mount point. For example: Mount Windows file system: 1) First we use
sudo fdisk-l
View mounted devices, such as the bottom:/dev/hda5 2) mkdir Create a directory where the directory is as hanging in the directory, that is, you want to hang the e-disk into this directory:
Mkdir/mnt/winc
3) Windows and Linux are not using a file system, typically Linux does not mount the Windows file system, so you manually mount:
MOUNT-T vfat/dev/hda5/mnt/winc//-T VFAT points out the file system here FAT32
You are now ready to read and write these files into directories such as/mnt/winc.

Linux file system

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.