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