Inode Object (in VFS)
1. Inode Object (in VFS)
In the Virtual File System (VFS) layer, an inode object is the in-memory representation of a file.
✅ What it represents
-
A file (regular file, directory, device, etc.)
-
Its metadata (not the actual data)
📌 Key idea
-
Disk → stores inode structure (persistent)
-
Memory → VFS creates inode object for active files
Contents of an inode object
The inode object typically contains:
1. File metadata
-
File type (file, directory, device)
-
Permissions (read/write/execute)
-
Owner (user ID, group ID)
-
File size
-
Timestamps (access, modify, change)
2. File location info
-
Pointers to data blocks (direct/indirect)
3. VFS-specific fields
-
Reference count (how many processes use it)
-
Locking information
-
Pointer to inode operations
-
Pointer to file system type
📌 Important concept
👉 One inode object = one file in memory
Even if multiple processes open the same file:
-
They share the same inode object
-
But have different file descriptors
2. Inode Operations
In VFS, each inode has a set of operations (functions) associated with it.
👉 These are called inode operations and define what you can do with that file.
🧩 Why inode operations exist
Different file systems (ext2, ext3, NFS, etc.) behave differently.
👉 VFS solves this by:
-
Defining a common interface
-
Letting each file system implement its own version
⚙️ Common inode operations
Here are the most important ones:
📂 1. lookup
-
Finds a file inside a directory
👉 Example:
-
Lookup is used to find
file.txtinside/home/user
➕ 2. create
-
Creates a new file in a directory
👉 Used when:
❌ 3. unlink
-
Removes a file (deletes a name)
👉 Important:
-
Decreases link count
-
Deletes file only if count = 0
📁 4. mkdir
-
Creates a directory
🗑️ 5. rmdir
-
Deletes a directory (must be empty)
🔗 6. link
-
Creates a hard link
🔗➡️ 7. symlink
-
Creates a symbolic link
✏️ 8. rename
-
Renames a file or directory (atomic operation)
📊 9. getattr
-
Gets file metadata (like
stat())
✍️ 10. setattr
-
Changes metadata (permissions, size, etc.)
3. How VFS Uses Inode + Operations
🔄 Flow example: opening a file
-
Path is given:
-
VFS:
-
Uses lookup() step-by-step
-
Finds corresponding inode objects
-
-
Once inode is found:
-
Uses inode operations for further actions
-
Key Insight
👉 Inode = data (what the file is)
👉 Inode operations = behavior (what you can do with it)
4. Simple Analogy
Think of inode like this:
| Concept | Real-world analogy |
|---|---|
| Inode object | File record in a library |
| Data blocks | Pages of the book |
| Inode operations | Actions (read, write, delete) |
| VFS | Librarian managing all books |
5. Key Points to Remember
-
Inode object is in-memory representation of a file
-
Stores metadata, not file name
-
File name is stored in directory
-
Inode operations define file behavior
-
VFS provides uniform interface across file systems
Summary
-
Inode object: Represents a file in memory with metadata and pointers
-
Inode operations: Functions that define actions like create, delete, lookup, etc.
-
VFS uses them to provide a common interface across different file systems
Comments
Post a Comment