common.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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) (avishay@il.ibm.com)
  6. * Copyright (C) 2005, 2006
  7. * International Business Machines
  8. * Copyright (C) 2008, 2009
  9. * Boaz Harrosh <bharrosh@panasas.com>
  10. *
  11. * Copyrights for code taken from ext2:
  12. * Copyright (C) 1992, 1993, 1994, 1995
  13. * Remy Card (card@masi.ibp.fr)
  14. * Laboratoire MASI - Institut Blaise Pascal
  15. * Universite Pierre et Marie Curie (Paris VI)
  16. * from
  17. * linux/fs/minix/inode.c
  18. * Copyright (C) 1991, 1992 Linus Torvalds
  19. *
  20. * This file is part of exofs.
  21. *
  22. * exofs is free software; you can redistribute it and/or modify
  23. * it under the terms of the GNU General Public License as published by
  24. * the Free Software Foundation. Since it is based on ext2, and the only
  25. * valid version of GPL for the Linux kernel is version 2, the only valid
  26. * version of GPL for exofs is version 2.
  27. *
  28. * exofs is distributed in the hope that it will be useful,
  29. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  30. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  31. * GNU General Public License for more details.
  32. *
  33. * You should have received a copy of the GNU General Public License
  34. * along with exofs; if not, write to the Free Software
  35. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  36. */
  37. #ifndef __EXOFS_COM_H__
  38. #define __EXOFS_COM_H__
  39. #include <linux/types.h>
  40. #include <scsi/osd_attributes.h>
  41. #include <scsi/osd_initiator.h>
  42. #include <scsi/osd_sec.h>
  43. /****************************************************************************
  44. * Object ID related defines
  45. * NOTE: inode# = object ID - EXOFS_OBJ_OFF
  46. ****************************************************************************/
  47. #define EXOFS_MIN_PID 0x10000 /* Smallest partition ID */
  48. #define EXOFS_OBJ_OFF 0x10000 /* offset for objects */
  49. #define EXOFS_SUPER_ID 0x10000 /* object ID for on-disk superblock */
  50. #define EXOFS_ROOT_ID 0x10002 /* object ID for root directory */
  51. /* exofs Application specific page/attribute */
  52. # define EXOFS_APAGE_FS_DATA (OSD_APAGE_APP_DEFINED_FIRST + 3)
  53. # define EXOFS_ATTR_INODE_DATA 1
  54. /*
  55. * The maximum number of files we can have is limited by the size of the
  56. * inode number. This is the largest object ID that the file system supports.
  57. * Object IDs 0, 1, and 2 are always in use (see above defines).
  58. */
  59. enum {
  60. EXOFS_MAX_INO_ID = (sizeof(ino_t) * 8 == 64) ? ULLONG_MAX :
  61. (1ULL << (sizeof(ino_t) * 8ULL - 1ULL)),
  62. EXOFS_MAX_ID = (EXOFS_MAX_INO_ID - 1 - EXOFS_OBJ_OFF),
  63. };
  64. /****************************************************************************
  65. * Misc.
  66. ****************************************************************************/
  67. #define EXOFS_BLKSHIFT 12
  68. #define EXOFS_BLKSIZE (1UL << EXOFS_BLKSHIFT)
  69. /****************************************************************************
  70. * superblock-related things
  71. ****************************************************************************/
  72. #define EXOFS_SUPER_MAGIC 0x5DF5
  73. /*
  74. * The file system control block - stored in an object's data (mainly, the one
  75. * with ID EXOFS_SUPER_ID). This is where the in-memory superblock is stored
  76. * on disk. Right now it just has a magic value, which is basically a sanity
  77. * check on our ability to communicate with the object store.
  78. */
  79. struct exofs_fscb {
  80. __le64 s_nextid; /* Highest object ID used */
  81. __le32 s_numfiles; /* Number of files on fs */
  82. __le16 s_magic; /* Magic signature */
  83. __le16 s_newfs; /* Non-zero if this is a new fs */
  84. };
  85. /****************************************************************************
  86. * inode-related things
  87. ****************************************************************************/
  88. #define EXOFS_IDATA 5
  89. /*
  90. * The file control block - stored in an object's attributes. This is where
  91. * the in-memory inode is stored on disk.
  92. */
  93. struct exofs_fcb {
  94. __le64 i_size; /* Size of the file */
  95. __le16 i_mode; /* File mode */
  96. __le16 i_links_count; /* Links count */
  97. __le32 i_uid; /* Owner Uid */
  98. __le32 i_gid; /* Group Id */
  99. __le32 i_atime; /* Access time */
  100. __le32 i_ctime; /* Creation time */
  101. __le32 i_mtime; /* Modification time */
  102. __le32 i_flags; /* File flags (unused for now)*/
  103. __le32 i_generation; /* File version (for NFS) */
  104. __le32 i_data[EXOFS_IDATA]; /* Short symlink names and device #s */
  105. };
  106. #define EXOFS_INO_ATTR_SIZE sizeof(struct exofs_fcb)
  107. /* This is the Attribute the fcb is stored in */
  108. static const struct __weak osd_attr g_attr_inode_data = ATTR_DEF(
  109. EXOFS_APAGE_FS_DATA,
  110. EXOFS_ATTR_INODE_DATA,
  111. EXOFS_INO_ATTR_SIZE);
  112. /****************************************************************************
  113. * dentry-related things
  114. ****************************************************************************/
  115. #define EXOFS_NAME_LEN 255
  116. /*
  117. * The on-disk directory entry
  118. */
  119. struct exofs_dir_entry {
  120. __le64 inode_no; /* inode number */
  121. __le16 rec_len; /* directory entry length */
  122. u8 name_len; /* name length */
  123. u8 file_type; /* umm...file type */
  124. char name[EXOFS_NAME_LEN]; /* file name */
  125. };
  126. enum {
  127. EXOFS_FT_UNKNOWN,
  128. EXOFS_FT_REG_FILE,
  129. EXOFS_FT_DIR,
  130. EXOFS_FT_CHRDEV,
  131. EXOFS_FT_BLKDEV,
  132. EXOFS_FT_FIFO,
  133. EXOFS_FT_SOCK,
  134. EXOFS_FT_SYMLINK,
  135. EXOFS_FT_MAX
  136. };
  137. #define EXOFS_DIR_PAD 4
  138. #define EXOFS_DIR_ROUND (EXOFS_DIR_PAD - 1)
  139. #define EXOFS_DIR_REC_LEN(name_len) \
  140. (((name_len) + offsetof(struct exofs_dir_entry, name) + \
  141. EXOFS_DIR_ROUND) & ~EXOFS_DIR_ROUND)
  142. /*************************
  143. * function declarations *
  144. *************************/
  145. /* osd.c */
  146. void exofs_make_credential(u8 cred_a[OSD_CAP_LEN],
  147. const struct osd_obj_id *obj);
  148. int exofs_check_ok_resid(struct osd_request *or, u64 *in_resid, u64 *out_resid);
  149. static inline int exofs_check_ok(struct osd_request *or)
  150. {
  151. return exofs_check_ok_resid(or, NULL, NULL);
  152. }
  153. int exofs_sync_op(struct osd_request *or, int timeout, u8 *cred);
  154. int exofs_async_op(struct osd_request *or,
  155. osd_req_done_fn *async_done, void *caller_context, u8 *cred);
  156. int extract_attr_from_req(struct osd_request *or, struct osd_attr *attr);
  157. int osd_req_read_kern(struct osd_request *or,
  158. const struct osd_obj_id *obj, u64 offset, void *buff, u64 len);
  159. int osd_req_write_kern(struct osd_request *or,
  160. const struct osd_obj_id *obj, u64 offset, void *buff, u64 len);
  161. #endif /*ifndef __EXOFS_COM_H__*/