common.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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 <bharrosh@panasas.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_ROOT_ID 0x10002 /* object ID for root directory */
  49. /* exofs Application specific page/attribute */
  50. # define EXOFS_APAGE_FS_DATA (OSD_APAGE_APP_DEFINED_FIRST + 3)
  51. # define EXOFS_ATTR_INODE_DATA 1
  52. /*
  53. * The maximum number of files we can have is limited by the size of the
  54. * inode number. This is the largest object ID that the file system supports.
  55. * Object IDs 0, 1, and 2 are always in use (see above defines).
  56. */
  57. enum {
  58. EXOFS_MAX_INO_ID = (sizeof(ino_t) * 8 == 64) ? ULLONG_MAX :
  59. (1ULL << (sizeof(ino_t) * 8ULL - 1ULL)),
  60. EXOFS_MAX_ID = (EXOFS_MAX_INO_ID - 1 - EXOFS_OBJ_OFF),
  61. };
  62. /****************************************************************************
  63. * Misc.
  64. ****************************************************************************/
  65. #define EXOFS_BLKSHIFT 12
  66. #define EXOFS_BLKSIZE (1UL << EXOFS_BLKSHIFT)
  67. /****************************************************************************
  68. * superblock-related things
  69. ****************************************************************************/
  70. #define EXOFS_SUPER_MAGIC 0x5DF5
  71. /*
  72. * The file system control block - stored in an object's data (mainly, the one
  73. * with ID EXOFS_SUPER_ID). This is where the in-memory superblock is stored
  74. * on disk. Right now it just has a magic value, which is basically a sanity
  75. * check on our ability to communicate with the object store.
  76. */
  77. struct exofs_fscb {
  78. __le64 s_nextid; /* Highest object ID used */
  79. __le32 s_numfiles; /* Number of files on fs */
  80. __le16 s_magic; /* Magic signature */
  81. __le16 s_newfs; /* Non-zero if this is a new fs */
  82. };
  83. /****************************************************************************
  84. * inode-related things
  85. ****************************************************************************/
  86. #define EXOFS_IDATA 5
  87. /*
  88. * The file control block - stored in an object's attributes. This is where
  89. * the in-memory inode is stored on disk.
  90. */
  91. struct exofs_fcb {
  92. __le64 i_size; /* Size of the file */
  93. __le16 i_mode; /* File mode */
  94. __le16 i_links_count; /* Links count */
  95. __le32 i_uid; /* Owner Uid */
  96. __le32 i_gid; /* Group Id */
  97. __le32 i_atime; /* Access time */
  98. __le32 i_ctime; /* Creation time */
  99. __le32 i_mtime; /* Modification time */
  100. __le32 i_flags; /* File flags (unused for now)*/
  101. __le32 i_generation; /* File version (for NFS) */
  102. __le32 i_data[EXOFS_IDATA]; /* Short symlink names and device #s */
  103. };
  104. #define EXOFS_INO_ATTR_SIZE sizeof(struct exofs_fcb)
  105. /* This is the Attribute the fcb is stored in */
  106. static const struct __weak osd_attr g_attr_inode_data = ATTR_DEF(
  107. EXOFS_APAGE_FS_DATA,
  108. EXOFS_ATTR_INODE_DATA,
  109. EXOFS_INO_ATTR_SIZE);
  110. /****************************************************************************
  111. * dentry-related things
  112. ****************************************************************************/
  113. #define EXOFS_NAME_LEN 255
  114. /*
  115. * The on-disk directory entry
  116. */
  117. struct exofs_dir_entry {
  118. __le64 inode_no; /* inode number */
  119. __le16 rec_len; /* directory entry length */
  120. u8 name_len; /* name length */
  121. u8 file_type; /* umm...file type */
  122. char name[EXOFS_NAME_LEN]; /* file name */
  123. };
  124. enum {
  125. EXOFS_FT_UNKNOWN,
  126. EXOFS_FT_REG_FILE,
  127. EXOFS_FT_DIR,
  128. EXOFS_FT_CHRDEV,
  129. EXOFS_FT_BLKDEV,
  130. EXOFS_FT_FIFO,
  131. EXOFS_FT_SOCK,
  132. EXOFS_FT_SYMLINK,
  133. EXOFS_FT_MAX
  134. };
  135. #define EXOFS_DIR_PAD 4
  136. #define EXOFS_DIR_ROUND (EXOFS_DIR_PAD - 1)
  137. #define EXOFS_DIR_REC_LEN(name_len) \
  138. (((name_len) + offsetof(struct exofs_dir_entry, name) + \
  139. EXOFS_DIR_ROUND) & ~EXOFS_DIR_ROUND)
  140. /*************************
  141. * function declarations *
  142. *************************/
  143. /* osd.c */
  144. void exofs_make_credential(u8 cred_a[OSD_CAP_LEN],
  145. const struct osd_obj_id *obj);
  146. int exofs_check_ok_resid(struct osd_request *or, u64 *in_resid, u64 *out_resid);
  147. static inline int exofs_check_ok(struct osd_request *or)
  148. {
  149. return exofs_check_ok_resid(or, NULL, NULL);
  150. }
  151. int exofs_sync_op(struct osd_request *or, int timeout, u8 *cred);
  152. int exofs_async_op(struct osd_request *or,
  153. osd_req_done_fn *async_done, void *caller_context, u8 *cred);
  154. int extract_attr_from_req(struct osd_request *or, struct osd_attr *attr);
  155. #endif /*ifndef __EXOFS_COM_H__*/