About Opening Files...
Find directory entry
Check permission
“Invalid File Name”, “File Not Defined”, “File Already open”, “Too Many Files Open”, “File Space Full”, …
Create a channel (file slot, handle)
Directory information
Transaction buffer
File status
File pointer
Return a File Descriptor
#pragma pack(push,1) // BYTE align in memory (no padding)
typedef struct
{ unsigned char name[8]; // file name
unsigned char extension[3]; // extension
unsigned char attributes; // file attributes code
unsigned short directoryCluster; // directory cluster
unsigned long fileSize; // file size in bytes
unsigned short startCluster; // first cluster of the file
unsigned short currentCluster; // current cluster in buffer
int pid; // process who opened file
char mode; // access mode (read, read-only, write, append)
char flags; // x80 = file altered
// x40 = sector altered
// x20 = locked
// x10 =
// x08 = write protected
// x04 = contiguous
// x02 =
// x01 =
unsigned long fileIndex; // next character position (from beg of file)
char buffer[BYTES_PER_SECTOR]; // file buffer
} FDEntry;
#pragma pack(pop) // End of strict alignment
typedef struct
{ unsigned char name[8];
unsigned char extension[3];
unsigned char attributes;
unsigned short directoryCluster;
unsigned short startCluster;
unsigned short currentCluster;
unsigned long fileSize;
int pid;
char mode;
char flags;
unsigned long fileIndex;
char buffer[BYTES_PER_SECTOR];
} FDEntry;
dirEntry->name, extension, attributes
cDir
dirEntry.startCluster
0
(mode == 1) ? 0 : dirEntry.fileSize
curTask
mode
o
(mode!=2)?0:dirEntry.fileSize
fdEntry->currentCluster = fdEntry->startCluster;
while ((nextCluster = GetFatEntry(fdEntry->currentCluster)) != FAT_EOC)
fdEntry->currentCluster = nextCluster;
if ((error = fmsReadSector(fdEntry->buffer,
CLUSTER_TO_SECTOR(fdEntry->currentCluster)))) return error;