473,750 Members | 2,253 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

large file support

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::All ocate(BitMap *freeMap, int fileSize)
{
int i;

numBytes = fileSize;
numSectors = divRoundUp(file Size, SectorSize);
if (freeMap->NumClear() < (numSectors+1))
return FALSE; // not enough space

int directSectors = numSectors % NumDirect;

for (i = 0; i < directSectors; i++)
dataSectors[i] = freeMap->Find();

if( (numSectors / NumDirect) > 0 ) {
indirectHdrSect or = freeMap->Find();
FileHeader *hdr = new FileHeader;
for( i = 0; i < (numSectors - directSectors); i++ )
hdr->dataSectors[i] = freeMap->Find();
hdr->WriteBack(indi rectHdrSector);
delete hdr;
}
return TRUE;
}
Jul 22 '05 #1
7 3536

"Joseph" <cr*******@gmai l.com> wrote in message
news:co******** **@usenet01.srv .cis.pitt.edu.. .
Hi,

I'm having bit of questions on recursive pointer.
What's a "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.
What 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?

??? I don't understand that sentence at all. What's the "last pointer"?
What's the "indirect sector"?

You do know there's no such thing as an "infinite" (infinitely) large file,
right? (A 12k file is actually quite small.)
-code-

bool
FileHeader::All ocate(BitMap *freeMap, int fileSize)
{
int i;

numBytes = fileSize;
numSectors = divRoundUp(file Size, SectorSize);
if (freeMap->NumClear() < (numSectors+1))
return FALSE; // not enough space

int directSectors = numSectors % NumDirect;

for (i = 0; i < directSectors; i++)
dataSectors[i] = freeMap->Find();

if( (numSectors / NumDirect) > 0 ) {
indirectHdrSect or = freeMap->Find();
Where is indirectHdrSect or defined?
FileHeader *hdr = new FileHeader;
for( i = 0; i < (numSectors - directSectors); i++ )
hdr->dataSectors[i] = freeMap->Find();
hdr->WriteBack(indi rectHdrSector);
delete hdr;
}
return TRUE;
}


Comments in the code would help a great deal. It's very difficult to try to
figure out what all this code is *supposed* to be doing.

Also, where does it crash? Can you debug it to see what is causing the
crash?

-Howard


Jul 22 '05 #2
Oh my,
you sure rip my post apart.

what i mean by "recursive pointer" i mean by a pointer that is defined
recursively. The code that i have posted below is the template in
defining couple of things. When i say infiately large file i mean
theoetically. indirectHdrSect or is defined in the header file as
private int.

-code-
bool
FileHeader::All ocate(BitMap *freeMap, int fileSize)
{
int i;

numBytes = fileSize;
numSectors = divRoundUp(file Size, SectorSize);
if (freeMap->NumClear() < (numSectors+1))
return FALSE; // not enough space

int directSectors = numSectors % NumDirect;

for (i = 0; i < directSectors; i++)
dataSectors[i] = freeMap->Find();

// this section of code supports file size bigger than 8KB but not
// bigger than 12KB need to support upto 128KB
if( (numSectors / NumDirect) > 0 ) {
indirectHdrSect or = freeMap->Find();
FileHeader *hdr = new FileHeader; // here is the pointer i was
// speaking of that which is
// indirect sector meaning
// anything above 4KB is
//indirect sector
for( i = 0; i < (numSectors - directSectors); i++ )
hdr->dataSectors[i] = freeMap->Find();
hdr->WriteBack(indi rectHdrSector);
delete hdr;
}
return TRUE;
}

Howard wrote:
"Joseph" <cr*******@gmai l.com> wrote in message
news:co******** **@usenet01.srv .cis.pitt.edu.. .
Hi,

I'm having bit of questions on recursive pointer.

What's a "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.

What 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?

??? I don't understand that sentence at all. What's the "last pointer"?
What's the "indirect sector"?

You do know there's no such thing as an "infinite" (infinitely) large file,
right? (A 12k file is actually quite small.)

