A little tidying.
[AROS.git] / rom / filesys / fat / fat_fs.h
blobdb9a6003f123a9c74a99553206bc3569c4096eed
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 {
50 struct FSSuper *sb; /* filesystem data */
52 ULONG first_cluster; /* first cluster of this file */
53 ULONG cur_cluster; /* cluster that the current sector is within */
55 ULONG cluster_offset; /* cluster number of this cluster within the current file */
57 ULONG first_sector; /* first sector in the first cluster, for fat12/16 root dir */
58 ULONG cur_sector; /* sector number our block is currently in */
60 ULONG sector_offset; /* current sector as an offset in the current cluster
61 i.e. cur = sector(cur_cluster) + offset */
63 APTR block; /* current block from the cache */
64 UBYTE *data; /* current data buffer (from cache) */
67 /* a handle on a directory */
68 struct DirHandle {
69 struct IOHandle ioh;
71 ULONG cur_index; /* last entry returned, for GetNextDirEntry */
74 /* single directory entry */
75 struct DirEntry {
76 struct FSSuper *sb; /* filesystem data */
78 ULONG cluster; /* cluster the containing directory starts at */
79 ULONG index; /* index of this entry */
81 ULONG pos; /* byte offset within directory that the entry came from */
83 union {
84 struct FATDirEntry entry;
85 struct FATLongDirEntry long_entry;
86 } e;
89 #define FAT_ROOTDIR_MARK 0xFFFFFFFFlu
91 struct GlobalLock;
93 struct ExtFileLock {
94 /* struct FileLock */
95 BPTR fl_Link;
96 IPTR fl_Key;
97 LONG fl_Access;
98 struct MsgPort * fl_Task;
99 BPTR fl_Volume;
101 ULONG magic; /* we set this to ID_FAT_DISK so we can tell
102 our locks from those of other filesystems */
104 struct MinNode node; /* node in the list of locks attached to the global lock */
105 struct GlobalLock *gl; /* pointer to the global lock for this file */
107 struct IOHandle ioh; /* handle for reads and writes */
108 ULONG pos; /* current seek position within the file */
110 BOOL do_notify; /* if set, send notification on file close (ACTION_END) */
111 struct FSSuper *sb; /* pointer to sb, for unlocking when volume is removed */
114 struct GlobalLock {
115 struct MinNode node;
117 ULONG dir_cluster; /* first cluster of the directory we're in */
118 ULONG dir_entry; /* this is our dir entry within dir_cluster */
120 LONG access; /* access mode, shared or exclusive */
122 ULONG first_cluster; /* first data cluster */
124 ULONG attr; /* file attributes, from the dir entry */
125 ULONG size; /* file size, from the dir entry */
127 UBYTE name[FAT_MAX_LONG_FILENAME]; /* copy of the name (bstr) */
128 #if DEBUG_NAMES
129 UBYTE shortname[FAT_MAX_SHORT_NAME + 2]; /* copy of the short name (bstr) */
130 #endif
132 struct MinList locks; /* list of ExtFileLocks opened on this file */
135 /* a node in the list of notification requests */
136 struct NotifyNode {
137 struct MinNode node;
139 struct GlobalLock *gl; /* pointer to global lock if this file is
140 locked. if it's not, this is NULL */
142 struct NotifyRequest *nr; /* the request that DOS passed us */
145 struct VolumeInfo {
146 APTR mem_pool;
147 ULONG id;
148 struct MinList locks; /* global locks */
149 struct GlobalLock root_lock;
150 struct MinList notifies;
153 struct VolumeIdentity {
154 UBYTE name[FAT_MAX_SHORT_NAME + 2]; /* BCPL string */
155 struct DateStamp create_time;
158 struct FSSuper {
159 struct Node node;
161 struct Globals *glob;
162 struct DosList *doslist;
164 struct VolumeInfo *info;
166 struct cache *cache;
167 ULONG first_device_sector;
169 ULONG sectorsize;
170 ULONG sectorsize_bits;
172 ULONG cluster_sectors;
173 ULONG clustersize;
174 ULONG clustersize_bits;
175 ULONG cluster_sectors_bits;
177 ULONG first_fat_sector;
178 ULONG first_data_sector;
179 ULONG first_rootdir_sector;
181 ULONG rootdir_sectors;
182 ULONG total_sectors;
183 ULONG data_sectors;
184 ULONG clusters_count;
185 ULONG fat_size;
186 UWORD fat_count;
188 ULONG free_clusters;
189 ULONG next_cluster;
191 ULONG volume_id;
192 ULONG type;
193 ULONG eoc_mark;
195 APTR *fat_blocks;
196 UBYTE **fat_buffers;
197 ULONG fat_blocks_count;
199 ULONG fat_cachesize;
200 ULONG fat_cachesize_bits;
201 ULONG fat_cache_block;
202 UWORD fat_cache_no; /* FAT number that cached FAT blocks belong to */
204 APTR fsinfo_block;
205 struct FATFSInfo *fsinfo_buffer;
207 ULONG rootdir_cluster;
208 ULONG rootdir_sector;
210 struct VolumeIdentity volume;
212 /* function table */
213 ULONG (*func_get_fat_entry)(struct FSSuper *sb, ULONG n);
214 void (*func_set_fat_entry)(struct FSSuper *sb, ULONG n, ULONG val);
215 /* ... */
218 struct Globals {
219 /* Libraries */
220 struct ExecBase *gl_SysBase;
221 struct DosLibrary *gl_DOSBase;
222 struct Library *gl_UtilityBase;
223 struct Device *gl_TimerBase;
225 /* mem/task */
226 struct Task *ourtask;
227 struct MsgPort *ourport;
228 APTR mempool;
230 struct MsgPort *notifyport;
232 /* fs */
233 struct DosList *devnode;
234 struct FileSysStartupMsg *fssm;
235 LONG quit;
236 struct DosPacket *death_packet;
237 BOOL autodetect;
239 /* io */
240 struct IOExtTD *diskioreq;
241 struct IOExtTD *diskchgreq;
242 struct MsgPort *diskport;
243 ULONG diskchgsig_bit;
244 struct timerequest *timereq;
245 struct MsgPort *timerport;
246 ULONG last_num; /* last block number that was outside boundaries */
247 UWORD readcmd;
248 UWORD writecmd;
249 char timer_active;
250 char restart_timer;
252 /* volumes */
253 struct FSSuper *sb; /* current sb */
254 struct MinList sblist; /* sbs with outstanding locks or notifies */
256 /* disk status */
257 LONG disk_inserted;
258 LONG disk_inhibited;
259 BOOL formatting;
261 /* Character sets translation */
262 UBYTE from_unicode[65536];
263 UWORD to_unicode[256];
265 /* Disk change interrupt */
266 struct IntData {
267 struct Interrupt Interrupt;
268 struct ExecBase *SysBase;
269 struct Task *task;
270 ULONG signal;
271 } DiskChangeIntData;
274 #define DOSBase (glob->gl_DOSBase)
275 #define SysBase (glob->gl_SysBase)
276 #define UtilityBase (glob->gl_UtilityBase)
277 #define TimerBase (glob->gl_TimerBase)
279 #include "support.h"
281 /* new definitions as we refactor the code */
283 /* get the first sector of a cluster */
284 #define SECTOR_FROM_CLUSTER(sb,cl) ((ULONG) (((cl-2) << sb->cluster_sectors_bits) + sb->first_data_sector))
286 #define FIRST_FILE_CLUSTER(de) \
287 (AROS_LE2WORD((de)->e.entry.first_cluster_lo) | \
288 (((ULONG) AROS_LE2WORD((de)->e.entry.first_cluster_hi)) << 16))
290 #define RESET_HANDLE(ioh) \
291 do { \
292 (ioh)->cluster_offset = (ioh)->sector_offset = 0xffffffff; \
293 if ((ioh)->block != NULL) { \
294 Cache_FreeBlock((ioh)->sb->cache, (ioh)->block); \
295 (ioh)->block = NULL; \
297 } while (0);
299 #define RESET_DIRHANDLE(dh) \
300 do { \
301 RESET_HANDLE(&((dh)->ioh)); \
302 (dh)->cur_index = 0xffffffff; \
303 } while(0);
305 #define GET_NEXT_CLUSTER(sb,cl) (sb->func_get_fat_entry(sb,cl))
306 #define SET_NEXT_CLUSTER(sb,cl,val) (sb->func_set_fat_entry(sb,cl,val))
308 #define CALC_SHORT_NAME_CHECKSUM(name,checksum) \
309 do { \
310 ULONG i; \
311 checksum = 0; \
312 for (i = 0; i < 11; i++) \
313 checksum = ((checksum & 1) ? 0x80 : 0) + (checksum >> 1) + name[i]; \
314 } while(0);
316 #define LOCKFROMNODE(A) \
317 ((struct ExtFileLock *) \
318 (((BYTE *)(A)) - (IPTR)&((struct ExtFileLock *)NULL)->node))
320 #endif