Make dev_t 32-bits and provide backwards compatibility

This commit is contained in:
Thomas Veerman 2011-08-31 13:38:28 +00:00
parent e68cf3bf89
commit fde9a258d0
15 changed files with 126 additions and 12 deletions

View file

@ -98,7 +98,7 @@ typedef long key_t;
/* Open Group Base Specifications Issue 6 (not complete) */
typedef long useconds_t; /* Time in microseconds */
typedef short dev_t; /* holds (major|minor) device pair */
typedef u32_t dev_t; /* holds (major|minor) device pair */
typedef u32_t big_dev_t;
/* Types used in disk, inode, etc. data structures.

View file

@ -73,6 +73,7 @@ struct msg_control
#define NWIOSUDSBLOG _IOW ('n', 73, int) /* listen() */
#define NWIOSUDSCONN _IOW ('n', 74, struct sockaddr_un) /* connect() */
#define NWIOSUDSSHUT _IOW ('n', 75, int) /* shutdown() */
#define NWIOSUDSPAIROLD _IOW ('n', 76, short) /* socketpair() */
#define NWIOSUDSPAIR _IOW ('n', 76, dev_t) /* socketpair() */
#define NWIOSUDSACCEPT _IOW ('n', 77, struct sockaddr_un) /* accept() */
#define NWIOSUDSCTRL _IOW ('n', 78, struct msg_control) /* sendmsg() */

View file

