Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

adfs: add hexadecimal filetype suffix option

ADFS (FileCore) storage complies with the RISC OS filetype specification
(12 bits of file type information is stored in the file load address,
rather than using a file extension). The existing driver largely ignores
this information and does not present it to the end user.

It is desirable that stored filetypes be made visible to the end user to
facilitate a precise copy of data and metadata from a hard disc (or image
thereof) into a RISC OS emulator (such as RPCEmu) or to a network share
which can be accessed by real Acorn systems.

This patch implements a per-mount filetype suffix option (use -o
ftsuffix=1) to present any filetype as a ,xyz hexadecimal suffix on each
file. This type suffix is compatible with that used by RISC OS systems
that access network servers using NFS client software and by RPCemu's host
filing system.

Signed-off-by: Stuart Swales <stuart.swales.croftnuisk@gmail.com>
Cc: Russell King <rmk@arm.linux.org.uk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Stuart Swales and committed by
Linus Torvalds
da23ef05 7a9730af

+99 -26
+18
Documentation/filesystems/adfs.txt
··· 9 9 will be nnn. Default 0700. 10 10 othmask=nnn The permission mask for ADFS 'other' permissions 11 11 will be nnn. Default 0077. 12 + ftsuffix=n When ftsuffix=0, no file type suffix will be applied. 13 + When ftsuffix=1, a hexadecimal suffix corresponding to 14 + the RISC OS file type will be added. Default 0. 12 15 13 16 Mapping of ADFS permissions to Linux permissions 14 17 ------------------------------------------------ ··· 58 55 59 56 You can therefore tailor the permission translation to whatever you 60 57 desire the permissions should be under Linux. 58 + 59 + RISC OS file type suffix 60 + ------------------------ 61 + 62 + RISC OS file types are stored in bits 19..8 of the file load address. 63 + 64 + To enable non-RISC OS systems to be used to store files without losing 65 + file type information, a file naming convention was devised (initially 66 + for use with NFS) such that a hexadecimal suffix of the form ,xyz 67 + denoted the file type: e.g. BasicFile,ffb is a BASIC (0xffb) file. This 68 + naming convention is now also used by RISC OS emulators such as RPCEmu. 69 + 70 + Mounting an ADFS disc with option ftsuffix=1 will cause appropriate file 71 + type suffixes to be appended to file names read from a directory. If the 72 + ftsuffix option is zero or omitted, no file type suffixes will be added.
+19 -2
fs/adfs/adfs.h
··· 50 50 gid_t s_gid; /* owner gid */ 51 51 umode_t s_owner_mask; /* ADFS owner perm -> unix perm */ 52 52 umode_t s_other_mask; /* ADFS other perm -> unix perm */ 53 + int s_ftsuffix; /* ,xyz hex filetype suffix option */ 53 54 54 55 __u32 s_ids_per_zone; /* max. no ids in one zone */ 55 56 __u32 s_idlen; /* length of ID in map */ ··· 94 93 /* 95 94 * This is the overall maximum name length 96 95 */ 97 - #define ADFS_MAX_NAME_LEN 256 96 + #define ADFS_MAX_NAME_LEN (256 + 4) /* +4 for ,xyz hex filetype suffix */ 98 97 struct object_info { 99 98 __u32 parent_id; /* parent object id */ 100 99 __u32 file_id; /* object id */ ··· 102 101 __u32 execaddr; /* execution address */ 103 102 __u32 size; /* size */ 104 103 __u8 attr; /* RISC OS attributes */ 105 - unsigned char name_len; /* name length */ 104 + unsigned int name_len; /* name length */ 106 105 char name[ADFS_MAX_NAME_LEN];/* file name */ 106 + 107 + /* RISC OS file type (12-bit: derived from loadaddr) */ 108 + __u16 filetype; 107 109 }; 110 + 111 + /* RISC OS 12-bit filetype converts to ,xyz hex filename suffix */ 112 + static inline int append_filetype_suffix(char *buf, __u16 filetype) 113 + { 114 + if (filetype == -1) 115 + return 0; 116 + 117 + *buf++ = ','; 118 + *buf++ = hex_asc_lo(filetype >> 8); 119 + *buf++ = hex_asc_lo(filetype >> 4); 120 + *buf++ = hex_asc_lo(filetype >> 0); 121 + return 4; 122 + } 108 123 109 124 struct adfs_dir_ops { 110 125 int (*read)(struct super_block *sb, unsigned int id, unsigned int sz, struct adfs_dir *dir);
+20 -3
fs/adfs/dir_f.c
··· 52 52 *buf++ = *ptr; 53 53 ptr++; 54 54 } 55 - *buf = '\0'; 56 55 57 56 return buf - old_buf; 58 57 } ··· 207 208 * convert a disk-based directory entry to a Linux ADFS directory entry 208 209 */ 209 210 static inline void 210 - adfs_dir2obj(struct object_info *obj, struct adfs_direntry *de) 211 + adfs_dir2obj(struct adfs_dir *dir, struct object_info *obj, 212 + struct adfs_direntry *de) 211 213 { 212 214 obj->name_len = adfs_readname(obj->name, de->dirobname, ADFS_F_NAME_LEN); 213 215 obj->file_id = adfs_readval(de->dirinddiscadd, 3); ··· 216 216 obj->execaddr = adfs_readval(de->direxec, 4); 217 217 obj->size = adfs_readval(de->dirlen, 4); 218 218 obj->attr = de->newdiratts; 219 + obj->filetype = -1; 220 + 221 + /* 222 + * object is a file and is filetyped and timestamped? 223 + * RISC OS 12-bit filetype is stored in load_address[19:8] 224 + */ 225 + if ((0 == (obj->attr & ADFS_NDA_DIRECTORY)) && 226 + (0xfff00000 == (0xfff00000 & obj->loadaddr))) { 227 + obj->filetype = (__u16) ((0x000fff00 & obj->loadaddr) >> 8); 228 + 229 + /* optionally append the ,xyz hex filetype suffix */ 230 + if (ADFS_SB(dir->sb)->s_ftsuffix) 231 + obj->name_len += 232 + append_filetype_suffix( 233 + &obj->name[obj->name_len], 234 + obj->filetype); 235 + } 219 236 } 220 237 221 238 /* ··· 277 260 if (!de.dirobname[0]) 278 261 return -ENOENT; 279 262 280 - adfs_dir2obj(obj, &de); 263 + adfs_dir2obj(dir, obj, &de); 281 264 282 265 return 0; 283 266 }
+18
fs/adfs/dir_fplus.c
··· 197 197 if (obj->name[i] == '/') 198 198 obj->name[i] = '.'; 199 199 200 + obj->filetype = -1; 201 + 202 + /* 203 + * object is a file and is filetyped and timestamped? 204 + * RISC OS 12-bit filetype is stored in load_address[19:8] 205 + */ 206 + if ((0 == (obj->attr & ADFS_NDA_DIRECTORY)) && 207 + (0xfff00000 == (0xfff00000 & obj->loadaddr))) { 208 + obj->filetype = (__u16) ((0x000fff00 & obj->loadaddr) >> 8); 209 + 210 + /* optionally append the ,xyz hex filetype suffix */ 211 + if (ADFS_SB(dir->sb)->s_ftsuffix) 212 + obj->name_len += 213 + append_filetype_suffix( 214 + &obj->name[obj->name_len], 215 + obj->filetype); 216 + } 217 + 200 218 dir->pos += 1; 201 219 ret = 0; 202 220 out:
+4 -18
fs/adfs/inode.c
··· 78 78 .bmap = _adfs_bmap 79 79 }; 80 80 81 - static inline unsigned int 82 - adfs_filetype(struct inode *inode) 83 - { 84 - unsigned int type; 85 - 86 - if (ADFS_I(inode)->stamped) 87 - type = (ADFS_I(inode)->loadaddr >> 8) & 0xfff; 88 - else 89 - type = (unsigned int) -1; 90 - 91 - return type; 92 - } 93 - 94 81 /* 95 82 * Convert ADFS attributes and filetype to Linux permission. 96 83 */ 97 84 static umode_t 98 85 adfs_atts2mode(struct super_block *sb, struct inode *inode) 99 86 { 100 - unsigned int filetype, attr = ADFS_I(inode)->attr; 87 + unsigned int attr = ADFS_I(inode)->attr; 101 88 umode_t mode, rmask; 102 89 struct adfs_sb_info *asb = ADFS_SB(sb); 103 90 ··· 93 106 return S_IFDIR | S_IXUGO | mode; 94 107 } 95 108 96 - filetype = adfs_filetype(inode); 97 - 98 - switch (filetype) { 109 + switch (ADFS_I(inode)->filetype) { 99 110 case 0xfc0: /* LinkFS */ 100 111 return S_IFLNK|S_IRWXUGO; 101 112 ··· 262 277 ADFS_I(inode)->loadaddr = obj->loadaddr; 263 278 ADFS_I(inode)->execaddr = obj->execaddr; 264 279 ADFS_I(inode)->attr = obj->attr; 265 - ADFS_I(inode)->stamped = ((obj->loadaddr & 0xfff00000) == 0xfff00000); 280 + ADFS_I(inode)->filetype = obj->filetype; 281 + ADFS_I(inode)->stamped = ((obj->loadaddr & 0xfff00000) == 0xfff00000); 266 282 267 283 inode->i_mode = adfs_atts2mode(sb, inode); 268 284 adfs_adfs2unix_time(&inode->i_mtime, inode);
+20 -3
fs/adfs/super.c
··· 138 138 seq_printf(seq, ",ownmask=%o", asb->s_owner_mask); 139 139 if (asb->s_other_mask != ADFS_DEFAULT_OTHER_MASK) 140 140 seq_printf(seq, ",othmask=%o", asb->s_other_mask); 141 + if (asb->s_ftsuffix != 0) 142 + seq_printf(seq, ",ftsuffix=%u", asb->s_ftsuffix); 141 143 142 144 return 0; 143 145 } 144 146 145 - enum {Opt_uid, Opt_gid, Opt_ownmask, Opt_othmask, Opt_err}; 147 + enum {Opt_uid, Opt_gid, Opt_ownmask, Opt_othmask, Opt_ftsuffix, Opt_err}; 146 148 147 149 static const match_table_t tokens = { 148 150 {Opt_uid, "uid=%u"}, 149 151 {Opt_gid, "gid=%u"}, 150 152 {Opt_ownmask, "ownmask=%o"}, 151 153 {Opt_othmask, "othmask=%o"}, 154 + {Opt_ftsuffix, "ftsuffix=%u"}, 152 155 {Opt_err, NULL} 153 156 }; 154 157 ··· 191 188 if (match_octal(args, &option)) 192 189 return -EINVAL; 193 190 asb->s_other_mask = option; 191 + break; 192 + case Opt_ftsuffix: 193 + if (match_int(args, &option)) 194 + return -EINVAL; 195 + asb->s_ftsuffix = option; 194 196 break; 195 197 default: 196 198 printk("ADFS-fs: unrecognised mount option \"%s\" " ··· 374 366 asb->s_gid = 0; 375 367 asb->s_owner_mask = ADFS_DEFAULT_OWNER_MASK; 376 368 asb->s_other_mask = ADFS_DEFAULT_OTHER_MASK; 369 + asb->s_ftsuffix = 0; 377 370 378 371 if (parse_options(sb, data)) 379 372 goto error; ··· 454 445 455 446 root_obj.parent_id = root_obj.file_id = le32_to_cpu(dr->root); 456 447 root_obj.name_len = 0; 457 - root_obj.loadaddr = 0; 458 - root_obj.execaddr = 0; 448 + /* Set root object date as 01 Jan 1987 00:00:00 */ 449 + root_obj.loadaddr = 0xfff0003f; 450 + root_obj.execaddr = 0xec22c000; 459 451 root_obj.size = ADFS_NEWDIR_SIZE; 460 452 root_obj.attr = ADFS_NDA_DIRECTORY | ADFS_NDA_OWNER_READ | 461 453 ADFS_NDA_OWNER_WRITE | ADFS_NDA_PUBLIC_READ; 454 + root_obj.filetype = -1; 462 455 463 456 /* 464 457 * If this is a F+ disk with variable length directories, ··· 474 463 asb->s_dir = &adfs_f_dir_ops; 475 464 asb->s_namelen = ADFS_F_NAME_LEN; 476 465 } 466 + /* 467 + * ,xyz hex filetype suffix may be added by driver 468 + * to files that have valid RISC OS filetype 469 + */ 470 + if (asb->s_ftsuffix) 471 + asb->s_namelen += 4; 477 472 478 473 sb->s_d_op = &adfs_dentry_operations; 479 474 root = adfs_iget(sb, &root_obj);