-code-

bool
FileHeader::A llocate(BitMap *freeMap, int fileSize)
{
int i;

numBytes = fileSize;
numSectors = divRoundUp(file Size, SectorSize);
if (freeMap->NumClear() < (numSectors+1))
return FALSE; // not enough space

int directSectors = numSectors % NumDirect;

for (i = 0; i < directSectors; i++)
dataSectors[i] = freeMap->Find();

if( (numSectors / NumDirect) > 0 ) {
indirectHdrSect or = freeMap->Find();

Where is indirectHdrSect or defined?

FileHeader *hdr = new FileHeader;
for( i = 0; i < (numSectors - directSectors); i++ )
hdr->dataSectors[i] = freeMap->Find();
hdr->WriteBack(indi rectHdrSector);
delete hdr;
}
return TRUE;
}

Comments in the code would help a great deal. It's very difficult to try to
figure out what all this code is *supposed* to be doing.

Also, where does it crash? Can you debug it to see what is causing the
crash?

-Howard

Jul 22 '05 #3
Joseph wrote:

Oh my,
you sure rip my post apart.

Look man.
Nobody here knows what you are working on.
Nobody knows what your class FileHeader should do or
how its internals are structured or what members it has.
Nor do we see the rest of the code to guess what you
don't tell us.

With that background nobody really can help you.
[Scroll down]
-code-
bool
FileHeader::All ocate(BitMap *freeMap, int fileSize)
{
int i;

numBytes = fileSize;
numSectors = divRoundUp(file Size, SectorSize);
if (freeMap->NumClear() < (numSectors+1))
return FALSE; // not enough space

int directSectors = numSectors % NumDirect;

for (i = 0; i < directSectors; i++)
dataSectors[i] = freeMap->Find();

// this section of code supports file size bigger than 8KB but not
// bigger than 12KB need to support upto 128KB
if( (numSectors / NumDirect) > 0 ) {
indirectHdrSect or = freeMap->Find();
FileHeader *hdr = new FileHeader; // here is the pointer i was
// speaking of that which is
// indirect sector meaning
// anything above 4KB is
//indirect sector
for( i = 0; i < (numSectors - directSectors); i++ )
hdr->dataSectors[i] = freeMap->Find();
So, you get a segfault. dataSectors seems to be a fixed size array
in that class. At least I can't see any allocation to a pointer
in that code. The first thing I would check if I were you is if
that array is overflowed.
hdr->WriteBack(indi rectHdrSector);
delete hdr;
}
return TRUE;
}


--
Karl Heinz Buchegger
kb******@gascad .at
Jul 22 '05 #4
I'm sorry i not too familiar with newgroup etiquotte for programming.
I've attached the files its the total code. I get segmenet fault
anything that is begger than 8K. Again i'm sorry i just didnt want to
fill the whole post with codes.

Karl Heinz Buchegger wrote:
Joseph wrote:
Oh my,
you sure rip my post apart.

Look man.
Nobody here knows what you are working on.
Nobody knows what your class FileHeader should do or
how its internals are structured or what members it has.
Nor do we see the rest of the code to guess what you
don't tell us.

With that background nobody really can help you.
[Scroll down]

-code-
bool
FileHeader::A llocate(BitMap *freeMap, int fileSize)
{
int i;

numBytes = fileSize;
numSectors = divRoundUp(file Size, SectorSize);
if (freeMap->NumClear() < (numSectors+1))
return FALSE; // not enough space

int directSectors = numSectors % NumDirect;

for (i = 0; i < directSectors; i++)
dataSectors[i] = freeMap->Find();

// this section of code supports file size bigger than 8KB but not
// bigger than 12KB need to support upto 128KB
if( (numSectors / NumDirect) > 0 ) {
indirectHdrSect or = freeMap->Find();
FileHeader *hdr = new FileHeader; // here is the pointer i was
// speaking of that which is
// indirect sector meaning
// anything above 4KB is
//indirect sector
for( i = 0; i < (numSectors - directSectors); i++ )
hdr->dataSectors[i] = freeMap->Find();

So, you get a segfault. dataSectors seems to be a fixed size array
in that class. At least I can't see any allocation to a pointer
in that code. The first thing I would check if I were you is if
that array is overflowed.

hdr->WriteBack(indi rectHdrSector);
delete hdr;
}
return TRUE;
}


