1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16#include "isofs.h"
17
18static struct dentry *
19isofs_export_iget(struct super_block *sb,
20 unsigned long block,
21 unsigned long offset,
22 __u32 generation)
23{
24 struct inode *inode;
25
26 if (block == 0)
27 return ERR_PTR(-ESTALE);
28 inode = isofs_iget(sb, block, offset);
29 if (IS_ERR(inode))
30 return ERR_CAST(inode);
31 if (generation && inode->i_generation != generation) {
32 iput(inode);
33 return ERR_PTR(-ESTALE);
34 }
35 return d_obtain_alias(inode);
36}
37
38
39
40
41
42
43static struct dentry *isofs_export_get_parent(struct dentry *child)
44{
45 unsigned long parent_block = 0;
46 unsigned long parent_offset = 0;
47 struct inode *child_inode = d_inode(child);
48 struct iso_inode_info *e_child_inode = ISOFS_I(child_inode);
49 struct iso_directory_record *de = NULL;
50 struct buffer_head * bh = NULL;
51 struct dentry *rv = NULL;
52
53
54 if (!S_ISDIR(child_inode->i_mode)) {
55 printk(KERN_ERR "isofs: isofs_export_get_parent(): "
56 "child is not a directory!\n");
57 rv = ERR_PTR(-EACCES);
58 goto out;
59 }
60
61
62
63
64 if (e_child_inode->i_iget5_offset != 0) {
65 printk(KERN_ERR "isofs: isofs_export_get_parent(): "
66 "child directory not normalized!\n");
67 rv = ERR_PTR(-EACCES);
68 goto out;
69 }
70
71
72
73
74 parent_block = e_child_inode->i_iget5_block;
75
76
77 bh = sb_bread(child_inode->i_sb, parent_block);
78 if (bh == NULL) {
79 rv = ERR_PTR(-EACCES);
80 goto out;
81 }
82
83
84 de = (struct iso_directory_record*)bh->b_data;
85
86
87 parent_offset = (unsigned long)isonum_711(de->length);
88 de = (struct iso_directory_record*)(bh->b_data + parent_offset);
89
90
91 if ((isonum_711(de->name_len) != 1) || (de->name[0] != 1)) {
92 printk(KERN_ERR "isofs: Unable to find the \"..\" "
93 "directory for NFS.\n");
94 rv = ERR_PTR(-EACCES);
95 goto out;
96 }
97
98
99 isofs_normalize_block_and_offset(de, &parent_block, &parent_offset);
100
101 rv = d_obtain_alias(isofs_iget(child_inode->i_sb, parent_block,
102 parent_offset));
103 out:
104 if (bh)
105 brelse(bh);
106 return rv;
107}
108
109static int
110isofs_export_encode_fh(struct inode *inode,
111 __u32 *fh32,
112 int *max_len,
113 struct inode *parent)
114{
115 struct iso_inode_info * ei = ISOFS_I(inode);
116 int len = *max_len;
117 int type = 1;
118 __u16 *fh16 = (__u16*)fh32;
119
120
121
122
123
124
125
126 if (parent && (len < 5)) {
127 *max_len = 5;
128 return FILEID_INVALID;
129 } else if (len < 3) {
130 *max_len = 3;
131 return FILEID_INVALID;
132 }
133
134 len = 3;
135 fh32[0] = ei->i_iget5_block;
136 fh16[2] = (__u16)ei->i_iget5_offset;
137 fh16[3] = 0;
138 fh32[2] = inode->i_generation;
139 if (parent) {
140 struct iso_inode_info *eparent;
141 eparent = ISOFS_I(parent);
142 fh32[3] = eparent->i_iget5_block;
143 fh16[3] = (__u16)eparent->i_iget5_offset;
144 fh32[4] = parent->i_generation;
145 len = 5;
146 type = 2;
147 }
148 *max_len = len;
149 return type;
150}
151
152struct isofs_fid {
153 u32 block;
154 u16 offset;
155 u16 parent_offset;
156 u32 generation;
157 u32 parent_block;
158 u32 parent_generation;
159};
160
161static struct dentry *isofs_fh_to_dentry(struct super_block *sb,
162 struct fid *fid, int fh_len, int fh_type)
163{
164 struct isofs_fid *ifid = (struct isofs_fid *)fid;
165
166 if (fh_len < 3 || fh_type > 2)
167 return NULL;
168
169 return isofs_export_iget(sb, ifid->block, ifid->offset,
170 ifid->generation);
171}
172
173static struct dentry *isofs_fh_to_parent(struct super_block *sb,
174 struct fid *fid, int fh_len, int fh_type)
175{
176 struct isofs_fid *ifid = (struct isofs_fid *)fid;
177
178 if (fh_len < 2 || fh_type != 2)
179 return NULL;
180
181 return isofs_export_iget(sb,
182 fh_len > 2 ? ifid->parent_block : 0,
183 ifid->parent_offset,
184 fh_len > 4 ? ifid->parent_generation : 0);
185}
186
187const struct export_operations isofs_export_ops = {
188 .encode_fh = isofs_export_encode_fh,
189 .fh_to_dentry = isofs_fh_to_dentry,
190 .fh_to_parent = isofs_fh_to_parent,
191 .get_parent = isofs_export_get_parent,
192};
193