Skip to content

Commit

Permalink
Fix various issues with invalid file operations:
Browse files Browse the repository at this point in the history
- Add invfo_rdwr() (for read and write), invfo_ioctl(), invfo_poll(),
  and invfo_kqfilter() for use by file types that do not support the
  respective operations.  Home-grown versions of invfo_poll() were
  universally broken (they returned an errno value, invfo_poll()
  uses poll_no_poll() to return an appropriate event mask).  Home-grown
  ioctl routines also tended to return an incorrect errno (invfo_ioctl
  returns ENOTTY).
- Use the invfo_*() functions instead of local versions for
  unsupported file operations.
- Reorder fileops members to match the order in the structure definition
  to make it easier to spot missing members.
- Add several missing methods to linuxfileops used by the OFED shim
  layer: fo_write(), fo_truncate(), fo_kqfilter(), and fo_stat().  Most
  of these used invfo_*(), but a dummy fo_stat() implementation was
  added.
  • Loading branch information
bsdjhb committed Sep 12, 2014
1 parent 94540ef commit 4cd91e9
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 281 deletions.
31 changes: 31 additions & 0 deletions sys/kern/kern_descrip.c
Original file line number Diff line number Diff line change
Expand Up @@ -3940,6 +3940,14 @@ struct fileops badfileops = {
.fo_sendfile = badfo_sendfile,
};

int
invfo_rdwr(struct file *fp, struct uio *uio, struct ucred *active_cred,
int flags, struct thread *td)
{

return (EOPNOTSUPP);
}

int
invfo_truncate(struct file *fp, off_t length, struct ucred *active_cred,
struct thread *td)
Expand All @@ -3948,6 +3956,29 @@ invfo_truncate(struct file *fp, off_t length, struct ucred *active_cred,
return (EINVAL);
}

int
invfo_ioctl(struct file *fp, u_long com, void *data,
struct ucred *active_cred, struct thread *td)
{

return (ENOTTY);
}

int
invfo_poll(struct file *fp, int events, struct ucred *active_cred,
struct thread *td)
{

return (poll_no_poll(events));
}

int
invfo_kqfilter(struct file *fp, struct knote *kn)
{

return (EINVAL);
}

int
invfo_chmod(struct file *fp, mode_t mode, struct ucred *active_cred,
struct thread *td)
Expand Down
38 changes: 3 additions & 35 deletions sys/kern/kern_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,19 +109,16 @@ static void kqueue_wakeup(struct kqueue *kq);
static struct filterops *kqueue_fo_find(int filt);
static void kqueue_fo_release(int filt);

static fo_rdwr_t kqueue_read;
static fo_rdwr_t kqueue_write;
static fo_truncate_t kqueue_truncate;
static fo_ioctl_t kqueue_ioctl;
static fo_poll_t kqueue_poll;
static fo_kqfilter_t kqueue_kqfilter;
static fo_stat_t kqueue_stat;
static fo_close_t kqueue_close;