// modified
// filehdr.cc
// Routines for managing the disk file header (in UNIX, this
// would be called the i-node).
//
// The file header is used to locate where on disk the
// file's data is stored. We implement this as a fixed size
// table of pointers -- each entry in the table points to the
// disk sector containing that portion of the file data
// (in other words, there are no indirect or doubly indirect
// blocks). The table size is chosen so that the file header
// will be just big enough to fit in one disk sector,
//
// Unlike in a real system, we do not keep track of file permissions,
// ownership, last modification date, etc., in the file header.
//
// A file header can be initialized in two ways:
// for a new file, by modifying the in-memory data structure
// to point to the newly allocated data blocks
// for a file already on disk, by reading the file header from disk
//
// Copyright (c) 1992-1993 The Regents of the University of California.
// All rights reserved. See copyright.h for copyright notice and limitation
// of liability and disclaimer of warranty provisions.

#include "copyright. h"

#include "system.h"
#include "filehdr.h"

//----------------------------------------------------------------------
// FileHeader::All ocate
// Initialize a fresh file header for a newly created file.
// Allocate data blocks for the file out of the map of free disk blocks.
// Return FALSE if there are not enough free blocks to accomodate
// the new file.
//
// "freeMap" is the bit map of free disk sectors
// "fileSize" is the bit map of free disk sectors
//----------------------------------------------------------------------

bool
FileHeader::All ocate(BitMap *freeMap, int fileSize)
{
int i;

numBytes = fileSize;
numSectors = divRoundUp(file Size, SectorSize);
if (freeMap->NumClear() < (numSectors+1))
return FALSE; // not enough space

int directSectors = numSectors % NumDirect;

for (i = 0; i < directSectors; i++)
dataSectors[i] = freeMap->Find();

if( (numSectors / NumDirect) > 0 ) {
indirectHdrSect or = freeMap->Find();
FileHeader *hdr = new FileHeader;
for( i = 0; i < (numSectors - directSectors); i++ )
hdr->dataSectors[i] = freeMap->Find();
hdr->WriteBack(indi rectHdrSector);
delete hdr;
}
return TRUE;
}

//----------------------------------------------------------------------
// FileHeader::Dea llocate
// De-allocate all the space allocated for data blocks for this file.
//
// "freeMap" is the bit map of free disk sectors
//----------------------------------------------------------------------

void
FileHeader::Dea llocate(BitMap *freeMap)
{
int i;

int directSectors = numSectors % NumDirect;

for (i = 0; i < directSectors; i++) {
ASSERT(freeMap->Test((int) dataSectors[i])); // ought to be marked!
freeMap->Clear((int) dataSectors[i]);
}

if( indirectHdrSect or != 0 ) {
FileHeader *hdr = new FileHeader;
hdr->FetchFrom(indi rectHdrSector);

for( i = 0; i < (numSectors - directSectors); i++) {
ASSERT(freeMap->Test((int) hdr->dataSectors[i]));
freeMap->Clear((int) hdr->dataSectors[i]);
}
delete hdr;
}
}

//----------------------------------------------------------------------
// FileHeader::Fet chFrom
// Fetch contents of file header from disk.
//
// "sector" is the disk sector containing the file header
//----------------------------------------------------------------------

void
FileHeader::Fet chFrom(int sector)
{
DEBUG('z', "Reading the sector from FileHeader:%d:\ n", sector);
synchDisk->ReadSector(sec tor, (char *)this);
}

//----------------------------------------------------------------------
// FileHeader::Wri teBack
// Write the modified contents of the file header back to disk.
//
// "sector" is the disk sector to contain the file header
//----------------------------------------------------------------------

