Ejemplo n.º 1
0
int
cloudabi_sys_fd_stat_get(struct thread *td,
    struct cloudabi_sys_fd_stat_get_args *uap)
{
	cloudabi_fdstat_t fsb = {};
	struct file *fp;
	cap_rights_t rights;
	struct filecaps fcaps;
	int error, oflags;

	/* Obtain file descriptor properties. */
	error = fget_cap(td, uap->fd, cap_rights_init(&rights), &fp,
	    &fcaps);
	if (error != 0)
		return (error);
	oflags = OFLAGS(fp->f_flag);
	fsb.fs_filetype = cloudabi_convert_filetype(fp);
	fdrop(fp, td);

	/* Convert file descriptor flags. */
	if (oflags & O_APPEND)
		fsb.fs_flags |= CLOUDABI_FDFLAG_APPEND;
	if (oflags & O_NONBLOCK)
		fsb.fs_flags |= CLOUDABI_FDFLAG_NONBLOCK;
	if (oflags & O_SYNC)
		fsb.fs_flags |= CLOUDABI_FDFLAG_SYNC;

	/* Convert capabilities to CloudABI rights. */
	convert_capabilities(&fcaps.fc_rights, fsb.fs_filetype,
	    &fsb.fs_rights_base, &fsb.fs_rights_inheriting);
	filecaps_free(&fcaps);
	return (copyout(&fsb, (void *)uap->buf, sizeof(fsb)));
}
Ejemplo n.º 2
0
int
cloudabi_sys_fd_stat_get(struct thread *td,
    struct cloudabi_sys_fd_stat_get_args *uap)
{
	cloudabi_fdstat_t fsb = {};
	struct filedesc *fdp;
	struct file *fp;
	seq_t seq;
	cap_rights_t rights;
	int error, oflags;
	bool modified;

	/* Obtain file descriptor properties. */
	fdp = td->td_proc->p_fd;
	do {
		error = fget_unlocked(fdp, uap->fd, cap_rights_init(&rights),
		    &fp, &seq);
		if (error != 0)
			return (error);
		if (fp->f_ops == &badfileops) {
			fdrop(fp, td);
			return (EBADF);
		}

		rights = *cap_rights(fdp, uap->fd);
		oflags = OFLAGS(fp->f_flag);
		fsb.fs_filetype = cloudabi_convert_filetype(fp);

		modified = fd_modified(fdp, uap->fd, seq);
		fdrop(fp, td);
	} while (modified);

	/* Convert file descriptor flags. */
	if (oflags & O_APPEND)
		fsb.fs_flags |= CLOUDABI_FDFLAG_APPEND;
	if (oflags & O_NONBLOCK)
		fsb.fs_flags |= CLOUDABI_FDFLAG_NONBLOCK;
	if (oflags & O_SYNC)
		fsb.fs_flags |= CLOUDABI_FDFLAG_SYNC;

	/* Convert capabilities to CloudABI rights. */
	convert_capabilities(&rights, fsb.fs_filetype,
	    &fsb.fs_rights_base, &fsb.fs_rights_inheriting);
	return (copyout(&fsb, (void *)uap->buf, sizeof(fsb)));
}