grub2: bring back build of aros-side grub2 tools
[AROS.git] / rom / filesys / fat / fat_fs.h
blob6df87062a52a0b50a2caed06688041be71edc219
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 <dos/dos.h>
28 #include <exec/interrupts.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 #define DEF_POOL_SIZE 65536
46 #define DEF_POOL_THRESHOLD DEF_POOL_SIZE
49 /* A handle on something, file or directory */
50 struct IOHandle
52 struct FSSuper *sb; /* filesystem data */
54 ULONG first_cluster; /* first cluster of this file */
55 ULONG cur_cluster; /* cluster that the current sector is within */
57 ULONG cluster_offset; /* cluster number of this cluster within the current file */
59 ULONG first_sector; /* first sector in the first cluster, for fat12/16 root dir */
60 ULONG cur_sector; /* sector number our block is currently in */
62 ULONG sector_offset; /* current sector as an offset in the current cluster
63 i.e. cur = sector(cur_cluster) + offset */
65 APTR block; /* current block from the cache */
66 UBYTE *data; /* current data buffer (from cache) */
69 /* A handle on a directory */
70 struct DirHandle
72 struct IOHandle ioh;
74 ULONG cur_index; /* last entry returned, for GetNextDirEntry */
77 /* Single directory entry */
78 struct DirEntry
80 struct FSSuper *sb; /* filesystem data */
82 ULONG cluster; /* cluster the containing directory starts at */
83 ULONG index; /* index of this entry */
85 ULONG pos; /* byte offset within directory that the entry came from */
87 union {
88 struct FATDirEntry entry;
89 struct FATLongDirEntry long_entry;
90 } e;
93 #define FAT_ROOTDIR_MARK 0xFFFFFFFFlu
95 struct GlobalLock;
97 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
121 struct MinNode node;
123 ULONG dir_cluster; /* first cluster of the directory we're in */
124 ULONG dir_entry; /* this is our dir entry within dir_cluster */
126 LONG access; /* access mode, shared or exclusive */
128 ULONG first_cluster; /* first data cluster */
130 ULONG attr; /* file attributes, from the dir entry */
131 ULONG size; /* file size, from the dir entry */
133 UBYTE name[FAT_MAX_LONG_FILENAME]; /* copy of the name (bstr) */
134 #if DEBUG_NAMES
135 UBYTE shortname[FAT_MAX_SHORT_NAME + 2]; /* copy of the short name (bstr) */
136 #endif
138 struct MinList locks; /* list of ExtFileLocks opened on this file */
141 /* A node in the list of notification requests */
142 struct NotifyNode
144 struct MinNode node;
146 struct GlobalLock *gl; /* pointer to global lock if this file is
147 locked. if it's not, this is NULL */
149 struct NotifyRequest *nr; /* the request that DOS passed us */
152 struct VolumeInfo
154 APTR mem_pool;
155 ULONG id;
156 struct MinList locks; /* global locks */
157 struct GlobalLock root_lock;
158 struct MinList notifies;
161 struct VolumeIdentity
163 UBYTE name[FAT_MAX_SHORT_NAME + 2]; /* BCPL string */
164 struct DateStamp create_time;
167 struct FSSuper
169 struct Node node;
171 struct Globals *glob;
172 struct DosList *doslist;
174 struct VolumeInfo *info;
176 struct cache *cache;
177 ULONG first_device_sector;
179 ULONG sectorsize;
180 ULONG sectorsize_bits;
182 ULONG cluster_sectors;
183 ULONG clustersize;
184 ULONG clustersize_bits;
185 ULONG cluster_sectors_bits;
187 ULONG first_fat_sector;
188 ULONG first_data_sector;
189 ULONG first_rootdir_sector;
191 ULONG rootdir_sectors;
192 ULONG total_sectors;
193 ULONG data_sectors;
194 ULONG clusters_count;
195 ULONG fat_size;
196 UWORD fat_count;
198 ULONG free_clusters;
199 ULONG next_cluster;
201 ULONG volume_id;
202 ULONG type;
203 ULONG eoc_mark;
205 APTR *fat_blocks;
206 UBYTE **fat_buffers;
207 ULONG fat_blocks_count;
209 ULONG fat_cachesize;
210 ULONG fat_cachesize_bits;
211 ULONG fat_cache_block;
212 UWORD fat_cache_no; /* FAT number that cached FAT blocks belong to */
214 APTR fsinfo_block;
215 struct FATFSInfo *fsinfo_buffer;
217 ULONG rootdir_cluster;
218 ULONG rootdir_sector;
220 struct VolumeIdentity volume;
222 /* function table */
223 ULONG (*func_get_fat_entry)(struct FSSuper *sb, ULONG n);
224 BOOL (*func_set_fat_entry)(struct FSSuper *sb, ULONG n, ULONG val);
225 /* ... */
228 struct Globals
230 /* Libraries */
231 struct ExecBase *gl_SysBase;
232 struct DosLibrary *gl_DOSBase;
233 struct Library *gl_UtilityBase;
234 struct Device *gl_TimerBase;
236 /* mem/task */
237 struct Task *ourtask;
238 struct MsgPort *ourport;
239 APTR mempool;
241 struct MsgPort *notifyport;
243 /* fs */
244 struct DosList *devnode;
245 struct FileSysStartupMsg *fssm;
246 BOOL quit;
247 struct DosPacket *death_packet;
248 BOOL autodetect;
250 /* io */
251 struct IOExtTD *diskioreq;
252 struct IOExtTD *diskchgreq;
253 struct MsgPort *diskport;
254 ULONG diskchgsig_bit;
255 struct timerequest *timereq;
256 struct MsgPort *timerport;
257 ULONG last_num; /* last block number that was outside boundaries */
258 UWORD readcmd;
259 UWORD writecmd;
260 BOOL timer_active;
261 BOOL restart_timer;
263 /* volumes */
264 struct FSSuper *sb; /* current sb */
265 struct MinList sblist; /* sbs with outstanding locks or notifies */
267 /* disk status */
268 LONG disk_inhibited;
269 BOOL disk_inserted;
270 BOOL formatting;
272 /* Character sets translation */
273 UBYTE from_unicode[65536];
274 UWORD to_unicode[256];
276 /* Disk change interrupt */
277 struct IntData {
278 struct Interrupt Interrupt;
279 struct ExecBase *SysBase;
280 struct Task *task;
281 ULONG signal;
282 } DiskChangeIntData;
285 #define DOSBase (glob->gl_DOSBase)
286 #define SysBase (glob->gl_SysBase)
287 #define UtilityBase (glob->gl_UtilityBase)
288 #define TimerBase (glob->gl_TimerBase)
290 #include "support.h"
292 /* Get the first sector of a cluster */
293 #define SECTOR_FROM_CLUSTER(sb,cl) \
294 ((ULONG) (((cl-2) << sb->cluster_sectors_bits) + sb->first_data_sector))
296 #define FIRST_FILE_CLUSTER(de) \
297 (AROS_LE2WORD((de)->e.entry.first_cluster_lo) | \
298 (((ULONG) AROS_LE2WORD((de)->e.entry.first_cluster_hi)) << 16))
300 #define RESET_HANDLE(ioh) \
301 do \
303 (ioh)->cluster_offset = (ioh)->sector_offset = 0xffffffff; \
304 if ((ioh)->block != NULL) \
306 Cache_FreeBlock((ioh)->sb->cache, (ioh)->block); \
307 (ioh)->block = NULL; \
310 while (0);
312 #define RESET_DIRHANDLE(dh) \
313 do \
315 RESET_HANDLE(&((dh)->ioh)); \
316 (dh)->cur_index = 0xffffffff; \
318 while(0);
320 #define GET_NEXT_CLUSTER(sb,cl) (sb->func_get_fat_entry(sb,cl))
321 #define SET_NEXT_CLUSTER(sb,cl,val) (sb->func_set_fat_entry(sb,cl,val))
323 #define CALC_SHORT_NAME_CHECKSUM(name,checksum) \
324 do \
326 ULONG i; \
327 checksum = 0; \
328 for (i = 0; i < FAT_MAX_SHORT_NAME; i++) \
329 checksum = \
330 ((checksum & 1) ? 0x80 : 0) + (checksum >> 1) + name[i]; \
332 while(0);
334 #define LOCKFROMNODE(A) \
335 ((struct ExtFileLock *) \
336 (((BYTE *)(A)) - (IPTR)&((struct ExtFileLock *)NULL)->node))
338 #endif