fat12 problem

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
xyjamepa
Member
Member
Posts: 397
Joined: Fri Sep 29, 2006 8:59 am

fat12 problem

Post by xyjamepa »

Hi...

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);
  }
}
Thanx.
kubeos
Member
Member
Posts: 138
Joined: Tue Jan 30, 2007 2:31 pm
Location: Kamloops BC, CANADA
Contact:

my fat code

Post by kubeos »

i think it's something in your fat store cluster routine... here's mine

Code: Select all

void storecluster(WORD value,int cluster)
{
	//store the value at the cluster in the fat
	int temp;
	WORD oldcluster;	//what was previously stored in that cluster
	oldcluster=_farpeekw(fatas,(cluster>>1)+cluster);
	if((cluster & 1)==1)
	{
		oldcluster=oldcluster<<12;
		oldcluster=oldcluster>>12;
		temp=oldcluster+(value<<4);
	}
	else
	{
		temp=oldcluster>>12;
		temp=temp<<12;
		temp=temp+value;
	}
	_farpokew(fatas,(cluster>>1)+cluster,(WORD)temp);
}
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Post by Dex »

Your problem could be, that there are no entrys for
EntryFirst db ". ",0 ; This is the for the first entry in a new folder
EntrySecond db ".. ",0 ; This is the for the second entry in a new folder

Even a empty folder has two entrys, but i have found that most info on the net is wrong or does not give the right info.
So you are best, making a new empty folder on windows and using a hex editor to read it.
User avatar
xyjamepa
Member
Member
Posts: 397
Joined: Fri Sep 29, 2006 8:59 am

Post by xyjamepa »

Hi...

It's working now the problem was in the folder name
I had to fill the rest of empty bytes with 0x20,any way
so now I can create folders,but I have a question about sub-directories
I don't know the way they are orgnized,I read microsoft specification
but it realy wasn't clear about that,so would someone please explain
to me how sub-dir orgnized in fat12 file system,or give me a link about that.

Thanx.
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Post by Dex »

Have you tryed deleting the folder from with in windows, including the wast bin ?.
As even when folder are not fully written, they seem to work ok, untill you try to delete them from wast bin.
User avatar
xyjamepa
Member
Member
Posts: 397
Joined: Fri Sep 29, 2006 8:59 am

Post by xyjamepa »

Have you tryed deleting the folder from with in windows, including the wast bin ?.
As even when folder are not fully written, they seem to work ok, untill you try to delete them from wast bin.
Yes and I deleted them successfuly,my create folder function
works fine now ,but my problem that I need more information
about how sub-directories work together,I mean the tree of
directories how it's orgnized?how am I suppose to know which
folder is parent and which one is child.
something like this...
root dir
/
dir1
/
dir2
how should I know that dir2 is child of dir1?

Thanx.
Post Reply