⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rddebug.c

📁 PDA上的CF CARD 文件系统的建立程式
💻 C
字号:
/*************************************************************
File Name: RDDEBUG.C (RAMDisk 4.1)			     *
**************************************************************
Programmer: MSC
Last Modified Date: 2000/02/29
Compiler : GNU Cross-compiler/SDS
Platform : X86 protection mode, MIPS, Dragonball
Usage :
	RAMDisk 4.0 debug functions
*************************************************************/
#include <sys/syscall.h>

//#include <ansi_c/stdio.h>
/**** modified by chilong 8/23/2001 ****/
#include <stdio.h>
/**** modified by chilong 8/23/2001 ****/

//#include "../../driver/rdebug/rdebug.h"
#include <ramdisk.h>
//#include "myansi.h"
#include <dskblk.h>
#include <rddebug.h>



#ifdef RAMDISK_DEBUG


char key_getc(void);

// piece.c
extern unsigned long RDPieceSize;
//extern void **RD_PLT;

// dskblk.c
extern struct diskBlock *RD_FirstFreeBlock;

// basic.c
extern unsigned char *RAMMemory;	// the starting location of the RAMDisk's memory block
extern unsigned long RD_DiskSize;		// size of the RAMDisk in bytes
extern void *RD_BootBegin;
//extern int RDerrno;
extern int RD_SemaphoreID;
extern unsigned long RDLowerBoundary;
extern unsigned long RDUpperBoundary;
extern int RDOutput;

// fio.c
extern struct RD_FILE **RD_HandleTable;



/*************************************************************
Fuction : RD_showFSInfo
	Show the file system information of the drive
**************************************************************/
void RD_showFSInfo(void)
{
  printStringLn("### The file system information of the drive ###");
  printString("Disk size in bytes             : ");
  printInt(RD_DiskSize, DEC);
  printString("Piece size in bytes            : ");
  printInt(RDPieceSize, DEC);
  printString("Address of the BOOT block      : ");
  printInt((unsigned long)RD_BootBegin, HEX);
  printString("Address of the 1st ROOT block  : ");
  printInt((unsigned long)(((struct signature *)RD_BootBegin)->rootBegin), HEX);
  printString("Address of the 1st free block  : ");
  printInt((unsigned long)RD_FirstFreeBlock, HEX);
  printString("RAMDisk starts from            : ");
  printInt((unsigned long)RAMMemory, HEX);
  printString("Lower boundary                 : ");
  printInt((unsigned long)RDLowerBoundary, HEX);
  printString("Upper boundary                 : ");
  printInt((unsigned long)RDUpperBoundary, HEX);
}



/*************************************************************
Function: RD_showFreeMemSize
Description:
	print the size of free memory blocks in RAMDisk memory pool
Input:
	NONE
Output:
	NONE
**************************************************************/
void RD_showFreeMemSize(void)
{
  sc_waitSemaphore(RD_SemaphoreID);

  RD_showFreeMemSize_r();

  sc_signalSemaphore(RD_SemaphoreID);
}

