Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2005 Silicon Graphics, Inc. All Rights Reserved. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify it |
| 5 | * under the terms of version 2 of the GNU General Public License as |
| 6 | * published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it would be useful, but |
| 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 11 | * |
| 12 | * Further, this software is distributed without any warranty that it is |
| 13 | * free of the rightful claim of any third person regarding infringement |
| 14 | * or the like. Any license provided herein, whether implied or |
| 15 | * otherwise, applies only to this software file. Patent licenses, if |
| 16 | * any, provided herein do not apply to combinations of this program with |
| 17 | * other software, or any other product whatsoever. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License along |
| 20 | * with this program; if not, write the Free Software Foundation, Inc., 59 |
| 21 | * Temple Place - Suite 330, Boston MA 02111-1307, USA. |
| 22 | * |
| 23 | * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, |
| 24 | * Mountain View, CA 94043, or: |
| 25 | * |
| 26 | * http://www.sgi.com |
| 27 | * |
| 28 | * For further information regarding this notice, see: |
| 29 | * |
| 30 | * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/ |
| 31 | */ |
| 32 | #ifndef __XFS_EXPORT_H__ |
| 33 | #define __XFS_EXPORT_H__ |
| 34 | |
| 35 | /* |
| 36 | * Common defines for code related to exporting XFS filesystems over NFS. |
| 37 | * |
| 38 | * The NFS fileid goes out on the wire as an array of |
| 39 | * 32bit unsigned ints in host order. There are 5 possible |
| 40 | * formats. |
| 41 | * |
| 42 | * (1) fileid_type=0x00 |
| 43 | * (no fileid data; handled by the generic code) |
| 44 | * |
| 45 | * (2) fileid_type=0x01 |
| 46 | * inode-num |
| 47 | * generation |
| 48 | * |
| 49 | * (3) fileid_type=0x02 |
| 50 | * inode-num |
| 51 | * generation |
| 52 | * parent-inode-num |
| 53 | * parent-generation |
| 54 | * |
| 55 | * (4) fileid_type=0x81 |
| 56 | * inode-num-lo32 |
| 57 | * inode-num-hi32 |
| 58 | * generation |
| 59 | * |
| 60 | * (5) fileid_type=0x82 |
| 61 | * inode-num-lo32 |
| 62 | * inode-num-hi32 |
| 63 | * generation |
| 64 | * parent-inode-num-lo32 |
| 65 | * parent-inode-num-hi32 |
| 66 | * parent-generation |
| 67 | * |
| 68 | * Note, the NFS filehandle also includes an fsid portion which |
| 69 | * may have an inode number in it. That number is hardcoded to |
| 70 | * 32bits and there is no way for XFS to intercept it. In |
| 71 | * practice this means when exporting an XFS filesytem with 64bit |
| 72 | * inodes you should either export the mountpoint (rather than |
| 73 | * a subdirectory) or use the "fsid" export option. |
| 74 | */ |
| 75 | |
| 76 | /* This flag goes on the wire. Don't play with it. */ |
| 77 | #define XFS_FILEID_TYPE_64FLAG 0x80 /* NFS fileid has 64bit inodes */ |
| 78 | |
| 79 | /* Calculate the length in u32 units of the fileid data */ |
| 80 | static inline int |
| 81 | xfs_fileid_length(int hasparent, int is64) |
| 82 | { |
| 83 | return hasparent ? (is64 ? 6 : 4) : (is64 ? 3 : 2); |
| 84 | } |
| 85 | |
| 86 | /* |
| 87 | * Decode encoded inode information (either for the inode itself |
| 88 | * or the parent) into an xfs_fid2_t structure. Advances and |
| 89 | * returns the new data pointer |
| 90 | */ |
| 91 | static inline __u32 * |
| 92 | xfs_fileid_decode_fid2(__u32 *p, xfs_fid2_t *fid, int is64) |
| 93 | { |
| 94 | fid->fid_len = sizeof(xfs_fid2_t) - sizeof(fid->fid_len); |
| 95 | fid->fid_pad = 0; |
| 96 | fid->fid_ino = *p++; |
| 97 | #if XFS_BIG_INUMS |
| 98 | if (is64) |
| 99 | fid->fid_ino |= (((__u64)(*p++)) << 32); |
| 100 | #endif |
| 101 | fid->fid_gen = *p++; |
| 102 | return p; |
| 103 | } |
| 104 | |
| 105 | /* |
| 106 | * Encode inode information (either for the inode itself or the |
| 107 | * parent) into a fileid buffer. Advances and returns the new |
| 108 | * data pointer. |
| 109 | */ |
| 110 | static inline __u32 * |
| 111 | xfs_fileid_encode_inode(__u32 *p, struct inode *inode, int is64) |
| 112 | { |
| 113 | *p++ = (__u32)inode->i_ino; |
| 114 | #if XFS_BIG_INUMS |
| 115 | if (is64) |
| 116 | *p++ = (__u32)(inode->i_ino >> 32); |
| 117 | #endif |
| 118 | *p++ = inode->i_generation; |
| 119 | return p; |
| 120 | } |
| 121 | |
| 122 | #endif /* __XFS_EXPORT_H__ */ |