]>
Commit | Line | Data |
---|---|---|
57c72a9a A |
1 | /* |
2 | * Copyright (c) 2004 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
6 | * Copyright (c) 1999-2004 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 | ||
26 | #include "libsaio.h" | |
27 | #include "sl.h" | |
28 | ||
29 | #define BYTE_ORDER_MARK 0xFEFF | |
30 | ||
31 | #include "ntfs_private.h" | |
32 | ||
33 | #define FS_TYPE "ntfs" | |
34 | #define FS_NAME_FILE "NTFS" | |
35 | ||
36 | #define MAX_BLOCK_SIZE 2048 | |
37 | #define MAX_CLUSTER_SIZE 32768 | |
38 | ||
39 | #define LABEL_LENGTH 1024 | |
40 | #define UNKNOWN_LABEL "Untitled NTFS" | |
41 | ||
42 | #define FSUR_IO_FAIL -1 | |
43 | #define FSUR_UNRECOGNIZED -1 | |
44 | #define FSUR_RECOGNIZED 0 | |
45 | ||
46 | #define ERROR -1 | |
47 | ||
48 | /* | |
49 | * Process per-sector "fixups" that NTFS uses to detect corruption of | |
50 | * multi-sector data structures, like MFT records. | |
51 | */ | |
52 | static int | |
53 | ntfs_fixup( | |
54 | char *buf, | |
55 | size_t len, | |
56 | u_int32_t magic, | |
57 | u_int32_t bytesPerSector) | |
58 | { | |
59 | struct fixuphdr *fhp = (struct fixuphdr *) buf; | |
60 | int i; | |
61 | u_int16_t fixup; | |
62 | u_int16_t *fxp; | |
63 | u_int16_t *cfxp; | |
64 | u_int32_t fixup_magic; | |
65 | u_int16_t fixup_count; | |
66 | u_int16_t fixup_offset; | |
67 | ||
68 | fixup_magic = OSReadLittleInt32(&fhp->fh_magic,0); | |
69 | if (fixup_magic != magic) { | |
70 | error("ntfs_fixup: magic doesn't match: %08x != %08x\n", | |
71 | fixup_magic, magic); | |
72 | return (ERROR); | |
73 | } | |
74 | fixup_count = OSReadLittleInt16(&fhp->fh_fnum,0); | |
75 | if ((fixup_count - 1) * bytesPerSector != len) { | |
76 | error("ntfs_fixup: " \ | |
77 | "bad fixups number: %d for %ld bytes block\n", | |
78 | fixup_count, (long)len); /* XXX printf kludge */ | |
79 | return (ERROR); | |
80 | } | |
81 | fixup_offset = OSReadLittleInt16(&fhp->fh_foff,0); | |
82 | if (fixup_offset >= len) { | |
83 | error("ntfs_fixup: invalid offset: %x", fixup_offset); | |
84 | return (ERROR); | |
85 | } | |
86 | fxp = (u_int16_t *) (buf + fixup_offset); | |
87 | cfxp = (u_int16_t *) (buf + bytesPerSector - 2); | |
88 | fixup = *fxp++; | |
89 | for (i = 1; i < fixup_count; i++, fxp++) { | |
90 | if (*cfxp != fixup) { | |
91 | error("ntfs_fixup: fixup %d doesn't match\n", i); | |
92 | return (ERROR); | |
93 | } | |
94 | *cfxp = *fxp; | |
bba600dd | 95 | cfxp = (u_int16_t *)(((caddr_t)cfxp) + bytesPerSector); |
57c72a9a A |
96 | } |
97 | return (0); | |
98 | } | |
99 | ||
100 | /* | |
101 | * Find a resident attribute of a given type. Returns a pointer to the | |
102 | * attribute data, and its size in bytes. | |
103 | */ | |
104 | static int | |
105 | ntfs_find_attr( | |
106 | char *buf, | |
107 | u_int32_t attrType, | |
108 | void **attrData, | |
109 | size_t *attrSize) | |
110 | { | |
111 | struct filerec *filerec; | |
112 | struct attr *attr; | |
113 | u_int16_t offset; | |
114 | ||
115 | filerec = (struct filerec *) buf; | |
116 | offset = OSReadLittleInt16(&filerec->fr_attroff,0); | |
117 | attr = (struct attr *) (buf + offset); | |
118 | ||
119 |