Skip to content

Commit d9c699f

Browse files
aalexandrovichgregkh
authored andcommitted
fs/ntfs3: Mark inode as bad as soon as error detected in mi_enum_attr()
[ Upstream commit 2afd4d2 ] Extended the `mi_enum_attr()` function interface with an additional parameter, `struct ntfs_inode *ni`, to allow marking the inode as bad as soon as an error is detected. Reported-by: [email protected] Signed-off-by: Konstantin Komarov <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 1605de8 commit d9c699f

File tree

4 files changed

+90
-80
lines changed

4 files changed

+90
-80
lines changed

fs/ntfs3/attrib.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,8 @@ int attr_set_size(struct ntfs_inode *ni, enum ATTR_TYPE type,
787787
if (err)
788788
goto out;
789789

790-
attr = mi_find_attr(mi, NULL, type, name, name_len, &le->id);
790+
attr = mi_find_attr(ni, mi, NULL, type, name, name_len,
791+
&le->id);
791792
if (!attr) {
792793
err = -EINVAL;
793794
goto bad_inode;
@@ -1181,7 +1182,7 @@ int attr_data_get_block(struct ntfs_inode *ni, CLST vcn, CLST clen, CLST *lcn,
11811182
goto out;
11821183
}
11831184

1184-
attr = mi_find_attr(mi, NULL, ATTR_DATA, NULL, 0, &le->id);
1185+
attr = mi_find_attr(ni, mi, NULL, ATTR_DATA, NULL, 0, &le->id);
11851186
if (!attr) {
11861187
err = -EINVAL;
11871188
goto out;
@@ -1796,7 +1797,7 @@ int attr_allocate_frame(struct ntfs_inode *ni, CLST frame, size_t compr_size,
17961797
goto out;
17971798
}
17981799

1799-
attr = mi_find_attr(mi, NULL, ATTR_DATA, NULL, 0,
1800+
attr = mi_find_attr(ni, mi, NULL, ATTR_DATA, NULL, 0,
18001801
&le->id);
18011802
if (!attr) {
18021803
err = -EINVAL;
@@ -2041,8 +2042,8 @@ int attr_collapse_range(struct ntfs_inode *ni, u64 vbo, u64 bytes)
20412042
}
20422043

20432044
/* Look for required attribute. */
2044-
attr = mi_find_attr(mi, NULL, ATTR_DATA, NULL,
2045-
0, &le->id);
2045+
attr = mi_find_attr(ni, mi, NULL, ATTR_DATA,
2046+
NULL, 0, &le->id);
20462047
if (!attr) {
20472048
err = -EINVAL;
20482049
goto out;

fs/ntfs3/frecord.c

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ struct ATTR_STD_INFO *ni_std(struct ntfs_inode *ni)
7575
{
7676
const struct ATTRIB *attr;
7777

78-
attr = mi_find_attr(&ni->mi, NULL, ATTR_STD, NULL, 0, NULL);
78+
attr = mi_find_attr(ni, &ni->mi, NULL, ATTR_STD, NULL, 0, NULL);
7979
return attr ? resident_data_ex(attr, sizeof(struct ATTR_STD_INFO)) :
8080
NULL;
8181
}
@@ -89,7 +89,7 @@ struct ATTR_STD_INFO5 *ni_std5(struct ntfs_inode *ni)
8989
{
9090
const struct ATTRIB *attr;
9191

92-
attr = mi_find_attr(&ni->mi, NULL, ATTR_STD, NULL, 0, NULL);
92+
attr = mi_find_attr(ni, &ni->mi, NULL, ATTR_STD, NULL, 0, NULL);
9393

9494
return attr ? resident_data_ex(attr, sizeof(struct ATTR_STD_INFO5)) :
9595
NULL;
@@ -201,7 +201,8 @@ struct ATTRIB *ni_find_attr(struct ntfs_inode *ni, struct ATTRIB *attr,
201201
*mi = &ni->mi;
202202

203203
/* Look for required attribute in primary record. */
204-
return mi_find_attr(&ni->mi, attr, type, name, name_len, NULL);
204+
return mi_find_attr(ni, &ni->mi, attr, type, name, name_len,
205+
NULL);
205206
}
206207

207208
/* First look for list entry of required type. */
@@ -217,7 +218,7 @@ struct ATTRIB *ni_find_attr(struct ntfs_inode *ni, struct ATTRIB *attr,
217218
return NULL;
218219

219220
/* Look for required attribute. */
220-
attr = mi_find_attr(m, NULL, type, name, name_len, &le->id);
221+
attr = mi_find_attr(ni, m, NULL, type, name, name_len, &le->id);
221222

222223
if (!attr)
223224
goto out;
@@ -259,7 +260,7 @@ struct ATTRIB *ni_enum_attr_ex(struct ntfs_inode *ni, struct ATTRIB *attr,
259260
if (mi)
260261
*mi = &ni->mi;
261262
/* Enum attributes in primary record. */
262-
return mi_enum_attr(&ni->mi, attr);
263+
return mi_enum_attr(ni, &ni->mi, attr);
263264
}
264265

265266
/* Get next list entry. */
@@ -275,7 +276,7 @@ struct ATTRIB *ni_enum_attr_ex(struct ntfs_inode *ni, struct ATTRIB *attr,
275276
*mi = mi2;
276277

277278
/* Find attribute in loaded record. */
278-
return rec_find_attr_le(mi2, le2);
279+
return rec_find_attr_le(ni, mi2, le2);
279280
}
280281

281282
/*
@@ -293,7 +294,8 @@ struct ATTRIB *ni_load_attr(struct ntfs_inode *ni, enum ATTR_TYPE type,
293294
if (!ni->attr_list.size) {
294295
if (pmi)
295296
*pmi = &ni->mi;
296-
return mi_find_attr(&ni->mi, NULL, type, name, name_len, NULL);
297+
return mi_find_attr(ni, &ni->mi, NULL, type, name, name_len,
298+
NULL);
297299
}
298300

299301
le = al_find_ex(ni, NULL, type, name, name_len, NULL);
@@ -319,7 +321,7 @@ struct ATTRIB *ni_load_attr(struct ntfs_inode *ni, enum ATTR_TYPE type,
319321
if (pmi)
320322
*pmi = mi;
321323

322-
attr = mi_find_attr(mi, NULL, type, name, name_len, &le->id);
324+
attr = mi_find_attr(ni, mi, NULL, type, name, name_len, &le->id);
323325
if (!attr)
324326
return NULL;
325327

@@ -398,7 +400,8 @@ int ni_remove_attr(struct ntfs_inode *ni, enum ATTR_TYPE type,
398400
int diff;
399401

400402
if (base_only || type == ATTR_LIST || !ni->attr_list.size) {
401-
attr = mi_find_attr(&ni->mi, NULL, type, name, name_len, id);
403+
attr = mi_find_attr(ni, &ni->mi, NULL, type, name, name_len,
404+
id);
402405
if (!attr)
403406
return -ENOENT;
404407

@@ -437,7 +440,7 @@ int ni_remove_attr(struct ntfs_inode *ni, enum ATTR_TYPE type,
437440

438441
al_remove_le(ni, le);
439442

440-
attr = mi_find_attr(mi, NULL, type, name, name_len, id);
443+
attr = mi_find_attr(ni, mi, NULL, type, name, name_len, id);
441444
if (!attr)
442445
return -ENOENT;
443446

@@ -485,7 +488,7 @@ ni_ins_new_attr(struct ntfs_inode *ni, struct mft_inode *mi,
485488
name = le->name;
486489
}
487490

488-
attr = mi_insert_attr(mi, type, name, name_len, asize, name_off);
491+
attr = mi_insert_attr(ni, mi, type, name, name_len, asize, name_off);
489492
if (!attr) {
490493
if (le_added)
491494
al_remove_le(ni, le);
@@ -673,7 +676,7 @@ static int ni_try_remove_attr_list(struct ntfs_inode *ni)
673676
if (err)
674677
return err;
675678

676-
attr_list = mi_find_attr(&ni->mi, NULL, ATTR_LIST, NULL, 0, NULL);
679+
attr_list = mi_find_attr(ni, &ni->mi, NULL, ATTR_LIST, NULL, 0, NULL);
677680
if (!attr_list)
678681
return 0;
679682

@@ -695,7 +698,7 @@ static int ni_try_remove_attr_list(struct ntfs_inode *ni)
695698
if (!mi)
696699
return 0;
697700

698-
attr = mi_find_attr(mi, NULL, le->type, le_name(le),
701+
attr = mi_find_attr(ni, mi, NULL, le->type, le_name(le),
699702
le->name_len, &le->id);
700703
if (!attr)
701704
return 0;
@@ -731,7 +734,7 @@ static int ni_try_remove_attr_list(struct ntfs_inode *ni)
731734
goto out;
732735
}
733736

734-
attr = mi_find_attr(mi, NULL, le->type, le_name(le),
737+
attr = mi_find_attr(ni, mi, NULL, le->type, le_name(le),
735738
le->name_len, &le->id);
736739
if (!attr) {
737740
/* Should never happened, 'cause already checked. */
@@ -740,7 +743,7 @@ static int ni_try_remove_attr_list(struct ntfs_inode *ni)
740743
asize = le32_to_cpu(attr->size);
741744

742745
/* Insert into primary record. */
743-
attr_ins = mi_insert_attr(&ni->mi, le->type, le_name(le),
746+
attr_ins = mi_insert_attr(ni, &ni->mi, le->type, le_name(le),
744747
le->name_len, asize,
745748
le16_to_cpu(attr->name_off));
746749
if (!attr_ins) {
@@ -768,7 +771,7 @@ static int ni_try_remove_attr_list(struct ntfs_inode *ni)
768771
if (!mi)
769772
continue;
770773

771-
attr = mi_find_attr(mi, NULL, le->type, le_name(le),
774+
attr = mi_find_attr(ni, mi, NULL, le->type, le_name(le),
772775
le->name_len, &le->id);
773776
if (!attr)
774777
continue;
@@ -831,7 +834,7 @@ int ni_create_attr_list(struct ntfs_inode *ni)
831834
free_b = 0;
832835
attr = NULL;
833836

834-
for (; (attr = mi_enum_attr(&ni->mi, attr)); le = Add2Ptr(le, sz)) {
837+
for (; (attr = mi_enum_attr(ni, &ni->mi, attr)); le = Add2Ptr(le, sz)) {
835838
sz = le_size(attr->name_len);
836839
le->type = attr->type;
837840
le->size = cpu_to_le16(sz);
@@ -886,7 +889,7 @@ int ni_create_attr_list(struct ntfs_inode *ni)
886889
u32 asize = le32_to_cpu(b->size);
887890
u16 name_off = le16_to_cpu(b->name_off);
888891

889-
attr = mi_insert_attr(mi, b->type, Add2Ptr(b, name_off),
892+
attr = mi_insert_attr(ni, mi, b->type, Add2Ptr(b, name_off),
890893
b->name_len, asize, name_off);
891894
if (!attr)
892895
goto out;
@@ -909,7 +912,7 @@ int ni_create_attr_list(struct ntfs_inode *ni)
909912
goto out;
910913
}
911914

912-
attr = mi_insert_attr(&ni->mi, ATTR_LIST, NULL, 0,
915+
attr = mi_insert_attr(ni, &ni->mi, ATTR_LIST, NULL, 0,
913916
lsize + SIZEOF_RESIDENT, SIZEOF_RESIDENT);
914917
if (!attr)
915918
goto out;
@@ -993,13 +996,13 @@ static int ni_ins_attr_ext(struct ntfs_inode *ni, struct ATTR_LIST_ENTRY *le,
993996
mi = rb_entry(node, struct mft_inode, node);
994997

995998
if (is_mft_data &&
996-
(mi_enum_attr(mi, NULL) ||
999+
(mi_enum_attr(ni, mi, NULL) ||
9971000
vbo <= ((u64)mi->rno << sbi->record_bits))) {
9981001
/* We can't accept this record 'cause MFT's bootstrapping. */
9991002
continue;
10001003
}
10011004
if (is_mft &&
1002-
mi_find_attr(mi, NULL, ATTR_DATA, NULL, 0, NULL)) {
1005+
mi_find_attr(ni, mi, NULL, ATTR_DATA, NULL, 0, NULL)) {
10031006
/*
10041007
* This child record already has a ATTR_DATA.
10051008
* So it can't accept any other records.
@@ -1008,7 +1011,7 @@ static int ni_ins_attr_ext(struct ntfs_inode *ni, struct ATTR_LIST_ENTRY *le,
10081011
}
10091012

10101013
if ((type != ATTR_NAME || name_len) &&
1011-
mi_find_attr(mi, NULL, type, name, name_len, NULL)) {
1014+
mi_find_attr(ni, mi, NULL, type, name, name_len, NULL)) {
10121015
/* Only indexed attributes can share same record. */
10131016
continue;
10141017
}
@@ -1157,7 +1160,7 @@ static int ni_insert_attr(struct ntfs_inode *ni, enum ATTR_TYPE type,
11571160
/* Estimate the result of moving all possible attributes away. */
11581161
attr = NULL;
11591162

1160-
while ((attr = mi_enum_attr(&ni->mi, attr))) {
1163+
while ((attr = mi_enum_attr(ni, &ni->mi, attr))) {
11611164
if (attr->type == ATTR_STD)
11621165
continue;
11631166
if (attr->type == ATTR_LIST)
@@ -1175,7 +1178,7 @@ static int ni_insert_attr(struct ntfs_inode *ni, enum ATTR_TYPE type,
11751178
attr = NULL;
11761179

11771180
for (;;) {
1178-
attr = mi_enum_attr(&ni->mi, attr);
1181+
attr = mi_enum_attr(ni, &ni->mi, attr);
11791182
if (!attr) {
11801183
/* We should never be here 'cause we have already check this case. */
11811184
err = -EINVAL;
@@ -1259,7 +1262,7 @@ static int ni_expand_mft_list(struct ntfs_inode *ni)
12591262
for (node = rb_first(&ni->mi_tree); node; node = rb_next(node)) {
12601263
mi = rb_entry(node, struct mft_inode, node);
12611264

1262-
attr = mi_enum_attr(mi, NULL);
1265+
attr = mi_enum_attr(ni, mi, NULL);
12631266

12641267
if (!attr) {
12651268
mft_min = mi->rno;
@@ -1280,7 +1283,7 @@ static int ni_expand_mft_list(struct ntfs_inode *ni)
12801283
ni_remove_mi(ni, mi_new);
12811284
}
12821285

1283-
attr = mi_find_attr(&ni->mi, NULL, ATTR_DATA, NULL, 0, NULL);
1286+
attr = mi_find_attr(ni, &ni->mi, NULL, ATTR_DATA, NULL, 0, NULL);
12841287
if (!attr) {
12851288
err = -EINVAL;
12861289
goto out;
@@ -1397,7 +1400,7 @@ int ni_expand_list(struct ntfs_inode *ni)
13971400
continue;
13981401

13991402
/* Find attribute in primary record. */
1400-
attr = rec_find_attr_le(&ni->mi, le);
1403+
attr = rec_find_attr_le(ni, &ni->mi, le);
14011404
if (!attr) {
14021405
err = -EINVAL;
14031406
goto out;
@@ -3343,7 +3346,7 @@ int ni_write_inode(struct inode *inode, int sync, const char *hint)
33433346
if (!mi->dirty)
33443347
continue;
33453348

3346-
is_empty = !mi_enum_attr(mi, NULL);
3349+
is_empty = !mi_enum_attr(ni, mi, NULL);
33473350

33483351
if (is_empty)
33493352
clear_rec_inuse(mi->mrec);

fs/ntfs3/ntfs_fs.h

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -745,23 +745,24 @@ int mi_get(struct ntfs_sb_info *sbi, CLST rno, struct mft_inode **mi);
745745
void mi_put(struct mft_inode *mi);
746746
int mi_init(struct mft_inode *mi, struct ntfs_sb_info *sbi, CLST rno);
747747
int mi_read(struct mft_inode *mi, bool is_mft);
748-
struct ATTRIB *mi_enum_attr(struct mft_inode *mi, struct ATTRIB *attr);
749-
// TODO: id?
750-
struct ATTRIB *mi_find_attr(struct mft_inode *mi, struct ATTRIB *attr,
751-
enum ATTR_TYPE type, const __le16 *name,
752-
u8 name_len, const __le16 *id);
753-
static inline struct ATTRIB *rec_find_attr_le(struct mft_inode *rec,
748+
struct ATTRIB *mi_enum_attr(struct ntfs_inode *ni, struct mft_inode *mi,
749+
struct ATTRIB *attr);
750+
struct ATTRIB *mi_find_attr(struct ntfs_inode *ni, struct mft_inode *mi,
751+
struct ATTRIB *attr, enum ATTR_TYPE type,
752+
const __le16 *name, u8 name_len, const __le16 *id);
753+
static inline struct ATTRIB *rec_find_attr_le(struct ntfs_inode *ni,
754+
struct mft_inode *rec,
754755
struct ATTR_LIST_ENTRY *le)
755756
{
756-
return mi_find_attr(rec, NULL, le->type, le_name(le), le->name_len,
757+
return mi_find_attr(ni, rec, NULL, le->type, le_name(le), le->name_len,
757758
&le->id);
758759
}
759760
int mi_write(struct mft_inode *mi, int wait);
760761
int mi_format_new(struct mft_inode *mi, struct ntfs_sb_info *sbi, CLST rno,
761762
__le16 flags, bool is_mft);
762-
struct ATTRIB *mi_insert_attr(struct mft_inode *mi, enum ATTR_TYPE type,
763-
const __le16 *name, u8 name_len, u32 asize,
764-
u16 name_off);
763+
struct ATTRIB *mi_insert_attr(struct ntfs_inode *ni, struct mft_inode *mi,
764+
enum ATTR_TYPE type, const __le16 *name,
765+
u8 name_len, u32 asize, u16 name_off);
765766

766767
bool mi_remove_attr(struct ntfs_inode *ni, struct mft_inode *mi,
767768
struct ATTRIB *attr);

0 commit comments

Comments
 (0)