Lesson 8 of 15

Inode

The Inode

Every file and directory in a Linux filesystem is represented by an inode (index node). The inode stores file metadata but not the filename — names live in directory entries, which point to inodes by number.

typedef struct {
    int   ino;       // inode number (unique within filesystem)
    int   mode;      // permissions: 0644 = rw-r--r--
    int   nlink;     // number of hard links
    int   uid;       // owner user ID
    int   gid;       // owner group ID
    int   size;      // file size in bytes
    int   blocks;    // number of 512-byte blocks allocated
} Inode;

This mirrors the stat struct you get from stat(2) and the output of ls -li.

Printing an Inode

stat output looks like this:

inode:  42
mode:   644
links:  1
uid:    1000
gid:    1000
size:   1024
blocks: 8

Your Task

Implement void print_inode(Inode *ino) that prints each field in the format above.

TCC compiler loading...
Loading...
Click "Run" to execute your code.