diff options
author | Miles Bader <miles@gnu.org> | 1996-03-22 00:45:06 +0000 |
---|---|---|
committer | Miles Bader <miles@gnu.org> | 1996-03-22 00:45:06 +0000 |
commit | 67e2194049b5da9cb8c2474239fbaaf52ddffb36 (patch) | |
tree | 855dd14251f76a43a647b1b6f97abba7e87bff57 /libstore/encode.c | |
parent | 0ce7ce68d043d0177113752b7293ca74e1083718 (diff) |
Initial revision
Diffstat (limited to 'libstore/encode.c')
-rw-r--r-- | libstore/encode.c | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/libstore/encode.c b/libstore/encode.c new file mode 100644 index 00000000..240a55d2 --- /dev/null +++ b/libstore/encode.c @@ -0,0 +1,112 @@ +/* Store wire encoding + + 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 <string.h> + +#include "store.h" + +/* Default encoding used for most leaf store types. */ + +error_t +store_default_leaf_allocate_encoding (struct store *store, + struct store_enc *enc) +{ + enc->ports_len++; + enc->ints_len += 6; + enc->offsets_len += store->runs_len; + if (store->name) + enc->data_len += strlen (store->name) + 1; + enc->data_len += store->misc_len; + return 0; +} + +error_t +store_default_leaf_encode (struct store *store, struct store_enc *enc) +{ + size_t name_len = (store->name ? strlen (store->name) + 1 : 0); + + enc->ports[enc->cur_port++] = store->port; + + enc->ints[enc->cur_int++] = store->class; + enc->ints[enc->cur_int++] = store->flags; + enc->ints[enc->cur_int++] = store->block_size; + enc->ints[enc->cur_int++] = store->runs_len; + enc->ints[enc->cur_int++] = name_len; + enc->ints[enc->cur_int++] = 0; /* User can fill this in if wanted. */ + + for (i = 0; i < store->runs_len; i++) + enc->offsets[enc->cur_offset++] = store->runs[i]; + + if (store->name) + { + bcopy (store->name, enc->data + enc->cur_data, name_len); + enc->cur_data += name_len; + } + if (store->misc_len) + { + bcopy (store->misc, enc->data + enc->cur_data, store->misc_len); + enc->cur_data += store->misc_len; + } + + return 0; +} + +/* Encode STORE into ENC, or return an error. The contents of ENC may + then be return as the value of file_get_storage_info; if for some reason + this can't be done, store_enc_dealloc may be used to deallocate the + mmemory used by the unsent vectors. */ +error_t +store_encode (const struct store *store, struct store_enc *enc) +{ + error_t err; + struct store_meths *meths = store->meths; + + if (!meths->allocate_encoding || !meths->encoding) + return EOPNOTSUPP; + + bzero (enc, sizeof (*enc)); + + err = (*meths->allocate_encoding) (store, enc); + if (err) + return err; + + if (enc->ports_len > 0) + err = vm_allocate (mach_task_self (), + (vm_address_t *)&enc->ports, enc->ports_len, 1); + if (!err && enc->ints_len > 0) + err = vm_allocate (mach_task_self (), + (vm_address_t *)&enc->ints, enc->ints_len, 1); + if (!err && enc->offsets_len > 0) + err = vm_allocate (mach_task_self (), + (vm_address_t *)&enc->offsets, enc->offsets_len, 1); + if (!err && enc->data_len > 0) + err = vm_allocate (mach_task_self (), + (vm_address_t *)&enc->data, enc->data_len, 1); + + if (! err) + err = (*meths->encode) (store, enc); + + if (err) + store_enc_dealloc (enc); + + return err; +} |