void
FileHeader::Wri teBack(int sector)
{
synchDisk->WriteSector(se ctor, (char *)this);
}

//----------------------------------------------------------------------
// FileHeader::Byt eToSector
// Return which disk sector is storing a particular byte within the file.
// This is essentially a translation from a virtual address (the
// offset in the file) to a physical address (the sector where the
// data at the offset is stored).
//
// "offset" is the location within the file of the byte in question
//----------------------------------------------------------------------

int
FileHeader::Byt eToSector(int offset)
{
int SectorNum = offset / SectorSize;

if( SectorNum < NumDirect )
return dataSectors[SectorNum];

else {
FileHeader *hdr = new FileHeader;
hdr->FetchFrom(indi rectHdrSector);
int returnNum = hdr->dataSectors[ SectorNum - NumDirect ];
delete hdr;
return returnNum;

}
//return(dataSect ors[offset / SectorSize]);
}

//----------------------------------------------------------------------
// FileHeader::Fil eLength
// Return the number of bytes in the file.
//----------------------------------------------------------------------

int
FileHeader::Fil eLength()
{
return numBytes;
}

//----------------------------------------------------------------------
// FileHeader::Pri nt
// Print the contents of the file header, and the contents of all
// the data blocks pointed to by the file header.
//----------------------------------------------------------------------

void
FileHeader::Pri nt()
{
int i, j, k;
char *data = new char[SectorSize];

printf("FileHea der contents. File size: %d. File blocks:\n", numBytes);
for (i = 0; i < numSectors; i++)
printf("%d ", dataSectors[i]);
printf("\nFile contents:\n");
for (i = k = 0; i < numSectors; i++) {
synchDisk->ReadSector(dat aSectors[i], data);
for (j = 0; (j < SectorSize) && (k < numBytes); j++, k++) {
if ('\040' <= data[j] && data[j] <= '\176') // isprint(data[j])
printf("%c", data[j]);
else
printf("\\%x", (unsigned char)data[j]);
}
printf("\n");
}
delete [] data;
}

#ifdef CHANGED
void FileHeader::Set FileAttr(int TotBytes, int TotSectors) {
numBytes = TotBytes;
numSectors = TotSectors;
}
#endif

// modified
// filehdr.h
// Data structures for managing a disk file header.
//
// A file header describes where on disk to find the data in a file,
// along with other information about the file (for instance, its
// length, owner, etc.)
//
// Copyright (c) 1992-1993 The Regents of the University of California.
// All rights reserved. See copyright.h for copyright notice and limitation
// of liability and disclaimer of warranty provisions.

#include "copyright. h"

#ifndef FILEHDR_H
#define FILEHDR_H

#include "disk.h"
#include "bitmap.h"

#define NumDirect ((SectorSize - 3 * sizeof(int)) / sizeof(int))
#define MaxFileSize (NumDirect * SectorSize)

// The following class defines the Nachos "file header" (in UNIX terms,
// the "i-node"), describing where on disk to find all of the data in the file.
// The file header is organized as a simple table of pointers to
// data blocks.
//
// The file header data structure can be stored in memory or on disk.
// When it is on disk, it is stored in a single sector -- this means
// that we assume the size of this data structure to be the same
// as one disk sector. Without indirect addressing, this
// limits the maximum file length to just under 4K bytes.
//
// There is no constructor; rather the file header can be initialized
// by allocating blocks for the file (if it is a new file), or by
// reading it from disk.

class FileHeader {
public:
bool Allocate(BitMap *bitMap, int fileSize);// Initialize a file header,
// including allocating space
// on disk for the file data
void Deallocate(BitM ap *bitMap); // De-allocate this file's
// data blocks

void FetchFrom(int sectorNumber); // Initialize file header from disk
void WriteBack(int sectorNumber); // Write modifications to file header
// back to disk

int ByteToSector(in t offset); // Convert a byte offset into the file
// to the disk sector containing
// the byte

int FileLength(); // Return the length of the file
// in bytes

void Print(); // Print the contents of the file.

#ifdef CHANGED
void SetFileAttr(int TotBytes, int TotSectors);
#endif
int dataSectors[NumDirect];
int indirectHdrSect or;

private:
int numBytes; // Number of bytes in the file
int numSectors; // Number of data sectors in the file
// int dataSectors[NumDirect]; // Disk sector numbers for each data
// block in the file
};

