Hi,
Here is another updated patch for libstore (which adds a store_set_size ()
call).
Thanks,
Ludovic.
diff -u libstore.20020912/ChangeLog libstore/ChangeLog
--- libstore.20020912/ChangeLog Thu Sep 12 23:00:02 2002
+++ libstore/ChangeLog Mon Sep 23 02:09:06 2002
@@ -1,3 +1,18 @@
+2002-09-22 Ludovic Court�s <[EMAIL PROTECTED]>
+
+ * file.c (file_set_size_): Update store->size.
+
+2002-09-12 Ludovic Court�s <[EMAIL PROTECTED]>
+
+ * store.h (struct store_class): Added a set_size () method.
+ * rdwr.c (store_set_size): New function.
+ * file.c (store_file_class): New function file_set_size_ () added.
+ * concat.c (store_concat_class): Likewise.
+ * copy.c (store_copy_class): Likewise.
+ * device.c (store_device_class): Likewise.
+ * stripe.c (store_ileave_class): Likewise.
+ * zero.c (store_zero_class): Likewise.
+
2002-06-07 Roland McGrath <[EMAIL PROTECTED]>
* store.h (struct store_enc): Use loff_t instead of off_t.
diff -u libstore.20020912/copy.c libstore/copy.c
--- libstore.20020912/copy.c Thu Sep 12 23:00:02 2002
+++ libstore/copy.c Thu Sep 12 23:00:27 2002
@@ -74,6 +74,13 @@
*amount = len;
return 0;
}
+
+static error_t
+copy_set_size (struct store *store, store_offset_t newsize)
+{
+ /* ... */
+ return EOPNOTSUPP;
+}
error_t
copy_allocate_encoding (const struct store *store, struct store_enc *enc)
@@ -159,7 +166,7 @@
const struct store_class
store_copy_class =
{
- STORAGE_COPY, "copy", copy_read, copy_write,
+ STORAGE_COPY, "copy", copy_read, copy_write, copy_set_size,
copy_allocate_encoding, copy_encode, copy_decode,
copy_set_flags, copy_clear_flags, copy_cleanup, copy_clone, 0, copy_open
};
diff -u libstore.20020912/device.c libstore/device.c
--- libstore.20020912/device.c Thu Sep 12 23:00:02 2002
+++ libstore/device.c Thu Sep 12 23:01:02 2002
@@ -70,6 +70,12 @@
}
static error_t
+dev_set_size (struct store *store, store_offset_t newsize)
+{
+ return EOPNOTSUPP;
+}
+
+static error_t
dev_decode (struct store_enc *enc, const struct store_class *const *classes,
struct store **store)
{
@@ -238,7 +244,7 @@
const struct store_class
store_device_class =
{
- STORAGE_DEVICE, "device", dev_read, dev_write,
+ STORAGE_DEVICE, "device", dev_read, dev_write, dev_set_size,
store_std_leaf_allocate_encoding, store_std_leaf_encode, dev_decode,
dev_set_flags, dev_clear_flags, 0, 0, 0, dev_open, 0, dev_map
};
diff -u libstore.20020912/file.c libstore/file.c
--- libstore.20020912/file.c Thu Sep 12 23:00:02 2002
+++ libstore/file.c Mon Sep 23 02:07:18 2002
@@ -27,6 +27,29 @@
#include "store.h"
+/* Return 0 if STORE's range is enforced by the filesystem, otherwise an
+ error. */
+static error_t
+enforced (struct store *store)
+{
+ if (store->num_runs != 1 || store->runs[0].start != 0)
+ /* Can't enforce non-contiguous ranges, or one not starting at 0. */
+ return EINVAL;
+ else
+ /* See if the the current (one) range is that the kernel is enforcing. */
+ {
+ struct stat st;
+ error_t err = io_stat (store->port, &st);
+
+ if (!err
+ && store->runs[0].length != (st.st_size >> store->log2_block_size))
+ /* The single run is not the whole file. */
+ err = EINVAL;
+
+ return err;
+ }
+}
+
static error_t
file_read (struct store *store,
store_offset_t addr, size_t index, size_t amount, void **buf,
@@ -46,6 +69,27 @@
}
static error_t
+file_set_size_ (struct store *store, store_offset_t newsize)
+{
+ error_t err;
+
+ if (enforced (store) != 0)
+ /* Bail out if there is more than a single run. */
+ return EOPNOTSUPP;
+
+ err = file_set_size (store->port, newsize);
+
+ if (! err)
+ {
+ /* Update STORE's size and run. */
+ store->size = newsize;
+ store->runs[0].length = newsize >> store->log2_block_size;
+ }
+
+ return err;
+}
+
+static error_t
file_decode (struct store_enc *enc, const struct store_class *const *classes,
struct store **store)
{
@@ -88,28 +132,7 @@
store->port = MACH_PORT_NULL;
}
-/* Return 0 if STORE's range is enforced by the filesystem, otherwise an
- error. */
-static error_t
-enforced (struct store *store)
-{
- if (store->num_runs != 1 || store->runs[0].start != 0)
- /* Can't enforce non-contiguous ranges, or one not starting at 0. */
- return EINVAL;
- else
- /* See if the the current (one) range is that the kernel is enforcing. */
- {
- struct stat st;
- error_t err = io_stat (store->port, &st);
-
- if (!err
- && store->runs[0].length != (st.st_size >> store->log2_block_size))
- /* The single run is not the whole file. */
- err = EINVAL;
- return err;
- }
-}
static error_t
file_set_flags (struct store *store, int flags)
@@ -192,7 +215,7 @@
const struct store_class
store_file_class =
{
- STORAGE_HURD_FILE, "file", file_read, file_write,
+ STORAGE_HURD_FILE, "file", file_read, file_write, file_set_size_,
store_std_leaf_allocate_encoding, store_std_leaf_encode, file_decode,
file_set_flags, file_clear_flags, 0, 0, 0, file_open, 0, file_map
};
@@ -218,7 +241,7 @@
struct store_class
store_file_byte_class =
{
- STORAGE_HURD_FILE, "file", file_byte_read, file_byte_write,
+ STORAGE_HURD_FILE, "file", file_byte_read, file_byte_write, file_set_size_,
store_std_leaf_allocate_encoding, store_std_leaf_encode, file_decode,
file_set_flags, file_clear_flags, 0, 0, 0, file_open, 0, file_map
};
diff -u libstore.20020912/rdwr.c libstore/rdwr.c
--- libstore.20020912/rdwr.c Thu Sep 12 23:00:02 2002
+++ libstore/rdwr.c Sat Sep 14 21:21:20 2002
@@ -285,3 +285,16 @@
return err;
}
}
+
+/* Set STORE's size to NEWSIZE (in bytes). */
+error_t
+store_set_size (struct store *store, off_t newsize)
+{
+ error_t err;
+ store_set_size_meth_t set_size = store->class->set_size;
+
+ /* Updating the runs list is up to the class set_size method. */
+ err = (* set_size) (store, newsize);
+
+ return err;
+}
diff -u libstore.20020912/store.h libstore/store.h
--- libstore.20020912/store.h Thu Sep 12 23:00:02 2002
+++ libstore/store.h Sat Sep 14 21:20:42 2002
@@ -132,6 +132,8 @@
store_offset_t addr, size_t index,
mach_msg_type_number_t amount,
void **buf, mach_msg_type_number_t *len);
+typedef error_t (*store_set_size_meth_t)(struct store *store,
+ store_offset_t newsize);
struct store_enc; /* fwd decl */
@@ -144,11 +146,13 @@
const char *name;
/* Read up to AMOUNT bytes at the underlying address ADDR from the storage
- into BUF and LEN. INDEX varies from 0 to the number of runs in STORE. */
+ into BUF and LEN. INDEX varies from 0 to the number of runs in STORE. */
store_read_meth_t read;
/* Write up to LEN bytes from BUF to the storage at the underlying address
- ADDR. INDEX varies from 0 to the number of runs in STORE. */
+ ADDR. INDEX varies from 0 to the number of runs in STORE. */
store_write_meth_t write;
+ /* Set store's size to NEWSIZE (in bytes). */
+ store_set_size_meth_t set_size;
/* To the lengths of each for the four arrays in ENC, add how much STORE
would need to be encoded. */
@@ -304,6 +308,9 @@
(as defined by STORE->block_size). Note that LEN is in bytes. */
error_t store_read (struct store *store,
store_offset_t addr, size_t amount, void **buf, size_t *len);
+
+/* Set STORE's size to NEWSIZE (in bytes). */
+error_t store_set_size (struct store *store, off_t newsize);
/* If STORE was created using store_create, remove the reference to the
source from which it was created. */
diff -u libstore.20020912/stripe.c libstore/stripe.c
--- libstore.20020912/stripe.c Thu Sep 12 23:00:02 2002
+++ libstore/stripe.c Thu Sep 12 23:06:24 2002
@@ -58,6 +58,12 @@
}
error_t
+stripe_set_size (struct store *store, store_offset_t newsize)
+{
+ return EOPNOTSUPP;
+}
+
+error_t
stripe_remap (struct store *source,
const struct store_run *runs, size_t num_runs,
struct store **store)
@@ -105,7 +111,7 @@
const struct store_class
store_ileave_class =
{
- STORAGE_INTERLEAVE, "interleave", stripe_read, stripe_write,
+ STORAGE_INTERLEAVE, "interleave", stripe_read, stripe_write, stripe_set_size,
ileave_allocate_encoding, ileave_encode, ileave_decode,
store_set_child_flags, store_clear_child_flags, 0, 0, stripe_remap
};
@@ -149,7 +155,7 @@
const struct store_class
store_concat_class =
{
- STORAGE_CONCAT, "concat", stripe_read, stripe_write,
+ STORAGE_CONCAT, "concat", stripe_read, stripe_write, stripe_set_size,
concat_allocate_encoding, concat_encode, concat_decode,
store_set_child_flags, store_clear_child_flags, 0, 0, stripe_remap,
store_concat_open
diff -u libstore.20020912/zero.c libstore/zero.c
--- libstore.20020912/zero.c Thu Sep 12 23:00:02 2002
+++ libstore/zero.c Thu Sep 12 23:07:01 2002
@@ -55,6 +55,12 @@
return 0;
}
+static error_t
+zero_set_size (struct store *store, store_offset_t newsize)
+{
+ return 0;
+}
+
/* Modify SOURCE to reflect those runs in RUNS, and return it in STORE. */
error_t
zero_remap (struct store *source,
@@ -173,7 +179,7 @@
const struct store_class
store_zero_class =
{
- STORAGE_ZERO, "zero", zero_read, zero_write,
+ STORAGE_ZERO, "zero", zero_read, zero_write, zero_set_size,
zero_allocate_encoding, zero_encode, zero_decode,
0, 0, 0, 0, zero_remap, zero_open, zero_validate_name,
zero_map