2 * 2007+ Copyright (c) Evgeniy Polyakov <zbr@ioremap.net>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
16 #include <linux/module.h>
18 #include <linux/ktime.h>
19 #include <linux/fs_struct.h>
20 #include <linux/pagemap.h>
21 #include <linux/writeback.h>
22 #include <linux/mount.h>
27 #define UNHASHED_OBSCURE_STRING_SIZE sizeof(" (deleted)")
30 * Create path from root for given inode.
31 * Path is formed as set of stuctures, containing name of the object
32 * and its inode data (mode, permissions and so on).
34 int pohmelfs_construct_path_string(struct pohmelfs_inode
*pi
, void *data
, int len
)
39 int err
= 0, strlen
, reduce
= 0;
41 d
= d_find_alias(&pi
->vfs_inode
);
43 printk("%s: no alias, list_empty: %d.\n", __func__
, list_empty(&pi
->vfs_inode
.i_dentry
));
47 spin_lock(¤t
->fs
->lock
);
48 path
.mnt
= mntget(current
->fs
->root
.mnt
);
49 spin_unlock(¤t
->fs
->lock
);
53 if (!IS_ROOT(d
) && d_unhashed(d
))
56 ptr
= d_path(&path
, data
, len
);
62 if (reduce
&& len
>= UNHASHED_OBSCURE_STRING_SIZE
) {
63 char *end
= data
+ len
- UNHASHED_OBSCURE_STRING_SIZE
;
67 strlen
= len
- (ptr
- (char *)data
);
68 memmove(data
, ptr
, strlen
);
73 dprintk("%s: dname: '%s', len: %u, maxlen: %u, name: '%s', strlen: %d.\n",
74 __func__
, d
->d_name
.name
, d
->d_name
.len
, len
, ptr
, strlen
);
83 int pohmelfs_path_length(struct pohmelfs_inode
*pi
)
85 struct dentry
*d
, *root
, *first
;
89 first
= d_find_alias(&pi
->vfs_inode
);
91 dprintk("%s: ino: %llu, mode: %o.\n", __func__
, pi
->ino
, pi
->vfs_inode
.i_mode
);
95 spin_lock(¤t
->fs
->lock
);
96 root
= dget(current
->fs
->root
.dentry
);
97 spin_unlock(¤t
->fs
->lock
);
100 len
= 1; /* Root slash */
102 seq
= read_seqbegin(&rename_lock
);
105 if (!IS_ROOT(d
) && d_unhashed(d
))
106 len
+= UNHASHED_OBSCURE_STRING_SIZE
; /* Obscure " (deleted)" string */
108 while (d
&& d
!= root
&& !IS_ROOT(d
)) {
109 len
+= d
->d_name
.len
+ 1; /* Plus slash */
113 if (read_seqretry(&rename_lock
, seq
))
119 return len
+ 1; /* Including zero-byte */