コード例 #1
0
ファイル: ext2fsutil.c プロジェクト: Vvnesaa/fsck
// get all data from one inode
void getData(int parStart, struct ext2_inode *inode, int blockSize, unsigned char* buf) {
	int i, j, k;
	int tempSize = 0;
	int totalSize = inode->i_size;
	int len = blockSize / sizeof(int);
	int* indblock = malloc(blockSize);
	int* dindblock = malloc(blockSize);
	int* tindblock = malloc(blockSize);

	// Direct Blocks
	for (i = 0; i < EXT2_NDIR_BLOCKS; ++i) { 
		readDisk(parStart * SECTOR_SIZE + blockSize * inode->i_block[i], blockSize, buf + tempSize);
		tempSize += blockSize;
		if (tempSize >= totalSize) goto FREE_MEMORY;
	}
	
	// Indirect Blocks
	readDisk(parStart * SECTOR_SIZE + blockSize * inode->i_block[EXT2_IND_BLOCK], blockSize, indblock);
	for (i = 0; i < len;  ++i) {
		readDisk(parStart * SECTOR_SIZE + blockSize * indblock[i], blockSize, buf + tempSize);
		tempSize += blockSize;
		if (tempSize >= totalSize) goto FREE_MEMORY;
	}
	
	// Doubly-indirect Blocks
	readDisk(parStart * SECTOR_SIZE + blockSize * inode->i_block[EXT2_DIND_BLOCK], blockSize, dindblock);
	for (i = 0; i < len; ++i) {
		readDisk(parStart * SECTOR_SIZE + blockSize * dindblock[i], blockSize, indblock);
		for (j = 0; j < len; ++j) {
			readDisk(parStart * SECTOR_SIZE + blockSize * indblock[j], blockSize, buf + tempSize);
			tempSize += blockSize;
			if (tempSize >= totalSize) goto FREE_MEMORY;
		}
	}

	// Thriply-indirect Blocks
	readDisk(parStart * SECTOR_SIZE + blockSize * inode->i_block[EXT2_TIND_BLOCK], blockSize, tindblock);
	for (i = 0; i < len; ++i) {
		readDisk(parStart * SECTOR_SIZE + blockSize * tindblock[i], blockSize, dindblock);
		for (j = 0; j < len; ++j) {
			readDisk(parStart * SECTOR_SIZE + blockSize * dindblock[j], blockSize, indblock);
			for (k = 0; k < len; ++k) {
				readDisk(parStart * SECTOR_SIZE + blockSize * indblock[k], blockSize, buf + tempSize);
				tempSize += blockSize;
				if (tempSize >= totalSize) goto FREE_MEMORY;
			}
		}
	}
	
	FREE_MEMORY:
		free(indblock);
		free(dindblock);
		free(tindblock);
}
コード例 #2
0
ファイル: main.c プロジェクト: defcode16/raidmanager
void testDisk(){
    clr();
    printf("Ingrese el nombre del disco\n");
    printf("raid-manager> ");
    char *path = readln(256);
    readDisk(path);
    readchar();
}
コード例 #3
0
ファイル: ext2fsutil.c プロジェクト: Vvnesaa/fsck
/* Read All Inodes From All Groups */
void getInodeTable(int parStart, struct ext2_super_block *superBlock, struct ext2_group_desc groupDescs[], int groupNum, struct ext2_inode *inodeTable, int blockSize) {
	int i;
	int last = 0;
	for (i = 0; i < groupNum; ++i) {
		readDisk(parStart * SECTOR_SIZE + groupDescs[i].bg_inode_table * blockSize, INODE_SIZE * superBlock->s_inodes_per_group, inodeTable + last);
		last += superBlock->s_inodes_per_group;
	}
}
コード例 #4
0
ファイル: DIrBlock.c プロジェクト: lijunfeng722/MyFileSys
DirBlock * getDirBlock(MyDisk *disk,char ** dirPath,int dep,short * dirBlockp)
{
	DirBlock * tBlock;
	int i=2;
	short pi=0,pb=0;
	tBlock=(DirBlock *)malloc(sizeof(DirBlock));
	readDisk(tBlock,sizeof(DirBlock),1,sizeof(MyDisk));//root的dirBlock
	while(i<=dep)
	{
		pi=getFileInodeID(tBlock,*(dirPath+(i-1)));
		++i;
		pb=disk->inodeTable[pi].blockPoint[0];
		readDisk(tBlock,sizeof(DirBlock),1,sizeof(MyDisk)+pb*BLOCK_SIZE);
	}
	
	*dirBlockp=pb;
//	showDirBlock(tBlock);
	return tBlock;
}
コード例 #5
0
ファイル: input.c プロジェクト: taysom/tau
void input (void)
{
	int	c;
	u64	x;
	u64	new_block = 0;

	NewNumber = TRUE;
	Radix = HEX;

	output();

	for (;;)	{

		if (new_block != BlockNum) {
			if (readDisk(new_block) != 0) {
				new_block = BlockNum;
			}
		}
		output();

		c = getch();

		switch (c) {
			/*
			 * Don't use these: CNTRL(C), CNTRL(Z), CNTRL(S),
			 *		CNTLR(Q), CNTRL(Y)
			 */
		case '?':			help();		break;
		case '_':	lastx();	neg();		break;
		case '+':	lastx();	add();		break;
		case '-':	lastx();	sub();		break;
		case '*':	lastx();	mul();		break;
		case '/':	lastx();	divide();	break;
		case '%':	lastx();	mod();		break;
		case '~':	lastx();	not();		break;
		case '&':	lastx();	and();		break;
		case '|':	lastx();	or();		break;
		case '^':	lastx();	xor();		break;
		case '<':	lastx();	leftShift();	break;
		case '>':	lastx();	rightShift();	break;
		case '.':	lastx();	swap();		break;
		case '!':	lastx();	store();	break;
		case '=':	lastx();	retrieve();	break;
		case '#':	lastx();	qrand();	break;

		case KEY_RESIZE:	/* Screen resize event - don't do anything */
				break;

		case KEY_LEFT:
		case 'h':	Current->left(); /* left one column */
				break;

		case KEY_DOWN:
		case 'j':	Current->down(); /* down one row */
				break;

		case KEY_UP:
		case 'k':	Current->up(); /* up one row */
				break;

		case KEY_RIGHT:
		case 'l':	Current->right(); /* right one column */
				break;

		case CNTRL('A'):clear(); /* switch to next format */
				next_format();
				break;

		case CNTRL('W'):clear(); /* switch to previous format */
				prev_format();
				break;

		case CNTRL('B'):/* Backward one block */
				if (BlockNum > 0) {
					new_block = BlockNum - 1;
				}
				break;

		case EOF:	/* Ignore EOF - send on resize */
				break;
		case 'q':
		case CNTRL('D'):finish(0); /* Exit */
				break;

		case CNTRL('F'):/* Forward a block */
				new_block = BlockNum + 1;
				break;

		case 'g':	/* Go to specified Block */
				lastx();
				x = pop();
				NewNumber = FALSE;
				new_block = x;
				break;

		case KEY_BACKSPACE:
		case KEY_DC:
		case CNTRL('H'):/* Delete last digit entered */
				push(pop() / RadixTable[Radix]);
				break;

		case CNTRL('I'):/* Next field */
				Current->next();
				break;

		case KEY_CLEAR:
		case CNTRL('L'):/* Refresh the display */
				wrefresh(curscr);
				break;

		case KEY_ENTER:
		case CNTRL('M'):/* Finish entry of number or duplicate top */
				if (!NewNumber)	{
					duptop();
				}
				NewNumber = FALSE;
				break;

		case CNTRL('P'):/* Push copy of current field */
				Current->copy();
				NewNumber = FALSE;
				break;

		case CNTRL('R'):/* Rotate from bottom of stack to top */
				rotate();
				break;

		case 'r':	/* Change radix */
				++Radix;
				if (Radix > UNSIGNED)	Radix = HEX;
				break;

		case CNTRL('T'):/* Reinitialize stack */
				initStack();
				NewNumber = TRUE;
				break;

		case CNTRL('U'):/* Push last x */
				push(Lastx);
				NewNumber = FALSE;
				break;

		case CNTRL('X'):/* Delete top of stack */
				(void)pop();
				push(0);
				NewNumber = TRUE;

		case 'Z':	/* Previous field */
				Current->prev();
				break;

		default:	/* Is it a digit? */
				if ((Radix == HEX) && isxdigit(c)) {
					if (isdigit(c)) {
						digit(c, '0');
					} else if (isupper(c)) {
						digit(c, 'A' - 10);
					} else {
						digit(c, 'a' - 10);
					}
				} else if ((Radix == UNSIGNED) && isdigit(c)) {
					digit(c, '0');
				} else if ((Radix == SIGNED) && isdigit(c)) {
					digit(c, '0');
				} else if (Radix == CHARACTER)	{
					digit(c, 0);
				} else {
					flash();
					sprintf(Error, "bad char=%d", c);
				}
				break;
		}
	}
}
コード例 #6
0
ファイル: ext2fsutil.c プロジェクト: Vvnesaa/fsck
void getGroupDescs(int parStart, struct ext2_group_desc *buf, int groupNum) {
	readDisk(parStart * SECTOR_SIZE + GROUP_DESC_OFFSET, ONE_GROUP_DESC_SIZE * groupNum, buf);
}
コード例 #7
0
ファイル: ext2fsutil.c プロジェクト: Vvnesaa/fsck
// Read All Inode Bitmap From All Group
void getInodeBitmap(int parStart, struct ext2_group_desc groupDescs[], int groupNum, unsigned char *inodeBitmap, int blockSize) {
	int i;
	for (i = 0; i < groupNum; ++i)
		readDisk(parStart * SECTOR_SIZE + groupDescs[i].bg_inode_bitmap * blockSize, blockSize, inodeBitmap + i * blockSize);
}
コード例 #8
0
ファイル: ext2fsutil.c プロジェクト: Vvnesaa/fsck
void getSuperBlock(int parStart, struct ext2_super_block *buf) {
	readDisk(parStart * SECTOR_SIZE + SUPER_BLOCK_OFFSET, SUPER_BLOCK_SIZE , buf);
}