]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - fs/adfs/adfs.h
Merge tag 'libata-5.10-2020-10-30' of git://git.kernel.dk/linux-block
[mirror_ubuntu-hirsute-kernel.git] / fs / adfs / adfs.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
1dfdfc94 2#include <linux/buffer_head.h>
608ba50b
AV
3#include <linux/fs.h>
4#include <linux/adfs_fs.h>
5
1da177e4
LT
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
b4ed8f75
RK
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
1da177e4
LT
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
608ba50b
AV
29/*
30 * adfs file system inode data in memory
31 */
32struct adfs_inode_info {
33 loff_t mmu_private;
5ed70bb4 34 __u32 parent_id; /* parent indirect disc address */
25e5d4df 35 __u32 indaddr; /* object indirect disc address */
608ba50b
AV
36 __u32 loadaddr; /* RISC OS load address */
37 __u32 execaddr; /* RISC OS exec address */
608ba50b 38 unsigned int attr; /* RISC OS permissions */
608ba50b
AV
39 struct inode vfs_inode;
40};
41
b4ed8f75
RK
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
608ba50b
AV
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 {
2d1d9b5b 62 union { struct {
90d6cd51
AM
63 struct adfs_discmap *s_map; /* bh list containing map */
64 const struct adfs_dir_ops *s_dir; /* directory operations */
2d1d9b5b 65 };
90d6cd51 66 struct rcu_head rcu; /* used only at shutdown time */
2d1d9b5b 67 };
90d6cd51
AM
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 */
da23ef05 72 int s_ftsuffix; /* ,xyz hex filetype suffix option */
608ba50b 73
90d6cd51
AM
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 */
90d6cd51
AM
77 signed int s_map2blk; /* shift left by this for map->sector*/
78 unsigned int s_log2sharesize;/* log2 share size */
608ba50b
AV
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
1da177e4
LT
87/*
88 * Directory handling
89 */
90struct adfs_dir {
91 struct super_block *sb;
92
93 int nr_buffers;
94 struct buffer_head *bh[4];
71b26127 95 struct buffer_head **bhs;
2f09719a 96
1da177e4 97 unsigned int pos;
5ed70bb4 98 __u32 parent_id;
1da177e4 99
016936b3
RK
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 };
1da177e4
LT
108};
109
110/*
111 * This is the overall maximum name length
112 */
da23ef05 113#define ADFS_MAX_NAME_LEN (256 + 4) /* +4 for ,xyz hex filetype suffix */
1da177e4
LT
114struct object_info {
115 __u32 parent_id; /* parent object id */
5ed70bb4 116 __u32 indaddr; /* indirect disc addr */
1da177e4
LT
117 __u32 loadaddr; /* load address */
118 __u32 execaddr; /* execution address */
119 __u32 size; /* size */
120 __u8 attr; /* RISC OS attributes */
da23ef05 121 unsigned int name_len; /* name length */
1da177e4
LT
122 char name[ADFS_MAX_NAME_LEN];/* file name */
123};
124
125struct adfs_dir_ops {
5ed70bb4
RK
126 int (*read)(struct super_block *sb, unsigned int indaddr,
127 unsigned int size, struct adfs_dir *dir);
4287e4de 128 int (*iterate)(struct adfs_dir *dir, struct dir_context *ctx);
1da177e4
LT
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);
aacc954c 134 int (*commit)(struct adfs_dir *dir);
1da177e4
LT
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);
a9185b41 146int adfs_write_inode(struct inode *inode, struct writeback_control *wbc);
1da177e4
LT
147int adfs_notify_change(struct dentry *dentry, struct iattr *attr);
148
149/* map.c */
5ed70bb4 150int adfs_map_lookup(struct super_block *sb, u32 frag_id, unsigned int offset);
e6160e46 151void adfs_map_statfs(struct super_block *sb, struct kstatfs *buf);
f75d398d 152struct adfs_discmap *adfs_read_map(struct super_block *sb, struct adfs_discrecord *dr);
7b195267 153void adfs_free_map(struct super_block *sb);
1da177e4
LT
154
155/* Misc */
19bdd41a 156__printf(3, 4)
1da177e4
LT
157void __adfs_error(struct super_block *sb, const char *function,
158 const char *fmt, ...);
8e24eea7 159#define adfs_error(sb, fmt...) __adfs_error(sb, __func__, fmt)
ceb3b106 160void adfs_msg(struct super_block *sb, const char *pfx, const char *fmt, ...);
1da177e4
LT
161
162/* super.c */
163
164/*
165 * Inodes and file operations
166 */
167
168/* dir_*.c */
754661f1 169extern const struct inode_operations adfs_dir_inode_operations;
4b6f5d20 170extern const struct file_operations adfs_dir_operations;
e16404ed 171extern const struct dentry_operations adfs_dentry_operations;
0125f504
JL
172extern const struct adfs_dir_ops adfs_f_dir_ops;
173extern const struct adfs_dir_ops adfs_fplus_dir_ops;
1da177e4 174
a317120b
RK
175int adfs_dir_copyfrom(void *dst, struct adfs_dir *dir, unsigned int offset,
176 size_t len);
177int adfs_dir_copyto(struct adfs_dir *dir, unsigned int offset, const void *src,
178 size_t len);
1dd9f5ba 179void adfs_dir_relse(struct adfs_dir *dir);
419a6e5e
RK
180int adfs_dir_read_buffers(struct super_block *sb, u32 indaddr,
181 unsigned int size, struct adfs_dir *dir);
411c49bc 182void adfs_object_fixup(struct adfs_dir *dir, struct object_info *obj);
ffdc9064
AV
183extern int adfs_dir_update(struct super_block *sb, struct object_info *obj,
184 int wait);
1da177e4
LT
185
186/* file.c */
754661f1 187extern const struct inode_operations adfs_file_inode_operations;
4b6f5d20 188extern const struct file_operations adfs_file_operations;
1da177e4 189
e0c93142 190static inline __u32 signed_asl(__u32 val, signed int shift)
1da177e4
LT
191{
192 if (shift >= 0)
193 val <<= shift;
194 else
195 val >>= -shift;
196 return val;
197}
198
199/*
200 * Calculate the address of a block in an object given the block offset
201 * and the object identity.
202 *
203 * The root directory ID should always be looked up in the map [3.4]
204 */
5ed70bb4
RK
205static inline int __adfs_block_map(struct super_block *sb, u32 indaddr,
206 unsigned int block)
1da177e4 207{
5ed70bb4 208 if (indaddr & 255) {
1da177e4
LT
209 unsigned int off;
210
5ed70bb4 211 off = (indaddr & 255) - 1;
1da177e4
LT
212 block += off << ADFS_SB(sb)->s_log2sharesize;
213 }
214
5ed70bb4 215 return adfs_map_lookup(sb, indaddr >> 8, block);
1da177e4 216}
1dfdfc94
RK
217
218/* Return the disc record from the map */
219static inline
220struct adfs_discrecord *adfs_map_discrecord(struct adfs_discmap *dm)
221{
222 return (void *)(dm[0].dm_bh->b_data + 4);
223}
275f5b99
RK
224
225static 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);
229}