#endif // FILEHDR_H

Jul 22 '05 #5
Modify the file system to allow the maximum size of a file to be as
large as the disk (128Kbytes). In the basic file system, each file is
limited to a file size of just under 4Kbytes. Each file has a header
(class FileHeader) that is a table of direct pointers to the disk blocks
for that file. Since the header is stored in one disk sector, the
maximum size of a file is limited by the number of pointers that will
fit in one disk sector. Increasing the limit to 128KBytes will probably
but not necessarily require you to implement double indirect, or
linked-list blocks.

Joseph wrote:
I'm sorry i not too familiar with newgroup etiquotte for programming.
I've attached the files its the total code. I get segmenet fault
anything that is begger than 8K. Again i'm sorry i just didnt want to
fill the whole post with codes.

Karl Heinz Buchegger wrote:
Joseph wrote:
Oh my,
you sure rip my post apart.

Look man.
Nobody here knows what you are working on.
Nobody knows what your class FileHeader should do or
how its internals are structured or what members it has.
Nor do we see the rest of the code to guess what you
don't tell us.

With that background nobody really can help you.
[Scroll down]

-code-
bool
FileHeader::All ocate(BitMap *freeMap, int fileSize)
{
int i;

numBytes = fileSize;
numSectors = divRoundUp(file Size, SectorSize);
if (freeMap->NumClear() < (numSectors+1))
return FALSE; // not enough space

int directSectors = numSectors % NumDirect;

for (i = 0; i < directSectors; i++)
dataSectors[i] = freeMap->Find();

// this section of code supports file size bigger than 8KB but not
// bigger than 12KB need to support upto 128KB
if( (numSectors / NumDirect) > 0 ) {
indirectHdrSect or = freeMap->Find();
FileHeader *hdr = new FileHeader; // here is the pointer i was
// speaking of that which is
// indirect sector meaning
// anything above 4KB is
//indirect sector
for( i = 0; i < (numSectors - directSectors); i++ )
hdr->dataSectors[i] = freeMap->Find();


So, you get a segfault. dataSectors seems to be a fixed size array
in that class. At least I can't see any allocation to a pointer
in that code. The first thing I would check if I were you is if
that array is overflowed.

hdr->WriteBack(indi rectHdrSector);
delete hdr;
}
return TRUE;
}


------------------------------------------------------------------------

// modified
// filehdr.cc
// Routines for managing the disk file header (in UNIX, this
// would be called the i-node).
//
// The file header is used to locate where on disk the
// file's data is stored. We implement this as a fixed size
// table of pointers -- each entry in the table points to the
// disk sector containing that portion of the file data
// (in other words, there are no indirect or doubly indirect
// blocks). The table size is chosen so that the file header
// will be just big enough to fit in one disk sector,
//
// Unlike in a real system, we do not keep track of file permissions,
// ownership, last modification date, etc., in the file header.
//
// A file header can be initialized in two ways:
// for a new file, by modifying the in-memory data structure
// to point to the newly allocated data blocks
// for a file already on disk, by reading the file header from disk
//
// Copyright (c) 1992-1993 The Regents of the University of California.
// All rights reserved. See copyright.h for copyright notice and limitation
// of liability and disclaimer of warranty provisions.

#include "copyright. h"

#include "system.h"
#include "filehdr.h"

//----------------------------------------------------------------------
// FileHeader::All ocate
// Initialize a fresh file header for a newly created file.
// Allocate data blocks for the file out of the map of free disk blocks.
// Return FALSE if there are not enough free blocks to accomodate
// the new file.
//
// "freeMap" is the bit map of free disk sectors
// "fileSize" is the bit map of free disk sectors
//----------------------------------------------------------------------

