52cce1724b8e8c4a20559afa6cbe8e6d59bdbd3c
[linux-flexiantxendom0-3.2.10.git] / fs / adfs / adfs.h
1 /* 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
15 #include <linux/version.h>
16 #include "dir_f.h"
17
18 struct buffer_head;
19
20 /*
21  * Directory handling
22  */
23 struct adfs_dir {
24         struct super_block      *sb;
25
26         int                     nr_buffers;
27         struct buffer_head      *bh[4];
28         unsigned int            pos;
29         unsigned int            parent_id;
30
31         struct adfs_dirheader   dirhead;
32         union  adfs_dirtail     dirtail;
33 };
34
35 /*
36  * This is the overall maximum name length
37  */
38 #define ADFS_MAX_NAME_LEN       256
39 struct object_info {
40         __u32           parent_id;              /* parent object id     */
41         __u32           file_id;                /* object id            */
42         __u32           loadaddr;               /* load address         */
43         __u32           execaddr;               /* execution address    */
44         __u32           size;                   /* size                 */
45         __u8            attr;                   /* RISC OS attributes   */
46         unsigned char   name_len;               /* name length          */
47         char            name[ADFS_MAX_NAME_LEN];/* file name            */
48 };
49
50 struct adfs_dir_ops {
51         int     (*read)(struct super_block *sb, unsigned int id, unsigned int sz, struct adfs_dir *dir);
52         int     (*setpos)(struct adfs_dir *dir, unsigned int fpos);
53         int     (*getnext)(struct adfs_dir *dir, struct object_info *obj);
54         int     (*update)(struct adfs_dir *dir, struct object_info *obj);
55         int     (*create)(struct adfs_dir *dir, struct object_info *obj);
56         int     (*remove)(struct adfs_dir *dir, struct object_info *obj);
57         void    (*free)(struct adfs_dir *dir);
58 };
59
60 struct 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 /* dir stuff */
68
69
70 /* Inode stuff */
71 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)
72 int adfs_get_block(struct inode *inode, sector_t block,
73                    struct buffer_head *bh, int create);
74 #else
75 int adfs_bmap(struct inode *inode, int block);
76 #endif
77 struct inode *adfs_iget(struct super_block *sb, struct object_info *obj);
78 void adfs_read_inode(struct inode *inode);
79 void adfs_write_inode(struct inode *inode,int unused);
80 int adfs_notify_change(struct dentry *dentry, struct iattr *attr);
81
82 /* map.c */
83 extern int adfs_map_lookup(struct super_block *sb, unsigned int frag_id, unsigned int offset);
84 extern unsigned int adfs_map_free(struct super_block *sb);
85
86 /* Misc */
87 void __adfs_error(struct super_block *sb, const char *function,
88                   const char *fmt, ...);
89 #define adfs_error(sb, fmt...) __adfs_error(sb, __FUNCTION__, fmt)
90
91 /* namei.c */
92 extern struct dentry *adfs_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *);
93
94 /* super.c */
95
96 /*
97  * Inodes and file operations
98  */
99
100 /* dir_*.c */
101 extern struct inode_operations adfs_dir_inode_operations;
102 extern struct file_operations adfs_dir_operations;
103 extern struct dentry_operations adfs_dentry_operations;
104 extern struct adfs_dir_ops adfs_f_dir_ops;
105 extern struct adfs_dir_ops adfs_fplus_dir_ops;
106
107 extern int adfs_dir_update(struct super_block *sb, struct object_info *obj);
108
109 /* file.c */
110 extern struct inode_operations adfs_file_inode_operations;
111 extern struct file_operations adfs_file_operations;
112
113 extern inline __u32 signed_asl(__u32 val, signed int shift)
114 {
115         if (shift >= 0)
116                 val <<= shift;
117         else
118                 val >>= -shift;
119         return val;
120 }
121
122 /*
123  * Calculate the address of a block in an object given the block offset
124  * and the object identity.
125  *
126  * The root directory ID should always be looked up in the map [3.4]
127  */
128 extern inline int
129 __adfs_block_map(struct super_block *sb, unsigned int object_id,
130                  unsigned int block)
131 {
132         if (object_id & 255) {
133                 unsigned int off;
134
135                 off = (object_id & 255) - 1;
136                 block += off << ADFS_SB(sb)->s_log2sharesize;
137         }
138
139         return adfs_map_lookup(sb, object_id >> 8, block);
140 }