18 #include <linux/string.h>
22 #include <linux/slab.h>
24 #include <linux/hash.h>
26 #include <linux/export.h>
29 #include <asm/uaccess.h>
38 #include <linux/prefetch.h>
99 #define D_HASHBITS d_hash_shift
100 #define D_HASHMASK d_hash_mask
112 return dentry_hashtable + (hash &
D_HASHMASK);
122 #if defined(CONFIG_SYSCTL) && defined(CONFIG_PROC_FS)
123 static int get_nr_dentry(
void)
133 size_t *lenp, loff_t *ppos)
144 #ifdef CONFIG_DCACHE_WORD_ACCESS
146 #include <asm/word-at-a-time.h>
156 static inline int dentry_string_cmp(
const unsigned char *
cs,
const unsigned char *
ct,
unsigned tcount)
161 a = *(
unsigned long *)cs;
162 b = load_unaligned_zeropad(ct);
163 if (tcount <
sizeof(
unsigned long))
167 cs +=
sizeof(
unsigned long);
168 ct +=
sizeof(
unsigned long);
169 tcount -=
sizeof(
unsigned long);
173 mask = ~(~0ul << tcount*8);
174 return unlikely(!!((a ^ b) & mask));
179 static inline int dentry_string_cmp(
const unsigned char *cs,
const unsigned char *ct,
unsigned tcount)
193 static inline int dentry_cmp(
const struct dentry *
dentry,
const unsigned char *ct,
unsigned tcount)
195 const unsigned char *
cs;
214 return dentry_string_cmp(cs, ct, tcount);
222 if (dname_external(dentry))
230 static void d_free(
struct dentry *dentry)
234 if (dentry->
d_op && dentry->
d_op->d_release)
235 dentry->
d_op->d_release(dentry);
251 static inline void dentry_rcuwalk_barrier(
struct dentry *dentry)
255 write_seqcount_barrier(&dentry->
d_seq);
263 static void dentry_iput(
struct dentry * dentry)
270 hlist_del_init(&dentry->
d_alias);
271 spin_unlock(&dentry->
d_lock);
272 spin_unlock(&inode->
i_lock);
274 fsnotify_inoderemove(inode);
275 if (dentry->
d_op && dentry->
d_op->d_iput)
276 dentry->
d_op->d_iput(dentry, inode);
280 spin_unlock(&dentry->
d_lock);
288 static void dentry_unlink_inode(
struct dentry * dentry)
292 struct inode *inode = dentry->
d_inode;
294 hlist_del_init(&dentry->
d_alias);
295 dentry_rcuwalk_barrier(dentry);
296 spin_unlock(&dentry->
d_lock);
297 spin_unlock(&inode->
i_lock);
299 fsnotify_inoderemove(inode);
300 if (dentry->
d_op && dentry->
d_op->d_iput)
301 dentry->
d_op->d_iput(dentry, inode);
309 static void dentry_lru_add(
struct dentry *dentry)
311 if (list_empty(&dentry->
d_lru)) {
312 spin_lock(&dcache_lru_lock);
313 list_add(&dentry->
d_lru, &dentry->
d_sb->s_dentry_lru);
314 dentry->
d_sb->s_nr_dentry_unused++;
316 spin_unlock(&dcache_lru_lock);
320 static void __dentry_lru_del(
struct dentry *dentry)
322 list_del_init(&dentry->
d_lru);
324 dentry->
d_sb->s_nr_dentry_unused--;
331 static void dentry_lru_del(
struct dentry *dentry)
333 if (!list_empty(&dentry->
d_lru)) {
334 spin_lock(&dcache_lru_lock);
335 __dentry_lru_del(dentry);
336 spin_unlock(&dcache_lru_lock);
345 static void dentry_lru_prune(
struct dentry *dentry)
347 if (!list_empty(&dentry->
d_lru)) {
349 dentry->
d_op->d_prune(dentry);
351 spin_lock(&dcache_lru_lock);
352 __dentry_lru_del(dentry);
353 spin_unlock(&dcache_lru_lock);
357 static void dentry_lru_move_list(
struct dentry *dentry,
struct list_head *
list)
359 spin_lock(&dcache_lru_lock);
360 if (list_empty(&dentry->
d_lru)) {
362 dentry->
d_sb->s_nr_dentry_unused++;
365 list_move_tail(&dentry->
d_lru, list);
367 spin_unlock(&dcache_lru_lock);
382 static struct dentry *d_kill(
struct dentry *dentry,
struct dentry *parent)
394 spin_unlock(&
parent->d_lock);
409 static void __d_shrink(
struct dentry *dentry)
411 if (!d_unhashed(dentry)) {
414 b = &dentry->
d_sb->s_anon;
419 __hlist_bl_del(&dentry->
d_hash);
442 if (!d_unhashed(dentry)) {
444 dentry_rcuwalk_barrier(dentry);
451 spin_lock(&dentry->
d_lock);
453 spin_unlock(&dentry->
d_lock);
468 spin_lock(&dentry->
d_lock);
471 spin_unlock(&dentry->
d_lock);
481 static inline struct dentry *dentry_kill(
struct dentry *dentry,
int ref)
488 if (inode && !spin_trylock(&inode->
i_lock)) {
490 spin_unlock(&dentry->
d_lock);
498 if (parent && !spin_trylock(&parent->
d_lock)) {
500 spin_unlock(&inode->
i_lock);
511 dentry_lru_prune(dentry);
514 return d_kill(dentry, parent);
543 void dput(
struct dentry *dentry)
551 spin_lock(&dentry->
d_lock);
555 spin_unlock(&dentry->
d_lock);
560 if (dentry->
d_op->d_delete(dentry))
565 if (d_unhashed(dentry))
573 if (!d_need_lookup(dentry))
575 dentry_lru_add(dentry);
578 spin_unlock(&dentry->
d_lock);
582 dentry = dentry_kill(dentry, 1);
605 spin_lock(&dentry->
d_lock);
606 if (d_unhashed(dentry)) {
607 spin_unlock(&dentry->
d_lock);
615 spin_unlock(&dentry->
d_lock);
617 spin_lock(&dentry->
d_lock);
634 spin_unlock(&dentry->
d_lock);
640 spin_unlock(&dentry->
d_lock);
646 static inline void __dget_dlock(
struct dentry *dentry)
651 static inline void __dget(
struct dentry *dentry)
653 spin_lock(&dentry->
d_lock);
654 __dget_dlock(dentry);
655 spin_unlock(&dentry->
d_lock);
671 spin_unlock(&ret->
d_lock);
678 spin_unlock(&ret->
d_lock);
699 static struct dentry *__d_find_alias(
struct inode *inode,
int want_discon)
701 struct dentry *
alias, *discon_alias;
707 spin_lock(&alias->
d_lock);
711 discon_alias =
alias;
712 }
else if (!want_discon) {
714 spin_unlock(&alias->
d_lock);
718 spin_unlock(&alias->
d_lock);
721 alias = discon_alias;
722 spin_lock(&alias->
d_lock);
727 spin_unlock(&alias->
d_lock);
731 spin_unlock(&alias->
d_lock);
739 struct dentry *de =
NULL;
741 if (!hlist_empty(&inode->
i_dentry)) {
742 spin_lock(&inode->
i_lock);
743 de = __d_find_alias(inode, 0);
744 spin_unlock(&inode->
i_lock);
756 struct dentry *dentry;
759 spin_lock(&inode->
i_lock);
761 spin_lock(&dentry->
d_lock);
763 __dget_dlock(dentry);
765 spin_unlock(&dentry->
d_lock);
766 spin_unlock(&inode->
i_lock);
770 spin_unlock(&dentry->
d_lock);
772 spin_unlock(&inode->
i_lock);
783 static void try_prune_one_dentry(
struct dentry *dentry)
786 struct dentry *parent;
788 parent = dentry_kill(dentry, 0);
801 if (parent == dentry)
807 spin_lock(&dentry->
d_lock);
810 spin_unlock(&dentry->
d_lock);
813 dentry = dentry_kill(dentry, 1);
817 static void shrink_dentry_list(
struct list_head *list)
819 struct dentry *dentry;
823 dentry = list_entry_rcu(list->
prev,
struct dentry,
d_lru);
824 if (&dentry->
d_lru == list)
826 spin_lock(&dentry->
d_lock);
828 spin_unlock(&dentry->
d_lock);
838 dentry_lru_del(dentry);
839 spin_unlock(&dentry->
d_lock);
845 try_prune_one_dentry(dentry);
866 struct dentry *dentry;
871 spin_lock(&dcache_lru_lock);
874 struct dentry,
d_lru);
877 if (!spin_trylock(&dentry->
d_lock)) {
878 spin_unlock(&dcache_lru_lock);
885 list_move(&dentry->
d_lru, &referenced);
886 spin_unlock(&dentry->
d_lock);
888 list_move_tail(&dentry->
d_lru, &
tmp);
890 spin_unlock(&dentry->
d_lock);
896 if (!list_empty(&referenced))
898 spin_unlock(&dcache_lru_lock);
900 shrink_dentry_list(&
tmp);
914 spin_lock(&dcache_lru_lock);
917 spin_unlock(&dcache_lru_lock);
918 shrink_dentry_list(&
tmp);
919 spin_lock(&dcache_lru_lock);
921 spin_unlock(&dcache_lru_lock);
930 static void shrink_dcache_for_umount_subtree(
struct dentry *dentry)
932 struct dentry *parent;
940 struct dentry,
d_u.d_child);
952 dentry_lru_prune(dentry);
957 "BUG: Dentry %p{i=%lx,n=%s}"
959 " [unmount of %s %s]\n",
965 dentry->
d_sb->s_type->name,
982 hlist_del_init(&dentry->
d_alias);
983 if (dentry->
d_op && dentry->
d_op->d_iput)
984 dentry->
d_op->d_iput(dentry, inode);
997 }
while (list_empty(&dentry->
d_subdirs));
1016 struct dentry *dentry;
1024 shrink_dcache_for_umount_subtree(dentry);
1026 while (!hlist_bl_empty(&sb->
s_anon)) {
1028 shrink_dcache_for_umount_subtree(dentry);
1038 static struct dentry *try_to_ascend(
struct dentry *old,
int locked,
unsigned seq)
1040 struct dentry *
new = old->
d_parent;
1043 spin_unlock(&old->
d_lock);
1044 spin_lock(&new->d_lock);
1052 (!locked && read_seqretry(&rename_lock, seq))) {
1053 spin_unlock(&new->d_lock);
1076 struct dentry *this_parent;
1083 this_parent = parent;
1085 if (d_mountpoint(parent))
1087 spin_lock(&this_parent->
d_lock);
1091 while (next != &this_parent->
d_subdirs) {
1093 struct dentry *dentry =
list_entry(tmp,
struct dentry,
d_u.d_child);
1098 if (d_mountpoint(dentry)) {
1099 spin_unlock(&dentry->
d_lock);
1100 spin_unlock(&this_parent->
d_lock);
1104 spin_unlock(&this_parent->
d_lock);
1106 this_parent = dentry;
1110 spin_unlock(&dentry->
d_lock);
1115 if (this_parent != parent) {
1116 struct dentry *
child = this_parent;
1117 this_parent = try_to_ascend(this_parent, locked, seq);
1123 spin_unlock(&this_parent->
d_lock);
1159 static int select_parent(
struct dentry *parent,
struct list_head *dispose)
1161 struct dentry *this_parent;
1167 seq = read_seqbegin(&rename_lock);
1169 this_parent = parent;
1170 spin_lock(&this_parent->
d_lock);
1174 while (next != &this_parent->
d_subdirs) {
1176 struct dentry *dentry =
list_entry(tmp,
struct dentry,
d_u.d_child);
1190 dentry_lru_del(dentry);
1192 dentry_lru_move_list(dentry, dispose);
1201 if (found && need_resched()) {
1202 spin_unlock(&dentry->
d_lock);
1210 spin_unlock(&this_parent->
d_lock);
1212 this_parent = dentry;
1217 spin_unlock(&dentry->
d_lock);
1222 if (this_parent != parent) {
1223 struct dentry *
child = this_parent;
1224 this_parent = try_to_ascend(this_parent, locked, seq);
1231 spin_unlock(&this_parent->
d_lock);
1232 if (!locked && read_seqretry(&rename_lock, seq))
1235 write_sequnlock(&rename_lock);
1244 write_seqlock(&rename_lock);
1259 while ((found = select_parent(parent, &dispose)) != 0)
1260 shrink_dentry_list(&dispose);
1276 struct dentry *dentry;
1300 dentry->
d_name.len = name->len;
1301 dentry->
d_name.hash = name->hash;
1303 dname[name->len] = 0;
1307 dentry->
d_name.name = dname;
1318 INIT_HLIST_BL_NODE(&dentry->
d_hash);
1319 INIT_LIST_HEAD(&dentry->
d_lru);
1321 INIT_HLIST_NODE(&dentry->
d_alias);
1345 spin_lock(&parent->
d_lock);
1350 __dget_dlock(parent);
1353 spin_unlock(&parent->
d_lock);
1361 struct dentry *dentry =
__d_alloc(sb, name);
1403 static void __d_instantiate(
struct dentry *dentry,
struct inode *inode)
1405 spin_lock(&dentry->
d_lock);
1412 dentry_rcuwalk_barrier(dentry);
1413 spin_unlock(&dentry->
d_lock);
1414 fsnotify_d_instantiate(dentry, inode);
1436 spin_lock(&inode->
i_lock);
1437 __d_instantiate(entry, inode);
1439 spin_unlock(&inode->
i_lock);
1460 static struct dentry *__d_instantiate_unique(
struct dentry *
entry,
1461 struct inode *inode)
1463 struct dentry *
alias;
1470 __d_instantiate(entry,
NULL);
1480 if (alias->
d_name.hash != hash)
1484 if (alias->
d_name.len != len)
1486 if (dentry_cmp(alias, name, len))
1492 __d_instantiate(entry, inode);
1503 spin_lock(&inode->
i_lock);
1504 result = __d_instantiate_unique(entry, inode);
1506 spin_unlock(&inode->
i_lock);
1513 BUG_ON(!d_unhashed(result));
1537 static struct dentry * __d_find_any_alias(
struct inode *inode)
1539 struct dentry *
alias;
1559 spin_lock(&inode->
i_lock);
1560 de = __d_find_any_alias(inode);
1561 spin_unlock(&inode->
i_lock);
1586 static const struct qstr anonstring = { .
name =
"" };
1593 return ERR_CAST(inode);
1605 spin_lock(&inode->
i_lock);
1606 res = __d_find_any_alias(inode);
1608 spin_unlock(&inode->
i_lock);
1618 hlist_bl_lock(&tmp->
d_sb->s_anon);
1619 hlist_bl_add_head(&tmp->
d_hash, &tmp->
d_sb->s_anon);
1620 hlist_bl_unlock(&tmp->
d_sb->s_anon);
1621 spin_unlock(&tmp->
d_lock);
1622 spin_unlock(&inode->
i_lock);
1628 if (res && !IS_ERR(res))
1653 struct dentry *
new =
NULL;
1656 return ERR_CAST(inode);
1659 spin_lock(&inode->
i_lock);
1660 new = __d_find_alias(inode, 1);
1663 spin_unlock(&inode->
i_lock);
1669 __d_instantiate(dentry, inode);
1670 spin_unlock(&inode->
i_lock);
1675 d_add(dentry, inode);
1696 struct dentry *
d_add_ci(
struct dentry *dentry,
struct inode *inode,
1700 struct dentry *found;
1743 if (
unlikely(d_need_lookup(found)))
1759 return ERR_PTR(error);
1784 const struct dentry *parent,
1785 struct inode *inode,
1786 struct dentry *dentry,
1788 const struct qstr *name)
1790 int tlen = dentry->
d_name.len;
1791 const char *tname = dentry->
d_name.name;
1792 struct inode *i = dentry->
d_inode;
1794 if (read_seqcount_retry(&dentry->
d_seq, seq)) {
1798 if (parent->
d_op->d_compare(parent, inode,
1836 const struct qstr *name,
1837 unsigned *seqp,
struct inode *inode)
1840 const unsigned char *
str = name->
name;
1843 struct dentry *dentry;
1884 seq = raw_seqcount_begin(&dentry->
d_seq);
1887 if (d_unhashed(dentry))
1894 switch (slow_dentry_cmp(parent, inode, dentry, seq, name)) {
1904 if (dentry->
d_name.hash_len != hashlen)
1906 if (!dentry_cmp(dentry, str,
hashlen_len(hashlen)))
1925 struct dentry *dentry;
1955 unsigned int len = name->len;
1956 unsigned int hash = name->hash;
1957 const unsigned char *
str = name->
name;
1960 struct dentry *found =
NULL;
1961 struct dentry *dentry;
1987 if (dentry->
d_name.hash != hash)
1990 spin_lock(&dentry->
d_lock);
1993 if (d_unhashed(dentry))
2001 int tlen = dentry->
d_name.len;
2002 const char *tname = dentry->
d_name.name;
2003 if (parent->
d_op->d_compare(parent, parent->
d_inode,
2008 if (dentry->
d_name.len != len)
2010 if (dentry_cmp(dentry, str, len))
2016 spin_unlock(&dentry->
d_lock);
2019 spin_unlock(&dentry->
d_lock);
2035 struct dentry *dentry =
NULL;
2044 if (dir->
d_op->d_hash(dir, dir->
d_inode, name) < 0)
2065 struct dentry *child;
2067 spin_lock(&dparent->
d_lock);
2069 if (dentry == child) {
2071 __dget_dlock(dentry);
2072 spin_unlock(&dentry->
d_lock);
2073 spin_unlock(&dparent->
d_lock);
2077 spin_unlock(&dparent->
d_lock);
2106 struct inode *
inode;
2112 spin_lock(&dentry->
d_lock);
2116 if (!spin_trylock(&inode->
i_lock)) {
2117 spin_unlock(&dentry->
d_lock);
2122 dentry_unlink_inode(dentry);
2123 fsnotify_nameremove(dentry, isdir);
2127 if (!d_unhashed(dentry))
2130 spin_unlock(&dentry->
d_lock);
2132 fsnotify_nameremove(dentry, isdir);
2136 static void __d_rehash(
struct dentry * entry,
struct hlist_bl_head *b)
2138 BUG_ON(!d_unhashed(entry));
2141 hlist_bl_add_head_rcu(&entry->
d_hash, b);
2145 static void _d_rehash(
struct dentry * entry)
2159 spin_lock(&entry->
d_lock);
2161 spin_unlock(&entry->
d_lock);
2184 spin_lock(&dentry->
d_lock);
2185 write_seqcount_begin(&dentry->
d_seq);
2187 write_seqcount_end(&dentry->
d_seq);
2188 spin_unlock(&dentry->
d_lock);
2192 static void switch_names(
struct dentry *dentry,
struct dentry *
target)
2194 if (dname_external(target)) {
2195 if (dname_external(dentry)) {
2211 if (dname_external(dentry)) {
2233 static void dentry_lock_for_move(
struct dentry *dentry,
struct dentry *target)
2239 spin_lock(&target->
d_parent->d_lock);
2242 spin_lock(&dentry->
d_parent->d_lock);
2246 spin_lock(&target->
d_parent->d_lock);
2251 if (target < dentry) {
2260 static void dentry_unlock_parents_for_move(
struct dentry *dentry,
2261 struct dentry *target)
2264 spin_unlock(&dentry->
d_parent->d_lock);
2266 spin_unlock(&target->
d_parent->d_lock);
2290 static void __d_move(
struct dentry * dentry,
struct dentry * target)
2298 dentry_lock_for_move(dentry, target);
2300 write_seqcount_begin(&dentry->
d_seq);
2301 write_seqcount_begin(&target->
d_seq);
2310 __d_rehash(dentry, d_hash(target->
d_parent, target->
d_name.hash));
2319 switch_names(dentry, target);
2336 write_seqcount_end(&target->
d_seq);
2337 write_seqcount_end(&dentry->
d_seq);
2339 dentry_unlock_parents_for_move(dentry, target);
2340 spin_unlock(&target->
d_lock);
2341 fsnotify_d_move(dentry);
2342 spin_unlock(&dentry->
d_lock);
2354 void d_move(
struct dentry *dentry,
struct dentry *target)
2357 __d_move(dentry, target);
2390 static struct dentry *__d_unalias(
struct inode *inode,
2391 struct dentry *dentry,
struct dentry *alias)
2394 struct dentry *
ret = ERR_PTR(-
EBUSY);
2403 m1 = &dentry->
d_sb->s_vfs_rename_mutex;
2406 m2 = &alias->
d_parent->d_inode->i_mutex;
2408 if (
likely(!d_mountpoint(alias))) {
2409 __d_move(alias, dentry);
2413 spin_unlock(&inode->
i_lock);
2426 static void __d_materialise_dentry(
struct dentry *dentry,
struct dentry *
anon)
2428 struct dentry *dparent, *aparent;
2430 dentry_lock_for_move(anon, dentry);
2432 write_seqcount_begin(&dentry->
d_seq);
2433 write_seqcount_begin(&anon->
d_seq);
2438 switch_names(dentry, anon);
2441 dentry->
d_parent = (aparent ==
anon) ? dentry : aparent;
2448 anon->
d_parent = (dparent == dentry) ? anon : dparent;
2455 write_seqcount_end(&dentry->
d_seq);
2456 write_seqcount_end(&anon->
d_seq);
2458 dentry_unlock_parents_for_move(anon, dentry);
2459 spin_unlock(&dentry->
d_lock);
2476 struct dentry *actual;
2478 BUG_ON(!d_unhashed(dentry));
2482 __d_instantiate(dentry,
NULL);
2487 spin_lock(&inode->
i_lock);
2490 struct dentry *
alias;
2493 alias = __d_find_alias(inode, 0);
2500 actual = ERR_PTR(-
ELOOP);
2501 spin_unlock(&inode->
i_lock);
2505 __d_materialise_dentry(dentry, alias);
2512 actual = __d_unalias(inode, dentry, alias);
2515 if (IS_ERR(actual)) {
2516 if (PTR_ERR(actual) == -
ELOOP)
2518 "VFS: Lookup of '%s' in %s %s"
2519 " would have caused loop\n",
2521 inode->
i_sb->s_type->name,
2530 actual = __d_instantiate_unique(dentry, inode);
2534 BUG_ON(!d_unhashed(actual));
2536 spin_lock(&actual->
d_lock);
2539 spin_unlock(&actual->
d_lock);
2540 spin_unlock(&inode->
i_lock);
2542 if (actual == dentry) {
2558 memcpy(*buffer, str, namelen);
2562 static int prepend_name(
char **buffer,
int *buflen,
struct qstr *name)
2564 return prepend(buffer, buflen, name->
name, name->len);
2576 static int prepend_path(
const struct path *
path,
2577 const struct path *root,
2578 char **buffer,
int *buflen)
2580 struct dentry *dentry = path->
dentry;
2582 struct mount *
mnt = real_mount(vfsmnt);
2587 while (dentry != root->
dentry || vfsmnt != root->
mnt) {
2588 struct dentry * parent;
2592 if (!mnt_has_parent(mnt))
2601 spin_lock(&dentry->
d_lock);
2602 error = prepend_name(buffer, buflen, &dentry->
d_name);
2603 spin_unlock(&dentry->
d_lock);
2605 error = prepend(buffer, buflen,
"/", 1);
2613 if (!error && !slash)
2614 error = prepend(buffer, buflen,
"/", 1);
2626 (dentry->
d_name.len != 1 || dentry->
d_name.name[0] !=
'/')) {
2627 WARN(1,
"Root dentry has weird name <%.*s>\n",
2631 error = prepend(buffer, buflen,
"/", 1);
2633 error = is_mounted(vfsmnt) ? 1 : 2;
2654 const struct path *root,
2655 char *
buf,
int buflen)
2660 prepend(&res, &buflen,
"\0", 1);
2662 error = prepend_path(path, root, &res, &buflen);
2666 return ERR_PTR(error);
2673 char *
buf,
int buflen)
2675 struct path root = {};
2679 prepend(&res, &buflen,
"\0", 1);
2681 error = prepend_path(path, &root, &res, &buflen);
2687 return ERR_PTR(error);
2694 static int path_with_deleted(
const struct path *path,
2695 const struct path *root,
2696 char **
buf,
int *buflen)
2698 prepend(buf, buflen,
"\0", 1);
2699 if (d_unlinked(path->
dentry)) {
2700 int error = prepend(buf, buflen,
" (deleted)", 10);
2705 return prepend_path(path, root, buf, buflen);
2708 static int prepend_unreachable(
char **buffer,
int *buflen)
2710 return prepend(buffer, buflen,
"(unreachable)", 13);
2729 char *
d_path(
const struct path *path,
char *buf,
int buflen)
2743 return path->
dentry->d_op->d_dname(path->
dentry, buf, buflen);
2745 get_fs_root(
current->fs, &root);
2747 error = path_with_deleted(path, &root, &res, &buflen);
2749 res = ERR_PTR(error);
2772 return path->
dentry->d_op->d_dname(path->
dentry, buf, buflen);
2774 get_fs_root(
current->fs, &root);
2776 error = path_with_deleted(path, &root, &res, &buflen);
2778 error = prepend_unreachable(&res, &buflen);
2782 res = ERR_PTR(error);
2791 const char *
fmt, ...)
2798 sz =
vsnprintf(temp,
sizeof(temp), fmt, args) + 1;
2801 if (sz >
sizeof(temp) || sz > buflen)
2804 buffer += buflen - sz;
2805 return memcpy(buffer, temp, sz);
2811 static char *__dentry_path(
struct dentry *dentry,
char *buf,
int buflen)
2816 prepend(&end, &buflen,
"\0", 1);
2824 struct dentry *parent = dentry->
d_parent;
2828 spin_lock(&dentry->
d_lock);
2829 error = prepend_name(&end, &buflen, &dentry->
d_name);
2830 spin_unlock(&dentry->
d_lock);
2831 if (error != 0 || prepend(&end, &buflen,
"/", 1) != 0)
2847 retval = __dentry_path(dentry, buf, buflen);
2860 if (d_unlinked(dentry)) {
2862 if (prepend(&p, &buflen,
"//deleted", 10) != 0)
2866 retval = __dentry_path(dentry, buf, buflen);
2868 if (!IS_ERR(retval) && p)
2896 struct path pwd, root;
2902 get_fs_root_and_pwd(
current->fs, &root, &pwd);
2906 if (!d_unlinked(pwd.
dentry)) {
2911 prepend(&cwd, &buflen,
"\0", 1);
2912 error = prepend_path(&pwd, &root, &cwd, &buflen);
2920 error = prepend_unreachable(&cwd, &buflen);
2926 len = PAGE_SIZE + page -
cwd;
2959 int is_subdir(
struct dentry *new_dentry,
struct dentry *old_dentry)
2964 if (new_dentry == old_dentry)
2987 struct dentry *this_parent;
2995 spin_lock(&this_parent->
d_lock);
2999 while (next != &this_parent->
d_subdirs) {
3001 struct dentry *dentry =
list_entry(tmp,
struct dentry,
d_u.d_child);
3005 if (d_unhashed(dentry) || !dentry->
d_inode) {
3006 spin_unlock(&dentry->
d_lock);
3010 spin_unlock(&this_parent->
d_lock);
3012 this_parent = dentry;
3020 spin_unlock(&dentry->
d_lock);
3022 if (this_parent != root) {
3023 struct dentry *child = this_parent;
3028 this_parent = try_to_ascend(this_parent, locked, seq);
3034 spin_unlock(&this_parent->
d_lock);
3065 struct dentry * dentry;
3078 static __initdata unsigned long dhash_entries;
3079 static int __init set_dhash_entries(
char *str)
3086 __setup(
"dhash_entries=", set_dhash_entries);
3088 static void __init dcache_init_early(
void)
3109 for (loop = 0; loop < (1
U << d_hash_shift); loop++)
3113 static void __init dcache_init(
void)
3140 for (loop = 0; loop < (1
U << d_hash_shift); loop++)
3152 dcache_init_early();
3163 reserve =
min((mempages - nr_free_pages()) * 3/2, mempages - 1);