Chapter 4: Files and Directories

Chapter 4: Files and Directories

Get file information functions: stat, fstat, fstatat, lstat The ls command calls stat the most.

File types:

  • Regular files (text and binary)
  • Directory files
  • Block special files
  • Character special files
  • Named pipes FIFO
  • Sockets
  • Symbolic links

File system: Partition | Partition | Partition | Boot block, superblock | Cylinder group … | 3 Superblock copies, configuration information, inode map, block bitmap | Inodes… | Data blocks

File data blocks can only be deleted when the link count is 0, which is why the function to delete a directory entry is called unlink.

Most of stat’s information comes from inodes. The inode array in 3 points to subsequent data blocks. Directory blocks and data blocks are placed together, consisting of pointed inode number + filename. This inode number points to the inode within the same file system.

When mv renames files within the same file system, it only creates new directory entries; the actual file content is not moved.

The directory’s inode array points to directory blocks. These contain at least directory entries with filenames . and ..

unlink ensures that even if a program crashes, the temporary files it created will not be preserved. Both unlink and remove can remove links to a file or directory. For files, remove is identical to unlink. For directories, remove functions the same as rmdir.

Hard link: Directly points to the inode Limitations:

  • Hard links require both the link and file to be on the same file system
  • Only superusers can create hard links to directories

Symbolic link (soft link): Solves the above limitations, generally used to move a file or entire directory structure to another location in the system.

Using symbolic links may introduce cycles in the file system, causing most pathname lookup functions to return errors.