summaryrefslogtreecommitdiff
path: root/storeio/dev.c
diff options
context:
space:
mode:
authorRoland McGrath <roland@gnu.org>2000-03-19 20:55:45 +0000
committerRoland McGrath <roland@gnu.org>2000-03-19 20:55:45 +0000
commit402d7b0b9e63a112cf827482a41b3a9c18afbb0f (patch)
treeb551e7f36e6d30cdd1694890c400d566854e5458 /storeio/dev.c
parent85f3e87e0238f89ae9a4fa9c57bad675814107fd (diff)
2000-03-19 Roland McGrath <roland@baalperazim.frob.com>
* dev.h (struct dev): New members store_name, readonly, rdev. (dev_is_readonly): New inline function. * dev.c (dev_open): Take just one arg, a struct dev whose store==0. (dev_close): Shut down the store, but leave DEV intact with store==0. * storeio.c (struct storeio_argp_params): New type. (device, device_lock, store_name): Variables removed. (readonly, inhibit_cache, enforce_store, rdev): Likewise. These are all now members in struct storeio_argp_params or struct dev; rdev now uses dev_t instead of int. (parse_opt): Find a struct storeio_argp_params in STATE->input and fill it in accordingly. Use makedev macro to construct rdev. (trivfs_append_args): Find options in struct dev off control hook. Use major, minor macros. (main): Make DEVICE a local here, and point FSYS->hook at it. Don't modify trivfs_allow_open. (getroot_hook): New static function. (trivfs_getroot_hook): New variable, initialized to that. (check_open_hook): Find struct dev in CNTL->hook and use new dev_open interface. Use dev_is_readonly. (open_hook): Find struct dev in PEROPEN->cntl->hook and check DEV->store. (trivfs_modify_stat): Find struct dev in CRED->po->cntl->hook. Use dev_is_readonly. (trivfs_goaway): Find struct dev in FSYS->hook and use its lock. (trivfs_S_fsys_syncfs): Find struct dev in CNTL->hook.
Diffstat (limited to 'storeio/dev.c')
-rw-r--r--storeio/dev.c58
1 files changed, 25 insertions, 33 deletions
diff --git a/storeio/dev.c b/storeio/dev.c
index 0a713253..ba57f23f 100644
--- a/storeio/dev.c
+++ b/storeio/dev.c
@@ -1,8 +1,7 @@
/* store `device' I/O
- Copyright (C) 1995, 1996, 1998, 1999 Free Software Foundation, Inc.
-
- Written by Miles Bader <miles@gnu.ai.mit.edu>
+ Copyright (C) 1995,96,98,99,2000 Free Software Foundation, Inc.
+ Written by Miles Bader <miles@gnu.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
@@ -133,55 +132,49 @@ dev_buf_rw (struct dev *dev, size_t buf_offs, size_t *io_offs, size_t *len,
}
}
-/* Returns a pointer to a new device structure in DEV for the kernel device
- NAME, with the given FLAGS. If BLOCK_SIZE is non-zero, it should be the
- desired block size, and must be a multiple of the device block size.
- If an error occurs, the error code is returned, otherwise 0. */
+/* Called with DEV->lock held. Try to open the store underlying DEV. */
error_t
-dev_open (struct store_parsed *name, int flags, int inhibit_cache,
- struct dev **dev)
+dev_open (struct dev *dev)
{
error_t err;
- struct dev *new = malloc (sizeof (struct dev));
- if (! new)
- return ENOMEM;
+ assert (dev->store == 0);
- err = store_parsed_open (name, flags, &new->store);
+ err = store_parsed_open (dev->store_name,
+ dev->readonly ? STORE_READONLY : 0,
+ &dev->store);
if (err)
- {
- free (new);
- return err;
- }
+ return err;
- new->buf = mmap (0, new->store->block_size, PROT_READ|PROT_WRITE,
+ dev->buf = mmap (0, dev->store->block_size, PROT_READ|PROT_WRITE,
MAP_ANON, 0, 0);
- if (new->buf == (void *) -1)
+ if (dev->buf == MAP_FAILED)
{
- store_free (new->store);
- free (new);
+ store_free (dev->store);
+ dev->store = 0;
return ENOMEM;
}
- new->inhibit_cache = inhibit_cache;
- new->owner = 0;
- if (!inhibit_cache)
+ if (!dev->inhibit_cache)
{
- new->buf_offs = -1;
- rwlock_init (&new->io_lock);
- new->block_mask = (1 << new->store->log2_block_size) - 1;
- new->pager = 0;
- mutex_init (&new->pager_lock);
+ dev->buf_offs = -1;
+ rwlock_init (&dev->io_lock);
+ dev->block_mask = (1 << dev->store->log2_block_size) - 1;
+ dev->pager = 0;
+ mutex_init (&dev->pager_lock);
}
- *dev = new;
return 0;
}
-/* Free DEV and any resources it consumes. */
+/* Shut down the store underlying DEV and free any resources it consumes.
+ DEV itself remains intact so that dev_open can be called again.
+ This should be called with DEV->lock held. */
void
dev_close (struct dev *dev)
{
+ assert (dev->store);
+
if (!dev->inhibit_cache)
{
if (dev->pager != NULL)
@@ -193,8 +186,7 @@ dev_close (struct dev *dev)
}
store_free (dev->store);
-
- free (dev);
+ dev->store = 0;
}
/* Try and write out any pending writes to DEV. If WAIT is true, will wait