Chameleon

Chameleon Svn Source Tree

Root/trunk/i386/libsaio/ntfs_private.h

1/*
2 * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25/*$NetBSD: ntfs.h,v 1.9 1999/10/31 19:45:26 jdolecek Exp $*/
26
27/*-
28 * Copyright (c) 1998, 1999 Semen Ustimenko
29 * All rights reserved.
30 *
31 * Redistribution and use in source and binary forms, with or without
32 * modification, are permitted provided that the following conditions
33 * are met:
34 * 1. Redistributions of source code must retain the above copyright
35 * notice, this list of conditions and the following disclaimer.
36 * 2. Redistributions in binary form must reproduce the above copyright
37 * notice, this list of conditions and the following disclaimer in the
38 * documentation and/or other materials provided with the distribution.
39 *
40 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
41 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
43 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
44 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
45 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
46 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
48 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
49 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
50 * SUCH DAMAGE.
51 *
52 * $FreeBSD: src/sys/fs/ntfs/ntfs.h,v 1.14 2001/11/27 00:18:33 jhb Exp $
53 */
54
55/*#define NTFS_DEBUG 1*/
56
57#ifdef APPLE
58/* We're using FreeBSD style byte order macros in the source. */
59#include <libkern/OSByteOrder.h>
60#define le16toh(x)OSSwapLittleToHostInt16(x)
61#define le32toh(x)OSSwapLittleToHostInt32(x)
62#define le64toh(x)OSSwapLittleToHostInt64(x)
63
64/* FreeBSD mutexes correspond to Darwin's simple locks */
65#define mtx_lock(lock)simple_lock(lock)
66#define mtx_unlock(lock)simple_unlock(lock)
67#define mtx_destroy(lock)/* Nothing. */
68
69#define lockdestroy(lock)/* Nothing. */
70
71#endif
72
73typedef u_int64_t cn_t;
74typedef u_int16_t wchar;
75
76#pragma pack(1)
77#define BBSIZE1024
78#defineBBOFF((off_t)(0))
79#defineBBLOCK((daddr_t)(0))
80#defineNTFS_MFTINO0
81#defineNTFS_VOLUMEINO3
82#defineNTFS_ATTRDEFINO4
83#defineNTFS_ROOTINO5
84#defineNTFS_BITMAPINO6
85#defineNTFS_BOOTINO7
86#defineNTFS_BADCLUSINO8
87#defineNTFS_UPCASEINO10
88#define NTFS_MAXFILENAME255
89
90struct fixuphdr {
91u_int32_t fh_magic;
92u_int16_t fh_foff;
93u_int16_t fh_fnum;
94};
95
96#define NTFS_AF_INRUN0x00000001
97
98struct attrhdr {
99u_int32_t a_type;
100u_int32_t reclen;
101u_int8_t a_flag;
102u_int8_t a_namelen;
103u_int8_t a_nameoff;
104u_int8_t reserved1;
105u_int8_t a_compression;
106u_int8_t reserved2;
107u_int16_t a_index;
108};
109
110#define NTFS_A_STD0x10
111#define NTFS_A_ATTRLIST0x20
112#define NTFS_A_NAME0x30
113#define NTFS_A_VOLUMENAME0x60
114#define NTFS_A_DATA0x80
115#defineNTFS_A_INDXROOT0x90
116#defineNTFS_A_INDX0xA0
117#define NTFS_A_INDXBITMAP0xB0
118
119#define NTFS_MAXATTRNAME255
120
121struct attr {
122struct attrhdr a_hdr;
123union {
124struct {
125u_int16_t a_datalen;
126u_int16_t reserved1;
127u_int16_t a_dataoff;
128u_int16_t a_indexed;
129} a_S_r;
130struct {
131cn_t a_vcnstart;
132cn_t a_vcnend;
133u_int16_t a_dataoff;
134u_int16_t a_compressalg;
135u_int32_t reserved1;
136u_int64_t a_allocated;
137u_int64_t a_datalen;
138u_int64_t a_initialized;
139} a_S_nr;
140} a_S;
141};
142#define a_ra_S.a_S_r
143#define a_nra_S.a_S_nr
144
145typedef struct {
146u_int64_t t_create;
147u_int64_t t_write;
148u_int64_t t_mftwrite;
149u_int64_t t_access;
150} ntfs_times_t;
151
152#define NTFS_FFLAG_RDONLY0x01LL
153#define NTFS_FFLAG_HIDDEN0x02LL
154#define NTFS_FFLAG_SYSTEM0x04LL
155#define NTFS_FFLAG_ARCHIVE0x20LL
156#define NTFS_FFLAG_COMPRESSED0x0800LL
157#define NTFS_FFLAG_DIR0x10000000LL
158
159struct attr_name {
160u_int32_tn_pnumber;/* Parent ntnode */
161u_int32_t reserved;
162ntfs_times_t n_times;
163u_int64_t n_size;
164u_int64_t n_attrsz;
165u_int64_t n_flag;
166u_int8_t n_namelen;
167u_int8_t n_nametype;
168u_int16_t n_name[1];
169};
170
171#define NTFS_IRFLAG_INDXALLOC0x00000001
172struct attr_indexroot {
173u_int32_t ir_unkn1;/* attribute type (0x30 for $FILE_NAME) */
174u_int32_t ir_unkn2;/* collation rule (0x01 for file names) */
175u_int32_t ir_size;/* size of index allocation entry */
176u_int32_t ir_unkn3;/* clusters per index record, and 3 bytes padding */
177u_int32_t ir_unkn4;/* (offset to first index entry?) always 0x10 */
178u_int32_t ir_datalen;/* (total size of index enties?) sizeof something */
179u_int32_t ir_allocated;/* (allocated size of index entries?) */
180u_int8_t ir_flag;/* 1=index allocation needed (large index) */
181 u_int8_tir_pad1;/* padding */
182u_int16_t ir_pad2;/* padding */
183};
184
185struct attr_attrlist {
186u_int32_t al_type;/* Attribute type */
187u_int16_t reclen;/* length of this entry */
188u_int8_t al_namelen;/* Attribute name len */
189u_int8_t al_nameoff;/* Name offset from entry start */
190u_int64_t al_vcnstart;/* VCN number */
191u_int32_t al_inumber;/* Parent ntnode */
192u_int32_t reserved;
193u_int16_t al_index;/* Attribute index in MFT record */
194u_int16_t al_name[1];/* Name */
195};
196
197#defineNTFS_INDXMAGIC(u_int32_t)(0x58444E49)
198struct attr_indexalloc {
199struct fixuphdr ia_fixup;
200u_int64_t unknown1;
201cn_t ia_bufcn;
202u_int16_t ia_hdrsize;
203u_int16_t unknown2;
204u_int32_t ia_inuse;
205u_int32_t ia_allocated;
206};
207
208#defineNTFS_IEFLAG_SUBNODE0x00000001
209#defineNTFS_IEFLAG_LAST0x00000002
210
211struct attr_indexentry {
212u_int32_t ie_number;
213u_int32_t unknown1;
214u_int16_t reclen;
215u_int16_t ie_size;
216u_int32_t ie_flag;/* 1 - has subnodes, 2 - last */
217u_int32_t ie_fpnumber;
218u_int32_t unknown2;
219ntfs_times_t ie_ftimes;
220u_int64_t ie_fallocated;
221u_int64_t ie_fsize;
222u_int32_t ie_fflag;
223 u_int32_tunknown3;/* used by reparse points and external attributes? */
224u_int8_t ie_fnamelen;
225u_int8_t ie_fnametype;
226wchar ie_fname[NTFS_MAXFILENAME];
227/* cn_tie_bufcn; buffer with subnodes */
228};
229
230#defineNTFS_FILEMAGIC(u_int32_t)(0x454C4946)
231#defineNTFS_FRFLAG_DIR0x0002
232struct filerec {
233struct fixuphdr fr_fixup;
234u_int8_t reserved[8];
235u_int16_t fr_seqnum;/* Sequence number */
236u_int16_t fr_nlink;
237u_int16_t fr_attroff;/* offset to attributes */
238u_int16_t fr_flags;/* 1-nonresident attr, 2-directory */
239u_int32_t fr_size;/* hdr + attributes */
240u_int32_t fr_allocated;/* allocated length of record */
241u_int64_t fr_mainrec;/* main record */
242u_int16_t fr_attrnum;/* maximum attr number + 1 ??? */
243};
244
245#defineNTFS_ATTRNAME_MAXLEN0x40
246#defineNTFS_ADFLAG_NONRES0x0080/* Attrib can be non resident */
247#defineNTFS_ADFLAG_INDEX0x0002/* Attrib can be indexed */
248struct attrdef {
249wcharad_name[NTFS_ATTRNAME_MAXLEN];
250u_int32_tad_type;
251u_int32_treserved1[2];
252u_int32_tad_flag;
253u_int64_tad_minlen;
254u_int64_tad_maxlen;/* -1 for nonlimited */
255};
256
257struct ntvattrdef {
258charad_name[0x40];
259intad_namelen;
260u_int32_tad_type;
261};
262
263#defineNTFS_BBID"NTFS "
264#defineNTFS_BBIDLEN8
265struct bootfile {
266u_int8_t reserved1[3];/* asm jmp near ... */
267u_int8_t bf_sysid[8];/* 'NTFS ' */
268u_int16_t bf_bps;/* bytes per sector */
269u_int8_t bf_spc;/* sectors per cluster */
270u_int8_t reserved2[7];/* unused (zeroed) */
271u_int8_t bf_media;/* media desc. (0xF8) */
272u_int8_t reserved3[2];/* always 0 */
273u_int16_t bf_spt;/* sectors per track */
274u_int16_t bf_heads;/* number of heads */
275u_int8_t reserver4[12];
276u_int64_t bf_spv;/* sectors per volume */
277cn_t bf_mftcn;/* $MFT cluster number */
278cn_t bf_mftmirrcn;/* $MFTMirr cn */
279u_int8_t bf_mftrecsz;/* MFT record size (clust) */
280/* 0xF6 inducates 1/4 */
281u_int8_t reserved5[3];
282u_int8_t bf_ibsz;/* index buffer size */
283u_int8_t reserved6[3];
284u_int64_t bf_volsn;/* volume ser. num. */
285};
286
287/*
288 * Darwin's ntfs.util needs to include this file to get definitions
289 * for the on-disk structures. It doesn't need the ntfsmount structure.
290 * In fact, since it doesn't #define KERNEL, the struct netexport below
291 * won't be defined.
292 *
293 * So, I'm using #ifdef KERNEL around the things that are only relevant
294 * to the in-kernel implementation.
295 *
296
297 * invent a different conditional here.
298 */
299#ifdef KERNEL
300
301#defineNTFS_SYSNODESNUM0x0B
302struct ntfsmount {
303struct mount *ntm_mountp;/* filesystem vfs structure */
304struct bootfile ntm_bootfile;
305dev_t ntm_dev;/* device mounted */
306struct vnode *ntm_devvp;/* block device mounted vnode */
307struct vnode *ntm_sysvn[NTFS_SYSNODESNUM];
308u_int32_t ntm_bpmftrec;
309uid_t ntm_uid;
310gid_t ntm_gid;
311mode_t ntm_mode;
312u_long ntm_flag;
313cn_tntm_cfree;
314struct ntvattrdef *ntm_ad;/* attribute names are stored in native byte order */
315intntm_adnum;
316 wchar *ntm_82u;/* 8bit to Unicode */
317 char **ntm_u28;/* Unicode to 8 bit */
318#ifdef APPLE
319struct netexport ntm_export;/* NFS export information */
320#endif
321};
322
323#define ntm_mftcnntm_bootfile.bf_mftcn
324#define ntm_mftmirrcnntm_bootfile.bf_mftmirrcn
325#definentm_mftrecszntm_bootfile.bf_mftrecsz
326#definentm_spcntm_bootfile.bf_spc
327#definentm_bpsntm_bootfile.bf_bps
328
329#pragma pack()
330
331#defineNTFS_NEXTREC(s, type) ((type)(((caddr_t) s) + le16toh((s)->reclen)))
332
333/* Convert mount ptr to ntfsmount ptr. */
334#define VFSTONTFS(mp)((struct ntfsmount *)((mp)->mnt_data))
335#define VTONT(v)FTONT(VTOF(v))
336#defineVTOF(v)((struct fnode *)((v)->v_data))
337#defineFTOV(f)((f)->f_vp)
338#defineFTONT(f)((f)->f_ip)
339#define ntfs_cntobn(cn)((daddr_t)(cn) * (ntmp->ntm_spc))
340#define ntfs_cntob(cn)((off_t)(cn) * (ntmp)->ntm_spc * (ntmp)->ntm_bps)
341#define ntfs_btocn(off)(cn_t)((off) / ((ntmp)->ntm_spc * (ntmp)->ntm_bps))
342#define ntfs_btocl(off)(cn_t)((off + ntfs_cntob(1) - 1) / ((ntmp)->ntm_spc * (ntmp)->ntm_bps))
343#define ntfs_btocnoff(off)(off_t)((off) % ((ntmp)->ntm_spc * (ntmp)->ntm_bps))
344#define ntfs_bntob(bn)(daddr_t)((bn) * (ntmp)->ntm_bps)
345
346#definentfs_bpbl(daddr_t)((ntmp)->ntm_bps)
347
348#ifdef MALLOC_DECLARE
349MALLOC_DECLARE(M_NTFSMNT);
350MALLOC_DECLARE(M_NTFSNTNODE);
351MALLOC_DECLARE(M_NTFSFNODE);
352MALLOC_DECLARE(M_NTFSDIR);
353MALLOC_DECLARE(M_NTFSNTHASH);
354#endif
355
356#ifndef M_NTFSMNT
357#define M_NTFSMNT M_TEMP
358#endif
359#ifndef M_NTFSNTNODE
360#define M_NTFSNTNODE M_TEMP
361#endif
362#ifndef M_NTFSFNODE
363#define M_NTFSFNODE M_TEMP
364#endif
365#ifndef M_NTFSDIR
366#define M_NTFSDIR M_TEMP
367#endif
368#ifndef M_NTFSNTHASH
369#define M_NTFSNTHASH M_TEMP
370#endif
371#ifndef M_NTFSRUN
372#define M_NTFSRUN M_TEMP
373#endif
374#ifndef M_NTFSRDATA
375#define M_NTFSRDATA M_TEMP
376#endif
377#ifndef M_NTFSNTVATTR
378#define M_NTFSNTVATTR M_TEMP
379#endif
380#ifndef M_NTFSDECOMP
381#define M_NTFSDECOMP M_TEMP
382#endif
383#define VT_NTFS VT_OTHER
384
385#if defined(NTFS_DEBUG)
386#define dprintf(a) printf a
387#if NTFS_DEBUG > 1
388#define ddprintf(a) printf a
389#else
390#define ddprintf(a)
391#endif
392#else
393#define dprintf(a)
394#define ddprintf(a)
395#endif
396
397#ifdef APPLE
398typedef int vop_t(void *);
399#else
400#endif
401extern vop_t **ntfs_vnodeop_p;
402#endif /* KERNEL */
403

Archive Download this file

Revision: 2583