Skip to content

Latest commit

 

History

History
187 lines (160 loc) · 6.2 KB

File metadata and controls

187 lines (160 loc) · 6.2 KB

ext4-fs

0.1 What are file systems:

  • A file system is a logical means for an operating system to store and retrieve data on the computer’s storage.
  • A file system implements a basic operations such as create, delete, read, write operations

0.2 VFS

0.2.1 Kernel’s relation to file systems: VFS

  • The task of organizing the millions of files is insulated from the kernel by the file system. VFS provides basic hooks into which each file can attach itself to provide the creation and management functions by creating appropriate intermediate control structures.

0.3 Common FileSystem Interface

  • This abstraction allows for a common interface for userspace to interact with kernel via system calls for all file related operations. This very mechanism also allows for abstracting the underlying details such as storage device, location, size etc.

0.4 Filesystem Abstraction Layer

0.5 Important data structures in VFS

0.5.1 The Superblock Object:

  • It is used to store information describing the specific filesystem. It is stored in a special sector on the disk. Super block object is represented by
struct super_block

defined in <linux/fs.h>

/* Definition of struct super_block */
struct super_block {
	struct list_head	s_list;		/* Keep this first */
	dev_t			s_dev;		/* search index; _not_ kdev_t */
	unsigned char		s_blocksize_bits;
	unsigned long		s_blocksize;
	loff_t			s_maxbytes;	/* Max file size */
	struct file_system_type	*s_type;
	const struct super_operations	*s_op;
	const struct dquot_operations	*dq_op;
	const struct quotactl_ops	*s_qcop;
	const struct export_operations *s_export_op;
	unsigned long		s_flags;
	unsigned long		s_iflags;	/* internal SB_I_* flags */
	unsigned long		s_magic;
	struct dentry		*s_root;
	struct rw_semaphore	s_umount;
	int			s_count;
	atomic_t		s_active;
#ifdef CONFIG_SECURITY
	void                    *s_security;
#endif
	const struct xattr_handler **s_xattr;

	const struct fscrypt_operations	*s_cop;

	struct hlist_bl_head	s_anon;		/* anonymous dentries for (nfs) exporting */
	struct list_head	s_mounts;	/* list of mounts; _not_ for fs use */
	struct block_device	*s_bdev;
	struct backing_dev_info *s_bdi;
	struct mtd_info		*s_mtd;
	struct hlist_node	s_instances;
	unsigned int		s_quota_types;	/* Bitmask of supported quota types */
	struct quota_info	s_dquot;	/* Diskquota specific options */

	struct sb_writers	s_writers;

	char s_id[32];				/* Informational name */
	u8 s_uuid[16];				/* UUID */

	void 			*s_fs_info;	/* Filesystem private info */
	unsigned int		s_max_links;
	fmode_t			s_mode;

	/* Granularity of c/m/atime in ns.
	   Cannot be worse than a second */
	u32		   s_time_gran;

	/*
	 * The next field is for VFS *only*. No filesystems have any business
	 * even looking at it. You had been warned.
	 */
	struct mutex s_vfs_rename_mutex;	/* Kludge */

	/*
	 * Filesystem subtype.  If non-empty the filesystem type field
	 * in /proc/mounts will be "type.subtype"
	 */
	char *s_subtype;

	/*
	 * Saved mount options for lazy filesystems using
	 * generic_show_options()
	 */
	char __rcu *s_options;
	const struct dentry_operations *s_d_op; /* default d_op for dentries */

	/*
	 * Saved pool identifier for cleancache (-1 means none)
	 */
	int cleancache_poolid;

	struct shrinker s_shrink;	/* per-sb shrinker handle */

	/* Number of inodes with nlink == 0 but still referenced */
	atomic_long_t s_remove_count;

	/* Being remounted read-only */
	int s_readonly_remount;

	/* AIO completions deferred from interrupt context */
	struct workqueue_struct *s_dio_done_wq;
	struct hlist_head s_pins;

	/*
	 * Keep the lru lists last in the structure so they always sit on their
	 * own individual cachelines.
	 */
	struct list_lru		s_dentry_lru ____cacheline_aligned_in_smp;
	struct list_lru		s_inode_lru ____cacheline_aligned_in_smp;
	struct rcu_head		rcu;
	struct work_struct	destroy_work;

	struct mutex		s_sync_lock;	/* sync serialisation lock */

	/*
	 * Indicates how deep in a filesystem stack this SB is
	 */
	int s_stack_depth;

	/* s_inode_list_lock protects s_inodes */
	spinlock_t		s_inode_list_lock ____cacheline_aligned_in_smp;
	struct list_head	s_inodes;	/* all inodes */
};
  • The most important member in the super block structure is:
	const struct super_operations	*s_op;

which is a pointer to a table of operations that are supported on the super block.

0.5.2 Inode object:

  • The Inode object contains all the information needed by the kernel to manipulate a file or directory. For most filesystems, this is simply reading or writing from the on-disk inode structures.

0.5.3 dentry object

0.5.4 file object

0.5.5 data structures associated with file systems

0.5.6 data structures associated with processes

1 Objects in a File System:

1.1 Buffers:

1.2 Caches:

1.3 Memory Garbage Collection:

1.4 The Buffer Cache:

1.5 Extents

1.6 Extent trees

1.7 bitmap

1.8 fiemap and fibmap

1.9 System calls made during this run:

strace of hdparm for obtaining the fibmap of a file threw up the following system calls made in the process.

1.9.1 open(“/sys/block/mmcblk0/mmcblk0p2/start”, O_RDONLY) = 5

1.9.2 ioctl(3, FIGETBSZ, 0x7eb6a4a8) = 0

1.9.2.1 This only fetches the block size for the system which is mostly static at 4096 (TBD??)

1.9.2.2 Do we have an ioctl to fetch this if this is not static (see procfs)

1.9.3 ioctl(3, FS_IOC_FIEMAP, 0x7eafce28) = 0

1.9.3.1 There were two calls made, why?

1.9.4 ioctl(3, FS_IOC_FIEMAP, 0x7eafce28) = 0

2 bdflush

3 kswapd

{{{more}}}