2 * Copyright (C) 2012-2013 Samsung Electronics Co., Ltd.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 /************************************************************************/
21 /* PROJECT : exFAT & FAT12/16/32 File System */
23 /* PURPOSE : Header File for exFAT File Manager */
25 /*----------------------------------------------------------------------*/
28 /*----------------------------------------------------------------------*/
29 /* REVISION HISTORY (Ver 0.9) */
31 /* - 2010.11.15 [Joosun Hahn] : first writing */
33 /************************************************************************/
38 #include "exfat_config.h"
39 #include "exfat_global.h"
40 #include "exfat_data.h"
41 #include "exfat_oal.h"
43 #include "exfat_blkdev.h"
44 #include "exfat_cache.h"
45 #include "exfat_nls.h"
46 #include "exfat_api.h"
47 #include "exfat_cache.h"
51 #endif /* __cplusplus */
53 #if EXFAT_CONFIG_KERNEL_DEBUG
54 /* For Debugging Purpose */
55 /* IOCTL code 'f' used by
56 * - file systems typically #0~0x1F
57 * - embedded terminal devices #128~
58 * - exts for debugging purpose #99
59 * number 100 and 101 is availble now but has possible conflicts
61 #define EXFAT_IOC_GET_DEBUGFLAGS _IOR('f', 100, long)
62 #define EXFAT_IOC_SET_DEBUGFLAGS _IOW('f', 101, long)
64 #define EXFAT_DEBUGFLAGS_INVALID_UMOUNT 0x01
65 #define EXFAT_DEBUGFLAGS_ERROR_RW 0x02
66 #endif /* EXFAT_CONFIG_KERNEL_DEBUG */
68 /*----------------------------------------------------------------------*/
69 /* Constant & Macro Definitions */
70 /*----------------------------------------------------------------------*/
72 #define MAX_VOLUME 4 // max num of volumes per device
74 #define DENTRY_SIZE 32 // dir entry size
75 #define DENTRY_SIZE_BITS 5
78 #define PBR_SIGNATURE 0xAA55
79 #define EXT_SIGNATURE 0xAA550000
80 #define VOL_LABEL "NO NAME " // size should be 11
81 #define OEM_NAME "MSWIN4.1" // size should be 8
82 #define STR_FAT12 "FAT12 " // size should be 8
83 #define STR_FAT16 "FAT16 " // size should be 8
84 #define STR_FAT32 "FAT32 " // size should be 8
85 #define STR_EXFAT "EXFAT " // size should be 8
86 #define VOL_CLEAN 0x0000
87 #define VOL_DIRTY 0x0002
89 /* max number of clusters */
90 #define FAT12_THRESHOLD 4087 // 2^12 - 1 + 2 (clu 0 & 1)
91 #define FAT16_THRESHOLD 65527 // 2^16 - 1 + 2
92 #define FAT32_THRESHOLD 268435457 // 2^28 - 1 + 2
93 #define EXFAT_THRESHOLD 268435457 // 2^28 - 1 + 2
96 #define TYPE_UNUSED 0x0000
97 #define TYPE_DELETED 0x0001
98 #define TYPE_INVALID 0x0002
99 #define TYPE_CRITICAL_PRI 0x0100
100 #define TYPE_BITMAP 0x0101
101 #define TYPE_UPCASE 0x0102
102 #define TYPE_VOLUME 0x0103
103 #define TYPE_DIR 0x0104
104 #define TYPE_FILE 0x011F
105 #define TYPE_SYMLINK 0x015F
106 #define TYPE_CRITICAL_SEC 0x0200
107 #define TYPE_STREAM 0x0201
108 #define TYPE_EXTEND 0x0202
109 #define TYPE_ACL 0x0203
110 #define TYPE_BENIGN_PRI 0x0400
111 #define TYPE_GUID 0x0401
112 #define TYPE_PADDING 0x0402
113 #define TYPE_ACLTAB 0x0403
114 #define TYPE_BENIGN_SEC 0x0800
115 #define TYPE_ALL 0x0FFF
123 #define CS_DIR_ENTRY 0
124 #define CS_PBR_SECTOR 1
127 #define CLUSTER_16(x) ((UINT16)(x))
128 #define CLUSTER_32(x) ((UINT32)(x))
130 #define START_SECTOR(x) \
131 ( (((x)-2) << p_fs->sectors_per_clu_bits) + p_fs->data_start_sector )
133 #define IS_LAST_SECTOR_IN_CLUSTER(sec) \
134 ( (((sec) - p_fs->data_start_sector + 1) & ((1 << p_fs->sectors_per_clu_bits) -1)) == 0)
136 #define GET_CLUSTER_FROM_SECTOR(sec) \
137 ((((sec) - p_fs->data_start_sector) >> p_fs->sectors_per_clu_bits) +2)
139 #define GET16(p_src) \
140 ( ((UINT16)(p_src)[0]) | (((UINT16)(p_src)[1]) << 8) )
141 #define GET32(p_src) \
142 ( ((UINT32)(p_src)[0]) | (((UINT32)(p_src)[1]) << 8) | \
143 (((UINT32)(p_src)[2]) << 16) | (((UINT32)(p_src)[3]) << 24) )
144 #define GET64(p_src) \
145 ( ((UINT64)(p_src)[0]) | (((UINT64)(p_src)[1]) << 8) | \
146 (((UINT64)(p_src)[2]) << 16) | (((UINT64)(p_src)[3]) << 24) | \
147 (((UINT64)(p_src)[4]) << 32) | (((UINT64)(p_src)[5]) << 40) | \
148 (((UINT64)(p_src)[6]) << 48) | (((UINT64)(p_src)[7]) << 56) )
151 #define SET16(p_dst,src) \
153 (p_dst)[0]=(UINT8)(src); \
154 (p_dst)[1]=(UINT8)(((UINT16)(src)) >> 8); \
156 #define SET32(p_dst,src) \
158 (p_dst)[0]=(UINT8)(src); \
159 (p_dst)[1]=(UINT8)(((UINT32)(src)) >> 8); \
160 (p_dst)[2]=(UINT8)(((UINT32)(src)) >> 16); \
161 (p_dst)[3]=(UINT8)(((UINT32)(src)) >> 24); \
163 #define SET64(p_dst,src) \
165 (p_dst)[0]=(UINT8)(src); \
166 (p_dst)[1]=(UINT8)(((UINT64)(src)) >> 8); \
167 (p_dst)[2]=(UINT8)(((UINT64)(src)) >> 16); \
168 (p_dst)[3]=(UINT8)(((UINT64)(src)) >> 24); \
169 (p_dst)[4]=(UINT8)(((UINT64)(src)) >> 32); \
170 (p_dst)[5]=(UINT8)(((UINT64)(src)) >> 40); \
171 (p_dst)[6]=(UINT8)(((UINT64)(src)) >> 48); \
172 (p_dst)[7]=(UINT8)(((UINT64)(src)) >> 56); \
175 #ifdef __LITTLE_ENDIAN
176 #define GET16_A(p_src) (*((UINT16 *)(p_src)))
177 #define GET32_A(p_src) (*((UINT32 *)(p_src)))
178 #define GET64_A(p_src) (*((UINT64 *)(p_src)))
179 #define SET16_A(p_dst,src) *((UINT16 *)(p_dst)) = (UINT16)(src)
180 #define SET32_A(p_dst,src) *((UINT32 *)(p_dst)) = (UINT32)(src)
181 #define SET64_A(p_dst,src) *((UINT64 *)(p_dst)) = (UINT64)(src)
183 #define GET16_A(p_src) GET16(p_src)
184 #define GET32_A(p_src) GET32(p_src)
185 #define GET64_A(p_src) GET64(p_src)
186 #define SET16_A(p_dst,src) SET16(p_dst, src)
187 #define SET32_A(p_dst,src) SET32(p_dst, src)
188 #define SET64_A(p_dst,src) SET64(p_dst, src)
191 /* Upcase tabel mecro */
192 #define HIGH_INDEX_BIT (8)
193 #define HIGH_INDEX_MASK (0xFF00)
194 #define LOW_INDEX_BIT (16-HIGH_INDEX_BIT)
195 #define UTBL_ROW_COUNT (1<<LOW_INDEX_BIT)
196 #define UTBL_COL_COUNT (1<<HIGH_INDEX_BIT)
198 static inline UINT16
get_col_index(UINT16 i
)
200 return i
>> LOW_INDEX_BIT
;
202 static inline UINT16
get_row_index(UINT16 i
)
204 return i
& ~HIGH_INDEX_MASK
;
206 /*----------------------------------------------------------------------*/
207 /* Type Definitions */
208 /*----------------------------------------------------------------------*/
210 /* MS_DOS FAT partition boot record (512 bytes) */
215 UINT8 boot_code
[390];
219 /* MS-DOS FAT12/16 BIOS parameter block (51 bytes) */
221 UINT8 sector_size
[2];
222 UINT8 sectors_per_clu
;
223 UINT8 num_reserved
[2];
225 UINT8 num_root_entries
[2];
226 UINT8 num_sectors
[2];
228 UINT8 num_fat_sectors
[2];
229 UINT8 sectors_in_track
[2];
231 UINT8 num_hid_sectors
[4];
232 UINT8 num_huge_sectors
[4];
242 /* MS-DOS FAT32 BIOS parameter block (79 bytes) */
244 UINT8 sector_size
[2];
245 UINT8 sectors_per_clu
;
246 UINT8 num_reserved
[2];
248 UINT8 num_root_entries
[2];
249 UINT8 num_sectors
[2];
251 UINT8 num_fat_sectors
[2];
252 UINT8 sectors_in_track
[2];
254 UINT8 num_hid_sectors
[4];
255 UINT8 num_huge_sectors
[4];
256 UINT8 num_fat32_sectors
[4];
259 UINT8 root_cluster
[4];
260 UINT8 fsinfo_sector
[2];
261 UINT8 backup_sector
[2];
272 /* MS-DOS EXFAT BIOS parameter block (109 bytes) */
281 UINT8 root_cluster
[4];
285 UINT8 sector_size_bits
;
286 UINT8 sectors_per_clu_bits
;
293 /* MS-DOS FAT file system information sector (512 bytes) */
295 UINT8 signature1
[4]; // aligned
296 UINT8 reserved1
[480];
297 UINT8 signature2
[4]; // aligned
298 UINT8 free_cluster
[4]; // aligned
299 UINT8 next_cluster
[4]; // aligned
304 /* MS-DOS FAT directory entry (32 bytes) */
310 UINT8 name
[DOS_NAME_LENGTH
];
313 UINT8 create_time_ms
;
314 UINT8 create_time
[2]; // aligned
315 UINT8 create_date
[2]; // aligned
316 UINT8 access_date
[2]; // aligned
317 UINT8 start_clu_hi
[2]; // aligned
318 UINT8 modify_time
[2]; // aligned
319 UINT8 modify_date
[2]; // aligned
320 UINT8 start_clu_lo
[2]; // aligned
321 UINT8 size
[4]; // aligned
324 /* MS-DOS FAT extended directory entry (32 bytes) */
327 UINT8 unicode_0_4
[10];
331 UINT8 unicode_5_10
[12]; // aligned
332 UINT8 start_clu
[2]; // aligned
333 UINT8 unicode_11_12
[4]; // aligned
336 /* MS-DOS EXFAT file directory entry (32 bytes) */
340 UINT8 checksum
[2]; // aligned
341 UINT8 attr
[2]; // aligned
343 UINT8 create_time
[2]; // aligned
344 UINT8 create_date
[2]; // aligned
345 UINT8 modify_time
[2]; // aligned
346 UINT8 modify_date
[2]; // aligned
347 UINT8 access_time
[2]; // aligned
348 UINT8 access_date
[2]; // aligned
349 UINT8 create_time_ms
;
350 UINT8 modify_time_ms
;
351 UINT8 access_time_ms
;
355 /* MS-DOS EXFAT stream extension directory entry (32 bytes) */
361 UINT8 name_hash
[2]; // aligned
363 UINT8 valid_size
[8]; // aligned
364 UINT8 reserved3
[4]; // aligned
365 UINT8 start_clu
[4]; // aligned
366 UINT8 size
[8]; // aligned
369 /* MS-DOS EXFAT file name directory entry (32 bytes) */
373 UINT8 unicode_0_14
[30]; // aligned
376 /* MS-DOS EXFAT allocation bitmap directory entry (32 bytes) */
381 UINT8 start_clu
[4]; // aligned
382 UINT8 size
[8]; // aligned
385 /* MS-DOS EXFAT up-case table directory entry (32 bytes) */
389 UINT8 checksum
[4]; // aligned
391 UINT8 start_clu
[4]; // aligned
392 UINT8 size
[8]; // aligned
395 /* MS-DOS EXFAT volume label directory entry (32 bytes) */
399 UINT8 unicode_0_10
[22]; // aligned
403 /* unused entry hint information */
410 /* file system volume information structure */
411 typedef struct __FS_STRUCT_T
{
413 struct super_block
*sb
;
414 struct semaphore v_sem
;
418 INT32 (*alloc_cluster
)(struct super_block
*sb
, INT32 num_alloc
, CHAIN_T
*p_chain
);
419 void (*free_cluster
)(struct super_block
*sb
, CHAIN_T
*p_chain
, INT32 do_relse
);
420 INT32 (*count_used_clusters
)(struct super_block
*sb
);
422 INT32 (*init_dir_entry
)(struct super_block
*sb
, CHAIN_T
*p_dir
, INT32 entry
, UINT32 type
,
423 UINT32 start_clu
, UINT64 size
);
424 INT32 (*init_ext_entry
)(struct super_block
*sb
, CHAIN_T
*p_dir
, INT32 entry
, INT32 num_entries
,
425 UNI_NAME_T
*p_uniname
, DOS_NAME_T
*p_dosname
);
426 INT32 (*find_dir_entry
)(struct super_block
*sb
, CHAIN_T
*p_dir
, UNI_NAME_T
*p_uniname
, INT32 num_entries
, DOS_NAME_T
*p_dosname
, UINT32 type
);
427 void (*delete_dir_entry
)(struct super_block
*sb
, CHAIN_T
*p_dir
, INT32 entry
, INT32 offset
, INT32 num_entries
);
428 void (*get_uni_name_from_ext_entry
)(struct super_block
*sb
, CHAIN_T
*p_dir
, INT32 entry
, UINT16
*uniname
);
429 INT32 (*count_ext_entries
)(struct super_block
*sb
, CHAIN_T
*p_dir
, INT32 entry
, DENTRY_T
*p_entry
);
430 INT32 (*calc_num_entries
)(UNI_NAME_T
*p_uniname
);
432 UINT32 (*get_entry_type
)(DENTRY_T
*p_entry
);
433 void (*set_entry_type
)(DENTRY_T
*p_entry
, UINT32 type
);
434 UINT32 (*get_entry_attr
)(DENTRY_T
*p_entry
);
435 void (*set_entry_attr
)(DENTRY_T
*p_entry
, UINT32 attr
);
436 UINT8 (*get_entry_flag
)(DENTRY_T
*p_entry
);
437 void (*set_entry_flag
)(DENTRY_T
*p_entry
, UINT8 flag
);
438 UINT32 (*get_entry_clu0
)(DENTRY_T
*p_entry
);
439 void (*set_entry_clu0
)(DENTRY_T
*p_entry
, UINT32 clu0
);
440 UINT64 (*get_entry_size
)(DENTRY_T
*p_entry
);
441 void (*set_entry_size
)(DENTRY_T
*p_entry
, UINT64 size
);
442 void (*get_entry_time
)(DENTRY_T
*p_entry
, TIMESTAMP_T
*tp
, UINT8 mode
);
443 void (*set_entry_time
)(DENTRY_T
*p_entry
, TIMESTAMP_T
*tp
, UINT8 mode
);
446 typedef struct __FS_INFO_T
{
447 UINT32 drv
; // drive ID
448 UINT32 vol_type
; // volume FAT type
449 UINT32 vol_id
; // volume serial number
451 UINT32 num_sectors
; // num of sectors in volume
452 UINT32 num_clusters
; // num of clusters in volume
453 UINT32 cluster_size
; // cluster size in bytes
454 UINT32 cluster_size_bits
;
455 UINT32 sectors_per_clu
; // cluster size in sectors
456 UINT32 sectors_per_clu_bits
;
458 UINT32 PBR_sector
; // PBR sector
459 UINT32 FAT1_start_sector
; // FAT1 start sector
460 UINT32 FAT2_start_sector
; // FAT2 start sector
461 UINT32 root_start_sector
; // root dir start sector
462 UINT32 data_start_sector
; // data area start sector
463 UINT32 num_FAT_sectors
; // num of FAT sectors
465 UINT32 root_dir
; // root dir cluster
466 UINT32 dentries_in_root
; // num of dentries in root dir
467 UINT32 dentries_per_clu
; // num of dentries per cluster
469 UINT32 vol_flag
; // volume dirty flag
470 struct buffer_head
*pbr_bh
; // PBR sector
472 UINT32 map_clu
; // allocation bitmap start cluster
473 UINT32 map_sectors
; // num of allocation bitmap sectors
474 struct buffer_head
**vol_amap
; // allocation bitmap
476 UINT16
**vol_utbl
; // upcase table
478 UINT32 clu_srch_ptr
; // cluster search pointer
479 UINT32 used_clusters
; // number of used clusters
480 UENTRY_T hint_uentry
; // unused entry hint information
482 UINT32 dev_ejected
; // block device operation error flag
487 BUF_CACHE_T FAT_cache_array
[FAT_CACHE_SIZE
];
488 BUF_CACHE_T FAT_cache_lru_list
;
489 BUF_CACHE_T FAT_cache_hash_list
[FAT_CACHE_HASH_SIZE
];
492 BUF_CACHE_T buf_cache_array
[BUF_CACHE_SIZE
];
493 BUF_CACHE_T buf_cache_lru_list
;
494 BUF_CACHE_T buf_cache_hash_list
[BUF_CACHE_HASH_SIZE
];
497 #define ES_2_ENTRIES 2
498 #define ES_3_ENTRIES 3
499 #define ES_ALL_ENTRIES 0
502 UINT32 sector
; // sector number that contains file_entry
503 INT32 offset
; // byte offset in the sector
504 INT32 alloc_flag
; // flag in stream entry. 01 for cluster chain, 03 for contig. clusteres.
507 // __buf should be the last member
511 /*----------------------------------------------------------------------*/
512 /* External Function Declarations */
513 /*----------------------------------------------------------------------*/
515 /* file system initialization & shutdown functions */
517 INT32
ffsShutdown(void);
519 /* volume management functions */
520 INT32
ffsMountVol(struct super_block
*sb
, INT32 drv
);
521 INT32
ffsUmountVol(struct super_block
*sb
);
522 INT32
ffsCheckVol(struct super_block
*sb
);
523 INT32
ffsGetVolInfo(struct super_block
*sb
, VOL_INFO_T
*info
);
524 INT32
ffsSyncVol(struct super_block
*sb
, INT32 do_sync
);
526 /* file management functions */
527 INT32
ffsLookupFile(struct inode
*inode
, UINT8
*path
, FILE_ID_T
*fid
);
528 INT32
ffsCreateFile(struct inode
*inode
, UINT8
*path
, UINT8 mode
, FILE_ID_T
*fid
);
529 INT32
ffsReadFile(struct inode
*inode
, FILE_ID_T
*fid
, void *buffer
, UINT64 count
, UINT64
*rcount
);
530 INT32
ffsWriteFile(struct inode
*inode
, FILE_ID_T
*fid
, void *buffer
, UINT64 count
, UINT64
*wcount
);
531 INT32
ffsTruncateFile(struct inode
*inode
, UINT64 old_size
, UINT64 new_size
);
532 INT32
ffsMoveFile(struct inode
*old_parent_inode
, FILE_ID_T
*fid
, struct inode
*new_parent_inode
, struct dentry
*new_dentry
);
533 INT32
ffsRemoveFile(struct inode
*inode
, FILE_ID_T
*fid
);
534 INT32
ffsSetAttr(struct inode
*inode
, UINT32 attr
);
535 INT32
ffsGetStat(struct inode
*inode
, DIR_ENTRY_T
*info
);
536 INT32
ffsSetStat(struct inode
*inode
, DIR_ENTRY_T
*info
);
537 INT32
ffsMapCluster(struct inode
*inode
, INT32 clu_offset
, UINT32
*clu
);
539 /* directory management functions */
540 INT32
ffsCreateDir(struct inode
*inode
, UINT8
*path
, FILE_ID_T
*fid
);
541 INT32
ffsReadDir(struct inode
*inode
, DIR_ENTRY_T
*dir_ent
);
542 INT32
ffsRemoveDir(struct inode
*inode
, FILE_ID_T
*fid
);
544 /*----------------------------------------------------------------------*/
545 /* External Function Declarations (NOT TO UPPER LAYER) */
546 /*----------------------------------------------------------------------*/
548 /* fs management functions */
550 INT32
fs_shutdown(void);
551 void fs_set_vol_flags(struct super_block
*sb
, UINT32 new_flag
);
552 void fs_sync(struct super_block
*sb
, INT32 do_sync
);
553 void fs_error(struct super_block
*sb
);
555 /* cluster management functions */
556 INT32
clear_cluster(struct super_block
*sb
, UINT32 clu
);
557 INT32
fat_alloc_cluster(struct super_block
*sb
, INT32 num_alloc
, CHAIN_T
*p_chain
);
558 INT32
exfat_alloc_cluster(struct super_block
*sb
, INT32 num_alloc
, CHAIN_T
*p_chain
);
559 void fat_free_cluster(struct super_block
*sb
, CHAIN_T
*p_chain
, INT32 do_relse
);
560 void exfat_free_cluster(struct super_block
*sb
, CHAIN_T
*p_chain
, INT32 do_relse
);
561 UINT32
find_last_cluster(struct super_block
*sb
, CHAIN_T
*p_chain
);
562 INT32
count_num_clusters(struct super_block
*sb
, CHAIN_T
*dir
);
563 INT32
fat_count_used_clusters(struct super_block
*sb
);
564 INT32
exfat_count_used_clusters(struct super_block
*sb
);
565 void exfat_chain_cont_cluster(struct super_block
*sb
, UINT32 chain
, INT32 len
);
567 /* allocation bitmap management functions */
568 INT32
load_alloc_bitmap(struct super_block
*sb
);
569 void free_alloc_bitmap(struct super_block
*sb
);
570 INT32
set_alloc_bitmap(struct super_block
*sb
, UINT32 clu
);
571 INT32
clr_alloc_bitmap(struct super_block
*sb
, UINT32 clu
);
572 UINT32
test_alloc_bitmap(struct super_block
*sb
, UINT32 clu
);
573 void sync_alloc_bitmap(struct super_block
*sb
);
575 /* upcase table management functions */
576 INT32
load_upcase_table(struct super_block
*sb
);
577 void free_upcase_table(struct super_block
*sb
);
579 /* dir entry management functions */
580 UINT32
fat_get_entry_type(DENTRY_T
*p_entry
);
581 UINT32
exfat_get_entry_type(DENTRY_T
*p_entry
);
582 void fat_set_entry_type(DENTRY_T
*p_entry
, UINT32 type
);
583 void exfat_set_entry_type(DENTRY_T
*p_entry
, UINT32 type
);
584 UINT32
fat_get_entry_attr(DENTRY_T
*p_entry
);
585 UINT32
exfat_get_entry_attr(DENTRY_T
*p_entry
);
586 void fat_set_entry_attr(DENTRY_T
*p_entry
, UINT32 attr
);
587 void exfat_set_entry_attr(DENTRY_T
*p_entry
, UINT32 attr
);
588 UINT8
fat_get_entry_flag(DENTRY_T
*p_entry
);
589 UINT8
exfat_get_entry_flag(DENTRY_T
*p_entry
);
590 void fat_set_entry_flag(DENTRY_T
*p_entry
, UINT8 flag
);
591 void exfat_set_entry_flag(DENTRY_T
*p_entry
, UINT8 flag
);
592 UINT32
fat_get_entry_clu0(DENTRY_T
*p_entry
);
593 UINT32
exfat_get_entry_clu0(DENTRY_T
*p_entry
);
594 void fat_set_entry_clu0(DENTRY_T
*p_entry
, UINT32 start_clu
);
595 void exfat_set_entry_clu0(DENTRY_T
*p_entry
, UINT32 start_clu
);
596 UINT64
fat_get_entry_size(DENTRY_T
*p_entry
);
597 UINT64
exfat_get_entry_size(DENTRY_T
*p_entry
);
598 void fat_set_entry_size(DENTRY_T
*p_entry
, UINT64 size
);
599 void exfat_set_entry_size(DENTRY_T
*p_entry
, UINT64 size
);
600 void fat_get_entry_time(DENTRY_T
*p_entry
, TIMESTAMP_T
*tp
, UINT8 mode
);
601 void exfat_get_entry_time(DENTRY_T
*p_entry
, TIMESTAMP_T
*tp
, UINT8 mode
);
602 void fat_set_entry_time(DENTRY_T
*p_entry
, TIMESTAMP_T
*tp
, UINT8 mode
);
603 void exfat_set_entry_time(DENTRY_T
*p_entry
, TIMESTAMP_T
*tp
, UINT8 mode
);
604 INT32
fat_init_dir_entry(struct super_block
*sb
, CHAIN_T
*p_dir
, INT32 entry
, UINT32 type
, UINT32 start_clu
, UINT64 size
);
605 INT32
exfat_init_dir_entry(struct super_block
*sb
, CHAIN_T
*p_dir
, INT32 entry
, UINT32 type
, UINT32 start_clu
, UINT64 size
);
606 INT32
fat_init_ext_dir_entry(struct super_block
*sb
, CHAIN_T
*p_dir
, INT32 entry
, INT32 num_entries
, UNI_NAME_T
*p_uniname
, DOS_NAME_T
*p_dosname
);
607 INT32
exfat_init_ext_dir_entry(struct super_block
*sb
, CHAIN_T
*p_dir
, INT32 entry
, INT32 num_entries
, UNI_NAME_T
*p_uniname
, DOS_NAME_T
*p_dosname
);
608 void init_dos_entry(DOS_DENTRY_T
*ep
, UINT32 type
, UINT32 start_clu
);
609 void init_ext_entry(EXT_DENTRY_T
*ep
, INT32 order
, UINT8 chksum
, UINT16
*uniname
);
610 void init_file_entry(FILE_DENTRY_T
*ep
, UINT32 type
);
611 void init_strm_entry(STRM_DENTRY_T
*ep
, UINT8 flags
, UINT32 start_clu
, UINT64 size
);
612 void init_name_entry(NAME_DENTRY_T
*ep
, UINT16
*uniname
);
613 void fat_delete_dir_entry(struct super_block
*sb
, CHAIN_T
*p_dir
, INT32 entry
, INT32 order
, INT32 num_entries
);
614 void exfat_delete_dir_entry(struct super_block
*sb
, CHAIN_T
*p_dir
, INT32 entry
, INT32 order
, INT32 num_entries
);
616 INT32
find_location(struct super_block
*sb
, CHAIN_T
*p_dir
, INT32 entry
, UINT32
*sector
, INT32
*offset
);
617 DENTRY_T
*get_entry_with_sector(struct super_block
*sb
, UINT32 sector
, INT32 offset
);
618 DENTRY_T
*get_entry_in_dir(struct super_block
*sb
, CHAIN_T
*p_dir
, INT32 entry
, UINT32
*sector
);
619 ENTRY_SET_CACHE_T
*get_entry_set_in_dir (struct super_block
*sb
, CHAIN_T
*p_dir
, INT32 entry
, UINT32 type
, DENTRY_T
**file_ep
);
620 void release_entry_set (ENTRY_SET_CACHE_T
*es
);
621 INT32
write_whole_entry_set (struct super_block
*sb
, ENTRY_SET_CACHE_T
*es
);
622 INT32
write_partial_entries_in_entry_set (struct super_block
*sb
, ENTRY_SET_CACHE_T
*es
, DENTRY_T
*ep
, UINT32 count
);
623 INT32
search_deleted_or_unused_entry(struct super_block
*sb
, CHAIN_T
*p_dir
, INT32 num_entries
);
624 INT32
find_empty_entry(struct inode
*inode
, CHAIN_T
*p_dir
, INT32 num_entries
);
625 INT32
fat_find_dir_entry(struct super_block
*sb
, CHAIN_T
*p_dir
, UNI_NAME_T
*p_uniname
, INT32 num_entries
, DOS_NAME_T
*p_dosname
, UINT32 type
);
626 INT32
exfat_find_dir_entry(struct super_block
*sb
, CHAIN_T
*p_dir
, UNI_NAME_T
*p_uniname
, INT32 num_entries
, DOS_NAME_T
*p_dosname
, UINT32 type
);
627 INT32
fat_count_ext_entries(struct super_block
*sb
, CHAIN_T
*p_dir
, INT32 entry
, DENTRY_T
*p_entry
);
628 INT32
exfat_count_ext_entries(struct super_block
*sb
, CHAIN_T
*p_dir
, INT32 entry
, DENTRY_T
*p_entry
);
629 INT32
count_dos_name_entries(struct super_block
*sb
, CHAIN_T
*p_dir
, UINT32 type
);
630 void update_dir_checksum(struct super_block
*sb
, CHAIN_T
*p_dir
, INT32 entry
);
631 void update_dir_checksum_with_entry_set (struct super_block
*sb
, ENTRY_SET_CACHE_T
*es
);
632 BOOL
is_dir_empty(struct super_block
*sb
, CHAIN_T
*p_dir
);
634 /* name conversion functions */
635 INT32
get_num_entries_and_dos_name(struct super_block
*sb
, CHAIN_T
*p_dir
, UNI_NAME_T
*p_uniname
, INT32
*entries
, DOS_NAME_T
*p_dosname
);
636 void get_uni_name_from_dos_entry(struct super_block
*sb
, DOS_DENTRY_T
*ep
, UNI_NAME_T
*p_uniname
, UINT8 mode
);
637 void fat_get_uni_name_from_ext_entry(struct super_block
*sb
, CHAIN_T
*p_dir
, INT32 entry
, UINT16
*uniname
);
638 void exfat_get_uni_name_from_ext_entry(struct super_block
*sb
, CHAIN_T
*p_dir
, INT32 entry
, UINT16
*uniname
);
639 INT32
extract_uni_name_from_ext_entry(EXT_DENTRY_T
*ep
, UINT16
*uniname
, INT32 order
);
640 INT32
extract_uni_name_from_name_entry(NAME_DENTRY_T
*ep
, UINT16
*uniname
, INT32 order
);
641 INT32
fat_generate_dos_name(struct super_block
*sb
, CHAIN_T
*p_dir
, DOS_NAME_T
*p_dosname
);
642 void fat_attach_count_to_dos_name(UINT8
*dosname
, INT32 count
);
643 INT32
fat_calc_num_entries(UNI_NAME_T
*p_uniname
);
644 INT32
exfat_calc_num_entries(UNI_NAME_T
*p_uniname
);
645 UINT8
calc_checksum_1byte(void *data
, INT32 len
, UINT8 chksum
);
646 UINT16
calc_checksum_2byte(void *data
, INT32 len
, UINT16 chksum
, INT32 type
);
647 UINT32
calc_checksum_4byte(void *data
, INT32 len
, UINT32 chksum
, INT32 type
);
649 /* name resolution functions */
650 INT32
resolve_path(struct inode
*inode
, UINT8
*path
, CHAIN_T
*p_dir
, UNI_NAME_T
*p_uniname
);
651 INT32
resolve_name(UINT8
*name
, UINT8
**arg
);
653 /* file operation functions */
654 INT32
fat16_mount(struct super_block
*sb
, PBR_SECTOR_T
*p_pbr
);
655 INT32
fat32_mount(struct super_block
*sb
, PBR_SECTOR_T
*p_pbr
);
656 INT32
exfat_mount(struct super_block
*sb
, PBR_SECTOR_T
*p_pbr
);
657 INT32
create_dir(struct inode
*inode
, CHAIN_T
*p_dir
, UNI_NAME_T
*p_uniname
, FILE_ID_T
*fid
);
658 INT32
create_file(struct inode
*inode
, CHAIN_T
*p_dir
, UNI_NAME_T
*p_uniname
, UINT8 mode
, FILE_ID_T
*fid
);
659 void remove_file(struct inode
*inode
, CHAIN_T
*p_dir
, INT32 entry
);
660 INT32
rename_file(struct inode
*inode
, CHAIN_T
*p_dir
, INT32 old_entry
, UNI_NAME_T
*p_uniname
, FILE_ID_T
*fid
);
661 INT32
move_file(struct inode
*inode
, CHAIN_T
*p_olddir
, INT32 oldentry
, CHAIN_T
*p_newdir
, UNI_NAME_T
*p_uniname
, FILE_ID_T
*fid
);
663 /* sector read/write functions */
664 INT32
sector_read(struct super_block
*sb
, UINT32 sec
, struct buffer_head
**bh
, INT32 read
);
665 INT32
sector_write(struct super_block
*sb
, UINT32 sec
, struct buffer_head
*bh
, INT32 sync
);
666 INT32
multi_sector_read(struct super_block
*sb
, UINT32 sec
, struct buffer_head
**bh
, INT32 num_secs
, INT32 read
);
667 INT32
multi_sector_write(struct super_block
*sb
, UINT32 sec
, struct buffer_head
*bh
, INT32 num_secs
, INT32 sync
);
671 #endif /* __cplusplus */
673 #endif /* _EXFAT_H */