kernel/stat.h
Included by 25 files
kernel/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.cAbout 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).
Inode types
The values stored in an inode’s type field, on disk and in memory. A
directory holds name entries, a file holds bytes, and a device inode has no
content at all: its major number picks a driver through devsw.
The value 0, which has no name here, means “free inode”: ialloc looks for it and
ifree writes it.
A directory.
An ordinary file.
A device file, such as console.
struct stat: what fstat reports
Filled from the inode by stati:
dev: the device number of the disk holding the file (alwaysROOTDEV, 1, in xv6).ino: the inode number. Two names with the samedevandinoare links to the same file.type: one of the three codes above.nlink: the link count (nlink).size: the size in bytes,uint64here although the inode stores it as a 32-bituint.
This is a much smaller structure than the struct stat of Unix systems: there are
no permissions, owners or timestamps, because xv6 inodes do not have them.