splitting fnctl(), ioctl()

David P. Reese, Jr. daver at gomerbud.com
Fri Oct 10 13:43:19 PDT 2003


On Fri, Oct 10, 2003 at 01:03:03PM -0700, Matthew Dillon wrote:
> 
> :In splitting syscalls like fcntl() and ioctl(), I am considering doing
> :something like the following:
> :
> :int
> :fcntl(stuct fcntl_args *uap)
> :{
> :	fcntl_copyin(uap->cmd, uap->arg, &buf);
> :	kern_fcntl(uap->fd, uap->arg, &buf);
> :	fcntl_copyout(uap->cmd, uap->arg, &buf);
> :}
> :
> :The buffer would be the size of the largest argument for fcntl.
> :The emulators would then implement their own versions of the copyin/
> :copyout functions.  While this does separate the copyin/copyout,
> :it places code for the same fcntl in three different places.
> :
> :The ioctl() syscall will be a little more trouble.  I don't like the
> :fact that drivers can copyin at their own discression, especially from
> :pointers stored in uap->arg.
> :
> :>From a syscall hacker's standpoint, I don't like the ioctl() interface.
> :
> :-- 
> :   David P. Reese, Jr.                                     daver at xxxxxxxxxxxx
> :                                               http://www.gomerbud.com/daver/
> 
>     This could be a tough nut to crack.  Have you coded up fcntl_copyin()
>     and fcntl_copyout() yet?  I'd like to see what they would contain.
> 
> 					-Matt
> 					Matthew Dillon 
> 					<dillon at xxxxxxxxxxxxx>

Not yet.  However, I expect them to look like:

int
fcntl_copyin(int cmd, caddr_t arg, caddr_t buf)
{
	switch (cmd) {
	case F_GETFD:
		break;
[snip]
	case F_SETLK:
		copyin(uap->arg, buf, sizeof(struct flock);
		break;
	case F_GETLK:
		copyin(uap->arg, buf, sizeof(struct flock);
		break;
	}
}

int
fcntl_copyout(int cmd, caddr_t arg, caddr_t buf)
{
	switch (cmd) {
	case F_GETFD:
		break;
[snip]
	case F_SETLK:
		break;
	case F_GETLK:
		copyout(buf, uap->arg, sizeof(struct flock);
	}
}

While they get most of the job done, I don't like the fact that this
method separates the code.

-- 
   David P. Reese, Jr.                                     daver at xxxxxxxxxxxx
                                               http://www.gomerbud.com/daver/





More information about the Kernel mailing list