it now compiles and somewhat works

This commit is contained in:
FactorialN 2023-11-29 19:01:08 -08:00
parent 652d066c8d
commit e377098fbc
3 changed files with 68 additions and 45 deletions

View File

@ -7,14 +7,37 @@
#include <fcntl.h>
#include <stddef.h>
#include <assert.h>
#include "fs.hpp"
#include "files.h"
void* fischl_init(struct fuse_conn_info *conn) {
/*
* Command line options
*
* We can't set default values for the char* fields here because
* fuse_opt_parse would attempt to free() them when the user specifies
* different values on the command line.
*/
static struct options {
RawDisk *H; // Use FakeRawDisk here if memory sanitizer complains
Fs *fs;
FilesOperation *fsop;
int show_help;
} options;
#define OPTION(t, p) \
{ t, offsetof(struct options, p), 1 }
static const struct fuse_opt option_spec[] = {
OPTION("-h", show_help),
OPTION("--help", show_help),
FUSE_OPT_END
};
void* fischl_init(struct fuse_conn_info *conn, struct fuse_config *cfg) {
}
int fischl_create(const char *path, mode_t mode, struct fuse_file_info *fi) {
return FilesOperation::fischl_create(path, mode, fi);
return options.fsop->fischl_create(path, mode, fi);
}
@ -22,12 +45,7 @@ void fischl_destroy(void* private_data) {
}
static int fischl_getattr(const char* path, struct stat* stbuf) {
return 0;
}
static int fischl_fgetattr(const char* path, struct stat* stbuf) {
static int fischl_getattr(const char *path, struct stat *mode, struct fuse_file_info *fi) {
return 0;
}
@ -44,7 +62,7 @@ static int fischl_opendir(const char* path, struct fuse_file_info* fi) {
}
static int fischl_readdir(const char* path, void* buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info* fi) {
static int fischl_readdir(const char *path, void *buf, fuse_fill_dir_t t, off_t ft, struct fuse_file_info *fi, enum fuse_readdir_flags) {
return 0;
}
@ -54,11 +72,11 @@ static int fischl_mknod(const char* path, mode_t mode, dev_t rdev) {
}
static int fischl_mkdir(const char *path, mode_t mode) {
return FilesOperation::fischl_mkdir(path, mode);
return options.fsop->fischl_mkdir(path, mode);
}
static int fischl_unlink(const char* path) {
return FilesOperation::fischl_unlink(path);
return options.fsop->fischl_unlink(path);
}
static int fischl_rmdir(const char* path) {
@ -69,7 +87,7 @@ static int fischl_symlink(const char* to, const char* from) {
}
static int fischl_rename(const char* from, const char* to) {
static int fischl_rename(const char *path, const char *, unsigned int flags) {
}
@ -77,36 +95,32 @@ static int fischl_link(const char* from, const char* to) {
}
static int fischl_chmod(const char* path, mode_t mode) {
static int fischl_chmod(const char *path, mode_t, struct fuse_file_info *fi) {
}
static int fischl_chown(const char* path, uid_t uid, gid_t gid) {
static int fischl_chown(const char *path, uid_t, gid_t, struct fuse_file_info *fi) {
}
static int fischl_truncate(const char* path, off_t size) {
static int fischl_truncate(const char *path, off_t, struct fuse_file_info *fi) {
}
static int fischl_ftruncate(const char* path, off_t size) {
}
static int fischl_utimens(const char* path, const struct timespec ts[2]) {
static int fischl_utimens(const char *path, const struct timespec tv[2], struct fuse_file_info *fi) {
}
static int fischl_open(const char *path, struct fuse_file_info *fi) {
return FilesOperation::fischl_open(path, fi);
return options.fsop->fischl_open(path, fi);
}
static int fischl_read(const char* path, char *buf, size_t size, off_t offset, struct fuse_file_info* fi) {
return FilesOperation::fischl_read(path, buf, size, offset, fi);
return options.fsop->fischl_read(path, buf, size, offset, fi);
}
static int fischl_write(const char* path, char *buf, size_t size, off_t offset, struct fuse_file_info* fi) {
return FilesOperation::fischl_write(path, buf, size, offset, fi);
static int fischl_write(const char *path, const char *buf, size_t size, off_t offset, struct fuse_file_info *fi) {
return options.fsop->fischl_write(path, buf, size, offset, fi);
}
static int fischl_statfs(const char* path, struct statvfs* stbuf) {
@ -114,7 +128,7 @@ static int fischl_statfs(const char* path, struct statvfs* stbuf) {
}
static int fischl_release(const char* path, struct fuse_file_info *fi) {
return FilesOperation::fischl_release(path, fi);
return options.fsop->fischl_release(path, fi);
}
static int fischl_releasedir(const char* path, struct fuse_file_info *fi) {
@ -135,36 +149,25 @@ static int fischl_poll(const char* path, struct fuse_file_info* fi, struct fuse_
static const struct fuse_operations fischl_oper = {
.init = fischl_init,
.destroy = fischl_destroy,
.getattr = fischl_getattr,
.fgetattr = fischl_fgetattr,
.access = fischl_access,
.readlink = fischl_readlink,
.readdir = fischl_readdir,
.mknod = fischl_mknod,
.mkdir = fischl_mkdir,
.symlink = fischl_symlink,
.unlink = fischl_unlink,
.rmdir = fischl_rmdir,
.symlink = fischl_symlink,
.rename = fischl_rename,
.link = fischl_link,
.chmod = fischl_chmod,
.chown = fischl_chown,
.truncate = fischl_truncate,
.ftruncate = fischl_ftruncate,
.utimens = fischl_utimens,
.create = fischl_create,
.open = fischl_open,
.read = fischl_read,
.write = fischl_write,
.statfs = fischl_statfs,
.release = fischl_release,
.opendir = fischl_opendir,
.releasedir = fischl_releasedir,
.bmap = fischl_bmap,
.ioctl = fischl_ioctl,
.poll = fischl_poll,
/*
#ifdef HAVE_SETXATTR
.setxattr = fischl_setxattr,
@ -173,10 +176,20 @@ static const struct fuse_operations fischl_oper = {
.removexattr = fischl_removexattr,
#endif
*/
.flag_nullpath_ok = 0,
.opendir = fischl_opendir,
.readdir = fischl_readdir,
.releasedir = fischl_releasedir,
.init = fischl_init,
.destroy = fischl_destroy,
.access = fischl_access,
.create = fischl_create,
.utimens = fischl_utimens,
.bmap = fischl_bmap,
.ioctl = fischl_ioctl,
.poll = fischl_poll,
};
static void fischl::show_help(const char *progname)
static void show_help(const char *progname)
{
printf("usage: %s [options] <mountpoint>\n\n", progname);
printf("File-system specific options:\n"
@ -191,6 +204,14 @@ int fischl(int argc, char *argv[])
{
int ret;
struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
srand(time(NULL)); // Seed the random number generator
const char* d = (argc < 2) ? "/dev/vdc" : argv[1];
//setupTestDirectory(&options.mock_root);
options.H = new FakeRawDisk(21504);
options.fs = new Fs(options.H);
options.fs->format();
options.fsop = new FilesOperation(*options.H, options.fs);

View File

@ -2,7 +2,7 @@
#include "fs.hpp"
#include <stdio.h>
int main() {
int main(int argc, char *argv[]) {
// printf("hello word!");
// fischl *F = new fischl;
// F->init();
@ -34,6 +34,7 @@ int main() {
// disk->print_block(1597);
/*
int err;
RawDisk *disk = new FakeRawDisk(2048);
@ -80,7 +81,9 @@ int main() {
printf("\n\nREAD: %d\n", err);
for (int i = 0; i < N; ++i)
printf("%d ", buf2[i]);
printf("\n");
printf("\n");*/
fischl(argc, argv);
return 0;
}

View File

@ -17,7 +17,6 @@ add_executable(${TARGET_LAYER1_API}
# add need lib and source code here
layer1_API.cpp
../lib/fischl.cpp
../lib/rawdisk.cpp
../lib/fs/datablock_manager.cpp
../lib/fs/fs_data_types.cpp