diff options
author | Miles Bader <miles@gnu.org> | 1996-05-22 00:20:02 +0000 |
---|---|---|
committer | Miles Bader <miles@gnu.org> | 1996-05-22 00:20:02 +0000 |
commit | b7de385d10b581c8118d44495b15fee55c903c98 (patch) | |
tree | fedeb7410da7dde9132fc02a4b0564454a525a3a /libstore | |
parent | 5ef1a9b75fde165f24c51e6483abf5966aead01f (diff) |
Initial revision
Diffstat (limited to 'libstore')
-rw-r--r-- | libstore/flags.c | 64 | ||||
-rw-r--r-- | libstore/kids.c | 102 | ||||
-rw-r--r-- | libstore/null.c | 109 | ||||
-rw-r--r-- | libstore/std.c | 33 |
4 files changed, 308 insertions, 0 deletions
diff --git a/libstore/flags.c b/libstore/flags.c new file mode 100644 index 00000000..5d2ce74b --- /dev/null +++ b/libstore/flags.c @@ -0,0 +1,64 @@ +/* Setting various store flags + + Copyright (C) 1996 Free Software Foundation, Inc. + + Written by Miles Bader <miles@gnu.ai.mit.edu> + + This file is part of the GNU Hurd. + + The GNU Hurd is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2, or (at + your option) any later version. + + The GNU Hurd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ + +#include <malloc.h> +#include <string.h> + +#include "store.h" + +/* Add FLAGS to STORE's currently set flags. */ +error_t +store_set_flags (struct store *store, int flags) +{ + error_t err = 0; + int orig = store->flags, new = flags & ~orig; + + if (new & STORE_BACKEND_FLAGS) + if (store->class->set_flags) + err = (*store->class->set_flags) (store, new); + else + err = EINVAL; + + if (! err) + store->flags |= (new & ~STORE_BACKEND_FLAGS); + + return err; +} + +/* Remove FLAGS from STORE's currently set flags. */ +error_t +store_clear_flags (struct store *store, int flags) +{ + error_t err = 0; + int orig = store->flags, kill = flags & orig; + + if (kill & STORE_BACKEND_FLAGS) + if (store->class->clear_flags) + err = (*store->class->clear_flags) (store, kill); + else + err = EINVAL; + + if (! err) + store->flags &= ~(kill & ~STORE_BACKEND_FLAGS); + + return err; +} diff --git a/libstore/kids.c b/libstore/kids.c new file mode 100644 index 00000000..7c6cf51d --- /dev/null +++ b/libstore/kids.c @@ -0,0 +1,102 @@ +/* Managing sub-stores + + Copyright (C) 1995, 1996 Free Software Foundation, Inc. + + Written by Miles Bader <miles@gnu.ai.mit.edu> + + This file is part of the GNU Hurd. + + The GNU Hurd is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2, or (at + your option) any later version. + + The GNU Hurd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ + +#include <malloc.h> +#include <string.h> + +#include "store.h" + +/* Set STORE's current children list to (a copy of) CHILDREN and NUM_CHILDREN. */ +error_t +store_set_children (struct store *store, + struct store *const *children, unsigned num_children) +{ + unsigned size = num_children * sizeof (struct store_run); + struct store **copy = malloc (size); + + if (!copy) + return ENOMEM; + + if (store->children) + free (store->children); + + bcopy (children, copy, size); + store->children = copy; + store->num_children = num_children; + + return 0; +} + +/* Calls the allocate_encoding method in each child store of STORE, + propagating any errors. If any child does not hae such a method, + EOPNOTSUPP is returned. */ +error_t +store_allocate_child_encodings (const struct store *store, + struct store_enc *enc) +{ + int i; + error_t err = 0; + for (i = 0; i < store->num_children && !err; i++) + { + struct store *k = store->children[i]; + if (k->class->allocate_encoding) + (*k->class->allocate_encoding) (store, enc); + else + err = EOPNOTSUPP; + } + return err; +} + +/* Calls the encode method in each child store of STORE, propagating any + errors. If any child does not hae such a method, EOPNOTSUPP is returned. */ +error_t +store_encode_children (const struct store *store, struct store_enc *enc) +{ + int i; + error_t err = 0; + for (i = 0; i < store->num_children && !err; i++) + { + struct store *k = store->children[i]; + if (k->class->encode) + (*k->class->encode) (store, enc); + else + err = EOPNOTSUPP; + } + return err; +} + +/* Decodes NUM_CHILDREN from ENC, storing the results into successive + positions in CHILDREN. */ +error_t +store_decode_children (struct store_enc *enc, int num_children, + struct store_class *classes, struct store **children) +{ + int i; + error_t err = 0; + for (i = 0; i < num_children && !err; i++) + err = store_decode (enc, classes, &children[i]); + if (err) + /* Deallocate anything we've already created. */ + while (--i >= 0) + store_free (children[i]); + return err; +} diff --git a/libstore/null.c b/libstore/null.c new file mode 100644 index 00000000..dd30ded1 --- /dev/null +++ b/libstore/null.c @@ -0,0 +1,109 @@ +/* Null store backend + + Copyright (C) 1995, 1996 Free Software Foundation, Inc. + + Written by Miles Bader <miles@gnu.ai.mit.edu> + + This file is part of the GNU Hurd. + + The GNU Hurd is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2, or (at + your option) any later version. + + The GNU Hurd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ + +#include <assert.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "store.h" + +static error_t +null_read (struct store *store, + off_t addr, size_t index, mach_msg_type_number_t amount, + char **buf, mach_msg_type_number_t *len) +{ + if (*len < amount) + { + error_t err = + vm_allocate (mach_task_self (), (vm_address_t *)buf, amount, 1); + if (! err) + *len = amount; + return err; + } + else + { + bzero (*buf, amount); + *len = amount; + return 0; + } +} + +static error_t +null_write (struct store *store, + off_t addr, size_t index, char *buf, mach_msg_type_number_t len, + mach_msg_type_number_t *amount) +{ + return 0; +} + +error_t +null_allocate_encoding (const struct store *store, struct store_enc *enc) +{ + enc->num_ints += 2; + enc->num_offsets += 1; + return 0; +} + +error_t +null_encode (const struct store *store, struct store_enc *enc) +{ + enc->ints[enc->cur_int++] = store->class->id; + enc->ints[enc->cur_int++] = store->flags; + enc->offsets[enc->cur_offset++] = store->size; + return 0; +} + +error_t +null_decode (struct store_enc *enc, struct store_class *classes, + struct store **store) +{ + off_t size; + int type, flags; + + if (enc->cur_int + 2 > enc->num_ints + || enc->cur_offset + 1 > enc->num_offsets) + return EINVAL; + + type = enc->ints[enc->cur_int++]; + flags = enc->ints[enc->cur_int++]; + size = enc->offsets[enc->cur_offset++]; + + return store_null_create (size, flags, store); +} + +static struct store_class +null_class = +{ + STORAGE_NULL, "null", null_read, null_write, + null_allocate_encoding, null_encode, null_decode +}; +_STORE_STD_CLASS (null_class); + +/* Return a new null store SIZE bytes long in STORE. */ +error_t +store_null_create (size_t size, int flags, struct store **store) +{ + struct store_run run = { 0, size }; + *store = _make_store (&null_class, MACH_PORT_NULL, flags, 1, &run, 1, 0); + return *store ? 0 : ENOMEM; +} diff --git a/libstore/std.c b/libstore/std.c new file mode 100644 index 00000000..37edc73b --- /dev/null +++ b/libstore/std.c @@ -0,0 +1,33 @@ +/* List of standard store classes + + Copyright (C) 1996 Free Software Foundation, Inc. + + Written by Miles Bader <miles@gnu.ai.mit.edu> + + This file is part of the GNU Hurd. + + The GNU Hurd is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2, or (at + your option) any later version. + + The GNU Hurd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ + +#include "store.h" + +struct store_class * +store_std_classes = 0; + +void +_store_add_std_class (struct store_class *class) +{ + class->next = store_std_classes; + store_std_classes = class; +} |