hc
2024-05-10 748e4f3d702def1a4bff191e0cf93b6a05340f01
kernel/fs/adfs/adfs.h
....@@ -1,4 +1,5 @@
11 /* SPDX-License-Identifier: GPL-2.0 */
2
+#include <linux/buffer_head.h>
23 #include <linux/fs.h>
34 #include <linux/adfs_fs.h>
45
....@@ -8,6 +9,15 @@
89 #define ADFS_BAD_FRAG 1
910 #define ADFS_ROOT_FRAG 2
1011
12
+#define ADFS_FILETYPE_NONE ((u16)~0)
13
+
14
+/* RISC OS 12-bit filetype is stored in load_address[19:8] */
15
+static inline u16 adfs_filetype(u32 loadaddr)
16
+{
17
+ return (loadaddr & 0xfff00000) == 0xfff00000 ?
18
+ (loadaddr >> 8) & 0xfff : ADFS_FILETYPE_NONE;
19
+}
20
+
1121 #define ADFS_NDA_OWNER_READ (1 << 0)
1222 #define ADFS_NDA_OWNER_WRITE (1 << 1)
1323 #define ADFS_NDA_LOCKED (1 << 2)
....@@ -16,23 +26,28 @@
1626 #define ADFS_NDA_PUBLIC_READ (1 << 5)
1727 #define ADFS_NDA_PUBLIC_WRITE (1 << 6)
1828
19
-#include "dir_f.h"
20
-
21
-struct buffer_head;
22
-
2329 /*
2430 * adfs file system inode data in memory
2531 */
2632 struct adfs_inode_info {
2733 loff_t mmu_private;
28
- unsigned long parent_id; /* object id of parent */
34
+ __u32 parent_id; /* parent indirect disc address */
35
+ __u32 indaddr; /* object indirect disc address */
2936 __u32 loadaddr; /* RISC OS load address */
3037 __u32 execaddr; /* RISC OS exec address */
31
- unsigned int filetype; /* RISC OS file type */
3238 unsigned int attr; /* RISC OS permissions */
33
- unsigned int stamped:1; /* RISC OS file has date/time */
3439 struct inode vfs_inode;
3540 };
41
+
42
+static inline struct adfs_inode_info *ADFS_I(struct inode *inode)
43
+{
44
+ return container_of(inode, struct adfs_inode_info, vfs_inode);
45
+}
46
+
47
+static inline bool adfs_inode_is_stamped(struct inode *inode)
48
+{
49
+ return (ADFS_I(inode)->loadaddr & 0xfff00000) == 0xfff00000;
50
+}
3651
3752 /*
3853 * Forward-declare this
....@@ -59,21 +74,14 @@
5974 __u32 s_ids_per_zone; /* max. no ids in one zone */
6075 __u32 s_idlen; /* length of ID in map */
6176 __u32 s_map_size; /* sector size of a map */
62
- unsigned long s_size; /* total size (in blocks) of this fs */
6377 signed int s_map2blk; /* shift left by this for map->sector*/
6478 unsigned int s_log2sharesize;/* log2 share size */
65
- __le32 s_version; /* disc format version */
6679 unsigned int s_namelen; /* maximum number of characters in name */
6780 };
6881
6982 static inline struct adfs_sb_info *ADFS_SB(struct super_block *sb)
7083 {
7184 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);
7785 }
7886
7987 /*
....@@ -84,15 +92,19 @@
8492
8593 int nr_buffers;
8694 struct buffer_head *bh[4];
87
-
88
- /* big directories need allocated buffers */
89
- struct buffer_head **bh_fplus;
95
+ struct buffer_head **bhs;
9096
9197 unsigned int pos;
92
- unsigned int parent_id;
98
+ __u32 parent_id;
9399
94
- struct adfs_dirheader dirhead;
95
- union adfs_dirtail dirtail;
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
+ };
96108 };
97109
98110 /*
....@@ -101,40 +113,25 @@
101113 #define ADFS_MAX_NAME_LEN (256 + 4) /* +4 for ,xyz hex filetype suffix */
102114 struct object_info {
103115 __u32 parent_id; /* parent object id */
104
- __u32 file_id; /* object id */
116
+ __u32 indaddr; /* indirect disc addr */
105117 __u32 loadaddr; /* load address */
106118 __u32 execaddr; /* execution address */
107119 __u32 size; /* size */
108120 __u8 attr; /* RISC OS attributes */
109121 unsigned int name_len; /* name length */
110122 char name[ADFS_MAX_NAME_LEN];/* file name */
111
-
112
- /* RISC OS file type (12-bit: derived from loadaddr) */
113
- __u16 filetype;
114123 };
115124
116
-/* RISC OS 12-bit filetype converts to ,xyz hex filename suffix */
117
-static inline int append_filetype_suffix(char *buf, __u16 filetype)
118
-{
119
- if (filetype == 0xffff) /* no explicit 12-bit file type was set */
120
- return 0;
121
-
122
- *buf++ = ',';
123
- *buf++ = hex_asc_lo(filetype >> 8);
124
- *buf++ = hex_asc_lo(filetype >> 4);
125
- *buf++ = hex_asc_lo(filetype >> 0);
126
- return 4;
127
-}
128
-
129125 struct adfs_dir_ops {
130
- int (*read)(struct super_block *sb, unsigned int id, unsigned int sz, struct adfs_dir *dir);
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);
131129 int (*setpos)(struct adfs_dir *dir, unsigned int fpos);
132130 int (*getnext)(struct adfs_dir *dir, struct object_info *obj);
133131 int (*update)(struct adfs_dir *dir, struct object_info *obj);
134132 int (*create)(struct adfs_dir *dir, struct object_info *obj);
135133 int (*remove)(struct adfs_dir *dir, struct object_info *obj);
136
- int (*sync)(struct adfs_dir *dir);
137
- void (*free)(struct adfs_dir *dir);
134
+ int (*commit)(struct adfs_dir *dir);
138135 };
139136
140137 struct adfs_discmap {
....@@ -150,14 +147,17 @@
150147 int adfs_notify_change(struct dentry *dentry, struct iattr *attr);
151148
152149 /* map.c */
153
-extern int adfs_map_lookup(struct super_block *sb, unsigned int frag_id, unsigned int offset);
154
-extern unsigned int adfs_map_free(struct super_block *sb);
150
+int adfs_map_lookup(struct super_block *sb, u32 frag_id, unsigned int offset);
151
+void adfs_map_statfs(struct super_block *sb, struct kstatfs *buf);
152
+struct adfs_discmap *adfs_read_map(struct super_block *sb, struct adfs_discrecord *dr);
153
+void adfs_free_map(struct super_block *sb);
155154
156155 /* Misc */
157156 __printf(3, 4)
158157 void __adfs_error(struct super_block *sb, const char *function,
159158 const char *fmt, ...);
160159 #define adfs_error(sb, fmt...) __adfs_error(sb, __func__, fmt)
160
+void adfs_msg(struct super_block *sb, const char *pfx, const char *fmt, ...);
161161
162162 /* super.c */
163163
....@@ -172,6 +172,14 @@
172172 extern const struct adfs_dir_ops adfs_f_dir_ops;
173173 extern const struct adfs_dir_ops adfs_fplus_dir_ops;
174174
175
+int adfs_dir_copyfrom(void *dst, struct adfs_dir *dir, unsigned int offset,
176
+ size_t len);
177
+int adfs_dir_copyto(struct adfs_dir *dir, unsigned int offset, const void *src,
178
+ size_t len);
179
+void adfs_dir_relse(struct adfs_dir *dir);
180
+int adfs_dir_read_buffers(struct super_block *sb, u32 indaddr,
181
+ unsigned int size, struct adfs_dir *dir);
182
+void adfs_object_fixup(struct adfs_dir *dir, struct object_info *obj);
175183 extern int adfs_dir_update(struct super_block *sb, struct object_info *obj,
176184 int wait);
177185
....@@ -194,16 +202,28 @@
194202 *
195203 * The root directory ID should always be looked up in the map [3.4]
196204 */
197
-static inline int
198
-__adfs_block_map(struct super_block *sb, unsigned int object_id,
199
- unsigned int block)
205
+static inline int __adfs_block_map(struct super_block *sb, u32 indaddr,
206
+ unsigned int block)
200207 {
201
- if (object_id & 255) {
208
+ if (indaddr & 255) {
202209 unsigned int off;
203210
204
- off = (object_id & 255) - 1;
211
+ off = (indaddr & 255) - 1;
205212 block += off << ADFS_SB(sb)->s_log2sharesize;
206213 }
207214
208
- return adfs_map_lookup(sb, object_id >> 8, block);
215
+ return adfs_map_lookup(sb, indaddr >> 8, block);
216
+}
217
+
218
+/* Return the disc record from the map */
219
+static inline
220
+struct adfs_discrecord *adfs_map_discrecord(struct adfs_discmap *dm)
221
+{
222
+ return (void *)(dm[0].dm_bh->b_data + 4);
223
+}
224
+
225
+static inline u64 adfs_disc_size(const struct adfs_discrecord *dr)
226
+{
227
+ return (u64)le32_to_cpu(dr->disc_size_high) << 32 |
228
+ le32_to_cpu(dr->disc_size);
209229 }