Esempio n. 1
0
void xHeap::DumpUsage(const char * filename)
{
  FILE * f = fopen(filename, "wt");
  if(!f)
    return;

  uint32 freeSize = 0x7fffffff;

  WriteStats(f, freeSize);

#ifndef USE_APP_HEAP_SAVING_MODE
  WriteFreeBlockHeader(f, freeSize);
  WriteFreeBlocks(f, freeSize);
#endif // USE_APP_HEAP_SAVING_MODE

#ifdef DEBUG_APP_HEAP
  WriteSmallBlockHeader(f, freeSize);
  WriteSmallBlocks(f, freeSize);
#endif

#ifndef USE_APP_HEAP_SAVING_MODE
  WriteBlockHeader(f, 1, freeSize);
  WriteBlocks(f, &dummyBlock, freeSize);
#endif // USE_APP_HEAP_SAVING_MODE

  WriteBlockHeader(f, 2, freeSize);
  WriteBlocks(f, &dummyLargeBlock, freeSize);

  fclose(f);
}
Esempio n. 2
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;
}
Esempio n. 3
0
File: node.c Progetto: cod5/kielder
int FlushDirent (struct FatSB *fsb, struct FatNode *node)
{
	fsb = node->fsb;
		
	if (fsb->validated == FALSE || node == &fsb->root_node || fsb->write_protect == TRUE)
		return 0;

	WriteBlocks (fsb, &kernel_as, &node->dirent, node->dirent_sector, node->dirent_offset, sizeof (struct FatDirEntry), BUF_IMMED);
	
	return 0;
}
Esempio n. 4
0
int ext2::WriteDataBlock(ulong blockNumber, FileDescriptor *fd, uchar *src)
{
	// find if we need to allocate a block or not
	ulong	addr = FindAddressByBlockNumber(blockNumber, fd->fileInode.blockPointers);
	
	if(addr == 0)	// we need to allocate a new block
	{
		Panic::PrintMessage("NEED TO ALLOCATE NEW BLOCK\n", false);
		addr = AllocateNewDataBlock(blockNumber, fd);
	}
	
	// write the block out to disk
	return WriteBlocks(addr, 1, src);
}
Esempio n. 5
0
int FatEraseDisk (struct FatSB *fsb, uint32 flags)
{
	uint32 t, sectors;
	uint32 fat_sz;
	uint32 root_dir_sectors = 0;
	uint8 temp_sector[512];
	
	
	KPRINTF ("FatEraseDisk()");


	MemSet (temp_sector, 0, 512);
	
	if (fsb->fat_type == TYPE_FAT32)
		fat_sz = fsb->bpb32.sectors_per_fat32;
	else
		fat_sz = fsb->bpb.sectors_per_fat16;
	
	root_dir_sectors = ((fsb->bpb.root_entries_cnt * 32) + (fsb->bpb.bytes_per_sector - 1)) / fsb->bpb.bytes_per_sector;
	
	
		
	if (flags & FORMATF_QUICK)
	{
		sectors = fsb->bpb.reserved_sectors_cnt + (fsb->bpb.fat_cnt * fat_sz)
					+ root_dir_sectors;
		
		if (fsb->fat_type == TYPE_FAT32)
			sectors += fsb->bpb.sectors_per_cluster;
	}
	else
		sectors = fsb->partition_size;
	
	
	for (t=0; t<sectors; t++)
	{
		KPRINTF ("Erasing sector %d", t);
		
		WriteBlocks (fsb, &kernel_as, temp_sector, t, 0, 512, BUF_IMMED);
	}
	
	
	return 0;
}
Esempio n. 6
0
//
// Write functions
//
int ext2::WriteInode(ulong inode, Inode *theInode)
{
	if(inode < 2)
	{
		Panic::PrintMessage("Tried to write inode zero\n");
		return(-1);
	}
	
	ulong	groupNumber = inode / theSuperBlock.inodesPerGroup;
	ulong	blocksNeeded = DivUp(theSuperBlock.inodesPerGroup * sizeof(Inode), blockSize); // calc 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);
	
	// check for an error on the read
	if(ret < 0)
	{
		delete [] buff;
		return ret;
	}
	
	// decrease inode because array index at zero and inodes at one
	MemCopy(&tmpInode[(inode-1) % theSuperBlock.inodesPerGroup], theInode, sizeof(Inode));
	
	// write this back out to disk
	ret = WriteBlocks(theGroupDescriptors[groupNumber].inodeTableAddress, blocksNeeded, buff);
	
	delete [] buff;
	
	return(ret);
	
}