From owner-freebsd-arch Sat Dec 22 17: 2:28 2001 Delivered-To: freebsd-arch@freebsd.org Received: from tomts9-srv.bellnexxia.net (tomts9.bellnexxia.net [209.226.175.53]) by hub.freebsd.org (Postfix) with ESMTP id E6A9037B416; Sat, 22 Dec 2001 17:02:16 -0800 (PST) Received: from khan.anarcat.dyndns.org ([65.94.189.35]) by tomts9-srv.bellnexxia.net (InterMail vM.4.01.03.16 201-229-121-116-20010115) with ESMTP id <20011223010215.PMYB3274.tomts9-srv.bellnexxia.net@khan.anarcat.dyndns.org>; Sat, 22 Dec 2001 20:02:15 -0500 Received: from shall.anarcat.dyndns.org (shall.anarcat.dyndns.org [192.168.0.1]) by khan.anarcat.dyndns.org (Postfix) with ESMTP id A0DDB1AB9; Sat, 22 Dec 2001 20:02:12 -0500 (EST) Received: by shall.anarcat.dyndns.org (Postfix, from userid 1000) id 7749020ACB; Sat, 22 Dec 2001 20:02:04 -0500 (EST) Date: Sat, 22 Dec 2001 20:02:03 -0500 From: The Anarcat To: gnats-admin@FreeBSD.org, freebsd-bugs@FreeBSD.org Cc: freebsd-gnats-submit@freebsd.org, arch@freebsd.org Subject: Re: bin/33070: libdisk::Disk_Names() returns empty strings Message-ID: <20011223010203.GF530@shall.anarcat.dyndns.org> References: <20011221220558.8DEB020ACD@shall.anarcat.dyndns.org> <200112212210.fBLMA1N83908@freefall.freebsd.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200112212210.fBLMA1N83908@freefall.freebsd.org> User-Agent: Mutt/1.3.24i Sender: owner-freebsd-arch@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG This is because of a commit to libdisk which disables the use of kern.disks because it doesn't sort its output. The alternate method of getting the disk list is to stat devices and try to open them which fails if you're a regular user. Here is a proper fix that sort the output of kern.disks in Disk_Names() instead. Index: Makefile =================================================================== RCS file: /home/ncvs/src/lib/libdisk/Makefile,v retrieving revision 1.27.2.5 diff -u -r1.27.2.5 Makefile --- Makefile 18 Sep 2001 06:47:30 -0000 1.27.2.5 +++ Makefile 22 Dec 2001 23:58:22 -0000 @@ -6,7 +6,7 @@ INCS= libdisk.h -# Remove KERN_DISKS_BROKEN when kern.disks sysctl returns disks in sorted order -CFLAGS+= -Wall -DKERN_DISKS_BROKEN +CFLAGS+= -Wall .if ${MACHINE} == "pc98" CFLAGS+= -DPC98 .endif Index: disk.c =================================================================== RCS file: /home/ncvs/src/lib/libdisk/disk.c,v retrieving revision 1.50.2.14 diff -u -r1.50.2.14 disk.c --- disk.c 18 Sep 2001 06:47:30 -0000 1.50.2.14 +++ disk.c 23 Dec 2001 00:43:01 -0000 @@ -483,10 +483,18 @@ static char * device_list[] = {"aacd", "ad", "da", "afd", "fla", "idad", "mlxd", "amrd", "twed", "ar", "fd", 0}; #endif +int qstrcmp(const void* a, const void* b) { + + char *str1 = *(char**)a; + char *str2 = *(char**)b; + return strcmp(str1, str2); + +} + char ** Disk_Names() { - int i,j,k; + int i,j,disk_cnt; char disk[25]; char diskname[25]; struct stat st; @@ -506,14 +514,16 @@ error = sysctlbyname("kern.disks", disklist, &listsize, NULL, 0); if (error) return NULL; - k = 0; - for (dp = disks; ((*dp = strsep(&disklist, " ")) != NULL) && k < MAX_NO_DISKS; k++, dp++); - return disks; - } + disk_cnt = 0; + for (dp = disks; ((*dp = strsep(&disklist, " ")) != NULL) && + disk_cnt < MAX_NO_DISKS; disk_cnt++, dp++); + } else { warn("kern.disks sysctl not available"); #endif - k = 0; + disk_cnt = 0; for (j = 0; device_list[j]; j++) { + if(disk_cnt >= MAX_NO_DISKS) + break; for (i = 0; i < MAX_NO_DISKS; i++) { sprintf(diskname, "%s%d", device_list[j], i); sprintf(disk, _PATH_DEV"%s", diskname); @@ -529,12 +539,17 @@ continue; } close(fd); - disks[k++] = strdup(diskname); - if(k == MAX_NO_DISKS) - return disks; + disks[disk_cnt++] = strdup(diskname); + if(disk_cnt >= MAX_NO_DISKS) + break; } } - return disks; +#if !defined(PC98) && !defined(KERN_DISKS_BROKEN) + } +#endif + qsort(disks, disk_cnt, sizeof(char*), qstrcmp); + + return disks; } #ifdef PC98 To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-arch" in the body of the message