void RD_showFreeMemSize_r(void)
{
  struct diskBlock *curBlock;
  struct diskBlock *lastBlock = NULL;

  curBlock = RD_FirstFreeBlock;

  sprintf(RD_DebugString, "Free blk list");
  if (RDOutput == TO_SERIAL_PORT)
	SprintStringLn(RD_DebugString);
  else
	printStringLn(RD_DebugString);

  sprintf(RD_DebugString, "Forwards:");
  if (RDOutput == TO_SERIAL_PORT)
	SprintStringLn(RD_DebugString);
  else
	printStringLn(RD_DebugString);

  while (curBlock != NULL)
  {
	if (RD_checkBlockLocation(curBlock) == -1)
	{
		sprintf(RD_DebugString, "Err blk:%x", curBlock);
		if (RDOutput == TO_SERIAL_PORT)
			SprintStringLn(RD_DebugString);
		else
			printStringLn(RD_DebugString);

		return;
	}

#ifdef RAMDISK_USE_VARIABLE_SIZE_BLOCK
	sprintf(RD_DebugString, "[%x](%d, %d)", curBlock, curBlock->size, *((long *)((unsigned long)curBlock + B_HEADER + curBlock->size)));
#else
	sprintf(RD_DebugString, "[%x](%d)", curBlock, curBlock->size);
#endif

	if (RDOutput == TO_SERIAL_PORT)
		SprintStringLn(RD_DebugString);
	else
		printStringLn(RD_DebugString);

	lastBlock = curBlock;
	curBlock = curBlock->nextBlock;
  }

  sprintf(RD_DebugString, "Backwards:");
  if (RDOutput == TO_SERIAL_PORT)
	SprintStringLn(RD_DebugString);
  else
	printStringLn(RD_DebugString);

  while (lastBlock != NULL)
  {
	if (RD_checkBlockLocation(lastBlock) == -1)
	{
		sprintf(RD_DebugString, "Err blk:%x", curBlock);
		if (RDOutput == TO_SERIAL_PORT)
			SprintStringLn(RD_DebugString);
		else
			printStringLn(RD_DebugString);

		return;
	}

#ifdef RAMDISK_USE_VARIABLE_SIZE_BLOCK
	sprintf(RD_DebugString, "[%x](%d, %d)", lastBlock, lastBlock->size, *((long *)((unsigned long)lastBlock + B_HEADER + lastBlock->size)));
#else
	sprintf(RD_DebugString, "[%x](%d)", lastBlock, lastBlock->size);
#endif

	if (RDOutput == TO_SERIAL_PORT)
		SprintStringLn(RD_DebugString);
	else
		printStringLn(RD_DebugString);

	lastBlock = lastBlock->prevBlock;
  }

  return;
}



/*************************************************************
Function: RD_showFileHandleBlockList
Description:
	print the block list of a file handle
Input:
	fhandle - the opened target file
Output:
	NONE
**************************************************************/
void RD_showFileHandleBlockList(int fhandle)
{
  sc_waitSemaphore(RD_SemaphoreID);

  RD_showFileHandleBlockList_r(fhandle);

  sc_signalSemaphore(RD_SemaphoreID);
}

void RD_showFileHandleBlockList_r(int fhandle)
{
  struct diskBlock *curBlock;
  struct diskBlock *lastBlock = NULL;
  int count = 0;
  char strTemp[80];

  curBlock = (RD_HandleTable[fhandle]->dirEntry)->startBlock;

  sprintf(strTemp, "File blk list");
  if (RDOutput == TO_SERIAL_PORT)
	SprintStringLn(strTemp);
  else
	printStringLn(strTemp);

  sprintf(strTemp, "From head to tail:");
  if (RDOutput == TO_SERIAL_PORT)
	SprintStringLn(strTemp);
  else
	printStringLn(strTemp);

  while (curBlock != NULL)
  {
	if (RD_checkBlockLocation(curBlock) == -1)
	{
		sprintf(strTemp, "Err blk:%x", curBlock);
		if (RDOutput == TO_SERIAL_PORT)
			SprintStringLn(strTemp);
		else
			printStringLn(strTemp);

		return;
	}

#ifdef RAMDISK_USE_VARIABLE_SIZE_BLOCK
	sprintf(strTemp, "[%x](%d, %d, %d, %d, %d, %d)", curBlock, curBlock->dataSize, curBlock->actualSize, curBlock->size, \
	        *((long *)((unsigned long)curBlock + B_HEADER + curBlock->size)), curBlock->status, curBlock->userCount);
#else
	sprintf(strTemp, "[%x](%d, %d, %d, %d, %d)", curBlock, curBlock->dataSize, curBlock->actualSize, curBlock->size, \
	        curBlock->status, curBlock->userCount);
#endif

	if (RDOutput == TO_SERIAL_PORT)
		SprintStringLn(strTemp);
	else
		printStringLn(strTemp);

	count += curBlock->actualSize;

	lastBlock = curBlock;
	curBlock = curBlock->nextBlock;
  }

  sprintf(strTemp, "From tail to head:");
  if (RDOutput == TO_SERIAL_PORT)
	SprintStringLn(strTemp);
  else
	printStringLn(strTemp);

  while (lastBlock != NULL)
  {
	if (RD_checkBlockLocation(lastBlock) == -1)
	{
		sprintf(strTemp, "Err blk:%x", curBlock);
		if (RDOutput == TO_SERIAL_PORT)
			SprintStringLn(strTemp);
		else
			printStringLn(strTemp);

		return;
	}

#ifdef RAMDISK_USE_VARIABLE_SIZE_BLOCK
	sprintf(strTemp, "[%x](%d, %d, %d, %d, %d, %d)", lastBlock, lastBlock->dataSize, lastBlock->actualSize, lastBlock->size, \
	        *((long *)((unsigned long)lastBlock + B_HEADER + lastBlock->size)), lastBlock->status, lastBlock->userCount);
#else
	sprintf(strTemp, "[%x](%d, %d, %d, %d, %d)", lastBlock, lastBlock->dataSize, lastBlock->actualSize, lastBlock->size, \
	        lastBlock->status, lastBlock->userCount);
#endif

	if (RDOutput == TO_SERIAL_PORT)
		SprintStringLn(strTemp);
	else
		printStringLn(strTemp);

	lastBlock = lastBlock->prevBlock;
  }

  sprintf(strTemp, "Total size = %d bytes", count);
  if (RDOutput == TO_SERIAL_PORT)
	SprintStringLn(strTemp);
  else
	printStringLn(strTemp);

  return;
}



