Date: Thu, 9 Nov 2000 23:35:08 +1100 (EST) From: Bruce Evans <bde@zeta.org.au> To: Clive Lin <clive@CirX.ORG> Cc: Adrian Chadd <adrian@FreeBSD.org>, cvs-committers@FreeBSD.org, cvs-all@FreeBSD.org Subject: Re: cvs commit: src/sbin/badsect badsect.c Message-ID: <Pine.BSF.4.21.0011092300120.8223-100000@besplex.bde.org> In-Reply-To: <20001109173927.B67472@educampus.ncl.edu.tw>
next in thread | previous in thread | raw e-mail | index | archive | help
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 <sys/param.h> ! #include <sys/stat.h> #include <ufs/ffs/fs.h> --- 57,61 ---- */ #include <sys/param.h> ! #include <sys/mount.h> #include <ufs/ffs/fs.h> *************** *** 63,71 **** #include <err.h> - #include <dirent.h> #include <fcntl.h> #include <paths.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> --- 63,71 ---- #include <err.h> #include <fcntl.h> #include <paths.h> #include <stdio.h> #include <stdlib.h> + #include <string.h> #include <unistd.h> *************** *** 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.21.0011092300120.8223-100000>