This repository has been archived by the owner on Apr 15, 2020. It is now read-only.
forked from cryptomilk/kernel-sdfat
-
Notifications
You must be signed in to change notification settings - Fork 1
/
core.h
221 lines (180 loc) · 9.2 KB
/
core.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/*
* Copyright (C) 2012-2013 Samsung Electronics Co., Ltd.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _SDFAT_CORE_H
#define _SDFAT_CORE_H
#include <asm/byteorder.h>
#include "config.h"
#include "api.h"
#include "upcase.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/*----------------------------------------------------------------------*/
/* Constant & Macro Definitions */
/*----------------------------------------------------------------------*/
#define get_next_clus(sb, pclu) fat_ent_get(sb, *(pclu), pclu)
#define get_next_clus_safe(sb, pclu) fat_ent_get_safe(sb, *(pclu), pclu)
/* file status */
/* this prevents
* fscore_write_inode, fscore_map_clus, ... with the unlinked inodes
* from corrupting on-disk dentry data.
*
* The fid->dir value of unlinked inode will be DIR_DELETED
* and those functions must check if fid->dir is valid prior to
* the calling of get_dentry_in_dir()
*/
#define DIR_DELETED 0xFFFF0321
/*----------------------------------------------------------------------*/
/* Type Definitions */
/*----------------------------------------------------------------------*/
#define ES_2_ENTRIES 2
#define ES_3_ENTRIES 3
#define ES_ALL_ENTRIES 0
typedef struct {
u64 sector; // sector number that contains file_entry
u32 offset; // byte offset in the sector
s32 alloc_flag; // flag in stream entry. 01 for cluster chain, 03 for contig. clusters.
u32 num_entries;
void *__buf; // __buf should be the last member
} ENTRY_SET_CACHE_T;
/*----------------------------------------------------------------------*/
/* External Function Declarations */
/*----------------------------------------------------------------------*/
/* file system initialization & shutdown functions */
s32 fscore_init(void);
s32 fscore_shutdown(void);
/* bdev management */
s32 fscore_check_bdi_valid(struct super_block *sb);
/* chain management */
s32 chain_cont_cluster(struct super_block *sb, u32 chain, u32 len);
/* volume management functions */
s32 fscore_mount(struct super_block *sb);
s32 fscore_umount(struct super_block *sb);
s32 fscore_statfs(struct super_block *sb, VOL_INFO_T *info);
s32 fscore_sync_fs(struct super_block *sb, s32 do_sync);
s32 fscore_set_vol_flags(struct super_block *sb, u16 new_flag, s32 always_sync);
u32 fscore_get_au_stat(struct super_block *sb, s32 mode);
/* file management functions */
s32 fscore_lookup(struct inode *inode, u8 *path, FILE_ID_T *fid);
s32 fscore_create(struct inode *inode, u8 *path, u8 mode, FILE_ID_T *fid);
s32 fscore_read_link(struct inode *inode, FILE_ID_T *fid, void *buffer, u64 count, u64 *rcount);
s32 fscore_write_link(struct inode *inode, FILE_ID_T *fid, void *buffer, u64 count, u64 *wcount);
s32 fscore_truncate(struct inode *inode, u64 old_size, u64 new_size);
s32 fscore_rename(struct inode *old_parent_inode, FILE_ID_T *fid,
struct inode *new_parent_inode, struct dentry *new_dentry);
s32 fscore_remove(struct inode *inode, FILE_ID_T *fid);
s32 fscore_read_inode(struct inode *inode, DIR_ENTRY_T *info);
s32 fscore_write_inode(struct inode *inode, DIR_ENTRY_T *info, int sync);
s32 fscore_map_clus(struct inode *inode, u32 clu_offset, u32 *clu, int dest);
s32 fscore_reserve_clus(struct inode *inode);
s32 fscore_unlink(struct inode *inode, FILE_ID_T *fid);
/* directory management functions */
s32 fscore_mkdir(struct inode *inode, u8 *path, FILE_ID_T *fid);
s32 fscore_readdir(struct inode *inode, DIR_ENTRY_T *dir_ent);
s32 fscore_rmdir(struct inode *inode, FILE_ID_T *fid);
/*----------------------------------------------------------------------*/
/* External Function Declarations (NOT TO UPPER LAYER) */
/*----------------------------------------------------------------------*/
/* core.c : core code for common */
/* dir entry management functions */
DENTRY_T *get_dentry_in_dir(struct super_block *sb, CHAIN_T *p_dir, s32 entry, u64 *sector);
/* name conversion functions */
void get_uniname_from_dos_entry(struct super_block *sb, DOS_DENTRY_T *ep, UNI_NAME_T *p_uniname, u8 mode);
/* file operation functions */
s32 walk_fat_chain(struct super_block *sb, CHAIN_T *p_dir, u32 byte_offset, u32 *clu);
/* sdfat/cache.c */
s32 meta_cache_init(struct super_block *sb);
s32 meta_cache_shutdown(struct super_block *sb);
u8 *fcache_getblk(struct super_block *sb, u64 sec);
s32 fcache_modify(struct super_block *sb, u64 sec);
s32 fcache_release_all(struct super_block *sb);
s32 fcache_flush(struct super_block *sb, u32 sync);
u8 *dcache_getblk(struct super_block *sb, u64 sec);
s32 dcache_modify(struct super_block *sb, u64 sec);
s32 dcache_lock(struct super_block *sb, u64 sec);
s32 dcache_unlock(struct super_block *sb, u64 sec);
s32 dcache_release(struct super_block *sb, u64 sec);
s32 dcache_release_all(struct super_block *sb);
s32 dcache_flush(struct super_block *sb, u32 sync);
s32 dcache_readahead(struct super_block *sb, u64 sec);
/* fatent.c */
s32 fat_ent_ops_init(struct super_block *sb);
s32 fat_ent_get(struct super_block *sb, u32 loc, u32 *content);
s32 fat_ent_set(struct super_block *sb, u32 loc, u32 content);
s32 fat_ent_get_safe(struct super_block *sb, u32 loc, u32 *content);
/* core_fat.c : core code for fat */
s32 fat_generate_dos_name_new(struct super_block *sb, CHAIN_T *p_dir, DOS_NAME_T *p_dosname, s32 n_entries);
s32 mount_fat16(struct super_block *sb, pbr_t *p_pbr);
s32 mount_fat32(struct super_block *sb, pbr_t *p_pbr);
/* core_exfat.c : core code for exfat */
s32 load_alloc_bmp(struct super_block *sb);
void free_alloc_bmp(struct super_block *sb);
ENTRY_SET_CACHE_T *get_dentry_set_in_dir(struct super_block *sb,
CHAIN_T *p_dir, s32 entry, u32 type, DENTRY_T **file_ep);
void release_dentry_set(ENTRY_SET_CACHE_T *es);
s32 update_dir_chksum(struct super_block *sb, CHAIN_T *p_dir, s32 entry);
s32 update_dir_chksum_with_entry_set(struct super_block *sb, ENTRY_SET_CACHE_T *es);
bool is_dir_empty(struct super_block *sb, CHAIN_T *p_dir);
s32 mount_exfat(struct super_block *sb, pbr_t *p_pbr);
/* amap_smart.c : creation on mount / destroy on umount */
int amap_create(struct super_block *sb, u32 pack_ratio, u32 sect_per_au, u32 hidden_sect);
void amap_destroy(struct super_block *sb);
/* amap_smart.c : (de)allocation functions */
s32 amap_fat_alloc_cluster(struct super_block *sb, u32 num_alloc, CHAIN_T *p_chain, s32 dest);
s32 amap_free_cluster(struct super_block *sb, CHAIN_T *p_chain, s32 do_relse);/* Not impelmented */
s32 amap_release_cluster(struct super_block *sb, u32 clu); /* Only update AMAP */
/* amap_smart.c : misc (for defrag) */
s32 amap_mark_ignore(struct super_block *sb, u32 clu);
s32 amap_unmark_ignore(struct super_block *sb, u32 clu);
s32 amap_unmark_ignore_all(struct super_block *sb);
s32 amap_check_working(struct super_block *sb, u32 clu);
s32 amap_get_freeclus(struct super_block *sb, u32 clu);
/* amap_smart.c : stat AU */
u32 amap_get_au_stat(struct super_block *sb, s32 mode);
/* blkdev.c */
s32 bdev_open_dev(struct super_block *sb);
s32 bdev_close_dev(struct super_block *sb);
s32 bdev_check_bdi_valid(struct super_block *sb);
s32 bdev_readahead(struct super_block *sb, u64 secno, u64 num_secs);
s32 bdev_mread(struct super_block *sb, u64 secno, struct buffer_head **bh, u64 num_secs, s32 read);
s32 bdev_mwrite(struct super_block *sb, u64 secno, struct buffer_head *bh, u64 num_secs, s32 sync);
s32 bdev_sync_all(struct super_block *sb);
/* blkdev.c : sector read/write functions */
s32 read_sect(struct super_block *sb, u64 sec, struct buffer_head **bh, s32 read);
s32 write_sect(struct super_block *sb, u64 sec, struct buffer_head *bh, s32 sync);
s32 read_msect(struct super_block *sb, u64 sec, struct buffer_head **bh, s64 num_secs, s32 read);
s32 write_msect(struct super_block *sb, u64 sec, struct buffer_head *bh, s64 num_secs, s32 sync);
s32 write_msect_zero(struct super_block *sb, u64 sec, u64 num_secs);
/* misc.c */
u8 calc_chksum_1byte(void *data, s32 len, u8 chksum);
u16 calc_chksum_2byte(void *data, s32 len, u16 chksum, s32 type);
/* extent.c */
s32 extent_cache_init(void);
void extent_cache_shutdown(void);
void extent_cache_init_inode(struct inode *inode);
void extent_cache_inval_inode(struct inode *inode);
s32 extent_get_clus(struct inode *inode, u32 cluster, u32 *fclus,
u32 *dclus, u32 *last_dclus, s32 allow_eof);
/*----------------------------------------------------------------------*/
/* Wrapper Function */
/*----------------------------------------------------------------------*/
void set_sb_dirty(struct super_block *sb);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* _SDFAT_CORE_H */
/* end of core.h */