revert between 56095 -> 55830 in arch
[AROS.git] / rom / filesys / fat / fat_fs.h
blob2ad3bcf44ac1649cda4b50a79066af6550dbe2c4
1 /*
2 * fat-handler - FAT12/16/32 filesystem handler
4 * Copyright © 2006 Marek Szyprowski
5 * Copyright © 2007-2018 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 <dos/dos.h>
28 #include <exec/interrupts.h>
30 #include "fat_struct.h"
32 #include "cache.h"
34 /* Supported Filesystem Ids */
35 #if !defined(ID_FAT12_DISK)
36 #define ID_FAT12_DISK 0x46415400UL
37 #endif
38 #if !defined(ID_FAT16_DISK)
39 #define ID_FAT16_DISK 0x46415401UL
40 #endif
41 #if !defined(ID_FAT32_DISK)
42 #define ID_FAT32_DISK 0x46415402UL
43 #endif
44 #if !defined(ID_FAT_DISK)
45 #define ID_FAT_DISK ID_FAT12_DISK
46 #endif
48 /* Filesystem structures */
50 #define ACTION_VOLUME_ADD 16000
51 #define ACTION_VOLUME_REMOVE 16001
53 #define DEF_POOL_SIZE 65536
54 #define DEF_POOL_THRESHOLD DEF_POOL_SIZE
57 /* A handle on something, file or directory */
58 struct IOHandle
60 struct FSSuper *sb; /* filesystem data */
62 ULONG first_cluster; /* first cluster of this file */
63 ULONG cur_cluster; /* cluster that the current sector is within */
65 ULONG cluster_offset; /* cluster number of this cluster within the current file */
67 ULONG first_sector; /* first sector in the first cluster, for fat12/16 root dir */
68 ULONG cur_sector; /* sector number our block is currently in */
70 ULONG sector_offset; /* current sector as an offset in the current cluster
71 i.e. cur = sector(cur_cluster) + offset */
73 APTR block; /* current block from the cache */
74 UBYTE *data; /* current data buffer (from cache) */
77 /* A handle on a directory */
78 struct DirHandle
80 struct IOHandle ioh;
82 ULONG cur_index; /* last entry returned, for GetNextDirEntry */
85 /* Single directory entry */
86 struct DirEntry
88 struct FSSuper *sb; /* filesystem data */
90 ULONG cluster; /* cluster the containing directory starts at */
91 ULONG index; /* index of this entry */
93 ULONG pos; /* byte offset within directory that the entry came from */
95 union {
96 struct FATDirEntry entry;
97 struct FATLongDirEntry long_entry;
98 } e;
101 #define FAT_ROOTDIR_MARK 0xFFFFFFFFlu
103 struct GlobalLock;
105 struct ExtFileLock
107 /* struct FileLock */
108 BPTR fl_Link;
109 IPTR fl_Key;
110 LONG fl_Access;
111 struct MsgPort * fl_Task;
112 BPTR fl_Volume;
114 ULONG magic; /* we set this to ID_FAT_DISK so we can tell
115 our locks from those of other filesystems */
117 struct MinNode node; /* node in the list of locks attached to the global lock */
118 struct GlobalLock *gl; /* pointer to the global lock for this file */
120 struct IOHandle ioh; /* handle for reads and writes */
121 ULONG pos; /* current seek position within the file */
123 BOOL do_notify; /* if set, send notification on file close (ACTION_END) */
124 struct FSSuper *sb; /* pointer to sb, for unlocking when volume is removed */
127 struct GlobalLock
129 struct MinNode node;
131 ULONG dir_cluster; /* first cluster of the directory we're in */
132 ULONG dir_entry; /* this is our dir entry within dir_cluster */
134 LONG access; /* access mode, shared or exclusive */
136 ULONG first_cluster; /* first data cluster */
138 ULONG attr; /* file attributes, from the dir entry */
139 ULONG size; /* file size, from the dir entry */
141 UBYTE name[FAT_MAX_LONG_FILENAME]; /* copy of the name (bstr) */
142 #if DEBUG_NAMES
143 UBYTE shortname[FAT_MAX_SHORT_NAME + 2]; /* copy of the short name (bstr) */
144 #endif
146 struct MinList locks; /* list of ExtFileLocks opened on this file */
149 /* A node in the list of notification requests */
150 struct NotifyNode
152 struct MinNode node;
154 struct GlobalLock *gl; /* pointer to global lock if this file is
155 locked. if it's not, this is NULL */
157 struct NotifyRequest *nr; /* the request that DOS passed us */
160 struct VolumeInfo
162 APTR mem_pool;
163 ULONG id;
164 struct MinList locks; /* global locks */
165 struct GlobalLock root_lock;
166 struct MinList notifies;
169 struct VolumeIdentity
171 UBYTE name[FAT_MAX_SHORT_NAME + 2]; /* BCPL string */
172 struct DateStamp create_time;
175 struct FSSuper
177 struct Node node;
179 struct Globals *glob;
180 struct DosList *doslist;
182 struct VolumeInfo *info;
184 struct cache *cache;
185 ULONG first_device_sector;
187 ULONG sectorsize;
188 ULONG sectorsize_bits;
190 ULONG cluster_sectors;
191 ULONG clustersize;
192 ULONG clustersize_bits;
193 ULONG cluster_sectors_bits;
195 ULONG first_fat_sector;
196 ULONG first_data_sector;
197 ULONG first_rootdir_sector;
199 ULONG rootdir_sectors;
200 ULONG total_sectors;
201 ULONG data_sectors;
202 ULONG clusters_count;
203 ULONG fat_size;
204 UWORD fat_count;
206 ULONG free_clusters;
207 ULONG next_cluster;
209 ULONG volume_id;
210 ULONG type;
211 ULONG eoc_mark;
213 APTR *fat_blocks;
214 UBYTE **fat_buffers;
215 ULONG fat_blocks_count;
217 ULONG fat_cachesize;
218 ULONG fat_cachesize_bits;
219 ULONG fat_cache_block;
220 UWORD fat_cache_no; /* FAT number that cached FAT blocks belong to */
222 APTR fsinfo_block;
223 struct FATFSInfo *fsinfo_buffer;
225 ULONG rootdir_cluster;
226 ULONG rootdir_sector;
228 struct VolumeIdentity volume;
230 /* function table */
231 ULONG (*func_get_fat_entry)(struct FSSuper *sb, ULONG n);
232 BOOL (*func_set_fat_entry)(struct FSSuper *sb, ULONG n, ULONG val);
233 /* ... */
236 struct Globals
238 /* Libraries */
239 struct ExecBase *gl_SysBase;
240 struct DosLibrary *gl_DOSBase;
241 struct Library *gl_UtilityBase;
242 struct Device *gl_TimerBase;
244 /* mem/task */
245 struct Task *ourtask;
246 struct MsgPort *ourport;
247 APTR mempool;
249 struct MsgPort *notifyport;
251 /* fs */
252 struct DosList *devnode;
253 struct FileSysStartupMsg *fssm;
254 BOOL quit;
255 struct DosPacket *death_packet;
256 BOOL autodetect;
258 /* io */
259 struct IOExtTD *diskioreq;
260 struct IOExtTD *diskchgreq;
261 struct MsgPort *diskport;
262 ULONG diskchgsig_bit;
263 struct timerequest *timereq;
264 struct MsgPort *timerport;
265 ULONG last_num; /* last block number that was outside boundaries */
266 UWORD readcmd;
267 UWORD writecmd;
268 BOOL timer_active;
269 BOOL restart_timer;
271 /* volumes */
272 struct FSSuper *sb; /* current sb */
273 struct MinList sblist; /* sbs with outstanding locks or notifies */
275 /* disk status */
276 LONG disk_inhibited;
277 BOOL disk_inserted;
278 BOOL formatting;
280 /* Character sets translation */
281 UBYTE from_unicode[65536];
282 UWORD to_unicode[256];
284 /* Disk change interrupt */
285 struct IntData {
286 struct Interrupt Interrupt;
287 struct ExecBase *SysBase;
288 struct Task *task;
289 ULONG signal;
290 } DiskChangeIntData;
293 #define DOSBase (glob->gl_DOSBase)
294 #define SysBase (glob->gl_SysBase)
295 #define UtilityBase (glob->gl_UtilityBase)
296 #define TimerBase (glob->gl_TimerBase)
298 #include "support.h"
300 /* Get the first sector of a cluster */
301 #define SECTOR_FROM_CLUSTER(sb,cl) \
302 ((ULONG) (((cl-2) << sb->cluster_sectors_bits) + sb->first_data_sector))
304 #define FIRST_FILE_CLUSTER(de) \
305 (AROS_LE2WORD((de)->e.entry.first_cluster_lo) | \
306 (((ULONG) AROS_LE2WORD((de)->e.entry.first_cluster_hi)) << 16))
308 #define RESET_HANDLE(ioh) \
309 do \
311 (ioh)->cluster_offset = (ioh)->sector_offset = 0xffffffff; \
312 if ((ioh)->block != NULL) \
314 Cache_FreeBlock((ioh)->sb->cache, (ioh)->block); \
315 (ioh)->block = NULL; \
318 while (0);
320 #define RESET_DIRHANDLE(dh) \
321 do \
323 RESET_HANDLE(&((dh)->ioh)); \
324 (dh)->cur_index = 0xffffffff; \
326 while(0);
328 #define GET_NEXT_CLUSTER(sb,cl) (sb->func_get_fat_entry(sb,cl))
329 #define SET_NEXT_CLUSTER(sb,cl,val) (sb->func_set_fat_entry(sb,cl,val))
331 #define CALC_SHORT_NAME_CHECKSUM(name,checksum) \
332 do \
334 ULONG i; \
335 checksum = 0; \
336 for (i = 0; i < FAT_MAX_SHORT_NAME; i++) \
337 checksum = \
338 ((checksum & 1) ? 0x80 : 0) + (checksum >> 1) + name[i]; \
340 while(0);
342 #define LOCKFROMNODE(A) \
343 ((struct ExtFileLock *) \
344 (((BYTE *)(A)) - (IPTR)&((struct ExtFileLock *)NULL)->node))
346 #endif