Al Viro | 608ba50 | 2009-06-16 14:52:13 -0400 | [diff] [blame] | 1 | #include <linux/fs.h> |
| 2 | #include <linux/adfs_fs.h> |
| 3 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | /* Internal data structures for ADFS */ |
| 5 | |
| 6 | #define ADFS_FREE_FRAG 0 |
| 7 | #define ADFS_BAD_FRAG 1 |
| 8 | #define ADFS_ROOT_FRAG 2 |
| 9 | |
| 10 | #define ADFS_NDA_OWNER_READ (1 << 0) |
| 11 | #define ADFS_NDA_OWNER_WRITE (1 << 1) |
| 12 | #define ADFS_NDA_LOCKED (1 << 2) |
| 13 | #define ADFS_NDA_DIRECTORY (1 << 3) |
| 14 | #define ADFS_NDA_EXECUTE (1 << 4) |
| 15 | #define ADFS_NDA_PUBLIC_READ (1 << 5) |
| 16 | #define ADFS_NDA_PUBLIC_WRITE (1 << 6) |
| 17 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include "dir_f.h" |
| 19 | |
| 20 | struct buffer_head; |
| 21 | |
| 22 | /* |
Al Viro | 608ba50 | 2009-06-16 14:52:13 -0400 | [diff] [blame] | 23 | * adfs file system inode data in memory |
| 24 | */ |
| 25 | struct adfs_inode_info { |
| 26 | loff_t mmu_private; |
| 27 | unsigned long parent_id; /* object id of parent */ |
| 28 | __u32 loadaddr; /* RISC OS load address */ |
| 29 | __u32 execaddr; /* RISC OS exec address */ |
| 30 | unsigned int filetype; /* RISC OS file type */ |
| 31 | unsigned int attr; /* RISC OS permissions */ |
| 32 | unsigned int stamped:1; /* RISC OS file has date/time */ |
| 33 | struct inode vfs_inode; |
| 34 | }; |
| 35 | |
| 36 | /* |
| 37 | * Forward-declare this |
| 38 | */ |
| 39 | struct adfs_discmap; |
| 40 | struct adfs_dir_ops; |
| 41 | |
| 42 | /* |
| 43 | * ADFS file system superblock data in memory |
| 44 | */ |
| 45 | struct adfs_sb_info { |
| 46 | struct adfs_discmap *s_map; /* bh list containing map */ |
| 47 | struct adfs_dir_ops *s_dir; /* directory operations */ |
| 48 | |
| 49 | uid_t s_uid; /* owner uid */ |
| 50 | gid_t s_gid; /* owner gid */ |
| 51 | umode_t s_owner_mask; /* ADFS owner perm -> unix perm */ |
| 52 | umode_t s_other_mask; /* ADFS other perm -> unix perm */ |
| 53 | |
| 54 | __u32 s_ids_per_zone; /* max. no ids in one zone */ |
| 55 | __u32 s_idlen; /* length of ID in map */ |
| 56 | __u32 s_map_size; /* sector size of a map */ |
| 57 | unsigned long s_size; /* total size (in blocks) of this fs */ |
| 58 | signed int s_map2blk; /* shift left by this for map->sector */ |
| 59 | unsigned int s_log2sharesize;/* log2 share size */ |
| 60 | __le32 s_version; /* disc format version */ |
| 61 | unsigned int s_namelen; /* maximum number of characters in name */ |
| 62 | }; |
| 63 | |
| 64 | static inline struct adfs_sb_info *ADFS_SB(struct super_block *sb) |
| 65 | { |
| 66 | return sb->s_fs_info; |
| 67 | } |
| 68 | |
| 69 | static inline struct adfs_inode_info *ADFS_I(struct inode *inode) |
| 70 | { |
| 71 | return container_of(inode, struct adfs_inode_info, vfs_inode); |
| 72 | } |
| 73 | |
| 74 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | * Directory handling |
| 76 | */ |
| 77 | struct adfs_dir { |
| 78 | struct super_block *sb; |
| 79 | |
| 80 | int nr_buffers; |
| 81 | struct buffer_head *bh[4]; |
| 82 | unsigned int pos; |
| 83 | unsigned int parent_id; |
| 84 | |
| 85 | struct adfs_dirheader dirhead; |
| 86 | union adfs_dirtail dirtail; |
| 87 | }; |
| 88 | |
| 89 | /* |
| 90 | * This is the overall maximum name length |
| 91 | */ |
| 92 | #define ADFS_MAX_NAME_LEN 256 |
| 93 | struct object_info { |
| 94 | __u32 parent_id; /* parent object id */ |
| 95 | __u32 file_id; /* object id */ |
| 96 | __u32 loadaddr; /* load address */ |
| 97 | __u32 execaddr; /* execution address */ |
| 98 | __u32 size; /* size */ |
| 99 | __u8 attr; /* RISC OS attributes */ |
| 100 | unsigned char name_len; /* name length */ |
| 101 | char name[ADFS_MAX_NAME_LEN];/* file name */ |
| 102 | }; |
| 103 | |
| 104 | struct adfs_dir_ops { |
| 105 | int (*read)(struct super_block *sb, unsigned int id, unsigned int sz, struct adfs_dir *dir); |
| 106 | int (*setpos)(struct adfs_dir *dir, unsigned int fpos); |
| 107 | int (*getnext)(struct adfs_dir *dir, struct object_info *obj); |
| 108 | int (*update)(struct adfs_dir *dir, struct object_info *obj); |
| 109 | int (*create)(struct adfs_dir *dir, struct object_info *obj); |
| 110 | int (*remove)(struct adfs_dir *dir, struct object_info *obj); |
Al Viro | ffdc906 | 2009-06-08 00:44:42 -0400 | [diff] [blame] | 111 | int (*sync)(struct adfs_dir *dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | void (*free)(struct adfs_dir *dir); |
| 113 | }; |
| 114 | |
| 115 | struct adfs_discmap { |
| 116 | struct buffer_head *dm_bh; |
| 117 | __u32 dm_startblk; |
| 118 | unsigned int dm_startbit; |
| 119 | unsigned int dm_endbit; |
| 120 | }; |
| 121 | |
| 122 | /* Inode stuff */ |
| 123 | struct inode *adfs_iget(struct super_block *sb, struct object_info *obj); |
| 124 | int adfs_write_inode(struct inode *inode,int unused); |
| 125 | int adfs_notify_change(struct dentry *dentry, struct iattr *attr); |
| 126 | |
| 127 | /* map.c */ |
| 128 | extern int adfs_map_lookup(struct super_block *sb, unsigned int frag_id, unsigned int offset); |
| 129 | extern unsigned int adfs_map_free(struct super_block *sb); |
| 130 | |
| 131 | /* Misc */ |
| 132 | void __adfs_error(struct super_block *sb, const char *function, |
| 133 | const char *fmt, ...); |
Harvey Harrison | 8e24eea | 2008-04-30 00:55:09 -0700 | [diff] [blame] | 134 | #define adfs_error(sb, fmt...) __adfs_error(sb, __func__, fmt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | |
| 136 | /* super.c */ |
| 137 | |
| 138 | /* |
| 139 | * Inodes and file operations |
| 140 | */ |
| 141 | |
| 142 | /* dir_*.c */ |
Arjan van de Ven | 754661f | 2007-02-12 00:55:38 -0800 | [diff] [blame] | 143 | extern const struct inode_operations adfs_dir_inode_operations; |
Arjan van de Ven | 4b6f5d2 | 2006-03-28 01:56:42 -0800 | [diff] [blame] | 144 | extern const struct file_operations adfs_dir_operations; |
Al Viro | e16404e | 2009-02-20 05:55:13 +0000 | [diff] [blame] | 145 | extern const struct dentry_operations adfs_dentry_operations; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | extern struct adfs_dir_ops adfs_f_dir_ops; |
| 147 | extern struct adfs_dir_ops adfs_fplus_dir_ops; |
| 148 | |
Al Viro | ffdc906 | 2009-06-08 00:44:42 -0400 | [diff] [blame] | 149 | extern int adfs_dir_update(struct super_block *sb, struct object_info *obj, |
| 150 | int wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | |
| 152 | /* file.c */ |
Arjan van de Ven | 754661f | 2007-02-12 00:55:38 -0800 | [diff] [blame] | 153 | extern const struct inode_operations adfs_file_inode_operations; |
Arjan van de Ven | 4b6f5d2 | 2006-03-28 01:56:42 -0800 | [diff] [blame] | 154 | extern const struct file_operations adfs_file_operations; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | |
Adrian Bunk | e0c9314 | 2005-08-20 17:20:28 +0100 | [diff] [blame] | 156 | static inline __u32 signed_asl(__u32 val, signed int shift) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | { |
| 158 | if (shift >= 0) |
| 159 | val <<= shift; |
| 160 | else |
| 161 | val >>= -shift; |
| 162 | return val; |
| 163 | } |
| 164 | |
| 165 | /* |
| 166 | * Calculate the address of a block in an object given the block offset |
| 167 | * and the object identity. |
| 168 | * |
| 169 | * The root directory ID should always be looked up in the map [3.4] |
| 170 | */ |
Adrian Bunk | e0c9314 | 2005-08-20 17:20:28 +0100 | [diff] [blame] | 171 | static inline int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | __adfs_block_map(struct super_block *sb, unsigned int object_id, |
| 173 | unsigned int block) |
| 174 | { |
| 175 | if (object_id & 255) { |
| 176 | unsigned int off; |
| 177 | |
| 178 | off = (object_id & 255) - 1; |
| 179 | block += off << ADFS_SB(sb)->s_log2sharesize; |
| 180 | } |
| 181 | |
| 182 | return adfs_map_lookup(sb, object_id >> 8, block); |
| 183 | } |