From amir@active.ath.cx  Thu Jun 10 12:13:25 2004
Return-Path: <amir@active.ath.cx>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP
	id BA80416A4CE; Thu, 10 Jun 2004 12:13:25 +0000 (GMT)
Received: from marco.bezeqint.net (marco.bezeqint.net [192.115.104.4])
	by mx1.FreeBSD.org (Postfix) with ESMTP
	id 2A8A643D1D; Thu, 10 Jun 2004 12:13:25 +0000 (GMT)
	(envelope-from amir@active.ath.cx)
Received: from marco.bezeqint.net (localhost [127.0.0.1])
	by marco.bezeqint.net (Bezeq International SMTP out Mail Server) with SMTP id 2891BFC92A;
	Thu, 10 Jun 2004 15:13:23 +0300 (IDT)
Received: from active.ath.cx ([IP=82.81.29.96]) by eSafe SMTP Relay 1086824256; Thu Jun 10 15:13:22 2004
Received: from localhost (localhost.active.ath.cx [127.0.0.1])
	by active.ath.cx (Postfix) with ESMTP id 45E8F5D09;
	Thu, 10 Jun 2004 15:13:22 +0300 (IDT)
Received: from active.ath.cx ([127.0.0.1])
 by localhost (active.ath.cx [127.0.0.1]) (amavisd-new, port 10024) with ESMTP
 id 52585-03; Thu, 10 Jun 2004 15:13:21 +0300 (IDT)
Received: by active.ath.cx (Postfix, from userid 1000)
	id DFADB5D08; Thu, 10 Jun 2004 15:13:20 +0300 (IDT)
Message-Id: <20040610121320.DFADB5D08@active.ath.cx>
Date: Thu, 10 Jun 2004 15:13:20 +0300 (IDT)
From: Amir Shalem <amir@active.ath.cx>
Reply-To: Amir Shalem <amir@boom.org.il>
To: FreeBSD-gnats-submit@freebsd.org
Cc: phk@FreeBSD.org
Subject: gbde doesn't complain correctly when file does not exists.
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         67793
>Category:       bin
>Synopsis:       gbde doesn't complain correctly when file does not exists.
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    pjd
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Jun 10 12:20:21 GMT 2004
>Closed-Date:    Thu Feb 03 14:48:33 GMT 2005
>Last-Modified:  Thu Feb 03 14:48:33 GMT 2005
>Originator:     Amir Shalem
>Release:        FreeBSD 5.2-CURRENT i386
>Organization:
None
>Environment:
System: FreeBSD active.ath.cx 5.2-CURRENT FreeBSD 5.2-CURRENT #0: Wed May 5 21:12:19 IDT 2004 amir@active.ath.cx:/usr/obj/usr/src/sys/ACTIVE i386


>Description:
	gbde doesn't open the device correctly, 
	it tries to open it with O_CREAT,
	which in case the file doesn't exists (or was given without /dev/)
	it creates it.

	beside creating the file, which doesn't fails,
	it tries than to ioctl() it, which fails ofcourse,
	so, what the user sees is:
	gbde: read: Inappropriate ioctl for device
	instand of:
	gbde: file: No such file or directory

>How-To-Repeat:
	in a directory where user can create files:
	$ gbde init ad0s1f
	$ gbde destroy test

	any command which involves setting doopen in gbde.c

>Fix:
	remove the O_CREAT flag.

--- gbde.c.orig Thu Jun 10 15:05:10 2004
+++ gbde.c      Thu Jun 10 15:01:13 2004
@@ -795,13 +795,13 @@
                }

        if (doopen) {
-               dfd = open(dest, O_RDWR | O_CREAT, 0644);
+               dfd = open(dest, O_RDWR, 0644);
                if (dfd < 0) {
                        if (snprintf(buf, sizeof(buf), "%s%s",
                            _PATH_DEV, dest) >= (ssize_t)sizeof(buf))
                                errno = ENAMETOOLONG;
                        else
-                               dfd = open(buf, O_RDWR | O_CREAT, 0644);
+                               dfd = open(buf, O_RDWR, 0644);
                }
                if (dfd < 0)
                        err(1, "%s", dest);


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->phk 
Responsible-Changed-By: simon 
Responsible-Changed-When: Thu Jun 10 19:10:31 GMT 2004 
Responsible-Changed-Why:  
Over to gbde author. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=67793 
Responsible-Changed-From-To: phk->pjd 
Responsible-Changed-By: pjd 
Responsible-Changed-When: Thu Feb 3 10:45:22 GMT 2005 
Responsible-Changed-Why:  
Steal responsibility from phk@, because I fixed this some time ago by myself 
and I've a patch ready to commit. 

My patch is very simlar to the one presented here, but it also removes 
file mode (this argument is not allowed when O_CREAT flag isn't used) 
and checks if file argument starts from "/dev/". 
It is available here: 

http://people.freebsd.org/~pjd/patches/gbde.c.3.patch 

Anyway, thanks for submission! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=67793 
State-Changed-From-To: open->closed 
State-Changed-By: pjd 
State-Changed-When: Thu Feb 3 14:48:05 GMT 2005 
State-Changed-Why:  
Fixed in -CURRENT, thanks! 
MFC after one week. 

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