Changed filesystem.c's struct naming to match rest of project
This commit is contained in:
@@ -25,24 +25,24 @@ enum {
|
|||||||
FILESYSTEM_TDIR,
|
FILESYSTEM_TDIR,
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct Mount Mount;
|
typedef struct mount_t mount_t;
|
||||||
|
|
||||||
struct Mount {
|
struct mount_t {
|
||||||
void (*unmount)(Mount *mnt);
|
void (*unmount)(mount_t *mnt);
|
||||||
int (*exists)(Mount *mnt, const char *filename);
|
int (*exists)(mount_t *mnt, const char *filename);
|
||||||
int (*isFile)(Mount *mnt, const char *filename);
|
int (*isFile)(mount_t *mnt, const char *filename);
|
||||||
int (*isDirectory)(Mount *mnt, const char *filename);
|
int (*isDirectory)(mount_t *mnt, const char *filename);
|
||||||
void *(*read)(Mount *mnt, const char *filename, int *size);
|
void *(*read)(mount_t *mnt, const char *filename, int *size);
|
||||||
void *udata;
|
void *udata;
|
||||||
char path[MAX_PATH];
|
char path[MAX_PATH];
|
||||||
};
|
};
|
||||||
|
|
||||||
int filesystem_mountIdx;
|
int filesystem_mountIdx;
|
||||||
Mount filesystem_mounts[MAX_MOUNTS];
|
mount_t filesystem_mounts[MAX_MOUNTS];
|
||||||
char filesystem_writeDir[MAX_PATH];
|
char filesystem_writeDir[MAX_PATH];
|
||||||
|
|
||||||
#define FOREACH_MOUNT(var)\
|
#define FOREACH_MOUNT(var)\
|
||||||
for (Mount *var = &filesystem_mounts[filesystem_mountIdx - 1];\
|
for (mount_t *var = &filesystem_mounts[filesystem_mountIdx - 1];\
|
||||||
var >= filesystem_mounts;\
|
var >= filesystem_mounts;\
|
||||||
var--)
|
var--)
|
||||||
|
|
||||||
@@ -143,30 +143,30 @@ static int make_dirs(const char *path) {
|
|||||||
|
|
||||||
|
|
||||||
/*==================*/
|
/*==================*/
|
||||||
/* Directory Mount */
|
/* Directory mount_t */
|
||||||
/*==================*/
|
/*==================*/
|
||||||
|
|
||||||
static void dir_unmount(Mount *mnt) {
|
static void dir_unmount(mount_t *mnt) {
|
||||||
/* Intentionally empty */
|
/* Intentionally empty */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int dir_exists(Mount *mnt, const char *filename) {
|
static int dir_exists(mount_t *mnt, const char *filename) {
|
||||||
return concat_and_get_file_type(mnt->path, filename) != FILESYSTEM_TNONE;
|
return concat_and_get_file_type(mnt->path, filename) != FILESYSTEM_TNONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int dir_isFile(Mount *mnt, const char *filename) {
|
static int dir_isFile(mount_t *mnt, const char *filename) {
|
||||||
return concat_and_get_file_type(mnt->path, filename) == FILESYSTEM_TREG;
|
return concat_and_get_file_type(mnt->path, filename) == FILESYSTEM_TREG;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int dir_isDirectory(Mount *mnt, const char *filename) {
|
static int dir_isDirectory(mount_t *mnt, const char *filename) {
|
||||||
return concat_and_get_file_type(mnt->path, filename) == FILESYSTEM_TDIR;
|
return concat_and_get_file_type(mnt->path, filename) == FILESYSTEM_TDIR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void* dir_read(Mount *mnt, const char *filename, int *size) {
|
static void* dir_read(mount_t *mnt, const char *filename, int *size) {
|
||||||
char buf[MAX_PATH];
|
char buf[MAX_PATH];
|
||||||
/* Make fullpath */
|
/* Make fullpath */
|
||||||
int err = concat_path(buf, mnt->path, filename);
|
int err = concat_path(buf, mnt->path, filename);
|
||||||
@@ -194,7 +194,7 @@ static void* dir_read(Mount *mnt, const char *filename, int *size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int dir_mount(Mount *mnt, const char *path) {
|
static int dir_mount(mount_t *mnt, const char *path) {
|
||||||
/* Check the path is actually a directory */
|
/* Check the path is actually a directory */
|
||||||
if ( get_file_type(path) != FILESYSTEM_TDIR ) {
|
if ( get_file_type(path) != FILESYSTEM_TDIR ) {
|
||||||
return FILESYSTEM_EFAILURE;
|
return FILESYSTEM_EFAILURE;
|
||||||
@@ -214,24 +214,24 @@ static int dir_mount(Mount *mnt, const char *path) {
|
|||||||
|
|
||||||
|
|
||||||
/*==================*/
|
/*==================*/
|
||||||
/* Tar Mount */
|
/* Tar mount_t */
|
||||||
/*==================*/
|
/*==================*/
|
||||||
|
|
||||||
typedef struct { unsigned hash, pos; } TarFileRef;
|
typedef struct { unsigned hash, pos; } tar_file_ref_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
mtar_t tar;
|
mtar_t tar;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
int offset;
|
int offset;
|
||||||
TarFileRef *map;
|
tar_file_ref_t *map;
|
||||||
int nfiles;
|
int nfiles;
|
||||||
} TarMount;
|
} tar_mount_t;
|
||||||
|
|
||||||
|
|
||||||
static int tar_find(Mount *mnt, const char *filename, mtar_header_t *h) {
|
static int tar_find(mount_t *mnt, const char *filename, mtar_header_t *h) {
|
||||||
/* Hash filename and linear search map for matching hash, read header and
|
/* Hash filename and linear search map for matching hash, read header and
|
||||||
* check against filename if the hashes match */
|
* check against filename if the hashes match */
|
||||||
TarMount *tm = mnt->udata;
|
tar_mount_t *tm = mnt->udata;
|
||||||
unsigned hash = hash_string(filename);
|
unsigned hash = hash_string(filename);
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < tm->nfiles; i++) {
|
for (i = 0; i < tm->nfiles; i++) {
|
||||||
@@ -252,21 +252,21 @@ static int tar_find(Mount *mnt, const char *filename, mtar_header_t *h) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void tar_unmount(Mount *mnt) {
|
static void tar_unmount(mount_t *mnt) {
|
||||||
TarMount *tm = mnt->udata;
|
tar_mount_t *tm = mnt->udata;
|
||||||
mtar_close(&tm->tar);
|
mtar_close(&tm->tar);
|
||||||
dmt_free(tm->map);
|
dmt_free(tm->map);
|
||||||
dmt_free(tm);
|
dmt_free(tm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int tar_exists(Mount *mnt, const char *filename) {
|
static int tar_exists(mount_t *mnt, const char *filename) {
|
||||||
mtar_header_t h;
|
mtar_header_t h;
|
||||||
return tar_find(mnt, filename, &h) == FILESYSTEM_ESUCCESS;
|
return tar_find(mnt, filename, &h) == FILESYSTEM_ESUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int tar_isFile(Mount *mnt, const char *filename) {
|
static int tar_isFile(mount_t *mnt, const char *filename) {
|
||||||
mtar_header_t h;
|
mtar_header_t h;
|
||||||
int err = tar_find(mnt, filename, &h);
|
int err = tar_find(mnt, filename, &h);
|
||||||
if (err) {
|
if (err) {
|
||||||
@@ -276,7 +276,7 @@ static int tar_isFile(Mount *mnt, const char *filename) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int tar_isDirectory(Mount *mnt, const char *filename) {
|
static int tar_isDirectory(mount_t *mnt, const char *filename) {
|
||||||
mtar_header_t h;
|
mtar_header_t h;
|
||||||
int err = tar_find(mnt, filename, &h);
|
int err = tar_find(mnt, filename, &h);
|
||||||
if (err) {
|
if (err) {
|
||||||
@@ -286,7 +286,7 @@ static int tar_isDirectory(Mount *mnt, const char *filename) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void* tar_read(Mount *mnt, const char *filename, int *size) {
|
static void* tar_read(mount_t *mnt, const char *filename, int *size) {
|
||||||
mtar_t *tar = mnt->udata;
|
mtar_t *tar = mnt->udata;
|
||||||
int err;
|
int err;
|
||||||
mtar_header_t h;
|
mtar_header_t h;
|
||||||
@@ -310,28 +310,28 @@ static void* tar_read(Mount *mnt, const char *filename, int *size) {
|
|||||||
|
|
||||||
|
|
||||||
static int tar_stream_read(mtar_t *tar, void *data, unsigned size) {
|
static int tar_stream_read(mtar_t *tar, void *data, unsigned size) {
|
||||||
TarMount *tm = tar->stream;
|
tar_mount_t *tm = tar->stream;
|
||||||
unsigned res = fread(data, 1, size, tm->fp);
|
unsigned res = fread(data, 1, size, tm->fp);
|
||||||
return (res == size) ? MTAR_ESUCCESS : MTAR_EREADFAIL;
|
return (res == size) ? MTAR_ESUCCESS : MTAR_EREADFAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int tar_stream_seek(mtar_t *tar, unsigned offset) {
|
static int tar_stream_seek(mtar_t *tar, unsigned offset) {
|
||||||
TarMount *tm = tar->stream;
|
tar_mount_t *tm = tar->stream;
|
||||||
int res = fseek(tm->fp, tm->offset + offset, SEEK_SET);
|
int res = fseek(tm->fp, tm->offset + offset, SEEK_SET);
|
||||||
return (res == 0) ? MTAR_ESUCCESS : MTAR_ESEEKFAIL;
|
return (res == 0) ? MTAR_ESUCCESS : MTAR_ESEEKFAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int tar_stream_close(mtar_t *tar) {
|
static int tar_stream_close(mtar_t *tar) {
|
||||||
TarMount *tm = tar->stream;
|
tar_mount_t *tm = tar->stream;
|
||||||
fclose(tm->fp);
|
fclose(tm->fp);
|
||||||
return MTAR_ESUCCESS;
|
return MTAR_ESUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int tar_mount(Mount *mnt, const char *path) {
|
static int tar_mount(mount_t *mnt, const char *path) {
|
||||||
TarMount *tm = NULL;
|
tar_mount_t *tm = NULL;
|
||||||
FILE *fp = NULL;
|
FILE *fp = NULL;
|
||||||
|
|
||||||
/* Try to open file */
|
/* Try to open file */
|
||||||
@@ -340,7 +340,7 @@ static int tar_mount(Mount *mnt, const char *path) {
|
|||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Init TarMount */
|
/* Init tar_mount_t */
|
||||||
tm = dmt_calloc(1, sizeof(*tm));
|
tm = dmt_calloc(1, sizeof(*tm));
|
||||||
tm->fp = fp;
|
tm->fp = fp;
|
||||||
|
|
||||||
@@ -462,7 +462,7 @@ int filesystem_mount(const char *path) {
|
|||||||
if (filesystem_mountIdx >= MAX_MOUNTS) {
|
if (filesystem_mountIdx >= MAX_MOUNTS) {
|
||||||
return FILESYSTEM_EFAILURE;
|
return FILESYSTEM_EFAILURE;
|
||||||
}
|
}
|
||||||
Mount *mnt = &filesystem_mounts[filesystem_mountIdx++];
|
mount_t *mnt = &filesystem_mounts[filesystem_mountIdx++];
|
||||||
|
|
||||||
/* Copy path name */
|
/* Copy path name */
|
||||||
strcpy(mnt->path, path);
|
strcpy(mnt->path, path);
|
||||||
@@ -487,7 +487,7 @@ int filesystem_unmount(const char *path) {
|
|||||||
mnt->unmount(mnt);
|
mnt->unmount(mnt);
|
||||||
/* Shift remaining mounts to fill gap and decrement idx */
|
/* Shift remaining mounts to fill gap and decrement idx */
|
||||||
int idx = mnt - filesystem_mounts;
|
int idx = mnt - filesystem_mounts;
|
||||||
memmove(mnt, mnt + 1, (filesystem_mountIdx - idx - 1) * sizeof(Mount));
|
memmove(mnt, mnt + 1, (filesystem_mountIdx - idx - 1) * sizeof(mount_t));
|
||||||
filesystem_mountIdx--;
|
filesystem_mountIdx--;
|
||||||
return FILESYSTEM_ESUCCESS;
|
return FILESYSTEM_ESUCCESS;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user