]> mj.ucw.cz Git - libucw.git/commitdiff
BCONFIG_CAN_OVERWRITE is a read/write parameter, i.e. the used can
authorRobert Spalek <robert@ucw.cz>
Mon, 28 Jun 2004 09:38:20 +0000 (09:38 +0000)
committerRobert Spalek <robert@ucw.cz>
Mon, 28 Jun 2004 09:38:20 +0000 (09:38 +0000)
temporarily lower the rights.  I need it somewhere.

lib/bucket.c
lib/fb-buffer.c
lib/fb-file.c
lib/fb-limfd.c
lib/fb-mem.c

index 2b7dc27a2e69129fd8878181242421709f6563ba..4a5533cfa6ef19e485e8a50d6d43429799b540f1 100644 (file)
@@ -2,6 +2,7 @@
  *     Sherlock Library -- Object Buckets
  *
  *     (c) 2001--2004 Martin Mares <mj@ucw.cz>
+ *     (c) 2004 Robert Spalek <robert@ucw.cz>
  *
  *     This software may be freely distributed and used according to the terms
  *     of the GNU Lesser General Public License.
@@ -130,6 +131,7 @@ obuck_unlock(void)
 
 struct fb_bucket {
   struct fastbuf fb;
+  int can_overwrite;
   sh_off_t start_pos;
   uns bucket_size;
   byte buffer[0];
@@ -301,12 +303,15 @@ obuck_find_next(struct obuck_header *hdrp, int full)
 }
 
 static int
-obuck_bconfig(struct fastbuf *f UNUSED, uns item, int value UNUSED)
+obuck_bconfig(struct fastbuf *f, uns item, int value)
 {
   switch (item)
     {
-    case BCONFIG_CAN_OVERWRITE:
-      return 2;
+    case BCONFIG_CAN_OVERWRITE: ;
+      int old_value = FB_BUCKET(f)->can_overwrite;
+      if (value >= 0 && value <= 2)
+       FB_BUCKET(f)->can_overwrite = value;
+      return old_value;
     default:
       return -1;
     }
@@ -370,6 +375,7 @@ obuck_create(u32 type)
   b->config = NULL;
   FB_BUCKET(b)->start_pos = start;
   FB_BUCKET(b)->bucket_size = 0;
+  FB_BUCKET(b)->can_overwrite = 2;
   bwrite(b, &obuck_create_hdr, sizeof(obuck_create_hdr));
 
   return b;
index 2e2d44541ff9cd87333baa85dd224e66fe3bcf72..2f52665f1bfbb879d69b9adaec550499b99a09e7 100644 (file)
@@ -2,6 +2,7 @@
  *     Sherlock Library -- Fast Buffered I/O on Static Buffers
  *
  *     (c) 2003 Martin Mares <mj@ucw.cz>
+ *     (c) 2004 Robert Spalek <robert@ucw.cz>
  *
  *     This software may be freely distributed and used according to the terms
  *     of the GNU Lesser General Public License.
 #include "lib/lib.h"
 #include "lib/fastbuf.h"
 
+static int
+fbbuf_config(struct fastbuf *f UNUSED, uns item, int value UNUSED)
+{
+  switch (item)
+    {
+    case BCONFIG_CAN_OVERWRITE:
+      // XXX: should we enable changing the value?
+      return 1;
+    default:
+      return -1;
+    }
+}
+
 static int
 fbbuf_refill(struct fastbuf *f UNUSED)
 {
@@ -27,7 +41,7 @@ fbbuf_init_read(struct fastbuf *f, byte *buf, uns size)
   f->spout = NULL;
   f->seek = NULL;
   f->close = NULL;
-  f->config = NULL;
+  f->config = fbbuf_config;
 }
 
 static void
@@ -36,18 +50,6 @@ fbbuf_spout(struct fastbuf *f UNUSED)
   die("fbbuf: buffer overflow on write");
 }
 
