/*1* common.h - Common definitions for both Kernel and user-mode utilities2*3* Copyright (C) 2005, 20064* Avishay Traeger ([email protected])5* Copyright (C) 2008, 20096* Boaz Harrosh <[email protected]>7*8* Copyrights for code taken from ext2:9* Copyright (C) 1992, 1993, 1994, 199510* Remy Card ([email protected])11* Laboratoire MASI - Institut Blaise Pascal12* Universite Pierre et Marie Curie (Paris VI)13* from14* linux/fs/minix/inode.c15* Copyright (C) 1991, 1992 Linus Torvalds16*17* This file is part of exofs.18*19* exofs is free software; you can redistribute it and/or modify20* it under the terms of the GNU General Public License as published by21* the Free Software Foundation. Since it is based on ext2, and the only22* valid version of GPL for the Linux kernel is version 2, the only valid23* version of GPL for exofs is version 2.24*25* exofs is distributed in the hope that it will be useful,26* but WITHOUT ANY WARRANTY; without even the implied warranty of27* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the28* GNU General Public License for more details.29*30* You should have received a copy of the GNU General Public License31* along with exofs; if not, write to the Free Software32* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA33*/3435#ifndef __EXOFS_COM_H__36#define __EXOFS_COM_H__3738#include <linux/types.h>3940#include <scsi/osd_attributes.h>41#include <scsi/osd_initiator.h>42#include <scsi/osd_sec.h>4344/****************************************************************************45* Object ID related defines46* NOTE: inode# = object ID - EXOFS_OBJ_OFF47****************************************************************************/48#define EXOFS_MIN_PID 0x10000 /* Smallest partition ID */49#define EXOFS_OBJ_OFF 0x10000 /* offset for objects */50#define EXOFS_SUPER_ID 0x10000 /* object ID for on-disk superblock */51#define EXOFS_DEVTABLE_ID 0x10001 /* object ID for on-disk device table */52#define EXOFS_ROOT_ID 0x10002 /* object ID for root directory */5354/* exofs Application specific page/attribute */55/* Inode attrs */56# define EXOFS_APAGE_FS_DATA (OSD_APAGE_APP_DEFINED_FIRST + 3)57# define EXOFS_ATTR_INODE_DATA 158# define EXOFS_ATTR_INODE_FILE_LAYOUT 259# define EXOFS_ATTR_INODE_DIR_LAYOUT 360/* Partition attrs */61# define EXOFS_APAGE_SB_DATA (0xF0000000U + 3)62# define EXOFS_ATTR_SB_STATS 16364/*65* The maximum number of files we can have is limited by the size of the66* inode number. This is the largest object ID that the file system supports.67* Object IDs 0, 1, and 2 are always in use (see above defines).68*/69enum {70EXOFS_MAX_INO_ID = (sizeof(ino_t) * 8 == 64) ? ULLONG_MAX :71(1ULL << (sizeof(ino_t) * 8ULL - 1ULL)),72EXOFS_MAX_ID = (EXOFS_MAX_INO_ID - 1 - EXOFS_OBJ_OFF),73};7475/****************************************************************************76* Misc.77****************************************************************************/78#define EXOFS_BLKSHIFT 1279#define EXOFS_BLKSIZE (1UL << EXOFS_BLKSHIFT)8081/****************************************************************************82* superblock-related things83****************************************************************************/84#define EXOFS_SUPER_MAGIC 0x5DF58586/*87* The file system control block - stored in object EXOFS_SUPER_ID's data.88* This is where the in-memory superblock is stored on disk.89*/90enum {EXOFS_FSCB_VER = 1, EXOFS_DT_VER = 1};91struct exofs_fscb {92__le64 s_nextid; /* Only used after mkfs */93__le64 s_numfiles; /* Only used after mkfs */94__le32 s_version; /* == EXOFS_FSCB_VER */95__le16 s_magic; /* Magic signature */96__le16 s_newfs; /* Non-zero if this is a new fs */9798/* From here on it's a static part, only written by mkexofs */99__le64 s_dev_table_oid; /* Resurved, not used */100__le64 s_dev_table_count; /* == 0 means no dev_table */101} __packed;102103/*104* This struct is set on the FS partition's attributes.105* [EXOFS_APAGE_SB_DATA, EXOFS_ATTR_SB_STATS] and is written together106* with the create command, to atomically persist the sb writeable information.107*/108struct exofs_sb_stats {109__le64 s_nextid; /* Highest object ID used */110__le64 s_numfiles; /* Number of files on fs */111} __packed;112113/*114* Describes the raid used in the FS. It is part of the device table.115* This here is taken from the pNFS-objects definition. In exofs we116* use one raid policy through-out the filesystem. (NOTE: the funny117* alignment at beginning. We take care of it at exofs_device_table.118*/119struct exofs_dt_data_map {120__le32 cb_num_comps;121__le64 cb_stripe_unit;122__le32 cb_group_width;123__le32 cb_group_depth;124__le32 cb_mirror_cnt;125__le32 cb_raid_algorithm;126} __packed;127128/*129* This is an osd device information descriptor. It is a single entry in130* the exofs device table. It describes an osd target lun which131* contains data belonging to this FS. (Same partition_id on all devices)132*/133struct exofs_dt_device_info {134__le32 systemid_len;135u8 systemid[OSD_SYSTEMID_LEN];136__le64 long_name_offset; /* If !0 then offset-in-file */137__le32 osdname_len; /* */138u8 osdname[44]; /* Embbeded, Usually an asci uuid */139} __packed;140141/*142* The EXOFS device table - stored in object EXOFS_DEVTABLE_ID's data.143* It contains the raid used for this multy-device FS and an array of144* participating devices.145*/146struct exofs_device_table {147__le32 dt_version; /* == EXOFS_DT_VER */148struct exofs_dt_data_map dt_data_map; /* Raid policy to use */149150/* Resurved space For future use. Total includeing this:151* (8 * sizeof(le64))152*/153__le64 __Resurved[4];154155__le64 dt_num_devices; /* Array size */156struct exofs_dt_device_info dt_dev_table[]; /* Array of devices */157} __packed;158159/****************************************************************************160* inode-related things161****************************************************************************/162#define EXOFS_IDATA 5163164/*165* The file control block - stored in an object's attributes. This is where166* the in-memory inode is stored on disk.167*/168struct exofs_fcb {169__le64 i_size; /* Size of the file */170__le16 i_mode; /* File mode */171__le16 i_links_count; /* Links count */172__le32 i_uid; /* Owner Uid */173__le32 i_gid; /* Group Id */174__le32 i_atime; /* Access time */175__le32 i_ctime; /* Creation time */176__le32 i_mtime; /* Modification time */177__le32 i_flags; /* File flags (unused for now)*/178__le32 i_generation; /* File version (for NFS) */179__le32 i_data[EXOFS_IDATA]; /* Short symlink names and device #s */180};181182#define EXOFS_INO_ATTR_SIZE sizeof(struct exofs_fcb)183184/* This is the Attribute the fcb is stored in */185static const struct __weak osd_attr g_attr_inode_data = ATTR_DEF(186EXOFS_APAGE_FS_DATA,187EXOFS_ATTR_INODE_DATA,188EXOFS_INO_ATTR_SIZE);189190/****************************************************************************191* dentry-related things192****************************************************************************/193#define EXOFS_NAME_LEN 255194195/*196* The on-disk directory entry197*/198struct exofs_dir_entry {199__le64 inode_no; /* inode number */200__le16 rec_len; /* directory entry length */201u8 name_len; /* name length */202u8 file_type; /* umm...file type */203char name[EXOFS_NAME_LEN]; /* file name */204};205206enum {207EXOFS_FT_UNKNOWN,208EXOFS_FT_REG_FILE,209EXOFS_FT_DIR,210EXOFS_FT_CHRDEV,211EXOFS_FT_BLKDEV,212EXOFS_FT_FIFO,213EXOFS_FT_SOCK,214EXOFS_FT_SYMLINK,215EXOFS_FT_MAX216};217218#define EXOFS_DIR_PAD 4219#define EXOFS_DIR_ROUND (EXOFS_DIR_PAD - 1)220#define EXOFS_DIR_REC_LEN(name_len) \221(((name_len) + offsetof(struct exofs_dir_entry, name) + \222EXOFS_DIR_ROUND) & ~EXOFS_DIR_ROUND)223224/*225* The on-disk (optional) layout structure.226* sits in an EXOFS_ATTR_INODE_FILE_LAYOUT or EXOFS_ATTR_INODE_DIR_LAYOUT227* attribute, attached to any inode, usually to a directory.228*/229230enum exofs_inode_layout_gen_functions {231LAYOUT_MOVING_WINDOW = 0,232LAYOUT_IMPLICT = 1,233};234235struct exofs_on_disk_inode_layout {236__le16 gen_func; /* One of enum exofs_inode_layout_gen_functions */237__le16 pad;238union {239/* gen_func == LAYOUT_MOVING_WINDOW (default) */240struct exofs_layout_sliding_window {241__le32 num_devices; /* first n devices in global-table*/242} sliding_window __packed;243244/* gen_func == LAYOUT_IMPLICT */245struct exofs_layout_implict_list {246struct exofs_dt_data_map data_map;247/* Variable array of size data_map.cb_num_comps. These248* are device indexes of the devices in the global table249*/250__le32 dev_indexes[];251} implict __packed;252};253} __packed;254255static inline size_t exofs_on_disk_inode_layout_size(unsigned max_devs)256{257return sizeof(struct exofs_on_disk_inode_layout) +258max_devs * sizeof(__le32);259}260261#endif /*ifndef __EXOFS_COM_H__*/262263264