From 2e176c3bc5a4efd236873b8db4eeb2917d24e34e Mon Sep 17 00:00:00 2001 From: Miles Bader Date: Fri, 10 May 1996 20:34:16 +0000 Subject: (fd_get_device): Update to use libstore. : New include. --- ufs-utils/dlabel.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/ufs-utils/dlabel.c b/ufs-utils/dlabel.c index dbae0457..33db56da 100644 --- a/ufs-utils/dlabel.c +++ b/ufs-utils/dlabel.c @@ -25,33 +25,37 @@ #include #include /* Ick */ #include +#include static error_t fd_get_device (int fd, device_t *device) { error_t err; - string_t name; - int class, flags = 0; - size_t block_size; - off_t *runs = 0; - char *misc = 0; - size_t runs_len = 0, misc_len = 0; + struct store *store; file_t node = getdport (fd); if (node == MACH_PORT_NULL) return errno; - err = file_get_storage_info (node, &class, &runs, &runs_len, &block_size, - name, device, &misc, &misc_len, &flags); - if (!err) + err = store_create (node, &store); + if (! err) { - if (runs_len != 2 || runs[0] != 0 || class != STORAGE_DEVICE) - /* This doesn't seem to be a handle on the whole device; be picky. */ + if (store->class != STORAGE_DEVICE + /* In addition to requiring a device, we also want the *whole* + device -- one contiguous run starting at 0. */ + || store->num_runs != 1 + || store->runs[0].start != 0) err = ENODEV; - if (runs_len) - vm_deallocate (mach_task_self (), (vm_address_t)runs, runs_len); - if (misc_len) - vm_deallocate (mach_task_self (), (vm_address_t)misc, misc_len); + else if (store->port == MACH_PORT_NULL) + /* Usually getting a null port back means we didn't have sufficient + privileges. */ + err = EPERM; + else + { + *device = store->port; + store->port = MACH_PORT_NULL; /* Steal the port from STORE! */ + } + store_free (store); } mach_port_deallocate (mach_task_self (), node); -- cgit v1.2.3