revert between 56095 -> 55830 in arch
[AROS.git] / workbench / fs / ntfs / ntfs_fs.h
blobe0a3c261b638d1c445d76190545a2115565b21fb
1 /*
2 * ntfs.handler - New Technology FileSystem handler
4 * Copyright © 2012 The AROS Development Team
6 * This program is free software; you can redistribute it and/or modify it
7 * under the same terms as AROS itself.
9 * $Id $
12 #ifndef NTFS_FS_H
13 #define NTFS_FS_H
15 //#define DEBUG 1
17 #define DEBUG_DIRENTRY 0
18 #define DEBUG_FILE 0
19 #define DEBUG_DUMP 0
20 #define DEBUG_LOCK 0
21 #define DEBUG_NAMES 0
22 #define DEBUG_NOTIFY 0
23 #define DEBUG_OPS 0
24 #define DEBUG_PACKETS 0
25 #define DEBUG_CACHESTATS 0
26 #define DEBUG_MISC 0
28 #include <aros/libcall.h>
29 #include <devices/trackdisk.h>
30 #include <libraries/uuid.h>
32 #include "ntfs_struct.h"
34 #include "cache.h"
36 #define NTFS_READONLY
38 extern struct Globals *glob;
40 /* filesystem structures */
41 #if !defined(ID_NTFS_DISK)
42 #define ID_NTFS_DISK 0x4E544653UL
43 #endif
45 #define ACTION_VOLUME_ADD 16000
46 #define ACTION_VOLUME_REMOVE 16001
48 #define DEF_POOL_SIZE 65536
49 #define DEF_POOL_THRESHOLD DEF_POOL_SIZE
50 #define DEF_BUFF_LINES 128
51 #define DEF_READ_AHEAD 16*1024
53 #define SECTORSIZE_SHIFT 9
55 #define RLEFLAG_COMPR (1 << 0)
56 #define RLEFLAG_SPARSE (1 << 1)
58 struct NTFSMFTAttr
60 struct MFTAttr *emft_buf;
61 struct MFTAttr *edat_buf;
62 struct MFTAttr *attr_cur;
63 struct MFTAttr *attr_nxt;
64 struct MFTAttr *attr_end;
65 struct NTFSMFTEntry *mft;
66 struct MFTAttr *sbuf;
67 ULONG save_pos;
68 UBYTE flags;
71 struct NTFSMFTEntry
73 struct FSData *data;
74 APTR cblock; /* current block from the cache */
75 UBYTE *cbuf; /* current data buffer (from cache) */
76 UBYTE *buf; /* MFT Entry Buffer */
77 UQUAD size;
78 UQUAD mftrec_no;
79 struct NTFSMFTAttr attr;
80 UBYTE buf_filled;
83 struct NTFSRunLstEntry
85 struct NTFSMFTAttr *attr;
86 UBYTE *mappingpair;
87 UQUAD target_vcn;
88 UQUAD curr_vcn;
89 UQUAD next_vcn;
90 UQUAD curr_lcn;
91 UBYTE flags;
94 /* a handle on something, file or directory */
95 struct IOHandle {
96 struct FSData *data; /* filesystem data */
98 UQUAD first_cluster; /* first cluster of this file */
100 struct NTFSMFTEntry mft;
101 UBYTE *bitmap;
102 UQUAD bitmap_len;
105 /* a handle on a directory */
106 struct DirHandle {
107 struct IOHandle ioh;
108 UQUAD parent_mft;
109 UBYTE *idx_root;
110 struct NTFSMFTAttr idx_attr;
111 ULONG cur_no; /* last entry returned, for GetNextDirEntry */
114 struct Index_Key {
115 UBYTE *indx;
116 UBYTE *bitmap;
117 UBYTE *pos; /* byte offset within index record that the entry came from */
118 ULONG current; /* index no. of this entry */
119 UQUAD i;
120 UWORD v;
123 /* single directory entry */
124 struct DirEntry {
125 struct FSData *data; /* filesystem data */
126 struct Index_Key *key;
127 struct NTFSMFTEntry *entry;
128 char *entryname;
129 ULONG entrytype;
130 ULONG no;
131 UQUAD cluster; /* cluster the containing directory starts at */
134 struct GlobalLock;
136 struct ExtFileLock {
137 /* struct FileLock */
138 BPTR fl_Link;
139 IPTR fl_Key;
140 LONG fl_Access;
141 struct MsgPort *fl_Task;
142 BPTR fl_Volume;
144 ULONG magic; /* we set this to ID_NTFS_DISK so we can tell
145 our locks from those of other filesystems */
147 struct FSData *data; /* pointer to data, for unlocking when volume is removed */
148 struct GlobalLock *gl; /* pointer to the global lock for this file */
149 struct MinNode node; /* node in the list of locks attached to the global lock */
151 struct DirHandle *dir; /* handle for reads and writes */
152 struct DirEntry *entry; /* handle for reads and writes */
153 UQUAD pos; /* current seek position within the file */
155 BOOL do_notify; /* if set, send notification on file close (ACTION_END) */
158 struct GlobalLock {
159 struct MinNode node;
161 ULONG dir_cluster; /* first cluster of the directory we're in */
162 ULONG dir_entry; /* this is our dir entry within dir_cluster */
164 LONG access; /* access mode, shared or exclusive */
166 ULONG first_cluster; /* first data cluster */
168 ULONG attr; /* file attributes, from the dir entry */
169 UQUAD size; /* file size, from the dir entry */
171 UBYTE name[256]; /* copy of the name (bstr) */
173 struct MinList locks; /* list of ExtFileLocks opened on this file */
176 /* a node in the list of notification requests */
177 struct NotifyNode {
178 struct MinNode node;
180 struct GlobalLock *gl; /* pointer to global lock if this file is
181 locked. if it's not, this is NULL */
183 struct NotifyRequest *nr; /* the request that DOS passed us */
186 struct VolumeInfo {
187 struct MinList locks; /* global locks */
188 struct MinList notifies;
189 APTR mem_pool;
190 struct GlobalLock root_lock;
191 uuid_t uuid;
194 struct VolumeIdentity {
195 UBYTE name[128]; /* BCPL string */
196 struct DateStamp create_time;
199 struct FSData {
200 struct Node node;
201 struct DosList *doslist;
203 struct VolumeInfo *info;
205 struct cache *cache;
206 ULONG first_device_sector;
208 ULONG sectorsize;
209 ULONG sectorsize_bits;
211 ULONG cluster_sectors;
212 ULONG clustersize;
213 ULONG clustersize_bits;
214 ULONG cluster_sectors_bits;
216 struct NTFSMFTEntry mft; /* Handle for $MFT access */
217 struct NTFSMFTEntry bmmft; /* Handle for $Bitmap access */
218 struct NTFSMFTEntry logmft; /* Handle for $LogFile access */
219 struct NTFSMFTEntry secmft; /* Handle for $LogFile access */
221 ULONG idx_size;
222 ULONG mft_size;
223 UQUAD mft_start;
225 uuid_t uuid;
227 struct VolumeIdentity volume;
229 UQUAD total_sectors;
230 UQUAD used_sectors;
233 struct Globals {
234 /* mem/task */
235 struct Task *ourtask;
236 struct MsgPort *ourport;
237 APTR mempool;
239 struct MsgPort *notifyport;
241 /* fs */
242 struct DosList *devnode;
243 struct FileSysStartupMsg *fssm;
244 LONG quit;
245 struct DosPacket *death_packet;
246 BOOL autodetect;
248 /* io */
249 struct IOExtTD *diskioreq;
250 struct IOExtTD *diskchgreq;
251 struct MsgPort *diskport;
252 ULONG diskchgsig_bit;
253 struct timerequest *timereq;
254 struct MsgPort *timerport;
255 ULONG last_num; /* last block number that was outside boundaries */
256 UWORD readcmd;
257 UWORD writecmd;
258 char timer_active;
259 char restart_timer;
261 /* volumes */
262 struct FSData *data; /* current data */
263 struct MinList sblist; /* sbs with outstanding locks or notifies */
265 /* disk status */
266 LONG disk_inserted;
267 LONG disk_inhibited;
269 /* Character sets translation */
270 UBYTE from_unicode[65536];
271 UWORD to_unicode[256];
274 //#include "support.h"
276 /* new definitions as we refactor the code */
278 #define RESET_HANDLE(ioh) \
279 do { \
280 if ((ioh)->mft.cblock != NULL) { \
281 Cache_FreeBlock((ioh)->data->cache, (ioh)->mft.cblock); \
282 (ioh)->mft.cblock = NULL; \
284 } while (0);
286 #define RESET_DIRHANDLE(dh) \
287 do { \
288 RESET_HANDLE(&((dh)->ioh)); \
289 (dh)->cur_no = -1; \
290 } while(0);
292 #define LOCKFROMNODE(A) \
293 ((struct ExtFileLock *) \
294 (((BYTE *)(A)) - (IPTR)&((struct ExtFileLock *)NULL)->node))
296 #define INIT_MFTATTRIB(attrib, mftentry) \
298 struct NTFSMFTAttr *tmpattr = (struct NTFSMFTAttr *)attrib; \
299 tmpattr->mft = mftentry; \
300 tmpattr->flags = (tmpattr->mft == &tmpattr->mft->data->mft) ? AF_MMFT : 0; \
301 tmpattr->attr_nxt = (struct MFTAttr *)(tmpattr->mft->buf + AROS_LE2WORD(*((UWORD *)(tmpattr->mft->buf + 0x14)))); \
302 tmpattr->attr_end = tmpattr->emft_buf = tmpattr->edat_buf = tmpattr->sbuf = NULL; \
305 #endif