示例#1
0
文件: File.cpp 项目: 02767a/linuxEEE
void File::writeFile(int fd, char* buffer, int size)//,  TableManager& tm, FileSystem& fs )
{
	TableManager* t = TableManager::getInstance();
	TableManager& tm = *t;

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

	// (FT)   fd�� Ÿ���� inode���� data block idx�޾ƿ���
	InodeElement* inodeE = ((InodeElement*)tm.getElement(INODET, fd));
	Inode inode = inodeE->inode;
	int blocks = atoi(inode.blocks);
	int* dataIdx = new int[blocks];
	translateCharArrToIntArr(inode.dataBlockList, dataIdx, blocks);

	string filedata = buffer;   // ���������ͺ��� ����� ���ο� ������ ��ģ ��

	fs.resetDataBlock(dataIdx, blocks);// writeFile���� writeFS�� �θ��� ���� BlockBitmap�� ���Ͽ� �Ҵ��� indxe �ʱ�ȭ
									   /* ���� BlockBitmap�� 1�� ��츸 �����ͺ��� ����Ǿ��ִ� ���̹Ƿ� getDatablock�� blockbitmap�� 1���� �˻� �� ����� data return */

									   /*
									   ������ data�� ������� �°� �ɰ��� (�ݺ���)
									   writeFS�� �Ѱܼ� �������ش�
									   (FS)   block idx�� blockdata�� �Ѱܼ�  writeFS������ �ش� ������ ���� blockdata�� ����
									   */
	char fileSize[4] = { 0 };
	memcpy(fileSize, &size, sizeof(int));
	inode.size = fileSize;

	char* blockData;
	int new_Blocks = 0;
	while (size != 0)
	{
		if (size > BLOCK_SIZE)
		{
			blockData = new char[BLOCK_SIZE];
			strcpy(blockData, (filedata.substr(0, BLOCK_SIZE)).c_str());

			size -= BLOCK_SIZE;
		}

		else
		{
			blockData = new char[size];
			strcpy(blockData, (filedata.substr(0, size)).c_str());

			size = 0;
		}

		int returnIdx = fs.writeFS(blockData);
		/*
		fs.writeFS ������
		block descriptor Table ���Ҵ�� ��� ��, -> �ʱ�ȭ�Ҷ��� �ٽ� ���� �� ��������� ��
		Block Bitmap�� idx�� �ش��ϴ� ��Ʈ 1�� set -> write���� �����ͺ��� �� �� �ٷ� �ٷ� ���ִ� �ɷ�
		write����  Datablock idxã�Ƽ� DataBlock�� ���� �� blockBitmap ����������� �׸��� idx ��ȯ���ִ� �ɷ�
		*/
		translateIntArrToCharArr(&returnIdx, inode.dataBlockList + new_Blocks, 1);

		new_Blocks++;
	}

	translateIntArrToCharArr(&new_Blocks, inode.blocks, 1);
	/* �Ƹ� translateIntArrToCharArr( &new_Blocks, inode.blocks, 1);�� ���� ����, �ȵǸ� �ٲ㼭 �غ���

	char c_blocks[4];
	memcpy( c_blocks, &new_Blocks, sizeof(int) );
	string s_blocks = c_blocks;
	inode.blocks = new char[3];
	strcpy(inode.blocks, (s_blocks.substr(1, 3)).c_str());
	*/

	/* (FS)   Inode Block �� size, time(���� ������ ���ٽð�), mtime(������ ���������� ������ �ð�) blocks, block[] ���� -> FT, FS ��� ���� */
	char* currTime;
	getCurrentTime(currTime);
	inode.time = currTime;
	inode.mtime = currTime;

	tm.updateInode(fd, inode);
	fs.updateInode_writeFile(inodeE->inode_number, inode);
}// writeFile
示例#2
0
// ������ �ִ� ���ϵ����͸� buffer�� ���� ����
void File::writeFile(int fd, char* buffer, int size)//,  TableManager& tm, FileSystem& fs )
{
	TableManager& tm = *TableManager::getInstance();
	FileSystem& fs = *FileSystem::getInstance();

	// (FT)   fd�� Ÿ���� inode���� data block idx�޾ƿ���
	InodeElement* inodeE = tm.getInodeByFD( fd );
	Inode inode = inodeE->inode;
	int blocks = atoi(inode.blocks);
	int* dataIdx = new int[blocks];
	translateCharArrToIntArr(inode.dataBlockList, dataIdx, blocks);

	string filedata = buffer;   // ���������ͺ��� ����� ���ο� ������ ��ģ ��

	fs.resetDataBlock(dataIdx, blocks);// writeFile���� writeFS�� �θ��� ���� BlockBitmap�� ���Ͽ� �Ҵ��� indxe �ʱ�ȭ
									   /* ���� BlockBitmap�� 1�� ��츸 �����ͺ��� ����Ǿ��ִ� ���̹Ƿ� getDatablock�� blockbitmap�� 1���� �˻� �� ����� data return */

									   /*
									   ������ data�� ������� �°� �ɰ��� (�ݺ���)
									   writeFS�� �Ѱܼ� �������ش�
									   (FS)   block idx�� blockdata�� �Ѱܼ�  writeFS������ �ش� ������ ���� blockdata�� ����
									   */
	char fileSize[4] = { 0 };
	if ( size != 0 )
	{
		_itoa( size, fileSize );
		inode.size = fileSize;
	}

	char* blockData;
	int new_Blocks = 0;
	while (size != 0)
	{
		if (size > BLOCK_SIZE)
		{
			blockData = new char[BLOCK_SIZE];
			strcpy(blockData, (filedata.substr(0, BLOCK_SIZE)).c_str());

			size -= BLOCK_SIZE;
		}

		else
		{
			blockData = new char[size];
			strcpy(blockData, (filedata.substr(0, size)).c_str());

			size = 0;
		}

		int returnIdx = fs.writeFS( blockData );
		
		translateIntArrToCharArr(&returnIdx, inode.dataBlockList + new_Blocks, 1); // inode�� �Ҵ���� �����ͺ� �ε��� ����

		new_Blocks++;
	}

	translateIntArrToCharArr(&new_Blocks, inode.blocks, 1);	// blocks( �Ҵ���� �����ͺ� �� ) ���� 

	/* (FS)   Inode Block �� size, time(���� ������ ���ٽð�), mtime(������ ���������� ������ �ð�) blocks, block[] ���� -> FT, FS ��� ���� */
	char currTime[13] = { 0 };
	getCurrentTime(currTime);
	inode.time = currTime;
	inode.mtime = currTime;

	tm.updateInode(fd, inode);
	fs.updateInode_writeFile(inodeE->inode_number, inode);
}// writeFile
示例#3
0
void Directory::addDirectory(Entry entry, int inodeNum)
{
	//���� �߰��� entry�� ������ ��Ͽ� ���
	memcpy(&entryList[entryCnt], &entry, sizeof(Entry));
	entryCnt ++ ;

	//DataBlock dB;
	string content = entry.name;
	content += "," + entry.inodeNum;
	content += ";";
	

	/*
	for ( int i = 0 ; i < entryCnt; i ++ )
	{
		content +=  entryList[i].name;
		content += "," + entryList[i].inodeNum;
		content +=  ";";
	}
	*/
	
	FileSystem& fs = *FileSystem::getInstance();

	//memcpy(dB.data, (void *)content.c_str(), sizeof(content)); //�����ͺ�Ͽ� ������ �߰�
	
	//int fd = tmpTm.fileOpenEvent(inodeNum, fs.inodeBlock->getInodeData(inodeNum));
	//InodeElement* inodeE = ((InodeElement*)tmpTm.getElement(INODET, fd));
	Inode inodeData = fs.inodeBlock->getInodeData(inodeNum);
	int blocks = atoi(inodeData.blocks);
	int* dataIdx = new int[blocks];
	translateCharArrToIntArr(inodeData.dataBlockList, dataIdx, blocks);

	// (FT)   fd�� Ÿ���� inode���� data block idx�޾ƿ���
	//InodeElement* inodeE = ((InodeElement*)tm.getElement(INODET, fd));
	//Inode inodeData = inodeE->inode;
	//int blocks = atoi(inode.blocks);
	//int* dataIdx = new int[blocks];
	//translateCharArrToIntArr(inodeData.dataBlockList, dataIdx, blocks);

	string data = "";
	for (int i = 0; i < blocks; i++)
	{
		char* blockData;
		fs.readFS(dataIdx[i], blockData);
		data += blockData;
	}
	/*
	(FS)   data block[idx]�� ����� ������ ����
	�ϳ��� data���� �� �����ͺ��� �л��� �͵��� ��ħ
	*/
	string filedata = data + content;   // ���������ͺ��� ����� ���ο� ������ ��ģ ��

	fs.resetDataBlock(dataIdx, blocks);// writeFile���� writeFS�� �θ��� ���� BlockBitmap�� ���Ͽ� �Ҵ��� indxe �ʱ�ȭ
									   /* ���� BlockBitmap�� 1�� ��츸 �����ͺ��� ����Ǿ��ִ� ���̹Ƿ� getDatablock�� blockbitmap�� 1���� �˻� �� ����� data return */

									   /*
									   ������ data�� ������� �°� �ɰ��� (�ݺ���)
									   writeFS�� �Ѱܼ� �������ش�
									   (FS)   block idx�� blockdata�� �Ѱܼ�  writeFS������ �ش� ������ ���� blockdata�� ����
									   */
	int length = filedata.length();
	char fileSize[7];
	for (int i = 0; i <7; i++)
		fileSize[i] = ' ';
	itoa(length, fileSize);

	inodeData.size = fileSize;

	char* blockData;
	int new_Blocks = 0;
	while (length != 0)
	{
		if (length > BLOCK_SIZE)
		{
			blockData = new char[BLOCK_SIZE];
			strcpy(blockData, (filedata.substr(0, BLOCK_SIZE)).c_str());

			length -= BLOCK_SIZE;
		}

		else
		{
			blockData = new char[length];
			strcpy(blockData, (filedata.substr(0, length)).c_str());

			length = 0;
		}

		int returnIdx = fs.writeFS(blockData);
		/*
		fs.writeFS ������
		block descriptor Table ���Ҵ�� ��� ��, -> �ʱ�ȭ�Ҷ��� �ٽ� ���� �� ��������� ��
		Block Bitmap�� idx�� �ش��ϴ� ��Ʈ 1�� set -> write���� �����ͺ��� �� �� �ٷ� �ٷ� ���ִ� �ɷ�
		write����  Datablock idxã�Ƽ� DataBlock�� ���� �� blockBitmap ����������� �׸��� idx ��ȯ���ִ� �ɷ�
		*/
		translateIntArrToCharArr(&returnIdx, inodeData.dataBlockList + new_Blocks * 3, 1);

		new_Blocks++;
	}

	translateIntArrToCharArr(&new_Blocks, inodeData.blocks, 1);
	/* �Ƹ� translateIntArrToCharArr( &new_Blocks, inode.blocks, 1);�� ���� ����, �ȵǸ� �ٲ㼭 �غ���

	char c_blocks[4];
	memcpy( c_blocks, &new_Blocks, sizeof(int) );
	string s_blocks = c_blocks;
	inode.blocks = new char[3];
	strcpy(inode.blocks, (s_blocks.substr(1, 3)).c_str());
	*/

	/* (FS)   Inode Block �� size, time(���� ������ ���ٽð�), mtime(������ ���������� ������ �ð�) blocks, block[] ���� -> FT, FS ��� ���� */
	char* currTime;
	getCurrentTime(currTime);
	inodeData.time = currTime;
	inodeData.mtime = currTime;

	fs.updateInode_writeFile(inodeNum, inodeData);
}
示例#4
0
 // ������ �ִ� ���ϵ����Ϳ� buffer�� �ٿ� ����
