Beispiel #1
0
int FatWriteBootRecord (struct FatSB *fsb)
{
	uint8 temp_sector[512];
	uint16 signature;
	int t;
	
	KPRINTF ("FatWriteBootRecord()");
	
	ReadBlocks (fsb, &kernel_as, temp_sector, 0, 0, 512);

	MemCpy (temp_sector, &fsb->bpb, sizeof (struct FatBPB));
	
	
	if (fsb->fat_type == TYPE_FAT32)
	{
		MemCpy (temp_sector + BPB_EXT_OFFSET, &fsb->bpb32, sizeof (struct FatBPB_32Ext));
		MemCpy (temp_sector + FAT32_BOOTCODE_START, fat32_bootcode, SIZEOF_FAT32_BOOTCODE);
	}
	else
	{
		MemCpy (temp_sector + BPB_EXT_OFFSET, &fsb->bpb16, sizeof (struct FatBPB_16Ext));
		MemCpy (temp_sector + FAT16_BOOTCODE_START, fat16_bootcode, SIZEOF_FAT16_BOOTCODE);
	}
	
	*(temp_sector + 510) = 0x55;
	*(temp_sector + 511) = 0xaa;	

	WriteBlocks (fsb, &kernel_as, temp_sector, 0, 0, 512, BUF_IMMED);
	
	
	
	
	
	
	if (fsb->fat_type == TYPE_FAT32)
	{		
		WriteBlocks (fsb, &kernel_as, &fsb->fsi, 1, 0, sizeof (struct FatFSInfo), BUF_IMMED);
			
		signature = 0xaa55;
				
		WriteBlocks (fsb, &kernel_as, &signature, 2, 510, 2, BUF_IMMED);
		
		
		for (t=0; t<3; t++)
		{			
			ReadBlocks (fsb, &kernel_as, temp_sector, t, 0, 512);
			WriteBlocks (fsb, &kernel_as, temp_sector, 6+t, 0, 512, BUF_IMMED);
		}
	}
	
	return 0;
}
Beispiel #2
0
status_t
TAPEReader::GetNextChunk(void* oCookie, const void** oChunkBuffer,
	size_t* oChunkSize, media_header* oMediaHeader)
{
	int64		aOutSize;

	// check whether song is finished or not
	if (mReadPosTotal - mReadPos + mPlayPos >= mDataSize)
		return B_ERROR;

	// reading data
	if (mPlayPos >= mReadPos )
		ReadBlocks();

	// passing data
	if (mReadPos-mPlayPos >= BUFFER_SIZE)
		aOutSize = BUFFER_SIZE;
	else
		aOutSize = mReadPos-mPlayPos;

	*oChunkBuffer = &mDecodedData[mPlayPos];
	mPlayPos += aOutSize;

	// passing info
	*oChunkSize = aOutSize;
	oMediaHeader->start_time = CurrentTime();
	oMediaHeader->file_pos = mPlayPos;
	return B_OK;
}
Beispiel #3
0
status_t
TAPEReader::Seek(void *cookie, uint32 flags, int64 *frame, bigtime_t *time)
{
	int32 aNewBlock;

	if (flags & B_MEDIA_SEEK_TO_FRAME) {
		printf("Seek to frame %Ld\n", *frame);
		aNewBlock = *frame;
	} else if (flags & B_MEDIA_SEEK_TO_TIME) {
		printf("Seek for time %Ld\n", *time);
		aNewBlock = (*time) / 1000 * mDecomp->GetInfo(APE_DECOMPRESS_TOTAL_BLOCKS)
			/ mDecomp->GetInfo(APE_DECOMPRESS_LENGTH_MS);
	} else
		return B_ERROR;

	int64 aNewTime = aNewBlock * mDecomp->GetInfo(APE_INFO_BLOCK_ALIGN);
	if (mReadPosTotal - mReadPos < aNewTime && mReadPosTotal > aNewTime) {
		// Requested seek frame is already in the current buffer, no need to
		// actually seek, just set the play position
		mPlayPos = aNewTime - mReadPosTotal + mReadPos;
	} else {
		mReadPosTotal = aNewBlock * mDecomp->GetInfo(APE_INFO_BLOCK_ALIGN);
		mDecomp->Seek(aNewBlock);
		ReadBlocks();
	}
	return B_OK;
}
Beispiel #4
0
//
// Read functions
//
int ext2::ReadInode(ulong inode, Inode *theInode)
{
	if(inode < 2)
	{
		Panic::PrintMessage("Tried to get inode zero\n");
		return(-1);
	}
	
	ulong	groupNumber = inode / theSuperBlock.inodesPerGroup; // DivUp(inode, theSuperBlock.inodesPerGroup);
	ulong	blocksNeeded = DivUp(theSuperBlock.inodesPerGroup * sizeof(Inode), blockSize); // cal the blocks needed for all inodes
	uchar	*buff = new uchar[blocksNeeded * blockSize];
	Inode	*tmpInode = reinterpret_cast<Inode*>(buff);
	
/*	printf("INODE: %d\n", inode);
	printf("INODES PER GROUP: %d\n", theSuperBlock.inodesPerGroup);
	printf("GROUP NUMBER: %d\n", groupNumber);
	printf("INODE TABLE ADDR: %d\n", theGroupDescriptors[groupNumber].inodeTableAddress);
	printf("BLOCKS REQUESTED: %d\n", blocksNeeded);
	printf("INODE SIZE: %d\n", sizeof(Inode));
	*/
	
	// read the inode table for that group
	int ret = ReadBlocks(theGroupDescriptors[groupNumber].inodeTableAddress, blocksNeeded, buff);
	
	if(ret >= 0)	 // decrease inode because array index at zero and inodes at one
		MemCopy(theInode, &tmpInode[(inode-1) % theSuperBlock.inodesPerGroup], sizeof(Inode));
	
	delete [] buff;
	
	return(ret);
}
Beispiel #5
0
CPLErr GDALWMSRasterBand::IReadBlock(int x, int y, void *buffer) {
    int bx0 = x;
    int by0 = y;
    int bx1 = x;
    int by1 = y;

    if ((m_parent_dataset->m_hint.m_valid) && (m_parent_dataset->m_hint.m_overview == m_overview)) {
        int tbx0 = m_parent_dataset->m_hint.m_x0 / nBlockXSize;
        int tby0 = m_parent_dataset->m_hint.m_y0 / nBlockYSize;
        int tbx1 = (m_parent_dataset->m_hint.m_x0 + m_parent_dataset->m_hint.m_sx - 1) / nBlockXSize;
        int tby1 = (m_parent_dataset->m_hint.m_y0 + m_parent_dataset->m_hint.m_sy - 1) / nBlockYSize;
        if ((tbx0 <= bx0) && (tby0 <= by0) && (tbx1 >= bx1) && (tby1 >= by1)) {
            bx0 = tbx0;
            by0 = tby0;
            bx1 = tbx1;
            by1 = tby1;
        }
    }

    CPLErr eErr = ReadBlocks(x, y, buffer, bx0, by0, bx1, by1, 0);

    if ((m_parent_dataset->m_hint.m_valid) && (m_parent_dataset->m_hint.m_overview == m_overview))
    {
        m_parent_dataset->m_hint.m_valid = false;
    }

    return eErr;
}
CPLErr GDALWMSRasterBand::AdviseRead(int x0, int y0, int sx, int sy, int bsx, int bsy, GDALDataType bdt, char **options) {
//    printf("AdviseRead(%d, %d, %d, %d)\n", x0, y0, sx, sy);
    if (m_parent_dataset->m_offline_mode || !m_parent_dataset->m_use_advise_read) return CE_None;
    if (m_parent_dataset->m_cache == NULL) return CE_Failure;

    int bx0 = x0 / nBlockXSize;
    int by0 = y0 / nBlockYSize;
    int bx1 = (x0 + sx - 1) / nBlockXSize;
    int by1 = (y0 + sy - 1) / nBlockYSize;

    return ReadBlocks(0, 0, NULL, bx0, by0, bx1, by1, 1);
}
Beispiel #7
0
// this function reads a data block performing indirection if necessary
int ext2::ReadDataBlock(ulong blockNumber, ulong blocksPointers[], uchar *dest)
{
// 	printf("BLOCK NUM: %u\n", blockNumber);
// 	printf("BLOCK: %u\n", blocksPointers[blockNumber]);
	
	ulong	addr = FindAddressByBlockNumber(blockNumber, blocksPointers);
	
	if(addr == 0)
		Panic::PrintMessage("Couldn't find block");
	
	return ReadBlocks(addr, 1, dest);
}
Beispiel #8
0
ulong ext2::AllocateNewDataBlock(ulong blockNumber, FileDescriptor *fd)
{
	// FIX ME
	(void)blockNumber;
	
	int	groupNumber = fd->inodeNumber / theSuperBlock.inodesPerGroup;
	
	if(theGroupDescriptors[groupNumber].freeBlockCount == 0)
		Panic::PrintMessage("FILE SYSTEM FULL\n");
	
	// read in the block bitmap
	ulong	numBlocksForBitmap = DivUp(DivUp(theSuperBlock.blocksPerGroup,ulong(8)), ulong(blockSize));
	uchar	*freeBlockBitmap = new uchar[numBlocksForBitmap * blockSize];
	
	printf("BLOCKS PER GROUP: %d\n", theSuperBlock.blocksPerGroup);
	printf("NUM BLOCKS: %d\n", numBlocksForBitmap);
	
	// search through the bitmap for an unused block
	ReadBlocks(theGroupDescriptors[groupNumber].blockBitmapAddress, numBlocksForBitmap, freeBlockBitmap);
	
	for(uint i=0; i < numBlocksForBitmap * blockSize; ++i)
		printf("%x ", freeBlockBitmap[i]);
	
/*	vector<bool>	bitMap(reinterpret_cast<ulong*>(freeBlockBitmap), theSuperBlock.blocksPerGroup);
	
	vector<bool>::iterator it = find(bitMap.begin(), bitMap.end(), false);
	
	
 	for(it = bitMap.begin(); it != bitMap.end(); ++it)
 		printf("%s", *it == true ? "U" : "F");
*/
	
	// mark it as used
	
	// update the count in the group descriptor
	
	// update the count in the super block
	
	// update the count in the inode
	
	return(0);
}
static void
BlockReaderMain(Datum main_arg)
{
	int					id = DatumGetInt32(main_arg);
	DIR				   *dir;
	const char		   *hibernate_dir = SAVE_LOCATION;
	struct dirent	   *dent;
	int					filenum;

	WorkerCommon();

	dir = opendir(hibernate_dir);
	if (dir == NULL)
		ereport(ERROR,
				(errcode_for_file_access(),
				 errmsg("Block Reader %d: could not open directory \"%s\": %m",
						id, hibernate_dir)));

	/*
	 * Reset errno before making system call, so that we don't trip over an
	 * error that occurred earlier.
	 */
	errno = 0;

	/* Scan the directory looking for file this worker is assigned to. */
	while ((dent = readdir(dir)) != NULL)
	{
		if (!parseSavefileName(dent->d_name, &filenum))
			continue;

		/* Stop if this is the file assigned to this worker. */
		if (filenum == id)
			break;
	}

	if (dent == NULL)
	{
		closedir(dir);

		if (errno != 0)
			ereport(ERROR,
					(errcode_for_file_access(),
					errmsg("Block Reader %d: encountered error during readdir \"%s\": %m",
							filenum, hibernate_dir)));

		ereport(ERROR,
				(errmsg("Block Reader %d: could not find its save-file", filenum)));
	}
	closedir(dir);

	/* We found the file we're supposed to restore. */

	/* If parallelism is disabled, wait until it's our turn to read blocks. */

	/*
	 * Despite the warning on LWLockAcquire() that an LWLock should not be held
	 * for more than a few seconds, because holding one causes the query-cancel
	 * and die signals are blocked, I think it's safe to hold an LWLock around
	 * a database buffer restore operation since we're a background worker and
	 * query-cancel is intended for regular backends, and die() (a.k.a SIGTERM)
	 * is handled by us, and we promptly honor it.
	 */
	if (!guc_parallel_enabled)
		LWLockAcquire(shared_mem->lock, LW_EXCLUSIVE);

	ReadBlocks(filenum);

	if (!guc_parallel_enabled)
		LWLockRelease(shared_mem->lock);

	/*
	 * Exit with non-zero status to ensure that this worker is not restarted.
	 *
	 * For any backend connected to shared-buffers, an exit code other than 0 or 1
	 * causes a system-wide restart, so we have no choice but to use 1. Since an
	 * ERROR also causes exit code 1, it would've been nice if we could use some
	 * other code to signal normal exit, so that a monitor could differentiate
	 * between a successful exit, and an exit due to an ERROR.
	 *
	 * To get around this ambiguity we resort to logging a message to server log;
	 * this message should console the user that everything went okay, even though
	 * the exit code is 1.
	 */
	ereport(LOG, (errmsg("Block Reader %d: all blocks read successfully", filenum)));
	proc_exit(1);
}
Beispiel #10
0
// the fd will be changed to a block device
ext2::ext2(BlockDevice *theDrive, ulong baseAddress)
	: FileSystemBase(theDrive, baseAddress)
{
	uchar		*buff = new uchar[1024];	// 2 block buffer, assume 512 byte blocks for ATA driver
	
	//
	// CLEAN THIS UP & DOUBLE CHECK
	//
	ReadBlocks(2, 2, buff);
	
/*	for(int i=0; i < 100; ++i)
		printf("%x ", buff[i]);
	*/
	MemCopy(&theSuperBlock, buff, sizeof(SuperBlock));	// copy over the super block
	
	delete [] buff;	// delete this memory
	
	// sanity checks
	if(theSuperBlock.magicValue != 0xEF53 ||
	   theSuperBlock.creatorOS != 0)
	{
		printf("MAGIC VALUE: 0x%x\n", theSuperBlock.magicValue);
		printf("OS TYPE: 0x%x\n", theSuperBlock.creatorOS);
		Panic::PrintMessage("Invalid super block or wrong OS type\n", false);
	}
	
	// fix up the block size
	switch(theSuperBlock.blockSize)
	{
		case 0:	theSuperBlock.blockSize = blockSize = 1024; break;	
		case 1:	theSuperBlock.blockSize = blockSize = 2048; break;	
		case 2:	theSuperBlock.blockSize = blockSize = 4096; break;
		default: Panic::PrintMessage("Unknown blocks size\n");
	}

	// set the block size multiplier
	SetFileSystemBlockSize(blockSize);
	
	// set the addresses per block
	addrPerBlock = blockSize / sizeof(ulong);
	
/*	printf("BLOCK SIZE: %d\n", blockSize);
	printf("BLOCK MUL: %d\n", blockMultiplier);
	
	printf("*** SUPER BLOCK ***\n");
	printf("INODE COUNT: %ul\n", theSuperBlock.inodeCount);			// Inodes count
	printf("BLOCK COUNT: %ul\n", theSuperBlock.blockCount);			// Blocks count 
	printf("RESERVE COUNT: %u\n", theSuperBlock.reservedBlockCount);	// Reserved blocks count 
	printf("FREE COUNT: %u\n", theSuperBlock.freeBlockCount);		// Free blocks count 
	printf("FREE INODE COUNT: %u\n", theSuperBlock.freeInodeCount);		// Free inodes count 
	printf("FIRST DATA BLOCK: %u\n", theSuperBlock.firstDataBlock);		// First Data Block 
	printf("BLOCK SIZE: %u\n", theSuperBlock.blockSize);			// Block size 
	printf("%u\n", theSuperBlock.fragmentSize);				// Fragment size 
	printf("BLOCKS PER GROUP: %u\n", theSuperBlock.blocksPerGroup);		// # Blocks per group 
	printf("%u\n", theSuperBlock.fragmentsPerGroup);			// # Fragments per group 
	printf("INODES PER GROUP: %u\n", theSuperBlock.inodesPerGroup);		// # Inodes per group 
	printf("MOUNT TIME: %u\n", theSuperBlock.mountTime);			// Mount time 
	printf("WRITE TIME: %u\n", theSuperBlock.writeTime);			// Write time 
	printf("MOUNT COUNT: %u\n", theSuperBlock.mountCount);			// Mount count 
	printf("MAX MOUNT COUNT: %u\n", theSuperBlock.maxMountCount);		// Maximal mount count 
	printf("MAGIC: 0x%x\n", theSuperBlock.magicValue);			// Magic signature 
	printf("STATE: 0x%x\n", theSuperBlock.state);				// File system state 
	printf("ERRORS: %u\n", theSuperBlock.errors);				// Behaviour when detecting errors 
	printf("MINOR REVISION: %u\n", theSuperBlock.minorRevisionLevel);	// minor revision level 
	printf("LAST CHECKED: %u\n", theSuperBlock.timeLastChecked);		// time of last check 
	printf("CHECK INTERVAL: %u\n", theSuperBlock.checkInterval);		// max. time between checks 
	printf("OS: %u\n", theSuperBlock.creatorOS);				// OS 
	printf("REVISION: %u\n", theSuperBlock.revisionLevel);			// Revision level 
	printf("UID: %u\n", theSuperBlock.defaultReservedUID);			// Default uid for reserved blocks 
	printf("GID: %u\n\n", theSuperBlock.defaultReservedGID);		// Default gid for reserved blocks 
*/
	
	//
	// Figure out how many blocks there are for all the group descriptors
	//
	ulong			numGroups = DivUp(theSuperBlock.blockCount, theSuperBlock.blocksPerGroup);
	ulong			blocksForGroupDescriptors = DivUp(numGroups*sizeof(GroupDescriptor), blockSize);
	uchar			*groupBlocks = new uchar[blocksForGroupDescriptors * blockSize];
	GroupDescriptor		*tmpDescriptor;
	
/*	printf("NUM GROUPS: %d\n", numGroups);	
	printf("BLOCKS NEEDED: %d\n", blocksForGroupDescriptors);
	
	printf("SIZE: %d\n", blocksForGroupDescriptors * blockSize);
*/	
	
	int	groupAddr = 0;
	
	// I have no idea how to calculate this value
	switch(blockSize)
	{
		case 1024: groupAddr += 2; break;
		case 4096: groupAddr += 4; break;
		default: Panic::PrintMessage("Unknown block size\n", false);
	}
	
	// read in the group
	ReadBlocks(groupAddr, blocksForGroupDescriptors, groupBlocks);
	
	for(ulong i=0; i < numGroups; ++i)
	{
		tmpDescriptor = reinterpret_cast<GroupDescriptor *>(&groupBlocks[i*sizeof(GroupDescriptor)]);
		
/*		printf("BLOCK BITMAP ADDR: %d\n", tmpDescriptor->blockBitmapAddress);
		printf("INODE BITMAP ADDR: %d\n", tmpDescriptor->inodeBitmapAddress);
		printf("INODE TABLE ADDR: %d\n", tmpDescriptor->inodeTableAddress);
		printf("FREE BLOCK COUNT: %d\n", tmpDescriptor->freeBlockCount);
		printf("FREE INODE COUNT: %d\n", tmpDescriptor->freeInodeCount);
		printf("USED DIR: %d\n\n", tmpDescriptor->usedDirCount);
*/
		theGroupDescriptors.push_back(*tmpDescriptor);	// add it to our list
	}
	
	delete [] groupBlocks;	// free up some memory
}
Beispiel #11
0
ulong ext2::FindAddressByBlockNumber(ulong blockNumber, ulong blockPointers[])
{
	ulong	addr = 0;
	ulong	*addrs = NULL;
	
	// make sure the request isn't larger then the largest block number
	if(blockNumber >= ulong(DIRECT_BLOCK_PTRS) + (addrPerBlock * addrPerBlock * addrPerBlock))
		return(0);
	
	// direct data block
	if(blockNumber <= ulong(DIRECT_BLOCK_PTRS))
		addr = blockPointers[blockNumber];
	
	// single indirection
	else if(blockNumber < ulong(INDIRECT_BLOCK_PTR + addrPerBlock))
	{
// 		printf("\nSINGLE INDIRECT\n");
// 		printf("BLOCK NUM: %d\n", blockNumber);
		
		// make space for our inodes
		addrs = new ulong[blockSize/sizeof(ulong)];
		
		// read in the indirect blocks
		ReadBlocks(blockPointers[INDIRECT_BLOCK_PTR], 1, reinterpret_cast<uchar*>(addrs));
		
		// update the block number
		blockNumber -= INDIRECT_BLOCK_PTR;
		
// 		printf("ASKING FOR: %d\n", addrs[blockNumber % addrPerBlock]);
		
		addr = addrs[blockNumber % addrPerBlock];
	}
	
	// double indirection
	else if(blockNumber < ulong(INDIRECT_BLOCK_PTR + (addrPerBlock * addrPerBlock)))
	{
// 		printf("\nDOUBLE INDIRECT\n");
// 		printf("BLOCK NUM: %d\n", blockNumber);
		
		// make space for our inodes
		addrs = new ulong[blockSize/sizeof(ulong)];
		
		// read in the indirect blocks
		ReadBlocks(blockPointers[DOUBLE_INDIRECT_BLOCK_PTR], 1, reinterpret_cast<uchar*>(addrs));
		
		// update the block number
		blockNumber = blockNumber - INDIRECT_BLOCK_PTR - addrPerBlock;
		 
		// read in the double indirect blocks
		ReadBlocks(addrs[blockNumber / addrPerBlock], 1, reinterpret_cast<uchar*>(addrs));
		
// 		printf("ASKING FOR: %d\n", addrs[blockNumber % addrPerBlock]);
		
		addr = addrs[blockNumber % addrPerBlock];
	}
	
	// tripple indirection
	else
	{
// 		printf("\nTRIPPLE INDIRECT\n");
// 		printf("BLOCK NUM: %d\n", blockNumber);
		
		// make space for our inodes
		addrs = new ulong[blockSize/sizeof(ulong)];
		
		// read in the indirect blocks
		ReadBlocks(blockPointers[TRIPPLE_INDIRECT_BLOCK_PTR], 1, reinterpret_cast<uchar*>(addrs));
		
		// update the block number
		blockNumber = blockNumber - INDIRECT_BLOCK_PTR - addrPerBlock - (addrPerBlock * addrPerBlock);
		 
		// read in the double indirect blocks
		ReadBlocks(addrs[blockNumber / (addrPerBlock * addrPerBlock)], 1, reinterpret_cast<uchar*>(addrs));
		
		// read in the tripple indirect blocks
		ReadBlocks(addrs[blockNumber / addrPerBlock], 1, reinterpret_cast<uchar*>(addrs));
		
// 		printf("ASKING FOR: %d\n", addrs[blockNumber % addrPerBlock]);
		
		addr = addrs[blockNumber % addrPerBlock];
	}
	
	// cleanup any memory we might have made
	if(addrs != NULL)
		delete [] addrs;

	return(addr);
}