Skip to content

Commit ffc8df3

Browse files
Russell KingAl Viro
authored andcommitted
fs/adfs: newdir: factor out directory format validation
We have two locations where we validate the new directory format, so factor this out to a helper. Signed-off-by: Russell King <[email protected]> Signed-off-by: Al Viro <[email protected]>
1 parent 016936b commit ffc8df3

File tree

1 file changed

+20
-28
lines changed

1 file changed

+20
-28
lines changed

fs/adfs/dir_f.c

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,21 @@ adfs_dir_checkbyte(const struct adfs_dir *dir)
121121
return (dircheck ^ (dircheck >> 8) ^ (dircheck >> 16) ^ (dircheck >> 24)) & 0xff;
122122
}
123123

124+
static int adfs_f_validate(struct adfs_dir *dir)
125+
{
126+
struct adfs_dirheader *head = dir->dirhead;
127+
struct adfs_newdirtail *tail = dir->newtail;
128+
129+
if (head->startmasseq != tail->endmasseq ||
130+
(memcmp(&head->startname, "Nick", 4) &&
131+
memcmp(&head->startname, "Hugo", 4)) ||
132+
memcmp(&head->startname, &tail->endname, 4) ||
133+
adfs_dir_checkbyte(dir) != tail->dircheckbyte)
134+
return -EIO;
135+
136+
return 0;
137+
}
138+
124139
/* Read and check that a directory is valid */
125140
static int adfs_dir_read(struct super_block *sb, u32 indaddr,
126141
unsigned int size, struct adfs_dir *dir)
@@ -142,15 +157,7 @@ static int adfs_dir_read(struct super_block *sb, u32 indaddr,
142157
dir->dirhead = bufoff(dir->bh, 0);
143158
dir->newtail = bufoff(dir->bh, 2007);
144159

145-
if (dir->dirhead->startmasseq != dir->newtail->endmasseq ||
146-
memcmp(&dir->dirhead->startname, &dir->newtail->endname, 4))
147-
goto bad_dir;
148-
149-
if (memcmp(&dir->dirhead->startname, "Nick", 4) &&
150-
memcmp(&dir->dirhead->startname, "Hugo", 4))
151-
goto bad_dir;
152-
153-
if (adfs_dir_checkbyte(dir) != dir->newtail->dircheckbyte)
160+
if (adfs_f_validate(dir))
154161
goto bad_dir;
155162

156163
return 0;
@@ -327,7 +334,7 @@ adfs_f_update(struct adfs_dir *dir, struct object_info *obj)
327334
ret = adfs_dir_find_entry(dir, obj->indaddr);
328335
if (ret < 0) {
329336
adfs_error(dir->sb, "unable to locate entry to update");
330-
goto out;
337+
return ret;
331338
}
332339

333340
__adfs_dir_put(dir, ret, obj);
@@ -344,26 +351,11 @@ adfs_f_update(struct adfs_dir *dir, struct object_info *obj)
344351
*/
345352
dir->newtail->dircheckbyte = ret;
346353

347-
#if 1
348-
if (dir->dirhead->startmasseq != dir->newtail->endmasseq ||
349-
memcmp(&dir->dirhead->startname, &dir->newtail->endname, 4))
350-
goto bad_dir;
351-
352-
if (memcmp(&dir->dirhead->startname, "Nick", 4) &&
353-
memcmp(&dir->dirhead->startname, "Hugo", 4))
354-
goto bad_dir;
354+
ret = adfs_f_validate(dir);
355+
if (ret)
356+
adfs_error(dir->sb, "whoops! I broke a directory!");
355357

356-
if (adfs_dir_checkbyte(dir) != dir->newtail->dircheckbyte)
357-
goto bad_dir;
358-
#endif
359-
ret = 0;
360-
out:
361358
return ret;
362-
#if 1
363-
bad_dir:
364-
adfs_error(dir->sb, "whoops! I broke a directory!");
365-
return -EIO;
366-
#endif
367359
}
368360

369361
const struct adfs_dir_ops adfs_f_dir_ops = {

0 commit comments

Comments
 (0)