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
|
## mount and test
|
||||||
normal usage:
|
normal usage:
|
||||||
```bash
|
```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:
|
if the diskpath need to be accessed by root:
|
||||||
```bash
|
```bash
|
||||||
sudo ./fischl diskpath -o allow_other mountpoint
|
sudo ./fischl diskpath n -o allow_other mountpoint
|
||||||
```
|
```
|
||||||
|
|
||||||
for debugging:
|
for debugging:
|
||||||
```bash
|
```bash
|
||||||
sudo ./fischl diskpath -o allow_other -d mountpoint
|
sudo ./fischl diskpath n -o allow_other -d mountpoint
|
||||||
```
|
```
|
||||||
|
|
||||||
## run test
|
## run test
|
||||||
|
@ -33,7 +33,7 @@ typedef struct RenameInfo {
|
|||||||
TreeNode *fischl_init_entry(int new_inode_number, const char *fileName, INode_Data *new_inode);
|
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 */
|
/*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*/
|
/*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_add_entry(TreeNode *parent, int new_inode_number, const char *fileName, INode_Data *new_inode);
|
||||||
int fischl_rm_entry(TreeNode *parent, const char *fileName);
|
int fischl_rm_entry(TreeNode *parent, const char *fileName);
|
||||||
/*if want to use dir mode use the subdirectory treeNode pointer */
|
/*if want to use dir mode use the subdirectory treeNode pointer */
|
||||||
|
@ -8,12 +8,13 @@ class FilesOperation {
|
|||||||
Fs *fs;
|
Fs *fs;
|
||||||
void create_dot_dotdot(INode_Data*, u_int64_t);
|
void create_dot_dotdot(INode_Data*, u_int64_t);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TreeNode *root_node;
|
TreeNode *root_node;
|
||||||
FilesOperation(RawDisk&, Fs*);
|
FilesOperation(RawDisk&, Fs*);
|
||||||
//int read_datablock(const INode_Data& inode, u_int64_t index, char* buffer);
|
//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);
|
//int write_datablock(INode_Data& inode, u_int64_t index, char* buffer);
|
||||||
void initialize_rootinode();
|
void initialize_rootinode();
|
||||||
|
void initialize(bool load);
|
||||||
void printbuffer(const char*,int);
|
void printbuffer(const char*,int);
|
||||||
void printDirectory(u_int64_t);
|
void printDirectory(u_int64_t);
|
||||||
bool permission_check(int, INode_Data*);
|
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;
|
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);
|
char *Name = strdup(fileName);
|
||||||
TreeNode *newDir = NULL;
|
TreeNode *newDir = NULL;
|
||||||
/*If directory, malloc TreeNode, and then create filenode that belongs to Parent hash table content*/
|
/*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
|
//Diretory have its own file information, that is . here
|
||||||
if(newDir != NULL)
|
if(newDir != NULL)
|
||||||
newDir->self_info = newFile;
|
newDir->self_info = newFile;
|
||||||
file = newFile;
|
return newFile;
|
||||||
//free(Name); cannot free name
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int fischl_add_entry(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){
|
||||||
@ -220,6 +218,8 @@ FileNode *fischl_find_entry(Fs *fs, TreeNode *root, const char *path){
|
|||||||
TreeNode *current = root;
|
TreeNode *current = root;
|
||||||
FileNode *file = NULL;
|
FileNode *file = NULL;
|
||||||
|
|
||||||
|
printf("FINDING %s %s %llu\n", path, segment, current->self_info->inode_number);
|
||||||
|
|
||||||
while (segment != NULL && current != NULL) {
|
while (segment != NULL && current != NULL) {
|
||||||
if (strcmp(segment, "..") == 0) {
|
if (strcmp(segment, "..") == 0) {
|
||||||
// Move up to the parent directory
|
// 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);
|
ent.deserialize(buffer+i);
|
||||||
//printf("WARNING:%d %llu %llu %s %s\n",__LINE__,inode.inode_num, ent.inode_number, ent.file_name, segment);
|
//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 (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){
|
file = fischl_add_entry_for_cache(current, ent.inode_number, ent.file_name, &inode);
|
||||||
return NULL;
|
//printf("DONE !! %llu\n", file->inode_number);
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -259,6 +258,7 @@ FileNode *fischl_find_entry(Fs *fs, TreeNode *root, const char *path){
|
|||||||
}
|
}
|
||||||
if (file != NULL && file->subdirectory == NULL) {
|
if (file != NULL && file->subdirectory == NULL) {
|
||||||
free(pathCopy);
|
free(pathCopy);
|
||||||
|
//printf("FOUND !! %llu\n", file->inode_number);
|
||||||
return file; //File found
|
return file; //File found
|
||||||
//return current; return filenode
|
//return current; return filenode
|
||||||
}
|
}
|
||||||
|
@ -46,6 +46,20 @@ void FilesOperation::initialize_rootinode() {
|
|||||||
fs->inode_manager->save_inode(root_inode);
|
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) {
|
void FilesOperation::printDirectory(u_int64_t inode_number) {
|
||||||
INode_Data inode;
|
INode_Data inode;
|
||||||
inode.inode_num = inode_number;
|
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;
|
bool allocated = false;
|
||||||
INode_Data *new_inode = new INode_Data();
|
INode_Data *new_inode = new INode_Data();
|
||||||
fs->inode_manager->new_inode(getuid(), getgid(), mode, new_inode);
|
fs->inode_manager->new_inode(getuid(), getgid(), mode, new_inode);
|
||||||
|
//printf("%llu\n",new_inode->inode_num);
|
||||||
if ((mode & S_IFMT) == S_IFDIR) {
|
if ((mode & S_IFMT) == S_IFDIR) {
|
||||||
create_dot_dotdot(new_inode, parent_inode_number);
|
create_dot_dotdot(new_inode, parent_inode_number);
|
||||||
fs->inode_manager->save_inode(new_inode);
|
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;
|
mode_t per = (mode_t)inode->metadata.permissions;
|
||||||
uid_t uid = (uid_t)inode->metadata.uid;
|
uid_t uid = (uid_t)inode->metadata.uid;
|
||||||
gid_t gid = (gid_t)inode->metadata.gid;
|
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(getuid() == uid){
|
||||||
if ((mask & R_OK) && !(per & S_IRUSR)) {
|
if ((mask & R_OK) && !(per & S_IRUSR)) {
|
||||||
return false; // Permission denied for reading
|
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;
|
inode.inode_num = fh;
|
||||||
fs->inode_manager->load_inode(&inode);
|
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));
|
//memset(stbuf, 0, sizeof(struct stat));
|
||||||
if ((inode.metadata.permissions & S_IFMT) == S_IFDIR) {
|
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);
|
ent.deserialize(buffer+i);
|
||||||
if (ent.inode_number) {
|
if (ent.inode_number) {
|
||||||
filler(buf, ent.file_name, NULL, 0, FUSE_FILL_DIR_PLUS);
|
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;
|
Fs *fs;
|
||||||
FilesOperation *fsop;
|
FilesOperation *fsop;
|
||||||
int show_help;
|
int show_help;
|
||||||
|
bool load;
|
||||||
} options;
|
} options;
|
||||||
|
|
||||||
#define OPTION(t, p) \
|
#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) {
|
void* fischl_init(struct fuse_conn_info *conn, struct fuse_config *cfg) {
|
||||||
cfg->use_ino = 1;
|
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) {
|
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 fischl(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
if(argc < 2){
|
if(argc < 3){
|
||||||
printf("WRONG ARGUMENTS");
|
printf("WRONG ARGUMENTS\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
std::swap(argv[0], argv[1]);
|
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
|
srand(time(NULL)); // Seed the random number generator
|
||||||
//const char* d = (argc < 2) ? "/dev/vdc" : argv[1];
|
//const char* d = (argc < 2) ? "/dev/vdc" : argv[1];
|
||||||
|
|
||||||
@ -207,8 +210,18 @@ int fischl(int argc, char *argv[])
|
|||||||
else{
|
else{
|
||||||
options.H = new RealRawDisk(argv[0]);
|
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 = new Fs(options.H);
|
||||||
options.fs->format();
|
if(!options.load)options.fs->format();
|
||||||
options.fsop = new FilesOperation(*options.H, options.fs);
|
options.fsop = new FilesOperation(*options.H, options.fs);
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user