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/>.
21 #include <asm/byteorder.h>
29 #endif /* __cplusplus */
31 /*----------------------------------------------------------------------*/
32 /* Constant & Macro Definitions */
33 /*----------------------------------------------------------------------*/
34 #define get_next_clus(sb, pclu) fat_ent_get(sb, *(pclu), pclu)
35 #define get_next_clus_safe(sb, pclu) fat_ent_get_safe(sb, *(pclu), pclu)
39 * fscore_write_inode, fscore_map_clus, ... with the unlinked inodes
40 * from corrupting on-disk dentry data.
42 * The fid->dir value of unlinked inode will be DIR_DELETED
43 * and those functions must check if fid->dir is valid prior to
44 * the calling of get_dentry_in_dir()
46 #define DIR_DELETED 0xFFFF0321
48 /*----------------------------------------------------------------------*/
49 /* Type Definitions */
50 /*----------------------------------------------------------------------*/
51 #define ES_2_ENTRIES 2
52 #define ES_3_ENTRIES 3
53 #define ES_ALL_ENTRIES 0
56 u32 sector
; // sector number that contains file_entry
57 s32 offset
; // byte offset in the sector
58 s32 alloc_flag
; // flag in stream entry. 01 for cluster chain, 03 for contig. clusteres.
60 // __buf should be the last member
66 /*----------------------------------------------------------------------*/
67 /* External Function Declarations */
68 /*----------------------------------------------------------------------*/
70 /* file system initialization & shutdown functions */
71 s32
fscore_init(void);
72 s32
fscore_shutdown(void);
74 /* chain management */
75 s32
chain_cont_cluster(struct super_block
*sb
, u32 chain
, s32 len
);
77 /* volume management functions */
78 s32
fscore_mount(struct super_block
*sb
);
79 s32
fscore_umount(struct super_block
*sb
);
80 s32
fscore_statfs(struct super_block
*sb
, VOL_INFO_T
*info
);
81 s32
fscore_sync_fs(struct super_block
*sb
, s32 do_sync
);
82 s32
fscore_set_vol_flags(struct super_block
*sb
, u16 new_flag
, s32 always_sync
);
83 u32
fscore_get_au_stat(struct super_block
*sb
, s32 mode
);
85 /* file management functions */
86 s32
fscore_lookup(struct inode
*inode
, u8
*path
, FILE_ID_T
*fid
);
87 s32
fscore_create(struct inode
*inode
, u8
*path
, u8 mode
, FILE_ID_T
*fid
);
88 s32
fscore_read_link(struct inode
*inode
, FILE_ID_T
*fid
, void *buffer
, u64 count
, u64
*rcount
);
89 s32
fscore_write_link(struct inode
*inode
, FILE_ID_T
*fid
, void *buffer
, u64 count
, u64
*wcount
);
90 s32
fscore_truncate(struct inode
*inode
, u64 old_size
, u64 new_size
);
91 s32
fscore_rename(struct inode
*old_parent_inode
, FILE_ID_T
*fid
,
92 struct inode
*new_parent_inode
, struct dentry
*new_dentry
);
93 s32
fscore_remove(struct inode
*inode
, FILE_ID_T
*fid
);
94 s32
fscore_read_inode(struct inode
*inode
, DIR_ENTRY_T
*info
);
95 s32
fscore_write_inode(struct inode
*inode
, DIR_ENTRY_T
*info
, int sync
);
96 s32
fscore_map_clus(struct inode
*inode
, s32 clu_offset
, u32
*clu
, int dest
);
97 s32
fscore_reserve_clus(struct inode
*inode
);
98 s32
fscore_unlink(struct inode
*inode
, FILE_ID_T
*fid
);
100 /* directory management functions */
101 s32
fscore_mkdir(struct inode
*inode
, u8
*path
, FILE_ID_T
*fid
);
102 s32
fscore_readdir(struct inode
*inode
, DIR_ENTRY_T
*dir_ent
);
103 s32
fscore_rmdir(struct inode
*inode
, FILE_ID_T
*fid
);
106 /*----------------------------------------------------------------------*/
107 /* External Function Declarations (NOT TO UPPER LAYER) */
108 /*----------------------------------------------------------------------*/
110 /* core.c : core code for common */
111 /* dir entry management functions */
112 DENTRY_T
*get_dentry_in_dir(struct super_block
*sb
, CHAIN_T
*p_dir
, s32 entry
, u32
*sector
);
114 /* name conversion functions */
115 void get_uniname_from_dos_entry(struct super_block
*sb
, DOS_DENTRY_T
*ep
, UNI_NAME_T
*p_uniname
, u8 mode
);
117 /* file operation functions */
118 s32
walk_fat_chain(struct super_block
*sb
, CHAIN_T
*p_dir
, s32 byte_offset
, u32
*clu
);
121 s32
meta_cache_init(struct super_block
*sb
);
122 s32
meta_cache_shutdown(struct super_block
*sb
);
123 u8
*fcache_getblk(struct super_block
*sb
, u32 sec
);
124 s32
fcache_modify(struct super_block
*sb
, u32 sec
);
125 s32
fcache_release_all(struct super_block
*sb
);
126 s32
fcache_flush(struct super_block
*sb
, u32 sync
);
128 u8
*dcache_getblk(struct super_block
*sb
, u32 sec
);
129 s32
dcache_modify(struct super_block
*sb
, u32 sec
);
130 s32
dcache_lock(struct super_block
*sb
, u32 sec
);
131 s32
dcache_unlock(struct super_block
*sb
, u32 sec
);
132 s32
dcache_release(struct super_block
*sb
, u32 sec
);
133 s32
dcache_release_all(struct super_block
*sb
);
134 s32
dcache_flush(struct super_block
*sb
, u32 sync
);
135 s32
dcache_readahead(struct super_block
*sb
, u32 sec
);
139 s32
fat_ent_ops_init(struct super_block
*sb
);
140 s32
fat_ent_get(struct super_block
*sb
, u32 loc
, u32
*content
);
141 s32
fat_ent_set(struct super_block
*sb
, u32 loc
, u32 content
);
142 s32
fat_ent_get_safe(struct super_block
*sb
, u32 loc
, u32
*content
);
144 /* core_fat.c : core code for fat */
145 s32
fat_generate_dos_name_new(struct super_block
*sb
, CHAIN_T
*p_dir
, DOS_NAME_T
*p_dosname
, s32 n_entries
);
146 s32
mount_fat16(struct super_block
*sb
, pbr_t
*p_pbr
);
147 s32
mount_fat32(struct super_block
*sb
, pbr_t
*p_pbr
);
149 /* core_exfat.c : core code for exfat */
151 s32
load_alloc_bmp(struct super_block
*sb
);
152 void free_alloc_bmp(struct super_block
*sb
);
153 ENTRY_SET_CACHE_T
*get_dentry_set_in_dir(struct super_block
*sb
,
154 CHAIN_T
*p_dir
, s32 entry
, u32 type
, DENTRY_T
**file_ep
);
155 void release_dentry_set(ENTRY_SET_CACHE_T
*es
);
156 s32
update_dir_chksum(struct super_block
*sb
, CHAIN_T
*p_dir
, s32 entry
);
157 s32
update_dir_chksum_with_entry_set(struct super_block
*sb
, ENTRY_SET_CACHE_T
*es
);
158 bool is_dir_empty(struct super_block
*sb
, CHAIN_T
*p_dir
);
159 s32
mount_exfat(struct super_block
*sb
, pbr_t
*p_pbr
);
161 /* amap_smart.c : creation on mount / destroy on umount */
162 int amap_create(struct super_block
*sb
, u32 pack_ratio
, u32 sect_per_au
, u32 hidden_sect
);
163 void amap_destroy(struct super_block
*sb
);
165 /* amap_smart.c : (de)allocation functions */
166 s32
amap_fat_alloc_cluster(struct super_block
*sb
, s32 num_alloc
, CHAIN_T
*p_chain
, int dest
);
167 s32
amap_free_cluster(struct super_block
*sb
, CHAIN_T
*p_chain
, s32 do_relse
);/* Not impelmented */
168 s32
amap_release_cluster(struct super_block
*sb
, u32 clu
); /* Only update AMAP */
170 /* amap_smart.c : misc (for defrag) */
171 s32
amap_mark_ignore(struct super_block
*sb
, u32 clu
);
172 s32
amap_unmark_ignore(struct super_block
*sb
, u32 clu
);
173 s32
amap_unmark_ignore_all(struct super_block
*sb
);
174 s32
amap_check_working(struct super_block
*sb
, u32 clu
);
175 s32
amap_get_freeclus(struct super_block
*sb
, u32 clu
);
177 /* amap_smart.c : stat AU */
178 u32
amap_get_au_stat(struct super_block
*sb
, s32 mode
);
182 s32
bdev_open_dev(struct super_block
*sb
);
183 s32
bdev_close_dev(struct super_block
*sb
);
184 s32
bdev_check_bdi_valid(struct super_block
*sb
);
185 s32
bdev_readahead(struct super_block
*sb
, u32 secno
, u32 num_secs
);
186 s32
bdev_mread(struct super_block
*sb
, u32 secno
, struct buffer_head
**bh
, u32 num_secs
, s32 read
);
187 s32
bdev_mwrite(struct super_block
*sb
, u32 secno
, struct buffer_head
*bh
, u32 num_secs
, s32 sync
);
188 s32
bdev_sync_all(struct super_block
*sb
);
190 /* blkdev.c : sector read/write functions */
191 s32
read_sect(struct super_block
*sb
, u32 sec
, struct buffer_head
**bh
, s32 read
);
192 s32
write_sect(struct super_block
*sb
, u32 sec
, struct buffer_head
*bh
, s32 sync
);
193 s32
read_msect(struct super_block
*sb
, u32 sec
, struct buffer_head
**bh
, s32 num_secs
, s32 read
);
194 s32
write_msect(struct super_block
*sb
, u32 sec
, struct buffer_head
*bh
, s32 num_secs
, s32 sync
);
195 s32
write_msect_zero(struct super_block
*sb
, u32 sec
, s32 num_secs
);
198 u8
calc_chksum_1byte(void *data
, s32 len
, u8 chksum
);
199 u16
calc_chksum_2byte(void *data
, s32 len
, u16 chksum
, s32 type
);
202 s32
extent_cache_init(void);
203 void extent_cache_shutdown(void);
204 void extent_cache_init_inode(struct inode
*inode
);
205 void extent_cache_inval_inode(struct inode
*inode
);
206 s32
extent_get_clus(struct inode
*inode
, s32 cluster
, s32
*fclus
,
207 u32
*dclus
, u32
*last_dclus
, s32 allow_eof
);
208 /*----------------------------------------------------------------------*/
209 /* Wrapper Function */
210 /*----------------------------------------------------------------------*/
211 void set_sb_dirty(struct super_block
*sb
);
215 #endif /* __cplusplus */
217 #endif /* _SDFAT_CORE_H */