xv6, line by line
kernel/stat.h

kernel/stat.h

C header · 11 lines · annotated 100% · kernel · upstream

Included by 25 fileskernel/file.c, kernel/fs.c, kernel/sysfile.c, mkfs/mkfs.c, user/dorphan.c, user/echo.c, user/forktest.c, user/forphan.c, user/grep.c, user/grind.c, user/init.c, user/kill.c, user/ln.c, user/logstress.c, user/ls.c, user/mkdir.c, user/printf.c, user/rm.c, user/stressfs.c, user/sync.c, user/ulib.c, user/umalloc.c, user/usertests.c, user/wc.c, user/zombie.c
About this file

The file metadata that user programs can ask for, shared by the kernel and user programs (many files in user/ include it as kernel/stat.h). It defines the three inode type codes and struct stat, which the fstat system call fills in through filestat and stati.

User programs such as user/ls.c use it to tell files from directories and to print sizes and inode numbers; the user-library function stat opens a path and calls fstat. mkfs/mkfs.c includes it too, renaming the structure to avoid a clash with the host system’s own struct stat.

Read next: kernel/fs.c (stati), kernel/file.c (filestat).

1#define T_DIR 1 // Directory
2#define T_FILE 2 // File
3#define T_DEVICE 3 // Device
5struct stat {
6 int dev; // File system's disk device
7 uint ino; // Inode number
8 short type; // Type of file
9 short nlink; // Number of links to file
10 uint64 size; // Size of file in bytes
11};