Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ntfs: update super block operations

Update the super block operations to support the new fs_context-based
mount API, full read-write support including ->sync_fs, and file system
shutdown support.

Update ntfs_statfs() to provide statistics using atomic counters for free
clusters and MFT records.

Add a dedicated workqueue to compute the total number of free clusters by
scanning asynchronously. Synchronous bitmap scanning during mount
can take a very long time on large volumes, severely delaying mount
completion. Moving this to the background allows mount to finish almost
immediately.

Implement ntfs_write_volume_label() to allow changing the volume label.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Acked-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>

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