/*************************************************************
Function: RD_showFileBlockList
Description:
	print the block list of a file
Input:
	name - the target filename
Output:
	NONE
**************************************************************/
void RD_showFileBlockList(unsigned char *name)
{
  int fd;
  char strTemp[40];

  sprintf(strTemp, "File:%s", name);
  if (RDOutput == TO_SERIAL_PORT)
	SprintStringLn(strTemp);
  else
	printStringLn(strTemp);

  if ((fd = RD_open(name, 0)) == -1)
  {
	sprintf(strTemp, "Open F: %x", RDerrno);
	if (RDOutput == TO_SERIAL_PORT)
		SprintStringLn(strTemp);
	else
		printStringLn(strTemp);

	return;
  }

  RD_showFileHandleBlockList(fd);

  if (RD_close(fd) == -1)
  {
	sprintf(strTemp, "Close F: %x", RDerrno);
	if (RDOutput == TO_SERIAL_PORT)
		SprintStringLn(strTemp);
	else
		printStringLn(strTemp);

	return;
  }

  return;
}



/*************************************************************
Fuction: RD_blockDump
	Dump a block
Input:
	block - pointer to the target block 
	start - begin dumping from this entry (0 is the 1st)
	end - end dumping at this entry (N is the last)
Output:
**************************************************************/
void RD_blockDump(struct diskBlock *block, int start, int end)
{
  int i;
  int count;
  unsigned char *p;

  printString("Dump block(");
  myPrintInt((unsigned long)block, DEC);
  printString(") from entry(");
  myPrintInt((unsigned long)start, DEC);
  printString(") to entry(");
  myPrintInt((unsigned long)end, DEC);
  printStringLn("):");

  p = (unsigned char *)((unsigned long)block + sizeof(struct diskBlock));
  count = 0;
  for (i = start; i <= end; i++)
  {
	myPrintInt((unsigned long)(*(p + i)), HEX);
	printString(" ");
	count++;
	if (count == 16)
	{
		count = 0;
		printStringLn("");
	}
  }
}