bool
FileHeader::All ocate(BitMap *freeMap, int fileSize)
{
int i;

numBytes = fileSize;
numSectors = divRoundUp(file Size, SectorSize);
if (freeMap->NumClear() < (numSectors+1))
return FALSE; // not enough space

int directSectors = numSectors % NumDirect;

for (i = 0; i < directSectors; i++)
dataSectors[i] = freeMap->Find();

if( (numSectors / NumDirect) > 0 ) {
indirectHdrSect or = freeMap->Find();
FileHeader *hdr = new FileHeader;
for( i = 0; i < (numSectors - directSectors); i++ )
hdr->dataSectors[i] = freeMap->Find();
hdr->WriteBack(indi rectHdrSector);
delete hdr;
}
return TRUE;
}

//----------------------------------------------------------------------
// FileHeader::Dea llocate
// De-allocate all the space allocated for data blocks for this file.
//
// "freeMap" is the bit map of free disk sectors
//----------------------------------------------------------------------

void
FileHeader::Dea llocate(BitMap *freeMap)
{
int i;

int directSectors = numSectors % NumDirect;

for (i = 0; i < directSectors; i++) {
ASSERT(freeMap->Test((int) dataSectors[i])); // ought to be marked!
freeMap->Clear((int) dataSectors[i]);
}

if( indirectHdrSect or != 0 ) {
FileHeader *hdr = new FileHeader;
hdr->FetchFrom(indi rectHdrSector);

for( i = 0; i < (numSectors - directSectors); i++) {
ASSERT(freeMap->Test((int) hdr->dataSectors[i]));
freeMap->Clear((int) hdr->dataSectors[i]);
}
delete hdr;
}
}

//----------------------------------------------------------------------
// FileHeader::Fet chFrom
// Fetch contents of file header from disk.
//
// "sector" is the disk sector containing the file header
//----------------------------------------------------------------------

void
FileHeader::Fet chFrom(int sector)
{
DEBUG('z', "Reading the sector from FileHeader:%d:\ n", sector);
synchDisk->ReadSector(sec tor, (char *)this);
}

//----------------------------------------------------------------------
// FileHeader::Wri teBack
// Write the modified contents of the file header back to disk.
//
// "sector" is the disk sector to contain the file header
//----------------------------------------------------------------------

void
FileHeader::Wri teBack(int sector)
{
synchDisk->WriteSector(se ctor, (char *)this);
}

//----------------------------------------------------------------------
// FileHeader::Byt eToSector
// Return which disk sector is storing a particular byte within the file.
// This is essentially a translation from a virtual address (the
// offset in the file) to a physical address (the sector where the
// data at the offset is stored).
//
// "offset" is the location within the file of the byte in question
//----------------------------------------------------------------------

int
FileHeader::Byt eToSector(int offset)
{
int SectorNum = offset / SectorSize;

if( SectorNum < NumDirect )
return dataSectors[SectorNum];

else {
FileHeader *hdr = new FileHeader;
hdr->FetchFrom(indi rectHdrSector);
int returnNum = hdr->dataSectors[ SectorNum - NumDirect ];
delete hdr;
return returnNum;

}
//return(dataSect ors[offset / SectorSize]);
}

//----------------------------------------------------------------------
// FileHeader::Fil eLength
// Return the number of bytes in the file.
//----------------------------------------------------------------------

int
FileHeader::Fil eLength()
{
return numBytes;
}

//----------------------------------------------------------------------
// FileHeader::Pri nt
// Print the contents of the file header, and the contents of all
// the data blocks pointed to by the file header.
//----------------------------------------------------------------------

