Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) #ifndef _FAT_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) #define _FAT_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) #include <linux/buffer_head.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include <linux/nls.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/hash.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/ratelimit.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/msdos_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  * vfat shortname flags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #define VFAT_SFN_DISPLAY_LOWER	0x0001 /* convert to lowercase for display */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #define VFAT_SFN_DISPLAY_WIN95	0x0002 /* emulate win95 rule for display */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #define VFAT_SFN_DISPLAY_WINNT	0x0004 /* emulate winnt rule for display */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #define VFAT_SFN_CREATE_WIN95	0x0100 /* emulate win95 rule for create */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #define VFAT_SFN_CREATE_WINNT	0x0200 /* emulate winnt rule for create */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #define FAT_ERRORS_CONT		1      /* ignore error and continue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #define FAT_ERRORS_PANIC	2      /* panic on error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #define FAT_ERRORS_RO		3      /* remount r/o on error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #define FAT_NFS_STALE_RW	1      /* NFS RW support, can cause ESTALE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #define FAT_NFS_NOSTALE_RO	2      /* NFS RO support, no ESTALE issue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) struct fat_mount_options {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	kuid_t fs_uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	kgid_t fs_gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	unsigned short fs_fmask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	unsigned short fs_dmask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	unsigned short codepage;   /* Codepage for shortname conversions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	int time_offset;	   /* Offset of timestamps from UTC (in minutes) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	char *iocharset;           /* Charset used for filename input/display */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	unsigned short shortname;  /* flags for shortname display/create rule */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	unsigned char name_check;  /* r = relaxed, n = normal, s = strict */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	unsigned char errors;	   /* On error: continue, panic, remount-ro */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	unsigned char nfs;	  /* NFS support: nostale_ro, stale_rw */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	unsigned short allow_utime;/* permission for setting the [am]time */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	unsigned quiet:1,          /* set = fake successful chmods and chowns */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 		 showexec:1,       /* set = only set x bit for com/exe/bat */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 		 sys_immutable:1,  /* set = system files are immutable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 		 dotsOK:1,         /* set = hidden and system files are named '.filename' */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 		 isvfat:1,         /* 0=no vfat long filename support, 1=vfat support */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 		 utf8:1,	   /* Use of UTF-8 character set (Default) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		 unicode_xlate:1,  /* create escape sequences for unhandled Unicode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		 numtail:1,        /* Does first alias have a numeric '~1' type tail? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 		 flush:1,	   /* write things quickly */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 		 nocase:1,	   /* Does this need case conversion? 0=need case conversion*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		 usefree:1,	   /* Use free_clusters for FAT32 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 		 tz_set:1,	   /* Filesystem timestamps' offset set */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 		 rodir:1,	   /* allow ATTR_RO for directory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 		 discard:1,	   /* Issue discard requests on deletions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		 dos1xfloppy:1;	   /* Assume default BPB for DOS 1.x floppies */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) #define FAT_HASH_BITS	8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) #define FAT_HASH_SIZE	(1UL << FAT_HASH_BITS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61)  * MS-DOS file system in-core superblock data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) struct msdos_sb_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	unsigned short sec_per_clus;  /* sectors/cluster */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	unsigned short cluster_bits;  /* log2(cluster_size) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	unsigned int cluster_size;    /* cluster size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	unsigned char fats, fat_bits; /* number of FATs, FAT bits (12,16 or 32) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	unsigned short fat_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	unsigned long fat_length;     /* FAT start & length (sec.) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	unsigned long dir_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	unsigned short dir_entries;   /* root dir start & entries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	unsigned long data_start;     /* first data sector */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	unsigned long max_cluster;    /* maximum cluster number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	unsigned long root_cluster;   /* first cluster of the root directory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	unsigned long fsinfo_sector;  /* sector number of FAT32 fsinfo */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	struct mutex fat_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	struct mutex nfs_build_inode_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	struct mutex s_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	unsigned int prev_free;      /* previously allocated cluster number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	unsigned int free_clusters;  /* -1 if undefined */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	unsigned int free_clus_valid; /* is free_clusters valid? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	struct fat_mount_options options;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	struct nls_table *nls_disk;   /* Codepage used on disk */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	struct nls_table *nls_io;     /* Charset used for input and display */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	const void *dir_ops;	      /* Opaque; default directory operations */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	int dir_per_block;	      /* dir entries per block */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	int dir_per_block_bits;	      /* log2(dir_per_block) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	unsigned int vol_id;		/*volume ID*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	int fatent_shift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	const struct fatent_operations *fatent_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	struct inode *fat_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	struct inode *fsinfo_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	struct ratelimit_state ratelimit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	spinlock_t inode_hash_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	struct hlist_head inode_hashtable[FAT_HASH_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	spinlock_t dir_hash_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	struct hlist_head dir_hashtable[FAT_HASH_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	unsigned int dirty;           /* fs state before mount */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	struct rcu_head rcu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) #define FAT_CACHE_VALID	0	/* special case for valid cache */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)  * MS-DOS file system inode data in memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) struct msdos_inode_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	spinlock_t cache_lru_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	struct list_head cache_lru;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	int nr_caches;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	/* for avoiding the race between fat_free() and fat_get_cluster() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	unsigned int cache_valid_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	/* NOTE: mmu_private is 64bits, so must hold ->i_mutex to access */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	loff_t mmu_private;	/* physically allocated size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	int i_start;		/* first cluster or 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	int i_logstart;		/* logical first cluster */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	int i_attrs;		/* unused attribute bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	loff_t i_pos;		/* on-disk position of directory entry or 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	struct hlist_node i_fat_hash;	/* hash by i_location */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	struct hlist_node i_dir_hash;	/* hash by i_logstart */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	struct rw_semaphore truncate_lock; /* protect bmap against truncate */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	struct inode vfs_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) struct fat_slot_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	loff_t i_pos;		/* on-disk position of directory entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	loff_t slot_off;	/* offset for slot or de start */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	int nr_slots;		/* number of slots + 1(de) in filename */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	struct msdos_dir_entry *de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	struct buffer_head *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) static inline struct msdos_sb_info *MSDOS_SB(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	return sb->s_fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)  * Functions that determine the variant of the FAT file system (i.e.,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)  * whether this is FAT12, FAT16 or FAT32.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) static inline bool is_fat12(const struct msdos_sb_info *sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	return sbi->fat_bits == 12;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) static inline bool is_fat16(const struct msdos_sb_info *sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	return sbi->fat_bits == 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) static inline bool is_fat32(const struct msdos_sb_info *sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	return sbi->fat_bits == 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) /* Maximum number of clusters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) static inline u32 max_fat(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	struct msdos_sb_info *sbi = MSDOS_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	return is_fat32(sbi) ? MAX_FAT32 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		is_fat16(sbi) ? MAX_FAT16 : MAX_FAT12;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) static inline struct msdos_inode_info *MSDOS_I(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	return container_of(inode, struct msdos_inode_info, vfs_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)  * If ->i_mode can't hold S_IWUGO (i.e. ATTR_RO), we use ->i_attrs to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)  * save ATTR_RO instead of ->i_mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)  * If it's directory and !sbi->options.rodir, ATTR_RO isn't read-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)  * bit, it's just used as flag for app.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) static inline int fat_mode_can_hold_ro(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	struct msdos_sb_info *sbi = MSDOS_SB(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	umode_t mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	if (S_ISDIR(inode->i_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		if (!sbi->options.rodir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		mask = ~sbi->options.fs_dmask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		mask = ~sbi->options.fs_fmask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	if (!(mask & S_IWUGO))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) /* Convert attribute bits and a mask to the UNIX mode. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) static inline umode_t fat_make_mode(struct msdos_sb_info *sbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 				   u8 attrs, umode_t mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	if (attrs & ATTR_RO && !((attrs & ATTR_DIR) && !sbi->options.rodir))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		mode &= ~S_IWUGO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	if (attrs & ATTR_DIR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		return (mode & ~sbi->options.fs_dmask) | S_IFDIR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		return (mode & ~sbi->options.fs_fmask) | S_IFREG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) /* Return the FAT attribute byte for this inode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) static inline u8 fat_make_attrs(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	u8 attrs = MSDOS_I(inode)->i_attrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	if (S_ISDIR(inode->i_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		attrs |= ATTR_DIR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	if (fat_mode_can_hold_ro(inode) && !(inode->i_mode & S_IWUGO))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		attrs |= ATTR_RO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	return attrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) static inline void fat_save_attrs(struct inode *inode, u8 attrs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	if (fat_mode_can_hold_ro(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		MSDOS_I(inode)->i_attrs = attrs & ATTR_UNUSED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		MSDOS_I(inode)->i_attrs = attrs & (ATTR_UNUSED | ATTR_RO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) static inline unsigned char fat_checksum(const __u8 *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	unsigned char s = name[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	s = (s<<7) + (s>>1) + name[1];	s = (s<<7) + (s>>1) + name[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	s = (s<<7) + (s>>1) + name[3];	s = (s<<7) + (s>>1) + name[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	s = (s<<7) + (s>>1) + name[5];	s = (s<<7) + (s>>1) + name[6];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	s = (s<<7) + (s>>1) + name[7];	s = (s<<7) + (s>>1) + name[8];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	s = (s<<7) + (s>>1) + name[9];	s = (s<<7) + (s>>1) + name[10];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	return s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) static inline sector_t fat_clus_to_blknr(struct msdos_sb_info *sbi, int clus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	return ((sector_t)clus - FAT_START_ENT) * sbi->sec_per_clus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 		+ sbi->data_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) static inline void fat_get_blknr_offset(struct msdos_sb_info *sbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 				loff_t i_pos, sector_t *blknr, int *offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	*blknr = i_pos >> sbi->dir_per_block_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	*offset = i_pos & (sbi->dir_per_block - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) static inline loff_t fat_i_pos_read(struct msdos_sb_info *sbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 					struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	loff_t i_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) #if BITS_PER_LONG == 32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	spin_lock(&sbi->inode_hash_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	i_pos = MSDOS_I(inode)->i_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) #if BITS_PER_LONG == 32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	spin_unlock(&sbi->inode_hash_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	return i_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) static inline void fat16_towchar(wchar_t *dst, const __u8 *src, size_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) #ifdef __BIG_ENDIAN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	while (len--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		*dst++ = src[0] | (src[1] << 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 		src += 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	memcpy(dst, src, len * 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) static inline int fat_get_start(const struct msdos_sb_info *sbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 				const struct msdos_dir_entry *de)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	int cluster = le16_to_cpu(de->start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	if (is_fat32(sbi))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 		cluster |= (le16_to_cpu(de->starthi) << 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	return cluster;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) static inline void fat_set_start(struct msdos_dir_entry *de, int cluster)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	de->start   = cpu_to_le16(cluster);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	de->starthi = cpu_to_le16(cluster >> 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) static inline void fatwchar_to16(__u8 *dst, const wchar_t *src, size_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) #ifdef __BIG_ENDIAN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	while (len--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		dst[0] = *src & 0x00FF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 		dst[1] = (*src & 0xFF00) >> 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		dst += 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 		src++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	memcpy(dst, src, len * 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) /* fat/cache.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) extern void fat_cache_inval_inode(struct inode *inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) extern int fat_get_cluster(struct inode *inode, int cluster,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 			   int *fclus, int *dclus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) extern int fat_get_mapped_cluster(struct inode *inode, sector_t sector,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 				  sector_t last_block,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 				  unsigned long *mapped_blocks, sector_t *bmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) extern int fat_bmap(struct inode *inode, sector_t sector, sector_t *phys,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 		    unsigned long *mapped_blocks, int create, bool from_bmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) /* fat/dir.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) extern const struct file_operations fat_dir_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) extern int fat_search_long(struct inode *inode, const unsigned char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 			   int name_len, struct fat_slot_info *sinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) extern int fat_dir_empty(struct inode *dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) extern int fat_subdirs(struct inode *dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) extern int fat_scan(struct inode *dir, const unsigned char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 		    struct fat_slot_info *sinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) extern int fat_scan_logstart(struct inode *dir, int i_logstart,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 			     struct fat_slot_info *sinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) extern int fat_get_dotdot_entry(struct inode *dir, struct buffer_head **bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 				struct msdos_dir_entry **de);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) extern int fat_alloc_new_dir(struct inode *dir, struct timespec64 *ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) extern int fat_add_entries(struct inode *dir, void *slots, int nr_slots,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 			   struct fat_slot_info *sinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) extern int fat_remove_entries(struct inode *dir, struct fat_slot_info *sinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) /* fat/fatent.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) struct fat_entry {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	int entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 		u8 *ent12_p[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 		__le16 *ent16_p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 		__le32 *ent32_p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	} u;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	int nr_bhs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	struct buffer_head *bhs[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	struct inode *fat_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) static inline void fatent_init(struct fat_entry *fatent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	fatent->nr_bhs = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	fatent->entry = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	fatent->u.ent32_p = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	fatent->bhs[0] = fatent->bhs[1] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	fatent->fat_inode = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) static inline void fatent_set_entry(struct fat_entry *fatent, int entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	fatent->entry = entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	fatent->u.ent32_p = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) static inline void fatent_brelse(struct fat_entry *fatent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	fatent->u.ent32_p = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	for (i = 0; i < fatent->nr_bhs; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 		brelse(fatent->bhs[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	fatent->nr_bhs = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	fatent->bhs[0] = fatent->bhs[1] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	fatent->fat_inode = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) static inline bool fat_valid_entry(struct msdos_sb_info *sbi, int entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	return FAT_START_ENT <= entry && entry < sbi->max_cluster;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) extern void fat_ent_access_init(struct super_block *sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) extern int fat_ent_read(struct inode *inode, struct fat_entry *fatent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 			int entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) extern int fat_ent_write(struct inode *inode, struct fat_entry *fatent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 			 int new, int wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) extern int fat_alloc_clusters(struct inode *inode, int *cluster,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 			      int nr_cluster);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) extern int fat_free_clusters(struct inode *inode, int cluster);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) extern int fat_count_free_clusters(struct super_block *sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) extern int fat_trim_fs(struct inode *inode, struct fstrim_range *range);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) /* fat/file.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) extern long fat_generic_ioctl(struct file *filp, unsigned int cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 			      unsigned long arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) extern const struct file_operations fat_file_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) extern const struct inode_operations fat_file_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) extern int fat_setattr(struct dentry *dentry, struct iattr *attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) extern void fat_truncate_blocks(struct inode *inode, loff_t offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) extern int fat_getattr(const struct path *path, struct kstat *stat,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 		       u32 request_mask, unsigned int flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) extern int fat_file_fsync(struct file *file, loff_t start, loff_t end,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 			  int datasync);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) /* fat/inode.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) extern int fat_block_truncate_page(struct inode *inode, loff_t from);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) extern void fat_attach(struct inode *inode, loff_t i_pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) extern void fat_detach(struct inode *inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) extern struct inode *fat_iget(struct super_block *sb, loff_t i_pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) extern struct inode *fat_build_inode(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 			struct msdos_dir_entry *de, loff_t i_pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) extern int fat_sync_inode(struct inode *inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) extern int fat_fill_super(struct super_block *sb, void *data, int silent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 			  int isvfat, void (*setup)(struct super_block *));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) extern int fat_fill_inode(struct inode *inode, struct msdos_dir_entry *de);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) extern int fat_flush_inodes(struct super_block *sb, struct inode *i1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 			    struct inode *i2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) static inline unsigned long fat_dir_hash(int logstart)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	return hash_32(logstart, FAT_HASH_BITS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) extern int fat_add_cluster(struct inode *inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) /* fat/misc.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) extern __printf(3, 4) __cold
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) void __fat_fs_error(struct super_block *sb, int report, const char *fmt, ...);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) #define fat_fs_error(sb, fmt, args...)		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	__fat_fs_error(sb, 1, fmt , ## args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) #define fat_fs_error_ratelimit(sb, fmt, args...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	__fat_fs_error(sb, __ratelimit(&MSDOS_SB(sb)->ratelimit), fmt , ## args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) __printf(3, 4) __cold
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) void fat_msg(struct super_block *sb, const char *level, const char *fmt, ...);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) #define fat_msg_ratelimit(sb, level, fmt, args...)	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	do {	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 			if (__ratelimit(&MSDOS_SB(sb)->ratelimit))	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 				fat_msg(sb, level, fmt, ## args);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	 } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) extern int fat_clusters_flush(struct super_block *sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) extern int fat_chain_add(struct inode *inode, int new_dclus, int nr_cluster);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) extern void fat_time_fat2unix(struct msdos_sb_info *sbi, struct timespec64 *ts,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 			      __le16 __time, __le16 __date, u8 time_cs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) extern void fat_time_unix2fat(struct msdos_sb_info *sbi, struct timespec64 *ts,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 			      __le16 *time, __le16 *date, u8 *time_cs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) extern int fat_truncate_time(struct inode *inode, struct timespec64 *now,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 			     int flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) extern int fat_update_time(struct inode *inode, struct timespec64 *now,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 			   int flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) extern int fat_sync_bhs(struct buffer_head **bhs, int nr_bhs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) int fat_cache_init(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) void fat_cache_destroy(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) /* fat/nfs.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) extern const struct export_operations fat_export_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) extern const struct export_operations fat_export_ops_nostale;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) /* helper for printk */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) typedef unsigned long long	llu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) #endif /* !_FAT_H */