int (*create)(struct adfs_dir *dir, struct object_info *obj);
int (*remove)(struct adfs_dir *dir, struct object_info *obj);
int (*sync)(struct adfs_dir *dir);
- void (*free)(struct adfs_dir *dir);
};
struct adfs_discmap {
extern const struct adfs_dir_ops adfs_f_dir_ops;
extern const struct adfs_dir_ops adfs_fplus_dir_ops;
+void adfs_dir_relse(struct adfs_dir *dir);
void adfs_object_fixup(struct adfs_dir *dir, struct object_info *obj);
extern int adfs_dir_update(struct super_block *sb, struct object_info *obj,
int wait);
*
* Common directory handling for ADFS
*/
+#include <linux/slab.h>
#include "adfs.h"
/*
*/
static DEFINE_RWLOCK(adfs_dir_lock);
+void adfs_dir_relse(struct adfs_dir *dir)
+{
+ unsigned int i;
+
+ for (i = 0; i < dir->nr_buffers; i++)
+ brelse(dir->bhs[i]);
+ dir->nr_buffers = 0;
+
+ if (dir->bhs != dir->bh)
+ kfree(dir->bhs);
+ dir->bhs = NULL;
+ dir->sb = NULL;
+}
+
static int adfs_dir_read(struct super_block *sb, u32 indaddr,
unsigned int size, struct adfs_dir *dir)
{
read_unlock(&adfs_dir_lock);
free_out:
- ops->free(&dir);
+ adfs_dir_relse(&dir);
return ret;
}
ret = err;
}
- ops->free(&dir);
+ adfs_dir_relse(&dir);
out:
#endif
return ret;
read_unlock(&adfs_dir_lock);
free_out:
- ops->free(&dir);
+ adfs_dir_relse(&dir);
out:
return ret;
}
#include "adfs.h"
#include "dir_f.h"
-static void adfs_f_free(struct adfs_dir *dir);
-
/*
* Read an (unaligned) value of length 1..4 bytes
*/
unsigned int size, struct adfs_dir *dir)
{
const unsigned int blocksize_bits = sb->s_blocksize_bits;
- int blk = 0;
+ int blk;
/*
* Directories which are not a multiple of 2048 bytes
dir->bh[blk] = sb_bread(sb, phys);
if (!dir->bh[blk])
goto release_buffers;
+
+ dir->nr_buffers += 1;
}
memcpy(&dir->dirhead, bufoff(dir->bh, 0), sizeof(dir->dirhead));
if (adfs_dir_checkbyte(dir) != dir->dirtail.new.dircheckbyte)
goto bad_dir;
- dir->nr_buffers = blk;
-
return 0;
bad_dir:
adfs_error(sb, "dir %06x is corrupted", indaddr);
release_buffers:
- for (blk -= 1; blk >= 0; blk -= 1)
- brelse(dir->bh[blk]);
-
- dir->sb = NULL;
+ adfs_dir_relse(dir);
return -EIO;
}
return err;
}
-static void
-adfs_f_free(struct adfs_dir *dir)
-{
- int i;
-
- for (i = dir->nr_buffers - 1; i >= 0; i--) {
- brelse(dir->bh[i]);
- dir->bh[i] = NULL;
- }
-
- dir->nr_buffers = 0;
- dir->sb = NULL;
-}
-
const struct adfs_dir_ops adfs_f_dir_ops = {
.read = adfs_f_read,
.setpos = adfs_f_setpos,
.getnext = adfs_f_getnext,
.update = adfs_f_update,
.sync = adfs_f_sync,
- .free = adfs_f_free
};
struct adfs_bigdirtail *t;
unsigned long block;
unsigned int blk, size;
- int i, ret = -EIO;
+ int ret = -EIO;
block = __adfs_block_map(sb, id, 0);
if (!block) {
return 0;
out:
- if (dir->bhs) {
- for (i = 0; i < dir->nr_buffers; i++)
- brelse(dir->bhs[i]);
+ adfs_dir_relse(dir);
- if (&dir->bh[0] != dir->bhs)
- kfree(dir->bhs);
-
- dir->bhs = NULL;
- }
-
- dir->nr_buffers = 0;
- dir->sb = NULL;
return ret;
}
return err;
}
-static void
-adfs_fplus_free(struct adfs_dir *dir)
-{
- int i;
-
- if (dir->bhs) {
- for (i = 0; i < dir->nr_buffers; i++)
- brelse(dir->bhs[i]);
-
- if (&dir->bh[0] != dir->bhs)
- kfree(dir->bhs);
-
- dir->bhs = NULL;
- }
-
- dir->nr_buffers = 0;
- dir->sb = NULL;
-}
-
const struct adfs_dir_ops adfs_fplus_dir_ops = {
.read = adfs_fplus_read,
.setpos = adfs_fplus_setpos,
.getnext = adfs_fplus_getnext,
.sync = adfs_fplus_sync,
- .free = adfs_fplus_free
};