From vova@sw.ru  Thu Apr 18 08:08:25 2002
Return-Path: <vova@sw.ru>
Received: from vbook.express.ru (asplinux.ru [195.133.213.194])
	by hub.freebsd.org (Postfix) with ESMTP id 4601237B41B
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 18 Apr 2002 08:08:24 -0700 (PDT)
Received: from vova by vbook.express.ru with local (Exim 3.35 #1)
	id 16yDWF-0000cK-00; Thu, 18 Apr 2002 19:08:19 +0400
Message-Id: <E16yDWF-0000cK-00@vbook.express.ru>
Date: Thu, 18 Apr 2002 19:08:19 +0400
From: Vladimir B.Grebenschikov <vova@sw.ru>
Sender: "Vladimir B. Grebenschikov" <vova@sw.ru>
Reply-To: Vladimir B.Grebenschikov <vova@sw.ru>
To: FreeBSD-gnats-submit@freebsd.org
Cc: vsilyaev@mindspring.com
Subject: VMWare do not work with raw disks due to invalid device hadling by linuxlator
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         37227
>Category:       kern
>Synopsis:       VMWare do not work with raw disks due to invalid device hadling by linuxlator
>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:   Thu Apr 18 08:10:01 PDT 2002
>Closed-Date:    Tue Apr 29 05:40:13 PDT 2003
>Last-Modified:  Thu Sep 11 03:30:11 PDT 2003
>Originator:     Vladimir B. Grebenschikov
>Release:        FreeBSD 5.0-CURRENT i386
>Organization:
SWsoft
>Environment:
System: FreeBSD vbook.express.ru 5.0-CURRENT FreeBSD 5.0-CURRENT #16: Tue Apr 9 12:13:44 MSD 2002 vova@vbook.express.ru:/usr/local/src/sys/i386/compile/VBOOK i386

-CURRENT kernel about  Tue Apr 9 12:13:44 MSD 
/usr/ports/emulators/vmware2 port

>Description:
When vmware tries to work with disk in "raw" mode it does some strange
magics actions to determine type of disk and in case of character device
(nowdays in FreeBSD) it failed to determine disk type validly.

>How-To-Repeat:
install /usr/ports/emulators/vmware2 port and try to use "raw" disk in
vmware, it will detect partitions right, but filed to start VirtualMachine

>Fix:

I found exactly same hack (BSD characted devices substituted to block device
for linux binaries) in newstat_copyout() and assume that this hack will help
in stat64_copyout() for vmware2 - it really helps.


Index: linux_stats.c
===================================================================
RCS file: /home/ncvs/src/sys/compat/linux/linux_stats.c,v
retrieving revision 1.40
diff -u -r1.40 linux_stats.c
--- linux_stats.c	2002/01/14 00:13:42	1.40
+++ linux_stats.c	2002/04/18 15:00:43
@@ -362,6 +362,8 @@
 stat64_copyout(struct stat *buf, void *ubuf)
 {
 	struct l_stat64 lbuf;
+        struct cdevsw *cdevsw;
+        dev_t dev;
 
 	bzero(&lbuf, sizeof(lbuf));
 	lbuf.st_dev = uminor(buf->st_dev) | (umajor(buf->st_dev) << 8);
@@ -377,6 +379,25 @@
 	lbuf.st_ctime = buf->st_ctime;
 	lbuf.st_blksize = buf->st_blksize;
 	lbuf.st_blocks = buf->st_blocks;
+
+
+        /* Lie about disk drives which are character devices
+         * in FreeBSD but block devices under Linux.
+         */
+        if (S_ISCHR(lbuf.st_mode) &&
+            (dev = udev2dev(buf->st_rdev, 0)) != NODEV) {
+                cdevsw = devsw(dev);
+                if (cdevsw != NULL && (cdevsw->d_flags & D_DISK)) {
+                        lbuf.st_mode &= ~S_IFMT;
+                        lbuf.st_mode |= S_IFBLK;
+
+                        /* XXX this may not be quite right */
+                        /* Map major number to 0 */
+                        lbuf.st_dev = uminor(buf->st_dev) & 0xf;
+                        lbuf.st_rdev = buf->st_rdev & 0xff;
+                }
+        }
+
 
 	/*
 	 * The __st_ino field makes all the difference. In the Linux kernel



>Release-Note:
>Audit-Trail:

From: "Vladimir B. " Grebenschikov <vova@sw.ru>
To: freebsd-gnats-submit@FreeBSD.org
Cc:  
Subject: Re: kern/37227: VMWare do not work with raw disks due to invalid
	device hadling by linuxlator
Date: 18 Apr 2002 20:18:06 +0500

 And more, I think this bug present on FreeBSD-4 after 4.3-RELEASE
 (whe block devices disappear)
 
 -- 
 SW Soft, Moscow
 Vladimir B. Grebenschikov, vova@sw.ru
 
State-Changed-From-To: open->closed 
State-Changed-By: mbr 
State-Changed-When: Tue Apr 29 05:39:55 PDT 2003 
State-Changed-Why:  
Committed, thanks ! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=37227 

From: "Rogier R. Mulhuijzen" <drwilco@drwilco.net>
To: freebsd-gnats-submit@FreeBSD.org
Cc:  
Subject: Re: kern/37227: VMWare do not work with raw disks due to invalid device hadling by linuxlator
Date: Thu, 11 Sep 2003 06:28:59 EDT

 The CVS log for the commit for the fix is dated "Tue Apr 29 12:36:03 2003 UTC" and says "MFC after:    2 weeks". However RELENG_4 still doesn't have the fix.
 
 Just thought I'd remind you =)
 
       DocWilco
>Unformatted:
