Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[patch 2/7] vfs: mountinfo: add seq_file_root()

Add a new function:

seq_file_root()

This is similar to seq_path(), but calculates the path relative to the
given root, instead of current->fs->root. If the path was unreachable
from root, then modify the root parameter to reflect this.

Signed-off-by: Miklos Szeredi <mszeredi@suse.cz>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>

authored by

Miklos Szeredi and committed by
Al Viro
9d1bc601 6092d048

+49 -8
+16 -8
fs/dcache.c
··· 1759 1759 1760 1760 /** 1761 1761 * d_path - return the path of a dentry 1762 - * @dentry: dentry to report 1763 - * @vfsmnt: vfsmnt to which the dentry belongs 1764 - * @root: root dentry 1765 - * @rootmnt: vfsmnt to which the root dentry belongs 1762 + * @path: the dentry/vfsmount to report 1763 + * @root: root vfsmnt/dentry (may be modified by this function) 1766 1764 * @buffer: buffer to return value in 1767 1765 * @buflen: buffer length 1768 1766 * ··· 1770 1772 * Returns the buffer or an error code if the path was too long. 1771 1773 * 1772 1774 * "buflen" should be positive. Caller holds the dcache_lock. 1775 + * 1776 + * If path is not reachable from the supplied root, then the value of 1777 + * root is changed (without modifying refcounts). 1773 1778 */ 1774 - static char *__d_path(struct dentry *dentry, struct vfsmount *vfsmnt, 1775 - struct path *root, char *buffer, int buflen) 1779 + char *__d_path(const struct path *path, struct path *root, 1780 + char *buffer, int buflen) 1776 1781 { 1782 + struct dentry *dentry = path->dentry; 1783 + struct vfsmount *vfsmnt = path->mnt; 1777 1784 char * end = buffer+buflen; 1778 1785 char * retval; 1779 1786 ··· 1827 1824 if (prepend(&retval, &buflen, dentry->d_name.name, 1828 1825 dentry->d_name.len) != 0) 1829 1826 goto Elong; 1827 + root->mnt = vfsmnt; 1828 + root->dentry = dentry; 1830 1829 return retval; 1831 1830 Elong: 1832 1831 return ERR_PTR(-ENAMETOOLONG); ··· 1851 1846 { 1852 1847 char *res; 1853 1848 struct path root; 1849 + struct path tmp; 1854 1850 1855 1851 /* 1856 1852 * We have various synthetic filesystems that never get mounted. On ··· 1868 1862 path_get(&root); 1869 1863 read_unlock(&current->fs->lock); 1870 1864 spin_lock(&dcache_lock); 1871 - res = __d_path(path->dentry, path->mnt, &root, buf, buflen); 1865 + tmp = root; 1866 + res = __d_path(path, &tmp, buf, buflen); 1872 1867 spin_unlock(&dcache_lock); 1873 1868 path_put(&root); 1874 1869 return res; ··· 1977 1970 spin_lock(&dcache_lock); 1978 1971 if (pwd.dentry->d_parent == pwd.dentry || !d_unhashed(pwd.dentry)) { 1979 1972 unsigned long len; 1973 + struct path tmp = root; 1980 1974 char * cwd; 1981 1975 1982 - cwd = __d_path(pwd.dentry, pwd.mnt, &root, page, PAGE_SIZE); 1976 + cwd = __d_path(&pwd, &tmp, page, PAGE_SIZE); 1983 1977 spin_unlock(&dcache_lock); 1984 1978 1985 1979 error = PTR_ERR(cwd);
+30
fs/seq_file.c
··· 393 393 EXPORT_SYMBOL(seq_path); 394 394 395 395 /* 396 + * Same as seq_path, but relative to supplied root. 397 + * 398 + * root may be changed, see __d_path(). 399 + */ 400 + int seq_path_root(struct seq_file *m, struct path *path, struct path *root, 401 + char *esc) 402 + { 403 + int err = -ENAMETOOLONG; 404 + if (m->count < m->size) { 405 + char *s = m->buf + m->count; 406 + char *p; 407 + 408 + spin_lock(&dcache_lock); 409 + p = __d_path(path, root, s, m->size - m->count); 410 + spin_unlock(&dcache_lock); 411 + err = PTR_ERR(p); 412 + if (!IS_ERR(p)) { 413 + s = mangle_path(s, p, esc); 414 + if (s) { 415 + p = m->buf + m->count; 416 + m->count = s - m->buf; 417 + return 0; 418 + } 419 + } 420 + } 421 + m->count = m->size; 422 + return err; 423 + } 424 + 425 + /* 396 426 * returns the path of the 'dentry' from the root of its filesystem. 397 427 */ 398 428 int seq_dentry(struct seq_file *m, struct dentry *dentry, char *esc)
+1
include/linux/dcache.h
··· 301 301 */ 302 302 extern char *dynamic_dname(struct dentry *, char *, int, const char *, ...); 303 303 304 + extern char *__d_path(const struct path *path, struct path *root, char *, int); 304 305 extern char *d_path(struct path *, char *, int); 305 306 extern char *dentry_path(struct dentry *, char *, int); 306 307
+2
include/linux/seq_file.h
··· 46 46 47 47 int seq_path(struct seq_file *, struct path *, char *); 48 48 int seq_dentry(struct seq_file *, struct dentry *, char *); 49 + int seq_path_root(struct seq_file *m, struct path *path, struct path *root, 50 + char *esc); 49 51 50 52 int single_open(struct file *, int (*)(struct seq_file *, void *), void *); 51 53 int single_release(struct inode *, struct file *);