hc
2024-05-11 645e752c5a84baeb21015cdc85fc05b7d16312c8
kernel/fs/fat/dir.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * linux/fs/fat/dir.c
34 *
....@@ -57,7 +58,7 @@
5758 if ((iblock & (sbi->sec_per_clus - 1)) || sbi->sec_per_clus == 1)
5859 return;
5960 /* root dir of FAT12/FAT16 */
60
- if ((sbi->fat_bits != 32) && (dir->i_ino == MSDOS_ROOT_INO))
61
+ if (!is_fat32(sbi) && (dir->i_ino == MSDOS_ROOT_INO))
6162 return;
6263
6364 bh = sb_find_get_block(sb, phys);
....@@ -87,9 +88,7 @@
8788 int err, offset;
8889
8990 next:
90
- if (*bh)
91
- brelse(*bh);
92
-
91
+ brelse(*bh);
9392 *bh = NULL;
9493 iblock = *pos >> sb->s_blocksize_bits;
9594 err = fat_bmap(dir, iblock, &phys, &mapped_blocks, 0, false);
....@@ -369,7 +368,9 @@
369368 }
370369
371370 memcpy(work, de->name, sizeof(work));
372
- /* see namei.c, msdos_format_name */
371
+ /* For an explanation of the special treatment of 0x05 in
372
+ * filenames, see msdos_format_name in namei_msdos.c
373
+ */
373374 if (work[0] == 0x05)
374375 work[0] = 0xE5;
375376
....@@ -803,8 +804,6 @@
803804 return fat_generic_ioctl(filp, cmd, arg);
804805 }
805806
806
- if (!access_ok(VERIFY_WRITE, d1, sizeof(struct __fat_dirent[2])))
807
- return -EFAULT;
808807 /*
809808 * Yes, we don't need this put_user() absolutely. However old
810809 * code didn't return the right value. So, app use this value,
....@@ -843,8 +842,6 @@
843842 return fat_generic_ioctl(filp, cmd, (unsigned long)arg);
844843 }
845844
846
- if (!access_ok(VERIFY_WRITE, d1, sizeof(struct compat_dirent[2])))
847
- return -EFAULT;
848845 /*
849846 * Yes, we don't need this put_user() absolutely. However old
850847 * code didn't return the right value. So, app use this value,
....@@ -1071,7 +1068,7 @@
10711068 }
10721069 }
10731070
1074
- dir->i_mtime = dir->i_atime = current_time(dir);
1071
+ fat_truncate_time(dir, NULL, S_ATIME|S_MTIME);
10751072 if (IS_DIRSYNC(dir))
10761073 (void)fat_sync_inode(dir);
10771074 else
....@@ -1287,7 +1284,7 @@
12871284 struct super_block *sb = dir->i_sb;
12881285 struct msdos_sb_info *sbi = MSDOS_SB(sb);
12891286 struct buffer_head *bh, *prev, *bhs[3]; /* 32*slots (672bytes) */
1290
- struct msdos_dir_entry *uninitialized_var(de);
1287
+ struct msdos_dir_entry *de;
12911288 int err, free_slots, i, nr_bhs;
12921289 loff_t pos, i_pos;
12931290
....@@ -1320,7 +1317,7 @@
13201317 }
13211318 }
13221319 if (dir->i_ino == MSDOS_ROOT_INO) {
1323
- if (sbi->fat_bits != 32)
1320
+ if (!is_fat32(sbi))
13241321 goto error;
13251322 } else if (MSDOS_I(dir)->i_start == 0) {
13261323 fat_msg(sb, KERN_ERR, "Corrupted directory (i_pos %lld)",