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

📄 file.c

📁 Win9x下文件系统驱动的例子(EXT2)源代码。
💻 C
字号:
#include "vxd.h"

#include "shared\vxddebug.h"
#include "file.h"
#include "error.h"

#include "ext2fs.h"
#include "super.h"
#include "inode.h"
#include "unixstat.h"
#include "util.h"


BOOL FileRead(TInode *Inode, ULONG Pos, ULONG Length, char *Data)
{
	BOOL		succes;
	char		*blockdata;
	TBlock		*block;
	ULONG		blockno, offset, blocksize, transfersize;

	blocksize = DevGetBlockSize(Inode->Super->Device);
	blockno = Pos / blocksize;
	offset = Pos % blocksize;

	succes = TRUE;
	while (Length)
	{
		if (!(block = InodeGetBlock(Inode, blockno)))
		{
			succes = FALSE;
			break;
		}

		blockdata = BlockLock(block);

			/*
			 * How much to transfer for this block
			 */
		transfersize = blocksize - offset;
		if (transfersize > Length)
			transfersize = Length;

			/*
			 * transfer it
			 */
		memcpy(Data, blockdata + offset, transfersize);
		BlockUnlock(block);
		BlockRelease(block);

			/*
			 * Prepare next block transfer
			 */
		Data += transfersize;
		Length -= transfersize;
		offset = 0;
		blockno++;
	}

	return succes;
}


TFileContext* FileCreateFileContext(TInode *Inode)
{
	TFileContext	*filecontext;
	ext2_inode		*ext2inode;

	if (!(filecontext = (TFileContext *) calloc(1, sizeof(TFileContext))))
		return 0;
	filecontext->Inode = Inode;

	ext2inode = InodeLock(Inode);
	filecontext->FileSize = ext2inode->i_size;
	InodeUnlock(Inode);

	return filecontext;

}


void FileDestroyFileContext(TFileContext *FileContext)
{
	InodeRelease(FileContext->Inode);
	free(FileContext);
}

⌨️ 快捷键说明

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