fs/adfs: clean up indirect disc addresses and fragment IDs

We use a variety of different names for the indirect disc address of
the current object, use a variety of different types, and print it in
a variety of different ways. Bring some consistency to this by naming
it "indaddr", use u32 or __u32 as the type since it fits in 32-bits,
and always print it with %06x (with no leading hex prefix.)

When printing it was a directory identifer, use "dir %06x" otherwise
use "object %06x".

Do the same for fragment IDs and the parent indirect disc addresses.

Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
Russell King 2019-06-04 14:49:57 +01:00 committed by Al Viro
parent ceb3b10613
commit 5ed70bb477
7 changed files with 41 additions and 49 deletions

View File

@ -24,7 +24,7 @@
*/ */
struct adfs_inode_info { struct adfs_inode_info {
loff_t mmu_private; loff_t mmu_private;
unsigned long parent_id; /* object id of parent */ __u32 parent_id; /* parent indirect disc address */
__u32 loadaddr; /* RISC OS load address */ __u32 loadaddr; /* RISC OS load address */
__u32 execaddr; /* RISC OS exec address */ __u32 execaddr; /* RISC OS exec address */
unsigned int filetype; /* RISC OS file type */ unsigned int filetype; /* RISC OS file type */
@ -86,7 +86,7 @@ struct adfs_dir {
struct buffer_head **bh_fplus; struct buffer_head **bh_fplus;
unsigned int pos; unsigned int pos;
unsigned int parent_id; __u32 parent_id;
struct adfs_dirheader dirhead; struct adfs_dirheader dirhead;
union adfs_dirtail dirtail; union adfs_dirtail dirtail;
@ -98,7 +98,7 @@ struct adfs_dir {
#define ADFS_MAX_NAME_LEN (256 + 4) /* +4 for ,xyz hex filetype suffix */ #define ADFS_MAX_NAME_LEN (256 + 4) /* +4 for ,xyz hex filetype suffix */
struct object_info { struct object_info {
__u32 parent_id; /* parent object id */ __u32 parent_id; /* parent object id */
__u32 file_id; /* object id */ __u32 indaddr; /* indirect disc addr */
__u32 loadaddr; /* load address */ __u32 loadaddr; /* load address */
__u32 execaddr; /* execution address */ __u32 execaddr; /* execution address */
__u32 size; /* size */ __u32 size; /* size */
@ -111,7 +111,8 @@ struct object_info {
}; };
struct adfs_dir_ops { struct adfs_dir_ops {
int (*read)(struct super_block *sb, unsigned int id, unsigned int sz, struct adfs_dir *dir); int (*read)(struct super_block *sb, unsigned int indaddr,
unsigned int size, struct adfs_dir *dir);
int (*setpos)(struct adfs_dir *dir, unsigned int fpos); int (*setpos)(struct adfs_dir *dir, unsigned int fpos);
int (*getnext)(struct adfs_dir *dir, struct object_info *obj); int (*getnext)(struct adfs_dir *dir, struct object_info *obj);
int (*update)(struct adfs_dir *dir, struct object_info *obj); int (*update)(struct adfs_dir *dir, struct object_info *obj);
@ -134,7 +135,7 @@ int adfs_write_inode(struct inode *inode, struct writeback_control *wbc);
int adfs_notify_change(struct dentry *dentry, struct iattr *attr); int adfs_notify_change(struct dentry *dentry, struct iattr *attr);
/* map.c */ /* map.c */
extern int adfs_map_lookup(struct super_block *sb, unsigned int frag_id, unsigned int offset); int adfs_map_lookup(struct super_block *sb, u32 frag_id, unsigned int offset);
extern unsigned int adfs_map_free(struct super_block *sb); extern unsigned int adfs_map_free(struct super_block *sb);
/* Misc */ /* Misc */
@ -180,18 +181,17 @@ static inline __u32 signed_asl(__u32 val, signed int shift)
* *
* The root directory ID should always be looked up in the map [3.4] * The root directory ID should always be looked up in the map [3.4]
*/ */
static inline int static inline int __adfs_block_map(struct super_block *sb, u32 indaddr,
__adfs_block_map(struct super_block *sb, unsigned int object_id, unsigned int block)
unsigned int block)
{ {
if (object_id & 255) { if (indaddr & 255) {
unsigned int off; unsigned int off;
off = (object_id & 255) - 1; off = (indaddr & 255) - 1;
block += off << ADFS_SB(sb)->s_log2sharesize; block += off << ADFS_SB(sb)->s_log2sharesize;
} }
return adfs_map_lookup(sb, object_id >> 8, block); return adfs_map_lookup(sb, indaddr >> 8, block);
} }
/* Return the disc record from the map */ /* Return the disc record from the map */

View File

@ -95,7 +95,7 @@ adfs_readdir(struct file *file, struct dir_context *ctx)
goto unlock_out; goto unlock_out;
while (ops->getnext(&dir, &obj) == 0) { while (ops->getnext(&dir, &obj) == 0) {
if (!dir_emit(ctx, obj.name, obj.name_len, if (!dir_emit(ctx, obj.name, obj.name_len,
obj.file_id, DT_UNKNOWN)) obj.indaddr, DT_UNKNOWN))
break; break;
ctx->pos++; ctx->pos++;
} }
@ -116,8 +116,8 @@ adfs_dir_update(struct super_block *sb, struct object_info *obj, int wait)
const struct adfs_dir_ops *ops = ADFS_SB(sb)->s_dir; const struct adfs_dir_ops *ops = ADFS_SB(sb)->s_dir;
struct adfs_dir dir; struct adfs_dir dir;
printk(KERN_INFO "adfs_dir_update: object %06X in dir %06X\n", printk(KERN_INFO "adfs_dir_update: object %06x in dir %06x\n",
obj->file_id, obj->parent_id); obj->indaddr, obj->parent_id);
if (!ops->update) { if (!ops->update) {
ret = -EINVAL; ret = -EINVAL;
@ -181,7 +181,8 @@ static int adfs_dir_lookup_byname(struct inode *inode, const struct qstr *qstr,
goto out; goto out;
if (ADFS_I(inode)->parent_id != dir.parent_id) { if (ADFS_I(inode)->parent_id != dir.parent_id) {
adfs_error(sb, "parent directory changed under me! (%lx but got %x)\n", adfs_error(sb,
"parent directory changed under me! (%06x but got %06x)\n",
ADFS_I(inode)->parent_id, dir.parent_id); ADFS_I(inode)->parent_id, dir.parent_id);
ret = -EIO; ret = -EIO;
goto free_out; goto free_out;

View File

@ -126,12 +126,9 @@ adfs_dir_checkbyte(const struct adfs_dir *dir)
return (dircheck ^ (dircheck >> 8) ^ (dircheck >> 16) ^ (dircheck >> 24)) & 0xff; return (dircheck ^ (dircheck >> 8) ^ (dircheck >> 16) ^ (dircheck >> 24)) & 0xff;
} }
/* /* Read and check that a directory is valid */
* Read and check that a directory is valid static int adfs_dir_read(struct super_block *sb, u32 indaddr,
*/ unsigned int size, struct adfs_dir *dir)
static int
adfs_dir_read(struct super_block *sb, unsigned long object_id,
unsigned int size, struct adfs_dir *dir)
{ {
const unsigned int blocksize_bits = sb->s_blocksize_bits; const unsigned int blocksize_bits = sb->s_blocksize_bits;
int blk = 0; int blk = 0;
@ -151,10 +148,10 @@ adfs_dir_read(struct super_block *sb, unsigned long object_id,
for (blk = 0; blk < size; blk++) { for (blk = 0; blk < size; blk++) {
int phys; int phys;
phys = __adfs_block_map(sb, object_id, blk); phys = __adfs_block_map(sb, indaddr, blk);
if (!phys) { if (!phys) {
adfs_error(sb, "dir object %lX has a hole at offset %d", adfs_error(sb, "dir %06x has a hole at offset %d",
object_id, blk); indaddr, blk);
goto release_buffers; goto release_buffers;
} }
@ -182,8 +179,7 @@ adfs_dir_read(struct super_block *sb, unsigned long object_id,
return 0; return 0;
bad_dir: bad_dir:
adfs_error(sb, "corrupted directory fragment %lX", adfs_error(sb, "dir %06x is corrupted", indaddr);
object_id);
release_buffers: release_buffers:
for (blk -= 1; blk >= 0; blk -= 1) for (blk -= 1; blk >= 0; blk -= 1)
brelse(dir->bh[blk]); brelse(dir->bh[blk]);
@ -210,7 +206,7 @@ adfs_dir2obj(struct adfs_dir *dir, struct object_info *obj,
} }
obj->name_len = name_len; obj->name_len = name_len;
obj->file_id = adfs_readval(de->dirinddiscadd, 3); obj->indaddr = adfs_readval(de->dirinddiscadd, 3);
obj->loadaddr = adfs_readval(de->dirload, 4); obj->loadaddr = adfs_readval(de->dirload, 4);
obj->execaddr = adfs_readval(de->direxec, 4); obj->execaddr = adfs_readval(de->direxec, 4);
obj->size = adfs_readval(de->dirlen, 4); obj->size = adfs_readval(de->dirlen, 4);
@ -225,7 +221,7 @@ adfs_dir2obj(struct adfs_dir *dir, struct object_info *obj,
static inline void static inline void
adfs_obj2dir(struct adfs_direntry *de, struct object_info *obj) adfs_obj2dir(struct adfs_direntry *de, struct object_info *obj)
{ {
adfs_writeval(de->dirinddiscadd, 3, obj->file_id); adfs_writeval(de->dirinddiscadd, 3, obj->indaddr);
adfs_writeval(de->dirload, 4, obj->loadaddr); adfs_writeval(de->dirload, 4, obj->loadaddr);
adfs_writeval(de->direxec, 4, obj->execaddr); adfs_writeval(de->direxec, 4, obj->execaddr);
adfs_writeval(de->dirlen, 4, obj->size); adfs_writeval(de->dirlen, 4, obj->size);
@ -311,8 +307,7 @@ __adfs_dir_put(struct adfs_dir *dir, int pos, struct object_info *obj)
* the caller is responsible for holding the necessary * the caller is responsible for holding the necessary
* locks. * locks.
*/ */
static int static int adfs_dir_find_entry(struct adfs_dir *dir, u32 indaddr)
adfs_dir_find_entry(struct adfs_dir *dir, unsigned long object_id)
{ {
int pos, ret; int pos, ret;
@ -324,7 +319,7 @@ adfs_dir_find_entry(struct adfs_dir *dir, unsigned long object_id)
if (!__adfs_dir_get(dir, pos, &obj)) if (!__adfs_dir_get(dir, pos, &obj))
break; break;
if (obj.file_id == object_id) { if (obj.indaddr == indaddr) {
ret = pos; ret = pos;
break; break;
} }
@ -333,15 +328,15 @@ adfs_dir_find_entry(struct adfs_dir *dir, unsigned long object_id)
return ret; return ret;
} }
static int static int adfs_f_read(struct super_block *sb, u32 indaddr, unsigned int size,
adfs_f_read(struct super_block *sb, unsigned int id, unsigned int sz, struct adfs_dir *dir) struct adfs_dir *dir)
{ {
int ret; int ret;
if (sz != ADFS_NEWDIR_SIZE) if (size != ADFS_NEWDIR_SIZE)
return -EIO; return -EIO;
ret = adfs_dir_read(sb, id, sz, dir); ret = adfs_dir_read(sb, indaddr, size, dir);
if (ret) if (ret)
adfs_error(sb, "unable to read directory"); adfs_error(sb, "unable to read directory");
else else
@ -378,7 +373,7 @@ adfs_f_update(struct adfs_dir *dir, struct object_info *obj)
struct super_block *sb = dir->sb; struct super_block *sb = dir->sb;
int ret, i; int ret, i;
ret = adfs_dir_find_entry(dir, obj->file_id); ret = adfs_dir_find_entry(dir, obj->indaddr);
if (ret < 0) { if (ret < 0) {
adfs_error(dir->sb, "unable to locate entry to update"); adfs_error(dir->sb, "unable to locate entry to update");
goto out; goto out;

View File

@ -180,7 +180,7 @@ adfs_fplus_getnext(struct adfs_dir *dir, struct object_info *obj)
obj->loadaddr = le32_to_cpu(bde.bigdirload); obj->loadaddr = le32_to_cpu(bde.bigdirload);
obj->execaddr = le32_to_cpu(bde.bigdirexec); obj->execaddr = le32_to_cpu(bde.bigdirexec);
obj->size = le32_to_cpu(bde.bigdirlen); obj->size = le32_to_cpu(bde.bigdirlen);
obj->file_id = le32_to_cpu(bde.bigdirindaddr); obj->indaddr = le32_to_cpu(bde.bigdirindaddr);
obj->attr = le32_to_cpu(bde.bigdirattr); obj->attr = le32_to_cpu(bde.bigdirattr);
obj->name_len = le32_to_cpu(bde.bigdirobnamelen); obj->name_len = le32_to_cpu(bde.bigdirobnamelen);

View File

@ -250,7 +250,7 @@ adfs_iget(struct super_block *sb, struct object_info *obj)
inode->i_uid = ADFS_SB(sb)->s_uid; inode->i_uid = ADFS_SB(sb)->s_uid;
inode->i_gid = ADFS_SB(sb)->s_gid; inode->i_gid = ADFS_SB(sb)->s_gid;
inode->i_ino = obj->file_id; inode->i_ino = obj->indaddr;
inode->i_size = obj->size; inode->i_size = obj->size;
set_nlink(inode, 2); set_nlink(inode, 2);
inode->i_blocks = (inode->i_size + sb->s_blocksize - 1) >> inode->i_blocks = (inode->i_size + sb->s_blocksize - 1) >>
@ -358,7 +358,7 @@ int adfs_write_inode(struct inode *inode, struct writeback_control *wbc)
struct object_info obj; struct object_info obj;
int ret; int ret;
obj.file_id = inode->i_ino; obj.indaddr = inode->i_ino;
obj.name_len = 0; obj.name_len = 0;
obj.parent_id = ADFS_I(inode)->parent_id; obj.parent_id = ADFS_I(inode)->parent_id;
obj.loadaddr = ADFS_I(inode)->loadaddr; obj.loadaddr = ADFS_I(inode)->loadaddr;

View File

@ -66,9 +66,8 @@ static DEFINE_RWLOCK(adfs_map_lock);
* output of: * output of:
* gcc -D__KERNEL__ -O2 -I../../include -o - -S map.c * gcc -D__KERNEL__ -O2 -I../../include -o - -S map.c
*/ */
static int static int lookup_zone(const struct adfs_discmap *dm, const unsigned int idlen,
lookup_zone(const struct adfs_discmap *dm, const unsigned int idlen, const u32 frag_id, unsigned int *offset)
const unsigned int frag_id, unsigned int *offset)
{ {
const unsigned int mapsize = dm->dm_endbit; const unsigned int mapsize = dm->dm_endbit;
const u32 idmask = (1 << idlen) - 1; const u32 idmask = (1 << idlen) - 1;
@ -187,9 +186,8 @@ error:
return 0; return 0;
} }
static int static int scan_map(struct adfs_sb_info *asb, unsigned int zone,
scan_map(struct adfs_sb_info *asb, unsigned int zone, const u32 frag_id, unsigned int mapoff)
const unsigned int frag_id, unsigned int mapoff)
{ {
const unsigned int idlen = asb->s_idlen; const unsigned int idlen = asb->s_idlen;
struct adfs_discmap *dm, *dm_end; struct adfs_discmap *dm, *dm_end;
@ -243,9 +241,7 @@ adfs_map_free(struct super_block *sb)
return signed_asl(total, asb->s_map2blk); return signed_asl(total, asb->s_map2blk);
} }
int int adfs_map_lookup(struct super_block *sb, u32 frag_id, unsigned int offset)
adfs_map_lookup(struct super_block *sb, unsigned int frag_id,
unsigned int offset)
{ {
struct adfs_sb_info *asb = ADFS_SB(sb); struct adfs_sb_info *asb = ADFS_SB(sb);
unsigned int zone, mapoff; unsigned int zone, mapoff;

View File

@ -462,7 +462,7 @@ static int adfs_fill_super(struct super_block *sb, void *data, int silent)
dr = adfs_map_discrecord(asb->s_map); dr = adfs_map_discrecord(asb->s_map);
root_obj.parent_id = root_obj.file_id = le32_to_cpu(dr->root); root_obj.parent_id = root_obj.indaddr = le32_to_cpu(dr->root);
root_obj.name_len = 0; root_obj.name_len = 0;
/* Set root object date as 01 Jan 1987 00:00:00 */ /* Set root object date as 01 Jan 1987 00:00:00 */
root_obj.loadaddr = 0xfff0003f; root_obj.loadaddr = 0xfff0003f;