void File::writeFile(int fd, char* buffer)//,  TableManager& tm, FileSystem& fs )
{
	FileSystem& fs = *FileSystem::getInstance();
	TableManager& tm = *TableManager::getInstance();

	// (FT)   fd�� Ÿ���� inode���� data block idx�޾ƿ���
	InodeElement* inodeE = tm.getInodeByFD( fd );
	Inode inode = inodeE->inode;
	int blocks = atoi(inode.blocks);
	int dataIdx[20];
	translateCharArrToIntArr(inode.dataBlockList, dataIdx, blocks);

	/*
		(FS)   data block[idx]�� ����� ������ ����
		�ϳ��� data���� �� �����ͺ��� �л��� �͵��� ��ħ
	*/
   string data = "";
   for (int i = 0; i < blocks; i++)
   {
      char blockData[BLOCK_SIZE];
      fs.readFS(dataIdx[i], blockData);
      data += blockData;
   }
	//cout << data.length() << endl;
	//string filedata = data;// + buffer;   // ���������ͺ��� ����� ���ο� ������ ��ģ ��

	fs.resetDataBlock(dataIdx, blocks);// writeFile���� writeFS�� �θ��� ���� BlockBitmap�� ���Ͽ� �Ҵ��� indxe �ʱ�ȭ
									   /* ���� BlockBitmap�� 1�� ��츸 �����ͺ��� ����Ǿ��ִ� ���̹Ƿ� getDatablock�� blockbitmap�� 1���� �˻� �� ����� data return */

									   /*
									   ������ data�� ������� �°� �ɰ��� (�ݺ���)
									   writeFS�� �Ѱܼ� �������ش�
									   (FS)   block idx�� blockdata�� �Ѱܼ�  writeFS������ �ش� ������ ���� blockdata�� ����
									   */

	if ( inode.size[0] == '0' )
		data.clear();

	data += buffer;
	int length = data.length();
	char fileSize[7];
	_itoa(length, inode.size);

	// ������ �����͸� FS�� DataBlock�� ���ִ� �κ�
	char blockData[BLOCK_SIZE];
	int new_Blocks = 0;
	while (length != 0)
	{
		if (length > BLOCK_SIZE)
		{
			strcpy(blockData, (data.substr(0, BLOCK_SIZE)).c_str());

			length -= BLOCK_SIZE;
		}

		else
		{
			strcpy(blockData, (data.substr(0, length)).c_str());

			length = 0;
		}

		int returnIdx = fs.writeFS(blockData);
		/*
		fs.writeFS ������
		block descriptor Table ���Ҵ�� ��� ��, -> �ʱ�ȭ�Ҷ��� �ٽ� ���� �� ��������� ��
		Block Bitmap�� idx�� �ش��ϴ� ��Ʈ 1�� set -> write���� �����ͺ��� �� �� �ٷ� �ٷ� ���ִ� �ɷ�
		write����  Datablock idxã�Ƽ� DataBlock�� ���� �� blockBitmap ����������� �׸��� idx ��ȯ���ִ� �ɷ�
		*/
		translateIntArrToCharArr(&returnIdx, inode.dataBlockList + new_Blocks * 3, 1);

		new_Blocks++;
	}

	translateIntArrToCharArr(&new_Blocks, inode.blocks, 1);

	/* (FS)   Inode Block �� size, time(���� ������ ���ٽð�), mtime(������ ���������� ������ �ð�) blocks, block[] ���� -> FT, FS ��� ���� */
	char currTime[13] = { 0 };
	getCurrentTime(currTime);
	inode.time = currTime;
	inode.mtime = currTime;

	//update Inode
	tm.updateInode(fd, inode);
	fs.updateInode_writeFile(inodeE->inode_number, inode);
}// writeFile