void DirectoryManager::Dir_Unlink(char* direc) { /* direc이 나타내는 디렉토리를 삭제. 해당 디렉토리를 포함하는 상위 디렉토리에서도 관련 내용 삭제 data block, inode도 삭제, 관련 bitmap도 0으로 설정 디렉토리에 파일이 존재하면 에러 메시지 출력 루트 디렉토리는 삭제 불가 */ Directory dr = Dir_Read(direc); if (dr.entryCnt == 2) { int topInodeNum = dr.findName("..")->inodeNum; int currInodeNum = dr.findName(".")->inodeNum; // 아이노드 번호가 시스템파일 테이블에 없으면 파일 Unlink과정을 한다 // 속하는 상위 디렉토리의 엔트리에 해당 파일과 아이노드번호 삭제 Directory d = *returnDir(topInodeNum); d.rmDirectory(currInodeNum, topInodeNum); FileSystem& fs = *FileSystem::getInstance(); // InodeBitmap의 해당 비트 0으로 set // BlockBitmap의 dataIdx 에 해당하는 비트 0으로 set // InodeBlock에서 아이노드 번호에 해당하는 아이노드 삭제 Inode inodeData = fs.inodeBlock->getInodeData(currInodeNum); int blocks = atoi(inodeData.blocks); int* dataIdx = new int[blocks]; translateCharArrToIntArr(inodeData.dataBlockList, dataIdx, blocks); fs.resetDataBlock(dataIdx, blocks); fs.writeFS(currInodeNum); } else throw "디렉토리가 비어있지 않습니다."; }
void DirectoryManager::Dir_Unlink_All(char * direc) { Directory dr = Dir_Read(direc); if (dr.entryCnt != 2) { for (int i = 0; i < dr.entryCnt; i++) { string path = direc; path.append("/"); path.append(dr.entryList[i].name); if (isFile(dr.entryList[i].name, dr) == 'f') { File f; f.removeFile(dr.entryList[i].name); } else Dir_Unlink_All(stringToCharArr(path)); } } Dir_Unlink(direc); }
void DirectoryManager::openAllDir(char * path) { FileSystem& fs = *FileSystem::getInstance(); TableManager& tm = *TableManager::getInstance(); PathManager& pm = *PathManager::getInstance(); vector<string> vStr = *pm.getAllAbsPath(path); vector<string> vAllDirec = pm.doAnalyzeFolder(path); Directory dir = *returnDir(0); // root의 dir 객체 가져오기 int fd = tm.fileOpenEvent(0, fs.inodeBlock->getInodeData(0)); openedDir_FDList.push_back(fd); for (int i = 1; i < vStr.size(); i++) { // 상위 디렉토리를 통해 먼저 inodeNum과 Block을 얻는다. Entry* en = dir.findName(stringToCharArr(vAllDirec[i])); if (!en) { cout << "Name : " << vAllDirec[i] << endl; throw "dir의 엔트리에서 name을 찾지 못함."; } int inodeNum = en->inodeNum; Inode inodeBl = fs.inodeBlock->getInodeData(inodeNum); dir = Dir_Read(stringToCharArr(vStr[i])); if (tm.isExistInInodeTable(inodeNum)) { cout << endl << "open되어있는 디렉토리임" << endl; throw "error in DirectoryManager.cpp in allOpen Func";// fd = 0 -> 이미 오픈되어있는 경우 } fd = tm.fileOpenEvent(inodeNum, inodeBl); openedDir_FDList.push_back(fd); openedDirList.push_back(dir); } }
/* Initialize ProvReg strucutre from given directory */ _Use_decl_annotations_ MI_Result ProvReg_Init(ProvReg* self, const char* directory) { RegFile* reg = NULL; Dir* dir = NULL; Dir* dir2 = NULL; MI_Result r = MI_RESULT_FAILED; /* Zero-fill self */ memset(self, 0, sizeof(*self)); dir = Dir_Open(directory); if (!dir) { return r; } /* Initialize batch allocator */ Batch_Init(&self->batch, BATCH_MAX_PAGES); /* For each namespace directory in 'omirgister' */ for (;;) { DirEnt* ent = Dir_Read(dir); if (!ent) { break; } /* Ignore system directories */ if (strcmp(ent->name, ".") == 0 || strcmp(ent->name, "..") == 0) continue; /* Skip 'CVS' directories */ if (strcmp(ent->name, "CVS") == 0) continue; /* Scan .reg files in the current namespace directory */ { char path[PAL_MAX_PATH_SIZE]; Strlcpy(path, directory, sizeof(path)); Strlcat(path, "/", sizeof(path)); Strlcat(path, ent->name, sizeof(path)); /* Skip if not a dir */ if(!Isdir(path)) continue; dir2 = Dir_Open(path); if (!dir2) { goto failed; } for (;;) { DirEnt* ent2 = Dir_Read(dir2); if (!ent2) { break; } /* Ignore system directories */ if (strcmp(ent2->name,".") == 0 || strcmp(ent2->name,"..") == 0) { continue; } /* Skip non-reg file */ { char* affix = Strrchr(ent2->name, '.'); if (!affix || (Strcasecmp(&affix[1], "reg") != 0)) continue; } /* Load the reg file */ { char regPath[PAL_MAX_PATH_SIZE]; /* Form path to .reg file */ Strlcpy(regPath, path, sizeof(regPath)); Strlcat(regPath, "/", sizeof(regPath)); Strlcat(regPath, ent2->name, sizeof(regPath)); /* Create new reg file object */ reg = RegFile_New(regPath); if (!reg) { trace_ProvReg_SkipRegFile(scs(regPath)); continue; } /* For each class in the reg file */ { RegClass* rc; char* p = ent->name; /* Transpose NAMESPACE_SEPARATOR characters to '/' * characters */ while (*p) { if (*p == NAMESPACE_SEPARATOR) *p = '/'; p++; } for (rc = reg->classesHead; rc; rc = rc->next) { if (_AddEntry(self, ent->name, reg, rc) != 0) { goto failed; } } } /* For each extraClass in the reg file */ { RegClass* rc; char* p = ent->name; /* Transpose NAMESPACE_SEPARATOR characters to '/' * characters */ while (*p) { if (*p == NAMESPACE_SEPARATOR) *p = '/'; p++; } for (rc = reg->extraClassesHead; rc; rc = rc->next) { if (_AddEntryForExtraClass(self, ent->name, reg, rc) != 0) { goto failed; } } } /* Delete the current entry */ RegFile_Delete(reg); reg = NULL; } } /* Close the directory */ Dir_Close(dir2); dir2 = NULL; } } r = MI_RESULT_OK; failed: if (dir2) { Dir_Close(dir2); } if (dir) { Dir_Close(dir); } if (r != MI_RESULT_OK) { ProvReg_Destroy(self); memset(self, 0, sizeof(*self)); } if(reg) { RegFile_Delete(reg); reg = NULL; } return r; }