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

📄 fssigleton.cpp

📁 类似Linux操作系统0.11版文件系统的文件系统设计和Windows下的操作程序
💻 CPP
字号:
#include "stdafx.h"
#include "FSSigleton.h"
#include "UL_Super.h"

CFSSigleton::CFSSigleton(void)
{
}

CFSSigleton::~CFSSigleton(void)
{
	if ( m_bVDiskLoaded)
		sys_sync();
}

// 装载磁盘
BOOL CFSSigleton::LoadVDisk(CString Path)
{
	if (Path.IsEmpty())
		return FALSE;

	buffer_init();		// 高速缓冲初始化
	blk_dev_init();		// 快设备初始化
	if (vhd_init(Path.LockBuffer()))
		return FALSE;
	if (mount_root())
		return FALSE;
	m_bVDiskLoaded = TRUE;
	return TRUE;
}
// 卸载磁盘
int CFSSigleton::UnLoadDisk()
{
	if ( m_bVDiskLoaded )
	{
		sys_sync();
		m_bVDiskLoaded = FALSE;
		vhd_release();
	}
	return 0;
}
//
int CFSSigleton::MakeDir (const char *pathname, int mode)
{
	if ( m_bVDiskLoaded )
		return UL_mkdir(pathname, mode);
	return -1;
}
int CFSSigleton::RemoveFolder (const char *pathname)
{
	if ( m_bVDiskLoaded)
		return UL_rmdir(pathname);
	return -1;
}
// 查找第一个文件
int CFSSigleton::FindFirstFile (const char *pathname, struct FIND_DATA* ff)
{
	if ( m_bVDiskLoaded )
		return findfirstfile(pathname, ff);
	return -1;
}
int CFSSigleton::FindNextFile (int handle, struct FIND_DATA* ff)
{
	if ( m_bVDiskLoaded )
		return findnextfile(handle, ff);
	return -1;
}

// 删除文件
int CFSSigleton::Delete (const char *name)
{
	if ( m_bVDiskLoaded )
		return UL_delete (name);
	return -1;
}
// 打开(创建)文件
int CFSSigleton::Open (const char *filename, int flag, int mode)
{
	if ( m_bVDiskLoaded)
		return UL_open (filename, flag, mode);
	return -1;
}
// 关闭文件
int CFSSigleton::Close (int fd)
{
	if ( m_bVDiskLoaded)
		return UL_close (fd);
	return -1;
}
// 写入文件
int CFSSigleton::Write (int fd, char *buf, int count)
{
	if ( m_bVDiskLoaded)
		return UL_write (fd, buf, count);
	return -1;
}
// 读取
int CFSSigleton::Read (int fd, char *buf, int count)
{
	if ( m_bVDiskLoaded)
		return UL_read (fd, buf, count);
	return -1;
}
// 移动文件指针
int CFSSigleton::Seek (int fd, long offset, int origin)
{
	if ( m_bVDiskLoaded)
		return UL_lseek (fd, offset, origin);
	return -1;
}
// 获得文件大小
unsigned long CFSSigleton::GetFileSize(int fd)
{
	if ( m_bVDiskLoaded)
		return UL_getfilesize(fd);
	return 0;
}
// 文件系统同步
int CFSSigleton::Sync()
{
	if ( m_bVDiskLoaded)
		return sys_sync();
	return -1;
}
int CFSSigleton::Rename(const char *pathname, const char *name)
{
	if ( m_bVDiskLoaded)
		return UL_rename(pathname, name);
	return -1;
}
struct super_block CFSSigleton::GetSuper()
{
	struct super_block Spuer;
	ZeroMemory(&Spuer, sizeof(struct super_block));
	if ( m_bVDiskLoaded)
	{
		Spuer = *get_super(0x301);
	}
	return Spuer;
};
long CFSSigleton::GetTotalBlocks()
{
	if ( !m_bVDiskLoaded)
		return 0;
	struct super_block * pSpuer = get_super(0x301);
	return pSpuer->s_nzones;
}
int CFSSigleton::GetFileAttr(int fd, FILE_INFO* FI)
{
	if ( m_bVDiskLoaded)
		return UL_getfileattr(fd, FI);
	return -1;
}

⌨️ 快捷键说明

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