From f1778623845f5ca11feb5e63360b4d037c8ad45b Mon Sep 17 00:00:00 2001 From: Philip Langdale Date: Sat, 31 Mar 2012 11:42:28 -0700 Subject: [PATCH] Do pi lookup on read and write. --- src/pifs.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/pifs.c b/src/pifs.c index 90e0bc4..4f8ab70 100644 --- a/src/pifs.c +++ b/src/pifs.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -11,6 +12,8 @@ #include #include +unsigned char get_byte(int id); + struct options { char *mdd; } options; @@ -149,7 +152,7 @@ static int pifs_read(const char *path, char *buf, size_t count, off_t offset, } else if (ret == 0) { return i; } - *buf = (char) index; + *buf = (char) get_byte(index); buf++; } @@ -165,7 +168,12 @@ static int pifs_write(const char *path, const char *buf, size_t count, } for (size_t i = 0; i < count; i++) { - short index = (short) *buf; + short index; + for (index = 0; index < SHRT_MAX; index++) { + if (get_byte(index) == *buf) { + break; + } + } ret = write(info->fh, &index, sizeof index); if (ret == -1) { return -errno;