/*************************************************************
Fuction : RD_showHandle
	Show all file handle that is currently being used
**************************************************************/
void RD_showHandle(void)
{
  int fd;
  int count = 0;
  char strTemp[80];
  struct directory *dirEntry;

  sc_waitSemaphore(RD_SemaphoreID);

  sprintf(strTemp, "Active file handles:");
  if (RDOutput == TO_SERIAL_PORT)
	SprintStringLn(strTemp);
  else
	printStringLn(strTemp);

  for (fd = 3; fd < MAX_OPEN_FILE; fd++)
  {
	if (RD_HandleTable[fd] != NULL)
	{
		if (RD_HandleTable[fd]->deviceID == RAMDISK_ID)
		{
			count++;

			dirEntry = RD_HandleTable[fd]->dirEntry;

			sprintf(strTemp, "%02d: %x %d [%s]", fd, RD_HandleTable[fd], RD_HandleTable[fd]->ownerID, dirEntry->name);
			if (RDOutput == TO_SERIAL_PORT)
				SprintStringLn(strTemp);
			else
				printStringLn(strTemp);
		}
	}
  }

  sprintf(strTemp, "%d active handles", count);
  if (RDOutput == TO_SERIAL_PORT)
	SprintStringLn(strTemp);
  else
	printStringLn(strTemp);

  sc_signalSemaphore(RD_SemaphoreID);
}



/*************************************************************
Fuction : RD_showCompressionStatus
	Show the compression status of the RAMDisk
**************************************************************/
void RD_showCompressionStatus(void)
{
  long totalUsedSize = 0;
  long totalCompressedSize = 0;
  long totalFileSize = 0;
  char strTemp[40];

  sc_waitSemaphore(RD_SemaphoreID);

  sprintf(strTemp, "Compression status:");
  if (RDOutput == TO_SERIAL_PORT)
	SprintStringLn(strTemp);
  else
	printStringLn(strTemp);

  RD_scanDisk_r(ECHO_OFF, 0, &totalUsedSize, &totalFileSize, &totalCompressedSize);

  sc_signalSemaphore(RD_SemaphoreID);

  // done, show total status
  sprintf(strTemp, "Total disk size       = %d", RD_DiskSize);
  if (RDOutput == TO_SERIAL_PORT)
	SprintStringLn(strTemp);
  else
	printStringLn(strTemp);

  sprintf(strTemp, "Total occupied size   = %d", totalUsedSize);
  if (RDOutput == TO_SERIAL_PORT)
	SprintStringLn(strTemp);
  else
	printStringLn(strTemp);

  sprintf(strTemp, "Free space            = %d", RD_getdiskspace());
  if (RDOutput == TO_SERIAL_PORT)
	SprintStringLn(strTemp);
  else
	printStringLn(strTemp);

  sprintf(strTemp, "Total file size       = %d", totalFileSize);
  if (RDOutput == TO_SERIAL_PORT)
	SprintStringLn(strTemp);
  else
	printStringLn(strTemp);

  sprintf(strTemp, "Total compressed size = %d", totalCompressedSize);
  if (RDOutput == TO_SERIAL_PORT)
	SprintStringLn(strTemp);
  else
	printStringLn(strTemp);

  return;
}



/*************************************************************
Fuction : RD_pause
	Wait till users to press a key before continuing
**************************************************************/
void RD_pause(void)
{
  printStringLn("Press any key to continue...");
  key_getc();
}



/*************************************************************
Function: RD_showFileHandleBufferInfo
Description:
	print the buffer info of a file handle
Input:
	fhandle - the opened target file
Output:
	NONE
**************************************************************/
void RD_showFileHandleBufferInfo(int fhandle)
{
  struct RD_FILE *target;
  char strTemp[40];

  target = RD_HandleTable[fhandle];

  if (target->deviceID != RAMDISK_ID)
	return;

  sprintf(strTemp, "dirEntry, handle, owner, fpos, curBlock, blkfpos");
  if (RDOutput == TO_SERIAL_PORT)
	SprintStringLn(strTemp);
  else
	printStringLn(strTemp);

  sprintf(strTemp, "%x, %d, %d, %d, %x, %d", target->dirEntry, target->fhandle, target->ownerID, target->fpos, target->currentBlock, target->blockfpos);
  if (RDOutput == TO_SERIAL_PORT)
	SprintStringLn(strTemp);
  else
	printStringLn(strTemp);

  return;
}



#endif	// RAMDISK_DEBUG


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -