I'm working on my fat12 driver so far I can
read the root directory also I can read files
now I'm tring to make an empty directory,and
after creating it,I can see it from windows
but when I try to open it,windows gives me
a box message saying that my folder refers
to location that is unavailable...
would you please help me here's my code:
Code: Select all
void md(){
int i,s,x;
char tmp_name[9]={' '};
gets(tmp_name,9);
char *name,*fat={' '};
name=toupper(tmp_name);
printf("\n");
for(i=0;i<8;i++)
putch(name[i]);
//load fat into memory
for(s=0,i=1;i<10;i++,s+=512)
{
floppy_read(i);
for(x=0;x<512;x++)
fat[x+s]=floppy_dmabuf[x];
}
/*
find first entry
in the root directory */
int j=get_first_entry();
//get first free cluster;
int cluster=32;
while(read_fat(fat,cluster)!=0)
{
cluster++ ;
}
int attr=j+11;
//start cluster
int st=j+26;
int size=j+28;
//load cluster 19
//into floppy_dmabuf
floppy_read(19);
//set the dir name
for(i=0;i<8;i++,j++)
floppy_dmabuf[j]=name[i];
//set dir attribute
floppy_dmabuf[attr] = read_only | directory ;
floppy_dmabuf[st]=cluster;
floppy_dmabuf[size]=0;
//write data to
//root directory
floppy_write(19);
//set fat
write_fat(cluster,fat,0xFFF);
//write new fat
//to floppy
for(s=0,i=1;i<10;i++,s+=512)
{
for(x=0;x<512;x++)
floppy_dmabuf[x]=fat[x+s];
floppy_write(i);
}
}
Code: Select all
int read_fat(char *fat,int entry)
{
int offset = (entry * 3) / 2;
if (entry & 1)
return((int)((short)fat[offset + 1] << 4)|(((short)fat[offset] & 0x00f0) >> 4));
else
return((int)(((short)fat[offset + 1] & 0x000f) << 8)|(short)fat[offset]);
}
void write_fat(int cluster,char *fat,unsigned value)
{
unsigned index;
index=(unsigned)(cluster * 1.5);
if(cluster % 2)
{
value =value << 4;
fat[index + 1]=(unsigned char)((value & 0xFF00)>>8);
fat[index]=(unsigned char)(fat[index] & 0x0F)+(unsigned char)((value & 0xF0));
}
else
{
fat[index+1]=(unsigned char)(fat[index+1] & 0xf0)+(unsigned char)((value &0x0f00)>>8);
fat[index]=(unsigned char)(value &0x00ff);
}
}