Core · Module 5 · Lesson 7 of 12
File Metadata, Permissions, and Inodes with stat
Inspect filesystem inodes, decode file types and permission masks using POSIX macros, differentiate stat from lstat, and prevent TOCTOU race conditions.
By the end you can
- Query file metadata using stat, lstat, and fstat system calls
- Decode file types and permission bits from st_mode using POSIX bitmasks and macros
- Distinguish inode status change time (ctime) from file creation time
- Eliminate Time-of-Check to Time-of-Use (TOCTOU) security vulnerabilities using fstat
Builds on Descriptor Duplication and Redirection with dup and dup2.
01 · A question first
Why does checking if a file exists with stat() before calling open() introduce a critical security vulnerability in multi-user systems? And why is the ctime timestamp in Linux file metadata completely different from the file's creation date?
Make a guess before you read on.
02 · The idea
Members only
Unlock the full lesson
This lesson is part of the membership. Join to read it in full, along with every other premium deep dive.
What's inside
- Start with the problem
- How the idea works
- Why it is correct
- What it costs
- Pitfalls and variations
- Where it is used
03 · Practice
Asked in interviews
Something wrong with this lesson? Report a problem