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