#include <openfile.h>
Public Methods | |
| OpenFile (int sector) | |
| ~OpenFile () | |
| void | Seek (int position) |
| int | Read (char *into, int numBytes) |
| int | Write (char *from, int numBytes) |
| int | ReadAt (char *into, int numBytes, int position) |
| int | WriteAt (char *from, int numBytes, int position) |
| int | Length () |
Private Attributes | |
| FileHeader * | hdr |
| int | seekPosition |
|
|
Definition at line 31 of file openfile.cc. References FileHeader::FetchFrom, hdr, and seekPosition.
00032 {
00033 hdr = new FileHeader;
00034 hdr->FetchFrom(sector);
00035 seekPosition = 0;
00036 }
|
|
|
Definition at line 43 of file openfile.cc. References hdr.
00044 {
00045 delete hdr;
00046 }
|
|
|
Definition at line 195 of file openfile.cc. References FileHeader::FileLength, and hdr.
00196 {
00197 return hdr->FileLength();
00198 }
|
|
||||||||||||
|
Definition at line 76 of file openfile.cc. References ReadAt, and seekPosition. Referenced by FileRead, and Print.
00077 {
00078 int result = ReadAt(into, numBytes, seekPosition);
00079 seekPosition += result;
00080 return result;
00081 }
|
|
||||||||||||||||
|
Definition at line 118 of file openfile.cc. References bcopy, FileHeader::ByteToSector, DEBUG, divRoundDown, FileHeader::FileLength, hdr, and SectorSize. Referenced by AddrSpace::AddrSpace, Directory::FetchFrom, BitMap::FetchFrom, Read, and WriteAt.
00119 {
00120 int fileLength = hdr->FileLength();
00121 int i, firstSector, lastSector, numSectors;
00122 char *buf;
00123
00124 if ((numBytes <= 0) || (position >= fileLength))
00125 return 0; // check request
00126 if ((position + numBytes) > fileLength)
00127 numBytes = fileLength - position;
00128 DEBUG('f', "Reading %d bytes at %d, from file of length %d.\n",
00129 numBytes, position, fileLength);
00130
00131 firstSector = divRoundDown(position, SectorSize);
00132 lastSector = divRoundDown(position + numBytes - 1, SectorSize);
00133 numSectors = 1 + lastSector - firstSector;
00134
00135 // read in all the full and partial sectors that we need
00136 buf = new char[numSectors * SectorSize];
00137 for (i = firstSector; i <= lastSector; i++)
00138 synchDisk->ReadSector(hdr->ByteToSector(i * SectorSize),
00139 &buf[(i - firstSector) * SectorSize]);
00140
00141 // copy the part we want
00142 bcopy(&buf[position - (firstSector * SectorSize)], into, numBytes);
00143 delete [] buf;
00144 return numBytes;
00145 }
|
|
|
Definition at line 57 of file openfile.cc. References seekPosition.
00058 {
00059 seekPosition = position;
00060 }
|
|
||||||||||||
|
Definition at line 84 of file openfile.cc. References seekPosition, and WriteAt. Referenced by Copy, and FileWrite.
00085 {
00086 int result = WriteAt(into, numBytes, seekPosition);
00087 seekPosition += result;
00088 return result;
00089 }
|
|
||||||||||||||||
|
Definition at line 148 of file openfile.cc. References bcopy, FileHeader::ByteToSector, DEBUG, divRoundDown, FileHeader::FileLength, hdr, ReadAt, and SectorSize. Referenced by Write, Directory::WriteBack, and BitMap::WriteBack.
00149 {
00150 int fileLength = hdr->FileLength();
00151 int i, firstSector, lastSector, numSectors;
00152 bool firstAligned, lastAligned;
00153 char *buf;
00154
00155 if ((numBytes <= 0) || (position >= fileLength))
00156 return 0; // check request
00157 if ((position + numBytes) > fileLength)
00158 numBytes = fileLength - position;
00159 DEBUG('f', "Writing %d bytes at %d, from file of length %d.\n",
00160 numBytes, position, fileLength);
00161
00162 firstSector = divRoundDown(position, SectorSize);
00163 lastSector = divRoundDown(position + numBytes - 1, SectorSize);
00164 numSectors = 1 + lastSector - firstSector;
00165
00166 buf = new char[numSectors * SectorSize];
00167
00168 firstAligned = (position == (firstSector * SectorSize));
00169 lastAligned = ((position + numBytes) == ((lastSector + 1) * SectorSize));
00170
00171 // read in first and last sector, if they are to be partially modified
00172 if (!firstAligned)
00173 ReadAt(buf, SectorSize, firstSector * SectorSize);
00174 if (!lastAligned && ((firstSector != lastSector) || firstAligned))
00175 ReadAt(&buf[(lastSector - firstSector) * SectorSize],
00176 SectorSize, lastSector * SectorSize);
00177
00178 // copy in the bytes we want to change
00179 bcopy(from, &buf[position - (firstSector * SectorSize)], numBytes);
00180
00181 // write modified sectors back
00182 for (i = firstSector; i <= lastSector; i++)
00183 synchDisk->WriteSector(hdr->ByteToSector(i * SectorSize),
00184 &buf[(i - firstSector) * SectorSize]);
00185 delete [] buf;
00186 return numBytes;
00187 }
|
|
|
Definition at line 90 of file openfile.h. Referenced by Length, OpenFile, ReadAt, WriteAt, and ~OpenFile. |
|
|
Definition at line 91 of file openfile.h. |
1.2.14 written by Dimitri van Heesch,
© 1997-2002