fixed persistency issue
This commit is contained in:
parent
a612d030f6
commit
1c792ba738
13
README.md
13
README.md
@ -22,18 +22,23 @@ make # cmake --build . is same
|
||||
## mount and test
|
||||
normal usage:
|
||||
```bash
|
||||
./fischl diskpath mountpoint
|
||||
./fischl diskpath n mountpoint
|
||||
```
|
||||
diskpath must be provided following ./fischl
|
||||
l/n must be provided following diskpath indicating whether to load the exisiting file system or create a new one.
|
||||
for loading:
|
||||
```bash
|
||||
./fischl diskpath l mountpoint
|
||||
```
|
||||
diskpath must be the provided following ./fischl
|
||||
|
||||
if the diskpath need to be accessed by root:
|
||||
```bash
|
||||
sudo ./fischl diskpath -o allow_other mountpoint
|
||||
sudo ./fischl diskpath n -o allow_other mountpoint
|
||||
```
|
||||
|
||||
for debugging:
|
||||
```bash
|
||||
sudo ./fischl diskpath -o allow_other -d mountpoint
|
||||
sudo ./fischl diskpath n -o allow_other -d mountpoint
|
||||
```
|
||||
|
||||
## run test
|
||||
|
@ -33,7 +33,7 @@ typedef struct RenameInfo {
|
||||
TreeNode *fischl_init_entry(int new_inode_number, const char *fileName, INode_Data *new_inode);
|
||||
/*the to be added file in add_entry should be parent-child relationship with treenode, otherwise will wrong */
|
||||
/*see Add_FindFiletest in dir_API.cpp*/
|
||||
int fischl_add_entry_for_cache(TreeNode *parent, int new_inode_number, const char *fileName, INode_Data *new_inode, FileNode *file);
|
||||
FileNode* fischl_add_entry_for_cache(TreeNode *parent, int new_inode_number, const char *fileName, INode_Data *new_inode);
|
||||
int fischl_add_entry(TreeNode *parent, int new_inode_number, const char *fileName, INode_Data *new_inode);
|
||||
int fischl_rm_entry(TreeNode *parent, const char *fileName);
|
||||
/*if want to use dir mode use the subdirectory treeNode pointer */
|
||||
|
@ -8,12 +8,13 @@ class FilesOperation {
|
||||
Fs *fs;
|
||||
void create_dot_dotdot(INode_Data*, u_int64_t);
|
||||
|
||||
public:
|
||||
public:
|
||||
TreeNode *root_node;
|
||||
FilesOperation(RawDisk&, Fs*);
|
||||
//int read_datablock(const INode_Data& inode, u_int64_t index, char* buffer);
|
||||
//int write_datablock(INode_Data& inode, u_int64_t index, char* buffer);
|
||||
void initialize_rootinode();
|
||||
void initialize(bool load);
|
||||
void printbuffer(const char*,int);
|
||||
void printDirectory(u_int64_t);
|
||||
bool permission_check(int, INode_Data*);
|
||||
|
@ -156,7 +156,7 @@ TreeNode *fischl_init_entry(int new_inode_number, const char *fileName, INode_Da
|
||||
return newDir;
|
||||
}
|
||||
|
||||
int fischl_add_entry_for_cache(TreeNode *parent, int new_inode_number, const char *fileName, INode_Data *new_inode, FileNode *file){
|
||||
FileNode* fischl_add_entry_for_cache(TreeNode *parent, int new_inode_number, const char *fileName, INode_Data *new_inode){
|
||||
char *Name = strdup(fileName);
|
||||
TreeNode *newDir = NULL;
|
||||
/*If directory, malloc TreeNode, and then create filenode that belongs to Parent hash table content*/
|
||||
@ -173,9 +173,7 @@ int fischl_add_entry_for_cache(TreeNode *parent, int new_inode_number, const cha
|
||||
//Diretory have its own file information, that is . here
|
||||
if(newDir != NULL)
|
||||
newDir->self_info = newFile;
|
||||
file = newFile;
|
||||
//free(Name); cannot free name
|
||||
return 0;
|
||||
return newFile;
|
||||
}
|
||||
|
||||
int fischl_add_entry(TreeNode *parent, int new_inode_number, const char *fileName, INode_Data *new_inode){
|
||||
@ -220,6 +218,8 @@ FileNode *fischl_find_entry(Fs *fs, TreeNode *root, const char *path){
|
||||
TreeNode *current = root;
|
||||
FileNode *file = NULL;
|
||||
|
||||
printf("FINDING %s %s %llu\n", path, segment, current->self_info->inode_number);
|
||||
|
||||
while (segment != NULL && current != NULL) {
|
||||
if (strcmp(segment, "..") == 0) {
|
||||
// Move up to the parent directory
|
||||
@ -249,9 +249,8 @@ FileNode *fischl_find_entry(Fs *fs, TreeNode *root, const char *path){
|
||||
ent.deserialize(buffer+i);
|
||||
//printf("WARNING:%d %llu %llu %s %s\n",__LINE__,inode.inode_num, ent.inode_number, ent.file_name, segment);
|
||||
if (ent.inode_number && strcmp(ent.file_name, segment)==0) {
|
||||
if(fischl_add_entry_for_cache(current, ent.inode_number, ent.file_name, &inode, file)<0){
|
||||
return NULL;
|
||||
}
|
||||
file = fischl_add_entry_for_cache(current, ent.inode_number, ent.file_name, &inode);
|
||||
//printf("DONE !! %llu\n", file->inode_number);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -259,6 +258,7 @@ FileNode *fischl_find_entry(Fs *fs, TreeNode *root, const char *path){
|
||||
}
|
||||
if (file != NULL && file->subdirectory == NULL) {
|
||||
free(pathCopy);
|
||||
//printf("FOUND !! %llu\n", file->inode_number);
|
||||
return file; //File found
|
||||
//return current; return filenode
|
||||
}
|
||||
|
@ -46,6 +46,20 @@ void FilesOperation::initialize_rootinode() {
|
||||
fs->inode_manager->save_inode(root_inode);
|
||||
}
|
||||
|
||||
void FilesOperation::initialize(bool load) {
|
||||
if (load){
|
||||
INode_Data *root_inode = new INode_Data();
|
||||
root_inode->inode_num = 1;
|
||||
fs->inode_manager->load_inode(root_inode);
|
||||
root_node = fischl_init_entry(1, "/", root_inode);
|
||||
assert(root_node->self_info!=NULL);
|
||||
fs->load_superblock();
|
||||
}
|
||||
else{
|
||||
initialize_rootinode();
|
||||
}
|
||||
}
|
||||
|
||||
void FilesOperation::printDirectory(u_int64_t inode_number) {
|
||||
INode_Data inode;
|
||||
inode.inode_num = inode_number;
|
||||
@ -97,6 +111,7 @@ INode_Data* FilesOperation::create_new_inode(u_int64_t parent_inode_number, cons
|
||||
bool allocated = false;
|
||||
INode_Data *new_inode = new INode_Data();
|
||||
fs->inode_manager->new_inode(getuid(), getgid(), mode, new_inode);
|
||||
//printf("%llu\n",new_inode->inode_num);
|
||||
if ((mode & S_IFMT) == S_IFDIR) {
|
||||
create_dot_dotdot(new_inode, parent_inode_number);
|
||||
fs->inode_manager->save_inode(new_inode);
|
||||
@ -194,7 +209,7 @@ bool FilesOperation::permission_check(int mask, INode_Data *inode) {
|
||||
mode_t per = (mode_t)inode->metadata.permissions;
|
||||
uid_t uid = (uid_t)inode->metadata.uid;
|
||||
gid_t gid = (gid_t)inode->metadata.gid;
|
||||
printf("PERMISSION CHECK %d %llu %llu %o\n", mask, uid, gid, per);
|
||||
//printf("PERMISSION CHECK %d %llu %llu %o\n", mask, uid, gid, per);
|
||||
if(getuid() == uid){
|
||||
if ((mask & R_OK) && !(per & S_IRUSR)) {
|
||||
return false; // Permission denied for reading
|
||||
@ -367,7 +382,7 @@ int FilesOperation::fischl_getattr(const char *path, struct stat *stbuf, struct
|
||||
inode.inode_num = fh;
|
||||
fs->inode_manager->load_inode(&inode);
|
||||
|
||||
printf("GETATTR PERM %o\n", (mode_t)inode.metadata.permissions);
|
||||
//printf("GETATTR PERM %o\n", (mode_t)inode.metadata.permissions);
|
||||
|
||||
//memset(stbuf, 0, sizeof(struct stat));
|
||||
if ((inode.metadata.permissions & S_IFMT) == S_IFDIR) {
|
||||
@ -424,7 +439,7 @@ int FilesOperation::fischl_readdir(const char *path, void *buf, fuse_fill_dir_t
|
||||
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);
|
||||
printf("%s\t%llu;\t\n", ent.file_name, ent.inode_number);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ static struct options {
|
||||
Fs *fs;
|
||||
FilesOperation *fsop;
|
||||
int show_help;
|
||||
bool load;
|
||||
} options;
|
||||
|
||||
#define OPTION(t, p) \
|
||||
@ -34,7 +35,7 @@ static const struct fuse_opt option_spec[] = {
|
||||
|
||||
void* fischl_init(struct fuse_conn_info *conn, struct fuse_config *cfg) {
|
||||
cfg->use_ino = 1;
|
||||
options.fsop->initialize_rootinode();
|
||||
options.fsop->initialize(options.load);
|
||||
}
|
||||
|
||||
int fischl_create(const char *path, mode_t mode, struct fuse_file_info *fi) {
|
||||
@ -191,12 +192,14 @@ static void show_help(const char *progname)
|
||||
int fischl(int argc, char *argv[])
|
||||
{
|
||||
int ret;
|
||||
if(argc < 2){
|
||||
printf("WRONG ARGUMENTS");
|
||||
if(argc < 3){
|
||||
printf("WRONG ARGUMENTS\n");
|
||||
return 0;
|
||||
}
|
||||
std::swap(argv[0], argv[1]);
|
||||
struct fuse_args args = FUSE_ARGS_INIT(argc-1, argv+1);
|
||||
std::swap(argv[1], argv[2]);
|
||||
|
||||
struct fuse_args args = FUSE_ARGS_INIT(argc-2, argv+2);
|
||||
srand(time(NULL)); // Seed the random number generator
|
||||
//const char* d = (argc < 2) ? "/dev/vdc" : argv[1];
|
||||
|
||||
@ -207,8 +210,18 @@ int fischl(int argc, char *argv[])
|
||||
else{
|
||||
options.H = new RealRawDisk(argv[0]);
|
||||
}
|
||||
if(strcmp(argv[1], "l")==0){
|
||||
options.load = true;
|
||||
}
|
||||
else if(strcmp(argv[1], "n")==0){
|
||||
options.load = false;
|
||||
}
|
||||
else{
|
||||
printf("WRONG l/n ARGUMENTS\n");
|
||||
return 0;
|
||||
}
|
||||
options.fs = new Fs(options.H);
|
||||
options.fs->format();
|
||||
if(!options.load)options.fs->format();
|
||||
options.fsop = new FilesOperation(*options.H, options.fs);
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user