some medium dev state

This commit is contained in:
Cloud User 2023-11-30 16:40:04 -08:00
parent 652d066c8d
commit 8a5f50574a
3 changed files with 128 additions and 72 deletions

View File

@ -2,19 +2,44 @@
#include <fuse.h> #include <fuse.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string>
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <stddef.h> #include <stddef.h>
#include <assert.h> #include <assert.h>
#include "fs.hpp"
#include "files.h" #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) {
options.fsop->initialize_rootinode();
perror("FUSE INITIALIZATION RUNNING");
} }
int fischl_create(const char *path, mode_t mode, struct fuse_file_info *fi) { 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,150 +47,161 @@ void fischl_destroy(void* private_data) {
} }
static int fischl_getattr(const char* path, struct stat* stbuf) { static int fischl_getattr(const char *path, struct stat *stbuf, struct fuse_file_info *fi) {
return 0; (void) fi;
} int res = 0;
u_int64_t fh = options.fsop->namei(path);
static int fischl_fgetattr(const char* path, struct stat* stbuf) { memset(stbuf, 0, sizeof(struct stat));
if (strcmp(path, "/") == 0) {
stbuf->st_mode = S_IFDIR | 0755;
stbuf->st_nlink = 2;
} else if (fh != -1) {
stbuf->st_mode = S_IFREG | 0444;
stbuf->st_nlink = 1;
// TO DO: make this the correct value
stbuf->st_size = 3;
} else
res = -ENOENT;
return 0; return res;
} }
static int fischl_access(const char* path, int mask) { static int fischl_access(const char* path, int mask) {
// return 0 when access is allowed
return 0;
} }
static int fischl_readlink(const char* path, char* buf, size_t size) { static int fischl_readlink(const char* path, char* buf, size_t size) {
return -1;
} }
static int fischl_opendir(const char* path, struct fuse_file_info* fi) { static int fischl_opendir(const char* path, struct fuse_file_info* fi) {
u_int64_t fh = options.fsop->namei(path);
fi->fh = fh;
return 0;
} }
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 filler, off_t ft, struct fuse_file_info *fi, enum fuse_readdir_flags) {
//check path
u_int64_t fh = options.fsop->namei(path);
return 0; options.fsop->printDirectory(fh);
char a[][6] = {".", "..", "a.txt"};
// Iterate through the directory entries and fill the buffer using 'filler'
for (size_t i = 0; i < 3; ++i) {
filler(buf, a[i], NULL, 0, FUSE_FILL_DIR_PLUS);
}
return 0;
} }
static int fischl_mknod(const char* path, mode_t mode, dev_t rdev) { static int fischl_mknod(const char* path, mode_t mode, dev_t rdev) {
return options.fsop->fischl_mknod(path, mode, rdev);
} }
static int fischl_mkdir(const char *path, mode_t mode) { 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) { 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) { static int fischl_rmdir(const char* path) {
return -1;
} }
static int fischl_symlink(const char* to, const char* from) { static int fischl_symlink(const char* to, const char* from) {
return -1;
} }
static int fischl_rename(const char* from, const char* to) { static int fischl_rename(const char *path, const char *, unsigned int flags) {
return -1;
} }
static int fischl_link(const char* from, const char* to) { static int fischl_link(const char* from, const char* to) {
return -1;
} }
static int fischl_chmod(const char* path, mode_t mode) { static int fischl_chmod(const char *path, mode_t, struct fuse_file_info *fi) {
return -1;
} }
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) {
return -1;
} }
static int fischl_truncate(const char* path, off_t size) { static int fischl_truncate(const char *path, off_t, struct fuse_file_info *fi) {
return -1;
} }
static int fischl_ftruncate(const char* path, off_t size) { static int fischl_utimens(const char *path, const struct timespec tv[2], struct fuse_file_info *fi) {
return -1;
}
static int fischl_utimens(const char* path, const struct timespec ts[2]) {
} }
static int fischl_open(const char *path, 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) { 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) { static int fischl_write(const char *path, const char *buf, size_t size, off_t offset, struct fuse_file_info *fi) {
return FilesOperation::fischl_write(path, buf, size, offset, fi); return options.fsop->fischl_write(path, buf, size, offset, fi);
} }
static int fischl_statfs(const char* path, struct statvfs* stbuf) { static int fischl_statfs(const char* path, struct statvfs* stbuf) {
return -1;
} }
static int fischl_release(const char* path, struct fuse_file_info *fi) { 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) { static int fischl_releasedir(const char* path, struct fuse_file_info *fi) {
return -1;
} }
static int fischl_bmap(const char* path, size_t blocksize, uint64_t* blockno) { static int fischl_bmap(const char* path, size_t blocksize, uint64_t* blockno) {
return -1;
} }
static int fischl_ioctl(const char* path, int cmd, void* arg, struct fuse_file_info* fi, unsigned int flags, void* data) { static int fischl_ioctl(const char* path, int cmd, void* arg, struct fuse_file_info* fi, unsigned int flags, void* data) {
return -1;
} }
static int fischl_poll(const char* path, struct fuse_file_info* fi, struct fuse_pollhandle* ph, unsigned* reventsp){ static int fischl_poll(const char* path, struct fuse_file_info* fi, struct fuse_pollhandle* ph, unsigned* reventsp){
return -1;
} }
static const struct fuse_operations fischl_oper = { static const struct fuse_operations fischl_oper = {
.init = fischl_init,
.destroy = fischl_destroy,
.getattr = fischl_getattr, .getattr = fischl_getattr,
.fgetattr = fischl_fgetattr, //.readlink = fischl_readlink,
.access = fischl_access,
.readlink = fischl_readlink,
.readdir = fischl_readdir,
.mknod = fischl_mknod, .mknod = fischl_mknod,
.mkdir = fischl_mkdir, .mkdir = fischl_mkdir,
.symlink = fischl_symlink,
.unlink = fischl_unlink, .unlink = fischl_unlink,
.rmdir = fischl_rmdir, //.rmdir = fischl_rmdir,
.rename = fischl_rename, //.symlink = fischl_symlink,
.link = fischl_link, //.rename = fischl_rename,
.chmod = fischl_chmod, //.link = fischl_link,
.chown = fischl_chown, //.chmod = fischl_chmod,
.truncate = fischl_truncate, //.chown = fischl_chown,
.ftruncate = fischl_ftruncate, //.truncate = fischl_truncate,
.utimens = fischl_utimens,
.create = fischl_create,
.open = fischl_open, .open = fischl_open,
.read = fischl_read, .read = fischl_read,
.write = fischl_write, .write = fischl_write,
.statfs = fischl_statfs, //.statfs = fischl_statfs,
.release = fischl_release, .release = fischl_release,
.opendir = fischl_opendir, /*
.releasedir = fischl_releasedir,
.bmap = fischl_bmap,
.ioctl = fischl_ioctl,
.poll = fischl_poll,
/*
#ifdef HAVE_SETXATTR #ifdef HAVE_SETXATTR
.setxattr = fischl_setxattr, .setxattr = fischl_setxattr,
.getxattr = fischl_getxattr, .getxattr = fischl_getxattr,
@ -173,10 +209,20 @@ static const struct fuse_operations fischl_oper = {
.removexattr = fischl_removexattr, .removexattr = fischl_removexattr,
#endif #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("usage: %s [options] <mountpoint>\n\n", progname);
printf("File-system specific options:\n" printf("File-system specific options:\n"
@ -187,10 +233,19 @@ static void fischl::show_help(const char *progname)
"\n"); "\n");
} }
int fischl(int argc, char *argv[]) int fischl(int argc, char *argv[])
{ {
int ret; int ret;
struct fuse_args args = FUSE_ARGS_INIT(argc, argv); 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.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 "fs.hpp"
#include <stdio.h> #include <stdio.h>
int main() { int main(int argc, char *argv[]) {
// printf("hello word!"); // printf("hello word!");
// fischl *F = new fischl; // fischl *F = new fischl;
// F->init(); // F->init();
@ -34,6 +34,7 @@ int main() {
// disk->print_block(1597); // disk->print_block(1597);
/*
int err; int err;
RawDisk *disk = new FakeRawDisk(2048); RawDisk *disk = new FakeRawDisk(2048);
@ -80,7 +81,9 @@ int main() {
printf("\n\nREAD: %d\n", err); printf("\n\nREAD: %d\n", err);
for (int i = 0; i < N; ++i) for (int i = 0; i < N; ++i)
printf("%d ", buf2[i]); printf("%d ", buf2[i]);
printf("\n"); printf("\n");*/
fischl(argc, argv);
return 0; return 0;
} }

View File

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