📄 fs.cpp
字号:
#ifndef _fs_
#define _fs_
#include "disk.cpp"
#include "shell.cpp"
#include "fat12.cpp"
#define FLOPPY 1
#define File_Not_Found 1
#define Folder_Not_Found 2
#define Destination_File_Exist 3
#define Destination_Folder_Exist 4
#define Access_Violation 5
#define No_Disk_Space 6
#define Des_Path_Not_Exist 7
#define RW 33
#define RO 32
struct flop
{
char h;
char s;
char t;
int noe;
int found;
int error;
unsigned int cnum;
char name[12];
};
char file_valid1;
char file_name1[11];
unsigned int file_next_lba1;
char *file_buffer1;
char file_pointer1;
char feof1;
long file_size1;
char ch = 1,ct = 0,cs = 2;
unsigned int ccls = 0x0000;
char cwd[100];
extern char Error_Code;
extern char floppy_hardd_tog;
void fclose();
void fopen(char*);
char fget_char();
void make1(char*,char*);
void ls1();
void ls2();
void rem1(char *str);
void rem2(char *str);
void types(char *str);
void rem2(char*);
void setcwd(unsigned int);
void dir();
void dir2();
void dir1();
void rem(char *str);
unsigned int copydata(unsigned int);
void ele(char[],char[]);
typedef struct flop hts;
Directory curr_dir;
void chmod(char buffer[32],char attr)
{
buffer[11] = attr;
}
void sethts(unsigned int cnum,hts *temp)
{
static unsigned int spt = 18,noh = 2;
static unsigned int secaddress;
static unsigned int laddress = 33;
secaddress = laddress + cnum-1;
temp->s = ((secaddress)%spt);
temp->h = (secaddress/spt)%noh;
temp->t = (secaddress/(spt*noh));
}
hts validate(char* path,int dorf)
{
static hts temp,temp1;
static hts temp2;
static char *vp = 0;
static int dirc;
static int icnt;
static char buffer[512];
static char name[12],fname[11];
static unsigned int tcnum;
static int i,j,found,w,flag;
static int curr;
dirc=0;
found = 0;
curr = 0;
vp = path;
temp.error = 0;
for(i=0;i<11;i++)temp.name[i] = 0;
temp.found = 0;
for(i=0;i<12;i++)fname[i] = 0;
if(streq(path,"A:\\"))
{
temp.h = 1;
temp.s = 2;
temp.t = 0;
temp.cnum = 0x0;
temp1.cnum = 0x0;
}
else
{
temp.h = ch;
temp.s = cs;
temp.t = ct;
curr = 1;
temp.cnum = ccls;
temp1.cnum = ccls;
}
if(!curr)
{
while(*path != '\\' && *path != 0 && *path != 32)path++;
path++;
}
i = 0;
while(*path != '\\' && *path != 0 && *path != 32)
{
fname[i++] = *path;path++;
}
ele(fname,name);
name[11] = 0;
temp1.h = temp.h;
temp1.t = temp.t;
temp1.s = temp.s;
temp2.s = temp.s;temp2.t = temp.t;temp2.h = temp.h;
temp2.noe = 0;
while(!found)
{
dirc = 0;
flopread(temp1.h,temp1.t,temp1.s,1,buffer);
for(i = 0;i<512&&buffer[i] != 0&&(!found);i+=32)
{
flag = 0;
for(w=0;w<11;w++)
if(buffer[i+w] != name[w])
{
flag = 1;
break;
}
if(!flag)
{
if((buffer[i+11]&16)!=0)
{
dorf=0;
dirc = 1;
j=0;
for(icnt=0;icnt<11;icnt++)temp2.name[icnt] = name[icnt];
if(*path == 0)fname[j]=0;
if(*path == '\\')path++;
while(*path != '\\' && *path != 0 && *path != 32)
{
fname[j++] = *path;
path++;
}
ele(fname,name);
tcnum = (unsigned int)(buffer[i+27]<<8) + (unsigned char)(buffer[i+26]);
temp2.s = temp.s;temp2.t = temp.t;temp2.h = temp.h;temp2.noe = i/32;
if(tcnum == 0x000)
{
temp.s = 2;temp.h = 0;temp.t = 1;
}
else
{
sethts(tcnum,&temp);
}
temp1.h = temp.h;
temp1.s = temp.s;
temp1.t = temp.t;
break;
}
else if(*path == 0)
{
temp.found = 1;
temp.noe = i/32;
found=1;
break;
}
}
}
if(!dirc && !found)
{
if(i != 512 && buffer[i] == 0)
{
if(strlen(name) == 0)
{
temp.s = temp2.s;temp.t = temp2.t;temp.h = temp2.h;temp.noe = temp2.noe;
for(icnt=0;icnt<11;icnt++)temp.name[icnt] = temp2.name[icnt];
}
if(((path[0] != 0) && (path[0] != 32))||(dorf)) temp.error = 1;
for(i=0;i<11;i++) temp.name[i] = name[i];
found = 1;
}
else if(i == 512)
{
if(temp1.cnum == 0)
{
temp1.s++;
if(temp1.s>18)
{
temp1.s=0;
if(temp1.h==1)
{
temp1.t++;
temp1.h=0;
}
else
{
temp1.h = 1;
}
}
}
else
{
temp1.cnum = getcnum(temp1.cnum);
if(temp1.cnum != 0xfff) sethts(temp1.cnum,&temp1);
else found = 1;
continue;
}
}
}
}
path = vp;
return temp;
}
hts findentries(hts thts)
{
static int h,t,s;
static int i,j,found;
static unsigned int *cnum;
static char buffer[512];
found = 0;
for(i=0;i<14;i++)
{
h = thts.h;
s = thts.s;
t = thts.t;
flopread(h,t,s,1,buffer);
for(j=0;j<512;j+=32)
{
if((buffer[j] == 0 || buffer[j] == '
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -