Linux Audio

Check our new training course

Loading...
v6.2
  1/* SPDX-License-Identifier: GPL-2.0 */
  2/*
  3 * Copyright (C) 1992, 1993, 1994, 1995
  4 * Remy Card (card@masi.ibp.fr)
  5 * Laboratoire MASI - Institut Blaise Pascal
  6 * Universite Pierre et Marie Curie (Paris VI)
  7 *
  8 *  from
  9 *
 10 *  linux/include/linux/minix_fs.h
 11 *
 12 *  Copyright (C) 1991, 1992  Linus Torvalds
 13 */
 14#include <linux/fs.h>
 15#include <linux/ext2_fs.h>
 16#include <linux/blockgroup_lock.h>
 17#include <linux/percpu_counter.h>
 18#include <linux/rbtree.h>
 19#include <linux/mm.h>
 20#include <linux/highmem.h>
 21
 22/* XXX Here for now... not interested in restructing headers JUST now */
 23
 24/* data type for block offset of block group */
 25typedef int ext2_grpblk_t;
 26
 27/* data type for filesystem-wide blocks number */
 28typedef unsigned long ext2_fsblk_t;
 29
 30#define E2FSBLK "%lu"
 31
 32struct ext2_reserve_window {
 33	ext2_fsblk_t		_rsv_start;	/* First byte reserved */
 34	ext2_fsblk_t		_rsv_end;	/* Last byte reserved or 0 */
 35};
 36
 37struct ext2_reserve_window_node {
 38	struct rb_node	 	rsv_node;
 39	__u32			rsv_goal_size;
 40	__u32			rsv_alloc_hit;
 41	struct ext2_reserve_window	rsv_window;
 42};
 43
 44struct ext2_block_alloc_info {
 45	/* information about reservation window */
 46	struct ext2_reserve_window_node	rsv_window_node;
 47	/*
 48	 * was i_next_alloc_block in ext2_inode_info
 49	 * is the logical (file-relative) number of the
 50	 * most-recently-allocated block in this file.
 51	 * We use this for detecting linearly ascending allocation requests.
 52	 */
 53	__u32			last_alloc_logical_block;
 54	/*
 55	 * Was i_next_alloc_goal in ext2_inode_info
 56	 * is the *physical* companion to i_next_alloc_block.
 57	 * it is the physical block number of the block which was most-recently
 58	 * allocated to this file.  This gives us the goal (target) for the next
 59	 * allocation when we detect linearly ascending requests.
 60	 */
 61	ext2_fsblk_t		last_alloc_physical_block;
 62};
 63
 64#define rsv_start rsv_window._rsv_start
 65#define rsv_end rsv_window._rsv_end
 66
 67struct mb_cache;
 68
 69/*
 70 * second extended-fs super-block data in memory
 71 */
 72struct ext2_sb_info {
 73	unsigned long s_frag_size;	/* Size of a fragment in bytes */
 74	unsigned long s_frags_per_block;/* Number of fragments per block */
 75	unsigned long s_inodes_per_block;/* Number of inodes per block */
 76	unsigned long s_frags_per_group;/* Number of fragments in a group */
 77	unsigned long s_blocks_per_group;/* Number of blocks in a group */
 78	unsigned long s_inodes_per_group;/* Number of inodes in a group */
 79	unsigned long s_itb_per_group;	/* Number of inode table blocks per group */
 80	unsigned long s_gdb_count;	/* Number of group descriptor blocks */
 81	unsigned long s_desc_per_block;	/* Number of group descriptors per block */
 82	unsigned long s_groups_count;	/* Number of groups in the fs */
 83	unsigned long s_overhead_last;  /* Last calculated overhead */
 84	unsigned long s_blocks_last;    /* Last seen block count */
 85	struct buffer_head * s_sbh;	/* Buffer containing the super block */
 86	struct ext2_super_block * s_es;	/* Pointer to the super block in the buffer */
 87	struct buffer_head ** s_group_desc;
 88	unsigned long  s_mount_opt;
 89	unsigned long s_sb_block;
 90	kuid_t s_resuid;
 91	kgid_t s_resgid;
 92	unsigned short s_mount_state;
 93	unsigned short s_pad;
 94	int s_addr_per_block_bits;
 95	int s_desc_per_block_bits;
 96	int s_inode_size;
 97	int s_first_ino;
 98	spinlock_t s_next_gen_lock;
 99	u32 s_next_generation;
100	unsigned long s_dir_count;
101	u8 *s_debts;
102	struct percpu_counter s_freeblocks_counter;
103	struct percpu_counter s_freeinodes_counter;
104	struct percpu_counter s_dirs_counter;
105	struct blockgroup_lock *s_blockgroup_lock;
106	/* root of the per fs reservation window tree */
107	spinlock_t s_rsv_window_lock;
108	struct rb_root s_rsv_window_root;
109	struct ext2_reserve_window_node s_rsv_window_head;
110	/*
111	 * s_lock protects against concurrent modifications of s_mount_state,
112	 * s_blocks_last, s_overhead_last and the content of superblock's
113	 * buffer pointed to by sbi->s_es.
114	 *
115	 * Note: It is used in ext2_show_options() to provide a consistent view
116	 * of the mount options.
117	 */
118	spinlock_t s_lock;
119	struct mb_cache *s_ea_block_cache;
120	struct dax_device *s_daxdev;
121	u64 s_dax_part_off;
122};
123
124static inline spinlock_t *
125sb_bgl_lock(struct ext2_sb_info *sbi, unsigned int block_group)
126{
127	return bgl_lock_ptr(sbi->s_blockgroup_lock, block_group);
128}
129
130/*
131 * Define EXT2FS_DEBUG to produce debug messages
132 */
133#undef EXT2FS_DEBUG
134
135/*
136 * Define EXT2_RESERVATION to reserve data blocks for expanding files
137 */
138#define EXT2_DEFAULT_RESERVE_BLOCKS     8
139/*max window size: 1024(direct blocks) + 3([t,d]indirect blocks) */
140#define EXT2_MAX_RESERVE_BLOCKS         1027
141#define EXT2_RESERVE_WINDOW_NOT_ALLOCATED 0
142/*
143 * The second extended file system version
144 */
145#define EXT2FS_DATE		"95/08/09"
146#define EXT2FS_VERSION		"0.5b"
147
148/*
149 * Debug code
150 */
151#ifdef EXT2FS_DEBUG
152#	define ext2_debug(f, a...)	{ \
153					printk ("EXT2-fs DEBUG (%s, %d): %s:", \
154						__FILE__, __LINE__, __func__); \
155				  	printk (f, ## a); \
156					}
157#else
158#	define ext2_debug(f, a...)	/**/
159#endif
160
161/*
162 * Special inode numbers
163 */
164#define	EXT2_BAD_INO		 1	/* Bad blocks inode */
165#define EXT2_ROOT_INO		 2	/* Root inode */
166#define EXT2_BOOT_LOADER_INO	 5	/* Boot loader inode */
167#define EXT2_UNDEL_DIR_INO	 6	/* Undelete directory inode */
168
169/* First non-reserved inode for old ext2 filesystems */
170#define EXT2_GOOD_OLD_FIRST_INO	11
171
172static inline struct ext2_sb_info *EXT2_SB(struct super_block *sb)
173{
174	return sb->s_fs_info;
175}
176
177/*
178 * Macro-instructions used to manage several block sizes
179 */
180#define EXT2_MIN_BLOCK_SIZE		1024
181#define	EXT2_MAX_BLOCK_SIZE		4096
182#define EXT2_MIN_BLOCK_LOG_SIZE		  10
 
