Introduce falloc_caps() to create descriptors with capabilties in place.

falloc_noinstall() followed by finstall() allows you to create and
install file descriptors with custom capabilities. Add falloc_caps()
that can do both of these actions in one go.

This will be used by CloudABI to create pipes with custom capabilities.

Reviewed by:	mjg
This commit is contained in:
Ed Schouten 2015-07-29 17:16:53 +00:00
parent 8843746ab4
commit e555b4309c
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=286020
2 changed files with 9 additions and 4 deletions

View File

@ -1707,7 +1707,8 @@ fdallocn(struct thread *td, int minfd, int *fds, int n)
* release the FILEDESC lock.
*/
int
falloc(struct thread *td, struct file **resultfp, int *resultfd, int flags)
falloc_caps(struct thread *td, struct file **resultfp, int *resultfd, int flags,
struct filecaps *fcaps)
{
struct file *fp;
int error, fd;
@ -1716,7 +1717,7 @@ falloc(struct thread *td, struct file **resultfp, int *resultfd, int flags)
if (error)
return (error); /* no reference held on error */
error = finstall(td, fp, &fd, flags, NULL);
error = finstall(td, fp, &fd, flags, fcaps);
if (error) {
fdrop(fp, td); /* one reference (fp only) */
return (error);

View File

@ -146,6 +146,10 @@ enum {
/* Flags for kern_dup(). */
#define FDDUP_FLAG_CLOEXEC 0x1 /* Atomically set UF_EXCLOSE. */
/* For backward compatibility. */
#define falloc(td, resultfp, resultfd, flags) \
falloc_caps(td, resultfp, resultfd, flags, NULL)
struct thread;
void filecaps_init(struct filecaps *fcaps);
@ -156,8 +160,8 @@ void filecaps_free(struct filecaps *fcaps);
int closef(struct file *fp, struct thread *td);
int dupfdopen(struct thread *td, struct filedesc *fdp, int dfd, int mode,
int openerror, int *indxp);
int falloc(struct thread *td, struct file **resultfp, int *resultfd,
int flags);
int falloc_caps(struct thread *td, struct file **resultfp, int *resultfd,
int flags, struct filecaps *fcaps);
int falloc_noinstall(struct thread *td, struct file **resultfp);
void _finstall(struct filedesc *fdp, struct file *fp, int fd, int flags,
struct filecaps *fcaps);