Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F140981854
D43529.id133104.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
4 KB
Referenced Files
None
Subscribers
None
D43529.id133104.diff
View Options
diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c
--- a/sys/kern/vfs_syscalls.c
+++ b/sys/kern/vfs_syscalls.c
@@ -1110,20 +1110,27 @@
uap->mode));
}
-int
-kern_openat(struct thread *td, int fd, const char *path, enum uio_seg pathseg,
- int flags, int mode)
+/*
+ * If fpp != NULL, opened file is not installed into the file
+ * descriptors table, instead it is returned in *fpp. This is
+ * incompatible with fdopen(), in which case we return EINVAL.
+ */
+static int
+openatfp(struct thread *td, int dirfd, const char *path,
+ enum uio_seg pathseg, int flags, int mode, struct file **fpp)
{
- struct proc *p = td->td_proc;
+ struct proc *p;
struct filedesc *fdp;
struct pwddesc *pdp;
struct file *fp;
struct vnode *vp;
+ struct filecaps *fcaps;
struct nameidata nd;
cap_rights_t rights;
int cmode, error, indx;
indx = -1;
+ p = td->td_proc;
fdp = p->p_fd;
pdp = p->p_pd;
@@ -1159,7 +1166,7 @@
fp->f_flag = flags & FMASK;
cmode = ((mode & ~pdp->pd_cmask) & ALLPERMS) & ~S_ISTXT;
NDINIT_ATRIGHTS(&nd, LOOKUP, FOLLOW | AUDITVNODE1 | WANTIOCTLCAPS,
- pathseg, path, fd, &rights);
+ pathseg, path, dirfd, &rights);
td->td_dupfd = -1; /* XXX check for fdopen */
error = vn_open_cred(&nd, &flags, cmode, VN_OPEN_WANTIOCTLCAPS,
td->td_ucred, fp);
@@ -1184,6 +1191,7 @@
if ((nd.ni_resflags & NIRES_STRICTREL) == 0 &&
(error == ENODEV || error == ENXIO) &&
td->td_dupfd >= 0) {
+ MPASS(fpp == NULL);
error = dupfdopen(td, fdp, td->td_dupfd, flags, error,
&indx);
if (error == 0)
@@ -1225,29 +1233,32 @@
goto bad;
}
success:
- /*
- * If we haven't already installed the FD (for dupfdopen), do so now.
- */
- if (indx == -1) {
- struct filecaps *fcaps;
-
+ if (fpp != NULL) {
+ NDFREE_IOCTLCAPS(&nd);
+ } else {
+ /*
+ * If we haven't already installed the FD (for
+ * dupfdopen), do so now.
+ */
+ if (indx == -1) {
#ifdef CAPABILITIES
- if ((nd.ni_resflags & NIRES_STRICTREL) != 0)
- fcaps = &nd.ni_filecaps;
- else
+ if ((nd.ni_resflags & NIRES_STRICTREL) != 0)
+ fcaps = &nd.ni_filecaps;
+ else
#endif
- fcaps = NULL;
- error = finstall_refed(td, fp, &indx, flags, fcaps);
- /* On success finstall_refed() consumes fcaps. */
- if (error != 0) {
- goto bad;
+ fcaps = NULL;
+ error = finstall_refed(td, fp, &indx, flags, fcaps);
+ /* On success finstall_refed() consumes fcaps. */
+ if (error != 0) {
+ goto bad;
+ }
+ } else {
+ NDFREE_IOCTLCAPS(&nd);
+ falloc_abort(td, fp);
}
- } else {
- NDFREE_IOCTLCAPS(&nd);
- falloc_abort(td, fp);
+ td->td_retval[0] = indx;
}
- td->td_retval[0] = indx;
return (0);
bad:
KASSERT(indx == -1, ("indx=%d, should be -1", indx));
@@ -1256,6 +1267,26 @@
return (error);
}
+int
+kern_openat(struct thread *td, int dirfd, const char *path,
+ enum uio_seg pathseg, int flags, int mode)
+{
+ return (openatfp(td, dirfd, path, pathseg, flags, mode, NULL));
+}
+
+int
+kern_openatfp(struct thread *td, int dirfd, const char *path,
+ enum uio_seg pathseg, int flags, int mode, struct file **fpp)
+{
+ int error, old_dupfd;
+
+ old_dupfd = td->td_dupfd;
+ td->td_dupfd = -1;
+ error = openatfp(td, dirfd, path, pathseg, flags, mode, fpp);
+ td->td_dupfd = old_dupfd;
+ return (error);
+}
+
#ifdef COMPAT_43
/*
* Create a file.
diff --git a/sys/sys/syscallsubr.h b/sys/sys/syscallsubr.h
--- a/sys/sys/syscallsubr.h
+++ b/sys/sys/syscallsubr.h
@@ -249,8 +249,10 @@
long *ploff);
int kern_ommap(struct thread *td, uintptr_t hint, int len, int oprot,
int oflags, int fd, long pos);
-int kern_openat(struct thread *td, int fd, const char *path,
+int kern_openat(struct thread *td, int dirfd, const char *path,
enum uio_seg pathseg, int flags, int mode);
+int kern_openatfp(struct thread *td, int dirfd, const char *path,
+ enum uio_seg pathseg, int flags, int mode, struct file **fpp);
int kern_pathconf(struct thread *td, const char *path,
enum uio_seg pathseg, int name, u_long flags, long *valuep);
int kern_pipe(struct thread *td, int fildes[2], int flags,
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Dec 31, 9:37 AM (4 h, 38 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
27407862
Default Alt Text
D43529.id133104.diff (4 KB)
Attached To
Mode
D43529: Add kern_openatfp(9)
Attached
Detach File
Event Timeline
Log In to Comment