183#define EXT2_BLOCK_SIZE(s)		((s)->s_blocksize)
184#define	EXT2_ADDR_PER_BLOCK(s)		(EXT2_BLOCK_SIZE(s) / sizeof (__u32))
185#define EXT2_BLOCK_SIZE_BITS(s)		((s)->s_blocksize_bits)
186#define	EXT2_ADDR_PER_BLOCK_BITS(s)	(EXT2_SB(s)->s_addr_per_block_bits)
187#define EXT2_INODE_SIZE(s)		(EXT2_SB(s)->s_inode_size)
188#define EXT2_FIRST_INO(s)		(EXT2_SB(s)->s_first_ino)
189
190/*
191 * Macro-instructions used to manage fragments
192 */
193#define EXT2_MIN_FRAG_SIZE		1024
194#define	EXT2_MAX_FRAG_SIZE		4096
195#define EXT2_MIN_FRAG_LOG_SIZE		  10
196#define EXT2_FRAG_SIZE(s)		(EXT2_SB(s)->s_frag_size)
197#define EXT2_FRAGS_PER_BLOCK(s)		(EXT2_SB(s)->s_frags_per_block)
198
199/*
200 * Structure of a blocks group descriptor
201 */
202struct ext2_group_desc
203{
204	__le32	bg_block_bitmap;		/* Blocks bitmap block */
205	__le32	bg_inode_bitmap;		/* Inodes bitmap block */
206	__le32	bg_inode_table;		/* Inodes table block */
207	__le16	bg_free_blocks_count;	/* Free blocks count */
208	__le16	bg_free_inodes_count;	/* Free inodes count */
209	__le16	bg_used_dirs_count;	/* Directories count */
210	__le16	bg_pad;
211	__le32	bg_reserved[3];
212};
213
214/*
215 * Macro-instructions used to manage group descriptors
216 */
217#define EXT2_BLOCKS_PER_GROUP(s)	(EXT2_SB(s)->s_blocks_per_group)
218#define EXT2_DESC_PER_BLOCK(s)		(EXT2_SB(s)->s_desc_per_block)
219#define EXT2_INODES_PER_GROUP(s)	(EXT2_SB(s)->s_inodes_per_group)
220#define EXT2_DESC_PER_BLOCK_BITS(s)	(EXT2_SB(s)->s_desc_per_block_bits)
221
222/*
223 * Constants relative to the data blocks
224 */
225#define	EXT2_NDIR_BLOCKS		12
226#define	EXT2_IND_BLOCK			EXT2_NDIR_BLOCKS
227#define	EXT2_DIND_BLOCK			(EXT2_IND_BLOCK + 1)
228#define	EXT2_TIND_BLOCK			(EXT2_DIND_BLOCK + 1)
229#define	EXT2_N_BLOCKS			(EXT2_TIND_BLOCK + 1)
230
231/*
232 * Inode flags (GETFLAGS/SETFLAGS)
233 */
234#define	EXT2_SECRM_FL			FS_SECRM_FL	/* Secure deletion */
235#define	EXT2_UNRM_FL			FS_UNRM_FL	/* Undelete */
236#define	EXT2_COMPR_FL			FS_COMPR_FL	/* Compress file */
237#define EXT2_SYNC_FL			FS_SYNC_FL	/* Synchronous updates */
238#define EXT2_IMMUTABLE_FL		FS_IMMUTABLE_FL	/* Immutable file */
239#define EXT2_APPEND_FL			FS_APPEND_FL	/* writes to file may only append */
240#define EXT2_NODUMP_FL			FS_NODUMP_FL	/* do not dump file */
241#define EXT2_NOATIME_FL			FS_NOATIME_FL	/* do not update atime */
242/* Reserved for compression usage... */
243#define EXT2_DIRTY_FL			FS_DIRTY_FL
244#define EXT2_COMPRBLK_FL		FS_COMPRBLK_FL	/* One or more compressed clusters */
245#define EXT2_NOCOMP_FL			FS_NOCOMP_FL	/* Don't compress */
246#define EXT2_ECOMPR_FL			FS_ECOMPR_FL	/* Compression error */
247/* End compression flags --- maybe not all used */	
248#define EXT2_BTREE_FL			FS_BTREE_FL	/* btree format dir */
249#define EXT2_INDEX_FL			FS_INDEX_FL	/* hash-indexed directory */
250#define EXT2_IMAGIC_FL			FS_IMAGIC_FL	/* AFS directory */
251#define EXT2_JOURNAL_DATA_FL		FS_JOURNAL_DATA_FL /* Reserved for ext3 */
252#define EXT2_NOTAIL_FL			FS_NOTAIL_FL	/* file tail should not be merged */
253#define EXT2_DIRSYNC_FL			FS_DIRSYNC_FL	/* dirsync behaviour (directories only) */
254#define EXT2_TOPDIR_FL			FS_TOPDIR_FL	/* Top of directory hierarchies*/
255#define EXT2_RESERVED_FL		FS_RESERVED_FL	/* reserved for ext2 lib */
256
257#define EXT2_FL_USER_VISIBLE		FS_FL_USER_VISIBLE	/* User visible flags */
258#define EXT2_FL_USER_MODIFIABLE		FS_FL_USER_MODIFIABLE	/* User modifiable flags */
259
260/* Flags that should be inherited by new inodes from their parent. */
261#define EXT2_FL_INHERITED (EXT2_SECRM_FL | EXT2_UNRM_FL | EXT2_COMPR_FL |\
262			   EXT2_SYNC_FL | EXT2_NODUMP_FL |\
263			   EXT2_NOATIME_FL | EXT2_COMPRBLK_FL |\
264			   EXT2_NOCOMP_FL | EXT2_JOURNAL_DATA_FL |\
265			   EXT2_NOTAIL_FL | EXT2_DIRSYNC_FL)
266
267/* Flags that are appropriate for regular files (all but dir-specific ones). */
268#define EXT2_REG_FLMASK (~(EXT2_DIRSYNC_FL | EXT2_TOPDIR_FL))
269
270/* Flags that are appropriate for non-directories/regular files. */
271#define EXT2_OTHER_FLMASK (EXT2_NODUMP_FL | EXT2_NOATIME_FL)
272
273/* Mask out flags that are inappropriate for the given type of inode. */
274static inline __u32 ext2_mask_flags(umode_t mode, __u32 flags)
275{
276	if (S_ISDIR(mode))
277		return flags;
278	else if (S_ISREG(mode))
279		return flags & EXT2_REG_FLMASK;
280	else
281		return flags & EXT2_OTHER_FLMASK;
282}
283
284/*
285 * ioctl commands
286 */
287#define	EXT2_IOC_GETVERSION		FS_IOC_GETVERSION
288#define	EXT2_IOC_SETVERSION		FS_IOC_SETVERSION
289#define	EXT2_IOC_GETRSVSZ		_IOR('f', 5, long)
290#define	EXT2_IOC_SETRSVSZ		_IOW('f', 6, long)
291
292/*
293 * ioctl commands in 32 bit emulation
294 */
295#define EXT2_IOC32_GETVERSION		FS_IOC32_GETVERSION
296#define EXT2_IOC32_SETVERSION		FS_IOC32_SETVERSION
297
298/*
299 * Structure of an inode on the disk
300 */
301struct ext2_inode {
302	__le16	i_mode;		/* File mode */
303	__le16	i_uid;		/* Low 16 bits of Owner Uid */
304	__le32	i_size;		/* Size in bytes */
305	__le32	i_atime;	/* Access time */
306	__le32	i_ctime;	/* Creation time */
307	__le32	i_mtime;	/* Modification time */
308	__le32	i_dtime;	/* Deletion Time */
309	__le16	i_gid;		/* Low 16 bits of Group Id */
310	__le16	i_links_count;	/* Links count */
311	__le32	i_blocks;	/* Blocks count */
312	__le32	i_flags;	/* File flags */
313	union {
314		struct {
315			__le32  l_i_reserved1;
316		} linux1;
317		struct {
318			__le32  h_i_translator;
319		} hurd1;
320		struct {
321			__le32  m_i_reserved1;
322		} masix1;
323	} osd1;				/* OS dependent 1 */
324	__le32	i_block[EXT2_N_BLOCKS];/* Pointers to blocks */
325	__le32	i_generation;	/* File version (for NFS) */
326	__le32	i_file_acl;	/* File ACL */
327	__le32	i_dir_acl;	/* Directory ACL */
328	__le32	i_faddr;	/* Fragment address */
329	union {
330		struct {
331			__u8	l_i_frag;	/* Fragment number */
332			__u8	l_i_fsize;	/* Fragment size */
333			__u16	i_pad1;
334			__le16	l_i_uid_high;	/* these 2 fields    */
335			__le16	l_i_gid_high;	/* were reserved2[0] */
336			__u32	l_i_reserved2;
337		} linux2;
338		struct {
339			__u8	h_i_frag;	/* Fragment number */
340			__u8	h_i_fsize;	/* Fragment size */
341			__le16	h_i_mode_high;
342			__le16	h_i_uid_high;
343			__le16	h_i_gid_high;
344			__le32	h_i_author;
345		} hurd2;
346		struct {
347			__u8	m_i_frag;	/* Fragment number */
348			__u8	m_i_fsize;	/* Fragment size */
349			__u16	m_pad1;
350			__u32	m_i_reserved2[2];
351		} masix2;
352	} osd2;				/* OS dependent 2 */
353};
354
355#define i_size_high	i_dir_acl
356
357#define i_reserved1	osd1.linux1.l_i_reserved1
358#define i_frag		osd2.linux2.l_i_frag
359#define i_fsize		osd2.linux2.l_i_fsize
360#define i_uid_low	i_uid
361#define i_gid_low	i_gid
362#define i_uid_high	osd2.linux2.l_i_uid_high
363#define i_gid_high	osd2.linux2.l_i_gid_high
364#define i_reserved2	osd2.linux2.l_i_reserved2
365
366/*
367 * File system states
368 */
369#define	EXT2_VALID_FS			0x0001	/* Unmounted cleanly */
370#define	EXT2_ERROR_FS			0x0002	/* Errors detected */
371#define	EFSCORRUPTED			EUCLEAN	/* Filesystem is corrupted */
372
373/*
374 * Mount flags
375 */
376#define EXT2_MOUNT_OLDALLOC		0x000002  /* Don't use the new Orlov allocator */
377#define EXT2_MOUNT_GRPID		0x000004  /* Create files with directory's group */
378#define EXT2_MOUNT_DEBUG		0x000008  /* Some debugging messages */
379#define EXT2_MOUNT_ERRORS_CONT		0x000010  /* Continue on errors */
380#define EXT2_MOUNT_ERRORS_RO		0x000020  /* Remount fs ro on errors */
381#define EXT2_MOUNT_ERRORS_PANIC		0x000040  /* Panic on errors */
382#define EXT2_MOUNT_MINIX_DF		0x000080  /* Mimics the Minix statfs */
383#define EXT2_MOUNT_NOBH			0x000100  /* No buffer_heads */
384#define EXT2_MOUNT_NO_UID32		0x000200  /* Disable 32-bit UIDs */
385#define EXT2_MOUNT_XATTR_USER		0x004000  /* Extended user attributes */
386#define EXT2_MOUNT_POSIX_ACL		0x008000  /* POSIX Access Control Lists */
387#define EXT2_MOUNT_XIP			0x010000  /* Obsolete, use DAX */
388#define EXT2_MOUNT_USRQUOTA		0x020000  /* user quota */
389#define EXT2_MOUNT_GRPQUOTA		0x040000  /* group quota */
390#define EXT2_MOUNT_RESERVATION		0x080000  /* Preallocation */
391#define EXT2_MOUNT_DAX			0x100000  /* Direct Access */
392
393
394#define clear_opt(o, opt)		o &= ~EXT2_MOUNT_##opt
395#define set_opt(o, opt)			o |= EXT2_MOUNT_##opt
396#define test_opt(sb, opt)		(EXT2_SB(sb)->s_mount_opt & \
397					 EXT2_MOUNT_##opt)
398/*
399 * Maximal mount counts between two filesystem checks
400 */
401#define EXT2_DFL_MAX_MNT_COUNT		20	/* Allow 20 mounts */
402#define EXT2_DFL_CHECKINTERVAL		0	/* Don't use interval check */
403
404/*
405 * Behaviour when detecting errors
406 */
407#define EXT2_ERRORS_CONTINUE		1	/* Continue execution */
408#define EXT2_ERRORS_RO			2	/* Remount fs read-only */
409#define EXT2_ERRORS_PANIC		3	/* Panic */
410#define EXT2_ERRORS_DEFAULT		EXT2_ERRORS_CONTINUE
411
412/*
 
 
 
 
 
 
413 * Structure of the super block
414 */
415struct ext2_super_block {
416	__le32	s_inodes_count;		/* Inodes count */
417	__le32	s_blocks_count;		/* Blocks count */
418	__le32	s_r_blocks_count;	/* Reserved blocks count */
419	__le32	s_free_blocks_count;	/* Free blocks count */
420	__le32	s_free_inodes_count;	/* Free inodes count */
421	__le32	s_first_data_block;	/* First Data Block */
422	__le32	s_log_block_size;	/* Block size */
423	__le32	s_log_frag_size;	/* Fragment size */
424	__le32	s_blocks_per_group;	/* # Blocks per group */
425	__le32	s_frags_per_group;	/* # Fragments per group */
426	__le32	s_inodes_per_group;	/* # Inodes per group */
427	__le32	s_mtime;		/* Mount time */
428	__le32	s_wtime;		/* Write time */
429	__le16	s_mnt_count;		/* Mount count */
430	__le16	s_max_mnt_count;	/* Maximal mount count */
431	__le16	s_magic;		/* Magic signature */
432	__le16	s_state;		/* File system state */
433	__le16	s_errors;		/* Behaviour when detecting errors */
434	__le16	s_minor_rev_level; 	/* minor revision level */
435	__le32	s_lastcheck;		/* time of last check */
436	__le32	s_checkinterval;	/* max. time between checks */
437	__le32	s_creator_os;		/* OS */
438	__le32	s_rev_level;		/* Revision level */
439	__le16	s_def_resuid;		/* Default uid for reserved blocks */
440	__le16	s_def_resgid;		/* Default gid for reserved blocks */
441	/*
442	 * These fields are for EXT2_DYNAMIC_REV superblocks only.
443	 *
444	 * Note: the difference between the compatible feature set and
445	 * the incompatible feature set is that if there is a bit set
446	 * in the incompatible feature set that the kernel doesn't
447	 * know about, it should refuse to mount the filesystem.
448	 * 
449	 * e2fsck's requirements are more strict; if it doesn't know
450	 * about a feature in either the compatible or incompatible
451	 * feature set, it must abort and not try to meddle with
452	 * things it doesn't understand...
453	 */
454	__le32	s_first_ino; 		/* First non-reserved inode */
455	__le16   s_inode_size; 		/* size of inode structure */
456	__le16	s_block_group_nr; 	/* block group # of this superblock */
457	__le32	s_feature_compat; 	/* compatible feature set */
458	__le32	s_feature_incompat; 	/* incompatible feature set */
459	__le32	s_feature_ro_compat; 	/* readonly-compatible feature set */
460	__u8	s_uuid[16];		/* 128-bit uuid for volume */
461	char	s_volume_name[16]; 	/* volume name */
462	char	s_last_mounted[64]; 	/* directory where last mounted */
463	__le32	s_algorithm_usage_bitmap; /* For compression */
464	/*
465	 * Performance hints.  Directory preallocation should only
466	 * happen if the EXT2_COMPAT_PREALLOC flag is on.
467	 */
468	__u8	s_prealloc_blocks;	/* Nr of blocks to try to preallocate*/
469	__u8	s_prealloc_dir_blocks;	/* Nr to preallocate for dirs */
470	__u16	s_padding1;
471	/*
472	 * Journaling support valid if EXT3_FEATURE_COMPAT_HAS_JOURNAL set.
473	 */
474	__u8	s_journal_uuid[16];	/* uuid of journal superblock */
475	__u32	s_journal_inum;		/* inode number of journal file */
476	__u32	s_journal_dev;		/* device number of journal file */
477	__u32	s_last_orphan;		/* start of list of inodes to delete */
478	__u32	s_hash_seed[4];		/* HTREE hash seed */
479	__u8	s_def_hash_version;	/* Default hash version to use */
480	__u8	s_reserved_char_pad;
481	__u16	s_reserved_word_pad;
482	__le32	s_default_mount_opts;
483 	__le32	s_first_meta_bg; 	/* First metablock block group */
484	__u32	s_reserved[190];	/* Padding to the end of the block */
485};
486
487/*
488 * Codes for operating systems
489 */
490#define EXT2_OS_LINUX		0
491#define EXT2_OS_HURD		1
492#define EXT2_OS_MASIX		2
493#define EXT2_OS_FREEBSD		3
494#define EXT2_OS_LITES		4
495
496/*
497 * Revision levels
498 */
499#define EXT2_GOOD_OLD_REV	0	/* The good old (original) format */
500#define EXT2_DYNAMIC_REV	1 	/* V2 format w/ dynamic inode sizes */
501
502#define EXT2_CURRENT_REV	EXT2_GOOD_OLD_REV
503#define EXT2_MAX_SUPP_REV	EXT2_DYNAMIC_REV
504
505#define EXT2_GOOD_OLD_INODE_SIZE 128
506
507/*
508 * Feature set definitions
509 */
510
511#define EXT2_HAS_COMPAT_FEATURE(sb,mask)			\
512	( EXT2_SB(sb)->s_es->s_feature_compat & cpu_to_le32(mask) )
513#define EXT2_HAS_RO_COMPAT_FEATURE(sb,mask)			\
514	( EXT2_SB(sb)->s_es->s_feature_ro_compat & cpu_to_le32(mask) )
515#define EXT2_HAS_INCOMPAT_FEATURE(sb,mask)			\
516	( EXT2_SB(sb)->s_es->s_feature_incompat & cpu_to_le32(mask) )
517#define EXT2_SET_COMPAT_FEATURE(sb,mask)			\
518	EXT2_SB(sb)->s_es->s_feature_compat |= cpu_to_le32(mask)
519#define EXT2_SET_RO_COMPAT_FEATURE(sb,mask)			\
520	EXT2_SB(sb)->s_es->s_feature_ro_compat |= cpu_to_le32(mask)
521#define EXT2_SET_INCOMPAT_FEATURE(sb,mask)			\
522	EXT2_SB(sb)->s_es->s_feature_incompat |= cpu_to_le32(mask)
523#define EXT2_CLEAR_COMPAT_FEATURE(sb,mask)			\
524	EXT2_SB(sb)->s_es->s_feature_compat &= ~cpu_to_le32(mask)
525#define EXT2_CLEAR_RO_COMPAT_FEATURE(sb,mask)			\
526	EXT2_SB(sb)->s_es->s_feature_ro_compat &= ~cpu_to_le32(mask)
527#define EXT2_CLEAR_INCOMPAT_FEATURE(sb,mask)			\
528	EXT2_SB(sb)->s_es->s_feature_incompat &= ~cpu_to_le32(mask)
529
530#define EXT2_FEATURE_COMPAT_DIR_PREALLOC	0x0001
531#define EXT2_FEATURE_COMPAT_IMAGIC_INODES	0x0002
532#define EXT3_FEATURE_COMPAT_HAS_JOURNAL		0x0004
533#define EXT2_FEATURE_COMPAT_EXT_ATTR		0x0008
534#define EXT2_FEATURE_COMPAT_RESIZE_INO		0x0010
535#define EXT2_FEATURE_COMPAT_DIR_INDEX		0x0020
536#define EXT2_FEATURE_COMPAT_ANY			0xffffffff
537
538#define EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER	0x0001
539#define EXT2_FEATURE_RO_COMPAT_LARGE_FILE	0x0002
540#define EXT2_FEATURE_RO_COMPAT_BTREE_DIR	0x0004
541#define EXT2_FEATURE_RO_COMPAT_ANY		0xffffffff
542
543#define EXT2_FEATURE_INCOMPAT_COMPRESSION	0x0001
544#define EXT2_FEATURE_INCOMPAT_FILETYPE		0x0002
545#define EXT3_FEATURE_INCOMPAT_RECOVER		0x0004
546#define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV	0x0008
547#define EXT2_FEATURE_INCOMPAT_META_BG		0x0010
548#define EXT2_FEATURE_INCOMPAT_ANY		0xffffffff
549
550#define EXT2_FEATURE_COMPAT_SUPP	EXT2_FEATURE_COMPAT_EXT_ATTR
551#define EXT2_FEATURE_INCOMPAT_SUPP	(EXT2_FEATURE_INCOMPAT_FILETYPE| \
552					 EXT2_FEATURE_INCOMPAT_META_BG)
553#define EXT2_FEATURE_RO_COMPAT_SUPP	(EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER| \
554					 EXT2_FEATURE_RO_COMPAT_LARGE_FILE| \
555					 EXT2_FEATURE_RO_COMPAT_BTREE_DIR)
556#define EXT2_FEATURE_RO_COMPAT_UNSUPPORTED	~EXT2_FEATURE_RO_COMPAT_SUPP
557#define EXT2_FEATURE_INCOMPAT_UNSUPPORTED	~EXT2_FEATURE_INCOMPAT_SUPP
558
559/*
560 * Default values for user and/or group using reserved blocks
561 */
562#define	EXT2_DEF_RESUID		0
563#define	EXT2_DEF_RESGID		0
564
565/*
566 * Default mount options
567 */
568#define EXT2_DEFM_DEBUG		0x0001
569#define EXT2_DEFM_BSDGROUPS	0x0002
570#define EXT2_DEFM_XATTR_USER	0x0004
571#define EXT2_DEFM_ACL		0x0008
572#define EXT2_DEFM_UID16		0x0010
573    /* Not used by ext2, but reserved for use by ext3 */
574#define EXT3_DEFM_JMODE		0x0060 
575#define EXT3_DEFM_JMODE_DATA	0x0020
576#define EXT3_DEFM_JMODE_ORDERED	0x0040
577#define EXT3_DEFM_JMODE_WBACK	0x0060
578
579/*
580 * Structure of a directory entry
581 */
582
583struct ext2_dir_entry {
584	__le32	inode;			/* Inode number */
585	__le16	rec_len;		/* Directory entry length */
586	__le16	name_len;		/* Name length */
587	char	name[];			/* File name, up to EXT2_NAME_LEN */
588};
589
590/*
591 * The new version of the directory entry.  Since EXT2 structures are
592 * stored in intel byte order, and the name_len field could never be
593 * bigger than 255 chars, it's safe to reclaim the extra byte for the
594 * file_type field.
595 */
596struct ext2_dir_entry_2 {
597	__le32	inode;			/* Inode number */
598	__le16	rec_len;		/* Directory entry length */
599	__u8	name_len;		/* Name length */
600	__u8	file_type;
601	char	name[];			/* File name, up to EXT2_NAME_LEN */
602};
603
604/*
605 * EXT2_DIR_PAD defines the directory entries boundaries
606 *
607 * NOTE: It must be a multiple of 4
608 */
609#define EXT2_DIR_PAD		 	4
610#define EXT2_DIR_ROUND 			(EXT2_DIR_PAD - 1)
611#define EXT2_DIR_REC_LEN(name_len)	(((name_len) + 8 + EXT2_DIR_ROUND) & \
612					 ~EXT2_DIR_ROUND)
613#define EXT2_MAX_REC_LEN		((1<<16)-1)
614
615static inline void verify_offsets(void)
616{
617#define A(x,y) BUILD_BUG_ON(x != offsetof(struct ext2_super_block, y));
618	A(EXT2_SB_MAGIC_OFFSET, s_magic);
619	A(EXT2_SB_BLOCKS_OFFSET, s_blocks_count);
620	A(EXT2_SB_BSIZE_OFFSET, s_log_block_size);
621#undef A
622}
623
624/*
625 * ext2 mount options
626 */
627struct ext2_mount_options {
628	unsigned long s_mount_opt;
629	kuid_t s_resuid;
630	kgid_t s_resgid;
631};
632
633/*
634 * second extended file system inode data in memory
635 */
636struct ext2_inode_info {
637	__le32	i_data[15];
638	__u32	i_flags;
639	__u32	i_faddr;
640	__u8	i_frag_no;
641	__u8	i_frag_size;
642	__u16	i_state;
643	__u32	i_file_acl;
644	__u32	i_dir_acl;
645	__u32	i_dtime;
646
647	/*
648	 * i_block_group is the number of the block group which contains
649	 * this file's inode.  Constant across the lifetime of the inode,
650	 * it is used for making block allocation decisions - we try to
651	 * place a file's data blocks near its inode block, and new inodes
652	 * near to their parent directory's inode.
653	 */
654	__u32	i_block_group;
655
656	/* block reservation info */
657	struct ext2_block_alloc_info *i_block_alloc_info;
658
659	__u32	i_dir_start_lookup;
660#ifdef CONFIG_EXT2_FS_XATTR
661	/*
662	 * Extended attributes can be read independently of the main file
663	 * data. Taking i_mutex even when reading would cause contention
664	 * between readers of EAs and writers of regular file data, so
665	 * instead we synchronize on xattr_sem when reading or changing
666	 * EAs.
667	 */
668	struct rw_semaphore xattr_sem;
669#endif
670	rwlock_t i_meta_lock;
671
672	/*
673	 * truncate_mutex is for serialising ext2_truncate() against
674	 * ext2_getblock().  It also protects the internals of the inode's
675	 * reservation data structures: ext2_reserve_window and
676	 * ext2_reserve_window_node.
677	 */
678	struct mutex truncate_mutex;
679	struct inode	vfs_inode;
680	struct list_head i_orphan;	/* unlinked but open inodes */
681#ifdef CONFIG_QUOTA
682	struct dquot *i_dquot[MAXQUOTAS];
683#endif
684};
685
686/*
687 * Inode dynamic state flags
688 */
689#define EXT2_STATE_NEW			0x00000001 /* inode is newly created */
690
691
692/*
693 * Function prototypes
694 */
695
696/*
697 * Ok, these declarations are also in <linux/kernel.h> but none of the
698 * ext2 source programs needs to include it so they are duplicated here.
699 */
700
701static inline struct ext2_inode_info *EXT2_I(struct inode *inode)
702{
703	return container_of(inode, struct ext2_inode_info, vfs_inode);
704}
705
706/* balloc.c */
707extern int ext2_bg_has_super(struct super_block *sb, int group);
708extern unsigned long ext2_bg_num_gdb(struct super_block *sb, int group);
709extern ext2_fsblk_t ext2_new_block(struct inode *, unsigned long, int *);
710extern ext2_fsblk_t ext2_new_blocks(struct inode *, unsigned long,
711				unsigned long *, int *);
712extern int ext2_data_block_valid(struct ext2_sb_info *sbi, ext2_fsblk_t start_blk,
713				 unsigned int count);
714extern void ext2_free_blocks (struct inode *, unsigned long,
715			      unsigned long);
716extern unsigned long ext2_count_free_blocks (struct super_block *);
717extern unsigned long ext2_count_dirs (struct super_block *);
718extern struct ext2_group_desc * ext2_get_group_desc(struct super_block * sb,
719						    unsigned int block_group,
720						    struct buffer_head ** bh);
721extern void ext2_discard_reservation (struct inode *);
722extern int ext2_should_retry_alloc(struct super_block *sb, int *retries);
723extern void ext2_init_block_alloc_info(struct inode *);
724extern void ext2_rsv_window_add(struct super_block *sb, struct ext2_reserve_window_node *rsv);
725
726/* dir.c */
727extern int ext2_add_link (struct dentry *, struct inode *);
728extern int ext2_inode_by_name(struct inode *dir,
729			      const struct qstr *child, ino_t *ino);
730extern int ext2_make_empty(struct inode *, struct inode *);
731extern struct ext2_dir_entry_2 *ext2_find_entry(struct inode *, const struct qstr *,
732						struct page **, void **res_page_addr);
733extern int ext2_delete_entry(struct ext2_dir_entry_2 *dir, struct page *page,
734			     char *kaddr);
735extern int ext2_empty_dir (struct inode *);
736extern struct ext2_dir_entry_2 *ext2_dotdot(struct inode *dir, struct page **p, void **pa);
737extern void ext2_set_link(struct inode *, struct ext2_dir_entry_2 *, struct page *, void *,
738			  struct inode *, int);
739static inline void ext2_put_page(struct page *page, void *page_addr)
740{
741	kunmap_local(page_addr);
742	put_page(page);
743}
744
745/* ialloc.c */
746extern struct inode * ext2_new_inode (struct inode *, umode_t, const struct qstr *);
747extern void ext2_free_inode (struct inode *);
748extern unsigned long ext2_count_free_inodes (struct super_block *);
749extern unsigned long ext2_count_free (struct buffer_head *, unsigned);
750
751/* inode.c */
752extern struct inode *ext2_iget (struct super_block *, unsigned long);
753extern int ext2_write_inode (struct inode *, struct writeback_control *);
754extern void ext2_evict_inode(struct inode *);
 
