Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Al Viro | 608ba50 | 2009-06-16 14:52:13 -0400 | [diff] [blame] | 2 | #include <linux/fs.h> |
| 3 | #include <linux/adfs_fs.h> |
| 4 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | /* Internal data structures for ADFS */ |
| 6 | |
| 7 | #define ADFS_FREE_FRAG 0 |
| 8 | #define ADFS_BAD_FRAG 1 |
| 9 | #define ADFS_ROOT_FRAG 2 |
| 10 | |
| 11 | #define ADFS_NDA_OWNER_READ (1 << 0) |
| 12 | #define ADFS_NDA_OWNER_WRITE (1 << 1) |
| 13 | #define ADFS_NDA_LOCKED (1 << 2) |
| 14 | #define ADFS_NDA_DIRECTORY (1 << 3) |
| 15 | #define ADFS_NDA_EXECUTE (1 << 4) |
| 16 | #define ADFS_NDA_PUBLIC_READ (1 << 5) |
| 17 | #define ADFS_NDA_PUBLIC_WRITE (1 << 6) |
| 18 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include "dir_f.h" |
| 20 | |
| 21 | struct buffer_head; |
| 22 | |
| 23 | /* |
Al Viro | 608ba50 | 2009-06-16 14:52:13 -0400 | [diff] [blame] | 24 | * adfs file system inode data in memory |
| 25 | */ |
| 26 | struct adfs_inode_info { |
| 27 | loff_t mmu_private; |
| 28 | unsigned long parent_id; /* object id of parent */ |
| 29 | __u32 loadaddr; /* RISC OS load address */ |
| 30 | __u32 execaddr; /* RISC OS exec address */ |
| 31 | unsigned int filetype; /* RISC OS file type */ |
| 32 | unsigned int attr; /* RISC OS permissions */ |
| 33 | unsigned int stamped:1; /* RISC OS file has date/time */ |
| 34 | struct inode vfs_inode; |
| 35 | }; |
| 36 | |
| 37 | /* |
| 38 | * Forward-declare this |
| 39 | */ |
| 40 | struct adfs_discmap; |
| 41 | struct adfs_dir_ops; |
| 42 | |
| 43 | /* |
| 44 | * ADFS file system superblock data in memory |
| 45 | */ |
| 46 | struct adfs_sb_info { |
Al Viro | 2d1d9b5 | 2013-10-03 12:37:18 -0400 | [diff] [blame] | 47 | union { struct { |
Andrew Morton | 90d6cd5 | 2016-01-20 15:01:16 -0800 | [diff] [blame] | 48 | struct adfs_discmap *s_map; /* bh list containing map */ |
| 49 | const struct adfs_dir_ops *s_dir; /* directory operations */ |
Al Viro | 2d1d9b5 | 2013-10-03 12:37:18 -0400 | [diff] [blame] | 50 | }; |
Andrew Morton | 90d6cd5 | 2016-01-20 15:01:16 -0800 | [diff] [blame] | 51 | struct rcu_head rcu; /* used only at shutdown time */ |
Al Viro | 2d1d9b5 | 2013-10-03 12:37:18 -0400 | [diff] [blame] | 52 | }; |
Andrew Morton | 90d6cd5 | 2016-01-20 15:01:16 -0800 | [diff] [blame] | 53 | kuid_t s_uid; /* owner uid */ |
| 54 | kgid_t s_gid; /* owner gid */ |
| 55 | umode_t s_owner_mask; /* ADFS owner perm -> unix perm */ |
| 56 | umode_t s_other_mask; /* ADFS other perm -> unix perm */ |
Stuart Swales | da23ef0 | 2011-03-22 16:35:06 -0700 | [diff] [blame] | 57 | int s_ftsuffix; /* ,xyz hex filetype suffix option */ |
Al Viro | 608ba50 | 2009-06-16 14:52:13 -0400 | [diff] [blame] | 58 | |
Andrew Morton | 90d6cd5 | 2016-01-20 15:01:16 -0800 | [diff] [blame] | 59 | __u32 s_ids_per_zone; /* max. no ids in one zone */ |
| 60 | __u32 s_idlen; /* length of ID in map */ |
| 61 | __u32 s_map_size; /* sector size of a map */ |
| 62 | unsigned long s_size; /* total size (in blocks) of this fs */ |
| 63 | signed int s_map2blk; /* shift left by this for map->sector*/ |
| 64 | unsigned int s_log2sharesize;/* log2 share size */ |
| 65 | __le32 s_version; /* disc format version */ |
Al Viro | 608ba50 | 2009-06-16 14:52:13 -0400 | [diff] [blame] | 66 | unsigned int s_namelen; /* maximum number of characters in name */ |
| 67 | }; |
| 68 | |
| 69 | static inline struct adfs_sb_info *ADFS_SB(struct super_block *sb) |
| 70 | { |
| 71 | return sb->s_fs_info; |
| 72 | } |
| 73 | |
| 74 | static inline struct adfs_inode_info *ADFS_I(struct inode *inode) |
| 75 | { |
| 76 | return container_of(inode, struct adfs_inode_info, vfs_inode); |
| 77 | } |
| 78 | |
| 79 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | * Directory handling |
| 81 | */ |
| 82 | struct adfs_dir { |
| 83 | struct super_block *sb; |
| 84 | |
| 85 | int nr_buffers; |
| 86 | struct buffer_head *bh[4]; |
Stuart Swales | 2f09719 | 2011-03-22 16:35:04 -0700 | [diff] [blame] | 87 | |
| 88 | /* big directories need allocated buffers */ |
| 89 | struct buffer_head **bh_fplus; |
| 90 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | unsigned int pos; |
| 92 | unsigned int parent_id; |
| 93 | |
| 94 | struct adfs_dirheader dirhead; |
| 95 | union adfs_dirtail dirtail; |
| 96 | }; |
| 97 | |
| 98 | /* |
| 99 | * This is the overall maximum name length |
| 100 | */ |
Stuart Swales | da23ef0 | 2011-03-22 16:35:06 -0700 | [diff] [blame] | 101 | #define ADFS_MAX_NAME_LEN (256 + 4) /* +4 for ,xyz hex filetype suffix */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | struct object_info { |
| 103 | __u32 parent_id; /* parent object id */ |
| 104 | __u32 file_id; /* object id */ |
| 105 | __u32 loadaddr; /* load address */ |
| 106 | __u32 execaddr; /* execution address */ |
| 107 | __u32 size; /* size */ |
| 108 | __u8 attr; /* RISC OS attributes */ |
Stuart Swales | da23ef0 | 2011-03-22 16:35:06 -0700 | [diff] [blame] | 109 | unsigned int name_len; /* name length */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | char name[ADFS_MAX_NAME_LEN];/* file name */ |
Stuart Swales | da23ef0 | 2011-03-22 16:35:06 -0700 | [diff] [blame] | 111 | |
| 112 | /* RISC OS file type (12-bit: derived from loadaddr) */ |
| 113 | __u16 filetype; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | }; |
| 115 | |
| 116 | struct adfs_dir_ops { |
| 117 | int (*read)(struct super_block *sb, unsigned int id, unsigned int sz, struct adfs_dir *dir); |
| 118 | int (*setpos)(struct adfs_dir *dir, unsigned int fpos); |
| 119 | int (*getnext)(struct adfs_dir *dir, struct object_info *obj); |
| 120 | int (*update)(struct adfs_dir *dir, struct object_info *obj); |
| 121 | int (*create)(struct adfs_dir *dir, struct object_info *obj); |
| 122 | int (*remove)(struct adfs_dir *dir, struct object_info *obj); |
Al Viro | ffdc906 | 2009-06-08 00:44:42 -0400 | [diff] [blame] | 123 | int (*sync)(struct adfs_dir *dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | void (*free)(struct adfs_dir *dir); |
| 125 | }; |
| 126 | |
| 127 | struct adfs_discmap { |
| 128 | struct buffer_head *dm_bh; |
| 129 | __u32 dm_startblk; |
| 130 | unsigned int dm_startbit; |
| 131 | unsigned int dm_endbit; |
| 132 | }; |
| 133 | |
| 134 | /* Inode stuff */ |
| 135 | struct inode *adfs_iget(struct super_block *sb, struct object_info *obj); |
Christoph Hellwig | a9185b4 | 2010-03-05 09:21:37 +0100 | [diff] [blame] | 136 | int adfs_write_inode(struct inode *inode, struct writeback_control *wbc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | int adfs_notify_change(struct dentry *dentry, struct iattr *attr); |
| 138 | |
| 139 | /* map.c */ |
| 140 | extern int adfs_map_lookup(struct super_block *sb, unsigned int frag_id, unsigned int offset); |
| 141 | extern unsigned int adfs_map_free(struct super_block *sb); |
| 142 | |
| 143 | /* Misc */ |
Joe Perches | 19bdd41a5 | 2014-08-08 14:22:26 -0700 | [diff] [blame] | 144 | __printf(3, 4) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | void __adfs_error(struct super_block *sb, const char *function, |
| 146 | const char *fmt, ...); |
Harvey Harrison | 8e24eea | 2008-04-30 00:55:09 -0700 | [diff] [blame] | 147 | #define adfs_error(sb, fmt...) __adfs_error(sb, __func__, fmt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | |
| 149 | /* super.c */ |
| 150 | |
| 151 | /* |
| 152 | * Inodes and file operations |
| 153 | */ |
| 154 | |
| 155 | /* dir_*.c */ |
Arjan van de Ven | 754661f | 2007-02-12 00:55:38 -0800 | [diff] [blame] | 156 | extern const struct inode_operations adfs_dir_inode_operations; |
Arjan van de Ven | 4b6f5d2 | 2006-03-28 01:56:42 -0800 | [diff] [blame] | 157 | extern const struct file_operations adfs_dir_operations; |
Al Viro | e16404e | 2009-02-20 05:55:13 +0000 | [diff] [blame] | 158 | extern const struct dentry_operations adfs_dentry_operations; |
Julia Lawall | 0125f50 | 2015-11-21 16:15:37 +0100 | [diff] [blame] | 159 | extern const struct adfs_dir_ops adfs_f_dir_ops; |
| 160 | extern const struct adfs_dir_ops adfs_fplus_dir_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | |
Russell King | 411c49b | 2019-03-24 12:57:32 +0000 | [diff] [blame] | 162 | void adfs_object_fixup(struct adfs_dir *dir, struct object_info *obj); |
Al Viro | ffdc906 | 2009-06-08 00:44:42 -0400 | [diff] [blame] | 163 | extern int adfs_dir_update(struct super_block *sb, struct object_info *obj, |
| 164 | int wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | |
| 166 | /* file.c */ |
Arjan van de Ven | 754661f | 2007-02-12 00:55:38 -0800 | [diff] [blame] | 167 | extern const struct inode_operations adfs_file_inode_operations; |
Arjan van de Ven | 4b6f5d2 | 2006-03-28 01:56:42 -0800 | [diff] [blame] | 168 | extern const struct file_operations adfs_file_operations; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | |
Adrian Bunk | e0c9314 | 2005-08-20 17:20:28 +0100 | [diff] [blame] | 170 | static inline __u32 signed_asl(__u32 val, signed int shift) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | { |
| 172 | if (shift >= 0) |
| 173 | val <<= shift; |
| 174 | else |
| 175 | val >>= -shift; |
| 176 | return val; |
| 177 | } |
| 178 | |
| 179 | /* |
| 180 | * Calculate the address of a block in an object given the block offset |
| 181 | * and the object identity. |
| 182 | * |
| 183 | * The root directory ID should always be looked up in the map [3.4] |
| 184 | */ |
Adrian Bunk | e0c9314 | 2005-08-20 17:20:28 +0100 | [diff] [blame] | 185 | static inline int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | __adfs_block_map(struct super_block *sb, unsigned int object_id, |
| 187 | unsigned int block) |
| 188 | { |
| 189 | if (object_id & 255) { |
| 190 | unsigned int off; |
| 191 | |
| 192 | off = (object_id & 255) - 1; |
| 193 | block += off << ADFS_SB(sb)->s_log2sharesize; |
| 194 | } |
| 195 | |
| 196 | return adfs_map_lookup(sb, object_id >> 8, block); |
| 197 | } |