J
Joseph
Hi,
I'm having bit of questions on recursive pointer. I have following
code that supports upto 8K files but when i do a file like 12K i get a
segment fault. I Know it is in this line of code. How do i make the
last pointer in the indirect sector that has another level of indirect
pointer, and be defined recursively to support infinite large files?
-code-
bool
FileHeader::Allocate(BitMap *freeMap, int fileSize)
{
int i;
numBytes = fileSize;
numSectors = divRoundUp(fileSize, SectorSize);
if (freeMap->NumClear() < (numSectors+1))
return FALSE; // not enough space
int directSectors = numSectors % NumDirect;
for (i = 0; i < directSectors; i++)
dataSectors = freeMap->Find();
if( (numSectors / NumDirect) > 0 ) {
indirectHdrSector = freeMap->Find();
FileHeader *hdr = new FileHeader;
for( i = 0; i < (numSectors - directSectors); i++ )
hdr->dataSectors = freeMap->Find();
hdr->WriteBack(indirectHdrSector);
delete hdr;
}
return TRUE;
}
I'm having bit of questions on recursive pointer. I have following
code that supports upto 8K files but when i do a file like 12K i get a
segment fault. I Know it is in this line of code. How do i make the
last pointer in the indirect sector that has another level of indirect
pointer, and be defined recursively to support infinite large files?
-code-
bool
FileHeader::Allocate(BitMap *freeMap, int fileSize)
{
int i;
numBytes = fileSize;
numSectors = divRoundUp(fileSize, SectorSize);
if (freeMap->NumClear() < (numSectors+1))
return FALSE; // not enough space
int directSectors = numSectors % NumDirect;
for (i = 0; i < directSectors; i++)
dataSectors = freeMap->Find();
if( (numSectors / NumDirect) > 0 ) {
indirectHdrSector = freeMap->Find();
FileHeader *hdr = new FileHeader;
for( i = 0; i < (numSectors - directSectors); i++ )
hdr->dataSectors = freeMap->Find();
hdr->WriteBack(indirectHdrSector);
delete hdr;
}
return TRUE;
}