diff options
Diffstat (limited to 'fs/ntfs/super.c')
| -rw-r--r-- | fs/ntfs/super.c | 722 |
1 files changed, 565 insertions, 157 deletions
diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c index 212a3d0f2073..453d0d51ea4b 100644 --- a/fs/ntfs/super.c +++ b/fs/ntfs/super.c | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * super.c - NTFS kernel super block handling. Part of the Linux-NTFS project. | 2 | * super.c - NTFS kernel super block handling. Part of the Linux-NTFS project. |
| 3 | * | 3 | * |
| 4 | * Copyright (c) 2001-2004 Anton Altaparmakov | 4 | * Copyright (c) 2001-2005 Anton Altaparmakov |
| 5 | * Copyright (c) 2001,2002 Richard Russon | 5 | * Copyright (c) 2001,2002 Richard Russon |
| 6 | * | 6 | * |
| 7 | * This program/include file is free software; you can redistribute it and/or | 7 | * This program/include file is free software; you can redistribute it and/or |
| @@ -34,14 +34,16 @@ | |||
| 34 | #include "sysctl.h" | 34 | #include "sysctl.h" |
| 35 | #include "logfile.h" | 35 | #include "logfile.h" |
| 36 | #include "quota.h" | 36 | #include "quota.h" |
| 37 | #include "usnjrnl.h" | ||
| 37 | #include "dir.h" | 38 | #include "dir.h" |
| 38 | #include "debug.h" | 39 | #include "debug.h" |
| 39 | #include "index.h" | 40 | #include "index.h" |
| 40 | #include "aops.h" | 41 | #include "aops.h" |
| 42 | #include "layout.h" | ||
| 41 | #include "malloc.h" | 43 | #include "malloc.h" |
| 42 | #include "ntfs.h" | 44 | #include "ntfs.h" |
| 43 | 45 | ||
| 44 | /* Number of mounted file systems which have compression enabled. */ | 46 | /* Number of mounted filesystems which have compression enabled. */ |
| 45 | static unsigned long ntfs_nr_compression_users; | 47 | static unsigned long ntfs_nr_compression_users; |
| 46 | 48 | ||
| 47 | /* A global default upcase table and a corresponding reference count. */ | 49 | /* A global default upcase table and a corresponding reference count. */ |
| @@ -102,7 +104,7 @@ static BOOL parse_options(ntfs_volume *vol, char *opt) | |||
| 102 | gid_t gid = (gid_t)-1; | 104 | gid_t gid = (gid_t)-1; |
| 103 | mode_t fmask = (mode_t)-1, dmask = (mode_t)-1; | 105 | mode_t fmask = (mode_t)-1, dmask = (mode_t)-1; |
| 104 | int mft_zone_multiplier = -1, on_errors = -1; | 106 | int mft_zone_multiplier = -1, on_errors = -1; |
| 105 | int show_sys_files = -1, case_sensitive = -1; | 107 | int show_sys_files = -1, case_sensitive = -1, disable_sparse = -1; |
| 106 | struct nls_table *nls_map = NULL, *old_nls; | 108 | struct nls_table *nls_map = NULL, *old_nls; |
| 107 | 109 | ||
| 108 | /* I am lazy... (-8 */ | 110 | /* I am lazy... (-8 */ |
| @@ -124,6 +126,14 @@ static BOOL parse_options(ntfs_volume *vol, char *opt) | |||
| 124 | if (*v) \ | 126 | if (*v) \ |
| 125 | goto needs_val; \ | 127 | goto needs_val; \ |
| 126 | } | 128 | } |
| 129 | #define NTFS_GETOPT_OCTAL(option, variable) \ | ||
| 130 | if (!strcmp(p, option)) { \ | ||
| 131 | if (!v || !*v) \ | ||
| 132 | goto needs_arg; \ | ||
| 133 | variable = simple_strtoul(ov = v, &v, 8); \ | ||
| 134 | if (*v) \ | ||
| 135 | goto needs_val; \ | ||
| 136 | } | ||
| 127 | #define NTFS_GETOPT_BOOL(option, variable) \ | 137 | #define NTFS_GETOPT_BOOL(option, variable) \ |
| 128 | if (!strcmp(p, option)) { \ | 138 | if (!strcmp(p, option)) { \ |
| 129 | BOOL val; \ | 139 | BOOL val; \ |
| @@ -155,13 +165,14 @@ static BOOL parse_options(ntfs_volume *vol, char *opt) | |||
| 155 | *v++ = 0; | 165 | *v++ = 0; |
| 156 | NTFS_GETOPT("uid", uid) | 166 | NTFS_GETOPT("uid", uid) |
| 157 | else NTFS_GETOPT("gid", gid) | 167 | else NTFS_GETOPT("gid", gid) |
| 158 | else NTFS_GETOPT("umask", fmask = dmask) | 168 | else NTFS_GETOPT_OCTAL("umask", fmask = dmask) |
| 159 | else NTFS_GETOPT("fmask", fmask) | 169 | else NTFS_GETOPT_OCTAL("fmask", fmask) |
| 160 | else NTFS_GETOPT("dmask", dmask) | 170 | else NTFS_GETOPT_OCTAL("dmask", dmask) |
| 161 | else NTFS_GETOPT("mft_zone_multiplier", mft_zone_multiplier) | 171 | else NTFS_GETOPT("mft_zone_multiplier", mft_zone_multiplier) |
| 162 | else NTFS_GETOPT_WITH_DEFAULT("sloppy", sloppy, TRUE) | 172 | else NTFS_GETOPT_WITH_DEFAULT("sloppy", sloppy, TRUE) |
| 163 | else NTFS_GETOPT_BOOL("show_sys_files", show_sys_files) | 173 | else NTFS_GETOPT_BOOL("show_sys_files", show_sys_files) |
| 164 | else NTFS_GETOPT_BOOL("case_sensitive", case_sensitive) | 174 | else NTFS_GETOPT_BOOL("case_sensitive", case_sensitive) |
| 175 | else NTFS_GETOPT_BOOL("disable_sparse", disable_sparse) | ||
| 165 | else NTFS_GETOPT_OPTIONS_ARRAY("errors", on_errors, | 176 | else NTFS_GETOPT_OPTIONS_ARRAY("errors", on_errors, |
| 166 | on_errors_arr) | 177 | on_errors_arr) |
| 167 | else if (!strcmp(p, "posix") || !strcmp(p, "show_inodes")) | 178 | else if (!strcmp(p, "posix") || !strcmp(p, "show_inodes")) |
| @@ -291,6 +302,21 @@ no_mount_options: | |||
| 291 | else | 302 | else |
| 292 | NVolClearCaseSensitive(vol); | 303 | NVolClearCaseSensitive(vol); |
| 293 | } | 304 | } |
| 305 | if (disable_sparse != -1) { | ||
| 306 | if (disable_sparse) | ||
| 307 | NVolClearSparseEnabled(vol); | ||
| 308 | else { | ||
| 309 | if (!NVolSparseEnabled(vol) && | ||
| 310 | vol->major_ver && vol->major_ver < 3) | ||
| 311 | ntfs_warning(vol->sb, "Not enabling sparse " | ||
| 312 | "support due to NTFS volume " | ||
| 313 | "version %i.%i (need at least " | ||
| 314 | "version 3.0).", vol->major_ver, | ||
| 315 | vol->minor_ver); | ||
| 316 | else | ||
| 317 | NVolSetSparseEnabled(vol); | ||
| 318 | } | ||
| 319 | } | ||
| 294 | return TRUE; | 320 | return TRUE; |
| 295 | needs_arg: | 321 | needs_arg: |
| 296 | ntfs_error(vol->sb, "The %s option requires an argument.", p); | 322 | ntfs_error(vol->sb, "The %s option requires an argument.", p); |
| @@ -480,6 +506,12 @@ static int ntfs_remount(struct super_block *sb, int *flags, char *opt) | |||
| 480 | NVolSetErrors(vol); | 506 | NVolSetErrors(vol); |
| 481 | return -EROFS; | 507 | return -EROFS; |
| 482 | } | 508 | } |
| 509 | if (!ntfs_stamp_usnjrnl(vol)) { | ||
| 510 | ntfs_error(sb, "Failed to stamp transation log " | ||
| 511 | "($UsnJrnl)%s", es); | ||
| 512 | NVolSetErrors(vol); | ||
| 513 | return -EROFS; | ||
| 514 | } | ||
| 483 | } else if (!(sb->s_flags & MS_RDONLY) && (*flags & MS_RDONLY)) { | 515 | } else if (!(sb->s_flags & MS_RDONLY) && (*flags & MS_RDONLY)) { |
| 484 | /* Remounting read-only. */ | 516 | /* Remounting read-only. */ |
| 485 | if (!NVolErrors(vol)) { | 517 | if (!NVolErrors(vol)) { |
| @@ -516,16 +548,19 @@ static BOOL is_boot_sector_ntfs(const struct super_block *sb, | |||
| 516 | { | 548 | { |
| 517 | /* | 549 | /* |
| 518 | * Check that checksum == sum of u32 values from b to the checksum | 550 | * Check that checksum == sum of u32 values from b to the checksum |
| 519 | * field. If checksum is zero, no checking is done. | 551 | * field. If checksum is zero, no checking is done. We will work when |
| 552 | * the checksum test fails, since some utilities update the boot sector | ||
| 553 | * ignoring the checksum which leaves the checksum out-of-date. We | ||
| 554 | * report a warning if this is the case. | ||
| 520 | */ | 555 | */ |
| 521 | if ((void*)b < (void*)&b->checksum && b->checksum) { | 556 | if ((void*)b < (void*)&b->checksum && b->checksum && !silent) { |
| 522 | le32 *u; | 557 | le32 *u; |
| 523 | u32 i; | 558 | u32 i; |
| 524 | 559 | ||
| 525 | for (i = 0, u = (le32*)b; u < (le32*)(&b->checksum); ++u) | 560 | for (i = 0, u = (le32*)b; u < (le32*)(&b->checksum); ++u) |
| 526 | i += le32_to_cpup(u); | 561 | i += le32_to_cpup(u); |
| 527 | if (le32_to_cpu(b->checksum) != i) | 562 | if (le32_to_cpu(b->checksum) != i) |
| 528 | goto not_ntfs; | 563 | ntfs_warning(sb, "Invalid boot sector checksum."); |
| 529 | } | 564 | } |
| 530 | /* Check OEMidentifier is "NTFS " */ | 565 | /* Check OEMidentifier is "NTFS " */ |
| 531 | if (b->oem_id != magicNTFS) | 566 | if (b->oem_id != magicNTFS) |
| @@ -541,9 +576,9 @@ static BOOL is_boot_sector_ntfs(const struct super_block *sb, | |||
| 541 | default: | 576 | default: |
| 542 | goto not_ntfs; | 577 | goto not_ntfs; |
| 543 | } | 578 | } |
| 544 | /* Check the cluster size is not above 65536 bytes. */ | 579 | /* Check the cluster size is not above the maximum (64kiB). */ |
| 545 | if ((u32)le16_to_cpu(b->bpb.bytes_per_sector) * | 580 | if ((u32)le16_to_cpu(b->bpb.bytes_per_sector) * |
| 546 | b->bpb.sectors_per_cluster > 0x10000) | 581 | b->bpb.sectors_per_cluster > NTFS_MAX_CLUSTER_SIZE) |
| 547 | goto not_ntfs; | 582 | goto not_ntfs; |
| 548 | /* Check reserved/unused fields are really zero. */ | 583 | /* Check reserved/unused fields are really zero. */ |
| 549 | if (le16_to_cpu(b->bpb.reserved_sectors) || | 584 | if (le16_to_cpu(b->bpb.reserved_sectors) || |
| @@ -575,7 +610,7 @@ static BOOL is_boot_sector_ntfs(const struct super_block *sb, | |||
| 575 | * many BIOSes will refuse to boot from a bootsector if the magic is | 610 | * many BIOSes will refuse to boot from a bootsector if the magic is |
| 576 | * incorrect, so we emit a warning. | 611 | * incorrect, so we emit a warning. |
| 577 | */ | 612 | */ |
| 578 | if (!silent && b->end_of_sector_marker != cpu_to_le16(0xaa55)) | 613 | if (!silent && b->end_of_sector_marker != const_cpu_to_le16(0xaa55)) |
| 579 | ntfs_warning(sb, "Invalid end of sector marker."); | 614 | ntfs_warning(sb, "Invalid end of sector marker."); |
| 580 | return TRUE; | 615 | return TRUE; |
| 581 | not_ntfs: | 616 | not_ntfs: |
| @@ -967,6 +1002,7 @@ static BOOL load_and_init_mft_mirror(ntfs_volume *vol) | |||
| 967 | tmp_ni = NTFS_I(tmp_ino); | 1002 | tmp_ni = NTFS_I(tmp_ino); |
| 968 | /* The $MFTMirr, like the $MFT is multi sector transfer protected. */ | 1003 | /* The $MFTMirr, like the $MFT is multi sector transfer protected. */ |
| 969 | NInoSetMstProtected(tmp_ni); | 1004 | NInoSetMstProtected(tmp_ni); |
| 1005 | NInoSetSparseDisabled(tmp_ni); | ||
| 970 | /* | 1006 | /* |
| 971 | * Set up our little cheat allowing us to reuse the async read io | 1007 | * Set up our little cheat allowing us to reuse the async read io |
| 972 | * completion handler for directories. | 1008 | * completion handler for directories. |
| @@ -990,12 +1026,12 @@ static BOOL load_and_init_mft_mirror(ntfs_volume *vol) | |||
| 990 | */ | 1026 | */ |
| 991 | static BOOL check_mft_mirror(ntfs_volume *vol) | 1027 | static BOOL check_mft_mirror(ntfs_volume *vol) |
| 992 | { | 1028 | { |
| 993 | unsigned long index; | ||
| 994 | struct super_block *sb = vol->sb; | 1029 | struct super_block *sb = vol->sb; |
| 995 | ntfs_inode *mirr_ni; | 1030 | ntfs_inode *mirr_ni; |
| 996 | struct page *mft_page, *mirr_page; | 1031 | struct page *mft_page, *mirr_page; |
| 997 | u8 *kmft, *kmirr; | 1032 | u8 *kmft, *kmirr; |
| 998 | runlist_element *rl, rl2[2]; | 1033 | runlist_element *rl, rl2[2]; |
| 1034 | pgoff_t index; | ||
| 999 | int mrecs_per_page, i; | 1035 | int mrecs_per_page, i; |
| 1000 | 1036 | ||
| 1001 | ntfs_debug("Entering."); | 1037 | ntfs_debug("Entering."); |
| @@ -1105,7 +1141,8 @@ mft_unmap_out: | |||
| 1105 | * | 1141 | * |
| 1106 | * Return TRUE on success or FALSE on error. | 1142 | * Return TRUE on success or FALSE on error. |
| 1107 | */ | 1143 | */ |
| 1108 | static BOOL load_and_check_logfile(ntfs_volume *vol) | 1144 | static BOOL load_and_check_logfile(ntfs_volume *vol, |
| 1145 | RESTART_PAGE_HEADER **rp) | ||
| 1109 | { | 1146 | { |
| 1110 | struct inode *tmp_ino; | 1147 | struct inode *tmp_ino; |
| 1111 | 1148 | ||
| @@ -1117,16 +1154,135 @@ static BOOL load_and_check_logfile(ntfs_volume *vol) | |||
| 1117 | /* Caller will display error message. */ | 1154 | /* Caller will display error message. */ |
| 1118 | return FALSE; | 1155 | return FALSE; |
| 1119 | } | 1156 | } |
| 1120 | if (!ntfs_check_logfile(tmp_ino)) { | 1157 | if (!ntfs_check_logfile(tmp_ino, rp)) { |
| 1121 | iput(tmp_ino); | 1158 | iput(tmp_ino); |
| 1122 | /* ntfs_check_logfile() will have displayed error output. */ | 1159 | /* ntfs_check_logfile() will have displayed error output. */ |
| 1123 | return FALSE; | 1160 | return FALSE; |
| 1124 | } | 1161 | } |
| 1162 | NInoSetSparseDisabled(NTFS_I(tmp_ino)); | ||
| 1125 | vol->logfile_ino = tmp_ino; | 1163 | vol->logfile_ino = tmp_ino; |
| 1126 | ntfs_debug("Done."); | 1164 | ntfs_debug("Done."); |
| 1127 | return TRUE; | 1165 | return TRUE; |
| 1128 | } | 1166 | } |
| 1129 | 1167 | ||
| 1168 | #define NTFS_HIBERFIL_HEADER_SIZE 4096 | ||
| 1169 | |||
| 1170 | /** | ||
| 1171 | * check_windows_hibernation_status - check if Windows is suspended on a volume | ||
| 1172 | * @vol: ntfs super block of device to check | ||
| 1173 | * | ||
| 1174 | * Check if Windows is hibernated on the ntfs volume @vol. This is done by | ||
| 1175 | * looking for the file hiberfil.sys in the root directory of the volume. If | ||
| 1176 | * the file is not present Windows is definitely not suspended. | ||
| 1177 | * | ||
| 1178 | * If hiberfil.sys exists and is less than 4kiB in size it means Windows is | ||
| 1179 | * definitely suspended (this volume is not the system volume). Caveat: on a | ||
| 1180 | * system with many volumes it is possible that the < 4kiB check is bogus but | ||
| 1181 | * for now this should do fine. | ||
| 1182 | * | ||
| 1183 | * If hiberfil.sys exists and is larger than 4kiB in size, we need to read the | ||
| 1184 | * hiberfil header (which is the first 4kiB). If this begins with "hibr", | ||
| 1185 | * Windows is definitely suspended. If it is completely full of zeroes, | ||
| 1186 | * Windows is definitely not hibernated. Any other case is treated as if | ||
| 1187 | * Windows is suspended. This caters for the above mentioned caveat of a | ||
| 1188 | * system with many volumes where no "hibr" magic would be present and there is | ||
| 1189 | * no zero header. | ||
| 1190 | * | ||
| 1191 | * Return 0 if Windows is not hibernated on the volume, >0 if Windows is | ||
| 1192 | * hibernated on the volume, and -errno on error. | ||
| 1193 | */ | ||
| 1194 | static int check_windows_hibernation_status(ntfs_volume *vol) | ||
| 1195 | { | ||
| 1196 | MFT_REF mref; | ||
| 1197 | struct inode *vi; | ||
| 1198 | ntfs_inode *ni; | ||
| 1199 | struct page *page; | ||
| 1200 | u32 *kaddr, *kend; | ||
| 1201 | ntfs_name *name = NULL; | ||
| 1202 | int ret = 1; | ||
| 1203 | static const ntfschar hiberfil[13] = { const_cpu_to_le16('h'), | ||
| 1204 | const_cpu_to_le16('i'), const_cpu_to_le16('b'), | ||
| 1205 | const_cpu_to_le16('e'), const_cpu_to_le16('r'), | ||
| 1206 | const_cpu_to_le16('f'), const_cpu_to_le16('i'), | ||
| 1207 | const_cpu_to_le16('l'), const_cpu_to_le16('.'), | ||
| 1208 | const_cpu_to_le16('s'), const_cpu_to_le16('y'), | ||
| 1209 | const_cpu_to_le16('s'), 0 }; | ||
| 1210 | |||
| 1211 | ntfs_debug("Entering."); | ||
| 1212 | /* | ||
| 1213 | * Find the inode number for the hibernation file by looking up the | ||
| 1214 | * filename hiberfil.sys in the root directory. | ||
| 1215 | */ | ||
| 1216 | down(&vol->root_ino->i_sem); | ||
| 1217 | mref = ntfs_lookup_inode_by_name(NTFS_I(vol->root_ino), hiberfil, 12, | ||
| 1218 | &name); | ||
| 1219 | up(&vol->root_ino->i_sem); | ||
| 1220 | if (IS_ERR_MREF(mref)) { | ||
| 1221 | ret = MREF_ERR(mref); | ||
| 1222 | /* If the file does not exist, Windows is not hibernated. */ | ||
| 1223 | if (ret == -ENOENT) { | ||
| 1224 | ntfs_debug("hiberfil.sys not present. Windows is not " | ||
| 1225 | "hibernated on the volume."); | ||
| 1226 | return 0; | ||
| 1227 | } | ||
| 1228 | /* A real error occured. */ | ||
| 1229 | ntfs_error(vol->sb, "Failed to find inode number for " | ||
| 1230 | "hiberfil.sys."); | ||
| 1231 | return ret; | ||
| 1232 | } | ||
| 1233 | /* We do not care for the type of match that was found. */ | ||
| 1234 | kfree(name); | ||
| 1235 | /* Get the inode. */ | ||
| 1236 | vi = ntfs_iget(vol->sb, MREF(mref)); | ||
| 1237 | if (IS_ERR(vi) || is_bad_inode(vi)) { | ||
| 1238 | if (!IS_ERR(vi)) | ||
| 1239 | iput(vi); | ||
| 1240 | ntfs_error(vol->sb, "Failed to load hiberfil.sys."); | ||
| 1241 | return IS_ERR(vi) ? PTR_ERR(vi) : -EIO; | ||
| 1242 | } | ||
| 1243 | if (unlikely(i_size_read(vi) < NTFS_HIBERFIL_HEADER_SIZE)) { | ||
| 1244 | ntfs_debug("hiberfil.sys is smaller than 4kiB (0x%llx). " | ||
| 1245 | "Windows is hibernated on the volume. This " | ||
| 1246 | "is not the system volume.", i_size_read(vi)); | ||
| 1247 | goto iput_out; | ||
| 1248 | } | ||
| 1249 | ni = NTFS_I(vi); | ||
| 1250 | page = ntfs_map_page(vi->i_mapping, 0); | ||
| 1251 | if (IS_ERR(page)) { | ||
| 1252 | ntfs_error(vol->sb, "Failed to read from hiberfil.sys."); | ||
| 1253 | ret = PTR_ERR(page); | ||
| 1254 | goto iput_out; | ||
| 1255 | } | ||
| 1256 | kaddr = (u32*)page_address(page); | ||
| 1257 | if (*(le32*)kaddr == const_cpu_to_le32(0x72626968)/*'hibr'*/) { | ||
| 1258 | ntfs_debug("Magic \"hibr\" found in hiberfil.sys. Windows is " | ||
| 1259 | "hibernated on the volume. This is the " | ||
| 1260 | "system volume."); | ||
| 1261 | goto unm_iput_out; | ||
| 1262 | } | ||
| 1263 | kend = kaddr + NTFS_HIBERFIL_HEADER_SIZE/sizeof(*kaddr); | ||
| 1264 | do { | ||
| 1265 | if (unlikely(*kaddr)) { | ||
| 1266 | ntfs_debug("hiberfil.sys is larger than 4kiB " | ||
| 1267 | "(0x%llx), does not contain the " | ||
| 1268 | "\"hibr\" magic, and does not have a " | ||
| 1269 | "zero header. Windows is hibernated " | ||
| 1270 | "on the volume. This is not the " | ||
| 1271 | "system volume.", i_size_read(vi)); | ||
| 1272 | goto unm_iput_out; | ||
| 1273 | } | ||
| 1274 | } while (++kaddr < kend); | ||
| 1275 | ntfs_debug("hiberfil.sys contains a zero header. Windows is not " | ||
| 1276 | "hibernated on the volume. This is the system " | ||
| 1277 | "volume."); | ||
| 1278 | ret = 0; | ||
| 1279 | unm_iput_out: | ||
| 1280 | ntfs_unmap_page(page); | ||
| 1281 | iput_out: | ||
| 1282 | iput(vi); | ||
| 1283 | return ret; | ||
| 1284 | } | ||
| 1285 | |||
| 1130 | /** | 1286 | /** |
| 1131 | * load_and_init_quota - load and setup the quota file for a volume if present | 1287 | * load_and_init_quota - load and setup the quota file for a volume if present |
| 1132 | * @vol: ntfs super block describing device whose quota file to load | 1288 | * @vol: ntfs super block describing device whose quota file to load |
| @@ -1175,8 +1331,7 @@ static BOOL load_and_init_quota(ntfs_volume *vol) | |||
| 1175 | return FALSE; | 1331 | return FALSE; |
| 1176 | } | 1332 | } |
| 1177 | /* We do not care for the type of match that was found. */ | 1333 | /* We do not care for the type of match that was found. */ |
| 1178 | if (name) | 1334 | kfree(name); |
| 1179 | kfree(name); | ||
| 1180 | /* Get the inode. */ | 1335 | /* Get the inode. */ |
| 1181 | tmp_ino = ntfs_iget(vol->sb, MREF(mref)); | 1336 | tmp_ino = ntfs_iget(vol->sb, MREF(mref)); |
| 1182 | if (IS_ERR(tmp_ino) || is_bad_inode(tmp_ino)) { | 1337 | if (IS_ERR(tmp_ino) || is_bad_inode(tmp_ino)) { |
| @@ -1198,6 +1353,167 @@ static BOOL load_and_init_quota(ntfs_volume *vol) | |||
| 1198 | } | 1353 | } |
| 1199 | 1354 | ||
| 1200 | /** | 1355 | /** |
| 1356 | * load_and_init_usnjrnl - load and setup the transaction log if present | ||
| 1357 | * @vol: ntfs super block describing device whose usnjrnl file to load | ||
| 1358 | * | ||
| 1359 | * Return TRUE on success or FALSE on error. | ||
| 1360 | * | ||
| 1361 | * If $UsnJrnl is not present or in the process of being disabled, we set | ||
| 1362 | * NVolUsnJrnlStamped() and return success. | ||
| 1363 | * | ||
| 1364 | * If the $UsnJrnl $DATA/$J attribute has a size equal to the lowest valid usn, | ||
| 1365 | * i.e. transaction logging has only just been enabled or the journal has been | ||
| 1366 | * stamped and nothing has been logged since, we also set NVolUsnJrnlStamped() | ||
| 1367 | * and return success. | ||
| 1368 | */ | ||
| 1369 | static BOOL load_and_init_usnjrnl(ntfs_volume *vol) | ||
| 1370 | { | ||
| 1371 | MFT_REF mref; | ||
| 1372 | struct inode *tmp_ino; | ||
| 1373 | ntfs_inode *tmp_ni; | ||
| 1374 | struct page *page; | ||
| 1375 | ntfs_name *name = NULL; | ||
| 1376 | USN_HEADER *uh; | ||
| 1377 | static const ntfschar UsnJrnl[9] = { const_cpu_to_le16('$'), | ||
| 1378 | const_cpu_to_le16('U'), const_cpu_to_le16('s'), | ||
| 1379 | const_cpu_to_le16('n'), const_cpu_to_le16('J'), | ||
| 1380 | const_cpu_to_le16('r'), const_cpu_to_le16('n'), | ||
| 1381 | const_cpu_to_le16('l'), 0 }; | ||
| 1382 | static ntfschar Max[5] = { const_cpu_to_le16('$'), | ||
| 1383 | const_cpu_to_le16('M'), const_cpu_to_le16('a'), | ||
| 1384 | const_cpu_to_le16('x'), 0 }; | ||
| 1385 | static ntfschar J[3] = { const_cpu_to_le16('$'), | ||
| 1386 | const_cpu_to_le16('J'), 0 }; | ||
| 1387 | |||
| 1388 | ntfs_debug("Entering."); | ||
| 1389 | /* | ||
| 1390 | * Find the inode number for the transaction log file by looking up the | ||
| 1391 | * filename $UsnJrnl in the extended system files directory $Extend. | ||
| 1392 | */ | ||
| 1393 | down(&vol->extend_ino->i_sem); | ||
| 1394 | mref = ntfs_lookup_inode_by_name(NTFS_I(vol->extend_ino), UsnJrnl, 8, | ||
| 1395 | &name); | ||
| 1396 | up(&vol->extend_ino->i_sem); | ||
| 1397 | if (IS_ERR_MREF(mref)) { | ||
| 1398 | /* | ||
| 1399 | * If the file does not exist, transaction logging is disabled, | ||
| 1400 | * just return success. | ||
| 1401 | */ | ||
| 1402 | if (MREF_ERR(mref) == -ENOENT) { | ||
| 1403 | ntfs_debug("$UsnJrnl not present. Volume does not " | ||
| 1404 | "have transaction logging enabled."); | ||
| 1405 | not_enabled: | ||
| 1406 | /* | ||
| 1407 | * No need to try to stamp the transaction log if | ||
| 1408 | * transaction logging is not enabled. | ||
| 1409 | */ | ||
| 1410 | NVolSetUsnJrnlStamped(vol); | ||
| 1411 | return TRUE; | ||
| 1412 | } | ||
| 1413 | /* A real error occured. */ | ||
| 1414 | ntfs_error(vol->sb, "Failed to find inode number for " | ||
| 1415 | "$UsnJrnl."); | ||
| 1416 | return FALSE; | ||
| 1417 | } | ||
| 1418 | /* We do not care for the type of match that was found. */ | ||
| 1419 | kfree(name); | ||
| 1420 | /* Get the inode. */ | ||
| 1421 | tmp_ino = ntfs_iget(vol->sb, MREF(mref)); | ||
| 1422 | if (unlikely(IS_ERR(tmp_ino) || is_bad_inode(tmp_ino))) { | ||
| 1423 | if (!IS_ERR(tmp_ino)) | ||
| 1424 | iput(tmp_ino); | ||
| 1425 | ntfs_error(vol->sb, "Failed to load $UsnJrnl."); | ||
| 1426 | return FALSE; | ||
| 1427 | } | ||
| 1428 | vol->usnjrnl_ino = tmp_ino; | ||
| 1429 | /* | ||
| 1430 | * If the transaction log is in the process of being deleted, we can | ||
| 1431 | * ignore it. | ||
| 1432 | */ | ||
| 1433 | if (unlikely(vol->vol_flags & VOLUME_DELETE_USN_UNDERWAY)) { | ||
| 1434 | ntfs_debug("$UsnJrnl in the process of being disabled. " | ||
| 1435 | "Volume does not have transaction logging " | ||
| 1436 | "enabled."); | ||
| 1437 | goto not_enabled; | ||
| 1438 | } | ||
| 1439 | /* Get the $DATA/$Max attribute. */ | ||
| 1440 | tmp_ino = ntfs_attr_iget(vol->usnjrnl_ino, AT_DATA, Max, 4); | ||
| 1441 | if (IS_ERR(tmp_ino)) { | ||
| 1442 | ntfs_error(vol->sb, "Failed to load $UsnJrnl/$DATA/$Max " | ||
| 1443 | "attribute."); | ||
| 1444 | return FALSE; | ||
| 1445 | } | ||
| 1446 | vol->usnjrnl_max_ino = tmp_ino; | ||
| 1447 | if (unlikely(i_size_read(tmp_ino) < sizeof(USN_HEADER))) { | ||
| 1448 | ntfs_error(vol->sb, "Found corrupt $UsnJrnl/$DATA/$Max " | ||
| 1449 | "attribute (size is 0x%llx but should be at " | ||
| 1450 | "least 0x%x bytes).", i_size_read(tmp_ino), | ||
| 1451 | sizeof(USN_HEADER)); | ||
| 1452 | return FALSE; | ||
| 1453 | } | ||
| 1454 | /* Get the $DATA/$J attribute. */ | ||
| 1455 | tmp_ino = ntfs_attr_iget(vol->usnjrnl_ino, AT_DATA, J, 2); | ||
| 1456 | if (IS_ERR(tmp_ino)) { | ||
| 1457 | ntfs_error(vol->sb, "Failed to load $UsnJrnl/$DATA/$J " | ||
| 1458 | "attribute."); | ||
| 1459 | return FALSE; | ||
| 1460 | } | ||
| 1461 | vol->usnjrnl_j_ino = tmp_ino; | ||
| 1462 | /* Verify $J is non-resident and sparse. */ | ||
| 1463 | tmp_ni = NTFS_I(vol->usnjrnl_j_ino); | ||
| 1464 | if (unlikely(!NInoNonResident(tmp_ni) || !NInoSparse(tmp_ni))) { | ||
| 1465 | ntfs_error(vol->sb, "$UsnJrnl/$DATA/$J attribute is resident " | ||
| 1466 | "and/or not sparse."); | ||
| 1467 | return FALSE; | ||
| 1468 | } | ||
| 1469 | /* Read the USN_HEADER from $DATA/$Max. */ | ||
| 1470 | page = ntfs_map_page(vol->usnjrnl_max_ino->i_mapping, 0); | ||
| 1471 | if (IS_ERR(page)) { | ||
| 1472 | ntfs_error(vol->sb, "Failed to read from $UsnJrnl/$DATA/$Max " | ||
| 1473 | "attribute."); | ||
| 1474 | return FALSE; | ||
| 1475 | } | ||
| 1476 | uh = (USN_HEADER*)page_address(page); | ||
| 1477 | /* Sanity check the $Max. */ | ||
| 1478 | if (unlikely(sle64_to_cpu(uh->allocation_delta) > | ||
| 1479 | sle64_to_cpu(uh->maximum_size))) { | ||
| 1480 | ntfs_error(vol->sb, "Allocation delta (0x%llx) exceeds " | ||
| 1481 | "maximum size (0x%llx). $UsnJrnl is corrupt.", | ||
| 1482 | (long long)sle64_to_cpu(uh->allocation_delta), | ||
| 1483 | (long long)sle64_to_cpu(uh->maximum_size)); | ||
| 1484 | ntfs_unmap_page(page); | ||
| 1485 | return FALSE; | ||
| 1486 | } | ||
| 1487 | /* | ||
| 1488 | * If the transaction log has been stamped and nothing has been written | ||
| 1489 | * to it since, we do not need to stamp it. | ||
| 1490 | */ | ||
| 1491 | if (unlikely(sle64_to_cpu(uh->lowest_valid_usn) >= | ||
| 1492 | i_size_read(vol->usnjrnl_j_ino))) { | ||
| 1493 | if (likely(sle64_to_cpu(uh->lowest_valid_usn) == | ||
| 1494 | i_size_read(vol->usnjrnl_j_ino))) { | ||
| 1495 | ntfs_unmap_page(page); | ||
| 1496 | ntfs_debug("$UsnJrnl is enabled but nothing has been " | ||
| 1497 | "logged since it was last stamped. " | ||
| 1498 | "Treating this as if the volume does " | ||
| 1499 | "not have transaction logging " | ||
| 1500 | "enabled."); | ||
| 1501 | goto not_enabled; | ||
| 1502 | } | ||
| 1503 | ntfs_error(vol->sb, "$UsnJrnl has lowest valid usn (0x%llx) " | ||
| 1504 | "which is out of bounds (0x%llx). $UsnJrnl " | ||
| 1505 | "is corrupt.", | ||
| 1506 | (long long)sle64_to_cpu(uh->lowest_valid_usn), | ||
| 1507 | i_size_read(vol->usnjrnl_j_ino)); | ||
| 1508 | ntfs_unmap_page(page); | ||
| 1509 | return FALSE; | ||
| 1510 | } | ||
| 1511 | ntfs_unmap_page(page); | ||
| 1512 | ntfs_debug("Done."); | ||
| 1513 | return TRUE; | ||
| 1514 | } | ||
| 1515 | |||
| 1516 | /** | ||
| 1201 | * load_and_init_attrdef - load the attribute definitions table for a volume | 1517 | * load_and_init_attrdef - load the attribute definitions table for a volume |
| 1202 | * @vol: ntfs super block describing device whose attrdef to load | 1518 | * @vol: ntfs super block describing device whose attrdef to load |
| 1203 | * | 1519 | * |
| @@ -1205,10 +1521,11 @@ static BOOL load_and_init_quota(ntfs_volume *vol) | |||
| 1205 | */ | 1521 | */ |
| 1206 | static BOOL load_and_init_attrdef(ntfs_volume *vol) | 1522 | static BOOL load_and_init_attrdef(ntfs_volume *vol) |
| 1207 | { | 1523 | { |
| 1524 | loff_t i_size; | ||
| 1208 | struct super_block *sb = vol->sb; | 1525 | struct super_block *sb = vol->sb; |
| 1209 | struct inode *ino; | 1526 | struct inode *ino; |
| 1210 | struct page *page; | 1527 | struct page *page; |
| 1211 | unsigned long index, max_index; | 1528 | pgoff_t index, max_index; |
| 1212 | unsigned int size; | 1529 | unsigned int size; |
| 1213 | 1530 | ||
| 1214 | ntfs_debug("Entering."); | 1531 | ntfs_debug("Entering."); |
| @@ -1219,14 +1536,16 @@ static BOOL load_and_init_attrdef(ntfs_volume *vol) | |||
| 1219 | iput(ino); | 1536 | iput(ino); |
| 1220 | goto failed; | 1537 | goto failed; |
| 1221 | } | 1538 | } |
| 1539 | NInoSetSparseDisabled(NTFS_I(ino)); | ||
| 1222 | /* The size of FILE_AttrDef must be above 0 and fit inside 31 bits. */ | 1540 | /* The size of FILE_AttrDef must be above 0 and fit inside 31 bits. */ |
| 1223 | if (!ino->i_size || ino->i_size > 0x7fffffff) | 1541 | i_size = i_size_read(ino); |
| 1542 | if (i_size <= 0 || i_size > 0x7fffffff) | ||
| 1224 | goto iput_failed; | 1543 | goto iput_failed; |
| 1225 | vol->attrdef = (ATTR_DEF*)ntfs_malloc_nofs(ino->i_size); | 1544 | vol->attrdef = (ATTR_DEF*)ntfs_malloc_nofs(i_size); |
| 1226 | if (!vol->attrdef) | 1545 | if (!vol->attrdef) |
| 1227 | goto iput_failed; | 1546 | goto iput_failed; |
| 1228 | index = 0; | 1547 | index = 0; |
| 1229 | max_index = ino->i_size >> PAGE_CACHE_SHIFT; | 1548 | max_index = i_size >> PAGE_CACHE_SHIFT; |
| 1230 | size = PAGE_CACHE_SIZE; | 1549 | size = PAGE_CACHE_SIZE; |
| 1231 | while (index < max_index) { | 1550 | while (index < max_index) { |
| 1232 | /* Read the attrdef table and copy it into the linear buffer. */ | 1551 | /* Read the attrdef table and copy it into the linear buffer. */ |
| @@ -1239,12 +1558,12 @@ read_partial_attrdef_page: | |||
| 1239 | ntfs_unmap_page(page); | 1558 | ntfs_unmap_page(page); |
| 1240 | }; | 1559 | }; |
| 1241 | if (size == PAGE_CACHE_SIZE) { | 1560 | if (size == PAGE_CACHE_SIZE) { |
| 1242 | size = ino->i_size & ~PAGE_CACHE_MASK; | 1561 | size = i_size & ~PAGE_CACHE_MASK; |
| 1243 | if (size) | 1562 | if (size) |
| 1244 | goto read_partial_attrdef_page; | 1563 | goto read_partial_attrdef_page; |
| 1245 | } | 1564 | } |
| 1246 | vol->attrdef_size = ino->i_size; | 1565 | vol->attrdef_size = i_size; |
| 1247 | ntfs_debug("Read %llu bytes from $AttrDef.", ino->i_size); | 1566 | ntfs_debug("Read %llu bytes from $AttrDef.", i_size); |
| 1248 | iput(ino); | 1567 | iput(ino); |
| 1249 | return TRUE; | 1568 | return TRUE; |
| 1250 | free_iput_failed: | 1569 | free_iput_failed: |
| @@ -1267,10 +1586,11 @@ failed: | |||
| 1267 | */ | 1586 | */ |
| 1268 | static BOOL load_and_init_upcase(ntfs_volume *vol) | 1587 | static BOOL load_and_init_upcase(ntfs_volume *vol) |
| 1269 | { | 1588 | { |
| 1589 | loff_t i_size; | ||
| 1270 | struct super_block *sb = vol->sb; | 1590 | struct super_block *sb = vol->sb; |
| 1271 | struct inode *ino; | 1591 | struct inode *ino; |
| 1272 | struct page *page; | 1592 | struct page *page; |
| 1273 | unsigned long index, max_index; | 1593 | pgoff_t index, max_index; |
| 1274 | unsigned int size; | 1594 | unsigned int size; |
| 1275 | int i, max; | 1595 | int i, max; |
| 1276 | 1596 | ||
| @@ -1286,14 +1606,15 @@ static BOOL load_and_init_upcase(ntfs_volume *vol) | |||
| 1286 | * The upcase size must not be above 64k Unicode characters, must not | 1606 | * The upcase size must not be above 64k Unicode characters, must not |
| 1287 | * be zero and must be a multiple of sizeof(ntfschar). | 1607 | * be zero and must be a multiple of sizeof(ntfschar). |
| 1288 | */ | 1608 | */ |
| 1289 | if (!ino->i_size || ino->i_size & (sizeof(ntfschar) - 1) || | 1609 | i_size = i_size_read(ino); |
| 1290 | ino->i_size > 64ULL * 1024 * sizeof(ntfschar)) | 1610 | if (!i_size || i_size & (sizeof(ntfschar) - 1) || |
| 1611 | i_size > 64ULL * 1024 * sizeof(ntfschar)) | ||
| 1291 | goto iput_upcase_failed; | 1612 | goto iput_upcase_failed; |
| 1292 | vol->upcase = (ntfschar*)ntfs_malloc_nofs(ino->i_size); | 1613 | vol->upcase = (ntfschar*)ntfs_malloc_nofs(i_size); |
| 1293 | if (!vol->upcase) | 1614 | if (!vol->upcase) |
| 1294 | goto iput_upcase_failed; | 1615 | goto iput_upcase_failed; |
| 1295 | index = 0; | 1616 | index = 0; |
| 1296 | max_index = ino->i_size >> PAGE_CACHE_SHIFT; | 1617 | max_index = i_size >> PAGE_CACHE_SHIFT; |
| 1297 | size = PAGE_CACHE_SIZE; | 1618 | size = PAGE_CACHE_SIZE; |
| 1298 | while (index < max_index) { | 1619 | while (index < max_index) { |
| 1299 | /* Read the upcase table and copy it into the linear buffer. */ | 1620 | /* Read the upcase table and copy it into the linear buffer. */ |
| @@ -1306,13 +1627,13 @@ read_partial_upcase_page: | |||
| 1306 | ntfs_unmap_page(page); | 1627 | ntfs_unmap_page(page); |
| 1307 | }; | 1628 | }; |
| 1308 | if (size == PAGE_CACHE_SIZE) { | 1629 | if (size == PAGE_CACHE_SIZE) { |
| 1309 | size = ino->i_size & ~PAGE_CACHE_MASK; | 1630 | size = i_size & ~PAGE_CACHE_MASK; |
| 1310 | if (size) | 1631 | if (size) |
| 1311 | goto read_partial_upcase_page; | 1632 | goto read_partial_upcase_page; |
| 1312 | } | 1633 | } |
| 1313 | vol->upcase_len = ino->i_size >> UCHAR_T_SIZE_BITS; | 1634 | vol->upcase_len = i_size >> UCHAR_T_SIZE_BITS; |
| 1314 | ntfs_debug("Read %llu bytes from $UpCase (expected %zu bytes).", | 1635 | ntfs_debug("Read %llu bytes from $UpCase (expected %zu bytes).", |
| 1315 | ino->i_size, 64 * 1024 * sizeof(ntfschar)); | 1636 | i_size, 64 * 1024 * sizeof(ntfschar)); |
| 1316 | iput(ino); | 1637 | iput(ino); |
| 1317 | down(&ntfs_lock); | 1638 | down(&ntfs_lock); |
| 1318 | if (!default_upcase) { | 1639 | if (!default_upcase) { |
| @@ -1376,6 +1697,10 @@ static BOOL load_system_files(ntfs_volume *vol) | |||
| 1376 | MFT_RECORD *m; | 1697 | MFT_RECORD *m; |
| 1377 | VOLUME_INFORMATION *vi; | 1698 | VOLUME_INFORMATION *vi; |
| 1378 | ntfs_attr_search_ctx *ctx; | 1699 | ntfs_attr_search_ctx *ctx; |
| 1700 | #ifdef NTFS_RW | ||
| 1701 | RESTART_PAGE_HEADER *rp; | ||
| 1702 | int err; | ||
| 1703 | #endif /* NTFS_RW */ | ||
| 1379 | 1704 | ||
| 1380 | ntfs_debug("Entering."); | 1705 | ntfs_debug("Entering."); |
| 1381 | #ifdef NTFS_RW | 1706 | #ifdef NTFS_RW |
| @@ -1435,7 +1760,8 @@ static BOOL load_system_files(ntfs_volume *vol) | |||
| 1435 | iput(vol->lcnbmp_ino); | 1760 | iput(vol->lcnbmp_ino); |
| 1436 | goto bitmap_failed; | 1761 | goto bitmap_failed; |
| 1437 | } | 1762 | } |
| 1438 | if ((vol->nr_clusters + 7) >> 3 > vol->lcnbmp_ino->i_size) { | 1763 | NInoSetSparseDisabled(NTFS_I(vol->lcnbmp_ino)); |
| 1764 | if ((vol->nr_clusters + 7) >> 3 > i_size_read(vol->lcnbmp_ino)) { | ||
| 1439 | iput(vol->lcnbmp_ino); | 1765 | iput(vol->lcnbmp_ino); |
| 1440 | bitmap_failed: | 1766 | bitmap_failed: |
| 1441 | ntfs_error(sb, "Failed to load $Bitmap."); | 1767 | ntfs_error(sb, "Failed to load $Bitmap."); |
| @@ -1486,6 +1812,12 @@ get_ctx_vol_failed: | |||
| 1486 | unmap_mft_record(NTFS_I(vol->vol_ino)); | 1812 | unmap_mft_record(NTFS_I(vol->vol_ino)); |
| 1487 | printk(KERN_INFO "NTFS volume version %i.%i.\n", vol->major_ver, | 1813 | printk(KERN_INFO "NTFS volume version %i.%i.\n", vol->major_ver, |
| 1488 | vol->minor_ver); | 1814 | vol->minor_ver); |
| 1815 | if (vol->major_ver < 3 && NVolSparseEnabled(vol)) { | ||
| 1816 | ntfs_warning(vol->sb, "Disabling sparse support due to NTFS " | ||
| 1817 | "volume version %i.%i (need at least version " | ||
| 1818 | "3.0).", vol->major_ver, vol->minor_ver); | ||
| 1819 | NVolClearSparseEnabled(vol); | ||
| 1820 | } | ||
| 1489 | #ifdef NTFS_RW | 1821 | #ifdef NTFS_RW |
| 1490 | /* Make sure that no unsupported volume flags are set. */ | 1822 | /* Make sure that no unsupported volume flags are set. */ |
| 1491 | if (vol->vol_flags & VOLUME_MUST_MOUNT_RO_MASK) { | 1823 | if (vol->vol_flags & VOLUME_MUST_MOUNT_RO_MASK) { |
| @@ -1519,8 +1851,9 @@ get_ctx_vol_failed: | |||
| 1519 | * Get the inode for the logfile, check it and determine if the volume | 1851 | * Get the inode for the logfile, check it and determine if the volume |
| 1520 | * was shutdown cleanly. | 1852 | * was shutdown cleanly. |
| 1521 | */ | 1853 | */ |
| 1522 | if (!load_and_check_logfile(vol) || | 1854 | rp = NULL; |
| 1523 | !ntfs_is_logfile_clean(vol->logfile_ino)) { | 1855 | if (!load_and_check_logfile(vol, &rp) || |
| 1856 | !ntfs_is_logfile_clean(vol->logfile_ino, rp)) { | ||
| 1524 | static const char *es1a = "Failed to load $LogFile"; | 1857 | static const char *es1a = "Failed to load $LogFile"; |
| 1525 | static const char *es1b = "$LogFile is not clean"; | 1858 | static const char *es1b = "$LogFile is not clean"; |
| 1526 | static const char *es2 = ". Mount in Windows."; | 1859 | static const char *es2 = ". Mount in Windows."; |
| @@ -1535,6 +1868,10 @@ get_ctx_vol_failed: | |||
| 1535 | "continue nor on_errors=" | 1868 | "continue nor on_errors=" |
| 1536 | "remount-ro was specified%s", | 1869 | "remount-ro was specified%s", |
| 1537 | es1, es2); | 1870 | es1, es2); |
| 1871 | if (vol->logfile_ino) { | ||
| 1872 | BUG_ON(!rp); | ||
| 1873 | ntfs_free(rp); | ||
| 1874 | } | ||
| 1538 | goto iput_logfile_err_out; | 1875 | goto iput_logfile_err_out; |
| 1539 | } | 1876 | } |
| 1540 | sb->s_flags |= MS_RDONLY | MS_NOATIME | MS_NODIRATIME; | 1877 | sb->s_flags |= MS_RDONLY | MS_NOATIME | MS_NODIRATIME; |
| @@ -1545,6 +1882,51 @@ get_ctx_vol_failed: | |||
| 1545 | /* This will prevent a read-write remount. */ | 1882 | /* This will prevent a read-write remount. */ |
| 1546 | NVolSetErrors(vol); | 1883 | NVolSetErrors(vol); |
| 1547 | } | 1884 | } |
| 1885 | ntfs_free(rp); | ||
| 1886 | #endif /* NTFS_RW */ | ||
| 1887 | /* Get the root directory inode so we can do path lookups. */ | ||
| 1888 | vol->root_ino = ntfs_iget(sb, FILE_root); | ||
| 1889 | if (IS_ERR(vol->root_ino) || is_bad_inode(vol->root_ino)) { | ||
| 1890 | if (!IS_ERR(vol->root_ino)) | ||
| 1891 | iput(vol->root_ino); | ||
| 1892 | ntfs_error(sb, "Failed to load root directory."); | ||
| 1893 | goto iput_logfile_err_out; | ||
| 1894 | } | ||
| 1895 | #ifdef NTFS_RW | ||
| 1896 | /* | ||
| 1897 | * Check if Windows is suspended to disk on the target volume. If it | ||
| 1898 | * is hibernated, we must not write *anything* to the disk so set | ||
| 1899 | * NVolErrors() without setting the dirty volume flag and mount | ||
| 1900 | * read-only. This will prevent read-write remounting and it will also | ||
| 1901 | * prevent all writes. | ||
| 1902 | */ | ||
| 1903 | err = check_windows_hibernation_status(vol); | ||
| 1904 | if (unlikely(err)) { | ||
| 1905 | static const char *es1a = "Failed to determine if Windows is " | ||
| 1906 | "hibernated"; | ||
| 1907 | static const char *es1b = "Windows is hibernated"; | ||
| 1908 | static const char *es2 = ". Run chkdsk."; | ||
| 1909 | const char *es1; | ||
| 1910 | |||
| 1911 | es1 = err < 0 ? es1a : es1b; | ||
| 1912 | /* If a read-write mount, convert it to a read-only mount. */ | ||
| 1913 | if (!(sb->s_flags & MS_RDONLY)) { | ||
| 1914 | if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO | | ||
| 1915 | ON_ERRORS_CONTINUE))) { | ||
| 1916 | ntfs_error(sb, "%s and neither on_errors=" | ||
| 1917 | "continue nor on_errors=" | ||
| 1918 | "remount-ro was specified%s", | ||
| 1919 | es1, es2); | ||
| 1920 | goto iput_root_err_out; | ||
| 1921 | } | ||
| 1922 | sb->s_flags |= MS_RDONLY | MS_NOATIME | MS_NODIRATIME; | ||
| 1923 | ntfs_error(sb, "%s. Mounting read-only%s", es1, es2); | ||
| 1924 | } else | ||
| 1925 | ntfs_warning(sb, "%s. Will not be able to remount " | ||
| 1926 | "read-write%s", es1, es2); | ||
| 1927 | /* This will prevent a read-write remount. */ | ||
| 1928 | NVolSetErrors(vol); | ||
| 1929 | } | ||
| 1548 | /* If (still) a read-write mount, mark the volume dirty. */ | 1930 | /* If (still) a read-write mount, mark the volume dirty. */ |
| 1549 | if (!(sb->s_flags & MS_RDONLY) && | 1931 | if (!(sb->s_flags & MS_RDONLY) && |
| 1550 | ntfs_set_volume_flags(vol, VOLUME_IS_DIRTY)) { | 1932 | ntfs_set_volume_flags(vol, VOLUME_IS_DIRTY)) { |
| @@ -1558,7 +1940,7 @@ get_ctx_vol_failed: | |||
| 1558 | ntfs_error(sb, "%s and neither on_errors=continue nor " | 1940 | ntfs_error(sb, "%s and neither on_errors=continue nor " |
| 1559 | "on_errors=remount-ro was specified%s", | 1941 | "on_errors=remount-ro was specified%s", |
| 1560 | es1, es2); | 1942 | es1, es2); |
| 1561 | goto iput_logfile_err_out; | 1943 | goto iput_root_err_out; |
| 1562 | } | 1944 | } |
| 1563 | ntfs_error(sb, "%s. Mounting read-only%s", es1, es2); | 1945 | ntfs_error(sb, "%s. Mounting read-only%s", es1, es2); |
| 1564 | sb->s_flags |= MS_RDONLY | MS_NOATIME | MS_NODIRATIME; | 1946 | sb->s_flags |= MS_RDONLY | MS_NOATIME | MS_NODIRATIME; |
| @@ -1585,7 +1967,7 @@ get_ctx_vol_failed: | |||
| 1585 | ntfs_error(sb, "%s and neither on_errors=continue nor " | 1967 | ntfs_error(sb, "%s and neither on_errors=continue nor " |
| 1586 | "on_errors=remount-ro was specified%s", | 1968 | "on_errors=remount-ro was specified%s", |
| 1587 | es1, es2); | 1969 | es1, es2); |
| 1588 | goto iput_logfile_err_out; | 1970 | goto iput_root_err_out; |
| 1589 | } | 1971 | } |
| 1590 | ntfs_error(sb, "%s. Mounting read-only%s", es1, es2); | 1972 | ntfs_error(sb, "%s. Mounting read-only%s", es1, es2); |
| 1591 | sb->s_flags |= MS_RDONLY | MS_NOATIME | MS_NODIRATIME; | 1973 | sb->s_flags |= MS_RDONLY | MS_NOATIME | MS_NODIRATIME; |
| @@ -1604,23 +1986,15 @@ get_ctx_vol_failed: | |||
| 1604 | ntfs_error(sb, "%s and neither on_errors=continue nor " | 1986 | ntfs_error(sb, "%s and neither on_errors=continue nor " |
| 1605 | "on_errors=remount-ro was specified%s", | 1987 | "on_errors=remount-ro was specified%s", |
| 1606 | es1, es2); | 1988 | es1, es2); |
| 1607 | goto iput_logfile_err_out; | 1989 | goto iput_root_err_out; |
| 1608 | } | 1990 | } |
| 1609 | ntfs_error(sb, "%s. Mounting read-only%s", es1, es2); | 1991 | ntfs_error(sb, "%s. Mounting read-only%s", es1, es2); |
| 1610 | sb->s_flags |= MS_RDONLY | MS_NOATIME | MS_NODIRATIME; | 1992 | sb->s_flags |= MS_RDONLY | MS_NOATIME | MS_NODIRATIME; |
| 1611 | NVolSetErrors(vol); | 1993 | NVolSetErrors(vol); |
| 1612 | } | 1994 | } |
| 1613 | #endif /* NTFS_RW */ | 1995 | #endif /* NTFS_RW */ |
| 1614 | /* Get the root directory inode. */ | ||
| 1615 | vol->root_ino = ntfs_iget(sb, FILE_root); | ||
| 1616 | if (IS_ERR(vol->root_ino) || is_bad_inode(vol->root_ino)) { | ||
| 1617 | if (!IS_ERR(vol->root_ino)) | ||
| 1618 | iput(vol->root_ino); | ||
| 1619 | ntfs_error(sb, "Failed to load root directory."); | ||
| 1620 | goto iput_logfile_err_out; | ||
| 1621 | } | ||
| 1622 | /* If on NTFS versions before 3.0, we are done. */ | 1996 | /* If on NTFS versions before 3.0, we are done. */ |
| 1623 | if (vol->major_ver < 3) | 1997 | if (unlikely(vol->major_ver < 3)) |
| 1624 | return TRUE; | 1998 | return TRUE; |
| 1625 | /* NTFS 3.0+ specific initialization. */ | 1999 | /* NTFS 3.0+ specific initialization. */ |
| 1626 | /* Get the security descriptors inode. */ | 2000 | /* Get the security descriptors inode. */ |
| @@ -1631,7 +2005,7 @@ get_ctx_vol_failed: | |||
| 1631 | ntfs_error(sb, "Failed to load $Secure."); | 2005 | ntfs_error(sb, "Failed to load $Secure."); |
| 1632 | goto iput_root_err_out; | 2006 | goto iput_root_err_out; |
| 1633 | } | 2007 | } |
| 1634 | // FIXME: Initialize security. | 2008 | // TODO: Initialize security. |
| 1635 | /* Get the extended system files' directory inode. */ | 2009 | /* Get the extended system files' directory inode. */ |
| 1636 | vol->extend_ino = ntfs_iget(sb, FILE_Extend); | 2010 | vol->extend_ino = ntfs_iget(sb, FILE_Extend); |
| 1637 | if (IS_ERR(vol->extend_ino) || is_bad_inode(vol->extend_ino)) { | 2011 | if (IS_ERR(vol->extend_ino) || is_bad_inode(vol->extend_ino)) { |
| @@ -1682,10 +2056,60 @@ get_ctx_vol_failed: | |||
| 1682 | sb->s_flags |= MS_RDONLY | MS_NOATIME | MS_NODIRATIME; | 2056 | sb->s_flags |= MS_RDONLY | MS_NOATIME | MS_NODIRATIME; |
| 1683 | NVolSetErrors(vol); | 2057 | NVolSetErrors(vol); |
| 1684 | } | 2058 | } |
| 1685 | // TODO: Delete or checkpoint the $UsnJrnl if it exists. | 2059 | /* |
| 2060 | * Find the transaction log file ($UsnJrnl), load it if present, check | ||
| 2061 | * it, and set it up. | ||
| 2062 | */ | ||
| 2063 | if (!load_and_init_usnjrnl(vol)) { | ||
| 2064 | static const char *es1 = "Failed to load $UsnJrnl"; | ||
| 2065 | static const char *es2 = ". Run chkdsk."; | ||
| 2066 | |||
| 2067 | /* If a read-write mount, convert it to a read-only mount. */ | ||
| 2068 | if (!(sb->s_flags & MS_RDONLY)) { | ||
| 2069 | if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO | | ||
| 2070 | ON_ERRORS_CONTINUE))) { | ||
| 2071 | ntfs_error(sb, "%s and neither on_errors=" | ||
| 2072 | "continue nor on_errors=" | ||
| 2073 | "remount-ro was specified%s", | ||
| 2074 | es1, es2); | ||
| 2075 | goto iput_usnjrnl_err_out; | ||
| 2076 | } | ||
| 2077 | sb->s_flags |= MS_RDONLY | MS_NOATIME | MS_NODIRATIME; | ||
| 2078 | ntfs_error(sb, "%s. Mounting read-only%s", es1, es2); | ||
| 2079 | } else | ||
| 2080 | ntfs_warning(sb, "%s. Will not be able to remount " | ||
| 2081 | "read-write%s", es1, es2); | ||
| 2082 | /* This will prevent a read-write remount. */ | ||
| 2083 | NVolSetErrors(vol); | ||
| 2084 | } | ||
| 2085 | /* If (still) a read-write mount, stamp the transaction log. */ | ||
| 2086 | if (!(sb->s_flags & MS_RDONLY) && !ntfs_stamp_usnjrnl(vol)) { | ||
| 2087 | static const char *es1 = "Failed to stamp transaction log " | ||
| 2088 | "($UsnJrnl)"; | ||
| 2089 | static const char *es2 = ". Run chkdsk."; | ||
| 2090 | |||
| 2091 | /* Convert to a read-only mount. */ | ||
| 2092 | if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO | | ||
| 2093 | ON_ERRORS_CONTINUE))) { | ||
| 2094 | ntfs_error(sb, "%s and neither on_errors=continue nor " | ||
| 2095 | "on_errors=remount-ro was specified%s", | ||
| 2096 | es1, es2); | ||
| 2097 | goto iput_usnjrnl_err_out; | ||
| 2098 | } | ||
| 2099 | ntfs_error(sb, "%s. Mounting read-only%s", es1, es2); | ||
| 2100 | sb->s_flags |= MS_RDONLY | MS_NOATIME | MS_NODIRATIME; | ||
| 2101 | NVolSetErrors(vol); | ||
| 2102 | } | ||
| 1686 | #endif /* NTFS_RW */ | 2103 | #endif /* NTFS_RW */ |
| 1687 | return TRUE; | 2104 | return TRUE; |
| 1688 | #ifdef NTFS_RW | 2105 | #ifdef NTFS_RW |
| 2106 | iput_usnjrnl_err_out: | ||
| 2107 | if (vol->usnjrnl_j_ino) | ||
| 2108 | iput(vol->usnjrnl_j_ino); | ||
| 2109 | if (vol->usnjrnl_max_ino) | ||
| 2110 | iput(vol->usnjrnl_max_ino); | ||
| 2111 | if (vol->usnjrnl_ino) | ||
| 2112 | iput(vol->usnjrnl_ino); | ||
| 1689 | iput_quota_err_out: | 2113 | iput_quota_err_out: |
| 1690 | if (vol->quota_q_ino) | 2114 | if (vol->quota_q_ino) |
| 1691 | iput(vol->quota_q_ino); | 2115 | iput(vol->quota_q_ino); |
| @@ -1759,6 +2183,12 @@ static void ntfs_put_super(struct super_block *sb) | |||
| 1759 | 2183 | ||
| 1760 | /* NTFS 3.0+ specific. */ | 2184 | /* NTFS 3.0+ specific. */ |
| 1761 | if (vol->major_ver >= 3) { | 2185 | if (vol->major_ver >= 3) { |
| 2186 | if (vol->usnjrnl_j_ino) | ||
| 2187 | ntfs_commit_inode(vol->usnjrnl_j_ino); | ||
| 2188 | if (vol->usnjrnl_max_ino) | ||
| 2189 | ntfs_commit_inode(vol->usnjrnl_max_ino); | ||
| 2190 | if (vol->usnjrnl_ino) | ||
| 2191 | ntfs_commit_inode(vol->usnjrnl_ino); | ||
| 1762 | if (vol->quota_q_ino) | 2192 | if (vol->quota_q_ino) |
| 1763 | ntfs_commit_inode(vol->quota_q_ino); | 2193 | ntfs_commit_inode(vol->quota_q_ino); |
| 1764 | if (vol->quota_ino) | 2194 | if (vol->quota_ino) |
| @@ -1814,6 +2244,18 @@ static void ntfs_put_super(struct super_block *sb) | |||
| 1814 | /* NTFS 3.0+ specific clean up. */ | 2244 | /* NTFS 3.0+ specific clean up. */ |
| 1815 | if (vol->major_ver >= 3) { | 2245 | if (vol->major_ver >= 3) { |
| 1816 | #ifdef NTFS_RW | 2246 | #ifdef NTFS_RW |
| 2247 | if (vol->usnjrnl_j_ino) { | ||
| 2248 | iput(vol->usnjrnl_j_ino); | ||
| 2249 | vol->usnjrnl_j_ino = NULL; | ||
| 2250 | } | ||
| 2251 | if (vol->usnjrnl_max_ino) { | ||
| 2252 | iput(vol->usnjrnl_max_ino); | ||
| 2253 | vol->usnjrnl_max_ino = NULL; | ||
| 2254 | } | ||
| 2255 | if (vol->usnjrnl_ino) { | ||
| 2256 | iput(vol->usnjrnl_ino); | ||
| 2257 | vol->usnjrnl_ino = NULL; | ||
| 2258 | } | ||
| 1817 | if (vol->quota_q_ino) { | 2259 | if (vol->quota_q_ino) { |
| 1818 | iput(vol->quota_q_ino); | 2260 | iput(vol->quota_q_ino); |
| 1819 | vol->quota_q_ino = NULL; | 2261 | vol->quota_q_ino = NULL; |
| @@ -1959,8 +2401,7 @@ static s64 get_nr_free_clusters(ntfs_volume *vol) | |||
| 1959 | struct address_space *mapping = vol->lcnbmp_ino->i_mapping; | 2401 | struct address_space *mapping = vol->lcnbmp_ino->i_mapping; |
| 1960 | filler_t *readpage = (filler_t*)mapping->a_ops->readpage; | 2402 | filler_t *readpage = (filler_t*)mapping->a_ops->readpage; |
| 1961 | struct page *page; | 2403 | struct page *page; |
| 1962 | unsigned long index, max_index; | 2404 | pgoff_t index, max_index; |
| 1963 | unsigned int max_size; | ||
| 1964 | 2405 | ||
| 1965 | ntfs_debug("Entering."); | 2406 | ntfs_debug("Entering."); |
| 1966 | /* Serialize accesses to the cluster bitmap. */ | 2407 | /* Serialize accesses to the cluster bitmap. */ |
| @@ -1972,11 +2413,10 @@ static s64 get_nr_free_clusters(ntfs_volume *vol) | |||
| 1972 | */ | 2413 | */ |
| 1973 | max_index = (((vol->nr_clusters + 7) >> 3) + PAGE_CACHE_SIZE - 1) >> | 2414 | max_index = (((vol->nr_clusters + 7) >> 3) + PAGE_CACHE_SIZE - 1) >> |
| 1974 | PAGE_CACHE_SHIFT; | 2415 | PAGE_CACHE_SHIFT; |
| 1975 | /* Use multiples of 4 bytes. */ | 2416 | /* Use multiples of 4 bytes, thus max_size is PAGE_CACHE_SIZE / 4. */ |
| 1976 | max_size = PAGE_CACHE_SIZE >> 2; | 2417 | ntfs_debug("Reading $Bitmap, max_index = 0x%lx, max_size = 0x%lx.", |
| 1977 | ntfs_debug("Reading $Bitmap, max_index = 0x%lx, max_size = 0x%x.", | 2418 | max_index, PAGE_CACHE_SIZE / 4); |
| 1978 | max_index, max_size); | 2419 | for (index = 0; index < max_index; index++) { |
| 1979 | for (index = 0UL; index < max_index; index++) { | ||
| 1980 | unsigned int i; | 2420 | unsigned int i; |
| 1981 | /* | 2421 | /* |
| 1982 | * Read the page from page cache, getting it from backing store | 2422 | * Read the page from page cache, getting it from backing store |
| @@ -2008,7 +2448,7 @@ static s64 get_nr_free_clusters(ntfs_volume *vol) | |||
| 2008 | * the result as all out of range bytes are set to zero by | 2448 | * the result as all out of range bytes are set to zero by |
| 2009 | * ntfs_readpage(). | 2449 | * ntfs_readpage(). |
| 2010 | */ | 2450 | */ |
| 2011 | for (i = 0; i < max_size; i++) | 2451 | for (i = 0; i < PAGE_CACHE_SIZE / 4; i++) |
| 2012 | nr_free -= (s64)hweight32(kaddr[i]); | 2452 | nr_free -= (s64)hweight32(kaddr[i]); |
| 2013 | kunmap_atomic(kaddr, KM_USER0); | 2453 | kunmap_atomic(kaddr, KM_USER0); |
| 2014 | page_cache_release(page); | 2454 | page_cache_release(page); |
| @@ -2031,6 +2471,8 @@ static s64 get_nr_free_clusters(ntfs_volume *vol) | |||
| 2031 | /** | 2471 | /** |
| 2032 | * __get_nr_free_mft_records - return the number of free inodes on a volume | 2472 | * __get_nr_free_mft_records - return the number of free inodes on a volume |
| 2033 | * @vol: ntfs volume for which to obtain free inode count | 2473 | * @vol: ntfs volume for which to obtain free inode count |
| 2474 | * @nr_free: number of mft records in filesystem | ||
| 2475 | * @max_index: maximum number of pages containing set bits | ||
| 2034 | * | 2476 | * |
| 2035 | * Calculate the number of free mft records (inodes) on the mounted NTFS | 2477 | * Calculate the number of free mft records (inodes) on the mounted NTFS |
| 2036 | * volume @vol. We actually calculate the number of mft records in use instead | 2478 | * volume @vol. We actually calculate the number of mft records in use instead |
| @@ -2043,32 +2485,20 @@ static s64 get_nr_free_clusters(ntfs_volume *vol) | |||
| 2043 | * | 2485 | * |
| 2044 | * NOTE: Caller must hold mftbmp_lock rw_semaphore for reading or writing. | 2486 | * NOTE: Caller must hold mftbmp_lock rw_semaphore for reading or writing. |
| 2045 | */ | 2487 | */ |
| 2046 | static unsigned long __get_nr_free_mft_records(ntfs_volume *vol) | 2488 | static unsigned long __get_nr_free_mft_records(ntfs_volume *vol, |
| 2489 | s64 nr_free, const pgoff_t max_index) | ||
| 2047 | { | 2490 | { |
| 2048 | s64 nr_free; | ||
| 2049 | u32 *kaddr; | 2491 | u32 *kaddr; |
| 2050 | struct address_space *mapping = vol->mftbmp_ino->i_mapping; | 2492 | struct address_space *mapping = vol->mftbmp_ino->i_mapping; |
| 2051 | filler_t *readpage = (filler_t*)mapping->a_ops->readpage; | 2493 | filler_t *readpage = (filler_t*)mapping->a_ops->readpage; |
| 2052 | struct page *page; | 2494 | struct page *page; |
| 2053 | unsigned long index, max_index; | 2495 | pgoff_t index; |
| 2054 | unsigned int max_size; | ||
| 2055 | 2496 | ||
| 2056 | ntfs_debug("Entering."); | 2497 | ntfs_debug("Entering."); |
| 2057 | /* Number of mft records in file system (at this point in time). */ | 2498 | /* Use multiples of 4 bytes, thus max_size is PAGE_CACHE_SIZE / 4. */ |
| 2058 | nr_free = vol->mft_ino->i_size >> vol->mft_record_size_bits; | ||
| 2059 | /* | ||
| 2060 | * Convert the maximum number of set bits into bytes rounded up, then | ||
| 2061 | * convert into multiples of PAGE_CACHE_SIZE, rounding up so that if we | ||
| 2062 | * have one full and one partial page max_index = 2. | ||
| 2063 | */ | ||
| 2064 | max_index = ((((NTFS_I(vol->mft_ino)->initialized_size >> | ||
| 2065 | vol->mft_record_size_bits) + 7) >> 3) + | ||
| 2066 | PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT; | ||
| 2067 | /* Use multiples of 4 bytes. */ | ||
| 2068 | max_size = PAGE_CACHE_SIZE >> 2; | ||
| 2069 | ntfs_debug("Reading $MFT/$BITMAP, max_index = 0x%lx, max_size = " | 2499 | ntfs_debug("Reading $MFT/$BITMAP, max_index = 0x%lx, max_size = " |
| 2070 | "0x%x.", max_index, max_size); | 2500 | "0x%lx.", max_index, PAGE_CACHE_SIZE / 4); |
| 2071 | for (index = 0UL; index < max_index; index++) { | 2501 | for (index = 0; index < max_index; index++) { |
| 2072 | unsigned int i; | 2502 | unsigned int i; |
| 2073 | /* | 2503 | /* |
| 2074 | * Read the page from page cache, getting it from backing store | 2504 | * Read the page from page cache, getting it from backing store |
| @@ -2100,7 +2530,7 @@ static unsigned long __get_nr_free_mft_records(ntfs_volume *vol) | |||
| 2100 | * the result as all out of range bytes are set to zero by | 2530 | * the result as all out of range bytes are set to zero by |
| 2101 | * ntfs_readpage(). | 2531 | * ntfs_readpage(). |
| 2102 | */ | 2532 | */ |
| 2103 | for (i = 0; i < max_size; i++) | 2533 | for (i = 0; i < PAGE_CACHE_SIZE / 4; i++) |
| 2104 | nr_free -= (s64)hweight32(kaddr[i]); | 2534 | nr_free -= (s64)hweight32(kaddr[i]); |
| 2105 | kunmap_atomic(kaddr, KM_USER0); | 2535 | kunmap_atomic(kaddr, KM_USER0); |
| 2106 | page_cache_release(page); | 2536 | page_cache_release(page); |
| @@ -2134,8 +2564,11 @@ static unsigned long __get_nr_free_mft_records(ntfs_volume *vol) | |||
| 2134 | */ | 2564 | */ |
| 2135 | static int ntfs_statfs(struct super_block *sb, struct kstatfs *sfs) | 2565 | static int ntfs_statfs(struct super_block *sb, struct kstatfs *sfs) |
| 2136 | { | 2566 | { |
| 2137 | ntfs_volume *vol = NTFS_SB(sb); | ||
| 2138 | s64 size; | 2567 | s64 size; |
| 2568 | ntfs_volume *vol = NTFS_SB(sb); | ||
| 2569 | ntfs_inode *mft_ni = NTFS_I(vol->mft_ino); | ||
| 2570 | pgoff_t max_index; | ||
| 2571 | unsigned long flags; | ||
| 2139 | 2572 | ||
| 2140 | ntfs_debug("Entering."); | 2573 | ntfs_debug("Entering."); |
| 2141 | /* Type of filesystem. */ | 2574 | /* Type of filesystem. */ |
| @@ -2143,13 +2576,13 @@ static int ntfs_statfs(struct super_block *sb, struct kstatfs *sfs) | |||
| 2143 | /* Optimal transfer block size. */ | 2576 | /* Optimal transfer block size. */ |
| 2144 | sfs->f_bsize = PAGE_CACHE_SIZE; | 2577 | sfs->f_bsize = PAGE_CACHE_SIZE; |
| 2145 | /* | 2578 | /* |
| 2146 | * Total data blocks in file system in units of f_bsize and since | 2579 | * Total data blocks in filesystem in units of f_bsize and since |
| 2147 | * inodes are also stored in data blocs ($MFT is a file) this is just | 2580 | * inodes are also stored in data blocs ($MFT is a file) this is just |
| 2148 | * the total clusters. | 2581 | * the total clusters. |
| 2149 | */ | 2582 | */ |
| 2150 | sfs->f_blocks = vol->nr_clusters << vol->cluster_size_bits >> | 2583 | sfs->f_blocks = vol->nr_clusters << vol->cluster_size_bits >> |
| 2151 | PAGE_CACHE_SHIFT; | 2584 | PAGE_CACHE_SHIFT; |
| 2152 | /* Free data blocks in file system in units of f_bsize. */ | 2585 | /* Free data blocks in filesystem in units of f_bsize. */ |
| 2153 | size = get_nr_free_clusters(vol) << vol->cluster_size_bits >> | 2586 | size = get_nr_free_clusters(vol) << vol->cluster_size_bits >> |
| 2154 | PAGE_CACHE_SHIFT; | 2587 | PAGE_CACHE_SHIFT; |
| 2155 | if (size < 0LL) | 2588 | if (size < 0LL) |
| @@ -2158,17 +2591,27 @@ static int ntfs_statfs(struct super_block *sb, struct kstatfs *sfs) | |||
| 2158 | sfs->f_bavail = sfs->f_bfree = size; | 2591 | sfs->f_bavail = sfs->f_bfree = size; |
| 2159 | /* Serialize accesses to the inode bitmap. */ | 2592 | /* Serialize accesses to the inode bitmap. */ |
| 2160 | down_read(&vol->mftbmp_lock); | 2593 | down_read(&vol->mftbmp_lock); |
| 2161 | /* Number of inodes in file system (at this point in time). */ | 2594 | read_lock_irqsave(&mft_ni->size_lock, flags); |
| 2162 | sfs->f_files = vol->mft_ino->i_size >> vol->mft_record_size_bits; | 2595 | size = i_size_read(vol->mft_ino) >> vol->mft_record_size_bits; |
| 2596 | /* | ||
| 2597 | * Convert the maximum number of set bits into bytes rounded up, then | ||
| 2598 | * convert into multiples of PAGE_CACHE_SIZE, rounding up so that if we | ||
| 2599 | * have one full and one partial page max_index = 2. | ||
| 2600 | */ | ||
| 2601 | max_index = ((((mft_ni->initialized_size >> vol->mft_record_size_bits) | ||
| 2602 | + 7) >> 3) + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT; | ||
| 2603 | read_unlock_irqrestore(&mft_ni->size_lock, flags); | ||
| 2604 | /* Number of inodes in filesystem (at this point in time). */ | ||
| 2605 | sfs->f_files = size; | ||
| 2163 | /* Free inodes in fs (based on current total count). */ | 2606 | /* Free inodes in fs (based on current total count). */ |
| 2164 | sfs->f_ffree = __get_nr_free_mft_records(vol); | 2607 | sfs->f_ffree = __get_nr_free_mft_records(vol, size, max_index); |
| 2165 | up_read(&vol->mftbmp_lock); | 2608 | up_read(&vol->mftbmp_lock); |
| 2166 | /* | 2609 | /* |
| 2167 | * File system id. This is extremely *nix flavour dependent and even | 2610 | * File system id. This is extremely *nix flavour dependent and even |
| 2168 | * within Linux itself all fs do their own thing. I interpret this to | 2611 | * within Linux itself all fs do their own thing. I interpret this to |
| 2169 | * mean a unique id associated with the mounted fs and not the id | 2612 | * mean a unique id associated with the mounted fs and not the id |
| 2170 | * associated with the file system driver, the latter is already given | 2613 | * associated with the filesystem driver, the latter is already given |
| 2171 | * by the file system type in sfs->f_type. Thus we use the 64-bit | 2614 | * by the filesystem type in sfs->f_type. Thus we use the 64-bit |
| 2172 | * volume serial number splitting it into two 32-bit parts. We enter | 2615 | * volume serial number splitting it into two 32-bit parts. We enter |
| 2173 | * the least significant 32-bits in f_fsid[0] and the most significant | 2616 | * the least significant 32-bits in f_fsid[0] and the most significant |
| 2174 | * 32-bits in f_fsid[1]. | 2617 | * 32-bits in f_fsid[1]. |
| @@ -2219,53 +2662,19 @@ static struct super_operations ntfs_sops = { | |||
| 2219 | proc. */ | 2662 | proc. */ |
| 2220 | }; | 2663 | }; |
| 2221 | 2664 | ||
| 2222 | |||
| 2223 | /** | ||
| 2224 | * Declarations for NTFS specific export operations (fs/ntfs/namei.c). | ||
| 2225 | */ | ||
| 2226 | extern struct dentry *ntfs_get_parent(struct dentry *child_dent); | ||
| 2227 | extern struct dentry *ntfs_get_dentry(struct super_block *sb, void *fh); | ||
| 2228 | |||
| 2229 | /** | ||
| 2230 | * Export operations allowing NFS exporting of mounted NTFS partitions. | ||
| 2231 | * | ||
| 2232 | * We use the default ->decode_fh() and ->encode_fh() for now. Note that they | ||
| 2233 | * use 32 bits to store the inode number which is an unsigned long so on 64-bit | ||
| 2234 | * architectures is usually 64 bits so it would all fail horribly on huge | ||
| 2235 | * volumes. I guess we need to define our own encode and decode fh functions | ||
| 2236 | * that store 64-bit inode numbers at some point but for now we will ignore the | ||
| 2237 | * problem... | ||
| 2238 | * | ||
| 2239 | * We also use the default ->get_name() helper (used by ->decode_fh() via | ||
| 2240 | * fs/exportfs/expfs.c::find_exported_dentry()) as that is completely fs | ||
| 2241 | * independent. | ||
| 2242 | * | ||
| 2243 | * The default ->get_parent() just returns -EACCES so we have to provide our | ||
| 2244 | * own and the default ->get_dentry() is incompatible with NTFS due to not | ||
| 2245 | * allowing the inode number 0 which is used in NTFS for the system file $MFT | ||
| 2246 | * and due to using iget() whereas NTFS needs ntfs_iget(). | ||
| 2247 | */ | ||
| 2248 | static struct export_operations ntfs_export_ops = { | ||
| 2249 | .get_parent = ntfs_get_parent, /* Find the parent of a given | ||
| 2250 | directory. */ | ||
| 2251 | .get_dentry = ntfs_get_dentry, /* Find a dentry for the inode | ||
| 2252 | given a file handle | ||
| 2253 | sub-fragment. */ | ||
| 2254 | }; | ||
| 2255 | |||
| 2256 | /** | 2665 | /** |
| 2257 | * ntfs_fill_super - mount an ntfs files system | 2666 | * ntfs_fill_super - mount an ntfs filesystem |
| 2258 | * @sb: super block of ntfs file system to mount | 2667 | * @sb: super block of ntfs filesystem to mount |
| 2259 | * @opt: string containing the mount options | 2668 | * @opt: string containing the mount options |
| 2260 | * @silent: silence error output | 2669 | * @silent: silence error output |
| 2261 | * | 2670 | * |
| 2262 | * ntfs_fill_super() is called by the VFS to mount the device described by @sb | 2671 | * ntfs_fill_super() is called by the VFS to mount the device described by @sb |
| 2263 | * with the mount otions in @data with the NTFS file system. | 2672 | * with the mount otions in @data with the NTFS filesystem. |
| 2264 | * | 2673 | * |
| 2265 | * If @silent is true, remain silent even if errors are detected. This is used | 2674 | * If @silent is true, remain silent even if errors are detected. This is used |
| 2266 | * during bootup, when the kernel tries to mount the root file system with all | 2675 | * during bootup, when the kernel tries to mount the root filesystem with all |
| 2267 | * registered file systems one after the other until one succeeds. This implies | 2676 | * registered filesystems one after the other until one succeeds. This implies |
| 2268 | * that all file systems except the correct one will quite correctly and | 2677 | * that all filesystems except the correct one will quite correctly and |
| 2269 | * expectedly return an error, but nobody wants to see error messages when in | 2678 | * expectedly return an error, but nobody wants to see error messages when in |
| 2270 | * fact this is what is supposed to happen. | 2679 | * fact this is what is supposed to happen. |
| 2271 | * | 2680 | * |
| @@ -2292,39 +2701,25 @@ static int ntfs_fill_super(struct super_block *sb, void *opt, const int silent) | |||
| 2292 | return -ENOMEM; | 2701 | return -ENOMEM; |
| 2293 | } | 2702 | } |
| 2294 | /* Initialize ntfs_volume structure. */ | 2703 | /* Initialize ntfs_volume structure. */ |
| 2295 | memset(vol, 0, sizeof(ntfs_volume)); | 2704 | *vol = (ntfs_volume) { |
| 2296 | vol->sb = sb; | 2705 | .sb = sb, |
| 2297 | vol->upcase = NULL; | 2706 | /* |
| 2298 | vol->attrdef = NULL; | 2707 | * Default is group and other don't have any access to files or |
| 2299 | vol->mft_ino = NULL; | 2708 | * directories while owner has full access. Further, files by |
| 2300 | vol->mftbmp_ino = NULL; | 2709 | * default are not executable but directories are of course |
| 2710 | * browseable. | ||
| 2711 | */ | ||
| 2712 | .fmask = 0177, | ||
| 2713 | .dmask = 0077, | ||
| 2714 | }; | ||
| 2301 | init_rwsem(&vol->mftbmp_lock); | 2715 | init_rwsem(&vol->mftbmp_lock); |
| 2302 | #ifdef NTFS_RW | ||
| 2303 | vol->mftmirr_ino = NULL; | ||
| 2304 | vol->logfile_ino = NULL; | ||
| 2305 | #endif /* NTFS_RW */ | ||
| 2306 | vol->lcnbmp_ino = NULL; | ||
| 2307 | init_rwsem(&vol->lcnbmp_lock); | 2716 | init_rwsem(&vol->lcnbmp_lock); |
| 2308 | vol->vol_ino = NULL; | ||
| 2309 | vol->root_ino = NULL; | ||
| 2310 | vol->secure_ino = NULL; | ||
| 2311 | vol->extend_ino = NULL; | ||
| 2312 | #ifdef NTFS_RW | ||
| 2313 | vol->quota_ino = NULL; | ||
| 2314 | vol->quota_q_ino = NULL; | ||
| 2315 | #endif /* NTFS_RW */ | ||
| 2316 | vol->nls_map = NULL; | ||
| 2317 | |||
| 2318 | /* | ||
| 2319 | * Default is group and other don't have any access to files or | ||
| 2320 | * directories while owner has full access. Further, files by default | ||
| 2321 | * are not executable but directories are of course browseable. | ||
| 2322 | */ | ||
| 2323 | vol->fmask = 0177; | ||
| 2324 | vol->dmask = 0077; | ||
| 2325 | 2717 | ||
| 2326 | unlock_kernel(); | 2718 | unlock_kernel(); |
| 2327 | 2719 | ||
| 2720 | /* By default, enable sparse support. */ | ||
| 2721 | NVolSetSparseEnabled(vol); | ||
| 2722 | |||
| 2328 | /* Important to get the mount options dealt with now. */ | 2723 | /* Important to get the mount options dealt with now. */ |
| 2329 | if (!parse_options(vol, (char*)opt)) | 2724 | if (!parse_options(vol, (char*)opt)) |
| 2330 | goto err_out_now; | 2725 | goto err_out_now; |
| @@ -2347,7 +2742,8 @@ static int ntfs_fill_super(struct super_block *sb, void *opt, const int silent) | |||
| 2347 | } | 2742 | } |
| 2348 | 2743 | ||
| 2349 | /* Get the size of the device in units of NTFS_BLOCK_SIZE bytes. */ | 2744 | /* Get the size of the device in units of NTFS_BLOCK_SIZE bytes. */ |
| 2350 | vol->nr_blocks = sb->s_bdev->bd_inode->i_size >> NTFS_BLOCK_SIZE_BITS; | 2745 | vol->nr_blocks = i_size_read(sb->s_bdev->bd_inode) >> |
| 2746 | NTFS_BLOCK_SIZE_BITS; | ||
| 2351 | 2747 | ||
| 2352 | /* Read the boot sector and return unlocked buffer head to it. */ | 2748 | /* Read the boot sector and return unlocked buffer head to it. */ |
| 2353 | if (!(bh = read_ntfs_boot_sector(sb, silent))) { | 2749 | if (!(bh = read_ntfs_boot_sector(sb, silent))) { |
| @@ -2476,6 +2872,18 @@ static int ntfs_fill_super(struct super_block *sb, void *opt, const int silent) | |||
| 2476 | /* NTFS 3.0+ specific clean up. */ | 2872 | /* NTFS 3.0+ specific clean up. */ |
| 2477 | if (vol->major_ver >= 3) { | 2873 | if (vol->major_ver >= 3) { |
| 2478 | #ifdef NTFS_RW | 2874 | #ifdef NTFS_RW |
| 2875 | if (vol->usnjrnl_j_ino) { | ||
| 2876 | iput(vol->usnjrnl_j_ino); | ||
| 2877 | vol->usnjrnl_j_ino = NULL; | ||
| 2878 | } | ||
| 2879 | if (vol->usnjrnl_max_ino) { | ||
| 2880 | iput(vol->usnjrnl_max_ino); | ||
| 2881 | vol->usnjrnl_max_ino = NULL; | ||
| 2882 | } | ||
| 2883 | if (vol->usnjrnl_ino) { | ||
| 2884 | iput(vol->usnjrnl_ino); | ||
| 2885 | vol->usnjrnl_ino = NULL; | ||
| 2886 | } | ||
| 2479 | if (vol->quota_q_ino) { | 2887 | if (vol->quota_q_ino) { |
| 2480 | iput(vol->quota_q_ino); | 2888 | iput(vol->quota_q_ino); |
| 2481 | vol->quota_q_ino = NULL; | 2889 | vol->quota_q_ino = NULL; |
| @@ -2581,7 +2989,7 @@ err_out_now: | |||
| 2581 | */ | 2989 | */ |
| 2582 | kmem_cache_t *ntfs_name_cache; | 2990 | kmem_cache_t *ntfs_name_cache; |
| 2583 | 2991 | ||
| 2584 | /* Slab caches for efficient allocation/deallocation of of inodes. */ | 2992 | /* Slab caches for efficient allocation/deallocation of inodes. */ |
| 2585 | kmem_cache_t *ntfs_inode_cache; | 2993 | kmem_cache_t *ntfs_inode_cache; |
| 2586 | kmem_cache_t *ntfs_big_inode_cache; | 2994 | kmem_cache_t *ntfs_big_inode_cache; |
| 2587 | 2995 | ||
| @@ -2705,7 +3113,7 @@ static int __init init_ntfs_fs(void) | |||
| 2705 | ntfs_debug("NTFS driver registered successfully."); | 3113 | ntfs_debug("NTFS driver registered successfully."); |
| 2706 | return 0; /* Success! */ | 3114 | return 0; /* Success! */ |
| 2707 | } | 3115 | } |
| 2708 | printk(KERN_CRIT "NTFS: Failed to register NTFS file system driver!\n"); | 3116 | printk(KERN_CRIT "NTFS: Failed to register NTFS filesystem driver!\n"); |
| 2709 | 3117 | ||
| 2710 | sysctl_err_out: | 3118 | sysctl_err_out: |
| 2711 | kmem_cache_destroy(ntfs_big_inode_cache); | 3119 | kmem_cache_destroy(ntfs_big_inode_cache); |
| @@ -2719,7 +3127,7 @@ actx_err_out: | |||
| 2719 | kmem_cache_destroy(ntfs_index_ctx_cache); | 3127 | kmem_cache_destroy(ntfs_index_ctx_cache); |
| 2720 | ictx_err_out: | 3128 | ictx_err_out: |
| 2721 | if (!err) { | 3129 | if (!err) { |
| 2722 | printk(KERN_CRIT "NTFS: Aborting NTFS file system driver " | 3130 | printk(KERN_CRIT "NTFS: Aborting NTFS filesystem driver " |
| 2723 | "registration...\n"); | 3131 | "registration...\n"); |
| 2724 | err = -ENOMEM; | 3132 | err = -ENOMEM; |
| 2725 | } | 3133 | } |
| @@ -2759,7 +3167,7 @@ static void __exit exit_ntfs_fs(void) | |||
| 2759 | } | 3167 | } |
| 2760 | 3168 | ||
| 2761 | MODULE_AUTHOR("Anton Altaparmakov <aia21@cantab.net>"); | 3169 | MODULE_AUTHOR("Anton Altaparmakov <aia21@cantab.net>"); |
| 2762 | MODULE_DESCRIPTION("NTFS 1.2/3.x driver - Copyright (c) 2001-2004 Anton Altaparmakov"); | 3170 | MODULE_DESCRIPTION("NTFS 1.2/3.x driver - Copyright (c) 2001-2005 Anton Altaparmakov"); |
| 2763 | MODULE_VERSION(NTFS_VERSION); | 3171 | MODULE_VERSION(NTFS_VERSION); |
| 2764 | MODULE_LICENSE("GPL"); | 3172 | MODULE_LICENSE("GPL"); |
| 2765 | #ifdef DEBUG | 3173 | #ifdef DEBUG |
