a correct readdir

This commit is contained in:
FactorialN 2023-11-30 17:36:26 -08:00
parent 73b2142d17
commit bcbd23003f
3 changed files with 52 additions and 32 deletions

View File

@ -23,6 +23,7 @@ class FilesOperation {
int fischl_mkdir(const char*, mode_t); int fischl_mkdir(const char*, mode_t);
int fischl_mknod(const char*, mode_t, dev_t);//for special file int fischl_mknod(const char*, mode_t, dev_t);//for special file
int fischl_create(const char *, mode_t, struct fuse_file_info *);//for regular file int fischl_create(const char *, mode_t, struct fuse_file_info *);//for regular file
int fischl_getattr(const char *path, struct stat *stbuf, struct fuse_file_info *fi);
int fischl_readdir(const char *, void *, fuse_fill_dir_t, off_t, struct fuse_file_info *, enum fuse_readdir_flags); int fischl_readdir(const char *, void *, fuse_fill_dir_t, off_t, struct fuse_file_info *, enum fuse_readdir_flags);
int fischl_unlink (const char *); int fischl_unlink (const char *);
int fischl_open (const char *, struct fuse_file_info *);//open file int fischl_open (const char *, struct fuse_file_info *);//open file

View File

@ -283,6 +283,54 @@ int FilesOperation::fischl_create(const char* path, mode_t mode, struct fuse_fil
return 0;//SUCESS return 0;//SUCESS
} }
int FilesOperation::fischl_getattr(const char *path, struct stat *stbuf, struct fuse_file_info *fi) {
(void) fi;
int res = 0;
u_int64_t fh = namei(path);
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 res;
}
int FilesOperation::fischl_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t ft, struct fuse_file_info *fi, enum fuse_readdir_flags flg) {
//check path
u_int64_t fh = namei(path);
if (fh == -1){
return -1;
}
INode_Data inode;
inode.inode_num = fh;
fs->inode_manager->load_inode(&inode);
char buffer[IO_BLOCK_SIZE] = {0};
for (u_int64_t idx=0; idx<inode.metadata.size/IO_BLOCK_SIZE; idx++) {
fs->read(&inode, buffer, IO_BLOCK_SIZE, idx*IO_BLOCK_SIZE);
DirectoryEntry ent;
for(int i=0;i<=IO_BLOCK_SIZE-264;i+=264){
ent.deserialize(buffer+i);
if (ent.inode_number) {
filler(buf, ent.file_name, NULL, 0, FUSE_FILL_DIR_PLUS);
//printf("%s\t%llu;\t", ent.file_name, ent.inode_number);
}
}
}
return 0;
}
void FilesOperation::unlink_inode(u_int64_t inode_number) { void FilesOperation::unlink_inode(u_int64_t inode_number) {
INode_Data inode; INode_Data inode;
inode.inode_num = inode_number; inode.inode_num = inode_number;

View File

@ -48,24 +48,7 @@ void fischl_destroy(void* private_data) {
} }
static int fischl_getattr(const char *path, struct stat *stbuf, struct fuse_file_info *fi) { static int fischl_getattr(const char *path, struct stat *stbuf, struct fuse_file_info *fi) {
return options.fsop->fischl_getattr(path, stbuf, fi);
(void) fi;
int res = 0;
u_int64_t fh = options.fsop->namei(path);
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 res;
} }
static int fischl_access(const char* path, int mask) { static int fischl_access(const char* path, int mask) {
@ -84,20 +67,8 @@ static int fischl_opendir(const char* path, struct fuse_file_info* fi) {
return 0; return 0;
} }
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) { 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 flg) {
//check path return options.fsop->fischl_readdir(path, buf, filler, ft, fi, flg);
u_int64_t fh = options.fsop->namei(path);
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) {