tech-kern archive

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

DIOCGDISKINFO for dk(4)



Hi,

The attached patch adds DIOCGDISKINFO support to dk(4).

This allows getdiskinfo() (used by newfs, fsck, et. al.)
to not fall over on dk(4).

Comments?

        Jonathan Kollasch
Index: dkwedge/dk.c
===================================================================
RCS file: /local/netbsd/anoncvs/src/sys/dev/dkwedge/dk.c,v
retrieving revision 1.46
diff -u -r1.46 dk.c
--- dkwedge/dk.c        2 Jul 2009 00:56:48 -0000       1.46
+++ dkwedge/dk.c        17 Aug 2009 02:31:09 -0000
@@ -105,6 +105,8 @@
 static dev_type_dump(dkdump);
 static dev_type_size(dksize);
 
+static void    dk_set_dkinfo(struct dkwedge_softc *);
+
 const struct bdevsw dk_bdevsw = {
        dkopen, dkclose, dkstrategy, dkioctl, dkdump, dksize, D_DISK
 };
@@ -402,6 +404,8 @@
        strlcpy(dkw->dkw_devname, device_xname(sc->sc_dev),
                sizeof(dkw->dkw_devname));
 
+       dk_set_dkinfo(sc);
+
        /*
         * XXX Really ought to make the disk_attach() and the changing
         * of state to RUNNING atomic.
@@ -1200,11 +1204,17 @@
 dkioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l)
 {
        struct dkwedge_softc *sc = dkwedge_lookup(dev);
-       int error = 0;
+       int error;
 
        if (sc->sc_state != DKW_STATE_RUNNING)
                return (ENXIO);
 
+       error = disk_ioctl(&sc->sc_dk, cmd, data, flag, l);
+       if (error != EPASSTHROUGH)
+               return (error);
+
+       error = 0;
+
        switch (cmd) {
        case DIOCCACHESYNC:
                /*
@@ -1326,3 +1336,38 @@
 
        return rv;
 }
+
+static void
+dk_set_dkinfo(struct dkwedge_softc *sc)
+{
+       prop_dictionary_t odisk_info, disk_info, geom, pgeom ;
+       uint32_t sector_size;
+
+
+       geom = prop_dictionary_create();
+
+       pgeom = prop_dictionary_get(sc->sc_parent->dk_info, "geometry");
+       if (pgeom) {
+               if(prop_dictionary_get_uint32(pgeom, "sector-size",
+                   &sector_size))
+                       prop_dictionary_set_uint32(geom, "sector-size",
+                               sector_size);
+       } else {
+               /* XXX */
+               prop_dictionary_set_uint32(geom, "sector-size", DEV_BSIZE);
+       }
+
+       prop_dictionary_set_uint64(geom, "sectors-per-unit", sc->sc_size);
+
+       disk_info = prop_dictionary_create();
+
+       prop_dictionary_set(disk_info, "geometry", geom);
+       prop_object_release(geom);
+
+       prop_dictionary_set(device_properties(sc->sc_dev), "disk-info", 
disk_info);
+
+       odisk_info = sc->sc_dk.dk_info;
+       sc->sc_dk.dk_info = disk_info;
+       if (odisk_info)
+               prop_object_release(odisk_info);
+}


Home | Main Index | Thread Index | Old Index