diff options
author | Al Viro <viro@zeniv.linux.org.uk> | 2009-12-26 10:56:19 -0500 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2010-03-05 09:22:25 -0500 |
commit | 1f36f774b22a0ceb7dd33eca626746c81a97b6a5 (patch) | |
tree | cfc2757bb3e21d484ce28bd3030e649b5767b5a1 /fs/namei.c | |
parent | def4af30cf945a3735ffca865788ea84b30b25d9 (diff) |
Switch !O_CREAT case to use of do_last()
... and now we have all intents crap well localized
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs/namei.c')
-rw-r--r-- | fs/namei.c | 127 |
1 files changed, 66 insertions, 61 deletions
diff --git a/fs/namei.c b/fs/namei.c index 1f5d86d1fbf5..9a6456099f1e 100644 --- a/fs/namei.c +++ b/fs/namei.c | |||
@@ -1359,22 +1359,6 @@ static inline int may_create(struct inode *dir, struct dentry *child) | |||
1359 | return inode_permission(dir, MAY_WRITE | MAY_EXEC); | 1359 | return inode_permission(dir, MAY_WRITE | MAY_EXEC); |
1360 | } | 1360 | } |
1361 | 1361 | ||
1362 | /* | ||
1363 | * O_DIRECTORY translates into forcing a directory lookup. | ||
1364 | */ | ||
1365 | static inline int lookup_flags(unsigned int f) | ||
1366 | { | ||
1367 | unsigned long retval = LOOKUP_FOLLOW; | ||
1368 | |||
1369 | if (f & O_NOFOLLOW) | ||
1370 | retval &= ~LOOKUP_FOLLOW; | ||
1371 | |||
1372 | if (f & O_DIRECTORY) | ||
1373 | retval |= LOOKUP_DIRECTORY; | ||
1374 | |||
1375 | return retval; | ||
1376 | } | ||
1377 | |||
1378 | /* | 1362 | /* |
1379 | * p1 and p2 should be directories on the same fs. | 1363 | * p1 and p2 should be directories on the same fs. |
1380 | */ | 1364 | */ |
@@ -1631,19 +1615,60 @@ exit: | |||
1631 | 1615 | ||
1632 | static struct file *do_last(struct nameidata *nd, struct path *path, | 1616 | static struct file *do_last(struct nameidata *nd, struct path *path, |
1633 | int open_flag, int acc_mode, | 1617 | int open_flag, int acc_mode, |
1634 | int mode, const char *pathname) | 1618 | int mode, const char *pathname, |
1619 | int *want_dir) | ||
1635 | { | 1620 | { |
1636 | struct dentry *dir = nd->path.dentry; | 1621 | struct dentry *dir = nd->path.dentry; |
1637 | struct file *filp; | 1622 | struct file *filp; |
1638 | int error; | 1623 | int error = -EISDIR; |
1639 | 1624 | ||
1640 | if (nd->last_type == LAST_BIND) | 1625 | switch (nd->last_type) { |
1626 | case LAST_DOTDOT: | ||
1627 | follow_dotdot(nd); | ||
1628 | dir = nd->path.dentry; | ||
1629 | if (nd->path.mnt->mnt_sb->s_type->fs_flags & FS_REVAL_DOT) { | ||
1630 | if (!dir->d_op->d_revalidate(dir, nd)) { | ||
1631 | error = -ESTALE; | ||
1632 | goto exit; | ||
1633 | } | ||
1634 | } | ||
1635 | /* fallthrough */ | ||
1636 | case LAST_DOT: | ||
1637 | case LAST_ROOT: | ||
1638 | if (open_flag & O_CREAT) | ||
1639 | goto exit; | ||
1640 | /* fallthrough */ | ||
1641 | case LAST_BIND: | ||
1642 | audit_inode(pathname, dir); | ||
1641 | goto ok; | 1643 | goto ok; |
1644 | } | ||
1642 | 1645 | ||
1643 | error = -EISDIR; | 1646 | /* trailing slashes? */ |
1644 | if (nd->last_type != LAST_NORM || nd->last.name[nd->last.len]) | 1647 | if (nd->last.name[nd->last.len]) { |
1645 | goto exit; | 1648 | if (open_flag & O_CREAT) |
1649 | goto exit; | ||
1650 | *want_dir = 1; | ||
1651 | } | ||
1646 | 1652 | ||
1653 | /* just plain open? */ | ||
1654 | if (!(open_flag & O_CREAT)) { | ||
1655 | error = do_lookup(nd, &nd->last, path); | ||
1656 | if (error) | ||
1657 | goto exit; | ||
1658 | error = -ENOENT; | ||
1659 | if (!path->dentry->d_inode) | ||
1660 | goto exit_dput; | ||
1661 | if (path->dentry->d_inode->i_op->follow_link) | ||
1662 | return NULL; | ||
1663 | error = -ENOTDIR; | ||
1664 | if (*want_dir & !path->dentry->d_inode->i_op->lookup) | ||
1665 | goto exit_dput; | ||
1666 | path_to_nameidata(path, nd); | ||
1667 | audit_inode(pathname, nd->path.dentry); | ||
1668 | goto ok; | ||
1669 | } | ||
1670 | |||
1671 | /* OK, it's O_CREAT */ | ||
1647 | mutex_lock(&dir->d_inode->i_mutex); | 1672 | mutex_lock(&dir->d_inode->i_mutex); |
1648 | 1673 | ||
1649 | path->dentry = lookup_hash(nd); | 1674 | path->dentry = lookup_hash(nd); |
@@ -1746,6 +1771,10 @@ struct file *do_filp_open(int dfd, const char *pathname, | |||
1746 | int count = 0; | 1771 | int count = 0; |
1747 | int flag = open_to_namei_flags(open_flag); | 1772 | int flag = open_to_namei_flags(open_flag); |
1748 | int force_reval = 0; | 1773 | int force_reval = 0; |
1774 | int want_dir = open_flag & O_DIRECTORY; | ||
1775 | |||
1776 | if (!(open_flag & O_CREAT)) | ||
1777 | mode = 0; | ||
1749 | 1778 | ||
1750 | /* | 1779 | /* |
1751 | * O_SYNC is implemented as __O_SYNC|O_DSYNC. As many places only | 1780 | * O_SYNC is implemented as __O_SYNC|O_DSYNC. As many places only |
@@ -1768,35 +1797,7 @@ struct file *do_filp_open(int dfd, const char *pathname, | |||
1768 | if (open_flag & O_APPEND) | 1797 | if (open_flag & O_APPEND) |
1769 | acc_mode |= MAY_APPEND; | 1798 | acc_mode |= MAY_APPEND; |
1770 | 1799 | ||
1771 | /* | 1800 | /* find the parent */ |
1772 | * The simplest case - just a plain lookup. | ||
1773 | */ | ||
1774 | if (!(open_flag & O_CREAT)) { | ||
1775 | filp = get_empty_filp(); | ||
1776 | |||
1777 | if (filp == NULL) | ||
1778 | return ERR_PTR(-ENFILE); | ||
1779 | nd.intent.open.file = filp; | ||
1780 | filp->f_flags = open_flag; | ||
1781 | nd.intent.open.flags = flag; | ||
1782 | nd.intent.open.create_mode = 0; | ||
1783 | error = do_path_lookup(dfd, pathname, | ||
1784 | lookup_flags(open_flag)|LOOKUP_OPEN, &nd); | ||
1785 | if (IS_ERR(nd.intent.open.file)) { | ||
1786 | if (error == 0) { | ||
1787 | error = PTR_ERR(nd.intent.open.file); | ||
1788 | path_put(&nd.path); | ||
1789 | } | ||
1790 | } else if (error) | ||
1791 | release_open_intent(&nd); | ||
1792 | if (error) | ||
1793 | return ERR_PTR(error); | ||
1794 | return finish_open(&nd, open_flag, acc_mode); | ||
1795 | } | ||
1796 | |||
1797 | /* | ||
1798 | * Create - we need to know the parent. | ||
1799 | */ | ||
1800 | reval: | 1801 | reval: |
1801 | error = path_init(dfd, pathname, LOOKUP_PARENT, &nd); | 1802 | error = path_init(dfd, pathname, LOOKUP_PARENT, &nd); |
1802 | if (error) | 1803 | if (error) |
@@ -1810,7 +1811,7 @@ reval: | |||
1810 | filp = ERR_PTR(error); | 1811 | filp = ERR_PTR(error); |
1811 | goto out; | 1812 | goto out; |
1812 | } | 1813 | } |
1813 | if (unlikely(!audit_dummy_context())) | 1814 | if (unlikely(!audit_dummy_context()) && (open_flag & O_CREAT)) |
1814 | audit_inode(pathname, nd.path.dentry); | 1815 | audit_inode(pathname, nd.path.dentry); |
1815 | 1816 | ||
1816 | /* | 1817 | /* |
@@ -1826,16 +1827,22 @@ reval: | |||
1826 | nd.intent.open.flags = flag; | 1827 | nd.intent.open.flags = flag; |
1827 | nd.intent.open.create_mode = mode; | 1828 | nd.intent.open.create_mode = mode; |
1828 | nd.flags &= ~LOOKUP_PARENT; | 1829 | nd.flags &= ~LOOKUP_PARENT; |
1829 | nd.flags |= LOOKUP_CREATE | LOOKUP_OPEN; | 1830 | nd.flags |= LOOKUP_OPEN; |
1830 | if (open_flag & O_EXCL) | 1831 | if (open_flag & O_CREAT) { |
1831 | nd.flags |= LOOKUP_EXCL; | 1832 | nd.flags |= LOOKUP_CREATE; |
1832 | filp = do_last(&nd, &path, open_flag, acc_mode, mode, pathname); | 1833 | if (open_flag & O_EXCL) |
1834 | nd.flags |= LOOKUP_EXCL; | ||
1835 | } | ||
1836 | filp = do_last(&nd, &path, open_flag, acc_mode, mode, pathname, &want_dir); | ||
1833 | while (unlikely(!filp)) { /* trailing symlink */ | 1837 | while (unlikely(!filp)) { /* trailing symlink */ |
1834 | struct path holder; | 1838 | struct path holder; |
1835 | struct inode *inode; | 1839 | struct inode *inode = path.dentry->d_inode; |
1836 | void *cookie; | 1840 | void *cookie; |
1837 | error = -ELOOP; | 1841 | error = -ELOOP; |
1838 | if ((open_flag & O_NOFOLLOW) || count++ == 32) | 1842 | /* S_ISDIR part is a temporary automount kludge */ |
1843 | if ((open_flag & O_NOFOLLOW) && !S_ISDIR(inode->i_mode)) | ||
1844 | goto exit_dput; | ||
1845 | if (count++ == 32) | ||
1839 | goto exit_dput; | 1846 | goto exit_dput; |
1840 | /* | 1847 | /* |
1841 | * This is subtle. Instead of calling do_follow_link() we do | 1848 | * This is subtle. Instead of calling do_follow_link() we do |
@@ -1855,7 +1862,6 @@ reval: | |||
1855 | error = __do_follow_link(&path, &nd, &cookie); | 1862 | error = __do_follow_link(&path, &nd, &cookie); |
1856 | if (unlikely(error)) { | 1863 | if (unlikely(error)) { |
1857 | /* nd.path had been dropped */ | 1864 | /* nd.path had been dropped */ |
1858 | inode = path.dentry->d_inode; | ||
1859 | if (!IS_ERR(cookie) && inode->i_op->put_link) | 1865 | if (!IS_ERR(cookie) && inode->i_op->put_link) |
1860 | inode->i_op->put_link(path.dentry, &nd, cookie); | 1866 | inode->i_op->put_link(path.dentry, &nd, cookie); |
1861 | path_put(&path); | 1867 | path_put(&path); |
@@ -1865,8 +1871,7 @@ reval: | |||
1865 | } | 1871 | } |
1866 | holder = path; | 1872 | holder = path; |
1867 | nd.flags &= ~LOOKUP_PARENT; | 1873 | nd.flags &= ~LOOKUP_PARENT; |
1868 | filp = do_last(&nd, &path, open_flag, acc_mode, mode, pathname); | 1874 | filp = do_last(&nd, &path, open_flag, acc_mode, mode, pathname, &want_dir); |
1869 | inode = holder.dentry->d_inode; | ||
1870 | if (inode->i_op->put_link) | 1875 | if (inode->i_op->put_link) |
1871 | inode->i_op->put_link(holder.dentry, &nd, cookie); | 1876 | inode->i_op->put_link(holder.dentry, &nd, cookie); |
1872 | path_put(&holder); | 1877 | path_put(&holder); |