void
FileHeader::Pri nt()
{
int i, j, k;
char *data = new char[SectorSize];

printf("FileHea der contents. File size: %d. File blocks:\n", numBytes);
for (i = 0; i < numSectors; i++)
printf("%d ", dataSectors[i]);
printf("\nFile contents:\n");
for (i = k = 0; i < numSectors; i++) {
synchDisk->ReadSector(dat aSectors[i], data);
for (j = 0; (j < SectorSize) && (k < numBytes); j++, k++) {
if ('\040' <= data[j] && data[j] <= '\176') // isprint(data[j])
printf("%c", data[j]);
else
printf("\\%x", (unsigned char)data[j]);
}
printf("\n");
}
delete [] data;
}

#ifdef CHANGED
void FileHeader::Set FileAttr(int TotBytes, int TotSectors) {
numBytes = TotBytes;
numSectors = TotSectors;
}
#endif
------------------------------------------------------------------------

// modified
// filehdr.h
// Data structures for managing a disk file header.
//
// A file header describes where on disk to find the data in a file,
// along with other information about the file (for instance, its
// length, owner, etc.)
//
// Copyright (c) 1992-1993 The Regents of the University of California.
// All rights reserved. See copyright.h for copyright notice and limitation
// of liability and disclaimer of warranty provisions.

#include "copyright. h"

#ifndef FILEHDR_H
#define FILEHDR_H

#include "disk.h"
#include "bitmap.h"

#define NumDirect ((SectorSize - 3 * sizeof(int)) / sizeof(int))
#define MaxFileSize (NumDirect * SectorSize)

// The following class defines the Nachos "file header" (in UNIX terms,
// the "i-node"), describing where on disk to find all of the data in the file.
// The file header is organized as a simple table of pointers to
// data blocks.
//
// The file header data structure can be stored in memory or on disk.
// When it is on disk, it is stored in a single sector -- this means
// that we assume the size of this data structure to be the same
// as one disk sector. Without indirect addressing, this
// limits the maximum file length to just under 4K bytes.
//
// There is no constructor; rather the file header can be initialized
// by allocating blocks for the file (if it is a new file), or by
// reading it from disk.

class FileHeader {
public:
bool Allocate(BitMap *bitMap, int fileSize);// Initialize a file header,
// including allocating space
// on disk for the file data
void Deallocate(BitM ap *bitMap); // De-allocate this file's
// data blocks

void FetchFrom(int sectorNumber); // Initialize file header from disk
void WriteBack(int sectorNumber); // Write modifications to file header
// back to disk

int ByteToSector(in t offset); // Convert a byte offset into the file
// to the disk sector containing
// the byte

int FileLength(); // Return the length of the file
// in bytes

void Print(); // Print the contents of the file.

#ifdef CHANGED
void SetFileAttr(int TotBytes, int TotSectors);
#endif
int dataSectors[NumDirect];
int indirectHdrSect or;

private:
int numBytes; // Number of bytes in the file
int numSectors; // Number of data sectors in the file
// int dataSectors[NumDirect]; // Disk sector numbers for each data
// block in the file
};

#endif // FILEHDR_H

Jul 22 '05 #6
Joseph wrote:
I'm sorry i not too familiar with newgroup etiquotte for programming.
I just saw another "Welcome to comp.lang.c++" message posted. Read it.
In addition, read http://www.parashift.com/c++-faq-lite/how-to-post.html

After that you should consider starting another thread by posting the way
folks here expect you to. Just a thought...
[..]


V
Jul 22 '05 #7
Joseph wrote:

I'm sorry i not too familiar with newgroup etiquotte for programming.
OK. Now you know.
In an ideal case you shorten the posted code such that:
* it shows the problem you are having
* enables us to cut&paste your code into our devlopment environment
* compile your code
* run it
I've attached the files its the total code. I get segmenet fault
anything that is begger than 8K.


This is by design, as far as I can see.

The thing works as follows:

One FileHeader object contains an array of sector numbers
(where the actual data is stored). That array is fixed size
to 'NumDirect' entries.

