hostemu.c

来自「好用的FAT文件系统,兼容FAT12/16/32」· C语言 代码 · 共 57 行

C
57
字号
/*
	hostemu.c
	DOSFS Embedded FAT-Compatible Filesystem
	Host-Side Emulation Code	
	(C) 2005 Lewin A.R.W. Edwards (sysadm@zws.com)
*/

#include <stdio.h>
#include <stdlib.h>

#include "dosfs.h"
#include "hostemu.h"

//===================================================================
// Globals
FILE *hostfile;			// references host-side image file

/*
	Attach emulation to a host-side disk image file
	Returns 0 OK, nonzero for any error
*/
int DFS_HostAttach(char *imagefile)
{
	hostfile = fopen(imagefile, "r+b");
	if (hostfile == NULL)
		return -1;

	return 0;	// OK
}

/*
	Read sector from image
	Returns 0 OK, nonzero for any error
*/
int DFS_HostReadSector(uint8_t *buffer, uint32_t sector, uint32_t count)
{
	if (fseek(hostfile, sector * SECTOR_SIZE, SEEK_SET))
		return -1;

	fread(buffer, SECTOR_SIZE, count, hostfile);
	return 0;
}

/*
	Write sector to image
	Returns 0 OK, nonzero for any error
*/
int DFS_HostWriteSector(uint8_t *buffer, uint32_t sector, uint32_t count)
{
	if (fseek(hostfile, sector * SECTOR_SIZE, SEEK_SET))
		return -1;

	fwrite(buffer, SECTOR_SIZE, count, hostfile);
	fflush(hostfile);
	return 0;
}

⌨️ 快捷键说明

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