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"
25 #include "xfs_mount.h"
26 #include "xfs_export.h"
29 * XFS encodes and decodes the fileid portion of NFS filehandles
30 * itself instead of letting the generic NFS code do it. This
31 * allows filesystems with 64 bit inode numbers to be exported.
33 * Note that a side effect is that xfs_vget() won't be passed a
34 * zero inode/generation pair under normal circumstances. As
35 * however a malicious client could send us such data, the check
36 * remains in that code.
39 STATIC struct dentry *
41 struct super_block *sb,
57 is64 = (fileid_type & XFS_FILEID_TYPE_64FLAG);
58 fileid_type &= ~XFS_FILEID_TYPE_64FLAG;
62 * Note that we only accept fileids which are long enough
63 * rather than allow the parent generation number to default
64 * to zero. XFS considers zero a valid generation number not
65 * an invalid/wildcard value. There's little point printk'ing
66 * a warning here as we don't have the client information
67 * which would make such a warning useful.
69 if (fileid_type > 2 ||
70 fh_len < xfs_fileid_length((fileid_type == 2), is64))
73 p = xfs_fileid_decode_fid2(p, &ifid, is64);
75 if (fileid_type == 2) {
76 p = xfs_fileid_decode_fid2(p, &pfid, is64);
81 return find_exported_dentry(sb, fh, parent, acceptable, context);
87 struct dentry *dentry,
92 struct inode *inode = dentry->d_inode;
98 vfs_t *vfs = LINVFS_GET_VFS(inode->i_sb);
100 if (!(vfs->vfs_flag & VFS_32BITINODES)) {
101 /* filesystem may contain 64bit inode numbers */
102 is64 = XFS_FILEID_TYPE_64FLAG;
106 /* Directories don't need their parent encoded, they have ".." */
107 if (S_ISDIR(inode->i_mode))
111 * Only encode if there is enough space given. In practice
112 * this means we can't export a filesystem with 64bit inodes
113 * over NFSv2 with the subtree_check export option; the other
114 * seven combinations work. The real answer is "don't use v2".
116 len = xfs_fileid_length(connectable, is64);
121 p = xfs_fileid_encode_inode(p, inode, is64);
123 spin_lock(&dentry->d_lock);
124 p = xfs_fileid_encode_inode(p, dentry->d_parent->d_inode, is64);
125 spin_unlock(&dentry->d_lock);
128 BUG_ON((p - fh) != len);
132 STATIC struct dentry *
134 struct super_block *sb,
139 struct dentry *result;
140 vfs_t *vfsp = LINVFS_GET_VFS(sb);
143 VFS_VGET(vfsp, &vp, (fid_t *)data, error);
144 if (error || vp == NULL)
145 return ERR_PTR(-ESTALE) ;
147 inode = LINVFS_GET_IP(vp);
148 result = d_alloc_anon(inode);
151 return ERR_PTR(-ENOMEM);
156 STATIC struct dentry *
158 struct dentry *child)
162 struct dentry *parent;
163 struct dentry dotdot;
165 dotdot.d_name.name = "..";
166 dotdot.d_name.len = 2;
167 dotdot.d_inode = NULL;
170 vp = LINVFS_GET_VP(child->d_inode);
171 VOP_LOOKUP(vp, &dotdot, &cvp, 0, NULL, NULL, error);
173 return ERR_PTR(-error);
175 parent = d_alloc_anon(LINVFS_GET_IP(cvp));
176 if (unlikely(!parent)) {
178 return ERR_PTR(-ENOMEM);
183 struct export_operations linvfs_export_ops = {
184 .decode_fh = linvfs_decode_fh,
185 .encode_fh = linvfs_encode_fh,
186 .get_parent = linvfs_get_parent,
187 .get_dentry = linvfs_get_dentry,