From: Robert Spalek Date: Mon, 28 Jun 2004 09:38:20 +0000 (+0000) Subject: BCONFIG_CAN_OVERWRITE is a read/write parameter, i.e. the used can X-Git-Tag: holmes-import~994 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=61da975c346c50ccf9bb9cb7271ef538dc15ab32;p=libucw.git BCONFIG_CAN_OVERWRITE is a read/write parameter, i.e. the used can temporarily lower the rights. I need it somewhere. --- diff --git a/lib/bucket.c b/lib/bucket.c index 2b7dc27a..4a5533cf 100644 --- a/lib/bucket.c +++ b/lib/bucket.c @@ -2,6 +2,7 @@ * Sherlock Library -- Object Buckets * * (c) 2001--2004 Martin Mares + * (c) 2004 Robert Spalek * * 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; diff --git a/lib/fb-buffer.c b/lib/fb-buffer.c index 2e2d4454..2f52665f 100644 --- a/lib/fb-buffer.c +++ b/lib/fb-buffer.c @@ -2,6 +2,7 @@ * Sherlock Library -- Fast Buffered I/O on Static Buffers * * (c) 2003 Martin Mares + * (c) 2004 Robert Spalek * * This software may be freely distributed and used according to the terms * of the GNU Lesser General Public License. @@ -10,6 +11,19 @@ #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) { diff --git a/lib/fb-file.c b/lib/fb-file.c index 3b416de3..c33698e9 100644 --- a/lib/fb-file.c +++ b/lib/fb-file.c @@ -2,6 +2,7 @@ * Sherlock Library -- Fast Buffered I/O on Files * * (c) 1997--2002 Martin Mares + * (c) 2004 Robert Spalek * * 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; } diff --git a/lib/fb-limfd.c b/lib/fb-limfd.c index ac95d908..7e07e328 100644 --- a/lib/fb-limfd.c +++ b/lib/fb-limfd.c @@ -2,6 +2,7 @@ * Sherlock Library -- Fast Buffered Input on Limited File Descriptors * * (c) 2003 Martin Mares + * (c) 2004 Robert Spalek * * 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; } diff --git a/lib/fb-mem.c b/lib/fb-mem.c index efe749c5..82fe251e 100644 --- a/lib/fb-mem.c +++ b/lib/fb-mem.c @@ -2,6 +2,7 @@ * Sherlock Library -- Fast Buffered I/O on Memory Streams * * (c) 1997--2002 Martin Mares + * (c) 2004 Robert Spalek * * 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; }