@ -47,13 +47,13 @@ struct stat {
struct minix_prev_stat {
dev_t st_dev; /* major/minor device number */
short st_dev; /* major/minor device number */
ino_t st_ino; /* i-node number */
mode_t st_mode; /* file mode, protection bits, etc. */
nlink_t st_nlink; /* # links; */
uid_t st_uid; /* uid of the file's owner */
short int st_gid; /* gid; TEMPORARY HACK: should be gid_t */
dev_t st_rdev;
short st_rdev;
off_t st_size; /* file size */
time_t st_atime; /* time of last access */
time_t st_mtime; /* time of last data modification */

View file

@ -77,6 +77,7 @@ struct msg_control
#define NWIOSUDSCONN _IOW ('n', 74, struct sockaddr_un) /* connect() */
#define NWIOSUDSSHUT _IOW ('n', 75, int) /* shutdown() */
#define NWIOSUDSPAIR _IOW ('n', 76, dev_t) /* socketpair() */
#define NWIOSUDSPAIROLD _IOW ('n', 76, short) /* socketpair() */
#define NWIOSUDSACCEPT _IOW ('n', 77, struct sockaddr_un) /* accept() */
#define NWIOSUDSCTRL _IOW ('n', 78, struct msg_control) /* sendmsg() */
#define NWIOGUDSCTRL _IORW('n', 79, struct msg_control) /* recvmsg() */

View file

@ -42,13 +42,13 @@ struct stat {
struct minix_prev_stat {
dev_t st_dev; /* major/minor device number */
short st_dev; /* major/minor device number */
ino_t st_ino; /* i-node number */
mode_t st_mode; /* file mode, protection bits, etc. */
nlink_t st_nlink; /* # links; */
uid_t st_uid; /* uid of the file's owner */
short int st_gid; /* gid; TEMPORARY HACK: should be gid_t */
dev_t st_rdev;
short st_rdev;
off_t st_size; /* file size */
time_t st_atime; /* time of last access */
time_t st_mtime; /* time of last data modification */

View file

@ -193,7 +193,7 @@ typedef int64_t daddr_t; /* disk address */
#endif
typedef short dev_t; /* device number */
typedef uint32_t dev_t; /* device number */
typedef uint32_t fixpt_t; /* fixed point number */
#ifndef gid_t

View file

@ -855,6 +855,13 @@ PUBLIC int uds_ioctl(message *dev_m_in, message *dev_m_out)
break;
case NWIOSUDSPAIROLD:
/* connect two sockets -- socketpair() */
rc = do_socketpair_old(dev_m_in, dev_m_out);
break;
case NWIOGUDSSOTYPE:
/* get socket type -- getsockopt(SO_TYPE) */

View file

@ -80,6 +80,7 @@ _PROTOTYPE( int do_getsockname, (message *dev_m_in, message *dev_m_out) );
_PROTOTYPE( int do_getpeername, (message *dev_m_in, message *dev_m_out) );
_PROTOTYPE( int do_shutdown, (message *dev_m_in, message *dev_m_out) );
_PROTOTYPE( int do_socketpair, (message *dev_m_in, message *dev_m_out) );
_PROTOTYPE( int do_socketpair_old, (message *dev_m_in, message *dev_m_out) );
_PROTOTYPE( int do_getsockopt_sotype,
(message *dev_m_in, message *dev_m_out) );
_PROTOTYPE( int do_getsockopt_peercred,

View file

@ -882,6 +882,53 @@ PUBLIC int do_shutdown(message *dev_m_in, message *dev_m_out)
return OK;
}
PUBLIC int do_socketpair_old(message *dev_m_in, message *dev_m_out)
{
int rc;
short minorin;
int minorx, minory;
struct sockaddr_un addr;
#if DEBUG == 1
static int call_count = 0;
printf("(uds) [%d] do_socketpair() call_count=%d\n",
uds_minor(dev_m_in), ++call_count);
#endif
/* first ioctl param is the first socket */
minorx = uds_minor_old(dev_m_in);
/* third ioctl param is the minor number of the second socket */
rc = sys_safecopyfrom(VFS_PROC_NR, (cp_grant_id_t) dev_m_in->IO_GRANT,
(vir_bytes) 0, (vir_bytes) &minorin, sizeof(short), D);
if (rc != OK) {
return EIO;
}
minory = minor(minorin);
#if DEBUG == 1
printf("socketpair() %d - %d\n", minorx, minory);
#endif
/* security check - both sockets must have the same endpoint (owner) */
if (uds_fd_table[minorx].owner != uds_fd_table[minory].owner) {
/* we won't allow you to magically connect your socket to
* someone elses socket
*/
return EPERM;
}
addr.sun_family = AF_UNIX;
addr.sun_path[0] = 'X';
addr.sun_path[1] = '\0';
uds_fd_table[minorx].syscall_done = 1;
return perform_connection(dev_m_in, dev_m_out, &addr, minorx, minory);
}
PUBLIC int do_socketpair(message *dev_m_in, message *dev_m_out)
{
int rc;
@ -906,7 +953,7 @@ PUBLIC int do_socketpair(message *dev_m_in, message *dev_m_out)
return EIO;
}
minory = (minor(minorin) & BYTE);
minory = minor(minorin);
#if DEBUG == 1
printf("socketpair() %d - %d\n", minorx, minory);

View file

@ -224,7 +224,8 @@ EXTERN uds_fd_t uds_fd_table[NR_FDS];
/*
* Take message m and get the index in uds_fd_table.
*/
#define uds_minor(m) (minor((dev_t) m->DEVICE) & BYTE)
#define uds_minor(m) (minor((dev_t) m->DEVICE))
#define uds_minor_old(m) (minor((short) m->DEVICE))
/*
* Fill in a reply message.

View file

@ -67,7 +67,7 @@ static void check_mknod(char *device, mode_t mode, int minor)
struct stat st;
dev_t dev;
dev= (ip_dev & 0xFF00) | minor;
dev= makedev(major(ip_dev), minor);
if (stat(device, &st) < 0) {
if (errno != ENOENT) fatal(device);
@ -77,7 +77,7 @@ static void check_mknod(char *device, mode_t mode, int minor)
}
if (mknod(device, S_IFCHR | mode, dev) < 0) fatal(device);
printf("mknod %s c %d %d\n", device, (ip_dev >> 8), minor);
printf("mknod %s c %d %d\n", device, major(ip_dev), minor);
}
static void check_ln(char *old, char *new)

View file

@ -865,6 +865,13 @@ PUBLIC int uds_ioctl(message *dev_m_in, message *dev_m_out)
break;
case NWIOSUDSPAIROLD:
/* connect two sockets -- socketpair() */
rc = do_socketpair_old(dev_m_in, dev_m_out);
break;
case NWIOGUDSSOTYPE:
/* get socket type -- getsockopt(SO_TYPE) */

View file

@ -77,6 +77,7 @@ _PROTOTYPE( int do_getsockname, (message *dev_m_in, message *dev_m_out) );
_PROTOTYPE( int do_getpeername, (message *dev_m_in, message *dev_m_out) );
_PROTOTYPE( int do_shutdown, (message *dev_m_in, message *dev_m_out) );
_PROTOTYPE( int do_socketpair, (message *dev_m_in, message *dev_m_out) );
_PROTOTYPE( int do_socketpair_old, (message *dev_m_in, message *dev_m_out) );
_PROTOTYPE( int do_getsockopt_sotype,
(message *dev_m_in, message *dev_m_out) );
_PROTOTYPE( int do_getsockopt_peercred,

View file

@ -884,6 +884,53 @@ PUBLIC int do_shutdown(message *dev_m_in, message *dev_m_out)
return OK;
}
PUBLIC int do_socketpair_old(message *dev_m_in, message *dev_m_out)
{
int rc;
short minorin;
int minorx, minory;
struct sockaddr_un addr;
#if DEBUG == 1
static int call_count = 0;
printf("(uds) [%d] do_socketpair() call_count=%d\n",
uds_minor(dev_m_in), ++call_count);
#endif
/* first ioctl param is the first socket */
minorx = uds_minor_old(dev_m_in);
/* third ioctl param is the minor number of the second socket */
rc = sys_safecopyfrom(VFS_PROC_NR, (cp_grant_id_t) dev_m_in->IO_GRANT,
(vir_bytes) 0, (vir_bytes) &minorin, sizeof(short), D);
if (rc != OK) {
return EIO;
}
minory = minor(minorin);
#if DEBUG == 1
printf("socketpair() %d - %d\n", minorx, minory);
#endif
/* security check - both sockets must have the same endpoint (owner) */
if (uds_fd_table[minorx].owner != uds_fd_table[minory].owner) {
/* we won't allow you to magically connect your socket to
* someone elses socket
*/
return EPERM;
}
addr.sun_family = AF_UNIX;
addr.sun_path[0] = 'X';
addr.sun_path[1] = '\0';
uds_fd_table[minorx].syscall_done = 1;
return perform_connection(dev_m_in, dev_m_out, &addr, minorx, minory);
}
PUBLIC int do_socketpair(message *dev_m_in, message *dev_m_out)
{
int rc;
@ -908,7 +955,7 @@ PUBLIC int do_socketpair(message *dev_m_in, message *dev_m_out)
return EIO;
}
minory = (minor(minorin) & BYTE);
minory = minor(minorin);
#if DEBUG == 1
printf("socketpair() %d - %d\n", minorx, minory);

View file

@ -224,7 +224,8 @@ EXTERN uds_fd_t uds_fd_table[NR_FDS];
/*
* Take message m and get the index in uds_fd_table.
*/
#define uds_minor(m) (minor((dev_t) m->DEVICE) & BYTE)
#define uds_minor(m) (minor((dev_t) m->DEVICE))
#define uds_minor_old(m) (minor((short) m->DEVICE))
/*
* Fill in a reply message.