fat: add extended fileds to struct fat_boot_sector
Subsystems (2)
OGAWA Hirofumi
maintainerPATCH 1/2 fat: add extended fileds to struct fat_boot_sector
From: Oleksij Rempel <[email protected]>
later we will need "state" field to check if volume was cleanly unmounted.
---
fs/fat/inode.c | 8 ++++---- include/uapi/linux/msdos_fs.h | 36 ++++++++++++++++++++++++++++-------- 2 files changed, 32 insertions(+), 12 deletions(-)
fs/fat/inode.c renamed from fs/fat/inode.c~fat-check-dirty-1 +4 -4
@@ -1298,17 +1298,17 @@ int fat_fill_super(struct super_block *s sbi->prev_free =FAT_START_ENT ; sb->s_maxbytes =0xffffffff ; -if (!sbi->fat_length && b->fat32_length) { +if (!sbi->fat_length && b->fat32.length) {struct fat_boot_fsinfo *fsinfo;struct buffer_head *fsinfo_bh;/* Must be FAT32 */ sbi->fat_bits =32 ; - sbi->fat_length =le32_to_cpu (b->fat32_length); - sbi->root_cluster =le32_to_cpu (b->root_cluster); + sbi->fat_length =le32_to_cpu (b->fat32.length); + sbi->root_cluster =le32_to_cpu (b->fat32.root_cluster);/* MC - if info_sector is 0, don't multiply by 0 */ - sbi->fsinfo_sector =le16_to_cpu (b->info_sector); + sbi->fsinfo_sector =le16_to_cpu (b->fat32.info_sector);if (sbi->fsinfo_sector ==0 ) sbi->fsinfo_sector =1 ;
include/uapi/linux/msdos_fs.h renamed from include/uapi/linux/msdos_fs.h~fat-check-dirty-1 +28 -8
@@ -120,14 +120,34 @@ struct fat_boot_sector {__le32 hidden;/* hidden sectors (unused) */ __le32 total_sect;/* number of sectors (if sectors == 0) */ -/* The following fields are only used by FAT32 */ -__le32 fat32_length;/* sectors/FAT */ -__le16 flags;/* bit 8: fat mirroring, low 4: active fat */ -__u8 version[2 ];/* major, minor filesystem version */ -__le32 root_cluster;/* first cluster in root directory */ -__le16 info_sector;/* filesystem info sector */ -__le16 backup_boot;/* backup boot sector */ -__le16 reserved2[6 ];/* Unused */ +union { +struct { +/* Extended BPB Fields for FAT16 */ +__u8 drive_number;/* Physical drive number */ +__u8 state;/* undocumented, but used +for mount state. */ +/* other fiealds are not added here */ + } fat16; + +struct { +/* only used by FAT32 */ +__le32 length;/* sectors/FAT */ +__le16 flags;/* bit 8: fat mirroring, +low 4: active fat */ +__u8 version[2 ];/* major, minor filesystem +version */ +__le32 root_cluster;/* first cluster in +root directory */ +__le16 info_sector;/* filesystem info sector */ +__le16 backup_boot;/* backup boot sector */ +__le16 reserved2[6 ];/* Unused */ +/* Extended BPB Fields for FAT32 */ +__u8 drive_number;/* Physical drive number */ +__u8 state;/* undocumented, but used +for mount state. */ +/* other fiealds are not added here */ + } fat32; + }; };struct fat_boot_fsinfo {
_
Signature · 1 line
OGAWA Hirofumi <[email protected]>
OGAWA Hirofumi
maintainerPATCH 2/2 fat: mark fs as dirty on mount and clean on umount
From: Oleksij Rempel <[email protected]>
There is no documented methods to mark FAT as dirty. Unofficially MS started to use reserved Byte in boot sector for this purpose, at least since Win 2000. With Win 7 user is warned if fs is dirty and asked to clean it.
Different versions of Win, handle it in different ways, but always have same meaning:
- Win 2000 and XP, set it on write operations and
remove it after operation was finnished
- Win 7, set dirty flag on first write and remove it on umount.
We will do it as fallow:
- set dirty flag on mount. If fs was initially dirty, warn user, remember it and do not do any changes to boot sector.
- clean it on umount. If fs was initially dirty, leave it dirty.
- do not do any thing if fs mounted read-only.
- TODO: leave fs dirty if we found some error after mount.
patch history:
- v2. do not warn on read-only. Some style fixes.
- v3. make fat_set_state static.
- v4. add "force" variable to fat_set_state and use it on remount ro to rw.
---
fs/fat/fat.h | 2 + fs/fat/inode.c | 66 +++++++++++++++++++++++++++++++++++++++++ include/uapi/linux/msdos_fs.h | 2 + 3 files changed, 70 insertions(+)
fs/fat/fat.h renamed from fs/fat/fat.h~fat-check-dirty-2 +2 -0
@@ -95,6 +95,8 @@ struct msdos_sb_info {spinlock_t dir_hash_lock;struct hlist_head dir_hashtable[FAT_HASH_SIZE ]; + +unsigned int dirty;/* fs state before mount */ };#define FAT_CACHE_VALID 0/* special case for valid cache */
fs/fat/inode.c renamed from fs/fat/inode.c~fat-check-dirty-2 +66 -0
96 lines not on this page · raw message
include/uapi/linux/msdos_fs.h renamed from include/uapi/linux/msdos_fs.h~fat-check-dirty-2 +2 -0
@@ -87,6 +87,8 @@#define IS_FSINFO (x) (le32_to_cpu((x)->signature1) == FAT_FSINFO_SIG1 \ && le32_to_cpu((x)->signature2) == FAT_FSINFO_SIG2) +#define FAT_STATE_DIRTY 0x01 +struct __fat_dirent {long d_ino;__kernel_off_t d_off;
_
Signature · 1 line
OGAWA Hirofumi <[email protected]>
Re: [PATCH 2/2] fat: mark fs as dirty on mount and clean on umount
Quoted 10 lines · On Fri, 28 Dec 2012 02:20:20 +0900 OGAWA Hirofumi…
There is no documented methods to mark FAT as dirty. Unofficially MS started to use reserved Byte in boot sector for this purpose, at least since Win 2000. With Win 7 user is warned if fs is dirty and asked to clean it.
Different versions of Win, handle it in different ways, but always have same meaning:
- Win 2000 and XP, set it on write operations and
remove it after operation was finnished
- Win 7, set dirty flag on first write and remove it on umount.
Quoted 6 lines
We will do it as fallow:
- set dirty flag on mount. If fs was initially dirty, warn user, remember it and do not do any changes to boot sector.
- clean it on umount. If fs was initially dirty, leave it dirty.
- do not do any thing if fs mounted read-only.
- TODO: leave fs dirty if we found some error after mount.
The changelog doesn't describe why we're making this change. Nor does it describe the user-visible effects of this change.
AFAICT the effect is to issue a warning at mount-time to tell the user that the fs wasn't cleanly unmounted and that the user should fsck the volume, correct?
If so, why is this considered a desirable feature? (I can guess, but would prefer to hear it spelled out by the experts, please).
Re: [PATCH 2/2] fat: mark fs as dirty on mount and clean on umount
Am 03.01.2013 00:44, schrieb Andrew Morton:
Quoted 23 lines
Quoted 10 lines · On Fri, 28 Dec 2012 02:20:20 +0900 OGAWA Hirofumi…
There is no documented methods to mark FAT as dirty. Unofficially MS started to use reserved Byte in boot sector for this purpose, at least since Win 2000. With Win 7 user is warned if fs is dirty and asked to clean it.
Different versions of Win, handle it in different ways, but always have same meaning:
- Win 2000 and XP, set it on write operations and
remove it after operation was finnished
- Win 7, set dirty flag on first write and remove it on umount.Quoted 6 lines
We will do it as fallow:
- set dirty flag on mount. If fs was initially dirty, warn user, remember it and do not do any changes to boot sector.
- clean it on umount. If fs was initially dirty, leave it dirty.
- do not do any thing if fs mounted read-only.
- TODO: leave fs dirty if we found some error after mount.The changelog doesn't describe why we're making this change. Nor does it describe the user-visible effects of this change.
Quoted 7 lines
AFAICT the effect is to issue a warning at mount-time to tell the user that the fs wasn't cleanly unmounted and that the user should fsck the volume, correct?
If so, why is this considered a desirable feature? (I can guess, but would prefer to hear it spelled out by the experts, please).
FAT is old and still intensively used file system with high number of data lost. This patch set is a try to reduce this numbers.
To make this work complete, we need some changes in user space too. But even stand alone, this patchset can warn M$ Windows 7 about probably damaged FS. In this case Win 7 will inform user and give option to start checkdisk.
Signature · 2 lines
Regards, Oleksij