adfs.h 5.7 KB

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