The code in Allocate() calculates the needed amount of sectors
end then checks with
if( (numSectors / NumDirect) > 0 ) {
if an additional FileHeader sector is needed.
This check gave me some headaches until I figured it out. Rewriting
it (and thus making it clearer) the above is simply:

if( numSectors > NumDirect ) {
// allocate the indirectHdrSect or and allocate sectors
// for it
}

That's fine. But there is a pitfall: Assume that
NumDirect equals 3 and numSectors equals 8. How many
indirect FileHeaders will you need? Well you need 2 of them,
not only 1! Your code correctly allocates the first 3 sectors
in the FileHeader, but then tries to squeeze the remaing 5
sectors in the indirectHdrSect or, which will not work, since
there is only room for 3 of them. In the end the loop

for( i = 0; i < (numSectors - directSectors); i++ )
hdr->dataSectors[i] = freeMap->Find();

will overflow the array. Didn't you do the test I told you
I would do? It is as easy as:

for( i = 0; i < (numSectors - directSectors); i++ ) {
if( i >= NumDirect ) {
printf( "Something is terribly wrong in Allocate()\n" );
}
hdr->dataSectors[i] = freeMap->Find();
}

And the program would have told you why it crashed!
--
Karl Heinz Buchegger
kb******@gascad .at
Jul 22 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1996
by: pruebauno | last post by:
Hello all, I am having issues compiling Python with large file support. I tried forcing the configure script to add it but then it bombs in the make process. Any help will be appreciated. Information: Architecture: PowerPc on AIX version 5 Compiler:
3
2341
by: A.M-SG | last post by:
Hi, I have a ASP.NET aspx file that needs to pass large images from a network storage to client browser. The requirement is that users cannot have access to the network share. The aspx file must be the only method that users receive image files.
2
1969
by: jdev8080 | last post by:
We are looking at creating large XML files containing binary data (encoded as base64) and passing them to transformers that will parse and transform the data into different formats. Basically, we have images that have associated metadata and we are trying to develop a unified delivery mechanism. Our XML documents may be as large as 1GB and contain up to 100,000 images. My question is, has anyone done anything like this before?
8
2488
by: Bern McCarty | last post by:
We have a large mixed dll that I can never seem to get to link incrementally. Below is the console output. For simplicity I've eliminated some stuff that we normally do when we really link this dll like manifest embedding and strong name delay signing. Can anyone see anything wrong with my link command? Or offer some other explanation why I can never get an incremental link out of it? To test, I'm just touching one of the source files so...
1
6320
by: Lars B | last post by:
Hey guys, I have written a C++ program that passes data from a file to an FPGA board and back again using software and DMA buffers. In my program I need to compare the size of a given file against a software buffer of size 3MB. This is needed so as to see which function to use to read from the file. As the files used range from very large (>30GB) to very small (<3MB), I have enabled large file support and I obtain the file size by using the...
2
3199
by: robert | last post by:
Somebody who uses my app gets a error : os.stat('/path/filename') OSError: Value too large for defined data type: '/path/filename' on a big file >4GB ( Python 2.4.4 / Linux )
1
3897
by: =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post by:
Using .NET 2.0 is it more efficient to copy files to a single folder versus spreading them across multiple folders. For instance if we have 100,000 files to be copied, Do we copy all of them to a single folder called 'All Files' Do we spread them out and copy them to multiple folders like Folder 000 - Copy files from 0 to 1000 Folder 001 - Copy files from 1000 to 2000 Folder 002 - Copy files from 2000 to 2999
4
6514
by: Nagrik | last post by:
Hello Group, I have to support 200 Gigabyte support to open a file in my program. My program exits with open("/mnt/d1/tmp/<file name>", O_RDONLY) = -1 EFBIG (File too large) This open system call is a result of fopen C++ library call, and there is no way I can provide
25
20561
by: tekctrl | last post by:
Anyone: I have a simple MSAccess DB which was created from an old ASCII flatfile. It works fine except for something that just started happening. I'll enter info in a record, save the record, and try to move to another record and get an Access error "Record is too large". The record is only half filled, with many empty fields. If I remove the added data or delete some older data, then it saves ok and works fine again. Whenever I'm...
0
8836
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9575
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9394
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9338
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9256
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6803
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
3322
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2223
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.