Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev Make vnd_size (the returned size) 64 bit, keeping ol...



details:   https://anonhg.NetBSD.org/src/rev/f4ca3b35e646
branches:  trunk
changeset: 749723:f4ca3b35e646
user:      dsl <dsl%NetBSD.org@localhost>
date:      Sun Dec 06 16:33:18 2009 +0000

description:
Make vnd_size (the returned size) 64 bit, keeping old field for ioctl
compatibility. Both fields are now unsigned.
Add compatibility for the old ioctl size.
Detect and error files which are definitely sparse (va_bytes < va_size).
Part of fix for PR/41873.

diffstat:

 sys/dev/vnd.c    |  26 +++++++++++++++++++++++---
 sys/dev/vndvar.h |  11 +++++++++--
 2 files changed, 32 insertions(+), 5 deletions(-)

diffs (111 lines):

diff -r 93050b1ec8e9 -r f4ca3b35e646 sys/dev/vnd.c
--- a/sys/dev/vnd.c     Sun Dec 06 16:15:15 2009 +0000
+++ b/sys/dev/vnd.c     Sun Dec 06 16:33:18 2009 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vnd.c,v 1.204 2009/08/07 00:08:07 dyoung Exp $ */
+/*     $NetBSD: vnd.c,v 1.205 2009/12/06 16:33:18 dsl Exp $    */
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2008 The NetBSD Foundation, Inc.
@@ -130,7 +130,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vnd.c,v 1.204 2009/08/07 00:08:07 dyoung Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vnd.c,v 1.205 2009/12/06 16:33:18 dsl Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "fs_nfs.h"
@@ -1037,6 +1037,10 @@
        switch (cmd) {
        case VNDIOCSET:
        case VNDIOCCLR:
+#ifdef VNDIOOCSET
+       case VNDIOOCSET:
+       case VNDIOOCCLR:
+#endif
        case DIOCSDINFO:
        case DIOCWDINFO:
 #ifdef __HAVE_OLD_DISKLABEL
@@ -1052,6 +1056,9 @@
        /* Must be initialized for these... */
        switch (cmd) {
        case VNDIOCCLR:
+#ifdef VNDIOOCCLR
+       case VNDIOOCCLR:
+#endif
        case DIOCGDINFO:
        case DIOCSDINFO:
        case DIOCWDINFO:
@@ -1071,6 +1078,9 @@
        }
 
        switch (cmd) {
+#ifdef VNDIOOCSET
+       case VNDIOOCSET:
+#endif
        case VNDIOCSET:
                if (vnd->sc_flags & VNF_INITED)
                        return EBUSY;
@@ -1088,6 +1098,9 @@
                error = VOP_GETATTR(nd.ni_vp, &vattr, l->l_cred);
                if (!error && nd.ni_vp->v_type != VREG)
                        error = EOPNOTSUPP;
+               if (!error && vattr.va_bytes < vattr.va_size)
+                       /* File is definitely sparse, reject here */
+                       error = EINVAL;
                if (error) {
                        VOP_UNLOCK(nd.ni_vp, 0);
                        goto close_and_exit;
@@ -1272,7 +1285,11 @@
                        goto close_and_exit;
 
                vndthrottle(vnd, vnd->sc_vp);
-               vio->vnd_size = dbtob(vnd->sc_size);
+               vio->vnd_osize = dbtob(vnd->sc_size);
+#ifdef VNDIOOCSET
+               if (cmd != VNDIOOCSET)
+#endif
+                       vio->vnd_size = dbtob(vnd->sc_size);
                vnd->sc_flags |= VNF_INITED;
 
                /* create the kernel thread, wait for it to be up */
@@ -1328,6 +1345,9 @@
                vndunlock(vnd);
                return error;
 
+#ifdef VNDIOOCCLR
+       case VNDIOOCCLR:
+#endif
        case VNDIOCCLR:
                part = DISKPART(dev);
                pmask = (1 << part);
diff -r 93050b1ec8e9 -r f4ca3b35e646 sys/dev/vndvar.h
--- a/sys/dev/vndvar.h  Sun Dec 06 16:15:15 2009 +0000
+++ b/sys/dev/vndvar.h  Sun Dec 06 16:33:18 2009 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vndvar.h,v 1.24 2009/04/30 22:36:10 dyoung Exp $       */
+/*     $NetBSD: vndvar.h,v 1.25 2009/12/06 16:33:18 dsl Exp $  */
 
 /*-
  * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc.
@@ -125,7 +125,8 @@
        char            *vnd_file;      /* pathname of file to mount */
        int             vnd_flags;      /* flags; see below */
        struct vndgeom  vnd_geom;       /* geometry to emulate */
-       int             vnd_size;       /* (returned) size of disk */
+       unsigned int    vnd_osize;      /* (returned) size of disk */
+       uint64_t        vnd_size;       /* (returned) size of disk */
 };
 
 /* vnd_flags */
@@ -213,3 +214,9 @@
 #define VNDIOCSET      _IOWR('F', 0, struct vnd_ioctl) /* enable disk */
 #define VNDIOCCLR      _IOW('F', 1, struct vnd_ioctl)  /* disable disk */
 #define VNDIOCGET      _IOWR('F', 3, struct vnd_user)  /* get list */
+
+/* These only have the 32bit vnd_osize field */
+#define VNDIOOCSET     _IOC(IOC_INOUT, 'F', 0, \
+                               offsetof(struct vnd_ioctl, vnd_size))
+#define VNDIOOCCLR     _IOC(IOC_IN, 'F', 1, \
+                               offsetof(struct vnd_ioctl, vnd_size))



Home | Main Index | Thread Index | Old Index