before big change
This commit is contained in:
parent
f816ea919c
commit
87299ece0a
@ -32,6 +32,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);
|
||||
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 */
|
||||
@ -42,4 +43,23 @@ FileNode *fischl_find_entry(TreeNode *root, const char *path);
|
||||
void freeTree(TreeNode *node);
|
||||
/*for debug use*/
|
||||
TreeNode *createDirectory(const char *dirName, TreeNode *parent, int hashSize);
|
||||
TreeNode *find_parentPath(TreeNode *root, const char *path);
|
||||
TreeNode *find_parentPath(TreeNode *root, const char *path);
|
||||
|
||||
struct DirectoryEntry {
|
||||
u_int64_t inode_number;
|
||||
char file_name[256];
|
||||
void serialize(char* buffer) {
|
||||
u_int64_t t = inode_number;
|
||||
for (int j = 0; j < 8; j++){
|
||||
buffer[j] = t & (((u_int64_t)1<<(8))-1);
|
||||
t >>= 8;
|
||||
}
|
||||
strcpy(buffer+8, file_name);
|
||||
}
|
||||
void deserialize(char* buffer) {
|
||||
inode_number = 0;
|
||||
for (int j = 0; j < 8; j++)
|
||||
inode_number = inode_number | (((u_int64_t)(unsigned char)buffer[j])<<(8*j));
|
||||
strcpy(file_name, buffer+8);
|
||||
}
|
||||
};
|
||||
|
@ -28,6 +28,7 @@ class FilesOperation {
|
||||
int fischl_readdir(const char *, void *, fuse_fill_dir_t, off_t, struct fuse_file_info *, enum fuse_readdir_flags);
|
||||
int fischl_releasedir(const char* path, struct fuse_file_info *fi);
|
||||
int fischl_unlink (const char *);
|
||||
int fischl_opendir(const char* path, struct fuse_file_info* fi);
|
||||
int fischl_rmdir(const char *);
|
||||
int fischl_readlink(const char* path, char* buf, size_t size);
|
||||
int fischl_symlink(const char* from, const char* to);
|
||||
|
@ -156,6 +156,28 @@ 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){
|
||||
char *Name = strdup(fileName);
|
||||
TreeNode *newDir = NULL;
|
||||
/*If directory, malloc TreeNode, and then create filenode that belongs to Parent hash table content*/
|
||||
if ((new_inode->metadata.permissions & S_IFMT) == S_IFDIR) {
|
||||
newDir = (TreeNode *)malloc(sizeof(TreeNode));
|
||||
newDir->dirName = Name;
|
||||
newDir->contents = createHashTable(20);//hasSize define 20
|
||||
newDir->parent = parent;
|
||||
}
|
||||
FileNode *newFile = insertHash(parent->contents, Name, newDir); //newDir == NULL indicates it's a file
|
||||
//assign INode *new_inode metadata to data member in FileNode structure
|
||||
newFile->permissions = new_inode->metadata.permissions;
|
||||
newFile->inode_number = new_inode_number;
|
||||
//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;
|
||||
}
|
||||
|
||||
int fischl_add_entry(TreeNode *parent, int new_inode_number, const char *fileName, INode_Data *new_inode){
|
||||
char *Name = strdup(fileName);
|
||||
TreeNode *newDir = NULL;
|
||||
@ -214,6 +236,26 @@ FileNode *fischl_find_entry(TreeNode *root, const char *path){
|
||||
}
|
||||
else{
|
||||
file = lookupHash(current->contents, segment);
|
||||
if (file == NULL) {
|
||||
// find on disk whether this exists
|
||||
INode_Data inode;
|
||||
inode.inode_num = current->self_info->inode_number;
|
||||
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 && strcmp(ent.file_name, segment)) {
|
||||
if(fischl_add_entry_for_cache(current, ent.inode_number, ent.file_name, &inode, file)<0){
|
||||
return NULL;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (file != NULL && file->subdirectory == NULL) {
|
||||
free(pathCopy);
|
||||
return file; //File found
|
||||
|
@ -6,25 +6,6 @@
|
||||
#include <sstream>
|
||||
#include <cassert>
|
||||
|
||||
struct DirectoryEntry {
|
||||
u_int64_t inode_number;
|
||||
char file_name[256];
|
||||
void serialize(char* buffer) {
|
||||
u_int64_t t = inode_number;
|
||||
for (int j = 0; j < 8; j++){
|
||||
buffer[j] = t & (((u_int64_t)1<<(8))-1);
|
||||
t >>= 8;
|
||||
}
|
||||
strcpy(buffer+8, file_name);
|
||||
}
|
||||
void deserialize(char* buffer) {
|
||||
inode_number = 0;
|
||||
for (int j = 0; j < 8; j++)
|
||||
inode_number = inode_number | (((u_int64_t)(unsigned char)buffer[j])<<(8*j));
|
||||
strcpy(file_name, buffer+8);
|
||||
}
|
||||
};
|
||||
|
||||
void FilesOperation::printbuffer(const char* buff, int len) {
|
||||
for(int i=0;i<len;i++){
|
||||
printf("%x ",buff[i]);
|
||||
@ -401,6 +382,15 @@ void FilesOperation::unlink_inode(u_int64_t inode_number) {
|
||||
fs->inode_manager->free_inode(&inode);
|
||||
}
|
||||
|
||||
int FilesOperation::fischl_opendir(const char* path, struct fuse_file_info* fi) {
|
||||
u_int64_t fh = namei(path);
|
||||
if (fh < 0){
|
||||
return -1;
|
||||
}
|
||||
fi->fh = fh;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int FilesOperation::fischl_rmdir(const char* path) {
|
||||
char *pathdup = strdup(path);
|
||||
char *lastSlash = strrchr(pathdup, '/');
|
||||
|
@ -61,9 +61,7 @@ static int fischl_readlink(const char* path, char* buf, size_t size) {
|
||||
}
|
||||
|
||||
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;
|
||||
return options.fsop->fischl_opendir(path, 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 flg) {
|
||||
@ -149,7 +147,7 @@ static const struct fuse_operations fischl_oper = {
|
||||
.unlink = fischl_unlink,
|
||||
.rmdir = fischl_rmdir,
|
||||
.symlink = fischl_symlink,
|
||||
.rename = fischl_rename,
|
||||
//.rename = fischl_rename,
|
||||
.link = fischl_link,
|
||||
.chmod = fischl_chmod,
|
||||
.chown = fischl_chown,
|
||||
@ -201,6 +199,7 @@ int fischl(int argc, char *argv[])
|
||||
|
||||
//setupTestDirectory(&options.root);
|
||||
options.H = new FakeRawDisk(23552);
|
||||
//options.H = new RealRawDisk("/dev/vdb");
|
||||
options.fs = new Fs(options.H);
|
||||
options.fs->format();
|
||||
options.fsop = new FilesOperation(*options.H, options.fs);
|
||||
|
Loading…
x
Reference in New Issue
Block a user