
I just uploaded to my site's server:
Download FAT.cpp
Take a look at that.
Code: Select all
int findfile (char *fname)
{
unsigned short entry = 1;
char *testfname;
DebugPrintf("\nLooking for file: %s\n\n", fname);
while (true)
{
for(int i=0; i<11; i++)
testfname[i] = RootDir_MemLocation[(32 * (entry-1)) + i]; // where does testfname point?
Code: Select all
void* _cdecl fread (unsigned char *fp, unsigned int offset, unsigned int count, bool readasint)
{
unsigned char *buff = 0;
for(int i=0; i<count; i++)
{
buff[i] = fp[offset + count]; // if not in virtual memory, say good bye to the IVT
If you thought that then you'd be surprised to know that that code actually worked fineneon wrote:Code: Select all
void* _cdecl fread (unsigned char *fp, unsigned int offset, unsigned int count, bool readasint) { unsigned char *buff = 0; for(int i=0; i<count; i++) { buff[i] = fp[offset + count]; // if not in virtual memory, say good bye to the IVT
The file size is merely the number of bytes in the file. You will still have to follow the cluster chain for reads that are not in the first cluster or that cross a cluster boundary.I was reading the file size to try to find a way to read entire files without using the FAT to follow clusters... <snip>... In Microsoft's specs they say the last 4 bytes of the directory entry are the file size.
You really should be either:Code: Select all
unsigned char *buff = 0;
Code: Select all
void* _cdecl fread (unsigned char *fp, unsigned int offset, unsigned int count, bool readasint, char *buffer)
{
/** Read <count> bytes into <buffer>, starting at <offset> bytes into the file **/
return buffer;
}
Again, testfname isn't defined... It could be pointing to code in your kernel for all you know, and you'll end up overwriting valid code with the filename.Code: Select all
char *testfname;
Regardless, you cannot ever assume that the cluster layout on disk is contiguous. If a read will pass a cluster boundary, you must follow the chain in the FAT - there's no getting around it.As for the cluster following replacement I converted the size to the number of sectors held by dividing by the bytes per sector, considering that in my boot sector each cluster is one sector.
If you're spending that much time coding, then I don't see why you can't just take the extra minute or so to think about what you're writing and do it right the first time...As for the fread buff variable, I tend to program till I literally can't think about anything but sleep over the weekends
It probably works fine because you're probably writing to some random address in memory that isn't used at that time. It's like doing this:accelleon wrote:If you thought that then you'd be surprised to know that that code actually worked fineneon wrote:Code: Select all
void* _cdecl fread (unsigned char *fp, unsigned int offset, unsigned int count, bool readasint) { unsigned char *buff = 0; for(int i=0; i<count; i++) { buff[i] = fp[offset + count]; // if not in virtual memory, say good bye to the IVT
. (for once in my FAT12 driver
)
Code: Select all
unsigned *p = 0x123456; // I need somewhere to store my value and this address is 'usable' memory.
*p = 5; // Sure, the value at this address might become 5, but if e.g. the heap had a header there, it will be corrupted and your OS will break down.
Code: Select all
byte NameBuffer[11];