Corrected module name.
[AROS.git] / rom / filesys / fat / fat_fs.h
blob6cd7df51f310d4486e27d300204ca36b935debba
1 /*
2 * fat-handler - FAT12/16/32 filesystem handler
4 * Copyright © 2006 Marek Szyprowski
5 * Copyright © 2007-2013 The AROS Development Team
7 * This program is free software; you can redistribute it and/or modify it
8 * under the same terms as AROS itself.
10 * $Id$
13 #ifndef FAT_HANDLER_H
14 #define FAT_HANDLER_H
16 #define DEBUG_DIRENTRY 0
17 #define DEBUG_FILE 0
18 #define DEBUG_DUMP 0
19 #define DEBUG_LOCK 0
20 #define DEBUG_NAMES 0
21 #define DEBUG_NOTIFY 0
22 #define DEBUG_OPS 0
23 #define DEBUG_PACKETS 0
24 #define DEBUG_CACHESTATS 0
25 #define DEBUG_MISC 0
27 #include <aros/libcall.h>
28 #include <devices/trackdisk.h>
30 #include "fat_struct.h"
32 #include "cache.h"
34 /* filesystem structures */
36 #define ID_FAT_DISK 0x46415400UL
38 #define ID_FAT12_DISK 0x46415400UL
39 #define ID_FAT16_DISK 0x46415401UL
40 #define ID_FAT32_DISK 0x46415402UL
42 #define ACTION_VOLUME_ADD 16000
43 #define ACTION_VOLUME_REMOVE 16001
45 extern struct Globals *glob;
47 #define DEF_POOL_SIZE 65536
48 #define DEF_POOL_THRESHOLD DEF_POOL_SIZE
49 #define DEF_BUFF_LINES 128
50 #define DEF_READ_AHEAD 16*1024
53 /* a handle on something, file or directory */
54 struct IOHandle {
55 struct FSSuper *sb; /* filesystem data */
57 ULONG first_cluster; /* first cluster of this file */
58 ULONG cur_cluster; /* cluster that the current sector is within */
60 ULONG cluster_offset; /* cluster number of this cluster within the current file */
62 ULONG first_sector; /* first sector in the first cluster, for fat12/16 root dir */
63 ULONG cur_sector; /* sector number our block is currently in */
65 ULONG sector_offset; /* current sector as an offset in the current cluster
66 i.e. cur = sector(cur_cluster) + offset */
68 APTR block; /* current block from the cache */
69 UBYTE *data; /* current data buffer (from cache) */
72 /* a handle on a directory */
73 struct DirHandle {
74 struct IOHandle ioh;
76 ULONG cur_index; /* last entry returned, for GetNextDirEntry */
79 /* single directory entry */
80 struct DirEntry {
81 struct FSSuper *sb; /* filesystem data */
83 ULONG cluster; /* cluster the containing directory starts at */
84 ULONG index; /* index of this entry */
86 ULONG pos; /* byte offset within directory that the entry came from */
88 union {
89 struct FATDirEntry entry;
90 struct FATLongDirEntry long_entry;
91 } e;
94 #define FAT_ROOTDIR_MARK 0xFFFFFFFFlu
96 struct GlobalLock;
98 struct ExtFileLock {
99 /* struct FileLock */
100 BPTR fl_Link;
101 IPTR fl_Key;
102 LONG fl_Access;
103 struct MsgPort * fl_Task;
104 BPTR fl_Volume;
106 ULONG magic; /* we set this to ID_FAT_DISK so we can tell
107 our locks from those of other filesystems */
109 struct MinNode node; /* node in the list of locks attached to the global lock */
110 struct GlobalLock *gl; /* pointer to the global lock for this file */
112 struct IOHandle ioh; /* handle for reads and writes */
113 ULONG pos; /* current seek position within the file */
115 BOOL do_notify; /* if set, send notification on file close (ACTION_END) */
116 struct FSSuper *sb; /* pointer to sb, for unlocking when volume is removed */
119 struct GlobalLock {
120 struct MinNode node;
122 ULONG dir_cluster; /* first cluster of the directory we're in */
123 ULONG dir_entry; /* this is our dir entry within dir_cluster */
125 LONG access; /* access mode, shared or exclusive */
127 ULONG first_cluster; /* first data cluster */
129 ULONG attr; /* file attributes, from the dir entry */
130 ULONG size; /* file size, from the dir entry */
132 UBYTE name[FAT_MAX_LONG_FILENAME]; /* copy of the name (bstr) */
133 #if DEBUG_NAMES
134 UBYTE shortname[13]; /* copy of the short name (bstr) */
135 #endif
137 struct MinList locks; /* list of ExtFileLocks opened on this file */
140 /* a node in the list of notification requests */
141 struct NotifyNode {
142 struct MinNode node;
144 struct GlobalLock *gl; /* pointer to global lock if this file is
145 locked. if it's not, this is NULL */
147 struct NotifyRequest *nr; /* the request that DOS passed us */
150 struct VolumeInfo {
151 APTR mem_pool;
152 ULONG id;
153 struct MinList locks; /* global locks */
154 struct GlobalLock root_lock;
155 struct MinList notifies;
158 struct VolumeIdentity {
159 UBYTE name[32]; /* BCPL string */
160 struct DateStamp create_time;
163 struct FSSuper {
164 struct Node node;
165 struct DosList *doslist;
167 struct VolumeInfo *info;
169 struct cache *cache;
170 ULONG first_device_sector;
172 ULONG sectorsize;
173 ULONG sectorsize_bits;
175 ULONG cluster_sectors;
176 ULONG clustersize;
177 ULONG clustersize_bits;
178 ULONG cluster_sectors_bits;
180 ULONG first_fat_sector;
181 ULONG first_data_sector;
182 ULONG first_rootdir_sector;
184 ULONG rootdir_sectors;
185 ULONG total_sectors;
186 ULONG data_sectors;
187 ULONG clusters_count;
188 ULONG fat_size;
189 UWORD fat_count;
191 ULONG free_clusters;
192 ULONG next_cluster;
194 ULONG volume_id;
195 ULONG type;
196 ULONG eoc_mark;
198 APTR *fat_blocks;
199 UBYTE **fat_buffers;
200 ULONG fat_blocks_count;
202 ULONG fat_cachesize;
203 ULONG fat_cachesize_bits;
204 ULONG fat_cache_block;
205 UWORD fat_cache_no; /* FAT number that cached FAT blocks belong to */
207 APTR fsinfo_block;
208 struct FATFSInfo *fsinfo_buffer;
210 ULONG rootdir_cluster;
211 ULONG rootdir_sector;
213 struct VolumeIdentity volume;
215 /* function table */
216 ULONG (*func_get_fat_entry)(struct FSSuper *sb, ULONG n);
217 void (*func_set_fat_entry)(struct FSSuper *sb, ULONG n, ULONG val);
218 /* ... */
221 struct Globals {
222 /* mem/task */
223 struct Task *ourtask;
224 struct MsgPort *ourport;
225 APTR mempool;
227 struct MsgPort *notifyport;
229 /* fs */
230 struct DosList *devnode;
231 struct FileSysStartupMsg *fssm;
232 LONG quit;
233 struct DosPacket *death_packet;
234 BOOL autodetect;
236 /* io */
237 struct IOExtTD *diskioreq;
238 struct IOExtTD *diskchgreq;
239 struct MsgPort *diskport;
240 ULONG diskchgsig_bit;
241 struct timerequest *timereq;
242 struct MsgPort *timerport;
243 ULONG last_num; /* last block number that was outside boundaries */
244 UWORD readcmd;
245 UWORD writecmd;
246 char timer_active;
247 char restart_timer;
249 /* volumes */
250 struct FSSuper *sb; /* current sb */
251 struct MinList sblist; /* sbs with outstanding locks or notifies */
253 /* disk status */
254 LONG disk_inserted;
255 LONG disk_inhibited;
257 /* Character sets translation */
258 UBYTE from_unicode[65536];
259 UWORD to_unicode[256];
262 #include "support.h"
264 /* new definitions as we refactor the code */
266 /* get the first sector of a cluster */
267 #define SECTOR_FROM_CLUSTER(sb,cl) ((ULONG) (((cl-2) << sb->cluster_sectors_bits) + sb->first_data_sector))
269 #define FIRST_FILE_CLUSTER(de) \
270 (AROS_LE2WORD((de)->e.entry.first_cluster_lo) | \
271 (((ULONG) AROS_LE2WORD((de)->e.entry.first_cluster_hi)) << 16))
273 #define RESET_HANDLE(ioh) \
274 do { \
275 (ioh)->cluster_offset = (ioh)->sector_offset = 0xffffffff; \
276 if ((ioh)->block != NULL) { \
277 Cache_FreeBlock((ioh)->sb->cache, (ioh)->block); \
278 (ioh)->block = NULL; \
280 } while (0);
282 #define RESET_DIRHANDLE(dh) \
283 do { \
284 RESET_HANDLE(&((dh)->ioh)); \
285 (dh)->cur_index = 0xffffffff; \
286 } while(0);
288 #define GET_NEXT_CLUSTER(sb,cl) (sb->func_get_fat_entry(sb,cl))
289 #define SET_NEXT_CLUSTER(sb,cl,val) (sb->func_set_fat_entry(sb,cl,val))
291 #define CALC_SHORT_NAME_CHECKSUM(name,checksum) \
292 do { \
293 ULONG i; \
294 checksum = 0; \
295 for (i = 0; i < 11; i++) \
296 checksum = ((checksum & 1) ? 0x80 : 0) + (checksum >> 1) + name[i]; \
297 } while(0);
299 #define LOCKFROMNODE(A) \
300 ((struct ExtFileLock *) \
301 (((BYTE *)(A)) - (IPTR)&((struct ExtFileLock *)NULL)->node))
303 #endif