First commit
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
*.exe
|
||||
*.out
|
||||
@@ -0,0 +1,32 @@
|
||||
|
||||
CFLAGS = -Wall -Wextra -ggdb
|
||||
|
||||
ifeq ($(OS),Windows_NT)
|
||||
LFLAGS = -lws2_32
|
||||
EXT = .exe
|
||||
else
|
||||
LFLAGS =
|
||||
EXT = .out
|
||||
endif
|
||||
|
||||
.PHONY: all clean
|
||||
|
||||
all: metadata_server$(EXT) chunk_server$(EXT) example$(EXT)
|
||||
|
||||
metadata_server$(EXT): TinyDFS.c TinyDFS.h
|
||||
gcc -o $@ TinyDFS.c -DBUILD_METADATA_SERVER $(CFLAGS) $(LFLAGS)
|
||||
|
||||
chunk_server$(EXT): TinyDFS.c TinyDFS.h
|
||||
gcc -o $@ TinyDFS.c -DBUILD_CHUNK_SERVER $(CFLAGS) $(LFLAGS)
|
||||
|
||||
example$(EXT): examples/main.c TinyDFS.c TinyDFS.h
|
||||
gcc -o $@ examples/main.c TinyDFS.c $(CFLAGS) $(LFLAGS)
|
||||
|
||||
clean:
|
||||
rm \
|
||||
metadata_server.exe \
|
||||
matadata_server.out \
|
||||
chunk_server.exe \
|
||||
chunk_server.out \
|
||||
example.exe \
|
||||
example.out
|
||||
@@ -0,0 +1,35 @@
|
||||
#ifndef TINYDFS_INCLUDED
|
||||
#define TINYDFS_INCLUDED
|
||||
|
||||
typedef struct TinyDFS TinyDFS;
|
||||
|
||||
typedef enum {
|
||||
TINYDFS_RESULT_CREATE_ERROR,
|
||||
TINYDFS_RESULT_CREATE_SUCCESS,
|
||||
TINYDFS_RESULT_DELETE_ERROR,
|
||||
TINYDFS_RESULT_DELETE_SUCCESS,
|
||||
TINYDFS_RESULT_LIST_ERROR,
|
||||
TINYDFS_RESULT_LIST_SUCCESS,
|
||||
TINYDFS_RESULT_READ_ERROR,
|
||||
TINYDFS_RESULT_READ_SUCCESS,
|
||||
TINYDFS_RESULT_WRITE_ERROR,
|
||||
TINYDFS_RESULT_WRITE_SUCCESS,
|
||||
} TinyDFS_ResultType;
|
||||
|
||||
typedef struct {
|
||||
TinyDFS_ResultType type;
|
||||
} TinyDFS_Result;
|
||||
|
||||
typedef int TinyDFS_Handle;
|
||||
#define TINYDFS_INVALID ((TinyDFS_Handle) -1)
|
||||
|
||||
TinyDFS* tinydfs_init(void);
|
||||
void tinydfs_free(TinyDFS *tdfs);
|
||||
int tinydfs_wait(TinyDFS *tdfs, TinyDFS_Handle handle, TinyDFS_Result *result, int timeout);
|
||||
TinyDFS_Handle tinydfs_submit_create (TinyDFS *tdfs, char *path, int path_len, bool is_dir, unsigned int chunk_size);
|
||||
TinyDFS_Handle tinydfs_submit_delete (TinyDFS *tdfs, char *path, int path_len);
|
||||
TinyDFS_Handle tinydfs_submit_list (TinyDFS *tdfs, char *path, int path_len);
|
||||
TinyDFS_Handle tinydfs_submit_read (TinyDFS *tdfs, char *path, int path_len, void *dst, int len);
|
||||
TinyDFS_Handle tinydfs_submit_write (TinyDFS *tdfs, char *path, int path_len, void *src, int len);
|
||||
|
||||
#endif // TINYDFS_INCLUDED
|
||||
@@ -0,0 +1,38 @@
|
||||
#include <TinyDFS.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
TinyDFS *tdfs = tinydfs_init();
|
||||
if (tdfs == NULL)
|
||||
return -1;
|
||||
|
||||
if (tinydfs_submit_create(tdfs, "/my_file_1", -1, false, 1024) == TINDFS_INVALID) {
|
||||
tinydfs_free(tdfs);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (tinydfs_submit_create(tdfs, "/my_file_2", -1, false, 1024) == TINDFS_INVALID) {
|
||||
tinydfs_free(tdfs);
|
||||
return -1;
|
||||
}
|
||||
|
||||
char buff_1[] = "This is file 1";
|
||||
if (tinydfs_submit_write(tdfs, "/my_file_1", buff_1, sizeof(buff_1)-1) == TINDFS_INVALID) {
|
||||
tinydfs_free(tdfs);
|
||||
return -1;
|
||||
}
|
||||
|
||||
char buff_2[] = "This is file 1";
|
||||
if (tinydfs_submit_write(tdfs, "/my_file_1", buff_2, sizeof(buff_2)-1) == TINDFS_INVALID) {
|
||||
tinydfs_free(tdfs);
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
TinyDFS_Result result;
|
||||
tinydfs_wait(tdfs, TINYDFS_INVALID, -1);
|
||||
}
|
||||
|
||||
tinydfs_free(tdfs);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user