Commit 0e37579506b9e0c11a4a95c8df6b156b2d6ccf9b
1 parent
719741d998
Exists in
smarc-l5.0.0_1.0.0-ga
and in
5 other branches
NTFS: Remove unused variable.
Found by Coverity software (http://scan.coverity.com). Signed-off-by: Anton Altaparmakov <anton@tuxera.com>
Showing 1 changed file with 1 additions and 3 deletions Inline Diff
fs/ntfs/super.c
1 | /* | 1 | /* |
2 | * super.c - NTFS kernel super block handling. Part of the Linux-NTFS project. | 2 | * super.c - NTFS kernel super block handling. Part of the Linux-NTFS project. |
3 | * | 3 | * |
4 | * Copyright (c) 2001-2011 Anton Altaparmakov and Tuxera Inc. | 4 | * Copyright (c) 2001-2012 Anton Altaparmakov and Tuxera Inc. |
5 | * Copyright (c) 2001,2002 Richard Russon | 5 | * Copyright (c) 2001,2002 Richard Russon |
6 | * | 6 | * |
7 | * This program/include file is free software; you can redistribute it and/or | 7 | * This program/include file is free software; you can redistribute it and/or |
8 | * modify it under the terms of the GNU General Public License as published | 8 | * modify it under the terms of the GNU General Public License as published |
9 | * by the Free Software Foundation; either version 2 of the License, or | 9 | * by the Free Software Foundation; either version 2 of the License, or |
10 | * (at your option) any later version. | 10 | * (at your option) any later version. |
11 | * | 11 | * |
12 | * This program/include file is distributed in the hope that it will be | 12 | * This program/include file is distributed in the hope that it will be |
13 | * useful, but WITHOUT ANY WARRANTY; without even the implied warranty | 13 | * useful, but WITHOUT ANY WARRANTY; without even the implied warranty |
14 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 14 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * GNU General Public License for more details. | 15 | * GNU General Public License for more details. |
16 | * | 16 | * |
17 | * You should have received a copy of the GNU General Public License | 17 | * You should have received a copy of the GNU General Public License |
18 | * along with this program (in the main directory of the Linux-NTFS | 18 | * along with this program (in the main directory of the Linux-NTFS |
19 | * distribution in the file COPYING); if not, write to the Free Software | 19 | * distribution in the file COPYING); if not, write to the Free Software |
20 | * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 20 | * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
21 | */ | 21 | */ |
22 | 22 | ||
23 | #include <linux/stddef.h> | 23 | #include <linux/stddef.h> |
24 | #include <linux/init.h> | 24 | #include <linux/init.h> |
25 | #include <linux/slab.h> | 25 | #include <linux/slab.h> |
26 | #include <linux/string.h> | 26 | #include <linux/string.h> |
27 | #include <linux/spinlock.h> | 27 | #include <linux/spinlock.h> |
28 | #include <linux/blkdev.h> /* For bdev_logical_block_size(). */ | 28 | #include <linux/blkdev.h> /* For bdev_logical_block_size(). */ |
29 | #include <linux/backing-dev.h> | 29 | #include <linux/backing-dev.h> |
30 | #include <linux/buffer_head.h> | 30 | #include <linux/buffer_head.h> |
31 | #include <linux/vfs.h> | 31 | #include <linux/vfs.h> |
32 | #include <linux/moduleparam.h> | 32 | #include <linux/moduleparam.h> |
33 | #include <linux/bitmap.h> | 33 | #include <linux/bitmap.h> |
34 | 34 | ||
35 | #include "sysctl.h" | 35 | #include "sysctl.h" |
36 | #include "logfile.h" | 36 | #include "logfile.h" |
37 | #include "quota.h" | 37 | #include "quota.h" |
38 | #include "usnjrnl.h" | 38 | #include "usnjrnl.h" |
39 | #include "dir.h" | 39 | #include "dir.h" |
40 | #include "debug.h" | 40 | #include "debug.h" |
41 | #include "index.h" | 41 | #include "index.h" |
42 | #include "inode.h" | 42 | #include "inode.h" |
43 | #include "aops.h" | 43 | #include "aops.h" |
44 | #include "layout.h" | 44 | #include "layout.h" |
45 | #include "malloc.h" | 45 | #include "malloc.h" |
46 | #include "ntfs.h" | 46 | #include "ntfs.h" |
47 | 47 | ||
48 | /* Number of mounted filesystems which have compression enabled. */ | 48 | /* Number of mounted filesystems which have compression enabled. */ |
49 | static unsigned long ntfs_nr_compression_users; | 49 | static unsigned long ntfs_nr_compression_users; |
50 | 50 | ||
51 | /* A global default upcase table and a corresponding reference count. */ | 51 | /* A global default upcase table and a corresponding reference count. */ |
52 | static ntfschar *default_upcase = NULL; | 52 | static ntfschar *default_upcase = NULL; |
53 | static unsigned long ntfs_nr_upcase_users = 0; | 53 | static unsigned long ntfs_nr_upcase_users = 0; |
54 | 54 | ||
55 | /* Error constants/strings used in inode.c::ntfs_show_options(). */ | 55 | /* Error constants/strings used in inode.c::ntfs_show_options(). */ |
56 | typedef enum { | 56 | typedef enum { |
57 | /* One of these must be present, default is ON_ERRORS_CONTINUE. */ | 57 | /* One of these must be present, default is ON_ERRORS_CONTINUE. */ |
58 | ON_ERRORS_PANIC = 0x01, | 58 | ON_ERRORS_PANIC = 0x01, |
59 | ON_ERRORS_REMOUNT_RO = 0x02, | 59 | ON_ERRORS_REMOUNT_RO = 0x02, |
60 | ON_ERRORS_CONTINUE = 0x04, | 60 | ON_ERRORS_CONTINUE = 0x04, |
61 | /* Optional, can be combined with any of the above. */ | 61 | /* Optional, can be combined with any of the above. */ |
62 | ON_ERRORS_RECOVER = 0x10, | 62 | ON_ERRORS_RECOVER = 0x10, |
63 | } ON_ERRORS_ACTIONS; | 63 | } ON_ERRORS_ACTIONS; |
64 | 64 | ||
65 | const option_t on_errors_arr[] = { | 65 | const option_t on_errors_arr[] = { |
66 | { ON_ERRORS_PANIC, "panic" }, | 66 | { ON_ERRORS_PANIC, "panic" }, |
67 | { ON_ERRORS_REMOUNT_RO, "remount-ro", }, | 67 | { ON_ERRORS_REMOUNT_RO, "remount-ro", }, |
68 | { ON_ERRORS_CONTINUE, "continue", }, | 68 | { ON_ERRORS_CONTINUE, "continue", }, |
69 | { ON_ERRORS_RECOVER, "recover" }, | 69 | { ON_ERRORS_RECOVER, "recover" }, |
70 | { 0, NULL } | 70 | { 0, NULL } |
71 | }; | 71 | }; |
72 | 72 | ||
73 | /** | 73 | /** |
74 | * simple_getbool - | 74 | * simple_getbool - |
75 | * | 75 | * |
76 | * Copied from old ntfs driver (which copied from vfat driver). | 76 | * Copied from old ntfs driver (which copied from vfat driver). |
77 | */ | 77 | */ |
78 | static int simple_getbool(char *s, bool *setval) | 78 | static int simple_getbool(char *s, bool *setval) |
79 | { | 79 | { |
80 | if (s) { | 80 | if (s) { |
81 | if (!strcmp(s, "1") || !strcmp(s, "yes") || !strcmp(s, "true")) | 81 | if (!strcmp(s, "1") || !strcmp(s, "yes") || !strcmp(s, "true")) |
82 | *setval = true; | 82 | *setval = true; |
83 | else if (!strcmp(s, "0") || !strcmp(s, "no") || | 83 | else if (!strcmp(s, "0") || !strcmp(s, "no") || |
84 | !strcmp(s, "false")) | 84 | !strcmp(s, "false")) |
85 | *setval = false; | 85 | *setval = false; |
86 | else | 86 | else |
87 | return 0; | 87 | return 0; |
88 | } else | 88 | } else |
89 | *setval = true; | 89 | *setval = true; |
90 | return 1; | 90 | return 1; |
91 | } | 91 | } |
92 | 92 | ||
93 | /** | 93 | /** |
94 | * parse_options - parse the (re)mount options | 94 | * parse_options - parse the (re)mount options |
95 | * @vol: ntfs volume | 95 | * @vol: ntfs volume |
96 | * @opt: string containing the (re)mount options | 96 | * @opt: string containing the (re)mount options |
97 | * | 97 | * |
98 | * Parse the recognized options in @opt for the ntfs volume described by @vol. | 98 | * Parse the recognized options in @opt for the ntfs volume described by @vol. |
99 | */ | 99 | */ |
100 | static bool parse_options(ntfs_volume *vol, char *opt) | 100 | static bool parse_options(ntfs_volume *vol, char *opt) |
101 | { | 101 | { |
102 | char *p, *v, *ov; | 102 | char *p, *v, *ov; |
103 | static char *utf8 = "utf8"; | 103 | static char *utf8 = "utf8"; |
104 | int errors = 0, sloppy = 0; | 104 | int errors = 0, sloppy = 0; |
105 | uid_t uid = (uid_t)-1; | 105 | uid_t uid = (uid_t)-1; |
106 | gid_t gid = (gid_t)-1; | 106 | gid_t gid = (gid_t)-1; |
107 | umode_t fmask = (umode_t)-1, dmask = (umode_t)-1; | 107 | umode_t fmask = (umode_t)-1, dmask = (umode_t)-1; |
108 | int mft_zone_multiplier = -1, on_errors = -1; | 108 | int mft_zone_multiplier = -1, on_errors = -1; |
109 | int show_sys_files = -1, case_sensitive = -1, disable_sparse = -1; | 109 | int show_sys_files = -1, case_sensitive = -1, disable_sparse = -1; |
110 | struct nls_table *nls_map = NULL, *old_nls; | 110 | struct nls_table *nls_map = NULL, *old_nls; |
111 | 111 | ||
112 | /* I am lazy... (-8 */ | 112 | /* I am lazy... (-8 */ |
113 | #define NTFS_GETOPT_WITH_DEFAULT(option, variable, default_value) \ | 113 | #define NTFS_GETOPT_WITH_DEFAULT(option, variable, default_value) \ |
114 | if (!strcmp(p, option)) { \ | 114 | if (!strcmp(p, option)) { \ |
115 | if (!v || !*v) \ | 115 | if (!v || !*v) \ |
116 | variable = default_value; \ | 116 | variable = default_value; \ |
117 | else { \ | 117 | else { \ |
118 | variable = simple_strtoul(ov = v, &v, 0); \ | 118 | variable = simple_strtoul(ov = v, &v, 0); \ |
119 | if (*v) \ | 119 | if (*v) \ |
120 | goto needs_val; \ | 120 | goto needs_val; \ |
121 | } \ | 121 | } \ |
122 | } | 122 | } |
123 | #define NTFS_GETOPT(option, variable) \ | 123 | #define NTFS_GETOPT(option, variable) \ |
124 | if (!strcmp(p, option)) { \ | 124 | if (!strcmp(p, option)) { \ |
125 | if (!v || !*v) \ | 125 | if (!v || !*v) \ |
126 | goto needs_arg; \ | 126 | goto needs_arg; \ |
127 | variable = simple_strtoul(ov = v, &v, 0); \ | 127 | variable = simple_strtoul(ov = v, &v, 0); \ |
128 | if (*v) \ | 128 | if (*v) \ |
129 | goto needs_val; \ | 129 | goto needs_val; \ |
130 | } | 130 | } |
131 | #define NTFS_GETOPT_OCTAL(option, variable) \ | 131 | #define NTFS_GETOPT_OCTAL(option, variable) \ |
132 | if (!strcmp(p, option)) { \ | 132 | if (!strcmp(p, option)) { \ |
133 | if (!v || !*v) \ | 133 | if (!v || !*v) \ |
134 | goto needs_arg; \ | 134 | goto needs_arg; \ |
135 | variable = simple_strtoul(ov = v, &v, 8); \ | 135 | variable = simple_strtoul(ov = v, &v, 8); \ |
136 | if (*v) \ | 136 | if (*v) \ |
137 | goto needs_val; \ | 137 | goto needs_val; \ |
138 | } | 138 | } |
139 | #define NTFS_GETOPT_BOOL(option, variable) \ | 139 | #define NTFS_GETOPT_BOOL(option, variable) \ |
140 | if (!strcmp(p, option)) { \ | 140 | if (!strcmp(p, option)) { \ |
141 | bool val; \ | 141 | bool val; \ |
142 | if (!simple_getbool(v, &val)) \ | 142 | if (!simple_getbool(v, &val)) \ |
143 | goto needs_bool; \ | 143 | goto needs_bool; \ |
144 | variable = val; \ | 144 | variable = val; \ |
145 | } | 145 | } |
146 | #define NTFS_GETOPT_OPTIONS_ARRAY(option, variable, opt_array) \ | 146 | #define NTFS_GETOPT_OPTIONS_ARRAY(option, variable, opt_array) \ |
147 | if (!strcmp(p, option)) { \ | 147 | if (!strcmp(p, option)) { \ |
148 | int _i; \ | 148 | int _i; \ |
149 | if (!v || !*v) \ | 149 | if (!v || !*v) \ |
150 | goto needs_arg; \ | 150 | goto needs_arg; \ |
151 | ov = v; \ | 151 | ov = v; \ |
152 | if (variable == -1) \ | 152 | if (variable == -1) \ |
153 | variable = 0; \ | 153 | variable = 0; \ |
154 | for (_i = 0; opt_array[_i].str && *opt_array[_i].str; _i++) \ | 154 | for (_i = 0; opt_array[_i].str && *opt_array[_i].str; _i++) \ |
155 | if (!strcmp(opt_array[_i].str, v)) { \ | 155 | if (!strcmp(opt_array[_i].str, v)) { \ |
156 | variable |= opt_array[_i].val; \ | 156 | variable |= opt_array[_i].val; \ |
157 | break; \ | 157 | break; \ |
158 | } \ | 158 | } \ |
159 | if (!opt_array[_i].str || !*opt_array[_i].str) \ | 159 | if (!opt_array[_i].str || !*opt_array[_i].str) \ |
160 | goto needs_val; \ | 160 | goto needs_val; \ |
161 | } | 161 | } |
162 | if (!opt || !*opt) | 162 | if (!opt || !*opt) |
163 | goto no_mount_options; | 163 | goto no_mount_options; |
164 | ntfs_debug("Entering with mount options string: %s", opt); | 164 | ntfs_debug("Entering with mount options string: %s", opt); |
165 | while ((p = strsep(&opt, ","))) { | 165 | while ((p = strsep(&opt, ","))) { |
166 | if ((v = strchr(p, '='))) | 166 | if ((v = strchr(p, '='))) |
167 | *v++ = 0; | 167 | *v++ = 0; |
168 | NTFS_GETOPT("uid", uid) | 168 | NTFS_GETOPT("uid", uid) |
169 | else NTFS_GETOPT("gid", gid) | 169 | else NTFS_GETOPT("gid", gid) |
170 | else NTFS_GETOPT_OCTAL("umask", fmask = dmask) | 170 | else NTFS_GETOPT_OCTAL("umask", fmask = dmask) |
171 | else NTFS_GETOPT_OCTAL("fmask", fmask) | 171 | else NTFS_GETOPT_OCTAL("fmask", fmask) |
172 | else NTFS_GETOPT_OCTAL("dmask", dmask) | 172 | else NTFS_GETOPT_OCTAL("dmask", dmask) |
173 | else NTFS_GETOPT("mft_zone_multiplier", mft_zone_multiplier) | 173 | else NTFS_GETOPT("mft_zone_multiplier", mft_zone_multiplier) |
174 | else NTFS_GETOPT_WITH_DEFAULT("sloppy", sloppy, true) | 174 | else NTFS_GETOPT_WITH_DEFAULT("sloppy", sloppy, true) |
175 | else NTFS_GETOPT_BOOL("show_sys_files", show_sys_files) | 175 | else NTFS_GETOPT_BOOL("show_sys_files", show_sys_files) |
176 | else NTFS_GETOPT_BOOL("case_sensitive", case_sensitive) | 176 | else NTFS_GETOPT_BOOL("case_sensitive", case_sensitive) |
177 | else NTFS_GETOPT_BOOL("disable_sparse", disable_sparse) | 177 | else NTFS_GETOPT_BOOL("disable_sparse", disable_sparse) |
178 | else NTFS_GETOPT_OPTIONS_ARRAY("errors", on_errors, | 178 | else NTFS_GETOPT_OPTIONS_ARRAY("errors", on_errors, |
179 | on_errors_arr) | 179 | on_errors_arr) |
180 | else if (!strcmp(p, "posix") || !strcmp(p, "show_inodes")) | 180 | else if (!strcmp(p, "posix") || !strcmp(p, "show_inodes")) |
181 | ntfs_warning(vol->sb, "Ignoring obsolete option %s.", | 181 | ntfs_warning(vol->sb, "Ignoring obsolete option %s.", |
182 | p); | 182 | p); |
183 | else if (!strcmp(p, "nls") || !strcmp(p, "iocharset")) { | 183 | else if (!strcmp(p, "nls") || !strcmp(p, "iocharset")) { |
184 | if (!strcmp(p, "iocharset")) | 184 | if (!strcmp(p, "iocharset")) |
185 | ntfs_warning(vol->sb, "Option iocharset is " | 185 | ntfs_warning(vol->sb, "Option iocharset is " |
186 | "deprecated. Please use " | 186 | "deprecated. Please use " |
187 | "option nls=<charsetname> in " | 187 | "option nls=<charsetname> in " |
188 | "the future."); | 188 | "the future."); |
189 | if (!v || !*v) | 189 | if (!v || !*v) |
190 | goto needs_arg; | 190 | goto needs_arg; |
191 | use_utf8: | 191 | use_utf8: |
192 | old_nls = nls_map; | 192 | old_nls = nls_map; |
193 | nls_map = load_nls(v); | 193 | nls_map = load_nls(v); |
194 | if (!nls_map) { | 194 | if (!nls_map) { |
195 | if (!old_nls) { | 195 | if (!old_nls) { |
196 | ntfs_error(vol->sb, "NLS character set " | 196 | ntfs_error(vol->sb, "NLS character set " |
197 | "%s not found.", v); | 197 | "%s not found.", v); |
198 | return false; | 198 | return false; |
199 | } | 199 | } |
200 | ntfs_error(vol->sb, "NLS character set %s not " | 200 | ntfs_error(vol->sb, "NLS character set %s not " |
201 | "found. Using previous one %s.", | 201 | "found. Using previous one %s.", |
202 | v, old_nls->charset); | 202 | v, old_nls->charset); |
203 | nls_map = old_nls; | 203 | nls_map = old_nls; |
204 | } else /* nls_map */ { | 204 | } else /* nls_map */ { |
205 | unload_nls(old_nls); | 205 | unload_nls(old_nls); |
206 | } | 206 | } |
207 | } else if (!strcmp(p, "utf8")) { | 207 | } else if (!strcmp(p, "utf8")) { |
208 | bool val = false; | 208 | bool val = false; |
209 | ntfs_warning(vol->sb, "Option utf8 is no longer " | 209 | ntfs_warning(vol->sb, "Option utf8 is no longer " |
210 | "supported, using option nls=utf8. Please " | 210 | "supported, using option nls=utf8. Please " |
211 | "use option nls=utf8 in the future and " | 211 | "use option nls=utf8 in the future and " |
212 | "make sure utf8 is compiled either as a " | 212 | "make sure utf8 is compiled either as a " |
213 | "module or into the kernel."); | 213 | "module or into the kernel."); |
214 | if (!v || !*v) | 214 | if (!v || !*v) |
215 | val = true; | 215 | val = true; |
216 | else if (!simple_getbool(v, &val)) | 216 | else if (!simple_getbool(v, &val)) |
217 | goto needs_bool; | 217 | goto needs_bool; |
218 | if (val) { | 218 | if (val) { |
219 | v = utf8; | 219 | v = utf8; |
220 | goto use_utf8; | 220 | goto use_utf8; |
221 | } | 221 | } |
222 | } else { | 222 | } else { |
223 | ntfs_error(vol->sb, "Unrecognized mount option %s.", p); | 223 | ntfs_error(vol->sb, "Unrecognized mount option %s.", p); |
224 | if (errors < INT_MAX) | 224 | if (errors < INT_MAX) |
225 | errors++; | 225 | errors++; |
226 | } | 226 | } |
227 | #undef NTFS_GETOPT_OPTIONS_ARRAY | 227 | #undef NTFS_GETOPT_OPTIONS_ARRAY |
228 | #undef NTFS_GETOPT_BOOL | 228 | #undef NTFS_GETOPT_BOOL |
229 | #undef NTFS_GETOPT | 229 | #undef NTFS_GETOPT |
230 | #undef NTFS_GETOPT_WITH_DEFAULT | 230 | #undef NTFS_GETOPT_WITH_DEFAULT |
231 | } | 231 | } |
232 | no_mount_options: | 232 | no_mount_options: |
233 | if (errors && !sloppy) | 233 | if (errors && !sloppy) |
234 | return false; | 234 | return false; |
235 | if (sloppy) | 235 | if (sloppy) |
236 | ntfs_warning(vol->sb, "Sloppy option given. Ignoring " | 236 | ntfs_warning(vol->sb, "Sloppy option given. Ignoring " |
237 | "unrecognized mount option(s) and continuing."); | 237 | "unrecognized mount option(s) and continuing."); |
238 | /* Keep this first! */ | 238 | /* Keep this first! */ |
239 | if (on_errors != -1) { | 239 | if (on_errors != -1) { |
240 | if (!on_errors) { | 240 | if (!on_errors) { |
241 | ntfs_error(vol->sb, "Invalid errors option argument " | 241 | ntfs_error(vol->sb, "Invalid errors option argument " |
242 | "or bug in options parser."); | 242 | "or bug in options parser."); |
243 | return false; | 243 | return false; |
244 | } | 244 | } |
245 | } | 245 | } |
246 | if (nls_map) { | 246 | if (nls_map) { |
247 | if (vol->nls_map && vol->nls_map != nls_map) { | 247 | if (vol->nls_map && vol->nls_map != nls_map) { |
248 | ntfs_error(vol->sb, "Cannot change NLS character set " | 248 | ntfs_error(vol->sb, "Cannot change NLS character set " |
249 | "on remount."); | 249 | "on remount."); |
250 | return false; | 250 | return false; |
251 | } /* else (!vol->nls_map) */ | 251 | } /* else (!vol->nls_map) */ |
252 | ntfs_debug("Using NLS character set %s.", nls_map->charset); | 252 | ntfs_debug("Using NLS character set %s.", nls_map->charset); |
253 | vol->nls_map = nls_map; | 253 | vol->nls_map = nls_map; |
254 | } else /* (!nls_map) */ { | 254 | } else /* (!nls_map) */ { |
255 | if (!vol->nls_map) { | 255 | if (!vol->nls_map) { |
256 | vol->nls_map = load_nls_default(); | 256 | vol->nls_map = load_nls_default(); |
257 | if (!vol->nls_map) { | 257 | if (!vol->nls_map) { |
258 | ntfs_error(vol->sb, "Failed to load default " | 258 | ntfs_error(vol->sb, "Failed to load default " |
259 | "NLS character set."); | 259 | "NLS character set."); |
260 | return false; | 260 | return false; |
261 | } | 261 | } |
262 | ntfs_debug("Using default NLS character set (%s).", | 262 | ntfs_debug("Using default NLS character set (%s).", |
263 | vol->nls_map->charset); | 263 | vol->nls_map->charset); |
264 | } | 264 | } |
265 | } | 265 | } |
266 | if (mft_zone_multiplier != -1) { | 266 | if (mft_zone_multiplier != -1) { |
267 | if (vol->mft_zone_multiplier && vol->mft_zone_multiplier != | 267 | if (vol->mft_zone_multiplier && vol->mft_zone_multiplier != |
268 | mft_zone_multiplier) { | 268 | mft_zone_multiplier) { |
269 | ntfs_error(vol->sb, "Cannot change mft_zone_multiplier " | 269 | ntfs_error(vol->sb, "Cannot change mft_zone_multiplier " |
270 | "on remount."); | 270 | "on remount."); |
271 | return false; | 271 | return false; |
272 | } | 272 | } |
273 | if (mft_zone_multiplier < 1 || mft_zone_multiplier > 4) { | 273 | if (mft_zone_multiplier < 1 || mft_zone_multiplier > 4) { |
274 | ntfs_error(vol->sb, "Invalid mft_zone_multiplier. " | 274 | ntfs_error(vol->sb, "Invalid mft_zone_multiplier. " |
275 | "Using default value, i.e. 1."); | 275 | "Using default value, i.e. 1."); |
276 | mft_zone_multiplier = 1; | 276 | mft_zone_multiplier = 1; |
277 | } | 277 | } |
278 | vol->mft_zone_multiplier = mft_zone_multiplier; | 278 | vol->mft_zone_multiplier = mft_zone_multiplier; |
279 | } | 279 | } |
280 | if (!vol->mft_zone_multiplier) | 280 | if (!vol->mft_zone_multiplier) |
281 | vol->mft_zone_multiplier = 1; | 281 | vol->mft_zone_multiplier = 1; |
282 | if (on_errors != -1) | 282 | if (on_errors != -1) |
283 | vol->on_errors = on_errors; | 283 | vol->on_errors = on_errors; |
284 | if (!vol->on_errors || vol->on_errors == ON_ERRORS_RECOVER) | 284 | if (!vol->on_errors || vol->on_errors == ON_ERRORS_RECOVER) |
285 | vol->on_errors |= ON_ERRORS_CONTINUE; | 285 | vol->on_errors |= ON_ERRORS_CONTINUE; |
286 | if (uid != (uid_t)-1) | 286 | if (uid != (uid_t)-1) |
287 | vol->uid = uid; | 287 | vol->uid = uid; |
288 | if (gid != (gid_t)-1) | 288 | if (gid != (gid_t)-1) |
289 | vol->gid = gid; | 289 | vol->gid = gid; |
290 | if (fmask != (umode_t)-1) | 290 | if (fmask != (umode_t)-1) |
291 | vol->fmask = fmask; | 291 | vol->fmask = fmask; |
292 | if (dmask != (umode_t)-1) | 292 | if (dmask != (umode_t)-1) |
293 | vol->dmask = dmask; | 293 | vol->dmask = dmask; |
294 | if (show_sys_files != -1) { | 294 | if (show_sys_files != -1) { |
295 | if (show_sys_files) | 295 | if (show_sys_files) |
296 | NVolSetShowSystemFiles(vol); | 296 | NVolSetShowSystemFiles(vol); |
297 | else | 297 | else |
298 | NVolClearShowSystemFiles(vol); | 298 | NVolClearShowSystemFiles(vol); |
299 | } | 299 | } |
300 | if (case_sensitive != -1) { | 300 | if (case_sensitive != -1) { |
301 | if (case_sensitive) | 301 | if (case_sensitive) |
302 | NVolSetCaseSensitive(vol); | 302 | NVolSetCaseSensitive(vol); |
303 | else | 303 | else |
304 | NVolClearCaseSensitive(vol); | 304 | NVolClearCaseSensitive(vol); |
305 | } | 305 | } |
306 | if (disable_sparse != -1) { | 306 | if (disable_sparse != -1) { |
307 | if (disable_sparse) | 307 | if (disable_sparse) |
308 | NVolClearSparseEnabled(vol); | 308 | NVolClearSparseEnabled(vol); |
309 | else { | 309 | else { |
310 | if (!NVolSparseEnabled(vol) && | 310 | if (!NVolSparseEnabled(vol) && |
311 | vol->major_ver && vol->major_ver < 3) | 311 | vol->major_ver && vol->major_ver < 3) |
312 | ntfs_warning(vol->sb, "Not enabling sparse " | 312 | ntfs_warning(vol->sb, "Not enabling sparse " |
313 | "support due to NTFS volume " | 313 | "support due to NTFS volume " |
314 | "version %i.%i (need at least " | 314 | "version %i.%i (need at least " |
315 | "version 3.0).", vol->major_ver, | 315 | "version 3.0).", vol->major_ver, |
316 | vol->minor_ver); | 316 | vol->minor_ver); |
317 | else | 317 | else |
318 | NVolSetSparseEnabled(vol); | 318 | NVolSetSparseEnabled(vol); |
319 | } | 319 | } |
320 | } | 320 | } |
321 | return true; | 321 | return true; |
322 | needs_arg: | 322 | needs_arg: |
323 | ntfs_error(vol->sb, "The %s option requires an argument.", p); | 323 | ntfs_error(vol->sb, "The %s option requires an argument.", p); |
324 | return false; | 324 | return false; |
325 | needs_bool: | 325 | needs_bool: |
326 | ntfs_error(vol->sb, "The %s option requires a boolean argument.", p); | 326 | ntfs_error(vol->sb, "The %s option requires a boolean argument.", p); |
327 | return false; | 327 | return false; |
328 | needs_val: | 328 | needs_val: |
329 | ntfs_error(vol->sb, "Invalid %s option argument: %s", p, ov); | 329 | ntfs_error(vol->sb, "Invalid %s option argument: %s", p, ov); |
330 | return false; | 330 | return false; |
331 | } | 331 | } |
332 | 332 | ||
333 | #ifdef NTFS_RW | 333 | #ifdef NTFS_RW |
334 | 334 | ||
335 | /** | 335 | /** |
336 | * ntfs_write_volume_flags - write new flags to the volume information flags | 336 | * ntfs_write_volume_flags - write new flags to the volume information flags |
337 | * @vol: ntfs volume on which to modify the flags | 337 | * @vol: ntfs volume on which to modify the flags |
338 | * @flags: new flags value for the volume information flags | 338 | * @flags: new flags value for the volume information flags |
339 | * | 339 | * |
340 | * Internal function. You probably want to use ntfs_{set,clear}_volume_flags() | 340 | * Internal function. You probably want to use ntfs_{set,clear}_volume_flags() |
341 | * instead (see below). | 341 | * instead (see below). |
342 | * | 342 | * |
343 | * Replace the volume information flags on the volume @vol with the value | 343 | * Replace the volume information flags on the volume @vol with the value |
344 | * supplied in @flags. Note, this overwrites the volume information flags, so | 344 | * supplied in @flags. Note, this overwrites the volume information flags, so |
345 | * make sure to combine the flags you want to modify with the old flags and use | 345 | * make sure to combine the flags you want to modify with the old flags and use |
346 | * the result when calling ntfs_write_volume_flags(). | 346 | * the result when calling ntfs_write_volume_flags(). |
347 | * | 347 | * |
348 | * Return 0 on success and -errno on error. | 348 | * Return 0 on success and -errno on error. |
349 | */ | 349 | */ |
350 | static int ntfs_write_volume_flags(ntfs_volume *vol, const VOLUME_FLAGS flags) | 350 | static int ntfs_write_volume_flags(ntfs_volume *vol, const VOLUME_FLAGS flags) |
351 | { | 351 | { |
352 | ntfs_inode *ni = NTFS_I(vol->vol_ino); | 352 | ntfs_inode *ni = NTFS_I(vol->vol_ino); |
353 | MFT_RECORD *m; | 353 | MFT_RECORD *m; |
354 | VOLUME_INFORMATION *vi; | 354 | VOLUME_INFORMATION *vi; |
355 | ntfs_attr_search_ctx *ctx; | 355 | ntfs_attr_search_ctx *ctx; |
356 | int err; | 356 | int err; |
357 | 357 | ||
358 | ntfs_debug("Entering, old flags = 0x%x, new flags = 0x%x.", | 358 | ntfs_debug("Entering, old flags = 0x%x, new flags = 0x%x.", |
359 | le16_to_cpu(vol->vol_flags), le16_to_cpu(flags)); | 359 | le16_to_cpu(vol->vol_flags), le16_to_cpu(flags)); |
360 | if (vol->vol_flags == flags) | 360 | if (vol->vol_flags == flags) |
361 | goto done; | 361 | goto done; |
362 | BUG_ON(!ni); | 362 | BUG_ON(!ni); |
363 | m = map_mft_record(ni); | 363 | m = map_mft_record(ni); |
364 | if (IS_ERR(m)) { | 364 | if (IS_ERR(m)) { |
365 | err = PTR_ERR(m); | 365 | err = PTR_ERR(m); |
366 | goto err_out; | 366 | goto err_out; |
367 | } | 367 | } |
368 | ctx = ntfs_attr_get_search_ctx(ni, m); | 368 | ctx = ntfs_attr_get_search_ctx(ni, m); |
369 | if (!ctx) { | 369 | if (!ctx) { |
370 | err = -ENOMEM; | 370 | err = -ENOMEM; |
371 | goto put_unm_err_out; | 371 | goto put_unm_err_out; |
372 | } | 372 | } |
373 | err = ntfs_attr_lookup(AT_VOLUME_INFORMATION, NULL, 0, 0, 0, NULL, 0, | 373 | err = ntfs_attr_lookup(AT_VOLUME_INFORMATION, NULL, 0, 0, 0, NULL, 0, |
374 | ctx); | 374 | ctx); |
375 | if (err) | 375 | if (err) |
376 | goto put_unm_err_out; | 376 | goto put_unm_err_out; |
377 | vi = (VOLUME_INFORMATION*)((u8*)ctx->attr + | 377 | vi = (VOLUME_INFORMATION*)((u8*)ctx->attr + |
378 | le16_to_cpu(ctx->attr->data.resident.value_offset)); | 378 | le16_to_cpu(ctx->attr->data.resident.value_offset)); |
379 | vol->vol_flags = vi->flags = flags; | 379 | vol->vol_flags = vi->flags = flags; |
380 | flush_dcache_mft_record_page(ctx->ntfs_ino); | 380 | flush_dcache_mft_record_page(ctx->ntfs_ino); |
381 | mark_mft_record_dirty(ctx->ntfs_ino); | 381 | mark_mft_record_dirty(ctx->ntfs_ino); |
382 | ntfs_attr_put_search_ctx(ctx); | 382 | ntfs_attr_put_search_ctx(ctx); |
383 | unmap_mft_record(ni); | 383 | unmap_mft_record(ni); |
384 | done: | 384 | done: |
385 | ntfs_debug("Done."); | 385 | ntfs_debug("Done."); |
386 | return 0; | 386 | return 0; |
387 | put_unm_err_out: | 387 | put_unm_err_out: |
388 | if (ctx) | 388 | if (ctx) |
389 | ntfs_attr_put_search_ctx(ctx); | 389 | ntfs_attr_put_search_ctx(ctx); |
390 | unmap_mft_record(ni); | 390 | unmap_mft_record(ni); |
391 | err_out: | 391 | err_out: |
392 | ntfs_error(vol->sb, "Failed with error code %i.", -err); | 392 | ntfs_error(vol->sb, "Failed with error code %i.", -err); |
393 | return err; | 393 | return err; |
394 | } | 394 | } |
395 | 395 | ||
396 | /** | 396 | /** |
397 | * ntfs_set_volume_flags - set bits in the volume information flags | 397 | * ntfs_set_volume_flags - set bits in the volume information flags |
398 | * @vol: ntfs volume on which to modify the flags | 398 | * @vol: ntfs volume on which to modify the flags |
399 | * @flags: flags to set on the volume | 399 | * @flags: flags to set on the volume |
400 | * | 400 | * |
401 | * Set the bits in @flags in the volume information flags on the volume @vol. | 401 | * Set the bits in @flags in the volume information flags on the volume @vol. |
402 | * | 402 | * |
403 | * Return 0 on success and -errno on error. | 403 | * Return 0 on success and -errno on error. |
404 | */ | 404 | */ |
405 | static inline int ntfs_set_volume_flags(ntfs_volume *vol, VOLUME_FLAGS flags) | 405 | static inline int ntfs_set_volume_flags(ntfs_volume *vol, VOLUME_FLAGS flags) |
406 | { | 406 | { |
407 | flags &= VOLUME_FLAGS_MASK; | 407 | flags &= VOLUME_FLAGS_MASK; |
408 | return ntfs_write_volume_flags(vol, vol->vol_flags | flags); | 408 | return ntfs_write_volume_flags(vol, vol->vol_flags | flags); |
409 | } | 409 | } |
410 | 410 | ||
411 | /** | 411 | /** |
412 | * ntfs_clear_volume_flags - clear bits in the volume information flags | 412 | * ntfs_clear_volume_flags - clear bits in the volume information flags |
413 | * @vol: ntfs volume on which to modify the flags | 413 | * @vol: ntfs volume on which to modify the flags |
414 | * @flags: flags to clear on the volume | 414 | * @flags: flags to clear on the volume |
415 | * | 415 | * |
416 | * Clear the bits in @flags in the volume information flags on the volume @vol. | 416 | * Clear the bits in @flags in the volume information flags on the volume @vol. |
417 | * | 417 | * |
418 | * Return 0 on success and -errno on error. | 418 | * Return 0 on success and -errno on error. |
419 | */ | 419 | */ |
420 | static inline int ntfs_clear_volume_flags(ntfs_volume *vol, VOLUME_FLAGS flags) | 420 | static inline int ntfs_clear_volume_flags(ntfs_volume *vol, VOLUME_FLAGS flags) |
421 | { | 421 | { |
422 | flags &= VOLUME_FLAGS_MASK; | 422 | flags &= VOLUME_FLAGS_MASK; |
423 | flags = vol->vol_flags & cpu_to_le16(~le16_to_cpu(flags)); | 423 | flags = vol->vol_flags & cpu_to_le16(~le16_to_cpu(flags)); |
424 | return ntfs_write_volume_flags(vol, flags); | 424 | return ntfs_write_volume_flags(vol, flags); |
425 | } | 425 | } |
426 | 426 | ||
427 | #endif /* NTFS_RW */ | 427 | #endif /* NTFS_RW */ |
428 | 428 | ||
429 | /** | 429 | /** |
430 | * ntfs_remount - change the mount options of a mounted ntfs filesystem | 430 | * ntfs_remount - change the mount options of a mounted ntfs filesystem |
431 | * @sb: superblock of mounted ntfs filesystem | 431 | * @sb: superblock of mounted ntfs filesystem |
432 | * @flags: remount flags | 432 | * @flags: remount flags |
433 | * @opt: remount options string | 433 | * @opt: remount options string |
434 | * | 434 | * |
435 | * Change the mount options of an already mounted ntfs filesystem. | 435 | * Change the mount options of an already mounted ntfs filesystem. |
436 | * | 436 | * |
437 | * NOTE: The VFS sets the @sb->s_flags remount flags to @flags after | 437 | * NOTE: The VFS sets the @sb->s_flags remount flags to @flags after |
438 | * ntfs_remount() returns successfully (i.e. returns 0). Otherwise, | 438 | * ntfs_remount() returns successfully (i.e. returns 0). Otherwise, |
439 | * @sb->s_flags are not changed. | 439 | * @sb->s_flags are not changed. |
440 | */ | 440 | */ |
441 | static int ntfs_remount(struct super_block *sb, int *flags, char *opt) | 441 | static int ntfs_remount(struct super_block *sb, int *flags, char *opt) |
442 | { | 442 | { |
443 | ntfs_volume *vol = NTFS_SB(sb); | 443 | ntfs_volume *vol = NTFS_SB(sb); |
444 | 444 | ||
445 | ntfs_debug("Entering with remount options string: %s", opt); | 445 | ntfs_debug("Entering with remount options string: %s", opt); |
446 | 446 | ||
447 | #ifndef NTFS_RW | 447 | #ifndef NTFS_RW |
448 | /* For read-only compiled driver, enforce read-only flag. */ | 448 | /* For read-only compiled driver, enforce read-only flag. */ |
449 | *flags |= MS_RDONLY; | 449 | *flags |= MS_RDONLY; |
450 | #else /* NTFS_RW */ | 450 | #else /* NTFS_RW */ |
451 | /* | 451 | /* |
452 | * For the read-write compiled driver, if we are remounting read-write, | 452 | * For the read-write compiled driver, if we are remounting read-write, |
453 | * make sure there are no volume errors and that no unsupported volume | 453 | * make sure there are no volume errors and that no unsupported volume |
454 | * flags are set. Also, empty the logfile journal as it would become | 454 | * flags are set. Also, empty the logfile journal as it would become |
455 | * stale as soon as something is written to the volume and mark the | 455 | * stale as soon as something is written to the volume and mark the |
456 | * volume dirty so that chkdsk is run if the volume is not umounted | 456 | * volume dirty so that chkdsk is run if the volume is not umounted |
457 | * cleanly. Finally, mark the quotas out of date so Windows rescans | 457 | * cleanly. Finally, mark the quotas out of date so Windows rescans |
458 | * the volume on boot and updates them. | 458 | * the volume on boot and updates them. |
459 | * | 459 | * |
460 | * When remounting read-only, mark the volume clean if no volume errors | 460 | * When remounting read-only, mark the volume clean if no volume errors |
461 | * have occurred. | 461 | * have occurred. |
462 | */ | 462 | */ |
463 | if ((sb->s_flags & MS_RDONLY) && !(*flags & MS_RDONLY)) { | 463 | if ((sb->s_flags & MS_RDONLY) && !(*flags & MS_RDONLY)) { |
464 | static const char *es = ". Cannot remount read-write."; | 464 | static const char *es = ". Cannot remount read-write."; |
465 | 465 | ||
466 | /* Remounting read-write. */ | 466 | /* Remounting read-write. */ |
467 | if (NVolErrors(vol)) { | 467 | if (NVolErrors(vol)) { |
468 | ntfs_error(sb, "Volume has errors and is read-only%s", | 468 | ntfs_error(sb, "Volume has errors and is read-only%s", |
469 | es); | 469 | es); |
470 | return -EROFS; | 470 | return -EROFS; |
471 | } | 471 | } |
472 | if (vol->vol_flags & VOLUME_IS_DIRTY) { | 472 | if (vol->vol_flags & VOLUME_IS_DIRTY) { |
473 | ntfs_error(sb, "Volume is dirty and read-only%s", es); | 473 | ntfs_error(sb, "Volume is dirty and read-only%s", es); |
474 | return -EROFS; | 474 | return -EROFS; |
475 | } | 475 | } |
476 | if (vol->vol_flags & VOLUME_MODIFIED_BY_CHKDSK) { | 476 | if (vol->vol_flags & VOLUME_MODIFIED_BY_CHKDSK) { |
477 | ntfs_error(sb, "Volume has been modified by chkdsk " | 477 | ntfs_error(sb, "Volume has been modified by chkdsk " |
478 | "and is read-only%s", es); | 478 | "and is read-only%s", es); |
479 | return -EROFS; | 479 | return -EROFS; |
480 | } | 480 | } |
481 | if (vol->vol_flags & VOLUME_MUST_MOUNT_RO_MASK) { | 481 | if (vol->vol_flags & VOLUME_MUST_MOUNT_RO_MASK) { |
482 | ntfs_error(sb, "Volume has unsupported flags set " | 482 | ntfs_error(sb, "Volume has unsupported flags set " |
483 | "(0x%x) and is read-only%s", | 483 | "(0x%x) and is read-only%s", |
484 | (unsigned)le16_to_cpu(vol->vol_flags), | 484 | (unsigned)le16_to_cpu(vol->vol_flags), |
485 | es); | 485 | es); |
486 | return -EROFS; | 486 | return -EROFS; |
487 | } | 487 | } |
488 | if (ntfs_set_volume_flags(vol, VOLUME_IS_DIRTY)) { | 488 | if (ntfs_set_volume_flags(vol, VOLUME_IS_DIRTY)) { |
489 | ntfs_error(sb, "Failed to set dirty bit in volume " | 489 | ntfs_error(sb, "Failed to set dirty bit in volume " |
490 | "information flags%s", es); | 490 | "information flags%s", es); |
491 | return -EROFS; | 491 | return -EROFS; |
492 | } | 492 | } |
493 | #if 0 | 493 | #if 0 |
494 | // TODO: Enable this code once we start modifying anything that | 494 | // TODO: Enable this code once we start modifying anything that |
495 | // is different between NTFS 1.2 and 3.x... | 495 | // is different between NTFS 1.2 and 3.x... |
496 | /* Set NT4 compatibility flag on newer NTFS version volumes. */ | 496 | /* Set NT4 compatibility flag on newer NTFS version volumes. */ |
497 | if ((vol->major_ver > 1)) { | 497 | if ((vol->major_ver > 1)) { |
498 | if (ntfs_set_volume_flags(vol, VOLUME_MOUNTED_ON_NT4)) { | 498 | if (ntfs_set_volume_flags(vol, VOLUME_MOUNTED_ON_NT4)) { |
499 | ntfs_error(sb, "Failed to set NT4 " | 499 | ntfs_error(sb, "Failed to set NT4 " |
500 | "compatibility flag%s", es); | 500 | "compatibility flag%s", es); |
501 | NVolSetErrors(vol); | 501 | NVolSetErrors(vol); |
502 | return -EROFS; | 502 | return -EROFS; |
503 | } | 503 | } |
504 | } | 504 | } |
505 | #endif | 505 | #endif |
506 | if (!ntfs_empty_logfile(vol->logfile_ino)) { | 506 | if (!ntfs_empty_logfile(vol->logfile_ino)) { |
507 | ntfs_error(sb, "Failed to empty journal $LogFile%s", | 507 | ntfs_error(sb, "Failed to empty journal $LogFile%s", |
508 | es); | 508 | es); |
509 | NVolSetErrors(vol); | 509 | NVolSetErrors(vol); |
510 | return -EROFS; | 510 | return -EROFS; |
511 | } | 511 | } |
512 | if (!ntfs_mark_quotas_out_of_date(vol)) { | 512 | if (!ntfs_mark_quotas_out_of_date(vol)) { |
513 | ntfs_error(sb, "Failed to mark quotas out of date%s", | 513 | ntfs_error(sb, "Failed to mark quotas out of date%s", |
514 | es); | 514 | es); |
515 | NVolSetErrors(vol); | 515 | NVolSetErrors(vol); |
516 | return -EROFS; | 516 | return -EROFS; |
517 | } | 517 | } |
518 | if (!ntfs_stamp_usnjrnl(vol)) { | 518 | if (!ntfs_stamp_usnjrnl(vol)) { |
519 | ntfs_error(sb, "Failed to stamp transation log " | 519 | ntfs_error(sb, "Failed to stamp transation log " |
520 | "($UsnJrnl)%s", es); | 520 | "($UsnJrnl)%s", es); |
521 | NVolSetErrors(vol); | 521 | NVolSetErrors(vol); |
522 | return -EROFS; | 522 | return -EROFS; |
523 | } | 523 | } |
524 | } else if (!(sb->s_flags & MS_RDONLY) && (*flags & MS_RDONLY)) { | 524 | } else if (!(sb->s_flags & MS_RDONLY) && (*flags & MS_RDONLY)) { |
525 | /* Remounting read-only. */ | 525 | /* Remounting read-only. */ |
526 | if (!NVolErrors(vol)) { | 526 | if (!NVolErrors(vol)) { |
527 | if (ntfs_clear_volume_flags(vol, VOLUME_IS_DIRTY)) | 527 | if (ntfs_clear_volume_flags(vol, VOLUME_IS_DIRTY)) |
528 | ntfs_warning(sb, "Failed to clear dirty bit " | 528 | ntfs_warning(sb, "Failed to clear dirty bit " |
529 | "in volume information " | 529 | "in volume information " |
530 | "flags. Run chkdsk."); | 530 | "flags. Run chkdsk."); |
531 | } | 531 | } |
532 | } | 532 | } |
533 | #endif /* NTFS_RW */ | 533 | #endif /* NTFS_RW */ |
534 | 534 | ||
535 | // TODO: Deal with *flags. | 535 | // TODO: Deal with *flags. |
536 | 536 | ||
537 | if (!parse_options(vol, opt)) | 537 | if (!parse_options(vol, opt)) |
538 | return -EINVAL; | 538 | return -EINVAL; |
539 | 539 | ||
540 | ntfs_debug("Done."); | 540 | ntfs_debug("Done."); |
541 | return 0; | 541 | return 0; |
542 | } | 542 | } |
543 | 543 | ||
544 | /** | 544 | /** |
545 | * is_boot_sector_ntfs - check whether a boot sector is a valid NTFS boot sector | 545 | * is_boot_sector_ntfs - check whether a boot sector is a valid NTFS boot sector |
546 | * @sb: Super block of the device to which @b belongs. | 546 | * @sb: Super block of the device to which @b belongs. |
547 | * @b: Boot sector of device @sb to check. | 547 | * @b: Boot sector of device @sb to check. |
548 | * @silent: If 'true', all output will be silenced. | 548 | * @silent: If 'true', all output will be silenced. |
549 | * | 549 | * |
550 | * is_boot_sector_ntfs() checks whether the boot sector @b is a valid NTFS boot | 550 | * is_boot_sector_ntfs() checks whether the boot sector @b is a valid NTFS boot |
551 | * sector. Returns 'true' if it is valid and 'false' if not. | 551 | * sector. Returns 'true' if it is valid and 'false' if not. |
552 | * | 552 | * |
553 | * @sb is only needed for warning/error output, i.e. it can be NULL when silent | 553 | * @sb is only needed for warning/error output, i.e. it can be NULL when silent |
554 | * is 'true'. | 554 | * is 'true'. |
555 | */ | 555 | */ |
556 | static bool is_boot_sector_ntfs(const struct super_block *sb, | 556 | static bool is_boot_sector_ntfs(const struct super_block *sb, |
557 | const NTFS_BOOT_SECTOR *b, const bool silent) | 557 | const NTFS_BOOT_SECTOR *b, const bool silent) |
558 | { | 558 | { |
559 | /* | 559 | /* |
560 | * Check that checksum == sum of u32 values from b to the checksum | 560 | * Check that checksum == sum of u32 values from b to the checksum |
561 | * field. If checksum is zero, no checking is done. We will work when | 561 | * field. If checksum is zero, no checking is done. We will work when |
562 | * the checksum test fails, since some utilities update the boot sector | 562 | * the checksum test fails, since some utilities update the boot sector |
563 | * ignoring the checksum which leaves the checksum out-of-date. We | 563 | * ignoring the checksum which leaves the checksum out-of-date. We |
564 | * report a warning if this is the case. | 564 | * report a warning if this is the case. |
565 | */ | 565 | */ |
566 | if ((void*)b < (void*)&b->checksum && b->checksum && !silent) { | 566 | if ((void*)b < (void*)&b->checksum && b->checksum && !silent) { |
567 | le32 *u; | 567 | le32 *u; |
568 | u32 i; | 568 | u32 i; |
569 | 569 | ||
570 | for (i = 0, u = (le32*)b; u < (le32*)(&b->checksum); ++u) | 570 | for (i = 0, u = (le32*)b; u < (le32*)(&b->checksum); ++u) |
571 | i += le32_to_cpup(u); | 571 | i += le32_to_cpup(u); |
572 | if (le32_to_cpu(b->checksum) != i) | 572 | if (le32_to_cpu(b->checksum) != i) |
573 | ntfs_warning(sb, "Invalid boot sector checksum."); | 573 | ntfs_warning(sb, "Invalid boot sector checksum."); |
574 | } | 574 | } |
575 | /* Check OEMidentifier is "NTFS " */ | 575 | /* Check OEMidentifier is "NTFS " */ |
576 | if (b->oem_id != magicNTFS) | 576 | if (b->oem_id != magicNTFS) |
577 | goto not_ntfs; | 577 | goto not_ntfs; |
578 | /* Check bytes per sector value is between 256 and 4096. */ | 578 | /* Check bytes per sector value is between 256 and 4096. */ |
579 | if (le16_to_cpu(b->bpb.bytes_per_sector) < 0x100 || | 579 | if (le16_to_cpu(b->bpb.bytes_per_sector) < 0x100 || |
580 | le16_to_cpu(b->bpb.bytes_per_sector) > 0x1000) | 580 | le16_to_cpu(b->bpb.bytes_per_sector) > 0x1000) |
581 | goto not_ntfs; | 581 | goto not_ntfs; |
582 | /* Check sectors per cluster value is valid. */ | 582 | /* Check sectors per cluster value is valid. */ |
583 | switch (b->bpb.sectors_per_cluster) { | 583 | switch (b->bpb.sectors_per_cluster) { |
584 | case 1: case 2: case 4: case 8: case 16: case 32: case 64: case 128: | 584 | case 1: case 2: case 4: case 8: case 16: case 32: case 64: case 128: |
585 | break; | 585 | break; |
586 | default: | 586 | default: |
587 | goto not_ntfs; | 587 | goto not_ntfs; |
588 | } | 588 | } |
589 | /* Check the cluster size is not above the maximum (64kiB). */ | 589 | /* Check the cluster size is not above the maximum (64kiB). */ |
590 | if ((u32)le16_to_cpu(b->bpb.bytes_per_sector) * | 590 | if ((u32)le16_to_cpu(b->bpb.bytes_per_sector) * |
591 | b->bpb.sectors_per_cluster > NTFS_MAX_CLUSTER_SIZE) | 591 | b->bpb.sectors_per_cluster > NTFS_MAX_CLUSTER_SIZE) |
592 | goto not_ntfs; | 592 | goto not_ntfs; |
593 | /* Check reserved/unused fields are really zero. */ | 593 | /* Check reserved/unused fields are really zero. */ |
594 | if (le16_to_cpu(b->bpb.reserved_sectors) || | 594 | if (le16_to_cpu(b->bpb.reserved_sectors) || |
595 | le16_to_cpu(b->bpb.root_entries) || | 595 | le16_to_cpu(b->bpb.root_entries) || |
596 | le16_to_cpu(b->bpb.sectors) || | 596 | le16_to_cpu(b->bpb.sectors) || |
597 | le16_to_cpu(b->bpb.sectors_per_fat) || | 597 | le16_to_cpu(b->bpb.sectors_per_fat) || |
598 | le32_to_cpu(b->bpb.large_sectors) || b->bpb.fats) | 598 | le32_to_cpu(b->bpb.large_sectors) || b->bpb.fats) |
599 | goto not_ntfs; | 599 | goto not_ntfs; |
600 | /* Check clusters per file mft record value is valid. */ | 600 | /* Check clusters per file mft record value is valid. */ |
601 | if ((u8)b->clusters_per_mft_record < 0xe1 || | 601 | if ((u8)b->clusters_per_mft_record < 0xe1 || |
602 | (u8)b->clusters_per_mft_record > 0xf7) | 602 | (u8)b->clusters_per_mft_record > 0xf7) |
603 | switch (b->clusters_per_mft_record) { | 603 | switch (b->clusters_per_mft_record) { |
604 | case 1: case 2: case 4: case 8: case 16: case 32: case 64: | 604 | case 1: case 2: case 4: case 8: case 16: case 32: case 64: |
605 | break; | 605 | break; |
606 | default: | 606 | default: |
607 | goto not_ntfs; | 607 | goto not_ntfs; |
608 | } | 608 | } |
609 | /* Check clusters per index block value is valid. */ | 609 | /* Check clusters per index block value is valid. */ |
610 | if ((u8)b->clusters_per_index_record < 0xe1 || | 610 | if ((u8)b->clusters_per_index_record < 0xe1 || |
611 | (u8)b->clusters_per_index_record > 0xf7) | 611 | (u8)b->clusters_per_index_record > 0xf7) |
612 | switch (b->clusters_per_index_record) { | 612 | switch (b->clusters_per_index_record) { |
613 | case 1: case 2: case 4: case 8: case 16: case 32: case 64: | 613 | case 1: case 2: case 4: case 8: case 16: case 32: case 64: |
614 | break; | 614 | break; |
615 | default: | 615 | default: |
616 | goto not_ntfs; | 616 | goto not_ntfs; |
617 | } | 617 | } |
618 | /* | 618 | /* |
619 | * Check for valid end of sector marker. We will work without it, but | 619 | * Check for valid end of sector marker. We will work without it, but |
620 | * many BIOSes will refuse to boot from a bootsector if the magic is | 620 | * many BIOSes will refuse to boot from a bootsector if the magic is |
621 | * incorrect, so we emit a warning. | 621 | * incorrect, so we emit a warning. |
622 | */ | 622 | */ |
623 | if (!silent && b->end_of_sector_marker != cpu_to_le16(0xaa55)) | 623 | if (!silent && b->end_of_sector_marker != cpu_to_le16(0xaa55)) |
624 | ntfs_warning(sb, "Invalid end of sector marker."); | 624 | ntfs_warning(sb, "Invalid end of sector marker."); |
625 | return true; | 625 | return true; |
626 | not_ntfs: | 626 | not_ntfs: |
627 | return false; | 627 | return false; |
628 | } | 628 | } |
629 | 629 | ||
630 | /** | 630 | /** |
631 | * read_ntfs_boot_sector - read the NTFS boot sector of a device | 631 | * read_ntfs_boot_sector - read the NTFS boot sector of a device |
632 | * @sb: super block of device to read the boot sector from | 632 | * @sb: super block of device to read the boot sector from |
633 | * @silent: if true, suppress all output | 633 | * @silent: if true, suppress all output |
634 | * | 634 | * |
635 | * Reads the boot sector from the device and validates it. If that fails, tries | 635 | * Reads the boot sector from the device and validates it. If that fails, tries |
636 | * to read the backup boot sector, first from the end of the device a-la NT4 and | 636 | * to read the backup boot sector, first from the end of the device a-la NT4 and |
637 | * later and then from the middle of the device a-la NT3.51 and before. | 637 | * later and then from the middle of the device a-la NT3.51 and before. |
638 | * | 638 | * |
639 | * If a valid boot sector is found but it is not the primary boot sector, we | 639 | * If a valid boot sector is found but it is not the primary boot sector, we |
640 | * repair the primary boot sector silently (unless the device is read-only or | 640 | * repair the primary boot sector silently (unless the device is read-only or |
641 | * the primary boot sector is not accessible). | 641 | * the primary boot sector is not accessible). |
642 | * | 642 | * |
643 | * NOTE: To call this function, @sb must have the fields s_dev, the ntfs super | 643 | * NOTE: To call this function, @sb must have the fields s_dev, the ntfs super |
644 | * block (u.ntfs_sb), nr_blocks and the device flags (s_flags) initialized | 644 | * block (u.ntfs_sb), nr_blocks and the device flags (s_flags) initialized |
645 | * to their respective values. | 645 | * to their respective values. |
646 | * | 646 | * |
647 | * Return the unlocked buffer head containing the boot sector or NULL on error. | 647 | * Return the unlocked buffer head containing the boot sector or NULL on error. |
648 | */ | 648 | */ |
649 | static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb, | 649 | static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb, |
650 | const int silent) | 650 | const int silent) |
651 | { | 651 | { |
652 | const char *read_err_str = "Unable to read %s boot sector."; | 652 | const char *read_err_str = "Unable to read %s boot sector."; |
653 | struct buffer_head *bh_primary, *bh_backup; | 653 | struct buffer_head *bh_primary, *bh_backup; |
654 | sector_t nr_blocks = NTFS_SB(sb)->nr_blocks; | 654 | sector_t nr_blocks = NTFS_SB(sb)->nr_blocks; |
655 | 655 | ||
656 | /* Try to read primary boot sector. */ | 656 | /* Try to read primary boot sector. */ |
657 | if ((bh_primary = sb_bread(sb, 0))) { | 657 | if ((bh_primary = sb_bread(sb, 0))) { |
658 | if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*) | 658 | if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*) |
659 | bh_primary->b_data, silent)) | 659 | bh_primary->b_data, silent)) |
660 | return bh_primary; | 660 | return bh_primary; |
661 | if (!silent) | 661 | if (!silent) |
662 | ntfs_error(sb, "Primary boot sector is invalid."); | 662 | ntfs_error(sb, "Primary boot sector is invalid."); |
663 | } else if (!silent) | 663 | } else if (!silent) |
664 | ntfs_error(sb, read_err_str, "primary"); | 664 | ntfs_error(sb, read_err_str, "primary"); |
665 | if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) { | 665 | if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) { |
666 | if (bh_primary) | 666 | if (bh_primary) |
667 | brelse(bh_primary); | 667 | brelse(bh_primary); |
668 | if (!silent) | 668 | if (!silent) |
669 | ntfs_error(sb, "Mount option errors=recover not used. " | 669 | ntfs_error(sb, "Mount option errors=recover not used. " |
670 | "Aborting without trying to recover."); | 670 | "Aborting without trying to recover."); |
671 | return NULL; | 671 | return NULL; |
672 | } | 672 | } |
673 | /* Try to read NT4+ backup boot sector. */ | 673 | /* Try to read NT4+ backup boot sector. */ |
674 | if ((bh_backup = sb_bread(sb, nr_blocks - 1))) { | 674 | if ((bh_backup = sb_bread(sb, nr_blocks - 1))) { |
675 | if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*) | 675 | if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*) |
676 | bh_backup->b_data, silent)) | 676 | bh_backup->b_data, silent)) |
677 | goto hotfix_primary_boot_sector; | 677 | goto hotfix_primary_boot_sector; |
678 | brelse(bh_backup); | 678 | brelse(bh_backup); |
679 | } else if (!silent) | 679 | } else if (!silent) |
680 | ntfs_error(sb, read_err_str, "backup"); | 680 | ntfs_error(sb, read_err_str, "backup"); |
681 | /* Try to read NT3.51- backup boot sector. */ | 681 | /* Try to read NT3.51- backup boot sector. */ |
682 | if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) { | 682 | if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) { |
683 | if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*) | 683 | if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*) |
684 | bh_backup->b_data, silent)) | 684 | bh_backup->b_data, silent)) |
685 | goto hotfix_primary_boot_sector; | 685 | goto hotfix_primary_boot_sector; |
686 | if (!silent) | 686 | if (!silent) |
687 | ntfs_error(sb, "Could not find a valid backup boot " | 687 | ntfs_error(sb, "Could not find a valid backup boot " |
688 | "sector."); | 688 | "sector."); |
689 | brelse(bh_backup); | 689 | brelse(bh_backup); |
690 | } else if (!silent) | 690 | } else if (!silent) |
691 | ntfs_error(sb, read_err_str, "backup"); | 691 | ntfs_error(sb, read_err_str, "backup"); |
692 | /* We failed. Cleanup and return. */ | 692 | /* We failed. Cleanup and return. */ |
693 | if (bh_primary) | 693 | if (bh_primary) |
694 | brelse(bh_primary); | 694 | brelse(bh_primary); |
695 | return NULL; | 695 | return NULL; |
696 | hotfix_primary_boot_sector: | 696 | hotfix_primary_boot_sector: |
697 | if (bh_primary) { | 697 | if (bh_primary) { |
698 | /* | 698 | /* |
699 | * If we managed to read sector zero and the volume is not | 699 | * If we managed to read sector zero and the volume is not |
700 | * read-only, copy the found, valid backup boot sector to the | 700 | * read-only, copy the found, valid backup boot sector to the |
701 | * primary boot sector. Note we only copy the actual boot | 701 | * primary boot sector. Note we only copy the actual boot |
702 | * sector structure, not the actual whole device sector as that | 702 | * sector structure, not the actual whole device sector as that |
703 | * may be bigger and would potentially damage the $Boot system | 703 | * may be bigger and would potentially damage the $Boot system |
704 | * file (FIXME: Would be nice to know if the backup boot sector | 704 | * file (FIXME: Would be nice to know if the backup boot sector |
705 | * on a large sector device contains the whole boot loader or | 705 | * on a large sector device contains the whole boot loader or |
706 | * just the first 512 bytes). | 706 | * just the first 512 bytes). |
707 | */ | 707 | */ |
708 | if (!(sb->s_flags & MS_RDONLY)) { | 708 | if (!(sb->s_flags & MS_RDONLY)) { |
709 | ntfs_warning(sb, "Hot-fix: Recovering invalid primary " | 709 | ntfs_warning(sb, "Hot-fix: Recovering invalid primary " |
710 | "boot sector from backup copy."); | 710 | "boot sector from backup copy."); |
711 | memcpy(bh_primary->b_data, bh_backup->b_data, | 711 | memcpy(bh_primary->b_data, bh_backup->b_data, |
712 | NTFS_BLOCK_SIZE); | 712 | NTFS_BLOCK_SIZE); |
713 | mark_buffer_dirty(bh_primary); | 713 | mark_buffer_dirty(bh_primary); |
714 | sync_dirty_buffer(bh_primary); | 714 | sync_dirty_buffer(bh_primary); |
715 | if (buffer_uptodate(bh_primary)) { | 715 | if (buffer_uptodate(bh_primary)) { |
716 | brelse(bh_backup); | 716 | brelse(bh_backup); |
717 | return bh_primary; | 717 | return bh_primary; |
718 | } | 718 | } |
719 | ntfs_error(sb, "Hot-fix: Device write error while " | 719 | ntfs_error(sb, "Hot-fix: Device write error while " |
720 | "recovering primary boot sector."); | 720 | "recovering primary boot sector."); |
721 | } else { | 721 | } else { |
722 | ntfs_warning(sb, "Hot-fix: Recovery of primary boot " | 722 | ntfs_warning(sb, "Hot-fix: Recovery of primary boot " |
723 | "sector failed: Read-only mount."); | 723 | "sector failed: Read-only mount."); |
724 | } | 724 | } |
725 | brelse(bh_primary); | 725 | brelse(bh_primary); |
726 | } | 726 | } |
727 | ntfs_warning(sb, "Using backup boot sector."); | 727 | ntfs_warning(sb, "Using backup boot sector."); |
728 | return bh_backup; | 728 | return bh_backup; |
729 | } | 729 | } |
730 | 730 | ||
731 | /** | 731 | /** |
732 | * parse_ntfs_boot_sector - parse the boot sector and store the data in @vol | 732 | * parse_ntfs_boot_sector - parse the boot sector and store the data in @vol |
733 | * @vol: volume structure to initialise with data from boot sector | 733 | * @vol: volume structure to initialise with data from boot sector |
734 | * @b: boot sector to parse | 734 | * @b: boot sector to parse |
735 | * | 735 | * |
736 | * Parse the ntfs boot sector @b and store all imporant information therein in | 736 | * Parse the ntfs boot sector @b and store all imporant information therein in |
737 | * the ntfs super block @vol. Return 'true' on success and 'false' on error. | 737 | * the ntfs super block @vol. Return 'true' on success and 'false' on error. |
738 | */ | 738 | */ |
739 | static bool parse_ntfs_boot_sector(ntfs_volume *vol, const NTFS_BOOT_SECTOR *b) | 739 | static bool parse_ntfs_boot_sector(ntfs_volume *vol, const NTFS_BOOT_SECTOR *b) |
740 | { | 740 | { |
741 | unsigned int sectors_per_cluster_bits, nr_hidden_sects; | 741 | unsigned int sectors_per_cluster_bits, nr_hidden_sects; |
742 | int clusters_per_mft_record, clusters_per_index_record; | 742 | int clusters_per_mft_record, clusters_per_index_record; |
743 | s64 ll; | 743 | s64 ll; |
744 | 744 | ||
745 | vol->sector_size = le16_to_cpu(b->bpb.bytes_per_sector); | 745 | vol->sector_size = le16_to_cpu(b->bpb.bytes_per_sector); |
746 | vol->sector_size_bits = ffs(vol->sector_size) - 1; | 746 | vol->sector_size_bits = ffs(vol->sector_size) - 1; |
747 | ntfs_debug("vol->sector_size = %i (0x%x)", vol->sector_size, | 747 | ntfs_debug("vol->sector_size = %i (0x%x)", vol->sector_size, |
748 | vol->sector_size); | 748 | vol->sector_size); |
749 | ntfs_debug("vol->sector_size_bits = %i (0x%x)", vol->sector_size_bits, | 749 | ntfs_debug("vol->sector_size_bits = %i (0x%x)", vol->sector_size_bits, |
750 | vol->sector_size_bits); | 750 | vol->sector_size_bits); |
751 | if (vol->sector_size < vol->sb->s_blocksize) { | 751 | if (vol->sector_size < vol->sb->s_blocksize) { |
752 | ntfs_error(vol->sb, "Sector size (%i) is smaller than the " | 752 | ntfs_error(vol->sb, "Sector size (%i) is smaller than the " |
753 | "device block size (%lu). This is not " | 753 | "device block size (%lu). This is not " |
754 | "supported. Sorry.", vol->sector_size, | 754 | "supported. Sorry.", vol->sector_size, |
755 | vol->sb->s_blocksize); | 755 | vol->sb->s_blocksize); |
756 | return false; | 756 | return false; |
757 | } | 757 | } |
758 | ntfs_debug("sectors_per_cluster = 0x%x", b->bpb.sectors_per_cluster); | 758 | ntfs_debug("sectors_per_cluster = 0x%x", b->bpb.sectors_per_cluster); |
759 | sectors_per_cluster_bits = ffs(b->bpb.sectors_per_cluster) - 1; | 759 | sectors_per_cluster_bits = ffs(b->bpb.sectors_per_cluster) - 1; |
760 | ntfs_debug("sectors_per_cluster_bits = 0x%x", | 760 | ntfs_debug("sectors_per_cluster_bits = 0x%x", |
761 | sectors_per_cluster_bits); | 761 | sectors_per_cluster_bits); |
762 | nr_hidden_sects = le32_to_cpu(b->bpb.hidden_sectors); | 762 | nr_hidden_sects = le32_to_cpu(b->bpb.hidden_sectors); |
763 | ntfs_debug("number of hidden sectors = 0x%x", nr_hidden_sects); | 763 | ntfs_debug("number of hidden sectors = 0x%x", nr_hidden_sects); |
764 | vol->cluster_size = vol->sector_size << sectors_per_cluster_bits; | 764 | vol->cluster_size = vol->sector_size << sectors_per_cluster_bits; |
765 | vol->cluster_size_mask = vol->cluster_size - 1; | 765 | vol->cluster_size_mask = vol->cluster_size - 1; |
766 | vol->cluster_size_bits = ffs(vol->cluster_size) - 1; | 766 | vol->cluster_size_bits = ffs(vol->cluster_size) - 1; |
767 | ntfs_debug("vol->cluster_size = %i (0x%x)", vol->cluster_size, | 767 | ntfs_debug("vol->cluster_size = %i (0x%x)", vol->cluster_size, |
768 | vol->cluster_size); | 768 | vol->cluster_size); |
769 | ntfs_debug("vol->cluster_size_mask = 0x%x", vol->cluster_size_mask); | 769 | ntfs_debug("vol->cluster_size_mask = 0x%x", vol->cluster_size_mask); |
770 | ntfs_debug("vol->cluster_size_bits = %i", vol->cluster_size_bits); | 770 | ntfs_debug("vol->cluster_size_bits = %i", vol->cluster_size_bits); |
771 | if (vol->cluster_size < vol->sector_size) { | 771 | if (vol->cluster_size < vol->sector_size) { |
772 | ntfs_error(vol->sb, "Cluster size (%i) is smaller than the " | 772 | ntfs_error(vol->sb, "Cluster size (%i) is smaller than the " |
773 | "sector size (%i). This is not supported. " | 773 | "sector size (%i). This is not supported. " |
774 | "Sorry.", vol->cluster_size, vol->sector_size); | 774 | "Sorry.", vol->cluster_size, vol->sector_size); |
775 | return false; | 775 | return false; |
776 | } | 776 | } |
777 | clusters_per_mft_record = b->clusters_per_mft_record; | 777 | clusters_per_mft_record = b->clusters_per_mft_record; |
778 | ntfs_debug("clusters_per_mft_record = %i (0x%x)", | 778 | ntfs_debug("clusters_per_mft_record = %i (0x%x)", |
779 | clusters_per_mft_record, clusters_per_mft_record); | 779 | clusters_per_mft_record, clusters_per_mft_record); |
780 | if (clusters_per_mft_record > 0) | 780 | if (clusters_per_mft_record > 0) |
781 | vol->mft_record_size = vol->cluster_size << | 781 | vol->mft_record_size = vol->cluster_size << |
782 | (ffs(clusters_per_mft_record) - 1); | 782 | (ffs(clusters_per_mft_record) - 1); |
783 | else | 783 | else |
784 | /* | 784 | /* |
785 | * When mft_record_size < cluster_size, clusters_per_mft_record | 785 | * When mft_record_size < cluster_size, clusters_per_mft_record |
786 | * = -log2(mft_record_size) bytes. mft_record_size normaly is | 786 | * = -log2(mft_record_size) bytes. mft_record_size normaly is |
787 | * 1024 bytes, which is encoded as 0xF6 (-10 in decimal). | 787 | * 1024 bytes, which is encoded as 0xF6 (-10 in decimal). |
788 | */ | 788 | */ |
789 | vol->mft_record_size = 1 << -clusters_per_mft_record; | 789 | vol->mft_record_size = 1 << -clusters_per_mft_record; |
790 | vol->mft_record_size_mask = vol->mft_record_size - 1; | 790 | vol->mft_record_size_mask = vol->mft_record_size - 1; |
791 | vol->mft_record_size_bits = ffs(vol->mft_record_size) - 1; | 791 | vol->mft_record_size_bits = ffs(vol->mft_record_size) - 1; |
792 | ntfs_debug("vol->mft_record_size = %i (0x%x)", vol->mft_record_size, | 792 | ntfs_debug("vol->mft_record_size = %i (0x%x)", vol->mft_record_size, |
793 | vol->mft_record_size); | 793 | vol->mft_record_size); |
794 | ntfs_debug("vol->mft_record_size_mask = 0x%x", | 794 | ntfs_debug("vol->mft_record_size_mask = 0x%x", |
795 | vol->mft_record_size_mask); | 795 | vol->mft_record_size_mask); |
796 | ntfs_debug("vol->mft_record_size_bits = %i (0x%x)", | 796 | ntfs_debug("vol->mft_record_size_bits = %i (0x%x)", |
797 | vol->mft_record_size_bits, vol->mft_record_size_bits); | 797 | vol->mft_record_size_bits, vol->mft_record_size_bits); |
798 | /* | 798 | /* |
799 | * We cannot support mft record sizes above the PAGE_CACHE_SIZE since | 799 | * We cannot support mft record sizes above the PAGE_CACHE_SIZE since |
800 | * we store $MFT/$DATA, the table of mft records in the page cache. | 800 | * we store $MFT/$DATA, the table of mft records in the page cache. |
801 | */ | 801 | */ |
802 | if (vol->mft_record_size > PAGE_CACHE_SIZE) { | 802 | if (vol->mft_record_size > PAGE_CACHE_SIZE) { |
803 | ntfs_error(vol->sb, "Mft record size (%i) exceeds the " | 803 | ntfs_error(vol->sb, "Mft record size (%i) exceeds the " |
804 | "PAGE_CACHE_SIZE on your system (%lu). " | 804 | "PAGE_CACHE_SIZE on your system (%lu). " |
805 | "This is not supported. Sorry.", | 805 | "This is not supported. Sorry.", |
806 | vol->mft_record_size, PAGE_CACHE_SIZE); | 806 | vol->mft_record_size, PAGE_CACHE_SIZE); |
807 | return false; | 807 | return false; |
808 | } | 808 | } |
809 | /* We cannot support mft record sizes below the sector size. */ | 809 | /* We cannot support mft record sizes below the sector size. */ |
810 | if (vol->mft_record_size < vol->sector_size) { | 810 | if (vol->mft_record_size < vol->sector_size) { |
811 | ntfs_error(vol->sb, "Mft record size (%i) is smaller than the " | 811 | ntfs_error(vol->sb, "Mft record size (%i) is smaller than the " |
812 | "sector size (%i). This is not supported. " | 812 | "sector size (%i). This is not supported. " |
813 | "Sorry.", vol->mft_record_size, | 813 | "Sorry.", vol->mft_record_size, |
814 | vol->sector_size); | 814 | vol->sector_size); |
815 | return false; | 815 | return false; |
816 | } | 816 | } |
817 | clusters_per_index_record = b->clusters_per_index_record; | 817 | clusters_per_index_record = b->clusters_per_index_record; |
818 | ntfs_debug("clusters_per_index_record = %i (0x%x)", | 818 | ntfs_debug("clusters_per_index_record = %i (0x%x)", |
819 | clusters_per_index_record, clusters_per_index_record); | 819 | clusters_per_index_record, clusters_per_index_record); |
820 | if (clusters_per_index_record > 0) | 820 | if (clusters_per_index_record > 0) |
821 | vol->index_record_size = vol->cluster_size << | 821 | vol->index_record_size = vol->cluster_size << |
822 | (ffs(clusters_per_index_record) - 1); | 822 | (ffs(clusters_per_index_record) - 1); |
823 | else | 823 | else |
824 | /* | 824 | /* |
825 | * When index_record_size < cluster_size, | 825 | * When index_record_size < cluster_size, |
826 | * clusters_per_index_record = -log2(index_record_size) bytes. | 826 | * clusters_per_index_record = -log2(index_record_size) bytes. |
827 | * index_record_size normaly equals 4096 bytes, which is | 827 | * index_record_size normaly equals 4096 bytes, which is |
828 | * encoded as 0xF4 (-12 in decimal). | 828 | * encoded as 0xF4 (-12 in decimal). |
829 | */ | 829 | */ |
830 | vol->index_record_size = 1 << -clusters_per_index_record; | 830 | vol->index_record_size = 1 << -clusters_per_index_record; |
831 | vol->index_record_size_mask = vol->index_record_size - 1; | 831 | vol->index_record_size_mask = vol->index_record_size - 1; |
832 | vol->index_record_size_bits = ffs(vol->index_record_size) - 1; | 832 | vol->index_record_size_bits = ffs(vol->index_record_size) - 1; |
833 | ntfs_debug("vol->index_record_size = %i (0x%x)", | 833 | ntfs_debug("vol->index_record_size = %i (0x%x)", |
834 | vol->index_record_size, vol->index_record_size); | 834 | vol->index_record_size, vol->index_record_size); |
835 | ntfs_debug("vol->index_record_size_mask = 0x%x", | 835 | ntfs_debug("vol->index_record_size_mask = 0x%x", |
836 | vol->index_record_size_mask); | 836 | vol->index_record_size_mask); |
837 | ntfs_debug("vol->index_record_size_bits = %i (0x%x)", | 837 | ntfs_debug("vol->index_record_size_bits = %i (0x%x)", |
838 | vol->index_record_size_bits, | 838 | vol->index_record_size_bits, |
839 | vol->index_record_size_bits); | 839 | vol->index_record_size_bits); |
840 | /* We cannot support index record sizes below the sector size. */ | 840 | /* We cannot support index record sizes below the sector size. */ |
841 | if (vol->index_record_size < vol->sector_size) { | 841 | if (vol->index_record_size < vol->sector_size) { |
842 | ntfs_error(vol->sb, "Index record size (%i) is smaller than " | 842 | ntfs_error(vol->sb, "Index record size (%i) is smaller than " |
843 | "the sector size (%i). This is not " | 843 | "the sector size (%i). This is not " |
844 | "supported. Sorry.", vol->index_record_size, | 844 | "supported. Sorry.", vol->index_record_size, |
845 | vol->sector_size); | 845 | vol->sector_size); |
846 | return false; | 846 | return false; |
847 | } | 847 | } |
848 | /* | 848 | /* |
849 | * Get the size of the volume in clusters and check for 64-bit-ness. | 849 | * Get the size of the volume in clusters and check for 64-bit-ness. |
850 | * Windows currently only uses 32 bits to save the clusters so we do | 850 | * Windows currently only uses 32 bits to save the clusters so we do |
851 | * the same as it is much faster on 32-bit CPUs. | 851 | * the same as it is much faster on 32-bit CPUs. |
852 | */ | 852 | */ |
853 | ll = sle64_to_cpu(b->number_of_sectors) >> sectors_per_cluster_bits; | 853 | ll = sle64_to_cpu(b->number_of_sectors) >> sectors_per_cluster_bits; |
854 | if ((u64)ll >= 1ULL << 32) { | 854 | if ((u64)ll >= 1ULL << 32) { |
855 | ntfs_error(vol->sb, "Cannot handle 64-bit clusters. Sorry."); | 855 | ntfs_error(vol->sb, "Cannot handle 64-bit clusters. Sorry."); |
856 | return false; | 856 | return false; |
857 | } | 857 | } |
858 | vol->nr_clusters = ll; | 858 | vol->nr_clusters = ll; |
859 | ntfs_debug("vol->nr_clusters = 0x%llx", (long long)vol->nr_clusters); | 859 | ntfs_debug("vol->nr_clusters = 0x%llx", (long long)vol->nr_clusters); |
860 | /* | 860 | /* |
861 | * On an architecture where unsigned long is 32-bits, we restrict the | 861 | * On an architecture where unsigned long is 32-bits, we restrict the |
862 | * volume size to 2TiB (2^41). On a 64-bit architecture, the compiler | 862 | * volume size to 2TiB (2^41). On a 64-bit architecture, the compiler |
863 | * will hopefully optimize the whole check away. | 863 | * will hopefully optimize the whole check away. |
864 | */ | 864 | */ |
865 | if (sizeof(unsigned long) < 8) { | 865 | if (sizeof(unsigned long) < 8) { |
866 | if ((ll << vol->cluster_size_bits) >= (1ULL << 41)) { | 866 | if ((ll << vol->cluster_size_bits) >= (1ULL << 41)) { |
867 | ntfs_error(vol->sb, "Volume size (%lluTiB) is too " | 867 | ntfs_error(vol->sb, "Volume size (%lluTiB) is too " |
868 | "large for this architecture. " | 868 | "large for this architecture. " |
869 | "Maximum supported is 2TiB. Sorry.", | 869 | "Maximum supported is 2TiB. Sorry.", |
870 | (unsigned long long)ll >> (40 - | 870 | (unsigned long long)ll >> (40 - |
871 | vol->cluster_size_bits)); | 871 | vol->cluster_size_bits)); |
872 | return false; | 872 | return false; |
873 | } | 873 | } |
874 | } | 874 | } |
875 | ll = sle64_to_cpu(b->mft_lcn); | 875 | ll = sle64_to_cpu(b->mft_lcn); |
876 | if (ll >= vol->nr_clusters) { | 876 | if (ll >= vol->nr_clusters) { |
877 | ntfs_error(vol->sb, "MFT LCN (%lli, 0x%llx) is beyond end of " | 877 | ntfs_error(vol->sb, "MFT LCN (%lli, 0x%llx) is beyond end of " |
878 | "volume. Weird.", (unsigned long long)ll, | 878 | "volume. Weird.", (unsigned long long)ll, |
879 | (unsigned long long)ll); | 879 | (unsigned long long)ll); |
880 | return false; | 880 | return false; |
881 | } | 881 | } |
882 | vol->mft_lcn = ll; | 882 | vol->mft_lcn = ll; |
883 | ntfs_debug("vol->mft_lcn = 0x%llx", (long long)vol->mft_lcn); | 883 | ntfs_debug("vol->mft_lcn = 0x%llx", (long long)vol->mft_lcn); |
884 | ll = sle64_to_cpu(b->mftmirr_lcn); | 884 | ll = sle64_to_cpu(b->mftmirr_lcn); |
885 | if (ll >= vol->nr_clusters) { | 885 | if (ll >= vol->nr_clusters) { |
886 | ntfs_error(vol->sb, "MFTMirr LCN (%lli, 0x%llx) is beyond end " | 886 | ntfs_error(vol->sb, "MFTMirr LCN (%lli, 0x%llx) is beyond end " |
887 | "of volume. Weird.", (unsigned long long)ll, | 887 | "of volume. Weird.", (unsigned long long)ll, |
888 | (unsigned long long)ll); | 888 | (unsigned long long)ll); |
889 | return false; | 889 | return false; |
890 | } | 890 | } |
891 | vol->mftmirr_lcn = ll; | 891 | vol->mftmirr_lcn = ll; |
892 | ntfs_debug("vol->mftmirr_lcn = 0x%llx", (long long)vol->mftmirr_lcn); | 892 | ntfs_debug("vol->mftmirr_lcn = 0x%llx", (long long)vol->mftmirr_lcn); |
893 | #ifdef NTFS_RW | 893 | #ifdef NTFS_RW |
894 | /* | 894 | /* |
895 | * Work out the size of the mft mirror in number of mft records. If the | 895 | * Work out the size of the mft mirror in number of mft records. If the |
896 | * cluster size is less than or equal to the size taken by four mft | 896 | * cluster size is less than or equal to the size taken by four mft |
897 | * records, the mft mirror stores the first four mft records. If the | 897 | * records, the mft mirror stores the first four mft records. If the |
898 | * cluster size is bigger than the size taken by four mft records, the | 898 | * cluster size is bigger than the size taken by four mft records, the |
899 | * mft mirror contains as many mft records as will fit into one | 899 | * mft mirror contains as many mft records as will fit into one |
900 | * cluster. | 900 | * cluster. |
901 | */ | 901 | */ |
902 | if (vol->cluster_size <= (4 << vol->mft_record_size_bits)) | 902 | if (vol->cluster_size <= (4 << vol->mft_record_size_bits)) |
903 | vol->mftmirr_size = 4; | 903 | vol->mftmirr_size = 4; |
904 | else | 904 | else |
905 | vol->mftmirr_size = vol->cluster_size >> | 905 | vol->mftmirr_size = vol->cluster_size >> |
906 | vol->mft_record_size_bits; | 906 | vol->mft_record_size_bits; |
907 | ntfs_debug("vol->mftmirr_size = %i", vol->mftmirr_size); | 907 | ntfs_debug("vol->mftmirr_size = %i", vol->mftmirr_size); |
908 | #endif /* NTFS_RW */ | 908 | #endif /* NTFS_RW */ |
909 | vol->serial_no = le64_to_cpu(b->volume_serial_number); | 909 | vol->serial_no = le64_to_cpu(b->volume_serial_number); |
910 | ntfs_debug("vol->serial_no = 0x%llx", | 910 | ntfs_debug("vol->serial_no = 0x%llx", |
911 | (unsigned long long)vol->serial_no); | 911 | (unsigned long long)vol->serial_no); |
912 | return true; | 912 | return true; |
913 | } | 913 | } |
914 | 914 | ||
915 | /** | 915 | /** |
916 | * ntfs_setup_allocators - initialize the cluster and mft allocators | 916 | * ntfs_setup_allocators - initialize the cluster and mft allocators |
917 | * @vol: volume structure for which to setup the allocators | 917 | * @vol: volume structure for which to setup the allocators |
918 | * | 918 | * |
919 | * Setup the cluster (lcn) and mft allocators to the starting values. | 919 | * Setup the cluster (lcn) and mft allocators to the starting values. |
920 | */ | 920 | */ |
921 | static void ntfs_setup_allocators(ntfs_volume *vol) | 921 | static void ntfs_setup_allocators(ntfs_volume *vol) |
922 | { | 922 | { |
923 | #ifdef NTFS_RW | 923 | #ifdef NTFS_RW |
924 | LCN mft_zone_size, mft_lcn; | 924 | LCN mft_zone_size, mft_lcn; |
925 | #endif /* NTFS_RW */ | 925 | #endif /* NTFS_RW */ |
926 | 926 | ||
927 | ntfs_debug("vol->mft_zone_multiplier = 0x%x", | 927 | ntfs_debug("vol->mft_zone_multiplier = 0x%x", |
928 | vol->mft_zone_multiplier); | 928 | vol->mft_zone_multiplier); |
929 | #ifdef NTFS_RW | 929 | #ifdef NTFS_RW |
930 | /* Determine the size of the MFT zone. */ | 930 | /* Determine the size of the MFT zone. */ |
931 | mft_zone_size = vol->nr_clusters; | 931 | mft_zone_size = vol->nr_clusters; |
932 | switch (vol->mft_zone_multiplier) { /* % of volume size in clusters */ | 932 | switch (vol->mft_zone_multiplier) { /* % of volume size in clusters */ |
933 | case 4: | 933 | case 4: |
934 | mft_zone_size >>= 1; /* 50% */ | 934 | mft_zone_size >>= 1; /* 50% */ |
935 | break; | 935 | break; |
936 | case 3: | 936 | case 3: |
937 | mft_zone_size = (mft_zone_size + | 937 | mft_zone_size = (mft_zone_size + |
938 | (mft_zone_size >> 1)) >> 2; /* 37.5% */ | 938 | (mft_zone_size >> 1)) >> 2; /* 37.5% */ |
939 | break; | 939 | break; |
940 | case 2: | 940 | case 2: |
941 | mft_zone_size >>= 2; /* 25% */ | 941 | mft_zone_size >>= 2; /* 25% */ |
942 | break; | 942 | break; |
943 | /* case 1: */ | 943 | /* case 1: */ |
944 | default: | 944 | default: |
945 | mft_zone_size >>= 3; /* 12.5% */ | 945 | mft_zone_size >>= 3; /* 12.5% */ |
946 | break; | 946 | break; |
947 | } | 947 | } |
948 | /* Setup the mft zone. */ | 948 | /* Setup the mft zone. */ |
949 | vol->mft_zone_start = vol->mft_zone_pos = vol->mft_lcn; | 949 | vol->mft_zone_start = vol->mft_zone_pos = vol->mft_lcn; |
950 | ntfs_debug("vol->mft_zone_pos = 0x%llx", | 950 | ntfs_debug("vol->mft_zone_pos = 0x%llx", |
951 | (unsigned long long)vol->mft_zone_pos); | 951 | (unsigned long long)vol->mft_zone_pos); |
952 | /* | 952 | /* |
953 | * Calculate the mft_lcn for an unmodified NTFS volume (see mkntfs | 953 | * Calculate the mft_lcn for an unmodified NTFS volume (see mkntfs |
954 | * source) and if the actual mft_lcn is in the expected place or even | 954 | * source) and if the actual mft_lcn is in the expected place or even |
955 | * further to the front of the volume, extend the mft_zone to cover the | 955 | * further to the front of the volume, extend the mft_zone to cover the |
956 | * beginning of the volume as well. This is in order to protect the | 956 | * beginning of the volume as well. This is in order to protect the |
957 | * area reserved for the mft bitmap as well within the mft_zone itself. | 957 | * area reserved for the mft bitmap as well within the mft_zone itself. |
958 | * On non-standard volumes we do not protect it as the overhead would | 958 | * On non-standard volumes we do not protect it as the overhead would |
959 | * be higher than the speed increase we would get by doing it. | 959 | * be higher than the speed increase we would get by doing it. |
960 | */ | 960 | */ |
961 | mft_lcn = (8192 + 2 * vol->cluster_size - 1) / vol->cluster_size; | 961 | mft_lcn = (8192 + 2 * vol->cluster_size - 1) / vol->cluster_size; |
962 | if (mft_lcn * vol->cluster_size < 16 * 1024) | 962 | if (mft_lcn * vol->cluster_size < 16 * 1024) |
963 | mft_lcn = (16 * 1024 + vol->cluster_size - 1) / | 963 | mft_lcn = (16 * 1024 + vol->cluster_size - 1) / |
964 | vol->cluster_size; | 964 | vol->cluster_size; |
965 | if (vol->mft_zone_start <= mft_lcn) | 965 | if (vol->mft_zone_start <= mft_lcn) |
966 | vol->mft_zone_start = 0; | 966 | vol->mft_zone_start = 0; |
967 | ntfs_debug("vol->mft_zone_start = 0x%llx", | 967 | ntfs_debug("vol->mft_zone_start = 0x%llx", |
968 | (unsigned long long)vol->mft_zone_start); | 968 | (unsigned long long)vol->mft_zone_start); |
969 | /* | 969 | /* |
970 | * Need to cap the mft zone on non-standard volumes so that it does | 970 | * Need to cap the mft zone on non-standard volumes so that it does |
971 | * not point outside the boundaries of the volume. We do this by | 971 | * not point outside the boundaries of the volume. We do this by |
972 | * halving the zone size until we are inside the volume. | 972 | * halving the zone size until we are inside the volume. |
973 | */ | 973 | */ |
974 | vol->mft_zone_end = vol->mft_lcn + mft_zone_size; | 974 | vol->mft_zone_end = vol->mft_lcn + mft_zone_size; |
975 | while (vol->mft_zone_end >= vol->nr_clusters) { | 975 | while (vol->mft_zone_end >= vol->nr_clusters) { |
976 | mft_zone_size >>= 1; | 976 | mft_zone_size >>= 1; |
977 | vol->mft_zone_end = vol->mft_lcn + mft_zone_size; | 977 | vol->mft_zone_end = vol->mft_lcn + mft_zone_size; |
978 | } | 978 | } |
979 | ntfs_debug("vol->mft_zone_end = 0x%llx", | 979 | ntfs_debug("vol->mft_zone_end = 0x%llx", |
980 | (unsigned long long)vol->mft_zone_end); | 980 | (unsigned long long)vol->mft_zone_end); |
981 | /* | 981 | /* |
982 | * Set the current position within each data zone to the start of the | 982 | * Set the current position within each data zone to the start of the |
983 | * respective zone. | 983 | * respective zone. |
984 | */ | 984 | */ |
985 | vol->data1_zone_pos = vol->mft_zone_end; | 985 | vol->data1_zone_pos = vol->mft_zone_end; |
986 | ntfs_debug("vol->data1_zone_pos = 0x%llx", | 986 | ntfs_debug("vol->data1_zone_pos = 0x%llx", |
987 | (unsigned long long)vol->data1_zone_pos); | 987 | (unsigned long long)vol->data1_zone_pos); |
988 | vol->data2_zone_pos = 0; | 988 | vol->data2_zone_pos = 0; |
989 | ntfs_debug("vol->data2_zone_pos = 0x%llx", | 989 | ntfs_debug("vol->data2_zone_pos = 0x%llx", |
990 | (unsigned long long)vol->data2_zone_pos); | 990 | (unsigned long long)vol->data2_zone_pos); |
991 | 991 | ||
992 | /* Set the mft data allocation position to mft record 24. */ | 992 | /* Set the mft data allocation position to mft record 24. */ |
993 | vol->mft_data_pos = 24; | 993 | vol->mft_data_pos = 24; |
994 | ntfs_debug("vol->mft_data_pos = 0x%llx", | 994 | ntfs_debug("vol->mft_data_pos = 0x%llx", |
995 | (unsigned long long)vol->mft_data_pos); | 995 | (unsigned long long)vol->mft_data_pos); |
996 | #endif /* NTFS_RW */ | 996 | #endif /* NTFS_RW */ |
997 | } | 997 | } |
998 | 998 | ||
999 | #ifdef NTFS_RW | 999 | #ifdef NTFS_RW |
1000 | 1000 | ||
1001 | /** | 1001 | /** |
1002 | * load_and_init_mft_mirror - load and setup the mft mirror inode for a volume | 1002 | * load_and_init_mft_mirror - load and setup the mft mirror inode for a volume |
1003 | * @vol: ntfs super block describing device whose mft mirror to load | 1003 | * @vol: ntfs super block describing device whose mft mirror to load |
1004 | * | 1004 | * |
1005 | * Return 'true' on success or 'false' on error. | 1005 | * Return 'true' on success or 'false' on error. |
1006 | */ | 1006 | */ |
1007 | static bool load_and_init_mft_mirror(ntfs_volume *vol) | 1007 | static bool load_and_init_mft_mirror(ntfs_volume *vol) |
1008 | { | 1008 | { |
1009 | struct inode *tmp_ino; | 1009 | struct inode *tmp_ino; |
1010 | ntfs_inode *tmp_ni; | 1010 | ntfs_inode *tmp_ni; |
1011 | 1011 | ||
1012 | ntfs_debug("Entering."); | 1012 | ntfs_debug("Entering."); |
1013 | /* Get mft mirror inode. */ | 1013 | /* Get mft mirror inode. */ |
1014 | tmp_ino = ntfs_iget(vol->sb, FILE_MFTMirr); | 1014 | tmp_ino = ntfs_iget(vol->sb, FILE_MFTMirr); |
1015 | if (IS_ERR(tmp_ino) || is_bad_inode(tmp_ino)) { | 1015 | if (IS_ERR(tmp_ino) || is_bad_inode(tmp_ino)) { |
1016 | if (!IS_ERR(tmp_ino)) | 1016 | if (!IS_ERR(tmp_ino)) |
1017 | iput(tmp_ino); | 1017 | iput(tmp_ino); |
1018 | /* Caller will display error message. */ | 1018 | /* Caller will display error message. */ |
1019 | return false; | 1019 | return false; |
1020 | } | 1020 | } |
1021 | /* | 1021 | /* |
1022 | * Re-initialize some specifics about $MFTMirr's inode as | 1022 | * Re-initialize some specifics about $MFTMirr's inode as |
1023 | * ntfs_read_inode() will have set up the default ones. | 1023 | * ntfs_read_inode() will have set up the default ones. |
1024 | */ | 1024 | */ |
1025 | /* Set uid and gid to root. */ | 1025 | /* Set uid and gid to root. */ |
1026 | tmp_ino->i_uid = tmp_ino->i_gid = 0; | 1026 | tmp_ino->i_uid = tmp_ino->i_gid = 0; |
1027 | /* Regular file. No access for anyone. */ | 1027 | /* Regular file. No access for anyone. */ |
1028 | tmp_ino->i_mode = S_IFREG; | 1028 | tmp_ino->i_mode = S_IFREG; |
1029 | /* No VFS initiated operations allowed for $MFTMirr. */ | 1029 | /* No VFS initiated operations allowed for $MFTMirr. */ |
1030 | tmp_ino->i_op = &ntfs_empty_inode_ops; | 1030 | tmp_ino->i_op = &ntfs_empty_inode_ops; |
1031 | tmp_ino->i_fop = &ntfs_empty_file_ops; | 1031 | tmp_ino->i_fop = &ntfs_empty_file_ops; |
1032 | /* Put in our special address space operations. */ | 1032 | /* Put in our special address space operations. */ |
1033 | tmp_ino->i_mapping->a_ops = &ntfs_mst_aops; | 1033 | tmp_ino->i_mapping->a_ops = &ntfs_mst_aops; |
1034 | tmp_ni = NTFS_I(tmp_ino); | 1034 | tmp_ni = NTFS_I(tmp_ino); |
1035 | /* The $MFTMirr, like the $MFT is multi sector transfer protected. */ | 1035 | /* The $MFTMirr, like the $MFT is multi sector transfer protected. */ |
1036 | NInoSetMstProtected(tmp_ni); | 1036 | NInoSetMstProtected(tmp_ni); |
1037 | NInoSetSparseDisabled(tmp_ni); | 1037 | NInoSetSparseDisabled(tmp_ni); |
1038 | /* | 1038 | /* |
1039 | * Set up our little cheat allowing us to reuse the async read io | 1039 | * Set up our little cheat allowing us to reuse the async read io |
1040 | * completion handler for directories. | 1040 | * completion handler for directories. |
1041 | */ | 1041 | */ |
1042 | tmp_ni->itype.index.block_size = vol->mft_record_size; | 1042 | tmp_ni->itype.index.block_size = vol->mft_record_size; |
1043 | tmp_ni->itype.index.block_size_bits = vol->mft_record_size_bits; | 1043 | tmp_ni->itype.index.block_size_bits = vol->mft_record_size_bits; |
1044 | vol->mftmirr_ino = tmp_ino; | 1044 | vol->mftmirr_ino = tmp_ino; |
1045 | ntfs_debug("Done."); | 1045 | ntfs_debug("Done."); |
1046 | return true; | 1046 | return true; |
1047 | } | 1047 | } |
1048 | 1048 | ||
1049 | /** | 1049 | /** |
1050 | * check_mft_mirror - compare contents of the mft mirror with the mft | 1050 | * check_mft_mirror - compare contents of the mft mirror with the mft |
1051 | * @vol: ntfs super block describing device whose mft mirror to check | 1051 | * @vol: ntfs super block describing device whose mft mirror to check |
1052 | * | 1052 | * |
1053 | * Return 'true' on success or 'false' on error. | 1053 | * Return 'true' on success or 'false' on error. |
1054 | * | 1054 | * |
1055 | * Note, this function also results in the mft mirror runlist being completely | 1055 | * Note, this function also results in the mft mirror runlist being completely |
1056 | * mapped into memory. The mft mirror write code requires this and will BUG() | 1056 | * mapped into memory. The mft mirror write code requires this and will BUG() |
1057 | * should it find an unmapped runlist element. | 1057 | * should it find an unmapped runlist element. |
1058 | */ | 1058 | */ |
1059 | static bool check_mft_mirror(ntfs_volume *vol) | 1059 | static bool check_mft_mirror(ntfs_volume *vol) |
1060 | { | 1060 | { |
1061 | struct super_block *sb = vol->sb; | 1061 | struct super_block *sb = vol->sb; |
1062 | ntfs_inode *mirr_ni; | 1062 | ntfs_inode *mirr_ni; |
1063 | struct page *mft_page, *mirr_page; | 1063 | struct page *mft_page, *mirr_page; |
1064 | u8 *kmft, *kmirr; | 1064 | u8 *kmft, *kmirr; |
1065 | runlist_element *rl, rl2[2]; | 1065 | runlist_element *rl, rl2[2]; |
1066 | pgoff_t index; | 1066 | pgoff_t index; |
1067 | int mrecs_per_page, i; | 1067 | int mrecs_per_page, i; |
1068 | 1068 | ||
1069 | ntfs_debug("Entering."); | 1069 | ntfs_debug("Entering."); |
1070 | /* Compare contents of $MFT and $MFTMirr. */ | 1070 | /* Compare contents of $MFT and $MFTMirr. */ |
1071 | mrecs_per_page = PAGE_CACHE_SIZE / vol->mft_record_size; | 1071 | mrecs_per_page = PAGE_CACHE_SIZE / vol->mft_record_size; |
1072 | BUG_ON(!mrecs_per_page); | 1072 | BUG_ON(!mrecs_per_page); |
1073 | BUG_ON(!vol->mftmirr_size); | 1073 | BUG_ON(!vol->mftmirr_size); |
1074 | mft_page = mirr_page = NULL; | 1074 | mft_page = mirr_page = NULL; |
1075 | kmft = kmirr = NULL; | 1075 | kmft = kmirr = NULL; |
1076 | index = i = 0; | 1076 | index = i = 0; |
1077 | do { | 1077 | do { |
1078 | u32 bytes; | 1078 | u32 bytes; |
1079 | 1079 | ||
1080 | /* Switch pages if necessary. */ | 1080 | /* Switch pages if necessary. */ |
1081 | if (!(i % mrecs_per_page)) { | 1081 | if (!(i % mrecs_per_page)) { |
1082 | if (index) { | 1082 | if (index) { |
1083 | ntfs_unmap_page(mft_page); | 1083 | ntfs_unmap_page(mft_page); |
1084 | ntfs_unmap_page(mirr_page); | 1084 | ntfs_unmap_page(mirr_page); |
1085 | } | 1085 | } |
1086 | /* Get the $MFT page. */ | 1086 | /* Get the $MFT page. */ |
1087 | mft_page = ntfs_map_page(vol->mft_ino->i_mapping, | 1087 | mft_page = ntfs_map_page(vol->mft_ino->i_mapping, |
1088 | index); | 1088 | index); |
1089 | if (IS_ERR(mft_page)) { | 1089 | if (IS_ERR(mft_page)) { |
1090 | ntfs_error(sb, "Failed to read $MFT."); | 1090 | ntfs_error(sb, "Failed to read $MFT."); |
1091 | return false; | 1091 | return false; |
1092 | } | 1092 | } |
1093 | kmft = page_address(mft_page); | 1093 | kmft = page_address(mft_page); |
1094 | /* Get the $MFTMirr page. */ | 1094 | /* Get the $MFTMirr page. */ |
1095 | mirr_page = ntfs_map_page(vol->mftmirr_ino->i_mapping, | 1095 | mirr_page = ntfs_map_page(vol->mftmirr_ino->i_mapping, |
1096 | index); | 1096 | index); |
1097 | if (IS_ERR(mirr_page)) { | 1097 | if (IS_ERR(mirr_page)) { |
1098 | ntfs_error(sb, "Failed to read $MFTMirr."); | 1098 | ntfs_error(sb, "Failed to read $MFTMirr."); |
1099 | goto mft_unmap_out; | 1099 | goto mft_unmap_out; |
1100 | } | 1100 | } |
1101 | kmirr = page_address(mirr_page); | 1101 | kmirr = page_address(mirr_page); |
1102 | ++index; | 1102 | ++index; |
1103 | } | 1103 | } |
1104 | /* Do not check the record if it is not in use. */ | 1104 | /* Do not check the record if it is not in use. */ |
1105 | if (((MFT_RECORD*)kmft)->flags & MFT_RECORD_IN_USE) { | 1105 | if (((MFT_RECORD*)kmft)->flags & MFT_RECORD_IN_USE) { |
1106 | /* Make sure the record is ok. */ | 1106 | /* Make sure the record is ok. */ |
1107 | if (ntfs_is_baad_recordp((le32*)kmft)) { | 1107 | if (ntfs_is_baad_recordp((le32*)kmft)) { |
1108 | ntfs_error(sb, "Incomplete multi sector " | 1108 | ntfs_error(sb, "Incomplete multi sector " |
1109 | "transfer detected in mft " | 1109 | "transfer detected in mft " |
1110 | "record %i.", i); | 1110 | "record %i.", i); |
1111 | mm_unmap_out: | 1111 | mm_unmap_out: |
1112 | ntfs_unmap_page(mirr_page); | 1112 | ntfs_unmap_page(mirr_page); |
1113 | mft_unmap_out: | 1113 | mft_unmap_out: |
1114 | ntfs_unmap_page(mft_page); | 1114 | ntfs_unmap_page(mft_page); |
1115 | return false; | 1115 | return false; |
1116 | } | 1116 | } |
1117 | } | 1117 | } |
1118 | /* Do not check the mirror record if it is not in use. */ | 1118 | /* Do not check the mirror record if it is not in use. */ |
1119 | if (((MFT_RECORD*)kmirr)->flags & MFT_RECORD_IN_USE) { | 1119 | if (((MFT_RECORD*)kmirr)->flags & MFT_RECORD_IN_USE) { |
1120 | if (ntfs_is_baad_recordp((le32*)kmirr)) { | 1120 | if (ntfs_is_baad_recordp((le32*)kmirr)) { |
1121 | ntfs_error(sb, "Incomplete multi sector " | 1121 | ntfs_error(sb, "Incomplete multi sector " |
1122 | "transfer detected in mft " | 1122 | "transfer detected in mft " |
1123 | "mirror record %i.", i); | 1123 | "mirror record %i.", i); |
1124 | goto mm_unmap_out; | 1124 | goto mm_unmap_out; |
1125 | } | 1125 | } |
1126 | } | 1126 | } |
1127 | /* Get the amount of data in the current record. */ | 1127 | /* Get the amount of data in the current record. */ |
1128 | bytes = le32_to_cpu(((MFT_RECORD*)kmft)->bytes_in_use); | 1128 | bytes = le32_to_cpu(((MFT_RECORD*)kmft)->bytes_in_use); |
1129 | if (bytes < sizeof(MFT_RECORD_OLD) || | 1129 | if (bytes < sizeof(MFT_RECORD_OLD) || |
1130 | bytes > vol->mft_record_size || | 1130 | bytes > vol->mft_record_size || |
1131 | ntfs_is_baad_recordp((le32*)kmft)) { | 1131 | ntfs_is_baad_recordp((le32*)kmft)) { |
1132 | bytes = le32_to_cpu(((MFT_RECORD*)kmirr)->bytes_in_use); | 1132 | bytes = le32_to_cpu(((MFT_RECORD*)kmirr)->bytes_in_use); |
1133 | if (bytes < sizeof(MFT_RECORD_OLD) || | 1133 | if (bytes < sizeof(MFT_RECORD_OLD) || |
1134 | bytes > vol->mft_record_size || | 1134 | bytes > vol->mft_record_size || |
1135 | ntfs_is_baad_recordp((le32*)kmirr)) | 1135 | ntfs_is_baad_recordp((le32*)kmirr)) |
1136 | bytes = vol->mft_record_size; | 1136 | bytes = vol->mft_record_size; |
1137 | } | 1137 | } |
1138 | /* Compare the two records. */ | 1138 | /* Compare the two records. */ |
1139 | if (memcmp(kmft, kmirr, bytes)) { | 1139 | if (memcmp(kmft, kmirr, bytes)) { |
1140 | ntfs_error(sb, "$MFT and $MFTMirr (record %i) do not " | 1140 | ntfs_error(sb, "$MFT and $MFTMirr (record %i) do not " |
1141 | "match. Run ntfsfix or chkdsk.", i); | 1141 | "match. Run ntfsfix or chkdsk.", i); |
1142 | goto mm_unmap_out; | 1142 | goto mm_unmap_out; |
1143 | } | 1143 | } |
1144 | kmft += vol->mft_record_size; | 1144 | kmft += vol->mft_record_size; |
1145 | kmirr += vol->mft_record_size; | 1145 | kmirr += vol->mft_record_size; |
1146 | } while (++i < vol->mftmirr_size); | 1146 | } while (++i < vol->mftmirr_size); |
1147 | /* Release the last pages. */ | 1147 | /* Release the last pages. */ |
1148 | ntfs_unmap_page(mft_page); | 1148 | ntfs_unmap_page(mft_page); |
1149 | ntfs_unmap_page(mirr_page); | 1149 | ntfs_unmap_page(mirr_page); |
1150 | 1150 | ||
1151 | /* Construct the mft mirror runlist by hand. */ | 1151 | /* Construct the mft mirror runlist by hand. */ |
1152 | rl2[0].vcn = 0; | 1152 | rl2[0].vcn = 0; |
1153 | rl2[0].lcn = vol->mftmirr_lcn; | 1153 | rl2[0].lcn = vol->mftmirr_lcn; |
1154 | rl2[0].length = (vol->mftmirr_size * vol->mft_record_size + | 1154 | rl2[0].length = (vol->mftmirr_size * vol->mft_record_size + |
1155 | vol->cluster_size - 1) / vol->cluster_size; | 1155 | vol->cluster_size - 1) / vol->cluster_size; |
1156 | rl2[1].vcn = rl2[0].length; | 1156 | rl2[1].vcn = rl2[0].length; |
1157 | rl2[1].lcn = LCN_ENOENT; | 1157 | rl2[1].lcn = LCN_ENOENT; |
1158 | rl2[1].length = 0; | 1158 | rl2[1].length = 0; |
1159 | /* | 1159 | /* |
1160 | * Because we have just read all of the mft mirror, we know we have | 1160 | * Because we have just read all of the mft mirror, we know we have |
1161 | * mapped the full runlist for it. | 1161 | * mapped the full runlist for it. |
1162 | */ | 1162 | */ |
1163 | mirr_ni = NTFS_I(vol->mftmirr_ino); | 1163 | mirr_ni = NTFS_I(vol->mftmirr_ino); |
1164 | down_read(&mirr_ni->runlist.lock); | 1164 | down_read(&mirr_ni->runlist.lock); |
1165 | rl = mirr_ni->runlist.rl; | 1165 | rl = mirr_ni->runlist.rl; |
1166 | /* Compare the two runlists. They must be identical. */ | 1166 | /* Compare the two runlists. They must be identical. */ |
1167 | i = 0; | 1167 | i = 0; |
1168 | do { | 1168 | do { |
1169 | if (rl2[i].vcn != rl[i].vcn || rl2[i].lcn != rl[i].lcn || | 1169 | if (rl2[i].vcn != rl[i].vcn || rl2[i].lcn != rl[i].lcn || |
1170 | rl2[i].length != rl[i].length) { | 1170 | rl2[i].length != rl[i].length) { |
1171 | ntfs_error(sb, "$MFTMirr location mismatch. " | 1171 | ntfs_error(sb, "$MFTMirr location mismatch. " |
1172 | "Run chkdsk."); | 1172 | "Run chkdsk."); |
1173 | up_read(&mirr_ni->runlist.lock); | 1173 | up_read(&mirr_ni->runlist.lock); |
1174 | return false; | 1174 | return false; |
1175 | } | 1175 | } |
1176 | } while (rl2[i++].length); | 1176 | } while (rl2[i++].length); |
1177 | up_read(&mirr_ni->runlist.lock); | 1177 | up_read(&mirr_ni->runlist.lock); |
1178 | ntfs_debug("Done."); | 1178 | ntfs_debug("Done."); |
1179 | return true; | 1179 | return true; |
1180 | } | 1180 | } |
1181 | 1181 | ||
1182 | /** | 1182 | /** |
1183 | * load_and_check_logfile - load and check the logfile inode for a volume | 1183 | * load_and_check_logfile - load and check the logfile inode for a volume |
1184 | * @vol: ntfs super block describing device whose logfile to load | 1184 | * @vol: ntfs super block describing device whose logfile to load |
1185 | * | 1185 | * |
1186 | * Return 'true' on success or 'false' on error. | 1186 | * Return 'true' on success or 'false' on error. |
1187 | */ | 1187 | */ |
1188 | static bool load_and_check_logfile(ntfs_volume *vol, | 1188 | static bool load_and_check_logfile(ntfs_volume *vol, |
1189 | RESTART_PAGE_HEADER **rp) | 1189 | RESTART_PAGE_HEADER **rp) |
1190 | { | 1190 | { |
1191 | struct inode *tmp_ino; | 1191 | struct inode *tmp_ino; |
1192 | 1192 | ||
1193 | ntfs_debug("Entering."); | 1193 | ntfs_debug("Entering."); |
1194 | tmp_ino = ntfs_iget(vol->sb, FILE_LogFile); | 1194 | tmp_ino = ntfs_iget(vol->sb, FILE_LogFile); |
1195 | if (IS_ERR(tmp_ino) || is_bad_inode(tmp_ino)) { | 1195 | if (IS_ERR(tmp_ino) || is_bad_inode(tmp_ino)) { |
1196 | if (!IS_ERR(tmp_ino)) | 1196 | if (!IS_ERR(tmp_ino)) |
1197 | iput(tmp_ino); | 1197 | iput(tmp_ino); |
1198 | /* Caller will display error message. */ | 1198 | /* Caller will display error message. */ |
1199 | return false; | 1199 | return false; |
1200 | } | 1200 | } |
1201 | if (!ntfs_check_logfile(tmp_ino, rp)) { | 1201 | if (!ntfs_check_logfile(tmp_ino, rp)) { |
1202 | iput(tmp_ino); | 1202 | iput(tmp_ino); |
1203 | /* ntfs_check_logfile() will have displayed error output. */ | 1203 | /* ntfs_check_logfile() will have displayed error output. */ |
1204 | return false; | 1204 | return false; |
1205 | } | 1205 | } |
1206 | NInoSetSparseDisabled(NTFS_I(tmp_ino)); | 1206 | NInoSetSparseDisabled(NTFS_I(tmp_ino)); |
1207 | vol->logfile_ino = tmp_ino; | 1207 | vol->logfile_ino = tmp_ino; |
1208 | ntfs_debug("Done."); | 1208 | ntfs_debug("Done."); |
1209 | return true; | 1209 | return true; |
1210 | } | 1210 | } |
1211 | 1211 | ||
1212 | #define NTFS_HIBERFIL_HEADER_SIZE 4096 | 1212 | #define NTFS_HIBERFIL_HEADER_SIZE 4096 |
1213 | 1213 | ||
1214 | /** | 1214 | /** |
1215 | * check_windows_hibernation_status - check if Windows is suspended on a volume | 1215 | * check_windows_hibernation_status - check if Windows is suspended on a volume |
1216 | * @vol: ntfs super block of device to check | 1216 | * @vol: ntfs super block of device to check |
1217 | * | 1217 | * |
1218 | * Check if Windows is hibernated on the ntfs volume @vol. This is done by | 1218 | * Check if Windows is hibernated on the ntfs volume @vol. This is done by |
1219 | * looking for the file hiberfil.sys in the root directory of the volume. If | 1219 | * looking for the file hiberfil.sys in the root directory of the volume. If |
1220 | * the file is not present Windows is definitely not suspended. | 1220 | * the file is not present Windows is definitely not suspended. |
1221 | * | 1221 | * |
1222 | * If hiberfil.sys exists and is less than 4kiB in size it means Windows is | 1222 | * If hiberfil.sys exists and is less than 4kiB in size it means Windows is |
1223 | * definitely suspended (this volume is not the system volume). Caveat: on a | 1223 | * definitely suspended (this volume is not the system volume). Caveat: on a |
1224 | * system with many volumes it is possible that the < 4kiB check is bogus but | 1224 | * system with many volumes it is possible that the < 4kiB check is bogus but |
1225 | * for now this should do fine. | 1225 | * for now this should do fine. |
1226 | * | 1226 | * |
1227 | * If hiberfil.sys exists and is larger than 4kiB in size, we need to read the | 1227 | * If hiberfil.sys exists and is larger than 4kiB in size, we need to read the |
1228 | * hiberfil header (which is the first 4kiB). If this begins with "hibr", | 1228 | * hiberfil header (which is the first 4kiB). If this begins with "hibr", |
1229 | * Windows is definitely suspended. If it is completely full of zeroes, | 1229 | * Windows is definitely suspended. If it is completely full of zeroes, |
1230 | * Windows is definitely not hibernated. Any other case is treated as if | 1230 | * Windows is definitely not hibernated. Any other case is treated as if |
1231 | * Windows is suspended. This caters for the above mentioned caveat of a | 1231 | * Windows is suspended. This caters for the above mentioned caveat of a |
1232 | * system with many volumes where no "hibr" magic would be present and there is | 1232 | * system with many volumes where no "hibr" magic would be present and there is |
1233 | * no zero header. | 1233 | * no zero header. |
1234 | * | 1234 | * |
1235 | * Return 0 if Windows is not hibernated on the volume, >0 if Windows is | 1235 | * Return 0 if Windows is not hibernated on the volume, >0 if Windows is |
1236 | * hibernated on the volume, and -errno on error. | 1236 | * hibernated on the volume, and -errno on error. |
1237 | */ | 1237 | */ |
1238 | static int check_windows_hibernation_status(ntfs_volume *vol) | 1238 | static int check_windows_hibernation_status(ntfs_volume *vol) |
1239 | { | 1239 | { |
1240 | MFT_REF mref; | 1240 | MFT_REF mref; |
1241 | struct inode *vi; | 1241 | struct inode *vi; |
1242 | ntfs_inode *ni; | ||
1243 | struct page *page; | 1242 | struct page *page; |
1244 | u32 *kaddr, *kend; | 1243 | u32 *kaddr, *kend; |
1245 | ntfs_name *name = NULL; | 1244 | ntfs_name *name = NULL; |
1246 | int ret = 1; | 1245 | int ret = 1; |
1247 | static const ntfschar hiberfil[13] = { cpu_to_le16('h'), | 1246 | static const ntfschar hiberfil[13] = { cpu_to_le16('h'), |
1248 | cpu_to_le16('i'), cpu_to_le16('b'), | 1247 | cpu_to_le16('i'), cpu_to_le16('b'), |
1249 | cpu_to_le16('e'), cpu_to_le16('r'), | 1248 | cpu_to_le16('e'), cpu_to_le16('r'), |
1250 | cpu_to_le16('f'), cpu_to_le16('i'), | 1249 | cpu_to_le16('f'), cpu_to_le16('i'), |
1251 | cpu_to_le16('l'), cpu_to_le16('.'), | 1250 | cpu_to_le16('l'), cpu_to_le16('.'), |
1252 | cpu_to_le16('s'), cpu_to_le16('y'), | 1251 | cpu_to_le16('s'), cpu_to_le16('y'), |
1253 | cpu_to_le16('s'), 0 }; | 1252 | cpu_to_le16('s'), 0 }; |
1254 | 1253 | ||
1255 | ntfs_debug("Entering."); | 1254 | ntfs_debug("Entering."); |
1256 | /* | 1255 | /* |
1257 | * Find the inode number for the hibernation file by looking up the | 1256 | * Find the inode number for the hibernation file by looking up the |
1258 | * filename hiberfil.sys in the root directory. | 1257 | * filename hiberfil.sys in the root directory. |
1259 | */ | 1258 | */ |
1260 | mutex_lock(&vol->root_ino->i_mutex); | 1259 | mutex_lock(&vol->root_ino->i_mutex); |
1261 | mref = ntfs_lookup_inode_by_name(NTFS_I(vol->root_ino), hiberfil, 12, | 1260 | mref = ntfs_lookup_inode_by_name(NTFS_I(vol->root_ino), hiberfil, 12, |
1262 | &name); | 1261 | &name); |
1263 | mutex_unlock(&vol->root_ino->i_mutex); | 1262 | mutex_unlock(&vol->root_ino->i_mutex); |
1264 | if (IS_ERR_MREF(mref)) { | 1263 | if (IS_ERR_MREF(mref)) { |
1265 | ret = MREF_ERR(mref); | 1264 | ret = MREF_ERR(mref); |
1266 | /* If the file does not exist, Windows is not hibernated. */ | 1265 | /* If the file does not exist, Windows is not hibernated. */ |
1267 | if (ret == -ENOENT) { | 1266 | if (ret == -ENOENT) { |
1268 | ntfs_debug("hiberfil.sys not present. Windows is not " | 1267 | ntfs_debug("hiberfil.sys not present. Windows is not " |
1269 | "hibernated on the volume."); | 1268 | "hibernated on the volume."); |
1270 | return 0; | 1269 | return 0; |
1271 | } | 1270 | } |
1272 | /* A real error occurred. */ | 1271 | /* A real error occurred. */ |
1273 | ntfs_error(vol->sb, "Failed to find inode number for " | 1272 | ntfs_error(vol->sb, "Failed to find inode number for " |
1274 | "hiberfil.sys."); | 1273 | "hiberfil.sys."); |
1275 | return ret; | 1274 | return ret; |
1276 | } | 1275 | } |
1277 | /* We do not care for the type of match that was found. */ | 1276 | /* We do not care for the type of match that was found. */ |
1278 | kfree(name); | 1277 | kfree(name); |
1279 | /* Get the inode. */ | 1278 | /* Get the inode. */ |
1280 | vi = ntfs_iget(vol->sb, MREF(mref)); | 1279 | vi = ntfs_iget(vol->sb, MREF(mref)); |
1281 | if (IS_ERR(vi) || is_bad_inode(vi)) { | 1280 | if (IS_ERR(vi) || is_bad_inode(vi)) { |
1282 | if (!IS_ERR(vi)) | 1281 | if (!IS_ERR(vi)) |
1283 | iput(vi); | 1282 | iput(vi); |
1284 | ntfs_error(vol->sb, "Failed to load hiberfil.sys."); | 1283 | ntfs_error(vol->sb, "Failed to load hiberfil.sys."); |
1285 | return IS_ERR(vi) ? PTR_ERR(vi) : -EIO; | 1284 | return IS_ERR(vi) ? PTR_ERR(vi) : -EIO; |
1286 | } | 1285 | } |
1287 | if (unlikely(i_size_read(vi) < NTFS_HIBERFIL_HEADER_SIZE)) { | 1286 | if (unlikely(i_size_read(vi) < NTFS_HIBERFIL_HEADER_SIZE)) { |
1288 | ntfs_debug("hiberfil.sys is smaller than 4kiB (0x%llx). " | 1287 | ntfs_debug("hiberfil.sys is smaller than 4kiB (0x%llx). " |
1289 | "Windows is hibernated on the volume. This " | 1288 | "Windows is hibernated on the volume. This " |
1290 | "is not the system volume.", i_size_read(vi)); | 1289 | "is not the system volume.", i_size_read(vi)); |
1291 | goto iput_out; | 1290 | goto iput_out; |
1292 | } | 1291 | } |
1293 | ni = NTFS_I(vi); | ||
1294 | page = ntfs_map_page(vi->i_mapping, 0); | 1292 | page = ntfs_map_page(vi->i_mapping, 0); |
1295 | if (IS_ERR(page)) { | 1293 | if (IS_ERR(page)) { |
1296 | ntfs_error(vol->sb, "Failed to read from hiberfil.sys."); | 1294 | ntfs_error(vol->sb, "Failed to read from hiberfil.sys."); |
1297 | ret = PTR_ERR(page); | 1295 | ret = PTR_ERR(page); |
1298 | goto iput_out; | 1296 | goto iput_out; |
1299 | } | 1297 | } |
1300 | kaddr = (u32*)page_address(page); | 1298 | kaddr = (u32*)page_address(page); |
1301 | if (*(le32*)kaddr == cpu_to_le32(0x72626968)/*'hibr'*/) { | 1299 | if (*(le32*)kaddr == cpu_to_le32(0x72626968)/*'hibr'*/) { |
1302 | ntfs_debug("Magic \"hibr\" found in hiberfil.sys. Windows is " | 1300 | ntfs_debug("Magic \"hibr\" found in hiberfil.sys. Windows is " |
1303 | "hibernated on the volume. This is the " | 1301 | "hibernated on the volume. This is the " |
1304 | "system volume."); | 1302 | "system volume."); |
1305 | goto unm_iput_out; | 1303 | goto unm_iput_out; |
1306 | } | 1304 | } |
1307 | kend = kaddr + NTFS_HIBERFIL_HEADER_SIZE/sizeof(*kaddr); | 1305 | kend = kaddr + NTFS_HIBERFIL_HEADER_SIZE/sizeof(*kaddr); |
1308 | do { | 1306 | do { |
1309 | if (unlikely(*kaddr)) { | 1307 | if (unlikely(*kaddr)) { |
1310 | ntfs_debug("hiberfil.sys is larger than 4kiB " | 1308 | ntfs_debug("hiberfil.sys is larger than 4kiB " |
1311 | "(0x%llx), does not contain the " | 1309 | "(0x%llx), does not contain the " |
1312 | "\"hibr\" magic, and does not have a " | 1310 | "\"hibr\" magic, and does not have a " |
1313 | "zero header. Windows is hibernated " | 1311 | "zero header. Windows is hibernated " |
1314 | "on the volume. This is not the " | 1312 | "on the volume. This is not the " |
1315 | "system volume.", i_size_read(vi)); | 1313 | "system volume.", i_size_read(vi)); |
1316 | goto unm_iput_out; | 1314 | goto unm_iput_out; |
1317 | } | 1315 | } |
1318 | } while (++kaddr < kend); | 1316 | } while (++kaddr < kend); |
1319 | ntfs_debug("hiberfil.sys contains a zero header. Windows is not " | 1317 | ntfs_debug("hiberfil.sys contains a zero header. Windows is not " |
1320 | "hibernated on the volume. This is the system " | 1318 | "hibernated on the volume. This is the system " |
1321 | "volume."); | 1319 | "volume."); |
1322 | ret = 0; | 1320 | ret = 0; |
1323 | unm_iput_out: | 1321 | unm_iput_out: |
1324 | ntfs_unmap_page(page); | 1322 | ntfs_unmap_page(page); |
1325 | iput_out: | 1323 | iput_out: |
1326 | iput(vi); | 1324 | iput(vi); |
1327 | return ret; | 1325 | return ret; |
1328 | } | 1326 | } |
1329 | 1327 | ||
1330 | /** | 1328 | /** |
1331 | * load_and_init_quota - load and setup the quota file for a volume if present | 1329 | * load_and_init_quota - load and setup the quota file for a volume if present |
1332 | * @vol: ntfs super block describing device whose quota file to load | 1330 | * @vol: ntfs super block describing device whose quota file to load |
1333 | * | 1331 | * |
1334 | * Return 'true' on success or 'false' on error. If $Quota is not present, we | 1332 | * Return 'true' on success or 'false' on error. If $Quota is not present, we |
1335 | * leave vol->quota_ino as NULL and return success. | 1333 | * leave vol->quota_ino as NULL and return success. |
1336 | */ | 1334 | */ |
1337 | static bool load_and_init_quota(ntfs_volume *vol) | 1335 | static bool load_and_init_quota(ntfs_volume *vol) |
1338 | { | 1336 | { |
1339 | MFT_REF mref; | 1337 | MFT_REF mref; |
1340 | struct inode *tmp_ino; | 1338 | struct inode *tmp_ino; |
1341 | ntfs_name *name = NULL; | 1339 | ntfs_name *name = NULL; |
1342 | static const ntfschar Quota[7] = { cpu_to_le16('$'), | 1340 | static const ntfschar Quota[7] = { cpu_to_le16('$'), |
1343 | cpu_to_le16('Q'), cpu_to_le16('u'), | 1341 | cpu_to_le16('Q'), cpu_to_le16('u'), |
1344 | cpu_to_le16('o'), cpu_to_le16('t'), | 1342 | cpu_to_le16('o'), cpu_to_le16('t'), |
1345 | cpu_to_le16('a'), 0 }; | 1343 | cpu_to_le16('a'), 0 }; |
1346 | static ntfschar Q[3] = { cpu_to_le16('$'), | 1344 | static ntfschar Q[3] = { cpu_to_le16('$'), |
1347 | cpu_to_le16('Q'), 0 }; | 1345 | cpu_to_le16('Q'), 0 }; |
1348 | 1346 | ||
1349 | ntfs_debug("Entering."); | 1347 | ntfs_debug("Entering."); |
1350 | /* | 1348 | /* |
1351 | * Find the inode number for the quota file by looking up the filename | 1349 | * Find the inode number for the quota file by looking up the filename |
1352 | * $Quota in the extended system files directory $Extend. | 1350 | * $Quota in the extended system files directory $Extend. |
1353 | */ | 1351 | */ |
1354 | mutex_lock(&vol->extend_ino->i_mutex); | 1352 | mutex_lock(&vol->extend_ino->i_mutex); |
1355 | mref = ntfs_lookup_inode_by_name(NTFS_I(vol->extend_ino), Quota, 6, | 1353 | mref = ntfs_lookup_inode_by_name(NTFS_I(vol->extend_ino), Quota, 6, |
1356 | &name); | 1354 | &name); |
1357 | mutex_unlock(&vol->extend_ino->i_mutex); | 1355 | mutex_unlock(&vol->extend_ino->i_mutex); |
1358 | if (IS_ERR_MREF(mref)) { | 1356 | if (IS_ERR_MREF(mref)) { |
1359 | /* | 1357 | /* |
1360 | * If the file does not exist, quotas are disabled and have | 1358 | * If the file does not exist, quotas are disabled and have |
1361 | * never been enabled on this volume, just return success. | 1359 | * never been enabled on this volume, just return success. |
1362 | */ | 1360 | */ |
1363 | if (MREF_ERR(mref) == -ENOENT) { | 1361 | if (MREF_ERR(mref) == -ENOENT) { |
1364 | ntfs_debug("$Quota not present. Volume does not have " | 1362 | ntfs_debug("$Quota not present. Volume does not have " |
1365 | "quotas enabled."); | 1363 | "quotas enabled."); |
1366 | /* | 1364 | /* |
1367 | * No need to try to set quotas out of date if they are | 1365 | * No need to try to set quotas out of date if they are |
1368 | * not enabled. | 1366 | * not enabled. |
1369 | */ | 1367 | */ |
1370 | NVolSetQuotaOutOfDate(vol); | 1368 | NVolSetQuotaOutOfDate(vol); |
1371 | return true; | 1369 | return true; |
1372 | } | 1370 | } |
1373 | /* A real error occurred. */ | 1371 | /* A real error occurred. */ |
1374 | ntfs_error(vol->sb, "Failed to find inode number for $Quota."); | 1372 | ntfs_error(vol->sb, "Failed to find inode number for $Quota."); |
1375 | return false; | 1373 | return false; |
1376 | } | 1374 | } |
1377 | /* We do not care for the type of match that was found. */ | 1375 | /* We do not care for the type of match that was found. */ |
1378 | kfree(name); | 1376 | kfree(name); |
1379 | /* Get the inode. */ | 1377 | /* Get the inode. */ |
1380 | tmp_ino = ntfs_iget(vol->sb, MREF(mref)); | 1378 | tmp_ino = ntfs_iget(vol->sb, MREF(mref)); |
1381 | if (IS_ERR(tmp_ino) || is_bad_inode(tmp_ino)) { | 1379 | if (IS_ERR(tmp_ino) || is_bad_inode(tmp_ino)) { |
1382 | if (!IS_ERR(tmp_ino)) | 1380 | if (!IS_ERR(tmp_ino)) |
1383 | iput(tmp_ino); | 1381 | iput(tmp_ino); |
1384 | ntfs_error(vol->sb, "Failed to load $Quota."); | 1382 | ntfs_error(vol->sb, "Failed to load $Quota."); |
1385 | return false; | 1383 | return false; |
1386 | } | 1384 | } |
1387 | vol->quota_ino = tmp_ino; | 1385 | vol->quota_ino = tmp_ino; |
1388 | /* Get the $Q index allocation attribute. */ | 1386 | /* Get the $Q index allocation attribute. */ |
1389 | tmp_ino = ntfs_index_iget(vol->quota_ino, Q, 2); | 1387 | tmp_ino = ntfs_index_iget(vol->quota_ino, Q, 2); |
1390 | if (IS_ERR(tmp_ino)) { | 1388 | if (IS_ERR(tmp_ino)) { |
1391 | ntfs_error(vol->sb, "Failed to load $Quota/$Q index."); | 1389 | ntfs_error(vol->sb, "Failed to load $Quota/$Q index."); |
1392 | return false; | 1390 | return false; |
1393 | } | 1391 | } |
1394 | vol->quota_q_ino = tmp_ino; | 1392 | vol->quota_q_ino = tmp_ino; |
1395 | ntfs_debug("Done."); | 1393 | ntfs_debug("Done."); |
1396 | return true; | 1394 | return true; |
1397 | } | 1395 | } |
1398 | 1396 | ||
1399 | /** | 1397 | /** |
1400 | * load_and_init_usnjrnl - load and setup the transaction log if present | 1398 | * load_and_init_usnjrnl - load and setup the transaction log if present |
1401 | * @vol: ntfs super block describing device whose usnjrnl file to load | 1399 | * @vol: ntfs super block describing device whose usnjrnl file to load |
1402 | * | 1400 | * |
1403 | * Return 'true' on success or 'false' on error. | 1401 | * Return 'true' on success or 'false' on error. |
1404 | * | 1402 | * |
1405 | * If $UsnJrnl is not present or in the process of being disabled, we set | 1403 | * If $UsnJrnl is not present or in the process of being disabled, we set |
1406 | * NVolUsnJrnlStamped() and return success. | 1404 | * NVolUsnJrnlStamped() and return success. |
1407 | * | 1405 | * |
1408 | * If the $UsnJrnl $DATA/$J attribute has a size equal to the lowest valid usn, | 1406 | * If the $UsnJrnl $DATA/$J attribute has a size equal to the lowest valid usn, |
1409 | * i.e. transaction logging has only just been enabled or the journal has been | 1407 | * i.e. transaction logging has only just been enabled or the journal has been |
1410 | * stamped and nothing has been logged since, we also set NVolUsnJrnlStamped() | 1408 | * stamped and nothing has been logged since, we also set NVolUsnJrnlStamped() |
1411 | * and return success. | 1409 | * and return success. |
1412 | */ | 1410 | */ |
1413 | static bool load_and_init_usnjrnl(ntfs_volume *vol) | 1411 | static bool load_and_init_usnjrnl(ntfs_volume *vol) |
1414 | { | 1412 | { |
1415 | MFT_REF mref; | 1413 | MFT_REF mref; |
1416 | struct inode *tmp_ino; | 1414 | struct inode *tmp_ino; |
1417 | ntfs_inode *tmp_ni; | 1415 | ntfs_inode *tmp_ni; |
1418 | struct page *page; | 1416 | struct page *page; |
1419 | ntfs_name *name = NULL; | 1417 | ntfs_name *name = NULL; |
1420 | USN_HEADER *uh; | 1418 | USN_HEADER *uh; |
1421 | static const ntfschar UsnJrnl[9] = { cpu_to_le16('$'), | 1419 | static const ntfschar UsnJrnl[9] = { cpu_to_le16('$'), |
1422 | cpu_to_le16('U'), cpu_to_le16('s'), | 1420 | cpu_to_le16('U'), cpu_to_le16('s'), |
1423 | cpu_to_le16('n'), cpu_to_le16('J'), | 1421 | cpu_to_le16('n'), cpu_to_le16('J'), |
1424 | cpu_to_le16('r'), cpu_to_le16('n'), | 1422 | cpu_to_le16('r'), cpu_to_le16('n'), |
1425 | cpu_to_le16('l'), 0 }; | 1423 | cpu_to_le16('l'), 0 }; |
1426 | static ntfschar Max[5] = { cpu_to_le16('$'), | 1424 | static ntfschar Max[5] = { cpu_to_le16('$'), |
1427 | cpu_to_le16('M'), cpu_to_le16('a'), | 1425 | cpu_to_le16('M'), cpu_to_le16('a'), |
1428 | cpu_to_le16('x'), 0 }; | 1426 | cpu_to_le16('x'), 0 }; |
1429 | static ntfschar J[3] = { cpu_to_le16('$'), | 1427 | static ntfschar J[3] = { cpu_to_le16('$'), |
1430 | cpu_to_le16('J'), 0 }; | 1428 | cpu_to_le16('J'), 0 }; |
1431 | 1429 | ||
1432 | ntfs_debug("Entering."); | 1430 | ntfs_debug("Entering."); |
1433 | /* | 1431 | /* |
1434 | * Find the inode number for the transaction log file by looking up the | 1432 | * Find the inode number for the transaction log file by looking up the |
1435 | * filename $UsnJrnl in the extended system files directory $Extend. | 1433 | * filename $UsnJrnl in the extended system files directory $Extend. |
1436 | */ | 1434 | */ |
1437 | mutex_lock(&vol->extend_ino->i_mutex); | 1435 | mutex_lock(&vol->extend_ino->i_mutex); |
1438 | mref = ntfs_lookup_inode_by_name(NTFS_I(vol->extend_ino), UsnJrnl, 8, | 1436 | mref = ntfs_lookup_inode_by_name(NTFS_I(vol->extend_ino), UsnJrnl, 8, |
1439 | &name); | 1437 | &name); |
1440 | mutex_unlock(&vol->extend_ino->i_mutex); | 1438 | mutex_unlock(&vol->extend_ino->i_mutex); |
1441 | if (IS_ERR_MREF(mref)) { | 1439 | if (IS_ERR_MREF(mref)) { |
1442 | /* | 1440 | /* |
1443 | * If the file does not exist, transaction logging is disabled, | 1441 | * If the file does not exist, transaction logging is disabled, |
1444 | * just return success. | 1442 | * just return success. |
1445 | */ | 1443 | */ |
1446 | if (MREF_ERR(mref) == -ENOENT) { | 1444 | if (MREF_ERR(mref) == -ENOENT) { |
1447 | ntfs_debug("$UsnJrnl not present. Volume does not " | 1445 | ntfs_debug("$UsnJrnl not present. Volume does not " |
1448 | "have transaction logging enabled."); | 1446 | "have transaction logging enabled."); |
1449 | not_enabled: | 1447 | not_enabled: |
1450 | /* | 1448 | /* |
1451 | * No need to try to stamp the transaction log if | 1449 | * No need to try to stamp the transaction log if |
1452 | * transaction logging is not enabled. | 1450 | * transaction logging is not enabled. |
1453 | */ | 1451 | */ |
1454 | NVolSetUsnJrnlStamped(vol); | 1452 | NVolSetUsnJrnlStamped(vol); |
1455 | return true; | 1453 | return true; |
1456 | } | 1454 | } |
1457 | /* A real error occurred. */ | 1455 | /* A real error occurred. */ |
1458 | ntfs_error(vol->sb, "Failed to find inode number for " | 1456 | ntfs_error(vol->sb, "Failed to find inode number for " |
1459 | "$UsnJrnl."); | 1457 | "$UsnJrnl."); |
1460 | return false; | 1458 | return false; |
1461 | } | 1459 | } |
1462 | /* We do not care for the type of match that was found. */ | 1460 | /* We do not care for the type of match that was found. */ |
1463 | kfree(name); | 1461 | kfree(name); |
1464 | /* Get the inode. */ | 1462 | /* Get the inode. */ |
1465 | tmp_ino = ntfs_iget(vol->sb, MREF(mref)); | 1463 | tmp_ino = ntfs_iget(vol->sb, MREF(mref)); |
1466 | if (unlikely(IS_ERR(tmp_ino) || is_bad_inode(tmp_ino))) { | 1464 | if (unlikely(IS_ERR(tmp_ino) || is_bad_inode(tmp_ino))) { |
1467 | if (!IS_ERR(tmp_ino)) | 1465 | if (!IS_ERR(tmp_ino)) |
1468 | iput(tmp_ino); | 1466 | iput(tmp_ino); |
1469 | ntfs_error(vol->sb, "Failed to load $UsnJrnl."); | 1467 | ntfs_error(vol->sb, "Failed to load $UsnJrnl."); |
1470 | return false; | 1468 | return false; |
1471 | } | 1469 | } |
1472 | vol->usnjrnl_ino = tmp_ino; | 1470 | vol->usnjrnl_ino = tmp_ino; |
1473 | /* | 1471 | /* |
1474 | * If the transaction log is in the process of being deleted, we can | 1472 | * If the transaction log is in the process of being deleted, we can |
1475 | * ignore it. | 1473 | * ignore it. |
1476 | */ | 1474 | */ |
1477 | if (unlikely(vol->vol_flags & VOLUME_DELETE_USN_UNDERWAY)) { | 1475 | if (unlikely(vol->vol_flags & VOLUME_DELETE_USN_UNDERWAY)) { |
1478 | ntfs_debug("$UsnJrnl in the process of being disabled. " | 1476 | ntfs_debug("$UsnJrnl in the process of being disabled. " |
1479 | "Volume does not have transaction logging " | 1477 | "Volume does not have transaction logging " |
1480 | "enabled."); | 1478 | "enabled."); |
1481 | goto not_enabled; | 1479 | goto not_enabled; |
1482 | } | 1480 | } |
1483 | /* Get the $DATA/$Max attribute. */ | 1481 | /* Get the $DATA/$Max attribute. */ |
1484 | tmp_ino = ntfs_attr_iget(vol->usnjrnl_ino, AT_DATA, Max, 4); | 1482 | tmp_ino = ntfs_attr_iget(vol->usnjrnl_ino, AT_DATA, Max, 4); |
1485 | if (IS_ERR(tmp_ino)) { | 1483 | if (IS_ERR(tmp_ino)) { |
1486 | ntfs_error(vol->sb, "Failed to load $UsnJrnl/$DATA/$Max " | 1484 | ntfs_error(vol->sb, "Failed to load $UsnJrnl/$DATA/$Max " |
1487 | "attribute."); | 1485 | "attribute."); |
1488 | return false; | 1486 | return false; |
1489 | } | 1487 | } |
1490 | vol->usnjrnl_max_ino = tmp_ino; | 1488 | vol->usnjrnl_max_ino = tmp_ino; |
1491 | if (unlikely(i_size_read(tmp_ino) < sizeof(USN_HEADER))) { | 1489 | if (unlikely(i_size_read(tmp_ino) < sizeof(USN_HEADER))) { |
1492 | ntfs_error(vol->sb, "Found corrupt $UsnJrnl/$DATA/$Max " | 1490 | ntfs_error(vol->sb, "Found corrupt $UsnJrnl/$DATA/$Max " |
1493 | "attribute (size is 0x%llx but should be at " | 1491 | "attribute (size is 0x%llx but should be at " |
1494 | "least 0x%zx bytes).", i_size_read(tmp_ino), | 1492 | "least 0x%zx bytes).", i_size_read(tmp_ino), |
1495 | sizeof(USN_HEADER)); | 1493 | sizeof(USN_HEADER)); |
1496 | return false; | 1494 | return false; |
1497 | } | 1495 | } |
1498 | /* Get the $DATA/$J attribute. */ | 1496 | /* Get the $DATA/$J attribute. */ |
1499 | tmp_ino = ntfs_attr_iget(vol->usnjrnl_ino, AT_DATA, J, 2); | 1497 | tmp_ino = ntfs_attr_iget(vol->usnjrnl_ino, AT_DATA, J, 2); |
1500 | if (IS_ERR(tmp_ino)) { | 1498 | if (IS_ERR(tmp_ino)) { |
1501 | ntfs_error(vol->sb, "Failed to load $UsnJrnl/$DATA/$J " | 1499 | ntfs_error(vol->sb, "Failed to load $UsnJrnl/$DATA/$J " |
1502 | "attribute."); | 1500 | "attribute."); |
1503 | return false; | 1501 | return false; |
1504 | } | 1502 | } |
1505 | vol->usnjrnl_j_ino = tmp_ino; | 1503 | vol->usnjrnl_j_ino = tmp_ino; |
1506 | /* Verify $J is non-resident and sparse. */ | 1504 | /* Verify $J is non-resident and sparse. */ |
1507 | tmp_ni = NTFS_I(vol->usnjrnl_j_ino); | 1505 | tmp_ni = NTFS_I(vol->usnjrnl_j_ino); |
1508 | if (unlikely(!NInoNonResident(tmp_ni) || !NInoSparse(tmp_ni))) { | 1506 | if (unlikely(!NInoNonResident(tmp_ni) || !NInoSparse(tmp_ni))) { |
1509 | ntfs_error(vol->sb, "$UsnJrnl/$DATA/$J attribute is resident " | 1507 | ntfs_error(vol->sb, "$UsnJrnl/$DATA/$J attribute is resident " |
1510 | "and/or not sparse."); | 1508 | "and/or not sparse."); |
1511 | return false; | 1509 | return false; |
1512 | } | 1510 | } |
1513 | /* Read the USN_HEADER from $DATA/$Max. */ | 1511 | /* Read the USN_HEADER from $DATA/$Max. */ |
1514 | page = ntfs_map_page(vol->usnjrnl_max_ino->i_mapping, 0); | 1512 | page = ntfs_map_page(vol->usnjrnl_max_ino->i_mapping, 0); |
1515 | if (IS_ERR(page)) { | 1513 | if (IS_ERR(page)) { |
1516 | ntfs_error(vol->sb, "Failed to read from $UsnJrnl/$DATA/$Max " | 1514 | ntfs_error(vol->sb, "Failed to read from $UsnJrnl/$DATA/$Max " |
1517 | "attribute."); | 1515 | "attribute."); |
1518 | return false; | 1516 | return false; |
1519 | } | 1517 | } |
1520 | uh = (USN_HEADER*)page_address(page); | 1518 | uh = (USN_HEADER*)page_address(page); |
1521 | /* Sanity check the $Max. */ | 1519 | /* Sanity check the $Max. */ |
1522 | if (unlikely(sle64_to_cpu(uh->allocation_delta) > | 1520 | if (unlikely(sle64_to_cpu(uh->allocation_delta) > |
1523 | sle64_to_cpu(uh->maximum_size))) { | 1521 | sle64_to_cpu(uh->maximum_size))) { |
1524 | ntfs_error(vol->sb, "Allocation delta (0x%llx) exceeds " | 1522 | ntfs_error(vol->sb, "Allocation delta (0x%llx) exceeds " |
1525 | "maximum size (0x%llx). $UsnJrnl is corrupt.", | 1523 | "maximum size (0x%llx). $UsnJrnl is corrupt.", |
1526 | (long long)sle64_to_cpu(uh->allocation_delta), | 1524 | (long long)sle64_to_cpu(uh->allocation_delta), |
1527 | (long long)sle64_to_cpu(uh->maximum_size)); | 1525 | (long long)sle64_to_cpu(uh->maximum_size)); |
1528 | ntfs_unmap_page(page); | 1526 | ntfs_unmap_page(page); |
1529 | return false; | 1527 | return false; |
1530 | } | 1528 | } |
1531 | /* | 1529 | /* |
1532 | * If the transaction log has been stamped and nothing has been written | 1530 | * If the transaction log has been stamped and nothing has been written |
1533 | * to it since, we do not need to stamp it. | 1531 | * to it since, we do not need to stamp it. |
1534 | */ | 1532 | */ |
1535 | if (unlikely(sle64_to_cpu(uh->lowest_valid_usn) >= | 1533 | if (unlikely(sle64_to_cpu(uh->lowest_valid_usn) >= |
1536 | i_size_read(vol->usnjrnl_j_ino))) { | 1534 | i_size_read(vol->usnjrnl_j_ino))) { |
1537 | if (likely(sle64_to_cpu(uh->lowest_valid_usn) == | 1535 | if (likely(sle64_to_cpu(uh->lowest_valid_usn) == |
1538 | i_size_read(vol->usnjrnl_j_ino))) { | 1536 | i_size_read(vol->usnjrnl_j_ino))) { |
1539 | ntfs_unmap_page(page); | 1537 | ntfs_unmap_page(page); |
1540 | ntfs_debug("$UsnJrnl is enabled but nothing has been " | 1538 | ntfs_debug("$UsnJrnl is enabled but nothing has been " |
1541 | "logged since it was last stamped. " | 1539 | "logged since it was last stamped. " |
1542 | "Treating this as if the volume does " | 1540 | "Treating this as if the volume does " |
1543 | "not have transaction logging " | 1541 | "not have transaction logging " |
1544 | "enabled."); | 1542 | "enabled."); |
1545 | goto not_enabled; | 1543 | goto not_enabled; |
1546 | } | 1544 | } |
1547 | ntfs_error(vol->sb, "$UsnJrnl has lowest valid usn (0x%llx) " | 1545 | ntfs_error(vol->sb, "$UsnJrnl has lowest valid usn (0x%llx) " |
1548 | "which is out of bounds (0x%llx). $UsnJrnl " | 1546 | "which is out of bounds (0x%llx). $UsnJrnl " |
1549 | "is corrupt.", | 1547 | "is corrupt.", |
1550 | (long long)sle64_to_cpu(uh->lowest_valid_usn), | 1548 | (long long)sle64_to_cpu(uh->lowest_valid_usn), |
1551 | i_size_read(vol->usnjrnl_j_ino)); | 1549 | i_size_read(vol->usnjrnl_j_ino)); |
1552 | ntfs_unmap_page(page); | 1550 | ntfs_unmap_page(page); |
1553 | return false; | 1551 | return false; |
1554 | } | 1552 | } |
1555 | ntfs_unmap_page(page); | 1553 | ntfs_unmap_page(page); |
1556 | ntfs_debug("Done."); | 1554 | ntfs_debug("Done."); |
1557 | return true; | 1555 | return true; |
1558 | } | 1556 | } |
1559 | 1557 | ||
1560 | /** | 1558 | /** |
1561 | * load_and_init_attrdef - load the attribute definitions table for a volume | 1559 | * load_and_init_attrdef - load the attribute definitions table for a volume |
1562 | * @vol: ntfs super block describing device whose attrdef to load | 1560 | * @vol: ntfs super block describing device whose attrdef to load |
1563 | * | 1561 | * |
1564 | * Return 'true' on success or 'false' on error. | 1562 | * Return 'true' on success or 'false' on error. |
1565 | */ | 1563 | */ |
1566 | static bool load_and_init_attrdef(ntfs_volume *vol) | 1564 | static bool load_and_init_attrdef(ntfs_volume *vol) |
1567 | { | 1565 | { |
1568 | loff_t i_size; | 1566 | loff_t i_size; |
1569 | struct super_block *sb = vol->sb; | 1567 | struct super_block *sb = vol->sb; |
1570 | struct inode *ino; | 1568 | struct inode *ino; |
1571 | struct page *page; | 1569 | struct page *page; |
1572 | pgoff_t index, max_index; | 1570 | pgoff_t index, max_index; |
1573 | unsigned int size; | 1571 | unsigned int size; |
1574 | 1572 | ||
1575 | ntfs_debug("Entering."); | 1573 | ntfs_debug("Entering."); |
1576 | /* Read attrdef table and setup vol->attrdef and vol->attrdef_size. */ | 1574 | /* Read attrdef table and setup vol->attrdef and vol->attrdef_size. */ |
1577 | ino = ntfs_iget(sb, FILE_AttrDef); | 1575 | ino = ntfs_iget(sb, FILE_AttrDef); |
1578 | if (IS_ERR(ino) || is_bad_inode(ino)) { | 1576 | if (IS_ERR(ino) || is_bad_inode(ino)) { |
1579 | if (!IS_ERR(ino)) | 1577 | if (!IS_ERR(ino)) |
1580 | iput(ino); | 1578 | iput(ino); |
1581 | goto failed; | 1579 | goto failed; |
1582 | } | 1580 | } |
1583 | NInoSetSparseDisabled(NTFS_I(ino)); | 1581 | NInoSetSparseDisabled(NTFS_I(ino)); |
1584 | /* The size of FILE_AttrDef must be above 0 and fit inside 31 bits. */ | 1582 | /* The size of FILE_AttrDef must be above 0 and fit inside 31 bits. */ |
1585 | i_size = i_size_read(ino); | 1583 | i_size = i_size_read(ino); |
1586 | if (i_size <= 0 || i_size > 0x7fffffff) | 1584 | if (i_size <= 0 || i_size > 0x7fffffff) |
1587 | goto iput_failed; | 1585 | goto iput_failed; |
1588 | vol->attrdef = (ATTR_DEF*)ntfs_malloc_nofs(i_size); | 1586 | vol->attrdef = (ATTR_DEF*)ntfs_malloc_nofs(i_size); |
1589 | if (!vol->attrdef) | 1587 | if (!vol->attrdef) |
1590 | goto iput_failed; | 1588 | goto iput_failed; |
1591 | index = 0; | 1589 | index = 0; |
1592 | max_index = i_size >> PAGE_CACHE_SHIFT; | 1590 | max_index = i_size >> PAGE_CACHE_SHIFT; |
1593 | size = PAGE_CACHE_SIZE; | 1591 | size = PAGE_CACHE_SIZE; |
1594 | while (index < max_index) { | 1592 | while (index < max_index) { |
1595 | /* Read the attrdef table and copy it into the linear buffer. */ | 1593 | /* Read the attrdef table and copy it into the linear buffer. */ |
1596 | read_partial_attrdef_page: | 1594 | read_partial_attrdef_page: |
1597 | page = ntfs_map_page(ino->i_mapping, index); | 1595 | page = ntfs_map_page(ino->i_mapping, index); |
1598 | if (IS_ERR(page)) | 1596 | if (IS_ERR(page)) |
1599 | goto free_iput_failed; | 1597 | goto free_iput_failed; |
1600 | memcpy((u8*)vol->attrdef + (index++ << PAGE_CACHE_SHIFT), | 1598 | memcpy((u8*)vol->attrdef + (index++ << PAGE_CACHE_SHIFT), |
1601 | page_address(page), size); | 1599 | page_address(page), size); |
1602 | ntfs_unmap_page(page); | 1600 | ntfs_unmap_page(page); |
1603 | }; | 1601 | }; |
1604 | if (size == PAGE_CACHE_SIZE) { | 1602 | if (size == PAGE_CACHE_SIZE) { |
1605 | size = i_size & ~PAGE_CACHE_MASK; | 1603 | size = i_size & ~PAGE_CACHE_MASK; |
1606 | if (size) | 1604 | if (size) |
1607 | goto read_partial_attrdef_page; | 1605 | goto read_partial_attrdef_page; |
1608 | } | 1606 | } |
1609 | vol->attrdef_size = i_size; | 1607 | vol->attrdef_size = i_size; |
1610 | ntfs_debug("Read %llu bytes from $AttrDef.", i_size); | 1608 | ntfs_debug("Read %llu bytes from $AttrDef.", i_size); |
1611 | iput(ino); | 1609 | iput(ino); |
1612 | return true; | 1610 | return true; |
1613 | free_iput_failed: | 1611 | free_iput_failed: |
1614 | ntfs_free(vol->attrdef); | 1612 | ntfs_free(vol->attrdef); |
1615 | vol->attrdef = NULL; | 1613 | vol->attrdef = NULL; |
1616 | iput_failed: | 1614 | iput_failed: |
1617 | iput(ino); | 1615 | iput(ino); |
1618 | failed: | 1616 | failed: |
1619 | ntfs_error(sb, "Failed to initialize attribute definition table."); | 1617 | ntfs_error(sb, "Failed to initialize attribute definition table."); |
1620 | return false; | 1618 | return false; |
1621 | } | 1619 | } |
1622 | 1620 | ||
1623 | #endif /* NTFS_RW */ | 1621 | #endif /* NTFS_RW */ |
1624 | 1622 | ||
1625 | /** | 1623 | /** |
1626 | * load_and_init_upcase - load the upcase table for an ntfs volume | 1624 | * load_and_init_upcase - load the upcase table for an ntfs volume |
1627 | * @vol: ntfs super block describing device whose upcase to load | 1625 | * @vol: ntfs super block describing device whose upcase to load |
1628 | * | 1626 | * |
1629 | * Return 'true' on success or 'false' on error. | 1627 | * Return 'true' on success or 'false' on error. |
1630 | */ | 1628 | */ |
1631 | static bool load_and_init_upcase(ntfs_volume *vol) | 1629 | static bool load_and_init_upcase(ntfs_volume *vol) |
1632 | { | 1630 | { |
1633 | loff_t i_size; | 1631 | loff_t i_size; |
1634 | struct super_block *sb = vol->sb; | 1632 | struct super_block *sb = vol->sb; |
1635 | struct inode *ino; | 1633 | struct inode *ino; |
1636 | struct page *page; | 1634 | struct page *page; |
1637 | pgoff_t index, max_index; | 1635 | pgoff_t index, max_index; |
1638 | unsigned int size; | 1636 | unsigned int size; |
1639 | int i, max; | 1637 | int i, max; |
1640 | 1638 | ||
1641 | ntfs_debug("Entering."); | 1639 | ntfs_debug("Entering."); |
1642 | /* Read upcase table and setup vol->upcase and vol->upcase_len. */ | 1640 | /* Read upcase table and setup vol->upcase and vol->upcase_len. */ |
1643 | ino = ntfs_iget(sb, FILE_UpCase); | 1641 | ino = ntfs_iget(sb, FILE_UpCase); |
1644 | if (IS_ERR(ino) || is_bad_inode(ino)) { | 1642 | if (IS_ERR(ino) || is_bad_inode(ino)) { |
1645 | if (!IS_ERR(ino)) | 1643 | if (!IS_ERR(ino)) |
1646 | iput(ino); | 1644 | iput(ino); |
1647 | goto upcase_failed; | 1645 | goto upcase_failed; |
1648 | } | 1646 | } |
1649 | /* | 1647 | /* |
1650 | * The upcase size must not be above 64k Unicode characters, must not | 1648 | * The upcase size must not be above 64k Unicode characters, must not |
1651 | * be zero and must be a multiple of sizeof(ntfschar). | 1649 | * be zero and must be a multiple of sizeof(ntfschar). |
1652 | */ | 1650 | */ |
1653 | i_size = i_size_read(ino); | 1651 | i_size = i_size_read(ino); |
1654 | if (!i_size || i_size & (sizeof(ntfschar) - 1) || | 1652 | if (!i_size || i_size & (sizeof(ntfschar) - 1) || |
1655 | i_size > 64ULL * 1024 * sizeof(ntfschar)) | 1653 | i_size > 64ULL * 1024 * sizeof(ntfschar)) |
1656 | goto iput_upcase_failed; | 1654 | goto iput_upcase_failed; |
1657 | vol->upcase = (ntfschar*)ntfs_malloc_nofs(i_size); | 1655 | vol->upcase = (ntfschar*)ntfs_malloc_nofs(i_size); |
1658 | if (!vol->upcase) | 1656 | if (!vol->upcase) |
1659 | goto iput_upcase_failed; | 1657 | goto iput_upcase_failed; |
1660 | index = 0; | 1658 | index = 0; |
1661 | max_index = i_size >> PAGE_CACHE_SHIFT; | 1659 | max_index = i_size >> PAGE_CACHE_SHIFT; |
1662 | size = PAGE_CACHE_SIZE; | 1660 | size = PAGE_CACHE_SIZE; |
1663 | while (index < max_index) { | 1661 | while (index < max_index) { |
1664 | /* Read the upcase table and copy it into the linear buffer. */ | 1662 | /* Read the upcase table and copy it into the linear buffer. */ |
1665 | read_partial_upcase_page: | 1663 | read_partial_upcase_page: |
1666 | page = ntfs_map_page(ino->i_mapping, index); | 1664 | page = ntfs_map_page(ino->i_mapping, index); |
1667 | if (IS_ERR(page)) | 1665 | if (IS_ERR(page)) |
1668 | goto iput_upcase_failed; | 1666 | goto iput_upcase_failed; |
1669 | memcpy((char*)vol->upcase + (index++ << PAGE_CACHE_SHIFT), | 1667 | memcpy((char*)vol->upcase + (index++ << PAGE_CACHE_SHIFT), |
1670 | page_address(page), size); | 1668 | page_address(page), size); |
1671 | ntfs_unmap_page(page); | 1669 | ntfs_unmap_page(page); |
1672 | }; | 1670 | }; |
1673 | if (size == PAGE_CACHE_SIZE) { | 1671 | if (size == PAGE_CACHE_SIZE) { |
1674 | size = i_size & ~PAGE_CACHE_MASK; | 1672 | size = i_size & ~PAGE_CACHE_MASK; |
1675 | if (size) | 1673 | if (size) |
1676 | goto read_partial_upcase_page; | 1674 | goto read_partial_upcase_page; |
1677 | } | 1675 | } |
1678 | vol->upcase_len = i_size >> UCHAR_T_SIZE_BITS; | 1676 | vol->upcase_len = i_size >> UCHAR_T_SIZE_BITS; |
1679 | ntfs_debug("Read %llu bytes from $UpCase (expected %zu bytes).", | 1677 | ntfs_debug("Read %llu bytes from $UpCase (expected %zu bytes).", |
1680 | i_size, 64 * 1024 * sizeof(ntfschar)); | 1678 | i_size, 64 * 1024 * sizeof(ntfschar)); |
1681 | iput(ino); | 1679 | iput(ino); |
1682 | mutex_lock(&ntfs_lock); | 1680 | mutex_lock(&ntfs_lock); |
1683 | if (!default_upcase) { | 1681 | if (!default_upcase) { |
1684 | ntfs_debug("Using volume specified $UpCase since default is " | 1682 | ntfs_debug("Using volume specified $UpCase since default is " |
1685 | "not present."); | 1683 | "not present."); |
1686 | mutex_unlock(&ntfs_lock); | 1684 | mutex_unlock(&ntfs_lock); |
1687 | return true; | 1685 | return true; |
1688 | } | 1686 | } |
1689 | max = default_upcase_len; | 1687 | max = default_upcase_len; |
1690 | if (max > vol->upcase_len) | 1688 | if (max > vol->upcase_len) |
1691 | max = vol->upcase_len; | 1689 | max = vol->upcase_len; |
1692 | for (i = 0; i < max; i++) | 1690 | for (i = 0; i < max; i++) |
1693 | if (vol->upcase[i] != default_upcase[i]) | 1691 | if (vol->upcase[i] != default_upcase[i]) |
1694 | break; | 1692 | break; |
1695 | if (i == max) { | 1693 | if (i == max) { |
1696 | ntfs_free(vol->upcase); | 1694 | ntfs_free(vol->upcase); |
1697 | vol->upcase = default_upcase; | 1695 | vol->upcase = default_upcase; |
1698 | vol->upcase_len = max; | 1696 | vol->upcase_len = max; |
1699 | ntfs_nr_upcase_users++; | 1697 | ntfs_nr_upcase_users++; |
1700 | mutex_unlock(&ntfs_lock); | 1698 | mutex_unlock(&ntfs_lock); |
1701 | ntfs_debug("Volume specified $UpCase matches default. Using " | 1699 | ntfs_debug("Volume specified $UpCase matches default. Using " |
1702 | "default."); | 1700 | "default."); |
1703 | return true; | 1701 | return true; |
1704 | } | 1702 | } |
1705 | mutex_unlock(&ntfs_lock); | 1703 | mutex_unlock(&ntfs_lock); |
1706 | ntfs_debug("Using volume specified $UpCase since it does not match " | 1704 | ntfs_debug("Using volume specified $UpCase since it does not match " |
1707 | "the default."); | 1705 | "the default."); |
1708 | return true; | 1706 | return true; |
1709 | iput_upcase_failed: | 1707 | iput_upcase_failed: |
1710 | iput(ino); | 1708 | iput(ino); |
1711 | ntfs_free(vol->upcase); | 1709 | ntfs_free(vol->upcase); |
1712 | vol->upcase = NULL; | 1710 | vol->upcase = NULL; |
1713 | upcase_failed: | 1711 | upcase_failed: |
1714 | mutex_lock(&ntfs_lock); | 1712 | mutex_lock(&ntfs_lock); |
1715 | if (default_upcase) { | 1713 | if (default_upcase) { |
1716 | vol->upcase = default_upcase; | 1714 | vol->upcase = default_upcase; |
1717 | vol->upcase_len = default_upcase_len; | 1715 | vol->upcase_len = default_upcase_len; |
1718 | ntfs_nr_upcase_users++; | 1716 | ntfs_nr_upcase_users++; |
1719 | mutex_unlock(&ntfs_lock); | 1717 | mutex_unlock(&ntfs_lock); |
1720 | ntfs_error(sb, "Failed to load $UpCase from the volume. Using " | 1718 | ntfs_error(sb, "Failed to load $UpCase from the volume. Using " |
1721 | "default."); | 1719 | "default."); |
1722 | return true; | 1720 | return true; |
1723 | } | 1721 | } |
1724 | mutex_unlock(&ntfs_lock); | 1722 | mutex_unlock(&ntfs_lock); |
1725 | ntfs_error(sb, "Failed to initialize upcase table."); | 1723 | ntfs_error(sb, "Failed to initialize upcase table."); |
1726 | return false; | 1724 | return false; |
1727 | } | 1725 | } |
1728 | 1726 | ||
1729 | /* | 1727 | /* |
1730 | * The lcn and mft bitmap inodes are NTFS-internal inodes with | 1728 | * The lcn and mft bitmap inodes are NTFS-internal inodes with |
1731 | * their own special locking rules: | 1729 | * their own special locking rules: |
1732 | */ | 1730 | */ |
1733 | static struct lock_class_key | 1731 | static struct lock_class_key |
1734 | lcnbmp_runlist_lock_key, lcnbmp_mrec_lock_key, | 1732 | lcnbmp_runlist_lock_key, lcnbmp_mrec_lock_key, |
1735 | mftbmp_runlist_lock_key, mftbmp_mrec_lock_key; | 1733 | mftbmp_runlist_lock_key, mftbmp_mrec_lock_key; |
1736 | 1734 | ||
1737 | /** | 1735 | /** |
1738 | * load_system_files - open the system files using normal functions | 1736 | * load_system_files - open the system files using normal functions |
1739 | * @vol: ntfs super block describing device whose system files to load | 1737 | * @vol: ntfs super block describing device whose system files to load |
1740 | * | 1738 | * |
1741 | * Open the system files with normal access functions and complete setting up | 1739 | * Open the system files with normal access functions and complete setting up |
1742 | * the ntfs super block @vol. | 1740 | * the ntfs super block @vol. |
1743 | * | 1741 | * |
1744 | * Return 'true' on success or 'false' on error. | 1742 | * Return 'true' on success or 'false' on error. |
1745 | */ | 1743 | */ |
1746 | static bool load_system_files(ntfs_volume *vol) | 1744 | static bool load_system_files(ntfs_volume *vol) |
1747 | { | 1745 | { |
1748 | struct super_block *sb = vol->sb; | 1746 | struct super_block *sb = vol->sb; |
1749 | MFT_RECORD *m; | 1747 | MFT_RECORD *m; |
1750 | VOLUME_INFORMATION *vi; | 1748 | VOLUME_INFORMATION *vi; |
1751 | ntfs_attr_search_ctx *ctx; | 1749 | ntfs_attr_search_ctx *ctx; |
1752 | #ifdef NTFS_RW | 1750 | #ifdef NTFS_RW |
1753 | RESTART_PAGE_HEADER *rp; | 1751 | RESTART_PAGE_HEADER *rp; |
1754 | int err; | 1752 | int err; |
1755 | #endif /* NTFS_RW */ | 1753 | #endif /* NTFS_RW */ |
1756 | 1754 | ||
1757 | ntfs_debug("Entering."); | 1755 | ntfs_debug("Entering."); |
1758 | #ifdef NTFS_RW | 1756 | #ifdef NTFS_RW |
1759 | /* Get mft mirror inode compare the contents of $MFT and $MFTMirr. */ | 1757 | /* Get mft mirror inode compare the contents of $MFT and $MFTMirr. */ |
1760 | if (!load_and_init_mft_mirror(vol) || !check_mft_mirror(vol)) { | 1758 | if (!load_and_init_mft_mirror(vol) || !check_mft_mirror(vol)) { |
1761 | static const char *es1 = "Failed to load $MFTMirr"; | 1759 | static const char *es1 = "Failed to load $MFTMirr"; |
1762 | static const char *es2 = "$MFTMirr does not match $MFT"; | 1760 | static const char *es2 = "$MFTMirr does not match $MFT"; |
1763 | static const char *es3 = ". Run ntfsfix and/or chkdsk."; | 1761 | static const char *es3 = ". Run ntfsfix and/or chkdsk."; |
1764 | 1762 | ||
1765 | /* If a read-write mount, convert it to a read-only mount. */ | 1763 | /* If a read-write mount, convert it to a read-only mount. */ |
1766 | if (!(sb->s_flags & MS_RDONLY)) { | 1764 | if (!(sb->s_flags & MS_RDONLY)) { |
1767 | if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO | | 1765 | if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO | |
1768 | ON_ERRORS_CONTINUE))) { | 1766 | ON_ERRORS_CONTINUE))) { |
1769 | ntfs_error(sb, "%s and neither on_errors=" | 1767 | ntfs_error(sb, "%s and neither on_errors=" |
1770 | "continue nor on_errors=" | 1768 | "continue nor on_errors=" |
1771 | "remount-ro was specified%s", | 1769 | "remount-ro was specified%s", |
1772 | !vol->mftmirr_ino ? es1 : es2, | 1770 | !vol->mftmirr_ino ? es1 : es2, |
1773 | es3); | 1771 | es3); |
1774 | goto iput_mirr_err_out; | 1772 | goto iput_mirr_err_out; |
1775 | } | 1773 | } |
1776 | sb->s_flags |= MS_RDONLY; | 1774 | sb->s_flags |= MS_RDONLY; |
1777 | ntfs_error(sb, "%s. Mounting read-only%s", | 1775 | ntfs_error(sb, "%s. Mounting read-only%s", |
1778 | !vol->mftmirr_ino ? es1 : es2, es3); | 1776 | !vol->mftmirr_ino ? es1 : es2, es3); |
1779 | } else | 1777 | } else |
1780 | ntfs_warning(sb, "%s. Will not be able to remount " | 1778 | ntfs_warning(sb, "%s. Will not be able to remount " |
1781 | "read-write%s", | 1779 | "read-write%s", |
1782 | !vol->mftmirr_ino ? es1 : es2, es3); | 1780 | !vol->mftmirr_ino ? es1 : es2, es3); |
1783 | /* This will prevent a read-write remount. */ | 1781 | /* This will prevent a read-write remount. */ |
1784 | NVolSetErrors(vol); | 1782 | NVolSetErrors(vol); |
1785 | } | 1783 | } |
1786 | #endif /* NTFS_RW */ | 1784 | #endif /* NTFS_RW */ |
1787 | /* Get mft bitmap attribute inode. */ | 1785 | /* Get mft bitmap attribute inode. */ |
1788 | vol->mftbmp_ino = ntfs_attr_iget(vol->mft_ino, AT_BITMAP, NULL, 0); | 1786 | vol->mftbmp_ino = ntfs_attr_iget(vol->mft_ino, AT_BITMAP, NULL, 0); |
1789 | if (IS_ERR(vol->mftbmp_ino)) { | 1787 | if (IS_ERR(vol->mftbmp_ino)) { |
1790 | ntfs_error(sb, "Failed to load $MFT/$BITMAP attribute."); | 1788 | ntfs_error(sb, "Failed to load $MFT/$BITMAP attribute."); |
1791 | goto iput_mirr_err_out; | 1789 | goto iput_mirr_err_out; |
1792 | } | 1790 | } |
1793 | lockdep_set_class(&NTFS_I(vol->mftbmp_ino)->runlist.lock, | 1791 | lockdep_set_class(&NTFS_I(vol->mftbmp_ino)->runlist.lock, |
1794 | &mftbmp_runlist_lock_key); | 1792 | &mftbmp_runlist_lock_key); |
1795 | lockdep_set_class(&NTFS_I(vol->mftbmp_ino)->mrec_lock, | 1793 | lockdep_set_class(&NTFS_I(vol->mftbmp_ino)->mrec_lock, |
1796 | &mftbmp_mrec_lock_key); | 1794 | &mftbmp_mrec_lock_key); |
1797 | /* Read upcase table and setup @vol->upcase and @vol->upcase_len. */ | 1795 | /* Read upcase table and setup @vol->upcase and @vol->upcase_len. */ |
1798 | if (!load_and_init_upcase(vol)) | 1796 | if (!load_and_init_upcase(vol)) |
1799 | goto iput_mftbmp_err_out; | 1797 | goto iput_mftbmp_err_out; |
1800 | #ifdef NTFS_RW | 1798 | #ifdef NTFS_RW |
1801 | /* | 1799 | /* |
1802 | * Read attribute definitions table and setup @vol->attrdef and | 1800 | * Read attribute definitions table and setup @vol->attrdef and |
1803 | * @vol->attrdef_size. | 1801 | * @vol->attrdef_size. |
1804 | */ | 1802 | */ |
1805 | if (!load_and_init_attrdef(vol)) | 1803 | if (!load_and_init_attrdef(vol)) |
1806 | goto iput_upcase_err_out; | 1804 | goto iput_upcase_err_out; |
1807 | #endif /* NTFS_RW */ | 1805 | #endif /* NTFS_RW */ |
1808 | /* | 1806 | /* |
1809 | * Get the cluster allocation bitmap inode and verify the size, no | 1807 | * Get the cluster allocation bitmap inode and verify the size, no |
1810 | * need for any locking at this stage as we are already running | 1808 | * need for any locking at this stage as we are already running |
1811 | * exclusively as we are mount in progress task. | 1809 | * exclusively as we are mount in progress task. |
1812 | */ | 1810 | */ |
1813 | vol->lcnbmp_ino = ntfs_iget(sb, FILE_Bitmap); | 1811 | vol->lcnbmp_ino = ntfs_iget(sb, FILE_Bitmap); |
1814 | if (IS_ERR(vol->lcnbmp_ino) || is_bad_inode(vol->lcnbmp_ino)) { | 1812 | if (IS_ERR(vol->lcnbmp_ino) || is_bad_inode(vol->lcnbmp_ino)) { |
1815 | if (!IS_ERR(vol->lcnbmp_ino)) | 1813 | if (!IS_ERR(vol->lcnbmp_ino)) |
1816 | iput(vol->lcnbmp_ino); | 1814 | iput(vol->lcnbmp_ino); |
1817 | goto bitmap_failed; | 1815 | goto bitmap_failed; |
1818 | } | 1816 | } |
1819 | lockdep_set_class(&NTFS_I(vol->lcnbmp_ino)->runlist.lock, | 1817 | lockdep_set_class(&NTFS_I(vol->lcnbmp_ino)->runlist.lock, |
1820 | &lcnbmp_runlist_lock_key); | 1818 | &lcnbmp_runlist_lock_key); |
1821 | lockdep_set_class(&NTFS_I(vol->lcnbmp_ino)->mrec_lock, | 1819 | lockdep_set_class(&NTFS_I(vol->lcnbmp_ino)->mrec_lock, |
1822 | &lcnbmp_mrec_lock_key); | 1820 | &lcnbmp_mrec_lock_key); |
1823 | 1821 | ||
1824 | NInoSetSparseDisabled(NTFS_I(vol->lcnbmp_ino)); | 1822 | NInoSetSparseDisabled(NTFS_I(vol->lcnbmp_ino)); |
1825 | if ((vol->nr_clusters + 7) >> 3 > i_size_read(vol->lcnbmp_ino)) { | 1823 | if ((vol->nr_clusters + 7) >> 3 > i_size_read(vol->lcnbmp_ino)) { |
1826 | iput(vol->lcnbmp_ino); | 1824 | iput(vol->lcnbmp_ino); |
1827 | bitmap_failed: | 1825 | bitmap_failed: |
1828 | ntfs_error(sb, "Failed to load $Bitmap."); | 1826 | ntfs_error(sb, "Failed to load $Bitmap."); |
1829 | goto iput_attrdef_err_out; | 1827 | goto iput_attrdef_err_out; |
1830 | } | 1828 | } |
1831 | /* | 1829 | /* |
1832 | * Get the volume inode and setup our cache of the volume flags and | 1830 | * Get the volume inode and setup our cache of the volume flags and |
1833 | * version. | 1831 | * version. |
1834 | */ | 1832 | */ |
1835 | vol->vol_ino = ntfs_iget(sb, FILE_Volume); | 1833 | vol->vol_ino = ntfs_iget(sb, FILE_Volume); |
1836 | if (IS_ERR(vol->vol_ino) || is_bad_inode(vol->vol_ino)) { | 1834 | if (IS_ERR(vol->vol_ino) || is_bad_inode(vol->vol_ino)) { |
1837 | if (!IS_ERR(vol->vol_ino)) | 1835 | if (!IS_ERR(vol->vol_ino)) |
1838 | iput(vol->vol_ino); | 1836 | iput(vol->vol_ino); |
1839 | volume_failed: | 1837 | volume_failed: |
1840 | ntfs_error(sb, "Failed to load $Volume."); | 1838 | ntfs_error(sb, "Failed to load $Volume."); |
1841 | goto iput_lcnbmp_err_out; | 1839 | goto iput_lcnbmp_err_out; |
1842 | } | 1840 | } |
1843 | m = map_mft_record(NTFS_I(vol->vol_ino)); | 1841 | m = map_mft_record(NTFS_I(vol->vol_ino)); |
1844 | if (IS_ERR(m)) { | 1842 | if (IS_ERR(m)) { |
1845 | iput_volume_failed: | 1843 | iput_volume_failed: |
1846 | iput(vol->vol_ino); | 1844 | iput(vol->vol_ino); |
1847 | goto volume_failed; | 1845 | goto volume_failed; |
1848 | } | 1846 | } |
1849 | if (!(ctx = ntfs_attr_get_search_ctx(NTFS_I(vol->vol_ino), m))) { | 1847 | if (!(ctx = ntfs_attr_get_search_ctx(NTFS_I(vol->vol_ino), m))) { |
1850 | ntfs_error(sb, "Failed to get attribute search context."); | 1848 | ntfs_error(sb, "Failed to get attribute search context."); |
1851 | goto get_ctx_vol_failed; | 1849 | goto get_ctx_vol_failed; |
1852 | } | 1850 | } |
1853 | if (ntfs_attr_lookup(AT_VOLUME_INFORMATION, NULL, 0, 0, 0, NULL, 0, | 1851 | if (ntfs_attr_lookup(AT_VOLUME_INFORMATION, NULL, 0, 0, 0, NULL, 0, |
1854 | ctx) || ctx->attr->non_resident || ctx->attr->flags) { | 1852 | ctx) || ctx->attr->non_resident || ctx->attr->flags) { |
1855 | err_put_vol: | 1853 | err_put_vol: |
1856 | ntfs_attr_put_search_ctx(ctx); | 1854 | ntfs_attr_put_search_ctx(ctx); |
1857 | get_ctx_vol_failed: | 1855 | get_ctx_vol_failed: |
1858 | unmap_mft_record(NTFS_I(vol->vol_ino)); | 1856 | unmap_mft_record(NTFS_I(vol->vol_ino)); |
1859 | goto iput_volume_failed; | 1857 | goto iput_volume_failed; |
1860 | } | 1858 | } |
1861 | vi = (VOLUME_INFORMATION*)((char*)ctx->attr + | 1859 | vi = (VOLUME_INFORMATION*)((char*)ctx->attr + |
1862 | le16_to_cpu(ctx->attr->data.resident.value_offset)); | 1860 | le16_to_cpu(ctx->attr->data.resident.value_offset)); |
1863 | /* Some bounds checks. */ | 1861 | /* Some bounds checks. */ |
1864 | if ((u8*)vi < (u8*)ctx->attr || (u8*)vi + | 1862 | if ((u8*)vi < (u8*)ctx->attr || (u8*)vi + |
1865 | le32_to_cpu(ctx->attr->data.resident.value_length) > | 1863 | le32_to_cpu(ctx->attr->data.resident.value_length) > |
1866 | (u8*)ctx->attr + le32_to_cpu(ctx->attr->length)) | 1864 | (u8*)ctx->attr + le32_to_cpu(ctx->attr->length)) |
1867 | goto err_put_vol; | 1865 | goto err_put_vol; |
1868 | /* Copy the volume flags and version to the ntfs_volume structure. */ | 1866 | /* Copy the volume flags and version to the ntfs_volume structure. */ |
1869 | vol->vol_flags = vi->flags; | 1867 | vol->vol_flags = vi->flags; |
1870 | vol->major_ver = vi->major_ver; | 1868 | vol->major_ver = vi->major_ver; |
1871 | vol->minor_ver = vi->minor_ver; | 1869 | vol->minor_ver = vi->minor_ver; |
1872 | ntfs_attr_put_search_ctx(ctx); | 1870 | ntfs_attr_put_search_ctx(ctx); |
1873 | unmap_mft_record(NTFS_I(vol->vol_ino)); | 1871 | unmap_mft_record(NTFS_I(vol->vol_ino)); |
1874 | printk(KERN_INFO "NTFS volume version %i.%i.\n", vol->major_ver, | 1872 | printk(KERN_INFO "NTFS volume version %i.%i.\n", vol->major_ver, |
1875 | vol->minor_ver); | 1873 | vol->minor_ver); |
1876 | if (vol->major_ver < 3 && NVolSparseEnabled(vol)) { | 1874 | if (vol->major_ver < 3 && NVolSparseEnabled(vol)) { |
1877 | ntfs_warning(vol->sb, "Disabling sparse support due to NTFS " | 1875 | ntfs_warning(vol->sb, "Disabling sparse support due to NTFS " |
1878 | "volume version %i.%i (need at least version " | 1876 | "volume version %i.%i (need at least version " |
1879 | "3.0).", vol->major_ver, vol->minor_ver); | 1877 | "3.0).", vol->major_ver, vol->minor_ver); |
1880 | NVolClearSparseEnabled(vol); | 1878 | NVolClearSparseEnabled(vol); |
1881 | } | 1879 | } |
1882 | #ifdef NTFS_RW | 1880 | #ifdef NTFS_RW |
1883 | /* Make sure that no unsupported volume flags are set. */ | 1881 | /* Make sure that no unsupported volume flags are set. */ |
1884 | if (vol->vol_flags & VOLUME_MUST_MOUNT_RO_MASK) { | 1882 | if (vol->vol_flags & VOLUME_MUST_MOUNT_RO_MASK) { |
1885 | static const char *es1a = "Volume is dirty"; | 1883 | static const char *es1a = "Volume is dirty"; |
1886 | static const char *es1b = "Volume has been modified by chkdsk"; | 1884 | static const char *es1b = "Volume has been modified by chkdsk"; |
1887 | static const char *es1c = "Volume has unsupported flags set"; | 1885 | static const char *es1c = "Volume has unsupported flags set"; |
1888 | static const char *es2a = ". Run chkdsk and mount in Windows."; | 1886 | static const char *es2a = ". Run chkdsk and mount in Windows."; |
1889 | static const char *es2b = ". Mount in Windows."; | 1887 | static const char *es2b = ". Mount in Windows."; |
1890 | const char *es1, *es2; | 1888 | const char *es1, *es2; |
1891 | 1889 | ||
1892 | es2 = es2a; | 1890 | es2 = es2a; |
1893 | if (vol->vol_flags & VOLUME_IS_DIRTY) | 1891 | if (vol->vol_flags & VOLUME_IS_DIRTY) |
1894 | es1 = es1a; | 1892 | es1 = es1a; |
1895 | else if (vol->vol_flags & VOLUME_MODIFIED_BY_CHKDSK) { | 1893 | else if (vol->vol_flags & VOLUME_MODIFIED_BY_CHKDSK) { |
1896 | es1 = es1b; | 1894 | es1 = es1b; |
1897 | es2 = es2b; | 1895 | es2 = es2b; |
1898 | } else { | 1896 | } else { |
1899 | es1 = es1c; | 1897 | es1 = es1c; |
1900 | ntfs_warning(sb, "Unsupported volume flags 0x%x " | 1898 | ntfs_warning(sb, "Unsupported volume flags 0x%x " |
1901 | "encountered.", | 1899 | "encountered.", |
1902 | (unsigned)le16_to_cpu(vol->vol_flags)); | 1900 | (unsigned)le16_to_cpu(vol->vol_flags)); |
1903 | } | 1901 | } |
1904 | /* If a read-write mount, convert it to a read-only mount. */ | 1902 | /* If a read-write mount, convert it to a read-only mount. */ |
1905 | if (!(sb->s_flags & MS_RDONLY)) { | 1903 | if (!(sb->s_flags & MS_RDONLY)) { |
1906 | if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO | | 1904 | if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO | |
1907 | ON_ERRORS_CONTINUE))) { | 1905 | ON_ERRORS_CONTINUE))) { |
1908 | ntfs_error(sb, "%s and neither on_errors=" | 1906 | ntfs_error(sb, "%s and neither on_errors=" |
1909 | "continue nor on_errors=" | 1907 | "continue nor on_errors=" |
1910 | "remount-ro was specified%s", | 1908 | "remount-ro was specified%s", |
1911 | es1, es2); | 1909 | es1, es2); |
1912 | goto iput_vol_err_out; | 1910 | goto iput_vol_err_out; |
1913 | } | 1911 | } |
1914 | sb->s_flags |= MS_RDONLY; | 1912 | sb->s_flags |= MS_RDONLY; |
1915 | ntfs_error(sb, "%s. Mounting read-only%s", es1, es2); | 1913 | ntfs_error(sb, "%s. Mounting read-only%s", es1, es2); |
1916 | } else | 1914 | } else |
1917 | ntfs_warning(sb, "%s. Will not be able to remount " | 1915 | ntfs_warning(sb, "%s. Will not be able to remount " |
1918 | "read-write%s", es1, es2); | 1916 | "read-write%s", es1, es2); |
1919 | /* | 1917 | /* |
1920 | * Do not set NVolErrors() because ntfs_remount() re-checks the | 1918 | * Do not set NVolErrors() because ntfs_remount() re-checks the |
1921 | * flags which we need to do in case any flags have changed. | 1919 | * flags which we need to do in case any flags have changed. |
1922 | */ | 1920 | */ |
1923 | } | 1921 | } |
1924 | /* | 1922 | /* |
1925 | * Get the inode for the logfile, check it and determine if the volume | 1923 | * Get the inode for the logfile, check it and determine if the volume |
1926 | * was shutdown cleanly. | 1924 | * was shutdown cleanly. |
1927 | */ | 1925 | */ |
1928 | rp = NULL; | 1926 | rp = NULL; |
1929 | if (!load_and_check_logfile(vol, &rp) || | 1927 | if (!load_and_check_logfile(vol, &rp) || |
1930 | !ntfs_is_logfile_clean(vol->logfile_ino, rp)) { | 1928 | !ntfs_is_logfile_clean(vol->logfile_ino, rp)) { |
1931 | static const char *es1a = "Failed to load $LogFile"; | 1929 | static const char *es1a = "Failed to load $LogFile"; |
1932 | static const char *es1b = "$LogFile is not clean"; | 1930 | static const char *es1b = "$LogFile is not clean"; |
1933 | static const char *es2 = ". Mount in Windows."; | 1931 | static const char *es2 = ". Mount in Windows."; |
1934 | const char *es1; | 1932 | const char *es1; |
1935 | 1933 | ||
1936 | es1 = !vol->logfile_ino ? es1a : es1b; | 1934 | es1 = !vol->logfile_ino ? es1a : es1b; |
1937 | /* If a read-write mount, convert it to a read-only mount. */ | 1935 | /* If a read-write mount, convert it to a read-only mount. */ |
1938 | if (!(sb->s_flags & MS_RDONLY)) { | 1936 | if (!(sb->s_flags & MS_RDONLY)) { |
1939 | if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO | | 1937 | if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO | |
1940 | ON_ERRORS_CONTINUE))) { | 1938 | ON_ERRORS_CONTINUE))) { |
1941 | ntfs_error(sb, "%s and neither on_errors=" | 1939 | ntfs_error(sb, "%s and neither on_errors=" |
1942 | "continue nor on_errors=" | 1940 | "continue nor on_errors=" |
1943 | "remount-ro was specified%s", | 1941 | "remount-ro was specified%s", |
1944 | es1, es2); | 1942 | es1, es2); |
1945 | if (vol->logfile_ino) { | 1943 | if (vol->logfile_ino) { |
1946 | BUG_ON(!rp); | 1944 | BUG_ON(!rp); |
1947 | ntfs_free(rp); | 1945 | ntfs_free(rp); |
1948 | } | 1946 | } |
1949 | goto iput_logfile_err_out; | 1947 | goto iput_logfile_err_out; |
1950 | } | 1948 | } |
1951 | sb->s_flags |= MS_RDONLY; | 1949 | sb->s_flags |= MS_RDONLY; |
1952 | ntfs_error(sb, "%s. Mounting read-only%s", es1, es2); | 1950 | ntfs_error(sb, "%s. Mounting read-only%s", es1, es2); |
1953 | } else | 1951 | } else |
1954 | ntfs_warning(sb, "%s. Will not be able to remount " | 1952 | ntfs_warning(sb, "%s. Will not be able to remount " |
1955 | "read-write%s", es1, es2); | 1953 | "read-write%s", es1, es2); |
1956 | /* This will prevent a read-write remount. */ | 1954 | /* This will prevent a read-write remount. */ |
1957 | NVolSetErrors(vol); | 1955 | NVolSetErrors(vol); |
1958 | } | 1956 | } |
1959 | ntfs_free(rp); | 1957 | ntfs_free(rp); |
1960 | #endif /* NTFS_RW */ | 1958 | #endif /* NTFS_RW */ |
1961 | /* Get the root directory inode so we can do path lookups. */ | 1959 | /* Get the root directory inode so we can do path lookups. */ |
1962 | vol->root_ino = ntfs_iget(sb, FILE_root); | 1960 | vol->root_ino = ntfs_iget(sb, FILE_root); |
1963 | if (IS_ERR(vol->root_ino) || is_bad_inode(vol->root_ino)) { | 1961 | if (IS_ERR(vol->root_ino) || is_bad_inode(vol->root_ino)) { |
1964 | if (!IS_ERR(vol->root_ino)) | 1962 | if (!IS_ERR(vol->root_ino)) |
1965 | iput(vol->root_ino); | 1963 | iput(vol->root_ino); |
1966 | ntfs_error(sb, "Failed to load root directory."); | 1964 | ntfs_error(sb, "Failed to load root directory."); |
1967 | goto iput_logfile_err_out; | 1965 | goto iput_logfile_err_out; |
1968 | } | 1966 | } |
1969 | #ifdef NTFS_RW | 1967 | #ifdef NTFS_RW |
1970 | /* | 1968 | /* |
1971 | * Check if Windows is suspended to disk on the target volume. If it | 1969 | * Check if Windows is suspended to disk on the target volume. If it |
1972 | * is hibernated, we must not write *anything* to the disk so set | 1970 | * is hibernated, we must not write *anything* to the disk so set |
1973 | * NVolErrors() without setting the dirty volume flag and mount | 1971 | * NVolErrors() without setting the dirty volume flag and mount |
1974 | * read-only. This will prevent read-write remounting and it will also | 1972 | * read-only. This will prevent read-write remounting and it will also |
1975 | * prevent all writes. | 1973 | * prevent all writes. |
1976 | */ | 1974 | */ |
1977 | err = check_windows_hibernation_status(vol); | 1975 | err = check_windows_hibernation_status(vol); |
1978 | if (unlikely(err)) { | 1976 | if (unlikely(err)) { |
1979 | static const char *es1a = "Failed to determine if Windows is " | 1977 | static const char *es1a = "Failed to determine if Windows is " |
1980 | "hibernated"; | 1978 | "hibernated"; |
1981 | static const char *es1b = "Windows is hibernated"; | 1979 | static const char *es1b = "Windows is hibernated"; |
1982 | static const char *es2 = ". Run chkdsk."; | 1980 | static const char *es2 = ". Run chkdsk."; |
1983 | const char *es1; | 1981 | const char *es1; |
1984 | 1982 | ||
1985 | es1 = err < 0 ? es1a : es1b; | 1983 | es1 = err < 0 ? es1a : es1b; |
1986 | /* If a read-write mount, convert it to a read-only mount. */ | 1984 | /* If a read-write mount, convert it to a read-only mount. */ |
1987 | if (!(sb->s_flags & MS_RDONLY)) { | 1985 | if (!(sb->s_flags & MS_RDONLY)) { |
1988 | if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO | | 1986 | if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO | |
1989 | ON_ERRORS_CONTINUE))) { | 1987 | ON_ERRORS_CONTINUE))) { |
1990 | ntfs_error(sb, "%s and neither on_errors=" | 1988 | ntfs_error(sb, "%s and neither on_errors=" |
1991 | "continue nor on_errors=" | 1989 | "continue nor on_errors=" |
1992 | "remount-ro was specified%s", | 1990 | "remount-ro was specified%s", |
1993 | es1, es2); | 1991 | es1, es2); |
1994 | goto iput_root_err_out; | 1992 | goto iput_root_err_out; |
1995 | } | 1993 | } |
1996 | sb->s_flags |= MS_RDONLY; | 1994 | sb->s_flags |= MS_RDONLY; |
1997 | ntfs_error(sb, "%s. Mounting read-only%s", es1, es2); | 1995 | ntfs_error(sb, "%s. Mounting read-only%s", es1, es2); |
1998 | } else | 1996 | } else |
1999 | ntfs_warning(sb, "%s. Will not be able to remount " | 1997 | ntfs_warning(sb, "%s. Will not be able to remount " |
2000 | "read-write%s", es1, es2); | 1998 | "read-write%s", es1, es2); |
2001 | /* This will prevent a read-write remount. */ | 1999 | /* This will prevent a read-write remount. */ |
2002 | NVolSetErrors(vol); | 2000 | NVolSetErrors(vol); |
2003 | } | 2001 | } |
2004 | /* If (still) a read-write mount, mark the volume dirty. */ | 2002 | /* If (still) a read-write mount, mark the volume dirty. */ |
2005 | if (!(sb->s_flags & MS_RDONLY) && | 2003 | if (!(sb->s_flags & MS_RDONLY) && |
2006 | ntfs_set_volume_flags(vol, VOLUME_IS_DIRTY)) { | 2004 | ntfs_set_volume_flags(vol, VOLUME_IS_DIRTY)) { |
2007 | static const char *es1 = "Failed to set dirty bit in volume " | 2005 | static const char *es1 = "Failed to set dirty bit in volume " |
2008 | "information flags"; | 2006 | "information flags"; |
2009 | static const char *es2 = ". Run chkdsk."; | 2007 | static const char *es2 = ". Run chkdsk."; |
2010 | 2008 | ||
2011 | /* Convert to a read-only mount. */ | 2009 | /* Convert to a read-only mount. */ |
2012 | if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO | | 2010 | if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO | |
2013 | ON_ERRORS_CONTINUE))) { | 2011 | ON_ERRORS_CONTINUE))) { |
2014 | ntfs_error(sb, "%s and neither on_errors=continue nor " | 2012 | ntfs_error(sb, "%s and neither on_errors=continue nor " |
2015 | "on_errors=remount-ro was specified%s", | 2013 | "on_errors=remount-ro was specified%s", |
2016 | es1, es2); | 2014 | es1, es2); |
2017 | goto iput_root_err_out; | 2015 | goto iput_root_err_out; |
2018 | } | 2016 | } |
2019 | ntfs_error(sb, "%s. Mounting read-only%s", es1, es2); | 2017 | ntfs_error(sb, "%s. Mounting read-only%s", es1, es2); |
2020 | sb->s_flags |= MS_RDONLY; | 2018 | sb->s_flags |= MS_RDONLY; |
2021 | /* | 2019 | /* |
2022 | * Do not set NVolErrors() because ntfs_remount() might manage | 2020 | * Do not set NVolErrors() because ntfs_remount() might manage |
2023 | * to set the dirty flag in which case all would be well. | 2021 | * to set the dirty flag in which case all would be well. |
2024 | */ | 2022 | */ |
2025 | } | 2023 | } |
2026 | #if 0 | 2024 | #if 0 |
2027 | // TODO: Enable this code once we start modifying anything that is | 2025 | // TODO: Enable this code once we start modifying anything that is |
2028 | // different between NTFS 1.2 and 3.x... | 2026 | // different between NTFS 1.2 and 3.x... |
2029 | /* | 2027 | /* |
2030 | * If (still) a read-write mount, set the NT4 compatibility flag on | 2028 | * If (still) a read-write mount, set the NT4 compatibility flag on |
2031 | * newer NTFS version volumes. | 2029 | * newer NTFS version volumes. |
2032 | */ | 2030 | */ |
2033 | if (!(sb->s_flags & MS_RDONLY) && (vol->major_ver > 1) && | 2031 | if (!(sb->s_flags & MS_RDONLY) && (vol->major_ver > 1) && |
2034 | ntfs_set_volume_flags(vol, VOLUME_MOUNTED_ON_NT4)) { | 2032 | ntfs_set_volume_flags(vol, VOLUME_MOUNTED_ON_NT4)) { |
2035 | static const char *es1 = "Failed to set NT4 compatibility flag"; | 2033 | static const char *es1 = "Failed to set NT4 compatibility flag"; |
2036 | static const char *es2 = ". Run chkdsk."; | 2034 | static const char *es2 = ". Run chkdsk."; |
2037 | 2035 | ||
2038 | /* Convert to a read-only mount. */ | 2036 | /* Convert to a read-only mount. */ |
2039 | if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO | | 2037 | if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO | |
2040 | ON_ERRORS_CONTINUE))) { | 2038 | ON_ERRORS_CONTINUE))) { |
2041 | ntfs_error(sb, "%s and neither on_errors=continue nor " | 2039 | ntfs_error(sb, "%s and neither on_errors=continue nor " |
2042 | "on_errors=remount-ro was specified%s", | 2040 | "on_errors=remount-ro was specified%s", |
2043 | es1, es2); | 2041 | es1, es2); |
2044 | goto iput_root_err_out; | 2042 | goto iput_root_err_out; |
2045 | } | 2043 | } |
2046 | ntfs_error(sb, "%s. Mounting read-only%s", es1, es2); | 2044 | ntfs_error(sb, "%s. Mounting read-only%s", es1, es2); |
2047 | sb->s_flags |= MS_RDONLY; | 2045 | sb->s_flags |= MS_RDONLY; |
2048 | NVolSetErrors(vol); | 2046 | NVolSetErrors(vol); |
2049 | } | 2047 | } |
2050 | #endif | 2048 | #endif |
2051 | /* If (still) a read-write mount, empty the logfile. */ | 2049 | /* If (still) a read-write mount, empty the logfile. */ |
2052 | if (!(sb->s_flags & MS_RDONLY) && | 2050 | if (!(sb->s_flags & MS_RDONLY) && |
2053 | !ntfs_empty_logfile(vol->logfile_ino)) { | 2051 | !ntfs_empty_logfile(vol->logfile_ino)) { |
2054 | static const char *es1 = "Failed to empty $LogFile"; | 2052 | static const char *es1 = "Failed to empty $LogFile"; |
2055 | static const char *es2 = ". Mount in Windows."; | 2053 | static const char *es2 = ". Mount in Windows."; |
2056 | 2054 | ||
2057 | /* Convert to a read-only mount. */ | 2055 | /* Convert to a read-only mount. */ |
2058 | if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO | | 2056 | if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO | |
2059 | ON_ERRORS_CONTINUE))) { | 2057 | ON_ERRORS_CONTINUE))) { |
2060 | ntfs_error(sb, "%s and neither on_errors=continue nor " | 2058 | ntfs_error(sb, "%s and neither on_errors=continue nor " |
2061 | "on_errors=remount-ro was specified%s", | 2059 | "on_errors=remount-ro was specified%s", |
2062 | es1, es2); | 2060 | es1, es2); |
2063 | goto iput_root_err_out; | 2061 | goto iput_root_err_out; |
2064 | } | 2062 | } |
2065 | ntfs_error(sb, "%s. Mounting read-only%s", es1, es2); | 2063 | ntfs_error(sb, "%s. Mounting read-only%s", es1, es2); |
2066 | sb->s_flags |= MS_RDONLY; | 2064 | sb->s_flags |= MS_RDONLY; |
2067 | NVolSetErrors(vol); | 2065 | NVolSetErrors(vol); |
2068 | } | 2066 | } |
2069 | #endif /* NTFS_RW */ | 2067 | #endif /* NTFS_RW */ |
2070 | /* If on NTFS versions before 3.0, we are done. */ | 2068 | /* If on NTFS versions before 3.0, we are done. */ |
2071 | if (unlikely(vol->major_ver < 3)) | 2069 | if (unlikely(vol->major_ver < 3)) |
2072 | return true; | 2070 | return true; |
2073 | /* NTFS 3.0+ specific initialization. */ | 2071 | /* NTFS 3.0+ specific initialization. */ |
2074 | /* Get the security descriptors inode. */ | 2072 | /* Get the security descriptors inode. */ |
2075 | vol->secure_ino = ntfs_iget(sb, FILE_Secure); | 2073 | vol->secure_ino = ntfs_iget(sb, FILE_Secure); |
2076 | if (IS_ERR(vol->secure_ino) || is_bad_inode(vol->secure_ino)) { | 2074 | if (IS_ERR(vol->secure_ino) || is_bad_inode(vol->secure_ino)) { |
2077 | if (!IS_ERR(vol->secure_ino)) | 2075 | if (!IS_ERR(vol->secure_ino)) |
2078 | iput(vol->secure_ino); | 2076 | iput(vol->secure_ino); |
2079 | ntfs_error(sb, "Failed to load $Secure."); | 2077 | ntfs_error(sb, "Failed to load $Secure."); |
2080 | goto iput_root_err_out; | 2078 | goto iput_root_err_out; |
2081 | } | 2079 | } |
2082 | // TODO: Initialize security. | 2080 | // TODO: Initialize security. |
2083 | /* Get the extended system files' directory inode. */ | 2081 | /* Get the extended system files' directory inode. */ |
2084 | vol->extend_ino = ntfs_iget(sb, FILE_Extend); | 2082 | vol->extend_ino = ntfs_iget(sb, FILE_Extend); |
2085 | if (IS_ERR(vol->extend_ino) || is_bad_inode(vol->extend_ino)) { | 2083 | if (IS_ERR(vol->extend_ino) || is_bad_inode(vol->extend_ino)) { |
2086 | if (!IS_ERR(vol->extend_ino)) | 2084 | if (!IS_ERR(vol->extend_ino)) |
2087 | iput(vol->extend_ino); | 2085 | iput(vol->extend_ino); |
2088 | ntfs_error(sb, "Failed to load $Extend."); | 2086 | ntfs_error(sb, "Failed to load $Extend."); |
2089 | goto iput_sec_err_out; | 2087 | goto iput_sec_err_out; |
2090 | } | 2088 | } |
2091 | #ifdef NTFS_RW | 2089 | #ifdef NTFS_RW |
2092 | /* Find the quota file, load it if present, and set it up. */ | 2090 | /* Find the quota file, load it if present, and set it up. */ |
2093 | if (!load_and_init_quota(vol)) { | 2091 | if (!load_and_init_quota(vol)) { |
2094 | static const char *es1 = "Failed to load $Quota"; | 2092 | static const char *es1 = "Failed to load $Quota"; |
2095 | static const char *es2 = ". Run chkdsk."; | 2093 | static const char *es2 = ". Run chkdsk."; |
2096 | 2094 | ||
2097 | /* If a read-write mount, convert it to a read-only mount. */ | 2095 | /* If a read-write mount, convert it to a read-only mount. */ |
2098 | if (!(sb->s_flags & MS_RDONLY)) { | 2096 | if (!(sb->s_flags & MS_RDONLY)) { |
2099 | if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO | | 2097 | if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO | |
2100 | ON_ERRORS_CONTINUE))) { | 2098 | ON_ERRORS_CONTINUE))) { |
2101 | ntfs_error(sb, "%s and neither on_errors=" | 2099 | ntfs_error(sb, "%s and neither on_errors=" |
2102 | "continue nor on_errors=" | 2100 | "continue nor on_errors=" |
2103 | "remount-ro was specified%s", | 2101 | "remount-ro was specified%s", |
2104 | es1, es2); | 2102 | es1, es2); |
2105 | goto iput_quota_err_out; | 2103 | goto iput_quota_err_out; |
2106 | } | 2104 | } |
2107 | sb->s_flags |= MS_RDONLY; | 2105 | sb->s_flags |= MS_RDONLY; |
2108 | ntfs_error(sb, "%s. Mounting read-only%s", es1, es2); | 2106 | ntfs_error(sb, "%s. Mounting read-only%s", es1, es2); |
2109 | } else | 2107 | } else |
2110 | ntfs_warning(sb, "%s. Will not be able to remount " | 2108 | ntfs_warning(sb, "%s. Will not be able to remount " |
2111 | "read-write%s", es1, es2); | 2109 | "read-write%s", es1, es2); |
2112 | /* This will prevent a read-write remount. */ | 2110 | /* This will prevent a read-write remount. */ |
2113 | NVolSetErrors(vol); | 2111 | NVolSetErrors(vol); |
2114 | } | 2112 | } |
2115 | /* If (still) a read-write mount, mark the quotas out of date. */ | 2113 | /* If (still) a read-write mount, mark the quotas out of date. */ |
2116 | if (!(sb->s_flags & MS_RDONLY) && | 2114 | if (!(sb->s_flags & MS_RDONLY) && |
2117 | !ntfs_mark_quotas_out_of_date(vol)) { | 2115 | !ntfs_mark_quotas_out_of_date(vol)) { |
2118 | static const char *es1 = "Failed to mark quotas out of date"; | 2116 | static const char *es1 = "Failed to mark quotas out of date"; |
2119 | static const char *es2 = ". Run chkdsk."; | 2117 | static const char *es2 = ". Run chkdsk."; |
2120 | 2118 | ||
2121 | /* Convert to a read-only mount. */ | 2119 | /* Convert to a read-only mount. */ |
2122 | if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO | | 2120 | if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO | |
2123 | ON_ERRORS_CONTINUE))) { | 2121 | ON_ERRORS_CONTINUE))) { |
2124 | ntfs_error(sb, "%s and neither on_errors=continue nor " | 2122 | ntfs_error(sb, "%s and neither on_errors=continue nor " |
2125 | "on_errors=remount-ro was specified%s", | 2123 | "on_errors=remount-ro was specified%s", |
2126 | es1, es2); | 2124 | es1, es2); |
2127 | goto iput_quota_err_out; | 2125 | goto iput_quota_err_out; |
2128 | } | 2126 | } |
2129 | ntfs_error(sb, "%s. Mounting read-only%s", es1, es2); | 2127 | ntfs_error(sb, "%s. Mounting read-only%s", es1, es2); |
2130 | sb->s_flags |= MS_RDONLY; | 2128 | sb->s_flags |= MS_RDONLY; |
2131 | NVolSetErrors(vol); | 2129 | NVolSetErrors(vol); |
2132 | } | 2130 | } |
2133 | /* | 2131 | /* |
2134 | * Find the transaction log file ($UsnJrnl), load it if present, check | 2132 | * Find the transaction log file ($UsnJrnl), load it if present, check |
2135 | * it, and set it up. | 2133 | * it, and set it up. |
2136 | */ | 2134 | */ |
2137 | if (!load_and_init_usnjrnl(vol)) { | 2135 | if (!load_and_init_usnjrnl(vol)) { |
2138 | static const char *es1 = "Failed to load $UsnJrnl"; | 2136 | static const char *es1 = "Failed to load $UsnJrnl"; |
2139 | static const char *es2 = ". Run chkdsk."; | 2137 | static const char *es2 = ". Run chkdsk."; |
2140 | 2138 | ||
2141 | /* If a read-write mount, convert it to a read-only mount. */ | 2139 | /* If a read-write mount, convert it to a read-only mount. */ |
2142 | if (!(sb->s_flags & MS_RDONLY)) { | 2140 | if (!(sb->s_flags & MS_RDONLY)) { |
2143 | if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO | | 2141 | if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO | |
2144 | ON_ERRORS_CONTINUE))) { | 2142 | ON_ERRORS_CONTINUE))) { |
2145 | ntfs_error(sb, "%s and neither on_errors=" | 2143 | ntfs_error(sb, "%s and neither on_errors=" |
2146 | "continue nor on_errors=" | 2144 | "continue nor on_errors=" |
2147 | "remount-ro was specified%s", | 2145 | "remount-ro was specified%s", |
2148 | es1, es2); | 2146 | es1, es2); |
2149 | goto iput_usnjrnl_err_out; | 2147 | goto iput_usnjrnl_err_out; |
2150 | } | 2148 | } |
2151 | sb->s_flags |= MS_RDONLY; | 2149 | sb->s_flags |= MS_RDONLY; |
2152 | ntfs_error(sb, "%s. Mounting read-only%s", es1, es2); | 2150 | ntfs_error(sb, "%s. Mounting read-only%s", es1, es2); |
2153 | } else | 2151 | } else |
2154 | ntfs_warning(sb, "%s. Will not be able to remount " | 2152 | ntfs_warning(sb, "%s. Will not be able to remount " |
2155 | "read-write%s", es1, es2); | 2153 | "read-write%s", es1, es2); |
2156 | /* This will prevent a read-write remount. */ | 2154 | /* This will prevent a read-write remount. */ |
2157 | NVolSetErrors(vol); | 2155 | NVolSetErrors(vol); |
2158 | } | 2156 | } |
2159 | /* If (still) a read-write mount, stamp the transaction log. */ | 2157 | /* If (still) a read-write mount, stamp the transaction log. */ |
2160 | if (!(sb->s_flags & MS_RDONLY) && !ntfs_stamp_usnjrnl(vol)) { | 2158 | if (!(sb->s_flags & MS_RDONLY) && !ntfs_stamp_usnjrnl(vol)) { |
2161 | static const char *es1 = "Failed to stamp transaction log " | 2159 | static const char *es1 = "Failed to stamp transaction log " |
2162 | "($UsnJrnl)"; | 2160 | "($UsnJrnl)"; |
2163 | static const char *es2 = ". Run chkdsk."; | 2161 | static const char *es2 = ". Run chkdsk."; |
2164 | 2162 | ||
2165 | /* Convert to a read-only mount. */ | 2163 | /* Convert to a read-only mount. */ |
2166 | if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO | | 2164 | if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO | |
2167 | ON_ERRORS_CONTINUE))) { | 2165 | ON_ERRORS_CONTINUE))) { |
2168 | ntfs_error(sb, "%s and neither on_errors=continue nor " | 2166 | ntfs_error(sb, "%s and neither on_errors=continue nor " |
2169 | "on_errors=remount-ro was specified%s", | 2167 | "on_errors=remount-ro was specified%s", |
2170 | es1, es2); | 2168 | es1, es2); |
2171 | goto iput_usnjrnl_err_out; | 2169 | goto iput_usnjrnl_err_out; |
2172 | } | 2170 | } |
2173 | ntfs_error(sb, "%s. Mounting read-only%s", es1, es2); | 2171 | ntfs_error(sb, "%s. Mounting read-only%s", es1, es2); |
2174 | sb->s_flags |= MS_RDONLY; | 2172 | sb->s_flags |= MS_RDONLY; |
2175 | NVolSetErrors(vol); | 2173 | NVolSetErrors(vol); |
2176 | } | 2174 | } |
2177 | #endif /* NTFS_RW */ | 2175 | #endif /* NTFS_RW */ |
2178 | return true; | 2176 | return true; |
2179 | #ifdef NTFS_RW | 2177 | #ifdef NTFS_RW |
2180 | iput_usnjrnl_err_out: | 2178 | iput_usnjrnl_err_out: |
2181 | if (vol->usnjrnl_j_ino) | 2179 | if (vol->usnjrnl_j_ino) |
2182 | iput(vol->usnjrnl_j_ino); | 2180 | iput(vol->usnjrnl_j_ino); |
2183 | if (vol->usnjrnl_max_ino) | 2181 | if (vol->usnjrnl_max_ino) |
2184 | iput(vol->usnjrnl_max_ino); | 2182 | iput(vol->usnjrnl_max_ino); |
2185 | if (vol->usnjrnl_ino) | 2183 | if (vol->usnjrnl_ino) |
2186 | iput(vol->usnjrnl_ino); | 2184 | iput(vol->usnjrnl_ino); |
2187 | iput_quota_err_out: | 2185 | iput_quota_err_out: |
2188 | if (vol->quota_q_ino) | 2186 | if (vol->quota_q_ino) |
2189 | iput(vol->quota_q_ino); | 2187 | iput(vol->quota_q_ino); |
2190 | if (vol->quota_ino) | 2188 | if (vol->quota_ino) |
2191 | iput(vol->quota_ino); | 2189 | iput(vol->quota_ino); |
2192 | iput(vol->extend_ino); | 2190 | iput(vol->extend_ino); |
2193 | #endif /* NTFS_RW */ | 2191 | #endif /* NTFS_RW */ |
2194 | iput_sec_err_out: | 2192 | iput_sec_err_out: |
2195 | iput(vol->secure_ino); | 2193 | iput(vol->secure_ino); |
2196 | iput_root_err_out: | 2194 | iput_root_err_out: |
2197 | iput(vol->root_ino); | 2195 | iput(vol->root_ino); |
2198 | iput_logfile_err_out: | 2196 | iput_logfile_err_out: |
2199 | #ifdef NTFS_RW | 2197 | #ifdef NTFS_RW |
2200 | if (vol->logfile_ino) | 2198 | if (vol->logfile_ino) |
2201 | iput(vol->logfile_ino); | 2199 | iput(vol->logfile_ino); |
2202 | iput_vol_err_out: | 2200 | iput_vol_err_out: |
2203 | #endif /* NTFS_RW */ | 2201 | #endif /* NTFS_RW */ |
2204 | iput(vol->vol_ino); | 2202 | iput(vol->vol_ino); |
2205 | iput_lcnbmp_err_out: | 2203 | iput_lcnbmp_err_out: |
2206 | iput(vol->lcnbmp_ino); | 2204 | iput(vol->lcnbmp_ino); |
2207 | iput_attrdef_err_out: | 2205 | iput_attrdef_err_out: |
2208 | vol->attrdef_size = 0; | 2206 | vol->attrdef_size = 0; |
2209 | if (vol->attrdef) { | 2207 | if (vol->attrdef) { |
2210 | ntfs_free(vol->attrdef); | 2208 | ntfs_free(vol->attrdef); |
2211 | vol->attrdef = NULL; | 2209 | vol->attrdef = NULL; |
2212 | } | 2210 | } |
2213 | #ifdef NTFS_RW | 2211 | #ifdef NTFS_RW |
2214 | iput_upcase_err_out: | 2212 | iput_upcase_err_out: |
2215 | #endif /* NTFS_RW */ | 2213 | #endif /* NTFS_RW */ |
2216 | vol->upcase_len = 0; | 2214 | vol->upcase_len = 0; |
2217 | mutex_lock(&ntfs_lock); | 2215 | mutex_lock(&ntfs_lock); |
2218 | if (vol->upcase == default_upcase) { | 2216 | if (vol->upcase == default_upcase) { |
2219 | ntfs_nr_upcase_users--; | 2217 | ntfs_nr_upcase_users--; |
2220 | vol->upcase = NULL; | 2218 | vol->upcase = NULL; |
2221 | } | 2219 | } |
2222 | mutex_unlock(&ntfs_lock); | 2220 | mutex_unlock(&ntfs_lock); |
2223 | if (vol->upcase) { | 2221 | if (vol->upcase) { |
2224 | ntfs_free(vol->upcase); | 2222 | ntfs_free(vol->upcase); |
2225 | vol->upcase = NULL; | 2223 | vol->upcase = NULL; |
2226 | } | 2224 | } |
2227 | iput_mftbmp_err_out: | 2225 | iput_mftbmp_err_out: |
2228 | iput(vol->mftbmp_ino); | 2226 | iput(vol->mftbmp_ino); |
2229 | iput_mirr_err_out: | 2227 | iput_mirr_err_out: |
2230 | #ifdef NTFS_RW | 2228 | #ifdef NTFS_RW |
2231 | if (vol->mftmirr_ino) | 2229 | if (vol->mftmirr_ino) |
2232 | iput(vol->mftmirr_ino); | 2230 | iput(vol->mftmirr_ino); |
2233 | #endif /* NTFS_RW */ | 2231 | #endif /* NTFS_RW */ |
2234 | return false; | 2232 | return false; |
2235 | } | 2233 | } |
2236 | 2234 | ||
2237 | /** | 2235 | /** |
2238 | * ntfs_put_super - called by the vfs to unmount a volume | 2236 | * ntfs_put_super - called by the vfs to unmount a volume |
2239 | * @sb: vfs superblock of volume to unmount | 2237 | * @sb: vfs superblock of volume to unmount |
2240 | * | 2238 | * |
2241 | * ntfs_put_super() is called by the VFS (from fs/super.c::do_umount()) when | 2239 | * ntfs_put_super() is called by the VFS (from fs/super.c::do_umount()) when |
2242 | * the volume is being unmounted (umount system call has been invoked) and it | 2240 | * the volume is being unmounted (umount system call has been invoked) and it |
2243 | * releases all inodes and memory belonging to the NTFS specific part of the | 2241 | * releases all inodes and memory belonging to the NTFS specific part of the |
2244 | * super block. | 2242 | * super block. |
2245 | */ | 2243 | */ |
2246 | static void ntfs_put_super(struct super_block *sb) | 2244 | static void ntfs_put_super(struct super_block *sb) |
2247 | { | 2245 | { |
2248 | ntfs_volume *vol = NTFS_SB(sb); | 2246 | ntfs_volume *vol = NTFS_SB(sb); |
2249 | 2247 | ||
2250 | ntfs_debug("Entering."); | 2248 | ntfs_debug("Entering."); |
2251 | 2249 | ||
2252 | #ifdef NTFS_RW | 2250 | #ifdef NTFS_RW |
2253 | /* | 2251 | /* |
2254 | * Commit all inodes while they are still open in case some of them | 2252 | * Commit all inodes while they are still open in case some of them |
2255 | * cause others to be dirtied. | 2253 | * cause others to be dirtied. |
2256 | */ | 2254 | */ |
2257 | ntfs_commit_inode(vol->vol_ino); | 2255 | ntfs_commit_inode(vol->vol_ino); |
2258 | 2256 | ||
2259 | /* NTFS 3.0+ specific. */ | 2257 | /* NTFS 3.0+ specific. */ |
2260 | if (vol->major_ver >= 3) { | 2258 | if (vol->major_ver >= 3) { |
2261 | if (vol->usnjrnl_j_ino) | 2259 | if (vol->usnjrnl_j_ino) |
2262 | ntfs_commit_inode(vol->usnjrnl_j_ino); | 2260 | ntfs_commit_inode(vol->usnjrnl_j_ino); |
2263 | if (vol->usnjrnl_max_ino) | 2261 | if (vol->usnjrnl_max_ino) |
2264 | ntfs_commit_inode(vol->usnjrnl_max_ino); | 2262 | ntfs_commit_inode(vol->usnjrnl_max_ino); |
2265 | if (vol->usnjrnl_ino) | 2263 | if (vol->usnjrnl_ino) |
2266 | ntfs_commit_inode(vol->usnjrnl_ino); | 2264 | ntfs_commit_inode(vol->usnjrnl_ino); |
2267 | if (vol->quota_q_ino) | 2265 | if (vol->quota_q_ino) |
2268 | ntfs_commit_inode(vol->quota_q_ino); | 2266 | ntfs_commit_inode(vol->quota_q_ino); |
2269 | if (vol->quota_ino) | 2267 | if (vol->quota_ino) |
2270 | ntfs_commit_inode(vol->quota_ino); | 2268 | ntfs_commit_inode(vol->quota_ino); |
2271 | if (vol->extend_ino) | 2269 | if (vol->extend_ino) |
2272 | ntfs_commit_inode(vol->extend_ino); | 2270 | ntfs_commit_inode(vol->extend_ino); |
2273 | if (vol->secure_ino) | 2271 | if (vol->secure_ino) |
2274 | ntfs_commit_inode(vol->secure_ino); | 2272 | ntfs_commit_inode(vol->secure_ino); |
2275 | } | 2273 | } |
2276 | 2274 | ||
2277 | ntfs_commit_inode(vol->root_ino); | 2275 | ntfs_commit_inode(vol->root_ino); |
2278 | 2276 | ||
2279 | down_write(&vol->lcnbmp_lock); | 2277 | down_write(&vol->lcnbmp_lock); |
2280 | ntfs_commit_inode(vol->lcnbmp_ino); | 2278 | ntfs_commit_inode(vol->lcnbmp_ino); |
2281 | up_write(&vol->lcnbmp_lock); | 2279 | up_write(&vol->lcnbmp_lock); |
2282 | 2280 | ||
2283 | down_write(&vol->mftbmp_lock); | 2281 | down_write(&vol->mftbmp_lock); |
2284 | ntfs_commit_inode(vol->mftbmp_ino); | 2282 | ntfs_commit_inode(vol->mftbmp_ino); |
2285 | up_write(&vol->mftbmp_lock); | 2283 | up_write(&vol->mftbmp_lock); |
2286 | 2284 | ||
2287 | if (vol->logfile_ino) | 2285 | if (vol->logfile_ino) |
2288 | ntfs_commit_inode(vol->logfile_ino); | 2286 | ntfs_commit_inode(vol->logfile_ino); |
2289 | 2287 | ||
2290 | if (vol->mftmirr_ino) | 2288 | if (vol->mftmirr_ino) |
2291 | ntfs_commit_inode(vol->mftmirr_ino); | 2289 | ntfs_commit_inode(vol->mftmirr_ino); |
2292 | ntfs_commit_inode(vol->mft_ino); | 2290 | ntfs_commit_inode(vol->mft_ino); |
2293 | 2291 | ||
2294 | /* | 2292 | /* |
2295 | * If a read-write mount and no volume errors have occurred, mark the | 2293 | * If a read-write mount and no volume errors have occurred, mark the |
2296 | * volume clean. Also, re-commit all affected inodes. | 2294 | * volume clean. Also, re-commit all affected inodes. |
2297 | */ | 2295 | */ |
2298 | if (!(sb->s_flags & MS_RDONLY)) { | 2296 | if (!(sb->s_flags & MS_RDONLY)) { |
2299 | if (!NVolErrors(vol)) { | 2297 | if (!NVolErrors(vol)) { |
2300 | if (ntfs_clear_volume_flags(vol, VOLUME_IS_DIRTY)) | 2298 | if (ntfs_clear_volume_flags(vol, VOLUME_IS_DIRTY)) |
2301 | ntfs_warning(sb, "Failed to clear dirty bit " | 2299 | ntfs_warning(sb, "Failed to clear dirty bit " |
2302 | "in volume information " | 2300 | "in volume information " |
2303 | "flags. Run chkdsk."); | 2301 | "flags. Run chkdsk."); |
2304 | ntfs_commit_inode(vol->vol_ino); | 2302 | ntfs_commit_inode(vol->vol_ino); |
2305 | ntfs_commit_inode(vol->root_ino); | 2303 | ntfs_commit_inode(vol->root_ino); |
2306 | if (vol->mftmirr_ino) | 2304 | if (vol->mftmirr_ino) |
2307 | ntfs_commit_inode(vol->mftmirr_ino); | 2305 | ntfs_commit_inode(vol->mftmirr_ino); |
2308 | ntfs_commit_inode(vol->mft_ino); | 2306 | ntfs_commit_inode(vol->mft_ino); |
2309 | } else { | 2307 | } else { |
2310 | ntfs_warning(sb, "Volume has errors. Leaving volume " | 2308 | ntfs_warning(sb, "Volume has errors. Leaving volume " |
2311 | "marked dirty. Run chkdsk."); | 2309 | "marked dirty. Run chkdsk."); |
2312 | } | 2310 | } |
2313 | } | 2311 | } |
2314 | #endif /* NTFS_RW */ | 2312 | #endif /* NTFS_RW */ |
2315 | 2313 | ||
2316 | iput(vol->vol_ino); | 2314 | iput(vol->vol_ino); |
2317 | vol->vol_ino = NULL; | 2315 | vol->vol_ino = NULL; |
2318 | 2316 | ||
2319 | /* NTFS 3.0+ specific clean up. */ | 2317 | /* NTFS 3.0+ specific clean up. */ |
2320 | if (vol->major_ver >= 3) { | 2318 | if (vol->major_ver >= 3) { |
2321 | #ifdef NTFS_RW | 2319 | #ifdef NTFS_RW |
2322 | if (vol->usnjrnl_j_ino) { | 2320 | if (vol->usnjrnl_j_ino) { |
2323 | iput(vol->usnjrnl_j_ino); | 2321 | iput(vol->usnjrnl_j_ino); |
2324 | vol->usnjrnl_j_ino = NULL; | 2322 | vol->usnjrnl_j_ino = NULL; |
2325 | } | 2323 | } |
2326 | if (vol->usnjrnl_max_ino) { | 2324 | if (vol->usnjrnl_max_ino) { |
2327 | iput(vol->usnjrnl_max_ino); | 2325 | iput(vol->usnjrnl_max_ino); |
2328 | vol->usnjrnl_max_ino = NULL; | 2326 | vol->usnjrnl_max_ino = NULL; |
2329 | } | 2327 | } |
2330 | if (vol->usnjrnl_ino) { | 2328 | if (vol->usnjrnl_ino) { |
2331 | iput(vol->usnjrnl_ino); | 2329 | iput(vol->usnjrnl_ino); |
2332 | vol->usnjrnl_ino = NULL; | 2330 | vol->usnjrnl_ino = NULL; |
2333 | } | 2331 | } |
2334 | if (vol->quota_q_ino) { | 2332 | if (vol->quota_q_ino) { |
2335 | iput(vol->quota_q_ino); | 2333 | iput(vol->quota_q_ino); |
2336 | vol->quota_q_ino = NULL; | 2334 | vol->quota_q_ino = NULL; |
2337 | } | 2335 | } |
2338 | if (vol->quota_ino) { | 2336 | if (vol->quota_ino) { |
2339 | iput(vol->quota_ino); | 2337 | iput(vol->quota_ino); |
2340 | vol->quota_ino = NULL; | 2338 | vol->quota_ino = NULL; |
2341 | } | 2339 | } |
2342 | #endif /* NTFS_RW */ | 2340 | #endif /* NTFS_RW */ |
2343 | if (vol->extend_ino) { | 2341 | if (vol->extend_ino) { |
2344 | iput(vol->extend_ino); | 2342 | iput(vol->extend_ino); |
2345 | vol->extend_ino = NULL; | 2343 | vol->extend_ino = NULL; |
2346 | } | 2344 | } |
2347 | if (vol->secure_ino) { | 2345 | if (vol->secure_ino) { |
2348 | iput(vol->secure_ino); | 2346 | iput(vol->secure_ino); |
2349 | vol->secure_ino = NULL; | 2347 | vol->secure_ino = NULL; |
2350 | } | 2348 | } |
2351 | } | 2349 | } |
2352 | 2350 | ||
2353 | iput(vol->root_ino); | 2351 | iput(vol->root_ino); |
2354 | vol->root_ino = NULL; | 2352 | vol->root_ino = NULL; |
2355 | 2353 | ||
2356 | down_write(&vol->lcnbmp_lock); | 2354 | down_write(&vol->lcnbmp_lock); |
2357 | iput(vol->lcnbmp_ino); | 2355 | iput(vol->lcnbmp_ino); |
2358 | vol->lcnbmp_ino = NULL; | 2356 | vol->lcnbmp_ino = NULL; |
2359 | up_write(&vol->lcnbmp_lock); | 2357 | up_write(&vol->lcnbmp_lock); |
2360 | 2358 | ||
2361 | down_write(&vol->mftbmp_lock); | 2359 | down_write(&vol->mftbmp_lock); |
2362 | iput(vol->mftbmp_ino); | 2360 | iput(vol->mftbmp_ino); |
2363 | vol->mftbmp_ino = NULL; | 2361 | vol->mftbmp_ino = NULL; |
2364 | up_write(&vol->mftbmp_lock); | 2362 | up_write(&vol->mftbmp_lock); |
2365 | 2363 | ||
2366 | #ifdef NTFS_RW | 2364 | #ifdef NTFS_RW |
2367 | if (vol->logfile_ino) { | 2365 | if (vol->logfile_ino) { |
2368 | iput(vol->logfile_ino); | 2366 | iput(vol->logfile_ino); |
2369 | vol->logfile_ino = NULL; | 2367 | vol->logfile_ino = NULL; |
2370 | } | 2368 | } |
2371 | if (vol->mftmirr_ino) { | 2369 | if (vol->mftmirr_ino) { |
2372 | /* Re-commit the mft mirror and mft just in case. */ | 2370 | /* Re-commit the mft mirror and mft just in case. */ |
2373 | ntfs_commit_inode(vol->mftmirr_ino); | 2371 | ntfs_commit_inode(vol->mftmirr_ino); |
2374 | ntfs_commit_inode(vol->mft_ino); | 2372 | ntfs_commit_inode(vol->mft_ino); |
2375 | iput(vol->mftmirr_ino); | 2373 | iput(vol->mftmirr_ino); |
2376 | vol->mftmirr_ino = NULL; | 2374 | vol->mftmirr_ino = NULL; |
2377 | } | 2375 | } |
2378 | /* | 2376 | /* |
2379 | * We should have no dirty inodes left, due to | 2377 | * We should have no dirty inodes left, due to |
2380 | * mft.c::ntfs_mft_writepage() cleaning all the dirty pages as | 2378 | * mft.c::ntfs_mft_writepage() cleaning all the dirty pages as |
2381 | * the underlying mft records are written out and cleaned. | 2379 | * the underlying mft records are written out and cleaned. |
2382 | */ | 2380 | */ |
2383 | ntfs_commit_inode(vol->mft_ino); | 2381 | ntfs_commit_inode(vol->mft_ino); |
2384 | write_inode_now(vol->mft_ino, 1); | 2382 | write_inode_now(vol->mft_ino, 1); |
2385 | #endif /* NTFS_RW */ | 2383 | #endif /* NTFS_RW */ |
2386 | 2384 | ||
2387 | iput(vol->mft_ino); | 2385 | iput(vol->mft_ino); |
2388 | vol->mft_ino = NULL; | 2386 | vol->mft_ino = NULL; |
2389 | 2387 | ||
2390 | /* Throw away the table of attribute definitions. */ | 2388 | /* Throw away the table of attribute definitions. */ |
2391 | vol->attrdef_size = 0; | 2389 | vol->attrdef_size = 0; |
2392 | if (vol->attrdef) { | 2390 | if (vol->attrdef) { |
2393 | ntfs_free(vol->attrdef); | 2391 | ntfs_free(vol->attrdef); |
2394 | vol->attrdef = NULL; | 2392 | vol->attrdef = NULL; |
2395 | } | 2393 | } |
2396 | vol->upcase_len = 0; | 2394 | vol->upcase_len = 0; |
2397 | /* | 2395 | /* |
2398 | * Destroy the global default upcase table if necessary. Also decrease | 2396 | * Destroy the global default upcase table if necessary. Also decrease |
2399 | * the number of upcase users if we are a user. | 2397 | * the number of upcase users if we are a user. |
2400 | */ | 2398 | */ |
2401 | mutex_lock(&ntfs_lock); | 2399 | mutex_lock(&ntfs_lock); |
2402 | if (vol->upcase == default_upcase) { | 2400 | if (vol->upcase == default_upcase) { |
2403 | ntfs_nr_upcase_users--; | 2401 | ntfs_nr_upcase_users--; |
2404 | vol->upcase = NULL; | 2402 | vol->upcase = NULL; |
2405 | } | 2403 | } |
2406 | if (!ntfs_nr_upcase_users && default_upcase) { | 2404 | if (!ntfs_nr_upcase_users && default_upcase) { |
2407 | ntfs_free(default_upcase); | 2405 | ntfs_free(default_upcase); |
2408 | default_upcase = NULL; | 2406 | default_upcase = NULL; |
2409 | } | 2407 | } |
2410 | if (vol->cluster_size <= 4096 && !--ntfs_nr_compression_users) | 2408 | if (vol->cluster_size <= 4096 && !--ntfs_nr_compression_users) |
2411 | free_compression_buffers(); | 2409 | free_compression_buffers(); |
2412 | mutex_unlock(&ntfs_lock); | 2410 | mutex_unlock(&ntfs_lock); |
2413 | if (vol->upcase) { | 2411 | if (vol->upcase) { |
2414 | ntfs_free(vol->upcase); | 2412 | ntfs_free(vol->upcase); |
2415 | vol->upcase = NULL; | 2413 | vol->upcase = NULL; |
2416 | } | 2414 | } |
2417 | 2415 | ||
2418 | unload_nls(vol->nls_map); | 2416 | unload_nls(vol->nls_map); |
2419 | 2417 | ||
2420 | sb->s_fs_info = NULL; | 2418 | sb->s_fs_info = NULL; |
2421 | kfree(vol); | 2419 | kfree(vol); |
2422 | } | 2420 | } |
2423 | 2421 | ||
2424 | /** | 2422 | /** |
2425 | * get_nr_free_clusters - return the number of free clusters on a volume | 2423 | * get_nr_free_clusters - return the number of free clusters on a volume |
2426 | * @vol: ntfs volume for which to obtain free cluster count | 2424 | * @vol: ntfs volume for which to obtain free cluster count |
2427 | * | 2425 | * |
2428 | * Calculate the number of free clusters on the mounted NTFS volume @vol. We | 2426 | * Calculate the number of free clusters on the mounted NTFS volume @vol. We |
2429 | * actually calculate the number of clusters in use instead because this | 2427 | * actually calculate the number of clusters in use instead because this |
2430 | * allows us to not care about partial pages as these will be just zero filled | 2428 | * allows us to not care about partial pages as these will be just zero filled |
2431 | * and hence not be counted as allocated clusters. | 2429 | * and hence not be counted as allocated clusters. |
2432 | * | 2430 | * |
2433 | * The only particularity is that clusters beyond the end of the logical ntfs | 2431 | * The only particularity is that clusters beyond the end of the logical ntfs |
2434 | * volume will be marked as allocated to prevent errors which means we have to | 2432 | * volume will be marked as allocated to prevent errors which means we have to |
2435 | * discount those at the end. This is important as the cluster bitmap always | 2433 | * discount those at the end. This is important as the cluster bitmap always |
2436 | * has a size in multiples of 8 bytes, i.e. up to 63 clusters could be outside | 2434 | * has a size in multiples of 8 bytes, i.e. up to 63 clusters could be outside |
2437 | * the logical volume and marked in use when they are not as they do not exist. | 2435 | * the logical volume and marked in use when they are not as they do not exist. |
2438 | * | 2436 | * |
2439 | * If any pages cannot be read we assume all clusters in the erroring pages are | 2437 | * If any pages cannot be read we assume all clusters in the erroring pages are |
2440 | * in use. This means we return an underestimate on errors which is better than | 2438 | * in use. This means we return an underestimate on errors which is better than |
2441 | * an overestimate. | 2439 | * an overestimate. |
2442 | */ | 2440 | */ |
2443 | static s64 get_nr_free_clusters(ntfs_volume *vol) | 2441 | static s64 get_nr_free_clusters(ntfs_volume *vol) |
2444 | { | 2442 | { |
2445 | s64 nr_free = vol->nr_clusters; | 2443 | s64 nr_free = vol->nr_clusters; |
2446 | struct address_space *mapping = vol->lcnbmp_ino->i_mapping; | 2444 | struct address_space *mapping = vol->lcnbmp_ino->i_mapping; |
2447 | struct page *page; | 2445 | struct page *page; |
2448 | pgoff_t index, max_index; | 2446 | pgoff_t index, max_index; |
2449 | 2447 | ||
2450 | ntfs_debug("Entering."); | 2448 | ntfs_debug("Entering."); |
2451 | /* Serialize accesses to the cluster bitmap. */ | 2449 | /* Serialize accesses to the cluster bitmap. */ |
2452 | down_read(&vol->lcnbmp_lock); | 2450 | down_read(&vol->lcnbmp_lock); |
2453 | /* | 2451 | /* |
2454 | * Convert the number of bits into bytes rounded up, then convert into | 2452 | * Convert the number of bits into bytes rounded up, then convert into |
2455 | * multiples of PAGE_CACHE_SIZE, rounding up so that if we have one | 2453 | * multiples of PAGE_CACHE_SIZE, rounding up so that if we have one |
2456 | * full and one partial page max_index = 2. | 2454 | * full and one partial page max_index = 2. |
2457 | */ | 2455 | */ |
2458 | max_index = (((vol->nr_clusters + 7) >> 3) + PAGE_CACHE_SIZE - 1) >> | 2456 | max_index = (((vol->nr_clusters + 7) >> 3) + PAGE_CACHE_SIZE - 1) >> |
2459 | PAGE_CACHE_SHIFT; | 2457 | PAGE_CACHE_SHIFT; |
2460 | /* Use multiples of 4 bytes, thus max_size is PAGE_CACHE_SIZE / 4. */ | 2458 | /* Use multiples of 4 bytes, thus max_size is PAGE_CACHE_SIZE / 4. */ |
2461 | ntfs_debug("Reading $Bitmap, max_index = 0x%lx, max_size = 0x%lx.", | 2459 | ntfs_debug("Reading $Bitmap, max_index = 0x%lx, max_size = 0x%lx.", |
2462 | max_index, PAGE_CACHE_SIZE / 4); | 2460 | max_index, PAGE_CACHE_SIZE / 4); |
2463 | for (index = 0; index < max_index; index++) { | 2461 | for (index = 0; index < max_index; index++) { |
2464 | unsigned long *kaddr; | 2462 | unsigned long *kaddr; |
2465 | 2463 | ||
2466 | /* | 2464 | /* |
2467 | * Read the page from page cache, getting it from backing store | 2465 | * Read the page from page cache, getting it from backing store |
2468 | * if necessary, and increment the use count. | 2466 | * if necessary, and increment the use count. |
2469 | */ | 2467 | */ |
2470 | page = read_mapping_page(mapping, index, NULL); | 2468 | page = read_mapping_page(mapping, index, NULL); |
2471 | /* Ignore pages which errored synchronously. */ | 2469 | /* Ignore pages which errored synchronously. */ |
2472 | if (IS_ERR(page)) { | 2470 | if (IS_ERR(page)) { |
2473 | ntfs_debug("read_mapping_page() error. Skipping " | 2471 | ntfs_debug("read_mapping_page() error. Skipping " |
2474 | "page (index 0x%lx).", index); | 2472 | "page (index 0x%lx).", index); |
2475 | nr_free -= PAGE_CACHE_SIZE * 8; | 2473 | nr_free -= PAGE_CACHE_SIZE * 8; |
2476 | continue; | 2474 | continue; |
2477 | } | 2475 | } |
2478 | kaddr = kmap_atomic(page, KM_USER0); | 2476 | kaddr = kmap_atomic(page, KM_USER0); |
2479 | /* | 2477 | /* |
2480 | * Subtract the number of set bits. If this | 2478 | * Subtract the number of set bits. If this |
2481 | * is the last page and it is partial we don't really care as | 2479 | * is the last page and it is partial we don't really care as |
2482 | * it just means we do a little extra work but it won't affect | 2480 | * it just means we do a little extra work but it won't affect |
2483 | * the result as all out of range bytes are set to zero by | 2481 | * the result as all out of range bytes are set to zero by |
2484 | * ntfs_readpage(). | 2482 | * ntfs_readpage(). |
2485 | */ | 2483 | */ |
2486 | nr_free -= bitmap_weight(kaddr, | 2484 | nr_free -= bitmap_weight(kaddr, |
2487 | PAGE_CACHE_SIZE * BITS_PER_BYTE); | 2485 | PAGE_CACHE_SIZE * BITS_PER_BYTE); |
2488 | kunmap_atomic(kaddr, KM_USER0); | 2486 | kunmap_atomic(kaddr, KM_USER0); |
2489 | page_cache_release(page); | 2487 | page_cache_release(page); |
2490 | } | 2488 | } |
2491 | ntfs_debug("Finished reading $Bitmap, last index = 0x%lx.", index - 1); | 2489 | ntfs_debug("Finished reading $Bitmap, last index = 0x%lx.", index - 1); |
2492 | /* | 2490 | /* |
2493 | * Fixup for eventual bits outside logical ntfs volume (see function | 2491 | * Fixup for eventual bits outside logical ntfs volume (see function |
2494 | * description above). | 2492 | * description above). |
2495 | */ | 2493 | */ |
2496 | if (vol->nr_clusters & 63) | 2494 | if (vol->nr_clusters & 63) |
2497 | nr_free += 64 - (vol->nr_clusters & 63); | 2495 | nr_free += 64 - (vol->nr_clusters & 63); |
2498 | up_read(&vol->lcnbmp_lock); | 2496 | up_read(&vol->lcnbmp_lock); |
2499 | /* If errors occurred we may well have gone below zero, fix this. */ | 2497 | /* If errors occurred we may well have gone below zero, fix this. */ |
2500 | if (nr_free < 0) | 2498 | if (nr_free < 0) |
2501 | nr_free = 0; | 2499 | nr_free = 0; |
2502 | ntfs_debug("Exiting."); | 2500 | ntfs_debug("Exiting."); |
2503 | return nr_free; | 2501 | return nr_free; |
2504 | } | 2502 | } |
2505 | 2503 | ||
2506 | /** | 2504 | /** |
2507 | * __get_nr_free_mft_records - return the number of free inodes on a volume | 2505 | * __get_nr_free_mft_records - return the number of free inodes on a volume |
2508 | * @vol: ntfs volume for which to obtain free inode count | 2506 | * @vol: ntfs volume for which to obtain free inode count |
2509 | * @nr_free: number of mft records in filesystem | 2507 | * @nr_free: number of mft records in filesystem |
2510 | * @max_index: maximum number of pages containing set bits | 2508 | * @max_index: maximum number of pages containing set bits |
2511 | * | 2509 | * |
2512 | * Calculate the number of free mft records (inodes) on the mounted NTFS | 2510 | * Calculate the number of free mft records (inodes) on the mounted NTFS |
2513 | * volume @vol. We actually calculate the number of mft records in use instead | 2511 | * volume @vol. We actually calculate the number of mft records in use instead |
2514 | * because this allows us to not care about partial pages as these will be just | 2512 | * because this allows us to not care about partial pages as these will be just |
2515 | * zero filled and hence not be counted as allocated mft record. | 2513 | * zero filled and hence not be counted as allocated mft record. |
2516 | * | 2514 | * |
2517 | * If any pages cannot be read we assume all mft records in the erroring pages | 2515 | * If any pages cannot be read we assume all mft records in the erroring pages |
2518 | * are in use. This means we return an underestimate on errors which is better | 2516 | * are in use. This means we return an underestimate on errors which is better |
2519 | * than an overestimate. | 2517 | * than an overestimate. |
2520 | * | 2518 | * |
2521 | * NOTE: Caller must hold mftbmp_lock rw_semaphore for reading or writing. | 2519 | * NOTE: Caller must hold mftbmp_lock rw_semaphore for reading or writing. |
2522 | */ | 2520 | */ |
2523 | static unsigned long __get_nr_free_mft_records(ntfs_volume *vol, | 2521 | static unsigned long __get_nr_free_mft_records(ntfs_volume *vol, |
2524 | s64 nr_free, const pgoff_t max_index) | 2522 | s64 nr_free, const pgoff_t max_index) |
2525 | { | 2523 | { |
2526 | struct address_space *mapping = vol->mftbmp_ino->i_mapping; | 2524 | struct address_space *mapping = vol->mftbmp_ino->i_mapping; |
2527 | struct page *page; | 2525 | struct page *page; |
2528 | pgoff_t index; | 2526 | pgoff_t index; |
2529 | 2527 | ||
2530 | ntfs_debug("Entering."); | 2528 | ntfs_debug("Entering."); |
2531 | /* Use multiples of 4 bytes, thus max_size is PAGE_CACHE_SIZE / 4. */ | 2529 | /* Use multiples of 4 bytes, thus max_size is PAGE_CACHE_SIZE / 4. */ |
2532 | ntfs_debug("Reading $MFT/$BITMAP, max_index = 0x%lx, max_size = " | 2530 | ntfs_debug("Reading $MFT/$BITMAP, max_index = 0x%lx, max_size = " |
2533 | "0x%lx.", max_index, PAGE_CACHE_SIZE / 4); | 2531 | "0x%lx.", max_index, PAGE_CACHE_SIZE / 4); |
2534 | for (index = 0; index < max_index; index++) { | 2532 | for (index = 0; index < max_index; index++) { |
2535 | unsigned long *kaddr; | 2533 | unsigned long *kaddr; |
2536 | 2534 | ||
2537 | /* | 2535 | /* |
2538 | * Read the page from page cache, getting it from backing store | 2536 | * Read the page from page cache, getting it from backing store |
2539 | * if necessary, and increment the use count. | 2537 | * if necessary, and increment the use count. |
2540 | */ | 2538 | */ |
2541 | page = read_mapping_page(mapping, index, NULL); | 2539 | page = read_mapping_page(mapping, index, NULL); |
2542 | /* Ignore pages which errored synchronously. */ | 2540 | /* Ignore pages which errored synchronously. */ |
2543 | if (IS_ERR(page)) { | 2541 | if (IS_ERR(page)) { |
2544 | ntfs_debug("read_mapping_page() error. Skipping " | 2542 | ntfs_debug("read_mapping_page() error. Skipping " |
2545 | "page (index 0x%lx).", index); | 2543 | "page (index 0x%lx).", index); |
2546 | nr_free -= PAGE_CACHE_SIZE * 8; | 2544 | nr_free -= PAGE_CACHE_SIZE * 8; |
2547 | continue; | 2545 | continue; |
2548 | } | 2546 | } |
2549 | kaddr = kmap_atomic(page, KM_USER0); | 2547 | kaddr = kmap_atomic(page, KM_USER0); |
2550 | /* | 2548 | /* |
2551 | * Subtract the number of set bits. If this | 2549 | * Subtract the number of set bits. If this |
2552 | * is the last page and it is partial we don't really care as | 2550 | * is the last page and it is partial we don't really care as |
2553 | * it just means we do a little extra work but it won't affect | 2551 | * it just means we do a little extra work but it won't affect |
2554 | * the result as all out of range bytes are set to zero by | 2552 | * the result as all out of range bytes are set to zero by |
2555 | * ntfs_readpage(). | 2553 | * ntfs_readpage(). |
2556 | */ | 2554 | */ |
2557 | nr_free -= bitmap_weight(kaddr, | 2555 | nr_free -= bitmap_weight(kaddr, |
2558 | PAGE_CACHE_SIZE * BITS_PER_BYTE); | 2556 | PAGE_CACHE_SIZE * BITS_PER_BYTE); |
2559 | kunmap_atomic(kaddr, KM_USER0); | 2557 | kunmap_atomic(kaddr, KM_USER0); |
2560 | page_cache_release(page); | 2558 | page_cache_release(page); |
2561 | } | 2559 | } |
2562 | ntfs_debug("Finished reading $MFT/$BITMAP, last index = 0x%lx.", | 2560 | ntfs_debug("Finished reading $MFT/$BITMAP, last index = 0x%lx.", |
2563 | index - 1); | 2561 | index - 1); |
2564 | /* If errors occurred we may well have gone below zero, fix this. */ | 2562 | /* If errors occurred we may well have gone below zero, fix this. */ |
2565 | if (nr_free < 0) | 2563 | if (nr_free < 0) |
2566 | nr_free = 0; | 2564 | nr_free = 0; |
2567 | ntfs_debug("Exiting."); | 2565 | ntfs_debug("Exiting."); |
2568 | return nr_free; | 2566 | return nr_free; |
2569 | } | 2567 | } |
2570 | 2568 | ||
2571 | /** | 2569 | /** |
2572 | * ntfs_statfs - return information about mounted NTFS volume | 2570 | * ntfs_statfs - return information about mounted NTFS volume |
2573 | * @dentry: dentry from mounted volume | 2571 | * @dentry: dentry from mounted volume |
2574 | * @sfs: statfs structure in which to return the information | 2572 | * @sfs: statfs structure in which to return the information |
2575 | * | 2573 | * |
2576 | * Return information about the mounted NTFS volume @dentry in the statfs structure | 2574 | * Return information about the mounted NTFS volume @dentry in the statfs structure |
2577 | * pointed to by @sfs (this is initialized with zeros before ntfs_statfs is | 2575 | * pointed to by @sfs (this is initialized with zeros before ntfs_statfs is |
2578 | * called). We interpret the values to be correct of the moment in time at | 2576 | * called). We interpret the values to be correct of the moment in time at |
2579 | * which we are called. Most values are variable otherwise and this isn't just | 2577 | * which we are called. Most values are variable otherwise and this isn't just |
2580 | * the free values but the totals as well. For example we can increase the | 2578 | * the free values but the totals as well. For example we can increase the |
2581 | * total number of file nodes if we run out and we can keep doing this until | 2579 | * total number of file nodes if we run out and we can keep doing this until |
2582 | * there is no more space on the volume left at all. | 2580 | * there is no more space on the volume left at all. |
2583 | * | 2581 | * |
2584 | * Called from vfs_statfs which is used to handle the statfs, fstatfs, and | 2582 | * Called from vfs_statfs which is used to handle the statfs, fstatfs, and |
2585 | * ustat system calls. | 2583 | * ustat system calls. |
2586 | * | 2584 | * |
2587 | * Return 0 on success or -errno on error. | 2585 | * Return 0 on success or -errno on error. |
2588 | */ | 2586 | */ |
2589 | static int ntfs_statfs(struct dentry *dentry, struct kstatfs *sfs) | 2587 | static int ntfs_statfs(struct dentry *dentry, struct kstatfs *sfs) |
2590 | { | 2588 | { |
2591 | struct super_block *sb = dentry->d_sb; | 2589 | struct super_block *sb = dentry->d_sb; |
2592 | s64 size; | 2590 | s64 size; |
2593 | ntfs_volume *vol = NTFS_SB(sb); | 2591 | ntfs_volume *vol = NTFS_SB(sb); |
2594 | ntfs_inode *mft_ni = NTFS_I(vol->mft_ino); | 2592 | ntfs_inode *mft_ni = NTFS_I(vol->mft_ino); |
2595 | pgoff_t max_index; | 2593 | pgoff_t max_index; |
2596 | unsigned long flags; | 2594 | unsigned long flags; |
2597 | 2595 | ||
2598 | ntfs_debug("Entering."); | 2596 | ntfs_debug("Entering."); |
2599 | /* Type of filesystem. */ | 2597 | /* Type of filesystem. */ |
2600 | sfs->f_type = NTFS_SB_MAGIC; | 2598 | sfs->f_type = NTFS_SB_MAGIC; |
2601 | /* Optimal transfer block size. */ | 2599 | /* Optimal transfer block size. */ |
2602 | sfs->f_bsize = PAGE_CACHE_SIZE; | 2600 | sfs->f_bsize = PAGE_CACHE_SIZE; |
2603 | /* | 2601 | /* |
2604 | * Total data blocks in filesystem in units of f_bsize and since | 2602 | * Total data blocks in filesystem in units of f_bsize and since |
2605 | * inodes are also stored in data blocs ($MFT is a file) this is just | 2603 | * inodes are also stored in data blocs ($MFT is a file) this is just |
2606 | * the total clusters. | 2604 | * the total clusters. |
2607 | */ | 2605 | */ |
2608 | sfs->f_blocks = vol->nr_clusters << vol->cluster_size_bits >> | 2606 | sfs->f_blocks = vol->nr_clusters << vol->cluster_size_bits >> |
2609 | PAGE_CACHE_SHIFT; | 2607 | PAGE_CACHE_SHIFT; |
2610 | /* Free data blocks in filesystem in units of f_bsize. */ | 2608 | /* Free data blocks in filesystem in units of f_bsize. */ |
2611 | size = get_nr_free_clusters(vol) << vol->cluster_size_bits >> | 2609 | size = get_nr_free_clusters(vol) << vol->cluster_size_bits >> |
2612 | PAGE_CACHE_SHIFT; | 2610 | PAGE_CACHE_SHIFT; |
2613 | if (size < 0LL) | 2611 | if (size < 0LL) |
2614 | size = 0LL; | 2612 | size = 0LL; |
2615 | /* Free blocks avail to non-superuser, same as above on NTFS. */ | 2613 | /* Free blocks avail to non-superuser, same as above on NTFS. */ |
2616 | sfs->f_bavail = sfs->f_bfree = size; | 2614 | sfs->f_bavail = sfs->f_bfree = size; |
2617 | /* Serialize accesses to the inode bitmap. */ | 2615 | /* Serialize accesses to the inode bitmap. */ |
2618 | down_read(&vol->mftbmp_lock); | 2616 | down_read(&vol->mftbmp_lock); |
2619 | read_lock_irqsave(&mft_ni->size_lock, flags); | 2617 | read_lock_irqsave(&mft_ni->size_lock, flags); |
2620 | size = i_size_read(vol->mft_ino) >> vol->mft_record_size_bits; | 2618 | size = i_size_read(vol->mft_ino) >> vol->mft_record_size_bits; |
2621 | /* | 2619 | /* |
2622 | * Convert the maximum number of set bits into bytes rounded up, then | 2620 | * Convert the maximum number of set bits into bytes rounded up, then |
2623 | * convert into multiples of PAGE_CACHE_SIZE, rounding up so that if we | 2621 | * convert into multiples of PAGE_CACHE_SIZE, rounding up so that if we |
2624 | * have one full and one partial page max_index = 2. | 2622 | * have one full and one partial page max_index = 2. |
2625 | */ | 2623 | */ |
2626 | max_index = ((((mft_ni->initialized_size >> vol->mft_record_size_bits) | 2624 | max_index = ((((mft_ni->initialized_size >> vol->mft_record_size_bits) |
2627 | + 7) >> 3) + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT; | 2625 | + 7) >> 3) + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT; |
2628 | read_unlock_irqrestore(&mft_ni->size_lock, flags); | 2626 | read_unlock_irqrestore(&mft_ni->size_lock, flags); |
2629 | /* Number of inodes in filesystem (at this point in time). */ | 2627 | /* Number of inodes in filesystem (at this point in time). */ |
2630 | sfs->f_files = size; | 2628 | sfs->f_files = size; |
2631 | /* Free inodes in fs (based on current total count). */ | 2629 | /* Free inodes in fs (based on current total count). */ |
2632 | sfs->f_ffree = __get_nr_free_mft_records(vol, size, max_index); | 2630 | sfs->f_ffree = __get_nr_free_mft_records(vol, size, max_index); |
2633 | up_read(&vol->mftbmp_lock); | 2631 | up_read(&vol->mftbmp_lock); |
2634 | /* | 2632 | /* |
2635 | * File system id. This is extremely *nix flavour dependent and even | 2633 | * File system id. This is extremely *nix flavour dependent and even |
2636 | * within Linux itself all fs do their own thing. I interpret this to | 2634 | * within Linux itself all fs do their own thing. I interpret this to |
2637 | * mean a unique id associated with the mounted fs and not the id | 2635 | * mean a unique id associated with the mounted fs and not the id |
2638 | * associated with the filesystem driver, the latter is already given | 2636 | * associated with the filesystem driver, the latter is already given |
2639 | * by the filesystem type in sfs->f_type. Thus we use the 64-bit | 2637 | * by the filesystem type in sfs->f_type. Thus we use the 64-bit |
2640 | * volume serial number splitting it into two 32-bit parts. We enter | 2638 | * volume serial number splitting it into two 32-bit parts. We enter |
2641 | * the least significant 32-bits in f_fsid[0] and the most significant | 2639 | * the least significant 32-bits in f_fsid[0] and the most significant |
2642 | * 32-bits in f_fsid[1]. | 2640 | * 32-bits in f_fsid[1]. |
2643 | */ | 2641 | */ |
2644 | sfs->f_fsid.val[0] = vol->serial_no & 0xffffffff; | 2642 | sfs->f_fsid.val[0] = vol->serial_no & 0xffffffff; |
2645 | sfs->f_fsid.val[1] = (vol->serial_no >> 32) & 0xffffffff; | 2643 | sfs->f_fsid.val[1] = (vol->serial_no >> 32) & 0xffffffff; |
2646 | /* Maximum length of filenames. */ | 2644 | /* Maximum length of filenames. */ |
2647 | sfs->f_namelen = NTFS_MAX_NAME_LEN; | 2645 | sfs->f_namelen = NTFS_MAX_NAME_LEN; |
2648 | return 0; | 2646 | return 0; |
2649 | } | 2647 | } |
2650 | 2648 | ||
2651 | #ifdef NTFS_RW | 2649 | #ifdef NTFS_RW |
2652 | static int ntfs_write_inode(struct inode *vi, struct writeback_control *wbc) | 2650 | static int ntfs_write_inode(struct inode *vi, struct writeback_control *wbc) |
2653 | { | 2651 | { |
2654 | return __ntfs_write_inode(vi, wbc->sync_mode == WB_SYNC_ALL); | 2652 | return __ntfs_write_inode(vi, wbc->sync_mode == WB_SYNC_ALL); |
2655 | } | 2653 | } |
2656 | #endif | 2654 | #endif |
2657 | 2655 | ||
2658 | /** | 2656 | /** |
2659 | * The complete super operations. | 2657 | * The complete super operations. |
2660 | */ | 2658 | */ |
2661 | static const struct super_operations ntfs_sops = { | 2659 | static const struct super_operations ntfs_sops = { |
2662 | .alloc_inode = ntfs_alloc_big_inode, /* VFS: Allocate new inode. */ | 2660 | .alloc_inode = ntfs_alloc_big_inode, /* VFS: Allocate new inode. */ |
2663 | .destroy_inode = ntfs_destroy_big_inode, /* VFS: Deallocate inode. */ | 2661 | .destroy_inode = ntfs_destroy_big_inode, /* VFS: Deallocate inode. */ |
2664 | #ifdef NTFS_RW | 2662 | #ifdef NTFS_RW |
2665 | //.dirty_inode = NULL, /* VFS: Called from | 2663 | //.dirty_inode = NULL, /* VFS: Called from |
2666 | // __mark_inode_dirty(). */ | 2664 | // __mark_inode_dirty(). */ |
2667 | .write_inode = ntfs_write_inode, /* VFS: Write dirty inode to | 2665 | .write_inode = ntfs_write_inode, /* VFS: Write dirty inode to |
2668 | disk. */ | 2666 | disk. */ |
2669 | //.drop_inode = NULL, /* VFS: Called just after the | 2667 | //.drop_inode = NULL, /* VFS: Called just after the |
2670 | // inode reference count has | 2668 | // inode reference count has |
2671 | // been decreased to zero. | 2669 | // been decreased to zero. |
2672 | // NOTE: The inode lock is | 2670 | // NOTE: The inode lock is |
2673 | // held. See fs/inode.c:: | 2671 | // held. See fs/inode.c:: |
2674 | // generic_drop_inode(). */ | 2672 | // generic_drop_inode(). */ |
2675 | //.delete_inode = NULL, /* VFS: Delete inode from disk. | 2673 | //.delete_inode = NULL, /* VFS: Delete inode from disk. |
2676 | // Called when i_count becomes | 2674 | // Called when i_count becomes |
2677 | // 0 and i_nlink is also 0. */ | 2675 | // 0 and i_nlink is also 0. */ |
2678 | //.write_super = NULL, /* Flush dirty super block to | 2676 | //.write_super = NULL, /* Flush dirty super block to |
2679 | // disk. */ | 2677 | // disk. */ |
2680 | //.sync_fs = NULL, /* ? */ | 2678 | //.sync_fs = NULL, /* ? */ |
2681 | //.write_super_lockfs = NULL, /* ? */ | 2679 | //.write_super_lockfs = NULL, /* ? */ |
2682 | //.unlockfs = NULL, /* ? */ | 2680 | //.unlockfs = NULL, /* ? */ |
2683 | #endif /* NTFS_RW */ | 2681 | #endif /* NTFS_RW */ |
2684 | .put_super = ntfs_put_super, /* Syscall: umount. */ | 2682 | .put_super = ntfs_put_super, /* Syscall: umount. */ |
2685 | .statfs = ntfs_statfs, /* Syscall: statfs */ | 2683 | .statfs = ntfs_statfs, /* Syscall: statfs */ |
2686 | .remount_fs = ntfs_remount, /* Syscall: mount -o remount. */ | 2684 | .remount_fs = ntfs_remount, /* Syscall: mount -o remount. */ |
2687 | .evict_inode = ntfs_evict_big_inode, /* VFS: Called when an inode is | 2685 | .evict_inode = ntfs_evict_big_inode, /* VFS: Called when an inode is |
2688 | removed from memory. */ | 2686 | removed from memory. */ |
2689 | //.umount_begin = NULL, /* Forced umount. */ | 2687 | //.umount_begin = NULL, /* Forced umount. */ |
2690 | .show_options = ntfs_show_options, /* Show mount options in | 2688 | .show_options = ntfs_show_options, /* Show mount options in |
2691 | proc. */ | 2689 | proc. */ |
2692 | }; | 2690 | }; |
2693 | 2691 | ||
2694 | /** | 2692 | /** |
2695 | * ntfs_fill_super - mount an ntfs filesystem | 2693 | * ntfs_fill_super - mount an ntfs filesystem |
2696 | * @sb: super block of ntfs filesystem to mount | 2694 | * @sb: super block of ntfs filesystem to mount |
2697 | * @opt: string containing the mount options | 2695 | * @opt: string containing the mount options |
2698 | * @silent: silence error output | 2696 | * @silent: silence error output |
2699 | * | 2697 | * |
2700 | * ntfs_fill_super() is called by the VFS to mount the device described by @sb | 2698 | * ntfs_fill_super() is called by the VFS to mount the device described by @sb |
2701 | * with the mount otions in @data with the NTFS filesystem. | 2699 | * with the mount otions in @data with the NTFS filesystem. |
2702 | * | 2700 | * |
2703 | * If @silent is true, remain silent even if errors are detected. This is used | 2701 | * If @silent is true, remain silent even if errors are detected. This is used |
2704 | * during bootup, when the kernel tries to mount the root filesystem with all | 2702 | * during bootup, when the kernel tries to mount the root filesystem with all |
2705 | * registered filesystems one after the other until one succeeds. This implies | 2703 | * registered filesystems one after the other until one succeeds. This implies |
2706 | * that all filesystems except the correct one will quite correctly and | 2704 | * that all filesystems except the correct one will quite correctly and |
2707 | * expectedly return an error, but nobody wants to see error messages when in | 2705 | * expectedly return an error, but nobody wants to see error messages when in |
2708 | * fact this is what is supposed to happen. | 2706 | * fact this is what is supposed to happen. |
2709 | * | 2707 | * |
2710 | * NOTE: @sb->s_flags contains the mount options flags. | 2708 | * NOTE: @sb->s_flags contains the mount options flags. |
2711 | */ | 2709 | */ |
2712 | static int ntfs_fill_super(struct super_block *sb, void *opt, const int silent) | 2710 | static int ntfs_fill_super(struct super_block *sb, void *opt, const int silent) |
2713 | { | 2711 | { |
2714 | ntfs_volume *vol; | 2712 | ntfs_volume *vol; |
2715 | struct buffer_head *bh; | 2713 | struct buffer_head *bh; |
2716 | struct inode *tmp_ino; | 2714 | struct inode *tmp_ino; |
2717 | int blocksize, result; | 2715 | int blocksize, result; |
2718 | 2716 | ||
2719 | /* | 2717 | /* |
2720 | * We do a pretty difficult piece of bootstrap by reading the | 2718 | * We do a pretty difficult piece of bootstrap by reading the |
2721 | * MFT (and other metadata) from disk into memory. We'll only | 2719 | * MFT (and other metadata) from disk into memory. We'll only |
2722 | * release this metadata during umount, so the locking patterns | 2720 | * release this metadata during umount, so the locking patterns |
2723 | * observed during bootstrap do not count. So turn off the | 2721 | * observed during bootstrap do not count. So turn off the |
2724 | * observation of locking patterns (strictly for this context | 2722 | * observation of locking patterns (strictly for this context |
2725 | * only) while mounting NTFS. [The validator is still active | 2723 | * only) while mounting NTFS. [The validator is still active |
2726 | * otherwise, even for this context: it will for example record | 2724 | * otherwise, even for this context: it will for example record |
2727 | * lock class registrations.] | 2725 | * lock class registrations.] |
2728 | */ | 2726 | */ |
2729 | lockdep_off(); | 2727 | lockdep_off(); |
2730 | ntfs_debug("Entering."); | 2728 | ntfs_debug("Entering."); |
2731 | #ifndef NTFS_RW | 2729 | #ifndef NTFS_RW |
2732 | sb->s_flags |= MS_RDONLY; | 2730 | sb->s_flags |= MS_RDONLY; |
2733 | #endif /* ! NTFS_RW */ | 2731 | #endif /* ! NTFS_RW */ |
2734 | /* Allocate a new ntfs_volume and place it in sb->s_fs_info. */ | 2732 | /* Allocate a new ntfs_volume and place it in sb->s_fs_info. */ |
2735 | sb->s_fs_info = kmalloc(sizeof(ntfs_volume), GFP_NOFS); | 2733 | sb->s_fs_info = kmalloc(sizeof(ntfs_volume), GFP_NOFS); |
2736 | vol = NTFS_SB(sb); | 2734 | vol = NTFS_SB(sb); |
2737 | if (!vol) { | 2735 | if (!vol) { |
2738 | if (!silent) | 2736 | if (!silent) |
2739 | ntfs_error(sb, "Allocation of NTFS volume structure " | 2737 | ntfs_error(sb, "Allocation of NTFS volume structure " |
2740 | "failed. Aborting mount..."); | 2738 | "failed. Aborting mount..."); |
2741 | lockdep_on(); | 2739 | lockdep_on(); |
2742 | return -ENOMEM; | 2740 | return -ENOMEM; |
2743 | } | 2741 | } |
2744 | /* Initialize ntfs_volume structure. */ | 2742 | /* Initialize ntfs_volume structure. */ |
2745 | *vol = (ntfs_volume) { | 2743 | *vol = (ntfs_volume) { |
2746 | .sb = sb, | 2744 | .sb = sb, |
2747 | /* | 2745 | /* |
2748 | * Default is group and other don't have any access to files or | 2746 | * Default is group and other don't have any access to files or |
2749 | * directories while owner has full access. Further, files by | 2747 | * directories while owner has full access. Further, files by |
2750 | * default are not executable but directories are of course | 2748 | * default are not executable but directories are of course |
2751 | * browseable. | 2749 | * browseable. |
2752 | */ | 2750 | */ |
2753 | .fmask = 0177, | 2751 | .fmask = 0177, |
2754 | .dmask = 0077, | 2752 | .dmask = 0077, |
2755 | }; | 2753 | }; |
2756 | init_rwsem(&vol->mftbmp_lock); | 2754 | init_rwsem(&vol->mftbmp_lock); |
2757 | init_rwsem(&vol->lcnbmp_lock); | 2755 | init_rwsem(&vol->lcnbmp_lock); |
2758 | 2756 | ||
2759 | /* By default, enable sparse support. */ | 2757 | /* By default, enable sparse support. */ |
2760 | NVolSetSparseEnabled(vol); | 2758 | NVolSetSparseEnabled(vol); |
2761 | 2759 | ||
2762 | /* Important to get the mount options dealt with now. */ | 2760 | /* Important to get the mount options dealt with now. */ |
2763 | if (!parse_options(vol, (char*)opt)) | 2761 | if (!parse_options(vol, (char*)opt)) |
2764 | goto err_out_now; | 2762 | goto err_out_now; |
2765 | 2763 | ||
2766 | /* We support sector sizes up to the PAGE_CACHE_SIZE. */ | 2764 | /* We support sector sizes up to the PAGE_CACHE_SIZE. */ |
2767 | if (bdev_logical_block_size(sb->s_bdev) > PAGE_CACHE_SIZE) { | 2765 | if (bdev_logical_block_size(sb->s_bdev) > PAGE_CACHE_SIZE) { |
2768 | if (!silent) | 2766 | if (!silent) |
2769 | ntfs_error(sb, "Device has unsupported sector size " | 2767 | ntfs_error(sb, "Device has unsupported sector size " |
2770 | "(%i). The maximum supported sector " | 2768 | "(%i). The maximum supported sector " |
2771 | "size on this architecture is %lu " | 2769 | "size on this architecture is %lu " |
2772 | "bytes.", | 2770 | "bytes.", |
2773 | bdev_logical_block_size(sb->s_bdev), | 2771 | bdev_logical_block_size(sb->s_bdev), |
2774 | PAGE_CACHE_SIZE); | 2772 | PAGE_CACHE_SIZE); |
2775 | goto err_out_now; | 2773 | goto err_out_now; |
2776 | } | 2774 | } |
2777 | /* | 2775 | /* |
2778 | * Setup the device access block size to NTFS_BLOCK_SIZE or the hard | 2776 | * Setup the device access block size to NTFS_BLOCK_SIZE or the hard |
2779 | * sector size, whichever is bigger. | 2777 | * sector size, whichever is bigger. |
2780 | */ | 2778 | */ |
2781 | blocksize = sb_min_blocksize(sb, NTFS_BLOCK_SIZE); | 2779 | blocksize = sb_min_blocksize(sb, NTFS_BLOCK_SIZE); |
2782 | if (blocksize < NTFS_BLOCK_SIZE) { | 2780 | if (blocksize < NTFS_BLOCK_SIZE) { |
2783 | if (!silent) | 2781 | if (!silent) |
2784 | ntfs_error(sb, "Unable to set device block size."); | 2782 | ntfs_error(sb, "Unable to set device block size."); |
2785 | goto err_out_now; | 2783 | goto err_out_now; |
2786 | } | 2784 | } |
2787 | BUG_ON(blocksize != sb->s_blocksize); | 2785 | BUG_ON(blocksize != sb->s_blocksize); |
2788 | ntfs_debug("Set device block size to %i bytes (block size bits %i).", | 2786 | ntfs_debug("Set device block size to %i bytes (block size bits %i).", |
2789 | blocksize, sb->s_blocksize_bits); | 2787 | blocksize, sb->s_blocksize_bits); |
2790 | /* Determine the size of the device in units of block_size bytes. */ | 2788 | /* Determine the size of the device in units of block_size bytes. */ |
2791 | if (!i_size_read(sb->s_bdev->bd_inode)) { | 2789 | if (!i_size_read(sb->s_bdev->bd_inode)) { |
2792 | if (!silent) | 2790 | if (!silent) |
2793 | ntfs_error(sb, "Unable to determine device size."); | 2791 | ntfs_error(sb, "Unable to determine device size."); |
2794 | goto err_out_now; | 2792 | goto err_out_now; |
2795 | } | 2793 | } |
2796 | vol->nr_blocks = i_size_read(sb->s_bdev->bd_inode) >> | 2794 | vol->nr_blocks = i_size_read(sb->s_bdev->bd_inode) >> |
2797 | sb->s_blocksize_bits; | 2795 | sb->s_blocksize_bits; |
2798 | /* Read the boot sector and return unlocked buffer head to it. */ | 2796 | /* Read the boot sector and return unlocked buffer head to it. */ |
2799 | if (!(bh = read_ntfs_boot_sector(sb, silent))) { | 2797 | if (!(bh = read_ntfs_boot_sector(sb, silent))) { |
2800 | if (!silent) | 2798 | if (!silent) |
2801 | ntfs_error(sb, "Not an NTFS volume."); | 2799 | ntfs_error(sb, "Not an NTFS volume."); |
2802 | goto err_out_now; | 2800 | goto err_out_now; |
2803 | } | 2801 | } |
2804 | /* | 2802 | /* |
2805 | * Extract the data from the boot sector and setup the ntfs volume | 2803 | * Extract the data from the boot sector and setup the ntfs volume |
2806 | * using it. | 2804 | * using it. |
2807 | */ | 2805 | */ |
2808 | result = parse_ntfs_boot_sector(vol, (NTFS_BOOT_SECTOR*)bh->b_data); | 2806 | result = parse_ntfs_boot_sector(vol, (NTFS_BOOT_SECTOR*)bh->b_data); |
2809 | brelse(bh); | 2807 | brelse(bh); |
2810 | if (!result) { | 2808 | if (!result) { |
2811 | if (!silent) | 2809 | if (!silent) |
2812 | ntfs_error(sb, "Unsupported NTFS filesystem."); | 2810 | ntfs_error(sb, "Unsupported NTFS filesystem."); |
2813 | goto err_out_now; | 2811 | goto err_out_now; |
2814 | } | 2812 | } |
2815 | /* | 2813 | /* |
2816 | * If the boot sector indicates a sector size bigger than the current | 2814 | * If the boot sector indicates a sector size bigger than the current |
2817 | * device block size, switch the device block size to the sector size. | 2815 | * device block size, switch the device block size to the sector size. |
2818 | * TODO: It may be possible to support this case even when the set | 2816 | * TODO: It may be possible to support this case even when the set |
2819 | * below fails, we would just be breaking up the i/o for each sector | 2817 | * below fails, we would just be breaking up the i/o for each sector |
2820 | * into multiple blocks for i/o purposes but otherwise it should just | 2818 | * into multiple blocks for i/o purposes but otherwise it should just |
2821 | * work. However it is safer to leave disabled until someone hits this | 2819 | * work. However it is safer to leave disabled until someone hits this |
2822 | * error message and then we can get them to try it without the setting | 2820 | * error message and then we can get them to try it without the setting |
2823 | * so we know for sure that it works. | 2821 | * so we know for sure that it works. |
2824 | */ | 2822 | */ |
2825 | if (vol->sector_size > blocksize) { | 2823 | if (vol->sector_size > blocksize) { |
2826 | blocksize = sb_set_blocksize(sb, vol->sector_size); | 2824 | blocksize = sb_set_blocksize(sb, vol->sector_size); |
2827 | if (blocksize != vol->sector_size) { | 2825 | if (blocksize != vol->sector_size) { |
2828 | if (!silent) | 2826 | if (!silent) |
2829 | ntfs_error(sb, "Unable to set device block " | 2827 | ntfs_error(sb, "Unable to set device block " |
2830 | "size to sector size (%i).", | 2828 | "size to sector size (%i).", |
2831 | vol->sector_size); | 2829 | vol->sector_size); |
2832 | goto err_out_now; | 2830 | goto err_out_now; |
2833 | } | 2831 | } |
2834 | BUG_ON(blocksize != sb->s_blocksize); | 2832 | BUG_ON(blocksize != sb->s_blocksize); |
2835 | vol->nr_blocks = i_size_read(sb->s_bdev->bd_inode) >> | 2833 | vol->nr_blocks = i_size_read(sb->s_bdev->bd_inode) >> |
2836 | sb->s_blocksize_bits; | 2834 | sb->s_blocksize_bits; |
2837 | ntfs_debug("Changed device block size to %i bytes (block size " | 2835 | ntfs_debug("Changed device block size to %i bytes (block size " |
2838 | "bits %i) to match volume sector size.", | 2836 | "bits %i) to match volume sector size.", |
2839 | blocksize, sb->s_blocksize_bits); | 2837 | blocksize, sb->s_blocksize_bits); |
2840 | } | 2838 | } |
2841 | /* Initialize the cluster and mft allocators. */ | 2839 | /* Initialize the cluster and mft allocators. */ |
2842 | ntfs_setup_allocators(vol); | 2840 | ntfs_setup_allocators(vol); |
2843 | /* Setup remaining fields in the super block. */ | 2841 | /* Setup remaining fields in the super block. */ |
2844 | sb->s_magic = NTFS_SB_MAGIC; | 2842 | sb->s_magic = NTFS_SB_MAGIC; |
2845 | /* | 2843 | /* |
2846 | * Ntfs allows 63 bits for the file size, i.e. correct would be: | 2844 | * Ntfs allows 63 bits for the file size, i.e. correct would be: |
2847 | * sb->s_maxbytes = ~0ULL >> 1; | 2845 | * sb->s_maxbytes = ~0ULL >> 1; |
2848 | * But the kernel uses a long as the page cache page index which on | 2846 | * But the kernel uses a long as the page cache page index which on |
2849 | * 32-bit architectures is only 32-bits. MAX_LFS_FILESIZE is kernel | 2847 | * 32-bit architectures is only 32-bits. MAX_LFS_FILESIZE is kernel |
2850 | * defined to the maximum the page cache page index can cope with | 2848 | * defined to the maximum the page cache page index can cope with |
2851 | * without overflowing the index or to 2^63 - 1, whichever is smaller. | 2849 | * without overflowing the index or to 2^63 - 1, whichever is smaller. |
2852 | */ | 2850 | */ |
2853 | sb->s_maxbytes = MAX_LFS_FILESIZE; | 2851 | sb->s_maxbytes = MAX_LFS_FILESIZE; |
2854 | /* Ntfs measures time in 100ns intervals. */ | 2852 | /* Ntfs measures time in 100ns intervals. */ |
2855 | sb->s_time_gran = 100; | 2853 | sb->s_time_gran = 100; |
2856 | /* | 2854 | /* |
2857 | * Now load the metadata required for the page cache and our address | 2855 | * Now load the metadata required for the page cache and our address |
2858 | * space operations to function. We do this by setting up a specialised | 2856 | * space operations to function. We do this by setting up a specialised |
2859 | * read_inode method and then just calling the normal iget() to obtain | 2857 | * read_inode method and then just calling the normal iget() to obtain |
2860 | * the inode for $MFT which is sufficient to allow our normal inode | 2858 | * the inode for $MFT which is sufficient to allow our normal inode |
2861 | * operations and associated address space operations to function. | 2859 | * operations and associated address space operations to function. |
2862 | */ | 2860 | */ |
2863 | sb->s_op = &ntfs_sops; | 2861 | sb->s_op = &ntfs_sops; |
2864 | tmp_ino = new_inode(sb); | 2862 | tmp_ino = new_inode(sb); |
2865 | if (!tmp_ino) { | 2863 | if (!tmp_ino) { |
2866 | if (!silent) | 2864 | if (!silent) |
2867 | ntfs_error(sb, "Failed to load essential metadata."); | 2865 | ntfs_error(sb, "Failed to load essential metadata."); |
2868 | goto err_out_now; | 2866 | goto err_out_now; |
2869 | } | 2867 | } |
2870 | tmp_ino->i_ino = FILE_MFT; | 2868 | tmp_ino->i_ino = FILE_MFT; |
2871 | insert_inode_hash(tmp_ino); | 2869 | insert_inode_hash(tmp_ino); |
2872 | if (ntfs_read_inode_mount(tmp_ino) < 0) { | 2870 | if (ntfs_read_inode_mount(tmp_ino) < 0) { |
2873 | if (!silent) | 2871 | if (!silent) |
2874 | ntfs_error(sb, "Failed to load essential metadata."); | 2872 | ntfs_error(sb, "Failed to load essential metadata."); |
2875 | goto iput_tmp_ino_err_out_now; | 2873 | goto iput_tmp_ino_err_out_now; |
2876 | } | 2874 | } |
2877 | mutex_lock(&ntfs_lock); | 2875 | mutex_lock(&ntfs_lock); |
2878 | /* | 2876 | /* |
2879 | * The current mount is a compression user if the cluster size is | 2877 | * The current mount is a compression user if the cluster size is |
2880 | * less than or equal 4kiB. | 2878 | * less than or equal 4kiB. |
2881 | */ | 2879 | */ |
2882 | if (vol->cluster_size <= 4096 && !ntfs_nr_compression_users++) { | 2880 | if (vol->cluster_size <= 4096 && !ntfs_nr_compression_users++) { |
2883 | result = allocate_compression_buffers(); | 2881 | result = allocate_compression_buffers(); |
2884 | if (result) { | 2882 | if (result) { |
2885 | ntfs_error(NULL, "Failed to allocate buffers " | 2883 | ntfs_error(NULL, "Failed to allocate buffers " |
2886 | "for compression engine."); | 2884 | "for compression engine."); |
2887 | ntfs_nr_compression_users--; | 2885 | ntfs_nr_compression_users--; |
2888 | mutex_unlock(&ntfs_lock); | 2886 | mutex_unlock(&ntfs_lock); |
2889 | goto iput_tmp_ino_err_out_now; | 2887 | goto iput_tmp_ino_err_out_now; |
2890 | } | 2888 | } |
2891 | } | 2889 | } |
2892 | /* | 2890 | /* |
2893 | * Generate the global default upcase table if necessary. Also | 2891 | * Generate the global default upcase table if necessary. Also |
2894 | * temporarily increment the number of upcase users to avoid race | 2892 | * temporarily increment the number of upcase users to avoid race |
2895 | * conditions with concurrent (u)mounts. | 2893 | * conditions with concurrent (u)mounts. |
2896 | */ | 2894 | */ |
2897 | if (!default_upcase) | 2895 | if (!default_upcase) |
2898 | default_upcase = generate_default_upcase(); | 2896 | default_upcase = generate_default_upcase(); |
2899 | ntfs_nr_upcase_users++; | 2897 | ntfs_nr_upcase_users++; |
2900 | mutex_unlock(&ntfs_lock); | 2898 | mutex_unlock(&ntfs_lock); |
2901 | /* | 2899 | /* |
2902 | * From now on, ignore @silent parameter. If we fail below this line, | 2900 | * From now on, ignore @silent parameter. If we fail below this line, |
2903 | * it will be due to a corrupt fs or a system error, so we report it. | 2901 | * it will be due to a corrupt fs or a system error, so we report it. |
2904 | */ | 2902 | */ |
2905 | /* | 2903 | /* |
2906 | * Open the system files with normal access functions and complete | 2904 | * Open the system files with normal access functions and complete |
2907 | * setting up the ntfs super block. | 2905 | * setting up the ntfs super block. |
2908 | */ | 2906 | */ |
2909 | if (!load_system_files(vol)) { | 2907 | if (!load_system_files(vol)) { |
2910 | ntfs_error(sb, "Failed to load system files."); | 2908 | ntfs_error(sb, "Failed to load system files."); |
2911 | goto unl_upcase_iput_tmp_ino_err_out_now; | 2909 | goto unl_upcase_iput_tmp_ino_err_out_now; |
2912 | } | 2910 | } |
2913 | if ((sb->s_root = d_alloc_root(vol->root_ino))) { | 2911 | if ((sb->s_root = d_alloc_root(vol->root_ino))) { |
2914 | /* We grab a reference, simulating an ntfs_iget(). */ | 2912 | /* We grab a reference, simulating an ntfs_iget(). */ |
2915 | ihold(vol->root_ino); | 2913 | ihold(vol->root_ino); |
2916 | ntfs_debug("Exiting, status successful."); | 2914 | ntfs_debug("Exiting, status successful."); |
2917 | /* Release the default upcase if it has no users. */ | 2915 | /* Release the default upcase if it has no users. */ |
2918 | mutex_lock(&ntfs_lock); | 2916 | mutex_lock(&ntfs_lock); |
2919 | if (!--ntfs_nr_upcase_users && default_upcase) { | 2917 | if (!--ntfs_nr_upcase_users && default_upcase) { |
2920 | ntfs_free(default_upcase); | 2918 | ntfs_free(default_upcase); |
2921 | default_upcase = NULL; | 2919 | default_upcase = NULL; |
2922 | } | 2920 | } |
2923 | mutex_unlock(&ntfs_lock); | 2921 | mutex_unlock(&ntfs_lock); |
2924 | sb->s_export_op = &ntfs_export_ops; | 2922 | sb->s_export_op = &ntfs_export_ops; |
2925 | lockdep_on(); | 2923 | lockdep_on(); |
2926 | return 0; | 2924 | return 0; |
2927 | } | 2925 | } |
2928 | ntfs_error(sb, "Failed to allocate root directory."); | 2926 | ntfs_error(sb, "Failed to allocate root directory."); |
2929 | /* Clean up after the successful load_system_files() call from above. */ | 2927 | /* Clean up after the successful load_system_files() call from above. */ |
2930 | // TODO: Use ntfs_put_super() instead of repeating all this code... | 2928 | // TODO: Use ntfs_put_super() instead of repeating all this code... |
2931 | // FIXME: Should mark the volume clean as the error is most likely | 2929 | // FIXME: Should mark the volume clean as the error is most likely |
2932 | // -ENOMEM. | 2930 | // -ENOMEM. |
2933 | iput(vol->vol_ino); | 2931 | iput(vol->vol_ino); |
2934 | vol->vol_ino = NULL; | 2932 | vol->vol_ino = NULL; |
2935 | /* NTFS 3.0+ specific clean up. */ | 2933 | /* NTFS 3.0+ specific clean up. */ |
2936 | if (vol->major_ver >= 3) { | 2934 | if (vol->major_ver >= 3) { |
2937 | #ifdef NTFS_RW | 2935 | #ifdef NTFS_RW |
2938 | if (vol->usnjrnl_j_ino) { | 2936 | if (vol->usnjrnl_j_ino) { |
2939 | iput(vol->usnjrnl_j_ino); | 2937 | iput(vol->usnjrnl_j_ino); |
2940 | vol->usnjrnl_j_ino = NULL; | 2938 | vol->usnjrnl_j_ino = NULL; |
2941 | } | 2939 | } |
2942 | if (vol->usnjrnl_max_ino) { | 2940 | if (vol->usnjrnl_max_ino) { |
2943 | iput(vol->usnjrnl_max_ino); | 2941 | iput(vol->usnjrnl_max_ino); |
2944 | vol->usnjrnl_max_ino = NULL; | 2942 | vol->usnjrnl_max_ino = NULL; |
2945 | } | 2943 | } |
2946 | if (vol->usnjrnl_ino) { | 2944 | if (vol->usnjrnl_ino) { |
2947 | iput(vol->usnjrnl_ino); | 2945 | iput(vol->usnjrnl_ino); |
2948 | vol->usnjrnl_ino = NULL; | 2946 | vol->usnjrnl_ino = NULL; |
2949 | } | 2947 | } |
2950 | if (vol->quota_q_ino) { | 2948 | if (vol->quota_q_ino) { |
2951 | iput(vol->quota_q_ino); | 2949 | iput(vol->quota_q_ino); |
2952 | vol->quota_q_ino = NULL; | 2950 | vol->quota_q_ino = NULL; |
2953 | } | 2951 | } |
2954 | if (vol->quota_ino) { | 2952 | if (vol->quota_ino) { |
2955 | iput(vol->quota_ino); | 2953 | iput(vol->quota_ino); |
2956 | vol->quota_ino = NULL; | 2954 | vol->quota_ino = NULL; |
2957 | } | 2955 | } |
2958 | #endif /* NTFS_RW */ | 2956 | #endif /* NTFS_RW */ |
2959 | if (vol->extend_ino) { | 2957 | if (vol->extend_ino) { |
2960 | iput(vol->extend_ino); | 2958 | iput(vol->extend_ino); |
2961 | vol->extend_ino = NULL; | 2959 | vol->extend_ino = NULL; |
2962 | } | 2960 | } |
2963 | if (vol->secure_ino) { | 2961 | if (vol->secure_ino) { |
2964 | iput(vol->secure_ino); | 2962 | iput(vol->secure_ino); |
2965 | vol->secure_ino = NULL; | 2963 | vol->secure_ino = NULL; |
2966 | } | 2964 | } |
2967 | } | 2965 | } |
2968 | iput(vol->root_ino); | 2966 | iput(vol->root_ino); |
2969 | vol->root_ino = NULL; | 2967 | vol->root_ino = NULL; |
2970 | iput(vol->lcnbmp_ino); | 2968 | iput(vol->lcnbmp_ino); |
2971 | vol->lcnbmp_ino = NULL; | 2969 | vol->lcnbmp_ino = NULL; |
2972 | iput(vol->mftbmp_ino); | 2970 | iput(vol->mftbmp_ino); |
2973 | vol->mftbmp_ino = NULL; | 2971 | vol->mftbmp_ino = NULL; |
2974 | #ifdef NTFS_RW | 2972 | #ifdef NTFS_RW |
2975 | if (vol->logfile_ino) { | 2973 | if (vol->logfile_ino) { |
2976 | iput(vol->logfile_ino); | 2974 | iput(vol->logfile_ino); |
2977 | vol->logfile_ino = NULL; | 2975 | vol->logfile_ino = NULL; |
2978 | } | 2976 | } |
2979 | if (vol->mftmirr_ino) { | 2977 | if (vol->mftmirr_ino) { |
2980 | iput(vol->mftmirr_ino); | 2978 | iput(vol->mftmirr_ino); |
2981 | vol->mftmirr_ino = NULL; | 2979 | vol->mftmirr_ino = NULL; |
2982 | } | 2980 | } |
2983 | #endif /* NTFS_RW */ | 2981 | #endif /* NTFS_RW */ |
2984 | /* Throw away the table of attribute definitions. */ | 2982 | /* Throw away the table of attribute definitions. */ |
2985 | vol->attrdef_size = 0; | 2983 | vol->attrdef_size = 0; |
2986 | if (vol->attrdef) { | 2984 | if (vol->attrdef) { |
2987 | ntfs_free(vol->attrdef); | 2985 | ntfs_free(vol->attrdef); |
2988 | vol->attrdef = NULL; | 2986 | vol->attrdef = NULL; |
2989 | } | 2987 | } |
2990 | vol->upcase_len = 0; | 2988 | vol->upcase_len = 0; |
2991 | mutex_lock(&ntfs_lock); | 2989 | mutex_lock(&ntfs_lock); |
2992 | if (vol->upcase == default_upcase) { | 2990 | if (vol->upcase == default_upcase) { |
2993 | ntfs_nr_upcase_users--; | 2991 | ntfs_nr_upcase_users--; |
2994 | vol->upcase = NULL; | 2992 | vol->upcase = NULL; |
2995 | } | 2993 | } |
2996 | mutex_unlock(&ntfs_lock); | 2994 | mutex_unlock(&ntfs_lock); |
2997 | if (vol->upcase) { | 2995 | if (vol->upcase) { |
2998 | ntfs_free(vol->upcase); | 2996 | ntfs_free(vol->upcase); |
2999 | vol->upcase = NULL; | 2997 | vol->upcase = NULL; |
3000 | } | 2998 | } |
3001 | if (vol->nls_map) { | 2999 | if (vol->nls_map) { |
3002 | unload_nls(vol->nls_map); | 3000 | unload_nls(vol->nls_map); |
3003 | vol->nls_map = NULL; | 3001 | vol->nls_map = NULL; |
3004 | } | 3002 | } |
3005 | /* Error exit code path. */ | 3003 | /* Error exit code path. */ |
3006 | unl_upcase_iput_tmp_ino_err_out_now: | 3004 | unl_upcase_iput_tmp_ino_err_out_now: |
3007 | /* | 3005 | /* |
3008 | * Decrease the number of upcase users and destroy the global default | 3006 | * Decrease the number of upcase users and destroy the global default |
3009 | * upcase table if necessary. | 3007 | * upcase table if necessary. |
3010 | */ | 3008 | */ |
3011 | mutex_lock(&ntfs_lock); | 3009 | mutex_lock(&ntfs_lock); |
3012 | if (!--ntfs_nr_upcase_users && default_upcase) { | 3010 | if (!--ntfs_nr_upcase_users && default_upcase) { |
3013 | ntfs_free(default_upcase); | 3011 | ntfs_free(default_upcase); |
3014 | default_upcase = NULL; | 3012 | default_upcase = NULL; |
3015 | } | 3013 | } |
3016 | if (vol->cluster_size <= 4096 && !--ntfs_nr_compression_users) | 3014 | if (vol->cluster_size <= 4096 && !--ntfs_nr_compression_users) |
3017 | free_compression_buffers(); | 3015 | free_compression_buffers(); |
3018 | mutex_unlock(&ntfs_lock); | 3016 | mutex_unlock(&ntfs_lock); |
3019 | iput_tmp_ino_err_out_now: | 3017 | iput_tmp_ino_err_out_now: |
3020 | iput(tmp_ino); | 3018 | iput(tmp_ino); |
3021 | if (vol->mft_ino && vol->mft_ino != tmp_ino) | 3019 | if (vol->mft_ino && vol->mft_ino != tmp_ino) |
3022 | iput(vol->mft_ino); | 3020 | iput(vol->mft_ino); |
3023 | vol->mft_ino = NULL; | 3021 | vol->mft_ino = NULL; |
3024 | /* Errors at this stage are irrelevant. */ | 3022 | /* Errors at this stage are irrelevant. */ |
3025 | err_out_now: | 3023 | err_out_now: |
3026 | sb->s_fs_info = NULL; | 3024 | sb->s_fs_info = NULL; |
3027 | kfree(vol); | 3025 | kfree(vol); |
3028 | ntfs_debug("Failed, returning -EINVAL."); | 3026 | ntfs_debug("Failed, returning -EINVAL."); |
3029 | lockdep_on(); | 3027 | lockdep_on(); |
3030 | return -EINVAL; | 3028 | return -EINVAL; |
3031 | } | 3029 | } |
3032 | 3030 | ||
3033 | /* | 3031 | /* |
3034 | * This is a slab cache to optimize allocations and deallocations of Unicode | 3032 | * This is a slab cache to optimize allocations and deallocations of Unicode |
3035 | * strings of the maximum length allowed by NTFS, which is NTFS_MAX_NAME_LEN | 3033 | * strings of the maximum length allowed by NTFS, which is NTFS_MAX_NAME_LEN |
3036 | * (255) Unicode characters + a terminating NULL Unicode character. | 3034 | * (255) Unicode characters + a terminating NULL Unicode character. |
3037 | */ | 3035 | */ |
3038 | struct kmem_cache *ntfs_name_cache; | 3036 | struct kmem_cache *ntfs_name_cache; |
3039 | 3037 | ||
3040 | /* Slab caches for efficient allocation/deallocation of inodes. */ | 3038 | /* Slab caches for efficient allocation/deallocation of inodes. */ |
3041 | struct kmem_cache *ntfs_inode_cache; | 3039 | struct kmem_cache *ntfs_inode_cache; |
3042 | struct kmem_cache *ntfs_big_inode_cache; | 3040 | struct kmem_cache *ntfs_big_inode_cache; |
3043 | 3041 | ||
3044 | /* Init once constructor for the inode slab cache. */ | 3042 | /* Init once constructor for the inode slab cache. */ |
3045 | static void ntfs_big_inode_init_once(void *foo) | 3043 | static void ntfs_big_inode_init_once(void *foo) |
3046 | { | 3044 | { |
3047 | ntfs_inode *ni = (ntfs_inode *)foo; | 3045 | ntfs_inode *ni = (ntfs_inode *)foo; |
3048 | 3046 | ||
3049 | inode_init_once(VFS_I(ni)); | 3047 | inode_init_once(VFS_I(ni)); |
3050 | } | 3048 | } |
3051 | 3049 | ||
3052 | /* | 3050 | /* |
3053 | * Slab caches to optimize allocations and deallocations of attribute search | 3051 | * Slab caches to optimize allocations and deallocations of attribute search |
3054 | * contexts and index contexts, respectively. | 3052 | * contexts and index contexts, respectively. |
3055 | */ | 3053 | */ |
3056 | struct kmem_cache *ntfs_attr_ctx_cache; | 3054 | struct kmem_cache *ntfs_attr_ctx_cache; |
3057 | struct kmem_cache *ntfs_index_ctx_cache; | 3055 | struct kmem_cache *ntfs_index_ctx_cache; |
3058 | 3056 | ||
3059 | /* Driver wide mutex. */ | 3057 | /* Driver wide mutex. */ |
3060 | DEFINE_MUTEX(ntfs_lock); | 3058 | DEFINE_MUTEX(ntfs_lock); |
3061 | 3059 | ||
3062 | static struct dentry *ntfs_mount(struct file_system_type *fs_type, | 3060 | static struct dentry *ntfs_mount(struct file_system_type *fs_type, |
3063 | int flags, const char *dev_name, void *data) | 3061 | int flags, const char *dev_name, void *data) |
3064 | { | 3062 | { |
3065 | return mount_bdev(fs_type, flags, dev_name, data, ntfs_fill_super); | 3063 | return mount_bdev(fs_type, flags, dev_name, data, ntfs_fill_super); |
3066 | } | 3064 | } |
3067 | 3065 | ||
3068 | static struct file_system_type ntfs_fs_type = { | 3066 | static struct file_system_type ntfs_fs_type = { |
3069 | .owner = THIS_MODULE, | 3067 | .owner = THIS_MODULE, |
3070 | .name = "ntfs", | 3068 | .name = "ntfs", |
3071 | .mount = ntfs_mount, | 3069 | .mount = ntfs_mount, |
3072 | .kill_sb = kill_block_super, | 3070 | .kill_sb = kill_block_super, |
3073 | .fs_flags = FS_REQUIRES_DEV, | 3071 | .fs_flags = FS_REQUIRES_DEV, |
3074 | }; | 3072 | }; |
3075 | 3073 | ||
3076 | /* Stable names for the slab caches. */ | 3074 | /* Stable names for the slab caches. */ |
3077 | static const char ntfs_index_ctx_cache_name[] = "ntfs_index_ctx_cache"; | 3075 | static const char ntfs_index_ctx_cache_name[] = "ntfs_index_ctx_cache"; |
3078 | static const char ntfs_attr_ctx_cache_name[] = "ntfs_attr_ctx_cache"; | 3076 | static const char ntfs_attr_ctx_cache_name[] = "ntfs_attr_ctx_cache"; |
3079 | static const char ntfs_name_cache_name[] = "ntfs_name_cache"; | 3077 | static const char ntfs_name_cache_name[] = "ntfs_name_cache"; |
3080 | static const char ntfs_inode_cache_name[] = "ntfs_inode_cache"; | 3078 | static const char ntfs_inode_cache_name[] = "ntfs_inode_cache"; |
3081 | static const char ntfs_big_inode_cache_name[] = "ntfs_big_inode_cache"; | 3079 | static const char ntfs_big_inode_cache_name[] = "ntfs_big_inode_cache"; |
3082 | 3080 | ||
3083 | static int __init init_ntfs_fs(void) | 3081 | static int __init init_ntfs_fs(void) |
3084 | { | 3082 | { |
3085 | int err = 0; | 3083 | int err = 0; |
3086 | 3084 | ||
3087 | /* This may be ugly but it results in pretty output so who cares. (-8 */ | 3085 | /* This may be ugly but it results in pretty output so who cares. (-8 */ |
3088 | printk(KERN_INFO "NTFS driver " NTFS_VERSION " [Flags: R/" | 3086 | printk(KERN_INFO "NTFS driver " NTFS_VERSION " [Flags: R/" |
3089 | #ifdef NTFS_RW | 3087 | #ifdef NTFS_RW |
3090 | "W" | 3088 | "W" |
3091 | #else | 3089 | #else |
3092 | "O" | 3090 | "O" |
3093 | #endif | 3091 | #endif |
3094 | #ifdef DEBUG | 3092 | #ifdef DEBUG |
3095 | " DEBUG" | 3093 | " DEBUG" |
3096 | #endif | 3094 | #endif |
3097 | #ifdef MODULE | 3095 | #ifdef MODULE |
3098 | " MODULE" | 3096 | " MODULE" |
3099 | #endif | 3097 | #endif |
3100 | "].\n"); | 3098 | "].\n"); |
3101 | 3099 | ||
3102 | ntfs_debug("Debug messages are enabled."); | 3100 | ntfs_debug("Debug messages are enabled."); |
3103 | 3101 | ||
3104 | ntfs_index_ctx_cache = kmem_cache_create(ntfs_index_ctx_cache_name, | 3102 | ntfs_index_ctx_cache = kmem_cache_create(ntfs_index_ctx_cache_name, |
3105 | sizeof(ntfs_index_context), 0 /* offset */, | 3103 | sizeof(ntfs_index_context), 0 /* offset */, |
3106 | SLAB_HWCACHE_ALIGN, NULL /* ctor */); | 3104 | SLAB_HWCACHE_ALIGN, NULL /* ctor */); |
3107 | if (!ntfs_index_ctx_cache) { | 3105 | if (!ntfs_index_ctx_cache) { |
3108 | printk(KERN_CRIT "NTFS: Failed to create %s!\n", | 3106 | printk(KERN_CRIT "NTFS: Failed to create %s!\n", |
3109 | ntfs_index_ctx_cache_name); | 3107 | ntfs_index_ctx_cache_name); |
3110 | goto ictx_err_out; | 3108 | goto ictx_err_out; |
3111 | } | 3109 | } |
3112 | ntfs_attr_ctx_cache = kmem_cache_create(ntfs_attr_ctx_cache_name, | 3110 | ntfs_attr_ctx_cache = kmem_cache_create(ntfs_attr_ctx_cache_name, |
3113 | sizeof(ntfs_attr_search_ctx), 0 /* offset */, | 3111 | sizeof(ntfs_attr_search_ctx), 0 /* offset */, |
3114 | SLAB_HWCACHE_ALIGN, NULL /* ctor */); | 3112 | SLAB_HWCACHE_ALIGN, NULL /* ctor */); |
3115 | if (!ntfs_attr_ctx_cache) { | 3113 | if (!ntfs_attr_ctx_cache) { |
3116 | printk(KERN_CRIT "NTFS: Failed to create %s!\n", | 3114 | printk(KERN_CRIT "NTFS: Failed to create %s!\n", |
3117 | ntfs_attr_ctx_cache_name); | 3115 | ntfs_attr_ctx_cache_name); |
3118 | goto actx_err_out; | 3116 | goto actx_err_out; |
3119 | } | 3117 | } |
3120 | 3118 | ||
3121 | ntfs_name_cache = kmem_cache_create(ntfs_name_cache_name, | 3119 | ntfs_name_cache = kmem_cache_create(ntfs_name_cache_name, |
3122 | (NTFS_MAX_NAME_LEN+1) * sizeof(ntfschar), 0, | 3120 | (NTFS_MAX_NAME_LEN+1) * sizeof(ntfschar), 0, |
3123 | SLAB_HWCACHE_ALIGN, NULL); | 3121 | SLAB_HWCACHE_ALIGN, NULL); |
3124 | if (!ntfs_name_cache) { | 3122 | if (!ntfs_name_cache) { |
3125 | printk(KERN_CRIT "NTFS: Failed to create %s!\n", | 3123 | printk(KERN_CRIT "NTFS: Failed to create %s!\n", |
3126 | ntfs_name_cache_name); | 3124 | ntfs_name_cache_name); |
3127 | goto name_err_out; | 3125 | goto name_err_out; |
3128 | } | 3126 | } |
3129 | 3127 | ||
3130 | ntfs_inode_cache = kmem_cache_create(ntfs_inode_cache_name, | 3128 | ntfs_inode_cache = kmem_cache_create(ntfs_inode_cache_name, |
3131 | sizeof(ntfs_inode), 0, | 3129 | sizeof(ntfs_inode), 0, |
3132 | SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD, NULL); | 3130 | SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD, NULL); |
3133 | if (!ntfs_inode_cache) { | 3131 | if (!ntfs_inode_cache) { |
3134 | printk(KERN_CRIT "NTFS: Failed to create %s!\n", | 3132 | printk(KERN_CRIT "NTFS: Failed to create %s!\n", |
3135 | ntfs_inode_cache_name); | 3133 | ntfs_inode_cache_name); |
3136 | goto inode_err_out; | 3134 | goto inode_err_out; |
3137 | } | 3135 | } |
3138 | 3136 | ||
3139 | ntfs_big_inode_cache = kmem_cache_create(ntfs_big_inode_cache_name, | 3137 | ntfs_big_inode_cache = kmem_cache_create(ntfs_big_inode_cache_name, |
3140 | sizeof(big_ntfs_inode), 0, | 3138 | sizeof(big_ntfs_inode), 0, |
3141 | SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD, | 3139 | SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD, |
3142 | ntfs_big_inode_init_once); | 3140 | ntfs_big_inode_init_once); |
3143 | if (!ntfs_big_inode_cache) { | 3141 | if (!ntfs_big_inode_cache) { |
3144 | printk(KERN_CRIT "NTFS: Failed to create %s!\n", | 3142 | printk(KERN_CRIT "NTFS: Failed to create %s!\n", |
3145 | ntfs_big_inode_cache_name); | 3143 | ntfs_big_inode_cache_name); |
3146 | goto big_inode_err_out; | 3144 | goto big_inode_err_out; |
3147 | } | 3145 | } |
3148 | 3146 | ||
3149 | /* Register the ntfs sysctls. */ | 3147 | /* Register the ntfs sysctls. */ |
3150 | err = ntfs_sysctl(1); | 3148 | err = ntfs_sysctl(1); |
3151 | if (err) { | 3149 | if (err) { |
3152 | printk(KERN_CRIT "NTFS: Failed to register NTFS sysctls!\n"); | 3150 | printk(KERN_CRIT "NTFS: Failed to register NTFS sysctls!\n"); |
3153 | goto sysctl_err_out; | 3151 | goto sysctl_err_out; |
3154 | } | 3152 | } |
3155 | 3153 | ||
3156 | err = register_filesystem(&ntfs_fs_type); | 3154 | err = register_filesystem(&ntfs_fs_type); |
3157 | if (!err) { | 3155 | if (!err) { |
3158 | ntfs_debug("NTFS driver registered successfully."); | 3156 | ntfs_debug("NTFS driver registered successfully."); |
3159 | return 0; /* Success! */ | 3157 | return 0; /* Success! */ |
3160 | } | 3158 | } |
3161 | printk(KERN_CRIT "NTFS: Failed to register NTFS filesystem driver!\n"); | 3159 | printk(KERN_CRIT "NTFS: Failed to register NTFS filesystem driver!\n"); |
3162 | 3160 | ||
3163 | sysctl_err_out: | 3161 | sysctl_err_out: |
3164 | kmem_cache_destroy(ntfs_big_inode_cache); | 3162 | kmem_cache_destroy(ntfs_big_inode_cache); |
3165 | big_inode_err_out: | 3163 | big_inode_err_out: |
3166 | kmem_cache_destroy(ntfs_inode_cache); | 3164 | kmem_cache_destroy(ntfs_inode_cache); |
3167 | inode_err_out: | 3165 | inode_err_out: |
3168 | kmem_cache_destroy(ntfs_name_cache); | 3166 | kmem_cache_destroy(ntfs_name_cache); |
3169 | name_err_out: | 3167 | name_err_out: |
3170 | kmem_cache_destroy(ntfs_attr_ctx_cache); | 3168 | kmem_cache_destroy(ntfs_attr_ctx_cache); |
3171 | actx_err_out: | 3169 | actx_err_out: |
3172 | kmem_cache_destroy(ntfs_index_ctx_cache); | 3170 | kmem_cache_destroy(ntfs_index_ctx_cache); |
3173 | ictx_err_out: | 3171 | ictx_err_out: |
3174 | if (!err) { | 3172 | if (!err) { |
3175 | printk(KERN_CRIT "NTFS: Aborting NTFS filesystem driver " | 3173 | printk(KERN_CRIT "NTFS: Aborting NTFS filesystem driver " |
3176 | "registration...\n"); | 3174 | "registration...\n"); |
3177 | err = -ENOMEM; | 3175 | err = -ENOMEM; |
3178 | } | 3176 | } |
3179 | return err; | 3177 | return err; |
3180 | } | 3178 | } |
3181 | 3179 | ||
3182 | static void __exit exit_ntfs_fs(void) | 3180 | static void __exit exit_ntfs_fs(void) |
3183 | { | 3181 | { |
3184 | ntfs_debug("Unregistering NTFS driver."); | 3182 | ntfs_debug("Unregistering NTFS driver."); |
3185 | 3183 | ||
3186 | unregister_filesystem(&ntfs_fs_type); | 3184 | unregister_filesystem(&ntfs_fs_type); |
3187 | kmem_cache_destroy(ntfs_big_inode_cache); | 3185 | kmem_cache_destroy(ntfs_big_inode_cache); |
3188 | kmem_cache_destroy(ntfs_inode_cache); | 3186 | kmem_cache_destroy(ntfs_inode_cache); |
3189 | kmem_cache_destroy(ntfs_name_cache); | 3187 | kmem_cache_destroy(ntfs_name_cache); |
3190 | kmem_cache_destroy(ntfs_attr_ctx_cache); | 3188 | kmem_cache_destroy(ntfs_attr_ctx_cache); |
3191 | kmem_cache_destroy(ntfs_index_ctx_cache); | 3189 | kmem_cache_destroy(ntfs_index_ctx_cache); |
3192 | /* Unregister the ntfs sysctls. */ | 3190 | /* Unregister the ntfs sysctls. */ |
3193 | ntfs_sysctl(0); | 3191 | ntfs_sysctl(0); |
3194 | } | 3192 | } |
3195 | 3193 | ||
3196 | MODULE_AUTHOR("Anton Altaparmakov <anton@tuxera.com>"); | 3194 | MODULE_AUTHOR("Anton Altaparmakov <anton@tuxera.com>"); |
3197 | MODULE_DESCRIPTION("NTFS 1.2/3.x driver - Copyright (c) 2001-2011 Anton Altaparmakov and Tuxera Inc."); | 3195 | MODULE_DESCRIPTION("NTFS 1.2/3.x driver - Copyright (c) 2001-2011 Anton Altaparmakov and Tuxera Inc."); |
3198 | MODULE_VERSION(NTFS_VERSION); | 3196 | MODULE_VERSION(NTFS_VERSION); |
3199 | MODULE_LICENSE("GPL"); | 3197 | MODULE_LICENSE("GPL"); |
3200 | #ifdef DEBUG | 3198 | #ifdef DEBUG |
3201 | module_param(debug_msgs, bint, 0); | 3199 | module_param(debug_msgs, bint, 0); |
3202 | MODULE_PARM_DESC(debug_msgs, "Enable debug messages."); | 3200 | MODULE_PARM_DESC(debug_msgs, "Enable debug messages."); |
3203 | #endif | 3201 | #endif |
3204 | 3202 | ||
3205 | module_init(init_ntfs_fs) | 3203 | module_init(init_ntfs_fs) |
3206 | module_exit(exit_ntfs_fs) | 3204 | module_exit(exit_ntfs_fs) |
3207 | 3205 |