Page principale | Liste des namespaces | Hiérarchie des classes | Liste des classes | Répertoires | Liste des fichiers | Membres de namespace | Membres de classe | Membres de fichier

filehdr.h

Aller à la documentation de ce fichier.
00001 // filehdr.h 
00002 //      Data structures for managing a disk file header.  
00003 //
00004 //      A file header describes where on disk to find the data in a file,
00005 //      along with other information about the file (for instance, its
00006 //      length, owner, etc.)
00007 //
00008 // Copyright (c) 1992-1993 The Regents of the University of California.
00009 // All rights reserved.  See copyright.h for copyright notice and limitation 
00010 // of liability and disclaimer of warranty provisions.
00011 
00012 #include "copyright.h"
00013 
00014 #ifndef FILEHDR_H
00015 #define FILEHDR_H
00016 
00017 #include "disk.h"
00018 #include "pbitmap.h"
00019 
00020 #define NumDirect       ((SectorSize - 2 * sizeof(int)) / sizeof(int))
00021 #define MaxFileSize     (NumDirect * SectorSize)
00022 
00023 // The following class defines the Nachos "file header" (in UNIX terms,  
00024 // the "i-node"), describing where on disk to find all of the data in the file.
00025 // The file header is organized as a simple table of pointers to
00026 // data blocks. 
00027 //
00028 // The file header data structure can be stored in memory or on disk.
00029 // When it is on disk, it is stored in a single sector -- this means
00030 // that we assume the size of this data structure to be the same
00031 // as one disk sector.  Without indirect addressing, this
00032 // limits the maximum file length to just under 4K bytes.
00033 //
00034 // There is no constructor; rather the file header can be initialized
00035 // by allocating blocks for the file (if it is a new file), or by
00036 // reading it from disk.
00037 
00038 class FileHeader {
00039   public:
00040     bool Allocate(PersistentBitmap *bitMap, int fileSize);// Initialize a file header, 
00041                                                 //  including allocating space 
00042                                                 //  on disk for the file data
00043     void Deallocate(PersistentBitmap *bitMap);  // De-allocate this file's 
00044                                                 //  data blocks
00045 
00046     void FetchFrom(int sectorNumber);   // Initialize file header from disk
00047     void WriteBack(int sectorNumber);   // Write modifications to file header
00048                                         //  back to disk
00049 
00050     int ByteToSector(int offset);       // Convert a byte offset into the file
00051                                         // to the disk sector containing
00052                                         // the byte
00053 
00054     int FileLength();                   // Return the length of the file 
00055                                         // in bytes
00056 
00057     void Print();                       // Print the contents of the file.
00058 
00059   private:
00060     int numBytes;                       // Number of bytes in the file
00061     int numSectors;                     // Number of data sectors in the file
00062     int dataSectors[NumDirect];         // Disk sector numbers for each data 
00063                                         // block in the file
00064 };
00065 
00066 #endif // FILEHDR_H

Généré le Sun Jan 15 00:45:45 2006 pour Système NachOS : par  doxygen 1.4.4