18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci#ifndef _FAT_H 38c2ecf20Sopenharmony_ci#define _FAT_H 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci#include <linux/buffer_head.h> 68c2ecf20Sopenharmony_ci#include <linux/nls.h> 78c2ecf20Sopenharmony_ci#include <linux/hash.h> 88c2ecf20Sopenharmony_ci#include <linux/ratelimit.h> 98c2ecf20Sopenharmony_ci#include <linux/msdos_fs.h> 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci/* 128c2ecf20Sopenharmony_ci * vfat shortname flags 138c2ecf20Sopenharmony_ci */ 148c2ecf20Sopenharmony_ci#define VFAT_SFN_DISPLAY_LOWER 0x0001 /* convert to lowercase for display */ 158c2ecf20Sopenharmony_ci#define VFAT_SFN_DISPLAY_WIN95 0x0002 /* emulate win95 rule for display */ 168c2ecf20Sopenharmony_ci#define VFAT_SFN_DISPLAY_WINNT 0x0004 /* emulate winnt rule for display */ 178c2ecf20Sopenharmony_ci#define VFAT_SFN_CREATE_WIN95 0x0100 /* emulate win95 rule for create */ 188c2ecf20Sopenharmony_ci#define VFAT_SFN_CREATE_WINNT 0x0200 /* emulate winnt rule for create */ 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci#define FAT_ERRORS_CONT 1 /* ignore error and continue */ 218c2ecf20Sopenharmony_ci#define FAT_ERRORS_PANIC 2 /* panic on error */ 228c2ecf20Sopenharmony_ci#define FAT_ERRORS_RO 3 /* remount r/o on error */ 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci#define FAT_NFS_STALE_RW 1 /* NFS RW support, can cause ESTALE */ 258c2ecf20Sopenharmony_ci#define FAT_NFS_NOSTALE_RO 2 /* NFS RO support, no ESTALE issue */ 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_cistruct fat_mount_options { 288c2ecf20Sopenharmony_ci kuid_t fs_uid; 298c2ecf20Sopenharmony_ci kgid_t fs_gid; 308c2ecf20Sopenharmony_ci unsigned short fs_fmask; 318c2ecf20Sopenharmony_ci unsigned short fs_dmask; 328c2ecf20Sopenharmony_ci unsigned short codepage; /* Codepage for shortname conversions */ 338c2ecf20Sopenharmony_ci int time_offset; /* Offset of timestamps from UTC (in minutes) */ 348c2ecf20Sopenharmony_ci char *iocharset; /* Charset used for filename input/display */ 358c2ecf20Sopenharmony_ci unsigned short shortname; /* flags for shortname display/create rule */ 368c2ecf20Sopenharmony_ci unsigned char name_check; /* r = relaxed, n = normal, s = strict */ 378c2ecf20Sopenharmony_ci unsigned char errors; /* On error: continue, panic, remount-ro */ 388c2ecf20Sopenharmony_ci unsigned char nfs; /* NFS support: nostale_ro, stale_rw */ 398c2ecf20Sopenharmony_ci unsigned short allow_utime;/* permission for setting the [am]time */ 408c2ecf20Sopenharmony_ci unsigned quiet:1, /* set = fake successful chmods and chowns */ 418c2ecf20Sopenharmony_ci showexec:1, /* set = only set x bit for com/exe/bat */ 428c2ecf20Sopenharmony_ci sys_immutable:1, /* set = system files are immutable */ 438c2ecf20Sopenharmony_ci dotsOK:1, /* set = hidden and system files are named '.filename' */ 448c2ecf20Sopenharmony_ci isvfat:1, /* 0=no vfat long filename support, 1=vfat support */ 458c2ecf20Sopenharmony_ci utf8:1, /* Use of UTF-8 character set (Default) */ 468c2ecf20Sopenharmony_ci unicode_xlate:1, /* create escape sequences for unhandled Unicode */ 478c2ecf20Sopenharmony_ci numtail:1, /* Does first alias have a numeric '~1' type tail? */ 488c2ecf20Sopenharmony_ci flush:1, /* write things quickly */ 498c2ecf20Sopenharmony_ci nocase:1, /* Does this need case conversion? 0=need case conversion*/ 508c2ecf20Sopenharmony_ci usefree:1, /* Use free_clusters for FAT32 */ 518c2ecf20Sopenharmony_ci tz_set:1, /* Filesystem timestamps' offset set */ 528c2ecf20Sopenharmony_ci rodir:1, /* allow ATTR_RO for directory */ 538c2ecf20Sopenharmony_ci discard:1, /* Issue discard requests on deletions */ 548c2ecf20Sopenharmony_ci dos1xfloppy:1; /* Assume default BPB for DOS 1.x floppies */ 558c2ecf20Sopenharmony_ci}; 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ci#define FAT_HASH_BITS 8 588c2ecf20Sopenharmony_ci#define FAT_HASH_SIZE (1UL << FAT_HASH_BITS) 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci/* 618c2ecf20Sopenharmony_ci * MS-DOS file system in-core superblock data 628c2ecf20Sopenharmony_ci */ 638c2ecf20Sopenharmony_cistruct msdos_sb_info { 648c2ecf20Sopenharmony_ci unsigned short sec_per_clus; /* sectors/cluster */ 658c2ecf20Sopenharmony_ci unsigned short cluster_bits; /* log2(cluster_size) */ 668c2ecf20Sopenharmony_ci unsigned int cluster_size; /* cluster size */ 678c2ecf20Sopenharmony_ci unsigned char fats, fat_bits; /* number of FATs, FAT bits (12,16 or 32) */ 688c2ecf20Sopenharmony_ci unsigned short fat_start; 698c2ecf20Sopenharmony_ci unsigned long fat_length; /* FAT start & length (sec.) */ 708c2ecf20Sopenharmony_ci unsigned long dir_start; 718c2ecf20Sopenharmony_ci unsigned short dir_entries; /* root dir start & entries */ 728c2ecf20Sopenharmony_ci unsigned long data_start; /* first data sector */ 738c2ecf20Sopenharmony_ci unsigned long max_cluster; /* maximum cluster number */ 748c2ecf20Sopenharmony_ci unsigned long root_cluster; /* first cluster of the root directory */ 758c2ecf20Sopenharmony_ci unsigned long fsinfo_sector; /* sector number of FAT32 fsinfo */ 768c2ecf20Sopenharmony_ci struct mutex fat_lock; 778c2ecf20Sopenharmony_ci struct mutex nfs_build_inode_lock; 788c2ecf20Sopenharmony_ci struct mutex s_lock; 798c2ecf20Sopenharmony_ci unsigned int prev_free; /* previously allocated cluster number */ 808c2ecf20Sopenharmony_ci unsigned int free_clusters; /* -1 if undefined */ 818c2ecf20Sopenharmony_ci unsigned int free_clus_valid; /* is free_clusters valid? */ 828c2ecf20Sopenharmony_ci struct fat_mount_options options; 838c2ecf20Sopenharmony_ci struct nls_table *nls_disk; /* Codepage used on disk */ 848c2ecf20Sopenharmony_ci struct nls_table *nls_io; /* Charset used for input and display */ 858c2ecf20Sopenharmony_ci const void *dir_ops; /* Opaque; default directory operations */ 868c2ecf20Sopenharmony_ci int dir_per_block; /* dir entries per block */ 878c2ecf20Sopenharmony_ci int dir_per_block_bits; /* log2(dir_per_block) */ 888c2ecf20Sopenharmony_ci unsigned int vol_id; /*volume ID*/ 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_ci int fatent_shift; 918c2ecf20Sopenharmony_ci const struct fatent_operations *fatent_ops; 928c2ecf20Sopenharmony_ci struct inode *fat_inode; 938c2ecf20Sopenharmony_ci struct inode *fsinfo_inode; 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_ci struct ratelimit_state ratelimit; 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_ci spinlock_t inode_hash_lock; 988c2ecf20Sopenharmony_ci struct hlist_head inode_hashtable[FAT_HASH_SIZE]; 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_ci spinlock_t dir_hash_lock; 1018c2ecf20Sopenharmony_ci struct hlist_head dir_hashtable[FAT_HASH_SIZE]; 1028c2ecf20Sopenharmony_ci 1038c2ecf20Sopenharmony_ci unsigned int dirty; /* fs state before mount */ 1048c2ecf20Sopenharmony_ci struct rcu_head rcu; 1058c2ecf20Sopenharmony_ci}; 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_ci#define FAT_CACHE_VALID 0 /* special case for valid cache */ 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_ci/* 1108c2ecf20Sopenharmony_ci * MS-DOS file system inode data in memory 1118c2ecf20Sopenharmony_ci */ 1128c2ecf20Sopenharmony_cistruct msdos_inode_info { 1138c2ecf20Sopenharmony_ci spinlock_t cache_lru_lock; 1148c2ecf20Sopenharmony_ci struct list_head cache_lru; 1158c2ecf20Sopenharmony_ci int nr_caches; 1168c2ecf20Sopenharmony_ci /* for avoiding the race between fat_free() and fat_get_cluster() */ 1178c2ecf20Sopenharmony_ci unsigned int cache_valid_id; 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_ci /* NOTE: mmu_private is 64bits, so must hold ->i_mutex to access */ 1208c2ecf20Sopenharmony_ci loff_t mmu_private; /* physically allocated size */ 1218c2ecf20Sopenharmony_ci 1228c2ecf20Sopenharmony_ci int i_start; /* first cluster or 0 */ 1238c2ecf20Sopenharmony_ci int i_logstart; /* logical first cluster */ 1248c2ecf20Sopenharmony_ci int i_attrs; /* unused attribute bits */ 1258c2ecf20Sopenharmony_ci loff_t i_pos; /* on-disk position of directory entry or 0 */ 1268c2ecf20Sopenharmony_ci struct hlist_node i_fat_hash; /* hash by i_location */ 1278c2ecf20Sopenharmony_ci struct hlist_node i_dir_hash; /* hash by i_logstart */ 1288c2ecf20Sopenharmony_ci struct rw_semaphore truncate_lock; /* protect bmap against truncate */ 1298c2ecf20Sopenharmony_ci struct inode vfs_inode; 1308c2ecf20Sopenharmony_ci}; 1318c2ecf20Sopenharmony_ci 1328c2ecf20Sopenharmony_cistruct fat_slot_info { 1338c2ecf20Sopenharmony_ci loff_t i_pos; /* on-disk position of directory entry */ 1348c2ecf20Sopenharmony_ci loff_t slot_off; /* offset for slot or de start */ 1358c2ecf20Sopenharmony_ci int nr_slots; /* number of slots + 1(de) in filename */ 1368c2ecf20Sopenharmony_ci struct msdos_dir_entry *de; 1378c2ecf20Sopenharmony_ci struct buffer_head *bh; 1388c2ecf20Sopenharmony_ci}; 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_cistatic inline struct msdos_sb_info *MSDOS_SB(struct super_block *sb) 1418c2ecf20Sopenharmony_ci{ 1428c2ecf20Sopenharmony_ci return sb->s_fs_info; 1438c2ecf20Sopenharmony_ci} 1448c2ecf20Sopenharmony_ci 1458c2ecf20Sopenharmony_ci/* 1468c2ecf20Sopenharmony_ci * Functions that determine the variant of the FAT file system (i.e., 1478c2ecf20Sopenharmony_ci * whether this is FAT12, FAT16 or FAT32. 1488c2ecf20Sopenharmony_ci */ 1498c2ecf20Sopenharmony_cistatic inline bool is_fat12(const struct msdos_sb_info *sbi) 1508c2ecf20Sopenharmony_ci{ 1518c2ecf20Sopenharmony_ci return sbi->fat_bits == 12; 1528c2ecf20Sopenharmony_ci} 1538c2ecf20Sopenharmony_ci 1548c2ecf20Sopenharmony_cistatic inline bool is_fat16(const struct msdos_sb_info *sbi) 1558c2ecf20Sopenharmony_ci{ 1568c2ecf20Sopenharmony_ci return sbi->fat_bits == 16; 1578c2ecf20Sopenharmony_ci} 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_cistatic inline bool is_fat32(const struct msdos_sb_info *sbi) 1608c2ecf20Sopenharmony_ci{ 1618c2ecf20Sopenharmony_ci return sbi->fat_bits == 32; 1628c2ecf20Sopenharmony_ci} 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_ci/* Maximum number of clusters */ 1658c2ecf20Sopenharmony_cistatic inline u32 max_fat(struct super_block *sb) 1668c2ecf20Sopenharmony_ci{ 1678c2ecf20Sopenharmony_ci struct msdos_sb_info *sbi = MSDOS_SB(sb); 1688c2ecf20Sopenharmony_ci 1698c2ecf20Sopenharmony_ci return is_fat32(sbi) ? MAX_FAT32 : 1708c2ecf20Sopenharmony_ci is_fat16(sbi) ? MAX_FAT16 : MAX_FAT12; 1718c2ecf20Sopenharmony_ci} 1728c2ecf20Sopenharmony_ci 1738c2ecf20Sopenharmony_cistatic inline struct msdos_inode_info *MSDOS_I(struct inode *inode) 1748c2ecf20Sopenharmony_ci{ 1758c2ecf20Sopenharmony_ci return container_of(inode, struct msdos_inode_info, vfs_inode); 1768c2ecf20Sopenharmony_ci} 1778c2ecf20Sopenharmony_ci 1788c2ecf20Sopenharmony_ci/* 1798c2ecf20Sopenharmony_ci * If ->i_mode can't hold S_IWUGO (i.e. ATTR_RO), we use ->i_attrs to 1808c2ecf20Sopenharmony_ci * save ATTR_RO instead of ->i_mode. 1818c2ecf20Sopenharmony_ci * 1828c2ecf20Sopenharmony_ci * If it's directory and !sbi->options.rodir, ATTR_RO isn't read-only 1838c2ecf20Sopenharmony_ci * bit, it's just used as flag for app. 1848c2ecf20Sopenharmony_ci */ 1858c2ecf20Sopenharmony_cistatic inline int fat_mode_can_hold_ro(struct inode *inode) 1868c2ecf20Sopenharmony_ci{ 1878c2ecf20Sopenharmony_ci struct msdos_sb_info *sbi = MSDOS_SB(inode->i_sb); 1888c2ecf20Sopenharmony_ci umode_t mask; 1898c2ecf20Sopenharmony_ci 1908c2ecf20Sopenharmony_ci if (S_ISDIR(inode->i_mode)) { 1918c2ecf20Sopenharmony_ci if (!sbi->options.rodir) 1928c2ecf20Sopenharmony_ci return 0; 1938c2ecf20Sopenharmony_ci mask = ~sbi->options.fs_dmask; 1948c2ecf20Sopenharmony_ci } else 1958c2ecf20Sopenharmony_ci mask = ~sbi->options.fs_fmask; 1968c2ecf20Sopenharmony_ci 1978c2ecf20Sopenharmony_ci if (!(mask & S_IWUGO)) 1988c2ecf20Sopenharmony_ci return 0; 1998c2ecf20Sopenharmony_ci return 1; 2008c2ecf20Sopenharmony_ci} 2018c2ecf20Sopenharmony_ci 2028c2ecf20Sopenharmony_ci/* Convert attribute bits and a mask to the UNIX mode. */ 2038c2ecf20Sopenharmony_cistatic inline umode_t fat_make_mode(struct msdos_sb_info *sbi, 2048c2ecf20Sopenharmony_ci u8 attrs, umode_t mode) 2058c2ecf20Sopenharmony_ci{ 2068c2ecf20Sopenharmony_ci if (attrs & ATTR_RO && !((attrs & ATTR_DIR) && !sbi->options.rodir)) 2078c2ecf20Sopenharmony_ci mode &= ~S_IWUGO; 2088c2ecf20Sopenharmony_ci 2098c2ecf20Sopenharmony_ci if (attrs & ATTR_DIR) 2108c2ecf20Sopenharmony_ci return (mode & ~sbi->options.fs_dmask) | S_IFDIR; 2118c2ecf20Sopenharmony_ci else 2128c2ecf20Sopenharmony_ci return (mode & ~sbi->options.fs_fmask) | S_IFREG; 2138c2ecf20Sopenharmony_ci} 2148c2ecf20Sopenharmony_ci 2158c2ecf20Sopenharmony_ci/* Return the FAT attribute byte for this inode */ 2168c2ecf20Sopenharmony_cistatic inline u8 fat_make_attrs(struct inode *inode) 2178c2ecf20Sopenharmony_ci{ 2188c2ecf20Sopenharmony_ci u8 attrs = MSDOS_I(inode)->i_attrs; 2198c2ecf20Sopenharmony_ci if (S_ISDIR(inode->i_mode)) 2208c2ecf20Sopenharmony_ci attrs |= ATTR_DIR; 2218c2ecf20Sopenharmony_ci if (fat_mode_can_hold_ro(inode) && !(inode->i_mode & S_IWUGO)) 2228c2ecf20Sopenharmony_ci attrs |= ATTR_RO; 2238c2ecf20Sopenharmony_ci return attrs; 2248c2ecf20Sopenharmony_ci} 2258c2ecf20Sopenharmony_ci 2268c2ecf20Sopenharmony_cistatic inline void fat_save_attrs(struct inode *inode, u8 attrs) 2278c2ecf20Sopenharmony_ci{ 2288c2ecf20Sopenharmony_ci if (fat_mode_can_hold_ro(inode)) 2298c2ecf20Sopenharmony_ci MSDOS_I(inode)->i_attrs = attrs & ATTR_UNUSED; 2308c2ecf20Sopenharmony_ci else 2318c2ecf20Sopenharmony_ci MSDOS_I(inode)->i_attrs = attrs & (ATTR_UNUSED | ATTR_RO); 2328c2ecf20Sopenharmony_ci} 2338c2ecf20Sopenharmony_ci 2348c2ecf20Sopenharmony_cistatic inline unsigned char fat_checksum(const __u8 *name) 2358c2ecf20Sopenharmony_ci{ 2368c2ecf20Sopenharmony_ci unsigned char s = name[0]; 2378c2ecf20Sopenharmony_ci s = (s<<7) + (s>>1) + name[1]; s = (s<<7) + (s>>1) + name[2]; 2388c2ecf20Sopenharmony_ci s = (s<<7) + (s>>1) + name[3]; s = (s<<7) + (s>>1) + name[4]; 2398c2ecf20Sopenharmony_ci s = (s<<7) + (s>>1) + name[5]; s = (s<<7) + (s>>1) + name[6]; 2408c2ecf20Sopenharmony_ci s = (s<<7) + (s>>1) + name[7]; s = (s<<7) + (s>>1) + name[8]; 2418c2ecf20Sopenharmony_ci s = (s<<7) + (s>>1) + name[9]; s = (s<<7) + (s>>1) + name[10]; 2428c2ecf20Sopenharmony_ci return s; 2438c2ecf20Sopenharmony_ci} 2448c2ecf20Sopenharmony_ci 2458c2ecf20Sopenharmony_cistatic inline sector_t fat_clus_to_blknr(struct msdos_sb_info *sbi, int clus) 2468c2ecf20Sopenharmony_ci{ 2478c2ecf20Sopenharmony_ci return ((sector_t)clus - FAT_START_ENT) * sbi->sec_per_clus 2488c2ecf20Sopenharmony_ci + sbi->data_start; 2498c2ecf20Sopenharmony_ci} 2508c2ecf20Sopenharmony_ci 2518c2ecf20Sopenharmony_cistatic inline void fat_get_blknr_offset(struct msdos_sb_info *sbi, 2528c2ecf20Sopenharmony_ci loff_t i_pos, sector_t *blknr, int *offset) 2538c2ecf20Sopenharmony_ci{ 2548c2ecf20Sopenharmony_ci *blknr = i_pos >> sbi->dir_per_block_bits; 2558c2ecf20Sopenharmony_ci *offset = i_pos & (sbi->dir_per_block - 1); 2568c2ecf20Sopenharmony_ci} 2578c2ecf20Sopenharmony_ci 2588c2ecf20Sopenharmony_cistatic inline loff_t fat_i_pos_read(struct msdos_sb_info *sbi, 2598c2ecf20Sopenharmony_ci struct inode *inode) 2608c2ecf20Sopenharmony_ci{ 2618c2ecf20Sopenharmony_ci loff_t i_pos; 2628c2ecf20Sopenharmony_ci#if BITS_PER_LONG == 32 2638c2ecf20Sopenharmony_ci spin_lock(&sbi->inode_hash_lock); 2648c2ecf20Sopenharmony_ci#endif 2658c2ecf20Sopenharmony_ci i_pos = MSDOS_I(inode)->i_pos; 2668c2ecf20Sopenharmony_ci#if BITS_PER_LONG == 32 2678c2ecf20Sopenharmony_ci spin_unlock(&sbi->inode_hash_lock); 2688c2ecf20Sopenharmony_ci#endif 2698c2ecf20Sopenharmony_ci return i_pos; 2708c2ecf20Sopenharmony_ci} 2718c2ecf20Sopenharmony_ci 2728c2ecf20Sopenharmony_cistatic inline void fat16_towchar(wchar_t *dst, const __u8 *src, size_t len) 2738c2ecf20Sopenharmony_ci{ 2748c2ecf20Sopenharmony_ci#ifdef __BIG_ENDIAN 2758c2ecf20Sopenharmony_ci while (len--) { 2768c2ecf20Sopenharmony_ci *dst++ = src[0] | (src[1] << 8); 2778c2ecf20Sopenharmony_ci src += 2; 2788c2ecf20Sopenharmony_ci } 2798c2ecf20Sopenharmony_ci#else 2808c2ecf20Sopenharmony_ci memcpy(dst, src, len * 2); 2818c2ecf20Sopenharmony_ci#endif 2828c2ecf20Sopenharmony_ci} 2838c2ecf20Sopenharmony_ci 2848c2ecf20Sopenharmony_cistatic inline int fat_get_start(const struct msdos_sb_info *sbi, 2858c2ecf20Sopenharmony_ci const struct msdos_dir_entry *de) 2868c2ecf20Sopenharmony_ci{ 2878c2ecf20Sopenharmony_ci int cluster = le16_to_cpu(de->start); 2888c2ecf20Sopenharmony_ci if (is_fat32(sbi)) 2898c2ecf20Sopenharmony_ci cluster |= (le16_to_cpu(de->starthi) << 16); 2908c2ecf20Sopenharmony_ci return cluster; 2918c2ecf20Sopenharmony_ci} 2928c2ecf20Sopenharmony_ci 2938c2ecf20Sopenharmony_cistatic inline void fat_set_start(struct msdos_dir_entry *de, int cluster) 2948c2ecf20Sopenharmony_ci{ 2958c2ecf20Sopenharmony_ci de->start = cpu_to_le16(cluster); 2968c2ecf20Sopenharmony_ci de->starthi = cpu_to_le16(cluster >> 16); 2978c2ecf20Sopenharmony_ci} 2988c2ecf20Sopenharmony_ci 2998c2ecf20Sopenharmony_cistatic inline void fatwchar_to16(__u8 *dst, const wchar_t *src, size_t len) 3008c2ecf20Sopenharmony_ci{ 3018c2ecf20Sopenharmony_ci#ifdef __BIG_ENDIAN 3028c2ecf20Sopenharmony_ci while (len--) { 3038c2ecf20Sopenharmony_ci dst[0] = *src & 0x00FF; 3048c2ecf20Sopenharmony_ci dst[1] = (*src & 0xFF00) >> 8; 3058c2ecf20Sopenharmony_ci dst += 2; 3068c2ecf20Sopenharmony_ci src++; 3078c2ecf20Sopenharmony_ci } 3088c2ecf20Sopenharmony_ci#else 3098c2ecf20Sopenharmony_ci memcpy(dst, src, len * 2); 3108c2ecf20Sopenharmony_ci#endif 3118c2ecf20Sopenharmony_ci} 3128c2ecf20Sopenharmony_ci 3138c2ecf20Sopenharmony_ci/* fat/cache.c */ 3148c2ecf20Sopenharmony_ciextern void fat_cache_inval_inode(struct inode *inode); 3158c2ecf20Sopenharmony_ciextern int fat_get_cluster(struct inode *inode, int cluster, 3168c2ecf20Sopenharmony_ci int *fclus, int *dclus); 3178c2ecf20Sopenharmony_ciextern int fat_get_mapped_cluster(struct inode *inode, sector_t sector, 3188c2ecf20Sopenharmony_ci sector_t last_block, 3198c2ecf20Sopenharmony_ci unsigned long *mapped_blocks, sector_t *bmap); 3208c2ecf20Sopenharmony_ciextern int fat_bmap(struct inode *inode, sector_t sector, sector_t *phys, 3218c2ecf20Sopenharmony_ci unsigned long *mapped_blocks, int create, bool from_bmap); 3228c2ecf20Sopenharmony_ci 3238c2ecf20Sopenharmony_ci/* fat/dir.c */ 3248c2ecf20Sopenharmony_ciextern const struct file_operations fat_dir_operations; 3258c2ecf20Sopenharmony_ciextern int fat_search_long(struct inode *inode, const unsigned char *name, 3268c2ecf20Sopenharmony_ci int name_len, struct fat_slot_info *sinfo); 3278c2ecf20Sopenharmony_ciextern int fat_dir_empty(struct inode *dir); 3288c2ecf20Sopenharmony_ciextern int fat_subdirs(struct inode *dir); 3298c2ecf20Sopenharmony_ciextern int fat_scan(struct inode *dir, const unsigned char *name, 3308c2ecf20Sopenharmony_ci struct fat_slot_info *sinfo); 3318c2ecf20Sopenharmony_ciextern int fat_scan_logstart(struct inode *dir, int i_logstart, 3328c2ecf20Sopenharmony_ci struct fat_slot_info *sinfo); 3338c2ecf20Sopenharmony_ciextern int fat_get_dotdot_entry(struct inode *dir, struct buffer_head **bh, 3348c2ecf20Sopenharmony_ci struct msdos_dir_entry **de); 3358c2ecf20Sopenharmony_ciextern int fat_alloc_new_dir(struct inode *dir, struct timespec64 *ts); 3368c2ecf20Sopenharmony_ciextern int fat_add_entries(struct inode *dir, void *slots, int nr_slots, 3378c2ecf20Sopenharmony_ci struct fat_slot_info *sinfo); 3388c2ecf20Sopenharmony_ciextern int fat_remove_entries(struct inode *dir, struct fat_slot_info *sinfo); 3398c2ecf20Sopenharmony_ci 3408c2ecf20Sopenharmony_ci/* fat/fatent.c */ 3418c2ecf20Sopenharmony_cistruct fat_entry { 3428c2ecf20Sopenharmony_ci int entry; 3438c2ecf20Sopenharmony_ci union { 3448c2ecf20Sopenharmony_ci u8 *ent12_p[2]; 3458c2ecf20Sopenharmony_ci __le16 *ent16_p; 3468c2ecf20Sopenharmony_ci __le32 *ent32_p; 3478c2ecf20Sopenharmony_ci } u; 3488c2ecf20Sopenharmony_ci int nr_bhs; 3498c2ecf20Sopenharmony_ci struct buffer_head *bhs[2]; 3508c2ecf20Sopenharmony_ci struct inode *fat_inode; 3518c2ecf20Sopenharmony_ci}; 3528c2ecf20Sopenharmony_ci 3538c2ecf20Sopenharmony_cistatic inline void fatent_init(struct fat_entry *fatent) 3548c2ecf20Sopenharmony_ci{ 3558c2ecf20Sopenharmony_ci fatent->nr_bhs = 0; 3568c2ecf20Sopenharmony_ci fatent->entry = 0; 3578c2ecf20Sopenharmony_ci fatent->u.ent32_p = NULL; 3588c2ecf20Sopenharmony_ci fatent->bhs[0] = fatent->bhs[1] = NULL; 3598c2ecf20Sopenharmony_ci fatent->fat_inode = NULL; 3608c2ecf20Sopenharmony_ci} 3618c2ecf20Sopenharmony_ci 3628c2ecf20Sopenharmony_cistatic inline void fatent_set_entry(struct fat_entry *fatent, int entry) 3638c2ecf20Sopenharmony_ci{ 3648c2ecf20Sopenharmony_ci fatent->entry = entry; 3658c2ecf20Sopenharmony_ci fatent->u.ent32_p = NULL; 3668c2ecf20Sopenharmony_ci} 3678c2ecf20Sopenharmony_ci 3688c2ecf20Sopenharmony_cistatic inline void fatent_brelse(struct fat_entry *fatent) 3698c2ecf20Sopenharmony_ci{ 3708c2ecf20Sopenharmony_ci int i; 3718c2ecf20Sopenharmony_ci fatent->u.ent32_p = NULL; 3728c2ecf20Sopenharmony_ci for (i = 0; i < fatent->nr_bhs; i++) 3738c2ecf20Sopenharmony_ci brelse(fatent->bhs[i]); 3748c2ecf20Sopenharmony_ci fatent->nr_bhs = 0; 3758c2ecf20Sopenharmony_ci fatent->bhs[0] = fatent->bhs[1] = NULL; 3768c2ecf20Sopenharmony_ci fatent->fat_inode = NULL; 3778c2ecf20Sopenharmony_ci} 3788c2ecf20Sopenharmony_ci 3798c2ecf20Sopenharmony_cistatic inline bool fat_valid_entry(struct msdos_sb_info *sbi, int entry) 3808c2ecf20Sopenharmony_ci{ 3818c2ecf20Sopenharmony_ci return FAT_START_ENT <= entry && entry < sbi->max_cluster; 3828c2ecf20Sopenharmony_ci} 3838c2ecf20Sopenharmony_ci 3848c2ecf20Sopenharmony_ciextern void fat_ent_access_init(struct super_block *sb); 3858c2ecf20Sopenharmony_ciextern int fat_ent_read(struct inode *inode, struct fat_entry *fatent, 3868c2ecf20Sopenharmony_ci int entry); 3878c2ecf20Sopenharmony_ciextern int fat_ent_write(struct inode *inode, struct fat_entry *fatent, 3888c2ecf20Sopenharmony_ci int new, int wait); 3898c2ecf20Sopenharmony_ciextern int fat_alloc_clusters(struct inode *inode, int *cluster, 3908c2ecf20Sopenharmony_ci int nr_cluster); 3918c2ecf20Sopenharmony_ciextern int fat_free_clusters(struct inode *inode, int cluster); 3928c2ecf20Sopenharmony_ciextern int fat_count_free_clusters(struct super_block *sb); 3938c2ecf20Sopenharmony_ciextern int fat_trim_fs(struct inode *inode, struct fstrim_range *range); 3948c2ecf20Sopenharmony_ci 3958c2ecf20Sopenharmony_ci/* fat/file.c */ 3968c2ecf20Sopenharmony_ciextern long fat_generic_ioctl(struct file *filp, unsigned int cmd, 3978c2ecf20Sopenharmony_ci unsigned long arg); 3988c2ecf20Sopenharmony_ciextern const struct file_operations fat_file_operations; 3998c2ecf20Sopenharmony_ciextern const struct inode_operations fat_file_inode_operations; 4008c2ecf20Sopenharmony_ciextern int fat_setattr(struct dentry *dentry, struct iattr *attr); 4018c2ecf20Sopenharmony_ciextern void fat_truncate_blocks(struct inode *inode, loff_t offset); 4028c2ecf20Sopenharmony_ciextern int fat_getattr(const struct path *path, struct kstat *stat, 4038c2ecf20Sopenharmony_ci u32 request_mask, unsigned int flags); 4048c2ecf20Sopenharmony_ciextern int fat_file_fsync(struct file *file, loff_t start, loff_t end, 4058c2ecf20Sopenharmony_ci int datasync); 4068c2ecf20Sopenharmony_ci 4078c2ecf20Sopenharmony_ci/* fat/inode.c */ 4088c2ecf20Sopenharmony_ciextern int fat_block_truncate_page(struct inode *inode, loff_t from); 4098c2ecf20Sopenharmony_ciextern void fat_attach(struct inode *inode, loff_t i_pos); 4108c2ecf20Sopenharmony_ciextern void fat_detach(struct inode *inode); 4118c2ecf20Sopenharmony_ciextern struct inode *fat_iget(struct super_block *sb, loff_t i_pos); 4128c2ecf20Sopenharmony_ciextern struct inode *fat_build_inode(struct super_block *sb, 4138c2ecf20Sopenharmony_ci struct msdos_dir_entry *de, loff_t i_pos); 4148c2ecf20Sopenharmony_ciextern int fat_sync_inode(struct inode *inode); 4158c2ecf20Sopenharmony_ciextern int fat_fill_super(struct super_block *sb, void *data, int silent, 4168c2ecf20Sopenharmony_ci int isvfat, void (*setup)(struct super_block *)); 4178c2ecf20Sopenharmony_ciextern int fat_fill_inode(struct inode *inode, struct msdos_dir_entry *de); 4188c2ecf20Sopenharmony_ci 4198c2ecf20Sopenharmony_ciextern int fat_flush_inodes(struct super_block *sb, struct inode *i1, 4208c2ecf20Sopenharmony_ci struct inode *i2); 4218c2ecf20Sopenharmony_cistatic inline unsigned long fat_dir_hash(int logstart) 4228c2ecf20Sopenharmony_ci{ 4238c2ecf20Sopenharmony_ci return hash_32(logstart, FAT_HASH_BITS); 4248c2ecf20Sopenharmony_ci} 4258c2ecf20Sopenharmony_ciextern int fat_add_cluster(struct inode *inode); 4268c2ecf20Sopenharmony_ci 4278c2ecf20Sopenharmony_ci/* fat/misc.c */ 4288c2ecf20Sopenharmony_ciextern __printf(3, 4) __cold 4298c2ecf20Sopenharmony_civoid __fat_fs_error(struct super_block *sb, int report, const char *fmt, ...); 4308c2ecf20Sopenharmony_ci#define fat_fs_error(sb, fmt, args...) \ 4318c2ecf20Sopenharmony_ci __fat_fs_error(sb, 1, fmt , ## args) 4328c2ecf20Sopenharmony_ci#define fat_fs_error_ratelimit(sb, fmt, args...) \ 4338c2ecf20Sopenharmony_ci __fat_fs_error(sb, __ratelimit(&MSDOS_SB(sb)->ratelimit), fmt , ## args) 4348c2ecf20Sopenharmony_ci__printf(3, 4) __cold 4358c2ecf20Sopenharmony_civoid fat_msg(struct super_block *sb, const char *level, const char *fmt, ...); 4368c2ecf20Sopenharmony_ci#define fat_msg_ratelimit(sb, level, fmt, args...) \ 4378c2ecf20Sopenharmony_ci do { \ 4388c2ecf20Sopenharmony_ci if (__ratelimit(&MSDOS_SB(sb)->ratelimit)) \ 4398c2ecf20Sopenharmony_ci fat_msg(sb, level, fmt, ## args); \ 4408c2ecf20Sopenharmony_ci } while (0) 4418c2ecf20Sopenharmony_ciextern int fat_clusters_flush(struct super_block *sb); 4428c2ecf20Sopenharmony_ciextern int fat_chain_add(struct inode *inode, int new_dclus, int nr_cluster); 4438c2ecf20Sopenharmony_ciextern void fat_time_fat2unix(struct msdos_sb_info *sbi, struct timespec64 *ts, 4448c2ecf20Sopenharmony_ci __le16 __time, __le16 __date, u8 time_cs); 4458c2ecf20Sopenharmony_ciextern void fat_time_unix2fat(struct msdos_sb_info *sbi, struct timespec64 *ts, 4468c2ecf20Sopenharmony_ci __le16 *time, __le16 *date, u8 *time_cs); 4478c2ecf20Sopenharmony_ciextern int fat_truncate_time(struct inode *inode, struct timespec64 *now, 4488c2ecf20Sopenharmony_ci int flags); 4498c2ecf20Sopenharmony_ciextern int fat_update_time(struct inode *inode, struct timespec64 *now, 4508c2ecf20Sopenharmony_ci int flags); 4518c2ecf20Sopenharmony_ciextern int fat_sync_bhs(struct buffer_head **bhs, int nr_bhs); 4528c2ecf20Sopenharmony_ci 4538c2ecf20Sopenharmony_ciint fat_cache_init(void); 4548c2ecf20Sopenharmony_civoid fat_cache_destroy(void); 4558c2ecf20Sopenharmony_ci 4568c2ecf20Sopenharmony_ci/* fat/nfs.c */ 4578c2ecf20Sopenharmony_ciextern const struct export_operations fat_export_ops; 4588c2ecf20Sopenharmony_ciextern const struct export_operations fat_export_ops_nostale; 4598c2ecf20Sopenharmony_ci 4608c2ecf20Sopenharmony_ci/* helper for printk */ 4618c2ecf20Sopenharmony_citypedef unsigned long long llu; 4628c2ecf20Sopenharmony_ci 4638c2ecf20Sopenharmony_ci#endif /* !_FAT_H */ 464