drm/radeon/kms: enable use of unmappable VRAM V2
[pandora-kernel.git] / drivers / staging / pohmelfs / path_entry.c
1 /*
2  * 2007+ Copyright (c) Evgeniy Polyakov <zbr@ioremap.net>
3  * All rights reserved.
4  *
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.
9  *
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.
14  */
15
16 #include <linux/module.h>
17 #include <linux/slab.h>
18 #include <linux/fs.h>
19 #include <linux/ktime.h>
20 #include <linux/fs_struct.h>
21 #include <linux/pagemap.h>
22 #include <linux/writeback.h>
23 #include <linux/mount.h>
24 #include <linux/mm.h>
25
26 #include "netfs.h"
27
28 #define UNHASHED_OBSCURE_STRING_SIZE            sizeof(" (deleted)")
29
30 /*
31  * Create path from root for given inode.
32  * Path is formed as set of stuctures, containing name of the object
33  * and its inode data (mode, permissions and so on).
34  */
35 int pohmelfs_construct_path_string(struct pohmelfs_inode *pi, void *data, int len)
36 {
37         struct path path;
38         struct dentry *d;
39         char *ptr;
40         int err = 0, strlen, reduce = 0;
41
42         d = d_find_alias(&pi->vfs_inode);
43         if (!d) {
44                 printk("%s: no alias, list_empty: %d.\n", __func__, list_empty(&pi->vfs_inode.i_dentry));
45                 return -ENOENT;
46         }
47
48         read_lock(&current->fs->lock);
49         path.mnt = mntget(current->fs->root.mnt);
50         read_unlock(&current->fs->lock);
51
52         path.dentry = d;
53
54         if (!IS_ROOT(d) && d_unhashed(d))
55                 reduce = 1;
56
57         ptr = d_path(&path, data, len);
58         if (IS_ERR(ptr)) {
59                 err = PTR_ERR(ptr);
60                 goto out;
61         }
62
63         if (reduce && len >= UNHASHED_OBSCURE_STRING_SIZE) {
64                 char *end = data + len - UNHASHED_OBSCURE_STRING_SIZE;
65                 *end = '\0';
66         }
67
68         strlen = len - (ptr - (char *)data);
69         memmove(data, ptr, strlen);
70         ptr = data;
71
72         err = strlen;
73
74         dprintk("%s: dname: '%s', len: %u, maxlen: %u, name: '%s', strlen: %d.\n",
75                         __func__, d->d_name.name, d->d_name.len, len, ptr, strlen);
76
77 out:
78         dput(d);
79         mntput(path.mnt);
80
81         return err;
82 }
83
84 int pohmelfs_path_length(struct pohmelfs_inode *pi)
85 {
86         struct dentry *d, *root, *first;
87         int len = 1; /* Root slash */
88
89         first = d = d_find_alias(&pi->vfs_inode);
90         if (!d) {
91                 dprintk("%s: ino: %llu, mode: %o.\n", __func__, pi->ino, pi->vfs_inode.i_mode);
92                 return -ENOENT;
93         }
94
95         read_lock(&current->fs->lock);
96         root = dget(current->fs->root.dentry);
97         read_unlock(&current->fs->lock);
98
99         spin_lock(&dcache_lock);
100
101         if (!IS_ROOT(d) && d_unhashed(d))
102                 len += UNHASHED_OBSCURE_STRING_SIZE; /* Obscure " (deleted)" string */
103
104         while (d && d != root && !IS_ROOT(d)) {
105                 len += d->d_name.len + 1; /* Plus slash */
106                 d = d->d_parent;
107         }
108         spin_unlock(&dcache_lock);
109
110         dput(root);
111         dput(first);
112
113         return len + 1; /* Including zero-byte */
114 }