MCPcopy Create free account
hub / github.com/davidgiven/fluxengine / adfOpenFile

Function adfOpenFile

dep/adflib/src/adf_file.c:265–336  ·  view source on GitHub ↗

* adfFileOpen * */

Source from the content-addressed store, hash-verified

263 *
264 */
265struct File* adfOpenFile(struct Volume *vol, char* name, char *mode)
266{
267 struct File *file;
268 SECTNUM nSect;
269 struct bEntryBlock entry, parent;
270 BOOL write;
271 char filename[200];
272
273 write=( strcmp("w",mode)==0 || strcmp("a",mode)==0 );
274
275 if (write && vol->dev->readOnly) {
276 (*adfEnv.wFct)("adfFileOpen : device is mounted 'read only'");
277 return NULL;
278 }
279
280 adfReadEntryBlock(vol, vol->curDirPtr, &parent);
281
282 nSect = adfNameToEntryBlk(vol, parent.hashTable, name, &entry, NULL);
283 if (!write && nSect==-1) {
284 sprintf(filename,"adfFileOpen : file \"%s\" not found.",name);
285 (*adfEnv.wFct)(filename);
286/*fprintf(stdout,"filename %s %d, parent =%d\n",name,strlen(name),vol->curDirPtr);*/
287 return NULL;
288 }
289 if (!write && hasR(entry.access)) {
290 (*adfEnv.wFct)("adfFileOpen : access denied"); return NULL; }
291/* if (entry.secType!=ST_FILE) {
292 (*adfEnv.wFct)("adfFileOpen : not a file"); return NULL; }
293 if (write && (hasE(entry.access)||hasW(entry.access))) {
294 (*adfEnv.wFct)("adfFileOpen : access denied"); return NULL; }
295*/ if (write && nSect!=-1) {
296 (*adfEnv.wFct)("adfFileOpen : file already exists"); return NULL; }
297
298 file = (struct File*)malloc(sizeof(struct File));
299 if (!file) { (*adfEnv.wFct)("adfFileOpen : malloc"); return NULL; }
300 file->fileHdr = (struct bFileHeaderBlock*)malloc(sizeof(struct bFileHeaderBlock));
301 if (!file->fileHdr) {
302 (*adfEnv.wFct)("adfFileOpen : malloc");
303 free(file); return NULL;
304 }
305 file->currentData = malloc(512*sizeof(uint8_t));
306 if (!file->currentData) {
307 (*adfEnv.wFct)("adfFileOpen : malloc");
308 free(file->fileHdr); free(file); return NULL;
309 }
310
311 file->volume = vol;
312 file->pos = 0;
313 file->posInExtBlk = 0;
314 file->posInDataBlk = 0;
315 file->writeMode = write;
316 file->currentExt = NULL;
317 file->nDataBlock = 0;
318
319 if (strcmp("w",mode)==0) {
320 memset(file->fileHdr,0,512);
321 adfCreateFile(vol,vol->curDirPtr,name,file->fileHdr);
322 file->eof = TRUE;

Callers 2

getFileMethod · 0.85
putFileMethod · 0.85

Calls 4

adfReadEntryBlockFunction · 0.85
adfNameToEntryBlkFunction · 0.85
adfCreateFileFunction · 0.85
adfFileSeekFunction · 0.85

Tested by

no test coverage detected