[En-Nut-Discussion] PHAT example code ?

Jesper Hansen jesperh at telia.com
Wed Jan 25 14:27:49 CET 2006


Okay, I've found the problem with the PHAT.

In MmCardMount the code assumes that there is a partition sector on 
sector 0 of the device.
This is far from usual, and normally only harddrives has this. Today, 
some larger MMC/SD/CF cards also has this, but not necessarily.
Most often cards start directly with the volume boot sector at physical 
sector 0.
I've mostly seen the partition sector on new cards, but if you format a 
card in Windows, it will normally NOT get a partition sector.

So, the code in MmCardMount fails with cards without the partition 
sector, like mine!

The code should check whether the loaded sector is a partition sector or 
a volume boot sector.
This can easily be done by checking the first byte of the sector for 
being 0xE9 or 0xEB (jump instruction).
If the first byte is any of these two values, the sector is a volume 
boot sector, and there is no partition sector on the device.

I was looking into making this change myself in mmcard.c, but there are 
other intricacies, so I'll leave that up to Harald ;-)

But, when fiddling with the httpd sample and my Nut 3, I found another 
problem.
The PHAT driver didn't implement dev_size causing _filelength to fail.
So, here's a solution for that :

In phatfs.c add:

/*!
  * \brief Return the size of a file.
  * \param nfp File descriptor.
  * \return File size.
  */
static long PhatFileSize(NUTFILE * nfp)
{
	return ((PHATFILE *)nfp->nf_fcb)->f_dirent.dent_fsize;
}

and insert PhatFileSize in the last slot in the devPhat0 record at the 
end of the phatfs.c file.

/Jesper


Harald Kipp wrote:
> Jesper,
> 
> At 02:03 25.01.2006 +0100, you wrote:
> 
>> Does any testcode or examples for the PHAT filesystem and MMC
>> on the Nut 3.0d exist ?
> 
> 
> app/ftpd
> Release 4.1.3
> 
> 
>>         DIR *d = opendir("/");
> 
> 
> Without trying your code, I think that the problem is here.
> Remember our conversation about missing cwd in Nut/OS?
> 
> Some additional information is available at
> http://www.ethernut.de/en/documents/phat.html
> 
> Harald
> 
> _______________________________________________
> En-Nut-Discussion mailing list
> En-Nut-Discussion at egnite.de
> http://www.egnite.de/mailman/listinfo.cgi/en-nut-discussion
> 
> 



More information about the En-Nut-Discussion mailing list