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, see <http://www.gnu.org/licenses/>.
26 #endif /* __cplusplus */
29 /*----------------------------------------------------------------------*/
30 /* Configure Constant & Macro Definitions */
31 /*----------------------------------------------------------------------*/
32 /* cache size (in number of sectors) */
33 /* (should be an exponential value of 2) */
34 #define FAT_CACHE_SIZE 128
35 #define FAT_CACHE_HASH_SIZE 64
36 #define BUF_CACHE_SIZE 256
37 #define BUF_CACHE_HASH_SIZE 64
39 /* Read-ahead related */
40 /* First config vars. should be pow of 2 */
41 #define FCACHE_MAX_RA_SIZE (PAGE_SIZE)
42 #define DCACHE_MAX_RA_SIZE (128*1024)
44 /*----------------------------------------------------------------------*/
45 /* Constant & Macro Definitions */
46 /*----------------------------------------------------------------------*/
48 #define TYPE_UNUSED 0x0000
49 #define TYPE_DELETED 0x0001
50 #define TYPE_INVALID 0x0002
51 #define TYPE_CRITICAL_PRI 0x0100
52 #define TYPE_BITMAP 0x0101
53 #define TYPE_UPCASE 0x0102
54 #define TYPE_VOLUME 0x0103
55 #define TYPE_DIR 0x0104
56 #define TYPE_FILE 0x011F
57 #define TYPE_SYMLINK 0x015F
58 #define TYPE_CRITICAL_SEC 0x0200
59 #define TYPE_STREAM 0x0201
60 #define TYPE_EXTEND 0x0202
61 #define TYPE_ACL 0x0203
62 #define TYPE_BENIGN_PRI 0x0400
63 #define TYPE_GUID 0x0401
64 #define TYPE_PADDING 0x0402
65 #define TYPE_ACLTAB 0x0403
66 #define TYPE_BENIGN_SEC 0x0800
67 #define TYPE_ALL 0x0FFF
70 #define SDFAT_EIO_NONE (0x00000000)
71 #define SDFAT_EIO_READ (0x00000001)
72 #define SDFAT_EIO_WRITE (0x00000002)
73 #define SDFAT_EIO_BDI (0x00000004)
75 /* modes for volume allocation unit status */
76 #define VOL_AU_STAT_TOTAL (0)
77 #define VOL_AU_STAT_CLEAN (1)
78 #define VOL_AU_STAT_FULL (2)
80 /*----------------------------------------------------------------------*/
81 /* NLS Type Definitions */
82 /*----------------------------------------------------------------------*/
84 /* DOS name structure */
86 u8 name
[DOS_NAME_LENGTH
];
90 /* unicode name structure */
92 u16 name
[MAX_NAME_LENGTH
+3]; /* +3 for null and for converting */
97 /*----------------------------------------------------------------------*/
98 /* Type Definitions */
99 /*----------------------------------------------------------------------*/
100 /* should be merged it to DATE_TIME_T */
102 u16 sec
; /* 0 ~ 59 */
103 u16 min
; /* 0 ~ 59 */
104 u16 hour
; /* 0 ~ 23 */
105 u16 day
; /* 1 ~ 31 */
106 u16 mon
; /* 1 ~ 12 */
107 u16 year
; /* 0 ~ 127 (since 1980) */
122 u32 Offset
; // start sector number of the partition
123 u32 Size
; // in sectors
127 u32 SecSize
; // sector size in bytes
128 u32 DevSize
; // block device size in sectors
139 /* directory structure */
150 s32 off
; // cluster offset
151 s32 eidx
; // entry index
156 spinlock_t cache_lru_lock
;
157 struct list_head cache_lru
;
159 u32 cache_valid_id
; // for avoiding the race between alloc and free
162 /* first empty entry hint information */
164 s32 eidx
; // entry index of a directory
165 s32 count
; // count of continuous empty entry
166 CHAIN_T cur
; // the cluster that first empty slot exists in
169 /* file id structure */
178 u8 reserved
[3]; // padding
179 u32 version
; // the copy of low 32bit of i_version to check the validation of hint_stat
180 s64 rwoffset
; // file offset or dentry index for readdir
181 EXTENT_T extent
; // extent cache for a file
182 HINT_T hint_bmap
; // hint for cluster last accessed
183 HINT_T hint_stat
; // hint for entry index we try to lookup next time
184 HINT_FEMP_T hint_femp
; // hint for first empty entry
190 s32 lfnbuf_len
; //usally MAX_UNINAME_BUF_SIZE
191 s32 sfnbuf_len
; //usally MAX_DOSNAME_BUF_SIZE, used only for vfat, not for exfat
198 DATE_TIME_T CreateTimestamp
;
199 DATE_TIME_T ModifyTimestamp
;
200 DATE_TIME_T AccessTimestamp
;
201 DENTRY_NAMEBUF_T NameBuf
;
204 /* cache information */
205 typedef struct __cache_entry
{
206 struct __cache_entry
*next
;
207 struct __cache_entry
*prev
;
209 struct __cache_entry
*next
;
210 struct __cache_entry
*prev
;
214 struct buffer_head
*bh
;
217 /*----------------------------------------------------------------------*/
218 /* Type Definitions : Wrapper & In-Core */
219 /*----------------------------------------------------------------------*/
220 typedef struct __FATENT_OPS_T
{
221 s32 (*ent_get
)(struct super_block
*sb
, u32 loc
, u32
*content
);
222 s32 (*ent_set
)(struct super_block
*sb
, u32 loc
, u32 content
);
226 s32 (*alloc_cluster
)(struct super_block
*, s32
, CHAIN_T
*, int);
227 s32 (*free_cluster
)(struct super_block
*, CHAIN_T
*, s32
);
228 s32 (*count_used_clusters
)(struct super_block
*, u32
*);
229 s32 (*init_dir_entry
)(struct super_block
*, CHAIN_T
*, s32
, u32
, u32
, u64
);
230 s32 (*init_ext_entry
)(struct super_block
*, CHAIN_T
*, s32
, s32
, UNI_NAME_T
*, DOS_NAME_T
*);
231 s32 (*find_dir_entry
)(struct super_block
*, FILE_ID_T
*, CHAIN_T
*, UNI_NAME_T
*, s32
, DOS_NAME_T
*, u32
);
232 s32 (*delete_dir_entry
)(struct super_block
*, CHAIN_T
*, s32
, s32
, s32
);
233 void (*get_uniname_from_ext_entry
)(struct super_block
*, CHAIN_T
*, s32
, u16
*);
234 s32 (*count_ext_entries
)(struct super_block
*, CHAIN_T
*, s32
, DENTRY_T
*);
235 s32 (*calc_num_entries
)(UNI_NAME_T
*);
236 s32 (*check_max_dentries
)(FILE_ID_T
*);
237 u32 (*get_entry_type
)(DENTRY_T
*);
238 void (*set_entry_type
)(DENTRY_T
*, u32
);
239 u32 (*get_entry_attr
)(DENTRY_T
*);
240 void (*set_entry_attr
)(DENTRY_T
*, u32
);
241 u8 (*get_entry_flag
)(DENTRY_T
*);
242 void (*set_entry_flag
)(DENTRY_T
*, u8
);
243 u32 (*get_entry_clu0
)(DENTRY_T
*);
244 void (*set_entry_clu0
)(DENTRY_T
*, u32
);
245 u64 (*get_entry_size
)(DENTRY_T
*);
246 void (*set_entry_size
)(DENTRY_T
*, u64
);
247 void (*get_entry_time
)(DENTRY_T
*, TIMESTAMP_T
*, u8
);
248 void (*set_entry_time
)(DENTRY_T
*, TIMESTAMP_T
*, u8
);
249 u32 (*get_au_stat
)(struct super_block
*, s32
);
252 typedef struct __FS_INFO_T
{
253 s32 bd_opened
; // opened or not
254 u32 vol_type
; // volume FAT type
255 u32 vol_id
; // volume serial number
256 u32 num_sectors
; // num of sectors in volume
257 u32 num_clusters
; // num of clusters in volume
258 u32 cluster_size
; // cluster size in bytes
259 u32 cluster_size_bits
;
260 u32 sect_per_clus
; // cluster size in sectors
261 u32 sect_per_clus_bits
;
262 u32 FAT1_start_sector
; // FAT1 start sector
263 u32 FAT2_start_sector
; // FAT2 start sector
264 u32 root_start_sector
; // root dir start sector
265 u32 data_start_sector
; // data area start sector
266 u32 num_FAT_sectors
; // num of FAT sectors
267 u32 root_dir
; // root dir cluster
268 u32 dentries_in_root
; // num of dentries in root dir
269 u32 dentries_per_clu
; // num of dentries per cluster
270 u32 vol_flag
; // volume dirty flag
271 struct buffer_head
*pbr_bh
; // buffer_head of PBR sector
273 u32 map_clu
; // allocation bitmap start cluster
274 u32 map_sectors
; // num of allocation bitmap sectors
275 struct buffer_head
**vol_amap
; // allocation bitmap
277 u16
**vol_utbl
; // upcase table
279 u32 clu_srch_ptr
; // cluster search pointer
280 u32 used_clusters
; // number of used clusters
282 u32 prev_eio
; // block device operation error flag
285 FATENT_OPS_T
*fatent_ops
;
287 s32 reserved_clusters
; // # of reserved clusters (DA)
288 void *amap
; // AU Allocation Map
292 cache_ent_t pool
[FAT_CACHE_SIZE
];
293 cache_ent_t lru_list
;
294 cache_ent_t hash_list
[FAT_CACHE_HASH_SIZE
];
299 cache_ent_t pool
[BUF_CACHE_SIZE
];
300 cache_ent_t lru_list
;
301 cache_ent_t keep_list
; // CACHEs in this list will not be kicked by normal lru operations
302 cache_ent_t hash_list
[BUF_CACHE_HASH_SIZE
];
306 /*======================================================================*/
308 /* API FUNCTION DECLARATIONS */
309 /* (CHANGE THIS PART IF REQUIRED) */
311 /*======================================================================*/
313 /*----------------------------------------------------------------------*/
314 /* External Function Declarations */
315 /*----------------------------------------------------------------------*/
317 /* file system initialization & shutdown functions */
318 s32
fsapi_init(void);
319 s32
fsapi_shutdown(void);
321 /* volume management functions */
322 s32
fsapi_mount(struct super_block
*sb
);
323 s32
fsapi_umount(struct super_block
*sb
);
324 s32
fsapi_statfs(struct super_block
*sb
, VOL_INFO_T
*info
);
325 s32
fsapi_sync_fs(struct super_block
*sb
, s32 do_sync
);
326 s32
fsapi_set_vol_flags(struct super_block
*sb
, u16 new_flag
, s32 always_sync
);
328 /* file management functions */
329 s32
fsapi_lookup(struct inode
*inode
, u8
*path
, FILE_ID_T
*fid
);
330 s32
fsapi_create(struct inode
*inode
, u8
*path
, u8 mode
, FILE_ID_T
*fid
);
331 s32
fsapi_read_link(struct inode
*inode
, FILE_ID_T
*fid
, void *buffer
, u64 count
, u64
*rcount
);
332 s32
fsapi_write_link(struct inode
*inode
, FILE_ID_T
*fid
, void *buffer
, u64 count
, u64
*wcount
);
333 s32
fsapi_remove(struct inode
*inode
, FILE_ID_T
*fid
); /* unlink and truncate */
334 s32
fsapi_truncate(struct inode
*inode
, u64 old_size
, u64 new_size
);
335 s32
fsapi_rename(struct inode
*old_parent_inode
, FILE_ID_T
*fid
,
336 struct inode
*new_parent_inode
, struct dentry
*new_dentry
);
337 s32
fsapi_unlink(struct inode
*inode
, FILE_ID_T
*fid
);
338 s32
fsapi_read_inode(struct inode
*inode
, DIR_ENTRY_T
*info
);
339 s32
fsapi_write_inode(struct inode
*inode
, DIR_ENTRY_T
*info
, int sync
);
340 s32
fsapi_map_clus(struct inode
*inode
, s32 clu_offset
, u32
*clu
, int dest
);
341 s32
fsapi_reserve_clus(struct inode
*inode
);
343 /* directory management functions */
344 s32
fsapi_mkdir(struct inode
*inode
, u8
*path
, FILE_ID_T
*fid
);
345 s32
fsapi_readdir(struct inode
*inode
, DIR_ENTRY_T
*dir_entry
);
346 s32
fsapi_rmdir(struct inode
*inode
, FILE_ID_T
*fid
);
348 /* FAT & buf cache functions */
349 s32
fsapi_cache_flush(struct super_block
*sb
, int do_sync
);
350 s32
fsapi_cache_release(struct super_block
*sb
);
352 /* extra info functions */
353 u32
fsapi_get_au_stat(struct super_block
*sb
, s32 mode
);
355 /* extent cache functions */
356 void fsapi_invalidate_extent(struct inode
*inode
);
358 #ifdef CONFIG_SDFAT_DFR
359 /*----------------------------------------------------------------------*/
360 /* Defragmentation related */
361 /*----------------------------------------------------------------------*/
363 s32
fsapi_dfr_get_info(struct super_block
*sb
, void *arg
);
365 s32
fsapi_dfr_scan_dir(struct super_block
*sb
, void *args
);
367 s32
fsapi_dfr_validate_clus(struct inode
*inode
, void *chunk
, int skip_prev
);
368 s32
fsapi_dfr_reserve_clus(struct super_block
*sb
, s32 nr_clus
);
369 s32
fsapi_dfr_mark_ignore(struct super_block
*sb
, unsigned int clus
);
370 void fsapi_dfr_unmark_ignore_all(struct super_block
*sb
);
372 s32
fsapi_dfr_map_clus(struct inode
*inode
, u32 clu_offset
, u32
*clu
);
373 void fsapi_dfr_writepage_endio(struct page
*page
);
375 void fsapi_dfr_update_fat_prev(struct super_block
*sb
, int force
);
376 void fsapi_dfr_update_fat_next(struct super_block
*sb
);
377 void fsapi_dfr_check_discard(struct super_block
*sb
);
378 void fsapi_dfr_free_clus(struct super_block
*sb
, u32 clus
);
380 s32
fsapi_dfr_check_dfr_required(struct super_block
*sb
, int *totalau
, int *cleanau
, int *fullau
);
381 s32
fsapi_dfr_check_dfr_on(struct inode
*inode
, loff_t start
, loff_t end
, s32 cancel
, const char *caller
);
384 #ifdef CONFIG_SDFAT_DFR_DEBUG
385 void fsapi_dfr_spo_test(struct super_block
*sb
, int flag
, const char *caller
);
386 #endif /* CONFIG_SDFAT_DFR_DEBUG */
388 #endif /* CONFIG_SDFAT_DFR */
393 #endif /* __cplusplus */
395 #endif /* _SDFAT_API_H */