From: Thomas Veerman Date: Wed, 31 Aug 2011 13:38:28 +0000 (+0000) Subject: Make dev_t 32-bits and provide backwards compatibility X-Git-Tag: v3.2.0~319 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/named.html?a=commitdiff_plain;h=fde9a258d09662014b3c145c511542fcf6861452;p=minix.git Make dev_t 32-bits and provide backwards compatibility --- diff --git a/include/minix/types.h b/include/minix/types.h index 1d1ef3149..4c46763dd 100644 --- a/include/minix/types.h +++ b/include/minix/types.h @@ -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. diff --git a/include/net/ioctl.h b/include/net/ioctl.h index feba25012..71ca4752b 100644 --- a/include/net/ioctl.h +++ b/include/net/ioctl.h @@ -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() */ diff --git a/include/sys/stat.h b/include/sys/stat.h index 3af7b8d92..ee7b7fc8a 100644 --- a/include/sys/stat.h +++ b/include/sys/stat.h @@ -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 */ diff --git a/nbsd_include/sys/ioc_net.h b/nbsd_include/sys/ioc_net.h index 12f4188a2..b2f831b60 100644 --- a/nbsd_include/sys/ioc_net.h +++ b/nbsd_include/sys/ioc_net.h @@ -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() */ diff --git a/nbsd_include/sys/stat.h b/nbsd_include/sys/stat.h index 27324e622..fd89f9def 100644 --- a/nbsd_include/sys/stat.h +++ b/nbsd_include/sys/stat.h @@ -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 */ diff --git a/nbsd_include/sys/types.h b/nbsd_include/sys/types.h index 546641a8c..9dcf4fd9d 100644 --- a/nbsd_include/sys/types.h +++ b/nbsd_include/sys/types.h @@ -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 diff --git a/servers/apfs/dev_uds.c b/servers/apfs/dev_uds.c index b88f3ee1e..e16ad099c 100644 --- a/servers/apfs/dev_uds.c +++ b/servers/apfs/dev_uds.c @@ -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) */ diff --git a/servers/apfs/proto.h b/servers/apfs/proto.h index fe28b2895..e0da81367 100644 --- a/servers/apfs/proto.h +++ b/servers/apfs/proto.h @@ -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, diff --git a/servers/apfs/uds.c b/servers/apfs/uds.c index a0d629796..67e5ae255 100644 --- a/servers/apfs/uds.c +++ b/servers/apfs/uds.c @@ -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); diff --git a/servers/apfs/uds.h b/servers/apfs/uds.h index 2c3d85520..efcb9c1da 100644 --- a/servers/apfs/uds.h +++ b/servers/apfs/uds.h @@ -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. diff --git a/servers/inet/inet_config.c b/servers/inet/inet_config.c index af54173a8..2a04540da 100644 --- a/servers/inet/inet_config.c +++ b/servers/inet/inet_config.c @@ -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) diff --git a/servers/pfs/dev_uds.c b/servers/pfs/dev_uds.c index 3d6e73241..c6033323e 100644 --- a/servers/pfs/dev_uds.c +++ b/servers/pfs/dev_uds.c @@ -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) */ diff --git a/servers/pfs/proto.h b/servers/pfs/proto.h index e6dedfc99..9ba371c97 100644 --- a/servers/pfs/proto.h +++ b/servers/pfs/proto.h @@ -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, diff --git a/servers/pfs/uds.c b/servers/pfs/uds.c index e184191c8..81efd2ef3 100644 --- a/servers/pfs/uds.c +++ b/servers/pfs/uds.c @@ -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); diff --git a/servers/pfs/uds.h b/servers/pfs/uds.h index cd754e343..facfdbc33 100644 --- a/servers/pfs/uds.h +++ b/servers/pfs/uds.h @@ -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.