fs/adfs: map: fix map scanning
[linux-block.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
1da177e4
LT
29#include "dir_f.h"
30
608ba50b
AV
31/*
32 * adfs file system inode data in memory
33 */
34struct adfs_inode_info {
35 loff_t mmu_private;
5ed70bb4 36 __u32 parent_id; /* parent indirect disc address */
608ba50b
AV
37 __u32 loadaddr; /* RISC OS load address */
38 __u32 execaddr; /* RISC OS exec address */
608ba50b 39 unsigned int attr; /* RISC OS permissions */
608ba50b
AV
40 struct inode vfs_inode;
41};
42
b4ed8f75
RK
43static inline struct adfs_inode_info *ADFS_I(struct inode *inode)
44{
45 return container_of(inode, struct adfs_inode_info, vfs_inode);
46}
47
48static inline bool adfs_inode_is_stamped(struct inode *inode)
49{
50 return (ADFS_I(inode)->loadaddr & 0xfff00000) == 0xfff00000;
51}
52
608ba50b
AV
53/*
54 * Forward-declare this
55 */
56struct adfs_discmap;
57struct adfs_dir_ops;
58
59/*
60 * ADFS file system superblock data in memory
61 */
62struct adfs_sb_info {
2d1d9b5b 63 union { struct {
90d6cd51
AM
64 struct adfs_discmap *s_map; /* bh list containing map */
65 const struct adfs_dir_ops *s_dir; /* directory operations */
2d1d9b5b 66 };
90d6cd51 67 struct rcu_head rcu; /* used only at shutdown time */
2d1d9b5b 68 };
90d6cd51
AM
69 kuid_t s_uid; /* owner uid */
70 kgid_t s_gid; /* owner gid */
71 umode_t s_owner_mask; /* ADFS owner perm -> unix perm */
72 umode_t s_other_mask; /* ADFS other perm -> unix perm */
da23ef05 73 int s_ftsuffix; /* ,xyz hex filetype suffix option */
608ba50b 74
90d6cd51
AM
75 __u32 s_ids_per_zone; /* max. no ids in one zone */
76 __u32 s_idlen; /* length of ID in map */
77 __u32 s_map_size; /* sector size of a map */
90d6cd51
AM
78 signed int s_map2blk; /* shift left by this for map->sector*/
79 unsigned int s_log2sharesize;/* log2 share size */
608ba50b
AV
80 unsigned int s_namelen; /* maximum number of characters in name */
81};
82
83static inline struct adfs_sb_info *ADFS_SB(struct super_block *sb)
84{
85 return sb->s_fs_info;
86}
87
1da177e4
LT
88/*
89 * Directory handling
90 */
91struct adfs_dir {
92 struct super_block *sb;
93
94 int nr_buffers;
95 struct buffer_head *bh[4];
2f09719a
SS
96
97 /* big directories need allocated buffers */
98 struct buffer_head **bh_fplus;
99
1da177e4 100 unsigned int pos;
5ed70bb4 101 __u32 parent_id;
1da177e4
LT
102
103 struct adfs_dirheader dirhead;
104 union adfs_dirtail dirtail;
105};
106
107/*
108 * This is the overall maximum name length
109 */
da23ef05 110#define ADFS_MAX_NAME_LEN (256 + 4) /* +4 for ,xyz hex filetype suffix */
1da177e4
LT
111struct object_info {
112 __u32 parent_id; /* parent object id */
5ed70bb4 113 __u32 indaddr; /* indirect disc addr */
1da177e4
LT
114 __u32 loadaddr; /* load address */
115 __u32 execaddr; /* execution address */
116 __u32 size; /* size */
117 __u8 attr; /* RISC OS attributes */
da23ef05 118 unsigned int name_len; /* name length */
1da177e4
LT
119 char name[ADFS_MAX_NAME_LEN];/* file name */
120};
121
122struct adfs_dir_ops {
5ed70bb4
RK
123 int (*read)(struct super_block *sb, unsigned int indaddr,
124 unsigned int size, struct adfs_dir *dir);
1da177e4
LT
125 int (*setpos)(struct adfs_dir *dir, unsigned int fpos);
126 int (*getnext)(struct adfs_dir *dir, struct object_info *obj);
127 int (*update)(struct adfs_dir *dir, struct object_info *obj);
128 int (*create)(struct adfs_dir *dir, struct object_info *obj);
129 int (*remove)(struct adfs_dir *dir, struct object_info *obj);
ffdc9064 130 int (*sync)(struct adfs_dir *dir);
1da177e4
LT
131 void (*free)(struct adfs_dir *dir);
132};
133
134struct adfs_discmap {
135 struct buffer_head *dm_bh;
136 __u32 dm_startblk;
137 unsigned int dm_startbit;
138 unsigned int dm_endbit;
139};
140
141/* Inode stuff */
142struct inode *adfs_iget(struct super_block *sb, struct object_info *obj);
a9185b41 143int adfs_write_inode(struct inode *inode, struct writeback_control *wbc);
1da177e4
LT
144int adfs_notify_change(struct dentry *dentry, struct iattr *attr);
145
146/* map.c */
5ed70bb4 147int adfs_map_lookup(struct super_block *sb, u32 frag_id, unsigned int offset);
e6160e46 148void adfs_map_statfs(struct super_block *sb, struct kstatfs *buf);
f75d398d 149struct adfs_discmap *adfs_read_map(struct super_block *sb, struct adfs_discrecord *dr);
7b195267 150void adfs_free_map(struct super_block *sb);
1da177e4
LT
151
152/* Misc */
19bdd41a 153__printf(3, 4)
1da177e4
LT
154void __adfs_error(struct super_block *sb, const char *function,
155 const char *fmt, ...);
8e24eea7 156#define adfs_error(sb, fmt...) __adfs_error(sb, __func__, fmt)
ceb3b106 157void adfs_msg(struct super_block *sb, const char *pfx, const char *fmt, ...);
1da177e4
LT
158
159/* super.c */
160
161/*
162 * Inodes and file operations
163 */
164
165/* dir_*.c */
754661f1 166extern const struct inode_operations adfs_dir_inode_operations;
4b6f5d20 167extern const struct file_operations adfs_dir_operations;
e16404ed 168extern const struct dentry_operations adfs_dentry_operations;
0125f504
JL
169extern const struct adfs_dir_ops adfs_f_dir_ops;
170extern const struct adfs_dir_ops adfs_fplus_dir_ops;
1da177e4 171
411c49bc 172void adfs_object_fixup(struct adfs_dir *dir, struct object_info *obj);
ffdc9064
AV
173extern int adfs_dir_update(struct super_block *sb, struct object_info *obj,
174 int wait);
1da177e4
LT
175
176/* file.c */
754661f1 177extern const struct inode_operations adfs_file_inode_operations;
4b6f5d20 178extern const struct file_operations adfs_file_operations;
1da177e4 179
e0c93142 180static inline __u32 signed_asl(__u32 val, signed int shift)
1da177e4
LT
181{
182 if (shift >= 0)
183 val <<= shift;
184 else
185 val >>= -shift;
186 return val;
187}
188
189/*
190 * Calculate the address of a block in an object given the block offset
191 * and the object identity.
192 *
193 * The root directory ID should always be looked up in the map [3.4]
194 */
5ed70bb4
RK
195static inline int __adfs_block_map(struct super_block *sb, u32 indaddr,
196 unsigned int block)
1da177e4 197{
5ed70bb4 198 if (indaddr & 255) {
1da177e4
LT
199 unsigned int off;
200
5ed70bb4 201 off = (indaddr & 255) - 1;
1da177e4
LT
202 block += off << ADFS_SB(sb)->s_log2sharesize;
203 }
204
5ed70bb4 205 return adfs_map_lookup(sb, indaddr >> 8, block);
1da177e4 206}
1dfdfc94
RK
207
208/* Return the disc record from the map */
209static inline
210struct adfs_discrecord *adfs_map_discrecord(struct adfs_discmap *dm)
211{
212 return (void *)(dm[0].dm_bh->b_data + 4);
213}
275f5b99
RK
214
215static inline u64 adfs_disc_size(const struct adfs_discrecord *dr)
216{
217 return (u64)le32_to_cpu(dr->disc_size_high) << 32 |
218 le32_to_cpu(dr->disc_size);
219}