2 * Copyright (c) 2004-2005 Silicon Graphics, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 #include "xfs_types.h"
20 #include "xfs_dmapi.h"
22 #include "xfs_trans.h"
24 #include "xfs_mount.h"
25 #include "xfs_export.h"
27 static struct dentry dotdot = { .d_name.name = "..", .d_name.len = 2, };
30 * XFS encodes and decodes the fileid portion of NFS filehandles
31 * itself instead of letting the generic NFS code do it. This
32 * allows filesystems with 64 bit inode numbers to be exported.
34 * Note that a side effect is that xfs_vget() won't be passed a
35 * zero inode/generation pair under normal circumstances. As
36 * however a malicious client could send us such data, the check
37 * remains in that code.
40 STATIC struct dentry *
42 struct super_block *sb,
58 is64 = (fileid_type & XFS_FILEID_TYPE_64FLAG);
59 fileid_type &= ~XFS_FILEID_TYPE_64FLAG;
63 * Note that we only accept fileids which are long enough
64 * rather than allow the parent generation number to default
65 * to zero. XFS considers zero a valid generation number not
66 * an invalid/wildcard value. There's little point printk'ing
67 * a warning here as we don't have the client information
68 * which would make such a warning useful.
70 if (fileid_type > 2 ||
71 fh_len < xfs_fileid_length((fileid_type == 2), is64))
74 p = xfs_fileid_decode_fid2(p, &ifid, is64);
76 if (fileid_type == 2) {
77 p = xfs_fileid_decode_fid2(p, &pfid, is64);
82 return sb->s_export_op->find_exported_dentry(sb, fh, parent, acceptable, context);
88 struct dentry *dentry,
93 struct inode *inode = dentry->d_inode;
99 bhv_vfs_t *vfs = vfs_from_sb(inode->i_sb);
101 if (!(vfs->vfs_flag & VFS_32BITINODES)) {
102 /* filesystem may contain 64bit inode numbers */
103 is64 = XFS_FILEID_TYPE_64FLAG;
107 /* Directories don't need their parent encoded, they have ".." */
108 if (S_ISDIR(inode->i_mode))
112 * Only encode if there is enough space given. In practice
113 * this means we can't export a filesystem with 64bit inodes
114 * over NFSv2 with the subtree_check export option; the other
115 * seven combinations work. The real answer is "don't use v2".
117 len = xfs_fileid_length(connectable, is64);
122 p = xfs_fileid_encode_inode(p, inode, is64);
124 spin_lock(&dentry->d_lock);
125 p = xfs_fileid_encode_inode(p, dentry->d_parent->d_inode, is64);
126 spin_unlock(&dentry->d_lock);
129 BUG_ON((p - fh) != len);
133 STATIC struct dentry *
135 struct super_block *sb,
140 struct dentry *result;
141 bhv_vfs_t *vfsp = vfs_from_sb(sb);
144 error = bhv_vfs_vget(vfsp, &vp, (fid_t *)data);
145 if (error || vp == NULL)
146 return ERR_PTR(-ESTALE) ;
148 inode = vn_to_inode(vp);
149 result = d_alloc_anon(inode);
152 return ERR_PTR(-ENOMEM);
157 STATIC struct dentry *
159 struct dentry *child)
162 bhv_vnode_t *vp, *cvp;
163 struct dentry *parent;
166 vp = vn_from_inode(child->d_inode);
167 error = bhv_vop_lookup(vp, &dotdot, &cvp, 0, NULL, NULL);
169 return ERR_PTR(-error);
171 parent = d_alloc_anon(vn_to_inode(cvp));
172 if (unlikely(!parent)) {
174 return ERR_PTR(-ENOMEM);
179 struct export_operations xfs_export_operations = {
180 .decode_fh = xfs_fs_decode_fh,
181 .encode_fh = xfs_fs_encode_fh,
182 .get_parent = xfs_fs_get_parent,
183 .get_dentry = xfs_fs_get_dentry,