added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / workbench / fs / fat / fat_fs.h
blob190b204411784f0c2149aa96fa0e0e07d7f182f0
1 /*
2 * fat.handler - FAT12/16/32 filesystem handler
4 * Copyright © 2006 Marek Szyprowski
5 * Copyright © 2007 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 ie cur = sector(cur_cluster) + offset */
68 struct cache_block *block; /* current block from the cache */
71 /* a handle on a directory */
72 struct DirHandle {
73 struct IOHandle ioh;
75 ULONG cur_index; /* last entry returned, for GetNextDirEntry */
78 /* single directory entry */
79 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 {
98 /* struct FileLock */
99 BPTR fl_Link;
100 LONG 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) */
117 struct GlobalLock {
118 struct MinNode node;
120 ULONG dir_cluster; /* first cluster of the directory we're in */
121 ULONG dir_entry; /* this is our dir entry within dir_cluster */
123 LONG access; /* access mode, shared or exclusive */
125 ULONG first_cluster; /* first data cluster */
127 ULONG attr; /* file attributes, from the dir entry */
128 ULONG size; /* file size, from the dir entry */
130 UBYTE name[108]; /* copy of the name (bstr) */
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 its not, this is NULL */
142 struct NotifyRequest *nr; /* the request that DOS passed us */
145 struct VolumeInfo {
146 UBYTE name[32]; /* BCPL string */
147 struct DateStamp create_time;
150 struct FSSuper {
151 struct FSSuper *next;
152 struct DosList *doslist;
154 struct cache *cache;
155 ULONG first_device_sector;
157 ULONG sectorsize;
158 ULONG sectorsize_bits;
160 ULONG cluster_sectors;
161 ULONG clustersize;
162 ULONG clustersize_bits;
163 ULONG cluster_sectors_bits;
165 ULONG first_fat_sector;
166 ULONG first_data_sector;
167 ULONG first_rootdir_sector;
169 ULONG rootdir_sectors;
170 ULONG total_sectors;
171 ULONG data_sectors;
172 ULONG clusters_count;
173 ULONG fat_size;
175 ULONG free_clusters;
177 ULONG volume_id;
178 ULONG type;
179 ULONG eoc_mark;
181 struct cache_block **fat_blocks;
182 ULONG fat_blocks_count;
184 ULONG fat_cachesize;
185 ULONG fat_cachesize_bits;
186 ULONG fat_cache_block;
188 ULONG rootdir_cluster;
189 ULONG rootdir_sector;
191 struct VolumeInfo volume;
193 struct MinList locks;
194 struct GlobalLock root_lock;
196 struct MinList notifies;
198 /* function table */
199 ULONG (*func_get_fat_entry)(struct FSSuper *sb, ULONG n);
200 void (*func_set_fat_entry)(struct FSSuper *sb, ULONG n, ULONG val);
201 /* ... */
204 struct Globals {
205 /* mem/task */
206 struct Task *ourtask;
207 struct MsgPort *ourport;
208 APTR mempool;
210 struct MsgPort *notifyport;
212 /* fs */
213 struct DosList *devnode;
214 struct FileSysStartupMsg *fssm;
215 LONG quit;
216 BOOL autodetect;
218 /* io */
219 struct IOExtTD *diskioreq;
220 struct IOExtTD *diskchgreq;
221 struct MsgPort *diskport;
223 /* volumes */
224 struct FSSuper *sb; /* current sb */
225 struct FSSuper *sblist; /* list of sbs with outstanding locks */
227 /* disk status */
228 LONG disk_inserted;
229 LONG disk_inhibited;
232 #include "support.h"
234 /* new definitions as we refactor the code */
236 /* get the first sector of a cluster */
237 #define SECTOR_FROM_CLUSTER(sb,cl) ((ULONG) (((cl-2) << sb->cluster_sectors_bits) + sb->first_data_sector))
239 #define FIRST_FILE_CLUSTER(de) \
240 (AROS_LE2WORD((de)->e.entry.first_cluster_lo) | \
241 (((ULONG) AROS_LE2WORD((de)->e.entry.first_cluster_hi)) << 16))
243 #define RESET_HANDLE(ioh) \
244 do { \
245 (ioh)->cluster_offset = (ioh)->sector_offset = 0xffffffff; \
246 if ((ioh)->block != NULL) { \
247 cache_put_block((ioh)->sb->cache, (ioh)->block, 0); \
248 (ioh)->block = NULL; \
250 } while (0);
252 #define GET_NEXT_CLUSTER(sb,cl) (sb->func_get_fat_entry(sb,cl))
253 #define SET_NEXT_CLUSTER(sb,cl,val) (sb->func_set_fat_entry(sb,cl,val))
255 #define CALC_SHORT_NAME_CHECKSUM(name,checksum) \
256 do { \
257 ULONG i; \
258 checksum = 0; \
259 for (i = 0; i < 11; i++) \
260 checksum = ((checksum & 1) ? 0x80 : 0) + (checksum >> 1) + name[i]; \
261 } while(0);
263 #endif