From 3cd1c5e506a878e234250b4d348b2b4dfafd407f Mon Sep 17 00:00:00 2001 From: Brandon Philips Date: Sat, 9 Sep 2006 22:38:44 -0500 Subject: [PATCH] make chunk files a parameter given by -o chunks="/path/tochunk1:/p/t/chunk2" Signed-off-by: Brandon Philips --- chunkfs.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++------------ 1 files changed, 67 insertions(+), 17 deletions(-) diff --git a/chunkfs.c b/chunkfs.c index fb4beb8..f5febdc 100644 --- a/chunkfs.c +++ b/chunkfs.c @@ -1,6 +1,5 @@ /* - * FUSE implementation of chunkfs techniques using libext2fs - * + * FUSE implementation of chunkfs techniques using libext2fs * * Copyright (C) 2006 Amit Gud * * This program can be distributed under the terms of the GNU GPL v2. @@ -10,6 +9,9 @@ #define FUSE_USE_VERSION 25 #include +#include +#include +#include #include #include #include @@ -20,9 +22,15 @@ #include "chunkfs.h" -/* chunk disks should be in the format chunk0.dsk, chunk1.dsk, ... */ -#define NR_CHUNKS 2 -#define CHUNKS "/chunkfs/disks" +#define MAX_CHUNKS 16 + +struct chunkfs { + char *chunks_param; + char *chunk_paths[MAX_CHUNKS]; + int nr_chunks; +}; + +static struct chunkfs *chunkfs; #define PATH_LEN 64 #define CONT_NAME "-cont" /* name to be prepended for continuation inodes */ @@ -32,7 +40,7 @@ */ #define CHUNK_SPACE_LEEWAY 16 /* chunk space hysteresis */ -chunk_t chunks[NR_CHUNKS] = {0}; +chunk_t chunks[MAX_CHUNKS] = {0}; int in_use; /* how many chunks are actually in use */ /* @@ -1201,18 +1209,11 @@ static void op_init(void *userdata) { errcode_t ret; int i; - char *device; - - device = (char *) malloc(strlen(CHUNKS) + 10); - - if(!device) { - printf("chunkfs: malloc error\n"); - exit(1); - } + char * device; in_use = 0; - for(i = 0; i < NR_CHUNKS; i++) { - sprintf(device, CHUNKS"/chunk%d.dsk", i); + for(i = 0; i < chunkfs->nr_chunks; i++) { + device = chunkfs->chunk_paths[i]; ret = ext2fs_open(device, EXT2_FLAG_RW | EXT2_FLAG_JOURNAL_DEV_OK, 0, 0, unix_io_manager, &chunks[in_use].fs); @@ -1247,7 +1248,6 @@ close_cont: } printf("chunkfs initialized with %d chunks\n", in_use); - free(device); } static void op_destroy(void *userdata) @@ -1297,6 +1297,42 @@ static struct fuse_lowlevel_ops chunkfs_ops = { .create = op_create, }; +#define CHUNKFS_OPT(t, p, v) { t, offsetof(struct chunkfs, p), v } +static struct fuse_opt chunkfs_opts[] = { + CHUNKFS_OPT("chunks=%s", chunks_param, 0), + FUSE_OPT_END +}; + +static int parse_chunks_param() +{ + char *start = chunkfs->chunks_param; + char *c = start; + char *buf = NULL; + + if (!chunkfs->chunks_param) goto error; + + while(*(c++)) { + if ((*c == ':' && (*(c - 1) != '\\')) || !*c) { + + buf = (char *)malloc((c - start + 1) * sizeof(char)); + strncpy(buf, start, (int)(c - start)); + + if (chunkfs->nr_chunks + 1 > MAX_CHUNKS) goto max_error; + + chunkfs->chunk_paths[chunkfs->nr_chunks++] = buf; + start = c + 1; + } + } + + return 0; + + +max_error: + free(buf); +error: + return -1; +} + int main(int argc, char *argv[]) { struct fuse_args args = FUSE_ARGS_INIT(argc, argv); @@ -1306,6 +1342,19 @@ int main(int argc, char *argv[]) struct fuse_session *se = NULL; struct fuse_chan *ch = NULL; + chunkfs = (struct chunkfs *)malloc(sizeof(struct chunkfs)); + if (!chunkfs) + goto error; + + bzero(chunkfs, sizeof(struct chunkfs)); + + if (fuse_opt_parse(&args, chunkfs, chunkfs_opts, NULL) < 0) + goto error; + + if (parse_chunks_param() < 0) { + printf("Invalid number of chunks specified\n"); + goto error; + } if (fuse_parse_cmdline(&args, &mountpoint, NULL, NULL) == -1) goto error; @@ -1327,6 +1376,7 @@ int main(int argc, char *argv[]) err = fuse_session_loop(se); error: + if (chunkfs) free(chunkfs); if (se) fuse_remove_signal_handlers(se); if (se) fuse_session_destroy(se); if (fd) close(fd); -- 1.4.4.1