From owner-svn-src-head@FreeBSD.ORG Thu Nov 20 21:18:20 2014 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 9F6DCA71; Thu, 20 Nov 2014 21:18:20 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::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 80C84DA4; Thu, 20 Nov 2014 21:18:20 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id sAKLIKOL077288; Thu, 20 Nov 2014 21:18:20 GMT (envelope-from imp@FreeBSD.org) Received: (from imp@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id sAKLIKcn077286; Thu, 20 Nov 2014 21:18:20 GMT (envelope-from imp@FreeBSD.org) Message-Id: <201411202118.sAKLIKcn077286@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: imp set sender to imp@FreeBSD.org using -f From: Warner Losh Date: Thu, 20 Nov 2014 21:18:20 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r274761 - head/sbin/fsck X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 20 Nov 2014 21:18:20 -0000 Author: imp Date: Thu Nov 20 21:18:19 2014 New Revision: 274761 URL: https://svnweb.freebsd.org/changeset/base/274761 Log: Back our r274750 until discussions on proper fix are over. Modified: head/sbin/fsck/fsck.c Modified: head/sbin/fsck/fsck.c ============================================================================== --- head/sbin/fsck/fsck.c Thu Nov 20 20:50:05 2014 (r274760) +++ head/sbin/fsck/fsck.c Thu Nov 20 21:18:19 2014 (r274761) @@ -41,7 +41,8 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include +#define FSTYPENAMES +#include #include #include @@ -80,21 +81,10 @@ static void addentry(struct fstypelist * static void maketypelist(char *); static void catopt(char **, const char *); static void mangle(char *, int *, const char ** volatile *, int *); -static const char *getfstype(const char *); +static const char *getfslab(const char *); static void usage(void) __dead2; static int isok(struct fstab *); -static struct { - const char *ptype; - const char *name; -} ptype_map[] = { - { "ufs", "ffs" }, - { "ffs", "ffs" }, - { "fat", "msdosfs" }, - { "efi", "msdosfs" }, - { NULL, NULL }, -}; - int main(int argc, char *argv[]) { @@ -213,7 +203,7 @@ main(int argc, char *argv[]) if ((fs = getfsfile(spec)) == NULL && (fs = getfsspec(spec)) == NULL) { if (vfstype == NULL) - vfstype = getfstype(spec); + vfstype = getfslab(spec); if (vfstype == NULL) errx(1, "Could not determine filesystem type"); type = vfstype; @@ -545,27 +535,41 @@ mangle(char *opts, int *argcp, const cha *maxargcp = maxargc; } + static const char * -getfstype(const char *str) +getfslab(const char *str) { - struct diocgattr_arg attr; - int fd, i; + struct disklabel dl; + int fd; + char p; + const char *vfstype; + u_char t; + /* deduce the file system type from the disk label */ if ((fd = open(str, O_RDONLY)) == -1) err(1, "cannot open `%s'", str); - strncpy(attr.name, "PART::type", sizeof(attr.name)); - memset(&attr.value, 0, sizeof(attr.value)); - attr.len = sizeof(attr.value); - if (ioctl(fd, DIOCGATTR, &attr) == -1) { + if (ioctl(fd, DIOCGDINFO, &dl) == -1) { (void) close(fd); return(NULL); } + (void) close(fd); - for (i = 0; ptype_map[i].ptype != NULL; i++) - if (strstr(attr.value.str, ptype_map[i].ptype) != NULL) - return (ptype_map[i].name); - return (NULL); + + p = str[strlen(str) - 1]; + + if ((p - 'a') >= dl.d_npartitions) + errx(1, "partition `%s' is not defined on disk", str); + + if ((t = dl.d_partitions[p - 'a'].p_fstype) >= FSMAXTYPES) + errx(1, "partition `%s' is not of a legal vfstype", + str); + + if ((vfstype = fstypenames[t]) == NULL) + errx(1, "vfstype `%s' on partition `%s' is not supported", + fstypenames[t], str); + + return vfstype; }