From owner-cvs-all Thu Nov 9 4:41:43 2000 Delivered-To: cvs-all@freebsd.org Received: from mailman.zeta.org.au (mailman.zeta.org.au [203.26.10.16]) by hub.freebsd.org (Postfix) with ESMTP id 0EBF137B479; Thu, 9 Nov 2000 04:41:34 -0800 (PST) Received: from bde.zeta.org.au (bde.zeta.org.au [203.2.228.102]) by mailman.zeta.org.au (8.8.7/8.8.7) with ESMTP id XAA22772; Thu, 9 Nov 2000 23:34:44 +1100 Date: Thu, 9 Nov 2000 23:35:08 +1100 (EST) From: Bruce Evans X-Sender: bde@besplex.bde.org To: Clive Lin Cc: Adrian Chadd , cvs-committers@FreeBSD.org, cvs-all@FreeBSD.org Subject: Re: cvs commit: src/sbin/badsect badsect.c In-Reply-To: <20001109173927.B67472@educampus.ncl.edu.tw> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-cvs-all@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On Thu, 9 Nov 2000, Clive Lin wrote: > Is it ok to close this PR ? bde talks too much , more than I could > catch :( > > http://www.FreeBSD.org/cgi/query-pr.cgi?pr=19574 My point in the followup about lots of dead code still applies. badsect used a readdir() loop instead of just statfs() because it wanted to find the character device corresponding to the mounted-on block device and not just the mounted-on device. This is now bogus. Lightly tested fixes relative to rev.1.8: --- diff -c2 badsect.c~ badsect.c *** badsect.c~ Thu Nov 9 22:55:28 2000 --- badsect.c Thu Nov 9 23:15:17 2000 *************** *** 57,61 **** */ #include ! #include #include --- 57,61 ---- */ #include ! #include #include *************** *** 63,71 **** #include - #include #include #include #include #include #include --- 63,71 ---- #include #include #include #include #include + #include #include *************** *** 104,134 **** daddr_t diskbn; daddr_t number; ! struct stat stbuf, devstat; ! register struct dirent *dp; ! DIR *dirp; ! char name[2 * MAXPATHLEN]; ! char *name_dir_end; if (argc < 3) usage(); ! if (chdir(argv[1]) < 0 || stat(".", &stbuf) < 0) err(2, "%s", argv[1]); ! strcpy(name, _PATH_DEV); ! if ((dirp = opendir(name)) == NULL) ! err(3, "%s", name); ! name_dir_end = name + strlen(name); ! while ((dp = readdir(dirp)) != NULL) { ! strcpy(name_dir_end, dp->d_name); ! if (lstat(name, &devstat) < 0) ! err(4, "%s", name); ! if (stbuf.st_dev == devstat.st_rdev && ! (devstat.st_mode & IFMT) == IFCHR) ! break; ! } ! closedir(dirp); ! if (dp == NULL) { ! printf("Cannot find dev 0%lo corresponding to %s\n", ! (u_long)stbuf.st_rdev, argv[1]); ! exit(5); } if ((fsi = open(name, O_RDONLY)) < 0) --- 104,122 ---- daddr_t diskbn; daddr_t number; ! struct statfs sfb; ! char namebuf[sizeof(_PATH_DEV) - 1 + MNAMELEN]; ! char *name; if (argc < 3) usage(); ! if (chdir(argv[1]) < 0 || statfs(".", &sfb) < 0) err(2, "%s", argv[1]); ! if (strcmp(sfb.f_fstypename, "ufs") != 0) ! errx(2, "badsect only works on ufs filesystems"); ! name = sfb.f_mntfromname; ! if (*name != '/') { ! strcpy(namebuf, _PATH_DEV); ! strcat(namebuf, name); ! name = namebuf; } if ((fsi = open(name, O_RDONLY)) < 0) --- Bruce To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe cvs-all" in the body of the message