Chameleon

Chameleon Svn Source Tree

Root/branches/ErmaC/Trunk/i386/libsaio/ntfs_private.h

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

Archive Download this file

Revision: 2045