udf: Do not mark possibly inconsistent filesystems as closed
authorJan Kara <jack@suse.cz>
Tue, 27 Feb 2018 17:55:31 +0000 (18:55 +0100)
committerJan Kara <jack@suse.cz>
Fri, 2 Mar 2018 13:22:57 +0000 (14:22 +0100)
If logical volume integrity descriptor contains non-closed integrity
type when mounting the volume, there are high chances that the volume is
not consistent (device was detached before the filesystem was
unmounted). Don't touch integrity type of such volume so that fsck can
recognize it and check such filesystem.

Reported-by: Pali Rohár <pali.rohar@gmail.com>
Reviewed-by: Pali Rohár <pali.rohar@gmail.com>
Signed-off-by: Jan Kara <jack@suse.cz>
fs/udf/super.c
fs/udf/udf_sb.h

index 2d4929fa884d4abbce8a067e7bb2a472505ca834..bf5f6084dcb2047d070cf72e09a4b98060abfa5c 100644 (file)
@@ -1988,7 +1988,10 @@ static void udf_open_lvid(struct super_block *sb)
        lvidiu->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
        ktime_get_real_ts(&ts);
        udf_time_to_disk_stamp(&lvid->recordingDateAndTime, ts);
-       lvid->integrityType = cpu_to_le32(LVID_INTEGRITY_TYPE_OPEN);
+       if (le32_to_cpu(lvid->integrityType) == LVID_INTEGRITY_TYPE_CLOSE)
+               lvid->integrityType = cpu_to_le32(LVID_INTEGRITY_TYPE_OPEN);
+       else
+               UDF_SET_FLAG(sb, UDF_FLAG_INCONSISTENT);
 
        lvid->descTag.descCRC = cpu_to_le16(
                crc_itu_t(0, (char *)lvid + sizeof(struct tag),
@@ -2028,7 +2031,8 @@ static void udf_close_lvid(struct super_block *sb)
                lvidiu->minUDFReadRev = cpu_to_le16(sbi->s_udfrev);
        if (sbi->s_udfrev > le16_to_cpu(lvidiu->minUDFWriteRev))
                lvidiu->minUDFWriteRev = cpu_to_le16(sbi->s_udfrev);
-       lvid->integrityType = cpu_to_le32(LVID_INTEGRITY_TYPE_CLOSE);
+       if (!UDF_QUERY_FLAG(sb, UDF_FLAG_INCONSISTENT))
+               lvid->integrityType = cpu_to_le32(LVID_INTEGRITY_TYPE_CLOSE);
 
        lvid->descTag.descCRC = cpu_to_le16(
                        crc_itu_t(0, (char *)lvid + sizeof(struct tag),
index 9dcb475fc74e04238218dae1284d7a3eaf68ad51..9dd3e1b9619e1ac2ce2485dd7a118601db0cb2a4 100644 (file)
@@ -29,6 +29,7 @@
 #define UDF_FLAG_SESSION_SET   15
 #define UDF_FLAG_LASTBLOCK_SET 16
 #define UDF_FLAG_BLOCKSIZE_SET 17
+#define UDF_FLAG_INCONSISTENT  18
 
 #define UDF_PART_FLAG_UNALLOC_BITMAP   0x0001
 #define UDF_PART_FLAG_UNALLOC_TABLE    0x0002