adfs.h 5.6 KB

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