2 * This file contains a number of device-type independent device routines.
4 * The entry points in this file are:
5 * do_ioctl: perform the IOCTL system call
6 * make_ioctl_grant: make a grant for an IOCTL request to a device
12 #include <sys/ioctl.h>
15 * Perform the ioctl(2) system call.
20 unsigned long request
;
22 register struct vnode
*vp
;
26 fd
= job_m_in
.m_lc_vfs_ioctl
.fd
;
27 request
= job_m_in
.m_lc_vfs_ioctl
.req
;
28 arg
= (vir_bytes
)job_m_in
.m_lc_vfs_ioctl
.arg
;
30 if ((f
= get_filp(fd
, VNODE_READ
)) == NULL
)
32 vp
= f
->filp_vno
; /* get vnode pointer */
34 switch (vp
->v_mode
& S_IFMT
) {
36 f
->filp_ioctl_fp
= fp
;
38 r
= bdev_ioctl(vp
->v_sdev
, who_e
, request
, arg
);
40 f
->filp_ioctl_fp
= NULL
;
44 r
= cdev_io(CDEV_IOCTL
, vp
->v_sdev
, who_e
, arg
, 0, request
,
49 r
= sdev_ioctl(vp
->v_sdev
, request
, arg
, f
->filp_flags
);
62 * Create a magic grant for the given IOCTL request.
65 make_ioctl_grant(endpoint_t driver_e
, endpoint_t user_e
, vir_bytes buf
,
66 unsigned long request
)
73 * For IOCTLs, the bytes parameter contains the IOCTL request.
74 * This request encodes the requested access method and buffer size.
77 if (_MINIX_IOCTL_IOR(request
)) access
|= CPF_WRITE
;
78 if (_MINIX_IOCTL_IOW(request
)) access
|= CPF_READ
;
79 if (_MINIX_IOCTL_BIG(request
))
80 size
= _MINIX_IOCTL_SIZE_BIG(request
);
82 size
= _MINIX_IOCTL_SIZE(request
);
85 * Grant access to the buffer even if no I/O happens with the ioctl,
86 * although now that we no longer identify responses based on grants,
87 * this is not strictly necessary.
89 grant
= cpf_grant_magic(driver_e
, user_e
, buf
, size
, access
);
91 if (!GRANT_VALID(grant
))
92 panic("VFS: cpf_grant_magic failed");