News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu

X-MASS, a mass-storage expansion for all CPC.

Started by TotO, 18:32, 14 December 14

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Prodatron

That's true, but for a good implementation you should exactly follow these official rules, as you can never know what could go wrong in other respects, and it wouldn't be your fault.

GRAPHICAL Z80 MULTITASKING OPERATING SYSTEM

gerald

#476
Quote from: Ast on 20:21, 26 February 16
You're right Prodatron but what i have written is also written in the ide Microsoft's documentation... Just see Page 9.
The documentation say that if you have a FAT32, those bytes are 0. Not the other way round.
You should not assume that if these byte are 0, you have a FAT32.
The only way to get the fat type is by calculating the number of clusters your partition have.

edit: some missing char .... really should re-read before posting  :picard:

Prodatron

#477
I must admit, that I really liked this Microsoft document back in these days, as it is written in an "idiot proofed" way (and this FAT detection paragraph is an example for this).
They provide formulas for everything you need to calculate and they often describe things in more than one sentence to ensure, that it's really clear for the coder.

Example: "There is considerable confusion over exactly how this works, which leads to many "off by 1", "off by 2", "off by 10", and "massively off" errors. It is really quite simple how this works. The FAT type— one of FAT12, FAT16, or FAT32—is determined by the count of clusters on the volume and nothing else." :D

GRAPHICAL Z80 MULTITASKING OPERATING SYSTEM

Ast

You could also read ascii char "FAT xx", and you'll know where you re.
In the pictures i posted here you could read "FAT 32"
_____________________

Ast/iMP4CT. "By the power of Grayskull, i've the power"

http://amstradplus.forumforever.com/index.php
http://impdos.wikidot.com/
http://impdraw.wikidot.com/

All friends are welcome !

gerald

Quote from: Ast on 20:58, 26 February 16
You could also read ascii char "FAT xx", and you'll know where you re.
In the pictures i posted here you could read "FAT 32"
BS_FilSysType :
NOTE: This string is informational only and does not determine the FAT type.
;D

Ast

Quote from: Ast on 17:10, 26 February 16
In my case, my x-Mass is Fat32 format. So what are the value to access directory ? explanations will be welcomed.

(of course, i see the following formula : RootDirSectors = ((BPB_RootEntCnt * 32) + (BPB_BytsPerSec – 1)) / BPB_BytsPerSec)

the calcul would be :

((2*32)+(512-1))/512 -> 64,99.....
Sorry but i make a big mistake because on fat32 BPB_RootEntCnt value is 0 so :

((0*32)+(512-1))/512 -> 0,9980

value is Strange, no ??
_____________________

Ast/iMP4CT. "By the power of Grayskull, i've the power"

http://amstradplus.forumforever.com/index.php
http://impdos.wikidot.com/
http://impdraw.wikidot.com/

All friends are welcome !

gerald

Quote from: Ast on 21:38, 27 February 16
Sorry but i make a big mistake because on fat32 BPB_RootEntCnt value is 0 so :

((0*32)+(512-1))/512 -> 0,9980

value is Strange, no ??
No, that's expected.
You only keep the integer part, and 0 is expected.

This calculation is to know the minimal number of sector needed by the root directory according to the number of entry.
The (512-1)[nb]It could have been anything between 512-1 and 512-32[/nb] term is there to force one sector as soon as 1 entry is required when doing round down arithmetic.
Then you just have to shift right by 9 bit to get your result.
That's the fastest way.


Ast

Quote from: gerald on 21:56, 27 February 16
Then you just have to shift right by 9 bit to get your result.
That's the fastest way.
shift right by 9 bit ???

You think about multiply 9 times (512-1)
_____________________

Ast/iMP4CT. "By the power of Grayskull, i've the power"

http://amstradplus.forumforever.com/index.php
http://impdos.wikidot.com/
http://impdraw.wikidot.com/

All friends are welcome !

Ast

Quote
4.1: Determination of FAT entry for a cluster
Given any valid cluster number N, this section describes the algorithm used to determine the
entry in the FAT(s) for that cluster number.
FAT 16 and FAT 32
The FAT entry in the first FAT is determined as described below:
If(BPB_FATSz16 != 0)
FATSz = BPB_FATSz16;
Else
FATSz = BPB_FATSz32;
If(FATType == FAT16)
FATOffset = N * 2;
Else if (FATType == FAT32)
FATOffset = N * 4;
ThisFATSecNum = BPB_ResvdSecCnt + (FATOffset / BPB_BytsPerSec);
ThisFATEntOffset = REM(FATOffset / BPB_BytsPerSec);2

What is N value ???
_____________________

Ast/iMP4CT. "By the power of Grayskull, i've the power"

http://amstradplus.forumforever.com/index.php
http://impdos.wikidot.com/
http://impdraw.wikidot.com/

All friends are welcome !

gerald

Quote from: Ast on 22:11, 27 February 16
shift right by 9 bit ???

You think about multiply 9 times (512-1)
Division by 512 = shift right by 9 bit (512 = 2^9)

Quote from: Ast on 22:16, 27 February 16
What is N value ???
N is the cluster value. 12 bit in FAT12, 16 bit in FA16, 32 bit in FAT32

Ast

@TotO : tu ne serais pas un peu moqueur toi ???? :-D
_____________________

Ast/iMP4CT. "By the power of Grayskull, i've the power"

http://amstradplus.forumforever.com/index.php
http://impdos.wikidot.com/
http://impdraw.wikidot.com/

All friends are welcome !

TotO

I agree about using bit shifting to do 2^n calculations.  :-*
"You make one mistake in your life and the internet will never let you live it down" (Keith Goodyer)

Executioner

Quote from: gerald on 22:37, 27 February 16
Division by 512 = shift right by 9 bit (512 = 2^9)
N is the cluster value. 12 bit in FAT12, 16 bit in FA16, 32 bit in FAT32

I wouldn't be using simple shifting for multiples of 8 bits. If it's in assembler, use LD reg, reg to shift the 8 bits, then a single shift for the 9th. Not sure how you'd do that in C precisely. (Of course, a decent optimising compiler might do it for you on >> 9)

gerald

Quote from: Executioner on 00:00, 28 February 16
I wouldn't be using simple shifting for multiples of 8 bits. If it's in assembler, use LD reg, reg to shift the 8 bits, then a single shift for the 9th. Not sure how you'd do that in C precisely. (Of course, a decent optimising compiler might do it for you on >> 9)
I usually look at the compiled C to see it the compiler is decent, and then adapt the code if not.  ;)
I think Ast is using ASM, and to my mind shifting by 9 is dropping le LSB + one shift.

Ast

#489
Here is the result of what is written in Microsoft's doc :

Quote
FDT start sector

33 = ResvdSecCnt
02 = BPB_BytsPerSec
00000002 = FATSz32

FatOffset = N*4

Si N=1 alors FatOffset=4
----

formule :

FatSecNum=RevdSecCnt+(FatOffset/BPB_BytsPerSec)
=33+(4/2)
=35
-----
FatEntOffset=(FatOffset/BPB_BytsPerSec)
=(4/2)

------
SectorNumber=(FatNumber*FATSz32)+FatSecNum

FatNumber=2 pour second Fat, 3 pour 3ème..etc

-> (2*2)+35=39

But what can i do now ???


Edit :
Exploring all X-mass sectors, i finally found the directories...
Directories seems to use 2 sectors, then displays the files present in this directory...

More far, you can find another directory (2 sectors too), + files are following...

I really need to know how it works (I know many things to make a driver but I want to know more...)

Edit 2:
@TotO : Why is my X-Mass formated in Fat32? Can you tell me where I can find the directory of ACMEdos ?
---
@Prodatron : Why do your SymbOS format Tools use Fat 16 format ?

Some words : I think using Fat16 for x-Mass would have to be better cause of his size (128 Mb) It's written in the Microsoft's Doc because Fat 32 use mirrors and lost spaces on the disc...
Fat 32 is more interresting for bigger spaces >128 Mb
_____________________

Ast/iMP4CT. "By the power of Grayskull, i've the power"

http://amstradplus.forumforever.com/index.php
http://impdos.wikidot.com/
http://impdraw.wikidot.com/

All friends are welcome !

TotO

Yes, it is possible that you DOM was formated in FAT32. It is not a problem as SymbOS work fine with...
But, better to reinitialise it by using the unparted FAT16 tools now.
"You make one mistake in your life and the internet will never let you live it down" (Keith Goodyer)

Ast

#491
@TotO : which is the tool you use to format these DoM ?
Have you connected them in usb using an usb 44 pins adaptator ?

---

You haven't answer my question about ACMEdos...

Quote
@TotO : Why is my X-Mass formated in Fat32? Can you tell me where I can find the directory of ACMEdos ?

Edit : Concerning the fat16 format, yes i'll do it for sure, but Prodatron, is your format Tools will erase SymbOS on the X-Mass ? Do i have to re-install SymbOS after the formatting ?
_____________________

Ast/iMP4CT. "By the power of Grayskull, i've the power"

http://amstradplus.forumforever.com/index.php
http://impdos.wikidot.com/
http://impdraw.wikidot.com/

All friends are welcome !

TotO

The SymbOS tool destroy the FAT to create and unparted FAT16 device, like expected by ACMEDOS.
So yes, you will have to copy again your files on the DOM after.

I will like to have the same from BASIC to initialize the DOM before shipping the X-MASS, but it is not the case.
So... Actually, I connect the DOM to a PC and I use Windows to format them.
"You make one mistake in your life and the internet will never let you live it down" (Keith Goodyer)

gerald

Quote from: Ast on 13:39, 28 February 16
Here is the result of what is written in Microsoft's doc :
But what can i do now ???
Let's start from the begining

0x00B : BPB_BytsPerSec : 00 02 -> 512 byte per sector
0x00D : BPB_SecPerClus : 02    -> 2 sector per cluster
0x00E : BPB_RsvdSecCnt : 21 00 -> 33 reserved sector
0x010 : BPB_NumFATs    : 02    -> 2 FAT
0x011 : BPB_RootEntCnt : 00 00 -> 0 Root entry
0x013 : BPB_TotSec16   : 00 00 -> 0 -> look at BPB_TotSec32
0x016 : BPB_FATSz16    : 00 00 -> 0 -> look at BPB_FATSz32

0x020 : BPB_TotSec32   : 0f ad 03 00 -> 240911 sectors
0x024 : BPB_FATSz32    : a6 03 00 00 -> 934 sectors

To find the 1st sector of data section :
1- get the number of sector used by the FAT12/16 root directory
RootDirSectors  = (BPB_RootEntCnt  * 32 + BPB_BytsPerSec-1 ) / BPB_BytsPerSec;
                = (        0       * 32 + 512           -1 ) / 512
                = 0
2- get the number of sectors used by non-data section
systemSectors = BPB_RsvdSecCnt + BPB_FATSz * BPB_NumFATs + RootDirSectors
              = 33             + 934       * 2           + 0
              = 1901

3- get the number of cluster for data storage
clusters = (BPB_TotSec - systemSectors) / BPB_SecPerClus
         = (240911     - 1901         ) / 2
         = 119504

119504 > 65525 => FAT32 => root directory is a regular folder starting at cluster BPB_RootClus

0x0x2c : BPB_RootClus : 02 00 00 00 -> cluster 2

Now where is cluster N on disk :
1stClusterSector = patritionOffset +  systemSectors + (N-2)*BPB_SecPerClus
                 = patritionOffset +  1901          + (2-2)*2
                 = patritionOffset +  1901

Quote from: Ast on 13:39, 28 February 16
Edit :
Exploring all X-mass sectors, i finally found the directories...
Directories seems to use 2 sectors, then displays the files present in this directory...

More far, you can find another directory (2 sectors too), + files are following...


I really need to know how it works (I know many things to make a driver but I want to know more...)
The fact that files are following the directories is just a side effect of when these were written. Do not count on that to find your way.
All you need to know is were to find on which cluster start a file/directory, and this is within the Fat directory structure : collection of 32bytes that makes a directory.
Next you need to understand how to follow the cluster chain, ie use the FAT itself.

Quote from: Ast on 13:39, 28 February 16
I think using Fat16 for x-Mass would have to be better cause of his size (128 Mb) It's written in the Microsoft's Doc because Fat 32 use mirrors and lost spaces on the disc...
Fat 32 is more interresting for bigger spaces >128 Mb
Its a trade-off.
To use a FAT16 on a 128MB device you have to use 2k clusters.
If you store a majority of small file (let say less than 1k), you end up wasting half your storage space.

Prodatron

Another advantage of FAT32 is the "FSInfo" sector, which is speeding up cluster allocation and free space calculation:
It stores "FSI_Free_Count" and FSI_Nxt_Free". The latter one makes it much faster to allocate new clusters inside the FAT (writing new files or extending existing files is quicker). With FAT12 and FAT16 you always have to search through the whole FAT when you need a new cluster.

GRAPHICAL Z80 MULTITASKING OPERATING SYSTEM

gerald

Quote from: Prodatron on 16:17, 28 February 16
Another advantage of FAT32 is the "FSInfo" sector, which is speeding up cluster allocation and free space calculation:
It stores "FSI_Free_Count" and FSI_Nxt_Free". The latter one makes it much faster to allocate new clusters inside the FAT (writing new files or extending existing files is quicker). With FAT12 and FAT16 you always have to search through the whole FAT when you need a new cluster.
You still need to maintain tha FSI_Nxt_Free, so you still have to search for it  ;) (but if done well, you do not need to parse the FAT from begining)
However, the FSI_Free_Count is real speedup.

Ast

First Step after using the SymbOS format tool...

Now DoM is Fat16 formatted so :

-> Re-install properly SymbOS (I really love it, very well done Prodatron!!!)
-> Install Properly all the Tools
-> Create "Format XMASS Dom" icône... I know, icône picture is still missing ^^

_____________________

Ast/iMP4CT. "By the power of Grayskull, i've the power"

http://amstradplus.forumforever.com/index.php
http://impdos.wikidot.com/
http://impdraw.wikidot.com/

All friends are welcome !

Ast

Quote from: gerald on 15:37, 28 February 16
Let's start from the begining

0x00B : BPB_BytsPerSec : 00 02 -> 512 byte per sector
0x00D : BPB_SecPerClus : 02    -> 2 sector per cluster
0x00E : BPB_RsvdSecCnt : 21 00 -> 33 reserved sector
0x010 : BPB_NumFATs    : 02    -> 2 FAT
0x011 : BPB_RootEntCnt : 00 00 -> 0 Root entry
0x013 : BPB_TotSec16   : 00 00 -> 0 -> look at BPB_TotSec32
0x016 : BPB_FATSz16    : 00 00 -> 0 -> look at BPB_FATSz32

0x020 : BPB_TotSec32   : 0f ad 03 00 -> 240911 sectors
0x024 : BPB_FATSz32    : a6 03 00 00 -> 934 sectors

To find the 1st sector of data section :
1- get the number of sector used by the FAT12/16 root directory
RootDirSectors  = (BPB_RootEntCnt  * 32 + BPB_BytsPerSec-1 ) / BPB_BytsPerSec;
                = (        0       * 32 + 512           -1 ) / 512
                = 0
2- get the number of sectors used by non-data section
systemSectors = BPB_RsvdSecCnt + BPB_FATSz * BPB_NumFATs + RootDirSectors
              = 33             + 934       * 2           + 0
              = 1901

3- get the number of cluster for data storage
clusters = (BPB_TotSec - systemSectors) / BPB_SecPerClus
         = (240911     - 1901         ) / 2
         = 119504

119504 > 65525 => FAT32 => root directory is a regular folder starting at cluster BPB_RootClus

0x0x2c : BPB_RootClus : 02 00 00 00 -> cluster 2

Now where is cluster N on disk :
1stClusterSector = patritionOffset +  systemSectors + (N-2)*BPB_SecPerClus
                 = patritionOffset +  1901          + (2-2)*2
                 = patritionOffset +  1901


Now, I'm in Fat16 format, so all calculate must be done !!!
But, good news, first sector (0) is Fat16 one ;-)

So many data to read...
_____________________

Ast/iMP4CT. "By the power of Grayskull, i've the power"

http://amstradplus.forumforever.com/index.php
http://impdos.wikidot.com/
http://impdraw.wikidot.com/

All friends are welcome !

Prodatron

#498
Quote from: Ast on 16:41, 28 February 16
First Step after using the SymbOS format tool...

Now DoM is Fat16 formatted so :

-> Re-install properly SymbOS (I really love it, very well done Prodatron!!!)
-> Install Properly all the Tools
-> Create "Format XMASS Dom" icône... I know, icône picture is still missing ^^

I am glad that it works, @Ast ! :)

Ok, I will add an icon for this little app  :D

GRAPHICAL Z80 MULTITASKING OPERATING SYSTEM

Prodatron

Quote from: gerald on 16:40, 28 February 16
You still need to maintain tha FSI_Nxt_Free, so you still have to search for it  ;) (but if done well, you do not need to parse the FAT from begining)
However, the FSI_Free_Count is real speedup.
You are right, but FSI_Nxt_Free usually points to the end or close to the end of the existing FAT entries, so in most cases there are not many entries to parse. Indeed you have to update this FSInfo entry everytime you allocate or free clusters (same for FSI_Free_Count), but in total it's faster in most cases.

GRAPHICAL Z80 MULTITASKING OPERATING SYSTEM

Powered by SMFPacks Menu Editor Mod