]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - fs/adfs/adfs.h
Merge branch 'for-linus' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/jikos...
[mirror_ubuntu-bionic-kernel.git] / fs / adfs / adfs.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
608ba50b
AV
2#include <linux/fs.h>
3#include <linux/adfs_fs.h>
4
1da177e4
LT
5/* Internal data structures for ADFS */
6
7#define ADFS_FREE_FRAG 0
8#define ADFS_BAD_FRAG 1
9#define ADFS_ROOT_FRAG 2
10
11#define ADFS_NDA_OWNER_READ (1 << 0)
12#define ADFS_NDA_OWNER_WRITE (1 << 1)
13#define ADFS_NDA_LOCKED (1 << 2)
14#define ADFS_NDA_DIRECTORY (1 << 3)
15#define ADFS_NDA_EXECUTE (1 << 4)
16#define ADFS_NDA_PUBLIC_READ (1 << 5)
17#define ADFS_NDA_PUBLIC_WRITE (1 << 6)
18
1da177e4
LT
19#include "dir_f.h"
20
21struct buffer_head;
22
608ba50b
AV
23/*
24 * adfs file system inode data in memory
25 */
26struct adfs_inode_info {
27 loff_t mmu_private;
28 unsigned long parent_id; /* object id of parent */
29 __u32 loadaddr; /* RISC OS load address */
30 __u32 execaddr; /* RISC OS exec address */
31 unsigned int filetype; /* RISC OS file type */
32 unsigned int attr; /* RISC OS permissions */
33 unsigned int stamped:1; /* RISC OS file has date/time */
34 struct inode vfs_inode;
35};
36
37/*
38 * Forward-declare this
39 */
40struct adfs_discmap;
41struct adfs_dir_ops;
42
43/*
44 * ADFS file system superblock data in memory
45 */
46struct adfs_sb_info {
2d1d9b5b 47 union { struct {
90d6cd51
AM
48 struct adfs_discmap *s_map; /* bh list containing map */
49 const struct adfs_dir_ops *s_dir; /* directory operations */
2d1d9b5b 50 };
90d6cd51 51 struct rcu_head rcu; /* used only at shutdown time */
2d1d9b5b 52 };
90d6cd51
AM
53 kuid_t s_uid; /* owner uid */
54 kgid_t s_gid; /* owner gid */
55 umode_t s_owner_mask; /* ADFS owner perm -> unix perm */
56 umode_t s_other_mask; /* ADFS other perm -> unix perm */
da23ef05 57 int s_ftsuffix; /* ,xyz hex filetype suffix option */
608ba50b 58
90d6cd51
AM
59 __u32 s_ids_per_zone; /* max. no ids in one zone */
60 __u32 s_idlen; /* length of ID in map */
61 __u32 s_map_size; /* sector size of a map */
62 unsigned long s_size; /* total size (in blocks) of this fs */
63 signed int s_map2blk; /* shift left by this for map->sector*/
64 unsigned int s_log2sharesize;/* log2 share size */
65 __le32 s_version; /* disc format version */
608ba50b
AV
66 unsigned int s_namelen; /* maximum number of characters in name */
67};
68
69static inline struct adfs_sb_info *ADFS_SB(struct super_block *sb)
70{
71 return sb->s_fs_info;
72}
73
74static inline struct adfs_inode_info *ADFS_I(struct inode *inode)
75{
76 return container_of(inode, struct adfs_inode_info, vfs_inode);
77}
78
1da177e4
LT
79/*
80 * Directory handling
81 */
82struct adfs_dir {
83 struct super_block *sb;
84
85 int nr_buffers;
86 struct buffer_head *bh[4];
2f09719a
SS
87
88 /* big directories need allocated buffers */
89 struct buffer_head **bh_fplus;
90
1da177e4
LT
91 unsigned int pos;
92 unsigned int parent_id;
93
94 struct adfs_dirheader dirhead;
95 union adfs_dirtail dirtail;
96};
97
98/*
99 * This is the overall maximum name length
100 */
da23ef05 101#define ADFS_MAX_NAME_LEN (256 + 4) /* +4 for ,xyz hex filetype suffix */
1da177e4
LT
102struct object_info {
103 __u32 parent_id; /* parent object id */
104 __u32 file_id; /* object id */
105 __u32 loadaddr; /* load address */
106 __u32 execaddr; /* execution address */
107 __u32 size; /* size */
108 __u8 attr; /* RISC OS attributes */
da23ef05 109 unsigned int name_len; /* name length */
1da177e4 110 char name[ADFS_MAX_NAME_LEN];/* file name */
da23ef05
SS
111
112 /* RISC OS file type (12-bit: derived from loadaddr) */
113 __u16 filetype;
1da177e4
LT
114};
115
da23ef05
SS
116/* RISC OS 12-bit filetype converts to ,xyz hex filename suffix */
117static inline int append_filetype_suffix(char *buf, __u16 filetype)
118{
135a9fcf 119 if (filetype == 0xffff) /* no explicit 12-bit file type was set */
da23ef05
SS
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
1da177e4
LT
129struct adfs_dir_ops {
130 int (*read)(struct super_block *sb, unsigned int id, unsigned int sz, struct adfs_dir *dir);
131 int (*setpos)(struct adfs_dir *dir, unsigned int fpos);
132 int (*getnext)(struct adfs_dir *dir, struct object_info *obj);
133 int (*update)(struct adfs_dir *dir, struct object_info *obj);
134 int (*create)(struct adfs_dir *dir, struct object_info *obj);
135 int (*remove)(struct adfs_dir *dir, struct object_info *obj);
ffdc9064 136 int (*sync)(struct adfs_dir *dir);
1da177e4
LT
137 void (*free)(struct adfs_dir *dir);
138};
139
140struct adfs_discmap {
141 struct buffer_head *dm_bh;
142 __u32 dm_startblk;
143 unsigned int dm_startbit;
144 unsigned int dm_endbit;
145};
146
147/* Inode stuff */
148struct inode *adfs_iget(struct super_block *sb, struct object_info *obj);
a9185b41 149int adfs_write_inode(struct inode *inode, struct writeback_control *wbc);
1da177e4
LT
150int adfs_notify_change(struct dentry *dentry, struct iattr *attr);
151
152/* map.c */
153extern int adfs_map_lookup(struct super_block *sb, unsigned int frag_id, unsigned int offset);
154extern unsigned int adfs_map_free(struct super_block *sb);
155
156/* Misc */
19bdd41a 157__printf(3, 4)
1da177e4
LT
158void __adfs_error(struct super_block *sb, const char *function,
159 const char *fmt, ...);
8e24eea7 160#define adfs_error(sb, fmt...) __adfs_error(sb, __func__, 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
ffdc9064
AV
175extern int adfs_dir_update(struct super_block *sb, struct object_info *obj,
176 int wait);
1da177e4
LT
177
178/* file.c */
754661f1 179extern const struct inode_operations adfs_file_inode_operations;
4b6f5d20 180extern const struct file_operations adfs_file_operations;
1da177e4 181
e0c93142 182static inline __u32 signed_asl(__u32 val, signed int shift)
1da177e4
LT
183{
184 if (shift >= 0)
185 val <<= shift;
186 else
187 val >>= -shift;
188 return val;
189}
190
191/*
192 * Calculate the address of a block in an object given the block offset
193 * and the object identity.
194 *
195 * The root directory ID should always be looked up in the map [3.4]
196 */
e0c93142 197static inline int
1da177e4
LT
198__adfs_block_map(struct super_block *sb, unsigned int object_id,
199 unsigned int block)
200{
201 if (object_id & 255) {
202 unsigned int off;
203
204 off = (object_id & 255) - 1;
205 block += off << ADFS_SB(sb)->s_log2sharesize;
206 }
207
208 return adfs_map_lookup(sb, object_id >> 8, block);
209}