Changes by: antona
Update of /cvsroot/linux-ntfs/linux-ntfs/libntfs
In directory usw-pr-cvs1:/tmp/cvs-serv23262/libntfs
Modified Files:
volume.c
Log Message:
Fix detection of read-only mounts in volume.c::ntfs_check_mnteent().
Index: volume.c
===================================================================
RCS file: /cvsroot/linux-ntfs/linux-ntfs/libntfs/volume.c,v
retrieving revision 1.41
retrieving revision 1.42
diff -U2 -r1.41 -r1.42
--- volume.c 1 Jun 2002 00:41:45 -0000 1.41
+++ volume.c 2 Jun 2002 13:57:59 -0000 1.42
@@ -120,5 +120,6 @@
ntfs_volume *vol = NULL;
NTFS_BOOT_SECTOR *bs = NULL;
- MFT_RECORD *m = NULL, *m2 = NULL, *mb = NULL;
+ MFT_RECORD *mb = NULL;
+ __u8 *m = NULL, *m2 = NULL;
ntfs_attr_search_ctx *ctx = NULL;
run_list_element *rl;
@@ -175,4 +176,5 @@
Dputs(OK);
if (!is_boot_sector_ntfs(bs, !debug)) {
+ // FIXME: Try the bootsector backup or leave to ntfsck? (AIA)
Dprintf("Error: %s is not a valid NTFS partition!\n", name);
errno = EINVAL;
@@ -514,7 +516,6 @@
/* Load $MFT and $MFTMirr and compare the contents. */
- m = (MFT_RECORD*)malloc(vol->mftmirr_size << vol->mft_record_size_bits);
- m2 = (MFT_RECORD*)malloc(vol->mftmirr_size <<
- vol->mft_record_size_bits);
+ m = (__u8*)malloc(vol->mftmirr_size << vol->mft_record_size_bits);
+ m2 = (__u8*)malloc(vol->mftmirr_size << vol->mft_record_size_bits);
if (!m || !m2) {
Dperror("Failed to allocate memory");
@@ -544,13 +545,56 @@
goto error_exit;
}
+ Dprintf("Verifying $MFTMirr and beginning of $MFT... ");
+ for (i = 0; i < vol->mftmirr_size; ++i) {
+ const char *ESTR[12] = { "$MFT", "$MFTMirr", "$LogFile",
+ "$Volume", "$AttrDef", "root directory", "$Bitmap",
+ "$Boot", "$BadClus", "$Secure", "$UpCase", "$Extend" };
+ const char *s;
+
+ if (i < 12)
+ s = ESTR[i];
+ else if (i < 16)
+ s = "system file";
+ else
+ s = "mft record";
+ if (is_baad_recordp(m + i * vol->mft_record_size)) {
+ Dputs("FAILED");
+ Dprintf("$MFT error: Incomplete multi sector transfer "
+ "detected in %s.\n", s);
+ goto io_error_exit;
+ }
+ if (!is_mft_recordp(m + i * vol->mft_record_size)) {
+ Dputs("FAILED");
+ Dprintf("$MFT error: Invalid mft record for %s.\n", s);
+ goto io_error_exit;
+ }
+ if (is_baad_recordp(m2 + i * vol->mft_record_size)) {
+ Dputs("FAILED");
+ Dprintf("$MFTMirr error: Incomplete multi sector "
+ "transfer detected in %s.\n", s);
+ goto io_error_exit;
+ }
+ if (!is_mft_recordp(m2 + i * vol->mft_record_size)) {
+ Dputs("FAILED");
+ Dprintf("$MFTMirr error: Invalid mft record for %s.\n",
+ s);
+ goto io_error_exit;
+ }
+ }
+ Dputs(OK);
Dprintf("Comparing $MFTMirr to $MFT... ");
- for (i = 0, j = 0; i < vol->mftmirr_size; ++i) {
+ for (i = 0; i < vol->mftmirr_size; ++i) {
if (memcmp((__u8*)m + i * vol->mft_record_size, (__u8*)m2 +
i * vol->mft_record_size,
ntfs_get_mft_record_data_size((MFT_RECORD*)(
- (__u8*)m + i * vol->mft_record_size))))
- j |= 1 << i;
+ (__u8*)m + i * vol->mft_record_size)))) {
+ Dputs(FAILED);
+ Dputs("The $MFT mirror does not match the $MFT. "
+ "You need to run chkdsk.");
+ goto io_error_exit;
+ }
}
+ Dputs(OK);
free(m2);
@@ -558,12 +602,4 @@
m = m2 = NULL;
- if (j) {
- Dputs(FAILED);
- Dputs("The $MFT mirror does not match the $MFT. "
- "You need to run chkdsk.");
- goto io_error_exit;
- }
- Dputs(OK);
-
/* Now load the bitmap from $Bitmap. */
Dprintf("Loading $Bitmap... ");
@@ -802,6 +838,4 @@
struct mntent *mnt;
FILE *f;
- char *s;
- int fd, len;
if (!(f = setmntent(MOUNTED, "r")))
@@ -816,19 +850,6 @@
if (!strcmp(mnt->mnt_dir, "/"))
*mnt_flags |= NTFS_MF_ISROOT;
- len = strlen(mnt->mnt_dir);
- s = malloc(len + 3);
- if (!s)
- return -1;
- strncpy(s, mnt->mnt_dir, len + 3);
- if (s[len - 1] != '/')
- s[len++] = '/';
- s[len++] = '.';
- s[len] = '\0';
- fd = open(s, O_RDWR);
- if (fd < 0) {
- if (errno == EROFS)
- *mnt_flags |= NTFS_MF_READONLY;
- } else
- close(fd);
+ if (hasmntopt(mnt, "ro") && !hasmntopt(mnt, "rw"))
+ *mnt_flags |= NTFS_MF_READONLY;
return 0;
}
|