From d266a94fea1894b1876270bf0a3daae8ccc22447 Mon Sep 17 00:00:00 2001 From: David van Moolenbroek Date: Wed, 18 Sep 2013 13:38:36 +0200 Subject: [PATCH] Enable devname(3) There is no support for a device name database yet, so this call is expected to be fairly slow. Change-Id: I73aa5f267e2b6921b7d3bbdcc4beac463931132c --- commands/fdisk/fdisk.c | 32 ++++++++++++++++---------------- include/stdlib.h | 2 -- lib/libc/gen/Makefile.inc | 4 ++-- lib/libc/gen/devname.c | 4 ++++ sys/stdlib.h | 3 +-- usr.bin/stat/stat.c | 5 ----- 6 files changed, 23 insertions(+), 27 deletions(-) diff --git a/commands/fdisk/fdisk.c b/commands/fdisk/fdisk.c index 4c237f27a..5b41d8308 100644 --- a/commands/fdisk/fdisk.c +++ b/commands/fdisk/fdisk.c @@ -75,7 +75,7 @@ char *secbuf; int badbases; int badsizes; int badorders; -char *devname; +char *dev_name; int nhead; int nsec; int ncyl = 1024; @@ -161,9 +161,9 @@ int main(int argc, char *argv[]) } if (argn == argc) - devname = DEFAULT_DEV; + dev_name = DEFAULT_DEV; else if (argn == argc - 1) - devname = argv[argn]; + dev_name = argv[argn]; else usage(); @@ -232,7 +232,7 @@ void getgeom(void) if (override) return; - if ((fd= open(devname, O_RDONLY)) < 0) return; + if ((fd= open(dev_name, O_RDONLY)) < 0) return; r = ioctl(fd, DIOCGETP, &geom); close(fd); @@ -242,21 +242,21 @@ void getgeom(void) nsec = geom.sectors; ncyl = geom.cylinders; - printf("Geometry of %s: %dx%dx%d\n", devname, ncyl, nhead, nsec); + printf("Geometry of %s: %dx%dx%d\n", dev_name, ncyl, nhead, nsec); } static int devfd; void getboot(char *buffer) { - devfd = open(devname, 2); + devfd = open(dev_name, 2); if (devfd < 0) { - printf("No write permission on %s\n", devname); + printf("No write permission on %s\n", dev_name); readonly = 1; - devfd = open(devname, 0); + devfd = open(dev_name, 0); } if (devfd < 0) { - printf("Cannot open device %s\n", devname); + printf("Cannot open device %s\n", dev_name); exit(1); } if (read(devfd, buffer, SECSIZE) != SECSIZE) { @@ -264,7 +264,7 @@ void getboot(char *buffer) exit(1); } if (* (unsigned short *) &buffer[510] != 0xAA55) { - printf("Invalid boot sector on %s.\n", devname); + printf("Invalid boot sector on %s.\n", dev_name); printf("Partition table reset and boot code installed.\n"); memset(buffer, 0, 512); memcpy(buffer, bootstrap, sizeof(bootstrap)); @@ -514,8 +514,8 @@ int chk_table(void) printf( "Disk appears to have mis-specified number of heads or sectors.\n"); printf("Try fdisk -h%d -s%d %s instead of\n", - maxhead + 1, maxsec, devname); - printf(" fdisk -h%d -s%d %s\n", nhead, nsec, devname); + maxhead + 1, maxsec, dev_name); + printf(" fdisk -h%d -s%d %s\n", nhead, nsec, dev_name); seenpart = 0; } } else { @@ -695,12 +695,12 @@ void getboot(char *buffer) segread(&sregs); /* get ds */ - if (devname[1] != ':') { - printf("Invalid drive %s\n", devname); + if (dev_name[1] != ':') { + printf("Invalid drive %s\n", dev_name); exit(1); } - if (*devname >= 'a') *devname += 'A' - 'a'; - drivenum = (*devname - 'C') & 0xff; + if (*dev_name >= 'a') *dev_name += 'A' - 'a'; + drivenum = (*dev_name - 'C') & 0xff; if (drivenum < 0 || drivenum > 7) { printf("Funny drive number %d\n", drivenum); exit(1); diff --git a/include/stdlib.h b/include/stdlib.h index 2a13afddc..03a735e20 100644 --- a/include/stdlib.h +++ b/include/stdlib.h @@ -272,12 +272,10 @@ int cgetustr(char *, const char *, char **); void csetexpandtc(int); int daemon(int, int); -#ifndef __minix int devname_r(dev_t, mode_t, char *, size_t); #ifndef __LIBC12_SOURCE__ __aconst char *devname(dev_t, mode_t) __RENAME(__devname50); #endif -#endif /* !__minix */ #define HN_DECIMAL 0x01 #define HN_NOSPACE 0x02 diff --git a/lib/libc/gen/Makefile.inc b/lib/libc/gen/Makefile.inc index 85fcb7573..69d9e21f1 100644 --- a/lib/libc/gen/Makefile.inc +++ b/lib/libc/gen/Makefile.inc @@ -12,7 +12,7 @@ # closefrom.c confstr.c extattr.c getdevmajor.c \ # pthread_atfork.c setdomainname.c sethostname.c setproctitle.c \ # sysctl.c sysctlbyname.c sysctlgetmibinfo.c sysctlnametomib.c \ -# devname.c wait3.c +# wait3.c # To be ported # nlist.c nlist_aout.c nlist_coff.c nlist_ecoff.c nlist_elf32.c nlist_elf64.c @@ -26,7 +26,7 @@ SRCS+= _errno.c alarm.c alphasort.c arc4random.c assert.c basename.c clock.c \ closedir.c \ ctermid.c ctype_.c daemon.c \ - dehumanize_number.c dirname.c err.c errx.c \ + dehumanize_number.c devname.c dirname.c err.c errx.c \ errlist.c errno.c execl.c execle.c execlp.c execv.c execvp.c \ fmtcheck.c fmtmsg.c fnmatch.c fstab.c ftok.c \ fts.c ftw.c getbsize.c getcap.c getcwd.c \ diff --git a/lib/libc/gen/devname.c b/lib/libc/gen/devname.c index f6719108f..d48b51e77 100644 --- a/lib/libc/gen/devname.c +++ b/lib/libc/gen/devname.c @@ -49,6 +49,7 @@ __RCSID("$NetBSD: devname.c,v 1.22 2012/06/03 21:42:46 joerg Exp $"); __weak_alias(devname_r,_devname_r) #endif +#ifndef __minix static once_t db_opened = ONCE_INITIALIZER; static struct cdbr *db; static devmajor_t pts; @@ -101,6 +102,7 @@ devname_ptslookup(dev_t dev, mode_t type, char *path, size_t len) return ERANGE; return 0; } +#endif static int devname_fts(dev_t dev, mode_t type, char *path, size_t len) @@ -140,6 +142,7 @@ devname_r(dev_t dev, mode_t type, char *path, size_t len) { int rv; +#ifndef __minix thr_once(&db_opened, devname_dbopen); if (db != NULL) { @@ -154,6 +157,7 @@ devname_r(dev_t dev, mode_t type, char *path, size_t len) if (db != NULL) return ENOENT; +#endif rv = devname_fts(dev, type, path, len); return rv; } diff --git a/sys/stdlib.h b/sys/stdlib.h index 66f86c382..287bb29ae 100644 --- a/sys/stdlib.h +++ b/sys/stdlib.h @@ -267,11 +267,10 @@ int cgetustr(char *, const char *, char **); void csetexpandtc(int); int daemon(int, int); -#ifndef __minix +int devname_r(dev_t, mode_t, char *, size_t); #if !defined(__LIBC12_SOURCE__) && !defined(_STANDALONE) __aconst char *devname(dev_t, mode_t) __RENAME(__devname50); #endif -#endif /* !__minix */ #define HN_DECIMAL 0x01 #define HN_NOSPACE 0x02 diff --git a/usr.bin/stat/stat.c b/usr.bin/stat/stat.c index ec66fc0aa..2d3929bd0 100644 --- a/usr.bin/stat/stat.c +++ b/usr.bin/stat/stat.c @@ -44,12 +44,7 @@ __RCSID("$NetBSD: stat.c,v 1.36 2011/09/22 20:23:56 apb Exp $"); #define HAVE_STRUCT_STAT_ST_BIRTHTIME 1 #define HAVE_STRUCT_STAT_ST_BIRTHTIMENSEC 1 #define HAVE_STRUCT_STAT_ST_MTIMENSEC 1 -#ifdef __minix -/* Not supported in Minix. */ -#define HAVE_DEVNAME 0 -#else /* __minix */ #define HAVE_DEVNAME 1 -#endif /* __minx */ #endif /* HAVE_NBTOOL_CONFIG_H */ #include -- 2.44.0