vfs_syscalls.c (bf876fcd34eac7f46d8bea6eeaa7291ab9337b1d) | vfs_syscalls.c (510ea843baf66ae678ca6ddbbbca9816177be5b0) |
---|---|
1/*- 2 * Copyright (c) 1989, 1993 3 * The Regents of the University of California. All rights reserved. 4 * (c) UNIX System Laboratories, Inc. 5 * All or some portions of this file are derived from material licensed 6 * to the University of California by American Telephone and Telegraph 7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 8 * the permission of UNIX System Laboratories, Inc. --- 1046 unchanged lines hidden (view full) --- 1055 struct flock lf; 1056 struct nameidata nd; 1057 int vfslocked; 1058 1059 AUDIT_ARG_FFLAGS(flags); 1060 AUDIT_ARG_MODE(mode); 1061 /* XXX: audit dirfd */ 1062 /* | 1/*- 2 * Copyright (c) 1989, 1993 3 * The Regents of the University of California. All rights reserved. 4 * (c) UNIX System Laboratories, Inc. 5 * All or some portions of this file are derived from material licensed 6 * to the University of California by American Telephone and Telegraph 7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 8 * the permission of UNIX System Laboratories, Inc. --- 1046 unchanged lines hidden (view full) --- 1055 struct flock lf; 1056 struct nameidata nd; 1057 int vfslocked; 1058 1059 AUDIT_ARG_FFLAGS(flags); 1060 AUDIT_ARG_MODE(mode); 1061 /* XXX: audit dirfd */ 1062 /* |
1063 * Only one of the O_EXEC, O_RDONLY, O_WRONLY and O_RDWR may 1064 * be specified. | 1063 * Only one of the O_EXEC, O_RDONLY, O_WRONLY and O_RDWR flags 1064 * may be specified. |
1065 */ 1066 if (flags & O_EXEC) { 1067 if (flags & O_ACCMODE) 1068 return (EINVAL); 1069 } else if ((flags & O_ACCMODE) == O_ACCMODE) 1070 return (EINVAL); 1071 else 1072 flags = FFLAGS(flags); --- 738 unchanged lines hidden (view full) --- 1811 char *path = uap->path; 1812 1813 if (flag & ~AT_REMOVEDIR) 1814 return (EINVAL); 1815 1816 if (flag & AT_REMOVEDIR) 1817 return (kern_rmdirat(td, fd, path, UIO_USERSPACE)); 1818 else | 1065 */ 1066 if (flags & O_EXEC) { 1067 if (flags & O_ACCMODE) 1068 return (EINVAL); 1069 } else if ((flags & O_ACCMODE) == O_ACCMODE) 1070 return (EINVAL); 1071 else 1072 flags = FFLAGS(flags); --- 738 unchanged lines hidden (view full) --- 1811 char *path = uap->path; 1812 1813 if (flag & ~AT_REMOVEDIR) 1814 return (EINVAL); 1815 1816 if (flag & AT_REMOVEDIR) 1817 return (kern_rmdirat(td, fd, path, UIO_USERSPACE)); 1818 else |
1819 return (kern_unlinkat(td, fd, path, UIO_USERSPACE)); | 1819 return (kern_unlinkat(td, fd, path, UIO_USERSPACE, 0)); |
1820} 1821 1822int 1823kern_unlink(struct thread *td, char *path, enum uio_seg pathseg) 1824{ 1825 | 1820} 1821 1822int 1823kern_unlink(struct thread *td, char *path, enum uio_seg pathseg) 1824{ 1825 |
1826 return (kern_unlinkat(td, AT_FDCWD, path, pathseg)); | 1826 return (kern_unlinkat(td, AT_FDCWD, path, pathseg, 0)); |
1827} 1828 1829int | 1827} 1828 1829int |
1830kern_unlinkat(struct thread *td, int fd, char *path, enum uio_seg pathseg) | 1830kern_unlinkat(struct thread *td, int fd, char *path, enum uio_seg pathseg, 1831 ino_t oldinum) |
1831{ 1832 struct mount *mp; 1833 struct vnode *vp; 1834 int error; 1835 struct nameidata nd; | 1832{ 1833 struct mount *mp; 1834 struct vnode *vp; 1835 int error; 1836 struct nameidata nd; |
1837 struct stat sb; |
|
1836 int vfslocked; 1837 1838restart: 1839 bwillwrite(); 1840 NDINIT_AT(&nd, DELETE, LOCKPARENT | LOCKLEAF | MPSAFE | AUDITVNODE1, 1841 pathseg, path, fd, td); 1842 if ((error = namei(&nd)) != 0) 1843 return (error == EINVAL ? EPERM : error); 1844 vfslocked = NDHASGIANT(&nd); 1845 vp = nd.ni_vp; | 1838 int vfslocked; 1839 1840restart: 1841 bwillwrite(); 1842 NDINIT_AT(&nd, DELETE, LOCKPARENT | LOCKLEAF | MPSAFE | AUDITVNODE1, 1843 pathseg, path, fd, td); 1844 if ((error = namei(&nd)) != 0) 1845 return (error == EINVAL ? EPERM : error); 1846 vfslocked = NDHASGIANT(&nd); 1847 vp = nd.ni_vp; |
1846 if (vp->v_type == VDIR) | 1848 if (vp->v_type == VDIR && oldinum == 0) { |
1847 error = EPERM; /* POSIX */ | 1849 error = EPERM; /* POSIX */ |
1848 else { | 1850 } else if (oldinum != 0 && 1851 ((error = vn_stat(vp, &sb, td->td_ucred, NOCRED, td)) == 0) && 1852 sb.st_ino != oldinum) { 1853 error = EIDRM; /* Identifier removed */ 1854 } else { |
1849 /* 1850 * The root of a mounted filesystem cannot be deleted. 1851 * 1852 * XXX: can this only be a VDIR case? 1853 */ 1854 if (vp->v_vflag & VV_ROOT) 1855 error = EBUSY; 1856 } --- 264 unchanged lines hidden (view full) --- 2121 struct ucred *cred, *tmpcred; 2122 struct vnode *vp; 2123 struct nameidata nd; 2124 int vfslocked; 2125 int error; 2126 2127 /* 2128 * Create and modify a temporary credential instead of one that | 1855 /* 1856 * The root of a mounted filesystem cannot be deleted. 1857 * 1858 * XXX: can this only be a VDIR case? 1859 */ 1860 if (vp->v_vflag & VV_ROOT) 1861 error = EBUSY; 1862 } --- 264 unchanged lines hidden (view full) --- 2127 struct ucred *cred, *tmpcred; 2128 struct vnode *vp; 2129 struct nameidata nd; 2130 int vfslocked; 2131 int error; 2132 2133 /* 2134 * Create and modify a temporary credential instead of one that |
2129 * is potentially shared. This could also mess up socket 2130 * buffer accounting which can run in an interrupt context. | 2135 * is potentially shared. |
2131 */ 2132 if (!(flags & AT_EACCESS)) { 2133 cred = td->td_ucred; 2134 tmpcred = crdup(cred); 2135 tmpcred->cr_uid = cred->cr_ruid; 2136 tmpcred->cr_groups[0] = cred->cr_rgid; 2137 td->td_ucred = tmpcred; 2138 } else --- 120 unchanged lines hidden (view full) --- 2259 ost->st_nlink = st->st_nlink; 2260 ost->st_uid = st->st_uid; 2261 ost->st_gid = st->st_gid; 2262 ost->st_rdev = st->st_rdev; 2263 if (st->st_size < (quad_t)1 << 32) 2264 ost->st_size = st->st_size; 2265 else 2266 ost->st_size = -2; | 2136 */ 2137 if (!(flags & AT_EACCESS)) { 2138 cred = td->td_ucred; 2139 tmpcred = crdup(cred); 2140 tmpcred->cr_uid = cred->cr_ruid; 2141 tmpcred->cr_groups[0] = cred->cr_rgid; 2142 td->td_ucred = tmpcred; 2143 } else --- 120 unchanged lines hidden (view full) --- 2264 ost->st_nlink = st->st_nlink; 2265 ost->st_uid = st->st_uid; 2266 ost->st_gid = st->st_gid; 2267 ost->st_rdev = st->st_rdev; 2268 if (st->st_size < (quad_t)1 << 32) 2269 ost->st_size = st->st_size; 2270 else 2271 ost->st_size = -2; |
2267 ost->st_atime = st->st_atime; 2268 ost->st_mtime = st->st_mtime; 2269 ost->st_ctime = st->st_ctime; | 2272 ost->st_atim = st->st_atim; 2273 ost->st_mtim = st->st_mtim; 2274 ost->st_ctim = st->st_ctim; |
2270 ost->st_blksize = st->st_blksize; 2271 ost->st_blocks = st->st_blocks; 2272 ost->st_flags = st->st_flags; 2273 ost->st_gen = st->st_gen; 2274} 2275#endif /* COMPAT_43 */ 2276 2277/* --- 143 unchanged lines hidden (view full) --- 2421 bzero(nsb, sizeof *nsb); 2422 nsb->st_dev = sb->st_dev; 2423 nsb->st_ino = sb->st_ino; 2424 nsb->st_mode = sb->st_mode; 2425 nsb->st_nlink = sb->st_nlink; 2426 nsb->st_uid = sb->st_uid; 2427 nsb->st_gid = sb->st_gid; 2428 nsb->st_rdev = sb->st_rdev; | 2275 ost->st_blksize = st->st_blksize; 2276 ost->st_blocks = st->st_blocks; 2277 ost->st_flags = st->st_flags; 2278 ost->st_gen = st->st_gen; 2279} 2280#endif /* COMPAT_43 */ 2281 2282/* --- 143 unchanged lines hidden (view full) --- 2426 bzero(nsb, sizeof *nsb); 2427 nsb->st_dev = sb->st_dev; 2428 nsb->st_ino = sb->st_ino; 2429 nsb->st_mode = sb->st_mode; 2430 nsb->st_nlink = sb->st_nlink; 2431 nsb->st_uid = sb->st_uid; 2432 nsb->st_gid = sb->st_gid; 2433 nsb->st_rdev = sb->st_rdev; |
2429 nsb->st_atimespec = sb->st_atimespec; 2430 nsb->st_mtimespec = sb->st_mtimespec; 2431 nsb->st_ctimespec = sb->st_ctimespec; | 2434 nsb->st_atim = sb->st_atim; 2435 nsb->st_mtim = sb->st_mtim; 2436 nsb->st_ctim = sb->st_ctim; |
2432 nsb->st_size = sb->st_size; 2433 nsb->st_blocks = sb->st_blocks; 2434 nsb->st_blksize = sb->st_blksize; 2435 nsb->st_flags = sb->st_flags; 2436 nsb->st_gen = sb->st_gen; | 2437 nsb->st_size = sb->st_size; 2438 nsb->st_blocks = sb->st_blocks; 2439 nsb->st_blksize = sb->st_blksize; 2440 nsb->st_flags = sb->st_flags; 2441 nsb->st_gen = sb->st_gen; |
2437 nsb->st_birthtimespec = sb->st_birthtimespec; | 2442 nsb->st_birthtim = sb->st_birthtim; |
2438} 2439 2440#ifndef _SYS_SYSPROTO_H_ 2441struct nstat_args { 2442 char *path; 2443 struct nstat *ub; 2444}; 2445#endif --- 1972 unchanged lines hidden (view full) --- 4418 if (vp->v_type == VLNK) { 4419 error = EMLINK; 4420 goto bad; 4421 } 4422 if (vp->v_type == VSOCK) { 4423 error = EOPNOTSUPP; 4424 goto bad; 4425 } | 2443} 2444 2445#ifndef _SYS_SYSPROTO_H_ 2446struct nstat_args { 2447 char *path; 2448 struct nstat *ub; 2449}; 2450#endif --- 1972 unchanged lines hidden (view full) --- 4423 if (vp->v_type == VLNK) { 4424 error = EMLINK; 4425 goto bad; 4426 } 4427 if (vp->v_type == VSOCK) { 4428 error = EOPNOTSUPP; 4429 goto bad; 4430 } |
4431 if (vp->v_type != VDIR && fmode & O_DIRECTORY) { 4432 error = ENOTDIR; 4433 goto bad; 4434 } |
|
4426 accmode = 0; 4427 if (fmode & (FWRITE | O_TRUNC)) { 4428 if (vp->v_type == VDIR) { 4429 error = EISDIR; 4430 goto bad; 4431 } 4432 error = vn_writechk(vp); 4433 if (error) --- 232 unchanged lines hidden --- | 4435 accmode = 0; 4436 if (fmode & (FWRITE | O_TRUNC)) { 4437 if (vp->v_type == VDIR) { 4438 error = EISDIR; 4439 goto bad; 4440 } 4441 error = vn_writechk(vp); 4442 if (error) --- 232 unchanged lines hidden --- |