commit 9903072cf148f1300844265c34a19b18d9ddd90a
parent e7eeca1ca087c7f38e07e8da8e55fe10890d31a9
Author: Tomas Hlavaty <tom@logand.com>
Date: Sun, 29 May 2011 16:27:52 +0200
odrawfs uses fuse
Diffstat:
M | odrawfs.c | | | 155 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------- |
1 file changed, 129 insertions(+), 26 deletions(-)
diff --git a/odrawfs.c b/odrawfs.c
@@ -16,9 +16,10 @@ typedef uint32_t dword;
typedef uint64_t filetime;
typedef uint64_t ulonglong;
+#define PATH_MAX 1024
+
char *filename;
-char *dir;
-FILE *stream;
+static char cwd[PATH_MAX]; // fuse changes cwd:-{
struct shorter_stream {
FILE *wrap;
@@ -58,7 +59,7 @@ struct RecordHeader {
dword recLen;
} __attribute__((__packed__));
-static int read_RecordHeader(struct RecordHeader *x) {
+static int read_RecordHeader(FILE *stream, struct RecordHeader *x) {
return fread(x, sizeof(struct RecordHeader), 1, stream);
}
@@ -128,6 +129,7 @@ static void blip(int n, ushort recType, ushort recInstance, dword recLen) {
if(OfficeArtBlip_config[i].recType == recType) break;
}
assert(member(recInstance, config->recInstance));
+ FILE *stream = fopen(filename, "r");
struct shorter_stream s = {stream, recLen, 0};
byte guid[16];
read_guid(&s, guid);
@@ -142,7 +144,7 @@ static void blip(int n, ushort recType, ushort recInstance, dword recLen) {
shorter_stream_read(&s, &b, 1);
}
char ofile[1024];
- snprintf(ofile, 1024, "%s/%d.%s", dir, n, config->ext);
+ //snprintf(ofile, 1024, "%s/%d.%s", dir, n, config->ext);
FILE *o = fopen(ofile, "w");
assert(o);
while(!shorter_stream_eof(&s)) {
@@ -152,36 +154,122 @@ static void blip(int n, ushort recType, ushort recInstance, dword recLen) {
fwrite(buf, sizeof(char), n, o);
}
fclose(o);
+ fclose(stream);
//printf("<p><img src=\"%d.%s\">\n", n, config->ext);
}
-int main(int argc, char *argv[]) {
- if(argc < 3) {
- fprintf(stderr, "Usage: %s filename directory\n", argv[0]);
- exit(-1);
+static int odrawfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
+ off_t offset, struct fuse_file_info *fi) {
+ (void) offset;
+ (void) fi;
+ /*
+ struct entry *root = &directories[0];
+ char name[32 * sizeof(wchar)];
+ xconv(root->name, name, root->name_length);
+ if(strcmp(path, "/") == 0) {
+ filler(buf, ".", NULL, 0);
+ filler(buf, "..", NULL, 0);
+ filler(buf, header_path + 1, NULL, 0);
+ filler(buf, name, NULL, 0);
}
- filename = argv[1];
- dir = argv[2];
- stream = fopen(filename, "r");
- if(!stream) {
- fprintf(stderr, "Unable to open '%s'.\n", filename);
- exit(-1);
+ else {
+ struct readdir_walk e = {path, buf, filler, -ENOENT};
+ walk_directory(&e, readdir_walk_cb, 0, "");
+ return e.result;
+ }*/
+ return 0;
+}
+
+static int odrawfs_getattr(const char *path, struct stat *stbuf) {
+ int res = 0;
+ memset(stbuf, 0, sizeof(struct stat));
+ /*
+ if(strcmp(path, "/") == 0) {
+ stbuf->st_mode = S_IFDIR | 0755;
+ stbuf->st_nlink = 2;
+ }
+ else if(strcmp(path, header_path) == 0) {
+ stbuf->st_mode = S_IFREG | 0444;
+ stbuf->st_nlink = 1;
+ size_t len;
+ char *header_str;
+ print_header_to_string(&header_str, &len);
+ free(header_str);
+ stbuf->st_size = len; //0; //strlen(header_str);
+ }
+ else {
+ struct getattr_walk e = {path, stbuf, -ENOENT};
+ walk_directory(&e, getattr_walk_cb, 0, "");
+ return e.result;
+ }*/
+ return res;
+}
+
+static int odrawfs_open(const char *path, struct fuse_file_info *fi) {
+ /*
+ if(!strcmp(path, header_path)) {
+ if((fi->flags & 3) != O_RDONLY)
+ return -EACCES;
+ return 0;
}
+ struct open_walk e = {path, fi, -ENOENT};
+ walk_directory(&e, open_walk_cb, 0, "");
+ return e.result;
+ */
+ return -EACCES;
+}
+
+static int odrawfs_read(const char *path, char *buf, size_t size, off_t offset,
+ struct fuse_file_info *fi) {
+ /* if(!strcmp(path, header_path)) { */
+ /* size_t len; */
+ /* char *header_str; */
+ /* print_header_to_string(&header_str, &len); */
+ /* /\* len = strlen(header_str); *\/ */
+ /* if (offset < len) { */
+ /* if (offset + size > len) */
+ /* size = len - offset; */
+ /* memcpy(buf, header_str + offset, size); */
+ /* } else */
+ /* size = 0; */
+ /* free(header_str); */
+ /* return size; */
+ /* } */
+ /* struct read_walk e = {path, buf, size, offset, fi, -ENOENT}; */
+ /* walk_directory(&e, read_walk_cb, 0, ""); */
+ /* return e.result; */
+ return -EACCES;
+}
+
+static struct fuse_operations odrawfs_operations = {
+ .readdir = odrawfs_readdir,
+ .getattr = odrawfs_getattr,
+ .open = odrawfs_open,
+ .read = odrawfs_read,
+};
+
+struct header {
+ struct RecordHeader h;
+ off_t fpos;
+ struct RecordHeader *next;
+};
+
+static void read_headers(FILE *stream) {
int i;
for(i = 0;; i++) {
struct RecordHeader h;
/* struct CurrentUserAtom u; */
- if(read_RecordHeader(&h) <= 0) break;
+ if(read_RecordHeader(stream, &h) <= 0) break;
//print_RecordHeader(&h);
switch(h.recType) {
- /* case RT_CurrentUserAtom: */
- /* assert(!x->recVer); */
- /* assert(!x->recInstance); */
- /* read_CurrentUserAtom(&u); */
- /* /\* #+nil ;; why recLen too small? *\/ */
- /* /\* (with-shorter-stream (in stream (RecordHeader.recLen x)) *\/ */
- /* /\* (list x (read-CurrentUserAtom in)))) *\/ */
- /* break; */
+ /* case RT_CurrentUserAtom: */
+ /* assert(!x->recVer); */
+ /* assert(!x->recInstance); */
+ /* read_CurrentUserAtom(&u); */
+ /* /\* #+nil ;; why recLen too small? *\/ */
+ /* /\* (with-shorter-stream (in stream (RecordHeader.recLen x)) *\/ */
+ /* /\* (list x (read-CurrentUserAtom in)))) *\/ */
+ /* break; */
case 0xF01A:
case 0xF01B:
case 0xF01C:
@@ -198,8 +286,23 @@ int main(int argc, char *argv[]) {
exit(-1);
}
}
- fclose(stream);
- return 0;
}
-// n[0..] -> fpos
+int main(int argc, char *argv[]) {
+ if(argc < 3) {
+ fprintf(stderr, "Usage: %s filename directory\n", argv[0]);
+ exit(-1);
+ }
+ filename = argv[1];
+ argv++;
+ argc--;
+ getcwd(cwd, PATH_MAX);
+ FILE *stream = fopen(filename, "r");
+ if(!stream) {
+ fprintf(stderr, "Unable to open '%s'.\n", filename);
+ exit(-1);
+ }
+ read_headers(stream);
+ fclose(stream);
+ return fuse_main(argc, argv, &odrawfs_operations);
+}