2 * super.c - NTFS kernel super block handling. Part of the Linux-NTFS project.
4 * Copyright (c) 2001-2005 Anton Altaparmakov
5 * Copyright (c) 2001,2002 Richard Russon
7 * This program/include file is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as published
9 * by the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program/include file is distributed in the hope that it will be
13 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program (in the main directory of the Linux-NTFS
19 * distribution in the file COPYING); if not, write to the Free Software
20 * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <linux/stddef.h>
24 #include <linux/init.h>
25 #include <linux/string.h>
26 #include <linux/spinlock.h>
27 #include <linux/blkdev.h> /* For bdev_hardsect_size(). */
28 #include <linux/backing-dev.h>
29 #include <linux/buffer_head.h>
30 #include <linux/vfs.h>
31 #include <linux/moduleparam.h>
32 #include <linux/smp_lock.h>
44 /* Number of mounted filesystems which have compression enabled. */
45 static unsigned long ntfs_nr_compression_users;
47 /* A global default upcase table and a corresponding reference count. */
48 static ntfschar *default_upcase = NULL;
49 static unsigned long ntfs_nr_upcase_users = 0;
51 /* Error constants/strings used in inode.c::ntfs_show_options(). */
53 /* One of these must be present, default is ON_ERRORS_CONTINUE. */
54 ON_ERRORS_PANIC = 0x01,
55 ON_ERRORS_REMOUNT_RO = 0x02,
56 ON_ERRORS_CONTINUE = 0x04,
57 /* Optional, can be combined with any of the above. */
58 ON_ERRORS_RECOVER = 0x10,
61 const option_t on_errors_arr[] = {
62 { ON_ERRORS_PANIC, "panic" },
63 { ON_ERRORS_REMOUNT_RO, "remount-ro", },
64 { ON_ERRORS_CONTINUE, "continue", },
65 { ON_ERRORS_RECOVER, "recover" },
72 * Copied from old ntfs driver (which copied from vfat driver).
74 static int simple_getbool(char *s, BOOL *setval)
77 if (!strcmp(s, "1") || !strcmp(s, "yes") || !strcmp(s, "true"))
79 else if (!strcmp(s, "0") || !strcmp(s, "no") ||
90 * parse_options - parse the (re)mount options
92 * @opt: string containing the (re)mount options
94 * Parse the recognized options in @opt for the ntfs volume described by @vol.
96 static BOOL parse_options(ntfs_volume *vol, char *opt)
99 static char *utf8 = "utf8";
100 int errors = 0, sloppy = 0;
101 uid_t uid = (uid_t)-1;
102 gid_t gid = (gid_t)-1;
103 mode_t fmask = (mode_t)-1, dmask = (mode_t)-1;
104 int mft_zone_multiplier = -1, on_errors = -1;
105 int show_sys_files = -1, case_sensitive = -1, disable_sparse = -1;
106 struct nls_table *nls_map = NULL, *old_nls;
108 /* I am lazy... (-8 */
109 #define NTFS_GETOPT_WITH_DEFAULT(option, variable, default_value) \
110 if (!strcmp(p, option)) { \
112 variable = default_value; \
114 variable = simple_strtoul(ov = v, &v, 0); \
119 #define NTFS_GETOPT(option, variable) \
120 if (!strcmp(p, option)) { \
123 variable = simple_strtoul(ov = v, &v, 0); \
127 #define NTFS_GETOPT_BOOL(option, variable) \
128 if (!strcmp(p, option)) { \
130 if (!simple_getbool(v, &val)) \
134 #define NTFS_GETOPT_OPTIONS_ARRAY(option, variable, opt_array) \
135 if (!strcmp(p, option)) { \
140 if (variable == -1) \
142 for (_i = 0; opt_array[_i].str && *opt_array[_i].str; _i++) \
143 if (!strcmp(opt_array[_i].str, v)) { \
144 variable |= opt_array[_i].val; \
147 if (!opt_array[_i].str || !*opt_array[_i].str) \
151 goto no_mount_options;
152 ntfs_debug("Entering with mount options string: %s", opt);
153 while ((p = strsep(&opt, ","))) {
154 if ((v = strchr(p, '=')))
156 NTFS_GETOPT("uid", uid)
157 else NTFS_GETOPT("gid", gid)
158 else NTFS_GETOPT("umask", fmask = dmask)
159 else NTFS_GETOPT("fmask", fmask)
160 else NTFS_GETOPT("dmask", dmask)
161 else NTFS_GETOPT("mft_zone_multiplier", mft_zone_multiplier)
162 else NTFS_GETOPT_WITH_DEFAULT("sloppy", sloppy, TRUE)
163 else NTFS_GETOPT_BOOL("show_sys_files", show_sys_files)
164 else NTFS_GETOPT_BOOL("case_sensitive", case_sensitive)
165 else NTFS_GETOPT_BOOL("disable_sparse", disable_sparse)
166 else NTFS_GETOPT_OPTIONS_ARRAY("errors", on_errors,
168 else if (!strcmp(p, "posix") || !strcmp(p, "show_inodes"))
169 ntfs_warning(vol->sb, "Ignoring obsolete option %s.",
171 else if (!strcmp(p, "nls") || !strcmp(p, "iocharset")) {
172 if (!strcmp(p, "iocharset"))
173 ntfs_warning(vol->sb, "Option iocharset is "
174 "deprecated. Please use "
175 "option nls=<charsetname> in "
181 nls_map = load_nls(v);
184 ntfs_error(vol->sb, "NLS character set "
188 ntfs_error(vol->sb, "NLS character set %s not "
189 "found. Using previous one %s.",
190 v, old_nls->charset);
192 } else /* nls_map */ {
196 } else if (!strcmp(p, "utf8")) {
198 ntfs_warning(vol->sb, "Option utf8 is no longer "
199 "supported, using option nls=utf8. Please "
200 "use option nls=utf8 in the future and "
201 "make sure utf8 is compiled either as a "
202 "module or into the kernel.");
205 else if (!simple_getbool(v, &val))
212 ntfs_error(vol->sb, "Unrecognized mount option %s.", p);
213 if (errors < INT_MAX)
216 #undef NTFS_GETOPT_OPTIONS_ARRAY
217 #undef NTFS_GETOPT_BOOL
219 #undef NTFS_GETOPT_WITH_DEFAULT
222 if (errors && !sloppy)
225 ntfs_warning(vol->sb, "Sloppy option given. Ignoring "
226 "unrecognized mount option(s) and continuing.");
227 /* Keep this first! */
228 if (on_errors != -1) {
230 ntfs_error(vol->sb, "Invalid errors option argument "
231 "or bug in options parser.");
236 if (vol->nls_map && vol->nls_map != nls_map) {
237 ntfs_error(vol->sb, "Cannot change NLS character set "
240 } /* else (!vol->nls_map) */
241 ntfs_debug("Using NLS character set %s.", nls_map->charset);
242 vol->nls_map = nls_map;
243 } else /* (!nls_map) */ {
245 vol->nls_map = load_nls_default();
247 ntfs_error(vol->sb, "Failed to load default "
248 "NLS character set.");
251 ntfs_debug("Using default NLS character set (%s).",
252 vol->nls_map->charset);
255 if (mft_zone_multiplier != -1) {
256 if (vol->mft_zone_multiplier && vol->mft_zone_multiplier !=
257 mft_zone_multiplier) {
258 ntfs_error(vol->sb, "Cannot change mft_zone_multiplier "
262 if (mft_zone_multiplier < 1 || mft_zone_multiplier > 4) {
263 ntfs_error(vol->sb, "Invalid mft_zone_multiplier. "
264 "Using default value, i.e. 1.");
265 mft_zone_multiplier = 1;
267 vol->mft_zone_multiplier = mft_zone_multiplier;
269 if (!vol->mft_zone_multiplier)
270 vol->mft_zone_multiplier = 1;
272 vol->on_errors = on_errors;
273 if (!vol->on_errors || vol->on_errors == ON_ERRORS_RECOVER)
274 vol->on_errors |= ON_ERRORS_CONTINUE;
275 if (uid != (uid_t)-1)
277 if (gid != (gid_t)-1)
279 if (fmask != (mode_t)-1)
281 if (dmask != (mode_t)-1)
283 if (show_sys_files != -1) {
285 NVolSetShowSystemFiles(vol);
287 NVolClearShowSystemFiles(vol);
289 if (case_sensitive != -1) {
291 NVolSetCaseSensitive(vol);
293 NVolClearCaseSensitive(vol);
295 if (disable_sparse != -1) {
297 NVolClearSparseEnabled(vol);
299 if (!NVolSparseEnabled(vol) &&
300 vol->major_ver && vol->major_ver < 3)
301 ntfs_warning(vol->sb, "Not enabling sparse "
302 "support due to NTFS volume "
303 "version %i.%i (need at least "
304 "version 3.0).", vol->major_ver,
307 NVolSetSparseEnabled(vol);
312 ntfs_error(vol->sb, "The %s option requires an argument.", p);
315 ntfs_error(vol->sb, "The %s option requires a boolean argument.", p);
318 ntfs_error(vol->sb, "Invalid %s option argument: %s", p, ov);
325 * ntfs_write_volume_flags - write new flags to the volume information flags
326 * @vol: ntfs volume on which to modify the flags
327 * @flags: new flags value for the volume information flags
329 * Internal function. You probably want to use ntfs_{set,clear}_volume_flags()
330 * instead (see below).
332 * Replace the volume information flags on the volume @vol with the value
333 * supplied in @flags. Note, this overwrites the volume information flags, so
334 * make sure to combine the flags you want to modify with the old flags and use
335 * the result when calling ntfs_write_volume_flags().
337 * Return 0 on success and -errno on error.
339 static int ntfs_write_volume_flags(ntfs_volume *vol, const VOLUME_FLAGS flags)
341 ntfs_inode *ni = NTFS_I(vol->vol_ino);
343 VOLUME_INFORMATION *vi;
344 ntfs_attr_search_ctx *ctx;
347 ntfs_debug("Entering, old flags = 0x%x, new flags = 0x%x.",
348 le16_to_cpu(vol->vol_flags), le16_to_cpu(flags));
349 if (vol->vol_flags == flags)
352 m = map_mft_record(ni);
357 ctx = ntfs_attr_get_search_ctx(ni, m);
360 goto put_unm_err_out;
362 err = ntfs_attr_lookup(AT_VOLUME_INFORMATION, NULL, 0, 0, 0, NULL, 0,
365 goto put_unm_err_out;
366 vi = (VOLUME_INFORMATION*)((u8*)ctx->attr +
367 le16_to_cpu(ctx->attr->data.resident.value_offset));
368 vol->vol_flags = vi->flags = flags;
369 flush_dcache_mft_record_page(ctx->ntfs_ino);
370 mark_mft_record_dirty(ctx->ntfs_ino);
371 ntfs_attr_put_search_ctx(ctx);
372 unmap_mft_record(ni);
378 ntfs_attr_put_search_ctx(ctx);
379 unmap_mft_record(ni);
381 ntfs_error(vol->sb, "Failed with error code %i.", -err);
386 * ntfs_set_volume_flags - set bits in the volume information flags
387 * @vol: ntfs volume on which to modify the flags
388 * @flags: flags to set on the volume
390 * Set the bits in @flags in the volume information flags on the volume @vol.
392 * Return 0 on success and -errno on error.
394 static inline int ntfs_set_volume_flags(ntfs_volume *vol, VOLUME_FLAGS flags)
396 flags &= VOLUME_FLAGS_MASK;
397 return ntfs_write_volume_flags(vol, vol->vol_flags | flags);
401 * ntfs_clear_volume_flags - clear bits in the volume information flags
402 * @vol: ntfs volume on which to modify the flags
403 * @flags: flags to clear on the volume
405 * Clear the bits in @flags in the volume information flags on the volume @vol.
407 * Return 0 on success and -errno on error.
409 static inline int ntfs_clear_volume_flags(ntfs_volume *vol, VOLUME_FLAGS flags)
411 flags &= VOLUME_FLAGS_MASK;
412 flags = vol->vol_flags & cpu_to_le16(~le16_to_cpu(flags));
413 return ntfs_write_volume_flags(vol, flags);
419 * ntfs_remount - change the mount options of a mounted ntfs filesystem
420 * @sb: superblock of mounted ntfs filesystem
421 * @flags: remount flags
422 * @opt: remount options string
424 * Change the mount options of an already mounted ntfs filesystem.
426 * NOTE: The VFS sets the @sb->s_flags remount flags to @flags after
427 * ntfs_remount() returns successfully (i.e. returns 0). Otherwise,
428 * @sb->s_flags are not changed.
430 static int ntfs_remount(struct super_block *sb, int *flags, char *opt)
432 ntfs_volume *vol = NTFS_SB(sb);
434 ntfs_debug("Entering with remount options string: %s", opt);
436 /* For read-only compiled driver, enforce all read-only flags. */
437 *flags |= MS_RDONLY | MS_NOATIME | MS_NODIRATIME;
440 * For the read-write compiled driver, if we are remounting read-write,
441 * make sure there are no volume errors and that no unsupported volume
442 * flags are set. Also, empty the logfile journal as it would become
443 * stale as soon as something is written to the volume and mark the
444 * volume dirty so that chkdsk is run if the volume is not umounted
445 * cleanly. Finally, mark the quotas out of date so Windows rescans
446 * the volume on boot and updates them.
448 * When remounting read-only, mark the volume clean if no volume errors
451 if ((sb->s_flags & MS_RDONLY) && !(*flags & MS_RDONLY)) {
452 static const char *es = ". Cannot remount read-write.";
454 /* Remounting read-write. */
455 if (NVolErrors(vol)) {
456 ntfs_error(sb, "Volume has errors and is read-only%s",
460 if (vol->vol_flags & VOLUME_IS_DIRTY) {
461 ntfs_error(sb, "Volume is dirty and read-only%s", es);
464 if (vol->vol_flags & VOLUME_MUST_MOUNT_RO_MASK) {
465 ntfs_error(sb, "Volume has unsupported flags set and "
466 "is read-only%s", es);
469 if (ntfs_set_volume_flags(vol, VOLUME_IS_DIRTY)) {
470 ntfs_error(sb, "Failed to set dirty bit in volume "
471 "information flags%s", es);
475 // TODO: Enable this code once we start modifying anything that
476 // is different between NTFS 1.2 and 3.x...
477 /* Set NT4 compatibility flag on newer NTFS version volumes. */
478 if ((vol->major_ver > 1)) {
479 if (ntfs_set_volume_flags(vol, VOLUME_MOUNTED_ON_NT4)) {
480 ntfs_error(sb, "Failed to set NT4 "
481 "compatibility flag%s", es);
487 if (!ntfs_empty_logfile(vol->logfile_ino)) {
488 ntfs_error(sb, "Failed to empty journal $LogFile%s",
493 if (!ntfs_mark_quotas_out_of_date(vol)) {
494 ntfs_error(sb, "Failed to mark quotas out of date%s",
499 } else if (!(sb->s_flags & MS_RDONLY) && (*flags & MS_RDONLY)) {
500 /* Remounting read-only. */
501 if (!NVolErrors(vol)) {
502 if (ntfs_clear_volume_flags(vol, VOLUME_IS_DIRTY))
503 ntfs_warning(sb, "Failed to clear dirty bit "
504 "in volume information "
505 "flags. Run chkdsk.");
510 // TODO: Deal with *flags.
512 if (!parse_options(vol, opt))
519 * is_boot_sector_ntfs - check whether a boot sector is a valid NTFS boot sector
520 * @sb: Super block of the device to which @b belongs.
521 * @b: Boot sector of device @sb to check.
522 * @silent: If TRUE, all output will be silenced.
524 * is_boot_sector_ntfs() checks whether the boot sector @b is a valid NTFS boot
525 * sector. Returns TRUE if it is valid and FALSE if not.
527 * @sb is only needed for warning/error output, i.e. it can be NULL when silent
530 static BOOL is_boot_sector_ntfs(const struct super_block *sb,
531 const NTFS_BOOT_SECTOR *b, const BOOL silent)
534 * Check that checksum == sum of u32 values from b to the checksum
535 * field. If checksum is zero, no checking is done.
537 if ((void*)b < (void*)&b->checksum && b->checksum) {
541 for (i = 0, u = (le32*)b; u < (le32*)(&b->checksum); ++u)
542 i += le32_to_cpup(u);
543 if (le32_to_cpu(b->checksum) != i)
546 /* Check OEMidentifier is "NTFS " */
547 if (b->oem_id != magicNTFS)
549 /* Check bytes per sector value is between 256 and 4096. */
550 if (le16_to_cpu(b->bpb.bytes_per_sector) < 0x100 ||
551 le16_to_cpu(b->bpb.bytes_per_sector) > 0x1000)
553 /* Check sectors per cluster value is valid. */
554 switch (b->bpb.sectors_per_cluster) {
555 case 1: case 2: case 4: case 8: case 16: case 32: case 64: case 128:
560 /* Check the cluster size is not above 65536 bytes. */
561 if ((u32)le16_to_cpu(b->bpb.bytes_per_sector) *
562 b->bpb.sectors_per_cluster > 0x10000)
564 /* Check reserved/unused fields are really zero. */
565 if (le16_to_cpu(b->bpb.reserved_sectors) ||
566 le16_to_cpu(b->bpb.root_entries) ||
567 le16_to_cpu(b->bpb.sectors) ||
568 le16_to_cpu(b->bpb.sectors_per_fat) ||
569 le32_to_cpu(b->bpb.large_sectors) || b->bpb.fats)
571 /* Check clusters per file mft record value is valid. */
572 if ((u8)b->clusters_per_mft_record < 0xe1 ||
573 (u8)b->clusters_per_mft_record > 0xf7)
574 switch (b->clusters_per_mft_record) {
575 case 1: case 2: case 4: case 8: case 16: case 32: case 64:
580 /* Check clusters per index block value is valid. */
581 if ((u8)b->clusters_per_index_record < 0xe1 ||
582 (u8)b->clusters_per_index_record > 0xf7)
583 switch (b->clusters_per_index_record) {
584 case 1: case 2: case 4: case 8: case 16: case 32: case 64:
590 * Check for valid end of sector marker. We will work without it, but
591 * many BIOSes will refuse to boot from a bootsector if the magic is
592 * incorrect, so we emit a warning.
594 if (!silent && b->end_of_sector_marker != cpu_to_le16(0xaa55))
595 ntfs_warning(sb, "Invalid end of sector marker.");
602 * read_ntfs_boot_sector - read the NTFS boot sector of a device
603 * @sb: super block of device to read the boot sector from
604 * @silent: if true, suppress all output
606 * Reads the boot sector from the device and validates it. If that fails, tries
607 * to read the backup boot sector, first from the end of the device a-la NT4 and
608 * later and then from the middle of the device a-la NT3.51 and before.
610 * If a valid boot sector is found but it is not the primary boot sector, we
611 * repair the primary boot sector silently (unless the device is read-only or
612 * the primary boot sector is not accessible).
614 * NOTE: To call this function, @sb must have the fields s_dev, the ntfs super
615 * block (u.ntfs_sb), nr_blocks and the device flags (s_flags) initialized
616 * to their respective values.
618 * Return the unlocked buffer head containing the boot sector or NULL on error.
620 static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
623 const char *read_err_str = "Unable to read %s boot sector.";
624 struct buffer_head *bh_primary, *bh_backup;
625 long nr_blocks = NTFS_SB(sb)->nr_blocks;
627 /* Try to read primary boot sector. */
628 if ((bh_primary = sb_bread(sb, 0))) {
629 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
630 bh_primary->b_data, silent))
633 ntfs_error(sb, "Primary boot sector is invalid.");
635 ntfs_error(sb, read_err_str, "primary");
636 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
640 ntfs_error(sb, "Mount option errors=recover not used. "
641 "Aborting without trying to recover.");
644 /* Try to read NT4+ backup boot sector. */
645 if ((bh_backup = sb_bread(sb, nr_blocks - 1))) {
646 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
647 bh_backup->b_data, silent))
648 goto hotfix_primary_boot_sector;
651 ntfs_error(sb, read_err_str, "backup");
652 /* Try to read NT3.51- backup boot sector. */
653 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
654 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
655 bh_backup->b_data, silent))
656 goto hotfix_primary_boot_sector;
658 ntfs_error(sb, "Could not find a valid backup boot "
662 ntfs_error(sb, read_err_str, "backup");
663 /* We failed. Cleanup and return. */
667 hotfix_primary_boot_sector:
670 * If we managed to read sector zero and the volume is not
671 * read-only, copy the found, valid backup boot sector to the
672 * primary boot sector.
674 if (!(sb->s_flags & MS_RDONLY)) {
675 ntfs_warning(sb, "Hot-fix: Recovering invalid primary "
676 "boot sector from backup copy.");
677 memcpy(bh_primary->b_data, bh_backup->b_data,
679 mark_buffer_dirty(bh_primary);
680 sync_dirty_buffer(bh_primary);
681 if (buffer_uptodate(bh_primary)) {
685 ntfs_error(sb, "Hot-fix: Device write error while "
686 "recovering primary boot sector.");
688 ntfs_warning(sb, "Hot-fix: Recovery of primary boot "
689 "sector failed: Read-only mount.");
693 ntfs_warning(sb, "Using backup boot sector.");
698 * parse_ntfs_boot_sector - parse the boot sector and store the data in @vol
699 * @vol: volume structure to initialise with data from boot sector
700 * @b: boot sector to parse
702 * Parse the ntfs boot sector @b and store all imporant information therein in
703 * the ntfs super block @vol. Return TRUE on success and FALSE on error.
705 static BOOL parse_ntfs_boot_sector(ntfs_volume *vol, const NTFS_BOOT_SECTOR *b)
707 unsigned int sectors_per_cluster_bits, nr_hidden_sects;
708 int clusters_per_mft_record, clusters_per_index_record;
711 vol->sector_size = le16_to_cpu(b->bpb.bytes_per_sector);
712 vol->sector_size_bits = ffs(vol->sector_size) - 1;
713 ntfs_debug("vol->sector_size = %i (0x%x)", vol->sector_size,
715 ntfs_debug("vol->sector_size_bits = %i (0x%x)", vol->sector_size_bits,
716 vol->sector_size_bits);
717 if (vol->sector_size != vol->sb->s_blocksize)
718 ntfs_warning(vol->sb, "The boot sector indicates a sector size "
719 "different from the device sector size.");
720 ntfs_debug("sectors_per_cluster = 0x%x", b->bpb.sectors_per_cluster);
721 sectors_per_cluster_bits = ffs(b->bpb.sectors_per_cluster) - 1;
722 ntfs_debug("sectors_per_cluster_bits = 0x%x",
723 sectors_per_cluster_bits);
724 nr_hidden_sects = le32_to_cpu(b->bpb.hidden_sectors);
725 ntfs_debug("number of hidden sectors = 0x%x", nr_hidden_sects);
726 vol->cluster_size = vol->sector_size << sectors_per_cluster_bits;
727 vol->cluster_size_mask = vol->cluster_size - 1;
728 vol->cluster_size_bits = ffs(vol->cluster_size) - 1;
729 ntfs_debug("vol->cluster_size = %i (0x%x)", vol->cluster_size,
731 ntfs_debug("vol->cluster_size_mask = 0x%x", vol->cluster_size_mask);
732 ntfs_debug("vol->cluster_size_bits = %i (0x%x)",
733 vol->cluster_size_bits, vol->cluster_size_bits);
734 if (vol->sector_size > vol->cluster_size) {
735 ntfs_error(vol->sb, "Sector sizes above the cluster size are "
736 "not supported. Sorry.");
739 if (vol->sb->s_blocksize > vol->cluster_size) {
740 ntfs_error(vol->sb, "Cluster sizes smaller than the device "
741 "sector size are not supported. Sorry.");
744 clusters_per_mft_record = b->clusters_per_mft_record;
745 ntfs_debug("clusters_per_mft_record = %i (0x%x)",
746 clusters_per_mft_record, clusters_per_mft_record);
747 if (clusters_per_mft_record > 0)
748 vol->mft_record_size = vol->cluster_size <<
749 (ffs(clusters_per_mft_record) - 1);
752 * When mft_record_size < cluster_size, clusters_per_mft_record
753 * = -log2(mft_record_size) bytes. mft_record_size normaly is
754 * 1024 bytes, which is encoded as 0xF6 (-10 in decimal).
756 vol->mft_record_size = 1 << -clusters_per_mft_record;
757 vol->mft_record_size_mask = vol->mft_record_size - 1;
758 vol->mft_record_size_bits = ffs(vol->mft_record_size) - 1;
759 ntfs_debug("vol->mft_record_size = %i (0x%x)", vol->mft_record_size,
760 vol->mft_record_size);
761 ntfs_debug("vol->mft_record_size_mask = 0x%x",
762 vol->mft_record_size_mask);
763 ntfs_debug("vol->mft_record_size_bits = %i (0x%x)",
764 vol->mft_record_size_bits, vol->mft_record_size_bits);
766 * We cannot support mft record sizes above the PAGE_CACHE_SIZE since
767 * we store $MFT/$DATA, the table of mft records in the page cache.
769 if (vol->mft_record_size > PAGE_CACHE_SIZE) {
770 ntfs_error(vol->sb, "Mft record size %i (0x%x) exceeds the "
771 "page cache size on your system %lu (0x%lx). "
772 "This is not supported. Sorry.",
773 vol->mft_record_size, vol->mft_record_size,
774 PAGE_CACHE_SIZE, PAGE_CACHE_SIZE);
777 clusters_per_index_record = b->clusters_per_index_record;
778 ntfs_debug("clusters_per_index_record = %i (0x%x)",
779 clusters_per_index_record, clusters_per_index_record);
780 if (clusters_per_index_record > 0)
781 vol->index_record_size = vol->cluster_size <<
782 (ffs(clusters_per_index_record) - 1);
785 * When index_record_size < cluster_size,
786 * clusters_per_index_record = -log2(index_record_size) bytes.
787 * index_record_size normaly equals 4096 bytes, which is
788 * encoded as 0xF4 (-12 in decimal).
790 vol->index_record_size = 1 << -clusters_per_index_record;
791 vol->index_record_size_mask = vol->index_record_size - 1;
792 vol->index_record_size_bits = ffs(vol->index_record_size) - 1;
793 ntfs_debug("vol->index_record_size = %i (0x%x)",
794 vol->index_record_size, vol->index_record_size);
795 ntfs_debug("vol->index_record_size_mask = 0x%x",
796 vol->index_record_size_mask);
797 ntfs_debug("vol->index_record_size_bits = %i (0x%x)",
798 vol->index_record_size_bits,
799 vol->index_record_size_bits);
801 * Get the size of the volume in clusters and check for 64-bit-ness.
802 * Windows currently only uses 32 bits to save the clusters so we do
803 * the same as it is much faster on 32-bit CPUs.
805 ll = sle64_to_cpu(b->number_of_sectors) >> sectors_per_cluster_bits;
806 if ((u64)ll >= 1ULL << 32) {
807 ntfs_error(vol->sb, "Cannot handle 64-bit clusters. Sorry.");
810 vol->nr_clusters = ll;
811 ntfs_debug("vol->nr_clusters = 0x%llx", (long long)vol->nr_clusters);
813 * On an architecture where unsigned long is 32-bits, we restrict the
814 * volume size to 2TiB (2^41). On a 64-bit architecture, the compiler
815 * will hopefully optimize the whole check away.
817 if (sizeof(unsigned long) < 8) {
818 if ((ll << vol->cluster_size_bits) >= (1ULL << 41)) {
819 ntfs_error(vol->sb, "Volume size (%lluTiB) is too "
820 "large for this architecture. "
821 "Maximum supported is 2TiB. Sorry.",
822 (unsigned long long)ll >> (40 -
823 vol->cluster_size_bits));
827 ll = sle64_to_cpu(b->mft_lcn);
828 if (ll >= vol->nr_clusters) {
829 ntfs_error(vol->sb, "MFT LCN is beyond end of volume. Weird.");
833 ntfs_debug("vol->mft_lcn = 0x%llx", (long long)vol->mft_lcn);
834 ll = sle64_to_cpu(b->mftmirr_lcn);
835 if (ll >= vol->nr_clusters) {
836 ntfs_error(vol->sb, "MFTMirr LCN is beyond end of volume. "
840 vol->mftmirr_lcn = ll;
841 ntfs_debug("vol->mftmirr_lcn = 0x%llx", (long long)vol->mftmirr_lcn);
844 * Work out the size of the mft mirror in number of mft records. If the
845 * cluster size is less than or equal to the size taken by four mft
846 * records, the mft mirror stores the first four mft records. If the
847 * cluster size is bigger than the size taken by four mft records, the
848 * mft mirror contains as many mft records as will fit into one
851 if (vol->cluster_size <= (4 << vol->mft_record_size_bits))
852 vol->mftmirr_size = 4;
854 vol->mftmirr_size = vol->cluster_size >>
855 vol->mft_record_size_bits;
856 ntfs_debug("vol->mftmirr_size = %i", vol->mftmirr_size);
858 vol->serial_no = le64_to_cpu(b->volume_serial_number);
859 ntfs_debug("vol->serial_no = 0x%llx",
860 (unsigned long long)vol->serial_no);
865 * ntfs_setup_allocators - initialize the cluster and mft allocators
866 * @vol: volume structure for which to setup the allocators
868 * Setup the cluster (lcn) and mft allocators to the starting values.
870 static void ntfs_setup_allocators(ntfs_volume *vol)
873 LCN mft_zone_size, mft_lcn;
876 ntfs_debug("vol->mft_zone_multiplier = 0x%x",
877 vol->mft_zone_multiplier);
879 /* Determine the size of the MFT zone. */
880 mft_zone_size = vol->nr_clusters;
881 switch (vol->mft_zone_multiplier) { /* % of volume size in clusters */
883 mft_zone_size >>= 1; /* 50% */
886 mft_zone_size = (mft_zone_size +
887 (mft_zone_size >> 1)) >> 2; /* 37.5% */
890 mft_zone_size >>= 2; /* 25% */
894 mft_zone_size >>= 3; /* 12.5% */
897 /* Setup the mft zone. */
898 vol->mft_zone_start = vol->mft_zone_pos = vol->mft_lcn;
899 ntfs_debug("vol->mft_zone_pos = 0x%llx",
900 (unsigned long long)vol->mft_zone_pos);
902 * Calculate the mft_lcn for an unmodified NTFS volume (see mkntfs
903 * source) and if the actual mft_lcn is in the expected place or even
904 * further to the front of the volume, extend the mft_zone to cover the
905 * beginning of the volume as well. This is in order to protect the
906 * area reserved for the mft bitmap as well within the mft_zone itself.
907 * On non-standard volumes we do not protect it as the overhead would
908 * be higher than the speed increase we would get by doing it.
910 mft_lcn = (8192 + 2 * vol->cluster_size - 1) / vol->cluster_size;
911 if (mft_lcn * vol->cluster_size < 16 * 1024)
912 mft_lcn = (16 * 1024 + vol->cluster_size - 1) /
914 if (vol->mft_zone_start <= mft_lcn)
915 vol->mft_zone_start = 0;
916 ntfs_debug("vol->mft_zone_start = 0x%llx",
917 (unsigned long long)vol->mft_zone_start);
919 * Need to cap the mft zone on non-standard volumes so that it does
920 * not point outside the boundaries of the volume. We do this by
921 * halving the zone size until we are inside the volume.
923 vol->mft_zone_end = vol->mft_lcn + mft_zone_size;
924 while (vol->mft_zone_end >= vol->nr_clusters) {
926 vol->mft_zone_end = vol->mft_lcn + mft_zone_size;
928 ntfs_debug("vol->mft_zone_end = 0x%llx",
929 (unsigned long long)vol->mft_zone_end);
931 * Set the current position within each data zone to the start of the
934 vol->data1_zone_pos = vol->mft_zone_end;
935 ntfs_debug("vol->data1_zone_pos = 0x%llx",
936 (unsigned long long)vol->data1_zone_pos);
937 vol->data2_zone_pos = 0;
938 ntfs_debug("vol->data2_zone_pos = 0x%llx",
939 (unsigned long long)vol->data2_zone_pos);
941 /* Set the mft data allocation position to mft record 24. */
942 vol->mft_data_pos = 24;
943 ntfs_debug("vol->mft_data_pos = 0x%llx",
944 (unsigned long long)vol->mft_data_pos);
951 * load_and_init_mft_mirror - load and setup the mft mirror inode for a volume
952 * @vol: ntfs super block describing device whose mft mirror to load
954 * Return TRUE on success or FALSE on error.
956 static BOOL load_and_init_mft_mirror(ntfs_volume *vol)
958 struct inode *tmp_ino;
961 ntfs_debug("Entering.");
962 /* Get mft mirror inode. */
963 tmp_ino = ntfs_iget(vol->sb, FILE_MFTMirr);
964 if (IS_ERR(tmp_ino) || is_bad_inode(tmp_ino)) {
965 if (!IS_ERR(tmp_ino))
967 /* Caller will display error message. */
971 * Re-initialize some specifics about $MFTMirr's inode as
972 * ntfs_read_inode() will have set up the default ones.
974 /* Set uid and gid to root. */
975 tmp_ino->i_uid = tmp_ino->i_gid = 0;
976 /* Regular file. No access for anyone. */
977 tmp_ino->i_mode = S_IFREG;
978 /* No VFS initiated operations allowed for $MFTMirr. */
979 tmp_ino->i_op = &ntfs_empty_inode_ops;
980 tmp_ino->i_fop = &ntfs_empty_file_ops;
981 /* Put in our special address space operations. */
982 tmp_ino->i_mapping->a_ops = &ntfs_mst_aops;
983 tmp_ni = NTFS_I(tmp_ino);
984 /* The $MFTMirr, like the $MFT is multi sector transfer protected. */
985 NInoSetMstProtected(tmp_ni);
986 NInoSetSparseDisabled(tmp_ni);
988 * Set up our little cheat allowing us to reuse the async read io
989 * completion handler for directories.
991 tmp_ni->itype.index.block_size = vol->mft_record_size;
992 tmp_ni->itype.index.block_size_bits = vol->mft_record_size_bits;
993 vol->mftmirr_ino = tmp_ino;
999 * check_mft_mirror - compare contents of the mft mirror with the mft
1000 * @vol: ntfs super block describing device whose mft mirror to check
1002 * Return TRUE on success or FALSE on error.
1004 * Note, this function also results in the mft mirror runlist being completely
1005 * mapped into memory. The mft mirror write code requires this and will BUG()
1006 * should it find an unmapped runlist element.
1008 static BOOL check_mft_mirror(ntfs_volume *vol)
1010 struct super_block *sb = vol->sb;
1011 ntfs_inode *mirr_ni;
1012 struct page *mft_page, *mirr_page;
1014 runlist_element *rl, rl2[2];
1016 int mrecs_per_page, i;
1018 ntfs_debug("Entering.");
1019 /* Compare contents of $MFT and $MFTMirr. */
1020 mrecs_per_page = PAGE_CACHE_SIZE / vol->mft_record_size;
1021 BUG_ON(!mrecs_per_page);
1022 BUG_ON(!vol->mftmirr_size);
1023 mft_page = mirr_page = NULL;
1024 kmft = kmirr = NULL;
1029 /* Switch pages if necessary. */
1030 if (!(i % mrecs_per_page)) {
1032 ntfs_unmap_page(mft_page);
1033 ntfs_unmap_page(mirr_page);
1035 /* Get the $MFT page. */
1036 mft_page = ntfs_map_page(vol->mft_ino->i_mapping,
1038 if (IS_ERR(mft_page)) {
1039 ntfs_error(sb, "Failed to read $MFT.");
1042 kmft = page_address(mft_page);
1043 /* Get the $MFTMirr page. */
1044 mirr_page = ntfs_map_page(vol->mftmirr_ino->i_mapping,
1046 if (IS_ERR(mirr_page)) {
1047 ntfs_error(sb, "Failed to read $MFTMirr.");
1050 kmirr = page_address(mirr_page);
1053 /* Make sure the record is ok. */
1054 if (ntfs_is_baad_recordp((le32*)kmft)) {
1055 ntfs_error(sb, "Incomplete multi sector transfer "
1056 "detected in mft record %i.", i);
1058 ntfs_unmap_page(mirr_page);
1060 ntfs_unmap_page(mft_page);
1063 if (ntfs_is_baad_recordp((le32*)kmirr)) {
1064 ntfs_error(sb, "Incomplete multi sector transfer "
1065 "detected in mft mirror record %i.", i);
1068 /* Get the amount of data in the current record. */
1069 bytes = le32_to_cpu(((MFT_RECORD*)kmft)->bytes_in_use);
1070 if (!bytes || bytes > vol->mft_record_size) {
1071 bytes = le32_to_cpu(((MFT_RECORD*)kmirr)->bytes_in_use);
1072 if (!bytes || bytes > vol->mft_record_size)
1073 bytes = vol->mft_record_size;
1075 /* Compare the two records. */
1076 if (memcmp(kmft, kmirr, bytes)) {
1077 ntfs_error(sb, "$MFT and $MFTMirr (record %i) do not "
1078 "match. Run ntfsfix or chkdsk.", i);
1081 kmft += vol->mft_record_size;
1082 kmirr += vol->mft_record_size;
1083 } while (++i < vol->mftmirr_size);
1084 /* Release the last pages. */
1085 ntfs_unmap_page(mft_page);
1086 ntfs_unmap_page(mirr_page);
1088 /* Construct the mft mirror runlist by hand. */
1090 rl2[0].lcn = vol->mftmirr_lcn;
1091 rl2[0].length = (vol->mftmirr_size * vol->mft_record_size +
1092 vol->cluster_size - 1) / vol->cluster_size;
1093 rl2[1].vcn = rl2[0].length;
1094 rl2[1].lcn = LCN_ENOENT;
1097 * Because we have just read all of the mft mirror, we know we have
1098 * mapped the full runlist for it.
1100 mirr_ni = NTFS_I(vol->mftmirr_ino);
1101 down_read(&mirr_ni->runlist.lock);
1102 rl = mirr_ni->runlist.rl;
1103 /* Compare the two runlists. They must be identical. */
1106 if (rl2[i].vcn != rl[i].vcn || rl2[i].lcn != rl[i].lcn ||
1107 rl2[i].length != rl[i].length) {
1108 ntfs_error(sb, "$MFTMirr location mismatch. "
1110 up_read(&mirr_ni->runlist.lock);
1113 } while (rl2[i++].length);
1114 up_read(&mirr_ni->runlist.lock);
1115 ntfs_debug("Done.");
1120 * load_and_check_logfile - load and check the logfile inode for a volume
1121 * @vol: ntfs super block describing device whose logfile to load
1123 * Return TRUE on success or FALSE on error.
1125 static BOOL load_and_check_logfile(ntfs_volume *vol)
1127 struct inode *tmp_ino;
1129 ntfs_debug("Entering.");
1130 tmp_ino = ntfs_iget(vol->sb, FILE_LogFile);
1131 if (IS_ERR(tmp_ino) || is_bad_inode(tmp_ino)) {
1132 if (!IS_ERR(tmp_ino))
1134 /* Caller will display error message. */
1137 if (!ntfs_check_logfile(tmp_ino)) {
1139 /* ntfs_check_logfile() will have displayed error output. */
1142 NInoSetSparseDisabled(NTFS_I(tmp_ino));
1143 vol->logfile_ino = tmp_ino;
1144 ntfs_debug("Done.");
1149 * load_and_init_quota - load and setup the quota file for a volume if present
1150 * @vol: ntfs super block describing device whose quota file to load
1152 * Return TRUE on success or FALSE on error. If $Quota is not present, we
1153 * leave vol->quota_ino as NULL and return success.
1155 static BOOL load_and_init_quota(ntfs_volume *vol)
1158 struct inode *tmp_ino;
1159 ntfs_name *name = NULL;
1160 static const ntfschar Quota[7] = { const_cpu_to_le16('$'),
1161 const_cpu_to_le16('Q'), const_cpu_to_le16('u'),
1162 const_cpu_to_le16('o'), const_cpu_to_le16('t'),
1163 const_cpu_to_le16('a'), 0 };
1164 static ntfschar Q[3] = { const_cpu_to_le16('$'),
1165 const_cpu_to_le16('Q'), 0 };
1167 ntfs_debug("Entering.");
1169 * Find the inode number for the quota file by looking up the filename
1170 * $Quota in the extended system files directory $Extend.
1172 down(&vol->extend_ino->i_sem);
1173 mref = ntfs_lookup_inode_by_name(NTFS_I(vol->extend_ino), Quota, 6,
1175 up(&vol->extend_ino->i_sem);
1176 if (IS_ERR_MREF(mref)) {
1178 * If the file does not exist, quotas are disabled and have
1179 * never been enabled on this volume, just return success.
1181 if (MREF_ERR(mref) == -ENOENT) {
1182 ntfs_debug("$Quota not present. Volume does not have "
1185 * No need to try to set quotas out of date if they are
1188 NVolSetQuotaOutOfDate(vol);
1191 /* A real error occured. */
1192 ntfs_error(vol->sb, "Failed to find inode number for $Quota.");
1195 /* We do not care for the type of match that was found. */
1197 /* Get the inode. */
1198 tmp_ino = ntfs_iget(vol->sb, MREF(mref));
1199 if (IS_ERR(tmp_ino) || is_bad_inode(tmp_ino)) {
1200 if (!IS_ERR(tmp_ino))
1202 ntfs_error(vol->sb, "Failed to load $Quota.");
1205 vol->quota_ino = tmp_ino;
1206 /* Get the $Q index allocation attribute. */
1207 tmp_ino = ntfs_index_iget(vol->quota_ino, Q, 2);
1208 if (IS_ERR(tmp_ino)) {
1209 ntfs_error(vol->sb, "Failed to load $Quota/$Q index.");
1212 vol->quota_q_ino = tmp_ino;
1213 ntfs_debug("Done.");
1218 * load_and_init_attrdef - load the attribute definitions table for a volume
1219 * @vol: ntfs super block describing device whose attrdef to load
1221 * Return TRUE on success or FALSE on error.
1223 static BOOL load_and_init_attrdef(ntfs_volume *vol)
1226 struct super_block *sb = vol->sb;
1229 pgoff_t index, max_index;
1232 ntfs_debug("Entering.");
1233 /* Read attrdef table and setup vol->attrdef and vol->attrdef_size. */
1234 ino = ntfs_iget(sb, FILE_AttrDef);
1235 if (IS_ERR(ino) || is_bad_inode(ino)) {
1240 NInoSetSparseDisabled(NTFS_I(ino));
1241 /* The size of FILE_AttrDef must be above 0 and fit inside 31 bits. */
1242 i_size = i_size_read(ino);
1243 if (i_size <= 0 || i_size > 0x7fffffff)
1245 vol->attrdef = (ATTR_DEF*)ntfs_malloc_nofs(i_size);
1249 max_index = i_size >> PAGE_CACHE_SHIFT;
1250 size = PAGE_CACHE_SIZE;
1251 while (index < max_index) {
1252 /* Read the attrdef table and copy it into the linear buffer. */
1253 read_partial_attrdef_page:
1254 page = ntfs_map_page(ino->i_mapping, index);
1256 goto free_iput_failed;
1257 memcpy((u8*)vol->attrdef + (index++ << PAGE_CACHE_SHIFT),
1258 page_address(page), size);
1259 ntfs_unmap_page(page);
1261 if (size == PAGE_CACHE_SIZE) {
1262 size = i_size & ~PAGE_CACHE_MASK;
1264 goto read_partial_attrdef_page;
1266 vol->attrdef_size = i_size;
1267 ntfs_debug("Read %llu bytes from $AttrDef.", i_size);
1271 ntfs_free(vol->attrdef);
1272 vol->attrdef = NULL;
1276 ntfs_error(sb, "Failed to initialize attribute definition table.");
1280 #endif /* NTFS_RW */
1283 * load_and_init_upcase - load the upcase table for an ntfs volume
1284 * @vol: ntfs super block describing device whose upcase to load
1286 * Return TRUE on success or FALSE on error.
1288 static BOOL load_and_init_upcase(ntfs_volume *vol)
1291 struct super_block *sb = vol->sb;
1294 pgoff_t index, max_index;
1298 ntfs_debug("Entering.");
1299 /* Read upcase table and setup vol->upcase and vol->upcase_len. */
1300 ino = ntfs_iget(sb, FILE_UpCase);
1301 if (IS_ERR(ino) || is_bad_inode(ino)) {
1307 * The upcase size must not be above 64k Unicode characters, must not
1308 * be zero and must be a multiple of sizeof(ntfschar).
1310 i_size = i_size_read(ino);
1311 if (!i_size || i_size & (sizeof(ntfschar) - 1) ||
1312 i_size > 64ULL * 1024 * sizeof(ntfschar))
1313 goto iput_upcase_failed;
1314 vol->upcase = (ntfschar*)ntfs_malloc_nofs(i_size);
1316 goto iput_upcase_failed;
1318 max_index = i_size >> PAGE_CACHE_SHIFT;
1319 size = PAGE_CACHE_SIZE;
1320 while (index < max_index) {
1321 /* Read the upcase table and copy it into the linear buffer. */
1322 read_partial_upcase_page:
1323 page = ntfs_map_page(ino->i_mapping, index);
1325 goto iput_upcase_failed;
1326 memcpy((char*)vol->upcase + (index++ << PAGE_CACHE_SHIFT),
1327 page_address(page), size);
1328 ntfs_unmap_page(page);
1330 if (size == PAGE_CACHE_SIZE) {
1331 size = i_size & ~PAGE_CACHE_MASK;
1333 goto read_partial_upcase_page;
1335 vol->upcase_len = i_size >> UCHAR_T_SIZE_BITS;
1336 ntfs_debug("Read %llu bytes from $UpCase (expected %zu bytes).",
1337 i_size, 64 * 1024 * sizeof(ntfschar));
1340 if (!default_upcase) {
1341 ntfs_debug("Using volume specified $UpCase since default is "
1346 max = default_upcase_len;
1347 if (max > vol->upcase_len)
1348 max = vol->upcase_len;
1349 for (i = 0; i < max; i++)
1350 if (vol->upcase[i] != default_upcase[i])
1353 ntfs_free(vol->upcase);
1354 vol->upcase = default_upcase;
1355 vol->upcase_len = max;
1356 ntfs_nr_upcase_users++;
1358 ntfs_debug("Volume specified $UpCase matches default. Using "
1363 ntfs_debug("Using volume specified $UpCase since it does not match "
1368 ntfs_free(vol->upcase);
1372 if (default_upcase) {
1373 vol->upcase = default_upcase;
1374 vol->upcase_len = default_upcase_len;
1375 ntfs_nr_upcase_users++;
1377 ntfs_error(sb, "Failed to load $UpCase from the volume. Using "
1382 ntfs_error(sb, "Failed to initialize upcase table.");
1387 * load_system_files - open the system files using normal functions
1388 * @vol: ntfs super block describing device whose system files to load
1390 * Open the system files with normal access functions and complete setting up
1391 * the ntfs super block @vol.
1393 * Return TRUE on success or FALSE on error.
1395 static BOOL load_system_files(ntfs_volume *vol)
1397 struct super_block *sb = vol->sb;
1399 VOLUME_INFORMATION *vi;
1400 ntfs_attr_search_ctx *ctx;
1402 ntfs_debug("Entering.");
1404 /* Get mft mirror inode compare the contents of $MFT and $MFTMirr. */
1405 if (!load_and_init_mft_mirror(vol) || !check_mft_mirror(vol)) {
1406 static const char *es1 = "Failed to load $MFTMirr";
1407 static const char *es2 = "$MFTMirr does not match $MFT";
1408 static const char *es3 = ". Run ntfsfix and/or chkdsk.";
1410 /* If a read-write mount, convert it to a read-only mount. */
1411 if (!(sb->s_flags & MS_RDONLY)) {
1412 if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO |
1413 ON_ERRORS_CONTINUE))) {
1414 ntfs_error(sb, "%s and neither on_errors="
1415 "continue nor on_errors="
1416 "remount-ro was specified%s",
1417 !vol->mftmirr_ino ? es1 : es2,
1419 goto iput_mirr_err_out;
1421 sb->s_flags |= MS_RDONLY | MS_NOATIME | MS_NODIRATIME;
1422 ntfs_error(sb, "%s. Mounting read-only%s",
1423 !vol->mftmirr_ino ? es1 : es2, es3);
1425 ntfs_warning(sb, "%s. Will not be able to remount "
1427 !vol->mftmirr_ino ? es1 : es2, es3);
1428 /* This will prevent a read-write remount. */
1431 #endif /* NTFS_RW */
1432 /* Get mft bitmap attribute inode. */
1433 vol->mftbmp_ino = ntfs_attr_iget(vol->mft_ino, AT_BITMAP, NULL, 0);
1434 if (IS_ERR(vol->mftbmp_ino)) {
1435 ntfs_error(sb, "Failed to load $MFT/$BITMAP attribute.");
1436 goto iput_mirr_err_out;
1438 /* Read upcase table and setup @vol->upcase and @vol->upcase_len. */
1439 if (!load_and_init_upcase(vol))
1440 goto iput_mftbmp_err_out;
1443 * Read attribute definitions table and setup @vol->attrdef and
1444 * @vol->attrdef_size.
1446 if (!load_and_init_attrdef(vol))
1447 goto iput_upcase_err_out;
1448 #endif /* NTFS_RW */
1450 * Get the cluster allocation bitmap inode and verify the size, no
1451 * need for any locking at this stage as we are already running
1452 * exclusively as we are mount in progress task.
1454 vol->lcnbmp_ino = ntfs_iget(sb, FILE_Bitmap);
1455 if (IS_ERR(vol->lcnbmp_ino) || is_bad_inode(vol->lcnbmp_ino)) {
1456 if (!IS_ERR(vol->lcnbmp_ino))
1457 iput(vol->lcnbmp_ino);
1460 NInoSetSparseDisabled(NTFS_I(vol->lcnbmp_ino));
1461 if ((vol->nr_clusters + 7) >> 3 > i_size_read(vol->lcnbmp_ino)) {
1462 iput(vol->lcnbmp_ino);
1464 ntfs_error(sb, "Failed to load $Bitmap.");
1465 goto iput_attrdef_err_out;
1468 * Get the volume inode and setup our cache of the volume flags and
1471 vol->vol_ino = ntfs_iget(sb, FILE_Volume);
1472 if (IS_ERR(vol->vol_ino) || is_bad_inode(vol->vol_ino)) {
1473 if (!IS_ERR(vol->vol_ino))
1476 ntfs_error(sb, "Failed to load $Volume.");
1477 goto iput_lcnbmp_err_out;
1479 m = map_mft_record(NTFS_I(vol->vol_ino));
1485 if (!(ctx = ntfs_attr_get_search_ctx(NTFS_I(vol->vol_ino), m))) {
1486 ntfs_error(sb, "Failed to get attribute search context.");
1487 goto get_ctx_vol_failed;
1489 if (ntfs_attr_lookup(AT_VOLUME_INFORMATION, NULL, 0, 0, 0, NULL, 0,
1490 ctx) || ctx->attr->non_resident || ctx->attr->flags) {
1492 ntfs_attr_put_search_ctx(ctx);
1494 unmap_mft_record(NTFS_I(vol->vol_ino));
1495 goto iput_volume_failed;
1497 vi = (VOLUME_INFORMATION*)((char*)ctx->attr +
1498 le16_to_cpu(ctx->attr->data.resident.value_offset));
1499 /* Some bounds checks. */
1500 if ((u8*)vi < (u8*)ctx->attr || (u8*)vi +
1501 le32_to_cpu(ctx->attr->data.resident.value_length) >
1502 (u8*)ctx->attr + le32_to_cpu(ctx->attr->length))
1504 /* Copy the volume flags and version to the ntfs_volume structure. */
1505 vol->vol_flags = vi->flags;
1506 vol->major_ver = vi->major_ver;
1507 vol->minor_ver = vi->minor_ver;
1508 ntfs_attr_put_search_ctx(ctx);
1509 unmap_mft_record(NTFS_I(vol->vol_ino));
1510 printk(KERN_INFO "NTFS volume version %i.%i.\n", vol->major_ver,
1512 if (vol->major_ver < 3 && NVolSparseEnabled(vol)) {
1513 ntfs_warning(vol->sb, "Disabling sparse support due to NTFS "
1514 "volume version %i.%i (need at least version "
1515 "3.0).", vol->major_ver, vol->minor_ver);
1516 NVolClearSparseEnabled(vol);
1519 /* Make sure that no unsupported volume flags are set. */
1520 if (vol->vol_flags & VOLUME_MUST_MOUNT_RO_MASK) {
1521 static const char *es1a = "Volume is dirty";
1522 static const char *es1b = "Volume has unsupported flags set";
1523 static const char *es2 = ". Run chkdsk and mount in Windows.";
1526 es1 = vol->vol_flags & VOLUME_IS_DIRTY ? es1a : es1b;
1527 /* If a read-write mount, convert it to a read-only mount. */
1528 if (!(sb->s_flags & MS_RDONLY)) {
1529 if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO |
1530 ON_ERRORS_CONTINUE))) {
1531 ntfs_error(sb, "%s and neither on_errors="
1532 "continue nor on_errors="
1533 "remount-ro was specified%s",
1535 goto iput_vol_err_out;
1537 sb->s_flags |= MS_RDONLY | MS_NOATIME | MS_NODIRATIME;
1538 ntfs_error(sb, "%s. Mounting read-only%s", es1, es2);
1540 ntfs_warning(sb, "%s. Will not be able to remount "
1541 "read-write%s", es1, es2);
1543 * Do not set NVolErrors() because ntfs_remount() re-checks the
1544 * flags which we need to do in case any flags have changed.
1548 * Get the inode for the logfile, check it and determine if the volume
1549 * was shutdown cleanly.
1551 if (!load_and_check_logfile(vol) ||
1552 !ntfs_is_logfile_clean(vol->logfile_ino)) {
1553 static const char *es1a = "Failed to load $LogFile";
1554 static const char *es1b = "$LogFile is not clean";
1555 static const char *es2 = ". Mount in Windows.";
1558 es1 = !vol->logfile_ino ? es1a : es1b;
1559 /* If a read-write mount, convert it to a read-only mount. */
1560 if (!(sb->s_flags & MS_RDONLY)) {
1561 if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO |
1562 ON_ERRORS_CONTINUE))) {
1563 ntfs_error(sb, "%s and neither on_errors="
1564 "continue nor on_errors="
1565 "remount-ro was specified%s",
1567 goto iput_logfile_err_out;
1569 sb->s_flags |= MS_RDONLY | MS_NOATIME | MS_NODIRATIME;
1570 ntfs_error(sb, "%s. Mounting read-only%s", es1, es2);
1572 ntfs_warning(sb, "%s. Will not be able to remount "
1573 "read-write%s", es1, es2);
1574 /* This will prevent a read-write remount. */
1577 /* If (still) a read-write mount, mark the volume dirty. */
1578 if (!(sb->s_flags & MS_RDONLY) &&
1579 ntfs_set_volume_flags(vol, VOLUME_IS_DIRTY)) {
1580 static const char *es1 = "Failed to set dirty bit in volume "
1581 "information flags";
1582 static const char *es2 = ". Run chkdsk.";
1584 /* Convert to a read-only mount. */
1585 if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO |
1586 ON_ERRORS_CONTINUE))) {
1587 ntfs_error(sb, "%s and neither on_errors=continue nor "
1588 "on_errors=remount-ro was specified%s",
1590 goto iput_logfile_err_out;
1592 ntfs_error(sb, "%s. Mounting read-only%s", es1, es2);
1593 sb->s_flags |= MS_RDONLY | MS_NOATIME | MS_NODIRATIME;
1595 * Do not set NVolErrors() because ntfs_remount() might manage
1596 * to set the dirty flag in which case all would be well.
1600 // TODO: Enable this code once we start modifying anything that is
1601 // different between NTFS 1.2 and 3.x...
1603 * If (still) a read-write mount, set the NT4 compatibility flag on
1604 * newer NTFS version volumes.
1606 if (!(sb->s_flags & MS_RDONLY) && (vol->major_ver > 1) &&
1607 ntfs_set_volume_flags(vol, VOLUME_MOUNTED_ON_NT4)) {
1608 static const char *es1 = "Failed to set NT4 compatibility flag";
1609 static const char *es2 = ". Run chkdsk.";
1611 /* Convert to a read-only mount. */
1612 if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO |
1613 ON_ERRORS_CONTINUE))) {
1614 ntfs_error(sb, "%s and neither on_errors=continue nor "
1615 "on_errors=remount-ro was specified%s",
1617 goto iput_logfile_err_out;
1619 ntfs_error(sb, "%s. Mounting read-only%s", es1, es2);
1620 sb->s_flags |= MS_RDONLY | MS_NOATIME | MS_NODIRATIME;
1624 /* If (still) a read-write mount, empty the logfile. */
1625 if (!(sb->s_flags & MS_RDONLY) &&
1626 !ntfs_empty_logfile(vol->logfile_ino)) {
1627 static const char *es1 = "Failed to empty $LogFile";
1628 static const char *es2 = ". Mount in Windows.";
1630 /* Convert to a read-only mount. */
1631 if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO |
1632 ON_ERRORS_CONTINUE))) {
1633 ntfs_error(sb, "%s and neither on_errors=continue nor "
1634 "on_errors=remount-ro was specified%s",
1636 goto iput_logfile_err_out;
1638 ntfs_error(sb, "%s. Mounting read-only%s", es1, es2);
1639 sb->s_flags |= MS_RDONLY | MS_NOATIME | MS_NODIRATIME;
1642 #endif /* NTFS_RW */
1643 /* Get the root directory inode. */
1644 vol->root_ino = ntfs_iget(sb, FILE_root);
1645 if (IS_ERR(vol->root_ino) || is_bad_inode(vol->root_ino)) {
1646 if (!IS_ERR(vol->root_ino))
1647 iput(vol->root_ino);
1648 ntfs_error(sb, "Failed to load root directory.");
1649 goto iput_logfile_err_out;
1651 /* If on NTFS versions before 3.0, we are done. */
1652 if (vol->major_ver < 3)
1654 /* NTFS 3.0+ specific initialization. */
1655 /* Get the security descriptors inode. */
1656 vol->secure_ino = ntfs_iget(sb, FILE_Secure);
1657 if (IS_ERR(vol->secure_ino) || is_bad_inode(vol->secure_ino)) {
1658 if (!IS_ERR(vol->secure_ino))
1659 iput(vol->secure_ino);
1660 ntfs_error(sb, "Failed to load $Secure.");
1661 goto iput_root_err_out;
1663 // FIXME: Initialize security.
1664 /* Get the extended system files' directory inode. */
1665 vol->extend_ino = ntfs_iget(sb, FILE_Extend);
1666 if (IS_ERR(vol->extend_ino) || is_bad_inode(vol->extend_ino)) {
1667 if (!IS_ERR(vol->extend_ino))
1668 iput(vol->extend_ino);
1669 ntfs_error(sb, "Failed to load $Extend.");
1670 goto iput_sec_err_out;
1673 /* Find the quota file, load it if present, and set it up. */
1674 if (!load_and_init_quota(vol)) {
1675 static const char *es1 = "Failed to load $Quota";
1676 static const char *es2 = ". Run chkdsk.";
1678 /* If a read-write mount, convert it to a read-only mount. */
1679 if (!(sb->s_flags & MS_RDONLY)) {
1680 if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO |
1681 ON_ERRORS_CONTINUE))) {
1682 ntfs_error(sb, "%s and neither on_errors="
1683 "continue nor on_errors="
1684 "remount-ro was specified%s",
1686 goto iput_quota_err_out;
1688 sb->s_flags |= MS_RDONLY | MS_NOATIME | MS_NODIRATIME;
1689 ntfs_error(sb, "%s. Mounting read-only%s", es1, es2);
1691 ntfs_warning(sb, "%s. Will not be able to remount "
1692 "read-write%s", es1, es2);
1693 /* This will prevent a read-write remount. */
1696 /* If (still) a read-write mount, mark the quotas out of date. */
1697 if (!(sb->s_flags & MS_RDONLY) &&
1698 !ntfs_mark_quotas_out_of_date(vol)) {
1699 static const char *es1 = "Failed to mark quotas out of date";
1700 static const char *es2 = ". Run chkdsk.";
1702 /* Convert to a read-only mount. */
1703 if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO |
1704 ON_ERRORS_CONTINUE))) {
1705 ntfs_error(sb, "%s and neither on_errors=continue nor "
1706 "on_errors=remount-ro was specified%s",
1708 goto iput_quota_err_out;
1710 ntfs_error(sb, "%s. Mounting read-only%s", es1, es2);
1711 sb->s_flags |= MS_RDONLY | MS_NOATIME | MS_NODIRATIME;
1714 // TODO: Delete or checkpoint the $UsnJrnl if it exists.
1715 #endif /* NTFS_RW */
1719 if (vol->quota_q_ino)
1720 iput(vol->quota_q_ino);
1722 iput(vol->quota_ino);
1723 iput(vol->extend_ino);
1724 #endif /* NTFS_RW */
1726 iput(vol->secure_ino);
1728 iput(vol->root_ino);
1729 iput_logfile_err_out:
1731 if (vol->logfile_ino)
1732 iput(vol->logfile_ino);
1734 #endif /* NTFS_RW */
1736 iput_lcnbmp_err_out:
1737 iput(vol->lcnbmp_ino);
1738 iput_attrdef_err_out:
1739 vol->attrdef_size = 0;
1741 ntfs_free(vol->attrdef);
1742 vol->attrdef = NULL;
1745 iput_upcase_err_out:
1746 #endif /* NTFS_RW */
1747 vol->upcase_len = 0;
1749 if (vol->upcase == default_upcase) {
1750 ntfs_nr_upcase_users--;
1755 ntfs_free(vol->upcase);
1758 iput_mftbmp_err_out:
1759 iput(vol->mftbmp_ino);
1762 if (vol->mftmirr_ino)
1763 iput(vol->mftmirr_ino);
1764 #endif /* NTFS_RW */
1769 * ntfs_put_super - called by the vfs to unmount a volume
1770 * @sb: vfs superblock of volume to unmount
1772 * ntfs_put_super() is called by the VFS (from fs/super.c::do_umount()) when
1773 * the volume is being unmounted (umount system call has been invoked) and it
1774 * releases all inodes and memory belonging to the NTFS specific part of the
1777 static void ntfs_put_super(struct super_block *sb)
1779 ntfs_volume *vol = NTFS_SB(sb);
1781 ntfs_debug("Entering.");
1784 * Commit all inodes while they are still open in case some of them
1785 * cause others to be dirtied.
1787 ntfs_commit_inode(vol->vol_ino);
1789 /* NTFS 3.0+ specific. */
1790 if (vol->major_ver >= 3) {
1791 if (vol->quota_q_ino)
1792 ntfs_commit_inode(vol->quota_q_ino);
1794 ntfs_commit_inode(vol->quota_ino);
1795 if (vol->extend_ino)
1796 ntfs_commit_inode(vol->extend_ino);
1797 if (vol->secure_ino)
1798 ntfs_commit_inode(vol->secure_ino);
1801 ntfs_commit_inode(vol->root_ino);
1803 down_write(&vol->lcnbmp_lock);
1804 ntfs_commit_inode(vol->lcnbmp_ino);
1805 up_write(&vol->lcnbmp_lock);
1807 down_write(&vol->mftbmp_lock);
1808 ntfs_commit_inode(vol->mftbmp_ino);
1809 up_write(&vol->mftbmp_lock);
1811 if (vol->logfile_ino)
1812 ntfs_commit_inode(vol->logfile_ino);
1814 if (vol->mftmirr_ino)
1815 ntfs_commit_inode(vol->mftmirr_ino);
1816 ntfs_commit_inode(vol->mft_ino);
1819 * If a read-write mount and no volume errors have occured, mark the
1820 * volume clean. Also, re-commit all affected inodes.
1822 if (!(sb->s_flags & MS_RDONLY)) {
1823 if (!NVolErrors(vol)) {
1824 if (ntfs_clear_volume_flags(vol, VOLUME_IS_DIRTY))
1825 ntfs_warning(sb, "Failed to clear dirty bit "
1826 "in volume information "
1827 "flags. Run chkdsk.");
1828 ntfs_commit_inode(vol->vol_ino);
1829 ntfs_commit_inode(vol->root_ino);
1830 if (vol->mftmirr_ino)
1831 ntfs_commit_inode(vol->mftmirr_ino);
1832 ntfs_commit_inode(vol->mft_ino);
1834 ntfs_warning(sb, "Volume has errors. Leaving volume "
1835 "marked dirty. Run chkdsk.");
1838 #endif /* NTFS_RW */
1841 vol->vol_ino = NULL;
1843 /* NTFS 3.0+ specific clean up. */
1844 if (vol->major_ver >= 3) {
1846 if (vol->quota_q_ino) {
1847 iput(vol->quota_q_ino);
1848 vol->quota_q_ino = NULL;
1850 if (vol->quota_ino) {
1851 iput(vol->quota_ino);
1852 vol->quota_ino = NULL;
1854 #endif /* NTFS_RW */
1855 if (vol->extend_ino) {
1856 iput(vol->extend_ino);
1857 vol->extend_ino = NULL;
1859 if (vol->secure_ino) {
1860 iput(vol->secure_ino);
1861 vol->secure_ino = NULL;
1865 iput(vol->root_ino);
1866 vol->root_ino = NULL;
1868 down_write(&vol->lcnbmp_lock);
1869 iput(vol->lcnbmp_ino);
1870 vol->lcnbmp_ino = NULL;
1871 up_write(&vol->lcnbmp_lock);
1873 down_write(&vol->mftbmp_lock);
1874 iput(vol->mftbmp_ino);
1875 vol->mftbmp_ino = NULL;
1876 up_write(&vol->mftbmp_lock);
1879 if (vol->logfile_ino) {
1880 iput(vol->logfile_ino);
1881 vol->logfile_ino = NULL;
1883 if (vol->mftmirr_ino) {
1884 /* Re-commit the mft mirror and mft just in case. */
1885 ntfs_commit_inode(vol->mftmirr_ino);
1886 ntfs_commit_inode(vol->mft_ino);
1887 iput(vol->mftmirr_ino);
1888 vol->mftmirr_ino = NULL;
1891 * If any dirty inodes are left, throw away all mft data page cache
1892 * pages to allow a clean umount. This should never happen any more
1893 * due to mft.c::ntfs_mft_writepage() cleaning all the dirty pages as
1894 * the underlying mft records are written out and cleaned. If it does,
1895 * happen anyway, we want to know...
1897 ntfs_commit_inode(vol->mft_ino);
1898 write_inode_now(vol->mft_ino, 1);
1899 if (!list_empty(&sb->s_dirty)) {
1900 const char *s1, *s2;
1902 down(&vol->mft_ino->i_sem);
1903 truncate_inode_pages(vol->mft_ino->i_mapping, 0);
1904 up(&vol->mft_ino->i_sem);
1905 write_inode_now(vol->mft_ino, 1);
1906 if (!list_empty(&sb->s_dirty)) {
1907 static const char *_s1 = "inodes";
1908 static const char *_s2 = "";
1912 static const char *_s1 = "mft pages";
1913 static const char *_s2 = "They have been thrown "
1918 ntfs_error(sb, "Dirty %s found at umount time. %sYou should "
1919 "run chkdsk. Please email "
1920 "linux-ntfs-dev@lists.sourceforge.net and say "
1921 "that you saw this message. Thank you.", s1,
1924 #endif /* NTFS_RW */
1927 vol->mft_ino = NULL;
1929 /* Throw away the table of attribute definitions. */
1930 vol->attrdef_size = 0;
1932 ntfs_free(vol->attrdef);
1933 vol->attrdef = NULL;
1935 vol->upcase_len = 0;
1937 * Destroy the global default upcase table if necessary. Also decrease
1938 * the number of upcase users if we are a user.
1941 if (vol->upcase == default_upcase) {
1942 ntfs_nr_upcase_users--;
1945 if (!ntfs_nr_upcase_users && default_upcase) {
1946 ntfs_free(default_upcase);
1947 default_upcase = NULL;
1949 if (vol->cluster_size <= 4096 && !--ntfs_nr_compression_users)
1950 free_compression_buffers();
1953 ntfs_free(vol->upcase);
1957 unload_nls(vol->nls_map);
1958 vol->nls_map = NULL;
1960 sb->s_fs_info = NULL;
1966 * get_nr_free_clusters - return the number of free clusters on a volume
1967 * @vol: ntfs volume for which to obtain free cluster count
1969 * Calculate the number of free clusters on the mounted NTFS volume @vol. We
1970 * actually calculate the number of clusters in use instead because this
1971 * allows us to not care about partial pages as these will be just zero filled
1972 * and hence not be counted as allocated clusters.
1974 * The only particularity is that clusters beyond the end of the logical ntfs
1975 * volume will be marked as allocated to prevent errors which means we have to
1976 * discount those at the end. This is important as the cluster bitmap always
1977 * has a size in multiples of 8 bytes, i.e. up to 63 clusters could be outside
1978 * the logical volume and marked in use when they are not as they do not exist.
1980 * If any pages cannot be read we assume all clusters in the erroring pages are
1981 * in use. This means we return an underestimate on errors which is better than
1984 static s64 get_nr_free_clusters(ntfs_volume *vol)
1986 s64 nr_free = vol->nr_clusters;
1988 struct address_space *mapping = vol->lcnbmp_ino->i_mapping;
1989 filler_t *readpage = (filler_t*)mapping->a_ops->readpage;
1991 pgoff_t index, max_index;
1993 ntfs_debug("Entering.");
1994 /* Serialize accesses to the cluster bitmap. */
1995 down_read(&vol->lcnbmp_lock);
1997 * Convert the number of bits into bytes rounded up, then convert into
1998 * multiples of PAGE_CACHE_SIZE, rounding up so that if we have one
1999 * full and one partial page max_index = 2.
2001 max_index = (((vol->nr_clusters + 7) >> 3) + PAGE_CACHE_SIZE - 1) >>
2003 /* Use multiples of 4 bytes, thus max_size is PAGE_CACHE_SIZE / 4. */
2004 ntfs_debug("Reading $Bitmap, max_index = 0x%lx, max_size = 0x%lx.",
2005 max_index, PAGE_CACHE_SIZE / 4);
2006 for (index = 0; index < max_index; index++) {
2009 * Read the page from page cache, getting it from backing store
2010 * if necessary, and increment the use count.
2012 page = read_cache_page(mapping, index, (filler_t*)readpage,
2014 /* Ignore pages which errored synchronously. */
2016 ntfs_debug("Sync read_cache_page() error. Skipping "
2017 "page (index 0x%lx).", index);
2018 nr_free -= PAGE_CACHE_SIZE * 8;
2021 wait_on_page_locked(page);
2022 /* Ignore pages which errored asynchronously. */
2023 if (!PageUptodate(page)) {
2024 ntfs_debug("Async read_cache_page() error. Skipping "
2025 "page (index 0x%lx).", index);
2026 page_cache_release(page);
2027 nr_free -= PAGE_CACHE_SIZE * 8;
2030 kaddr = (u32*)kmap_atomic(page, KM_USER0);
2032 * For each 4 bytes, subtract the number of set bits. If this
2033 * is the last page and it is partial we don't really care as
2034 * it just means we do a little extra work but it won't affect
2035 * the result as all out of range bytes are set to zero by
2038 for (i = 0; i < PAGE_CACHE_SIZE / 4; i++)
2039 nr_free -= (s64)hweight32(kaddr[i]);
2040 kunmap_atomic(kaddr, KM_USER0);
2041 page_cache_release(page);
2043 ntfs_debug("Finished reading $Bitmap, last index = 0x%lx.", index - 1);
2045 * Fixup for eventual bits outside logical ntfs volume (see function
2046 * description above).
2048 if (vol->nr_clusters & 63)
2049 nr_free += 64 - (vol->nr_clusters & 63);
2050 up_read(&vol->lcnbmp_lock);
2051 /* If errors occured we may well have gone below zero, fix this. */
2054 ntfs_debug("Exiting.");
2059 * __get_nr_free_mft_records - return the number of free inodes on a volume
2060 * @vol: ntfs volume for which to obtain free inode count
2061 * @nr_free: number of mft records in filesystem
2062 * @max_index: maximum number of pages containing set bits
2064 * Calculate the number of free mft records (inodes) on the mounted NTFS
2065 * volume @vol. We actually calculate the number of mft records in use instead
2066 * because this allows us to not care about partial pages as these will be just
2067 * zero filled and hence not be counted as allocated mft record.
2069 * If any pages cannot be read we assume all mft records in the erroring pages
2070 * are in use. This means we return an underestimate on errors which is better
2071 * than an overestimate.
2073 * NOTE: Caller must hold mftbmp_lock rw_semaphore for reading or writing.
2075 static unsigned long __get_nr_free_mft_records(ntfs_volume *vol,
2076 s64 nr_free, const pgoff_t max_index)
2079 struct address_space *mapping = vol->mftbmp_ino->i_mapping;
2080 filler_t *readpage = (filler_t*)mapping->a_ops->readpage;
2084 ntfs_debug("Entering.");
2085 /* Use multiples of 4 bytes, thus max_size is PAGE_CACHE_SIZE / 4. */
2086 ntfs_debug("Reading $MFT/$BITMAP, max_index = 0x%lx, max_size = "
2087 "0x%lx.", max_index, PAGE_CACHE_SIZE / 4);
2088 for (index = 0; index < max_index; index++) {
2091 * Read the page from page cache, getting it from backing store
2092 * if necessary, and increment the use count.
2094 page = read_cache_page(mapping, index, (filler_t*)readpage,
2096 /* Ignore pages which errored synchronously. */
2098 ntfs_debug("Sync read_cache_page() error. Skipping "
2099 "page (index 0x%lx).", index);
2100 nr_free -= PAGE_CACHE_SIZE * 8;
2103 wait_on_page_locked(page);
2104 /* Ignore pages which errored asynchronously. */
2105 if (!PageUptodate(page)) {
2106 ntfs_debug("Async read_cache_page() error. Skipping "
2107 "page (index 0x%lx).", index);
2108 page_cache_release(page);
2109 nr_free -= PAGE_CACHE_SIZE * 8;
2112 kaddr = (u32*)kmap_atomic(page, KM_USER0);
2114 * For each 4 bytes, subtract the number of set bits. If this
2115 * is the last page and it is partial we don't really care as
2116 * it just means we do a little extra work but it won't affect
2117 * the result as all out of range bytes are set to zero by
2120 for (i = 0; i < PAGE_CACHE_SIZE / 4; i++)
2121 nr_free -= (s64)hweight32(kaddr[i]);
2122 kunmap_atomic(kaddr, KM_USER0);
2123 page_cache_release(page);
2125 ntfs_debug("Finished reading $MFT/$BITMAP, last index = 0x%lx.",
2127 /* If errors occured we may well have gone below zero, fix this. */
2130 ntfs_debug("Exiting.");
2135 * ntfs_statfs - return information about mounted NTFS volume
2136 * @sb: super block of mounted volume
2137 * @sfs: statfs structure in which to return the information
2139 * Return information about the mounted NTFS volume @sb in the statfs structure
2140 * pointed to by @sfs (this is initialized with zeros before ntfs_statfs is
2141 * called). We interpret the values to be correct of the moment in time at
2142 * which we are called. Most values are variable otherwise and this isn't just
2143 * the free values but the totals as well. For example we can increase the
2144 * total number of file nodes if we run out and we can keep doing this until
2145 * there is no more space on the volume left at all.
2147 * Called from vfs_statfs which is used to handle the statfs, fstatfs, and
2148 * ustat system calls.
2150 * Return 0 on success or -errno on error.
2152 static int ntfs_statfs(struct super_block *sb, struct kstatfs *sfs)
2155 ntfs_volume *vol = NTFS_SB(sb);
2156 ntfs_inode *mft_ni = NTFS_I(vol->mft_ino);
2158 unsigned long flags;
2160 ntfs_debug("Entering.");
2161 /* Type of filesystem. */
2162 sfs->f_type = NTFS_SB_MAGIC;
2163 /* Optimal transfer block size. */
2164 sfs->f_bsize = PAGE_CACHE_SIZE;
2166 * Total data blocks in filesystem in units of f_bsize and since
2167 * inodes are also stored in data blocs ($MFT is a file) this is just
2168 * the total clusters.
2170 sfs->f_blocks = vol->nr_clusters << vol->cluster_size_bits >>
2172 /* Free data blocks in filesystem in units of f_bsize. */
2173 size = get_nr_free_clusters(vol) << vol->cluster_size_bits >>
2177 /* Free blocks avail to non-superuser, same as above on NTFS. */
2178 sfs->f_bavail = sfs->f_bfree = size;
2179 /* Serialize accesses to the inode bitmap. */
2180 down_read(&vol->mftbmp_lock);
2181 read_lock_irqsave(&mft_ni->size_lock, flags);
2182 size = i_size_read(vol->mft_ino) >> vol->mft_record_size_bits;
2184 * Convert the maximum number of set bits into bytes rounded up, then
2185 * convert into multiples of PAGE_CACHE_SIZE, rounding up so that if we
2186 * have one full and one partial page max_index = 2.
2188 max_index = ((((mft_ni->initialized_size >> vol->mft_record_size_bits)
2189 + 7) >> 3) + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
2190 read_unlock_irqrestore(&mft_ni->size_lock, flags);
2191 /* Number of inodes in filesystem (at this point in time). */
2192 sfs->f_files = size;
2193 /* Free inodes in fs (based on current total count). */
2194 sfs->f_ffree = __get_nr_free_mft_records(vol, size, max_index);
2195 up_read(&vol->mftbmp_lock);
2197 * File system id. This is extremely *nix flavour dependent and even
2198 * within Linux itself all fs do their own thing. I interpret this to
2199 * mean a unique id associated with the mounted fs and not the id
2200 * associated with the filesystem driver, the latter is already given
2201 * by the filesystem type in sfs->f_type. Thus we use the 64-bit
2202 * volume serial number splitting it into two 32-bit parts. We enter
2203 * the least significant 32-bits in f_fsid[0] and the most significant
2204 * 32-bits in f_fsid[1].
2206 sfs->f_fsid.val[0] = vol->serial_no & 0xffffffff;
2207 sfs->f_fsid.val[1] = (vol->serial_no >> 32) & 0xffffffff;
2208 /* Maximum length of filenames. */
2209 sfs->f_namelen = NTFS_MAX_NAME_LEN;
2214 * The complete super operations.
2216 static struct super_operations ntfs_sops = {
2217 .alloc_inode = ntfs_alloc_big_inode, /* VFS: Allocate new inode. */
2218 .destroy_inode = ntfs_destroy_big_inode, /* VFS: Deallocate inode. */
2219 .put_inode = ntfs_put_inode, /* VFS: Called just before
2220 the inode reference count
2223 //.dirty_inode = NULL, /* VFS: Called from
2224 // __mark_inode_dirty(). */
2225 .write_inode = ntfs_write_inode, /* VFS: Write dirty inode to
2227 //.drop_inode = NULL, /* VFS: Called just after the
2228 // inode reference count has
2229 // been decreased to zero.
2230 // NOTE: The inode lock is
2231 // held. See fs/inode.c::
2232 // generic_drop_inode(). */
2233 //.delete_inode = NULL, /* VFS: Delete inode from disk.
2234 // Called when i_count becomes
2235 // 0 and i_nlink is also 0. */
2236 //.write_super = NULL, /* Flush dirty super block to
2238 //.sync_fs = NULL, /* ? */
2239 //.write_super_lockfs = NULL, /* ? */
2240 //.unlockfs = NULL, /* ? */
2241 #endif /* NTFS_RW */
2242 .put_super = ntfs_put_super, /* Syscall: umount. */
2243 .statfs = ntfs_statfs, /* Syscall: statfs */
2244 .remount_fs = ntfs_remount, /* Syscall: mount -o remount. */
2245 .clear_inode = ntfs_clear_big_inode, /* VFS: Called when an inode is
2246 removed from memory. */
2247 //.umount_begin = NULL, /* Forced umount. */
2248 .show_options = ntfs_show_options, /* Show mount options in
2253 * ntfs_fill_super - mount an ntfs filesystem
2254 * @sb: super block of ntfs filesystem to mount
2255 * @opt: string containing the mount options
2256 * @silent: silence error output
2258 * ntfs_fill_super() is called by the VFS to mount the device described by @sb
2259 * with the mount otions in @data with the NTFS filesystem.
2261 * If @silent is true, remain silent even if errors are detected. This is used
2262 * during bootup, when the kernel tries to mount the root filesystem with all
2263 * registered filesystems one after the other until one succeeds. This implies
2264 * that all filesystems except the correct one will quite correctly and
2265 * expectedly return an error, but nobody wants to see error messages when in
2266 * fact this is what is supposed to happen.
2268 * NOTE: @sb->s_flags contains the mount options flags.
2270 static int ntfs_fill_super(struct super_block *sb, void *opt, const int silent)
2273 struct buffer_head *bh;
2274 struct inode *tmp_ino;
2277 ntfs_debug("Entering.");
2279 sb->s_flags |= MS_RDONLY | MS_NOATIME | MS_NODIRATIME;
2280 #endif /* ! NTFS_RW */
2281 /* Allocate a new ntfs_volume and place it in sb->s_fs_info. */
2282 sb->s_fs_info = kmalloc(sizeof(ntfs_volume), GFP_NOFS);
2286 ntfs_error(sb, "Allocation of NTFS volume structure "
2287 "failed. Aborting mount...");
2290 /* Initialize ntfs_volume structure. */
2291 memset(vol, 0, sizeof(ntfs_volume));
2294 vol->attrdef = NULL;
2295 vol->mft_ino = NULL;
2296 vol->mftbmp_ino = NULL;
2297 init_rwsem(&vol->mftbmp_lock);
2299 vol->mftmirr_ino = NULL;
2300 vol->logfile_ino = NULL;
2301 #endif /* NTFS_RW */
2302 vol->lcnbmp_ino = NULL;
2303 init_rwsem(&vol->lcnbmp_lock);
2304 vol->vol_ino = NULL;
2305 vol->root_ino = NULL;
2306 vol->secure_ino = NULL;
2307 vol->extend_ino = NULL;
2309 vol->quota_ino = NULL;
2310 vol->quota_q_ino = NULL;
2311 #endif /* NTFS_RW */
2312 vol->nls_map = NULL;
2315 * Default is group and other don't have any access to files or
2316 * directories while owner has full access. Further, files by default
2317 * are not executable but directories are of course browseable.
2324 /* By default, enable sparse support. */
2325 NVolSetSparseEnabled(vol);
2327 /* Important to get the mount options dealt with now. */
2328 if (!parse_options(vol, (char*)opt))
2332 * TODO: Fail safety check. In the future we should really be able to
2333 * cope with this being the case, but for now just bail out.
2335 if (bdev_hardsect_size(sb->s_bdev) > NTFS_BLOCK_SIZE) {
2337 ntfs_error(sb, "Device has unsupported hardsect_size.");
2341 /* Setup the device access block size to NTFS_BLOCK_SIZE. */
2342 if (sb_set_blocksize(sb, NTFS_BLOCK_SIZE) != NTFS_BLOCK_SIZE) {
2344 ntfs_error(sb, "Unable to set block size.");
2348 /* Get the size of the device in units of NTFS_BLOCK_SIZE bytes. */
2349 vol->nr_blocks = i_size_read(sb->s_bdev->bd_inode) >>
2350 NTFS_BLOCK_SIZE_BITS;
2352 /* Read the boot sector and return unlocked buffer head to it. */
2353 if (!(bh = read_ntfs_boot_sector(sb, silent))) {
2355 ntfs_error(sb, "Not an NTFS volume.");
2360 * Extract the data from the boot sector and setup the ntfs super block
2363 result = parse_ntfs_boot_sector(vol, (NTFS_BOOT_SECTOR*)bh->b_data);
2365 /* Initialize the cluster and mft allocators. */
2366 ntfs_setup_allocators(vol);
2372 ntfs_error(sb, "Unsupported NTFS filesystem.");
2377 * TODO: When we start coping with sector sizes different from
2378 * NTFS_BLOCK_SIZE, we now probably need to set the blocksize of the
2379 * device (probably to NTFS_BLOCK_SIZE).
2382 /* Setup remaining fields in the super block. */
2383 sb->s_magic = NTFS_SB_MAGIC;
2386 * Ntfs allows 63 bits for the file size, i.e. correct would be:
2387 * sb->s_maxbytes = ~0ULL >> 1;
2388 * But the kernel uses a long as the page cache page index which on
2389 * 32-bit architectures is only 32-bits. MAX_LFS_FILESIZE is kernel
2390 * defined to the maximum the page cache page index can cope with
2391 * without overflowing the index or to 2^63 - 1, whichever is smaller.
2393 sb->s_maxbytes = MAX_LFS_FILESIZE;
2395 sb->s_time_gran = 100;
2398 * Now load the metadata required for the page cache and our address
2399 * space operations to function. We do this by setting up a specialised
2400 * read_inode method and then just calling the normal iget() to obtain
2401 * the inode for $MFT which is sufficient to allow our normal inode
2402 * operations and associated address space operations to function.
2404 sb->s_op = &ntfs_sops;
2405 tmp_ino = new_inode(sb);
2408 ntfs_error(sb, "Failed to load essential metadata.");
2411 tmp_ino->i_ino = FILE_MFT;
2412 insert_inode_hash(tmp_ino);
2413 if (ntfs_read_inode_mount(tmp_ino) < 0) {
2415 ntfs_error(sb, "Failed to load essential metadata.");
2416 goto iput_tmp_ino_err_out_now;
2420 * The current mount is a compression user if the cluster size is
2421 * less than or equal 4kiB.
2423 if (vol->cluster_size <= 4096 && !ntfs_nr_compression_users++) {
2424 result = allocate_compression_buffers();
2426 ntfs_error(NULL, "Failed to allocate buffers "
2427 "for compression engine.");
2428 ntfs_nr_compression_users--;
2430 goto iput_tmp_ino_err_out_now;
2434 * Generate the global default upcase table if necessary. Also
2435 * temporarily increment the number of upcase users to avoid race
2436 * conditions with concurrent (u)mounts.
2438 if (!default_upcase)
2439 default_upcase = generate_default_upcase();
2440 ntfs_nr_upcase_users++;
2443 * From now on, ignore @silent parameter. If we fail below this line,
2444 * it will be due to a corrupt fs or a system error, so we report it.
2447 * Open the system files with normal access functions and complete
2448 * setting up the ntfs super block.
2450 if (!load_system_files(vol)) {
2451 ntfs_error(sb, "Failed to load system files.");
2452 goto unl_upcase_iput_tmp_ino_err_out_now;
2454 if ((sb->s_root = d_alloc_root(vol->root_ino))) {
2455 /* We increment i_count simulating an ntfs_iget(). */
2456 atomic_inc(&vol->root_ino->i_count);
2457 ntfs_debug("Exiting, status successful.");
2458 /* Release the default upcase if it has no users. */
2460 if (!--ntfs_nr_upcase_users && default_upcase) {
2461 ntfs_free(default_upcase);
2462 default_upcase = NULL;
2465 sb->s_export_op = &ntfs_export_ops;
2469 ntfs_error(sb, "Failed to allocate root directory.");
2470 /* Clean up after the successful load_system_files() call from above. */
2471 // TODO: Use ntfs_put_super() instead of repeating all this code...
2472 // FIXME: Should mark the volume clean as the error is most likely
2475 vol->vol_ino = NULL;
2476 /* NTFS 3.0+ specific clean up. */
2477 if (vol->major_ver >= 3) {
2479 if (vol->quota_q_ino) {
2480 iput(vol->quota_q_ino);
2481 vol->quota_q_ino = NULL;
2483 if (vol->quota_ino) {
2484 iput(vol->quota_ino);
2485 vol->quota_ino = NULL;
2487 #endif /* NTFS_RW */
2488 if (vol->extend_ino) {
2489 iput(vol->extend_ino);
2490 vol->extend_ino = NULL;
2492 if (vol->secure_ino) {
2493 iput(vol->secure_ino);
2494 vol->secure_ino = NULL;
2497 iput(vol->root_ino);
2498 vol->root_ino = NULL;
2499 iput(vol->lcnbmp_ino);
2500 vol->lcnbmp_ino = NULL;
2501 iput(vol->mftbmp_ino);
2502 vol->mftbmp_ino = NULL;
2504 if (vol->logfile_ino) {
2505 iput(vol->logfile_ino);
2506 vol->logfile_ino = NULL;
2508 if (vol->mftmirr_ino) {
2509 iput(vol->mftmirr_ino);
2510 vol->mftmirr_ino = NULL;
2512 #endif /* NTFS_RW */
2513 /* Throw away the table of attribute definitions. */
2514 vol->attrdef_size = 0;
2516 ntfs_free(vol->attrdef);
2517 vol->attrdef = NULL;
2519 vol->upcase_len = 0;
2521 if (vol->upcase == default_upcase) {
2522 ntfs_nr_upcase_users--;
2527 ntfs_free(vol->upcase);
2531 unload_nls(vol->nls_map);
2532 vol->nls_map = NULL;
2534 /* Error exit code path. */
2535 unl_upcase_iput_tmp_ino_err_out_now:
2537 * Decrease the number of upcase users and destroy the global default
2538 * upcase table if necessary.
2541 if (!--ntfs_nr_upcase_users && default_upcase) {
2542 ntfs_free(default_upcase);
2543 default_upcase = NULL;
2545 if (vol->cluster_size <= 4096 && !--ntfs_nr_compression_users)
2546 free_compression_buffers();
2548 iput_tmp_ino_err_out_now:
2550 if (vol->mft_ino && vol->mft_ino != tmp_ino)
2552 vol->mft_ino = NULL;
2554 * This is needed to get ntfs_clear_extent_inode() called for each
2555 * inode we have ever called ntfs_iget()/iput() on, otherwise we A)
2556 * leak resources and B) a subsequent mount fails automatically due to
2557 * ntfs_iget() never calling down into our ntfs_read_locked_inode()
2558 * method again... FIXME: Do we need to do this twice now because of
2559 * attribute inodes? I think not, so leave as is for now... (AIA)
2561 if (invalidate_inodes(sb)) {
2562 ntfs_error(sb, "Busy inodes left. This is most likely a NTFS "
2564 /* Copied from fs/super.c. I just love this message. (-; */
2565 printk("NTFS: Busy inodes after umount. Self-destruct in 5 "
2566 "seconds. Have a nice day...\n");
2568 /* Errors at this stage are irrelevant. */
2571 sb->s_fs_info = NULL;
2573 ntfs_debug("Failed, returning -EINVAL.");
2578 * This is a slab cache to optimize allocations and deallocations of Unicode
2579 * strings of the maximum length allowed by NTFS, which is NTFS_MAX_NAME_LEN
2580 * (255) Unicode characters + a terminating NULL Unicode character.
2582 kmem_cache_t *ntfs_name_cache;
2584 /* Slab caches for efficient allocation/deallocation of of inodes. */
2585 kmem_cache_t *ntfs_inode_cache;
2586 kmem_cache_t *ntfs_big_inode_cache;
2588 /* Init once constructor for the inode slab cache. */
2589 static void ntfs_big_inode_init_once(void *foo, kmem_cache_t *cachep,
2590 unsigned long flags)
2592 ntfs_inode *ni = (ntfs_inode *)foo;
2594 if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
2595 SLAB_CTOR_CONSTRUCTOR)
2596 inode_init_once(VFS_I(ni));
2600 * Slab caches to optimize allocations and deallocations of attribute search
2601 * contexts and index contexts, respectively.
2603 kmem_cache_t *ntfs_attr_ctx_cache;
2604 kmem_cache_t *ntfs_index_ctx_cache;
2606 /* Driver wide semaphore. */
2607 DECLARE_MUTEX(ntfs_lock);
2609 static struct super_block *ntfs_get_sb(struct file_system_type *fs_type,
2610 int flags, const char *dev_name, void *data)
2612 return get_sb_bdev(fs_type, flags, dev_name, data, ntfs_fill_super);
2615 static struct file_system_type ntfs_fs_type = {
2616 .owner = THIS_MODULE,
2618 .get_sb = ntfs_get_sb,
2619 .kill_sb = kill_block_super,
2620 .fs_flags = FS_REQUIRES_DEV,
2623 /* Stable names for the slab caches. */
2624 static const char ntfs_index_ctx_cache_name[] = "ntfs_index_ctx_cache";
2625 static const char ntfs_attr_ctx_cache_name[] = "ntfs_attr_ctx_cache";
2626 static const char ntfs_name_cache_name[] = "ntfs_name_cache";
2627 static const char ntfs_inode_cache_name[] = "ntfs_inode_cache";
2628 static const char ntfs_big_inode_cache_name[] = "ntfs_big_inode_cache";
2630 static int __init init_ntfs_fs(void)
2634 /* This may be ugly but it results in pretty output so who cares. (-8 */
2635 printk(KERN_INFO "NTFS driver " NTFS_VERSION " [Flags: R/"
2649 ntfs_debug("Debug messages are enabled.");
2651 ntfs_index_ctx_cache = kmem_cache_create(ntfs_index_ctx_cache_name,
2652 sizeof(ntfs_index_context), 0 /* offset */,
2653 SLAB_HWCACHE_ALIGN, NULL /* ctor */, NULL /* dtor */);
2654 if (!ntfs_index_ctx_cache) {
2655 printk(KERN_CRIT "NTFS: Failed to create %s!\n",
2656 ntfs_index_ctx_cache_name);
2659 ntfs_attr_ctx_cache = kmem_cache_create(ntfs_attr_ctx_cache_name,
2660 sizeof(ntfs_attr_search_ctx), 0 /* offset */,
2661 SLAB_HWCACHE_ALIGN, NULL /* ctor */, NULL /* dtor */);
2662 if (!ntfs_attr_ctx_cache) {
2663 printk(KERN_CRIT "NTFS: Failed to create %s!\n",
2664 ntfs_attr_ctx_cache_name);
2668 ntfs_name_cache = kmem_cache_create(ntfs_name_cache_name,
2669 (NTFS_MAX_NAME_LEN+1) * sizeof(ntfschar), 0,
2670 SLAB_HWCACHE_ALIGN, NULL, NULL);
2671 if (!ntfs_name_cache) {
2672 printk(KERN_CRIT "NTFS: Failed to create %s!\n",
2673 ntfs_name_cache_name);
2677 ntfs_inode_cache = kmem_cache_create(ntfs_inode_cache_name,
2678 sizeof(ntfs_inode), 0,
2679 SLAB_RECLAIM_ACCOUNT, NULL, NULL);
2680 if (!ntfs_inode_cache) {
2681 printk(KERN_CRIT "NTFS: Failed to create %s!\n",
2682 ntfs_inode_cache_name);
2686 ntfs_big_inode_cache = kmem_cache_create(ntfs_big_inode_cache_name,
2687 sizeof(big_ntfs_inode), 0,
2688 SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT,
2689 ntfs_big_inode_init_once, NULL);
2690 if (!ntfs_big_inode_cache) {
2691 printk(KERN_CRIT "NTFS: Failed to create %s!\n",
2692 ntfs_big_inode_cache_name);
2693 goto big_inode_err_out;
2696 /* Register the ntfs sysctls. */
2697 err = ntfs_sysctl(1);
2699 printk(KERN_CRIT "NTFS: Failed to register NTFS sysctls!\n");
2700 goto sysctl_err_out;
2703 err = register_filesystem(&ntfs_fs_type);
2705 ntfs_debug("NTFS driver registered successfully.");
2706 return 0; /* Success! */
2708 printk(KERN_CRIT "NTFS: Failed to register NTFS filesystem driver!\n");
2711 kmem_cache_destroy(ntfs_big_inode_cache);
2713 kmem_cache_destroy(ntfs_inode_cache);
2715 kmem_cache_destroy(ntfs_name_cache);
2717 kmem_cache_destroy(ntfs_attr_ctx_cache);
2719 kmem_cache_destroy(ntfs_index_ctx_cache);
2722 printk(KERN_CRIT "NTFS: Aborting NTFS filesystem driver "
2723 "registration...\n");
2729 static void __exit exit_ntfs_fs(void)
2733 ntfs_debug("Unregistering NTFS driver.");
2735 unregister_filesystem(&ntfs_fs_type);
2737 if (kmem_cache_destroy(ntfs_big_inode_cache) && (err = 1))
2738 printk(KERN_CRIT "NTFS: Failed to destory %s.\n",
2739 ntfs_big_inode_cache_name);
2740 if (kmem_cache_destroy(ntfs_inode_cache) && (err = 1))
2741 printk(KERN_CRIT "NTFS: Failed to destory %s.\n",
2742 ntfs_inode_cache_name);
2743 if (kmem_cache_destroy(ntfs_name_cache) && (err = 1))
2744 printk(KERN_CRIT "NTFS: Failed to destory %s.\n",
2745 ntfs_name_cache_name);
2746 if (kmem_cache_destroy(ntfs_attr_ctx_cache) && (err = 1))
2747 printk(KERN_CRIT "NTFS: Failed to destory %s.\n",
2748 ntfs_attr_ctx_cache_name);
2749 if (kmem_cache_destroy(ntfs_index_ctx_cache) && (err = 1))
2750 printk(KERN_CRIT "NTFS: Failed to destory %s.\n",
2751 ntfs_index_ctx_cache_name);
2753 printk(KERN_CRIT "NTFS: This causes memory to leak! There is "
2754 "probably a BUG in the driver! Please report "
2755 "you saw this message to "
2756 "linux-ntfs-dev@lists.sourceforge.net\n");
2757 /* Unregister the ntfs sysctls. */
2761 MODULE_AUTHOR("Anton Altaparmakov <aia21@cantab.net>");
2762 MODULE_DESCRIPTION("NTFS 1.2/3.x driver - Copyright (c) 2001-2005 Anton Altaparmakov");
2763 MODULE_VERSION(NTFS_VERSION);
2764 MODULE_LICENSE("GPL");
2766 module_param(debug_msgs, bool, 0);
2767 MODULE_PARM_DESC(debug_msgs, "Enable debug messages.");
2770 module_init(init_ntfs_fs)
2771 module_exit(exit_ntfs_fs)