blob: a6665f37f45604305129e4fd865d74750a49a26a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* Internal data structures for ADFS */
2
3#define ADFS_FREE_FRAG 0
4#define ADFS_BAD_FRAG 1
5#define ADFS_ROOT_FRAG 2
6
7#define ADFS_NDA_OWNER_READ (1 << 0)
8#define ADFS_NDA_OWNER_WRITE (1 << 1)
9#define ADFS_NDA_LOCKED (1 << 2)
10#define ADFS_NDA_DIRECTORY (1 << 3)
11#define ADFS_NDA_EXECUTE (1 << 4)
12#define ADFS_NDA_PUBLIC_READ (1 << 5)
13#define ADFS_NDA_PUBLIC_WRITE (1 << 6)
14
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include "dir_f.h"
16
17struct buffer_head;
18
19/*
20 * Directory handling
21 */
22struct adfs_dir {
23 struct super_block *sb;
24
25 int nr_buffers;
26 struct buffer_head *bh[4];
27 unsigned int pos;
28 unsigned int parent_id;
29
30 struct adfs_dirheader dirhead;
31 union adfs_dirtail dirtail;
32};
33
34/*
35 * This is the overall maximum name length
36 */
37#define ADFS_MAX_NAME_LEN 256
38struct object_info {
39 __u32 parent_id; /* parent object id */
40 __u32 file_id; /* object id */
41 __u32 loadaddr; /* load address */
42 __u32 execaddr; /* execution address */
43 __u32 size; /* size */
44 __u8 attr; /* RISC OS attributes */
45 unsigned char name_len; /* name length */
46 char name[ADFS_MAX_NAME_LEN];/* file name */
47};
48
49struct adfs_dir_ops {
50 int (*read)(struct super_block *sb, unsigned int id, unsigned int sz, struct adfs_dir *dir);
51 int (*setpos)(struct adfs_dir *dir, unsigned int fpos);
52 int (*getnext)(struct adfs_dir *dir, struct object_info *obj);
53 int (*update)(struct adfs_dir *dir, struct object_info *obj);
54 int (*create)(struct adfs_dir *dir, struct object_info *obj);
55 int (*remove)(struct adfs_dir *dir, struct object_info *obj);
Al Viroffdc9062009-06-08 00:44:42 -040056 int (*sync)(struct adfs_dir *dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 void (*free)(struct adfs_dir *dir);
58};
59
60struct adfs_discmap {
61 struct buffer_head *dm_bh;
62 __u32 dm_startblk;
63 unsigned int dm_startbit;
64 unsigned int dm_endbit;
65};
66
67/* Inode stuff */
68struct inode *adfs_iget(struct super_block *sb, struct object_info *obj);
69int adfs_write_inode(struct inode *inode,int unused);
70int adfs_notify_change(struct dentry *dentry, struct iattr *attr);
71
72/* map.c */
73extern int adfs_map_lookup(struct super_block *sb, unsigned int frag_id, unsigned int offset);
74extern unsigned int adfs_map_free(struct super_block *sb);
75
76/* Misc */
77void __adfs_error(struct super_block *sb, const char *function,
78 const char *fmt, ...);
Harvey Harrison8e24eea2008-04-30 00:55:09 -070079#define adfs_error(sb, fmt...) __adfs_error(sb, __func__, fmt)
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
81/* super.c */
82
83/*
84 * Inodes and file operations
85 */
86
87/* dir_*.c */
Arjan van de Ven754661f2007-02-12 00:55:38 -080088extern const struct inode_operations adfs_dir_inode_operations;
Arjan van de Ven4b6f5d22006-03-28 01:56:42 -080089extern const struct file_operations adfs_dir_operations;
Al Viroe16404e2009-02-20 05:55:13 +000090extern const struct dentry_operations adfs_dentry_operations;
Linus Torvalds1da177e2005-04-16 15:20:36 -070091extern struct adfs_dir_ops adfs_f_dir_ops;
92extern struct adfs_dir_ops adfs_fplus_dir_ops;
93
Al Viroffdc9062009-06-08 00:44:42 -040094extern int adfs_dir_update(struct super_block *sb, struct object_info *obj,
95 int wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
97/* file.c */
Arjan van de Ven754661f2007-02-12 00:55:38 -080098extern const struct inode_operations adfs_file_inode_operations;
Arjan van de Ven4b6f5d22006-03-28 01:56:42 -080099extern const struct file_operations adfs_file_operations;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100
Adrian Bunke0c93142005-08-20 17:20:28 +0100101static inline __u32 signed_asl(__u32 val, signed int shift)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102{
103 if (shift >= 0)
104 val <<= shift;
105 else
106 val >>= -shift;
107 return val;
108}
109
110/*
111 * Calculate the address of a block in an object given the block offset
112 * and the object identity.
113 *
114 * The root directory ID should always be looked up in the map [3.4]
115 */
Adrian Bunke0c93142005-08-20 17:20:28 +0100116static inline int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117__adfs_block_map(struct super_block *sb, unsigned int object_id,
118 unsigned int block)
119{
120 if (object_id & 255) {
121 unsigned int off;
122
123 off = (object_id & 255) - 1;
124 block += off << ADFS_SB(sb)->s_log2sharesize;
125 }
126
127 return adfs_map_lookup(sb, object_id >> 8, block);
128}