/* 实用与学习软件系列(33) MinixDiskReader Minix文件系统解析程序(含源码)
资源大小: 16.88KB
资源类型:
发布人: wfywangfeiyao
发布日期: 3个月前
Tag: Minix 文件系统磁盘格式
资源分: 0
下载人数: 16
http://download.csdn.net/source/689207
修改日期: hugion 2009.6.14
增加内容:扩充对minix2.0文件系统的支持
包括minix2.0磁盘文件系统,和软盘文件系统
增加文件显示命令 : cat [file]
增加文件提取命令 : get [file]
增加文件16进制显示命令:hex [file]
EMAIL : [email protected]
申明 : 请勿将本代码用作商业用途,如果确有需要,请和作者联系.
非商业用途,您可以自由拷贝,修改.
*/
#include <stdio.h>
#include <malloc.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#define ROOT_INODE 1
#define MINIX_VER2 2
struct partitionInfo
{
long sectors; //sectors count (including the unused block)
int offset; //offset from start of file
} partition_Info[4];
// 磁盘上的索引节点(i 节点)数据结构。
#ifdef MINIX_VER2
typedef unsigned short mode_t ;
typedef unsigned short uid_t ;
typedef unsigned long off_t ;
//typedef unsigned long time_t ;
typedef unsigned char gid_t ;
typedef unsigned char nlink_t ;
typedef unsigned short u16_t ;
typedef unsigned short zone_t ;
#define V1_NR_TZONES 9
#define V2_NR_TZONES 10
typedef struct d_inode{ /* V2.x disk inode */
mode_t i_mode; /* file type, protection, etc. */
u16_t i_nlinks; /* how many links to this file. HACK! */
uid_t i_uid; /* user id of the file's owner. */
u16_t i_gid; /* group number HACK! */
off_t i_size; /* current file size in bytes */
unsigned long d2_atime; /* when was file data last accessed */
unsigned long i_time; /* when was file data last changed */
unsigned long d2_ctime; /* when was inode data last changed */
zone_t i_zone[V2_NR_TZONES]; /* block nums for direct, ind, and dbl ind */
} d_inode;
#else
typedef struct d_inode
{
unsigned short i_mode; // 文件类型和属性(rwx 位)。
unsigned short i_uid; // 用户id(文件拥有者标识符)。
unsigned long i_size; // 文件大小(字节数)。
unsigned long i_time; // 修改时间(自1970.1.1:0 算起,秒)。
unsigned char i_gid; // 组id(文件拥有者所在的组)。
unsigned char i_nlinks; // 链接数(多少个文件目录项指向该i 节点)。
unsigned short i_zone[9]; // 直接(0-6)、间接(7)或双重间接(8)逻辑块号。
// zone 是区的意思,可译成区段,或逻辑块。
}d_inode;
#endif
// 磁盘上超级块结构。上面125-132 行完全一样。
struct d_super_block
{
unsigned short s_ninodes; // 节点数。
unsigned short s_nzones; // 逻辑块数。
unsigned short s_imap_blocks; // i 节点位图所占用的数据块数。
unsigned short s_zmap_blocks; // 逻辑块位图所占用的数据块数。
unsigned short s_firstdatazone; // 第一个数据逻辑块。
unsigned short s_log_zone_size; // log(数据块数/逻辑块)。(以2 为底)。
unsigned long s_max_size; // 文件最大长度。
unsigned short s_magic; // 文件系统魔数。
};
// 文件目录项结构。
#define NAME_LEN 14 // 名字长度值
struct dir_entry
{
unsigned short inode; // i 节点。
char name[NAME_LEN]; // 文件名。
};
int cur_part_offfset = 0;
char current_path_name[1024]={0};
#define STDOUT_DEF 0x00 /* */
#define STDOUT_PRT 0x01
#define STDOUT_HEX 0x02
int cur_stdout = 0;
long cur_pos =0;
int cur_ftype=0;/*
0x00 unknow;
0x01 mbr;
0x02 minix flopy fs; */
FILE* fp = 0;
FILE* fpw = 0;
//int indentLevel = 0;
d_inode currentNode;
d_inode rootNode;
int inodeStartPos = 0;
int currentNodeIndex = -1;
#define SUPER_BLOCK_SIZE sizeof(struct d_super_block)
#define SUPER_BLOCK_ASIZE 1024
char block_buff[SUPER_BLOCK_ASIZE];/* 读文件块使用 */
void get_partition_info();
struct d_inode readInode(unsigned short inodeIndex);
void showDirectory(const struct d_inode* pInode, const int startPos, int recursive, int depth);
void showFileInfo(const d_inode* pInode, const char* name, int nodeId, int showColumn);
void getSubItems(const struct d_inode* pInode, struct dir_entry* pDirs);
void get_modeStr(unsigned short i_mode, char res[]);
unsigned short _bmap(const struct d_inode* pInode, unsigned short block);
void run();
void showDirItems(const struct d_inode* pInode, const char* name, int nodeId, int nameOnly);
int inodeFromName(const char* name, int length, const d_inode* parent);
int inodeFromPathName(const char* pathName);
void makeFullPath(const char* pathName, char fullPath[]);
void argFromCmd(const char* command, char arg[]);
void trim_str(char* str);
void setCurrentNode(int nodeId, d_inode node);
int parseImage(int partition);
int isImageFile();
int isMinixSystem(int partition);
void getParentPath(const char* currentPath, char parentPath[]);
void showFileInfoHead();
int main(int argc, char* argv[])
{
char* filename = 0;
int i=0;
int count = 0;
int ok = 0;
struct d_super_block * lpSupBlock;
printf("******************************\n");
printf("* author: hugion *\n");
printf("* date : 2009.6.14 *\n");
printf("* email : [email protected] *\n");
printf("* addr : nanjing, china *\n");
printf("******************************\n\n");
if(argc < 2)
{
char buf[256];
printf("Input image file name: ");
scanf("%s", buf);
//strcpy(buf,"E:\\minux\\flopy\\blankFs.flp");
//strcpy(buf,"E:\\minux\\flopy\\myflopy.flp");
//strcpy(buf,"E:\\program\\minix\\minix_2-f001.vmdk");
fp = fopen(buf, "rb");
if(!fp)
{
printf("Failed to open the file:%s!\n",buf);
system("pause");
return -1;
}
}
else
{
fp = fopen(argv[1], "rb");
if(!fp)
{
printf("Failed to open the file:%s!\n",argv[1]);
system("pause");
return -1;
}
}
if(!isImageFile())
{
printf("Not a hard disk image file\n");
if(!cur_ftype)
{
system("pause");
return -1;
}
}
if(cur_ftype&0x02)/* 读取超级块 */
{/* flopy disk */
memset(block_buff,0,SUPER_BLOCK_ASIZE);
lpSupBlock = (struct d_super_block *)block_buff;
fseek(fp, 1024, 0); /* start 1k */
fread(lpSupBlock, 1, SUPER_BLOCK_ASIZE, fp);
printf("s_magic: %#x.\n",lpSupBlock->s_magic);
/* minix magic: 其s_magic分别为0x137F, 0x138F, 0x2468, 0x2478. */
if(!cur_ftype)
{
system("pause");
return -1;
}
partition_Info[0].sectors = 1;
ok = parseImage(0);
}
else
{/* hard disk */
get_partition_info();
count = 0;
for(i=0; i<4; i++)
{
if(partition_Info[i].sectors && isMinixSystem(i))
{
printf("Minix System found on partition: %d\n", i+1);
count++;
}
}
if(count == 0)
{
printf("No Minix System found on any partition.\n");
return -1;
}
if(count > 1)
{
int partitionId;
printf("Select a partition, possible values are: ");
for(i=0; i<4; i++)
{
if(partition_Info[i].sectors)
printf("%d ", i + 1);
}
printf("\nInput your choice: ");
scanf("%d", &partitionId);
partitionId--;
if(partitionId >=0 && partitionId < 4)
ok = parseImage(partitionId);
else
{
printf("Input id is invalid.\n");
system("pause");
return -1;
}
}
else//only one minix partition
{
for(i=0; i<4; i++)
if(partition_Info[i].sectors)
{
ok = parseImage(i);
break;
}
/*
partition_Info[0].sectors = 1;
ok = parseImage(0);
*/
}
}
//run command
if(!ok)
{
system("pause");
return -1;
}
run();
fclose(fp);
return 0;
}
/***********************************************************************
硬盘主引导扇区 = 硬盘主引导记录(MBR)+ 硬盘分区表(DPT)
--------------------------------------------------------------
物理位置:0面0道1扇区(clindyer 0, side 0, sector 1)
大小: 512字节
其中:MBR 446字节(0000--01BD),DPT 64字节(01BE--01FD)�

hugion
- 粉丝: 15
最新资源
- 基于Tensorflow卷积神经网络天气图像识别系统设计毕业源码案例设计
- 【多变量时序预测】MATLAB实现基于LSTM-XGBoost长短期记忆网络(LSTM)结合极端梯度提升(XGBoost)进行多变量时序预测的详细项目实例(含模型描述及部分示例代码)
- 【机器学习与深度学习】MATLAB实现基于LSTM-XGBoost长短期记忆网络(LSTM)结合极端梯度提升(XGBoost)进行多输入单输出回归预测的详细项目实例(含模型描述及部分示例代码)
- Flet框架图片自动轮播组件自定义模板
- 【时间序列预测】MATLAB实现基于MLR-NGO-BiLSTM多元线性回归(MLR)结合北方苍鹰优化算法(NGO)和双向长短期记忆网络(BiLSTM)进行多变量时间序列预测的详细项目实例(含模型描述
- 基于MATLAB遗传算法的公交线路优化研究
- 故障诊断MATLAB实现基于MSPE-KPCA-LSTM多尺度排列熵(MSPE)结合核主成分分析(KPCA)和长短期记忆网络(LSTM)进行故障诊断分类预测测的详细项目实例(含模型描述及部分示例代
- 【多变量时间序列预测】MATLAB实现基于NGO-BiLSTM北方苍鹰优化算法(NGO)结合双向长短期记忆网络(BiLSTM)进行多变量时间序列预测的详细项目实例(含模型描述及部分示例代码)
- 图片播放插件,实现图片模仿PPT播放效果
- 成果转化智能体:赋能高校科研创新与成果落地的新引擎.docx
- 2025年中国医院创新转化报告.pdf
- 成果转化智能体:赋能科研创新与产业升级的新引擎.docx
- 成果转化智能体:构建高校科研成果转化新生态.docx
- 成果转化智能体:构建技术成果高效转化新生态.docx
- 成果转化智能体:构建生态协同创新新范式.docx
- 成果转化智能体:构建生态协同创新新机制.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈


