common.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. /*
  2. * common.h - Common definitions for both Kernel and user-mode utilities
  3. *
  4. * Copyright (C) 2005, 2006
  5. * Avishay Traeger (avishay@gmail.com)
  6. * Copyright (C) 2008, 2009
  7. * Boaz Harrosh <ooo@electrozaur.com>
  8. *
  9. * Copyrights for code taken from ext2:
  10. * Copyright (C) 1992, 1993, 1994, 1995
  11. * Remy Card (card@masi.ibp.fr)
  12. * Laboratoire MASI - Institut Blaise Pascal
  13. * Universite Pierre et Marie Curie (Paris VI)
  14. * from
  15. * linux/fs/minix/inode.c
  16. * Copyright (C) 1991, 1992 Linus Torvalds
  17. *
  18. * This file is part of exofs.
  19. *
  20. * exofs is free software; you can redistribute it and/or modify
  21. * it under the terms of the GNU General Public License as published by
  22. * the Free Software Foundation. Since it is based on ext2, and the only
  23. * valid version of GPL for the Linux kernel is version 2, the only valid
  24. * version of GPL for exofs is version 2.
  25. *
  26. * exofs is distributed in the hope that it will be useful,
  27. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  28. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  29. * GNU General Public License for more details.
  30. *
  31. * You should have received a copy of the GNU General Public License
  32. * along with exofs; if not, write to the Free Software
  33. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  34. */
  35. #ifndef __EXOFS_COM_H__
  36. #define __EXOFS_COM_H__
  37. #include <linux/types.h>
  38. #include <scsi/osd_attributes.h>
  39. #include <scsi/osd_initiator.h>
  40. #include <scsi/osd_sec.h>
  41. /****************************************************************************
  42. * Object ID related defines
  43. * NOTE: inode# = object ID - EXOFS_OBJ_OFF
  44. ****************************************************************************/
  45. #define EXOFS_MIN_PID 0x10000 /* Smallest partition ID */
  46. #define EXOFS_OBJ_OFF 0x10000 /* offset for objects */
  47. #define EXOFS_SUPER_ID 0x10000 /* object ID for on-disk superblock */
  48. #define EXOFS_DEVTABLE_ID 0x10001 /* object ID for on-disk device table */
  49. #define EXOFS_ROOT_ID 0x10002 /* object ID for root directory */
  50. /* exofs Application specific page/attribute */
  51. /* Inode attrs */
  52. # define EXOFS_APAGE_FS_DATA (OSD_APAGE_APP_DEFINED_FIRST + 3)
  53. # define EXOFS_ATTR_INODE_DATA 1
  54. # define EXOFS_ATTR_INODE_FILE_LAYOUT 2
  55. # define EXOFS_ATTR_INODE_DIR_LAYOUT 3
  56. /* Partition attrs */
  57. # define EXOFS_APAGE_SB_DATA (0xF0000000U + 3)
  58. # define EXOFS_ATTR_SB_STATS 1
  59. /*
  60. * The maximum number of files we can have is limited by the size of the
  61. * inode number. This is the largest object ID that the file system supports.
  62. * Object IDs 0, 1, and 2 are always in use (see above defines).
  63. */
  64. enum {
  65. EXOFS_MAX_INO_ID = (sizeof(ino_t) * 8 == 64) ? ULLONG_MAX :
  66. (1ULL << (sizeof(ino_t) * 8ULL - 1ULL)),
  67. EXOFS_MAX_ID = (EXOFS_MAX_INO_ID - 1 - EXOFS_OBJ_OFF),
  68. };
  69. /****************************************************************************
  70. * Misc.
  71. ****************************************************************************/
  72. #define EXOFS_BLKSHIFT 12
  73. #define EXOFS_BLKSIZE (1UL << EXOFS_BLKSHIFT)
  74. /****************************************************************************
  75. * superblock-related things
  76. ****************************************************************************/
  77. #define EXOFS_SUPER_MAGIC 0x5DF5
  78. /*
  79. * The file system control block - stored in object EXOFS_SUPER_ID's data.
  80. * This is where the in-memory superblock is stored on disk.
  81. */
  82. enum {EXOFS_FSCB_VER = 1, EXOFS_DT_VER = 1};
  83. struct exofs_fscb {
  84. __le64 s_nextid; /* Only used after mkfs */
  85. __le64 s_numfiles; /* Only used after mkfs */
  86. __le32 s_version; /* == EXOFS_FSCB_VER */
  87. __le16 s_magic; /* Magic signature */
  88. __le16 s_newfs; /* Non-zero if this is a new fs */
  89. /* From here on it's a static part, only written by mkexofs */
  90. __le64 s_dev_table_oid; /* Resurved, not used */
  91. __le64 s_dev_table_count; /* == 0 means no dev_table */
  92. } __packed;
  93. /*
  94. * This struct is set on the FS partition's attributes.
  95. * [EXOFS_APAGE_SB_DATA, EXOFS_ATTR_SB_STATS] and is written together
  96. * with the create command, to atomically persist the sb writeable information.
  97. */
  98. struct exofs_sb_stats {
  99. __le64 s_nextid; /* Highest object ID used */
  100. __le64 s_numfiles; /* Number of files on fs */
  101. } __packed;
  102. /*
  103. * Describes the raid used in the FS. It is part of the device table.
  104. * This here is taken from the pNFS-objects definition. In exofs we
  105. * use one raid policy through-out the filesystem. (NOTE: the funny
  106. * alignment at beginning. We take care of it at exofs_device_table.
  107. */
  108. struct exofs_dt_data_map {
  109. __le32 cb_num_comps;
  110. __le64 cb_stripe_unit;
  111. __le32 cb_group_width;
  112. __le32 cb_group_depth;
  113. __le32 cb_mirror_cnt;
  114. __le32 cb_raid_algorithm;
  115. } __packed;
  116. /*
  117. * This is an osd device information descriptor. It is a single entry in
  118. * the exofs device table. It describes an osd target lun which
  119. * contains data belonging to this FS. (Same partition_id on all devices)
  120. */
  121. struct exofs_dt_device_info {
  122. __le32 systemid_len;
  123. u8 systemid[OSD_SYSTEMID_LEN];
  124. __le64 long_name_offset; /* If !0 then offset-in-file */
  125. __le32 osdname_len; /* */
  126. u8 osdname[44]; /* Embbeded, Usually an asci uuid */
  127. } __packed;
  128. /*
  129. * The EXOFS device table - stored in object EXOFS_DEVTABLE_ID's data.
  130. * It contains the raid used for this multy-device FS and an array of
  131. * participating devices.
  132. */
  133. struct exofs_device_table {
  134. __le32 dt_version; /* == EXOFS_DT_VER */
  135. struct exofs_dt_data_map dt_data_map; /* Raid policy to use */
  136. /* Resurved space For future use. Total includeing this:
  137. * (8 * sizeof(le64))
  138. */
  139. __le64 __Resurved[4];
  140. __le64 dt_num_devices; /* Array size */
  141. struct exofs_dt_device_info dt_dev_table[]; /* Array of devices */
  142. } __packed;
  143. /****************************************************************************
  144. * inode-related things
  145. ****************************************************************************/
  146. #define EXOFS_IDATA 5
  147. /*
  148. * The file control block - stored in an object's attributes. This is where
  149. * the in-memory inode is stored on disk.
  150. */
  151. struct exofs_fcb {
  152. __le64 i_size; /* Size of the file */
  153. __le16 i_mode; /* File mode */
  154. __le16 i_links_count; /* Links count */
  155. __le32 i_uid; /* Owner Uid */
  156. __le32 i_gid; /* Group Id */
  157. __le32 i_atime; /* Access time */
  158. __le32 i_ctime; /* Creation time */
  159. __le32 i_mtime; /* Modification time */
  160. __le32 i_flags; /* File flags (unused for now)*/
  161. __le32 i_generation; /* File version (for NFS) */
  162. __le32 i_data[EXOFS_IDATA]; /* Short symlink names and device #s */
  163. };
  164. #define EXOFS_INO_ATTR_SIZE sizeof(struct exofs_fcb)
  165. /* This is the Attribute the fcb is stored in */
  166. static const struct __weak osd_attr g_attr_inode_data = ATTR_DEF(
  167. EXOFS_APAGE_FS_DATA,
  168. EXOFS_ATTR_INODE_DATA,
  169. EXOFS_INO_ATTR_SIZE);
  170. /****************************************************************************
  171. * dentry-related things
  172. ****************************************************************************/
  173. #define EXOFS_NAME_LEN 255
  174. /*
  175. * The on-disk directory entry
  176. */
  177. struct exofs_dir_entry {
  178. __le64 inode_no; /* inode number */
  179. __le16 rec_len; /* directory entry length */
  180. u8 name_len; /* name length */
  181. u8 file_type; /* umm...file type */
  182. char name[EXOFS_NAME_LEN]; /* file name */
  183. };
  184. enum {
  185. EXOFS_FT_UNKNOWN,
  186. EXOFS_FT_REG_FILE,
  187. EXOFS_FT_DIR,
  188. EXOFS_FT_CHRDEV,
  189. EXOFS_FT_BLKDEV,
  190. EXOFS_FT_FIFO,
  191. EXOFS_FT_SOCK,
  192. EXOFS_FT_SYMLINK,
  193. EXOFS_FT_MAX
  194. };
  195. #define EXOFS_DIR_PAD 4
  196. #define EXOFS_DIR_ROUND (EXOFS_DIR_PAD - 1)
  197. #define EXOFS_DIR_REC_LEN(name_len) \
  198. (((name_len) + offsetof(struct exofs_dir_entry, name) + \
  199. EXOFS_DIR_ROUND) & ~EXOFS_DIR_ROUND)
  200. /*
  201. * The on-disk (optional) layout structure.
  202. * sits in an EXOFS_ATTR_INODE_FILE_LAYOUT or EXOFS_ATTR_INODE_DIR_LAYOUT
  203. * attribute, attached to any inode, usually to a directory.
  204. */
  205. enum exofs_inode_layout_gen_functions {
  206. LAYOUT_MOVING_WINDOW = 0,
  207. LAYOUT_IMPLICT = 1,
  208. };
  209. struct exofs_on_disk_inode_layout {
  210. __le16 gen_func; /* One of enum exofs_inode_layout_gen_functions */
  211. __le16 pad;
  212. union {
  213. /* gen_func == LAYOUT_MOVING_WINDOW (default) */
  214. struct exofs_layout_sliding_window {
  215. __le32 num_devices; /* first n devices in global-table*/
  216. } sliding_window __packed;
  217. /* gen_func == LAYOUT_IMPLICT */
  218. struct exofs_layout_implict_list {
  219. struct exofs_dt_data_map data_map;
  220. /* Variable array of size data_map.cb_num_comps. These
  221. * are device indexes of the devices in the global table
  222. */
  223. __le32 dev_indexes[];
  224. } implict __packed;
  225. };
  226. } __packed;
  227. static inline size_t exofs_on_disk_inode_layout_size(unsigned max_devs)
  228. {
  229. return sizeof(struct exofs_on_disk_inode_layout) +
  230. max_devs * sizeof(__le32);
  231. }
  232. #endif /*ifndef __EXOFS_COM_H__*/