Similar presentations:
Linux Virtual Filesystem
1. Linux Virtual Filesystem
Chris Gill and James OrrCSE 422S - Operating Systems Organization
Washington University in St. Louis
St. Louis, MO 63130
1
2. Linux VFS Layer
Kernel-wide filesystem view– Superblock (struct super_block) describes a
filesystem, provides operations the OS can use
– Each superblock has a list (in its s_list field) of
superblocks for all available file systems
– It also keeps lists of index nodes, directory entries, files
Process-specific filesystem view
– Process’ task_struct points to 3 filesystem structs
• Field fs points to a filesystem structure (struct fs_struct)
• Field files points to open files table (struct files_struct)
• Field nsproxy points to a wrapper for its namespace, etc.
– Each of these has further structure we will look at next
CSE 422S – Operating Systems Organization
2
3. Linux Process’ Views of Filesystem
• Fields in the process’task_struct point to
key filesystem structs
current
task_struct
– The new nsproxy field points nsproxy
fs
files
to a nsproxy struct that wraps
a pointer to the filesystem’s
nsproxy
files_struct
namespace (mnt_namespace)
– The files field points to a
table of process’ open files
mnt_namespace
– The fs field points to a
filesystem structure that
points to paths for the
fs_struct
process’ root and current
working directories
root
pwd
CSE 422S – Operating Systems Organization
3
4. Paths and Directory Entries
current• Each path points to a VFS
mount structure (vfs_mount)
and a directory entry (dentry)
structure (filesystem+directory)
• A VFS mount structure describes
a specific filesystem instance
(a “mount point”)
• A directory entry structure
describes any element in the
filesystem (directory or file,
though in a path it’s a directory)
task_struct
fs
fs_struct
root
pwd
path
mnt
Vfs_mount
CSE 422S – Operating Systems Organization
dentry
dentry
4
5. Directory Entries and Index Nodes
• Each directory entry points to anassociated index node (inode)
that contains metadata about the
directory entry
– Last access time, permissions, etc.
– E.g., what you see with ls command
• Index nodes also implement
operations the superblock uses
• Each directory entry also has a
character array field (d_iname)
that contains its name
dentry
d_iname
‘/’
\0 ...
d_inode
inode
CSE 422S – Operating Systems Organization
5
6. Directory Entry Hierarchy
• A directory’s dentry lists otherdirectory entries that it contains
– Stored in its d_subdirs field
• List iteration requires special
operations (see LKD Chapter 6)
– E.g., list_empty(),
list_for_each(),
list_for_each_entry(), etc.
• Can use those operations to
traverse a path (or an entire
filesystem) recursively via the
directory entry hierarchy
dentry
d_iname
\0 ...
‘/’
d_subdirs
...
dentry
d_iname
‘b’
‘i’
‘n’
\0 ...
d_subdirs
...
dentry
d_iname
‘l’
‘s’
\0 ...
d_subdirs (empty)
6
CSE 422S – Operating Systems Organization
7. Studio Exercises Today
Create a kernel module with a single thread– Runs in kernel space, in process context
– Has access to filesystem, but details differ a bit from
the view a user-space process has
– Kernel thread can get PID for a user-space process,
get its task_struct and see its filesystem view
Explore different file system data structures
– Working from process to filesystem structure to root
and working directory paths, to dentrys, etc.
– Looking at directory entries specifically as you go
CSE 422S – Operating Systems Organization
7