aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorOmar Rizwan <omar.rizwan@gmail.com>2019-02-27 22:06:37 -0800
committerOmar Rizwan <omar.rizwan@gmail.com>2019-02-27 22:06:37 -0800
commit73f8bc754e200c041e17e613a61dfc35db414b66 (patch)
tree0b2aadcc2fc1edf75e35c5af12dacb921036d94f /fs
parent74c794d75c7205123c4dc37e7a997507b61be98b (diff)
base64 hack to handle binary files.
add memory fences because why not.
Diffstat (limited to 'fs')
-rw-r--r--fs/Makefile2
m---------fs/base640
-rw-r--r--fs/common.c16
-rw-r--r--fs/tabfs.c14
4 files changed, 20 insertions, 12 deletions
diff --git a/fs/Makefile b/fs/Makefile
index d6b822a..a34412c 100644
--- a/fs/Makefile
+++ b/fs/Makefile
@@ -14,7 +14,7 @@ CFLAGS_OSXFUSE += -DFUSE_USE_VERSION=26
CFLAGS_OSXFUSE += -D_FILE_OFFSET_BITS=64
CFLAGS_OSXFUSE += -D_DARWIN_USE_64_BIT_INODE
-CFLAGS_EXTRA = -Wall -g $(CFLAGS)
+CFLAGS_EXTRA = -Wall -Wno-unused-function -g $(CFLAGS)
LIBS = -losxfuse
diff --git a/fs/base64 b/fs/base64
new file mode 160000
+Subproject 6148c6944469d629a94a1695eb91989030762ff
diff --git a/fs/common.c b/fs/common.c
index c2bf3dd..d810fb9 100644
--- a/fs/common.c
+++ b/fs/common.c
@@ -1,10 +1,7 @@
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
-
-#include <sys/time.h>
-#include <stdio.h>
-#include <signal.h>
+#include <stdatomic.h>
#include "common.h"
@@ -16,11 +13,13 @@ void common_init() {
if (pipe(ws_to_tabfs)) exit(1);
}
-// FIXME: we probably need memory fences here?? especially on
-// non-x86?? idk
-// see https://stackoverflow.com/questions/35837539/does-the-use-of-an-anonymous-pipe-introduce-a-memory-barrier-for-interthread-com
+// We probably technically need memory fences here? especially on
+// non-x86?? Are these right? idk. See
+// https://stackoverflow.com/questions/35837539/does-the-use-of-an-anonymous-pipe-introduce-a-memory-barrier-for-interthread-com
+// https://preshing.com/20120913/acquire-and-release-semantics/
void common_send_tabfs_to_ws(char *request_data) {
+ atomic_thread_fence(memory_order_release);
write(tabfs_to_ws[1], &request_data, sizeof(request_data));
}
@@ -51,16 +50,19 @@ char *common_receive_tabfs_to_ws(fd_set_filler_fn_t filler) {
char *request_data;
read(tabfs_to_ws[0], &request_data, sizeof(request_data));
+ atomic_thread_fence(memory_order_acquire);
return request_data;
}
void common_send_ws_to_tabfs(char *response_data) {
+ atomic_thread_fence(memory_order_release);
write(ws_to_tabfs[1], &response_data, sizeof(response_data));
}
char *common_receive_ws_to_tabfs() {
char *response_data;
read(ws_to_tabfs[0], &response_data, sizeof(response_data));
+ atomic_thread_fence(memory_order_acquire);
return response_data;
}
diff --git a/fs/tabfs.c b/fs/tabfs.c
index 1fa5476..0447387 100644
--- a/fs/tabfs.c
+++ b/fs/tabfs.c
@@ -8,6 +8,9 @@
#include "cJSON/cJSON.h"
#include "cJSON/cJSON.c"
+#include "base64/base64.h"
+#include "base64/base64.c"
+
#include "common.h"
#include "ws.h"
@@ -119,12 +122,15 @@ tabfs_read(const char *path, char *buf, size_t size, off_t offset,
char *resp_buf = cJSON_GetStringValue(resp_buf_item);
if (!resp_buf) return -EIO;
-
size_t resp_buf_len = strlen(resp_buf);
- size = resp_buf_len < size ? resp_buf_len : size;
-
- memcpy(buf, resp_buf, size);
+ cJSON *base64_encoded_item = cJSON_GetObjectItemCaseSensitive(resp, "base64Encoded");
+ if (base64_encoded_item && cJSON_IsTrue(base64_encoded_item)) {
+ size = base64_decode(resp_buf, resp_buf_len, (unsigned char *) buf);
+ } else {
+ size = resp_buf_len < size ? resp_buf_len : size;
+ memcpy(buf, resp_buf, size);
+ }
ret = size;
});
}