aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarvin Borner2022-01-01 13:51:51 +0100
committerMarvin Borner2022-01-01 13:51:51 +0100
commit85e869783c5f4f5586520f0b36f739f03607bda6 (patch)
tree12ebf921a4219da430bb1b2441b07fc3e7d09060
parent96797653950948165863d9dd016c82af7468636f (diff)
Debug mount
-rw-r--r--.gitignore1
-rw-r--r--makefile4
-rw-r--r--src/fuse.c54
3 files changed, 46 insertions, 13 deletions
diff --git a/.gitignore b/.gitignore
index 39b9f19..0b517a8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,4 @@ tags
compile_commands.json
build/
+mnt/
diff --git a/makefile b/makefile
index dd02100..16094e0 100644
--- a/makefile
+++ b/makefile
@@ -47,13 +47,13 @@ $(MNT):
mount: disk $(MNT)
@DEV=$$(losetup -a | grep $(BUILD)/disk.img | grep -m 1 -o '/dev/loop[[:digit:]]*') && \
PART="p1" && \
- $(BUILD)/marfs_fuse "$$DEV$$PART" $(MNT) && \
+ ($(BUILD)/marfs_fuse "$$DEV$$PART" -f $(MNT) &) && \
echo "Mounted $$DEV$$PART"
umount:
@DEV=$$(losetup -a | grep $(BUILD)/disk.img | grep -m 1 -o '/dev/loop[[:digit:]]*') && \
- umount $(MNT) && \
$(SU) losetup -d "$$DEV" && \
+ umount $(MNT) && \
echo "Unmounted $$DEV$$PART" || \
echo "No disk to unmount"
diff --git a/src/fuse.c b/src/fuse.c
index 262317a..a3c946d 100644
--- a/src/fuse.c
+++ b/src/fuse.c
@@ -7,6 +7,7 @@
#include <spec.h>
+#include <errno.h>
#include <fuse.h>
#include <limits.h>
#include <stdio.h>
@@ -19,14 +20,17 @@ static char *image = 0;
static void marfs_debug(const char *fmt, ...)
{
+ printf("\t>>> ");
va_list args;
va_start(args, fmt);
vfprintf(stdout, fmt, args);
va_end(args);
+ printf("\n");
}
static void *marfs_init(struct fuse_conn_info *conn, struct fuse_config *cfg)
{
+ marfs_debug("init()");
UNUSED(conn);
cfg->kernel_cache = 1;
return NULL;
@@ -34,97 +38,125 @@ static void *marfs_init(struct fuse_conn_info *conn, struct fuse_config *cfg)
static void marfs_destroy(void *data)
{
+ marfs_debug("destroy()");
if (image)
free(image);
}
static int marfs_open(const char *file_path, struct fuse_file_info *file_info)
{
- marfs_debug("opening file %s\n", file_path);
+ marfs_debug("open() on %s", file_path);
return 0;
}
static int marfs_opendir(const char *dir_path, struct fuse_file_info *file_info)
{
- marfs_debug("opening dir %s\n", dir_path);
+ marfs_debug("opendir() on %s", dir_path);
return 0;
}
static int marfs_getattr(const char *path, struct stat *stat, struct fuse_file_info *info)
{
- marfs_debug("getattr() on %s\n", path);
+ marfs_debug("getattr() on %s", path);
+ UNUSED(info);
+
+ memset(stat, 0, sizeof(*stat));
+ if (strcmp(path, "/") == 0) {
+ stat->st_mode = S_IFDIR | 0000;
+ } else if (strcmp(path + 1, "aah") == 0) {
+ stat->st_mode = S_IFREG | 0000;
+ stat->st_size = 0;
+ } else {
+ return -ENOENT;
+ }
+
return 0;
}
static int marfs_readdir(const char *path, void *buf, fuse_fill_dir_t fill, off_t offset,
struct fuse_file_info *file_info, enum fuse_readdir_flags flags)
{
- marfs_debug("readdir() on %s and offset %lu\n", path, offset);
+ marfs_debug("readdir() on %s and offset %lu", path, offset);
+
+ UNUSED(offset);
+ UNUSED(file_info);
+ UNUSED(flags);
+ if (strcmp(path, "/") != 0)
+ return -ENOENT;
+
+ fill(buf, ".", NULL, 0, 0);
+ fill(buf, "..", NULL, 0, 0);
+ fill(buf, "aah", NULL, 0, 0);
+
return 0;
}
static int marfs_release(const char *path, struct fuse_file_info *file_info)
{
+ marfs_debug("release() on %s", path);
return 0;
}
static int marfs_releasedir(const char *path, struct fuse_file_info *file_info)
{
+ marfs_debug("releasedir() on %s", path);
return 0;
}
static int marfs_read(const char *path, char *buf, size_t to_read, off_t offset,
struct fuse_file_info *file_info)
{
- marfs_debug("marfs_read() on %s, %lu\n", path, to_read);
+ marfs_debug("read() on %s, %lu", path, to_read);
return to_read;
}
static int marfs_write(const char *path, const char *buf, size_t to_write, off_t offset,
struct fuse_file_info *file_info)
{
- marfs_debug("marfs_write() on %s\n", path);
+ marfs_debug("write() on %s", path);
return to_write;
}
static int marfs_create(const char *path, mode_t mode, struct fuse_file_info *file_info)
{
- marfs_debug("marfs_create() on %s\n", path);
+ marfs_debug("create() on %s", path);
return 0;
}
static int marfs_mkdir(const char *path, mode_t mode)
{
- marfs_debug("marfs_mkdir() on %s\n", path);
+ marfs_debug("mkdir() on %s", path);
return 0;
}
static int marfs_unlink(const char *path)
{
+ marfs_debug("unlink() on %s", path);
return 0;
}
static int marfs_rmdir(const char *path)
{
+ marfs_debug("rmdir() on %s", path);
return 0;
}
static int marfs_utimens(const char *path, const struct timespec tv[2],
struct fuse_file_info *file_info)
{
- marfs_debug("marfs_utimens() on %s\n", path);
+ marfs_debug("utimens() on %s", path);
return 0;
}
static int marfs_truncate(const char *path, off_t size, struct fuse_file_info *file_info)
{
- marfs_debug("marfs_truncate() on %s, size %lu\n", path, size);
+ marfs_debug("truncate() on %s, size %lu", path, size);
return 0;
}
static int marfs_rename(const char *path, const char *new, unsigned int flags)
{
- marfs_debug("marfs_rename() on %s, %s\n", path, new);
+ marfs_debug("rename() on %s -> %s", path, new);
return 0;
}