/* Open a regular file as an affile. * Can only be a raw file... */ AFFILE *af_freopen(FILE *file) { if(!aff_initialized) af_initialize(); AFFILE *af = (AFFILE *)calloc(sizeof(AFFILE),1); af->v = &vnode_raw; af->image_sectorsize = 512; // default raw_freopen(af,file); return af; }
/* Open a regular file as an affile */ AFFILE *af_popen(const char *command,const char *type) { if(!aff_initialized) af_initialize(); AFFILE *af = (AFFILE *)calloc(sizeof(AFFILE),1); af->v = &vnode_raw; raw_popen(af,command,type); af->image_sectorsize = 512; // default af->openflags = O_RDONLY; af->fname = strdup(command); return af; }
AFFILE *af_open(const char *filename,int flags,int mode) { if(!aff_initialized) af_initialize(); if(flags & O_WRONLY){ errno = EINVAL; return 0; // this flag not supported } /* Figure out it's format, then hand off to the correct subsystem. */ for(int i = 0; af_vnode_array[i]; i++){ /* Check to see if the implementation identifies the file */ if( (*af_vnode_array[i]->identify)(filename)==1 ){ return af_open_with(filename,flags,mode,af_vnode_array[i]); } } return 0; // can't figure it out. }
AFFILE *af_open(const char *filename,int flags,int mode) { if(!aff_initialized) af_initialize(); if(flags & O_WRONLY){ errno = EINVAL; return 0; // this flag not supported } int exists = (flags & O_CREAT) ? 0 : 1; // file must exist if O_CREAT not specified /* Figure out it's format, then hand off to the correct subsystem. */ for(int i = 0; af_vnode_array[i]; i++){ /* Check to see if the implementation identifies the file */ if( (*af_vnode_array[i]->identify)(filename,exists)==1 ){ AFFILE *af = af_open_with(filename,flags,mode,af_vnode_array[i]); return af; } } errno = EINVAL; if(exists) errno = ENOENT; return 0; // can't figure it out; must be an invalid extension }