VisionFive2 Linux kernel

StarFive Tech Linux Kernel for VisionFive (JH7110) boards (mirror)

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