23 #include <linux/stddef.h>
25 #include <linux/slab.h>
26 #include <linux/string.h>
33 #include <linux/bitmap.h>
49 static unsigned long ntfs_nr_compression_users;
53 static unsigned long ntfs_nr_upcase_users = 0;
78 static int simple_getbool(
char *
s,
bool *setval)
103 static char *utf8 =
"utf8";
104 int errors = 0, sloppy = 0;
108 int mft_zone_multiplier = -1, on_errors = -1;
109 int show_sys_files = -1, case_sensitive = -1, disable_sparse = -1;
113 #define NTFS_GETOPT_WITH_DEFAULT(option, variable, default_value) \
114 if (!strcmp(p, option)) { \
116 variable = default_value; \
118 variable = simple_strtoul(ov = v, &v, 0); \
123 #define NTFS_GETOPT(option, variable) \
124 if (!strcmp(p, option)) { \
127 variable = simple_strtoul(ov = v, &v, 0); \
131 #define NTFS_GETOPT_UID(option, variable) \
132 if (!strcmp(p, option)) { \
136 uid_value = simple_strtoul(ov = v, &v, 0); \
139 variable = make_kuid(current_user_ns(), uid_value); \
140 if (!uid_valid(variable)) \
143 #define NTFS_GETOPT_GID(option, variable) \
144 if (!strcmp(p, option)) { \
148 gid_value = simple_strtoul(ov = v, &v, 0); \
151 variable = make_kgid(current_user_ns(), gid_value); \
152 if (!gid_valid(variable)) \
155 #define NTFS_GETOPT_OCTAL(option, variable) \
156 if (!strcmp(p, option)) { \
159 variable = simple_strtoul(ov = v, &v, 8); \
163 #define NTFS_GETOPT_BOOL(option, variable) \
164 if (!strcmp(p, option)) { \
166 if (!simple_getbool(v, &val)) \
170 #define NTFS_GETOPT_OPTIONS_ARRAY(option, variable, opt_array) \
171 if (!strcmp(p, option)) { \
176 if (variable == -1) \
178 for (_i = 0; opt_array[_i].str && *opt_array[_i].str; _i++) \
179 if (!strcmp(opt_array[_i].str, v)) { \
180 variable |= opt_array[_i].val; \
183 if (!opt_array[_i].str || !*opt_array[_i].str) \
187 goto no_mount_options;
188 ntfs_debug(
"Entering with mount options string: %s", opt);
189 while ((p =
strsep(&opt,
","))) {
193 else NTFS_GETOPT_GID("gid", gid)
194 else NTFS_GETOPT_OCTAL("umask", fmask = dmask)
195 else NTFS_GETOPT_OCTAL("fmask", fmask)
196 else NTFS_GETOPT_OCTAL("dmask", dmask)
197 else NTFS_GETOPT("mft_zone_multiplier", mft_zone_multiplier)
198 else NTFS_GETOPT_WITH_DEFAULT("sloppy", sloppy,
true)
199 else NTFS_GETOPT_BOOL("show_sys_files", show_sys_files)
200 else NTFS_GETOPT_BOOL("case_sensitive", case_sensitive)
201 else NTFS_GETOPT_BOOL("disable_sparse", disable_sparse)
202 else NTFS_GETOPT_OPTIONS_ARRAY("errors", on_errors,
208 if (!
strcmp(p,
"iocharset"))
210 "deprecated. Please use "
211 "option nls=<charsetname> in "
225 "found. Using previous one %s.",
226 v, old_nls->charset);
231 }
else if (!
strcmp(p,
"utf8")) {
234 "supported, using option nls=utf8. Please "
235 "use option nls=utf8 in the future and "
236 "make sure utf8 is compiled either as a "
237 "module or into the kernel.");
240 else if (!simple_getbool(v, &val))
247 ntfs_error(vol->
sb,
"Unrecognized mount option %s.", p);
251 #undef NTFS_GETOPT_OPTIONS_ARRAY
252 #undef NTFS_GETOPT_BOOL
254 #undef NTFS_GETOPT_WITH_DEFAULT
257 if (errors && !sloppy)
261 "unrecognized mount option(s) and continuing.");
263 if (on_errors != -1) {
266 "or bug in options parser.");
283 "NLS character set.");
286 ntfs_debug(
"Using default NLS character set (%s).",
290 if (mft_zone_multiplier != -1) {
292 mft_zone_multiplier) {
293 ntfs_error(vol->
sb,
"Cannot change mft_zone_multiplier "
297 if (mft_zone_multiplier < 1 || mft_zone_multiplier > 4) {
299 "Using default value, i.e. 1.");
300 mft_zone_multiplier = 1;
318 if (show_sys_files != -1) {
320 NVolSetShowSystemFiles(vol);
322 NVolClearShowSystemFiles(vol);
324 if (case_sensitive != -1) {
326 NVolSetCaseSensitive(vol);
328 NVolClearCaseSensitive(vol);
330 if (disable_sparse != -1) {
332 NVolClearSparseEnabled(vol);
334 if (!NVolSparseEnabled(vol) &&
337 "support due to NTFS volume "
338 "version %i.%i (need at least "
342 NVolSetSparseEnabled(vol);
347 ntfs_error(vol->
sb,
"The %s option requires an argument.", p);
350 ntfs_error(vol->
sb,
"The %s option requires a boolean argument.", p);
353 ntfs_error(vol->
sb,
"Invalid %s option argument: %s", p, ov);
378 VOLUME_INFORMATION *vi;
382 ntfs_debug(
"Entering, old flags = 0x%x, new flags = 0x%x.",
395 goto put_unm_err_out;
400 goto put_unm_err_out;
401 vi = (VOLUME_INFORMATION*)((
u8*)ctx->
attr +
404 flush_dcache_mft_record_page(ctx->
ntfs_ino);
405 mark_mft_record_dirty(ctx->
ntfs_ino);
416 ntfs_error(vol->
sb,
"Failed with error code %i.", -err);
432 return ntfs_write_volume_flags(vol, vol->
vol_flags | flags);
448 return ntfs_write_volume_flags(vol, flags);
465 static int ntfs_remount(
struct super_block *sb,
int *flags,
char *opt)
469 ntfs_debug(
"Entering with remount options string: %s", opt);
488 static const char *
es =
". Cannot remount read-write.";
491 if (NVolErrors(vol)) {
492 ntfs_error(sb,
"Volume has errors and is read-only%s",
497 ntfs_error(sb,
"Volume is dirty and read-only%s", es);
501 ntfs_error(sb,
"Volume has been modified by chkdsk "
502 "and is read-only%s", es);
506 ntfs_error(sb,
"Volume has unsupported flags set "
507 "(0x%x) and is read-only%s",
513 ntfs_error(sb,
"Failed to set dirty bit in volume "
514 "information flags%s", es);
524 "compatibility flag%s", es);
530 if (!ntfs_empty_logfile(vol->logfile_ino)) {
531 ntfs_error(sb,
"Failed to empty journal $LogFile%s",
536 if (!ntfs_mark_quotas_out_of_date(vol)) {
537 ntfs_error(sb,
"Failed to mark quotas out of date%s",
542 if (!ntfs_stamp_usnjrnl(vol)) {
543 ntfs_error(sb,
"Failed to stamp transation log "
548 }
else if (!(sb->
s_flags & MS_RDONLY) && (*flags & MS_RDONLY)) {
550 if (!NVolErrors(vol)) {
553 "in volume information "
554 "flags. Run chkdsk.");
561 if (!parse_options(vol, opt))
580 static bool is_boot_sector_ntfs(
const struct super_block *sb,
581 const NTFS_BOOT_SECTOR *
b,
const bool silent)
590 if ((
void*)b < (
void*)&b->checksum && b->checksum && !silent) {
594 for (i = 0, u = (
le32*)b; u < (
le32*)(&b->checksum); ++
u)
603 if (
le16_to_cpu(b->bpb.bytes_per_sector) < 0x100 ||
607 switch (b->bpb.sectors_per_cluster) {
608 case 1:
case 2:
case 4:
case 8:
case 16:
case 32:
case 64:
case 128:
625 if ((
u8)b->clusters_per_mft_record < 0xe1 ||
626 (
u8)b->clusters_per_mft_record > 0xf7)
627 switch (b->clusters_per_mft_record) {
628 case 1:
case 2:
case 4:
case 8:
case 16:
case 32:
case 64:
634 if ((
u8)b->clusters_per_index_record < 0xe1 ||
635 (
u8)b->clusters_per_index_record > 0xf7)
636 switch (b->clusters_per_index_record) {
637 case 1:
case 2:
case 4:
case 8:
case 16:
case 32:
case 64:
647 if (!silent && b->end_of_sector_marker !=
cpu_to_le16(0xaa55))
673 static struct buffer_head *read_ntfs_boot_sector(
struct super_block *sb,
676 const char *read_err_str =
"Unable to read %s boot sector.";
677 struct buffer_head *bh_primary, *bh_backup;
678 sector_t nr_blocks = NTFS_SB(sb)->nr_blocks;
681 if ((bh_primary = sb_bread(sb, 0))) {
682 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
683 bh_primary->b_data, silent))
686 ntfs_error(sb,
"Primary boot sector is invalid.");
693 ntfs_error(sb,
"Mount option errors=recover not used. "
694 "Aborting without trying to recover.");
698 if ((bh_backup = sb_bread(sb, nr_blocks - 1))) {
699 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
700 bh_backup->b_data, silent))
701 goto hotfix_primary_boot_sector;
706 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
707 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
708 bh_backup->b_data, silent))
709 goto hotfix_primary_boot_sector;
711 ntfs_error(sb,
"Could not find a valid backup boot "
720 hotfix_primary_boot_sector:
732 if (!(sb->
s_flags & MS_RDONLY)) {
734 "boot sector from backup copy.");
735 memcpy(bh_primary->b_data, bh_backup->b_data,
739 if (buffer_uptodate(bh_primary)) {
743 ntfs_error(sb,
"Hot-fix: Device write error while "
744 "recovering primary boot sector.");
747 "sector failed: Read-only mount.");
763 static bool parse_ntfs_boot_sector(
ntfs_volume *vol,
const NTFS_BOOT_SECTOR *b)
765 unsigned int sectors_per_cluster_bits, nr_hidden_sects;
766 int clusters_per_mft_record, clusters_per_index_record;
776 ntfs_error(vol->
sb,
"Sector size (%i) is smaller than the "
777 "device block size (%lu). This is not "
779 vol->
sb->s_blocksize);
782 ntfs_debug(
"sectors_per_cluster = 0x%x", b->bpb.sectors_per_cluster);
783 sectors_per_cluster_bits =
ffs(b->bpb.sectors_per_cluster) - 1;
785 sectors_per_cluster_bits);
786 nr_hidden_sects =
le32_to_cpu(b->bpb.hidden_sectors);
787 ntfs_debug(
"number of hidden sectors = 0x%x", nr_hidden_sects);
796 ntfs_error(vol->
sb,
"Cluster size (%i) is smaller than the "
797 "sector size (%i). This is not supported. "
801 clusters_per_mft_record = b->clusters_per_mft_record;
802 ntfs_debug(
"clusters_per_mft_record = %i (0x%x)",
803 clusters_per_mft_record, clusters_per_mft_record);
804 if (clusters_per_mft_record > 0)
806 (
ffs(clusters_per_mft_record) - 1);
818 ntfs_debug(
"vol->mft_record_size_mask = 0x%x",
820 ntfs_debug(
"vol->mft_record_size_bits = %i (0x%x)",
828 "PAGE_CACHE_SIZE on your system (%lu). "
829 "This is not supported. Sorry.",
835 ntfs_error(vol->
sb,
"Mft record size (%i) is smaller than the "
836 "sector size (%i). This is not supported. "
841 clusters_per_index_record = b->clusters_per_index_record;
842 ntfs_debug(
"clusters_per_index_record = %i (0x%x)",
843 clusters_per_index_record, clusters_per_index_record);
844 if (clusters_per_index_record > 0)
846 (
ffs(clusters_per_index_record) - 1);
857 ntfs_debug(
"vol->index_record_size = %i (0x%x)",
859 ntfs_debug(
"vol->index_record_size_mask = 0x%x",
861 ntfs_debug(
"vol->index_record_size_bits = %i (0x%x)",
866 ntfs_error(vol->
sb,
"Index record size (%i) is smaller than "
867 "the sector size (%i). This is not "
877 ll = sle64_to_cpu(b->number_of_sectors) >> sectors_per_cluster_bits;
878 if ((
u64)ll >= 1ULL << 32) {
879 ntfs_error(vol->
sb,
"Cannot handle 64-bit clusters. Sorry.");
889 if (
sizeof(
unsigned long) < 8) {
892 "large for this architecture. "
893 "Maximum supported is 2TiB. Sorry.",
894 (
unsigned long long)ll >> (40 -
899 ll = sle64_to_cpu(b->mft_lcn);
901 ntfs_error(vol->
sb,
"MFT LCN (%lli, 0x%llx) is beyond end of "
902 "volume. Weird.", (
unsigned long long)ll,
903 (
unsigned long long)ll);
908 ll = sle64_to_cpu(b->mftmirr_lcn);
910 ntfs_error(vol->
sb,
"MFTMirr LCN (%lli, 0x%llx) is beyond end "
911 "of volume. Weird.", (
unsigned long long)ll,
912 (
unsigned long long)ll);
927 vol->mftmirr_size = 4;
931 ntfs_debug(
"vol->mftmirr_size = %i", vol->mftmirr_size);
945 static void ntfs_setup_allocators(
ntfs_volume *vol)
948 LCN mft_zone_size, mft_lcn;
961 mft_zone_size = (mft_zone_size +
962 (mft_zone_size >> 1)) >> 2;
973 vol->mft_zone_start = vol->mft_zone_pos = vol->
mft_lcn;
975 (
unsigned long long)vol->mft_zone_pos);
989 if (vol->mft_zone_start <= mft_lcn)
990 vol->mft_zone_start = 0;
992 (
unsigned long long)vol->mft_zone_start);
998 vol->mft_zone_end = vol->
mft_lcn + mft_zone_size;
1000 mft_zone_size >>= 1;
1001 vol->mft_zone_end = vol->
mft_lcn + mft_zone_size;
1004 (
unsigned long long)vol->mft_zone_end);
1009 vol->data1_zone_pos = vol->mft_zone_end;
1011 (
unsigned long long)vol->data1_zone_pos);
1012 vol->data2_zone_pos = 0;
1014 (
unsigned long long)vol->data2_zone_pos);
1017 vol->mft_data_pos = 24;
1019 (
unsigned long long)vol->mft_data_pos);
1031 static bool load_and_init_mft_mirror(
ntfs_volume *vol)
1033 struct inode *tmp_ino;
1040 if (!IS_ERR(tmp_ino))
1059 tmp_ni = NTFS_I(tmp_ino);
1061 NInoSetMstProtected(tmp_ni);
1062 NInoSetSparseDisabled(tmp_ni);
1069 vol->mftmirr_ino = tmp_ino;
1088 struct page *mft_page, *mirr_page;
1092 int mrecs_per_page,
i;
1098 BUG_ON(!vol->mftmirr_size);
1099 mft_page = mirr_page =
NULL;
1100 kmft = kmirr =
NULL;
1106 if (!(i % mrecs_per_page)) {
1108 ntfs_unmap_page(mft_page);
1109 ntfs_unmap_page(mirr_page);
1112 mft_page = ntfs_map_page(vol->
mft_ino->i_mapping,
1114 if (IS_ERR(mft_page)) {
1120 mirr_page = ntfs_map_page(vol->mftmirr_ino->i_mapping,
1122 if (IS_ERR(mirr_page)) {
1134 "transfer detected in mft "
1137 ntfs_unmap_page(mirr_page);
1139 ntfs_unmap_page(mft_page);
1144 if (((MFT_RECORD*)kmirr)->flags & MFT_RECORD_IN_USE) {
1147 "transfer detected in mft "
1148 "mirror record %i.", i);
1153 bytes =
le32_to_cpu(((MFT_RECORD*)kmft)->bytes_in_use);
1154 if (bytes <
sizeof(MFT_RECORD_OLD) ||
1157 bytes =
le32_to_cpu(((MFT_RECORD*)kmirr)->bytes_in_use);
1158 if (bytes <
sizeof(MFT_RECORD_OLD) ||
1164 if (
memcmp(kmft, kmirr, bytes)) {
1165 ntfs_error(sb,
"$MFT and $MFTMirr (record %i) do not "
1166 "match. Run ntfsfix or chkdsk.", i);
1171 }
while (++i < vol->mftmirr_size);
1173 ntfs_unmap_page(mft_page);
1174 ntfs_unmap_page(mirr_page);
1188 mirr_ni = NTFS_I(vol->mftmirr_ino);
1194 if (rl2[i].vcn != rl[i].vcn || rl2[i].lcn != rl[i].lcn ||
1196 ntfs_error(sb,
"$MFTMirr location mismatch. "
1201 }
while (rl2[i++].
length);
1213 static bool load_and_check_logfile(
ntfs_volume *vol,
1214 RESTART_PAGE_HEADER **
rp)
1216 struct inode *tmp_ino;
1221 if (!IS_ERR(tmp_ino))
1226 if (!ntfs_check_logfile(tmp_ino, rp)) {
1231 NInoSetSparseDisabled(NTFS_I(tmp_ino));
1232 vol->logfile_ino = tmp_ino;
1237 #define NTFS_HIBERFIL_HEADER_SIZE 4096
1263 static int check_windows_hibernation_status(
ntfs_volume *vol)
1292 ntfs_debug(
"hiberfil.sys not present. Windows is not "
1293 "hibernated on the volume.");
1309 return IS_ERR(vi) ? PTR_ERR(vi) : -
EIO;
1311 if (
unlikely(i_size_read(vi) < NTFS_HIBERFIL_HEADER_SIZE)) {
1312 ntfs_debug(
"hiberfil.sys is smaller than 4kiB (0x%llx). "
1313 "Windows is hibernated on the volume. This "
1314 "is not the system volume.", i_size_read(vi));
1319 ntfs_error(vol->
sb,
"Failed to read from hiberfil.sys.");
1320 ret = PTR_ERR(page);
1325 ntfs_debug(
"Magic \"hibr\" found in hiberfil.sys. Windows is "
1326 "hibernated on the volume. This is the "
1330 kend = kaddr + NTFS_HIBERFIL_HEADER_SIZE/
sizeof(*kaddr);
1333 ntfs_debug(
"hiberfil.sys is larger than 4kiB "
1334 "(0x%llx), does not contain the "
1335 "\"hibr\" magic, and does not have a "
1336 "zero header. Windows is hibernated "
1337 "on the volume. This is not the "
1338 "system volume.", i_size_read(vi));
1341 }
while (++kaddr < kend);
1342 ntfs_debug(
"hiberfil.sys contains a zero header. Windows is not "
1343 "hibernated on the volume. This is the system "
1347 ntfs_unmap_page(page);
1363 struct inode *tmp_ino;
1364 ntfs_name *name =
NULL;
1387 ntfs_debug(
"$Quota not present. Volume does not have "
1393 NVolSetQuotaOutOfDate(vol);
1397 ntfs_error(vol->
sb,
"Failed to find inode number for $Quota.");
1405 if (!IS_ERR(tmp_ino))
1410 vol->quota_ino = tmp_ino;
1413 if (IS_ERR(tmp_ino)) {
1414 ntfs_error(vol->
sb,
"Failed to load $Quota/$Q index.");
1417 vol->quota_q_ino = tmp_ino;
1436 static bool load_and_init_usnjrnl(
ntfs_volume *vol)
1439 struct inode *tmp_ino;
1442 ntfs_name *name =
NULL;
1470 ntfs_debug(
"$UsnJrnl not present. Volume does not "
1471 "have transaction logging enabled.");
1477 NVolSetUsnJrnlStamped(vol);
1490 if (!IS_ERR(tmp_ino))
1495 vol->usnjrnl_ino = tmp_ino;
1501 ntfs_debug(
"$UsnJrnl in the process of being disabled. "
1502 "Volume does not have transaction logging "
1508 if (IS_ERR(tmp_ino)) {
1509 ntfs_error(vol->
sb,
"Failed to load $UsnJrnl/$DATA/$Max "
1513 vol->usnjrnl_max_ino = tmp_ino;
1514 if (
unlikely(i_size_read(tmp_ino) <
sizeof(USN_HEADER))) {
1515 ntfs_error(vol->
sb,
"Found corrupt $UsnJrnl/$DATA/$Max "
1516 "attribute (size is 0x%llx but should be at "
1517 "least 0x%zx bytes).", i_size_read(tmp_ino),
1518 sizeof(USN_HEADER));
1523 if (IS_ERR(tmp_ino)) {
1524 ntfs_error(vol->
sb,
"Failed to load $UsnJrnl/$DATA/$J "
1528 vol->usnjrnl_j_ino = tmp_ino;
1530 tmp_ni = NTFS_I(vol->usnjrnl_j_ino);
1531 if (
unlikely(!NInoNonResident(tmp_ni) || !NInoSparse(tmp_ni))) {
1532 ntfs_error(vol->
sb,
"$UsnJrnl/$DATA/$J attribute is resident "
1533 "and/or not sparse.");
1537 page = ntfs_map_page(vol->usnjrnl_max_ino->i_mapping, 0);
1539 ntfs_error(vol->
sb,
"Failed to read from $UsnJrnl/$DATA/$Max "
1545 if (
unlikely(sle64_to_cpu(uh->allocation_delta) >
1546 sle64_to_cpu(uh->maximum_size))) {
1547 ntfs_error(vol->
sb,
"Allocation delta (0x%llx) exceeds "
1548 "maximum size (0x%llx). $UsnJrnl is corrupt.",
1549 (
long long)sle64_to_cpu(uh->allocation_delta),
1550 (
long long)sle64_to_cpu(uh->maximum_size));
1551 ntfs_unmap_page(page);
1558 if (
unlikely(sle64_to_cpu(uh->lowest_valid_usn) >=
1559 i_size_read(vol->usnjrnl_j_ino))) {
1560 if (
likely(sle64_to_cpu(uh->lowest_valid_usn) ==
1561 i_size_read(vol->usnjrnl_j_ino))) {
1562 ntfs_unmap_page(page);
1563 ntfs_debug(
"$UsnJrnl is enabled but nothing has been "
1564 "logged since it was last stamped. "
1565 "Treating this as if the volume does "
1566 "not have transaction logging "
1570 ntfs_error(vol->
sb,
"$UsnJrnl has lowest valid usn (0x%llx) "
1571 "which is out of bounds (0x%llx). $UsnJrnl "
1573 (
long long)sle64_to_cpu(uh->lowest_valid_usn),
1574 i_size_read(vol->usnjrnl_j_ino));
1575 ntfs_unmap_page(page);
1578 ntfs_unmap_page(page);
1589 static bool load_and_init_attrdef(
ntfs_volume *vol)
1606 NInoSetSparseDisabled(NTFS_I(ino));
1608 i_size = i_size_read(ino);
1609 if (i_size <= 0 || i_size > 0x7fffffff)
1617 while (index < max_index) {
1619 read_partial_attrdef_page:
1620 page = ntfs_map_page(ino->
i_mapping, index);
1622 goto free_iput_failed;
1625 ntfs_unmap_page(page);
1630 goto read_partial_attrdef_page;
1633 ntfs_debug(
"Read %llu bytes from $AttrDef.", i_size);
1642 ntfs_error(sb,
"Failed to initialize attribute definition table.");
1654 static bool load_and_init_upcase(
ntfs_volume *vol)
1676 i_size = i_size_read(ino);
1677 if (!i_size || i_size & (
sizeof(
ntfschar) - 1) ||
1678 i_size > 64ULL * 1024 *
sizeof(
ntfschar))
1679 goto iput_upcase_failed;
1682 goto iput_upcase_failed;
1686 while (index < max_index) {
1688 read_partial_upcase_page:
1689 page = ntfs_map_page(ino->
i_mapping, index);
1691 goto iput_upcase_failed;
1692 memcpy((
char*)vol->
upcase + (index++ << PAGE_CACHE_SHIFT),
1694 ntfs_unmap_page(page);
1699 goto read_partial_upcase_page;
1702 ntfs_debug(
"Read %llu bytes from $UpCase (expected %zu bytes).",
1703 i_size, 64 * 1024 *
sizeof(
ntfschar));
1706 if (!default_upcase) {
1707 ntfs_debug(
"Using volume specified $UpCase since default is "
1715 for (i = 0; i <
max; i++)
1716 if (vol->
upcase[i] != default_upcase[i])
1720 vol->
upcase = default_upcase;
1722 ntfs_nr_upcase_users++;
1724 ntfs_debug(
"Volume specified $UpCase matches default. Using "
1729 ntfs_debug(
"Using volume specified $UpCase since it does not match "
1738 if (default_upcase) {
1739 vol->
upcase = default_upcase;
1741 ntfs_nr_upcase_users++;
1743 ntfs_error(sb,
"Failed to load $UpCase from the volume. Using "
1748 ntfs_error(sb,
"Failed to initialize upcase table.");
1757 lcnbmp_runlist_lock_key, lcnbmp_mrec_lock_key,
1758 mftbmp_runlist_lock_key, mftbmp_mrec_lock_key;
1773 VOLUME_INFORMATION *vi;
1776 RESTART_PAGE_HEADER *
rp;
1783 if (!load_and_init_mft_mirror(vol) || !check_mft_mirror(vol)) {
1784 static const char *es1 =
"Failed to load $MFTMirr";
1785 static const char *es2 =
"$MFTMirr does not match $MFT";
1786 static const char *es3 =
". Run ntfsfix and/or chkdsk.";
1789 if (!(sb->
s_flags & MS_RDONLY)) {
1793 "continue nor on_errors="
1794 "remount-ro was specified%s",
1795 !vol->mftmirr_ino ? es1 : es2,
1797 goto iput_mirr_err_out;
1801 !vol->mftmirr_ino ? es1 : es2, es3);
1805 !vol->mftmirr_ino ? es1 : es2, es3);
1813 ntfs_error(sb,
"Failed to load $MFT/$BITMAP attribute.");
1814 goto iput_mirr_err_out;
1817 &mftbmp_runlist_lock_key);
1819 &mftbmp_mrec_lock_key);
1821 if (!load_and_init_upcase(vol))
1822 goto iput_mftbmp_err_out;
1828 if (!load_and_init_attrdef(vol))
1829 goto iput_upcase_err_out;
1843 &lcnbmp_runlist_lock_key);
1845 &lcnbmp_mrec_lock_key);
1847 NInoSetSparseDisabled(NTFS_I(vol->
lcnbmp_ino));
1852 goto iput_attrdef_err_out;
1864 goto iput_lcnbmp_err_out;
1873 ntfs_error(sb,
"Failed to get attribute search context.");
1874 goto get_ctx_vol_failed;
1877 ctx) || ctx->
attr->non_resident || ctx->
attr->flags) {
1882 goto iput_volume_failed;
1884 vi = (VOLUME_INFORMATION*)((
char*)ctx->
attr +
1899 if (vol->
major_ver < 3 && NVolSparseEnabled(vol)) {
1901 "volume version %i.%i (need at least version "
1903 NVolClearSparseEnabled(vol);
1908 static const char *es1a =
"Volume is dirty";
1909 static const char *es1b =
"Volume has been modified by chkdsk";
1910 static const char *es1c =
"Volume has unsupported flags set";
1911 static const char *es2a =
". Run chkdsk and mount in Windows.";
1912 static const char *es2b =
". Mount in Windows.";
1913 const char *es1, *es2;
1928 if (!(sb->
s_flags & MS_RDONLY)) {
1932 "continue nor on_errors="
1933 "remount-ro was specified%s",
1935 goto iput_vol_err_out;
1938 ntfs_error(sb,
"%s. Mounting read-only%s", es1, es2);
1941 "read-write%s", es1, es2);
1952 if (!load_and_check_logfile(vol, &rp) ||
1953 !ntfs_is_logfile_clean(vol->logfile_ino, rp)) {
1954 static const char *es1a =
"Failed to load $LogFile";
1955 static const char *es1b =
"$LogFile is not clean";
1956 static const char *es2 =
". Mount in Windows.";
1959 es1 = !vol->logfile_ino ? es1a : es1b;
1961 if (!(sb->
s_flags & MS_RDONLY)) {
1965 "continue nor on_errors="
1966 "remount-ro was specified%s",
1968 if (vol->logfile_ino) {
1972 goto iput_logfile_err_out;
1975 ntfs_error(sb,
"%s. Mounting read-only%s", es1, es2);
1978 "read-write%s", es1, es2);
1989 ntfs_error(sb,
"Failed to load root directory.");
1990 goto iput_logfile_err_out;
2000 err = check_windows_hibernation_status(vol);
2002 static const char *es1a =
"Failed to determine if Windows is "
2004 static const char *es1b =
"Windows is hibernated";
2005 static const char *es2 =
". Run chkdsk.";
2008 es1 = err < 0 ? es1a : es1b;
2010 if (!(sb->
s_flags & MS_RDONLY)) {
2014 "continue nor on_errors="
2015 "remount-ro was specified%s",
2017 goto iput_root_err_out;
2020 ntfs_error(sb,
"%s. Mounting read-only%s", es1, es2);
2023 "read-write%s", es1, es2);
2028 if (!(sb->
s_flags & MS_RDONLY) &&
2030 static const char *es1 =
"Failed to set dirty bit in volume "
2031 "information flags";
2032 static const char *es2 =
". Run chkdsk.";
2037 ntfs_error(sb,
"%s and neither on_errors=continue nor "
2038 "on_errors=remount-ro was specified%s",
2040 goto iput_root_err_out;
2042 ntfs_error(sb,
"%s. Mounting read-only%s", es1, es2);
2058 static const char *es1 =
"Failed to set NT4 compatibility flag";
2059 static const char *es2 =
". Run chkdsk.";
2064 ntfs_error(sb,
"%s and neither on_errors=continue nor "
2065 "on_errors=remount-ro was specified%s",
2067 goto iput_root_err_out;
2069 ntfs_error(sb,
"%s. Mounting read-only%s", es1, es2);
2075 if (!(sb->
s_flags & MS_RDONLY) &&
2076 !ntfs_empty_logfile(vol->logfile_ino)) {
2077 static const char *es1 =
"Failed to empty $LogFile";
2078 static const char *es2 =
". Mount in Windows.";
2083 ntfs_error(sb,
"%s and neither on_errors=continue nor "
2084 "on_errors=remount-ro was specified%s",
2086 goto iput_root_err_out;
2088 ntfs_error(sb,
"%s. Mounting read-only%s", es1, es2);
2103 goto iput_root_err_out;
2112 goto iput_sec_err_out;
2116 if (!load_and_init_quota(vol)) {
2117 static const char *es1 =
"Failed to load $Quota";
2118 static const char *es2 =
". Run chkdsk.";
2121 if (!(sb->
s_flags & MS_RDONLY)) {
2125 "continue nor on_errors="
2126 "remount-ro was specified%s",
2128 goto iput_quota_err_out;
2131 ntfs_error(sb,
"%s. Mounting read-only%s", es1, es2);
2134 "read-write%s", es1, es2);
2139 if (!(sb->
s_flags & MS_RDONLY) &&
2140 !ntfs_mark_quotas_out_of_date(vol)) {
2141 static const char *es1 =
"Failed to mark quotas out of date";
2142 static const char *es2 =
". Run chkdsk.";
2147 ntfs_error(sb,
"%s and neither on_errors=continue nor "
2148 "on_errors=remount-ro was specified%s",
2150 goto iput_quota_err_out;
2152 ntfs_error(sb,
"%s. Mounting read-only%s", es1, es2);
2160 if (!load_and_init_usnjrnl(vol)) {
2161 static const char *es1 =
"Failed to load $UsnJrnl";
2162 static const char *es2 =
". Run chkdsk.";
2165 if (!(sb->
s_flags & MS_RDONLY)) {
2169 "continue nor on_errors="
2170 "remount-ro was specified%s",
2172 goto iput_usnjrnl_err_out;
2175 ntfs_error(sb,
"%s. Mounting read-only%s", es1, es2);
2178 "read-write%s", es1, es2);
2183 if (!(sb->
s_flags & MS_RDONLY) && !ntfs_stamp_usnjrnl(vol)) {
2184 static const char *es1 =
"Failed to stamp transaction log "
2186 static const char *es2 =
". Run chkdsk.";
2191 ntfs_error(sb,
"%s and neither on_errors=continue nor "
2192 "on_errors=remount-ro was specified%s",
2194 goto iput_usnjrnl_err_out;
2196 ntfs_error(sb,
"%s. Mounting read-only%s", es1, es2);
2203 iput_usnjrnl_err_out:
2204 if (vol->usnjrnl_j_ino)
2205 iput(vol->usnjrnl_j_ino);
2206 if (vol->usnjrnl_max_ino)
2207 iput(vol->usnjrnl_max_ino);
2208 if (vol->usnjrnl_ino)
2209 iput(vol->usnjrnl_ino);
2211 if (vol->quota_q_ino)
2212 iput(vol->quota_q_ino);
2214 iput(vol->quota_ino);
2221 iput_logfile_err_out:
2223 if (vol->logfile_ino)
2224 iput(vol->logfile_ino);
2228 iput_lcnbmp_err_out:
2230 iput_attrdef_err_out:
2237 iput_upcase_err_out:
2241 if (vol->
upcase == default_upcase) {
2242 ntfs_nr_upcase_users--;
2250 iput_mftbmp_err_out:
2254 if (vol->mftmirr_ino)
2255 iput(vol->mftmirr_ino);
2269 static void ntfs_put_super(
struct super_block *sb)
2280 ntfs_commit_inode(vol->
vol_ino);
2284 if (vol->usnjrnl_j_ino)
2285 ntfs_commit_inode(vol->usnjrnl_j_ino);
2286 if (vol->usnjrnl_max_ino)
2287 ntfs_commit_inode(vol->usnjrnl_max_ino);
2288 if (vol->usnjrnl_ino)
2289 ntfs_commit_inode(vol->usnjrnl_ino);
2290 if (vol->quota_q_ino)
2291 ntfs_commit_inode(vol->quota_q_ino);
2293 ntfs_commit_inode(vol->quota_ino);
2310 if (vol->logfile_ino)
2311 ntfs_commit_inode(vol->logfile_ino);
2313 if (vol->mftmirr_ino)
2314 ntfs_commit_inode(vol->mftmirr_ino);
2315 ntfs_commit_inode(vol->
mft_ino);
2321 if (!(sb->
s_flags & MS_RDONLY)) {
2322 if (!NVolErrors(vol)) {
2325 "in volume information "
2326 "flags. Run chkdsk.");
2327 ntfs_commit_inode(vol->
vol_ino);
2329 if (vol->mftmirr_ino)
2330 ntfs_commit_inode(vol->mftmirr_ino);
2331 ntfs_commit_inode(vol->
mft_ino);
2334 "marked dirty. Run chkdsk.");
2345 if (vol->usnjrnl_j_ino) {
2346 iput(vol->usnjrnl_j_ino);
2347 vol->usnjrnl_j_ino =
NULL;
2349 if (vol->usnjrnl_max_ino) {
2350 iput(vol->usnjrnl_max_ino);
2351 vol->usnjrnl_max_ino =
NULL;
2353 if (vol->usnjrnl_ino) {
2354 iput(vol->usnjrnl_ino);
2355 vol->usnjrnl_ino =
NULL;
2357 if (vol->quota_q_ino) {
2358 iput(vol->quota_q_ino);
2359 vol->quota_q_ino =
NULL;
2361 if (vol->quota_ino) {
2362 iput(vol->quota_ino);
2363 vol->quota_ino =
NULL;
2390 if (vol->logfile_ino) {
2391 iput(vol->logfile_ino);
2392 vol->logfile_ino =
NULL;
2394 if (vol->mftmirr_ino) {
2396 ntfs_commit_inode(vol->mftmirr_ino);
2397 ntfs_commit_inode(vol->
mft_ino);
2398 iput(vol->mftmirr_ino);
2399 vol->mftmirr_ino =
NULL;
2406 ntfs_commit_inode(vol->
mft_ino);
2425 if (vol->
upcase == default_upcase) {
2426 ntfs_nr_upcase_users--;
2429 if (!ntfs_nr_upcase_users && default_upcase) {
2430 ntfs_free(default_upcase);
2431 default_upcase =
NULL;
2433 if (vol->
cluster_size <= 4096 && !--ntfs_nr_compression_users)
2484 ntfs_debug(
"Reading $Bitmap, max_index = 0x%lx, max_size = 0x%lx.",
2486 for (index = 0; index < max_index; index++) {
2487 unsigned long *kaddr;
2493 page = read_mapping_page(mapping, index,
NULL);
2496 ntfs_debug(
"read_mapping_page() error. Skipping "
2497 "page (index 0x%lx).", index);
2509 nr_free -= bitmap_weight(kaddr,
2514 ntfs_debug(
"Finished reading $Bitmap, last index = 0x%lx.", index - 1);
2546 static unsigned long __get_nr_free_mft_records(
ntfs_volume *vol,
2555 ntfs_debug(
"Reading $MFT/$BITMAP, max_index = 0x%lx, max_size = "
2557 for (index = 0; index < max_index; index++) {
2558 unsigned long *kaddr;
2564 page = read_mapping_page(mapping, index,
NULL);
2567 ntfs_debug(
"read_mapping_page() error. Skipping "
2568 "page (index 0x%lx).", index);
2580 nr_free -= bitmap_weight(kaddr,
2585 ntfs_debug(
"Finished reading $MFT/$BITMAP, last index = 0x%lx.",
2619 unsigned long flags;
2655 sfs->
f_ffree = __get_nr_free_mft_records(vol, size, max_index);
2688 .write_inode = ntfs_write_inode,
2691 .put_super = ntfs_put_super,
2692 .statfs = ntfs_statfs,
2693 .remount_fs = ntfs_remount,
2718 static int ntfs_fill_super(
struct super_block *sb,
void *opt,
const int silent)
2721 struct buffer_head *bh;
2722 struct inode *tmp_ino;
2745 ntfs_error(sb,
"Allocation of NTFS volume structure "
2746 "failed. Aborting mount...");
2766 NVolSetSparseEnabled(vol);
2769 if (!parse_options(vol, (
char*)opt))
2775 ntfs_error(sb,
"Device has unsupported sector size "
2776 "(%i). The maximum supported sector "
2777 "size on this architecture is %lu "
2779 bdev_logical_block_size(sb->
s_bdev),
2790 ntfs_error(sb,
"Unable to set device block size.");
2794 ntfs_debug(
"Set device block size to %i bytes (block size bits %i).",
2797 if (!i_size_read(sb->
s_bdev->bd_inode)) {
2799 ntfs_error(sb,
"Unable to determine device size.");
2805 if (!(bh = read_ntfs_boot_sector(sb, silent))) {
2814 result = parse_ntfs_boot_sector(vol, (NTFS_BOOT_SECTOR*)bh->b_data);
2818 ntfs_error(sb,
"Unsupported NTFS filesystem.");
2836 "size to sector size (%i).",
2843 ntfs_debug(
"Changed device block size to %i bytes (block size "
2844 "bits %i) to match volume sector size.",
2848 ntfs_setup_allocators(vol);
2869 sb->
s_op = &ntfs_sops;
2873 ntfs_error(sb,
"Failed to load essential metadata.");
2877 insert_inode_hash(tmp_ino);
2880 ntfs_error(sb,
"Failed to load essential metadata.");
2881 goto iput_tmp_ino_err_out_now;
2888 if (vol->
cluster_size <= 4096 && !ntfs_nr_compression_users++) {
2892 "for compression engine.");
2893 ntfs_nr_compression_users--;
2895 goto iput_tmp_ino_err_out_now;
2903 if (!default_upcase)
2905 ntfs_nr_upcase_users++;
2915 if (!load_system_files(vol)) {
2916 ntfs_error(sb,
"Failed to load system files.");
2917 goto unl_upcase_iput_tmp_ino_err_out_now;
2926 if (!--ntfs_nr_upcase_users && default_upcase) {
2927 ntfs_free(default_upcase);
2928 default_upcase =
NULL;
2935 ntfs_error(sb,
"Failed to allocate root directory.");
2945 if (vol->usnjrnl_j_ino) {
2946 iput(vol->usnjrnl_j_ino);
2947 vol->usnjrnl_j_ino =
NULL;
2949 if (vol->usnjrnl_max_ino) {
2950 iput(vol->usnjrnl_max_ino);
2951 vol->usnjrnl_max_ino =
NULL;
2953 if (vol->usnjrnl_ino) {
2954 iput(vol->usnjrnl_ino);
2955 vol->usnjrnl_ino =
NULL;
2957 if (vol->quota_q_ino) {
2958 iput(vol->quota_q_ino);
2959 vol->quota_q_ino =
NULL;
2961 if (vol->quota_ino) {
2962 iput(vol->quota_ino);
2963 vol->quota_ino =
NULL;
2982 if (vol->logfile_ino) {
2983 iput(vol->logfile_ino);
2984 vol->logfile_ino =
NULL;
2986 if (vol->mftmirr_ino) {
2987 iput(vol->mftmirr_ino);
2988 vol->mftmirr_ino =
NULL;
2999 if (vol->
upcase == default_upcase) {
3000 ntfs_nr_upcase_users--;
3013 unl_upcase_iput_tmp_ino_err_out_now:
3019 if (!--ntfs_nr_upcase_users && default_upcase) {
3020 ntfs_free(default_upcase);
3021 default_upcase =
NULL;
3023 if (vol->
cluster_size <= 4096 && !--ntfs_nr_compression_users)
3026 iput_tmp_ino_err_out_now:
3052 static void ntfs_big_inode_init_once(
void *
foo)
3070 int flags,
const char *dev_name,
void *
data)
3072 return mount_bdev(fs_type, flags, dev_name, data, ntfs_fill_super);
3078 .mount = ntfs_mount,
3084 static const char ntfs_index_ctx_cache_name[] =
"ntfs_index_ctx_cache";
3085 static const char ntfs_attr_ctx_cache_name[] =
"ntfs_attr_ctx_cache";
3086 static const char ntfs_name_cache_name[] =
"ntfs_name_cache";
3087 static const char ntfs_inode_cache_name[] =
"ntfs_inode_cache";
3088 static const char ntfs_big_inode_cache_name[] =
"ntfs_big_inode_cache";
3090 static int __init init_ntfs_fs(
void)
3114 if (!ntfs_index_ctx_cache) {
3116 ntfs_index_ctx_cache_name);
3122 if (!ntfs_attr_ctx_cache) {
3124 ntfs_attr_ctx_cache_name);
3131 if (!ntfs_name_cache) {
3133 ntfs_name_cache_name);
3140 if (!ntfs_inode_cache) {
3142 ntfs_inode_cache_name);
3149 ntfs_big_inode_init_once);
3150 if (!ntfs_big_inode_cache) {
3152 ntfs_big_inode_cache_name);
3153 goto big_inode_err_out;
3157 err = ntfs_sysctl(1);
3160 goto sysctl_err_out;
3165 ntfs_debug(
"NTFS driver registered successfully.");
3168 printk(
KERN_CRIT "NTFS: Failed to register NTFS filesystem driver!\n");
3185 "registration...\n");
3191 static void __exit exit_ntfs_fs(
void)
3212 MODULE_DESCRIPTION(
"NTFS 1.2/3.x driver - Copyright (c) 2001-2011 Anton Altaparmakov and Tuxera Inc.");