Tabs to spaces; more consistent and conventional formatting.
[AROS.git] / rom / filesys / fat / fat_fs.h
blob70b59e527de5fb739efac03f450de72380943f38
1 /*
2 * fat-handler - FAT12/16/32 filesystem handler
4 * Copyright © 2006 Marek Szyprowski
5 * Copyright © 2007-2015 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 <devices/trackdisk.h>
29 #include "fat_struct.h"
31 #include "cache.h"
33 /* filesystem structures */
35 #define ID_FAT_DISK 0x46415400UL
37 #define ID_FAT12_DISK 0x46415400UL
38 #define ID_FAT16_DISK 0x46415401UL
39 #define ID_FAT32_DISK 0x46415402UL
41 #define ACTION_VOLUME_ADD 16000
42 #define ACTION_VOLUME_REMOVE 16001
44 #define DEF_POOL_SIZE 65536
45 #define DEF_POOL_THRESHOLD DEF_POOL_SIZE
48 /* a handle on something, file or directory */
49 struct IOHandle
51 struct FSSuper *sb; /* filesystem data */
53 ULONG first_cluster; /* first cluster of this file */
54 ULONG cur_cluster; /* cluster that the current sector is within */
56 ULONG cluster_offset; /* cluster number of this cluster within the current file */
58 ULONG first_sector; /* first sector in the first cluster, for fat12/16 root dir */
59 ULONG cur_sector; /* sector number our block is currently in */
61 ULONG sector_offset; /* current sector as an offset in the current cluster
62 i.e. cur = sector(cur_cluster) + offset */
64 APTR block; /* current block from the cache */
65 UBYTE *data; /* current data buffer (from cache) */
68 /* a handle on a directory */
69 struct DirHandle
71 struct IOHandle ioh;
73 ULONG cur_index; /* last entry returned, for GetNextDirEntry */
76 /* single directory entry */
77 struct DirEntry
79 struct FSSuper *sb; /* filesystem data */
81 ULONG cluster; /* cluster the containing directory starts at */
82 ULONG index; /* index of this entry */
84 ULONG pos; /* byte offset within directory that the entry came from */
86 union {
87 struct FATDirEntry entry;
88 struct FATLongDirEntry long_entry;
89 } e;
92 #define FAT_ROOTDIR_MARK 0xFFFFFFFFlu
94 struct GlobalLock;
96 struct ExtFileLock
98 /* struct FileLock */
99 BPTR fl_Link;
100 IPTR fl_Key;
101 LONG fl_Access;
102 struct MsgPort * fl_Task;
103 BPTR fl_Volume;
105 ULONG magic; /* we set this to ID_FAT_DISK so we can tell
106 our locks from those of other filesystems */
108 struct MinNode node; /* node in the list of locks attached to the global lock */
109 struct GlobalLock *gl; /* pointer to the global lock for this file */
111 struct IOHandle ioh; /* handle for reads and writes */
112 ULONG pos; /* current seek position within the file */
114 BOOL do_notify; /* if set, send notification on file close (ACTION_END) */
115 struct FSSuper *sb; /* pointer to sb, for unlocking when volume is removed */
118 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[FAT_MAX_SHORT_NAME + 2]; /* 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
143 struct MinNode node;
145 struct GlobalLock *gl; /* pointer to global lock if this file is
146 locked. if it's not, this is NULL */
148 struct NotifyRequest *nr; /* the request that DOS passed us */
151 struct VolumeInfo
153 APTR mem_pool;
154 ULONG id;
155 struct MinList locks; /* global locks */
156 struct GlobalLock root_lock;
157 struct MinList notifies;
160 struct VolumeIdentity
162 UBYTE name[FAT_MAX_SHORT_NAME + 2]; /* BCPL string */
163 struct DateStamp create_time;
166 struct FSSuper
168 struct Node node;
170 struct Globals *glob;
171 struct DosList *doslist;
173 struct VolumeInfo *info;
175 struct cache *cache;
176 ULONG first_device_sector;
178 ULONG sectorsize;
179 ULONG sectorsize_bits;
181 ULONG cluster_sectors;
182 ULONG clustersize;
183 ULONG clustersize_bits;
184 ULONG cluster_sectors_bits;
186 ULONG first_fat_sector;
187 ULONG first_data_sector;
188 ULONG first_rootdir_sector;
190 ULONG rootdir_sectors;
191 ULONG total_sectors;
192 ULONG data_sectors;
193 ULONG clusters_count;
194 ULONG fat_size;
195 UWORD fat_count;
197 ULONG free_clusters;
198 ULONG next_cluster;
200 ULONG volume_id;
201 ULONG type;
202 ULONG eoc_mark;
204 APTR *fat_blocks;
205 UBYTE **fat_buffers;
206 ULONG fat_blocks_count;
208 ULONG fat_cachesize;
209 ULONG fat_cachesize_bits;
210 ULONG fat_cache_block;
211 UWORD fat_cache_no; /* FAT number that cached FAT blocks belong to */
213 APTR fsinfo_block;
214 struct FATFSInfo *fsinfo_buffer;
216 ULONG rootdir_cluster;
217 ULONG rootdir_sector;
219 struct VolumeIdentity volume;
221 /* function table */
222 ULONG (*func_get_fat_entry)(struct FSSuper *sb, ULONG n);
223 void (*func_set_fat_entry)(struct FSSuper *sb, ULONG n, ULONG val);
224 /* ... */
227 struct Globals
229 /* Libraries */
230 struct ExecBase *gl_SysBase;
231 struct DosLibrary *gl_DOSBase;
232 struct Library *gl_UtilityBase;
233 struct Device *gl_TimerBase;
235 /* mem/task */
236 struct Task *ourtask;
237 struct MsgPort *ourport;
238 APTR mempool;
240 struct MsgPort *notifyport;
242 /* fs */
243 struct DosList *devnode;
244 struct FileSysStartupMsg *fssm;
245 LONG quit;
246 struct DosPacket *death_packet;
247 BOOL autodetect;
249 /* io */
250 struct IOExtTD *diskioreq;
251 struct IOExtTD *diskchgreq;
252 struct MsgPort *diskport;
253 ULONG diskchgsig_bit;
254 struct timerequest *timereq;
255 struct MsgPort *timerport;
256 ULONG last_num; /* last block number that was outside boundaries */
257 UWORD readcmd;
258 UWORD writecmd;
259 char timer_active;
260 char restart_timer;
262 /* volumes */
263 struct FSSuper *sb; /* current sb */
264 struct MinList sblist; /* sbs with outstanding locks or notifies */
266 /* disk status */
267 LONG disk_inserted;
268 LONG disk_inhibited;
269 BOOL formatting;
271 /* Character sets translation */
272 UBYTE from_unicode[65536];
273 UWORD to_unicode[256];
275 /* Disk change interrupt */
276 struct IntData {
277 struct Interrupt Interrupt;
278 struct ExecBase *SysBase;
279 struct Task *task;
280 ULONG signal;
281 } DiskChangeIntData;
284 #define DOSBase (glob->gl_DOSBase)
285 #define SysBase (glob->gl_SysBase)
286 #define UtilityBase (glob->gl_UtilityBase)
287 #define TimerBase (glob->gl_TimerBase)
289 #include "support.h"
291 /* new definitions as we refactor the code */
293 /* get the first sector of a cluster */
294 #define SECTOR_FROM_CLUSTER(sb,cl) \
295 ((ULONG) (((cl-2) << sb->cluster_sectors_bits) + sb->first_data_sector))
297 #define FIRST_FILE_CLUSTER(de) \
298 (AROS_LE2WORD((de)->e.entry.first_cluster_lo) | \
299 (((ULONG) AROS_LE2WORD((de)->e.entry.first_cluster_hi)) << 16))
301 #define RESET_HANDLE(ioh) \
302 do \
304 (ioh)->cluster_offset = (ioh)->sector_offset = 0xffffffff; \
305 if ((ioh)->block != NULL) \
307 Cache_FreeBlock((ioh)->sb->cache, (ioh)->block); \
308 (ioh)->block = NULL; \
311 while (0);
313 #define RESET_DIRHANDLE(dh) \
314 do \
316 RESET_HANDLE(&((dh)->ioh)); \
317 (dh)->cur_index = 0xffffffff; \
319 while(0);
321 #define GET_NEXT_CLUSTER(sb,cl) (sb->func_get_fat_entry(sb,cl))
322 #define SET_NEXT_CLUSTER(sb,cl,val) (sb->func_set_fat_entry(sb,cl,val))
324 #define CALC_SHORT_NAME_CHECKSUM(name,checksum) \
325 do \
327 ULONG i; \
328 checksum = 0; \
329 for (i = 0; i < 11; i++) \
330 checksum = \
331 ((checksum & 1) ? 0x80 : 0) + (checksum >> 1) + name[i]; \
333 while(0);
335 #define LOCKFROMNODE(A) \
336 ((struct ExtFileLock *) \
337 (((BYTE *)(A)) - (IPTR)&((struct ExtFileLock *)NULL)->node))
339 #endif