Loading...
1#include <linux/fs.h>
2#include <linux/adfs_fs.h>
3
4/* Internal data structures for ADFS */
5
6#define ADFS_FREE_FRAG 0
7#define ADFS_BAD_FRAG 1
8#define ADFS_ROOT_FRAG 2
9
10#define ADFS_NDA_OWNER_READ (1 << 0)
11#define ADFS_NDA_OWNER_WRITE (1 << 1)
12#define ADFS_NDA_LOCKED (1 << 2)
13#define ADFS_NDA_DIRECTORY (1 << 3)
14#define ADFS_NDA_EXECUTE (1 << 4)
15#define ADFS_NDA_PUBLIC_READ (1 << 5)
16#define ADFS_NDA_PUBLIC_WRITE (1 << 6)
17
18#include "dir_f.h"
19
20struct buffer_head;
21
22/*
23 * adfs file system inode data in memory
24 */
25struct adfs_inode_info {
26 loff_t mmu_private;
27 unsigned long parent_id; /* object id of parent */
28 __u32 loadaddr; /* RISC OS load address */
29 __u32 execaddr; /* RISC OS exec address */
30 unsigned int filetype; /* RISC OS file type */
31 unsigned int attr; /* RISC OS permissions */
32 unsigned int stamped:1; /* RISC OS file has date/time */
33 struct inode vfs_inode;
34};
35
36/*
37 * Forward-declare this
38 */
39struct adfs_discmap;
40struct adfs_dir_ops;
41
42/*
43 * ADFS file system superblock data in memory
44 */
45struct adfs_sb_info {
46 struct adfs_discmap *s_map; /* bh list containing map */
47 struct adfs_dir_ops *s_dir; /* directory operations */
48
49 uid_t s_uid; /* owner uid */
50 gid_t s_gid; /* owner gid */
51 umode_t s_owner_mask; /* ADFS owner perm -> unix perm */
52 umode_t s_other_mask; /* ADFS other perm -> unix perm */
53 int s_ftsuffix; /* ,xyz hex filetype suffix option */
54
55 __u32 s_ids_per_zone; /* max. no ids in one zone */
56 __u32 s_idlen; /* length of ID in map */
57 __u32 s_map_size; /* sector size of a map */
58 unsigned long s_size; /* total size (in blocks) of this fs */
59 signed int s_map2blk; /* shift left by this for map->sector */
60 unsigned int s_log2sharesize;/* log2 share size */
61 __le32 s_version; /* disc format version */
62 unsigned int s_namelen; /* maximum number of characters in name */
63};
64
65static inline struct adfs_sb_info *ADFS_SB(struct super_block *sb)
66{
67 return sb->s_fs_info;
68}
69
70static inline struct adfs_inode_info *ADFS_I(struct inode *inode)
71{
72 return container_of(inode, struct adfs_inode_info, vfs_inode);
73}
74
75/*
76 * Directory handling
77 */
78struct adfs_dir {
79 struct super_block *sb;
80
81 int nr_buffers;
82 struct buffer_head *bh[4];
83
84 /* big directories need allocated buffers */
85 struct buffer_head **bh_fplus;
86
87 unsigned int pos;
88 unsigned int parent_id;
89
90 struct adfs_dirheader dirhead;
91 union adfs_dirtail dirtail;
92};
93
94/*
95 * This is the overall maximum name length
96 */
97#define ADFS_MAX_NAME_LEN (256 + 4) /* +4 for ,xyz hex filetype suffix */
98struct object_info {
99 __u32 parent_id; /* parent object id */
100 __u32 file_id; /* object id */
101 __u32 loadaddr; /* load address */
102 __u32 execaddr; /* execution address */
103 __u32 size; /* size */
104 __u8 attr; /* RISC OS attributes */
105 unsigned int name_len; /* name length */
106 char name[ADFS_MAX_NAME_LEN];/* file name */
107
108 /* RISC OS file type (12-bit: derived from loadaddr) */
109 __u16 filetype;
110};
111
112/* RISC OS 12-bit filetype converts to ,xyz hex filename suffix */
113static inline int append_filetype_suffix(char *buf, __u16 filetype)
114{
115 if (filetype == 0xffff) /* no explicit 12-bit file type was set */
116 return 0;
117
118 *buf++ = ',';
119 *buf++ = hex_asc_lo(filetype >> 8);
120 *buf++ = hex_asc_lo(filetype >> 4);
121 *buf++ = hex_asc_lo(filetype >> 0);
122 return 4;
123}
124
125struct adfs_dir_ops {
126 int (*read)(struct super_block *sb, unsigned int id, unsigned int sz, struct adfs_dir *dir);
127 int (*setpos)(struct adfs_dir *dir, unsigned int fpos);
128 int (*getnext)(struct adfs_dir *dir, struct object_info *obj);
129 int (*update)(struct adfs_dir *dir, struct object_info *obj);
130 int (*create)(struct adfs_dir *dir, struct object_info *obj);
131 int (*remove)(struct adfs_dir *dir, struct object_info *obj);
132 int (*sync)(struct adfs_dir *dir);
133 void (*free)(struct adfs_dir *dir);
134};
135
136struct adfs_discmap {
137 struct buffer_head *dm_bh;
138 __u32 dm_startblk;
139 unsigned int dm_startbit;
140 unsigned int dm_endbit;
141};
142
143/* Inode stuff */
144struct inode *adfs_iget(struct super_block *sb, struct object_info *obj);
145int adfs_write_inode(struct inode *inode, struct writeback_control *wbc);
146int adfs_notify_change(struct dentry *dentry, struct iattr *attr);
147
148/* map.c */
149extern int adfs_map_lookup(struct super_block *sb, unsigned int frag_id, unsigned int offset);
150extern unsigned int adfs_map_free(struct super_block *sb);
151
152/* Misc */
153void __adfs_error(struct super_block *sb, const char *function,
154 const char *fmt, ...);
155#define adfs_error(sb, fmt...) __adfs_error(sb, __func__, fmt)
156
157/* super.c */
158
159/*
160 * Inodes and file operations
161 */
162
163/* dir_*.c */
164extern const struct inode_operations adfs_dir_inode_operations;
165extern const struct file_operations adfs_dir_operations;
166extern const struct dentry_operations adfs_dentry_operations;
167extern struct adfs_dir_ops adfs_f_dir_ops;
168extern struct adfs_dir_ops adfs_fplus_dir_ops;
169
170extern int adfs_dir_update(struct super_block *sb, struct object_info *obj,
171 int wait);
172
173/* file.c */
174extern const struct inode_operations adfs_file_inode_operations;
175extern const struct file_operations adfs_file_operations;
176
177static inline __u32 signed_asl(__u32 val, signed int shift)
178{
179 if (shift >= 0)
180 val <<= shift;
181 else
182 val >>= -shift;
183 return val;
184}
185
186/*
187 * Calculate the address of a block in an object given the block offset
188 * and the object identity.
189 *
190 * The root directory ID should always be looked up in the map [3.4]
191 */
192static inline int
193__adfs_block_map(struct super_block *sb, unsigned int object_id,
194 unsigned int block)
195{
196 if (object_id & 255) {
197 unsigned int off;
198
199 off = (object_id & 255) - 1;
200 block += off << ADFS_SB(sb)->s_log2sharesize;
201 }
202
203 return adfs_map_lookup(sb, object_id >> 8, block);
204}
1/* SPDX-License-Identifier: GPL-2.0 */
2#include <linux/buffer_head.h>
3#include <linux/fs.h>
4#include <linux/adfs_fs.h>
5
6/* Internal data structures for ADFS */
7
8#define ADFS_FREE_FRAG 0
9#define ADFS_BAD_FRAG 1
10#define ADFS_ROOT_FRAG 2
11
12#define ADFS_FILETYPE_NONE ((u16)~0)
13
14/* RISC OS 12-bit filetype is stored in load_address[19:8] */
15static inline u16 adfs_filetype(u32 loadaddr)
16{
17 return (loadaddr & 0xfff00000) == 0xfff00000 ?
18 (loadaddr >> 8) & 0xfff : ADFS_FILETYPE_NONE;
19}
20
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)
28
29/*
30 * adfs file system inode data in memory
31 */
32struct adfs_inode_info {
33 loff_t mmu_private;
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;
40};
41
42static inline struct adfs_inode_info *ADFS_I(struct inode *inode)
43{
44 return container_of(inode, struct adfs_inode_info, vfs_inode);
45}
46
47static inline bool adfs_inode_is_stamped(struct inode *inode)
48{
49 return (ADFS_I(inode)->loadaddr & 0xfff00000) == 0xfff00000;
50}
51
52/*
53 * Forward-declare this
54 */
55struct adfs_discmap;
56struct adfs_dir_ops;
57
58/*
59 * ADFS file system superblock data in memory
60 */
61struct adfs_sb_info {
62 union { struct {
63 struct adfs_discmap *s_map; /* bh list containing map */
64 const struct adfs_dir_ops *s_dir; /* directory operations */
65 };
66 struct rcu_head rcu; /* used only at shutdown time */
67 };
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 */
73
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 */
80};
81
82static inline struct adfs_sb_info *ADFS_SB(struct super_block *sb)
83{
84 return sb->s_fs_info;
85}
86
87/*
88 * Directory handling
89 */
90struct adfs_dir {
91 struct super_block *sb;
92
93 int nr_buffers;
94 struct buffer_head *bh[4];
95 struct buffer_head **bhs;
96
97 unsigned int pos;
98 __u32 parent_id;
99
100 union {
101 struct adfs_dirheader *dirhead;
102 struct adfs_bigdirheader *bighead;
103 };
104 union {
105 struct adfs_newdirtail *newtail;
106 struct adfs_bigdirtail *bigtail;
107 };
108};
109
110/*
111 * This is the overall maximum name length
112 */
113#define ADFS_MAX_NAME_LEN (256 + 4) /* +4 for ,xyz hex filetype suffix */
114struct object_info {
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 */
123};
124
125struct 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);
135};
136
137struct adfs_discmap {
138 struct buffer_head *dm_bh;
139 __u32 dm_startblk;
140 unsigned int dm_startbit;
141 unsigned int dm_endbit;
142};
143
144/* Inode stuff */
145struct inode *adfs_iget(struct super_block *sb, struct object_info *obj);
146int adfs_write_inode(struct inode *inode, struct writeback_control *wbc);
147int adfs_notify_change(struct mnt_idmap *idmap, struct dentry *dentry,
148 struct iattr *attr);
149
150/* map.c */
151int adfs_map_lookup(struct super_block *sb, u32 frag_id, unsigned int offset);
152void adfs_map_statfs(struct super_block *sb, struct kstatfs *buf);
153struct adfs_discmap *adfs_read_map(struct super_block *sb, struct adfs_discrecord *dr);
154void adfs_free_map(struct super_block *sb);
155
156/* Misc */
157__printf(3, 4)
158void __adfs_error(struct super_block *sb, const char *function,
159 const char *fmt, ...);
160#define adfs_error(sb, fmt...) __adfs_error(sb, __func__, fmt)
161void adfs_msg(struct super_block *sb, const char *pfx, const char *fmt, ...);
162
163/* super.c */
164
165/*
166 * Inodes and file operations
167 */
168
169/* dir_*.c */
170extern const struct inode_operations adfs_dir_inode_operations;
171extern const struct file_operations adfs_dir_operations;
172extern const struct dentry_operations adfs_dentry_operations;
173extern const struct adfs_dir_ops adfs_f_dir_ops;
174extern const struct adfs_dir_ops adfs_fplus_dir_ops;
175
176int adfs_dir_copyfrom(void *dst, struct adfs_dir *dir, unsigned int offset,
177 size_t len);
178int adfs_dir_copyto(struct adfs_dir *dir, unsigned int offset, const void *src,
179 size_t len);
180void adfs_dir_relse(struct adfs_dir *dir);
181int adfs_dir_read_buffers(struct super_block *sb, u32 indaddr,
182 unsigned int size, struct adfs_dir *dir);
183void adfs_object_fixup(struct adfs_dir *dir, struct object_info *obj);
184extern int adfs_dir_update(struct super_block *sb, struct object_info *obj,
185 int wait);
186
187/* file.c */
188extern const struct inode_operations adfs_file_inode_operations;
189extern const struct file_operations adfs_file_operations;
190
191static inline __u32 signed_asl(__u32 val, signed int shift)
192{
193 if (shift >= 0)
194 val <<= shift;
195 else
196 val >>= -shift;
197 return val;
198}
199
200/*
201 * Calculate the address of a block in an object given the block offset
202 * and the object identity.
203 *
204 * The root directory ID should always be looked up in the map [3.4]
205 */
206static inline int __adfs_block_map(struct super_block *sb, u32 indaddr,
207 unsigned int block)
208{
209 if (indaddr & 255) {
210 unsigned int off;
211
212 off = (indaddr & 255) - 1;
213 block += off << ADFS_SB(sb)->s_log2sharesize;
214 }
215
216 return adfs_map_lookup(sb, indaddr >> 8, block);
217}
218
219/* Return the disc record from the map */
220static inline
221struct adfs_discrecord *adfs_map_discrecord(struct adfs_discmap *dm)
222{
223 return (void *)(dm[0].dm_bh->b_data + 4);
224}
225
226static inline u64 adfs_disc_size(const struct adfs_discrecord *dr)
227{
228 return (u64)le32_to_cpu(dr->disc_size_high) << 32 |
229 le32_to_cpu(dr->disc_size);
230}