FAT12 file problems
Re: FAT12 file problems
Why are you using uninitialized pointers everywhere?
*and pointers set to 0 are being used?
*and pointers set to 0 are being used?
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
Re: FAT12 file problems
If your talking about the ones in the structs Visual C++ doesn't let me initialize variables that aren't integral or aren't a static constant. Anything else that's uninitialized is probably because one time when I tried to initialize a variable (forget which one) it triple faulted. Driver = .
I will try to initialize all of the other variables but if it triple faults...
I will try to initialize all of the other variables but if it triple faults...
Re: FAT12 file problems
No, Im referring to your code like this:
The above occurs everywhere throughout your code. Along with code like:
Do you see the problem in the above code? (Comments added by me.)
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
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
Re: FAT12 file problems
Thanks, I got my findfile function to work, the strcmp function you had in your standard lib didn't work for that function, I replaced it with my own and it worked. I still have issues though after I got findfile to work I put in one DebugPrintf and found out that for some odd reason the file size section of the directory entry was missing. I'm very confused as of now:
In Microsoft's specs they say the last 4 bytes of the directory entry are the file size.
But in the majority of other specs they say its reserved.
I was reading the file size to try to find a way to read entire files without using the FAT to follow clusters (I'll admit: sort of a lazy replacement). But anyway anyone got an example of how to follow clusters using the FAT; The loading part should be fine.
In Microsoft's specs they say the last 4 bytes of the directory entry are the file size.
But in the majority of other specs they say its reserved.
I was reading the file size to try to find a way to read entire files without using the FAT to follow clusters (I'll admit: sort of a lazy replacement). But anyway anyone got an example of how to follow clusters using the FAT; The loading part should be fine.
If you thought that then you'd be surprised to know that that code actually worked fine . (for once in my FAT12 driver )neon 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
-
- Member
- Posts: 2566
- Joined: Sun Jan 14, 2007 9:15 pm
- Libera.chat IRC: miselin
- Location: Sydney, Australia (I come from a land down under!)
- Contact:
Re: FAT12 file problems
Hi,
I highly suggest you read the "fatgen130.doc" file that you can find on the internet. It's the definitive specification for the FAT filesystem, and it's all you should need to implement a FAT driver. My FAT driver supports FAT12, FAT16 and FAT32; you may find it beneficial to read the code and compare it to the spec to try and understand what's happening.
However, it does look like you have some bad practices in your code...
Finally,
The best course of action for you now is to fix the problems with your code. Once you're no longer reading from null or undefined pointers, you'll be in a better place to debug the problems with your FAT driver.
Cheers,
Matt
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.
I highly suggest you read the "fatgen130.doc" file that you can find on the internet. It's the definitive specification for the FAT filesystem, and it's all you should need to implement a FAT driver. My FAT driver supports FAT12, FAT16 and FAT32; you may find it beneficial to read the code and compare it to the spec to try and understand what's happening.
However, it does look like you have some bad practices in your code...
You really should be either:Code: Select all
unsigned char *buff = 0;
- Passing the buffer to read into to fread (to avoid overwriting other concurrent reads), or
- Allocate some memory (malloc, if you have it, or use a static sized array)
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;
The best course of action for you now is to fix the problems with your code. Once you're no longer reading from null or undefined pointers, you'll be in a better place to debug the problems with your FAT driver.
Cheers,
Matt
Re: FAT12 file problems
The fatgen103 is the one I was using... As for the fread buff variable, I tend to program till I literally can't think about anything but sleep over the weekends; I will fix that now but will not have that as a parameter until I get some working code or if that's the only error. As for the testfname I fixed that as soon as I read neon's post . 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. Anyway off to initializing every variable correctly.
-
- Member
- Posts: 2566
- Joined: Sun Jan 14, 2007 9:15 pm
- Libera.chat IRC: miselin
- Location: Sydney, Australia (I come from a land down under!)
- Contact:
Re: FAT12 file problems
Hi,
That'll also give you an off-by-one error: if a file is 516 bytes, 516 / 512 = 1, not 2 (truncated).
Cheers,
Matt
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.
That'll also give you an off-by-one error: if a file is 516 bytes, 516 / 512 = 1, not 2 (truncated).
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
Cheers,
Matt
Re: FAT12 file problems
Yeah I guess there is no excuse, but regardless fixing your own mistakes is just one way off learning more, so at least I learned something today . Any way back to finishing my LoadFAT function then implement the cluster following code.
Re: FAT12 file problems
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 fine . (for once in my FAT12 driver )neon 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
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];
When the chance of succeeding is 99%, there is still a 50% chance of that success happening.
Re: FAT12 file problems
I would need to use more an array more than 1024: 512 for each sector and due to the fact that the FAT and the Root Directory span over multiple sectors plus I would then need to use an array like that for every file I load into memory. I could just check which memory is free in the memory manager, load the FAT, Root Directory or file to the memory then mark it as used. (If possible)
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: FAT12 file problems
Might I recommend passing /W4 /Wall /Wp64 /WX to the visual studio compiler. It might magically solve your problems (and more )
(disclaimer: I don't know your VC version so some switches might be different in your version)
(disclaimer: I don't know your VC version so some switches might be different in your version)