1 /* $NetBSD: ntfs.h,v 1.9 1999/10/31 19:45:26 jdolecek Exp $ */
4 * Copyright (c) 1998, 1999 Semen Ustimenko
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * $FreeBSD: src/sys/ntfs/ntfs.h,v 1.8.2.2 2001/10/12 22:08:49 semenu Exp $
29 * $DragonFly: src/sys/vfs/ntfs/ntfs.h,v 1.7 2004/10/12 19:21:02 dillon Exp $
32 /*#define NTFS_DEBUG 1*/
33 #if defined(__NetBSD__) && defined(_KERNEL) && !defined(_LKM)
36 #if defined(__DragonFly__)
37 #include <sys/thread2.h>
40 typedef u_int64_t cn_t;
41 typedef u_int16_t wchar;
45 #define BBOFF ((off_t)(0))
46 #define BBLOCK ((daddr_t)(0))
48 #define NTFS_VOLUMEINO 3
49 #define NTFS_ATTRDEFINO 4
50 #define NTFS_ROOTINO 5
51 #define NTFS_BITMAPINO 6
52 #define NTFS_BOOTINO 7
53 #define NTFS_BADCLUSINO 8
54 #define NTFS_UPCASEINO 10
55 #define NTFS_MAXFILENAME 255
63 #define NTFS_AF_INRUN 0x00000001
71 u_int8_t a_compression;
75 #define NTFS_A_STD 0x10
76 #define NTFS_A_ATTRLIST 0x20
77 #define NTFS_A_NAME 0x30
78 #define NTFS_A_VOLUMENAME 0x60
79 #define NTFS_A_DATA 0x80
80 #define NTFS_A_INDXROOT 0x90
81 #define NTFS_A_INDX 0xA0
82 #define NTFS_A_INDXBITMAP 0xB0
84 #define NTFS_MAXATTRNAME 255
98 u_int16_t a_compressalg;
100 u_int64_t a_allocated;
102 u_int64_t a_initialized;
106 #define a_r a_S.a_S_r
107 #define a_nr a_S.a_S_nr
112 u_int64_t t_mftwrite;
116 #define NTFS_FFLAG_RDONLY 0x01LL
117 #define NTFS_FFLAG_HIDDEN 0x02LL
118 #define NTFS_FFLAG_SYSTEM 0x04LL
119 #define NTFS_FFLAG_ARCHIVE 0x20LL
120 #define NTFS_FFLAG_COMPRESSED 0x0800LL
121 #define NTFS_FFLAG_DIR 0x10000000LL
124 u_int32_t n_pnumber; /* Parent ntnode */
126 ntfs_times_t n_times;
135 #define NTFS_IRFLAG_INDXALLOC 0x00000001
136 struct attr_indexroot {
137 u_int32_t ir_unkn1; /* always 0x30 */
138 u_int32_t ir_unkn2; /* always 0x1 */
139 u_int32_t ir_size;/* ??? */
140 u_int32_t ir_unkn3; /* number of cluster */
141 u_int32_t ir_unkn4; /* always 0x10 */
142 u_int32_t ir_datalen; /* sizeof simething */
143 u_int32_t ir_allocated; /* same as above */
144 u_int16_t ir_flag;/* ?? always 1 */
148 struct attr_attrlist {
149 u_int32_t al_type; /* Attribute type */
150 u_int16_t reclen; /* length of this entry */
151 u_int8_t al_namelen; /* Attribute name len */
152 u_int8_t al_nameoff; /* Name offset from entry start */
153 u_int64_t al_vcnstart; /* VCN number */
154 u_int32_t al_inumber; /* Parent ntnode */
156 u_int16_t al_index; /* Attribute index in MFT record */
157 u_int16_t al_name[1]; /* Name */
160 #define NTFS_INDXMAGIC (u_int32_t)(0x58444E49)
161 struct attr_indexalloc {
162 struct fixuphdr ia_fixup;
165 u_int16_t ia_hdrsize;
168 u_int32_t ia_allocated;
171 #define NTFS_IEFLAG_SUBNODE 0x00000001
172 #define NTFS_IEFLAG_LAST 0x00000002
174 struct attr_indexentry {
179 u_int32_t ie_flag;/* 1 - has subnodes, 2 - last */
180 u_int32_t ie_fpnumber;
182 ntfs_times_t ie_ftimes;
183 u_int64_t ie_fallocated;
186 u_int8_t ie_fnamelen;
187 u_int8_t ie_fnametype;
188 wchar ie_fname[NTFS_MAXFILENAME];
189 /* cn_t ie_bufcn; buffer with subnodes */
192 #define NTFS_FILEMAGIC (u_int32_t)(0x454C4946)
193 #define NTFS_FRFLAG_DIR 0x0002
195 struct fixuphdr fr_fixup;
196 u_int8_t reserved[8];
197 u_int16_t fr_seqnum; /* Sequence number */
199 u_int16_t fr_attroff; /* offset to attributes */
200 u_int16_t fr_flags; /* 1-nonresident attr, 2-directory */
201 u_int32_t fr_size;/* hdr + attributes */
202 u_int32_t fr_allocated; /* allocated length of record */
203 u_int64_t fr_mainrec; /* main record */
204 u_int16_t fr_attrnum; /* maximum attr number + 1 ??? */
207 #define NTFS_ATTRNAME_MAXLEN 0x40
208 #define NTFS_ADFLAG_NONRES 0x0080 /* Attrib can be non resident */
209 #define NTFS_ADFLAG_INDEX 0x0002 /* Attrib can be indexed */
211 wchar ad_name[NTFS_ATTRNAME_MAXLEN];
213 u_int32_t reserved1[2];
216 u_int64_t ad_maxlen; /* -1 for nonlimited */
225 #define NTFS_BBID "NTFS "
226 #define NTFS_BBIDLEN 8
228 u_int8_t reserved1[3]; /* asm jmp near ... */
229 u_int8_t bf_sysid[8]; /* 'NTFS ' */
230 u_int16_t bf_bps; /* bytes per sector */
231 u_int8_t bf_spc; /* sectors per cluster */
232 u_int8_t reserved2[7]; /* unused (zeroed) */
233 u_int8_t bf_media; /* media desc. (0xF8) */
234 u_int8_t reserved3[2];
235 u_int16_t bf_spt; /* sectors per track */
236 u_int16_t bf_heads; /* number of heads */
237 u_int8_t reserver4[12];
238 u_int64_t bf_spv; /* sectors per volume */
239 cn_t bf_mftcn; /* $MFT cluster number */
240 cn_t bf_mftmirrcn; /* $MFTMirr cn */
241 u_int8_t bf_mftrecsz; /* MFT record size (clust) */
242 /* 0xF6 inducates 1/4 */
243 u_int32_t bf_ibsz; /* index buffer size */
244 u_int32_t bf_volsn; /* volume ser. num. */
247 #define NTFS_SYSNODESNUM 0x0B
249 struct mount *ntm_mountp; /* filesystem vfs structure */
250 struct bootfile ntm_bootfile;
251 dev_t ntm_dev; /* device mounted */
252 struct vnode *ntm_devvp; /* block device mounted vnode */
253 struct vnode *ntm_sysvn[NTFS_SYSNODESNUM];
254 u_int32_t ntm_bpmftrec;
260 struct ntvattrdef *ntm_ad;
262 struct netexport ntm_export; /* export information */
263 wchar * ntm_82u; /* 8bit to Unicode */
264 char ** ntm_u28; /* Unicode to 8 bit */
267 #define ntm_mftcn ntm_bootfile.bf_mftcn
268 #define ntm_mftmirrcn ntm_bootfile.bf_mftmirrcn
269 #define ntm_mftrecsz ntm_bootfile.bf_mftrecsz
270 #define ntm_spc ntm_bootfile.bf_spc
271 #define ntm_bps ntm_bootfile.bf_bps
275 #define NTFS_NEXTREC(s, type) ((type)(((caddr_t) s) + (s)->reclen))
277 /* Convert mount ptr to ntfsmount ptr. */
278 #define VFSTONTFS(mp) ((struct ntfsmount *)((mp)->mnt_data))
279 #define VTONT(v) FTONT(VTOF(v))
280 #define VTOF(v) ((struct fnode *)((v)->v_data))
281 #define FTOV(f) ((f)->f_vp)
282 #define FTONT(f) ((f)->f_ip)
283 #define ntfs_cntobn(cn) (daddr_t)((cn) * (ntmp->ntm_spc))
284 #define ntfs_cntob(cn) (off_t)((cn) * (ntmp)->ntm_spc * (ntmp)->ntm_bps)
285 #define ntfs_btocn(off) (cn_t)((off) / ((ntmp)->ntm_spc * (ntmp)->ntm_bps))
286 #define ntfs_btocl(off) (cn_t)((off + ntfs_cntob(1) - 1) / ((ntmp)->ntm_spc * (ntmp)->ntm_bps))
287 #define ntfs_btocnoff(off) (off_t)((off) % ((ntmp)->ntm_spc * (ntmp)->ntm_bps))
288 #define ntfs_bntob(bn) (daddr_t)((bn) * (ntmp)->ntm_bps)
290 #define ntfs_bpbl (daddr_t)((ntmp)->ntm_bps)
292 #ifdef MALLOC_DECLARE
293 MALLOC_DECLARE(M_NTFSMNT);
294 MALLOC_DECLARE(M_NTFSNTNODE);
295 MALLOC_DECLARE(M_NTFSFNODE);
296 MALLOC_DECLARE(M_NTFSDIR);
297 MALLOC_DECLARE(M_NTFSNTHASH);
301 #define MALLOC_DEFINE(a, b, c)
302 #define M_NTFSNTHASH M_NTFS
303 #define M_NTFSNTVATTR M_NTFS
304 #define M_NTFSRDATA M_NTFS
305 #define M_NTFSRUN M_NTFS
306 #define M_NTFSDECOMP M_NTFS
307 #define M_NTFSMNT M_NTFS
308 #define M_NTFSNTNODE M_NTFS
309 #define M_NTFSFNODE M_NTFS
310 #define M_NTFSDIR M_NTFS
311 typedef int (vop_t) (void *);
312 #define HASHINIT(a, b, c, d) hashinit((a), (b), (c), (d))
313 #define bqrelse(bp) brelse(bp)
314 #define VOP__UNLOCK(a, b, c) VOP_UNLOCK((a), (b))
315 #define VGET(a, b, c) vget((a), (b))
316 #define VN_LOCK(a, b, c) vn_lock((a), (b))
317 #define LOCKMGR(a, b, c) lockmgr((a), (b), (c))
319 #define HASHINIT(a, b, c, d) hashinit((a), (b), (d))
320 #define VOP__UNLOCK(a, b, c) VOP_UNLOCK((a), (b), (c))
321 #define VGET(a, b, c) vget((a), (b), (c))
322 #define VN_LOCK(a, b, c) vn_lock((a), (b), (c))
323 #define LOCKMGR(a, b, c) lockmgr((a), (b), (c), curthread)
327 #if defined(NTFS_DEBUG)
328 #define dprintf(a) printf a
330 #define ddprintf(a) printf a