]> git.saurik.com Git - apple/boot.git/blame - i386/libsaio/ntfs_private.h
boot-122.tar.gz
[apple/boot.git] / i386 / libsaio / ntfs_private.h
CommitLineData
57c72a9a
A
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 BBSIZE 1024
78#define BBOFF ((off_t)(0))
79#define BBLOCK ((daddr_t)(0))
80#define NTFS_MFTINO 0
81#define NTFS_VOLUMEINO 3
82#define NTFS_ATTRDEFINO 4
83#define NTFS_ROOTINO 5
84#define NTFS_BITMAPINO 6
85#define NTFS_BOOTINO 7
86#define NTFS_BADCLUSINO 8
87#define NTFS_UPCASEINO 10
88#define NTFS_MAXFILENAME 255
89
90struct fixuphdr {
91 u_int32_t fh_magic;
92 u_int16_t fh_foff;
93 u_int16_t fh_fnum;
94};
95
96#define NTFS_AF_INRUN 0x00000001
97struct attrhdr {
98 u_int32_t a_type;
99 u_int32_t reclen;
100 u_int8_t a_flag;
101 u_int8_t a_namelen;
102 u_int8_t a_nameoff;
103 u_int8_t reserved1;
104 u_int8_t a_compression;
105 u_int8_t reserved2;
106 u_int16_t a_index;
107};
108#define NTFS_A_STD 0x10
109#define NTFS_A_ATTRLIST 0x20
110#define NTFS_A_NAME 0x30
111#define NTFS_A_VOLUMENAME 0x60
112#define NTFS_A_DATA 0x80
113#define NTFS_A_INDXROOT 0x90
114#define NTFS_A_INDX 0xA0
115#define NTFS_A_INDXBITMAP 0xB0
116
117#define NTFS_MAXATTRNAME 255
118struct attr {
119 struct attrhdr a_hdr;
120 union {
121 struct {
122 u_int16_t a_datalen;
123 u_int16_t reserved1;
124 u_int16_t a_dataoff;
125 u_int16_t a_indexed;
126 } a_S_r;
127 struct {
128 cn_t a_vcnstart;
129 cn_t a_vcnend;
130 u_int16_t a_dataoff;
131 u_int16_t a_compressalg;
132 u_int32_t reserved1;
133 u_int64_t a_allocated;
134 u_int64_t a_datalen;
135 u_int64_t a_initialized;
136 } a_S_nr;
137 } a_S;
138};
139#define a_r a_S.a_S_r
140#define a_nr a_S.a_S_nr
141
142typedef struct {
143 u_int64_t t_create;
144 u_int64_t t_write;
145 u_int64_t t_mftwrite;
146 u_int64_t t_access;
147} ntfs_times_t;
148
149#define NTFS_FFLAG_RDONLY 0x01LL
150#define NTFS_FFLAG_HIDDEN 0x02LL
151#define NTFS_FFLAG_SYSTEM 0x04LL
152#define NTFS_FFLAG_ARCHIVE 0x20LL
153#define NTFS_FFLAG_COMPRESSED 0x0800LL
154#define NTFS_FFLAG_DIR 0x10000000LL
155
156struct attr_name {
157 u_int32_t n_pnumber; /* Parent ntnode */
158 u_int32_t reserved;
159 ntfs_times_t n_times;
160 u_int64_t n_size;
161 u_int64_t n_attrsz;
162 u_int64_t n_flag;
163 u_int8_t n_namelen;
164 u_int8_t n_nametype;
165 u_int16_t n_name[1];
166};
167
168#define NTFS_IRFLAG_INDXALLOC 0x00000001
169struct attr_indexroot {
170 u_int32_t ir_unkn1; /* attribute type (0x30 for $FILE_NAME) */
171 u_int32_t ir_unkn2; /* collation rule (0x01 for file names) */
172 u_int32_t ir_size; /* size of index allocation entry */
173 u_int32_t ir_unkn3; /* clusters per index record, and 3 bytes padding */
174 u_int32_t ir_unkn4; /* (offset to first index entry?) always 0x10 */
175 u_int32_t ir_datalen; /* (total size of index enties?) sizeof something */
176 u_int32_t ir_allocated; /* (allocated size of index entries?) */
177 u_int8_t ir_flag; /* 1=index allocation needed (large index) */
178 u_int8_t ir_pad1; /* padding */
179 u_int16_t ir_pad2; /* padding */
180};
181
182struct attr_attrlist {
183 u_int32_t al_type; /* Attribute type */
184 u_int16_t reclen; /* length of this entry */
185 u_int8_t al_namelen; /* Attribute name len */
186 u_int8_t al_nameoff; /* Name offset from entry start */
187 u_int64_t al_vcnstart; /* VCN number */
188 u_int32_t al_inumber; /* Parent ntnode */
189 u_int32_t reserved;
190 u_int16_t al_index; /* Attribute index in MFT record */
191 u_int16_t al_name[1]; /* Name */
192};
193
194#define NTFS_INDXMAGIC (u_int32_t)(0x58444E49)
195struct attr_indexalloc {
196 struct fixuphdr ia_fixup;
197 u_int64_t unknown1;
198 cn_t ia_bufcn;
199 u_int16_t ia_hdrsize;
200 u_int16_t unknown2;
201 u_int32_t ia_inuse;
202 u_int32_t ia_allocated;
203};
204
205#define NTFS_IEFLAG_SUBNODE 0x00000001
206#define NTFS_IEFLAG_LAST 0x00000002
207
208struct attr_indexentry {
209 u_int32_t ie_number;
210 u_int32_t unknown1;
211 u_int16_t reclen;
212 u_int16_t ie_size;
213 u_int32_t ie_flag;/* 1 - has subnodes, 2 - last */
214 u_int32_t ie_fpnumber;
215 u_int32_t unknown2;
216 ntfs_times_t ie_ftimes;
217 u_int64_t ie_fallocated;
218 u_int64_t ie_fsize;
219 u_int32_t ie_fflag;
220 u_int32_t unknown3; /* used by reparse points and external attributes? */
221 u_int8_t ie_fnamelen;
222 u_int8_t ie_fnametype;
223 wchar ie_fname[NTFS_MAXFILENAME];
224 /* cn_t ie_bufcn; buffer with subnodes */
225};
226
227#define NTFS_FILEMAGIC (u_int32_t)(0x454C4946)
228#define NTFS_FRFLAG_DIR 0x0002
229struct filerec {
230 struct fixuphdr fr_fixup;
231 u_int8_t reserved[8];
232 u_int16_t fr_seqnum; /* Sequence number */
233 u_int16_t fr_nlink;
234 u_int16_t fr_attroff; /* offset to attributes */
235 u_int16_t fr_flags; /* 1-nonresident attr, 2-directory */
236 u_int32_t fr_size;/* hdr + attributes */
237 u_int32_t fr_allocated; /* allocated length of record */
238 u_int64_t fr_mainrec; /* main record */
239 u_int16_t fr_attrnum; /* maximum attr number + 1 ??? */
240};
241
242#define NTFS_ATTRNAME_MAXLEN 0x40
243#define NTFS_ADFLAG_NONRES 0x0080 /* Attrib can be non resident */
244#define NTFS_ADFLAG_INDEX 0x0002 /* Attrib can be indexed */
245struct attrdef {
246 wchar ad_name[NTFS_ATTRNAME_MAXLEN];
247 u_int32_t ad_type;
248 u_int32_t reserved1[2];
249 u_int32_t ad_flag;
250 u_int64_t ad_minlen;
251 u_int64_t ad_maxlen; /* -1 for nonlimited */
252};
253
254struct ntvattrdef {
255 char ad_name[0x40];
256 int ad_namelen;
257 u_int32_t ad_type;
258};
259
260#define NTFS_BBID "NTFS "
261#define NTFS_BBIDLEN 8
262struct bootfile {
263 u_int8_t reserved1[3]; /* asm jmp near ... */
264 u_int8_t bf_sysid[8]; /* 'NTFS ' */
265 u_int16_t bf_bps; /* bytes per sector */
266 u_int8_t bf_spc; /* sectors per cluster */
267 u_int8_t reserved2[7]; /* unused (zeroed) */
268 u_int8_t bf_media; /* media desc. (0xF8) */
269 u_int8_t reserved3[2];
270 u_int16_t bf_spt; /* sectors per track */
271 u_int16_t bf_heads; /* number of heads */
272 u_int8_t reserver4[12];
273 u_int64_t bf_spv; /* sectors per volume */
274 cn_t bf_mftcn; /* $MFT cluster number */
275 cn_t bf_mftmirrcn; /* $MFTMirr cn */
276 u_int8_t bf_mftrecsz; /* MFT record size (clust) */
277 /* 0xF6 inducates 1/4 */
278 u_int32_t bf_ibsz; /* index buffer size */
279 u_int32_t bf_volsn; /* volume ser. num. */
280};
281
282/*
283 * Darwin's ntfs.util needs to include this file to get definitions
284 * for the on-disk structures. It doesn't need the ntfsmount structure.
285 * In fact, since it doesn't #define KERNEL, the struct netexport below
286 * won't be defined.
287 *
288 * So, I'm using #ifdef KERNEL around the things that are only relevant
289 * to the in-kernel implementation.
290 *
291