1 /* SPDX-License-Identifier: GPL-2.0 */
2 #include <linux/buffer_head.h>
4 #include <linux/adfs_fs.h>
6 /* Internal data structures for ADFS */
8 #define ADFS_FREE_FRAG 0
9 #define ADFS_BAD_FRAG 1
10 #define ADFS_ROOT_FRAG 2
12 #define ADFS_FILETYPE_NONE ((u16)~0)
14 /* RISC OS 12-bit filetype is stored in load_address[19:8] */
15 static inline u16 adfs_filetype(u32 loadaddr)
17 return (loadaddr & 0xfff00000) == 0xfff00000 ?
18 (loadaddr >> 8) & 0xfff : ADFS_FILETYPE_NONE;
21 #define ADFS_NDA_OWNER_READ (1 << 0)
22 #define ADFS_NDA_OWNER_WRITE (1 << 1)
23 #define ADFS_NDA_LOCKED (1 << 2)
24 #define ADFS_NDA_DIRECTORY (1 << 3)
25 #define ADFS_NDA_EXECUTE (1 << 4)
26 #define ADFS_NDA_PUBLIC_READ (1 << 5)
27 #define ADFS_NDA_PUBLIC_WRITE (1 << 6)
30 * adfs file system inode data in memory
32 struct adfs_inode_info {
34 __u32 parent_id; /* parent indirect disc address */
35 __u32 indaddr; /* object indirect disc address */
36 __u32 loadaddr; /* RISC OS load address */
37 __u32 execaddr; /* RISC OS exec address */
38 unsigned int attr; /* RISC OS permissions */
39 struct inode vfs_inode;
42 static inline struct adfs_inode_info *ADFS_I(struct inode *inode)
44 return container_of(inode, struct adfs_inode_info, vfs_inode);
47 static inline bool adfs_inode_is_stamped(struct inode *inode)
49 return (ADFS_I(inode)->loadaddr & 0xfff00000) == 0xfff00000;
53 * Forward-declare this
59 * ADFS file system superblock data in memory
63 struct adfs_discmap *s_map; /* bh list containing map */
64 const struct adfs_dir_ops *s_dir; /* directory operations */
66 struct rcu_head rcu; /* used only at shutdown time */
68 kuid_t s_uid; /* owner uid */
69 kgid_t s_gid; /* owner gid */
70 umode_t s_owner_mask; /* ADFS owner perm -> unix perm */
71 umode_t s_other_mask; /* ADFS other perm -> unix perm */
72 int s_ftsuffix; /* ,xyz hex filetype suffix option */
74 __u32 s_ids_per_zone; /* max. no ids in one zone */
75 __u32 s_idlen; /* length of ID in map */
76 __u32 s_map_size; /* sector size of a map */
77 signed int s_map2blk; /* shift left by this for map->sector*/
78 unsigned int s_log2sharesize;/* log2 share size */
79 unsigned int s_namelen; /* maximum number of characters in name */
82 static inline struct adfs_sb_info *ADFS_SB(struct super_block *sb)
91 struct super_block *sb;
94 struct buffer_head *bh[4];
95 struct buffer_head **bhs;
101 struct adfs_dirheader *dirhead;
102 struct adfs_bigdirheader *bighead;
105 struct adfs_newdirtail *newtail;
106 struct adfs_bigdirtail *bigtail;
111 * This is the overall maximum name length
113 #define ADFS_MAX_NAME_LEN (256 + 4) /* +4 for ,xyz hex filetype suffix */
115 __u32 parent_id; /* parent object id */
116 __u32 indaddr; /* indirect disc addr */
117 __u32 loadaddr; /* load address */
118 __u32 execaddr; /* execution address */
119 __u32 size; /* size */
120 __u8 attr; /* RISC OS attributes */
121 unsigned int name_len; /* name length */
122 char name[ADFS_MAX_NAME_LEN];/* file name */
125 struct adfs_dir_ops {
126 int (*read)(struct super_block *sb, unsigned int indaddr,
127 unsigned int size, struct adfs_dir *dir);
128 int (*iterate)(struct adfs_dir *dir, struct dir_context *ctx);
129 int (*setpos)(struct adfs_dir *dir, unsigned int fpos);
130 int (*getnext)(struct adfs_dir *dir, struct object_info *obj);
131 int (*update)(struct adfs_dir *dir, struct object_info *obj);
132 int (*create)(struct adfs_dir *dir, struct object_info *obj);
133 int (*remove)(struct adfs_dir *dir, struct object_info *obj);
134 int (*commit)(struct adfs_dir *dir);
137 struct adfs_discmap {
138 struct buffer_head *dm_bh;
140 unsigned int dm_startbit;
141 unsigned int dm_endbit;
145 struct inode *adfs_iget(struct super_block *sb, struct object_info *obj);
146 int adfs_write_inode(struct inode *inode, struct writeback_control *wbc);
147 int adfs_notify_change(struct mnt_idmap *idmap, struct dentry *dentry,
151 int adfs_map_lookup(struct super_block *sb, u32 frag_id, unsigned int offset);
152 void adfs_map_statfs(struct super_block *sb, struct kstatfs *buf);
153 struct adfs_discmap *adfs_read_map(struct super_block *sb, struct adfs_discrecord *dr);
154 void adfs_free_map(struct super_block *sb);
158 void __adfs_error(struct super_block *sb, const char *function,
159 const char *fmt, ...);
160 #define adfs_error(sb, fmt...) __adfs_error(sb, __func__, fmt)
161 void adfs_msg(struct super_block *sb, const char *pfx, const char *fmt, ...);
166 * Inodes and file operations
170 extern const struct inode_operations adfs_dir_inode_operations;
171 extern const struct file_operations adfs_dir_operations;
172 extern const struct dentry_operations adfs_dentry_operations;
173 extern const struct adfs_dir_ops adfs_f_dir_ops;
174 extern const struct adfs_dir_ops adfs_fplus_dir_ops;
176 int adfs_dir_copyfrom(void *dst, struct adfs_dir *dir, unsigned int offset,
178 int adfs_dir_copyto(struct adfs_dir *dir, unsigned int offset, const void *src,
180 void adfs_dir_relse(struct adfs_dir *dir);
181 int adfs_dir_read_buffers(struct super_block *sb, u32 indaddr,
182 unsigned int size, struct adfs_dir *dir);
183 void adfs_object_fixup(struct adfs_dir *dir, struct object_info *obj);
184 extern int adfs_dir_update(struct super_block *sb, struct object_info *obj,
188 extern const struct inode_operations adfs_file_inode_operations;
189 extern const struct file_operations adfs_file_operations;
191 static inline __u32 signed_asl(__u32 val, signed int shift)
201 * Calculate the address of a block in an object given the block offset
202 * and the object identity.
204 * The root directory ID should always be looked up in the map [3.4]
206 static inline int __adfs_block_map(struct super_block *sb, u32 indaddr,
212 off = (indaddr & 255) - 1;
213 block += off << ADFS_SB(sb)->s_log2sharesize;
216 return adfs_map_lookup(sb, indaddr >> 8, block);
219 /* Return the disc record from the map */
221 struct adfs_discrecord *adfs_map_discrecord(struct adfs_discmap *dm)
223 return (void *)(dm[0].dm_bh->b_data + 4);
226 static inline u64 adfs_disc_size(const struct adfs_discrecord *dr)
228 return (u64)le32_to_cpu(dr->disc_size_high) << 32 |
229 le32_to_cpu(dr->disc_size);