static struct fileops kqueueops = {
.fo_read = kqueue_read,
.fo_write = kqueue_write,
.fo_truncate = kqueue_truncate,
.fo_read = invfo_rdwr,
.fo_write = invfo_rdwr,
.fo_truncate = invfo_truncate,
.fo_ioctl = kqueue_ioctl,
.fo_poll = kqueue_poll,
.fo_kqfilter = kqueue_kqfilter,
Expand Down Expand Up @@ -1602,35 +1599,6 @@ kqueue_scan(struct kqueue *kq, int maxevents, struct kevent_copyops *k_ops,
return (error);
}

/*
* XXX
* This could be expanded to call kqueue_scan, if desired.
*/
/*ARGSUSED*/
static int
kqueue_read(struct file *fp, struct uio *uio, struct ucred *active_cred,
int flags, struct thread *td)
{
return (ENXIO);
}

/*ARGSUSED*/
static int
kqueue_write(struct file *fp, struct uio *uio, struct ucred *active_cred,
int flags, struct thread *td)
{
return (ENXIO);
}

/*ARGSUSED*/
static int
kqueue_truncate(struct file *fp, off_t length, struct ucred *active_cred,
struct thread *td)
{

return (EINVAL);
}

/*ARGSUSED*/
static int
kqueue_ioctl(struct file *fp, u_long cmd, void *data,
Expand Down
65 changes: 6 additions & 59 deletions sys/kern/sys_procdesc.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,28 +87,22 @@ FEATURE(process_descriptors, "Process Descriptors");

static uma_zone_t procdesc_zone;

static fo_rdwr_t procdesc_read;
static fo_rdwr_t procdesc_write;
static fo_truncate_t procdesc_truncate;
static fo_ioctl_t procdesc_ioctl;
static fo_poll_t procdesc_poll;
static fo_kqfilter_t procdesc_kqfilter;
static fo_stat_t procdesc_stat;
static fo_close_t procdesc_close;
static fo_chmod_t procdesc_chmod;
static fo_chown_t procdesc_chown;

static struct fileops procdesc_ops = {
.fo_read = procdesc_read,
.fo_write = procdesc_write,
.fo_truncate = procdesc_truncate,
.fo_ioctl = procdesc_ioctl,
.fo_read = invfo_rdwr,
.fo_write = invfo_rdwr,
.fo_truncate = invfo_truncate,
.fo_ioctl = invfo_ioctl,
.fo_poll = procdesc_poll,
.fo_kqfilter = procdesc_kqfilter,
.fo_stat = procdesc_stat,
.fo_close = procdesc_close,
.fo_chmod = procdesc_chmod,
.fo_chown = procdesc_chown,
.fo_chmod = invfo_chmod,
.fo_chown = invfo_chown,
.fo_sendfile = invfo_sendfile,
.fo_flags = DFLAG_PASSABLE,
};
Expand Down Expand Up @@ -412,38 +406,6 @@ procdesc_close(struct file *fp, struct thread *td)
return (0);
}

static int
procdesc_read(struct file *fp, struct uio *uio, struct ucred *active_cred,
int flags, struct thread *td)
{

return (EOPNOTSUPP);
}

static int
procdesc_write(struct file *fp, struct uio *uio, struct ucred *active_cred,
int flags, struct thread *td)
{

return (EOPNOTSUPP);
}

static int
procdesc_truncate(struct file *fp, off_t length, struct ucred *active_cred,
struct thread *td)
{

return (EOPNOTSUPP);
}

static int
procdesc_ioctl(struct file *fp, u_long com, void *data,
struct ucred *active_cred, struct thread *td)
{

return (EOPNOTSUPP);
}

static int
procdesc_poll(struct file *fp, int events, struct ucred *active_cred,
struct thread *td)
Expand Down Expand Up @@ -569,18 +531,3 @@ procdesc_stat(struct file *fp, struct stat *sb, struct ucred *active_cred,
return (0);
}

static int
procdesc_chmod(struct file *fp, mode_t mode, struct ucred *active_cred,
struct thread *td)
{

return (EOPNOTSUPP);
}

static int
procdesc_chown(struct file *fp, uid_t uid, gid_t gid, struct ucred *active_cred,
struct thread *td)
{

return (EOPNOTSUPP);
}
10 changes: 1 addition & 9 deletions sys/kern/tty_pts.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,14 +252,6 @@ done: ttydisc_rint_done(tp);
return (error);
}

static int
ptsdev_truncate(struct file *fp, off_t length, struct ucred *active_cred,
struct thread *td)
{

return (EINVAL);
}

static int
ptsdev_ioctl(struct file *fp, u_long cmd, void *data,
struct ucred *active_cred, struct thread *td)
Expand Down Expand Up @@ -591,7 +583,7 @@ ptsdev_close(struct file *fp, struct thread *td)
static struct fileops ptsdev_ops = {
.fo_read = ptsdev_read,
.fo_write = ptsdev_write,
.fo_truncate = ptsdev_truncate,
.fo_truncate = invfo_truncate,
.fo_ioctl = ptsdev_ioctl,
.fo_poll = ptsdev_poll,
.fo_kqfilter = ptsdev_kqfilter,
Expand Down
39 changes: 5 additions & 34 deletions sys/kern/uipc_mqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -2417,35 +2417,6 @@ mq_proc_exit(void *arg __unused, struct proc *p)
KASSERT(LIST_EMPTY(&p->p_mqnotifier), ("mq notifiers left"));
}

