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 #define ID_NTFS_DISK 0x4E544653UL
43 #define ACTION_VOLUME_ADD 16000
44 #define ACTION_VOLUME_REMOVE 16001
46 #define DEF_POOL_SIZE 65536
47 #define DEF_POOL_THRESHOLD DEF_POOL_SIZE
48 #define DEF_BUFF_LINES 128
49 #define DEF_READ_AHEAD 16*1024
51 #define SECTORSIZE_SHIFT 9
53 #define RLEFLAG_COMPR (1 << 0)
54 #define RLEFLAG_SPARSE (1 << 1)
58 struct MFTAttr
*emft_buf
;
59 struct MFTAttr
*edat_buf
;
60 struct MFTAttr
*attr_cur
;
61 struct MFTAttr
*attr_nxt
;
62 struct MFTAttr
*attr_end
;
63 struct NTFSMFTEntry
*mft
;
72 APTR cblock
; /* current block from the cache */
73 UBYTE
*cbuf
; /* current data buffer (from cache) */
74 UBYTE
*buf
; /* MFT Entry Buffer */
77 struct NTFSMFTAttr attr
;
81 struct NTFSRunLstEntry
83 struct NTFSMFTAttr
*attr
;
92 /* a handle on something, file or directory */
94 struct FSData
*data
; /* filesystem data */
96 UQUAD first_cluster
; /* first cluster of this file */
98 struct NTFSMFTEntry mft
;
103 /* a handle on a directory */
108 struct NTFSMFTAttr idx_attr
;
109 ULONG cur_no
; /* last entry returned, for GetNextDirEntry */
115 UBYTE
*pos
; /* byte offset within index record that the entry came from */
116 ULONG current
; /* index no. of this entry */
121 /* single directory entry */
123 struct FSData
*data
; /* filesystem data */
124 struct Index_Key
*key
;
125 struct NTFSMFTEntry
*entry
;
129 UQUAD cluster
; /* cluster the containing directory starts at */
135 /* struct FileLock */
139 struct MsgPort
*fl_Task
;
142 ULONG magic
; /* we set this to ID_NTFS_DISK so we can tell
143 our locks from those of other filesystems */
145 struct FSData
*data
; /* pointer to data, for unlocking when volume is removed */
146 struct GlobalLock
*gl
; /* pointer to the global lock for this file */
147 struct MinNode node
; /* node in the list of locks attached to the global lock */
149 struct DirHandle
*dir
; /* handle for reads and writes */
150 struct DirEntry
*entry
; /* handle for reads and writes */
151 UQUAD pos
; /* current seek position within the file */
153 BOOL do_notify
; /* if set, send notification on file close (ACTION_END) */
159 ULONG dir_cluster
; /* first cluster of the directory we're in */
160 ULONG dir_entry
; /* this is our dir entry within dir_cluster */
162 LONG access
; /* access mode, shared or exclusive */
164 ULONG first_cluster
; /* first data cluster */
166 ULONG attr
; /* file attributes, from the dir entry */
167 UQUAD size
; /* file size, from the dir entry */
169 UBYTE name
[256]; /* copy of the name (bstr) */
171 struct MinList locks
; /* list of ExtFileLocks opened on this file */
174 /* a node in the list of notification requests */
178 struct GlobalLock
*gl
; /* pointer to global lock if this file is
179 locked. if it's not, this is NULL */
181 struct NotifyRequest
*nr
; /* the request that DOS passed us */
185 struct MinList locks
; /* global locks */
186 struct MinList notifies
;
188 struct GlobalLock root_lock
;
192 struct VolumeIdentity
{
193 UBYTE name
[128]; /* BCPL string */
194 struct DateStamp create_time
;
199 struct DosList
*doslist
;
201 struct VolumeInfo
*info
;
204 ULONG first_device_sector
;
207 ULONG sectorsize_bits
;
209 ULONG cluster_sectors
;
211 ULONG clustersize_bits
;
212 ULONG cluster_sectors_bits
;
214 struct NTFSMFTEntry mft
; /* Handle for $MFT access */
215 struct NTFSMFTEntry bmmft
; /* Handle for $Bitmap access */
216 struct NTFSMFTEntry logmft
; /* Handle for $LogFile access */
217 struct NTFSMFTEntry secmft
; /* Handle for $LogFile access */
225 struct VolumeIdentity volume
;
233 struct Task
*ourtask
;
234 struct MsgPort
*ourport
;
237 struct MsgPort
*notifyport
;
240 struct DosList
*devnode
;
241 struct FileSysStartupMsg
*fssm
;
243 struct DosPacket
*death_packet
;
247 struct IOExtTD
*diskioreq
;
248 struct IOExtTD
*diskchgreq
;
249 struct MsgPort
*diskport
;
250 ULONG diskchgsig_bit
;
251 struct timerequest
*timereq
;
252 struct MsgPort
*timerport
;
253 ULONG last_num
; /* last block number that was outside boundaries */
260 struct FSData
*data
; /* current data */
261 struct MinList sblist
; /* sbs with outstanding locks or notifies */
267 /* Character sets translation */
268 UBYTE from_unicode
[65536];
269 UWORD to_unicode
[256];
272 //#include "support.h"
274 /* new definitions as we refactor the code */
276 #define RESET_HANDLE(ioh) \
278 if ((ioh)->mft.cblock != NULL) { \
279 Cache_FreeBlock((ioh)->data->cache, (ioh)->mft.cblock); \
280 (ioh)->mft.cblock = NULL; \
284 #define RESET_DIRHANDLE(dh) \
286 RESET_HANDLE(&((dh)->ioh)); \
290 #define LOCKFROMNODE(A) \
291 ((struct ExtFileLock *) \
292 (((BYTE *)(A)) - (IPTR)&((struct ExtFileLock *)NULL)->node))
294 #define INIT_MFTATTRIB(attrib, mftentry) \
296 struct NTFSMFTAttr *tmpattr = (struct NTFSMFTAttr *)attrib; \
297 tmpattr->mft = mftentry; \
298 tmpattr->flags = (tmpattr->mft == &tmpattr->mft->data->mft) ? AF_MMFT : 0; \
299 tmpattr->attr_nxt = (struct MFTAttr *)(tmpattr->mft->buf + AROS_LE2WORD(*((UWORD *)(tmpattr->mft->buf + 0x14)))); \
300 tmpattr->attr_end = tmpattr->emft_buf = tmpattr->edat_buf = tmpattr->sbuf = NULL; \