From olgeni@colby.it  Fri Jul 24 20:07:28 2009
Return-Path: <olgeni@colby.it>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 7AD9C106566B
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 24 Jul 2009 20:07:28 +0000 (UTC)
	(envelope-from olgeni@colby.it)
Received: from jack.mail.tiscali.it (jack.mail.tiscali.it [213.205.33.53])
	by mx1.freebsd.org (Postfix) with ESMTP id 06C3D8FC1A
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 24 Jul 2009 20:07:27 +0000 (UTC)
	(envelope-from olgeni@colby.it)
Received: from olgeni.olgeni (94.36.172.211) by jack.mail.tiscali.it (8.0.022)
        id 499F036C053D1CC4 for FreeBSD-gnats-submit@freebsd.org; Fri, 24 Jul 2009 21:56:12 +0200
Received: from olgeni.olgeni (localhost [127.0.0.1])
	by olgeni.olgeni (8.14.3/8.14.3) with ESMTP id n6OJuBIv002332
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 24 Jul 2009 21:56:11 +0200 (CEST)
	(envelope-from olgeni@olgeni.olgeni)
Received: (from olgeni@localhost)
	by olgeni.olgeni (8.14.3/8.14.3/Submit) id n6OJuBxO002331;
	Fri, 24 Jul 2009 21:56:11 +0200 (CEST)
	(envelope-from olgeni)
Message-Id: <200907241956.n6OJuBxO002331@olgeni.olgeni>
Date: Fri, 24 Jul 2009 21:56:11 +0200 (CEST)
From: Jimmy Olgeni <olgeni@freebsd.org>
Reply-To:
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: missing "rw" option in mount(8) -p output
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         137101
>Category:       bin
>Synopsis:       [patch] missing "rw" option in mount(8) -p output
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Jul 24 20:10:06 UTC 2009
>Closed-Date:    Mon Aug 17 13:55:11 UTC 2009
>Last-Modified:  Mon Aug 17 13:55:11 UTC 2009
>Originator:     Jimmy Olgeni
>Release:        FreeBSD 7.2-STABLE i386
>Organization:
>Environment:
System: FreeBSD olgeni 7.2-STABLE FreeBSD 7.2-STABLE #0: Fri Jul 3 15:50:27 CEST 2009 root@localhost:/usr/obj/usr/src/sys/RELENG_7.i386 i386
>Description:
The -p option in mount(8) enables fstab_style, which is supposed
to print mount information in fstab(5) format.

If a mounted file system does not have any options specified
(MNT_NOEXEC, MNT_NOSUID) then the default "rw" option is printed.

However, if any of the MNT_* flags is present (MNT_RDONLY aside)
the "rw" option is skipped. If the output is used in an actual fstab
file, output similar to the following will occur during mounts, and
the corresponding mounts would fail:

fstab: /etc/fstab:6: Inappropriate file type or format
fstab: /etc/fstab:6: Inappropriate file type or format
mount: /storage: unknown special file or file system

>How-To-Repeat:
# mount -p
/dev/ad0s1a		/			ufs	noatime		1 1
/dev/ad0s1d		/var			ufs	noatime		2 2
/dev/ad0s1e		/usr			ufs	noatime		2 2
/dev/ad2s1f		/storage		ufs	noatime		2 2

The problem may be repeated by temporarily removing "rw" from any
non essential filesystem and trying to umount/mount it.

>Fix:

The following patch to src/sbin/mount/mount.c 1.96.2.3 (RELENG_7)
changes flags2opts to consider "rw" the opposite of "ro", even if
other options are defined.

The original check for NULL options is removed, since flags2opts
now always adds at least "rw" or "ro" to the option string.

--- mount.c.orig	2009-07-24 21:28:50.000000000 +0200
+++ mount.c	2009-07-24 21:39:02.000000000 +0200
@@ -857,10 +857,6 @@
 		    +1));
 	}
 
-	/*
-	 * "rw" is not a real mount option; this is why we print NULL as "rw"
-	 * if opts is still NULL here.
-	 */
 	l = strlen(ent->f_mntfromname);
 	printf("%s%s%s%s", ent->f_mntfromname,
 	    l < 8 ? "\t" : "",
@@ -872,13 +868,9 @@
 	    l < 16 ? "\t" : "",
 	    l < 24 ? "\t" : " ");
 	printf("%s\t", ent->f_fstypename);
-	if (opts == NULL) {
-		printf("%s\t", "rw");
-	} else {
-		l = strlen(opts);
-		printf("%s%s", opts,
-		    l < 8 ? "\t" : " ");
-	}
+	l = strlen(opts);
+	printf("%s%s", opts,
+	    l < 8 ? "\t" : " ");
 	free(opts);
 
 	if ((fst = getfsspec(ent->f_mntfromname)))
@@ -902,7 +894,11 @@
 
 	res = NULL;
 
-	if (flags & MNT_RDONLY)		res = catopt(res, "ro");
+	if (flags & MNT_RDONLY)
+		res = catopt(res, "ro");
+	else
+		res = catopt(res, "rw");
+
 	if (flags & MNT_SYNCHRONOUS)	res = catopt(res, "sync");
 	if (flags & MNT_NOEXEC)		res = catopt(res, "noexec");
 	if (flags & MNT_NOSUID)		res = catopt(res, "nosuid");

>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: linimon 
State-Changed-When: Mon Aug 17 13:52:32 UTC 2009 
State-Changed-Why:  
Apparently a duplicate of bin/123021. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=137101 
>Unformatted:
