fat12 set cluster

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.
User avatar
xyjamepa
Member
Member
Posts: 397
Joined: Fri Sep 29, 2006 8:59 am

fat12 set cluster

Post by xyjamepa »

Hi,

I'm trying to write a fat12 driver,but this time I'm writing it using assembly,
right now I don't know how to set an entry in the fat table to a specific value,
would you please give me a code snippt (asm code) about that...

Thanx.
The man who follows the crowd will usually get no further than the crowd.
The man who walks alone is likely to find himself in places
no one has ever been before.
User avatar
DT170x
Posts: 19
Joined: Mon Aug 25, 2008 6:12 pm

Post by DT170x »

I thought there is FAT, FAT16, and FAT32

FAT 12

It that odd
DT Model 1540 OS 1% <Kernel>
User avatar
suthers
Member
Member
Posts: 672
Joined: Tue Feb 20, 2007 3:00 pm
Location: London UK
Contact:

Re:

Post by suthers »

DT170x wrote:I thought there is FAT, FAT16, and FAT32

FAT 12

It that odd
FAT12 definitely exist, trust me, I'm an OSdever :lol:
Jules
User avatar
DT170x
Posts: 19
Joined: Mon Aug 25, 2008 6:12 pm

Re: fat12 set cluster

Post by DT170x »

Sorry I didn't Know that.
DT Model 1540 OS 1% <Kernel>
PatrickV
Member
Member
Posts: 151
Joined: Sun Jul 06, 2008 7:50 pm
Location: New Zealand
Contact:

Re: fat12 set cluster

Post by PatrickV »

I think the number is the number of clusters per file it can handle for example FAT12- 12 Clusters? That i at least what i think it is. Please point out to me if I am wrong
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: fat12 set cluster

Post by egos »

DT170x wrote:Sorry I didn't Know that.
Look at my reset macro to generate sequential cluster chain for a file. Maybe this helps you.

Code: Select all

if id#_size>0
count=(id#_size+511)/512
cur=id#_base/512-(33-2)
repeat count
if %=count
val=0FFFh
else
val=cur+1
end if
if cur and 1
val=val shl 4
end if
disp=(cur*3)/2
load var word from 512+disp
var=var or val
store word var at 512+disp
store word var at 10*512+disp
cur=cur+1
end repeat
end if
Source: mkfloppy.zip
If you have seen bad English in my words, tell me what's wrong, please.
ru2aqare
Member
Member
Posts: 342
Joined: Fri Jul 11, 2008 5:15 am
Location: Hungary

Re: fat12 set cluster

Post by ru2aqare »

PatrickV wrote:I think the number is the number of clusters per file it can handle for example FAT12- 12 Clusters? That i at least what i think it is. Please point out to me if I am wrong
The number is the amount of bits that are used to store each cluster number in the allocation table. So FAT12 theoretically supports 2^12 clusters (actually, it's around 4086, due to the last ten or so numbers being reserved), FAT16 theoretically supports 2^16 clusters (again, somewhat less), and FAT32 supports 2^28 clusters (although the name says 32, only 28 bits are used for the cluster number, the highest four bits are reserved; and again there are some reserved cluster numbers).

It would be a pretty serious limitation, if FAT12 could only handle files that are 12 clusters long. Even with the maximum cluster size 64KiB (if I remember correctly, FAT12 can't do clusters larger than this), that is only 768KiB - that would be pretty lame.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re:

Post by AJ »

Hi,
DT170x wrote:I thought there is FAT, FAT16, and FAT32
As a word of warning, FAT (without a suffix) normally relates to FAT16 - at least on MS fdisk.

Cheers,
Adam
User avatar
xyjamepa
Member
Member
Posts: 397
Joined: Fri Sep 29, 2006 8:59 am

Re: fat12 set cluster

Post by xyjamepa »

Okay guys lets get back to the main point :wink:
some asm code snippt...
The man who follows the crowd will usually get no further than the crowd.
The man who walks alone is likely to find himself in places
no one has ever been before.
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: fat12 set cluster

Post by egos »

abuashraf wrote:Okay guys lets get back to the main point :wink:
some asm code snippt...
It's so pitiful for me to give you my code :D
If you have seen bad English in my words, tell me what's wrong, please.
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Re: fat12 set cluster

Post by Dex »

My OS has fat12, fat16, fat32 implemented (in fasm) you are free to use it, but you MUST include the licence, if you use any part of the code.
You can get it here: http://dex4u.com/download.htm
User avatar
salil_bhagurkar
Member
Member
Posts: 261
Joined: Mon Feb 19, 2007 10:40 am
Location: India

Re: fat12 set cluster

Post by salil_bhagurkar »

Why don't you go for the actual math instead, and write a driver yourself using this specification from MS... Reading it at the most 10 times, you should be able to understand the FAT in general (and hence FAT12). :twisted:
User avatar
xyjamepa
Member
Member
Posts: 397
Joined: Fri Sep 29, 2006 8:59 am

Re: fat12 set cluster

Post by xyjamepa »

I already wrote complete fat12 driver in C,but now I'm writing it in asm
but I'm really having problem with this specific function,I wrote "getFat" function by
myself ,but till now I couldn't get this function done.
anyway here's what I have...

Code: Select all

	mov	ax,word [cluster]
	mov	cx,ax
	mov	dx,ax
	shr	dx,0x0001
	add	cx,dx		;sum of (3/2)
	mov	bx,[es:0x500]	;location of fat table in memory
	add	bx,cx		;index into fat
	test	ax,0x0001
	jnz	.odd
.eve:	
	push	bx
	inc	bx
	and	bx,0x0F
	mov	cx,[value]
	and	cx,0xF00
	shr	cx,0x0008
	or	bx,cx
	mov	cx,[value]
	and	cx,0x0FF
	pop	bx
	mov	[bx],cx
.odd:
	and	[bx],0x0F
	mov	cx,[value]
	and	cx,0x00F
	shl	cx,4
	or	[bx],cx
	mov	cx,value
	and	cx,0xFF0
	shr	cx,4
	inc	bx
	mov	bx,cx
Please note that I loaded the fat table into memory at [es:0x500]
Also "value" holds the value I want to set the entry to it
The man who follows the crowd will usually get no further than the crowd.
The man who walks alone is likely to find himself in places
no one has ever been before.
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: fat12 set cluster

Post by Troy Martin »

PatrickV wrote:I think the number is the number of clusters per file it can handle for example FAT12- 12 Clusters? That i at least what i think it is. Please point out to me if I am wrong
FAT12 uses a twelve-bit File Allocation Table, allowing 2^12-19 clusters. At 8KB per cluster (16 sectors) that makes a volume max size of 32 MB.
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
User avatar
xyjamepa
Member
Member
Posts: 397
Joined: Fri Sep 29, 2006 8:59 am

Re: fat12 set cluster

Post by xyjamepa »

here's what I got till now...

Code: Select all

setcluster:
             mov	ax,word [cluster]   ;current cluster
	mov	cx,ax
	mov	dx,ax
	shr	dx,0x0001
	add	cx,dx		;sum of (3/2)
	mov	bx,[es:0x500]	;location of fat table in memory
	add	bx,cx		;index into fat
	mov       dx, WORD [bx]       ;read two bytes from FAT
	test	ax,0x0001
	jnz	.odd
.eve:	
	and	[value],0xFFF
	and	bx,0xF000
	jmp	done
.odd:
	shl	[value],4
	and	bx,0x000F

done:
	or	bx,[value]
            ret
would any one please check this function and till me what bugs does it have?
Thanx.
The man who follows the crowd will usually get no further than the crowd.
The man who walks alone is likely to find himself in places
no one has ever been before.
Post Reply