- Define disk information, disk geometry, and disk partition dictionary

schemas.  Disk information and disk geometry are designed to replace
  information currently conveyed to user space using struct disklabel.
- Add a dk_info member to struct disk; a reference to a disk information
  dictionary.  This dictionary is to be allocated and the reference stored
  in struct disk by individual drivers.
- disk_detach0() will release dk_info if non-NULL.
- Convert the wd(4) driver to stash geometry and other disk properties
  as the "disk-info" property in its properties dictionary.  This needs
  some cleanup, but will serve as an example of what to do with other
  disk drivers.
This commit is contained in:
thorpej 2006-09-22 04:48:38 +00:00
parent ef731d9e00
commit 1edb40635e
3 changed files with 278 additions and 7 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: wd.c,v 1.329 2006/08/27 23:51:31 christos Exp $ */
/* $NetBSD: wd.c,v 1.330 2006/09/22 04:48:38 thorpej Exp $ */
/*
* Copyright (c) 1998, 2001 Manuel Bouyer. All rights reserved.
@ -66,7 +66,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: wd.c,v 1.329 2006/08/27 23:51:31 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: wd.c,v 1.330 2006/09/22 04:48:38 thorpej Exp $");
#ifndef ATADEBUG
#define ATADEBUG
@ -105,6 +105,8 @@ __KERNEL_RCSID(0, "$NetBSD: wd.c,v 1.329 2006/08/27 23:51:31 christos Exp $");
#include <sys/ataio.h>
#include "locators.h"
#include <prop/proplib.h>
#define LBA48_THRESHOLD (0xfffffff) /* 128GB / DEV_BSIZE */
#define WDIORETRIES_SINGLE 4 /* number of retries before single-sector */
@ -1674,6 +1676,59 @@ bad144intern(struct wd_softc *wd)
}
#endif
static void
wd_params_to_properties(struct wd_softc *wd, struct ataparams *params)
{
prop_dictionary_t disk_info, geom;
prop_string_t string;
prop_number_t number;
disk_info = prop_dictionary_create();
if (strcmp(wd->sc_params.atap_model, "ST506") == 0)
string = prop_string_create_cstring_nocopy("ST506");
else {
/* XXX Should have a case for ATA here, too. */
string = prop_string_create_cstring_nocopy("ESDI");
}
prop_dictionary_set(disk_info, "type", string);
prop_object_release(string);
geom = prop_dictionary_create();
number = prop_number_create_integer(wd->sc_capacity);
prop_dictionary_set(geom, "sectors-per-unit", number);
prop_object_release(number);
number = prop_number_create_integer(DEV_BSIZE /* XXX 512? */);
prop_dictionary_set(geom, "sector-size", number);
prop_object_release(number);
number = prop_number_create_integer(wd->sc_params.atap_sectors);
prop_dictionary_set(geom, "sectors-per-track", number);
prop_object_release(number);
number = prop_number_create_integer(wd->sc_params.atap_heads);
prop_dictionary_set(geom, "tracks-per-cylinder", number);
prop_object_release(number);
number = prop_number_create_integer(
(wd->sc_flags & WDF_LBA) ?
wd->sc_capacity / (wd->sc_params.atap_heads *
wd->sc_params.atap_sectors)
:
wd->sc_params.atap_cylinders);
prop_dictionary_set(geom, "cylinders-per-unit", number);
prop_object_release(number);
prop_dictionary_set(disk_info, "geometry", geom);
prop_object_release(geom);
prop_dictionary_set(device_properties(&wd->sc_dev),
"disk-info", disk_info);
prop_object_release(disk_info);
}
int
wd_get_params(struct wd_softc *wd, u_int8_t flags, struct ataparams *params)
{
@ -1695,8 +1750,9 @@ wd_get_params(struct wd_softc *wd, u_int8_t flags, struct ataparams *params)
params->atap_multi = 1;
params->atap_capabilities1 = params->atap_capabilities2 = 0;
wd->drvp->ata_vers = -1; /* Mark it as pre-ATA */
return 0;
/* FALLTHROUGH */
case CMD_OK:
wd_params_to_properties(wd, params);
return 0;
default:
panic("wd_get_params: bad return code from ata_get_params");

View File

@ -1,4 +1,4 @@
/* $NetBSD: subr_disk.c,v 1.80 2006/08/23 17:19:32 christos Exp $ */
/* $NetBSD: subr_disk.c,v 1.81 2006/09/22 04:48:38 thorpej Exp $ */
/*-
* Copyright (c) 1996, 1997, 1999, 2000 The NetBSD Foundation, Inc.
@ -74,7 +74,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: subr_disk.c,v 1.80 2006/08/23 17:19:32 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: subr_disk.c,v 1.81 2006/09/22 04:48:38 thorpej Exp $");
#include <sys/param.h>
#include <sys/kernel.h>
@ -224,6 +224,14 @@ disk_detach0(struct disk *diskp)
*/
iostat_free(diskp->dk_stats);
/*
* Release the disk-info dictionary.
*/
if (diskp->dk_info) {
prop_object_release(diskp->dk_info);
diskp->dk_info = NULL;
}
/*
* Free the space used by the disklabel structures.
*/

View File

@ -1,4 +1,4 @@
/* $NetBSD: disk.h,v 1.37 2006/09/13 00:47:03 christos Exp $ */
/* $NetBSD: disk.h,v 1.38 2006/09/22 04:48:38 thorpej Exp $ */
/*-
* Copyright (c) 1996, 1997, 2004 The NetBSD Foundation, Inc.
@ -91,6 +91,7 @@
#include <sys/queue.h>
#include <sys/lock.h>
#include <sys/iostat.h>
#include <prop/proplib.h>
struct buf;
struct disk;
@ -98,6 +99,70 @@ struct disklabel;
struct cpu_disklabel;
struct vnode;
/*
* Disk information dictionary.
*
* This contains general infomation for disk devices.
*
* <dict>
* <key>type</key>
* <string>...</string>
* <key>geometry</key>
* <dict>
* <!-- See below for disk geometry dictionary
* contents. -->
* </dict>
*
* <!-- optional information -->
* <key>rpm</key>
* <integer>...</integer>
* <key>sector-interleave</key>
* <integer>...</integer>
* <key>track-skew</key>
* <integer>...</integer>
* <key>cylinder-skew</key>
* <integer>...</integer>
* <key>head-switch-usecs</key>
* <integer>...</integer>
* <key>track-seek-usecs</key>
* <integer>...</integer>
* <key>removable</key>
* <false/>
* <key>ecc</key>
* <false/>
* <key>bad-sector-forwarding</key>
* <true/>
* <key>ramdisk</key>
* <false/>
* <key>back-to-back-transfers</key>
* <true/>
*
* <!-- additional information for SMD drives -->
* <key>smd-skip-sectoring</key>
* <false/>
* <!-- XXX better names for these properties -->
* <key>smd-mindist</key>
* <integer>...</integer>
* <key>smd-maxdist</key>
* <integer>...</integer>
* <key>smd-sdist</key>
* <integer>...</integer>
*
* <!-- additional information for ST506 drives -->
* <!-- XXX better names for these properties -->
* <key>st506-precompcyl</key>
* <integer>...</integer>
* <key>st506-gap3</key>
* <integer>...</integer>
*
* <!-- additional information for ATA drives -->
* <!-- XXX -->
*
* <!-- additional information for SCSI drives -->
* <!-- XXX -->
* </dict>
*/
/*
* dkwedge_info:
*
@ -168,10 +233,33 @@ __link_set_add_data(dkwedge_methods, name ## _ddm)
#define DKW_PTYPE_NTFS "ntfs"
/*
* Disk geometry information.
* Disk geometry dictionary.
*
* NOTE: Not all geometry information is relevant for every kind of disk.
*
* <dict>
* <key>sectors-per-unit</key>
* <integer>...</integer>
* <key>sector-size</key>
* <integer>...</integer>
* <key>sectors-per-track</key>
* <integer>...</integer>
* <key>tracks-per-cylinder</key>
* <integer>...</integer>
* <key>cylinders-per-unit</key>
* <integer>...</integer>
* <key>physical-cylinders-per-unit</key>
* <integer>...</integer>
* <key>spare-sectors-per-track</key>
* <integer>...</integer>
* <key>spare-sectors-per-cylinder</key>
* <integer>...</integer>
* <key>alternative-cylinders</key>
* <integer>...</integer>
* </dict>
* NOTE: Not all geometry information is relevant for every kind of disk.
*/
struct disk_geom {
int64_t dg_secperunit; /* # of data sectors per unit */
uint32_t dg_secsize; /* # of bytes per sector */
@ -196,9 +284,128 @@ struct disk_geom {
uint32_t dg_acylinders;
};
/*
* Disk partition dictionary.
*
* A partition is represented as a dictionary containing generic partition
* properties (such as starting block and block count), as well as information
* that is specific to individual partition map formats.
*
* <dict>
* <key>start-block</key>
* <integer>...</integer>
* <key>block-count</key>
* <integer>...</integer>
* <!-- DKW_PTYPE strings ("" or missing if unknown) -->
* <key>type</type>
* <string>...</string>
* <!-- optional -->
* <key>name</key>
* <string>...</string>
*
* <!-- these are valid for GPT partition maps -->
* <key>gpt-type-guid</key>
* <string>...</string>
* <key>gpt-partition-guid</key>
* <string>...</string>
* <key>gpt-platform-required</key>
* <false/>
*
* <!-- these are valid for 4.4BSD partition maps -->
* <key>bsd44-partition-type</key>
* <integer>...</integer>
* <key>bsd44-fs-fragment-size</key>
* <integer>...</integer>
* <key>bsd44-iso9660-session-offset</key>
* <integer>...</integer>
* <key>bsd44-ffs-cylinders-per-group</key>
* <integer>...</integer>
* <key>bsd44-lfs-segment-shift</key>
* <integer>...</integer>
*
* <!-- these are valid for NeXT partition maps -->
* <key>next-block-size</key>
* <integer>...</integer>
* <key>next-fs-fragment-size</key>
* <integer>...</integer>
* <key>next-fs-optimization</key>
* <string>...</string> <!-- "space" or "time" -->
* <key>next-fs-cylinders-per-group</key>
* <integer>...</integer>
* <key>next-bytes-per-inode-density</key>
* <integer>...</integer>
* <key>next-minfree-percentage</key>
* <integer>...</integer>
* <key>next-run-newfs-during-init</key>
* <false/>
* <key>next-mount-point</key>
* <string>...</string>
* <key>next-automount</key>
* <true/>
* <key>next-partition-type</key>
* <string>...</string>
*
* <!-- these are valid for MBR partition maps -->
* <key>mbr-start-head</key>
* <integer>...</integer>
* <key>mbr-start-sector</key>
* <integer>...</integer>
* <key>mbr-start-cylinder</key>
* <integer>...</integer>
* <key>mbr-partition-type</key>
* <integer>...</integer>
* <key>mbr-end-head</key>
* <integer>...</integer>
* <key>mbr-end-sector</key>
* <integer>...</integer>
* <key>mbr-end-cylinder</key>
* <integer>...</integer>
* <key>mbr-active-partition</key>
* <false/>
*
* <!-- these are valid for Apple partition maps -->
* <key>apple-partition-type</key>
* <string>...</string>
* <!-- XXX What else do we need? wrstuden? -->
*
* <!-- these are valid for RISCiX partition maps -->
* <key>riscix-partition-type</key>
* <integer>...</integer>
*
* <!-- these are valid for MIPS/SGI partition maps -->
* <key>mips-partition-type</key>
* <integer>...</integer>
*
* <!-- SunOS 4 partition maps have no specific
* additional information. Note, however,
* that SunOS 4 partitions must begin on
* cylinder boundaries. -->
*
* <!-- XXX Need Amiga partition map info -->
*
* <!-- these are valid for VTOC partition maps -->
* <key>vtoc-tag</key>
* <integer>...</integer>
* <key>vtoc-unmount</key>
* <false/>
* <key>vtoc-read-only</key>
* <false/>
* <!-- XXX is this really part of the partition info? -->
* <key>vtoc-timestamp</key>
* <integer>...</integer>
*
* <!-- mvme68k partition maps use 4.4BSD partition
* info stuffed into two different areas of the
* disk information label recognized by BUG. -->
*
* <!-- XXX What else? -->
* </dict>
*/
struct disk {
TAILQ_ENTRY(disk) dk_link; /* link in global disklist */
char *dk_name; /* disk name */
prop_dictionary_t dk_info; /* reference to disk-info dictionary */
int dk_bopenmask; /* block devices open */
int dk_copenmask; /* character devices open */
int dk_openmask; /* composite (bopen|copen) */