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.
17 #define DEBUG_DIRENTRY 0
22 #define DEBUG_NOTIFY 0
24 #define DEBUG_PACKETS 0
25 #define DEBUG_CACHESTATS 0
28 #include <aros/libcall.h>
29 #include <devices/trackdisk.h>
30 #include <libraries/uuid.h>
32 #include "ntfs_struct.h"
38 extern struct Globals
*glob
;
40 /* filesystem structures */
41 #if !defined(ID_NTFS_DISK)
42 #define ID_NTFS_DISK 0x4E544653UL
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)
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
;
74 APTR cblock
; /* current block from the cache */
75 UBYTE
*cbuf
; /* current data buffer (from cache) */
76 UBYTE
*buf
; /* MFT Entry Buffer */
79 struct NTFSMFTAttr attr
;
83 struct NTFSRunLstEntry
85 struct NTFSMFTAttr
*attr
;
94 /* a handle on something, file or directory */
96 struct FSData
*data
; /* filesystem data */
98 UQUAD first_cluster
; /* first cluster of this file */
100 struct NTFSMFTEntry mft
;
105 /* a handle on a directory */
110 struct NTFSMFTAttr idx_attr
;
111 ULONG cur_no
; /* last entry returned, for GetNextDirEntry */
117 UBYTE
*pos
; /* byte offset within index record that the entry came from */
118 ULONG current
; /* index no. of this entry */
123 /* single directory entry */
125 struct FSData
*data
; /* filesystem data */
126 struct Index_Key
*key
;
127 struct NTFSMFTEntry
*entry
;
131 UQUAD cluster
; /* cluster the containing directory starts at */
137 /* struct FileLock */
141 struct MsgPort
*fl_Task
;
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) */
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 */
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 */
187 struct MinList locks
; /* global locks */
188 struct MinList notifies
;
190 struct GlobalLock root_lock
;
194 struct VolumeIdentity
{
195 UBYTE name
[128]; /* BCPL string */
196 struct DateStamp create_time
;
201 struct DosList
*doslist
;
203 struct VolumeInfo
*info
;
206 ULONG first_device_sector
;
209 ULONG sectorsize_bits
;
211 ULONG cluster_sectors
;
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 */
227 struct VolumeIdentity volume
;
235 struct Task
*ourtask
;
236 struct MsgPort
*ourport
;
239 struct MsgPort
*notifyport
;
242 struct DosList
*devnode
;
243 struct FileSysStartupMsg
*fssm
;
245 struct DosPacket
*death_packet
;
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 */
262 struct FSData
*data
; /* current data */
263 struct MinList sblist
; /* sbs with outstanding locks or notifies */
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) \
280 if ((ioh)->mft.cblock != NULL) { \
281 Cache_FreeBlock((ioh)->data->cache, (ioh)->mft.cblock); \
282 (ioh)->mft.cblock = NULL; \
286 #define RESET_DIRHANDLE(dh) \
288 RESET_HANDLE(&((dh)->ioh)); \
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; \