1af96c1e3STobin C. Harding.. SPDX-License-Identifier: GPL-2.0
2af96c1e3STobin C. Harding
3af96c1e3STobin C. Harding=========================================
4af96c1e3STobin C. HardingOverview of the Linux Virtual File System
5af96c1e3STobin C. Harding=========================================
6af96c1e3STobin C. Harding
7af96c1e3STobin C. HardingOriginal author: Richard Gooch <rgooch@atnf.csiro.au>
8af96c1e3STobin C. Harding
9af96c1e3STobin C. Harding- Copyright (C) 1999 Richard Gooch
10af96c1e3STobin C. Harding- Copyright (C) 2005 Pekka Enberg
11af96c1e3STobin C. Harding
12af96c1e3STobin C. Harding
13af96c1e3STobin C. HardingIntroduction
14af96c1e3STobin C. Harding============
15af96c1e3STobin C. Harding
16af96c1e3STobin C. HardingThe Virtual File System (also known as the Virtual Filesystem Switch) is
17af96c1e3STobin C. Hardingthe software layer in the kernel that provides the filesystem interface
18af96c1e3STobin C. Hardingto userspace programs.  It also provides an abstraction within the
19af96c1e3STobin C. Hardingkernel which allows different filesystem implementations to coexist.
20af96c1e3STobin C. Harding
21af96c1e3STobin C. HardingVFS system calls open(2), stat(2), read(2), write(2), chmod(2) and so on
22af96c1e3STobin C. Hardingare called from a process context.  Filesystem locking is described in
23ec23eb54SMauro Carvalho Chehabthe document Documentation/filesystems/locking.rst.
24af96c1e3STobin C. Harding
25af96c1e3STobin C. Harding
26af96c1e3STobin C. HardingDirectory Entry Cache (dcache)
27af96c1e3STobin C. Harding------------------------------
28af96c1e3STobin C. Harding
29af96c1e3STobin C. HardingThe VFS implements the open(2), stat(2), chmod(2), and similar system
30af96c1e3STobin C. Hardingcalls.  The pathname argument that is passed to them is used by the VFS
31af96c1e3STobin C. Hardingto search through the directory entry cache (also known as the dentry
32af96c1e3STobin C. Hardingcache or dcache).  This provides a very fast look-up mechanism to
33af96c1e3STobin C. Hardingtranslate a pathname (filename) into a specific dentry.  Dentries live
34af96c1e3STobin C. Hardingin RAM and are never saved to disc: they exist only for performance.
35af96c1e3STobin C. Harding
36af96c1e3STobin C. HardingThe dentry cache is meant to be a view into your entire filespace.  As
37af96c1e3STobin C. Hardingmost computers cannot fit all dentries in the RAM at the same time, some
38af96c1e3STobin C. Hardingbits of the cache are missing.  In order to resolve your pathname into a
39af96c1e3STobin C. Hardingdentry, the VFS may have to resort to creating dentries along the way,
40af96c1e3STobin C. Hardingand then loading the inode.  This is done by looking up the inode.
41af96c1e3STobin C. Harding
42af96c1e3STobin C. Harding
43af96c1e3STobin C. HardingThe Inode Object
44af96c1e3STobin C. Harding----------------
45af96c1e3STobin C. Harding
46af96c1e3STobin C. HardingAn individual dentry usually has a pointer to an inode.  Inodes are
47af96c1e3STobin C. Hardingfilesystem objects such as regular files, directories, FIFOs and other
48af96c1e3STobin C. Hardingbeasts.  They live either on the disc (for block device filesystems) or
49af96c1e3STobin C. Hardingin the memory (for pseudo filesystems).  Inodes that live on the disc
50af96c1e3STobin C. Hardingare copied into the memory when required and changes to the inode are
51af96c1e3STobin C. Hardingwritten back to disc.  A single inode can be pointed to by multiple
52af96c1e3STobin C. Hardingdentries (hard links, for example, do this).
53af96c1e3STobin C. Harding
54af96c1e3STobin C. HardingTo look up an inode requires that the VFS calls the lookup() method of
55af96c1e3STobin C. Hardingthe parent directory inode.  This method is installed by the specific
56af96c1e3STobin C. Hardingfilesystem implementation that the inode lives in.  Once the VFS has the
57af96c1e3STobin C. Hardingrequired dentry (and hence the inode), we can do all those boring things
58af96c1e3STobin C. Hardinglike open(2) the file, or stat(2) it to peek at the inode data.  The
59af96c1e3STobin C. Hardingstat(2) operation is fairly simple: once the VFS has the dentry, it
60af96c1e3STobin C. Hardingpeeks at the inode data and passes some of it back to userspace.
61af96c1e3STobin C. Harding
62af96c1e3STobin C. Harding
63af96c1e3STobin C. HardingThe File Object
64af96c1e3STobin C. Harding---------------
65af96c1e3STobin C. Harding
66af96c1e3STobin C. HardingOpening a file requires another operation: allocation of a file
67af96c1e3STobin C. Hardingstructure (this is the kernel-side implementation of file descriptors).
68af96c1e3STobin C. HardingThe freshly allocated file structure is initialized with a pointer to
69af96c1e3STobin C. Hardingthe dentry and a set of file operation member functions.  These are
70af96c1e3STobin C. Hardingtaken from the inode data.  The open() file method is then called so the
71af96c1e3STobin C. Hardingspecific filesystem implementation can do its work.  You can see that
72af96c1e3STobin C. Hardingthis is another switch performed by the VFS.  The file structure is
73af96c1e3STobin C. Hardingplaced into the file descriptor table for the process.
74af96c1e3STobin C. Harding
75af96c1e3STobin C. HardingReading, writing and closing files (and other assorted VFS operations)
76af96c1e3STobin C. Hardingis done by using the userspace file descriptor to grab the appropriate
77af96c1e3STobin C. Hardingfile structure, and then calling the required file structure method to
78af96c1e3STobin C. Hardingdo whatever is required.  For as long as the file is open, it keeps the
79af96c1e3STobin C. Hardingdentry in use, which in turn means that the VFS inode is still in use.
80af96c1e3STobin C. Harding
81af96c1e3STobin C. Harding
82af96c1e3STobin C. HardingRegistering and Mounting a Filesystem
83af96c1e3STobin C. Harding=====================================
84af96c1e3STobin C. Harding
85af96c1e3STobin C. HardingTo register and unregister a filesystem, use the following API
86af96c1e3STobin C. Hardingfunctions:
87af96c1e3STobin C. Harding
88af96c1e3STobin C. Harding.. code-block:: c
89af96c1e3STobin C. Harding
90af96c1e3STobin C. Harding	#include <linux/fs.h>
91af96c1e3STobin C. Harding
92af96c1e3STobin C. Harding	extern int register_filesystem(struct file_system_type *);
93af96c1e3STobin C. Harding	extern int unregister_filesystem(struct file_system_type *);
94af96c1e3STobin C. Harding
95af96c1e3STobin C. HardingThe passed struct file_system_type describes your filesystem.  When a
96af96c1e3STobin C. Hardingrequest is made to mount a filesystem onto a directory in your
97af96c1e3STobin C. Hardingnamespace, the VFS will call the appropriate mount() method for the
98af96c1e3STobin C. Hardingspecific filesystem.  New vfsmount referring to the tree returned by
99af96c1e3STobin C. Harding->mount() will be attached to the mountpoint, so that when pathname
100af96c1e3STobin C. Hardingresolution reaches the mountpoint it will jump into the root of that
101af96c1e3STobin C. Hardingvfsmount.
102af96c1e3STobin C. Harding
103af96c1e3STobin C. HardingYou can see all filesystems that are registered to the kernel in the
104af96c1e3STobin C. Hardingfile /proc/filesystems.
105af96c1e3STobin C. Harding
106af96c1e3STobin C. Harding
107af96c1e3STobin C. Hardingstruct file_system_type
108af96c1e3STobin C. Harding-----------------------
109af96c1e3STobin C. Harding
110af96c1e3STobin C. HardingThis describes the filesystem.  As of kernel 2.6.39, the following
111af96c1e3STobin C. Hardingmembers are defined:
112af96c1e3STobin C. Harding
113af96c1e3STobin C. Harding.. code-block:: c
114af96c1e3STobin C. Harding
115af96c1e3STobin C. Harding	struct file_system_operations {
116af96c1e3STobin C. Harding		const char *name;
117af96c1e3STobin C. Harding		int fs_flags;
118af96c1e3STobin C. Harding		struct dentry *(*mount) (struct file_system_type *, int,
119af96c1e3STobin C. Harding					 const char *, void *);
120af96c1e3STobin C. Harding		void (*kill_sb) (struct super_block *);
121af96c1e3STobin C. Harding		struct module *owner;
122af96c1e3STobin C. Harding		struct file_system_type * next;
123af96c1e3STobin C. Harding		struct list_head fs_supers;
124af96c1e3STobin C. Harding		struct lock_class_key s_lock_key;
125af96c1e3STobin C. Harding		struct lock_class_key s_umount_key;
126af96c1e3STobin C. Harding	};
127af96c1e3STobin C. Harding
128ee5dc049STobin C. Harding``name``
129ee5dc049STobin C. Harding	the name of the filesystem type, such as "ext2", "iso9660",
130af96c1e3STobin C. Harding	"msdos" and so on
131af96c1e3STobin C. Harding
132ee5dc049STobin C. Harding``fs_flags``
133ee5dc049STobin C. Harding	various flags (i.e. FS_REQUIRES_DEV, FS_NO_DCACHE, etc.)
134af96c1e3STobin C. Harding
135ee5dc049STobin C. Harding``mount``
136ee5dc049STobin C. Harding	the method to call when a new instance of this filesystem should
137af96c1e3STobin C. Harding	be mounted
138af96c1e3STobin C. Harding
139ee5dc049STobin C. Harding``kill_sb``
140ee5dc049STobin C. Harding	the method to call when an instance of this filesystem should be
141ee5dc049STobin C. Harding	shut down
142af96c1e3STobin C. Harding
143af96c1e3STobin C. Harding
144ee5dc049STobin C. Harding``owner``
145ee5dc049STobin C. Harding	for internal VFS use: you should initialize this to THIS_MODULE
146ee5dc049STobin C. Harding	in most cases.
147ee5dc049STobin C. Harding
148ee5dc049STobin C. Harding``next``
149ee5dc049STobin C. Harding	for internal VFS use: you should initialize this to NULL
150af96c1e3STobin C. Harding
151af96c1e3STobin C. Harding  s_lock_key, s_umount_key: lockdep-specific
152af96c1e3STobin C. Harding
153af96c1e3STobin C. HardingThe mount() method has the following arguments:
154af96c1e3STobin C. Harding
155ee5dc049STobin C. Harding``struct file_system_type *fs_type``
156ee5dc049STobin C. Harding	describes the filesystem, partly initialized by the specific
157ee5dc049STobin C. Harding	filesystem code
158af96c1e3STobin C. Harding
159ee5dc049STobin C. Harding``int flags``
160ee5dc049STobin C. Harding	mount flags
161af96c1e3STobin C. Harding
162ee5dc049STobin C. Harding``const char *dev_name``
163ee5dc049STobin C. Harding	the device name we are mounting.
164af96c1e3STobin C. Harding
165ee5dc049STobin C. Harding``void *data``
166ee5dc049STobin C. Harding	arbitrary mount options, usually comes as an ASCII string (see
167ee5dc049STobin C. Harding	"Mount Options" section)
168af96c1e3STobin C. Harding
169af96c1e3STobin C. HardingThe mount() method must return the root dentry of the tree requested by
170af96c1e3STobin C. Hardingcaller.  An active reference to its superblock must be grabbed and the
171af96c1e3STobin C. Hardingsuperblock must be locked.  On failure it should return ERR_PTR(error).
172af96c1e3STobin C. Harding
173af96c1e3STobin C. HardingThe arguments match those of mount(2) and their interpretation depends
174af96c1e3STobin C. Hardingon filesystem type.  E.g. for block filesystems, dev_name is interpreted
175af96c1e3STobin C. Hardingas block device name, that device is opened and if it contains a
176af96c1e3STobin C. Hardingsuitable filesystem image the method creates and initializes struct
177af96c1e3STobin C. Hardingsuper_block accordingly, returning its root dentry to caller.
178af96c1e3STobin C. Harding
179af96c1e3STobin C. Harding->mount() may choose to return a subtree of existing filesystem - it
180af96c1e3STobin C. Hardingdoesn't have to create a new one.  The main result from the caller's
181af96c1e3STobin C. Hardingpoint of view is a reference to dentry at the root of (sub)tree to be
182af96c1e3STobin C. Hardingattached; creation of new superblock is a common side effect.
183af96c1e3STobin C. Harding
184af96c1e3STobin C. HardingThe most interesting member of the superblock structure that the mount()
185af96c1e3STobin C. Hardingmethod fills in is the "s_op" field.  This is a pointer to a "struct
186af96c1e3STobin C. Hardingsuper_operations" which describes the next level of the filesystem
187af96c1e3STobin C. Hardingimplementation.
188af96c1e3STobin C. Harding
189af96c1e3STobin C. HardingUsually, a filesystem uses one of the generic mount() implementations
190af96c1e3STobin C. Hardingand provides a fill_super() callback instead.  The generic variants are:
191af96c1e3STobin C. Harding
192ee5dc049STobin C. Harding``mount_bdev``
193ee5dc049STobin C. Harding	mount a filesystem residing on a block device
194af96c1e3STobin C. Harding
195ee5dc049STobin C. Harding``mount_nodev``
196ee5dc049STobin C. Harding	mount a filesystem that is not backed by a device
197af96c1e3STobin C. Harding
198ee5dc049STobin C. Harding``mount_single``
199ee5dc049STobin C. Harding	mount a filesystem which shares the instance between all mounts
200af96c1e3STobin C. Harding
201af96c1e3STobin C. HardingA fill_super() callback implementation has the following arguments:
202af96c1e3STobin C. Harding
203ee5dc049STobin C. Harding``struct super_block *sb``
204ee5dc049STobin C. Harding	the superblock structure.  The callback must initialize this
205ee5dc049STobin C. Harding	properly.
206af96c1e3STobin C. Harding
207ee5dc049STobin C. Harding``void *data``
208ee5dc049STobin C. Harding	arbitrary mount options, usually comes as an ASCII string (see
209ee5dc049STobin C. Harding	"Mount Options" section)
210af96c1e3STobin C. Harding
211ee5dc049STobin C. Harding``int silent``
212ee5dc049STobin C. Harding	whether or not to be silent on error
213af96c1e3STobin C. Harding
214af96c1e3STobin C. Harding
215af96c1e3STobin C. HardingThe Superblock Object
216af96c1e3STobin C. Harding=====================
217af96c1e3STobin C. Harding
218af96c1e3STobin C. HardingA superblock object represents a mounted filesystem.
219af96c1e3STobin C. Harding
220af96c1e3STobin C. Harding
221af96c1e3STobin C. Hardingstruct super_operations
222af96c1e3STobin C. Harding-----------------------
223af96c1e3STobin C. Harding
224af96c1e3STobin C. HardingThis describes how the VFS can manipulate the superblock of your
225af96c1e3STobin C. Hardingfilesystem.  As of kernel 2.6.22, the following members are defined:
226af96c1e3STobin C. Harding
227af96c1e3STobin C. Harding.. code-block:: c
228af96c1e3STobin C. Harding
229af96c1e3STobin C. Harding	struct super_operations {
230af96c1e3STobin C. Harding		struct inode *(*alloc_inode)(struct super_block *sb);
231af96c1e3STobin C. Harding		void (*destroy_inode)(struct inode *);
232af96c1e3STobin C. Harding
233af96c1e3STobin C. Harding		void (*dirty_inode) (struct inode *, int flags);
234af96c1e3STobin C. Harding		int (*write_inode) (struct inode *, int);
235af96c1e3STobin C. Harding		void (*drop_inode) (struct inode *);
236af96c1e3STobin C. Harding		void (*delete_inode) (struct inode *);
237af96c1e3STobin C. Harding		void (*put_super) (struct super_block *);
238af96c1e3STobin C. Harding		int (*sync_fs)(struct super_block *sb, int wait);
239af96c1e3STobin C. Harding		int (*freeze_fs) (struct super_block *);
240af96c1e3STobin C. Harding		int (*unfreeze_fs) (struct super_block *);
241af96c1e3STobin C. Harding		int (*statfs) (struct dentry *, struct kstatfs *);
242af96c1e3STobin C. Harding		int (*remount_fs) (struct super_block *, int *, char *);
243af96c1e3STobin C. Harding		void (*clear_inode) (struct inode *);
244af96c1e3STobin C. Harding		void (*umount_begin) (struct super_block *);
245af96c1e3STobin C. Harding
246af96c1e3STobin C. Harding		int (*show_options)(struct seq_file *, struct dentry *);
247af96c1e3STobin C. Harding
248af96c1e3STobin C. Harding		ssize_t (*quota_read)(struct super_block *, int, char *, size_t, loff_t);
249af96c1e3STobin C. Harding		ssize_t (*quota_write)(struct super_block *, int, const char *, size_t, loff_t);
250af96c1e3STobin C. Harding		int (*nr_cached_objects)(struct super_block *);
251af96c1e3STobin C. Harding		void (*free_cached_objects)(struct super_block *, int);
252af96c1e3STobin C. Harding	};
253af96c1e3STobin C. Harding
254af96c1e3STobin C. HardingAll methods are called without any locks being held, unless otherwise
255af96c1e3STobin C. Hardingnoted.  This means that most methods can block safely.  All methods are
256af96c1e3STobin C. Hardingonly called from a process context (i.e. not from an interrupt handler
257af96c1e3STobin C. Hardingor bottom half).
258af96c1e3STobin C. Harding
259ee5dc049STobin C. Harding``alloc_inode``
260ee5dc049STobin C. Harding	this method is called by alloc_inode() to allocate memory for
261ee5dc049STobin C. Harding	struct inode and initialize it.  If this function is not
262af96c1e3STobin C. Harding	defined, a simple 'struct inode' is allocated.  Normally
263af96c1e3STobin C. Harding	alloc_inode will be used to allocate a larger structure which
264af96c1e3STobin C. Harding	contains a 'struct inode' embedded within it.
265af96c1e3STobin C. Harding
266ee5dc049STobin C. Harding``destroy_inode``
267ee5dc049STobin C. Harding	this method is called by destroy_inode() to release resources
268ee5dc049STobin C. Harding	allocated for struct inode.  It is only required if
269af96c1e3STobin C. Harding	->alloc_inode was defined and simply undoes anything done by
270af96c1e3STobin C. Harding	->alloc_inode.
271af96c1e3STobin C. Harding
272ee5dc049STobin C. Harding``dirty_inode``
273*a38ed483SEric Biggers	this method is called by the VFS when an inode is marked dirty.
274*a38ed483SEric Biggers	This is specifically for the inode itself being marked dirty,
275*a38ed483SEric Biggers	not its data.  If the update needs to be persisted by fdatasync(),
276*a38ed483SEric Biggers	then I_DIRTY_DATASYNC will be set in the flags argument.
277af96c1e3STobin C. Harding
278ee5dc049STobin C. Harding``write_inode``
279ee5dc049STobin C. Harding	this method is called when the VFS needs to write an inode to
280ee5dc049STobin C. Harding	disc.  The second parameter indicates whether the write should
281ee5dc049STobin C. Harding	be synchronous or not, not all filesystems check this flag.
282af96c1e3STobin C. Harding
283ee5dc049STobin C. Harding``drop_inode``
284ee5dc049STobin C. Harding	called when the last access to the inode is dropped, with the
285ee5dc049STobin C. Harding	inode->i_lock spinlock held.
286af96c1e3STobin C. Harding
287af96c1e3STobin C. Harding	This method should be either NULL (normal UNIX filesystem
288ee5dc049STobin C. Harding	semantics) or "generic_delete_inode" (for filesystems that do
289ee5dc049STobin C. Harding	not want to cache inodes - causing "delete_inode" to always be
290af96c1e3STobin C. Harding	called regardless of the value of i_nlink)
291af96c1e3STobin C. Harding
292ee5dc049STobin C. Harding	The "generic_delete_inode()" behavior is equivalent to the old
293ee5dc049STobin C. Harding	practice of using "force_delete" in the put_inode() case, but
294ee5dc049STobin C. Harding	does not have the races that the "force_delete()" approach had.
295af96c1e3STobin C. Harding
296ee5dc049STobin C. Harding``delete_inode``
297ee5dc049STobin C. Harding	called when the VFS wants to delete an inode
298af96c1e3STobin C. Harding
299ee5dc049STobin C. Harding``put_super``
300ee5dc049STobin C. Harding	called when the VFS wishes to free the superblock
301af96c1e3STobin C. Harding	(i.e. unmount).  This is called with the superblock lock held
302af96c1e3STobin C. Harding
303ee5dc049STobin C. Harding``sync_fs``
304ee5dc049STobin C. Harding	called when VFS is writing out all dirty data associated with a
305ee5dc049STobin C. Harding	superblock.  The second parameter indicates whether the method
306af96c1e3STobin C. Harding	should wait until the write out has been completed.  Optional.
307af96c1e3STobin C. Harding
308ee5dc049STobin C. Harding``freeze_fs``
309ee5dc049STobin C. Harding	called when VFS is locking a filesystem and forcing it into a
310ee5dc049STobin C. Harding	consistent state.  This method is currently used by the Logical
311ee5dc049STobin C. Harding	Volume Manager (LVM).
312af96c1e3STobin C. Harding
313ee5dc049STobin C. Harding``unfreeze_fs``
314ee5dc049STobin C. Harding	called when VFS is unlocking a filesystem and making it writable
315af96c1e3STobin C. Harding	again.
316af96c1e3STobin C. Harding
317ee5dc049STobin C. Harding``statfs``
318ee5dc049STobin C. Harding	called when the VFS needs to get filesystem statistics.
319af96c1e3STobin C. Harding
320ee5dc049STobin C. Harding``remount_fs``
321ee5dc049STobin C. Harding	called when the filesystem is remounted.  This is called with
322ee5dc049STobin C. Harding	the kernel lock held
323af96c1e3STobin C. Harding
324ee5dc049STobin C. Harding``clear_inode``
325ee5dc049STobin C. Harding	called then the VFS clears the inode.  Optional
326af96c1e3STobin C. Harding
327ee5dc049STobin C. Harding``umount_begin``
328ee5dc049STobin C. Harding	called when the VFS is unmounting a filesystem.
329af96c1e3STobin C. Harding
330ee5dc049STobin C. Harding``show_options``
331ee5dc049STobin C. Harding	called by the VFS to show mount options for /proc/<pid>/mounts.
332ee5dc049STobin C. Harding	(see "Mount Options" section)
333af96c1e3STobin C. Harding
334ee5dc049STobin C. Harding``quota_read``
335ee5dc049STobin C. Harding	called by the VFS to read from filesystem quota file.
336af96c1e3STobin C. Harding
337ee5dc049STobin C. Harding``quota_write``
338ee5dc049STobin C. Harding	called by the VFS to write to filesystem quota file.
339af96c1e3STobin C. Harding
340ee5dc049STobin C. Harding``nr_cached_objects``
341ee5dc049STobin C. Harding	called by the sb cache shrinking function for the filesystem to
342ee5dc049STobin C. Harding	return the number of freeable cached objects it contains.
343af96c1e3STobin C. Harding	Optional.
344af96c1e3STobin C. Harding
345ee5dc049STobin C. Harding``free_cache_objects``
346ee5dc049STobin C. Harding	called by the sb cache shrinking function for the filesystem to
347ee5dc049STobin C. Harding	scan the number of objects indicated to try to free them.
348ee5dc049STobin C. Harding	Optional, but any filesystem implementing this method needs to
349ee5dc049STobin C. Harding	also implement ->nr_cached_objects for it to be called
350ee5dc049STobin C. Harding	correctly.
351af96c1e3STobin C. Harding
352af96c1e3STobin C. Harding	We can't do anything with any errors that the filesystem might
353ee5dc049STobin C. Harding	encountered, hence the void return type.  This will never be
354ee5dc049STobin C. Harding	called if the VM is trying to reclaim under GFP_NOFS conditions,
355ee5dc049STobin C. Harding	hence this method does not need to handle that situation itself.
356af96c1e3STobin C. Harding
357ee5dc049STobin C. Harding	Implementations must include conditional reschedule calls inside
358ee5dc049STobin C. Harding	any scanning loop that is done.  This allows the VFS to
359ee5dc049STobin C. Harding	determine appropriate scan batch sizes without having to worry
360ee5dc049STobin C. Harding	about whether implementations will cause holdoff problems due to
361ee5dc049STobin C. Harding	large scan batch sizes.
362af96c1e3STobin C. Harding
363af96c1e3STobin C. HardingWhoever sets up the inode is responsible for filling in the "i_op"
364af96c1e3STobin C. Hardingfield.  This is a pointer to a "struct inode_operations" which describes
365af96c1e3STobin C. Hardingthe methods that can be performed on individual inodes.
366af96c1e3STobin C. Harding
367af96c1e3STobin C. Harding
368af96c1e3STobin C. Hardingstruct xattr_handlers
369af96c1e3STobin C. Harding---------------------
370af96c1e3STobin C. Harding
371af96c1e3STobin C. HardingOn filesystems that support extended attributes (xattrs), the s_xattr
372af96c1e3STobin C. Hardingsuperblock field points to a NULL-terminated array of xattr handlers.
373af96c1e3STobin C. HardingExtended attributes are name:value pairs.
374af96c1e3STobin C. Harding
375ee5dc049STobin C. Harding``name``
376ee5dc049STobin C. Harding	Indicates that the handler matches attributes with the specified
377ee5dc049STobin C. Harding	name (such as "system.posix_acl_access"); the prefix field must
378ee5dc049STobin C. Harding	be NULL.
379af96c1e3STobin C. Harding
380ee5dc049STobin C. Harding``prefix``
381ee5dc049STobin C. Harding	Indicates that the handler matches all attributes with the
382ee5dc049STobin C. Harding	specified name prefix (such as "user."); the name field must be
383ee5dc049STobin C. Harding	NULL.
384af96c1e3STobin C. Harding
385ee5dc049STobin C. Harding``list``
386ee5dc049STobin C. Harding	Determine if attributes matching this xattr handler should be
387ee5dc049STobin C. Harding	listed for a particular dentry.  Used by some listxattr
388ee5dc049STobin C. Harding	implementations like generic_listxattr.
389af96c1e3STobin C. Harding
390ee5dc049STobin C. Harding``get``
391ee5dc049STobin C. Harding	Called by the VFS to get the value of a particular extended
392ee5dc049STobin C. Harding	attribute.  This method is called by the getxattr(2) system
393ee5dc049STobin C. Harding	call.
394af96c1e3STobin C. Harding
395ee5dc049STobin C. Harding``set``
396ee5dc049STobin C. Harding	Called by the VFS to set the value of a particular extended
397ee5dc049STobin C. Harding	attribute.  When the new value is NULL, called to remove a
3988286de7cSRandy Dunlap	particular extended attribute.  This method is called by the
399ee5dc049STobin C. Harding	setxattr(2) and removexattr(2) system calls.
400af96c1e3STobin C. Harding
401af96c1e3STobin C. HardingWhen none of the xattr handlers of a filesystem match the specified
402af96c1e3STobin C. Hardingattribute name or when a filesystem doesn't support extended attributes,
403af96c1e3STobin C. Hardingthe various ``*xattr(2)`` system calls return -EOPNOTSUPP.
404af96c1e3STobin C. Harding
405af96c1e3STobin C. Harding
406af96c1e3STobin C. HardingThe Inode Object
407af96c1e3STobin C. Harding================
408af96c1e3STobin C. Harding
409af96c1e3STobin C. HardingAn inode object represents an object within the filesystem.
410af96c1e3STobin C. Harding
411af96c1e3STobin C. Harding
412af96c1e3STobin C. Hardingstruct inode_operations
413af96c1e3STobin C. Harding-----------------------
414af96c1e3STobin C. Harding
415af96c1e3STobin C. HardingThis describes how the VFS can manipulate an inode in your filesystem.
416af96c1e3STobin C. HardingAs of kernel 2.6.22, the following members are defined:
417af96c1e3STobin C. Harding
418af96c1e3STobin C. Harding.. code-block:: c
419af96c1e3STobin C. Harding
420af96c1e3STobin C. Harding	struct inode_operations {
421af96c1e3STobin C. Harding		int (*create) (struct inode *,struct dentry *, umode_t, bool);
422af96c1e3STobin C. Harding		struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
423af96c1e3STobin C. Harding		int (*link) (struct dentry *,struct inode *,struct dentry *);
424af96c1e3STobin C. Harding		int (*unlink) (struct inode *,struct dentry *);
425af96c1e3STobin C. Harding		int (*symlink) (struct inode *,struct dentry *,const char *);
426af96c1e3STobin C. Harding		int (*mkdir) (struct inode *,struct dentry *,umode_t);
427af96c1e3STobin C. Harding		int (*rmdir) (struct inode *,struct dentry *);
428af96c1e3STobin C. Harding		int (*mknod) (struct inode *,struct dentry *,umode_t,dev_t);
429af96c1e3STobin C. Harding		int (*rename) (struct inode *, struct dentry *,
430af96c1e3STobin C. Harding			       struct inode *, struct dentry *, unsigned int);
431af96c1e3STobin C. Harding		int (*readlink) (struct dentry *, char __user *,int);
432af96c1e3STobin C. Harding		const char *(*get_link) (struct dentry *, struct inode *,
433af96c1e3STobin C. Harding					 struct delayed_call *);
434af96c1e3STobin C. Harding		int (*permission) (struct inode *, int);
435af96c1e3STobin C. Harding		int (*get_acl)(struct inode *, int);
436af96c1e3STobin C. Harding		int (*setattr) (struct dentry *, struct iattr *);
437af96c1e3STobin C. Harding		int (*getattr) (const struct path *, struct kstat *, u32, unsigned int);
438af96c1e3STobin C. Harding		ssize_t (*listxattr) (struct dentry *, char *, size_t);
439af96c1e3STobin C. Harding		void (*update_time)(struct inode *, struct timespec *, int);
440af96c1e3STobin C. Harding		int (*atomic_open)(struct inode *, struct dentry *, struct file *,
441af96c1e3STobin C. Harding				   unsigned open_flag, umode_t create_mode);
442af96c1e3STobin C. Harding		int (*tmpfile) (struct inode *, struct dentry *, umode_t);
443af96c1e3STobin C. Harding	};
444af96c1e3STobin C. Harding
445af96c1e3STobin C. HardingAgain, all methods are called without any locks being held, unless
446af96c1e3STobin C. Hardingotherwise noted.
447af96c1e3STobin C. Harding
448ee5dc049STobin C. Harding``create``
449ee5dc049STobin C. Harding	called by the open(2) and creat(2) system calls.  Only required
450ee5dc049STobin C. Harding	if you want to support regular files.  The dentry you get should
451ee5dc049STobin C. Harding	not have an inode (i.e. it should be a negative dentry).  Here
452ee5dc049STobin C. Harding	you will probably call d_instantiate() with the dentry and the
453ee5dc049STobin C. Harding	newly created inode
454af96c1e3STobin C. Harding
455ee5dc049STobin C. Harding``lookup``
456ee5dc049STobin C. Harding	called when the VFS needs to look up an inode in a parent
457af96c1e3STobin C. Harding	directory.  The name to look for is found in the dentry.  This
458af96c1e3STobin C. Harding	method must call d_add() to insert the found inode into the
459af96c1e3STobin C. Harding	dentry.  The "i_count" field in the inode structure should be
460af96c1e3STobin C. Harding	incremented.  If the named inode does not exist a NULL inode
461af96c1e3STobin C. Harding	should be inserted into the dentry (this is called a negative
462ee5dc049STobin C. Harding	dentry).  Returning an error code from this routine must only be
463ee5dc049STobin C. Harding	done on a real error, otherwise creating inodes with system
464af96c1e3STobin C. Harding	calls like create(2), mknod(2), mkdir(2) and so on will fail.
465af96c1e3STobin C. Harding	If you wish to overload the dentry methods then you should
466ee5dc049STobin C. Harding	initialise the "d_dop" field in the dentry; this is a pointer to
467ee5dc049STobin C. Harding	a struct "dentry_operations".  This method is called with the
468ee5dc049STobin C. Harding	directory inode semaphore held
469af96c1e3STobin C. Harding
470ee5dc049STobin C. Harding``link``
471ee5dc049STobin C. Harding	called by the link(2) system call.  Only required if you want to
472ee5dc049STobin C. Harding	support hard links.  You will probably need to call
473af96c1e3STobin C. Harding	d_instantiate() just as you would in the create() method
474af96c1e3STobin C. Harding
475ee5dc049STobin C. Harding``unlink``
476ee5dc049STobin C. Harding	called by the unlink(2) system call.  Only required if you want
477ee5dc049STobin C. Harding	to support deleting inodes
478af96c1e3STobin C. Harding
479ee5dc049STobin C. Harding``symlink``
480ee5dc049STobin C. Harding	called by the symlink(2) system call.  Only required if you want
481ee5dc049STobin C. Harding	to support symlinks.  You will probably need to call
482af96c1e3STobin C. Harding	d_instantiate() just as you would in the create() method
483af96c1e3STobin C. Harding
484ee5dc049STobin C. Harding``mkdir``
485ee5dc049STobin C. Harding	called by the mkdir(2) system call.  Only required if you want
486af96c1e3STobin C. Harding	to support creating subdirectories.  You will probably need to
487af96c1e3STobin C. Harding	call d_instantiate() just as you would in the create() method
488af96c1e3STobin C. Harding
489ee5dc049STobin C. Harding``rmdir``
490ee5dc049STobin C. Harding	called by the rmdir(2) system call.  Only required if you want
491af96c1e3STobin C. Harding	to support deleting subdirectories
492af96c1e3STobin C. Harding
493ee5dc049STobin C. Harding``mknod``
494ee5dc049STobin C. Harding	called by the mknod(2) system call to create a device (char,
495ee5dc049STobin C. Harding	block) inode or a named pipe (FIFO) or socket.  Only required if
496ee5dc049STobin C. Harding	you want to support creating these types of inodes.  You will
497ee5dc049STobin C. Harding	probably need to call d_instantiate() just as you would in the
498ee5dc049STobin C. Harding	create() method
499af96c1e3STobin C. Harding
500ee5dc049STobin C. Harding``rename``
501ee5dc049STobin C. Harding	called by the rename(2) system call to rename the object to have
502ee5dc049STobin C. Harding	the parent and name given by the second inode and dentry.
503af96c1e3STobin C. Harding
504af96c1e3STobin C. Harding	The filesystem must return -EINVAL for any unsupported or
505af96c1e3STobin C. Harding	unknown flags.  Currently the following flags are implemented:
506ee5dc049STobin C. Harding	(1) RENAME_NOREPLACE: this flag indicates that if the target of
507ee5dc049STobin C. Harding	the rename exists the rename should fail with -EEXIST instead of
508ee5dc049STobin C. Harding	replacing the target.  The VFS already checks for existence, so
509ee5dc049STobin C. Harding	for local filesystems the RENAME_NOREPLACE implementation is
510ee5dc049STobin C. Harding	equivalent to plain rename.
511af96c1e3STobin C. Harding	(2) RENAME_EXCHANGE: exchange source and target.  Both must
512ee5dc049STobin C. Harding	exist; this is checked by the VFS.  Unlike plain rename, source
513ee5dc049STobin C. Harding	and target may be of different type.
514af96c1e3STobin C. Harding
515ee5dc049STobin C. Harding``get_link``
516ee5dc049STobin C. Harding	called by the VFS to follow a symbolic link to the inode it
517ee5dc049STobin C. Harding	points to.  Only required if you want to support symbolic links.
518ee5dc049STobin C. Harding	This method returns the symlink body to traverse (and possibly
519ee5dc049STobin C. Harding	resets the current position with nd_jump_link()).  If the body
520ee5dc049STobin C. Harding	won't go away until the inode is gone, nothing else is needed;
521ee5dc049STobin C. Harding	if it needs to be otherwise pinned, arrange for its release by
522ee5dc049STobin C. Harding	having get_link(..., ..., done) do set_delayed_call(done,
523ee5dc049STobin C. Harding	destructor, argument).  In that case destructor(argument) will
524ee5dc049STobin C. Harding	be called once VFS is done with the body you've returned.  May
525ee5dc049STobin C. Harding	be called in RCU mode; that is indicated by NULL dentry
526af96c1e3STobin C. Harding	argument.  If request can't be handled without leaving RCU mode,
527af96c1e3STobin C. Harding	have it return ERR_PTR(-ECHILD).
528af96c1e3STobin C. Harding
529af96c1e3STobin C. Harding	If the filesystem stores the symlink target in ->i_link, the
530af96c1e3STobin C. Harding	VFS may use it directly without calling ->get_link(); however,
531af96c1e3STobin C. Harding	->get_link() must still be provided.  ->i_link must not be
532af96c1e3STobin C. Harding	freed until after an RCU grace period.  Writing to ->i_link
533af96c1e3STobin C. Harding	post-iget() time requires a 'release' memory barrier.
534af96c1e3STobin C. Harding
535ee5dc049STobin C. Harding``readlink``
536ee5dc049STobin C. Harding	this is now just an override for use by readlink(2) for the
537af96c1e3STobin C. Harding	cases when ->get_link uses nd_jump_link() or object is not in
538af96c1e3STobin C. Harding	fact a symlink.  Normally filesystems should only implement
539af96c1e3STobin C. Harding	->get_link for symlinks and readlink(2) will automatically use
540af96c1e3STobin C. Harding	that.
541af96c1e3STobin C. Harding
542ee5dc049STobin C. Harding``permission``
543ee5dc049STobin C. Harding	called by the VFS to check for access rights on a POSIX-like
544af96c1e3STobin C. Harding	filesystem.
545af96c1e3STobin C. Harding
546ee5dc049STobin C. Harding	May be called in rcu-walk mode (mask & MAY_NOT_BLOCK).  If in
547ee5dc049STobin C. Harding	rcu-walk mode, the filesystem must check the permission without
548ee5dc049STobin C. Harding	blocking or storing to the inode.
549af96c1e3STobin C. Harding
550ee5dc049STobin C. Harding	If a situation is encountered that rcu-walk cannot handle,
551ee5dc049STobin C. Harding	return
552af96c1e3STobin C. Harding	-ECHILD and it will be called again in ref-walk mode.
553af96c1e3STobin C. Harding
554ee5dc049STobin C. Harding``setattr``
555ee5dc049STobin C. Harding	called by the VFS to set attributes for a file.  This method is
556ee5dc049STobin C. Harding	called by chmod(2) and related system calls.
557af96c1e3STobin C. Harding
558ee5dc049STobin C. Harding``getattr``
559ee5dc049STobin C. Harding	called by the VFS to get attributes of a file.  This method is
560ee5dc049STobin C. Harding	called by stat(2) and related system calls.
561af96c1e3STobin C. Harding
562ee5dc049STobin C. Harding``listxattr``
563ee5dc049STobin C. Harding	called by the VFS to list all extended attributes for a given
564ee5dc049STobin C. Harding	file.  This method is called by the listxattr(2) system call.
565af96c1e3STobin C. Harding
566ee5dc049STobin C. Harding``update_time``
567ee5dc049STobin C. Harding	called by the VFS to update a specific time or the i_version of
568ee5dc049STobin C. Harding	an inode.  If this is not defined the VFS will update the inode
569ee5dc049STobin C. Harding	itself and call mark_inode_dirty_sync.
570af96c1e3STobin C. Harding
571ee5dc049STobin C. Harding``atomic_open``
572ee5dc049STobin C. Harding	called on the last component of an open.  Using this optional
573ee5dc049STobin C. Harding	method the filesystem can look up, possibly create and open the
574ee5dc049STobin C. Harding	file in one atomic operation.  If it wants to leave actual
575ee5dc049STobin C. Harding	opening to the caller (e.g. if the file turned out to be a
576ee5dc049STobin C. Harding	symlink, device, or just something filesystem won't do atomic
577ee5dc049STobin C. Harding	open for), it may signal this by returning finish_no_open(file,
578ee5dc049STobin C. Harding	dentry).  This method is only called if the last component is
579ee5dc049STobin C. Harding	negative or needs lookup.  Cached positive dentries are still
580ee5dc049STobin C. Harding	handled by f_op->open().  If the file was created, FMODE_CREATED
581ee5dc049STobin C. Harding	flag should be set in file->f_mode.  In case of O_EXCL the
582ee5dc049STobin C. Harding	method must only succeed if the file didn't exist and hence
583ee5dc049STobin C. Harding	FMODE_CREATED shall always be set on success.
584af96c1e3STobin C. Harding
585ee5dc049STobin C. Harding``tmpfile``
586ee5dc049STobin C. Harding	called in the end of O_TMPFILE open().  Optional, equivalent to
587ee5dc049STobin C. Harding	atomically creating, opening and unlinking a file in given
588ee5dc049STobin C. Harding	directory.
589af96c1e3STobin C. Harding
590af96c1e3STobin C. Harding
591af96c1e3STobin C. HardingThe Address Space Object
592af96c1e3STobin C. Harding========================
593af96c1e3STobin C. Harding
594af96c1e3STobin C. HardingThe address space object is used to group and manage pages in the page
595af96c1e3STobin C. Hardingcache.  It can be used to keep track of the pages in a file (or anything
596af96c1e3STobin C. Hardingelse) and also track the mapping of sections of the file into process
597af96c1e3STobin C. Hardingaddress spaces.
598af96c1e3STobin C. Harding
599af96c1e3STobin C. HardingThere are a number of distinct yet related services that an
600af96c1e3STobin C. Hardingaddress-space can provide.  These include communicating memory pressure,
601af96c1e3STobin C. Hardingpage lookup by address, and keeping track of pages tagged as Dirty or
602af96c1e3STobin C. HardingWriteback.
603af96c1e3STobin C. Harding
604af96c1e3STobin C. HardingThe first can be used independently to the others.  The VM can try to
605af96c1e3STobin C. Hardingeither write dirty pages in order to clean them, or release clean pages
606af96c1e3STobin C. Hardingin order to reuse them.  To do this it can call the ->writepage method
607af96c1e3STobin C. Hardingon dirty pages, and ->releasepage on clean pages with PagePrivate set.
608af96c1e3STobin C. HardingClean pages without PagePrivate and with no external references will be
609af96c1e3STobin C. Hardingreleased without notice being given to the address_space.
610af96c1e3STobin C. Harding
611af96c1e3STobin C. HardingTo achieve this functionality, pages need to be placed on an LRU with
612af96c1e3STobin C. Hardinglru_cache_add and mark_page_active needs to be called whenever the page
613af96c1e3STobin C. Hardingis used.
614af96c1e3STobin C. Harding
615af96c1e3STobin C. HardingPages are normally kept in a radix tree index by ->index.  This tree
616af96c1e3STobin C. Hardingmaintains information about the PG_Dirty and PG_Writeback status of each
617af96c1e3STobin C. Hardingpage, so that pages with either of these flags can be found quickly.
618af96c1e3STobin C. Harding
619af96c1e3STobin C. HardingThe Dirty tag is primarily used by mpage_writepages - the default
620af96c1e3STobin C. Harding->writepages method.  It uses the tag to find dirty pages to call
621af96c1e3STobin C. Harding->writepage on.  If mpage_writepages is not used (i.e. the address
622af96c1e3STobin C. Hardingprovides its own ->writepages) , the PAGECACHE_TAG_DIRTY tag is almost
623af96c1e3STobin C. Hardingunused.  write_inode_now and sync_inode do use it (through
624af96c1e3STobin C. Harding__sync_single_inode) to check if ->writepages has been successful in
625af96c1e3STobin C. Hardingwriting out the whole address_space.
626af96c1e3STobin C. Harding
627af96c1e3STobin C. HardingThe Writeback tag is used by filemap*wait* and sync_page* functions, via
628af96c1e3STobin C. Hardingfilemap_fdatawait_range, to wait for all writeback to complete.
629af96c1e3STobin C. Harding
630af96c1e3STobin C. HardingAn address_space handler may attach extra information to a page,
631af96c1e3STobin C. Hardingtypically using the 'private' field in the 'struct page'.  If such
632af96c1e3STobin C. Hardinginformation is attached, the PG_Private flag should be set.  This will
633af96c1e3STobin C. Hardingcause various VM routines to make extra calls into the address_space
634af96c1e3STobin C. Hardinghandler to deal with that data.
635af96c1e3STobin C. Harding
636af96c1e3STobin C. HardingAn address space acts as an intermediate between storage and
637af96c1e3STobin C. Hardingapplication.  Data is read into the address space a whole page at a
638af96c1e3STobin C. Hardingtime, and provided to the application either by copying of the page, or
639af96c1e3STobin C. Hardingby memory-mapping the page.  Data is written into the address space by
640af96c1e3STobin C. Hardingthe application, and then written-back to storage typically in whole
641af96c1e3STobin C. Hardingpages, however the address_space has finer control of write sizes.
642af96c1e3STobin C. Harding
643af96c1e3STobin C. HardingThe read process essentially only requires 'readpage'.  The write
644af96c1e3STobin C. Hardingprocess is more complicated and uses write_begin/write_end or
645af96c1e3STobin C. Hardingset_page_dirty to write data into the address_space, and writepage and
646af96c1e3STobin C. Hardingwritepages to writeback data to storage.
647af96c1e3STobin C. Harding
648af96c1e3STobin C. HardingAdding and removing pages to/from an address_space is protected by the
649af96c1e3STobin C. Hardinginode's i_mutex.
650af96c1e3STobin C. Harding
651af96c1e3STobin C. HardingWhen data is written to a page, the PG_Dirty flag should be set.  It
652af96c1e3STobin C. Hardingtypically remains set until writepage asks for it to be written.  This
653af96c1e3STobin C. Hardingshould clear PG_Dirty and set PG_Writeback.  It can be actually written
654af96c1e3STobin C. Hardingat any point after PG_Dirty is clear.  Once it is known to be safe,
655af96c1e3STobin C. HardingPG_Writeback is cleared.
656af96c1e3STobin C. Harding
657af96c1e3STobin C. HardingWriteback makes use of a writeback_control structure to direct the
6588286de7cSRandy Dunlapoperations.  This gives the writepage and writepages operations some
659af96c1e3STobin C. Hardinginformation about the nature of and reason for the writeback request,
660af96c1e3STobin C. Hardingand the constraints under which it is being done.  It is also used to
661af96c1e3STobin C. Hardingreturn information back to the caller about the result of a writepage or
662af96c1e3STobin C. Hardingwritepages request.
663af96c1e3STobin C. Harding
664af96c1e3STobin C. Harding
665af96c1e3STobin C. HardingHandling errors during writeback
666af96c1e3STobin C. Harding--------------------------------
667af96c1e3STobin C. Harding
668af96c1e3STobin C. HardingMost applications that do buffered I/O will periodically call a file
669af96c1e3STobin C. Hardingsynchronization call (fsync, fdatasync, msync or sync_file_range) to
670af96c1e3STobin C. Hardingensure that data written has made it to the backing store.  When there
671af96c1e3STobin C. Hardingis an error during writeback, they expect that error to be reported when
672af96c1e3STobin C. Hardinga file sync request is made.  After an error has been reported on one
673af96c1e3STobin C. Hardingrequest, subsequent requests on the same file descriptor should return
674af96c1e3STobin C. Harding0, unless further writeback errors have occurred since the previous file
675af96c1e3STobin C. Hardingsyncronization.
676af96c1e3STobin C. Harding
677af96c1e3STobin C. HardingIdeally, the kernel would report errors only on file descriptions on
678af96c1e3STobin C. Hardingwhich writes were done that subsequently failed to be written back.  The
679af96c1e3STobin C. Hardinggeneric pagecache infrastructure does not track the file descriptions
680af96c1e3STobin C. Hardingthat have dirtied each individual page however, so determining which
681af96c1e3STobin C. Hardingfile descriptors should get back an error is not possible.
682af96c1e3STobin C. Harding
683af96c1e3STobin C. HardingInstead, the generic writeback error tracking infrastructure in the
684af96c1e3STobin C. Hardingkernel settles for reporting errors to fsync on all file descriptions
685af96c1e3STobin C. Hardingthat were open at the time that the error occurred.  In a situation with
686af96c1e3STobin C. Hardingmultiple writers, all of them will get back an error on a subsequent
687af96c1e3STobin C. Hardingfsync, even if all of the writes done through that particular file
688af96c1e3STobin C. Hardingdescriptor succeeded (or even if there were no writes on that file
689af96c1e3STobin C. Hardingdescriptor at all).
690af96c1e3STobin C. Harding
691af96c1e3STobin C. HardingFilesystems that wish to use this infrastructure should call
692af96c1e3STobin C. Hardingmapping_set_error to record the error in the address_space when it
693af96c1e3STobin C. Hardingoccurs.  Then, after writing back data from the pagecache in their
694af96c1e3STobin C. Hardingfile->fsync operation, they should call file_check_and_advance_wb_err to
695af96c1e3STobin C. Hardingensure that the struct file's error cursor has advanced to the correct
696af96c1e3STobin C. Hardingpoint in the stream of errors emitted by the backing device(s).
697af96c1e3STobin C. Harding
698af96c1e3STobin C. Harding
699af96c1e3STobin C. Hardingstruct address_space_operations
700af96c1e3STobin C. Harding-------------------------------
701af96c1e3STobin C. Harding
702af96c1e3STobin C. HardingThis describes how the VFS can manipulate mapping of a file to page
703af96c1e3STobin C. Hardingcache in your filesystem.  The following members are defined:
704af96c1e3STobin C. Harding
705af96c1e3STobin C. Harding.. code-block:: c
706af96c1e3STobin C. Harding
707af96c1e3STobin C. Harding	struct address_space_operations {
708af96c1e3STobin C. Harding		int (*writepage)(struct page *page, struct writeback_control *wbc);
709af96c1e3STobin C. Harding		int (*readpage)(struct file *, struct page *);
710af96c1e3STobin C. Harding		int (*writepages)(struct address_space *, struct writeback_control *);
711af96c1e3STobin C. Harding		int (*set_page_dirty)(struct page *page);
7128151b4c8SMatthew Wilcox (Oracle)		void (*readahead)(struct readahead_control *);
713af96c1e3STobin C. Harding		int (*readpages)(struct file *filp, struct address_space *mapping,
714af96c1e3STobin C. Harding				 struct list_head *pages, unsigned nr_pages);
715af96c1e3STobin C. Harding		int (*write_begin)(struct file *, struct address_space *mapping,
716af96c1e3STobin C. Harding				   loff_t pos, unsigned len, unsigned flags,
717af96c1e3STobin C. Harding				struct page **pagep, void **fsdata);
718af96c1e3STobin C. Harding		int (*write_end)(struct file *, struct address_space *mapping,
719af96c1e3STobin C. Harding				 loff_t pos, unsigned len, unsigned copied,
720af96c1e3STobin C. Harding				 struct page *page, void *fsdata);
721af96c1e3STobin C. Harding		sector_t (*bmap)(struct address_space *, sector_t);
722af96c1e3STobin C. Harding		void (*invalidatepage) (struct page *, unsigned int, unsigned int);
723af96c1e3STobin C. Harding		int (*releasepage) (struct page *, int);
724af96c1e3STobin C. Harding		void (*freepage)(struct page *);
725af96c1e3STobin C. Harding		ssize_t (*direct_IO)(struct kiocb *, struct iov_iter *iter);
726af96c1e3STobin C. Harding		/* isolate a page for migration */
727af96c1e3STobin C. Harding		bool (*isolate_page) (struct page *, isolate_mode_t);
728af96c1e3STobin C. Harding		/* migrate the contents of a page to the specified target */
729af96c1e3STobin C. Harding		int (*migratepage) (struct page *, struct page *);
730af96c1e3STobin C. Harding		/* put migration-failed page back to right list */
731af96c1e3STobin C. Harding		void (*putback_page) (struct page *);
732af96c1e3STobin C. Harding		int (*launder_page) (struct page *);
733af96c1e3STobin C. Harding
734af96c1e3STobin C. Harding		int (*is_partially_uptodate) (struct page *, unsigned long,
735af96c1e3STobin C. Harding					      unsigned long);
736af96c1e3STobin C. Harding		void (*is_dirty_writeback) (struct page *, bool *, bool *);
737af96c1e3STobin C. Harding		int (*error_remove_page) (struct mapping *mapping, struct page *page);
738af96c1e3STobin C. Harding		int (*swap_activate)(struct file *);
739af96c1e3STobin C. Harding		int (*swap_deactivate)(struct file *);
740af96c1e3STobin C. Harding	};
741af96c1e3STobin C. Harding
742ee5dc049STobin C. Harding``writepage``
743ee5dc049STobin C. Harding	called by the VM to write a dirty page to backing store.  This
744ee5dc049STobin C. Harding	may happen for data integrity reasons (i.e. 'sync'), or to free
745ee5dc049STobin C. Harding	up memory (flush).  The difference can be seen in
746ee5dc049STobin C. Harding	wbc->sync_mode.  The PG_Dirty flag has been cleared and
747ee5dc049STobin C. Harding	PageLocked is true.  writepage should start writeout, should set
748ee5dc049STobin C. Harding	PG_Writeback, and should make sure the page is unlocked, either
749ee5dc049STobin C. Harding	synchronously or asynchronously when the write operation
750ee5dc049STobin C. Harding	completes.
751af96c1e3STobin C. Harding
752af96c1e3STobin C. Harding	If wbc->sync_mode is WB_SYNC_NONE, ->writepage doesn't have to
753af96c1e3STobin C. Harding	try too hard if there are problems, and may choose to write out
754af96c1e3STobin C. Harding	other pages from the mapping if that is easier (e.g. due to
755af96c1e3STobin C. Harding	internal dependencies).  If it chooses not to start writeout, it
756ee5dc049STobin C. Harding	should return AOP_WRITEPAGE_ACTIVATE so that the VM will not
757ee5dc049STobin C. Harding	keep calling ->writepage on that page.
758af96c1e3STobin C. Harding
759af96c1e3STobin C. Harding	See the file "Locking" for more details.
760af96c1e3STobin C. Harding
761ee5dc049STobin C. Harding``readpage``
762ee5dc049STobin C. Harding	called by the VM to read a page from backing store.  The page
763ee5dc049STobin C. Harding	will be Locked when readpage is called, and should be unlocked
764ee5dc049STobin C. Harding	and marked uptodate once the read completes.  If ->readpage
765ee5dc049STobin C. Harding	discovers that it needs to unlock the page for some reason, it
766ee5dc049STobin C. Harding	can do so, and then return AOP_TRUNCATED_PAGE.  In this case,
767ee5dc049STobin C. Harding	the page will be relocated, relocked and if that all succeeds,
768ee5dc049STobin C. Harding	->readpage will be called again.
769af96c1e3STobin C. Harding
770ee5dc049STobin C. Harding``writepages``
771ee5dc049STobin C. Harding	called by the VM to write out pages associated with the
772e9b2f15bSJulia Lawall	address_space object.  If wbc->sync_mode is WB_SYNC_ALL, then
773af96c1e3STobin C. Harding	the writeback_control will specify a range of pages that must be
774e9b2f15bSJulia Lawall	written out.  If it is WB_SYNC_NONE, then a nr_to_write is
775ee5dc049STobin C. Harding	given and that many pages should be written if possible.  If no
776ee5dc049STobin C. Harding	->writepages is given, then mpage_writepages is used instead.
777ee5dc049STobin C. Harding	This will choose pages from the address space that are tagged as
778ee5dc049STobin C. Harding	DIRTY and will pass them to ->writepage.
779af96c1e3STobin C. Harding
780ee5dc049STobin C. Harding``set_page_dirty``
781ee5dc049STobin C. Harding	called by the VM to set a page dirty.  This is particularly
782ee5dc049STobin C. Harding	needed if an address space attaches private data to a page, and
783ee5dc049STobin C. Harding	that data needs to be updated when a page is dirtied.  This is
784ee5dc049STobin C. Harding	called, for example, when a memory mapped page gets modified.
785af96c1e3STobin C. Harding	If defined, it should set the PageDirty flag, and the
786af96c1e3STobin C. Harding	PAGECACHE_TAG_DIRTY tag in the radix tree.
787af96c1e3STobin C. Harding
7888151b4c8SMatthew Wilcox (Oracle)``readahead``
7898151b4c8SMatthew Wilcox (Oracle)	Called by the VM to read pages associated with the address_space
7908151b4c8SMatthew Wilcox (Oracle)	object.  The pages are consecutive in the page cache and are
7918151b4c8SMatthew Wilcox (Oracle)	locked.  The implementation should decrement the page refcount
7928151b4c8SMatthew Wilcox (Oracle)	after starting I/O on each page.  Usually the page will be
7938151b4c8SMatthew Wilcox (Oracle)	unlocked by the I/O completion handler.  If the filesystem decides
7948151b4c8SMatthew Wilcox (Oracle)	to stop attempting I/O before reaching the end of the readahead
7958151b4c8SMatthew Wilcox (Oracle)	window, it can simply return.  The caller will decrement the page
7968151b4c8SMatthew Wilcox (Oracle)	refcount and unlock the remaining pages for you.  Set PageUptodate
7978151b4c8SMatthew Wilcox (Oracle)	if the I/O completes successfully.  Setting PageError on any page
7988151b4c8SMatthew Wilcox (Oracle)	will be ignored; simply unlock the page if an I/O error occurs.
7998151b4c8SMatthew Wilcox (Oracle)
800ee5dc049STobin C. Harding``readpages``
801ee5dc049STobin C. Harding	called by the VM to read pages associated with the address_space
802ee5dc049STobin C. Harding	object.  This is essentially just a vector version of readpage.
803ee5dc049STobin C. Harding	Instead of just one page, several pages are requested.
804af96c1e3STobin C. Harding	readpages is only used for read-ahead, so read errors are
805af96c1e3STobin C. Harding	ignored.  If anything goes wrong, feel free to give up.
8068151b4c8SMatthew Wilcox (Oracle)	This interface is deprecated and will be removed by the end of
8078151b4c8SMatthew Wilcox (Oracle)	2020; implement readahead instead.
808af96c1e3STobin C. Harding
809ee5dc049STobin C. Harding``write_begin``
810ee5dc049STobin C. Harding	Called by the generic buffered write code to ask the filesystem
811ee5dc049STobin C. Harding	to prepare to write len bytes at the given offset in the file.
812ee5dc049STobin C. Harding	The address_space should check that the write will be able to
813ee5dc049STobin C. Harding	complete, by allocating space if necessary and doing any other
814ee5dc049STobin C. Harding	internal housekeeping.  If the write will update parts of any
815ee5dc049STobin C. Harding	basic-blocks on storage, then those blocks should be pre-read
816ee5dc049STobin C. Harding	(if they haven't been read already) so that the updated blocks
817ee5dc049STobin C. Harding	can be written out properly.
818af96c1e3STobin C. Harding
819ee5dc049STobin C. Harding	The filesystem must return the locked pagecache page for the
820ee5dc049STobin C. Harding	specified offset, in ``*pagep``, for the caller to write into.
821af96c1e3STobin C. Harding
822ee5dc049STobin C. Harding	It must be able to cope with short writes (where the length
823ee5dc049STobin C. Harding	passed to write_begin is greater than the number of bytes copied
824ee5dc049STobin C. Harding	into the page).
825af96c1e3STobin C. Harding
826af96c1e3STobin C. Harding	flags is a field for AOP_FLAG_xxx flags, described in
827af96c1e3STobin C. Harding	include/linux/fs.h.
828af96c1e3STobin C. Harding
829af96c1e3STobin C. Harding	A void * may be returned in fsdata, which then gets passed into
830af96c1e3STobin C. Harding	write_end.
831af96c1e3STobin C. Harding
832ee5dc049STobin C. Harding	Returns 0 on success; < 0 on failure (which is the error code),
833ee5dc049STobin C. Harding	in which case write_end is not called.
834af96c1e3STobin C. Harding
835ee5dc049STobin C. Harding``write_end``
836ee5dc049STobin C. Harding	After a successful write_begin, and data copy, write_end must be
837ee5dc049STobin C. Harding	called.  len is the original len passed to write_begin, and
838ee5dc049STobin C. Harding	copied is the amount that was able to be copied.
839af96c1e3STobin C. Harding
840ee5dc049STobin C. Harding	The filesystem must take care of unlocking the page and
841ee5dc049STobin C. Harding	releasing it refcount, and updating i_size.
842af96c1e3STobin C. Harding
843ee5dc049STobin C. Harding	Returns < 0 on failure, otherwise the number of bytes (<=
844ee5dc049STobin C. Harding	'copied') that were able to be copied into pagecache.
845af96c1e3STobin C. Harding
846ee5dc049STobin C. Harding``bmap``
847ee5dc049STobin C. Harding	called by the VFS to map a logical block offset within object to
848ee5dc049STobin C. Harding	physical block number.  This method is used by the FIBMAP ioctl
849ee5dc049STobin C. Harding	and for working with swap-files.  To be able to swap to a file,
850ee5dc049STobin C. Harding	the file must have a stable mapping to a block device.  The swap
851ee5dc049STobin C. Harding	system does not go through the filesystem but instead uses bmap
852ee5dc049STobin C. Harding	to find out where the blocks in the file are and uses those
853ee5dc049STobin C. Harding	addresses directly.
854af96c1e3STobin C. Harding
855ee5dc049STobin C. Harding``invalidatepage``
856ee5dc049STobin C. Harding	If a page has PagePrivate set, then invalidatepage will be
857ee5dc049STobin C. Harding	called when part or all of the page is to be removed from the
858ee5dc049STobin C. Harding	address space.  This generally corresponds to either a
859af96c1e3STobin C. Harding	truncation, punch hole or a complete invalidation of the address
860af96c1e3STobin C. Harding	space (in the latter case 'offset' will always be 0 and 'length'
861af96c1e3STobin C. Harding	will be PAGE_SIZE).  Any private data associated with the page
862ee5dc049STobin C. Harding	should be updated to reflect this truncation.  If offset is 0
863ee5dc049STobin C. Harding	and length is PAGE_SIZE, then the private data should be
864ee5dc049STobin C. Harding	released, because the page must be able to be completely
865ee5dc049STobin C. Harding	discarded.  This may be done by calling the ->releasepage
866ee5dc049STobin C. Harding	function, but in this case the release MUST succeed.
867af96c1e3STobin C. Harding
868ee5dc049STobin C. Harding``releasepage``
869ee5dc049STobin C. Harding	releasepage is called on PagePrivate pages to indicate that the
870ee5dc049STobin C. Harding	page should be freed if possible.  ->releasepage should remove
871ee5dc049STobin C. Harding	any private data from the page and clear the PagePrivate flag.
872ee5dc049STobin C. Harding	If releasepage() fails for some reason, it must indicate failure
873ee5dc049STobin C. Harding	with a 0 return value.  releasepage() is used in two distinct
874ee5dc049STobin C. Harding	though related cases.  The first is when the VM finds a clean
875ee5dc049STobin C. Harding	page with no active users and wants to make it a free page.  If
876ee5dc049STobin C. Harding	->releasepage succeeds, the page will be removed from the
877ee5dc049STobin C. Harding	address_space and become free.
878af96c1e3STobin C. Harding
879af96c1e3STobin C. Harding	The second case is when a request has been made to invalidate
880ee5dc049STobin C. Harding	some or all pages in an address_space.  This can happen through
881ee5dc049STobin C. Harding	the fadvise(POSIX_FADV_DONTNEED) system call or by the
882ee5dc049STobin C. Harding	filesystem explicitly requesting it as nfs and 9fs do (when they
883ee5dc049STobin C. Harding	believe the cache may be out of date with storage) by calling
884ee5dc049STobin C. Harding	invalidate_inode_pages2().  If the filesystem makes such a call,
885ee5dc049STobin C. Harding	and needs to be certain that all pages are invalidated, then its
886ee5dc049STobin C. Harding	releasepage will need to ensure this.  Possibly it can clear the
887ee5dc049STobin C. Harding	PageUptodate bit if it cannot free private data yet.
888af96c1e3STobin C. Harding
889ee5dc049STobin C. Harding``freepage``
890ee5dc049STobin C. Harding	freepage is called once the page is no longer visible in the
891ee5dc049STobin C. Harding	page cache in order to allow the cleanup of any private data.
892ee5dc049STobin C. Harding	Since it may be called by the memory reclaimer, it should not
893ee5dc049STobin C. Harding	assume that the original address_space mapping still exists, and
894ee5dc049STobin C. Harding	it should not block.
895af96c1e3STobin C. Harding
896ee5dc049STobin C. Harding``direct_IO``
897ee5dc049STobin C. Harding	called by the generic read/write routines to perform direct_IO -
898ee5dc049STobin C. Harding	that is IO requests which bypass the page cache and transfer
899ee5dc049STobin C. Harding	data directly between the storage and the application's address
900ee5dc049STobin C. Harding	space.
901af96c1e3STobin C. Harding
902ee5dc049STobin C. Harding``isolate_page``
903ee5dc049STobin C. Harding	Called by the VM when isolating a movable non-lru page.  If page
904ee5dc049STobin C. Harding	is successfully isolated, VM marks the page as PG_isolated via
905ee5dc049STobin C. Harding	__SetPageIsolated.
906af96c1e3STobin C. Harding
907ee5dc049STobin C. Harding``migrate_page``
908ee5dc049STobin C. Harding	This is used to compact the physical memory usage.  If the VM
909ee5dc049STobin C. Harding	wants to relocate a page (maybe off a memory card that is
910ee5dc049STobin C. Harding	signalling imminent failure) it will pass a new page and an old
911ee5dc049STobin C. Harding	page to this function.  migrate_page should transfer any private
912ee5dc049STobin C. Harding	data across and update any references that it has to the page.
913af96c1e3STobin C. Harding
914ee5dc049STobin C. Harding``putback_page``
915ee5dc049STobin C. Harding	Called by the VM when isolated page's migration fails.
916af96c1e3STobin C. Harding
917ee5dc049STobin C. Harding``launder_page``
918ee5dc049STobin C. Harding	Called before freeing a page - it writes back the dirty page.
919ee5dc049STobin C. Harding	To prevent redirtying the page, it is kept locked during the
920ee5dc049STobin C. Harding	whole operation.
921af96c1e3STobin C. Harding
922ee5dc049STobin C. Harding``is_partially_uptodate``
923ee5dc049STobin C. Harding	Called by the VM when reading a file through the pagecache when
924ee5dc049STobin C. Harding	the underlying blocksize != pagesize.  If the required block is
925ee5dc049STobin C. Harding	up to date then the read can complete without needing the IO to
926ee5dc049STobin C. Harding	bring the whole page up to date.
927af96c1e3STobin C. Harding
928ee5dc049STobin C. Harding``is_dirty_writeback``
929ee5dc049STobin C. Harding	Called by the VM when attempting to reclaim a page.  The VM uses
930ee5dc049STobin C. Harding	dirty and writeback information to determine if it needs to
931ee5dc049STobin C. Harding	stall to allow flushers a chance to complete some IO.
932ee5dc049STobin C. Harding	Ordinarily it can use PageDirty and PageWriteback but some
933ee5dc049STobin C. Harding	filesystems have more complex state (unstable pages in NFS
934ee5dc049STobin C. Harding	prevent reclaim) or do not set those flags due to locking
935ee5dc049STobin C. Harding	problems.  This callback allows a filesystem to indicate to the
936ee5dc049STobin C. Harding	VM if a page should be treated as dirty or writeback for the
937ee5dc049STobin C. Harding	purposes of stalling.
938af96c1e3STobin C. Harding
939ee5dc049STobin C. Harding``error_remove_page``
940ee5dc049STobin C. Harding	normally set to generic_error_remove_page if truncation is ok
941ee5dc049STobin C. Harding	for this address space.  Used for memory failure handling.
942af96c1e3STobin C. Harding	Setting this implies you deal with pages going away under you,
943af96c1e3STobin C. Harding	unless you have them locked or reference counts increased.
944af96c1e3STobin C. Harding
945ee5dc049STobin C. Harding``swap_activate``
946ee5dc049STobin C. Harding	Called when swapon is used on a file to allocate space if
947ee5dc049STobin C. Harding	necessary and pin the block lookup information in memory.  A
948ee5dc049STobin C. Harding	return value of zero indicates success, in which case this file
949ee5dc049STobin C. Harding	can be used to back swapspace.
950af96c1e3STobin C. Harding
951ee5dc049STobin C. Harding``swap_deactivate``
952ee5dc049STobin C. Harding	Called during swapoff on files where swap_activate was
953ee5dc049STobin C. Harding	successful.
954af96c1e3STobin C. Harding
955af96c1e3STobin C. Harding
956af96c1e3STobin C. HardingThe File Object
957af96c1e3STobin C. Harding===============
958af96c1e3STobin C. Harding
959af96c1e3STobin C. HardingA file object represents a file opened by a process.  This is also known
960af96c1e3STobin C. Hardingas an "open file description" in POSIX parlance.
961af96c1e3STobin C. Harding
962af96c1e3STobin C. Harding
963af96c1e3STobin C. Hardingstruct file_operations
964af96c1e3STobin C. Harding----------------------
965af96c1e3STobin C. Harding
966af96c1e3STobin C. HardingThis describes how the VFS can manipulate an open file.  As of kernel
967af96c1e3STobin C. Harding4.18, the following members are defined:
968af96c1e3STobin C. Harding
969af96c1e3STobin C. Harding.. code-block:: c
970af96c1e3STobin C. Harding
971af96c1e3STobin C. Harding	struct file_operations {
972af96c1e3STobin C. Harding		struct module *owner;
973af96c1e3STobin C. Harding		loff_t (*llseek) (struct file *, loff_t, int);
974af96c1e3STobin C. Harding		ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
975af96c1e3STobin C. Harding		ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
976af96c1e3STobin C. Harding		ssize_t (*read_iter) (struct kiocb *, struct iov_iter *);
977af96c1e3STobin C. Harding		ssize_t (*write_iter) (struct kiocb *, struct iov_iter *);
978af96c1e3STobin C. Harding		int (*iopoll)(struct kiocb *kiocb, bool spin);
979af96c1e3STobin C. Harding		int (*iterate) (struct file *, struct dir_context *);
980af96c1e3STobin C. Harding		int (*iterate_shared) (struct file *, struct dir_context *);
981af96c1e3STobin C. Harding		__poll_t (*poll) (struct file *, struct poll_table_struct *);
982af96c1e3STobin C. Harding		long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long);
983af96c1e3STobin C. Harding		long (*compat_ioctl) (struct file *, unsigned int, unsigned long);
984af96c1e3STobin C. Harding		int (*mmap) (struct file *, struct vm_area_struct *);
985af96c1e3STobin C. Harding		int (*open) (struct inode *, struct file *);
986af96c1e3STobin C. Harding		int (*flush) (struct file *, fl_owner_t id);
987af96c1e3STobin C. Harding		int (*release) (struct inode *, struct file *);
988af96c1e3STobin C. Harding		int (*fsync) (struct file *, loff_t, loff_t, int datasync);
989af96c1e3STobin C. Harding		int (*fasync) (int, struct file *, int);
990af96c1e3STobin C. Harding		int (*lock) (struct file *, int, struct file_lock *);
991af96c1e3STobin C. Harding		ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int);
992af96c1e3STobin C. Harding		unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
993af96c1e3STobin C. Harding		int (*check_flags)(int);
994af96c1e3STobin C. Harding		int (*flock) (struct file *, int, struct file_lock *);
995af96c1e3STobin C. Harding		ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int);
996af96c1e3STobin C. Harding		ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int);
997af96c1e3STobin C. Harding		int (*setlease)(struct file *, long, struct file_lock **, void **);
998af96c1e3STobin C. Harding		long (*fallocate)(struct file *file, int mode, loff_t offset,
999af96c1e3STobin C. Harding				  loff_t len);
1000af96c1e3STobin C. Harding		void (*show_fdinfo)(struct seq_file *m, struct file *f);
1001af96c1e3STobin C. Harding	#ifndef CONFIG_MMU
1002af96c1e3STobin C. Harding		unsigned (*mmap_capabilities)(struct file *);
1003af96c1e3STobin C. Harding	#endif
1004af96c1e3STobin C. Harding		ssize_t (*copy_file_range)(struct file *, loff_t, struct file *, loff_t, size_t, unsigned int);
1005af96c1e3STobin C. Harding		loff_t (*remap_file_range)(struct file *file_in, loff_t pos_in,
1006af96c1e3STobin C. Harding					   struct file *file_out, loff_t pos_out,
1007af96c1e3STobin C. Harding					   loff_t len, unsigned int remap_flags);
1008af96c1e3STobin C. Harding		int (*fadvise)(struct file *, loff_t, loff_t, int);
1009af96c1e3STobin C. Harding	};
1010af96c1e3STobin C. Harding
1011af96c1e3STobin C. HardingAgain, all methods are called without any locks being held, unless
1012af96c1e3STobin C. Hardingotherwise noted.
1013af96c1e3STobin C. Harding
1014ee5dc049STobin C. Harding``llseek``
1015ee5dc049STobin C. Harding	called when the VFS needs to move the file position index
1016af96c1e3STobin C. Harding
1017ee5dc049STobin C. Harding``read``
1018ee5dc049STobin C. Harding	called by read(2) and related system calls
1019af96c1e3STobin C. Harding
1020ee5dc049STobin C. Harding``read_iter``
1021ee5dc049STobin C. Harding	possibly asynchronous read with iov_iter as destination
1022af96c1e3STobin C. Harding
1023ee5dc049STobin C. Harding``write``
1024ee5dc049STobin C. Harding	called by write(2) and related system calls
1025af96c1e3STobin C. Harding
1026ee5dc049STobin C. Harding``write_iter``
1027ee5dc049STobin C. Harding	possibly asynchronous write with iov_iter as source
1028af96c1e3STobin C. Harding
1029ee5dc049STobin C. Harding``iopoll``
1030ee5dc049STobin C. Harding	called when aio wants to poll for completions on HIPRI iocbs
1031af96c1e3STobin C. Harding
1032ee5dc049STobin C. Harding``iterate``
1033ee5dc049STobin C. Harding	called when the VFS needs to read the directory contents
1034af96c1e3STobin C. Harding
1035ee5dc049STobin C. Harding``iterate_shared``
1036ee5dc049STobin C. Harding	called when the VFS needs to read the directory contents when
1037ee5dc049STobin C. Harding	filesystem supports concurrent dir iterators
1038af96c1e3STobin C. Harding
1039ee5dc049STobin C. Harding``poll``
1040ee5dc049STobin C. Harding	called by the VFS when a process wants to check if there is
1041af96c1e3STobin C. Harding	activity on this file and (optionally) go to sleep until there
1042af96c1e3STobin C. Harding	is activity.  Called by the select(2) and poll(2) system calls
1043af96c1e3STobin C. Harding
1044ee5dc049STobin C. Harding``unlocked_ioctl``
1045ee5dc049STobin C. Harding	called by the ioctl(2) system call.
1046af96c1e3STobin C. Harding
1047ee5dc049STobin C. Harding``compat_ioctl``
1048ee5dc049STobin C. Harding	called by the ioctl(2) system call when 32 bit system calls are
1049ee5dc049STobin C. Harding	 used on 64 bit kernels.
1050af96c1e3STobin C. Harding
1051ee5dc049STobin C. Harding``mmap``
1052ee5dc049STobin C. Harding	called by the mmap(2) system call
1053af96c1e3STobin C. Harding
1054ee5dc049STobin C. Harding``open``
1055ee5dc049STobin C. Harding	called by the VFS when an inode should be opened.  When the VFS
1056af96c1e3STobin C. Harding	opens a file, it creates a new "struct file".  It then calls the
1057af96c1e3STobin C. Harding	open method for the newly allocated file structure.  You might
1058ee5dc049STobin C. Harding	think that the open method really belongs in "struct
1059ee5dc049STobin C. Harding	inode_operations", and you may be right.  I think it's done the
1060ee5dc049STobin C. Harding	way it is because it makes filesystems simpler to implement.
1061ee5dc049STobin C. Harding	The open() method is a good place to initialize the
1062af96c1e3STobin C. Harding	"private_data" member in the file structure if you want to point
1063af96c1e3STobin C. Harding	to a device structure
1064af96c1e3STobin C. Harding
1065ee5dc049STobin C. Harding``flush``
1066ee5dc049STobin C. Harding	called by the close(2) system call to flush a file
1067af96c1e3STobin C. Harding
1068ee5dc049STobin C. Harding``release``
1069ee5dc049STobin C. Harding	called when the last reference to an open file is closed
1070af96c1e3STobin C. Harding
1071ee5dc049STobin C. Harding``fsync``
1072ee5dc049STobin C. Harding	called by the fsync(2) system call.  Also see the section above
1073af96c1e3STobin C. Harding	entitled "Handling errors during writeback".
1074af96c1e3STobin C. Harding
1075ee5dc049STobin C. Harding``fasync``
1076ee5dc049STobin C. Harding	called by the fcntl(2) system call when asynchronous
1077af96c1e3STobin C. Harding	(non-blocking) mode is enabled for a file
1078af96c1e3STobin C. Harding
1079ee5dc049STobin C. Harding``lock``
1080ee5dc049STobin C. Harding	called by the fcntl(2) system call for F_GETLK, F_SETLK, and
1081ee5dc049STobin C. Harding	F_SETLKW commands
1082af96c1e3STobin C. Harding
1083ee5dc049STobin C. Harding``get_unmapped_area``
1084ee5dc049STobin C. Harding	called by the mmap(2) system call
1085af96c1e3STobin C. Harding
1086ee5dc049STobin C. Harding``check_flags``
1087ee5dc049STobin C. Harding	called by the fcntl(2) system call for F_SETFL command
1088af96c1e3STobin C. Harding
1089ee5dc049STobin C. Harding``flock``
1090ee5dc049STobin C. Harding	called by the flock(2) system call
1091af96c1e3STobin C. Harding
1092ee5dc049STobin C. Harding``splice_write``
1093ee5dc049STobin C. Harding	called by the VFS to splice data from a pipe to a file.  This
1094af96c1e3STobin C. Harding	method is used by the splice(2) system call
1095af96c1e3STobin C. Harding
1096ee5dc049STobin C. Harding``splice_read``
1097ee5dc049STobin C. Harding	called by the VFS to splice data from file to a pipe.  This
1098af96c1e3STobin C. Harding	method is used by the splice(2) system call
1099af96c1e3STobin C. Harding
1100ee5dc049STobin C. Harding``setlease``
1101ee5dc049STobin C. Harding	called by the VFS to set or release a file lock lease.  setlease
1102af96c1e3STobin C. Harding	implementations should call generic_setlease to record or remove
1103af96c1e3STobin C. Harding	the lease in the inode after setting it.
1104af96c1e3STobin C. Harding
1105ee5dc049STobin C. Harding``fallocate``
1106ee5dc049STobin C. Harding	called by the VFS to preallocate blocks or punch a hole.
1107af96c1e3STobin C. Harding
1108ee5dc049STobin C. Harding``copy_file_range``
1109ee5dc049STobin C. Harding	called by the copy_file_range(2) system call.
1110af96c1e3STobin C. Harding
1111ee5dc049STobin C. Harding``remap_file_range``
1112ee5dc049STobin C. Harding	called by the ioctl(2) system call for FICLONERANGE and FICLONE
1113ee5dc049STobin C. Harding	and FIDEDUPERANGE commands to remap file ranges.  An
1114ee5dc049STobin C. Harding	implementation should remap len bytes at pos_in of the source
1115ee5dc049STobin C. Harding	file into the dest file at pos_out.  Implementations must handle
1116ee5dc049STobin C. Harding	callers passing in len == 0; this means "remap to the end of the
1117ee5dc049STobin C. Harding	source file".  The return value should the number of bytes
1118ee5dc049STobin C. Harding	remapped, or the usual negative error code if errors occurred
1119ee5dc049STobin C. Harding	before any bytes were remapped.  The remap_flags parameter
1120ee5dc049STobin C. Harding	accepts REMAP_FILE_* flags.  If REMAP_FILE_DEDUP is set then the
1121ee5dc049STobin C. Harding	implementation must only remap if the requested file ranges have
1122cb56ecaeSJulia Lawall	identical contents.  If REMAP_FILE_CAN_SHORTEN is set, the caller is
1123ee5dc049STobin C. Harding	ok with the implementation shortening the request length to
1124ee5dc049STobin C. Harding	satisfy alignment or EOF requirements (or any other reason).
1125af96c1e3STobin C. Harding
1126ee5dc049STobin C. Harding``fadvise``
1127ee5dc049STobin C. Harding	possibly called by the fadvise64() system call.
1128af96c1e3STobin C. Harding
1129af96c1e3STobin C. HardingNote that the file operations are implemented by the specific
1130af96c1e3STobin C. Hardingfilesystem in which the inode resides.  When opening a device node
1131af96c1e3STobin C. Harding(character or block special) most filesystems will call special
1132af96c1e3STobin C. Hardingsupport routines in the VFS which will locate the required device
1133af96c1e3STobin C. Hardingdriver information.  These support routines replace the filesystem file
1134af96c1e3STobin C. Hardingoperations with those for the device driver, and then proceed to call
1135af96c1e3STobin C. Hardingthe new open() method for the file.  This is how opening a device file
1136af96c1e3STobin C. Hardingin the filesystem eventually ends up calling the device driver open()
1137af96c1e3STobin C. Hardingmethod.
1138af96c1e3STobin C. Harding
1139af96c1e3STobin C. Harding
1140af96c1e3STobin C. HardingDirectory Entry Cache (dcache)
1141af96c1e3STobin C. Harding==============================
1142af96c1e3STobin C. Harding
1143af96c1e3STobin C. Harding
1144af96c1e3STobin C. Hardingstruct dentry_operations
1145af96c1e3STobin C. Harding------------------------
1146af96c1e3STobin C. Harding
1147af96c1e3STobin C. HardingThis describes how a filesystem can overload the standard dentry
1148af96c1e3STobin C. Hardingoperations.  Dentries and the dcache are the domain of the VFS and the
1149af96c1e3STobin C. Hardingindividual filesystem implementations.  Device drivers have no business
1150af96c1e3STobin C. Hardinghere.  These methods may be set to NULL, as they are either optional or
1151af96c1e3STobin C. Hardingthe VFS uses a default.  As of kernel 2.6.22, the following members are
1152af96c1e3STobin C. Hardingdefined:
1153af96c1e3STobin C. Harding
1154af96c1e3STobin C. Harding.. code-block:: c
1155af96c1e3STobin C. Harding
1156af96c1e3STobin C. Harding	struct dentry_operations {
1157af96c1e3STobin C. Harding		int (*d_revalidate)(struct dentry *, unsigned int);
1158af96c1e3STobin C. Harding		int (*d_weak_revalidate)(struct dentry *, unsigned int);
1159af96c1e3STobin C. Harding		int (*d_hash)(const struct dentry *, struct qstr *);
1160af96c1e3STobin C. Harding		int (*d_compare)(const struct dentry *,
1161af96c1e3STobin C. Harding				 unsigned int, const char *, const struct qstr *);
1162af96c1e3STobin C. Harding		int (*d_delete)(const struct dentry *);
1163af96c1e3STobin C. Harding		int (*d_init)(struct dentry *);
1164af96c1e3STobin C. Harding		void (*d_release)(struct dentry *);
1165af96c1e3STobin C. Harding		void (*d_iput)(struct dentry *, struct inode *);
1166af96c1e3STobin C. Harding		char *(*d_dname)(struct dentry *, char *, int);
1167af96c1e3STobin C. Harding		struct vfsmount *(*d_automount)(struct path *);
1168af96c1e3STobin C. Harding		int (*d_manage)(const struct path *, bool);
1169af96c1e3STobin C. Harding		struct dentry *(*d_real)(struct dentry *, const struct inode *);
1170af96c1e3STobin C. Harding	};
1171af96c1e3STobin C. Harding
1172ee5dc049STobin C. Harding``d_revalidate``
1173ee5dc049STobin C. Harding	called when the VFS needs to revalidate a dentry.  This is
1174ee5dc049STobin C. Harding	called whenever a name look-up finds a dentry in the dcache.
1175ee5dc049STobin C. Harding	Most local filesystems leave this as NULL, because all their
1176ee5dc049STobin C. Harding	dentries in the dcache are valid.  Network filesystems are
1177ee5dc049STobin C. Harding	different since things can change on the server without the
1178ee5dc049STobin C. Harding	client necessarily being aware of it.
1179af96c1e3STobin C. Harding
1180ee5dc049STobin C. Harding	This function should return a positive value if the dentry is
1181ee5dc049STobin C. Harding	still valid, and zero or a negative error code if it isn't.
1182af96c1e3STobin C. Harding
1183ee5dc049STobin C. Harding	d_revalidate may be called in rcu-walk mode (flags &
1184ee5dc049STobin C. Harding	LOOKUP_RCU).  If in rcu-walk mode, the filesystem must
1185ee5dc049STobin C. Harding	revalidate the dentry without blocking or storing to the dentry,
1186ee5dc049STobin C. Harding	d_parent and d_inode should not be used without care (because
1187ee5dc049STobin C. Harding	they can change and, in d_inode case, even become NULL under
1188ee5dc049STobin C. Harding	us).
1189af96c1e3STobin C. Harding
1190ee5dc049STobin C. Harding	If a situation is encountered that rcu-walk cannot handle,
1191ee5dc049STobin C. Harding	return
1192af96c1e3STobin C. Harding	-ECHILD and it will be called again in ref-walk mode.
1193af96c1e3STobin C. Harding
1194ee5dc049STobin C. Harding``_weak_revalidate``
1195ee5dc049STobin C. Harding	called when the VFS needs to revalidate a "jumped" dentry.  This
1196ee5dc049STobin C. Harding	is called when a path-walk ends at dentry that was not acquired
1197ee5dc049STobin C. Harding	by doing a lookup in the parent directory.  This includes "/",
1198ee5dc049STobin C. Harding	"." and "..", as well as procfs-style symlinks and mountpoint
1199ee5dc049STobin C. Harding	traversal.
1200af96c1e3STobin C. Harding
1201ee5dc049STobin C. Harding	In this case, we are less concerned with whether the dentry is
1202ee5dc049STobin C. Harding	still fully correct, but rather that the inode is still valid.
1203ee5dc049STobin C. Harding	As with d_revalidate, most local filesystems will set this to
1204ee5dc049STobin C. Harding	NULL since their dcache entries are always valid.
1205af96c1e3STobin C. Harding
1206ee5dc049STobin C. Harding	This function has the same return code semantics as
1207ee5dc049STobin C. Harding	d_revalidate.
1208af96c1e3STobin C. Harding
1209af96c1e3STobin C. Harding	d_weak_revalidate is only called after leaving rcu-walk mode.
1210af96c1e3STobin C. Harding
1211ee5dc049STobin C. Harding``d_hash``
1212ee5dc049STobin C. Harding	called when the VFS adds a dentry to the hash table.  The first
1213af96c1e3STobin C. Harding	dentry passed to d_hash is the parent directory that the name is
1214af96c1e3STobin C. Harding	to be hashed into.
1215af96c1e3STobin C. Harding
1216af96c1e3STobin C. Harding	Same locking and synchronisation rules as d_compare regarding
1217af96c1e3STobin C. Harding	what is safe to dereference etc.
1218af96c1e3STobin C. Harding
1219ee5dc049STobin C. Harding``d_compare``
1220ee5dc049STobin C. Harding	called to compare a dentry name with a given name.  The first
1221af96c1e3STobin C. Harding	dentry is the parent of the dentry to be compared, the second is
1222ee5dc049STobin C. Harding	the child dentry.  len and name string are properties of the
1223ee5dc049STobin C. Harding	dentry to be compared.  qstr is the name to compare it with.
1224af96c1e3STobin C. Harding
1225af96c1e3STobin C. Harding	Must be constant and idempotent, and should not take locks if
1226ee5dc049STobin C. Harding	possible, and should not or store into the dentry.  Should not
1227ee5dc049STobin C. Harding	dereference pointers outside the dentry without lots of care
1228ee5dc049STobin C. Harding	(eg.  d_parent, d_inode, d_name should not be used).
1229af96c1e3STobin C. Harding
1230ee5dc049STobin C. Harding	However, our vfsmount is pinned, and RCU held, so the dentries
1231ee5dc049STobin C. Harding	and inodes won't disappear, neither will our sb or filesystem
1232ee5dc049STobin C. Harding	module.  ->d_sb may be used.
1233af96c1e3STobin C. Harding
1234ee5dc049STobin C. Harding	It is a tricky calling convention because it needs to be called
1235ee5dc049STobin C. Harding	under "rcu-walk", ie. without any locks or references on things.
1236af96c1e3STobin C. Harding
1237ee5dc049STobin C. Harding``d_delete``
1238ee5dc049STobin C. Harding	called when the last reference to a dentry is dropped and the
1239ee5dc049STobin C. Harding	dcache is deciding whether or not to cache it.  Return 1 to
1240ee5dc049STobin C. Harding	delete immediately, or 0 to cache the dentry.  Default is NULL
1241ee5dc049STobin C. Harding	which means to always cache a reachable dentry.  d_delete must
1242ee5dc049STobin C. Harding	be constant and idempotent.
1243af96c1e3STobin C. Harding
1244ee5dc049STobin C. Harding``d_init``
1245ee5dc049STobin C. Harding	called when a dentry is allocated
1246af96c1e3STobin C. Harding
1247ee5dc049STobin C. Harding``d_release``
1248ee5dc049STobin C. Harding	called when a dentry is really deallocated
1249af96c1e3STobin C. Harding
1250ee5dc049STobin C. Harding``d_iput``
1251ee5dc049STobin C. Harding	called when a dentry loses its inode (just prior to its being
1252ee5dc049STobin C. Harding	deallocated).  The default when this is NULL is that the VFS
1253ee5dc049STobin C. Harding	calls iput().  If you define this method, you must call iput()
1254ee5dc049STobin C. Harding	yourself
1255af96c1e3STobin C. Harding
1256ee5dc049STobin C. Harding``d_dname``
1257ee5dc049STobin C. Harding	called when the pathname of a dentry should be generated.
1258ee5dc049STobin C. Harding	Useful for some pseudo filesystems (sockfs, pipefs, ...) to
1259ee5dc049STobin C. Harding	delay pathname generation.  (Instead of doing it when dentry is
1260ee5dc049STobin C. Harding	created, it's done only when the path is needed.).  Real
1261ee5dc049STobin C. Harding	filesystems probably dont want to use it, because their dentries
1262ee5dc049STobin C. Harding	are present in global dcache hash, so their hash should be an
1263ee5dc049STobin C. Harding	invariant.  As no lock is held, d_dname() should not try to
1264ee5dc049STobin C. Harding	modify the dentry itself, unless appropriate SMP safety is used.
1265ee5dc049STobin C. Harding	CAUTION : d_path() logic is quite tricky.  The correct way to
1266ee5dc049STobin C. Harding	return for example "Hello" is to put it at the end of the
1267ee5dc049STobin C. Harding	buffer, and returns a pointer to the first char.
1268ee5dc049STobin C. Harding	dynamic_dname() helper function is provided to take care of
1269ee5dc049STobin C. Harding	this.
1270af96c1e3STobin C. Harding
1271af96c1e3STobin C. Harding	Example :
1272af96c1e3STobin C. Harding
1273af96c1e3STobin C. Harding.. code-block:: c
1274af96c1e3STobin C. Harding
1275af96c1e3STobin C. Harding	static char *pipefs_dname(struct dentry *dent, char *buffer, int buflen)
1276af96c1e3STobin C. Harding	{
1277af96c1e3STobin C. Harding		return dynamic_dname(dentry, buffer, buflen, "pipe:[%lu]",
1278af96c1e3STobin C. Harding				dentry->d_inode->i_ino);
1279af96c1e3STobin C. Harding	}
1280af96c1e3STobin C. Harding
1281ee5dc049STobin C. Harding``d_automount``
1282ee5dc049STobin C. Harding	called when an automount dentry is to be traversed (optional).
1283ee5dc049STobin C. Harding	This should create a new VFS mount record and return the record
1284ee5dc049STobin C. Harding	to the caller.  The caller is supplied with a path parameter
1285ee5dc049STobin C. Harding	giving the automount directory to describe the automount target
1286ee5dc049STobin C. Harding	and the parent VFS mount record to provide inheritable mount
1287ee5dc049STobin C. Harding	parameters.  NULL should be returned if someone else managed to
1288ee5dc049STobin C. Harding	make the automount first.  If the vfsmount creation failed, then
1289ee5dc049STobin C. Harding	an error code should be returned.  If -EISDIR is returned, then
1290ee5dc049STobin C. Harding	the directory will be treated as an ordinary directory and
1291ee5dc049STobin C. Harding	returned to pathwalk to continue walking.
1292af96c1e3STobin C. Harding
1293ee5dc049STobin C. Harding	If a vfsmount is returned, the caller will attempt to mount it
1294ee5dc049STobin C. Harding	on the mountpoint and will remove the vfsmount from its
1295ee5dc049STobin C. Harding	expiration list in the case of failure.  The vfsmount should be
1296ee5dc049STobin C. Harding	returned with 2 refs on it to prevent automatic expiration - the
1297ee5dc049STobin C. Harding	caller will clean up the additional ref.
1298af96c1e3STobin C. Harding
1299ee5dc049STobin C. Harding	This function is only used if DCACHE_NEED_AUTOMOUNT is set on
1300ee5dc049STobin C. Harding	the dentry.  This is set by __d_instantiate() if S_AUTOMOUNT is
1301ee5dc049STobin C. Harding	set on the inode being added.
1302af96c1e3STobin C. Harding
1303ee5dc049STobin C. Harding``d_manage``
1304ee5dc049STobin C. Harding	called to allow the filesystem to manage the transition from a
1305ee5dc049STobin C. Harding	dentry (optional).  This allows autofs, for example, to hold up
1306ee5dc049STobin C. Harding	clients waiting to explore behind a 'mountpoint' while letting
1307ee5dc049STobin C. Harding	the daemon go past and construct the subtree there.  0 should be
1308ee5dc049STobin C. Harding	returned to let the calling process continue.  -EISDIR can be
1309ee5dc049STobin C. Harding	returned to tell pathwalk to use this directory as an ordinary
1310ee5dc049STobin C. Harding	directory and to ignore anything mounted on it and not to check
1311ee5dc049STobin C. Harding	the automount flag.  Any other error code will abort pathwalk
1312ee5dc049STobin C. Harding	completely.
1313af96c1e3STobin C. Harding
1314af96c1e3STobin C. Harding	If the 'rcu_walk' parameter is true, then the caller is doing a
1315ee5dc049STobin C. Harding	pathwalk in RCU-walk mode.  Sleeping is not permitted in this
1316ee5dc049STobin C. Harding	mode, and the caller can be asked to leave it and call again by
1317ee5dc049STobin C. Harding	returning -ECHILD.  -EISDIR may also be returned to tell
1318ee5dc049STobin C. Harding	pathwalk to ignore d_automount or any mounts.
1319af96c1e3STobin C. Harding
1320ee5dc049STobin C. Harding	This function is only used if DCACHE_MANAGE_TRANSIT is set on
1321ee5dc049STobin C. Harding	the dentry being transited from.
1322af96c1e3STobin C. Harding
1323ee5dc049STobin C. Harding``d_real``
1324ee5dc049STobin C. Harding	overlay/union type filesystems implement this method to return
1325ee5dc049STobin C. Harding	one of the underlying dentries hidden by the overlay.  It is
1326ee5dc049STobin C. Harding	used in two different modes:
1327af96c1e3STobin C. Harding
1328ee5dc049STobin C. Harding	Called from file_dentry() it returns the real dentry matching
1329ee5dc049STobin C. Harding	the inode argument.  The real dentry may be from a lower layer
1330ee5dc049STobin C. Harding	already copied up, but still referenced from the file.  This
1331ee5dc049STobin C. Harding	mode is selected with a non-NULL inode argument.
1332af96c1e3STobin C. Harding
1333af96c1e3STobin C. Harding	With NULL inode the topmost real underlying dentry is returned.
1334af96c1e3STobin C. Harding
1335af96c1e3STobin C. HardingEach dentry has a pointer to its parent dentry, as well as a hash list
1336af96c1e3STobin C. Hardingof child dentries.  Child dentries are basically like files in a
1337af96c1e3STobin C. Hardingdirectory.
1338af96c1e3STobin C. Harding
1339af96c1e3STobin C. Harding
1340af96c1e3STobin C. HardingDirectory Entry Cache API
1341af96c1e3STobin C. Harding--------------------------
1342af96c1e3STobin C. Harding
1343af96c1e3STobin C. HardingThere are a number of functions defined which permit a filesystem to
1344af96c1e3STobin C. Hardingmanipulate dentries:
1345af96c1e3STobin C. Harding
1346ee5dc049STobin C. Harding``dget``
1347ee5dc049STobin C. Harding	open a new handle for an existing dentry (this just increments
1348af96c1e3STobin C. Harding	the usage count)
1349af96c1e3STobin C. Harding
1350ee5dc049STobin C. Harding``dput``
1351ee5dc049STobin C. Harding	close a handle for a dentry (decrements the usage count).  If
1352af96c1e3STobin C. Harding	the usage count drops to 0, and the dentry is still in its
1353af96c1e3STobin C. Harding	parent's hash, the "d_delete" method is called to check whether
1354ee5dc049STobin C. Harding	it should be cached.  If it should not be cached, or if the
1355ee5dc049STobin C. Harding	dentry is not hashed, it is deleted.  Otherwise cached dentries
1356ee5dc049STobin C. Harding	are put into an LRU list to be reclaimed on memory shortage.
1357af96c1e3STobin C. Harding
1358ee5dc049STobin C. Harding``d_drop``
1359ee5dc049STobin C. Harding	this unhashes a dentry from its parents hash list.  A subsequent
1360ee5dc049STobin C. Harding	call to dput() will deallocate the dentry if its usage count
1361ee5dc049STobin C. Harding	drops to 0
1362af96c1e3STobin C. Harding
1363ee5dc049STobin C. Harding``d_delete``
1364ee5dc049STobin C. Harding	delete a dentry.  If there are no other open references to the
1365ee5dc049STobin C. Harding	dentry then the dentry is turned into a negative dentry (the
1366ee5dc049STobin C. Harding	d_iput() method is called).  If there are other references, then
1367ee5dc049STobin C. Harding	d_drop() is called instead
1368af96c1e3STobin C. Harding
1369ee5dc049STobin C. Harding``d_add``
1370ee5dc049STobin C. Harding	add a dentry to its parents hash list and then calls
1371af96c1e3STobin C. Harding	d_instantiate()
1372af96c1e3STobin C. Harding
1373ee5dc049STobin C. Harding``d_instantiate``
1374ee5dc049STobin C. Harding	add a dentry to the alias hash list for the inode and updates
1375ee5dc049STobin C. Harding	the "d_inode" member.  The "i_count" member in the inode
1376ee5dc049STobin C. Harding	structure should be set/incremented.  If the inode pointer is
1377ee5dc049STobin C. Harding	NULL, the dentry is called a "negative dentry".  This function
1378ee5dc049STobin C. Harding	is commonly called when an inode is created for an existing
1379ee5dc049STobin C. Harding	negative dentry
1380af96c1e3STobin C. Harding
1381ee5dc049STobin C. Harding``d_lookup``
1382ee5dc049STobin C. Harding	look up a dentry given its parent and path name component It
1383ee5dc049STobin C. Harding	looks up the child of that given name from the dcache hash
1384ee5dc049STobin C. Harding	table.  If it is found, the reference count is incremented and
1385ee5dc049STobin C. Harding	the dentry is returned.  The caller must use dput() to free the
1386ee5dc049STobin C. Harding	dentry when it finishes using it.
1387af96c1e3STobin C. Harding
1388af96c1e3STobin C. Harding
1389af96c1e3STobin C. HardingMount Options
1390af96c1e3STobin C. Harding=============
1391af96c1e3STobin C. Harding
1392af96c1e3STobin C. Harding
1393af96c1e3STobin C. HardingParsing options
1394af96c1e3STobin C. Harding---------------
1395af96c1e3STobin C. Harding
1396af96c1e3STobin C. HardingOn mount and remount the filesystem is passed a string containing a
1397af96c1e3STobin C. Hardingcomma separated list of mount options.  The options can have either of
1398af96c1e3STobin C. Hardingthese forms:
1399af96c1e3STobin C. Harding
1400af96c1e3STobin C. Harding  option
1401af96c1e3STobin C. Harding  option=value
1402af96c1e3STobin C. Harding
1403af96c1e3STobin C. HardingThe <linux/parser.h> header defines an API that helps parse these
1404af96c1e3STobin C. Hardingoptions.  There are plenty of examples on how to use it in existing
1405af96c1e3STobin C. Hardingfilesystems.
1406af96c1e3STobin C. Harding
1407af96c1e3STobin C. Harding
1408af96c1e3STobin C. HardingShowing options
1409af96c1e3STobin C. Harding---------------
1410af96c1e3STobin C. Harding
1411af96c1e3STobin C. HardingIf a filesystem accepts mount options, it must define show_options() to
1412af96c1e3STobin C. Hardingshow all the currently active options.  The rules are:
1413af96c1e3STobin C. Harding
1414af96c1e3STobin C. Harding  - options MUST be shown which are not default or their values differ
1415af96c1e3STobin C. Harding    from the default
1416af96c1e3STobin C. Harding
1417af96c1e3STobin C. Harding  - options MAY be shown which are enabled by default or have their
1418af96c1e3STobin C. Harding    default value
1419af96c1e3STobin C. Harding
1420af96c1e3STobin C. HardingOptions used only internally between a mount helper and the kernel (such
1421af96c1e3STobin C. Hardingas file descriptors), or which only have an effect during the mounting
1422af96c1e3STobin C. Harding(such as ones controlling the creation of a journal) are exempt from the
1423af96c1e3STobin C. Hardingabove rules.
1424af96c1e3STobin C. Harding
1425af96c1e3STobin C. HardingThe underlying reason for the above rules is to make sure, that a mount
1426af96c1e3STobin C. Hardingcan be accurately replicated (e.g. umounting and mounting again) based
1427af96c1e3STobin C. Hardingon the information found in /proc/mounts.
1428af96c1e3STobin C. Harding
1429af96c1e3STobin C. Harding
1430af96c1e3STobin C. HardingResources
1431af96c1e3STobin C. Harding=========
1432af96c1e3STobin C. Harding
1433af96c1e3STobin C. Harding(Note some of these resources are not up-to-date with the latest kernel
1434af96c1e3STobin C. Harding version.)
1435af96c1e3STobin C. Harding
1436af96c1e3STobin C. HardingCreating Linux virtual filesystems. 2002
1437c69f22f2SAlexander A. Klimov    <https://lwn.net/Articles/13325/>
1438af96c1e3STobin C. Harding
1439af96c1e3STobin C. HardingThe Linux Virtual File-system Layer by Neil Brown. 1999
1440af96c1e3STobin C. Harding    <http://www.cse.unsw.edu.au/~neilb/oss/linux-commentary/vfs.html>
1441af96c1e3STobin C. Harding
1442af96c1e3STobin C. HardingA tour of the Linux VFS by Michael K. Johnson. 1996
1443c69f22f2SAlexander A. Klimov    <https://www.tldp.org/LDP/khg/HyperNews/get/fs/vfstour.html>
1444af96c1e3STobin C. Harding
1445af96c1e3STobin C. HardingA small trail through the Linux kernel by Andries Brouwer. 2001
1446c69f22f2SAlexander A. Klimov    <https://www.win.tue.nl/~aeb/linux/vfs/trail.html>
1447