Properties of Files and Directories

Three Main Functions

D-SP-Ch5aa-stat_fstat_lstat

File Types

File Types

  • Regular Files: text, binary, etc.
  • Directory Files: can be only update by kernel - {(filename, pointer)}
  • Character Special Files: tty, audio, etc.
  • Block Special Files: disks, etc
  • Symbolic Links

Macros

MacroType of File
S_ISREG()regular file
S_ISDIR()directory file
S_ISCHR()character of special file
S_ISFIFO()block of special file
S_ISLNK()pipe of FIFO
S_ISLNK()symbolic link
S_ISSOCK()socket

The argument to these macros is the st_mode from stat structure

Access Permission

D-SP-Ch5ab-Access_Permissions

Real/Effective User ID

D-SP-Ch5ac-RealEffectiveUID

Ownership of a New File

D-SP-Ch5ad-NewFile_Ownership

Functions: access / umask / chmod & fchmod

D-SP-Ch5ae-access D-SP-Ch5af-umask D-SP-Ch5ag-chmod_fchmod

Sticky Bit

D-SP-Ch5ah-Sticky_Bit

Function: chown, fchown, lchown

D-SP-Ch5ai-chown_fchown_lchown

Compiler-time and Run-time Limits

Compile-time Limits

The limitation enforced during compilation - when source code is changed into executable code

e.g., array size limits, largest size of int, etc

Run-time Limits

The limitation enforced during program execution - when we actually run the program

e.g., memory limits, stack size limits, time limits, etc

D-SP-Ch5aj-sysconf_pathconf_fpathconf

File Size

File Sizes - st_size

The “logical” size of the file. File holes won’t actually occupy physical disks but will be count in st_size

File Holes

When we lseek() or truncate() beyond file size, we create “file holes”. These holes read as zeros but don’t consume physical disk space

However, when copying a file with holes, the copy operation writes actual zeros to disk, so the new file occupies full physical space without holes

Using st_blocks (actual blocks allocated), we can calculate real disk usage: st_blocks × st_blksize. This differs from st_size (logical file size) when holes exist

Functions: truncate, ftruncate

D-SP-Ch5ak-truncate_ftruncate