Exemplo n.º 1
0
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 "디렉토리가 비어있지 않습니다.";
}
Exemplo n.º 2
0
int File::openFile(char* file, TableManager& tm)//, FileSystem& fs )
{
	FileSystem* f = FileSystem::getInstance();
	FileSystem& fs = *f;

	PathManager* p = PathManager::getInstance();
	PathManager& pm = *p;

	int fd = 0;

	// InodeTable���� ���� ���丮�� ������ �� idx �޾ƿ�
	vector<string>* pathFiles = pm.getAllAbsPath(file);// ������ ���ʷ� ��������
	DirectoryManager dm = DirectoryManager::getTmpInstance();
	Directory dir = dm.Dir_Read(stringToCharArr((*pathFiles)[pathFiles->size() - 2]));

	// ���͸��� �����ͺ� �о��
	Entry* dirFileEntry = dir.findName(stringToCharArr((*pathFiles)[pathFiles->size() - 1]));

	if (dirFileEntry == nullptr)
	{
		cout << endl << "�ش� ���丮�� ������ ����." << endl;
		fd = -1;
		return fd;
	}

	int inodeNo = dirFileEntry->inodeNum;
	Inode inode = fs.readFS(inodeNo);
	/* (FS)   InodeBlock���� inodeNo��° �о� �� */

	if (tm.isExistInInodeTable(inodeNo))
	{
		cout << endl << "open�Ǿ��ִ� �Լ���" << endl;
		return fd;// fd = 0 -> �̹� ���µǾ��ִ� ���
	}

	fd = tm.fileOpenEvent(inodeNo, inode);
	/*
	InodeTable�� �о�� inode���� ����->�ý����������̺�->���ϵ�ũ���� ������

	InodeBlocks���� ������ ���̳�� ������ �о� ���̳�� ���̺��� �ε��� n�� ����
	�ý��� ���� ���̺��� �ε��� k�� ���� ������ ����
	inode��ȣ�� �ε���n�� �����ϰ� ���� �����ʹ� 0���� �ʱ�ȭ
	���� ��ũ���� ���̺��� �ε��� j �� �ý��� ���� ���̺��� �ε��� k ����
	��� j ����
	*/

	return fd;      //���� ��ũ���� ��ȯ
} // openFile
Exemplo n.º 3
0
char DirectoryManager::isFile(char* filename, Directory currentDir)
{
	if (strcmp(filename, "/") == 0)
	{
		return 'd';
	}
	Entry* fileEntry = currentDir.findName(filename);
	if (fileEntry == NULL) {
		throw "파일이 존재하지 않습니다.";
	}

	Directory* dir = returnDir(fileEntry->inodeNum);
	if (dir == NULL)
		return 'f';
	return 'd';
}
Exemplo n.º 4
0
int File::findFile(char* file) // ����� Ȥ�� ������ 
{
	PathManager* p = PathManager::getInstance();
	PathManager& pm = *p;

	FileSystem* f = FileSystem::getInstance();
	FileSystem& fs = *f;

	char* absFile = pm.getAbsolutePath(file);

	TableManager tmpTM = TableManager::getTmpInstance();
	vector<string>* pathFiles = pm.getAllAbsPath(file);// ������ ���ʷ� ��������
	int count = pathFiles->size();
	int *fd = new int[count];
	for (int i = 0; i < count - 1; i++)
	{
		fd[i] = openFile(stringToCharArr((*pathFiles)[i]), tmpTM);
	}
	InodeElement* dirInode = (InodeElement*)tmpTM.getElement(INODET, fd[count - 2]);
	DirectoryManager dm = DirectoryManager::getTmpInstance();
	Directory* dir = dm.returnDir(dirInode->inode_number);

	Entry* fileEntry = dir->findName(file);

	if (fileEntry == nullptr)
	{
		string path = pm.getCurrentPath() + '/';
		string filename = file;
		path = path + filename;

		createFile((char*)path.c_str());
	}

	TableManager* t = TableManager::getInstance();
	TableManager& tm = *t;

	return openFile(file, tm);
}
Exemplo n.º 5
0
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);
	}
}
Exemplo n.º 6
0
Entry* File::findFile( char* filename,  int* dirInodeNo ) // ������ 
{
	FileSystem& fs = *FileSystem::getInstance();
	PathManager& pm = *PathManager::getInstance();
	TableManager& tm = *TableManager::getInstance();
	DirectoryManager& dm = *DirectoryManager::getInstance();

	vector<string> filenames = pm.doAnalyzeFolder( filename );
	vector<string>& pathFiles = *pm.getAllAbsPath( filename );

	Entry* fileEntry;
	
	//int count = pathFiles.size();
	vector<string>::size_type count = pathFiles.size();
	// Ÿ������ ������ �����θ� ���� ���丮�� ã�� ���̳�� ��ȣ�� ����

	*dirInodeNo = dm.returnInodeNum( (char*) pathFiles.at( count -2 ).c_str() );
	// ���丮�� ���̳�� ��ȣ�� ���� ���丮�� �޾ƿ�
	Directory* dir = dm.returnDir( *dirInodeNo );
	fileEntry = dir->findName( (char*)filenames[ filenames.size()-1].c_str() ); // ���丮���� ���Ͽ�Ʈ���� ã��
	//delete dir;

	return fileEntry; // ��� ��� nullptr
}