示例#1
0
文件: File.cpp 项目: 02767a/linuxEEE
void File::createFile(char* file)//, DirectoryManager& dm )
{
	DirectoryManager* d = DirectoryManager::getInstance();
	DirectoryManager& dm = *d;

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

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

	Inode inode;

	char mode[5] = "f666";

	char time[13];
	getCurrentTime(time);

	char linkCount[2] = "1";
	char blocks[2] = "1";

	/* ( ���� ) ���� ���� �� ������ ���� ������ 1 ( �� ������ �����ϹǷ� ), ������ ���� �ε����� FileSystem���� �Ҵ����� */
	// datablock[dataIdx] �� ���ϸ� ���� setDatablock( int idx, char* data ) --> ( dataIdx, file );
	char size[2] = "0"; // getSizeOfDataBlock( int idx );
						// Inode Table�� ���� ���ֱ� ( char* mode ,int size, struct tm lastTime, struct tm creatTime, struct tm modifyTime,  int links_count, int blocks, int dataIdx) 
						// Inode Table������ block[]�� dataIdx ������

	inode.mode = mode;
	inode.size = size;

	// ���ϻ����ÿ��� ��� �����Ƿ� �Ű������� ������ Ÿ�� ��ü�� �ѱ�
	inode.time = time;      // ���� ������ ���� �ð� ����
	inode.ctime = time;      // ���� ���� �ð� ����
	inode.mtime = time;      // ������ ���������� ������ �ð� ����
	inode.linksCount = linkCount;
	inode.blocks = blocks;

	int inodeNo = fs.writeFS(inode);
	/*
	(FS)   BlockDescriptor Table�� �� �Ҵ�� ��� ��, �� �Ҵ�� inode �� ����
	inode�� writeFS�� ���� FS�� ������ ���� ���� �������� FS�� �������ְ�,  inodeNo�� �޾ƿ´�.
	*/

	vector<string>* pathFiles = pm.getAllAbsPath(file);
	Directory dir = dm.Dir_Read(stringToCharArr((*pathFiles)[pathFiles->size() - 2]));

	Entry fileEntry;
	fileEntry.inodeNum = inodeNo;

	vector<string> files;
	pm.doAnalyzeFolder(file, files);// ������ ���ʷ� ��������

	strcpy(fileEntry.name, files[files.size() - 1].c_str());

	// directory.addDir( inodeNo, filename ); // ���ϸ�� ����InodeNo�� ���丮�� ����
	dir.addDirectory(fileEntry, inodeNo);
}   // createFile
示例#2
0
void File::createFile(Entry* fileEntry, int& dirInodeNo)//, DirectoryManager& dm )
{
	FileSystem& fs = *FileSystem::getInstance();

	Inode inode;

	char mode[5] = "f666";

	char time[13];
	getCurrentTime(time);

	char linkCount[2] = "1";
	char blocks[2] = "1";

	char size[2] = "0"; // getSizeOfDataBlock( int idx );
						// Inode Table�� ���� ���ֱ� ( char* mode ,int size, struct tm lastTime, struct tm creatTime, struct tm modifyTime,  int links_count, int blocks, int dataIdx) 
						// Inode Table������ block[]�� dataIdx ������

	inode.mode = mode;
	inode.size = size;

	// ���ϻ����ÿ��� ��� �����Ƿ� �Ű������� ������ Ÿ�� ��ü�� �ѱ�
	inode.time = time;      // ���� ������ ���� �ð� ����
	inode.ctime = time;      // ���� ���� �ð� ����
	inode.mtime = time;      // ������ ���������� ������ �ð� ����
	inode.linksCount = linkCount;
	inode.blocks = blocks;

	int inodeNo = fs.writeFS(inode);
	/*
	(FS)   BlockDescriptor Table�� �� �Ҵ�� ��� ��, �� �Ҵ�� inode �� ����
	inode�� writeFS�� ���� FS�� ������ ���� ���� �������� FS�� �������ְ�,  inodeNo�� �޾ƿ´�.
	*/

	fileEntry->inodeNum = inodeNo;
	
	// directory.addDir( inodeNo, filename ); // ���ϸ�� ����InodeNo�� ���丮�� ����
	Directory dir;
	dir.addDirectory( *fileEntry, dirInodeNo );
}   // createFile
示例#3
0
bool Directory::addItems(const QString & path )
{
	QDir thisDir( path );
	if( !thisDir.isReadable() )
	{
		return false;
	}

	treeWidget()->setUpdatesEnabled( false );

	bool added_something = false;

	QStringList files = thisDir.entryList( QDir::Dirs, QDir::Name );
	for( QStringList::const_iterator it = files.constBegin();
						it != files.constEnd(); ++it )
	{
		QString cur_file = *it;
		if( cur_file[0] != '.' )
		{
			bool orphan = true;
			for( int i = 0; i < childCount(); ++i )
			{
				Directory * d = dynamic_cast<Directory *>(
								child( i ) );
				if( d == NULL || cur_file < d->text( 0 ) )
				{
					insertChild( i, new Directory( cur_file,
							path, m_filter ) );
					orphan = false;
					break;
				}
				else if( cur_file == d->text( 0 ) )
				{
					d->addDirectory( path );
					orphan = false;
					break;
				}
			}
			if( orphan )
			{
				addChild( new Directory( cur_file, path,
								m_filter ) );
			}

			added_something = true;
		}
	}

	QList<QTreeWidgetItem*> items;
	files = thisDir.entryList( QDir::Files, QDir::Name );
	for( QStringList::const_iterator it = files.constBegin();
						it != files.constEnd(); ++it )
	{
		QString cur_file = *it;
		if( cur_file[0] != '.' &&
				thisDir.match( m_filter, cur_file.toLower() ) )
		{
			items << new FileItem( cur_file, path );
			added_something = true;
		}
	}
	addChildren( items );

	treeWidget()->setUpdatesEnabled( true );

	return added_something;
}
示例#4
0
void FileBrowser::addItems(const QString & path )
{
	if( m_dirsAsItems )
	{
		m_l->addTopLevelItem( new Directory( path,
						QString::null, m_filter ) );
		return;
	}

	QDir cdir( path );
	QStringList files = cdir.entryList( QDir::Dirs, QDir::Name );
	for( QStringList::const_iterator it = files.constBegin();
						it != files.constEnd(); ++it )
	{
		QString cur_file = *it;
		if( cur_file[0] != '.' )
		{
			bool orphan = true;
			for( int i = 0; i < m_l->topLevelItemCount(); ++i )
			{
				Directory * d = dynamic_cast<Directory *>(
						m_l->topLevelItem( i ) );
				if( d == NULL || cur_file < d->text( 0 ) )
				{
					m_l->insertTopLevelItem( i,
						new Directory( cur_file, path,
								m_filter ) );
					orphan = false;
					break;
				}
				else if( cur_file == d->text( 0 ) )
				{
					d->addDirectory( path );
					orphan = false;
					break;
				}
			}
			if( orphan )
			{
				m_l->addTopLevelItem( new Directory( cur_file,
							path, m_filter ) );
			}
		}
	}

	files = cdir.entryList( QDir::Files, QDir::Name );
	for( QStringList::const_iterator it = files.constBegin();
						it != files.constEnd(); ++it )
	{
		QString cur_file = *it;
		if( cur_file[0] != '.' )
		{
			// TODO: don't insert instead of removing, order changed
			// remove existing file-items
			QList<QTreeWidgetItem *> existing = m_l->findItems(
					cur_file, Qt::MatchFixedString );
			if( !existing.empty() )
			{
				delete existing.front();
			}
			(void) new FileItem( m_l, cur_file, path );
		}
	}
}
示例#5
0
Directory* DirectoryManager::returnDir(int in)
{
	//이 아이노드 넘버가 저장되어있는 블락 가져온다.
	//이 블락으로 데이터블록에 접근하여 데이터블록 가져온다.
	//이 데이터블록으로 디렉토리 객체를 만든다. ( 엔트리들 )
	FileSystem& fs = *FileSystem::getInstance();
	Inode inode = fs.readFS(in);
	if (strchr(inode.mode, 'f'))
		return NULL;
	int blocks = atoi(inode.blocks); //해당 파일의 블록 수
	int dataIdx[20];
	translateCharArrToIntArr(inode.dataBlockList, dataIdx, blocks);

	DataBlock* dBlock = new DataBlock[blocks];

	for (int i = 0; i < blocks; i++)
	{
		dBlock[i] = fs.dataBlocks[dataIdx[i]-6]; //dataBlock 내용들 
	}
	string data = "";
	cout << "blocks " << blocks << endl;
	for (int i = 0; i < blocks; i++)
	{
		char blockData[BLOCK_SIZE];
		fs.readFS(dataIdx[i], blockData);
		data += blockData;
	}

	Directory* dr = new Directory;

	//1. 엔트리 리스트 받아오기 -> 구분자 "/"
	//vector<string>& eList = *tokenize(data,"/");
	//2. 엔트리 간 구분하기 -> 구분자 ";"


	// Trimming
	string str = data;
	str.erase(0, str.find_first_not_of(' '));       //prefixing spaces
	str.erase(str.find_last_not_of(' ') + 1);


	vector<Entry> vEntry;

	//3. 엔트리 속성 뽑아내기 -> 구분자 ","
	vector<string>& entry = *tokenize(str.c_str(), ";");
	for (int j = 0; j < entry.size(); j++)
	{
		Entry en;
		vector<string>& tmp = *tokenize(entry[j], ",");

		strcpy(en.name, tmp[0].c_str());
		en.inodeNum = stoi(tmp[1]);
		vEntry.push_back(en);
	}

	for (int i = 0; i < vEntry.size(); i++)
	{
		dr->addDirectory(vEntry[i]);
	}
	return dr;
}
示例#6
0
void DirectoryManager::Dir_Create(char* direc)
{
	try {
		//Bitmap 갱신 함수를 통해 비트맵 갱신
		string path = direc;

		Inode inode;
		
		// inode 설정
		//비트맵들 1로 설정 ..
		
		inode.mode = "d777";

		// int EmptyDataNum = dBlockBitmap.getEmpty();
		// int EmptyInodeNum = inodeBitmap.getEmpty();

		ppp.push("DC");
		// 절대 경로 분석
		PathManager& pm = *PathManager::getInstance();
		vector<string> arr;

		pm.doAnalyzeFolder(direc, arr);
		

		int n = arr.size(); // n: 경로상의 폴더 개수?

		string currDir = arr[n - 1]; // 현재디렉토리 이름(내가 만들 디렉토리)
		string topDir = ""; // 상위디렉토리 이름

		if (strcmp(direc, "/") == 0)
			topDir = arr[n - 1]; // 현재디렉토리 이름(내가 만들 디렉토리)
		else
			topDir = arr[n - 2];
		//addDirectory 

		int currDirInode = -1;
		int topDirInode = -1;
		
		if(path == "/")
			topDirInode = returnInodeNum((char*)topDir.c_str());
		else
			topDirInode = returnInodeNum(stringToCharArr((*pm.getAllAbsPath(direc))[n - 2]));


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

		//memcpy(dB.data, (void *)content.c_str, sizeof(content)); 


		Directory curDr;
		Directory topDr;

		char time[13];
		getCurrentTime(time);

		char linkCount[2] = "0";

		//Inode 정보 설정
		inode.blocks = "1";
		inode.linksCount = linkCount;
		inode.mtime = time;
		inode.size = "0";
		inode.time = time;
		inode.ctime = time;

		if (strcmp(direc, "/") != 0 && topDr.isExist((char*)currDir.c_str()) == true)
		{
			cout << "dir exist" << endl;
			return;
		}//디렉토리 중복 검사
		ppp.push("2");
		currDirInode = fs.writeFS_Dir(inode);
		
		ppp.push("3");
		


		if (strcmp(direc, "/") != 0)
		{
			topDr = *returnDir(topDirInode);
			Entry e;
			ppp.push("4");
			e.inodeNum = currDirInode;
			strcpy(e.name, currDir.c_str());
			topDr.addDirectory(e, topDirInode);
			ppp.push("5");
		}
		curDr.setInodeNum(currDirInode, topDirInode);
		Entry *enList = curDr.entryList;

		string content = ".,";

		//cout << enList[0].inodeNum << endl;
		content.append(to_string(enList[0].inodeNum));
		content.append(";..," + to_string(enList[1].inodeNum));
		content.append(";");
		//데이터블록에 데이터 추가(idx는 datablock Index)
		
		//할당받은 블록 받아오기
		char* tmpBlockList = fs.inodeBlock->getDataBlockList(currDirInode);
		int idx = atoi(tmpBlockList);

		//할당받은 블록 리셋
		fs.resetDataBlock(&idx, 1);
		
		//다시 쓴다
		int assignedIdx = fs.writeFS((char*)content.c_str());
		char dataBlockList[] = "   \0";
		itoa(assignedIdx, dataBlockList);

		char size[4];
		memcpy(size, stringToCharArr(to_string(content.length())), strlen(stringToCharArr(to_string(content.length())))+1);

		//링크 정보 다시 읽어와야 함
		inode = fs.readFS(currDirInode);

		//Inode 정보 설정
		getCurrentTime(time);

		inode.blocks = "1";
		inode.mtime = time;
		inode.size = size;
		inode.dataBlockList = dataBlockList;

		ppp.push("6");
		//데이터 블록 추가 후 업데이트
		fs.updateInode_writeFile(currDirInode, inode);
		ppp.push("7");
	}
	catch (char* msg)
	{
		cerr << "error : " << msg << endl;
	}
}