From owner-svn-src-stable-11@freebsd.org Sat Mar 18 17:57:48 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 809D4D121AC; Sat, 18 Mar 2017 17:57:48 +0000 (UTC) (envelope-from trasz@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 557DC186C; Sat, 18 Mar 2017 17:57:48 +0000 (UTC) (envelope-from trasz@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v2IHvlMl058199; Sat, 18 Mar 2017 17:57:47 GMT (envelope-from trasz@FreeBSD.org) Received: (from trasz@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v2IHvlFs058198; Sat, 18 Mar 2017 17:57:47 GMT (envelope-from trasz@FreeBSD.org) Message-Id: <201703181757.v2IHvlFs058198@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: trasz set sender to trasz@FreeBSD.org using -f From: Edward Tomasz Napierala Date: Sat, 18 Mar 2017 17:57:47 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r315491 - stable/11/usr.sbin/diskinfo X-SVN-Group: stable-11 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 18 Mar 2017 17:57:48 -0000 Author: trasz Date: Sat Mar 18 17:57:47 2017 New Revision: 315491 URL: https://svnweb.freebsd.org/changeset/base/315491 Log: MFC r306094: Make it possible for diskinfo(8) to operate on files. This is useful with -t and upcoming -i. Modified: stable/11/usr.sbin/diskinfo/diskinfo.c Directory Properties: stable/11/ (props changed) Modified: stable/11/usr.sbin/diskinfo/diskinfo.c ============================================================================== --- stable/11/usr.sbin/diskinfo/diskinfo.c Sat Mar 18 17:50:49 2017 (r315490) +++ stable/11/usr.sbin/diskinfo/diskinfo.c Sat Mar 18 17:57:47 2017 (r315491) @@ -42,6 +42,7 @@ #include #include #include +#include #include static void @@ -61,6 +62,7 @@ static int zonecheck(int fd, uint32_t *z int main(int argc, char **argv) { + struct stat sb; int i, ch, fd, error, exitval = 0; char buf[BUFSIZ], ident[DISK_IDENT_SIZE], physpath[MAXPATHLEN]; char zone_desc[64]; @@ -92,7 +94,7 @@ main(int argc, char **argv) usage(); for (i = 0; i < argc; i++) { - fd = open(argv[i], O_RDONLY); + fd = open(argv[i], O_RDONLY | O_DIRECT); if (fd < 0 && errno == ENOENT && *argv[i] != '/') { snprintf(buf, BUFSIZ, "%s%s", _PATH_DEV, argv[i]); fd = open(buf, O_RDONLY); @@ -101,33 +103,48 @@ main(int argc, char **argv) warn("%s", argv[i]); exit(1); } - error = ioctl(fd, DIOCGMEDIASIZE, &mediasize); - if (error) { - warnx("%s: ioctl(DIOCGMEDIASIZE) failed, probably not a disk.", argv[i]); + error = fstat(fd, &sb); + if (error != 0) { + warn("cannot stat %s", argv[i]); exitval = 1; goto out; } - error = ioctl(fd, DIOCGSECTORSIZE, §orsize); - if (error) { - warnx("%s: ioctl(DIOCGSECTORSIZE) failed, probably not a disk.", argv[i]); - exitval = 1; - goto out; - } - error = ioctl(fd, DIOCGFWSECTORS, &fwsectors); - if (error) + if (S_ISREG(sb.st_mode)) { + mediasize = sb.st_size; + sectorsize = S_BLKSIZE; fwsectors = 0; - error = ioctl(fd, DIOCGFWHEADS, &fwheads); - if (error) fwheads = 0; - error = ioctl(fd, DIOCGSTRIPESIZE, &stripesize); - if (error) - stripesize = 0; - error = ioctl(fd, DIOCGSTRIPEOFFSET, &stripeoffset); - if (error) + stripesize = sb.st_blksize; stripeoffset = 0; - error = zonecheck(fd, &zone_mode, zone_desc, sizeof(zone_desc)); - if (error == 0) - zoned = 1; + } else { + error = ioctl(fd, DIOCGMEDIASIZE, &mediasize); + if (error) { + warnx("%s: ioctl(DIOCGMEDIASIZE) failed, probably not a disk.", argv[i]); + exitval = 1; + goto out; + } + error = ioctl(fd, DIOCGSECTORSIZE, §orsize); + if (error) { + warnx("%s: ioctl(DIOCGSECTORSIZE) failed, probably not a disk.", argv[i]); + exitval = 1; + goto out; + } + error = ioctl(fd, DIOCGFWSECTORS, &fwsectors); + if (error) + fwsectors = 0; + error = ioctl(fd, DIOCGFWHEADS, &fwheads); + if (error) + fwheads = 0; + error = ioctl(fd, DIOCGSTRIPESIZE, &stripesize); + if (error) + stripesize = 0; + error = ioctl(fd, DIOCGSTRIPEOFFSET, &stripeoffset); + if (error) + stripeoffset = 0; + error = zonecheck(fd, &zone_mode, zone_desc, sizeof(zone_desc)); + if (error == 0) + zoned = 1; + } if (!opt_v) { printf("%s", argv[i]); printf("\t%u", sectorsize);