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

openfile.h

Aller à la documentation de ce fichier.
00001 // openfile.h 
00002 //      Data structures for opening, closing, reading and writing to 
00003 //      individual files.  The operations supported are similar to
00004 //      the UNIX ones -- type 'man open' to the UNIX prompt.
00005 //
00006 //      There are two implementations.  One is a "STUB" that directly
00007 //      turns the file operations into the underlying UNIX operations.
00008 //      (cf. comment in filesys.h).
00009 //
00010 //      The other is the "real" implementation, that turns these
00011 //      operations into read and write disk sector requests. 
00012 //      In this baseline implementation of the file system, we don't 
00013 //      worry about concurrent accesses to the file system
00014 //      by different threads.
00015 //
00016 // Copyright (c) 1992-1993 The Regents of the University of California.
00017 // All rights reserved.  See copyright.h for copyright notice and limitation 
00018 // of liability and disclaimer of warranty provisions.
00019 
00020 #ifndef OPENFILE_H
00021 #define OPENFILE_H
00022 
00023 #include "copyright.h"
00024 #include "utility.h"
00025 #include "sysdep.h"
00026 
00027 #ifdef FILESYS_STUB                     // Temporarily implement calls to 
00028                                         // Nachos file system as calls to UNIX!
00029                                         // See definitions listed under #else
00030 class OpenFile {
00031   public:
00032     OpenFile(int f) { file = f; currentOffset = 0; }    // open the file
00033     ~OpenFile() { Close(file); }                        // close the file
00034 
00035     int ReadAt(char *into, int numBytes, int position) { 
00036                 Lseek(file, position, 0); 
00037                 return ReadPartial(file, into, numBytes); 
00038                 }       
00039     int WriteAt(char *from, int numBytes, int position) { 
00040                 Lseek(file, position, 0); 
00041                 WriteFile(file, from, numBytes); 
00042                 return numBytes;
00043                 }       
00044     int Read(char *into, int numBytes) {
00045                 int numRead = ReadAt(into, numBytes, currentOffset); 
00046                 currentOffset += numRead;
00047                 return numRead;
00048                 }
00049     int Write(char *from, int numBytes) {
00050                 int numWritten = WriteAt(from, numBytes, currentOffset); 
00051                 currentOffset += numWritten;
00052                 return numWritten;
00053                 }
00054 
00055     int Length() { Lseek(file, 0, 2); return Tell(file); }
00056     
00057   private:
00058     int file;
00059     int currentOffset;
00060 };
00061 
00062 #else // FILESYS
00063 class FileHeader;
00064 
00065 class OpenFile {
00066   public:
00067     OpenFile(int sector);               // Open a file whose header is located
00068                                         // at "sector" on the disk
00069     ~OpenFile();                        // Close the file
00070 
00071     void Seek(int position);            // Set the position from which to 
00072                                         // start reading/writing -- UNIX lseek
00073 
00074     int Read(char *into, int numBytes); // Read/write bytes from the file,
00075                                         // starting at the implicit position.
00076                                         // Return the # actually read/written,
00077                                         // and increment position in file.
00078     int Write(char *from, int numBytes);
00079 
00080     int ReadAt(char *into, int numBytes, int position);
00081                                         // Read/write bytes from the file,
00082                                         // bypassing the implicit position.
00083     int WriteAt(char *from, int numBytes, int position);
00084 
00085     int Length();                       // Return the number of bytes in the
00086                                         // file (this interface is simpler 
00087                                         // than the UNIX idiom -- lseek to 
00088                                         // end of file, tell, lseek back 
00089     
00090   private:
00091     FileHeader *hdr;                    // Header for this file 
00092     int seekPosition;                   // Current position within the file
00093 };
00094 
00095 #endif // FILESYS
00096 
00097 #endif // OPENFILE_H

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