exfat_fs.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Copyright (C) 2012-2013 Samsung Electronics Co., Ltd.
  4. */
  5. #ifndef _EXFAT_FS_H
  6. #define _EXFAT_FS_H
  7. #include <linux/fs.h>
  8. #include <linux/ratelimit.h>
  9. #include <linux/nls.h>
  10. #include <linux/blkdev.h>
  11. #include <uapi/linux/exfat.h>
  12. #define EXFAT_ROOT_INO 1
  13. #define EXFAT_CLUSTERS_UNTRACKED (~0u)
  14. /*
  15. * exfat error flags
  16. */
  17. enum exfat_error_mode {
  18. EXFAT_ERRORS_CONT, /* ignore error and continue */
  19. EXFAT_ERRORS_PANIC, /* panic on error */
  20. EXFAT_ERRORS_RO, /* remount r/o on error */
  21. };
  22. /*
  23. * exfat nls lossy flag
  24. */
  25. enum {
  26. NLS_NAME_NO_LOSSY = 0, /* no lossy */
  27. NLS_NAME_LOSSY = 1 << 0, /* just detected incorrect filename(s) */
  28. NLS_NAME_OVERLEN = 1 << 1, /* the length is over than its limit */
  29. };
  30. #define EXFAT_HASH_BITS 8
  31. #define EXFAT_HASH_SIZE (1UL << EXFAT_HASH_BITS)
  32. /*
  33. * Type Definitions
  34. */
  35. #define ES_2_ENTRIES 2
  36. #define ES_ALL_ENTRIES 0
  37. #define ES_IDX_FILE 0
  38. #define ES_IDX_STREAM 1
  39. #define ES_IDX_FIRST_FILENAME 2
  40. #define EXFAT_FILENAME_ENTRY_NUM(name_len) \
  41. DIV_ROUND_UP(name_len, EXFAT_FILE_NAME_LEN)
  42. #define ES_IDX_LAST_FILENAME(name_len) \
  43. (ES_IDX_FIRST_FILENAME + EXFAT_FILENAME_ENTRY_NUM(name_len) - 1)
  44. #define DIR_DELETED 0xFFFFFFF7
  45. /* type values */
  46. #define TYPE_UNUSED 0x0000
  47. #define TYPE_DELETED 0x0001
  48. #define TYPE_INVALID 0x0002
  49. #define TYPE_CRITICAL_PRI 0x0100
  50. #define TYPE_BITMAP 0x0101
  51. #define TYPE_UPCASE 0x0102
  52. #define TYPE_VOLUME 0x0103
  53. #define TYPE_DIR 0x0104
  54. #define TYPE_FILE 0x011F
  55. #define TYPE_CRITICAL_SEC 0x0200
  56. #define TYPE_STREAM 0x0201
  57. #define TYPE_EXTEND 0x0202
  58. #define TYPE_ACL 0x0203
  59. #define TYPE_BENIGN_PRI 0x0400
  60. #define TYPE_GUID 0x0401
  61. #define TYPE_PADDING 0x0402
  62. #define TYPE_ACLTAB 0x0403
  63. #define TYPE_BENIGN_SEC 0x0800
  64. #define TYPE_VENDOR_EXT 0x0801
  65. #define TYPE_VENDOR_ALLOC 0x0802
  66. #define MAX_CHARSET_SIZE 6 /* max size of multi-byte character */
  67. #define MAX_NAME_LENGTH 255 /* max len of file name excluding NULL */
  68. #define MAX_VFSNAME_BUF_SIZE ((MAX_NAME_LENGTH + 1) * MAX_CHARSET_SIZE)
  69. #define EXFAT_HINT_NONE -1
  70. #define EXFAT_MIN_SUBDIR 2
  71. /*
  72. * helpers for cluster size to byte conversion.
  73. */
  74. #define EXFAT_CLU_TO_B(b, sbi) ((b) << (sbi)->cluster_size_bits)
  75. #define EXFAT_B_TO_CLU(b, sbi) ((b) >> (sbi)->cluster_size_bits)
  76. #define EXFAT_B_TO_CLU_ROUND_UP(b, sbi) \
  77. (((b - 1) >> (sbi)->cluster_size_bits) + 1)
  78. #define EXFAT_CLU_OFFSET(off, sbi) ((off) & ((sbi)->cluster_size - 1))
  79. /*
  80. * helpers for block size to byte conversion.
  81. */
  82. #define EXFAT_BLK_TO_B(b, sb) ((b) << (sb)->s_blocksize_bits)
  83. #define EXFAT_B_TO_BLK(b, sb) ((b) >> (sb)->s_blocksize_bits)
  84. #define EXFAT_B_TO_BLK_ROUND_UP(b, sb) \
  85. (((b - 1) >> (sb)->s_blocksize_bits) + 1)
  86. #define EXFAT_BLK_OFFSET(off, sb) ((off) & ((sb)->s_blocksize - 1))
  87. /*
  88. * helpers for block size to dentry size conversion.
  89. */
  90. #define EXFAT_B_TO_DEN(b) ((b) >> DENTRY_SIZE_BITS)
  91. #define EXFAT_DEN_TO_B(b) ((b) << DENTRY_SIZE_BITS)
  92. /*
  93. * helpers for cluster size to dentry size conversion.
  94. */
  95. #define EXFAT_CLU_TO_DEN(clu, sbi) \
  96. ((clu) << ((sbi)->cluster_size_bits - DENTRY_SIZE_BITS))
  97. #define EXFAT_DEN_TO_CLU(dentry, sbi) \
  98. ((dentry) >> ((sbi)->cluster_size_bits - DENTRY_SIZE_BITS))
  99. /*
  100. * helpers for fat entry.
  101. */
  102. #define FAT_ENT_SIZE (4)
  103. #define FAT_ENT_SIZE_BITS (2)
  104. #define FAT_ENT_OFFSET_SECTOR(sb, loc) (EXFAT_SB(sb)->FAT1_start_sector + \
  105. (((u64)loc << FAT_ENT_SIZE_BITS) >> sb->s_blocksize_bits))
  106. #define FAT_ENT_OFFSET_BYTE_IN_SECTOR(sb, loc) \
  107. ((loc << FAT_ENT_SIZE_BITS) & (sb->s_blocksize - 1))
  108. /*
  109. * helpers for bitmap.
  110. */
  111. #define CLUSTER_TO_BITMAP_ENT(clu) ((clu) - EXFAT_RESERVED_CLUSTERS)
  112. #define BITMAP_ENT_TO_CLUSTER(ent) ((ent) + EXFAT_RESERVED_CLUSTERS)
  113. #define BITS_PER_SECTOR(sb) ((sb)->s_blocksize * BITS_PER_BYTE)
  114. #define BITS_PER_SECTOR_MASK(sb) (BITS_PER_SECTOR(sb) - 1)
  115. #define BITMAP_OFFSET_SECTOR_INDEX(sb, ent) \
  116. ((ent / BITS_PER_BYTE) >> (sb)->s_blocksize_bits)
  117. #define BITMAP_OFFSET_BIT_IN_SECTOR(sb, ent) (ent & BITS_PER_SECTOR_MASK(sb))
  118. #define BITMAP_OFFSET_BYTE_IN_SECTOR(sb, ent) \
  119. ((ent / BITS_PER_BYTE) & ((sb)->s_blocksize - 1))
  120. #define IGNORED_BITS_REMAINED(clu, clu_base) ((1UL << ((clu) - (clu_base))) - 1)
  121. #define ES_ENTRY_NUM(name_len) (ES_IDX_LAST_FILENAME(name_len) + 1)
  122. /* 19 entries = 1 file entry + 1 stream entry + 17 filename entries */
  123. #define ES_MAX_ENTRY_NUM ES_ENTRY_NUM(MAX_NAME_LENGTH)
  124. /*
  125. * 19 entries x 32 bytes/entry = 608 bytes.
  126. * The 608 bytes are in 3 sectors at most (even 512 Byte sector).
  127. */
  128. #define DIR_CACHE_SIZE \
  129. (DIV_ROUND_UP(EXFAT_DEN_TO_B(ES_MAX_ENTRY_NUM), SECTOR_SIZE) + 1)
  130. /* Superblock flags */
  131. #define EXFAT_FLAGS_SHUTDOWN 1
  132. struct exfat_dentry_namebuf {
  133. char *lfn;
  134. int lfnbuf_len; /* usually MAX_UNINAME_BUF_SIZE */
  135. };
  136. /* unicode name structure */
  137. struct exfat_uni_name {
  138. /* +3 for null and for converting */
  139. unsigned short name[MAX_NAME_LENGTH + 3];
  140. u16 name_hash;
  141. unsigned char name_len;
  142. };
  143. /* directory structure */
  144. struct exfat_chain {
  145. unsigned int dir;
  146. unsigned int size;
  147. unsigned char flags;
  148. };
  149. /* first empty entry hint information */
  150. struct exfat_hint_femp {
  151. /* entry index of a directory */
  152. int eidx;
  153. /* count of continuous empty entry */
  154. int count;
  155. /* the cluster that first empty slot exists in */
  156. struct exfat_chain cur;
  157. };
  158. /* hint structure */
  159. struct exfat_hint {
  160. unsigned int clu;
  161. union {
  162. unsigned int off; /* cluster offset */
  163. int eidx; /* entry index */
  164. };
  165. };
  166. struct exfat_entry_set_cache {
  167. struct super_block *sb;
  168. unsigned int start_off;
  169. int num_bh;
  170. struct buffer_head *__bh[DIR_CACHE_SIZE];
  171. struct buffer_head **bh;
  172. unsigned int num_entries;
  173. bool modified;
  174. };
  175. #define IS_DYNAMIC_ES(es) ((es)->__bh != (es)->bh)
  176. struct exfat_dir_entry {
  177. struct exfat_chain dir;
  178. int entry;
  179. unsigned int type;
  180. unsigned int start_clu;
  181. unsigned char flags;
  182. unsigned short attr;
  183. loff_t size;
  184. loff_t valid_size;
  185. unsigned int num_subdirs;
  186. struct timespec64 atime;
  187. struct timespec64 mtime;
  188. struct timespec64 crtime;
  189. struct exfat_dentry_namebuf namebuf;
  190. };
  191. /*
  192. * exfat mount in-memory data
  193. */
  194. struct exfat_mount_options {
  195. kuid_t fs_uid;
  196. kgid_t fs_gid;
  197. unsigned short fs_fmask;
  198. unsigned short fs_dmask;
  199. /* permission for setting the [am]time */
  200. unsigned short allow_utime;
  201. /* charset for filename input/display */
  202. char *iocharset;
  203. /* on error: continue, panic, remount-ro */
  204. enum exfat_error_mode errors;
  205. unsigned utf8:1, /* Use of UTF-8 character set */
  206. sys_tz:1, /* Use local timezone */
  207. discard:1, /* Issue discard requests on deletions */
  208. keep_last_dots:1; /* Keep trailing periods in paths */
  209. int time_offset; /* Offset of timestamps from UTC (in minutes) */
  210. /* Support creating zero-size directory, default: false */
  211. bool zero_size_dir;
  212. };
  213. /*
  214. * EXFAT file system superblock in-memory data
  215. */
  216. struct exfat_sb_info {
  217. unsigned long long num_sectors; /* num of sectors in volume */
  218. unsigned int num_clusters; /* num of clusters in volume */
  219. unsigned int cluster_size; /* cluster size in bytes */
  220. unsigned int cluster_size_bits;
  221. unsigned int sect_per_clus; /* cluster size in sectors */
  222. unsigned int sect_per_clus_bits;
  223. unsigned long long FAT1_start_sector; /* FAT1 start sector */
  224. unsigned long long FAT2_start_sector; /* FAT2 start sector */
  225. unsigned long long data_start_sector; /* data area start sector */
  226. unsigned int num_FAT_sectors; /* num of FAT sectors */
  227. unsigned int root_dir; /* root dir cluster */
  228. unsigned int dentries_per_clu; /* num of dentries per cluster */
  229. unsigned int vol_flags; /* volume flags */
  230. unsigned int vol_flags_persistent; /* volume flags to retain */
  231. struct buffer_head *boot_bh; /* buffer_head of BOOT sector */
  232. unsigned int map_clu; /* allocation bitmap start cluster */
  233. unsigned int map_sectors; /* num of allocation bitmap sectors */
  234. struct buffer_head **vol_amap; /* allocation bitmap */
  235. unsigned short *vol_utbl; /* upcase table */
  236. unsigned int clu_srch_ptr; /* cluster search pointer */
  237. unsigned int used_clusters; /* number of used clusters */
  238. unsigned long s_exfat_flags; /* Exfat superblock flags */
  239. struct mutex s_lock; /* superblock lock */
  240. struct mutex bitmap_lock; /* bitmap lock */
  241. struct exfat_mount_options options;
  242. struct nls_table *nls_io; /* Charset used for input and display */
  243. struct ratelimit_state ratelimit;
  244. spinlock_t inode_hash_lock;
  245. struct hlist_head inode_hashtable[EXFAT_HASH_SIZE];
  246. struct rcu_head rcu;
  247. };
  248. #define EXFAT_CACHE_VALID 0
  249. /*
  250. * EXFAT file system inode in-memory data
  251. */
  252. struct exfat_inode_info {
  253. struct exfat_chain dir;
  254. int entry;
  255. unsigned int type;
  256. unsigned short attr;
  257. unsigned int start_clu;
  258. unsigned char flags;
  259. /*
  260. * the copy of low 32bit of i_version to check
  261. * the validation of hint_stat.
  262. */
  263. unsigned int version;
  264. /* hint for cluster last accessed */
  265. struct exfat_hint hint_bmap;
  266. /* hint for entry index we try to lookup next time */
  267. struct exfat_hint hint_stat;
  268. /* hint for first empty entry */
  269. struct exfat_hint_femp hint_femp;
  270. spinlock_t cache_lru_lock;
  271. struct list_head cache_lru;
  272. int nr_caches;
  273. /* for avoiding the race between alloc and free */
  274. unsigned int cache_valid_id;
  275. /* on-disk position of directory entry or 0 */
  276. loff_t i_pos;
  277. loff_t valid_size;
  278. /* hash by i_location */
  279. struct hlist_node i_hash_fat;
  280. /* protect bmap against truncate */
  281. struct rw_semaphore truncate_lock;
  282. struct inode vfs_inode;
  283. /* File creation time */
  284. struct timespec64 i_crtime;
  285. };
  286. static inline struct exfat_sb_info *EXFAT_SB(struct super_block *sb)
  287. {
  288. return sb->s_fs_info;
  289. }
  290. static inline struct exfat_inode_info *EXFAT_I(struct inode *inode)
  291. {
  292. return container_of(inode, struct exfat_inode_info, vfs_inode);
  293. }
  294. static inline int exfat_forced_shutdown(struct super_block *sb)
  295. {
  296. return test_bit(EXFAT_FLAGS_SHUTDOWN, &EXFAT_SB(sb)->s_exfat_flags);
  297. }
  298. /*
  299. * If ->i_mode can't hold 0222 (i.e. ATTR_RO), we use ->i_attrs to
  300. * save ATTR_RO instead of ->i_mode.
  301. *
  302. * If it's directory and !sbi->options.rodir, ATTR_RO isn't read-only
  303. * bit, it's just used as flag for app.
  304. */
  305. static inline int exfat_mode_can_hold_ro(struct inode *inode)
  306. {
  307. struct exfat_sb_info *sbi = EXFAT_SB(inode->i_sb);
  308. if (S_ISDIR(inode->i_mode))
  309. return 0;
  310. if ((~sbi->options.fs_fmask) & 0222)
  311. return 1;
  312. return 0;
  313. }
  314. /* Convert attribute bits and a mask to the UNIX mode. */
  315. static inline mode_t exfat_make_mode(struct exfat_sb_info *sbi,
  316. unsigned short attr, mode_t mode)
  317. {
  318. if ((attr & EXFAT_ATTR_READONLY) && !(attr & EXFAT_ATTR_SUBDIR))
  319. mode &= ~0222;
  320. if (attr & EXFAT_ATTR_SUBDIR)
  321. return (mode & ~sbi->options.fs_dmask) | S_IFDIR;
  322. return (mode & ~sbi->options.fs_fmask) | S_IFREG;
  323. }
  324. /* Return the FAT attribute byte for this inode */
  325. static inline unsigned short exfat_make_attr(struct inode *inode)
  326. {
  327. unsigned short attr = EXFAT_I(inode)->attr;
  328. if (S_ISDIR(inode->i_mode))
  329. attr |= EXFAT_ATTR_SUBDIR;
  330. if (exfat_mode_can_hold_ro(inode) && !(inode->i_mode & 0222))
  331. attr |= EXFAT_ATTR_READONLY;
  332. return attr;
  333. }
  334. static inline void exfat_save_attr(struct inode *inode, unsigned short attr)
  335. {
  336. if (exfat_mode_can_hold_ro(inode))
  337. EXFAT_I(inode)->attr = attr & (EXFAT_ATTR_RWMASK | EXFAT_ATTR_READONLY);
  338. else
  339. EXFAT_I(inode)->attr = attr & EXFAT_ATTR_RWMASK;
  340. }
  341. static inline bool exfat_is_last_sector_in_cluster(struct exfat_sb_info *sbi,
  342. sector_t sec)
  343. {
  344. return ((sec - sbi->data_start_sector + 1) &
  345. ((1 << sbi->sect_per_clus_bits) - 1)) == 0;
  346. }
  347. static inline sector_t exfat_cluster_to_sector(struct exfat_sb_info *sbi,
  348. unsigned int clus)
  349. {
  350. return ((sector_t)(clus - EXFAT_RESERVED_CLUSTERS) << sbi->sect_per_clus_bits) +
  351. sbi->data_start_sector;
  352. }
  353. static inline unsigned int exfat_sector_to_cluster(struct exfat_sb_info *sbi,
  354. sector_t sec)
  355. {
  356. return ((sec - sbi->data_start_sector) >> sbi->sect_per_clus_bits) +
  357. EXFAT_RESERVED_CLUSTERS;
  358. }
  359. static inline bool is_valid_cluster(struct exfat_sb_info *sbi,
  360. unsigned int clus)
  361. {
  362. return clus >= EXFAT_FIRST_CLUSTER && clus < sbi->num_clusters;
  363. }
  364. static inline loff_t exfat_ondisk_size(const struct inode *inode)
  365. {
  366. return ((loff_t)inode->i_blocks) << 9;
  367. }
  368. /* super.c */
  369. int exfat_set_volume_dirty(struct super_block *sb);
  370. int exfat_clear_volume_dirty(struct super_block *sb);
  371. /* fatent.c */
  372. #define exfat_get_next_cluster(sb, pclu) exfat_ent_get(sb, *(pclu), pclu)
  373. int exfat_alloc_cluster(struct inode *inode, unsigned int num_alloc,
  374. struct exfat_chain *p_chain, bool sync_bmap);
  375. int exfat_free_cluster(struct inode *inode, struct exfat_chain *p_chain);
  376. int exfat_ent_get(struct super_block *sb, unsigned int loc,
  377. unsigned int *content);
  378. int exfat_ent_set(struct super_block *sb, unsigned int loc,
  379. unsigned int content);
  380. int exfat_chain_cont_cluster(struct super_block *sb, unsigned int chain,
  381. unsigned int len);
  382. int exfat_zeroed_cluster(struct inode *dir, unsigned int clu);
  383. int exfat_find_last_cluster(struct super_block *sb, struct exfat_chain *p_chain,
  384. unsigned int *ret_clu);
  385. int exfat_count_num_clusters(struct super_block *sb,
  386. struct exfat_chain *p_chain, unsigned int *ret_count);
  387. /* balloc.c */
  388. int exfat_load_bitmap(struct super_block *sb);
  389. void exfat_free_bitmap(struct exfat_sb_info *sbi);
  390. int exfat_set_bitmap(struct inode *inode, unsigned int clu, bool sync);
  391. int exfat_clear_bitmap(struct inode *inode, unsigned int clu, bool sync);
  392. unsigned int exfat_find_free_bitmap(struct super_block *sb, unsigned int clu);
  393. int exfat_count_used_clusters(struct super_block *sb, unsigned int *ret_count);
  394. int exfat_trim_fs(struct inode *inode, struct fstrim_range *range);
  395. /* file.c */
  396. extern const struct file_operations exfat_file_operations;
  397. int __exfat_truncate(struct inode *inode);
  398. void exfat_truncate(struct inode *inode);
  399. int exfat_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
  400. struct iattr *attr);
  401. int exfat_getattr(struct mnt_idmap *idmap, const struct path *path,
  402. struct kstat *stat, unsigned int request_mask,
  403. unsigned int query_flags);
  404. int exfat_file_fsync(struct file *file, loff_t start, loff_t end, int datasync);
  405. long exfat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
  406. long exfat_compat_ioctl(struct file *filp, unsigned int cmd,
  407. unsigned long arg);
  408. int exfat_force_shutdown(struct super_block *sb, u32 flags);
  409. /* namei.c */
  410. extern const struct dentry_operations exfat_dentry_ops;
  411. extern const struct dentry_operations exfat_utf8_dentry_ops;
  412. /* cache.c */
  413. int exfat_cache_init(void);
  414. void exfat_cache_shutdown(void);
  415. void exfat_cache_inval_inode(struct inode *inode);
  416. int exfat_get_cluster(struct inode *inode, unsigned int cluster,
  417. unsigned int *fclus, unsigned int *dclus,
  418. unsigned int *last_dclus, int allow_eof);
  419. /* dir.c */
  420. extern const struct inode_operations exfat_dir_inode_operations;
  421. extern const struct file_operations exfat_dir_operations;
  422. unsigned int exfat_get_entry_type(struct exfat_dentry *p_entry);
  423. void exfat_init_dir_entry(struct exfat_entry_set_cache *es,
  424. unsigned int type, unsigned int start_clu,
  425. unsigned long long size, struct timespec64 *ts);
  426. void exfat_init_ext_entry(struct exfat_entry_set_cache *es, int num_entries,
  427. struct exfat_uni_name *p_uniname);
  428. void exfat_remove_entries(struct inode *inode, struct exfat_entry_set_cache *es,
  429. int order);
  430. void exfat_update_dir_chksum(struct exfat_entry_set_cache *es);
  431. int exfat_calc_num_entries(struct exfat_uni_name *p_uniname);
  432. int exfat_find_dir_entry(struct super_block *sb, struct exfat_inode_info *ei,
  433. struct exfat_chain *p_dir, struct exfat_uni_name *p_uniname,
  434. struct exfat_hint *hint_opt);
  435. int exfat_alloc_new_dir(struct inode *inode, struct exfat_chain *clu);
  436. struct exfat_dentry *exfat_get_dentry(struct super_block *sb,
  437. struct exfat_chain *p_dir, int entry, struct buffer_head **bh);
  438. struct exfat_dentry *exfat_get_dentry_cached(struct exfat_entry_set_cache *es,
  439. int num);
  440. int exfat_get_dentry_set(struct exfat_entry_set_cache *es,
  441. struct super_block *sb, struct exfat_chain *p_dir, int entry,
  442. unsigned int num_entries);
  443. int exfat_get_empty_dentry_set(struct exfat_entry_set_cache *es,
  444. struct super_block *sb, struct exfat_chain *p_dir, int entry,
  445. unsigned int num_entries);
  446. int exfat_put_dentry_set(struct exfat_entry_set_cache *es, int sync);
  447. int exfat_count_dir_entries(struct super_block *sb, struct exfat_chain *p_dir);
  448. /* inode.c */
  449. extern const struct inode_operations exfat_file_inode_operations;
  450. void exfat_sync_inode(struct inode *inode);
  451. struct inode *exfat_build_inode(struct super_block *sb,
  452. struct exfat_dir_entry *info, loff_t i_pos);
  453. void exfat_hash_inode(struct inode *inode, loff_t i_pos);
  454. void exfat_unhash_inode(struct inode *inode);
  455. struct inode *exfat_iget(struct super_block *sb, loff_t i_pos);
  456. int __exfat_write_inode(struct inode *inode, int sync);
  457. int exfat_write_inode(struct inode *inode, struct writeback_control *wbc);
  458. void exfat_evict_inode(struct inode *inode);
  459. int exfat_block_truncate_page(struct inode *inode, loff_t from);
  460. /* exfat/nls.c */
  461. unsigned short exfat_toupper(struct super_block *sb, unsigned short a);
  462. int exfat_uniname_ncmp(struct super_block *sb, unsigned short *a,
  463. unsigned short *b, unsigned int len);
  464. int exfat_utf16_to_nls(struct super_block *sb,
  465. struct exfat_uni_name *uniname, unsigned char *p_cstring,
  466. int len);
  467. int exfat_nls_to_utf16(struct super_block *sb,
  468. const unsigned char *p_cstring, const int len,
  469. struct exfat_uni_name *uniname, int *p_lossy);
  470. int exfat_create_upcase_table(struct super_block *sb);
  471. void exfat_free_upcase_table(struct exfat_sb_info *sbi);
  472. /* exfat/misc.c */
  473. void __exfat_fs_error(struct super_block *sb, int report, const char *fmt, ...)
  474. __printf(3, 4) __cold;
  475. #define exfat_fs_error(sb, fmt, args...) \
  476. __exfat_fs_error(sb, 1, fmt, ## args)
  477. #define exfat_fs_error_ratelimit(sb, fmt, args...) \
  478. __exfat_fs_error(sb, __ratelimit(&EXFAT_SB(sb)->ratelimit), \
  479. fmt, ## args)
  480. /* expand to pr_*() with prefix */
  481. #define exfat_err(sb, fmt, ...) \
  482. pr_err("exFAT-fs (%s): " fmt "\n", (sb)->s_id, ##__VA_ARGS__)
  483. #define exfat_warn(sb, fmt, ...) \
  484. pr_warn("exFAT-fs (%s): " fmt "\n", (sb)->s_id, ##__VA_ARGS__)
  485. #define exfat_info(sb, fmt, ...) \
  486. pr_info("exFAT-fs (%s): " fmt "\n", (sb)->s_id, ##__VA_ARGS__)
  487. #define exfat_debug(sb, fmt, ...) \
  488. pr_debug("exFAT-fs (%s): " fmt "\n", (sb)->s_id, ##__VA_ARGS__)
  489. void exfat_get_entry_time(struct exfat_sb_info *sbi, struct timespec64 *ts,
  490. u8 tz, __le16 time, __le16 date, u8 time_cs);
  491. void exfat_truncate_atime(struct timespec64 *ts);
  492. void exfat_truncate_inode_atime(struct inode *inode);
  493. void exfat_set_entry_time(struct exfat_sb_info *sbi, struct timespec64 *ts,
  494. u8 *tz, __le16 *time, __le16 *date, u8 *time_cs);
  495. u16 exfat_calc_chksum16(void *data, int len, u16 chksum, int type);
  496. u32 exfat_calc_chksum32(void *data, int len, u32 chksum, int type);
  497. void exfat_update_bh(struct buffer_head *bh, int sync);
  498. int exfat_update_bhs(struct buffer_head **bhs, int nr_bhs, int sync);
  499. void exfat_chain_set(struct exfat_chain *ec, unsigned int dir,
  500. unsigned int size, unsigned char flags);
  501. void exfat_chain_dup(struct exfat_chain *dup, struct exfat_chain *ec);
  502. #endif /* !_EXFAT_FS_H */