adfs.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. #include <linux/fs.h>
  2. #include <linux/adfs_fs.h>
  3. /* Internal data structures for ADFS */
  4. #define ADFS_FREE_FRAG 0
  5. #define ADFS_BAD_FRAG 1
  6. #define ADFS_ROOT_FRAG 2
  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. #include "dir_f.h"
  15. struct buffer_head;
  16. /*
  17. * adfs file system inode data in memory
  18. */
  19. struct adfs_inode_info {
  20. loff_t mmu_private;
  21. unsigned long parent_id; /* object id of parent */
  22. __u32 loadaddr; /* RISC OS load address */
  23. __u32 execaddr; /* RISC OS exec address */
  24. unsigned int filetype; /* RISC OS file type */
  25. unsigned int attr; /* RISC OS permissions */
  26. unsigned int stamped:1; /* RISC OS file has date/time */
  27. struct inode vfs_inode;
  28. };
  29. /*
  30. * Forward-declare this
  31. */
  32. struct adfs_discmap;
  33. struct adfs_dir_ops;
  34. /*
  35. * ADFS file system superblock data in memory
  36. */
  37. struct adfs_sb_info {
  38. union { struct {
  39. struct adfs_discmap *s_map; /* bh list containing map */
  40. const struct adfs_dir_ops *s_dir; /* directory operations */
  41. };
  42. struct rcu_head rcu; /* used only at shutdown time */
  43. };
  44. kuid_t s_uid; /* owner uid */
  45. kgid_t s_gid; /* owner gid */
  46. umode_t s_owner_mask; /* ADFS owner perm -> unix perm */
  47. umode_t s_other_mask; /* ADFS other perm -> unix perm */
  48. int s_ftsuffix; /* ,xyz hex filetype suffix option */
  49. __u32 s_ids_per_zone; /* max. no ids in one zone */
  50. __u32 s_idlen; /* length of ID in map */
  51. __u32 s_map_size; /* sector size of a map */
  52. unsigned long s_size; /* total size (in blocks) of this fs */
  53. signed int s_map2blk; /* shift left by this for map->sector*/
  54. unsigned int s_log2sharesize;/* log2 share size */
  55. __le32 s_version; /* disc format version */
  56. unsigned int s_namelen; /* maximum number of characters in name */
  57. };
  58. static inline struct adfs_sb_info *ADFS_SB(struct super_block *sb)
  59. {
  60. return sb->s_fs_info;
  61. }
  62. static inline struct adfs_inode_info *ADFS_I(struct inode *inode)
  63. {
  64. return container_of(inode, struct adfs_inode_info, vfs_inode);
  65. }
  66. /*
  67. * Directory handling
  68. */
  69. struct adfs_dir {
  70. struct super_block *sb;
  71. int nr_buffers;
  72. struct buffer_head *bh[4];
  73. /* big directories need allocated buffers */
  74. struct buffer_head **bh_fplus;
  75. unsigned int pos;
  76. unsigned int parent_id;
  77. struct adfs_dirheader dirhead;
  78. union adfs_dirtail dirtail;
  79. };
  80. /*
  81. * This is the overall maximum name length
  82. */
  83. #define ADFS_MAX_NAME_LEN (256 + 4) /* +4 for ,xyz hex filetype suffix */
  84. struct object_info {
  85. __u32 parent_id; /* parent object id */
  86. __u32 file_id; /* object id */
  87. __u32 loadaddr; /* load address */
  88. __u32 execaddr; /* execution address */
  89. __u32 size; /* size */
  90. __u8 attr; /* RISC OS attributes */
  91. unsigned int name_len; /* name length */
  92. char name[ADFS_MAX_NAME_LEN];/* file name */
  93. /* RISC OS file type (12-bit: derived from loadaddr) */
  94. __u16 filetype;
  95. };
  96. /* RISC OS 12-bit filetype converts to ,xyz hex filename suffix */
  97. static inline int append_filetype_suffix(char *buf, __u16 filetype)
  98. {
  99. if (filetype == 0xffff) /* no explicit 12-bit file type was set */
  100. return 0;
  101. *buf++ = ',';
  102. *buf++ = hex_asc_lo(filetype >> 8);
  103. *buf++ = hex_asc_lo(filetype >> 4);
  104. *buf++ = hex_asc_lo(filetype >> 0);
  105. return 4;
  106. }
  107. struct adfs_dir_ops {
  108. int (*read)(struct super_block *sb, unsigned int id, unsigned int sz, struct adfs_dir *dir);
  109. int (*setpos)(struct adfs_dir *dir, unsigned int fpos);
  110. int (*getnext)(struct adfs_dir *dir, struct object_info *obj);
  111. int (*update)(struct adfs_dir *dir, struct object_info *obj);
  112. int (*create)(struct adfs_dir *dir, struct object_info *obj);
  113. int (*remove)(struct adfs_dir *dir, struct object_info *obj);
  114. int (*sync)(struct adfs_dir *dir);
  115. void (*free)(struct adfs_dir *dir);
  116. };
  117. struct adfs_discmap {
  118. struct buffer_head *dm_bh;
  119. __u32 dm_startblk;
  120. unsigned int dm_startbit;
  121. unsigned int dm_endbit;
  122. };
  123. /* Inode stuff */
  124. struct inode *adfs_iget(struct super_block *sb, struct object_info *obj);
  125. int adfs_write_inode(struct inode *inode, struct writeback_control *wbc);
  126. int adfs_notify_change(struct dentry *dentry, struct iattr *attr);
  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. /* Misc */
  131. __printf(3, 4)
  132. void __adfs_error(struct super_block *sb, const char *function,
  133. const char *fmt, ...);
  134. #define adfs_error(sb, fmt...) __adfs_error(sb, __func__, fmt)
  135. /* super.c */
  136. /*
  137. * Inodes and file operations
  138. */
  139. /* dir_*.c */
  140. extern const struct inode_operations adfs_dir_inode_operations;
  141. extern const struct file_operations adfs_dir_operations;
  142. extern const struct dentry_operations adfs_dentry_operations;
  143. extern const struct adfs_dir_ops adfs_f_dir_ops;
  144. extern const struct adfs_dir_ops adfs_fplus_dir_ops;
  145. extern int adfs_dir_update(struct super_block *sb, struct object_info *obj,
  146. int wait);
  147. /* file.c */
  148. extern const struct inode_operations adfs_file_inode_operations;
  149. extern const struct file_operations adfs_file_operations;
  150. static inline __u32 signed_asl(__u32 val, signed int shift)
  151. {
  152. if (shift >= 0)
  153. val <<= shift;
  154. else
  155. val >>= -shift;
  156. return val;
  157. }
  158. /*
  159. * Calculate the address of a block in an object given the block offset
  160. * and the object identity.
  161. *
  162. * The root directory ID should always be looked up in the map [3.4]
  163. */
  164. static inline int
  165. __adfs_block_map(struct super_block *sb, unsigned int object_id,
  166. unsigned int block)
  167. {
  168. if (object_id & 255) {
  169. unsigned int off;
  170. off = (object_id & 255) - 1;
  171. block += off << ADFS_SB(sb)->s_log2sharesize;
  172. }
  173. return adfs_map_lookup(sb, object_id >> 8, block);
  174. }