The Linux Kernel Virtual File System (VFS) Reference
====================================================
Based on kernel version 2.1.61
First Edition
November 3, 1997
Written by
Andrew E. Mileski
Abstract
--------
The Linux Kernel Virtual File System is simple in concept, but complex
in implementation, which makes it difficult for the first time file
system developer to quickly understand. Having the kernel source code
at hand makes it possible to learn all of the kernel's secrets, but
this can consume much valuable development time. This document strives
to flatten the normally steep learning curve into a gentle slope, so
that a file system developer can spend less time studying the kernel
source code, and more time on programming. Even so, this document is
only a reference, and not a how-to manual.
Table of Contents
-----------------
0. File System Type Structure
0.1 name
0.2 fs_flags
0.3 read_super
0.4 next
1. Super blocks
1.1 Super block Structure
1.1.1 s_dev
1.1.2 s_blocksize
1.1.3 s_blocksize_bits
1.1.4 s_lock
1.1.5 s_rd_only
1.1.6 s_dirt
1.1.7 s_type
1.1.8 s_op
1.1.9 dq_op
1.1.10 s_flags
1.1.11 s_magic
1.1.12 s_time
1.1.13 s_root
1.1.14 s_wait
1.1.15 s_ibasket
1.1.16 s_ibasket_count
1.1.17 s_ibasket_max
1.1.18 s_dirty
1.1.19 u
1.2 Super block Operations Structure
1.2.1 read_inode
1.2.2 write_inode
1.2.3 put_inode
1.2.4 delete_inode
1.2.5 notify_change
1.2.6 put_super
1.2.7 write_super
1.2.8 statfs
1.2.9 remount_fs
2. Inodes
2.1 Inode Structure
2.1.1 i_hash
2.1.2 i_list
2.1.3 i_ino
2.1.4 i_dev
2.1.5 i_count
2.1.6 i_mode
2.1.7 i_nlink
2.1.8 i_uid
2.1.9 i_gid
2.1.10 i_rdev
2.1.11 i_size
2.1.12 i_atime
2.1.13 i_mtime
2.1.14 i_ctime
2.1.15 i_blksize
2.1.16 i_blocks
2.1.17 i_version
2.1.18 i_nrpages
2.1.19 i_sem
2.1.20 i_op
2.1.21 i_sb
2.1.22 i_wait
2.1.23 i_flock
2.1.24 i_mmap
2.1.25 i_pages
2.1.26 i_dquot
2.1.27 i_state
2.1.28 i_flags
2.1.29 i_pipe
2.1.30 i_sock
2.1.31 i_writecount
2.1.32 i_attr_flags
2.1.33 u
2.2 Inode Operations Structure
2.2.1 default_file_ops
2.2.2 create
2.2.3 lookup
2.2.4 link
2.2.5 unlink
2.2.6 symlink
2.2.7 mkdir
2.2.8 rmdir
2.2.9 mknod
2.2.10 rename
2.2.11 readlink
2.2.12 follow_link
2.2.13 readpage
2.2.14 writepage
2.2.15 bmap
2.2.16 truncate
2.2.17 permission
2.2.18 smap
2.2.19 updatepage
2.2.20 revalidate
2.3 The Inode Cache
3. Files
3.1 File Structure
3.1.1 f_next
3.1.2 f_pprev
3.1.3 f_dentry
3.1.4 f_op
3.1.5 f_mode
3.1.6 f_pos
3.1.7 f_count
3.1.8 f_flags
3.1.9 f_reada
3.1.10 f_ramax
3.1.11 f_raend
3.1.12 f_ralen
3.1.13 f_rawin
3.1.14 f_owner
3.1.15 f_version
3.1.16 private_data
3.2 File Operations Structure
3.2.1 llseek
3.2.2 read
3.2.3 write
3.2.4 readdir
3.2.5 poll
3.2.6 ioctl
3.2.7 mmap
3.2.8 open
3.2.9 release
3.2.10 fsync
3.2.11 fasync
3.2.12 check_media_change
3.2.13 revalidate
3.2.14 lock
3.3 The File Table
4. The Directory Entry Cache
4.1 Dentry Structure
4.1.1 d_count
4.1.2 d_flags
4.1.3 d_inode
4.1.4 d_parent
4.1.5 d_mounts
4.1.6 d_covers
4.1.7 d_hash
4.1.8 d_lru
4.1.9 d_name
4.1.10 d_time
4.1.11 d_op
4.1.12 d_sb
4.2 Dentry Operations Structure
4.2.1 d_revalidate
4.2.2 d_hash
4.2.3 d_compare
4.2.4 d_delete
4.3 Quick Strings
4.3.1 Quick String Structure
4.3.1.1 name
4.3.1.2 len
4.3.1.3 hash
4.3.2 Hashing a Quick String
5. The Buffer Cache
5.1 The Buffer Head Structure
5.1.1 b_next
5.1.2 b_blocknr
5.1.3 b_size
5.1.4 b_dev
5.1.5 b_rdev
5.1.6 b_rsector
5.1.7 b_this_page
5.1.8 b_state
5.1.9 b_next_free
5.1.10 b_count
5.1.11 b_data
5.1.12 b_list
5.1.13 b_flushtime
5.1.14 b_lru_time
5.1.15 b_wait
5.1.16 b_pprev
5.1.17 b_prev_free
5.1.18 b_reqnext
5.2 Reading a Buffer
5.3 Writing a Buffer
4. Regular files
5. Directories
6. Links
7. Symbolic links
8. Block Devices
9. Character Devices
10. Memory Mapped Files
11. Quotas
11.1 Quota Operations Structure
11.1.1 initialize
11.1.2 drop
11.1.3 alloc_block
11.1.4 alloc_inode
11.1.5 free_block
11.1.6 free_inode
11.1.7 transfer
12. The VFS Character Set
12.1 Encoding with UTF-8.
Appendix A List of Kernel Filesystem Routines
Appendix B Linux on the Internet
-----------------
Preface
-------
This document is a result of many hours of studying the Linux kernel
source code by the author, in an attempt to implement a new file
system type [OSTA-UDF(tm) to be exact]. Like all tools, this document
was born out of frustration with the lack of documention available on
the subject. A few seasoned Linux kernel developers claim the kernel
source code is "self documenting", which the author of this document
strongly disagrees with.
Though every attempt has been made to ensure the correctness of this
document, the author cannot make any guarantees as to its accuracy.
The Linux kernel source code is constantly being revised, debugged,
and upgraded by volunteer programmers from around the globe. This
particular document is based on the 2.1.61 experimental kernel, which
was the latest available at the time of writing.
0. File System Type Structure
------------------------------
The following definition of the file system type structure can be found
in the header file linux/include/linux/fs.h
struct file_system_type {
const char *name;
int fs_flags;
struct super_block *(*read_super) (struct super_block *,
void *, int);
struct file_system_type * next;
};
This structure is registered with the kernel to add support for the
new file system type.
0.1 name
---------
Definition:
const char *name;
Purpose:
Pointer to a name string for the file system type.
Description:
The name string is used to locate the file system driver to use
when mounting.
For convenience, the name should be short (8 characters or less
is reasonable), and should only contain printable lower case
letters [a-z] and numbers [0-9].
The following are reserved:
affs Amiga Fast File System
afs Andrew File System
autofs AUTO-mounter File System
coherent Coherent
ext EXTended (obsolete)
ext2 Second EXTended (Linux native)
hpfs High Performance File System (OS/2)
iso9660 ISO 9660 compliant
minix Minix
msdos MS-DOS (FAT12 and FAT16)
ncpfs Novell File System
nfs Network File System
proc PROCess
romfs ROM File System
smbfs SamBA File System
sysv SYSV (and SYSV2, SYSV4)
udf Universal Disk Format
ufs
umsdos Use MS-DOS
vfat Versatile FAT (extended FAT16, FAT32)
xenix Xenix
Status:
Required.
0.2 fs_flags
-------------
Definition:
int fs_flags;
Purpose:
File system flags.
Description:
The following flags can be combined with a bitwise OR:
FS_REQUIRES_DEV File system requires a block device.
FS_NO_DCACHE Only dcache the necessary things.
FS_NO_PRELIM Prevent preloading of dentries, even if
FS_NO_DCACHE is not set.
FS_IBASKET File syst