Skip to content

Commit cc625cc

Browse files
Russell KingAl Viro
authored andcommitted
fs/adfs: newdir: clean up adfs_f_update()
__adfs_dir_put() and adfs_dir_find_entry() are only called from adfs_f_update(), so move them into this function, removing some unnecessary entry copying by doing so. Signed-off-by: Russell King <[email protected]> Signed-off-by: Al Viro <[email protected]>
1 parent 9318731 commit cc625cc

File tree

1 file changed

+24
-49
lines changed

1 file changed

+24
-49
lines changed

fs/adfs/dir_f.c

Lines changed: 24 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -229,46 +229,6 @@ __adfs_dir_get(struct adfs_dir *dir, int pos, struct object_info *obj)
229229
return 0;
230230
}
231231

232-
static int
233-
__adfs_dir_put(struct adfs_dir *dir, int pos, struct object_info *obj)
234-
{
235-
struct adfs_direntry de;
236-
int ret;
237-
238-
ret = adfs_dir_copyfrom(&de, dir, pos, 26);
239-
if (ret)
240-
return ret;
241-
242-
adfs_obj2dir(&de, obj);
243-
244-
return adfs_dir_copyto(dir, pos, &de, 26);
245-
}
246-
247-
/*
248-
* the caller is responsible for holding the necessary
249-
* locks.
250-
*/
251-
static int adfs_dir_find_entry(struct adfs_dir *dir, u32 indaddr)
252-
{
253-
int pos, ret;
254-
255-
ret = -ENOENT;
256-
257-
for (pos = 5; pos < ADFS_NUM_DIR_ENTRIES * 26 + 5; pos += 26) {
258-
struct object_info obj;
259-
260-
if (!__adfs_dir_get(dir, pos, &obj))
261-
break;
262-
263-
if (obj.indaddr == indaddr) {
264-
ret = pos;
265-
break;
266-
}
267-
}
268-
269-
return ret;
270-
}
271-
272232
static int
273233
adfs_f_setpos(struct adfs_dir *dir, unsigned int fpos)
274234
{
@@ -308,18 +268,33 @@ static int adfs_f_iterate(struct adfs_dir *dir, struct dir_context *ctx)
308268
return 0;
309269
}
310270

311-
static int
312-
adfs_f_update(struct adfs_dir *dir, struct object_info *obj)
271+
static int adfs_f_update(struct adfs_dir *dir, struct object_info *obj)
313272
{
314-
int ret;
273+
struct adfs_direntry de;
274+
int offset, ret;
315275

316-
ret = adfs_dir_find_entry(dir, obj->indaddr);
317-
if (ret < 0) {
318-
adfs_error(dir->sb, "unable to locate entry to update");
319-
return ret;
320-
}
276+
offset = 5 - (int)sizeof(de);
277+
278+
do {
279+
offset += sizeof(de);
280+
ret = adfs_dir_copyfrom(&de, dir, offset, sizeof(de));
281+
if (ret) {
282+
adfs_error(dir->sb, "error reading directory entry");
283+
return -ENOENT;
284+
}
285+
if (!de.dirobname[0]) {
286+
adfs_error(dir->sb, "unable to locate entry to update");
287+
return -ENOENT;
288+
}
289+
} while (adfs_readval(de.dirinddiscadd, 3) != obj->indaddr);
290+
291+
/* Update the directory entry with the new object state */
292+
adfs_obj2dir(&de, obj);
321293

322-
__adfs_dir_put(dir, ret, obj);
294+
/* Write the directory entry back to the directory */
295+
ret = adfs_dir_copyto(dir, pos, &de, 26);
296+
if (ret)
297+
return ret;
323298

324299
/*
325300
* Increment directory sequence number

0 commit comments

Comments
 (0)