blob: e5e7311f1b92abe20b7213b1efb97e6795ac6889 [file] [log] [blame]
Ryusuke Konishid2500652009-04-06 19:01:34 -07001/*
2 * namei.c - NILFS pathname lookup operations.
3 *
4 * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 *
20 * Modified for NILFS by Amagai Yoshiji <amagai@osrg.net>,
21 * Ryusuke Konishi <ryusuke@osrg.net>
22 */
23/*
24 * linux/fs/ext2/namei.c
25 *
26 * Copyright (C) 1992, 1993, 1994, 1995
27 * Remy Card (card@masi.ibp.fr)
28 * Laboratoire MASI - Institut Blaise Pascal
29 * Universite Pierre et Marie Curie (Paris VI)
30 *
31 * from
32 *
33 * linux/fs/minix/namei.c
34 *
35 * Copyright (C) 1991, 1992 Linus Torvalds
36 *
37 * Big-endian to little-endian byte-swapping/bitmaps by
38 * David S. Miller (davem@caip.rutgers.edu), 1995
39 */
40
41#include <linux/pagemap.h>
42#include "nilfs.h"
Ryusuke Konishi8e656fd2010-08-27 00:23:02 +090043#include "export.h"
Ryusuke Konishid2500652009-04-06 19:01:34 -070044
Ryusuke Konishi8e656fd2010-08-27 00:23:02 +090045#define NILFS_FID_SIZE_NON_CONNECTABLE \
46 (offsetof(struct nilfs_fid, parent_gen) / 4)
47#define NILFS_FID_SIZE_CONNECTABLE (sizeof(struct nilfs_fid) / 4)
Ryusuke Konishid2500652009-04-06 19:01:34 -070048
49static inline int nilfs_add_nondir(struct dentry *dentry, struct inode *inode)
50{
51 int err = nilfs_add_link(dentry, inode);
52 if (!err) {
53 d_instantiate(dentry, inode);
54 return 0;
55 }
56 inode_dec_link_count(inode);
57 iput(inode);
58 return err;
59}
60
61/*
62 * Methods themselves.
63 */
64
65static struct dentry *
66nilfs_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
67{
68 struct inode *inode;
69 ino_t ino;
70
71 if (dentry->d_name.len > NILFS_NAME_LEN)
72 return ERR_PTR(-ENAMETOOLONG);
73
Al Viro03190032010-01-31 21:02:09 -050074 ino = nilfs_inode_by_name(dir, &dentry->d_name);
Al Viroa9049372011-07-08 21:20:11 -040075 inode = ino ? nilfs_iget(dir->i_sb, NILFS_I(dir)->i_root, ino) : NULL;
Ryusuke Konishid2500652009-04-06 19:01:34 -070076 return d_splice_alias(inode, dentry);
77}
78
Ryusuke Konishid2500652009-04-06 19:01:34 -070079/*
80 * By the time this is called, we already have created
81 * the directory cache entry for the new file, but it
82 * is so far negative - it has no inode.
83 *
84 * If the create succeeds, we fill in the inode information
85 * with d_instantiate().
86 */
87static int nilfs_create(struct inode *dir, struct dentry *dentry, int mode,
88 struct nameidata *nd)
89{
90 struct inode *inode;
91 struct nilfs_transaction_info ti;
Ryusuke Konishi47420c72009-04-06 19:01:45 -070092 int err;
Ryusuke Konishid2500652009-04-06 19:01:34 -070093
94 err = nilfs_transaction_begin(dir->i_sb, &ti, 1);
95 if (err)
96 return err;
97 inode = nilfs_new_inode(dir, mode);
98 err = PTR_ERR(inode);
99 if (!IS_ERR(inode)) {
100 inode->i_op = &nilfs_file_inode_operations;
101 inode->i_fop = &nilfs_file_operations;
102 inode->i_mapping->a_ops = &nilfs_aops;
Jiro SEKIBAabdb3182009-11-27 19:41:14 +0900103 nilfs_mark_inode_dirty(inode);
Ryusuke Konishid2500652009-04-06 19:01:34 -0700104 err = nilfs_add_nondir(dentry, inode);
105 }
Ryusuke Konishi47420c72009-04-06 19:01:45 -0700106 if (!err)
107 err = nilfs_transaction_commit(dir->i_sb);
108 else
109 nilfs_transaction_abort(dir->i_sb);
110
111 return err;
Ryusuke Konishid2500652009-04-06 19:01:34 -0700112}
113
114static int
115nilfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t rdev)
116{
117 struct inode *inode;
118 struct nilfs_transaction_info ti;
Ryusuke Konishi47420c72009-04-06 19:01:45 -0700119 int err;
Ryusuke Konishid2500652009-04-06 19:01:34 -0700120
121 if (!new_valid_dev(rdev))
122 return -EINVAL;
123
124 err = nilfs_transaction_begin(dir->i_sb, &ti, 1);
125 if (err)
126 return err;
127 inode = nilfs_new_inode(dir, mode);
128 err = PTR_ERR(inode);
129 if (!IS_ERR(inode)) {
130 init_special_inode(inode, inode->i_mode, rdev);
Jiro SEKIBAabdb3182009-11-27 19:41:14 +0900131 nilfs_mark_inode_dirty(inode);
Ryusuke Konishid2500652009-04-06 19:01:34 -0700132 err = nilfs_add_nondir(dentry, inode);
133 }
Ryusuke Konishi47420c72009-04-06 19:01:45 -0700134 if (!err)
135 err = nilfs_transaction_commit(dir->i_sb);
136 else
137 nilfs_transaction_abort(dir->i_sb);
138
139 return err;
Ryusuke Konishid2500652009-04-06 19:01:34 -0700140}
141
142static int nilfs_symlink(struct inode *dir, struct dentry *dentry,
143 const char *symname)
144{
145 struct nilfs_transaction_info ti;
146 struct super_block *sb = dir->i_sb;
147 unsigned l = strlen(symname)+1;
148 struct inode *inode;
Ryusuke Konishi47420c72009-04-06 19:01:45 -0700149 int err;
Ryusuke Konishid2500652009-04-06 19:01:34 -0700150
151 if (l > sb->s_blocksize)
152 return -ENAMETOOLONG;
153
154 err = nilfs_transaction_begin(dir->i_sb, &ti, 1);
155 if (err)
156 return err;
157
158 inode = nilfs_new_inode(dir, S_IFLNK | S_IRWXUGO);
159 err = PTR_ERR(inode);
160 if (IS_ERR(inode))
161 goto out;
162
163 /* slow symlink */
164 inode->i_op = &nilfs_symlink_inode_operations;
165 inode->i_mapping->a_ops = &nilfs_aops;
166 err = page_symlink(inode, symname, l);
167 if (err)
168 goto out_fail;
169
170 /* mark_inode_dirty(inode); */
Jiro SEKIBA9ca941d2009-11-27 19:41:06 +0900171 /* page_symlink() do this */
Ryusuke Konishid2500652009-04-06 19:01:34 -0700172
173 err = nilfs_add_nondir(dentry, inode);
174out:
Ryusuke Konishi47420c72009-04-06 19:01:45 -0700175 if (!err)
176 err = nilfs_transaction_commit(dir->i_sb);
177 else
178 nilfs_transaction_abort(dir->i_sb);
179
180 return err;
Ryusuke Konishid2500652009-04-06 19:01:34 -0700181
182out_fail:
Jiro SEKIBA565de402009-11-27 19:41:08 +0900183 drop_nlink(inode);
Jiro SEKIBAabdb3182009-11-27 19:41:14 +0900184 nilfs_mark_inode_dirty(inode);
Ryusuke Konishid2500652009-04-06 19:01:34 -0700185 iput(inode);
186 goto out;
187}
188
189static int nilfs_link(struct dentry *old_dentry, struct inode *dir,
190 struct dentry *dentry)
191{
192 struct inode *inode = old_dentry->d_inode;
193 struct nilfs_transaction_info ti;
Ryusuke Konishi47420c72009-04-06 19:01:45 -0700194 int err;
Ryusuke Konishid2500652009-04-06 19:01:34 -0700195
196 if (inode->i_nlink >= NILFS_LINK_MAX)
197 return -EMLINK;
198
199 err = nilfs_transaction_begin(dir->i_sb, &ti, 1);
200 if (err)
201 return err;
202
203 inode->i_ctime = CURRENT_TIME;
204 inode_inc_link_count(inode);
Al Viro7de9c6ee2010-10-23 11:11:40 -0400205 ihold(inode);
Ryusuke Konishid2500652009-04-06 19:01:34 -0700206
207 err = nilfs_add_nondir(dentry, inode);
Ryusuke Konishi47420c72009-04-06 19:01:45 -0700208 if (!err)
209 err = nilfs_transaction_commit(dir->i_sb);
210 else
211 nilfs_transaction_abort(dir->i_sb);
212
213 return err;
Ryusuke Konishid2500652009-04-06 19:01:34 -0700214}
215
Al Viro18bb1db2011-07-26 01:41:39 -0400216static int nilfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
Ryusuke Konishid2500652009-04-06 19:01:34 -0700217{
218 struct inode *inode;
219 struct nilfs_transaction_info ti;
Ryusuke Konishi47420c72009-04-06 19:01:45 -0700220 int err;
Ryusuke Konishid2500652009-04-06 19:01:34 -0700221
222 if (dir->i_nlink >= NILFS_LINK_MAX)
223 return -EMLINK;
224
225 err = nilfs_transaction_begin(dir->i_sb, &ti, 1);
226 if (err)
227 return err;
228
Jiro SEKIBA565de402009-11-27 19:41:08 +0900229 inc_nlink(dir);
Ryusuke Konishid2500652009-04-06 19:01:34 -0700230
231 inode = nilfs_new_inode(dir, S_IFDIR | mode);
232 err = PTR_ERR(inode);
233 if (IS_ERR(inode))
234 goto out_dir;
235
236 inode->i_op = &nilfs_dir_inode_operations;
237 inode->i_fop = &nilfs_dir_operations;
238 inode->i_mapping->a_ops = &nilfs_aops;
239
Jiro SEKIBA565de402009-11-27 19:41:08 +0900240 inc_nlink(inode);
Ryusuke Konishid2500652009-04-06 19:01:34 -0700241
242 err = nilfs_make_empty(inode, dir);
243 if (err)
244 goto out_fail;
245
246 err = nilfs_add_link(dentry, inode);
247 if (err)
248 goto out_fail;
249
Jiro SEKIBAabdb3182009-11-27 19:41:14 +0900250 nilfs_mark_inode_dirty(inode);
Ryusuke Konishid2500652009-04-06 19:01:34 -0700251 d_instantiate(dentry, inode);
252out:
Ryusuke Konishi47420c72009-04-06 19:01:45 -0700253 if (!err)
254 err = nilfs_transaction_commit(dir->i_sb);
255 else
256 nilfs_transaction_abort(dir->i_sb);
257
258 return err;
Ryusuke Konishid2500652009-04-06 19:01:34 -0700259
260out_fail:
Jiro SEKIBA565de402009-11-27 19:41:08 +0900261 drop_nlink(inode);
Jiro SEKIBA565de402009-11-27 19:41:08 +0900262 drop_nlink(inode);
Jiro SEKIBAabdb3182009-11-27 19:41:14 +0900263 nilfs_mark_inode_dirty(inode);
Ryusuke Konishid2500652009-04-06 19:01:34 -0700264 iput(inode);
265out_dir:
Jiro SEKIBA565de402009-11-27 19:41:08 +0900266 drop_nlink(dir);
Jiro SEKIBAabdb3182009-11-27 19:41:14 +0900267 nilfs_mark_inode_dirty(dir);
Ryusuke Konishid2500652009-04-06 19:01:34 -0700268 goto out;
269}
270
Jiro SEKIBA4cd76c32009-11-27 19:41:10 +0900271static int nilfs_do_unlink(struct inode *dir, struct dentry *dentry)
Ryusuke Konishid2500652009-04-06 19:01:34 -0700272{
273 struct inode *inode;
274 struct nilfs_dir_entry *de;
275 struct page *page;
Ryusuke Konishi47420c72009-04-06 19:01:45 -0700276 int err;
Ryusuke Konishid2500652009-04-06 19:01:34 -0700277
Ryusuke Konishid2500652009-04-06 19:01:34 -0700278 err = -ENOENT;
Al Viro03190032010-01-31 21:02:09 -0500279 de = nilfs_find_entry(dir, &dentry->d_name, &page);
Ryusuke Konishid2500652009-04-06 19:01:34 -0700280 if (!de)
281 goto out;
282
283 inode = dentry->d_inode;
284 err = -EIO;
285 if (le64_to_cpu(de->inode) != inode->i_ino)
286 goto out;
287
288 if (!inode->i_nlink) {
289 nilfs_warning(inode->i_sb, __func__,
290 "deleting nonexistent file (%lu), %d\n",
291 inode->i_ino, inode->i_nlink);
Miklos Szeredibfe86842011-10-28 14:13:29 +0200292 set_nlink(inode, 1);
Ryusuke Konishid2500652009-04-06 19:01:34 -0700293 }
294 err = nilfs_delete_entry(de, page);
295 if (err)
296 goto out;
297
298 inode->i_ctime = dir->i_ctime;
Jiro SEKIBA565de402009-11-27 19:41:08 +0900299 drop_nlink(inode);
Ryusuke Konishid2500652009-04-06 19:01:34 -0700300 err = 0;
301out:
Jiro SEKIBA4cd76c32009-11-27 19:41:10 +0900302 return err;
303}
304
305static int nilfs_unlink(struct inode *dir, struct dentry *dentry)
306{
307 struct nilfs_transaction_info ti;
308 int err;
309
310 err = nilfs_transaction_begin(dir->i_sb, &ti, 0);
311 if (err)
312 return err;
313
314 err = nilfs_do_unlink(dir, dentry);
315
316 if (!err) {
Jiro SEKIBAabdb3182009-11-27 19:41:14 +0900317 nilfs_mark_inode_dirty(dir);
318 nilfs_mark_inode_dirty(dentry->d_inode);
Ryusuke Konishi47420c72009-04-06 19:01:45 -0700319 err = nilfs_transaction_commit(dir->i_sb);
Jiro SEKIBA4cd76c32009-11-27 19:41:10 +0900320 } else
Ryusuke Konishi47420c72009-04-06 19:01:45 -0700321 nilfs_transaction_abort(dir->i_sb);
322
323 return err;
Ryusuke Konishid2500652009-04-06 19:01:34 -0700324}
325
326static int nilfs_rmdir(struct inode *dir, struct dentry *dentry)
327{
328 struct inode *inode = dentry->d_inode;
329 struct nilfs_transaction_info ti;
Ryusuke Konishi47420c72009-04-06 19:01:45 -0700330 int err;
Ryusuke Konishid2500652009-04-06 19:01:34 -0700331
332 err = nilfs_transaction_begin(dir->i_sb, &ti, 0);
333 if (err)
334 return err;
335
336 err = -ENOTEMPTY;
337 if (nilfs_empty_dir(inode)) {
Jiro SEKIBA4cd76c32009-11-27 19:41:10 +0900338 err = nilfs_do_unlink(dir, dentry);
Ryusuke Konishid2500652009-04-06 19:01:34 -0700339 if (!err) {
340 inode->i_size = 0;
Jiro SEKIBA565de402009-11-27 19:41:08 +0900341 drop_nlink(inode);
Jiro SEKIBAabdb3182009-11-27 19:41:14 +0900342 nilfs_mark_inode_dirty(inode);
Jiro SEKIBA565de402009-11-27 19:41:08 +0900343 drop_nlink(dir);
Jiro SEKIBAabdb3182009-11-27 19:41:14 +0900344 nilfs_mark_inode_dirty(dir);
Ryusuke Konishid2500652009-04-06 19:01:34 -0700345 }
346 }
Ryusuke Konishi47420c72009-04-06 19:01:45 -0700347 if (!err)
348 err = nilfs_transaction_commit(dir->i_sb);
349 else
350 nilfs_transaction_abort(dir->i_sb);
351
352 return err;
Ryusuke Konishid2500652009-04-06 19:01:34 -0700353}
354
355static int nilfs_rename(struct inode *old_dir, struct dentry *old_dentry,
356 struct inode *new_dir, struct dentry *new_dentry)
357{
358 struct inode *old_inode = old_dentry->d_inode;
359 struct inode *new_inode = new_dentry->d_inode;
360 struct page *dir_page = NULL;
361 struct nilfs_dir_entry *dir_de = NULL;
362 struct page *old_page;
363 struct nilfs_dir_entry *old_de;
364 struct nilfs_transaction_info ti;
365 int err;
366
367 err = nilfs_transaction_begin(old_dir->i_sb, &ti, 1);
368 if (unlikely(err))
369 return err;
370
371 err = -ENOENT;
Al Viro03190032010-01-31 21:02:09 -0500372 old_de = nilfs_find_entry(old_dir, &old_dentry->d_name, &old_page);
Ryusuke Konishid2500652009-04-06 19:01:34 -0700373 if (!old_de)
374 goto out;
375
376 if (S_ISDIR(old_inode->i_mode)) {
377 err = -EIO;
378 dir_de = nilfs_dotdot(old_inode, &dir_page);
379 if (!dir_de)
380 goto out_old;
381 }
382
383 if (new_inode) {
384 struct page *new_page;
385 struct nilfs_dir_entry *new_de;
386
387 err = -ENOTEMPTY;
388 if (dir_de && !nilfs_empty_dir(new_inode))
389 goto out_dir;
390
391 err = -ENOENT;
Al Viro03190032010-01-31 21:02:09 -0500392 new_de = nilfs_find_entry(new_dir, &new_dentry->d_name, &new_page);
Ryusuke Konishid2500652009-04-06 19:01:34 -0700393 if (!new_de)
394 goto out_dir;
Ryusuke Konishid2500652009-04-06 19:01:34 -0700395 nilfs_set_link(new_dir, new_de, new_page, old_inode);
Jiro SEKIBAabdb3182009-11-27 19:41:14 +0900396 nilfs_mark_inode_dirty(new_dir);
Ryusuke Konishid2500652009-04-06 19:01:34 -0700397 new_inode->i_ctime = CURRENT_TIME;
398 if (dir_de)
399 drop_nlink(new_inode);
Jiro SEKIBA565de402009-11-27 19:41:08 +0900400 drop_nlink(new_inode);
Jiro SEKIBAabdb3182009-11-27 19:41:14 +0900401 nilfs_mark_inode_dirty(new_inode);
Ryusuke Konishid2500652009-04-06 19:01:34 -0700402 } else {
403 if (dir_de) {
404 err = -EMLINK;
405 if (new_dir->i_nlink >= NILFS_LINK_MAX)
406 goto out_dir;
407 }
Ryusuke Konishid2500652009-04-06 19:01:34 -0700408 err = nilfs_add_link(new_dentry, old_inode);
Al Viro30eb43d2011-03-02 12:01:13 -0500409 if (err)
Ryusuke Konishid2500652009-04-06 19:01:34 -0700410 goto out_dir;
Jiro SEKIBA565de402009-11-27 19:41:08 +0900411 if (dir_de) {
412 inc_nlink(new_dir);
Jiro SEKIBAabdb3182009-11-27 19:41:14 +0900413 nilfs_mark_inode_dirty(new_dir);
Jiro SEKIBA565de402009-11-27 19:41:08 +0900414 }
Ryusuke Konishid2500652009-04-06 19:01:34 -0700415 }
416
417 /*
418 * Like most other Unix systems, set the ctime for inodes on a
419 * rename.
Ryusuke Konishid2500652009-04-06 19:01:34 -0700420 */
421 old_inode->i_ctime = CURRENT_TIME;
422
423 nilfs_delete_entry(old_de, old_page);
Ryusuke Konishid2500652009-04-06 19:01:34 -0700424
425 if (dir_de) {
426 nilfs_set_link(old_inode, dir_de, dir_page, new_dir);
Jiro SEKIBA565de402009-11-27 19:41:08 +0900427 drop_nlink(old_dir);
Ryusuke Konishid2500652009-04-06 19:01:34 -0700428 }
Jiro SEKIBAabdb3182009-11-27 19:41:14 +0900429 nilfs_mark_inode_dirty(old_dir);
430 nilfs_mark_inode_dirty(old_inode);
Ryusuke Konishid2500652009-04-06 19:01:34 -0700431
Ryusuke Konishi47420c72009-04-06 19:01:45 -0700432 err = nilfs_transaction_commit(old_dir->i_sb);
Ryusuke Konishid2500652009-04-06 19:01:34 -0700433 return err;
434
435out_dir:
436 if (dir_de) {
437 kunmap(dir_page);
438 page_cache_release(dir_page);
439 }
440out_old:
441 kunmap(old_page);
442 page_cache_release(old_page);
443out:
Ryusuke Konishi47420c72009-04-06 19:01:45 -0700444 nilfs_transaction_abort(old_dir->i_sb);
Ryusuke Konishid2500652009-04-06 19:01:34 -0700445 return err;
446}
447
Ryusuke Konishi8e656fd2010-08-27 00:23:02 +0900448/*
449 * Export operations
450 */
451static struct dentry *nilfs_get_parent(struct dentry *child)
452{
453 unsigned long ino;
454 struct inode *inode;
455 struct qstr dotdot = {.name = "..", .len = 2};
456 struct nilfs_root *root;
457
458 ino = nilfs_inode_by_name(child->d_inode, &dotdot);
459 if (!ino)
460 return ERR_PTR(-ENOENT);
461
462 root = NILFS_I(child->d_inode)->i_root;
463
464 inode = nilfs_iget(child->d_inode->i_sb, root, ino);
465 if (IS_ERR(inode))
466 return ERR_CAST(inode);
467
468 return d_obtain_alias(inode);
469}
470
471static struct dentry *nilfs_get_dentry(struct super_block *sb, u64 cno,
472 u64 ino, u32 gen)
473{
474 struct nilfs_root *root;
475 struct inode *inode;
476
477 if (ino < NILFS_FIRST_INO(sb) && ino != NILFS_ROOT_INO)
478 return ERR_PTR(-ESTALE);
479
Ryusuke Konishie3154e92011-03-09 11:05:08 +0900480 root = nilfs_lookup_root(sb->s_fs_info, cno);
Ryusuke Konishi8e656fd2010-08-27 00:23:02 +0900481 if (!root)
482 return ERR_PTR(-ESTALE);
483
484 inode = nilfs_iget(sb, root, ino);
485 nilfs_put_root(root);
486
487 if (IS_ERR(inode))
488 return ERR_CAST(inode);
489 if (gen && inode->i_generation != gen) {
490 iput(inode);
491 return ERR_PTR(-ESTALE);
492 }
493 return d_obtain_alias(inode);
494}
495
496static struct dentry *nilfs_fh_to_dentry(struct super_block *sb, struct fid *fh,
497 int fh_len, int fh_type)
498{
499 struct nilfs_fid *fid = (struct nilfs_fid *)fh;
500
501 if ((fh_len != NILFS_FID_SIZE_NON_CONNECTABLE &&
502 fh_len != NILFS_FID_SIZE_CONNECTABLE) ||
503 (fh_type != FILEID_NILFS_WITH_PARENT &&
504 fh_type != FILEID_NILFS_WITHOUT_PARENT))
505 return NULL;
506
507 return nilfs_get_dentry(sb, fid->cno, fid->ino, fid->gen);
508}
509
510static struct dentry *nilfs_fh_to_parent(struct super_block *sb, struct fid *fh,
511 int fh_len, int fh_type)
512{
513 struct nilfs_fid *fid = (struct nilfs_fid *)fh;
514
515 if (fh_len != NILFS_FID_SIZE_CONNECTABLE ||
516 fh_type != FILEID_NILFS_WITH_PARENT)
517 return NULL;
518
519 return nilfs_get_dentry(sb, fid->cno, fid->parent_ino, fid->parent_gen);
520}
521
522static int nilfs_encode_fh(struct dentry *dentry, __u32 *fh, int *lenp,
523 int connectable)
524{
525 struct nilfs_fid *fid = (struct nilfs_fid *)fh;
526 struct inode *inode = dentry->d_inode;
527 struct nilfs_root *root = NILFS_I(inode)->i_root;
528 int type;
529
530 if (*lenp < NILFS_FID_SIZE_NON_CONNECTABLE ||
531 (connectable && *lenp < NILFS_FID_SIZE_CONNECTABLE))
532 return 255;
533
534 fid->cno = root->cno;
535 fid->ino = inode->i_ino;
536 fid->gen = inode->i_generation;
537
538 if (connectable && !S_ISDIR(inode->i_mode)) {
539 struct inode *parent;
540
541 spin_lock(&dentry->d_lock);
542 parent = dentry->d_parent->d_inode;
543 fid->parent_ino = parent->i_ino;
544 fid->parent_gen = parent->i_generation;
545 spin_unlock(&dentry->d_lock);
546
547 type = FILEID_NILFS_WITH_PARENT;
548 *lenp = NILFS_FID_SIZE_CONNECTABLE;
549 } else {
550 type = FILEID_NILFS_WITHOUT_PARENT;
551 *lenp = NILFS_FID_SIZE_NON_CONNECTABLE;
552 }
553
554 return type;
555}
556
Alexey Dobriyan6e1d5dc2009-09-21 17:01:11 -0700557const struct inode_operations nilfs_dir_inode_operations = {
Ryusuke Konishid2500652009-04-06 19:01:34 -0700558 .create = nilfs_create,
559 .lookup = nilfs_lookup,
560 .link = nilfs_link,
561 .unlink = nilfs_unlink,
562 .symlink = nilfs_symlink,
563 .mkdir = nilfs_mkdir,
564 .rmdir = nilfs_rmdir,
565 .mknod = nilfs_mknod,
566 .rename = nilfs_rename,
567 .setattr = nilfs_setattr,
568 .permission = nilfs_permission,
Ryusuke Konishi622daaff2010-12-26 16:38:43 +0900569 .fiemap = nilfs_fiemap,
Ryusuke Konishid2500652009-04-06 19:01:34 -0700570};
571
Alexey Dobriyan6e1d5dc2009-09-21 17:01:11 -0700572const struct inode_operations nilfs_special_inode_operations = {
Ryusuke Konishid2500652009-04-06 19:01:34 -0700573 .setattr = nilfs_setattr,
574 .permission = nilfs_permission,
575};
576
Alexey Dobriyan6e1d5dc2009-09-21 17:01:11 -0700577const struct inode_operations nilfs_symlink_inode_operations = {
Ryusuke Konishid2500652009-04-06 19:01:34 -0700578 .readlink = generic_readlink,
579 .follow_link = page_follow_link_light,
580 .put_link = page_put_link,
Ryusuke Konishidc3d3b82010-08-15 23:33:57 +0900581 .permission = nilfs_permission,
Ryusuke Konishid2500652009-04-06 19:01:34 -0700582};
Ryusuke Konishi8e656fd2010-08-27 00:23:02 +0900583
584const struct export_operations nilfs_export_ops = {
585 .encode_fh = nilfs_encode_fh,
586 .fh_to_dentry = nilfs_fh_to_dentry,
587 .fh_to_parent = nilfs_fh_to_parent,
588 .get_parent = nilfs_get_parent,
589};