@@ -121,6 +121,21 @@ adfs_dir_checkbyte(const struct adfs_dir *dir)
121
121
return (dircheck ^ (dircheck >> 8 ) ^ (dircheck >> 16 ) ^ (dircheck >> 24 )) & 0xff ;
122
122
}
123
123
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
+
124
139
/* Read and check that a directory is valid */
125
140
static int adfs_dir_read (struct super_block * sb , u32 indaddr ,
126
141
unsigned int size , struct adfs_dir * dir )
@@ -142,15 +157,7 @@ static int adfs_dir_read(struct super_block *sb, u32 indaddr,
142
157
dir -> dirhead = bufoff (dir -> bh , 0 );
143
158
dir -> newtail = bufoff (dir -> bh , 2007 );
144
159
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 ))
154
161
goto bad_dir ;
155
162
156
163
return 0 ;
@@ -327,7 +334,7 @@ adfs_f_update(struct adfs_dir *dir, struct object_info *obj)
327
334
ret = adfs_dir_find_entry (dir , obj -> indaddr );
328
335
if (ret < 0 ) {
329
336
adfs_error (dir -> sb , "unable to locate entry to update" );
330
- goto out ;
337
+ return ret ;
331
338
}
332
339
333
340
__adfs_dir_put (dir , ret , obj );
@@ -344,26 +351,11 @@ adfs_f_update(struct adfs_dir *dir, struct object_info *obj)
344
351
*/
345
352
dir -> newtail -> dircheckbyte = ret ;
346
353
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!" );
355
357
356
- if (adfs_dir_checkbyte (dir ) != dir -> newtail -> dircheckbyte )
357
- goto bad_dir ;
358
- #endif
359
- ret = 0 ;
360
- out :
361
358
return ret ;
362
- #if 1
363
- bad_dir :
364
- adfs_error (dir -> sb , "whoops! I broke a directory!" );
365
- return - EIO ;
366
- #endif
367
359
}
368
360
369
361
const struct adfs_dir_ops adfs_f_dir_ops = {
0 commit comments