Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 8: The Virtual Filesystem


int (mknod) (struct inode ,struct dentry ,int,dev_t);
int (
rename) (struct inode , struct dentry ,
struct inode , struct dentry );
int (readlink) (struct dentry , char __user ,int);
void
(follow_link) (struct dentry , struct nameidata );
void (
put_link) (struct dentry , struct nameidata , void );
void (
truncate) (struct inode );
int (
permission) (struct inode , int, struct nameidata );
int (setattr) (struct dentry , struct iattr );
int (
getattr) (struct vfsmount mnt, struct dentry , struct kstat );
int (
setxattr) (struct dentry , const char ,const void ,size_t,int);
ssize_t (
getxattr) (struct dentry , const char , void , size_t);
ssize_t (
listxattr) (struct dentry , char , size_t);
int (removexattr) (struct dentry , const char );
void (
truncate_range)(struct inode , loff_t, loff_t);
long (
fallocate)(struct inode *inode, int mode, loff_t offset,
loff_t len);
}


In most cases, the meaning of the element is clear from the name of the function pointer. The strong
similarity with the names of the corresponding system calls and userspace tools is intentional. For
example,rmdirdeletes directories,renamerenames filesystem objects, and so on.

Nevertheless, not all names can be traced back to familiar standard commands:

❑ lookupfinds the inode instance of a filesystem object by reference to its name (expressed as a
string).
❑ linkis invoked to delete a file. However, as described above, the delete operation is not
carried out if the hard link reference counter indicates that the inode is in use by more than
one file.
❑ Thexattrfunctions create, read, and delete extended attributes not supported in the
classicUnixmodel. They are used, for example, in the implementation of access control
lists (ACLs).
❑ truncatechanges the size of the specified inode. Thefunction accepts just one parameter — the
datastructureoftheinodetobeprocessed.Thenewfilesizemustbesetmanuallyinthei_size
element of the inode structure before the function is invoked.
❑ truncate_rangeallows for truncating a range of blocks (i.e., for punching holes into files), but
this operation is currently only supported by the shared memory filesystem.
❑ follow_linkfollows a symbolic link by finding the inode of the target file. Because sym-
bolic links may go beyond filesystem boundaries, the implementation of the routine is
usually very short, and work is quickly delegated to generic VFS routines that complete
the task.
❑ fallocateis used to pre-allocate space for a file, which can in some circumstances lead to per-
formance benefits. However, only very recent filesystems (like Reiserfs or Ext4) support this
operation.

struct dentrys are used as parameters throughout the function prototypes. Astruct dentryis a stan-
dardized data structure that may represent a filename or a directory. It also establishes the important
link between a filename and its inode. We examine the structure extensively below when we discuss the
Free download pdf