fs/adfs: factor out filename fixup

Move the filename fixup to adfs_object_fixup() so we only have one
implementation of this.

Acked-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
This commit is contained in:
Russell King 2019-03-24 13:22:28 +00:00
parent 411c49bcf3
commit adb514a4e0
3 changed files with 24 additions and 21 deletions

View File

@ -18,6 +18,19 @@ static DEFINE_RWLOCK(adfs_dir_lock);
void adfs_object_fixup(struct adfs_dir *dir, struct object_info *obj)
{
unsigned int i;
/*
* RISC OS allows the use of '/' in directory entry names, so we need
* to fix these up. '/' is typically used for FAT compatibility to
* represent '.', so do the same conversion here. In any case, '.'
* will never be in a RISC OS name since it is used as the pathname
* separator.
*/
for (i = 0; i < obj->name_len; i++)
if (obj->name[i] == '/')
obj->name[i] = '.';
obj->filetype = -1;
/*

View File

@ -41,21 +41,6 @@ static inline void adfs_writeval(unsigned char *p, int len, unsigned int val)
}
}
static inline int adfs_readname(char *buf, char *ptr, int maxlen)
{
char *old_buf = buf;
while ((unsigned char)*ptr >= ' ' && maxlen--) {
if (*ptr == '/')
*buf++ = '.';
else
*buf++ = *ptr;
ptr++;
}
return buf - old_buf;
}
#define ror13(v) ((v >> 13) | (v << 19))
#define dir_u8(idx) \
@ -210,7 +195,16 @@ static inline void
adfs_dir2obj(struct adfs_dir *dir, struct object_info *obj,
struct adfs_direntry *de)
{
obj->name_len = adfs_readname(obj->name, de->dirobname, ADFS_F_NAME_LEN);
unsigned int name_len;
for (name_len = 0; name_len < ADFS_F_NAME_LEN; name_len++) {
if (de->dirobname[name_len] < ' ')
break;
obj->name[name_len] = de->dirobname[name_len];
}
obj->name_len = name_len;
obj->file_id = adfs_readval(de->dirinddiscadd, 3);
obj->loadaddr = adfs_readval(de->dirload, 4);
obj->execaddr = adfs_readval(de->direxec, 4);

View File

@ -169,7 +169,7 @@ adfs_fplus_getnext(struct adfs_dir *dir, struct object_info *obj)
(struct adfs_bigdirheader *) dir->bh_fplus[0]->b_data;
struct adfs_bigdirentry bde;
unsigned int offset;
int i, ret = -ENOENT;
int ret = -ENOENT;
if (dir->pos >= le32_to_cpu(h->bigdirentries))
goto out;
@ -193,10 +193,6 @@ adfs_fplus_getnext(struct adfs_dir *dir, struct object_info *obj)
offset += le32_to_cpu(bde.bigdirobnameptr);
dir_memcpy(dir, offset, obj->name, obj->name_len);
for (i = 0; i < obj->name_len; i++)
if (obj->name[i] == '/')
obj->name[i] = '.';
adfs_object_fixup(dir, obj);
dir->pos += 1;