-static int
-fbbuf_config(struct fastbuf *f UNUSED, uns item, int value UNUSED)
-{
-  switch (item)
-    {
-    case BCONFIG_CAN_OVERWRITE:
-      return 1;
-    default:
-      return -1;
-    }
-}
-
 void
 fbbuf_init_write(struct fastbuf *f, byte *buf, uns size)
 {
index 3b416de3fb965c5a059f5b06a52ff8d15fd5bcb9..c33698e9d0d815738ef39eb0143dde933832549a 100644 (file)
@@ -2,6 +2,7 @@
  *     Sherlock Library -- Fast Buffered I/O on Files
  *
  *     (c) 1997--2002 Martin Mares <mj@ucw.cz>
+ *     (c) 2004 Robert Spalek <robert@ucw.cz>
  *
  *     This software may be freely distributed and used according to the terms
  *     of the GNU Lesser General Public License.
@@ -20,6 +21,7 @@ struct fb_file {
   struct fastbuf fb;
   int fd;                              /* File descriptor, -1 if not a real file */
   int is_temp_file;                    /* 0=normal file, 1=temporary file, delete on close, -1=shared FD */
+  int can_overwrite;
 };
 #define FB_FILE(f) ((struct fb_file *)(f)->is_fastbuf)
 
@@ -89,8 +91,11 @@ bfd_config(struct fastbuf *f, uns item, int value)
     case BCONFIG_IS_TEMP_FILE:
       FB_FILE(f)->is_temp_file = value;
       return 0;
-    case BCONFIG_CAN_OVERWRITE:
-      return 2;
+    case BCONFIG_CAN_OVERWRITE: ;
+      int old_value = FB_FILE(f)->can_overwrite;
+      if (value >= 0 && value <= 2)
+       FB_FILE(f)->can_overwrite = value;
+      return old_value;
     default:
       return -1;
     }
@@ -115,6 +120,7 @@ bfdopen_internal(int fd, uns buflen, byte *name)
   f->seek = bfd_seek;
   f->close = bfd_close;
   f->config = bfd_config;
+  F->can_overwrite = 2;
   return f;
 }
 
index ac95d908915b42fb3ea2f0c4145886c8e4c77f16..7e07e328f94a0d6de2bac582d9641fb412d86511 100644 (file)
@@ -2,6 +2,7 @@
  *     Sherlock Library -- Fast Buffered Input on Limited File Descriptors
  *
  *     (c) 2003 Martin Mares <mj@ucw.cz>
+ *     (c) 2004 Robert Spalek <robert@ucw.cz>
  *
  *     This software may be freely distributed and used according to the terms
  *     of the GNU Lesser General Public License.
@@ -17,6 +18,7 @@ struct fb_limfd {
   struct fastbuf fb;
   int fd;                              /* File descriptor */
   int limit;
+  int can_overwrite;
 };
 #define FB_LIMFD(f) ((struct fb_limfd *)(f)->is_fastbuf)
 
@@ -40,12 +42,15 @@ bfl_close(struct fastbuf *f)
 }
 
 static int
-bfl_config(struct fastbuf *f UNUSED, uns item, int value UNUSED)
+bfl_config(struct fastbuf *f, uns item, int value)
 {
   switch (item)
     {
-    case BCONFIG_CAN_OVERWRITE:
-      return 2;
+    case BCONFIG_CAN_OVERWRITE: ;
+      int old_value = FB_LIMFD(f)->can_overwrite;
+      if (value >= 0 && value <= 2)
+       FB_LIMFD(f)->can_overwrite = value;
+      return old_value;
     default:
       return -1;
     }
@@ -67,6 +72,7 @@ bopen_limited_fd(int fd, uns buflen, uns limit)
   f->refill = bfl_refill;
   f->close = bfl_close;
   f->config = bfl_config;
+  F->can_overwrite = 2;
   return f;
 }
 
index efe749c51ede07d18c1b1db6d4b2290ccd243e95..82fe251e9ec28413e155e7149c85bccac78873fd 100644 (file)
@@ -2,6 +2,7 @@
  *     Sherlock Library -- Fast Buffered I/O on Memory Streams
  *
  *     (c) 1997--2002 Martin Mares <mj@ucw.cz>
+ *     (c) 2004 Robert Spalek <robert@ucw.cz>
  *
  *     This software may be freely distributed and used according to the terms
  *     of the GNU Lesser General Public License.
@@ -29,6 +30,7 @@ struct fb_mem {
   struct fastbuf fb;
   struct memstream *stream;
   struct msblock *block;
+  int can_overwrite;
 };
 #define FB_MEM(f) ((struct fb_mem *)(f)->is_fastbuf)
 
@@ -150,12 +152,15 @@ fbmem_close(struct fastbuf *f)
 }
 
 static int
-fbmem_config(struct fastbuf *f UNUSED, uns item, int value UNUSED)
+fbmem_config(struct fastbuf *f, uns item, int value)
 {
   switch (item)
     {
-    case BCONFIG_CAN_OVERWRITE:
-      return 1;
+    case BCONFIG_CAN_OVERWRITE: ;
+      int old_value = FB_MEM(f)->can_overwrite;
+      if (value >= 0 && value <= 1)
+       FB_MEM(f)->can_overwrite = value;
+      return old_value;
     default:
       return -1;
     }
@@ -193,6 +198,7 @@ fbmem_clone_read(struct fastbuf *b)
   f->seek = fbmem_seek;
   f->close = fbmem_close;
   f->config = fbmem_config;
+  FB_MEM(f)->can_overwrite = 1;
   return f;
 }