Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

fat: cleanup the flags for fat_truncate_time

Fat only has a single on-disk timestamp covering ctime and mtime. Add
fat-specific flags that indicate which timestamp fat_truncate_time should
update to make this more clear. This allows removing no-op
fat_truncate_time calls with the S_CTIME flag and prepares for removing
the S_* flags.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Link: https://patch.msgid.link/20260108141934.2052404-5-hch@lst.de
Acked-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Signed-off-by: Christian Brauner <brauner@kernel.org>

authored by

Christoph Hellwig and committed by
Christian Brauner
1cbc8228 b8b3002f

+44 -51
+1 -1
fs/fat/dir.c
··· 1080 1080 } 1081 1081 } 1082 1082 1083 - fat_truncate_time(dir, NULL, S_ATIME|S_MTIME); 1083 + fat_truncate_time(dir, NULL, FAT_UPDATE_ATIME | FAT_UPDATE_CMTIME); 1084 1084 if (IS_DIRSYNC(dir)) 1085 1085 (void)fat_sync_inode(dir); 1086 1086 else
+4 -4
fs/fat/fat.h
··· 468 468 __le16 *time, __le16 *date, u8 *time_cs); 469 469 extern struct timespec64 fat_truncate_atime(const struct msdos_sb_info *sbi, 470 470 const struct timespec64 *ts); 471 - extern struct timespec64 fat_truncate_mtime(const struct msdos_sb_info *sbi, 472 - const struct timespec64 *ts); 473 - extern int fat_truncate_time(struct inode *inode, struct timespec64 *now, 474 - int flags); 471 + #define FAT_UPDATE_ATIME (1u << 0) 472 + #define FAT_UPDATE_CMTIME (1u << 1) 473 + void fat_truncate_time(struct inode *inode, struct timespec64 *now, 474 + unsigned int flags); 475 475 extern int fat_update_time(struct inode *inode, int flags); 476 476 extern int fat_sync_bhs(struct buffer_head **bhs, int nr_bhs); 477 477
+6 -8
fs/fat/file.c
··· 224 224 if (err) 225 225 goto out; 226 226 227 - fat_truncate_time(inode, NULL, S_CTIME|S_MTIME); 227 + fat_truncate_time(inode, NULL, FAT_UPDATE_CMTIME); 228 228 mark_inode_dirty(inode); 229 229 if (IS_SYNC(inode)) { 230 230 int err2; ··· 327 327 MSDOS_I(inode)->i_logstart = 0; 328 328 } 329 329 MSDOS_I(inode)->i_attrs |= ATTR_ARCH; 330 - fat_truncate_time(inode, NULL, S_CTIME|S_MTIME); 330 + fat_truncate_time(inode, NULL, FAT_UPDATE_CMTIME); 331 331 if (wait) { 332 332 err = fat_sync_inode(inode); 333 333 if (err) { ··· 553 553 } 554 554 555 555 /* 556 - * setattr_copy can't truncate these appropriately, so we'll 557 - * copy them ourselves 556 + * setattr_copy can't truncate these appropriately, so we'll copy them 557 + * ourselves. See fat_truncate_time for the c/mtime logic on fat. 558 558 */ 559 559 if (attr->ia_valid & ATTR_ATIME) 560 - fat_truncate_time(inode, &attr->ia_atime, S_ATIME); 561 - if (attr->ia_valid & ATTR_CTIME) 562 - fat_truncate_time(inode, &attr->ia_ctime, S_CTIME); 560 + fat_truncate_time(inode, &attr->ia_atime, FAT_UPDATE_ATIME); 563 561 if (attr->ia_valid & ATTR_MTIME) 564 - fat_truncate_time(inode, &attr->ia_mtime, S_MTIME); 562 + fat_truncate_time(inode, &attr->ia_mtime, FAT_UPDATE_CMTIME); 565 563 attr->ia_valid &= ~(ATTR_ATIME|ATTR_CTIME|ATTR_MTIME); 566 564 567 565 setattr_copy(idmap, inode, attr);
+1 -1
fs/fat/inode.c
··· 246 246 if (err < len) 247 247 fat_write_failed(mapping, pos + len); 248 248 if (!(err < 0) && !(MSDOS_I(inode)->i_attrs & ATTR_ARCH)) { 249 - fat_truncate_time(inode, NULL, S_CTIME|S_MTIME); 249 + fat_truncate_time(inode, NULL, FAT_UPDATE_CMTIME); 250 250 MSDOS_I(inode)->i_attrs |= ATTR_ARCH; 251 251 mark_inode_dirty(inode); 252 252 }
+23 -24
fs/fat/misc.c
··· 299 299 } 300 300 301 301 /* 302 - * truncate mtime to 2 second granularity 302 + * Update the in-inode atime and/or mtime after truncating the timestamp to the 303 + * granularity. All timestamps in root inode are always 0. 304 + * 305 + * ctime and mtime share the same on-disk field, and should be identical in 306 + * memory. All mtime updates will be applied to ctime, but ctime updates are 307 + * ignored. 303 308 */ 304 - struct timespec64 fat_truncate_mtime(const struct msdos_sb_info *sbi, 305 - const struct timespec64 *ts) 306 - { 307 - return fat_timespec64_trunc_2secs(*ts); 308 - } 309 - 310 - /* 311 - * truncate the various times with appropriate granularity: 312 - * all times in root node are always 0 313 - */ 314 - int fat_truncate_time(struct inode *inode, struct timespec64 *now, int flags) 309 + void fat_truncate_time(struct inode *inode, struct timespec64 *now, 310 + unsigned int flags) 315 311 { 316 312 struct msdos_sb_info *sbi = MSDOS_SB(inode->i_sb); 317 313 struct timespec64 ts; 318 314 319 315 if (inode->i_ino == MSDOS_ROOT_INO) 320 - return 0; 316 + return; 321 317 322 318 if (now == NULL) { 323 319 now = &ts; 324 320 ts = current_time(inode); 325 321 } 326 322 327 - if (flags & S_ATIME) 323 + if (flags & FAT_UPDATE_ATIME) 328 324 inode_set_atime_to_ts(inode, fat_truncate_atime(sbi, now)); 329 - /* 330 - * ctime and mtime share the same on-disk field, and should be 331 - * identical in memory. all mtime updates will be applied to ctime, 332 - * but ctime updates are ignored. 333 - */ 334 - if (flags & S_MTIME) 335 - inode_set_mtime_to_ts(inode, 336 - inode_set_ctime_to_ts(inode, fat_truncate_mtime(sbi, now))); 325 + if (flags & FAT_UPDATE_CMTIME) { 326 + /* truncate mtime to 2 second granularity */ 327 + struct timespec64 mtime = fat_timespec64_trunc_2secs(*now); 337 328 338 - return 0; 329 + inode_set_mtime_to_ts(inode, mtime); 330 + inode_set_ctime_to_ts(inode, mtime); 331 + } 339 332 } 340 333 EXPORT_SYMBOL_GPL(fat_truncate_time); 341 334 342 335 int fat_update_time(struct inode *inode, int flags) 343 336 { 337 + unsigned int fat_flags = 0; 344 338 int dirty_flags = 0; 345 339 346 340 if (inode->i_ino == MSDOS_ROOT_INO) 347 341 return 0; 348 342 349 - if (flags & (S_ATIME | S_CTIME | S_MTIME)) { 343 + if (flags & S_ATIME) 344 + fat_flags |= FAT_UPDATE_ATIME; 345 + if (flags & (S_CTIME | S_MTIME)) 346 + fat_flags |= FAT_UPDATE_CMTIME; 347 + 348 + if (fat_flags) { 350 349 fat_truncate_time(inode, NULL, flags); 351 350 if (inode->i_sb->s_flags & SB_LAZYTIME) 352 351 dirty_flags |= I_DIRTY_TIME;
+5 -8
fs/fat/namei_msdos.c
··· 251 251 if (err) 252 252 return err; 253 253 254 - fat_truncate_time(dir, ts, S_CTIME|S_MTIME); 254 + fat_truncate_time(dir, ts, FAT_UPDATE_CMTIME); 255 255 if (IS_DIRSYNC(dir)) 256 256 (void)fat_sync_inode(dir); 257 257 else ··· 295 295 err = PTR_ERR(inode); 296 296 goto out; 297 297 } 298 - fat_truncate_time(inode, &ts, S_ATIME|S_CTIME|S_MTIME); 298 + fat_truncate_time(inode, &ts, FAT_UPDATE_ATIME | FAT_UPDATE_CMTIME); 299 299 /* timestamp is already written, so mark_inode_dirty() is unneeded. */ 300 300 301 301 d_instantiate(dentry, inode); ··· 328 328 drop_nlink(dir); 329 329 330 330 clear_nlink(inode); 331 - fat_truncate_time(inode, NULL, S_CTIME); 332 331 fat_detach(inode); 333 332 out: 334 333 mutex_unlock(&MSDOS_SB(sb)->s_lock); ··· 381 382 goto out; 382 383 } 383 384 set_nlink(inode, 2); 384 - fat_truncate_time(inode, &ts, S_ATIME|S_CTIME|S_MTIME); 385 + fat_truncate_time(inode, &ts, FAT_UPDATE_ATIME | FAT_UPDATE_CMTIME); 385 386 /* timestamp is already written, so mark_inode_dirty() is unneeded. */ 386 387 387 388 d_instantiate(dentry, inode); ··· 414 415 if (err) 415 416 goto out; 416 417 clear_nlink(inode); 417 - fat_truncate_time(inode, NULL, S_CTIME); 418 418 fat_detach(inode); 419 419 out: 420 420 mutex_unlock(&MSDOS_SB(sb)->s_lock); ··· 478 480 mark_inode_dirty(old_inode); 479 481 480 482 inode_inc_iversion(old_dir); 481 - fat_truncate_time(old_dir, NULL, S_CTIME|S_MTIME); 483 + fat_truncate_time(old_dir, NULL, FAT_UPDATE_CMTIME); 482 484 if (IS_DIRSYNC(old_dir)) 483 485 (void)fat_sync_inode(old_dir); 484 486 else ··· 538 540 if (err) 539 541 goto error_dotdot; 540 542 inode_inc_iversion(old_dir); 541 - fat_truncate_time(old_dir, &ts, S_CTIME|S_MTIME); 543 + fat_truncate_time(old_dir, &ts, FAT_UPDATE_CMTIME); 542 544 if (IS_DIRSYNC(old_dir)) 543 545 (void)fat_sync_inode(old_dir); 544 546 else ··· 548 550 drop_nlink(new_inode); 549 551 if (is_dir) 550 552 drop_nlink(new_inode); 551 - fat_truncate_time(new_inode, &ts, S_CTIME); 552 553 } 553 554 out: 554 555 brelse(sinfo.bh);
+4 -5
fs/fat/namei_vfat.c
··· 676 676 goto cleanup; 677 677 678 678 /* update timestamp */ 679 - fat_truncate_time(dir, ts, S_CTIME|S_MTIME); 679 + fat_truncate_time(dir, ts, FAT_UPDATE_CMTIME); 680 680 if (IS_DIRSYNC(dir)) 681 681 (void)fat_sync_inode(dir); 682 682 else ··· 806 806 drop_nlink(dir); 807 807 808 808 clear_nlink(inode); 809 - fat_truncate_time(inode, NULL, S_ATIME|S_MTIME); 809 + fat_truncate_time(inode, NULL, FAT_UPDATE_ATIME | FAT_UPDATE_CMTIME); 810 810 fat_detach(inode); 811 811 vfat_d_version_set(dentry, inode_query_iversion(dir)); 812 812 out: ··· 832 832 if (err) 833 833 goto out; 834 834 clear_nlink(inode); 835 - fat_truncate_time(inode, NULL, S_ATIME|S_MTIME); 835 + fat_truncate_time(inode, NULL, FAT_UPDATE_ATIME | FAT_UPDATE_CMTIME); 836 836 fat_detach(inode); 837 837 vfat_d_version_set(dentry, inode_query_iversion(dir)); 838 838 out: ··· 918 918 static void vfat_update_dir_metadata(struct inode *dir, struct timespec64 *ts) 919 919 { 920 920 inode_inc_iversion(dir); 921 - fat_truncate_time(dir, ts, S_CTIME | S_MTIME); 921 + fat_truncate_time(dir, ts, FAT_UPDATE_CMTIME); 922 922 if (IS_DIRSYNC(dir)) 923 923 (void)fat_sync_inode(dir); 924 924 else ··· 996 996 drop_nlink(new_inode); 997 997 if (is_dir) 998 998 drop_nlink(new_inode); 999 - fat_truncate_time(new_inode, &ts, S_CTIME); 1000 999 } 1001 1000 out: 1002 1001 brelse(sinfo.bh);