diff options
-rw-r--r-- | fs/gfs2/dir.c | 56 |
1 files changed, 29 insertions, 27 deletions
diff --git a/fs/gfs2/dir.c b/fs/gfs2/dir.c index c32f7b3de662..65871a2b460e 100644 --- a/fs/gfs2/dir.c +++ b/fs/gfs2/dir.c | |||
@@ -417,6 +417,12 @@ static int dirent_next(struct gfs2_inode *dip, struct buffer_head *bh, | |||
417 | gfs2_consist_inode(dip); | 417 | gfs2_consist_inode(dip); |
418 | return -EIO; | 418 | return -EIO; |
419 | } | 419 | } |
420 | |||
421 | if (cur_rec_len == 0) { | ||
422 | gfs2_consist_inode(dip); | ||
423 | return -EIO; | ||
424 | } | ||
425 | |||
420 | /* Only the first dent could ever have de_inum.no_addr == 0 */ | 426 | /* Only the first dent could ever have de_inum.no_addr == 0 */ |
421 | if (!tmp->de_inum.no_addr) { | 427 | if (!tmp->de_inum.no_addr) { |
422 | gfs2_consist_inode(dip); | 428 | gfs2_consist_inode(dip); |
@@ -512,9 +518,8 @@ int gfs2_dirent_alloc(struct gfs2_inode *dip, struct buffer_head *bh, | |||
512 | 518 | ||
513 | gfs2_trans_add_bh(dip->i_gl, bh, 1); | 519 | gfs2_trans_add_bh(dip->i_gl, bh, 1); |
514 | 520 | ||
515 | dent->de_rec_len = bh->b_size - offset; | 521 | dent->de_rec_len = cpu_to_be16(bh->b_size - offset); |
516 | dent->de_rec_len = cpu_to_be16(dent->de_rec_len); | 522 | dent->de_name_len = cpu_to_be16(name_len); |
517 | dent->de_name_len = name_len; | ||
518 | 523 | ||
519 | *dent_out = dent; | 524 | *dent_out = dent; |
520 | return 0; | 525 | return 0; |
@@ -522,10 +527,10 @@ int gfs2_dirent_alloc(struct gfs2_inode *dip, struct buffer_head *bh, | |||
522 | 527 | ||
523 | do { | 528 | do { |
524 | uint16_t cur_rec_len; | 529 | uint16_t cur_rec_len; |
525 | uint32_t cur_name_len; | 530 | uint16_t cur_name_len; |
526 | 531 | ||
527 | cur_rec_len = be16_to_cpu(dent->de_rec_len); | 532 | cur_rec_len = be16_to_cpu(dent->de_rec_len); |
528 | cur_name_len = dent->de_name_len; | 533 | cur_name_len = be16_to_cpu(dent->de_name_len); |
529 | 534 | ||
530 | if ((!dent->de_inum.no_addr && cur_rec_len >= rec_len) || | 535 | if ((!dent->de_inum.no_addr && cur_rec_len >= rec_len) || |
531 | (cur_rec_len >= GFS2_DIRENT_SIZE(cur_name_len) + rec_len)) { | 536 | (cur_rec_len >= GFS2_DIRENT_SIZE(cur_name_len) + rec_len)) { |
@@ -536,18 +541,16 @@ int gfs2_dirent_alloc(struct gfs2_inode *dip, struct buffer_head *bh, | |||
536 | GFS2_DIRENT_SIZE(cur_name_len)); | 541 | GFS2_DIRENT_SIZE(cur_name_len)); |
537 | memset(new, 0, sizeof(struct gfs2_dirent)); | 542 | memset(new, 0, sizeof(struct gfs2_dirent)); |
538 | 543 | ||
539 | new->de_rec_len = cur_rec_len - GFS2_DIRENT_SIZE(cur_name_len); | 544 | new->de_rec_len = cpu_to_be16(cur_rec_len - GFS2_DIRENT_SIZE(cur_name_len)); |
540 | new->de_rec_len = cpu_to_be16(new->de_rec_len); | 545 | new->de_name_len = cpu_to_be16(name_len); |
541 | new->de_name_len = name_len; | ||
542 | 546 | ||
543 | dent->de_rec_len = cur_rec_len - be16_to_cpu(new->de_rec_len); | 547 | dent->de_rec_len = cpu_to_be16(cur_rec_len - be16_to_cpu(new->de_rec_len)); |
544 | dent->de_rec_len = cpu_to_be16(dent->de_rec_len); | ||
545 | 548 | ||
546 | *dent_out = new; | 549 | *dent_out = new; |
547 | return 0; | 550 | return 0; |
548 | } | 551 | } |
549 | 552 | ||
550 | dent->de_name_len = name_len; | 553 | dent->de_name_len = cpu_to_be16(name_len); |
551 | 554 | ||
552 | *dent_out = dent; | 555 | *dent_out = dent; |
553 | return 0; | 556 | return 0; |
@@ -594,7 +597,7 @@ static int dirent_fits(struct gfs2_inode *dip, struct buffer_head *bh, | |||
594 | uint32_t cur_name_len; | 597 | uint32_t cur_name_len; |
595 | 598 | ||
596 | cur_rec_len = be16_to_cpu(dent->de_rec_len); | 599 | cur_rec_len = be16_to_cpu(dent->de_rec_len); |
597 | cur_name_len = dent->de_name_len; | 600 | cur_name_len = be16_to_cpu(dent->de_name_len); |
598 | 601 | ||
599 | if ((!dent->de_inum.no_addr && cur_rec_len >= rec_len) || | 602 | if ((!dent->de_inum.no_addr && cur_rec_len >= rec_len) || |
600 | (cur_rec_len >= GFS2_DIRENT_SIZE(cur_name_len) + rec_len)) | 603 | (cur_rec_len >= GFS2_DIRENT_SIZE(cur_name_len) + rec_len)) |
@@ -635,7 +638,7 @@ static int leaf_search(struct gfs2_inode *dip, struct buffer_head *bh, | |||
635 | 638 | ||
636 | if (be32_to_cpu(dent->de_hash) == hash && | 639 | if (be32_to_cpu(dent->de_hash) == hash && |
637 | gfs2_filecmp(filename, (char *)(dent + 1), | 640 | gfs2_filecmp(filename, (char *)(dent + 1), |
638 | dent->de_name_len)) { | 641 | be16_to_cpu(dent->de_name_len))) { |
639 | *dent_out = dent; | 642 | *dent_out = dent; |
640 | if (dent_prev) | 643 | if (dent_prev) |
641 | *dent_prev = prev; | 644 | *dent_prev = prev; |
@@ -834,10 +837,9 @@ static int dir_make_exhash(struct gfs2_inode *dip) | |||
834 | /* Adjust the last dirent's record length | 837 | /* Adjust the last dirent's record length |
835 | (Remember that dent still points to the last entry.) */ | 838 | (Remember that dent still points to the last entry.) */ |
836 | 839 | ||
837 | dent->de_rec_len = be16_to_cpu(dent->de_rec_len) + | 840 | dent->de_rec_len = cpu_to_be16(be16_to_cpu(dent->de_rec_len) + |
838 | sizeof(struct gfs2_dinode) - | 841 | sizeof(struct gfs2_dinode) - |
839 | sizeof(struct gfs2_leaf); | 842 | sizeof(struct gfs2_leaf)); |
840 | dent->de_rec_len = cpu_to_be16(dent->de_rec_len); | ||
841 | 843 | ||
842 | brelse(bh); | 844 | brelse(bh); |
843 | 845 | ||
@@ -969,7 +971,7 @@ static int dir_split_leaf(struct gfs2_inode *dip, uint32_t index, | |||
969 | 971 | ||
970 | if (dent->de_inum.no_addr && | 972 | if (dent->de_inum.no_addr && |
971 | be32_to_cpu(dent->de_hash) < divider) { | 973 | be32_to_cpu(dent->de_hash) < divider) { |
972 | name_len = dent->de_name_len; | 974 | name_len = be16_to_cpu(dent->de_name_len); |
973 | 975 | ||
974 | gfs2_dirent_alloc(dip, nbh, name_len, &new); | 976 | gfs2_dirent_alloc(dip, nbh, name_len, &new); |
975 | 977 | ||
@@ -1139,8 +1141,8 @@ static int compare_dents(const void *a, const void *b) | |||
1139 | else if (hash_a < hash_b) | 1141 | else if (hash_a < hash_b) |
1140 | ret = -1; | 1142 | ret = -1; |
1141 | else { | 1143 | else { |
1142 | unsigned int len_a = dent_a->de_name_len; | 1144 | unsigned int len_a = be16_to_cpu(dent_a->de_name_len); |
1143 | unsigned int len_b = dent_b->de_name_len; | 1145 | unsigned int len_b = be16_to_cpu(dent_b->de_name_len); |
1144 | 1146 | ||
1145 | if (len_a > len_b) | 1147 | if (len_a > len_b) |
1146 | ret = 1; | 1148 | ret = 1; |
@@ -1219,9 +1221,9 @@ static int do_filldir_main(struct gfs2_inode *dip, uint64_t *offset, | |||
1219 | gfs2_inum_in(&inum, (char *)&dent->de_inum); | 1221 | gfs2_inum_in(&inum, (char *)&dent->de_inum); |
1220 | 1222 | ||
1221 | error = filldir(opaque, (char *)(dent + 1), | 1223 | error = filldir(opaque, (char *)(dent + 1), |
1222 | dent->de_name_len, | 1224 | be16_to_cpu(dent->de_name_len), |
1223 | off, &inum, | 1225 | off, &inum, |
1224 | dent->de_type); | 1226 | be16_to_cpu(dent->de_type)); |
1225 | if (error) | 1227 | if (error) |
1226 | return 1; | 1228 | return 1; |
1227 | 1229 | ||
@@ -1454,7 +1456,7 @@ static int dir_e_search(struct gfs2_inode *dip, struct qstr *filename, | |||
1454 | if (inum) | 1456 | if (inum) |
1455 | gfs2_inum_in(inum, (char *)&dent->de_inum); | 1457 | gfs2_inum_in(inum, (char *)&dent->de_inum); |
1456 | if (type) | 1458 | if (type) |
1457 | *type = dent->de_type; | 1459 | *type = be16_to_cpu(dent->de_type); |
1458 | 1460 | ||
1459 | brelse(bh); | 1461 | brelse(bh); |
1460 | 1462 | ||
@@ -1563,7 +1565,7 @@ static int dir_e_add(struct gfs2_inode *dip, struct qstr *filename, | |||
1563 | 1565 | ||
1564 | gfs2_inum_out(inum, (char *)&dent->de_inum); | 1566 | gfs2_inum_out(inum, (char *)&dent->de_inum); |
1565 | dent->de_hash = cpu_to_be32(hash); | 1567 | dent->de_hash = cpu_to_be32(hash); |
1566 | dent->de_type = type; | 1568 | dent->de_type = cpu_to_be16(type); |
1567 | memcpy((char *)(dent + 1), filename->name, filename->len); | 1569 | memcpy((char *)(dent + 1), filename->name, filename->len); |
1568 | 1570 | ||
1569 | leaf->lf_entries = be16_to_cpu(leaf->lf_entries) + 1; | 1571 | leaf->lf_entries = be16_to_cpu(leaf->lf_entries) + 1; |
@@ -1732,7 +1734,7 @@ static int dir_e_mvino(struct gfs2_inode *dip, struct qstr *filename, | |||
1732 | gfs2_trans_add_bh(dip->i_gl, bh, 1); | 1734 | gfs2_trans_add_bh(dip->i_gl, bh, 1); |
1733 | 1735 | ||
1734 | gfs2_inum_out(inum, (char *)&dent->de_inum); | 1736 | gfs2_inum_out(inum, (char *)&dent->de_inum); |
1735 | dent->de_type = new_type; | 1737 | dent->de_type = cpu_to_be16(new_type); |
1736 | 1738 | ||
1737 | brelse(bh); | 1739 | brelse(bh); |
1738 | 1740 | ||
@@ -1780,7 +1782,7 @@ static int dir_l_search(struct gfs2_inode *dip, struct qstr *filename, | |||
1780 | if (inum) | 1782 | if (inum) |
1781 | gfs2_inum_in(inum, (char *)&dent->de_inum); | 1783 | gfs2_inum_in(inum, (char *)&dent->de_inum); |
1782 | if (type) | 1784 | if (type) |
1783 | *type = dent->de_type; | 1785 | *type = be16_to_cpu(dent->de_type); |
1784 | } | 1786 | } |
1785 | 1787 | ||
1786 | brelse(dibh); | 1788 | brelse(dibh); |
@@ -1819,7 +1821,7 @@ static int dir_l_add(struct gfs2_inode *dip, struct qstr *filename, | |||
1819 | gfs2_inum_out(inum, (char *)&dent->de_inum); | 1821 | gfs2_inum_out(inum, (char *)&dent->de_inum); |
1820 | dent->de_hash = gfs2_disk_hash(filename->name, filename->len); | 1822 | dent->de_hash = gfs2_disk_hash(filename->name, filename->len); |
1821 | dent->de_hash = cpu_to_be32(dent->de_hash); | 1823 | dent->de_hash = cpu_to_be32(dent->de_hash); |
1822 | dent->de_type = type; | 1824 | dent->de_type = cpu_to_be16(type); |
1823 | memcpy((char *)(dent + 1), filename->name, filename->len); | 1825 | memcpy((char *)(dent + 1), filename->name, filename->len); |
1824 | 1826 | ||
1825 | dip->i_di.di_entries++; | 1827 | dip->i_di.di_entries++; |
@@ -1932,7 +1934,7 @@ static int dir_l_mvino(struct gfs2_inode *dip, struct qstr *filename, | |||
1932 | gfs2_trans_add_bh(dip->i_gl, dibh, 1); | 1934 | gfs2_trans_add_bh(dip->i_gl, dibh, 1); |
1933 | 1935 | ||
1934 | gfs2_inum_out(inum, (char *)&dent->de_inum); | 1936 | gfs2_inum_out(inum, (char *)&dent->de_inum); |
1935 | dent->de_type = new_type; | 1937 | dent->de_type = cpu_to_be16(new_type); |
1936 | 1938 | ||
1937 | dip->i_di.di_mtime = dip->i_di.di_ctime = get_seconds(); | 1939 | dip->i_di.di_mtime = dip->i_di.di_ctime = get_seconds(); |
1938 | 1940 | ||