755extern int ext2_get_block(struct inode *, sector_t, struct buffer_head *, int);
756extern int ext2_setattr (struct user_namespace *, struct dentry *, struct iattr *);
757extern int ext2_getattr (struct user_namespace *, const struct path *,
758			 struct kstat *, u32, unsigned int);
759extern void ext2_set_inode_flags(struct inode *inode);
760extern int ext2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
761		       u64 start, u64 len);
762
763/* ioctl.c */
764extern int ext2_fileattr_get(struct dentry *dentry, struct fileattr *fa);
765extern int ext2_fileattr_set(struct user_namespace *mnt_userns,
766			     struct dentry *dentry, struct fileattr *fa);
767extern long ext2_ioctl(struct file *, unsigned int, unsigned long);
768extern long ext2_compat_ioctl(struct file *, unsigned int, unsigned long);
769
770/* namei.c */
771struct dentry *ext2_get_parent(struct dentry *child);
772
773/* super.c */
774extern __printf(3, 4)
775void ext2_error(struct super_block *, const char *, const char *, ...);
776extern __printf(3, 4)
777void ext2_msg(struct super_block *, const char *, const char *, ...);
778extern void ext2_update_dynamic_rev (struct super_block *sb);
779extern void ext2_sync_super(struct super_block *sb, struct ext2_super_block *es,
780			    int wait);
781
782/*
783 * Inodes and files operations
784 */
785
786/* dir.c */
787extern const struct file_operations ext2_dir_operations;
788
789/* file.c */
790extern int ext2_fsync(struct file *file, loff_t start, loff_t end,
791		      int datasync);
792extern const struct inode_operations ext2_file_inode_operations;
793extern const struct file_operations ext2_file_operations;
794
795/* inode.c */
796extern void ext2_set_file_ops(struct inode *inode);
797extern const struct address_space_operations ext2_aops;
798extern const struct iomap_ops ext2_iomap_ops;
799
800/* namei.c */
801extern const struct inode_operations ext2_dir_inode_operations;
802extern const struct inode_operations ext2_special_inode_operations;
803
804/* symlink.c */
805extern const struct inode_operations ext2_fast_symlink_inode_operations;
806extern const struct inode_operations ext2_symlink_inode_operations;
807
808static inline ext2_fsblk_t
809ext2_group_first_block_no(struct super_block *sb, unsigned long group_no)
810{
811	return group_no * (ext2_fsblk_t)EXT2_BLOCKS_PER_GROUP(sb) +
812		le32_to_cpu(EXT2_SB(sb)->s_es->s_first_data_block);
813}
814
815static inline ext2_fsblk_t
816ext2_group_last_block_no(struct super_block *sb, unsigned long group_no)
817{
818	struct ext2_sb_info *sbi = EXT2_SB(sb);
819
820	if (group_no == sbi->s_groups_count - 1)
821		return le32_to_cpu(sbi->s_es->s_blocks_count) - 1;
822	else
823		return ext2_group_first_block_no(sb, group_no) +
824			EXT2_BLOCKS_PER_GROUP(sb) - 1;
825}
826
827#define ext2_set_bit	__test_and_set_bit_le
828#define ext2_clear_bit	__test_and_clear_bit_le
829#define ext2_test_bit	test_bit_le
830#define ext2_find_first_zero_bit	find_first_zero_bit_le
831#define ext2_find_next_zero_bit		find_next_zero_bit_le
v6.13.7
  1/* SPDX-License-Identifier: GPL-2.0 */
  2/*
  3 * Copyright (C) 1992, 1993, 1994, 1995
  4 * Remy Card (card@masi.ibp.fr)
  5 * Laboratoire MASI - Institut Blaise Pascal
  6 * Universite Pierre et Marie Curie (Paris VI)
  7 *
  8 *  from
  9 *
 10 *  linux/include/linux/minix_fs.h
 11 *
 12 *  Copyright (C) 1991, 1992  Linus Torvalds
 13 */
 14#include <linux/fs.h>
 15#include <linux/ext2_fs.h>
 16#include <linux/blockgroup_lock.h>
 17#include <linux/percpu_counter.h>
 18#include <linux/rbtree.h>
 19#include <linux/mm.h>
 20#include <linux/highmem.h>
 21
 22/* XXX Here for now... not interested in restructing headers JUST now */
 23
 24/* data type for block offset of block group */
 25typedef int ext2_grpblk_t;
 26
 27/* data type for filesystem-wide blocks number */
 28typedef unsigned long ext2_fsblk_t;
 29
 30#define E2FSBLK "%lu"
 31
 32struct ext2_reserve_window {
 33	ext2_fsblk_t		_rsv_start;	/* First byte reserved */
 34	ext2_fsblk_t		_rsv_end;	/* Last byte reserved or 0 */
 35};
 36
 37struct ext2_reserve_window_node {
 38	struct rb_node	 	rsv_node;
 39	__u32			rsv_goal_size;
 40	__u32			rsv_alloc_hit;
 41	struct ext2_reserve_window	rsv_window;
 42};
 43
 44struct ext2_block_alloc_info {
 45	/* information about reservation window */
 46	struct ext2_reserve_window_node	rsv_window_node;
 47	/*
 48	 * was i_next_alloc_block in ext2_inode_info
 49	 * is the logical (file-relative) number of the
 50	 * most-recently-allocated block in this file.
 51	 * We use this for detecting linearly ascending allocation requests.
 52	 */
 53	__u32			last_alloc_logical_block;
 54	/*
 55	 * Was i_next_alloc_goal in ext2_inode_info
 56	 * is the *physical* companion to i_next_alloc_block.
 57	 * it is the physical block number of the block which was most-recently
 58	 * allocated to this file.  This gives us the goal (target) for the next
 59	 * allocation when we detect linearly ascending requests.
 60	 */
 61	ext2_fsblk_t		last_alloc_physical_block;
 62};
 63
 64#define rsv_start rsv_window._rsv_start
 65#define rsv_end rsv_window._rsv_end
 66
 67struct mb_cache;
 68
 69/*
 70 * second extended-fs super-block data in memory
 71 */
 72struct ext2_sb_info {
 
 
 73	unsigned long s_inodes_per_block;/* Number of inodes per block */
 
 74	unsigned long s_blocks_per_group;/* Number of blocks in a group */
 75	unsigned long s_inodes_per_group;/* Number of inodes in a group */
 76	unsigned long s_itb_per_group;	/* Number of inode table blocks per group */
 77	unsigned long s_gdb_count;	/* Number of group descriptor blocks */
 78	unsigned long s_desc_per_block;	/* Number of group descriptors per block */
 79	unsigned long s_groups_count;	/* Number of groups in the fs */
 80	unsigned long s_overhead_last;  /* Last calculated overhead */
 81	unsigned long s_blocks_last;    /* Last seen block count */
 82	struct buffer_head * s_sbh;	/* Buffer containing the super block */
 83	struct ext2_super_block * s_es;	/* Pointer to the super block in the buffer */
 84	struct buffer_head ** s_group_desc;
 85	unsigned long  s_mount_opt;
 86	unsigned long s_sb_block;
 87	kuid_t s_resuid;
 88	kgid_t s_resgid;
 89	unsigned short s_mount_state;
 90	unsigned short s_pad;
 91	int s_addr_per_block_bits;
 92	int s_desc_per_block_bits;
 93	int s_inode_size;
 94	int s_first_ino;
 95	spinlock_t s_next_gen_lock;
 96	u32 s_next_generation;
 97	unsigned long s_dir_count;
 98	u8 *s_debts;
 99	struct percpu_counter s_freeblocks_counter;
100	struct percpu_counter s_freeinodes_counter;
101	struct percpu_counter s_dirs_counter;
102	struct blockgroup_lock *s_blockgroup_lock;
103	/* root of the per fs reservation window tree */
104	spinlock_t s_rsv_window_lock;
105	struct rb_root s_rsv_window_root;
106	struct ext2_reserve_window_node s_rsv_window_head;
107	/*
108	 * s_lock protects against concurrent modifications of s_mount_state,
109	 * s_blocks_last, s_overhead_last and the content of superblock's
110	 * buffer pointed to by sbi->s_es.
111	 *
112	 * Note: It is used in ext2_show_options() to provide a consistent view
113	 * of the mount options.
114	 */
115	spinlock_t s_lock;
116	struct mb_cache *s_ea_block_cache;
117	struct dax_device *s_daxdev;
118	u64 s_dax_part_off;
119};
120
121static inline spinlock_t *
122sb_bgl_lock(struct ext2_sb_info *sbi, unsigned int block_group)
123{
124	return bgl_lock_ptr(sbi->s_blockgroup_lock, block_group);
125}
126
127/*
128 * Define EXT2FS_DEBUG to produce debug messages
129 */
130#undef EXT2FS_DEBUG
131
132/*
133 * Define EXT2_RESERVATION to reserve data blocks for expanding files
134 */
135#define EXT2_DEFAULT_RESERVE_BLOCKS     8
136/*max window size: 1024(direct blocks) + 3([t,d]indirect blocks) */
137#define EXT2_MAX_RESERVE_BLOCKS         1027
138#define EXT2_RESERVE_WINDOW_NOT_ALLOCATED 0
139/*
140 * The second extended file system version
141 */
142#define EXT2FS_DATE		"95/08/09"
143#define EXT2FS_VERSION		"0.5b"
144
145/*
146 * Debug code
147 */
148#ifdef EXT2FS_DEBUG
149#	define ext2_debug(f, a...)	{ \
150					printk ("EXT2-fs DEBUG (%s, %d): %s:", \
151						__FILE__, __LINE__, __func__); \
152				  	printk (f, ## a); \
153					}
154#else
155#	define ext2_debug(f, a...)	/**/
156#endif
157
158/*
159 * Special inode numbers
160 */
161#define	EXT2_BAD_INO		 1	/* Bad blocks inode */
162#define EXT2_ROOT_INO		 2	/* Root inode */
163#define EXT2_BOOT_LOADER_INO	 5	/* Boot loader inode */
164#define EXT2_UNDEL_DIR_INO	 6	/* Undelete directory inode */
165
166/* First non-reserved inode for old ext2 filesystems */
167#define EXT2_GOOD_OLD_FIRST_INO	11
168
169static inline struct ext2_sb_info *EXT2_SB(struct super_block *sb)
170{
171	return sb->s_fs_info;
172}
173
174/*
175 * Macro-instructions used to manage several block sizes
176 */
177#define EXT2_MIN_BLOCK_SIZE		1024
178#define	EXT2_MAX_BLOCK_SIZE		65536
179#define EXT2_MIN_BLOCK_LOG_SIZE		  10
180#define EXT2_MAX_BLOCK_LOG_SIZE		  16
181#define EXT2_BLOCK_SIZE(s)		((s)->s_blocksize)
182#define	EXT2_ADDR_PER_BLOCK(s)		(EXT2_BLOCK_SIZE(s) / sizeof (__u32))
183#define EXT2_BLOCK_SIZE_BITS(s)		((s)->s_blocksize_bits)
184#define	EXT2_ADDR_PER_BLOCK_BITS(s)	(EXT2_SB(s)->s_addr_per_block_bits)
185#define EXT2_INODE_SIZE(s)		(EXT2_SB(s)->s_inode_size)
186#define EXT2_FIRST_INO(s)		(EXT2_SB(s)->s_first_ino)
187
188/*
 
 
 
 
 
 
 
 
 
189 * Structure of a blocks group descriptor
190 */
191struct ext2_group_desc
192{
193	__le32	bg_block_bitmap;		/* Blocks bitmap block */
194	__le32	bg_inode_bitmap;		/* Inodes bitmap block */
195	__le32	bg_inode_table;		/* Inodes table block */
196	__le16	bg_free_blocks_count;	/* Free blocks count */
197	__le16	bg_free_inodes_count;	/* Free inodes count */
198	__le16	bg_used_dirs_count;	/* Directories count */
199	__le16	bg_pad;
200	__le32	bg_reserved[3];
201};
202
203/*
204 * Macro-instructions used to manage group descriptors
205 */
206#define EXT2_BLOCKS_PER_GROUP(s)	(EXT2_SB(s)->s_blocks_per_group)
207#define EXT2_DESC_PER_BLOCK(s)		(EXT2_SB(s)->s_desc_per_block)
208#define EXT2_INODES_PER_GROUP(s)	(EXT2_SB(s)->s_inodes_per_group)
209#define EXT2_DESC_PER_BLOCK_BITS(s)	(EXT2_SB(s)->s_desc_per_block_bits)
210
211/*
212 * Constants relative to the data blocks
213 */
214#define	EXT2_NDIR_BLOCKS		12
215#define	EXT2_IND_BLOCK			EXT2_NDIR_BLOCKS
216#define	EXT2_DIND_BLOCK			(EXT2_IND_BLOCK + 1)
217#define	EXT2_TIND_BLOCK			(EXT2_DIND_BLOCK + 1)
218#define	EXT2_N_BLOCKS			(EXT2_TIND_BLOCK + 1)
219
220/*
221 * Inode flags (GETFLAGS/SETFLAGS)
222 */
223#define	EXT2_SECRM_FL			FS_SECRM_FL	/* Secure deletion */
224#define	EXT2_UNRM_FL			FS_UNRM_FL	/* Undelete */
225#define	EXT2_COMPR_FL			FS_COMPR_FL	/* Compress file */
226#define EXT2_SYNC_FL			FS_SYNC_FL	/* Synchronous updates */
227#define EXT2_IMMUTABLE_FL		FS_IMMUTABLE_FL	/* Immutable file */
228#define EXT2_APPEND_FL			FS_APPEND_FL	/* writes to file may only append */
229#define EXT2_NODUMP_FL			FS_NODUMP_FL	/* do not dump file */
230#define EXT2_NOATIME_FL			FS_NOATIME_FL	/* do not update atime */
231/* Reserved for compression usage... */
232#define EXT2_DIRTY_FL			FS_DIRTY_FL
233#define EXT2_COMPRBLK_FL		FS_COMPRBLK_FL	/* One or more compressed clusters */
234#define EXT2_NOCOMP_FL			FS_NOCOMP_FL	/* Don't compress */
235#define EXT2_ECOMPR_FL			FS_ECOMPR_FL	/* Compression error */
236/* End compression flags --- maybe not all used */	
237#define EXT2_BTREE_FL			FS_BTREE_FL	/* btree format dir */
238#define EXT2_INDEX_FL			FS_INDEX_FL	/* hash-indexed directory */
239#define EXT2_IMAGIC_FL			FS_IMAGIC_FL	/* AFS directory */
240#define EXT2_JOURNAL_DATA_FL		FS_JOURNAL_DATA_FL /* Reserved for ext3 */
241#define EXT2_NOTAIL_FL			FS_NOTAIL_FL	/* file tail should not be merged */
242#define EXT2_DIRSYNC_FL			FS_DIRSYNC_FL	/* dirsync behaviour (directories only) */
243#define EXT2_TOPDIR_FL			FS_TOPDIR_FL	/* Top of directory hierarchies*/
244#define EXT2_RESERVED_FL		FS_RESERVED_FL	/* reserved for ext2 lib */
245
246#define EXT2_FL_USER_VISIBLE		FS_FL_USER_VISIBLE	/* User visible flags */
247#define EXT2_FL_USER_MODIFIABLE		FS_FL_USER_MODIFIABLE	/* User modifiable flags */
248
249/* Flags that should be inherited by new inodes from their parent. */
250#define EXT2_FL_INHERITED (EXT2_SECRM_FL | EXT2_UNRM_FL | EXT2_COMPR_FL |\
251			   EXT2_SYNC_FL | EXT2_NODUMP_FL |\
252			   EXT2_NOATIME_FL | EXT2_COMPRBLK_FL |\
253			   EXT2_NOCOMP_FL | EXT2_JOURNAL_DATA_FL |\
254			   EXT2_NOTAIL_FL | EXT2_DIRSYNC_FL)
255
256/* Flags that are appropriate for regular files (all but dir-specific ones). */
257#define EXT2_REG_FLMASK (~(EXT2_DIRSYNC_FL | EXT2_TOPDIR_FL))
258
259/* Flags that are appropriate for non-directories/regular files. */
260#define EXT2_OTHER_FLMASK (EXT2_NODUMP_FL | EXT2_NOATIME_FL)
261
262/* Mask out flags that are inappropriate for the given type of inode. */
263static inline __u32 ext2_mask_flags(umode_t mode, __u32 flags)
264{
265	if (S_ISDIR(mode))
266		return flags;
267	else if (S_ISREG(mode))
268		return flags & EXT2_REG_FLMASK;
269	else
270		return flags & EXT2_OTHER_FLMASK;
271}
272
273/*
274 * ioctl commands
275 */
276#define	EXT2_IOC_GETVERSION		FS_IOC_GETVERSION
277#define	EXT2_IOC_SETVERSION		FS_IOC_SETVERSION
278#define	EXT2_IOC_GETRSVSZ		_IOR('f', 5, long)
279#define	EXT2_IOC_SETRSVSZ		_IOW('f', 6, long)
280
281/*
282 * ioctl commands in 32 bit emulation
283 */
284#define EXT2_IOC32_GETVERSION		FS_IOC32_GETVERSION
285#define EXT2_IOC32_SETVERSION		FS_IOC32_SETVERSION
286
287/*
288 * Structure of an inode on the disk
289 */
290struct ext2_inode {
291	__le16	i_mode;		/* File mode */
292	__le16	i_uid;		/* Low 16 bits of Owner Uid */
293	__le32	i_size;		/* Size in bytes */
294	__le32	i_atime;	/* Access time */
295	__le32	i_ctime;	/* Creation time */
296	__le32	i_mtime;	/* Modification time */
297	__le32	i_dtime;	/* Deletion Time */
298	__le16	i_gid;		/* Low 16 bits of Group Id */
299	__le16	i_links_count;	/* Links count */
300	__le32	i_blocks;	/* Blocks count */
301	__le32	i_flags;	/* File flags */
302	union {
303		struct {
304			__le32  l_i_reserved1;
305		} linux1;
306		struct {
307			__le32  h_i_translator;
308		} hurd1;
309		struct {
310			__le32  m_i_reserved1;
311		} masix1;
312	} osd1;				/* OS dependent 1 */
313	__le32	i_block[EXT2_N_BLOCKS];/* Pointers to blocks */
314	__le32	i_generation;	/* File version (for NFS) */
315	__le32	i_file_acl;	/* File ACL */
316	__le32	i_dir_acl;	/* Directory ACL */
317	__le32	i_faddr;	/* Fragment address */
318	union {
319		struct {
320			__u8	l_i_frag;	/* Fragment number */
321			__u8	l_i_fsize;	/* Fragment size */
322			__u16	i_pad1;
323			__le16	l_i_uid_high;	/* these 2 fields    */
324			__le16	l_i_gid_high;	/* were reserved2[0] */
325			__u32	l_i_reserved2;
326		} linux2;
327		struct {
328			__u8	h_i_frag;	/* Fragment number */
329			__u8	h_i_fsize;	/* Fragment size */
330			__le16	h_i_mode_high;
331			__le16	h_i_uid_high;
332			__le16	h_i_gid_high;
333			__le32	h_i_author;
334		} hurd2;
335		struct {
336			__u8	m_i_frag;	/* Fragment number */
337			__u8	m_i_fsize;	/* Fragment size */
338			__u16	m_pad1;
339			__u32	m_i_reserved2[2];
340		} masix2;
341	} osd2;				/* OS dependent 2 */
342};
343
344#define i_size_high	i_dir_acl
345
346#define i_reserved1	osd1.linux1.l_i_reserved1
347#define i_frag		osd2.linux2.l_i_frag
348#define i_fsize		osd2.linux2.l_i_fsize
349#define i_uid_low	i_uid
350#define i_gid_low	i_gid
351#define i_uid_high	osd2.linux2.l_i_uid_high
352#define i_gid_high	osd2.linux2.l_i_gid_high
353#define i_reserved2	osd2.linux2.l_i_reserved2
354
355/*
356 * File system states
357 */
358#define	EXT2_VALID_FS			0x0001	/* Unmounted cleanly */
359#define	EXT2_ERROR_FS			0x0002	/* Errors detected */
360#define	EFSCORRUPTED			EUCLEAN	/* Filesystem is corrupted */
361
362/*
363 * Mount flags
364 */
365#define EXT2_MOUNT_OLDALLOC		0x000002  /* Don't use the new Orlov allocator */
366#define EXT2_MOUNT_GRPID		0x000004  /* Create files with directory's group */
367#define EXT2_MOUNT_DEBUG		0x000008  /* Some debugging messages */
368#define EXT2_MOUNT_ERRORS_CONT		0x000010  /* Continue on errors */
369#define EXT2_MOUNT_ERRORS_RO		0x000020  /* Remount fs ro on errors */
370#define EXT2_MOUNT_ERRORS_PANIC		0x000040  /* Panic on errors */
371#define EXT2_MOUNT_MINIX_DF		0x000080  /* Mimics the Minix statfs */
372#define EXT2_MOUNT_NOBH			0x000100  /* No buffer_heads */
373#define EXT2_MOUNT_NO_UID32		0x000200  /* Disable 32-bit UIDs */
374#define EXT2_MOUNT_XATTR_USER		0x004000  /* Extended user attributes */
375#define EXT2_MOUNT_POSIX_ACL		0x008000  /* POSIX Access Control Lists */
376#define EXT2_MOUNT_XIP			0x010000  /* Obsolete, use DAX */
377#define EXT2_MOUNT_USRQUOTA		0x020000  /* user quota */
378#define EXT2_MOUNT_GRPQUOTA		0x040000  /* group quota */
379#define EXT2_MOUNT_RESERVATION		0x080000  /* Preallocation */
380#define EXT2_MOUNT_DAX			0x100000  /* Direct Access */
381
382
383#define clear_opt(o, opt)		o &= ~EXT2_MOUNT_##opt
384#define set_opt(o, opt)			o |= EXT2_MOUNT_##opt
385#define test_opt(sb, opt)		(EXT2_SB(sb)->s_mount_opt & \
386					 EXT2_MOUNT_##opt)
387/*
388 * Maximal mount counts between two filesystem checks
389 */
390#define EXT2_DFL_MAX_MNT_COUNT		20	/* Allow 20 mounts */
391#define EXT2_DFL_CHECKINTERVAL		0	/* Don't use interval check */
392
393/*
394 * Behaviour when detecting errors
395 */
396#define EXT2_ERRORS_CONTINUE		1	/* Continue execution */
397#define EXT2_ERRORS_RO			2	/* Remount fs read-only */
398#define EXT2_ERRORS_PANIC		3	/* Panic */
399#define EXT2_ERRORS_DEFAULT		EXT2_ERRORS_CONTINUE
400
401/*
402 * Allocation flags
403 */
404#define EXT2_ALLOC_NORESERVE            0x1	/* Do not use reservation
405						 * window for allocation */
406
407/*
408 * Structure of the super block
409 */
410struct ext2_super_block {
411	__le32	s_inodes_count;		/* Inodes count */
412	__le32	s_blocks_count;		/* Blocks count */
413	__le32	s_r_blocks_count;	/* Reserved blocks count */
414	__le32	s_free_blocks_count;	/* Free blocks count */
415	__le32	s_free_inodes_count;	/* Free inodes count */
416	__le32	s_first_data_block;	/* First Data Block */
417	__le32	s_log_block_size;	/* Block size */
418	__le32	s_log_frag_size;	/* Fragment size */
419	__le32	s_blocks_per_group;	/* # Blocks per group */
420	__le32	s_frags_per_group;	/* # Fragments per group */
421	__le32	s_inodes_per_group;	/* # Inodes per group */
422	__le32	s_mtime;		/* Mount time */
423	__le32	s_wtime;		/* Write time */
424	__le16	s_mnt_count;		/* Mount count */
425	__le16	s_max_mnt_count;	/* Maximal mount count */
426	__le16	s_magic;		/* Magic signature */
427	__le16	s_state;		/* File system state */
428	__le16	s_errors;		/* Behaviour when detecting errors */
429	__le16	s_minor_rev_level; 	/* minor revision level */
430	__le32	s_lastcheck;		/* time of last check */
431	__le32	s_checkinterval;	/* max. time between checks */
432	__le32	s_creator_os;		/* OS */
433	__le32	s_rev_level;		/* Revision level */
434	__le16	s_def_resuid;		/* Default uid for reserved blocks */
435	__le16	s_def_resgid;		/* Default gid for reserved blocks */
436	/*
437	 * These fields are for EXT2_DYNAMIC_REV superblocks only.
438	 *
439	 * Note: the difference between the compatible feature set and
440	 * the incompatible feature set is that if there is a bit set
441	 * in the incompatible feature set that the kernel doesn't
442	 * know about, it should refuse to mount the filesystem.
443	 * 
444	 * e2fsck's requirements are more strict; if it doesn't know
445	 * about a feature in either the compatible or incompatible
446	 * feature set, it must abort and not try to meddle with
447	 * things it doesn't understand...
448	 */
449	__le32	s_first_ino; 		/* First non-reserved inode */
450	__le16   s_inode_size; 		/* size of inode structure */
451	__le16	s_block_group_nr; 	/* block group # of this superblock */
452	__le32	s_feature_compat; 	/* compatible feature set */
453	__le32	s_feature_incompat; 	/* incompatible feature set */
454	__le32	s_feature_ro_compat; 	/* readonly-compatible feature set */
455	__u8	s_uuid[16];		/* 128-bit uuid for volume */
456	char	s_volume_name[16]; 	/* volume name */
457	char	s_last_mounted[64]; 	/* directory where last mounted */
458	__le32	s_algorithm_usage_bitmap; /* For compression */
459	/*
460	 * Performance hints.  Directory preallocation should only
461	 * happen if the EXT2_COMPAT_PREALLOC flag is on.
462	 */
463	__u8	s_prealloc_blocks;	/* Nr of blocks to try to preallocate*/
464	__u8	s_prealloc_dir_blocks;	/* Nr to preallocate for dirs */
465	__u16	s_padding1;
466	/*
467	 * Journaling support valid if EXT3_FEATURE_COMPAT_HAS_JOURNAL set.
468	 */
469	__u8	s_journal_uuid[16];	/* uuid of journal superblock */
470	__u32	s_journal_inum;		/* inode number of journal file */
471	__u32	s_journal_dev;		/* device number of journal file */
472	__u32	s_last_orphan;		/* start of list of inodes to delete */
473	__u32	s_hash_seed[4];		/* HTREE hash seed */
474	__u8	s_def_hash_version;	/* Default hash version to use */
475	__u8	s_reserved_char_pad;
476	__u16	s_reserved_word_pad;
477	__le32	s_default_mount_opts;
478 	__le32	s_first_meta_bg; 	/* First metablock block group */
479	__u32	s_reserved[190];	/* Padding to the end of the block */
480};
481
482/*
483 * Codes for operating systems
484 */
485#define EXT2_OS_LINUX		0
486#define EXT2_OS_HURD		1
487#define EXT2_OS_MASIX		2
488#define EXT2_OS_FREEBSD		3
489#define EXT2_OS_LITES		4
490
491/*
492 * Revision levels
493 */
494#define EXT2_GOOD_OLD_REV	0	/* The good old (original) format */
495#define EXT2_DYNAMIC_REV	1 	/* V2 format w/ dynamic inode sizes */
496
497#define EXT2_CURRENT_REV	EXT2_GOOD_OLD_REV
498#define EXT2_MAX_SUPP_REV	EXT2_DYNAMIC_REV
499
500#define EXT2_GOOD_OLD_INODE_SIZE 128
501
502/*
503 * Feature set definitions
504 */
505
506#define EXT2_HAS_COMPAT_FEATURE(sb,mask)			\
507	( EXT2_SB(sb)->s_es->s_feature_compat & cpu_to_le32(mask) )
508#define EXT2_HAS_RO_COMPAT_FEATURE(sb,mask)			\
509	( EXT2_SB(sb)->s_es->s_feature_ro_compat & cpu_to_le32(mask) )
510#define EXT2_HAS_INCOMPAT_FEATURE(sb,mask)			\
511	( EXT2_SB(sb)->s_es->s_feature_incompat & cpu_to_le32(mask) )
512#define EXT2_SET_COMPAT_FEATURE(sb,mask)			\
513	EXT2_SB(sb)->s_es->s_feature_compat |= cpu_to_le32(mask)
514#define EXT2_SET_RO_COMPAT_FEATURE(sb,mask)			\
515	EXT2_SB(sb)->s_es->s_feature_ro_compat |= cpu_to_le32(mask)
516#define EXT2_SET_INCOMPAT_FEATURE(sb,mask)			\
517	EXT2_SB(sb)->s_es->s_feature_incompat |= cpu_to_le32(mask)
518#define EXT2_CLEAR_COMPAT_FEATURE(sb,mask)			\
519	EXT2_SB(sb)->s_es->s_feature_compat &= ~cpu_to_le32(mask)
520#define EXT2_CLEAR_RO_COMPAT_FEATURE(sb,mask)			\
521	EXT2_SB(sb)->s_es->s_feature_ro_compat &= ~cpu_to_le32(mask)
522#define EXT2_CLEAR_INCOMPAT_FEATURE(sb,mask)			\
523	EXT2_SB(sb)->s_es->s_feature_incompat &= ~cpu_to_le32(mask)
524
525#define EXT2_FEATURE_COMPAT_DIR_PREALLOC	0x0001
526#define EXT2_FEATURE_COMPAT_IMAGIC_INODES	0x0002
527#define EXT3_FEATURE_COMPAT_HAS_JOURNAL		0x0004
528#define EXT2_FEATURE_COMPAT_EXT_ATTR		0x0008
529#define EXT2_FEATURE_COMPAT_RESIZE_INO		0x0010
530#define EXT2_FEATURE_COMPAT_DIR_INDEX		0x0020
531#define EXT2_FEATURE_COMPAT_ANY			0xffffffff
532
533#define EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER	0x0001
534#define EXT2_FEATURE_RO_COMPAT_LARGE_FILE	0x0002
535#define EXT2_FEATURE_RO_COMPAT_BTREE_DIR	0x0004
536#define EXT2_FEATURE_RO_COMPAT_ANY		0xffffffff
537
538#define EXT2_FEATURE_INCOMPAT_COMPRESSION	0x0001
539#define EXT2_FEATURE_INCOMPAT_FILETYPE		0x0002
540#define EXT3_FEATURE_INCOMPAT_RECOVER		0x0004
541#define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV	0x0008
542#define EXT2_FEATURE_INCOMPAT_META_BG		0x0010
543#define EXT2_FEATURE_INCOMPAT_ANY		0xffffffff
544
545#define EXT2_FEATURE_COMPAT_SUPP	EXT2_FEATURE_COMPAT_EXT_ATTR
546#define EXT2_FEATURE_INCOMPAT_SUPP	(EXT2_FEATURE_INCOMPAT_FILETYPE| \
547					 EXT2_FEATURE_INCOMPAT_META_BG)
548#define EXT2_FEATURE_RO_COMPAT_SUPP	(EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER| \
549					 EXT2_FEATURE_RO_COMPAT_LARGE_FILE| \
550					 EXT2_FEATURE_RO_COMPAT_BTREE_DIR)
551#define EXT2_FEATURE_RO_COMPAT_UNSUPPORTED	~EXT2_FEATURE_RO_COMPAT_SUPP
552#define EXT2_FEATURE_INCOMPAT_UNSUPPORTED	~EXT2_FEATURE_INCOMPAT_SUPP
553
554/*
555 * Default values for user and/or group using reserved blocks
556 */
557#define	EXT2_DEF_RESUID		0
558#define	EXT2_DEF_RESGID		0
559
560/*
561 * Default mount options
562 */
563#define EXT2_DEFM_DEBUG		0x0001
564#define EXT2_DEFM_BSDGROUPS	0x0002
565#define EXT2_DEFM_XATTR_USER	0x0004
566#define EXT2_DEFM_ACL		0x0008
567#define EXT2_DEFM_UID16		0x0010
568    /* Not used by ext2, but reserved for use by ext3 */
569#define EXT3_DEFM_JMODE		0x0060 
570#define EXT3_DEFM_JMODE_DATA	0x0020
571#define EXT3_DEFM_JMODE_ORDERED	0x0040
572#define EXT3_DEFM_JMODE_WBACK	0x0060
573
574/*
575 * Structure of a directory entry
576 */
577
578struct ext2_dir_entry {
579	__le32	inode;			/* Inode number */
580	__le16	rec_len;		/* Directory entry length */
581	__le16	name_len;		/* Name length */
582	char	name[];			/* File name, up to EXT2_NAME_LEN */
583};
584
585/*
586 * The new version of the directory entry.  Since EXT2 structures are
587 * stored in intel byte order, and the name_len field could never be
588 * bigger than 255 chars, it's safe to reclaim the extra byte for the
589 * file_type field.
590 */
591struct ext2_dir_entry_2 {
592	__le32	inode;			/* Inode number */
593	__le16	rec_len;		/* Directory entry length */
594	__u8	name_len;		/* Name length */
595	__u8	file_type;
596	char	name[];			/* File name, up to EXT2_NAME_LEN */
597};
598
599/*
600 * EXT2_DIR_PAD defines the directory entries boundaries
601 *
602 * NOTE: It must be a multiple of 4
603 */
604#define EXT2_DIR_PAD		 	4
605#define EXT2_DIR_ROUND 			(EXT2_DIR_PAD - 1)
606#define EXT2_DIR_REC_LEN(name_len)	(((name_len) + 8 + EXT2_DIR_ROUND) & \
607					 ~EXT2_DIR_ROUND)
608#define EXT2_MAX_REC_LEN		((1<<16)-1)
609
610static inline void verify_offsets(void)
611{
612#define A(x,y) BUILD_BUG_ON(x != offsetof(struct ext2_super_block, y));
613	A(EXT2_SB_MAGIC_OFFSET, s_magic);
614	A(EXT2_SB_BLOCKS_OFFSET, s_blocks_count);
615	A(EXT2_SB_BSIZE_OFFSET, s_log_block_size);
616#undef A
617}
618
619/*
620 * ext2 mount options
621 */
622struct ext2_mount_options {
623	unsigned long s_mount_opt;
624	kuid_t s_resuid;
625	kgid_t s_resgid;
626};
627
628/*
629 * second extended file system inode data in memory
630 */
631struct ext2_inode_info {
632	__le32	i_data[15];
633	__u32	i_flags;
634	__u32	i_faddr;
635	__u8	i_frag_no;
636	__u8	i_frag_size;
637	__u16	i_state;
638	__u32	i_file_acl;
639	__u32	i_dir_acl;
640	__u32	i_dtime;
641
642	/*
643	 * i_block_group is the number of the block group which contains
644	 * this file's inode.  Constant across the lifetime of the inode,
645	 * it is used for making block allocation decisions - we try to
646	 * place a file's data blocks near its inode block, and new inodes
647	 * near to their parent directory's inode.
648	 */
649	__u32	i_block_group;
650
651	/* block reservation info */
652	struct ext2_block_alloc_info *i_block_alloc_info;
653
654	__u32	i_dir_start_lookup;
655#ifdef CONFIG_EXT2_FS_XATTR
656	/*
657	 * Extended attributes can be read independently of the main file
658	 * data. Taking i_mutex even when reading would cause contention
659	 * between readers of EAs and writers of regular file data, so
660	 * instead we synchronize on xattr_sem when reading or changing
661	 * EAs.
662	 */
663	struct rw_semaphore xattr_sem;
664#endif
665	rwlock_t i_meta_lock;
666
667	/*
668	 * truncate_mutex is for serialising ext2_truncate() against
669	 * ext2_getblock().  It also protects the internals of the inode's
670	 * reservation data structures: ext2_reserve_window and
671	 * ext2_reserve_window_node.
672	 */
673	struct mutex truncate_mutex;
674	struct inode	vfs_inode;
675	struct list_head i_orphan;	/* unlinked but open inodes */
676#ifdef CONFIG_QUOTA
677	struct dquot __rcu *i_dquot[MAXQUOTAS];
678#endif
679};
680
681/*
682 * Inode dynamic state flags
683 */
684#define EXT2_STATE_NEW			0x00000001 /* inode is newly created */
685
686
687/*
688 * Function prototypes
689 */
690
691/*
692 * Ok, these declarations are also in <linux/kernel.h> but none of the
693 * ext2 source programs needs to include it so they are duplicated here.
694 */
695
696static inline struct ext2_inode_info *EXT2_I(struct inode *inode)
697{
698	return container_of(inode, struct ext2_inode_info, vfs_inode);
699}
700
701/* balloc.c */
702extern int ext2_bg_has_super(struct super_block *sb, int group);
703extern unsigned long ext2_bg_num_gdb(struct super_block *sb, int group);
704extern ext2_fsblk_t ext2_new_blocks(struct inode *, ext2_fsblk_t,
705				unsigned long *, int *, unsigned int);
 
