Description of St_size in file structure stat in Linux operating system and understanding of holes (Holes) in Files

Source: Internet
Author: User
St_size member in file stat struct

For all file types, st_size members have a real meaning to ordinary files, directories, and symbolic links. For ordinary files, St_size records the actual size of the file, and for a directory, the value of St_size is 16 or a multiple of 512, and for symbolic links, the value of st_size is the length of the path that the symbolic link refers to. For example, Lib->usr/lib, the value of St_size is 7.

In some UNIX systems, the value of st_size is also meaningful for files such as pipes, indicating the number of bytes that can be read in the current pipe.

Causes of holes production

When we use the Lseek function to start writing bytes at a location beyond the end of the file's original file, the space that is not written between them is not fully allocated to the file system in order to conserve disk space. This time, it will cause the size of the file, and the amount of disk space occupied by the file is inconsistent. We can see the size of the file using the Ls-l command. When using Du-s to view the disk footprint of a file, there is an inconsistency between them, and interested readers can experiment on their own under Linux.

If we use the Read function for reading in a location in hole, the function returns 0.

One thing to note is that when we use cat instructions to copy files with hole, the hole are populated with 0, which matches the disk footprint of the file to its actual size.

Description of St_size in file structure stat in Linux operating system and understanding of holes (Holes) in Files

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.