This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[WIP] BZ #14361: POSIX vs. BSD and the `ioctl' interface.
- From: Carlos O'Donell <carlos_odonell at mentor dot com>
- To: Roland McGrath <roland at hack dot frob dot com>
- Cc: libc-alpha <libc-alpha at sourceware dot org>, Chris Metcalf<cmetcalf at tilera dot com>, "Joseph S. Myers" <joseph at codesourcery dot com>
- Date: Mon, 23 Jul 2012 23:55:18 -0400
- Subject: [WIP] BZ #14361: POSIX vs. BSD and the `ioctl' interface.
Roland,
In 1993 you changed ioctl's second argument to be `unsigned long int' to
match BSD 4.4. Here is the excerpt from ChangeLog.2:
...
Fri Dec 17 15:05:58 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu)
* misc/sys/ioctl.h (__ioctl, ioctl): Make second arg `unsigned
long int' instead of `int' (4.4 uses unsigned long).
...
In BZ #14362 Linus Torvalds points out that `unsigned long int' as a
second argument doesn't match SuS. I verified that is still the case in
POSIX 2008/SUSv4.
Worse it doesn't even match our own documentation in manual/llio.texi:
...
@comment sys/ioctl.h
@comment BSD
@deftypefun int ioctl (int @var{filedes}, int @var{command}, @dots{})
...
which also uses `int' for the second argument (written by Ulrich in 1998).
My worries are:
(a) POSIX conformance.
and
(b) Backwards compatibility with an interface that has been around
since 1993.
Can we somehow juggle (a) and (b)?
Comments?
Just to frame the discussion I wrote up a WIP patch and included some
FIXME's for Tilera and MIPS which expect certain behaviour from our
ioctl interface:
2012-07-23 Carlos O'Donell <carlos_odonell@mentor.com>
[BZ #14362]
* include/sys/ioctl.h: Use `int' for __request argument
of function __ioctl.
* misc/ioctl.c (__ioctl): Likewise.
* misc/sys/ioctl.h: Likewise.
* sysdeps/mach/hurd/ioctl.c (__ioctl): Likewise.
* sysdeps/unix/sysv/linux/powerpc/ioctl.c (__ioctl): Likewise.
* ports/sysdeps/unix/sysv/linux/mips/mips64/n64/ioctl.S:
Add FIXME.
* ports/sysdeps/unix/sysv/linux/tile/tilegx/ioctl.S:
Add FIXME.
diff --git a/include/sys/ioctl.h b/include/sys/ioctl.h
index ebadd52..883c12e 100644
--- a/include/sys/ioctl.h
+++ b/include/sys/ioctl.h
@@ -2,5 +2,5 @@
#include <misc/sys/ioctl.h>
/* Now define the internal interfaces. */
-extern int __ioctl (int __fd, unsigned long int __request, ...);
+extern int __ioctl (int __fd, int __request, ...);
#endif
diff --git a/misc/ioctl.c b/misc/ioctl.c
index 616ee2d..a5d4a81 100644
--- a/misc/ioctl.c
+++ b/misc/ioctl.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991, 93, 94, 95, 96, 97 Free Software Foundation, Inc.
+/* Copyright (C) 1991-2012 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -23,7 +23,7 @@
int
__ioctl (fd, request)
int fd;
- unsigned long int request;
+ int request;
{
__set_errno (ENOSYS);
return -1;
diff --git a/misc/sys/ioctl.h b/misc/sys/ioctl.h
index c49c4ab..8340a0a 100644
--- a/misc/sys/ioctl.h
+++ b/misc/sys/ioctl.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991, 92, 93, 94, 96, 98, 99 Free Software Foundation, Inc.
+/* Copyright (C) 1991-2012 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -38,7 +38,7 @@ __BEGIN_DECLS
/* Perform the I/O control operation specified by REQUEST on FD.
One argument may follow; its presence and type depend on REQUEST.
Return value depends on REQUEST. Usually -1 indicates error. */
-extern int ioctl (int __fd, unsigned long int __request, ...) __THROW;
+extern int ioctl (int __fd, int __request, ...) __THROW;
__END_DECLS
diff --git a/ports/sysdeps/unix/sysv/linux/mips/mips64/n64/ioctl.S b/ports/sysdeps/unix/sysv/linux/mips/mips64/n64/ioctl.S
index 3ff0d0e..1cb3541 100644
--- a/ports/sysdeps/unix/sysv/linux/mips/mips64/n64/ioctl.S
+++ b/ports/sysdeps/unix/sysv/linux/mips/mips64/n64/ioctl.S
@@ -1,4 +1,4 @@
-/* Copyright 2003, 2005 Free Software Foundation, Inc.
+/* Copyright 2003-2012 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -19,6 +19,9 @@
#include <sys/asm.h>
+/* FIXME: Now that the userspace API claims that the argument
+ if of type `int' does this code need updating? */
+
/* Sign-extend the ioctl number, since the kernel wants it as a
sign-extended 32-bit value, but our prototype is that of a long. */
diff --git a/ports/sysdeps/unix/sysv/linux/tile/tilegx/ioctl.S b/ports/sysdeps/unix/sysv/linux/tile/tilegx/ioctl.S
index e966c4d..b61592c 100644
--- a/ports/sysdeps/unix/sysv/linux/tile/tilegx/ioctl.S
+++ b/ports/sysdeps/unix/sysv/linux/tile/tilegx/ioctl.S
@@ -1,4 +1,4 @@
-/* Copyright (C) 2011 Free Software Foundation, Inc.
+/* Copyright (C) 2011-2012 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
@@ -16,6 +16,8 @@
License along with the GNU C Library. If not, see
<http://www.gnu.org/licenses/>. */
+/* FIXME: Now that the userspace API claims that the argument
+ if of type `int' does this code need updating? */
/* TILE-Gx specifies that "unsigned int" is sign extended in the high
32 bits. But since the userspace API claims to be "unsigned long",
diff --git a/sysdeps/mach/hurd/ioctl.c b/sysdeps/mach/hurd/ioctl.c
index 543d437..6aeeca4 100644
--- a/sysdeps/mach/hurd/ioctl.c
+++ b/sysdeps/mach/hurd/ioctl.c
@@ -36,7 +36,7 @@
/* Perform the I/O control operation specified by REQUEST on FD.
The actual type and use of ARG and the return value depend on REQUEST. */
int
-__ioctl (int fd, unsigned long int request, ...)
+__ioctl (int fd, int request, ...)
{
#ifdef MACH_MSG_TYPE_CHAR
/* Map individual type fields to Mach IPC types. */
diff --git a/sysdeps/unix/sysv/linux/powerpc/ioctl.c b/sysdeps/unix/sysv/linux/powerpc/ioctl.c
index e8f5d16..b470ae8 100644
--- a/sysdeps/unix/sysv/linux/powerpc/ioctl.c
+++ b/sysdeps/unix/sysv/linux/powerpc/ioctl.c
@@ -25,7 +25,7 @@
using the new-style struct termios, and translate them to old-style. */
int
-__ioctl (int fd, unsigned long int request, ...)
+__ioctl (int fd, int request, ...)
{
void *arg;
va_list ap;
---
Cheers,
Carlos.
--
Carlos O'Donell
Mentor Graphics / CodeSourcery
carlos_odonell@mentor.com
carlos@codesourcery.com
+1 (613) 963 1026