706extern int ext2_data_block_valid(struct ext2_sb_info *sbi, ext2_fsblk_t start_blk,
707				 unsigned int count);
708extern void ext2_free_blocks(struct inode *, ext2_fsblk_t, unsigned long);
 
709extern unsigned long ext2_count_free_blocks (struct super_block *);
710extern unsigned long ext2_count_dirs (struct super_block *);
711extern struct ext2_group_desc * ext2_get_group_desc(struct super_block * sb,
712						    unsigned int block_group,
713						    struct buffer_head ** bh);
714extern void ext2_discard_reservation (struct inode *);
715extern int ext2_should_retry_alloc(struct super_block *sb, int *retries);
716extern void ext2_init_block_alloc_info(struct inode *);
717extern void ext2_rsv_window_add(struct super_block *sb, struct ext2_reserve_window_node *rsv);
718
719/* dir.c */
720int ext2_add_link(struct dentry *, struct inode *);
721int ext2_inode_by_name(struct inode *dir,
722			      const struct qstr *child, ino_t *ino);
723int ext2_make_empty(struct inode *, struct inode *);
724struct ext2_dir_entry_2 *ext2_find_entry(struct inode *, const struct qstr *,
725		struct folio **foliop);
726int ext2_delete_entry(struct ext2_dir_entry_2 *dir, struct folio *folio);
727int ext2_empty_dir(struct inode *);
728struct ext2_dir_entry_2 *ext2_dotdot(struct inode *dir, struct folio **foliop);
729int ext2_set_link(struct inode *dir, struct ext2_dir_entry_2 *de,
730		struct folio *folio, struct inode *inode, bool update_times);
 
 
 
 
 
 
731
732/* ialloc.c */
733extern struct inode * ext2_new_inode (struct inode *, umode_t, const struct qstr *);
734extern void ext2_free_inode (struct inode *);
735extern unsigned long ext2_count_free_inodes (struct super_block *);
736extern unsigned long ext2_count_free (struct buffer_head *, unsigned);
737
738/* inode.c */
739extern struct inode *ext2_iget (struct super_block *, unsigned long);
740extern int ext2_write_inode (struct inode *, struct writeback_control *);
741extern void ext2_evict_inode(struct inode *);
742void ext2_write_failed(struct address_space *mapping, loff_t to);
743extern int ext2_get_block(struct inode *, sector_t, struct buffer_head *, int);
744extern int ext2_setattr (struct mnt_idmap *, struct dentry *, struct iattr *);
745extern int ext2_getattr (struct mnt_idmap *, const struct path *,
746			 struct kstat *, u32, unsigned int);
747extern void ext2_set_inode_flags(struct inode *inode);
748extern int ext2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
749		       u64 start, u64 len);
750
751/* ioctl.c */
752extern int ext2_fileattr_get(struct dentry *dentry, struct fileattr *fa);
753extern int ext2_fileattr_set(struct mnt_idmap *idmap,
754			     struct dentry *dentry, struct fileattr *fa);
755extern long ext2_ioctl(struct file *, unsigned int, unsigned long);
756extern long ext2_compat_ioctl(struct file *, unsigned int, unsigned long);
757
758/* namei.c */
759struct dentry *ext2_get_parent(struct dentry *child);
760
761/* super.c */
762extern __printf(3, 4)
763void ext2_error(struct super_block *, const char *, const char *, ...);
764extern __printf(3, 4)
765void ext2_msg(struct super_block *, const char *, const char *, ...);
766extern void ext2_update_dynamic_rev (struct super_block *sb);
767extern void ext2_sync_super(struct super_block *sb, struct ext2_super_block *es,
768			    int wait);
769
770/*
771 * Inodes and files operations
772 */
773
774/* dir.c */
775extern const struct file_operations ext2_dir_operations;
776
777/* file.c */
778extern int ext2_fsync(struct file *file, loff_t start, loff_t end,
779		      int datasync);
780extern const struct inode_operations ext2_file_inode_operations;
781extern const struct file_operations ext2_file_operations;
782
783/* inode.c */
784extern void ext2_set_file_ops(struct inode *inode);
785extern const struct address_space_operations ext2_aops;
786extern const struct iomap_ops ext2_iomap_ops;
787
788/* namei.c */
789extern const struct inode_operations ext2_dir_inode_operations;
790extern const struct inode_operations ext2_special_inode_operations;
791
792/* symlink.c */
793extern const struct inode_operations ext2_fast_symlink_inode_operations;
794extern const struct inode_operations ext2_symlink_inode_operations;
795
796static inline ext2_fsblk_t
797ext2_group_first_block_no(struct super_block *sb, unsigned long group_no)
798{
799	return group_no * (ext2_fsblk_t)EXT2_BLOCKS_PER_GROUP(sb) +
800		le32_to_cpu(EXT2_SB(sb)->s_es->s_first_data_block);
801}
802
803static inline ext2_fsblk_t
804ext2_group_last_block_no(struct super_block *sb, unsigned long group_no)
805{
806	struct ext2_sb_info *sbi = EXT2_SB(sb);
807
808	if (group_no == sbi->s_groups_count - 1)
809		return le32_to_cpu(sbi->s_es->s_blocks_count) - 1;
810	else
811		return ext2_group_first_block_no(sb, group_no) +
812			EXT2_BLOCKS_PER_GROUP(sb) - 1;
813}
814
815#define ext2_set_bit	__test_and_set_bit_le
816#define ext2_clear_bit	__test_and_clear_bit_le
817#define ext2_test_bit	test_bit_le
818#define ext2_find_first_zero_bit	find_first_zero_bit_le
819#define ext2_find_next_zero_bit		find_next_zero_bit_le