//---------------------------------------------------------------------- // // FsClose // // Close an open file. Call the FS-specific routine, and then mark // the file table entry unused. // //---------------------------------------------------------------------- int FsClose (int fd) { int retval; if (!FdValid (fd)) { return (-1); } retval = fs[openfiles[fd].fs].Close (fd); FsFreeEntry (fd); return (retval); }
//---------------------------------------------------------------------- // // FsOpen // // Open a file. The name of the file is passed, along with the file // mode (read or write). // // This function figures out which file system is desired using a // simple heuristic. Basically, if the file starts with "dlx:", it's // a DLX file system file. Otherwise, it's a UNIX file. // // Once the file system is figured out, this routine allocates a // file descriptor and calls the file-system specific open routine. // //---------------------------------------------------------------------- int FsOpen (const char *name, int mode) { int i, retval; dbprintf ('f', "Attepmting to open %s mode=%d.\n", name, mode); /* printf ("Attepmting to open %s mode=%d.\n", name, mode); */ // Mask off all but the mode bits mode &= FS_MODE_RW; // ERROR if the caller hasn't specified a file mode. if (mode == 0) { printf("FsOpen: file mode unspecified!\n"); return (-1); } for (i = 0; i < FS_MAX_OPEN_FILES; i++) { if (openfiles[i].flags == 0) { break; } } if (i >= FS_MAX_OPEN_FILES) { printf("FsOpen: no available open file structures!\n"); return (-1); } openfiles[i].flags = mode; // If file name starts with "dlx:", it's a DLX file system file. Pass // the remainder of the file name to FsDlxOpen. if (!dstrncmp (name, "dlx:", 4)) { name += 4; // Skip past the "dlx:" openfiles[i].fs = 1; } else { openfiles[i].fs = 0; } dbprintf ('f', "File %s opening in file system %d.\n",name,openfiles[i].fs); /* printf ("File %s opening in file system %d.\n",name,openfiles[i].fs); */ retval = fs[openfiles[i].fs].Open (i, name, mode); if (retval < 0) { // Open failed, so return error code printf("FsOpen: failed to open file with Open function pointer\n"); FsFreeEntry (i); return (retval); } dbprintf ('f', "Opened %s in FS %d, mode=%d slot=%d.\n", name, openfiles[i].fs, mode, i); return (i); }