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.

Merge tag 'exfat-for-6.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/linkinjeon/exfat

Pull exfat updates from Namjae Jeon:

- Improve dirsync performance by syncing on a dentry-set rather than on
a per-directory entry

* tag 'exfat-for-6.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/linkinjeon/exfat:
exfat: remove duplicate update parent dir
exfat: do not sync parent dir if just update timestamp
exfat: remove unused functions
exfat: convert exfat_find_empty_entry() to use dentry cache
exfat: convert exfat_init_ext_entry() to use dentry cache
exfat: move free cluster out of exfat_init_ext_entry()
exfat: convert exfat_remove_entries() to use dentry cache
exfat: convert exfat_add_entry() to use dentry cache
exfat: add exfat_get_empty_dentry_set() helper
exfat: add __exfat_get_dentry_set() helper

+291 -374
+144 -146
fs/exfat/dir.c
··· 448 448 } 449 449 } 450 450 451 - int exfat_init_dir_entry(struct inode *inode, struct exfat_chain *p_dir, 452 - int entry, unsigned int type, unsigned int start_clu, 453 - unsigned long long size) 451 + void exfat_init_dir_entry(struct exfat_entry_set_cache *es, 452 + unsigned int type, unsigned int start_clu, 453 + unsigned long long size, struct timespec64 *ts) 454 454 { 455 - struct super_block *sb = inode->i_sb; 455 + struct super_block *sb = es->sb; 456 456 struct exfat_sb_info *sbi = EXFAT_SB(sb); 457 - struct timespec64 ts = current_time(inode); 458 457 struct exfat_dentry *ep; 459 - struct buffer_head *bh; 460 458 461 - /* 462 - * We cannot use exfat_get_dentry_set here because file ep is not 463 - * initialized yet. 464 - */ 465 - ep = exfat_get_dentry(sb, p_dir, entry, &bh); 466 - if (!ep) 467 - return -EIO; 468 - 459 + ep = exfat_get_dentry_cached(es, ES_IDX_FILE); 469 460 exfat_set_entry_type(ep, type); 470 - exfat_set_entry_time(sbi, &ts, 461 + exfat_set_entry_time(sbi, ts, 471 462 &ep->dentry.file.create_tz, 472 463 &ep->dentry.file.create_time, 473 464 &ep->dentry.file.create_date, 474 465 &ep->dentry.file.create_time_cs); 475 - exfat_set_entry_time(sbi, &ts, 466 + exfat_set_entry_time(sbi, ts, 476 467 &ep->dentry.file.modify_tz, 477 468 &ep->dentry.file.modify_time, 478 469 &ep->dentry.file.modify_date, 479 470 &ep->dentry.file.modify_time_cs); 480 - exfat_set_entry_time(sbi, &ts, 471 + exfat_set_entry_time(sbi, ts, 481 472 &ep->dentry.file.access_tz, 482 473 &ep->dentry.file.access_time, 483 474 &ep->dentry.file.access_date, 484 475 NULL); 485 476 486 - exfat_update_bh(bh, IS_DIRSYNC(inode)); 487 - brelse(bh); 488 - 489 - ep = exfat_get_dentry(sb, p_dir, entry + 1, &bh); 490 - if (!ep) 491 - return -EIO; 492 - 477 + ep = exfat_get_dentry_cached(es, ES_IDX_STREAM); 493 478 exfat_init_stream_entry(ep, start_clu, size); 494 - exfat_update_bh(bh, IS_DIRSYNC(inode)); 495 - brelse(bh); 496 - 497 - return 0; 498 - } 499 - 500 - int exfat_update_dir_chksum(struct inode *inode, struct exfat_chain *p_dir, 501 - int entry) 502 - { 503 - struct super_block *sb = inode->i_sb; 504 - int ret = 0; 505 - int i, num_entries; 506 - u16 chksum; 507 - struct exfat_dentry *ep, *fep; 508 - struct buffer_head *fbh, *bh; 509 - 510 - fep = exfat_get_dentry(sb, p_dir, entry, &fbh); 511 - if (!fep) 512 - return -EIO; 513 - 514 - num_entries = fep->dentry.file.num_ext + 1; 515 - chksum = exfat_calc_chksum16(fep, DENTRY_SIZE, 0, CS_DIR_ENTRY); 516 - 517 - for (i = 1; i < num_entries; i++) { 518 - ep = exfat_get_dentry(sb, p_dir, entry + i, &bh); 519 - if (!ep) { 520 - ret = -EIO; 521 - goto release_fbh; 522 - } 523 - chksum = exfat_calc_chksum16(ep, DENTRY_SIZE, chksum, 524 - CS_DEFAULT); 525 - brelse(bh); 526 - } 527 - 528 - fep->dentry.file.checksum = cpu_to_le16(chksum); 529 - exfat_update_bh(fbh, IS_DIRSYNC(inode)); 530 - release_fbh: 531 - brelse(fbh); 532 - return ret; 533 479 } 534 480 535 481 static void exfat_free_benign_secondary_clusters(struct inode *inode, ··· 497 551 exfat_free_cluster(inode, &dir); 498 552 } 499 553 500 - int exfat_init_ext_entry(struct inode *inode, struct exfat_chain *p_dir, 501 - int entry, int num_entries, struct exfat_uni_name *p_uniname) 554 + void exfat_init_ext_entry(struct exfat_entry_set_cache *es, int num_entries, 555 + struct exfat_uni_name *p_uniname) 502 556 { 503 - struct super_block *sb = inode->i_sb; 504 557 int i; 505 558 unsigned short *uniname = p_uniname->name; 506 559 struct exfat_dentry *ep; 507 - struct buffer_head *bh; 508 - int sync = IS_DIRSYNC(inode); 509 560 510 - ep = exfat_get_dentry(sb, p_dir, entry, &bh); 511 - if (!ep) 512 - return -EIO; 513 - 561 + ep = exfat_get_dentry_cached(es, ES_IDX_FILE); 514 562 ep->dentry.file.num_ext = (unsigned char)(num_entries - 1); 515 - exfat_update_bh(bh, sync); 516 - brelse(bh); 517 563 518 - ep = exfat_get_dentry(sb, p_dir, entry + 1, &bh); 519 - if (!ep) 520 - return -EIO; 521 - 564 + ep = exfat_get_dentry_cached(es, ES_IDX_STREAM); 522 565 ep->dentry.stream.name_len = p_uniname->name_len; 523 566 ep->dentry.stream.name_hash = cpu_to_le16(p_uniname->name_hash); 524 - exfat_update_bh(bh, sync); 525 - brelse(bh); 526 567 527 - for (i = EXFAT_FIRST_CLUSTER; i < num_entries; i++) { 528 - ep = exfat_get_dentry(sb, p_dir, entry + i, &bh); 529 - if (!ep) 530 - return -EIO; 531 - 532 - if (exfat_get_entry_type(ep) & TYPE_BENIGN_SEC) 533 - exfat_free_benign_secondary_clusters(inode, ep); 534 - 568 + for (i = ES_IDX_FIRST_FILENAME; i < num_entries; i++) { 569 + ep = exfat_get_dentry_cached(es, i); 535 570 exfat_init_name_entry(ep, uniname); 536 - exfat_update_bh(bh, sync); 537 - brelse(bh); 538 571 uniname += EXFAT_FILE_NAME_LEN; 539 572 } 540 573 541 - exfat_update_dir_chksum(inode, p_dir, entry); 542 - return 0; 574 + exfat_update_dir_chksum(es); 543 575 } 544 576 545 - int exfat_remove_entries(struct inode *inode, struct exfat_chain *p_dir, 546 - int entry, int order, int num_entries) 577 + void exfat_remove_entries(struct inode *inode, struct exfat_entry_set_cache *es, 578 + int order) 547 579 { 548 - struct super_block *sb = inode->i_sb; 549 580 int i; 550 581 struct exfat_dentry *ep; 551 - struct buffer_head *bh; 552 582 553 - for (i = order; i < num_entries; i++) { 554 - ep = exfat_get_dentry(sb, p_dir, entry + i, &bh); 555 - if (!ep) 556 - return -EIO; 583 + for (i = order; i < es->num_entries; i++) { 584 + ep = exfat_get_dentry_cached(es, i); 557 585 558 586 if (exfat_get_entry_type(ep) & TYPE_BENIGN_SEC) 559 587 exfat_free_benign_secondary_clusters(inode, ep); 560 588 561 589 exfat_set_entry_type(ep, TYPE_DELETED); 562 - exfat_update_bh(bh, IS_DIRSYNC(inode)); 563 - brelse(bh); 564 590 } 565 591 566 - return 0; 592 + if (order < es->num_entries) 593 + es->modified = true; 567 594 } 568 595 569 - void exfat_update_dir_chksum_with_entry_set(struct exfat_entry_set_cache *es) 596 + void exfat_update_dir_chksum(struct exfat_entry_set_cache *es) 570 597 { 571 598 int chksum_type = CS_DIR_ENTRY, i; 572 599 unsigned short chksum = 0; ··· 694 775 } 695 776 696 777 enum exfat_validate_dentry_mode { 697 - ES_MODE_STARTED, 698 778 ES_MODE_GET_FILE_ENTRY, 699 779 ES_MODE_GET_STRM_ENTRY, 700 780 ES_MODE_GET_NAME_ENTRY, ··· 708 790 return false; 709 791 710 792 switch (*mode) { 711 - case ES_MODE_STARTED: 712 - if (type != TYPE_FILE && type != TYPE_DIR) 713 - return false; 714 - *mode = ES_MODE_GET_FILE_ENTRY; 715 - break; 716 793 case ES_MODE_GET_FILE_ENTRY: 717 794 if (type != TYPE_STREAM) 718 795 return false; ··· 747 834 } 748 835 749 836 /* 750 - * Returns a set of dentries for a file or dir. 837 + * Returns a set of dentries. 751 838 * 752 839 * Note It provides a direct pointer to bh->data via exfat_get_dentry_cached(). 753 840 * User should call exfat_get_dentry_set() after setting 'modified' to apply ··· 755 842 * 756 843 * in: 757 844 * sb+p_dir+entry: indicates a file/dir 758 - * type: specifies how many dentries should be included. 845 + * num_entries: specifies how many dentries should be included. 846 + * It will be set to es->num_entries if it is not 0. 847 + * If num_entries is 0, es->num_entries will be obtained 848 + * from the first dentry. 849 + * out: 850 + * es: pointer of entry set on success. 759 851 * return: 760 - * pointer of entry set on success, 761 - * NULL on failure. 852 + * 0 on success 853 + * -error code on failure 762 854 */ 763 - int exfat_get_dentry_set(struct exfat_entry_set_cache *es, 855 + static int __exfat_get_dentry_set(struct exfat_entry_set_cache *es, 764 856 struct super_block *sb, struct exfat_chain *p_dir, int entry, 765 - unsigned int type) 857 + unsigned int num_entries) 766 858 { 767 859 int ret, i, num_bh; 768 860 unsigned int off; 769 861 sector_t sec; 770 862 struct exfat_sb_info *sbi = EXFAT_SB(sb); 771 - struct exfat_dentry *ep; 772 - int num_entries; 773 - enum exfat_validate_dentry_mode mode = ES_MODE_STARTED; 774 863 struct buffer_head *bh; 775 864 776 865 if (p_dir->dir == DIR_DELETED) { ··· 795 880 return -EIO; 796 881 es->bh[es->num_bh++] = bh; 797 882 798 - ep = exfat_get_dentry_cached(es, ES_IDX_FILE); 799 - if (!exfat_validate_entry(exfat_get_entry_type(ep), &mode)) 800 - goto put_es; 883 + if (num_entries == ES_ALL_ENTRIES) { 884 + struct exfat_dentry *ep; 801 885 802 - num_entries = type == ES_ALL_ENTRIES ? 803 - ep->dentry.file.num_ext + 1 : type; 886 + ep = exfat_get_dentry_cached(es, ES_IDX_FILE); 887 + if (ep->type != EXFAT_FILE) { 888 + brelse(bh); 889 + return -EIO; 890 + } 891 + 892 + num_entries = ep->dentry.file.num_ext + 1; 893 + } 894 + 804 895 es->num_entries = num_entries; 805 896 806 897 num_bh = EXFAT_B_TO_BLK_ROUND_UP(off + num_entries * DENTRY_SIZE, sb); ··· 839 918 es->bh[es->num_bh++] = bh; 840 919 } 841 920 921 + return 0; 922 + 923 + put_es: 924 + exfat_put_dentry_set(es, false); 925 + return -EIO; 926 + } 927 + 928 + int exfat_get_dentry_set(struct exfat_entry_set_cache *es, 929 + struct super_block *sb, struct exfat_chain *p_dir, 930 + int entry, unsigned int num_entries) 931 + { 932 + int ret, i; 933 + struct exfat_dentry *ep; 934 + enum exfat_validate_dentry_mode mode = ES_MODE_GET_FILE_ENTRY; 935 + 936 + ret = __exfat_get_dentry_set(es, sb, p_dir, entry, num_entries); 937 + if (ret < 0) 938 + return ret; 939 + 842 940 /* validate cached dentries */ 843 - for (i = ES_IDX_STREAM; i < num_entries; i++) { 941 + for (i = ES_IDX_STREAM; i < es->num_entries; i++) { 844 942 ep = exfat_get_dentry_cached(es, i); 845 943 if (!exfat_validate_entry(exfat_get_entry_type(ep), &mode)) 846 944 goto put_es; ··· 869 929 put_es: 870 930 exfat_put_dentry_set(es, false); 871 931 return -EIO; 932 + } 933 + 934 + static int exfat_validate_empty_dentry_set(struct exfat_entry_set_cache *es) 935 + { 936 + struct exfat_dentry *ep; 937 + struct buffer_head *bh; 938 + int i, off; 939 + bool unused_hit = false; 940 + 941 + /* 942 + * ONLY UNUSED OR DELETED DENTRIES ARE ALLOWED: 943 + * Although it violates the specification for a deleted entry to 944 + * follow an unused entry, some exFAT implementations could work 945 + * like this. Therefore, to improve compatibility, let's allow it. 946 + */ 947 + for (i = 0; i < es->num_entries; i++) { 948 + ep = exfat_get_dentry_cached(es, i); 949 + if (ep->type == EXFAT_UNUSED) { 950 + unused_hit = true; 951 + } else if (!IS_EXFAT_DELETED(ep->type)) { 952 + if (unused_hit) 953 + goto err_used_follow_unused; 954 + i++; 955 + goto count_skip_entries; 956 + } 957 + } 958 + 959 + return 0; 960 + 961 + err_used_follow_unused: 962 + off = es->start_off + (i << DENTRY_SIZE_BITS); 963 + bh = es->bh[EXFAT_B_TO_BLK(off, es->sb)]; 964 + 965 + exfat_fs_error(es->sb, 966 + "in sector %lld, dentry %d should be unused, but 0x%x", 967 + bh->b_blocknr, off >> DENTRY_SIZE_BITS, ep->type); 968 + 969 + return -EIO; 970 + 971 + count_skip_entries: 972 + es->num_entries = EXFAT_B_TO_DEN(EXFAT_BLK_TO_B(es->num_bh, es->sb) - es->start_off); 973 + for (; i < es->num_entries; i++) { 974 + ep = exfat_get_dentry_cached(es, i); 975 + if (IS_EXFAT_DELETED(ep->type)) 976 + break; 977 + } 978 + 979 + return i; 980 + } 981 + 982 + /* 983 + * Get an empty dentry set. 984 + * 985 + * in: 986 + * sb+p_dir+entry: indicates the empty dentry location 987 + * num_entries: specifies how many empty dentries should be included. 988 + * out: 989 + * es: pointer of empty dentry set on success. 990 + * return: 991 + * 0 : on success 992 + * >0 : the dentries are not empty, the return value is the number of 993 + * dentries to be skipped for the next lookup. 994 + * <0 : on failure 995 + */ 996 + int exfat_get_empty_dentry_set(struct exfat_entry_set_cache *es, 997 + struct super_block *sb, struct exfat_chain *p_dir, 998 + int entry, unsigned int num_entries) 999 + { 1000 + int ret; 1001 + 1002 + ret = __exfat_get_dentry_set(es, sb, p_dir, entry, num_entries); 1003 + if (ret < 0) 1004 + return ret; 1005 + 1006 + ret = exfat_validate_empty_dentry_set(es); 1007 + if (ret) 1008 + exfat_put_dentry_set(es, false); 1009 + 1010 + return ret; 872 1011 } 873 1012 874 1013 static inline void exfat_reset_empty_hint(struct exfat_hint_femp *hint_femp) ··· 1204 1185 hint_stat->clu = clu.dir; 1205 1186 hint_stat->eidx = dentry + 1; 1206 1187 return dentry - num_ext; 1207 - } 1208 - 1209 - int exfat_count_ext_entries(struct super_block *sb, struct exfat_chain *p_dir, 1210 - int entry, struct exfat_dentry *ep) 1211 - { 1212 - int i, count = 0; 1213 - unsigned int type; 1214 - struct exfat_dentry *ext_ep; 1215 - struct buffer_head *bh; 1216 - 1217 - for (i = 0, entry++; i < ep->dentry.file.num_ext; i++, entry++) { 1218 - ext_ep = exfat_get_dentry(sb, p_dir, entry, &bh); 1219 - if (!ext_ep) 1220 - return -EIO; 1221 - 1222 - type = exfat_get_entry_type(ext_ep); 1223 - brelse(bh); 1224 - if (type & TYPE_CRITICAL_SEC || type & TYPE_BENIGN_SEC) 1225 - count++; 1226 - } 1227 - return count; 1228 1188 } 1229 1189 1230 1190 int exfat_count_dir_entries(struct super_block *sb, struct exfat_chain *p_dir)
+12 -13
fs/exfat/exfat_fs.h
··· 431 431 unsigned int *content); 432 432 int exfat_ent_set(struct super_block *sb, unsigned int loc, 433 433 unsigned int content); 434 - int exfat_count_ext_entries(struct super_block *sb, struct exfat_chain *p_dir, 435 - int entry, struct exfat_dentry *p_entry); 436 434 int exfat_chain_cont_cluster(struct super_block *sb, unsigned int chain, 437 435 unsigned int len); 438 436 int exfat_zeroed_cluster(struct inode *dir, unsigned int clu); ··· 478 480 extern const struct inode_operations exfat_dir_inode_operations; 479 481 extern const struct file_operations exfat_dir_operations; 480 482 unsigned int exfat_get_entry_type(struct exfat_dentry *p_entry); 481 - int exfat_init_dir_entry(struct inode *inode, struct exfat_chain *p_dir, 482 - int entry, unsigned int type, unsigned int start_clu, 483 - unsigned long long size); 484 - int exfat_init_ext_entry(struct inode *inode, struct exfat_chain *p_dir, 485 - int entry, int num_entries, struct exfat_uni_name *p_uniname); 486 - int exfat_remove_entries(struct inode *inode, struct exfat_chain *p_dir, 487 - int entry, int order, int num_entries); 488 - int exfat_update_dir_chksum(struct inode *inode, struct exfat_chain *p_dir, 489 - int entry); 490 - void exfat_update_dir_chksum_with_entry_set(struct exfat_entry_set_cache *es); 483 + void exfat_init_dir_entry(struct exfat_entry_set_cache *es, 484 + unsigned int type, unsigned int start_clu, 485 + unsigned long long size, struct timespec64 *ts); 486 + void exfat_init_ext_entry(struct exfat_entry_set_cache *es, int num_entries, 487 + struct exfat_uni_name *p_uniname); 488 + void exfat_remove_entries(struct inode *inode, struct exfat_entry_set_cache *es, 489 + int order); 490 + void exfat_update_dir_chksum(struct exfat_entry_set_cache *es); 491 491 int exfat_calc_num_entries(struct exfat_uni_name *p_uniname); 492 492 int exfat_find_dir_entry(struct super_block *sb, struct exfat_inode_info *ei, 493 493 struct exfat_chain *p_dir, struct exfat_uni_name *p_uniname, ··· 497 501 int num); 498 502 int exfat_get_dentry_set(struct exfat_entry_set_cache *es, 499 503 struct super_block *sb, struct exfat_chain *p_dir, int entry, 500 - unsigned int type); 504 + unsigned int num_entries); 505 + int exfat_get_empty_dentry_set(struct exfat_entry_set_cache *es, 506 + struct super_block *sb, struct exfat_chain *p_dir, int entry, 507 + unsigned int num_entries); 501 508 int exfat_put_dentry_set(struct exfat_entry_set_cache *es, int sync); 502 509 int exfat_count_dir_entries(struct super_block *sb, struct exfat_chain *p_dir); 503 510
+1 -1
fs/exfat/inode.c
··· 94 94 ep2->dentry.stream.start_clu = EXFAT_FREE_CLUSTER; 95 95 } 96 96 97 - exfat_update_dir_chksum_with_entry_set(&es); 97 + exfat_update_dir_chksum(&es); 98 98 return exfat_put_dentry_set(&es, sync); 99 99 } 100 100
+134 -214
fs/exfat/namei.c
··· 204 204 .d_compare = exfat_utf8_d_cmp, 205 205 }; 206 206 207 - /* used only in search empty_slot() */ 208 - #define CNT_UNUSED_NOHIT (-1) 209 - #define CNT_UNUSED_HIT (-2) 210 207 /* search EMPTY CONTINUOUS "num_entries" entries */ 211 208 static int exfat_search_empty_slot(struct super_block *sb, 212 209 struct exfat_hint_femp *hint_femp, struct exfat_chain *p_dir, 213 - int num_entries) 210 + int num_entries, struct exfat_entry_set_cache *es) 214 211 { 215 - int i, dentry, num_empty = 0; 212 + int i, dentry, ret; 216 213 int dentries_per_clu; 217 - unsigned int type; 218 214 struct exfat_chain clu; 219 - struct exfat_dentry *ep; 220 215 struct exfat_sb_info *sbi = EXFAT_SB(sb); 221 - struct buffer_head *bh; 216 + int total_entries = EXFAT_CLU_TO_DEN(p_dir->size, sbi); 222 217 223 218 dentries_per_clu = sbi->dentries_per_clu; 224 219 ··· 226 231 * Otherwise, and if "dentry + hint_famp->count" is also equal 227 232 * to "p_dir->size * dentries_per_clu", it means ENOSPC. 228 233 */ 229 - if (dentry + hint_femp->count == p_dir->size * dentries_per_clu && 234 + if (dentry + hint_femp->count == total_entries && 230 235 num_entries > hint_femp->count) 231 236 return -ENOSPC; 232 237 ··· 237 242 dentry = 0; 238 243 } 239 244 240 - while (clu.dir != EXFAT_EOF_CLUSTER) { 245 + while (dentry + num_entries < total_entries && 246 + clu.dir != EXFAT_EOF_CLUSTER) { 241 247 i = dentry & (dentries_per_clu - 1); 242 248 243 - for (; i < dentries_per_clu; i++, dentry++) { 244 - ep = exfat_get_dentry(sb, &clu, i, &bh); 245 - if (!ep) 246 - return -EIO; 247 - type = exfat_get_entry_type(ep); 248 - brelse(bh); 249 + ret = exfat_get_empty_dentry_set(es, sb, &clu, i, num_entries); 250 + if (ret < 0) 251 + return ret; 252 + else if (ret == 0) 253 + return dentry; 249 254 250 - if (type == TYPE_UNUSED || type == TYPE_DELETED) { 251 - num_empty++; 252 - if (hint_femp->eidx == EXFAT_HINT_NONE) { 253 - hint_femp->eidx = dentry; 254 - hint_femp->count = CNT_UNUSED_NOHIT; 255 - exfat_chain_set(&hint_femp->cur, 256 - clu.dir, clu.size, clu.flags); 257 - } 255 + dentry += ret; 256 + i += ret; 258 257 259 - if (type == TYPE_UNUSED && 260 - hint_femp->count != CNT_UNUSED_HIT) 261 - hint_femp->count = CNT_UNUSED_HIT; 258 + while (i >= dentries_per_clu) { 259 + if (clu.flags == ALLOC_NO_FAT_CHAIN) { 260 + if (--clu.size > 0) 261 + clu.dir++; 262 + else 263 + clu.dir = EXFAT_EOF_CLUSTER; 262 264 } else { 263 - if (hint_femp->eidx != EXFAT_HINT_NONE && 264 - hint_femp->count == CNT_UNUSED_HIT) { 265 - /* unused empty group means 266 - * an empty group which includes 267 - * unused dentry 268 - */ 269 - exfat_fs_error(sb, 270 - "found bogus dentry(%d) beyond unused empty group(%d) (start_clu : %u, cur_clu : %u)", 271 - dentry, hint_femp->eidx, 272 - p_dir->dir, clu.dir); 265 + if (exfat_get_next_cluster(sb, &clu.dir)) 273 266 return -EIO; 274 - } 275 - 276 - num_empty = 0; 277 - hint_femp->eidx = EXFAT_HINT_NONE; 278 267 } 279 268 280 - if (num_empty >= num_entries) { 281 - /* found and invalidate hint_femp */ 282 - hint_femp->eidx = EXFAT_HINT_NONE; 283 - return (dentry - (num_entries - 1)); 284 - } 285 - } 286 - 287 - if (clu.flags == ALLOC_NO_FAT_CHAIN) { 288 - if (--clu.size > 0) 289 - clu.dir++; 290 - else 291 - clu.dir = EXFAT_EOF_CLUSTER; 292 - } else { 293 - if (exfat_get_next_cluster(sb, &clu.dir)) 294 - return -EIO; 269 + i -= dentries_per_clu; 295 270 } 296 271 } 297 272 298 - hint_femp->eidx = p_dir->size * dentries_per_clu - num_empty; 299 - hint_femp->count = num_empty; 300 - if (num_empty == 0) 273 + hint_femp->eidx = dentry; 274 + hint_femp->count = 0; 275 + if (dentry == total_entries || clu.dir == EXFAT_EOF_CLUSTER) 301 276 exfat_chain_set(&hint_femp->cur, EXFAT_EOF_CLUSTER, 0, 302 277 clu.flags); 278 + else 279 + hint_femp->cur = clu; 303 280 304 281 return -ENOSPC; 305 282 } ··· 292 325 * if there isn't any empty slot, expand cluster chain. 293 326 */ 294 327 static int exfat_find_empty_entry(struct inode *inode, 295 - struct exfat_chain *p_dir, int num_entries) 328 + struct exfat_chain *p_dir, int num_entries, 329 + struct exfat_entry_set_cache *es) 296 330 { 297 331 int dentry; 298 332 unsigned int ret, last_clu; ··· 312 344 } 313 345 314 346 while ((dentry = exfat_search_empty_slot(sb, &hint_femp, p_dir, 315 - num_entries)) < 0) { 347 + num_entries, es)) < 0) { 316 348 if (dentry == -EIO) 317 349 break; 318 350 ··· 467 499 struct exfat_sb_info *sbi = EXFAT_SB(sb); 468 500 struct exfat_uni_name uniname; 469 501 struct exfat_chain clu; 502 + struct timespec64 ts = current_time(inode); 503 + struct exfat_entry_set_cache es; 470 504 int clu_size = 0; 471 505 unsigned int start_clu = EXFAT_FREE_CLUSTER; 472 506 ··· 483 513 } 484 514 485 515 /* exfat_find_empty_entry must be called before alloc_cluster() */ 486 - dentry = exfat_find_empty_entry(inode, p_dir, num_entries); 516 + dentry = exfat_find_empty_entry(inode, p_dir, num_entries, &es); 487 517 if (dentry < 0) { 488 518 ret = dentry; /* -EIO or -ENOSPC */ 489 519 goto out; ··· 491 521 492 522 if (type == TYPE_DIR && !sbi->options.zero_size_dir) { 493 523 ret = exfat_alloc_new_dir(inode, &clu); 494 - if (ret) 524 + if (ret) { 525 + exfat_put_dentry_set(&es, false); 495 526 goto out; 527 + } 496 528 start_clu = clu.dir; 497 529 clu_size = sbi->cluster_size; 498 530 } ··· 503 531 /* fill the dos name directory entry information of the created file. 504 532 * the first cluster is not determined yet. (0) 505 533 */ 506 - ret = exfat_init_dir_entry(inode, p_dir, dentry, type, 507 - start_clu, clu_size); 508 - if (ret) 509 - goto out; 534 + exfat_init_dir_entry(&es, type, start_clu, clu_size, &ts); 535 + exfat_init_ext_entry(&es, num_entries, &uniname); 510 536 511 - ret = exfat_init_ext_entry(inode, p_dir, dentry, num_entries, &uniname); 537 + ret = exfat_put_dentry_set(&es, IS_DIRSYNC(inode)); 512 538 if (ret) 513 539 goto out; 514 540 ··· 547 577 struct exfat_dir_entry info; 548 578 loff_t i_pos; 549 579 int err; 580 + loff_t size = i_size_read(dir); 550 581 551 582 mutex_lock(&EXFAT_SB(sb)->s_lock); 552 583 exfat_set_volume_dirty(sb); ··· 558 587 559 588 inode_inc_iversion(dir); 560 589 inode_set_mtime_to_ts(dir, inode_set_ctime_current(dir)); 561 - if (IS_DIRSYNC(dir)) 590 + if (IS_DIRSYNC(dir) && size != i_size_read(dir)) 562 591 exfat_sync_inode(dir); 563 592 else 564 593 mark_inode_dirty(dir); ··· 766 795 static int exfat_unlink(struct inode *dir, struct dentry *dentry) 767 796 { 768 797 struct exfat_chain cdir; 769 - struct exfat_dentry *ep; 770 798 struct super_block *sb = dir->i_sb; 771 799 struct inode *inode = dentry->d_inode; 772 800 struct exfat_inode_info *ei = EXFAT_I(inode); 773 - struct buffer_head *bh; 774 - int num_entries, entry, err = 0; 801 + struct exfat_entry_set_cache es; 802 + int entry, err = 0; 775 803 776 804 mutex_lock(&EXFAT_SB(sb)->s_lock); 777 805 exfat_chain_dup(&cdir, &ei->dir); ··· 781 811 goto unlock; 782 812 } 783 813 784 - ep = exfat_get_dentry(sb, &cdir, entry, &bh); 785 - if (!ep) { 814 + err = exfat_get_dentry_set(&es, sb, &cdir, entry, ES_ALL_ENTRIES); 815 + if (err) { 786 816 err = -EIO; 787 817 goto unlock; 788 818 } 789 - num_entries = exfat_count_ext_entries(sb, &cdir, entry, ep); 790 - if (num_entries < 0) { 791 - err = -EIO; 792 - brelse(bh); 793 - goto unlock; 794 - } 795 - num_entries++; 796 - brelse(bh); 797 819 798 820 exfat_set_volume_dirty(sb); 821 + 799 822 /* update the directory entry */ 800 - if (exfat_remove_entries(dir, &cdir, entry, 0, num_entries)) { 801 - err = -EIO; 823 + exfat_remove_entries(inode, &es, ES_IDX_FILE); 824 + 825 + err = exfat_put_dentry_set(&es, IS_DIRSYNC(inode)); 826 + if (err) 802 827 goto unlock; 803 - } 804 828 805 829 /* This doesn't modify ei */ 806 830 ei->dir.dir = DIR_DELETED; ··· 802 838 inode_inc_iversion(dir); 803 839 simple_inode_init_ts(dir); 804 840 exfat_truncate_inode_atime(dir); 805 - if (IS_DIRSYNC(dir)) 806 - exfat_sync_inode(dir); 807 - else 808 - mark_inode_dirty(dir); 841 + mark_inode_dirty(dir); 809 842 810 843 clear_nlink(inode); 811 844 simple_inode_init_ts(inode); ··· 823 862 struct exfat_chain cdir; 824 863 loff_t i_pos; 825 864 int err; 865 + loff_t size = i_size_read(dir); 826 866 827 867 mutex_lock(&EXFAT_SB(sb)->s_lock); 828 868 exfat_set_volume_dirty(sb); ··· 834 872 835 873 inode_inc_iversion(dir); 836 874 inode_set_mtime_to_ts(dir, inode_set_ctime_current(dir)); 837 - if (IS_DIRSYNC(dir)) 875 + if (IS_DIRSYNC(dir) && size != i_size_read(dir)) 838 876 exfat_sync_inode(dir); 839 877 else 840 878 mark_inode_dirty(dir); ··· 908 946 static int exfat_rmdir(struct inode *dir, struct dentry *dentry) 909 947 { 910 948 struct inode *inode = dentry->d_inode; 911 - struct exfat_dentry *ep; 912 949 struct exfat_chain cdir, clu_to_free; 913 950 struct super_block *sb = inode->i_sb; 914 951 struct exfat_sb_info *sbi = EXFAT_SB(sb); 915 952 struct exfat_inode_info *ei = EXFAT_I(inode); 916 - struct buffer_head *bh; 917 - int num_entries, entry, err; 953 + struct exfat_entry_set_cache es; 954 + int entry, err; 918 955 919 956 mutex_lock(&EXFAT_SB(inode->i_sb)->s_lock); 920 957 ··· 937 976 goto unlock; 938 977 } 939 978 940 - ep = exfat_get_dentry(sb, &cdir, entry, &bh); 941 - if (!ep) { 979 + err = exfat_get_dentry_set(&es, sb, &cdir, entry, ES_ALL_ENTRIES); 980 + if (err) { 942 981 err = -EIO; 943 982 goto unlock; 944 983 } 945 - 946 - num_entries = exfat_count_ext_entries(sb, &cdir, entry, ep); 947 - if (num_entries < 0) { 948 - err = -EIO; 949 - brelse(bh); 950 - goto unlock; 951 - } 952 - num_entries++; 953 - brelse(bh); 954 984 955 985 exfat_set_volume_dirty(sb); 956 - err = exfat_remove_entries(dir, &cdir, entry, 0, num_entries); 957 - if (err) { 958 - exfat_err(sb, "failed to exfat_remove_entries : err(%d)", err); 986 + 987 + exfat_remove_entries(inode, &es, ES_IDX_FILE); 988 + 989 + err = exfat_put_dentry_set(&es, IS_DIRSYNC(dir)); 990 + if (err) 959 991 goto unlock; 960 - } 992 + 961 993 ei->dir.dir = DIR_DELETED; 962 994 963 995 inode_inc_iversion(dir); ··· 976 1022 int oldentry, struct exfat_uni_name *p_uniname, 977 1023 struct exfat_inode_info *ei) 978 1024 { 979 - int ret, num_old_entries, num_new_entries; 1025 + int ret, num_new_entries; 980 1026 struct exfat_dentry *epold, *epnew; 981 1027 struct super_block *sb = inode->i_sb; 982 - struct buffer_head *new_bh, *old_bh; 1028 + struct exfat_entry_set_cache old_es, new_es; 983 1029 int sync = IS_DIRSYNC(inode); 984 - 985 - epold = exfat_get_dentry(sb, p_dir, oldentry, &old_bh); 986 - if (!epold) 987 - return -EIO; 988 - 989 - num_old_entries = exfat_count_ext_entries(sb, p_dir, oldentry, epold); 990 - if (num_old_entries < 0) 991 - return -EIO; 992 - num_old_entries++; 993 1030 994 1031 num_new_entries = exfat_calc_num_entries(p_uniname); 995 1032 if (num_new_entries < 0) 996 1033 return num_new_entries; 997 1034 998 - if (num_old_entries < num_new_entries) { 1035 + ret = exfat_get_dentry_set(&old_es, sb, p_dir, oldentry, ES_ALL_ENTRIES); 1036 + if (ret) { 1037 + ret = -EIO; 1038 + return ret; 1039 + } 1040 + 1041 + epold = exfat_get_dentry_cached(&old_es, ES_IDX_FILE); 1042 + 1043 + if (old_es.num_entries < num_new_entries) { 999 1044 int newentry; 1000 1045 1001 - newentry = 1002 - exfat_find_empty_entry(inode, p_dir, num_new_entries); 1003 - if (newentry < 0) 1004 - return newentry; /* -EIO or -ENOSPC */ 1046 + newentry = exfat_find_empty_entry(inode, p_dir, num_new_entries, 1047 + &new_es); 1048 + if (newentry < 0) { 1049 + ret = newentry; /* -EIO or -ENOSPC */ 1050 + goto put_old_es; 1051 + } 1005 1052 1006 - epnew = exfat_get_dentry(sb, p_dir, newentry, &new_bh); 1007 - if (!epnew) 1008 - return -EIO; 1009 - 1053 + epnew = exfat_get_dentry_cached(&new_es, ES_IDX_FILE); 1010 1054 *epnew = *epold; 1011 1055 if (exfat_get_entry_type(epnew) == TYPE_FILE) { 1012 1056 epnew->dentry.file.attr |= cpu_to_le16(EXFAT_ATTR_ARCHIVE); 1013 1057 ei->attr |= EXFAT_ATTR_ARCHIVE; 1014 1058 } 1015 - exfat_update_bh(new_bh, sync); 1016 - brelse(old_bh); 1017 - brelse(new_bh); 1018 1059 1019 - epold = exfat_get_dentry(sb, p_dir, oldentry + 1, &old_bh); 1020 - if (!epold) 1021 - return -EIO; 1022 - epnew = exfat_get_dentry(sb, p_dir, newentry + 1, &new_bh); 1023 - if (!epnew) { 1024 - brelse(old_bh); 1025 - return -EIO; 1026 - } 1027 - 1060 + epold = exfat_get_dentry_cached(&old_es, ES_IDX_STREAM); 1061 + epnew = exfat_get_dentry_cached(&new_es, ES_IDX_STREAM); 1028 1062 *epnew = *epold; 1029 - exfat_update_bh(new_bh, sync); 1030 - brelse(old_bh); 1031 - brelse(new_bh); 1032 1063 1033 - ret = exfat_init_ext_entry(inode, p_dir, newentry, 1034 - num_new_entries, p_uniname); 1064 + exfat_init_ext_entry(&new_es, num_new_entries, p_uniname); 1065 + 1066 + ret = exfat_put_dentry_set(&new_es, sync); 1035 1067 if (ret) 1036 - return ret; 1068 + goto put_old_es; 1037 1069 1038 - exfat_remove_entries(inode, p_dir, oldentry, 0, 1039 - num_old_entries); 1070 + exfat_remove_entries(inode, &old_es, ES_IDX_FILE); 1040 1071 ei->dir = *p_dir; 1041 1072 ei->entry = newentry; 1042 1073 } else { ··· 1029 1090 epold->dentry.file.attr |= cpu_to_le16(EXFAT_ATTR_ARCHIVE); 1030 1091 ei->attr |= EXFAT_ATTR_ARCHIVE; 1031 1092 } 1032 - exfat_update_bh(old_bh, sync); 1033 - brelse(old_bh); 1034 - ret = exfat_init_ext_entry(inode, p_dir, oldentry, 1035 - num_new_entries, p_uniname); 1036 - if (ret) 1037 - return ret; 1038 1093 1039 - exfat_remove_entries(inode, p_dir, oldentry, num_new_entries, 1040 - num_old_entries); 1094 + exfat_remove_entries(inode, &old_es, ES_IDX_FIRST_FILENAME + 1); 1095 + exfat_init_ext_entry(&old_es, num_new_entries, p_uniname); 1041 1096 } 1042 - return 0; 1097 + return exfat_put_dentry_set(&old_es, sync); 1098 + 1099 + put_old_es: 1100 + exfat_put_dentry_set(&old_es, false); 1101 + return ret; 1043 1102 } 1044 1103 1045 1104 static int exfat_move_file(struct inode *inode, struct exfat_chain *p_olddir, 1046 1105 int oldentry, struct exfat_chain *p_newdir, 1047 1106 struct exfat_uni_name *p_uniname, struct exfat_inode_info *ei) 1048 1107 { 1049 - int ret, newentry, num_new_entries, num_old_entries; 1108 + int ret, newentry, num_new_entries; 1050 1109 struct exfat_dentry *epmov, *epnew; 1051 1110 struct super_block *sb = inode->i_sb; 1052 - struct buffer_head *mov_bh, *new_bh; 1053 - 1054 - epmov = exfat_get_dentry(sb, p_olddir, oldentry, &mov_bh); 1055 - if (!epmov) 1056 - return -EIO; 1057 - 1058 - num_old_entries = exfat_count_ext_entries(sb, p_olddir, oldentry, 1059 - epmov); 1060 - if (num_old_entries < 0) 1061 - return -EIO; 1062 - num_old_entries++; 1111 + struct exfat_entry_set_cache mov_es, new_es; 1063 1112 1064 1113 num_new_entries = exfat_calc_num_entries(p_uniname); 1065 1114 if (num_new_entries < 0) 1066 1115 return num_new_entries; 1067 1116 1068 - newentry = exfat_find_empty_entry(inode, p_newdir, num_new_entries); 1069 - if (newentry < 0) 1070 - return newentry; /* -EIO or -ENOSPC */ 1071 - 1072 - epnew = exfat_get_dentry(sb, p_newdir, newentry, &new_bh); 1073 - if (!epnew) 1117 + ret = exfat_get_dentry_set(&mov_es, sb, p_olddir, oldentry, 1118 + ES_ALL_ENTRIES); 1119 + if (ret) 1074 1120 return -EIO; 1075 1121 1122 + newentry = exfat_find_empty_entry(inode, p_newdir, num_new_entries, 1123 + &new_es); 1124 + if (newentry < 0) { 1125 + ret = newentry; /* -EIO or -ENOSPC */ 1126 + goto put_mov_es; 1127 + } 1128 + 1129 + epmov = exfat_get_dentry_cached(&mov_es, ES_IDX_FILE); 1130 + epnew = exfat_get_dentry_cached(&new_es, ES_IDX_FILE); 1076 1131 *epnew = *epmov; 1077 1132 if (exfat_get_entry_type(epnew) == TYPE_FILE) { 1078 1133 epnew->dentry.file.attr |= cpu_to_le16(EXFAT_ATTR_ARCHIVE); 1079 1134 ei->attr |= EXFAT_ATTR_ARCHIVE; 1080 1135 } 1081 - exfat_update_bh(new_bh, IS_DIRSYNC(inode)); 1082 - brelse(mov_bh); 1083 - brelse(new_bh); 1084 1136 1085 - epmov = exfat_get_dentry(sb, p_olddir, oldentry + 1, &mov_bh); 1086 - if (!epmov) 1087 - return -EIO; 1088 - epnew = exfat_get_dentry(sb, p_newdir, newentry + 1, &new_bh); 1089 - if (!epnew) { 1090 - brelse(mov_bh); 1091 - return -EIO; 1092 - } 1093 - 1137 + epmov = exfat_get_dentry_cached(&mov_es, ES_IDX_STREAM); 1138 + epnew = exfat_get_dentry_cached(&new_es, ES_IDX_STREAM); 1094 1139 *epnew = *epmov; 1095 - exfat_update_bh(new_bh, IS_DIRSYNC(inode)); 1096 - brelse(mov_bh); 1097 - brelse(new_bh); 1098 1140 1099 - ret = exfat_init_ext_entry(inode, p_newdir, newentry, num_new_entries, 1100 - p_uniname); 1101 - if (ret) 1102 - return ret; 1103 - 1104 - exfat_remove_entries(inode, p_olddir, oldentry, 0, num_old_entries); 1141 + exfat_init_ext_entry(&new_es, num_new_entries, p_uniname); 1142 + exfat_remove_entries(inode, &mov_es, ES_IDX_FILE); 1105 1143 1106 1144 exfat_chain_set(&ei->dir, p_newdir->dir, p_newdir->size, 1107 1145 p_newdir->flags); 1108 1146 1109 1147 ei->entry = newentry; 1110 - return 0; 1148 + 1149 + ret = exfat_put_dentry_set(&new_es, IS_DIRSYNC(inode)); 1150 + if (ret) 1151 + goto put_mov_es; 1152 + 1153 + return exfat_put_dentry_set(&mov_es, IS_DIRSYNC(inode)); 1154 + 1155 + put_mov_es: 1156 + exfat_put_dentry_set(&mov_es, false); 1157 + 1158 + return ret; 1111 1159 } 1112 1160 1113 1161 /* rename or move a old file into a new file */ ··· 1112 1186 struct exfat_sb_info *sbi = EXFAT_SB(sb); 1113 1187 const unsigned char *new_path = new_dentry->d_name.name; 1114 1188 struct inode *new_inode = new_dentry->d_inode; 1115 - int num_entries; 1116 1189 struct exfat_inode_info *new_ei = NULL; 1117 1190 unsigned int new_entry_type = TYPE_UNUSED; 1118 1191 int new_entry = 0; ··· 1182 1257 &newdir, &uni_name, ei); 1183 1258 1184 1259 if (!ret && new_inode) { 1260 + struct exfat_entry_set_cache es; 1261 + 1185 1262 /* delete entries of new_dir */ 1186 - ep = exfat_get_dentry(sb, p_dir, new_entry, &new_bh); 1187 - if (!ep) { 1263 + ret = exfat_get_dentry_set(&es, sb, p_dir, new_entry, 1264 + ES_ALL_ENTRIES); 1265 + if (ret) { 1188 1266 ret = -EIO; 1189 1267 goto del_out; 1190 1268 } 1191 1269 1192 - num_entries = exfat_count_ext_entries(sb, p_dir, new_entry, ep); 1193 - if (num_entries < 0) { 1194 - ret = -EIO; 1195 - goto del_out; 1196 - } 1197 - brelse(new_bh); 1270 + exfat_remove_entries(new_inode, &es, ES_IDX_FILE); 1198 1271 1199 - if (exfat_remove_entries(new_inode, p_dir, new_entry, 0, 1200 - num_entries + 1)) { 1201 - ret = -EIO; 1272 + ret = exfat_put_dentry_set(&es, IS_DIRSYNC(new_inode)); 1273 + if (ret) 1202 1274 goto del_out; 1203 - } 1204 1275 1205 1276 /* Free the clusters if new_inode is a dir(as if exfat_rmdir) */ 1206 1277 if (new_entry_type == TYPE_DIR && ··· 1238 1317 struct super_block *sb = old_dir->i_sb; 1239 1318 loff_t i_pos; 1240 1319 int err; 1320 + loff_t size = i_size_read(new_dir); 1241 1321 1242 1322 /* 1243 1323 * The VFS already checks for existence, so for local filesystems ··· 1260 1338 simple_rename_timestamp(old_dir, old_dentry, new_dir, new_dentry); 1261 1339 EXFAT_I(new_dir)->i_crtime = current_time(new_dir); 1262 1340 exfat_truncate_inode_atime(new_dir); 1263 - if (IS_DIRSYNC(new_dir)) 1341 + if (IS_DIRSYNC(new_dir) && size != i_size_read(new_dir)) 1264 1342 exfat_sync_inode(new_dir); 1265 1343 else 1266 1344 mark_inode_dirty(new_dir); ··· 1281 1359 } 1282 1360 1283 1361 inode_inc_iversion(old_dir); 1284 - if (IS_DIRSYNC(old_dir)) 1285 - exfat_sync_inode(old_dir); 1286 - else 1362 + if (new_dir != old_dir) 1287 1363 mark_inode_dirty(old_dir); 1288 1364 1289 1365 if (new_inode) {