/* * Open function for PFAT filesystems. */ static int PFAT_Open(struct Mount_Point *mountPoint, const char *path, int mode, struct File **pFile) { int rc = 0; struct PFAT_Instance *instance = (struct PFAT_Instance*) mountPoint->fsData; directoryEntry *entry; struct PFAT_File *pfatFile = 0; struct File *file = 0; int i = 0; /* Reject attempts to create or write */ if ((mode & (O_WRITE | O_CREATE)) != 0) return EACCESS; /* Look up the directory entry */ entry = PFAT_Lookup(instance, path); if (entry == 0) return ENOTFOUND; /* Make sure the entry is not a directory. */ if (entry->directory) return EACCESS; /* Get PFAT_File object */ pfatFile = Get_PFAT_File(instance, entry); if (pfatFile == 0) goto done; /* Create the file object. */ file = Allocate_File(&s_pfatFileOps, 0, entry->fileSize, pfatFile, mode, mountPoint); if (file == 0) { rc = ENOMEM; goto done; } /* Success! */ *pFile = file; // Error: I have to fix this to let pfat work with the standard syscalls; if (g_currentThread->userContext != 0) { for(i = 0; i < GOSFS_NUM_DIR_ENTRY; i++) { if(g_currentThread->userContext->fileList[i] == 0) break; } g_currentThread->userContext->fileList[i] = file; rc = i; Debug("gosfs open rc:%d\n", rc); g_currentThread->userContext->fileCount++; } done: return rc; }
/* * If the given PFAT instance has a paging file, * register it as the paging device, unless a paging device * has already been registered. */ static void PFAT_Register_Paging_File(struct Mount_Point *mountPoint, struct PFAT_Instance *instance) { directoryEntry *pagefileEntry; struct Paging_Device *pagedev = 0; size_t nameLen; char *fileName = 0; if (Get_Paging_Device() != 0) return; /* A paging device is already registered */ pagefileEntry = PFAT_Lookup(instance, PAGEFILE_FILENAME); if (pagefileEntry == 0) return; /* No paging file in this filesystem */ /* TODO: verify that paging file is contiguous */ /* Create Paging_Device object. */ pagedev = (struct Paging_Device*) Malloc(sizeof(*pagedev)); if (pagedev == 0) goto memfail; nameLen = strlen(mountPoint->pathPrefix) + strlen(PAGEFILE_FILENAME) + 3; fileName = (char*) Malloc(nameLen); if (fileName == 0) goto memfail; /* Format page filename */ snprintf(fileName, nameLen, "/%s%s", mountPoint->pathPrefix, PAGEFILE_FILENAME); /* Initialize Paging_Device */ pagedev->fileName = fileName; pagedev->dev = mountPoint->dev; pagedev->startSector = pagefileEntry->firstBlock; pagedev->numSectors = pagefileEntry->fileSize / SECTOR_SIZE; /* Register it */ Register_Paging_Device(pagedev); return; memfail: Print(" Error: could not create paging device for pfat on %s (%s)\n", mountPoint->pathPrefix, mountPoint->dev->name); if (pagedev != 0) Free(pagedev); if (fileName != 0) Free(fileName); }
/* * Stat function for PFAT filesystems. */ static int PFAT_Stat(struct Mount_Point *mountPoint, const char *path, struct VFS_File_Stat *stat) { struct PFAT_Instance *instance = (struct PFAT_Instance*) mountPoint->fsData; directoryEntry *entry; KASSERT(path != 0); KASSERT(stat != 0); Debug("PFAT_Stat(%s)\n", path); entry = PFAT_Lookup(instance, path); if (entry == 0) return ENOTFOUND; Copy_Stat(stat, entry); return 0; }
/* * Open function for PFAT filesystems. */ static int PFAT_Open(struct Mount_Point *mountPoint, const char *path, int mode, struct File **pFile) { int rc = 0; struct PFAT_Instance *instance = (struct PFAT_Instance*) mountPoint->fsData; directoryEntry *entry; struct PFAT_File *pfatFile = 0; struct File *file = 0; /* Reject attempts to create or write */ if ((mode & (O_WRITE | O_CREATE)) != 0) return EACCESS; /* Look up the directory entry */ entry = PFAT_Lookup(instance, path); if (entry == 0) return ENOTFOUND; /* Make sure the entry is not a directory. */ if (entry->directory) return EACCESS; /* Get PFAT_File object */ pfatFile = Get_PFAT_File(instance, entry); if (pfatFile == 0) goto done; /* Create the file object. */ file = Allocate_File(&s_pfatFileOps, 0, entry->fileSize, pfatFile, 0, 0); if (file == 0) { rc = ENOMEM; goto done; } /* Success! */ *pFile = file; done: return rc; }