static int
mqf_read(struct file *fp, struct uio *uio, struct ucred *active_cred,
int flags, struct thread *td)
{
return (EOPNOTSUPP);
}

static int
mqf_write(struct file *fp, struct uio *uio, struct ucred *active_cred,
int flags, struct thread *td)
{
return (EOPNOTSUPP);
}

static int
mqf_truncate(struct file *fp, off_t length, struct ucred *active_cred,
struct thread *td)
{

return (EINVAL);
}

static int
mqf_ioctl(struct file *fp, u_long cmd, void *data,
struct ucred *active_cred, struct thread *td)
{
return (ENOTTY);
}

static int
mqf_poll(struct file *fp, int events, struct ucred *active_cred,
struct thread *td)
Expand Down Expand Up @@ -2601,16 +2572,16 @@ filt_mqwrite(struct knote *kn, long hint)
}

static struct fileops mqueueops = {
.fo_read = mqf_read,
.fo_write = mqf_write,
.fo_truncate = mqf_truncate,
.fo_ioctl = mqf_ioctl,
.fo_read = invfo_rdwr,
.fo_write = invfo_rdwr,
.fo_truncate = invfo_truncate,
.fo_ioctl = invfo_ioctl,
.fo_poll = mqf_poll,
.fo_kqfilter = mqf_kqfilter,
.fo_stat = mqf_stat,
.fo_close = mqf_close,
.fo_chmod = mqf_chmod,
.fo_chown = mqf_chown,
.fo_close = mqf_close,
.fo_sendfile = invfo_sendfile,
};

Expand Down
65 changes: 6 additions & 59 deletions sys/kern/uipc_sem.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,25 +126,19 @@ static int ksem_module_init(void);
static int ksem_remove(char *path, Fnv32_t fnv, struct ucred *ucred);
static int sem_modload(struct module *module, int cmd, void *arg);

static fo_rdwr_t ksem_read;
static fo_rdwr_t ksem_write;
static fo_truncate_t ksem_truncate;
static fo_ioctl_t ksem_ioctl;
static fo_poll_t ksem_poll;
static fo_kqfilter_t ksem_kqfilter;
static fo_stat_t ksem_stat;
static fo_close_t ksem_closef;
static fo_chmod_t ksem_chmod;
static fo_chown_t ksem_chown;

/* File descriptor operations. */
static struct fileops ksem_ops = {
.fo_read = ksem_read,
.fo_write = ksem_write,
.fo_truncate = ksem_truncate,
.fo_ioctl = ksem_ioctl,
.fo_poll = ksem_poll,
.fo_kqfilter = ksem_kqfilter,
.fo_read = invfo_rdwr,
.fo_write = invfo_rdwr,
.fo_truncate = invfo_truncate,
.fo_ioctl = invfo_ioctl,
.fo_poll = invfo_poll,
.fo_kqfilter = invfo_kqfilter,
.fo_stat = ksem_stat,
.fo_close = ksem_closef,
.fo_chmod = ksem_chmod,
Expand All @@ -155,53 +149,6 @@ static struct fileops ksem_ops = {

FEATURE(posix_sem, "POSIX semaphores");

static int
ksem_read(struct file *fp, struct uio *uio, struct ucred *active_cred,
int flags, struct thread *td)
{

return (EOPNOTSUPP);
}

static int
ksem_write(struct file *fp, struct uio *uio, struct ucred *active_cred,
int flags, struct thread *td)
{

return (EOPNOTSUPP);
}

static int
ksem_truncate(struct file *fp, off_t length, struct ucred *active_cred,
struct thread *td)
{

return (EINVAL);
}

static int
ksem_ioctl(struct file *fp, u_long com, void *data,
struct ucred *active_cred, struct thread *td)
{

return (EOPNOTSUPP);
}

static int
ksem_poll(struct file *fp, int events, struct ucred *active_cred,
struct thread *td)
{

return (EOPNOTSUPP);
}

static int
ksem_kqfilter(struct file *fp, struct knote *kn)
{

return (EOPNOTSUPP);
}

static int
ksem_stat(struct file *fp, struct stat *sb, struct ucred *active_cred,
struct thread *td)
Expand Down
Loading

0 comments on commit 4cd91e9

Please sign in to comment.