From owner-freebsd-bugs@FreeBSD.ORG Mon Jun 28 23:00:42 2004 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 138EE16A4D2 for ; Mon, 28 Jun 2004 23:00:42 +0000 (GMT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 0B2BB43D46 for ; Mon, 28 Jun 2004 23:00:31 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.11/8.12.11) with ESMTP id i5SN0Uc2095519 for ; Mon, 28 Jun 2004 23:00:30 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.11/8.12.11/Submit) id i5SN0Uvs095518; Mon, 28 Jun 2004 23:00:30 GMT (envelope-from gnats) Resent-Date: Mon, 28 Jun 2004 23:00:30 GMT Resent-Message-Id: <200406282300.i5SN0Uvs095518@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Joao Carlos Mendes Luis Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 93DBF16A4CE for ; Mon, 28 Jun 2004 22:57:35 +0000 (GMT) Received: from coe.ufrj.br (roma.coe.ufrj.br [146.164.53.65]) by mx1.FreeBSD.org (Postfix) with ESMTP id D77D343D45 for ; Mon, 28 Jun 2004 22:57:34 +0000 (GMT) (envelope-from jonny@jonny.eng.br) Received: from localhost (localhost [127.0.0.1]) by coe.ufrj.br (Postfix) with ESMTP id E14BD1A326A8 for ; Mon, 28 Jun 2004 19:57:27 -0300 (BRT) Received: from coe.ufrj.br ([146.164.53.65]) by localhost (roma.coe.ufrj.br [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 50165-04 for ; Mon, 28 Jun 2004 19:57:25 -0300 (BRT) Received: by coe.ufrj.br (Postfix, from userid 2000) id 2319A1A326A7; Mon, 28 Jun 2004 19:57:25 -0300 (BRT) Message-Id: <20040628225725.2319A1A326A7@coe.ufrj.br> Date: Mon, 28 Jun 2004 19:57:25 -0300 (BRT) From: Joao Carlos Mendes Luis To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Subject: kern/68459: Patches to mknod(2) behave more like Linux X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: Joao Carlos Mendes Luis List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 28 Jun 2004 23:00:42 -0000 >Number: 68459 >Category: kern >Synopsis: Patches to mknod(2) behave more like Linux >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Mon Jun 28 23:00:30 GMT 2004 >Closed-Date: >Last-Modified: >Originator: Joao Carlos Mendes Luis >Release: FreeBSD 4.10-BETA i386 >Organization: Barradev Tecnologia Ltda. >Environment: System: FreeBSD roma.coe.ufrj.br 4.10-BETA FreeBSD 4.10-BETA #4: Fri Apr 16 03:25:06 BRT 2004 jonny@roma.coe.ufrj.br:/usr/cvsup/RELENG_4/src/sys/compile/ROMA i386 FreeBSD 4-stable VFS subsystem >Description: Here a copy of an email sent to -hackers: I´ve done some changes to the kernel mknod(2) handling to make it more compatible to the Linux behaviour, allowing one to create files of type VREG, VSOCK and VFIFO with mknod(2). I already know that BSD way is that one should use creat(2), bind(2) and mkfifo(2) functions for these, but, if all these are indeed vnodes, why bother if one use mkfifo(2) or mknod(2) to create fifos?? The only vnode type I think I left out is VDIR, because it needs to be initialized with "." and "..". I first came with this idea using rsync for a full backup, noticing it could not copy fifos or sockets. I could simply fix rsync, but I thought "fixing" FreeBSD would be a little bit funnier! To allow your appreciation, here are my patches. I am not an expert in VFS coding, so it should probably be checked by an expert before commiting. All I can say is that it worked for me. >How-To-Repeat: Here's a small test program: #include #include #include #include #include main() { mknod( "test1", S_IFSOCK|0777, 0 ); perror( "mknod" ); errno=0; mknod( "test2", S_IFIFO|0777, 0 ); perror( "mknod" ); errno=0; mknod( "test3", S_IFREG|0777, 0 ); perror( "mknod" ); errno=0; mknod( "test4", S_IFBLK|0777, 0 ); perror( "mknod" ); errno=0; mknod( "test5", S_IFCHR|0777, 0 ); perror( "mknod" ); errno=0; } >Fix: The following patches should be verified by a VFS expert. A merge to -current should follow, of course. --- RELENG_4/src/sys/kern/vfs_syscalls.c.orig Mon Jun 28 18:11:58 2004 +++ RELENG_4/src/sys/kern/vfs_syscalls.c Mon Jun 28 19:26:31 2004 @@ -1187,14 +1187,20 @@ register struct vnode *vp; struct vattr vattr; int error; - int whiteout = 0; + int vtype; struct nameidata nd; - switch (SCARG(uap, mode) & S_IFMT) { + vtype = SCARG(uap, mode) & S_IFMT; + switch ( vtype ) { case S_IFCHR: case S_IFBLK: error = suser(p); break; + case S_IFREG: + case S_IFIFO: + case S_IFSOCK: + error = 0; + break; default: error = suser_xxx(0, p, PRISON_ROOT); break; @@ -1202,7 +1208,7 @@ if (error) return (error); bwillwrite(); - NDINIT(&nd, CREATE, LOCKPARENT, UIO_USERSPACE, SCARG(uap, path), p); + NDINIT(&nd, CREATE, LOCKPARENT, (vtype==S_IFSOCK)?UIO_SYSSPACE:UIO_USERSPACE, SCARG(uap, path), p); if ((error = namei(&nd)) != 0) return (error); vp = nd.ni_vp; @@ -1212,9 +1218,8 @@ VATTR_NULL(&vattr); vattr.va_mode = (SCARG(uap, mode) & ALLPERMS) &~ p->p_fd->fd_cmask; vattr.va_rdev = SCARG(uap, dev); - whiteout = 0; - switch (SCARG(uap, mode) & S_IFMT) { + switch ( vtype ) { case S_IFMT: /* used by badsect to flag bad sectors */ vattr.va_type = VBAD; break; @@ -1224,8 +1229,17 @@ case S_IFBLK: vattr.va_type = VBLK; break; + case S_IFREG: + vattr.va_type = VREG; + break; + case S_IFSOCK: + vattr.va_type = VSOCK; + break; + case S_IFIFO: + vattr.va_type = VFIFO; + break; case S_IFWHT: - whiteout = 1; + /* NOTHING */ break; default: error = EINVAL; @@ -1234,9 +1248,18 @@ } if (!error) { VOP_LEASE(nd.ni_dvp, p, p->p_ucred, LEASE_WRITE); - if (whiteout) + switch ( vtype ) { + case S_IFWHT: error = VOP_WHITEOUT(nd.ni_dvp, &nd.ni_cnd, CREATE); - else { + break; + case S_IFREG: + case S_IFSOCK: + error = VOP_CREATE(nd.ni_dvp, &nd.ni_vp, + &nd.ni_cnd, &vattr); + if (error == 0) + vput(nd.ni_vp); + break; + default: error = VOP_MKNOD(nd.ni_dvp, &nd.ni_vp, &nd.ni_cnd, &vattr); if (error == 0) >Release-Note: >Audit-Trail: >Unformatted: