static SIMULATED_DIR * simulated_opendir(char *path) { BOOL ok = FALSE; SIMULATED_DIR *result = se_malloc(sizeof(SIMULATED_DIR)); if (result != NULL) { result->lock = NULL; result->info = (struct FileInfoBlock *) AllocDosObject(DOS_FIB, NULL); if (result->info != NULL) { result->lock = Lock(path, ACCESS_READ); if (result->lock != NULL) { ok = (Examine(result->lock, result->info) != DOSFALSE); if (ok) { /* Ensure we are scanning a directory, not a file */ ok = (result->info->fib_DirEntryType >= 0) && (result->info->fib_DirEntryType != ST_SOFTLINK); } } } } if (!ok) { free_simulated_dir(result); result = NULL; } return result; }
static PtrT ReadFileToCustomMemory(const StrT fileName, uint32_t memFlags) { BPTR fh; PtrT data = NULL; PtrT path = AbsPath(fileName); if ((fh = Open(path, MODE_OLDFILE))) { struct FileInfoBlock *infoBlock; if ((infoBlock = (struct FileInfoBlock *) AllocDosObject(DOS_FIB, NULL))) { if (ExamineFH(fh, infoBlock)) { size_t dataLen = infoBlock->fib_Size; if ((data = MemNewCustom(dataLen, memFlags, NULL))) { if (dataLen != Read(fh, data, dataLen)) { MemUnref(data); data = NULL; } } } FreeDosObject(DOS_FIB, infoBlock); } Close(fh); } MemUnref(path); return data; }
VOID ToggleModuleDisabled( BlankerPrefs *Prefs ) { struct FileInfoBlock *Blk; BPTR BlankerLock; BYTE Path[108]; strcpy( Path, Prefs->bp_Dir ); AddPart( Path, Prefs->bp_Blanker, 108 ); if( BlankerLock = Lock( Path, ACCESS_READ )) { if( Blk = AllocDosObject( DOS_FIB, 0L )) { if( Examine( BlankerLock, Blk )) { if( Stricmp( Blk->fib_Comment, "Disabled" )) SetComment( Path, "Disabled" ); else SetComment( Path, "" ); } FreeDosObject( DOS_FIB, Blk ); } UnLock( BlankerLock ); } }
/* Parse a line for a template. Result should be freed via FreeTemplate() */ APTR ParseTemplate(CONST_STRPTR temp, STRPTR line, APTR results) { ULONG *mem = (ULONG*)AllocVec(12,0); if(mem) { struct RDArgs *rdargs = (struct RDArgs*)AllocDosObject(DOS_RDARGS,NULL); if((mem[0] = (ULONG)rdargs)) { LONG len = mystrlen(line)+2; STRPTR buf = (STRPTR)AllocVec(len,0); if((mem[1] = (ULONG)buf)) { struct RDArgs *rd; if (line) strcpy(buf,line); buf[len-2]=10; buf[len-1]=0; rdargs->RDA_Buffer = NULL; rdargs->RDA_Source.CS_Buffer = (UBYTE *)buf; rdargs->RDA_Source.CS_Length = strlen(buf); rdargs->RDA_Source.CS_CurChr = 0; rd = ReadArgs(temp,(LONG*)results, rdargs ); if((mem[2] = (ULONG)rd)) { return mem; } } } } FreeTemplate(mem); return NULL; }
/****************************************************************** * my_isfilehidden * * Hidden is *wrong* here. AmigaOS just knows "Hold"! ******************************************************************/ bool my_isfilehidden (const TCHAR *name) { struct FileInfoBlock *fib=NULL; BPTR lock=NULL; bool result=FALSE; D(bug("[JUAE:A-FSDB] %s('%s')\n", __PRETTY_FUNCTION__, name)); lock=Lock(name, SHARED_LOCK); if(!lock) { bug("[JUAE:A-FSDB] %s: failed to lock entry %s\n", __PRETTY_FUNCTION__, name); goto exit; } if(!(fib=(struct FileInfoBlock *) AllocDosObject(DOS_FIB, NULL)) || !Examine(lock, fib)) { bug("[JUAE:A-FSDB] %s: failed to examine lock @ 0x%p [fib @ 0x%p]\n", __PRETTY_FUNCTION__, lock, fib); goto exit; } if(fib->fib_Protection & FIBF_HOLD) { result=TRUE; } exit: if(lock) UnLock(lock); if(fib) FreeDosObject(DOS_FIB, fib); return result; }
int deleteDir(char *dirname) { char __aligned buffer[2048]; struct ExAllControl *ec; int moreFromExAll, success = TRUE; BPTR lock; if(!(lock = Lock(dirname, ACCESS_READ))) { return 1; } printf("Deleting all files in directory %s\n", dirname); ec = (struct ExAllControl *) AllocDosObject(DOS_EXALLCONTROL, NULL); ec->eac_LastKey=0L; ec->eac_MatchString=NULL; ec->eac_MatchFunc=NULL; do { moreFromExAll = ExAll(lock, (struct ExAllData *)buffer, 2048, ED_TYPE, ec); if(!handleExAllResult(ec, (struct ExAllData *) buffer, dirname)) { success = FALSE; break; } } while(moreFromExAll); UnLock(lock); FreeDosObject(DOS_EXALLCONTROL,ec); if(success) { success = deleteFile(dirname); } return success; }
void my_setfilehidden (const TCHAR *name, bool hidden) { LONG mask; struct FileInfoBlock *fib=NULL; BPTR lock=NULL; D(bug("[JUAE:A-FSDB] %s('%s')\n", __PRETTY_FUNCTION__, name)); lock=Lock(name, SHARED_LOCK); if(!lock) { bug("[JUAE:A-FSDB] %s: failed to lock entry %s\n", __PRETTY_FUNCTION__, name); goto exit; } if(!(fib=(struct FileInfoBlock *) AllocDosObject(DOS_FIB, NULL)) || !Examine(lock, fib)) { bug("[JUAE:A-FSDB] %s: failed to examine lock @ 0x%p [fib @ 0x%p]\n", __PRETTY_FUNCTION__, lock, fib); goto exit; } mask=fib->fib_Protection | FIBF_HOLD; if(!SetProtection(name, mask)) { bug("ERROR: could not set %s to FIBF_HOLD!\n", name); } exit: if(lock) UnLock(lock); if(fib) FreeDosObject(DOS_FIB, fib); return; }
FT_Stream_Open( FT_Stream stream, const char* filepathname ) { // FILE* file; BPTR file; // TetiSoft struct FileInfoBlock* fib; // TetiSoft if ( !stream ) return FT_Err_Invalid_Stream_Handle; // file = fopen( filepathname, "rb" ); file = Open( filepathname, MODE_OLDFILE ); // TetiSoft if ( !file ) { FT_ERROR(( "FT_Stream_Open:" )); FT_ERROR(( " could not open `%s'\n", filepathname )); return FT_Err_Cannot_Open_Resource; } // fseek( file, 0, SEEK_END ); // astream->size = ftell( file ); // fseek( file, 0, SEEK_SET ); fib = AllocDosObject( DOS_FIB, NULL ); if ( !fib ) { Close ( file ); FT_ERROR(( "FT_Stream_Open:" )); FT_ERROR(( " could not open `%s'\n", filepathname )); return FT_Err_Cannot_Open_Resource; } if ( !( ExamineFH( file, fib ) ) ) { FreeDosObject( DOS_FIB, fib ); Close ( file ); FT_ERROR(( "FT_Stream_Open:" )); FT_ERROR(( " could not open `%s'\n", filepathname )); return FT_Err_Cannot_Open_Resource; } stream->size = fib->fib_Size; FreeDosObject( DOS_FIB, fib ); // stream->descriptor.pointer = file; stream->descriptor.pointer = (void *)file; stream->pathname.pointer = (char*)filepathname; stream->pos = 0; stream->read = ft_io_stream; stream->close = ft_close_stream; FT_TRACE1(( "FT_Stream_Open:" )); FT_TRACE1(( " opened `%s' (%d bytes) successfully\n", filepathname, stream->size )); return FT_Err_Ok; }
int stat(const char *name,struct stat *buf) { APTR oldwin,*wptr=&((struct Process *)FindTask(NULL))->pr_WindowPtr; struct FileInfoBlock *fib; BPTR lock; int ret=-1; #ifdef IXPATHS if((name=__amigapath(name))==NULL) return -1; #endif /* avoid possible dos-requesters ;-( */ oldwin=*wptr; *wptr=(APTR)ret; if((lock=Lock((STRPTR)name,SHARED_LOCK))!=0) { if((fib=(struct FileInfoBlock *)AllocDosObject(DOS_FIB,NULL))!=NULL) { if(Examine(lock,fib)!=DOSFALSE) ret=__stat(buf,fib); else __seterrno(); FreeDosObject(DOS_FIB,fib); } else __seterrno(); UnLock(lock); } else __seterrno(); *wptr=oldwin; return ret; }
void ami_menu_arexx_scan(struct gui_window_2 *gwin) { int item = AMI_MENU_AREXX; BPTR lock = 0; UBYTE *buffer; struct ExAllControl *ctrl; char matchpatt[16]; LONG cont; struct ExAllData *ead; char *menu_lab; if(lock = Lock(nsoption_charp(arexx_dir), SHARED_LOCK)) { if(buffer = AllocVecTagList(1024, NULL)) { if(ctrl = AllocDosObject(DOS_EXALLCONTROL,NULL)) { ctrl->eac_LastKey = 0; if(ParsePatternNoCase("#?.nsrx",(char *)&matchpatt,16) != -1) { ctrl->eac_MatchString = (char *)&matchpatt; } do { cont = ExAll(lock,(struct ExAllData *)buffer,1024,ED_COMMENT,ctrl); if((!cont) && (IoErr() != ERROR_NO_MORE_ENTRIES)) break; if(!ctrl->eac_Entries) continue; for(ead = (struct ExAllData *)buffer; ead; ead = ead->ed_Next) { if(item >= AMI_MENU_AREXX_MAX) continue; if(EAD_IS_FILE(ead)) { gwin->menu[item].nm_Type = NM_ITEM; if(ead->ed_Comment[0] != '\0') menu_lab = ead->ed_Comment; else menu_lab = ead->ed_Name; ami_menu_alloc_item(gwin, item, NM_ITEM, menu_lab, 0, NULL, ami_menu_item_arexx_entries, (void *)strdup(ead->ed_Name)); item++; } } }while(cont); FreeDosObject(DOS_EXALLCONTROL,ctrl); } FreeVec(buffer); } UnLock(lock); } gwin->menu[item].nm_Type = NM_END; gwin->menu[item].nm_Label = NULL; }
/****************************************************************** * my_getvolumeinfo (also works for directories on AROS) * * * return FLAGS: * -1: error * MYVOLUMEINFO_READONLY * * all other flags not supported, as they are not used anywhere * ******************************************************************/ int my_getvolumeinfo (const TCHAR *name) { struct FileInfoBlock *fib; BPTR file=NULL; int ret=-1; bug("[JUAE:A-FSDB] %s('%s')\n", __PRETTY_FUNCTION__, name); fib = (struct FileInfoBlock *)AllocDosObject(DOS_FIB, TAG_END); if(!fib) { bug("[JUAE:A-FSDB] %s: failed to allocate FIB\n", __PRETTY_FUNCTION__); goto EXIT; } if(!(file=Lock(name, SHARED_LOCK))) { bug("[JUAE:A-FSDB] %s: failed to lock entry\n", __PRETTY_FUNCTION__); DebOut("no lock..\n"); goto EXIT; } if (!Examine(file, fib)) { bug("[JUAE:A-FSDB] %s: failed to examine\n", __PRETTY_FUNCTION__); goto EXIT; } bug("[JUAE:A-FSDB] %s: fib prot flags 0x%lx\n", __PRETTY_FUNCTION__, fib->fib_Protection); if(fib->fib_DirEntryType >0) { bug("[JUAE:A-FSDB] %s: DIRECTORY!\n", __PRETTY_FUNCTION__); ret=0; } if(!(fib->fib_Protection && FIBF_WRITE)) { bug("[JUAE:A-FSDB] %s: read only entry!\n", __PRETTY_FUNCTION__); ret=MYVOLUMEINFO_READONLY; } EXIT: if(fib) { FreeDosObject(DOS_FIB, fib); } if(file) { UnLock(file); } return ret; }
/****************************************************************** * fsdb_fill_file_attrs * * For an a_inode we have newly created based on a filename we * found on the native fs, fill in information about this * file/directory. * ******************************************************************/ int fsdb_fill_file_attrs (a_inode *base, a_inode *aino) { struct FileInfoBlock *fib=NULL; BPTR lock=NULL; int ret=0; //DebOut("%lx %lx\n", base, aino); //DebOut("aino->dir: %s\n", aino->dir); DebOut("aino->nname: %s\n", aino->nname); fib = (struct FileInfoBlock *)AllocDosObject(DOS_FIB, TAG_END); if(!fib) goto ERROR; lock=Lock(aino->nname, SHARED_LOCK); if(!lock) goto ERROR; if (!Examine(lock, fib)) goto ERROR; if(fib->fib_DirEntryType>0) { //DebOut("=> directory\n"); aino->dir=1; if(fib->fib_DirEntryType==ST_SOFTLINK) { DebOut("WARNING: not tested: SoftLink detected!\n"); aino->softlink=2; /* 1 hardlink, 2 softlink ? */ } } if(fib->fib_Comment) { //DebOut("comment: >%s<\n", fib->fib_Comment); aino->comment=(TCHAR *) strndup((const char *)fib->fib_Comment, 79); /* maximum length is 79 chars, 0 will be added automatically */ } aino->amigaos_mode=fib->fib_Protection; //DebOut("protection: %04x\n", fib->fib_Protection); /* !? */ #if 0 if (reset && (base->volflags & MYVOLUMEINFO_STREAMS)) { create_uaefsdb (aino, fsdb, mode); write_uaefsdb (aino->nname, fsdb); } #endif ret=1; #warning TODO?: care for base and host changes! ERROR: if(fib) FreeDosObject(DOS_FIB, fib); if(lock) UnLock(lock); return ret; }
/** WARNING: mask does *not* work !! */ struct my_opendir_s *my_opendir (const TCHAR *name, const TCHAR *mask) { struct my_opendir_s *mod; TCHAR tmp[MAX_DPATH]; unsigned int len=strlen(name); DebOut("name: %s, mask: %s\n", name, mask); tmp[0] = 0; #if 0 if (currprefs.win32_filesystem_mangle_reserved_names == false) _tcscpy (tmp, PATHPREFIX); _tcscat (tmp, name); DebOut("lastchar: %c\n", name[len-1]); if(! (name[len-1]=='/' || name[len-1]==':')) { _tcscat (tmp, _T("/")); } _tcscat (tmp, mask); DebOut("tmp: %s\n", tmp); #else strcpy(tmp, name); #endif mod = xmalloc (struct my_opendir_s, 1); if(!mod) return NULL; mod->h=(struct FileInfoBlock *) AllocDosObject(DOS_FIB, TAG_END); if(!mod->h) goto ERROR; mod->lock=Lock(tmp, ACCESS_READ); /* TODO: ACCESS_READ or ACCESS_WRITE!? */ if(!mod->lock) { DebOut("unable to lock: %s\n", tmp); goto ERROR; } if(!Examine(mod->lock, mod->h)) { DebOut("Examine failed!\n"); goto ERROR; } if(!(mod->h->fib_DirEntryType > 0 )) { DebOut("%s is NOT a directory!\n", tmp); goto ERROR; } DebOut("ok\n"); return mod; ERROR: my_closedir(mod); return NULL; }
void readUserData(void) { BPTR lock; int goon; char __aligned buffer[2048]; struct ExAllControl *ec; struct ExAllData *ed; printf("Reading user data...\n"); if(!(ec = (struct ExAllControl *)AllocDosObject(DOS_EXALLCONTROL, NULL))) { cleanup(EXIT_ERROR, "Out of memory."); } if(!(lock = Lock("NiKom:Users", ACCESS_READ))) { FreeDosObject(DOS_EXALLCONTROL, ec); cleanup(EXIT_ERROR,"Could not Lock() NiKom:Users\n"); } ec->eac_LastKey = 0L; ec->eac_MatchString = NULL; ec->eac_MatchFunc = NULL; goon = ExAll(lock, (struct ExAllData *)buffer, 2048, ED_NAME, ec); ed = (struct ExAllData *)buffer; for(;;) { if(!ec->eac_Entries) { if(!goon) { break; } goon = ExAll(lock, (struct ExAllData *)buffer, 2048, ED_NAME, ec); ed = (struct ExAllData *)buffer; continue; } if(!scanUserDir(ed->ed_Name)) { UnLock(lock); FreeDosObject(DOS_EXALLCONTROL,ec); cleanup(EXIT_ERROR, "Could not read users."); } ed = ed->ed_Next; if(!ed) { if(!goon) { break; } goon = ExAll(lock,(struct ExAllData *)buffer,2048,ED_NAME,ec); ed = (struct ExAllData *)buffer; } } UnLock(lock); FreeDosObject(DOS_EXALLCONTROL,ec); printf("Read users (Highest id: %d)\n", ((struct ShortUser *)Servermem->user_list.mlh_TailPred)->nummer); printf("User #0 : %s\n",((struct ShortUser *)Servermem->user_list.mlh_Head)->namn); }
int scanUserDir(char *dirname) { BPTR lock; int goon; char __aligned buffer[2048]; struct ExAllControl *ec; struct ExAllData *ed; char path[100]; printf(" Reading user directory %s...\n", dirname); if(!(ec = (struct ExAllControl *)AllocDosObject(DOS_EXALLCONTROL, NULL))) { cleanup(EXIT_ERROR,"Out of memory."); } sprintf(path, "NiKom:Users/%s", dirname); if(!(lock = Lock(path, ACCESS_READ))) { FreeDosObject(DOS_EXALLCONTROL, ec); cleanup(EXIT_ERROR,"Could not Lock() NiKom:Users/x"); } ec->eac_LastKey = 0L; ec->eac_MatchString = NULL; ec->eac_MatchFunc = NULL; goon = ExAll(lock, (struct ExAllData *)buffer, 2048, ED_NAME, ec); ed = (struct ExAllData *)buffer; for(;;) { if(!ec->eac_Entries) { if(!goon) { break; } goon = ExAll(lock, (struct ExAllData *)buffer, 2048, ED_NAME, ec); ed = (struct ExAllData *)buffer; continue; } if(!readSingleUser(atoi(ed->ed_Name))) { UnLock(lock); FreeDosObject(DOS_EXALLCONTROL, ec); return 0; } ed = ed->ed_Next; if(!ed) { if(!goon) { break; } goon = ExAll(lock, (struct ExAllData *)buffer, 2048, ED_NAME, ec); ed = (struct ExAllData *)buffer; } } UnLock(lock); FreeDosObject(DOS_EXALLCONTROL, ec); return 1; }
static inline SIPTR readargs_buff(CONST_STRPTR format, IPTR *args, CONST_STRPTR input, struct RDArgs **retp) { SIPTR retval; struct RDArgs *ret, *in; in = AllocDosObject(DOS_RDARGS, NULL); in->RDA_Source.CS_Buffer = (APTR)input; in->RDA_Source.CS_Length = strlen(input); in->RDA_Source.CS_CurChr = 0; SetIoErr(0); ret = ReadArgs(format, args, in); *retp = ret; retval = (ret != NULL) ? RETURN_OK : IoErr(); return retval; }
long Q_filesize (const char *path) { long size = -1; BPTR fh = Open((const STRPTR) path, MODE_OLDFILE); if (fh) { struct FileInfoBlock *fib = (struct FileInfoBlock*) AllocDosObject(DOS_FIB, NULL); if (fib != NULL) { if (ExamineFH(fh, fib)) size = fib->fib_Size; FreeDosObject(DOS_FIB, fib); } Close(fh); } return size; }
struct List *LoadBlankerEntries( STRPTR Path ) { struct FileInfoBlock *Blk; struct List *Entries = 0L; BlankerEntry *New; BPTR DirLock; if(!( Entries = AllocVec( sizeof( struct List ), MEMF_CLEAR ))) return 0L; else NewList( Entries ); NumBlankEntries = 0; if( DirLock = Lock( Path, ACCESS_READ )) { if(( Blk = AllocDosObject( DOS_FIB, 0L ))&&( Examine( DirLock, Blk ))) { while( ExNext( DirLock, Blk )) { if(( Blk->fib_FileName )&& ( FileIsModule( Path, Blk->fib_FileName ))) { if( New = NewBlankerEntry( Path, Blk->fib_FileName, Blk->fib_Comment )) { New->be_Node.ln_Pri = 128 - ( New->be_Name[0] - 'a' ); Enqueue( Entries, ( struct Node * )New ); NumBlankEntries++; } } } FreeDosObject( DOS_FIB, Blk ); } UnLock( DirLock ); } if( New = NewBlankerEntry( ":", "Random", "" )) AddTail( Entries, ( struct Node * )New ); return Entries; }
/************************************************************************** Returns the size of a file **************************************************************************/ LONG GetFileSize( BPTR fileh ) { struct FileInfoBlock *fib = (struct FileInfoBlock*)AllocDosObject( DOS_FIB, NULL ); LONG size = -1; if (fib) { if (ExamineFH( fileh, fib )) { if ((fib->fib_DirEntryType > 0) && (fib->fib_DirEntryType != ST_SOFTLINK)) { size = 0; } size = fib->fib_Size; } FreeDosObject( DOS_FIB, fib ); } return size; }
/* get file size */ ULONG file_size(BYTE *path) { BPTR file; struct FileInfoBlock *fib; struct Library *dosBase; dosBase = OpenLibrary("dos.library", 40L); if (!dosBase) { printf("Error opening dos.library!\n"); exit(20); } fib = (struct FileInfoBlock *) AllocDosObject(DOS_FIB, TAG_END); if (!fib) { printf("Couldn't allocate dos object!\n"); CloseLibrary(dosBase); exit(20); } if (file = Lock(path, SHARED_LOCK)) { if (Examine(file, fib)) { #ifdef DEBUG printf("DEBUG: Examine() returns file size %lx\n", fib->fib_Size); #endif /* DEBUG */ } else { printf("Couldn't Examine() file!\n"); /* XXX */ } UnLock(file); } else { printf("Couldn't lock file!\n"); exit(20); } FreeDosObject(DOS_FIB, fib); CloseLibrary(dosBase); return fib->fib_Size; }
ULONG FileSize(char *filename) { struct FileInfoBlock *fib; BPTR lock; ULONG size = 0; if((lock = Lock((STRPTR)filename, ACCESS_READ))) { if((fib = AllocDosObject(DOS_FIB, NULL))) { if(Examine(lock, fib)) { size = fib->fib_Size; } FreeDosObject(DOS_FIB, fib); } UnLock(lock); } return size; }
int Q_FileType (const char *path) { int type = FS_ENT_NONE; BPTR fh = Open((const STRPTR) path, MODE_OLDFILE); if (fh) { struct FileInfoBlock *fib = (struct FileInfoBlock*) AllocDosObject(DOS_FIB, NULL); if (fib != NULL) { if (ExamineFH(fh, fib)) { if (fib->fib_DirEntryType >= 0) type = FS_ENT_DIRECTORY; else type = FS_ENT_FILE; } FreeDosObject(DOS_FIB, fib); } Close(fh); } return type; }
/* TODO: 64bit sizes !? */ uae_s64 int my_fsize (struct my_openfile_s *mos) { struct FileInfoBlock * fib=NULL; BPTR lock=NULL; uae_s64 size; if(!(fib=(struct FileInfoBlock *) AllocDosObject(DOS_FIB, NULL)) || !Examine(lock, fib)) { bug("[JUAE:A-FSDB] %s: failed to examine lock @ 0x%p [fib @ 0x%p]\n", __PRETTY_FUNCTION__, lock, fib); size=-1; goto EXIT; } /* test for 64 bit filesize */ if(fib->fib_Size >= 0x7FFFFFFF) { bug("[JUAE:A-FSDB] %s: WARNING: filesize >2GB detected. This has never been tested!\n", __PRETTY_FUNCTION__); UQUAD *size_ptr=(UQUAD *)DoPkt(((struct FileLock *)lock)->fl_Task, ACTION_GET_FILE_SIZE64, (IPTR)lock, 0, 0, 0, 0); if (size_ptr) { size=(uae_s64) *size_ptr; } else { bug("[JUAE:A-FSDB] %s: ERROR: DoPkt return NULL!\n"); size=-1; } goto EXIT; } /* extend 32-bit */ size=(uae_s64) fib->fib_Size; EXIT: DebOut("size: %d\n", size); FreeDosObject(DOS_FIB, fib); return size; }
int main(void) { struct DateTime curr; char day[LEN_DATSTRING]; char time[LEN_DATSTRING]; char date[LEN_DATSTRING]; struct DateStamp stamp; curr.dat_Format = FORMAT_DOS; curr.dat_Flags = 0; curr.dat_StrDay = day; curr.dat_StrDate = date; curr.dat_StrTime = time; DateStamp(&curr.dat_Stamp); DateToStr(&curr); Printf("Current time: %s, %s, %s\n", day, date, time); BPTR fh = Open("__TEST__", MODE_NEWFILE); if (fh != BNULL) { struct FileInfoBlock *fib = AllocDosObject(DOS_FIB, NULL); if (fib != NULL) { if (ExamineFH(fh, fib)) { curr.dat_Stamp = fib->fib_Date; DateToStr(&curr); Printf("File modification time: %s, %s, %s\n", day, date, time); } else PrintFault(IoErr(), "Examine failed"); Printf("Waiting 5 seconds\n"); Delay(5*50); DateStamp(&stamp); Printf("Calling SetFileDate\n"); if(SetFileDate("__TEST__", &stamp)) { if (ExamineFH(fh, fib)) { curr.dat_Stamp = fib->fib_Date; DateToStr(&curr); Printf("New file modification time: %s, %s, %s\n", day, date, time); } else PrintFault(IoErr(), "Examine failed"); } else PrintFault(IoErr(), "SetFileDate"); FreeDosObject(DOS_FIB, fib); } else PrintFault(IoErr(), "Couldn't alloc FileInfoBlock"); Close(fh); DeleteFile("__TEST__"); } else PrintFault(IoErr(), "Couldn't create file"); return 0; }
BOOL FileNameComplete(Object *obj, BOOL backwards, struct InstData *data) { BOOL edited = FALSE; ENTER(); if(data->FNCBuffer != NULL) { if(data->FileEntries == 1) { DisplayBeep(NULL); } else { if(backwards) { if(--data->FileNumber < 0) data->FileNumber = data->FileEntries-1; } else { if(++data->FileNumber >= data->FileEntries) data->FileNumber = 0; } } InsertFileName(data->FileNameStart, data); edited = TRUE; } else { LONG pos = DoMethod(obj, MUIM_BetterString_FileNameStart, data->Contents, data->BufferPos); switch(pos) { case MUIR_BetterString_FileNameStart_Volume: { struct DosList *dl; STRPTR volumeName = NULL; char tmpBuffer[256]; UWORD cut; pos = VolumeStart(data->Contents, data->BufferPos); if((cut = data->BufferPos-pos) != 0) { dl = LockDosList(LDF_READ|LDF_DEVICES|LDF_VOLUMES|LDF_ASSIGNS); while((dl = NextDosEntry(dl, LDF_READ|LDF_DEVICES|LDF_VOLUMES|LDF_ASSIGNS)) != NULL) { #ifdef __AROS__ strlcpy(tmpBuffer, dl->dol_Ext.dol_AROS.dol_DevName, sizeof tmpBuffer); #else // dol_Name is a BSTR, we have to convert it to a regular C string char *bstr = BADDR(dl->dol_Name); // a BSTR cannot exceed 255 characters, hence the buffer size of 256 is enough in any case strlcpy(tmpBuffer, &bstr[1], (unsigned char)bstr[0]); #endif if(Strnicmp(tmpBuffer, data->Contents+pos, cut) == 0) { volumeName = tmpBuffer; break; } } if(volumeName != NULL) { if(OverwriteA(volumeName, pos, cut, strlen(volumeName)+1, data)) data->Contents[data->BufferPos-1] = ':'; edited = TRUE; } UnLockDosList(LDF_READ|LDF_DEVICES|LDF_VOLUMES|LDF_ASSIGNS); } } break; default: { struct FNCData *fncbuffer; struct FNCData *fncframe; struct ExAllControl *control; BPTR dirlock; char pattern[42]; UWORD namestart = data->BufferPos; char oldletter = '\0'; BOOL filename = TRUE; while(filename) { switch(*(data->Contents+namestart-1)) { case '/': case ':': filename = FALSE; break; default: namestart--; break; } } if((data->BufferPos-namestart) < 32) { strlcpy(pattern, data->Contents+namestart, sizeof(pattern)); strlcat(pattern, "~(#?.info)", sizeof(pattern)); oldletter = data->Contents[namestart]; data->Contents[namestart] = '\0'; if((fncbuffer = (struct FNCData *)SharedPoolAlloc(4100)) != NULL) { fncbuffer->next = NULL; if((control = (struct ExAllControl *)AllocDosObject(DOS_EXALLCONTROL, NULL))) { char tokenized[sizeof(pattern) * 2 + 2]; if(ParsePatternNoCase(pattern, tokenized, sizeof(tokenized)) != -1) control->eac_MatchString = tokenized; if((dirlock = Lock(data->Contents+pos, ACCESS_READ))) { UWORD entries = 0; fncframe = fncbuffer; while(fncframe && ExAll(dirlock, &fncframe->buffer, 4096, ED_TYPE, control)) { entries += control->eac_Entries; if((fncframe->next = (struct FNCData *)SharedPoolAlloc(4100))) fncframe->next->next = NULL; fncframe = fncframe->next; } control->eac_Entries += entries; data->FileNumber = backwards ? control->eac_Entries-1 : 0; data->FileEntries = control->eac_Entries; data->FileNameStart = namestart; data->FNCBuffer = fncbuffer; if(control->eac_Entries) { data->Contents[namestart] = oldletter; InsertFileName(namestart, data); edited = TRUE; } UnLock(dirlock); } else { SharedPoolFree(fncbuffer); } FreeDosObject(DOS_EXALLCONTROL, (APTR)control); } } } if(edited == FALSE) data->Contents[namestart] = oldletter; } break; } } RETURN(edited); return edited; }
bool my_stat (const TCHAR *name, struct mystat *statbuf) { struct FileInfoBlock *fib=NULL; BPTR lock=NULL; bool result=FALSE; D(bug("[JUAE:A-FSDB] %s('%s')\n", __PRETTY_FUNCTION__, name)); lock=Lock(name, SHARED_LOCK); if(!lock) { bug("[JUAE:A-FSDB] %s: failed to lock entry %s\n", __PRETTY_FUNCTION__, name); goto exit; } if(!(fib=(struct FileInfoBlock *) AllocDosObject(DOS_FIB, NULL)) || !Examine(lock, fib)) { bug("[JUAE:A-FSDB] %s: failed to examine lock @ 0x%p [fib @ 0x%p]\n", __PRETTY_FUNCTION__, lock, fib); goto exit; } statbuf->size=fib->fib_Size; statbuf->mode=0; if(fib->fib_DiskKey) { D(bug("[JUAE:A-FSDB] %s: %s FILEFLAG_DIR\n", __PRETTY_FUNCTION__, name)); statbuf->mode |= FILEFLAG_DIR; } #ifdef DEBUG { char flags[8]; flags[0] = fib->fib_Protection & FIBF_SCRIPT ? 's' : '-'; flags[1] = fib->fib_Protection & FIBF_PURE ? 'p' : '-'; flags[2] = fib->fib_Protection & FIBF_ARCHIVE ? 'a' : '-'; // Active when unset! flags[3] = fib->fib_Protection & FIBF_READ ? '-' : 'r'; flags[4] = fib->fib_Protection & FIBF_WRITE ? '-' : 'w'; flags[5] = fib->fib_Protection & FIBF_EXECUTE ? '-' : 'e'; flags[6] = fib->fib_Protection & FIBF_DELETE ? '-' : 'd'; flags[7] = 0x00; bug("[JUAE:A-FSDB] %s: %s protection: %s\n", __PRETTY_FUNCTION__, name, flags); } #endif /* fib_Protection: active-low, i.e. not set means active! (who invented this !??) */ if(!(fib->fib_Protection & FIBF_READ)) { statbuf->mode |= FILEFLAG_READ; } if(!(fib->fib_Protection & FIBF_WRITE)) { statbuf->mode |= FILEFLAG_WRITE; } if(!(fib->fib_Protection & FIBF_EXECUTE)) { statbuf->mode |= FILEFLAG_EXECUTE; } /* FIBF_ARCHIVE, FIBF_PURE and FIBF_SCRIPT are active when set */ if(fib->fib_Protection & FIBF_ARCHIVE) { statbuf->mode |= FILEFLAG_ARCHIVE; } if(fib->fib_Protection & FIBF_PURE) { statbuf->mode |= FILEFLAG_PURE; } if(fib->fib_Protection & FIBF_SCRIPT) { statbuf->mode |= FILEFLAG_SCRIPT; } amiga_to_timeval(&statbuf->mtime, fib->fib_Date.ds_Days, fib->fib_Date.ds_Minute, fib->fib_Date.ds_Tick); result=TRUE; exit: if(lock) UnLock(lock); if(fib) FreeDosObject(DOS_FIB, fib); return result; }
LONG SmartReadArgs(struct WBStartup * wb_startup, struct SmartArgs * args) { LONG error; args->sa_Flags = 0; D(bug("UtilityBase = 0x%lx\n", (ULONG) UtilityBase)); D(bug("IconBase = 0x%lx\n", (ULONG) IconBase)); D(bug("WBStartup = 0x%lx\n", (ULONG) wb_startup)); if (wb_startup != NULL) { struct WBArg *wbarg = wb_startup->sm_ArgList; LONG arg_counter = 0; D(bug(" numArgs = %ld\n", wb_startup->sm_NumArgs)); while (arg_counter < wb_startup->sm_NumArgs) { D(bug(" name[%ld] = \"%s\"\n", arg_counter, wbarg->wa_Name)); wbarg += 1; arg_counter += 1; } } if (wb_startup != NULL) { if (!(args->sa_RDArgs = AllocDosObject(DOS_RDARGS, NULL))) { return (ERROR_NO_FREE_STORE); } else { args->sa_Flags |= SAF_ALLOCRDARGS; if (!args->sa_Buffer) { args->sa_BufferSize = MAX(SA_MINIMUM_BUFFER_SIZE, args->sa_BufferSize); args->sa_Buffer = AllocMem(args->sa_BufferSize, MEMF_ANY); args->sa_Flags |= SAF_ALLOCBUFFER; } if (!args->sa_Buffer) return (ERROR_NO_FREE_STORE); else { struct DiskObject *dobj; args->sa_ActualPtr = args->sa_Buffer; args->sa_EndPtr = args->sa_Buffer + args->sa_BufferSize - 1; if (!(dobj = smart_get_icon(args, wb_startup))) { return (ERROR_OBJECT_NOT_FOUND); } else { struct WBArg *wbarg = args->sa_WBArg; ULONG num = args->sa_NumArgs; STRPTR *tooltypes = (STRPTR *) dobj->do_ToolTypes; STRPTR name; STRPTR temp; STRPTR ptr; if (num > 1 && args->sa_FileParameter >= 0 && (temp = AllocMem(TEMPSIZE, MEMF_ANY))) { ULONG modes = 0; get_arg_name(args, temp, TEMPSIZE, &modes); fstrcpy(args, temp); fstrcpy(args, " "); /* no "/M" specifier in the ReadArgs() template, thus use only the first file */ if (modes != MODE_MULTI) num = 2; while (num > 1) { get_wbarg_name(wbarg, temp, TEMPSIZE); fstrcpy(args, "\""); fstrcpy(args, temp); fstrcpy(args, "\" "); num--; wbarg++; } FreeMem(temp, TEMPSIZE); } D(bug("tooltypes=%lx\n", (ULONG) tooltypes)); if (tooltypes) { while (*tooltypes) { ptr = *tooltypes; name = ptr; /* check if this tooltype enabled and part of the * template */ if ((*ptr != '(') && is_in_template(name, args->sa_Template)) { while (*ptr != '=' && *ptr != EOS) ptr++; if (*ptr == '=') { *ptr = EOS; if (!Stricmp(name, "WINDOW")) { STRPTR win; if ((win = AllocVec(strlen(ptr + 1) + 1, MEMF_ANY))) { strcpy(win, ptr + 1); args->sa_Window = win; args->sa_Flags |= SAF_ALLOCWINDOW; } } else { fstrcpy(args, name); /* enclose the argument in "" */ if (*(ptr + 1) == '"') { fstrcpy(args, "="); fstrcpy(args, ptr + 1); } else { fstrcpy(args, "=\""); fstrcpy(args, ptr + 1); fstrcpy(args, "\""); } *ptr = '='; } } else fstrcpy(args, name); fstrcpy(args, " "); } tooltypes++; } /* while (*tooltypes) */ } /* if (tooltypes) */ fstrcpy(args, "\n"); D(bug("final wb command line : \"%s\"\n", args->sa_Buffer)); } } } args->sa_RDArgs->RDA_Source.CS_Buffer = args->sa_Buffer; args->sa_RDArgs->RDA_Source.CS_Length = strlen(args->sa_Buffer); args->sa_Flags |= SAF_WORKBENCH; } args->sa_FreeArgs = ReadArgs(args->sa_Template, args->sa_Parameter, args->sa_RDArgs); if (SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) { SetIoErr(ERROR_BREAK); } if ((error = IoErr()) == 0 && (wb_startup != NULL)) { if (args->sa_Window) { args->sa_WindowFH = Open(args->sa_Window, MODE_NEWFILE); if (args->sa_WindowFH) { args->sa_OldOutput = SelectOutput(args->sa_WindowFH); args->sa_OldInput = SelectInput(args->sa_WindowFH); } } } return (error); }
FT_Stream_Open( FT_Stream stream, const char* filepathname ) { struct FileInfoBlock* fib; struct SysFile* sysfile; if ( !stream ) return FT_THROW( Invalid_Stream_Handle ); #ifdef __amigaos4__ sysfile = AllocMem ( sizeof (struct SysFile ), MEMF_SHARED ); #else sysfile = AllocMem ( sizeof (struct SysFile ), MEMF_PUBLIC ); #endif if ( !sysfile ) { FT_ERROR(( "FT_Stream_Open:" )); FT_ERROR(( " could not open `%s'\n", filepathname )); return FT_THROW( Cannot_Open_Resource ); } sysfile->file = Open( (STRPTR)filepathname, MODE_OLDFILE ); if ( !sysfile->file ) { FreeMem ( sysfile, sizeof ( struct SysFile )); FT_ERROR(( "FT_Stream_Open:" )); FT_ERROR(( " could not open `%s'\n", filepathname )); return FT_THROW( Cannot_Open_Resource ); } fib = AllocDosObject( DOS_FIB, NULL ); if ( !fib ) { Close ( sysfile->file ); FreeMem ( sysfile, sizeof ( struct SysFile )); FT_ERROR(( "FT_Stream_Open:" )); FT_ERROR(( " could not open `%s'\n", filepathname )); return FT_THROW( Cannot_Open_Resource ); } if ( !( ExamineFH( sysfile->file, fib ) ) ) { FreeDosObject( DOS_FIB, fib ); Close ( sysfile->file ); FreeMem ( sysfile, sizeof ( struct SysFile )); FT_ERROR(( "FT_Stream_Open:" )); FT_ERROR(( " could not open `%s'\n", filepathname )); return FT_THROW( Cannot_Open_Resource ); } stream->size = fib->fib_Size; FreeDosObject( DOS_FIB, fib ); stream->descriptor.pointer = (void *)sysfile; stream->pathname.pointer = (char*)filepathname; sysfile->iobuf_start = 0; sysfile->iobuf_end = 0; stream->pos = 0; stream->read = ft_amiga_stream_io; stream->close = ft_amiga_stream_close; if ( !stream->size ) { ft_amiga_stream_close( stream ); FT_ERROR(( "FT_Stream_Open:" )); FT_ERROR(( " opened `%s' but zero-sized\n", filepathname )); return FT_THROW( Cannot_Open_Stream ); } FT_TRACE1(( "FT_Stream_Open:" )); FT_TRACE1(( " opened `%s' (%ld bytes) successfully\n", filepathname, stream->size )); return FT_Err_Ok; }
// Searches for a named buffer and moves to it if found // Called from the LISTER PROCESS (unless LISTER_BFPF_DONT_MOVE is set) DirBuffer *lister_find_buffer( Lister *lister, DirBuffer *start, char *path, struct DateStamp *stamp, char *volume, ULONG flags) { short ret=0; DirBuffer *buffer; char *path_buffer; struct FileInfoBlock *fib; // Got a lister? if (lister) { path_buffer=lister->work_buffer; fib=lister->fib; } // Need to allocate data else { if (!(path_buffer=AllocVec(512,0)) || !(fib=AllocDosObject(DOS_FIB,0))) { FreeVec(path_buffer); return 0; } } // Copy path, terminate correctly strcpy(path_buffer,path); AddPart(path_buffer,"",512); // Lock buffer list if (!(flags&LISTER_BFPF_DONT_LOCK)) lock_listlock(&GUI->buffer_list,FALSE); // Get starting position if (start) buffer=start; else buffer=(DirBuffer *)GUI->buffer_list.list.lh_Head; // Go through all buffers for (;buffer->node.ln_Succ; buffer=(DirBuffer *)buffer->node.ln_Succ) { // Valid path in this directory? if (buffer->flags&DWF_VALID && (flags&LISTER_BFPF_DONT_LOCK || !buffer->buf_CurrentLister || buffer->buf_CurrentLister==lister)) { // Does pathname match? if (stricmp(path_buffer,buffer->buf_Path)==0) { BOOL match=1; // If datestamp is supplied, try that if (stamp) { if (CompareDates(stamp,&buffer->buf_VolumeDate)!=0) match=0; } // Or if a volume name is provided, test that if (volume) { if (stricmp(volume,buffer->buf_VolumeLabel)!=0) match=0; } // Matched? if (match) { BPTR lock; // Do we need to test dates? if (!(flags&LISTER_BFPF_DONT_TEST)) { // Try to lock and examine this directory if (lock=Lock(path_buffer,ACCESS_READ)) { // Examine and unlock Examine(lock,fib); UnLock(lock); // If datestamp on directory has changed, don't go to it if (CompareDates(&fib->fib_Date,&buffer->buf_DirectoryDate)!=0) continue; } else continue; } ret=1; break; } } } } // Did we find one? if (ret) { // Go to buffer if requested if (!(flags&LISTER_BFPF_DONT_MOVE) && lister) { // Show buffer in lister lister_show_buffer(lister,buffer,1,1); // See if buffer needs re-reading lister_check_old_buffer(lister,0); } } else buffer=0; // Was the list locked? if (!(flags&LISTER_BFPF_DONT_LOCK)) { // Allowed to unlock? if (!(flags&LISTER_BFPF_DONT_UNLOCK) || !buffer) // Unlock buffer list unlock_listlock(&GUI->buffer_list); } // Cleanup if (!lister) { FreeVec(path_buffer); FreeDosObject(DOS_FIB,fib); } return buffer; }
/**************************** Function: ReadArgs Vector: 133 Offset: -798 Arguments: D1.L pointer to argument string D2.L pointer to array of longs D3.L pointer to structure RDArgs Returns: D0.L pointer to structure RDArgs ****************************/ int lib_dos_f_ReadArgs(emumsg_syscall_t *msg) { cpu_t *cpu; struct RDArgs *rdargs_real; lib_dos_s_rdargs_t *rdargs; int slen, i; uint8_t *controlStr, *sptr, prevch; uint32_t longdata; uint8_t *argstring; DEBUG(4) dprintf("dos.library: lib_dos_f_ReadArgs() called\n"); cpu = msg->proc->cpu; DEBUG(5) dprintf(" Argument string (D1): 0x%x, Ptr array (D2): 0x%x, Ptr RDArgs (D3): 0x%x\n",cpu->d[1],cpu->d[2],cpu->d[3]); if(cpu->d[3] != 0) { dprintf("Error: dos.library: ReadArgs: Supplying a RDArgs pointer is not supported\n"); return HOOK_END_PROC; } /* TODO: Implement some kind of check for MMU entry ending within the string */ sptr = vptr(cpu->d[1]); if(sptr == NULL) { /* Illegal VADDR */ dprintf("Error: dos.library: ReadArgs: String pointer adress is invalid. Ptr=0x%x\n",cpu->d[1]); return HOOK_END_PROC; } DEBUG(5) dprintf(" Argument string (native): %p\n",sptr); slen = strlen((char *)sptr); if(slen==0) { /* Nothing to do.. */ cpu->d[0]=0; return HOOK_DONE; } controlStr = sptr; /* DEBUG dprintf("Control string: %s\n",controlStr); */ /* TODO: Is AllocDosObject suitable to use from the library process? */ /* Prepare our own RDArgs structure */ rdargs_real = (struct RDArgs *)AllocDosObject(DOS_RDARGS, NULL); if(rdargs_real == NULL) { dprintf("Error: dos.library: ReadArgs: Could not allocate dos object for struct RDArgs\n"); return HOOK_END_PROC; } /* Get mapped structure */ rdargs = lib_dos_s_rdargs_get_real(rdargs_real); if(rdargs == 0) { /* Error */ dprintf("Error: dos.library: ReadArgs: Failed to create RDArgs mapping\n"); FreeDosObject(DOS_RDARGS, rdargs_real); return HOOK_END_PROC; } rdargs->cnt = 1; rdargs->type[rdargs->cnt-1] = LIB_DOS_S_RDARGS_ARGTYPE_STRING; prevch = '\0'; while(*sptr != '\0'){ if(*sptr == ','){ /* New arg */ rdargs->cnt++; if(rdargs->cnt > LIB_DOS_S_RDARGS_ARGS_MAX) { /* Too many */ dprintf("Error: dos.library: ReadArgs: Too many arguments\n"); mmu_delEntry(rdargs->entry); FreeDosObject(DOS_RDARGS, rdargs_real); return HOOK_END_PROC; } rdargs->type[rdargs->cnt-1] = LIB_DOS_S_RDARGS_ARGTYPE_STRING; } if(prevch == '/'){ switch(*sptr) { case 's': case 'S': case 't': case 'T': rdargs->type[rdargs->cnt-1] = LIB_DOS_S_RDARGS_ARGTYPE_BOOLEAN; break; case 'n': case 'N': rdargs->type[rdargs->cnt-1] = LIB_DOS_S_RDARGS_ARGTYPE_INTEGER; break; case 'm': case 'M': rdargs->type[rdargs->cnt-1] = LIB_DOS_S_RDARGS_ARGTYPE_STRINGARRAY; break; default: break; } } prevch = *sptr++; } /* DEBUG for(i=0;i < rdargs->cnt;i++) { dprintf("Arg %d type %d\n",i,rdargs->type[i]); } */ /* Init defaults */ for(i=0;i < rdargs->cnt;i++) { if(READMEM_32(cpu->d[2]+4*i, &longdata)) { /* Read failed */ dprintf("Error: dos.library: ReadArgs: Failed to read initially set values\n"); mmu_delEntry(rdargs->entry); FreeDosObject(DOS_RDARGS, rdargs_real); return HOOK_END_PROC; } rdargs->data[i] = (IPTR)longdata; if(longdata != 0) { if(rdargs->type[i] == LIB_DOS_S_RDARGS_ARGTYPE_STRING || rdargs->type[i] == LIB_DOS_S_RDARGS_ARGTYPE_STRINGARRAY) { /* A string was defined. Set the IPTR to point to the struct. This way we can determine if ReadArgs() has set a new pointer value without having to set up mappings for the original strings. ReadArgs() is not reading the initial strings anyway. */ rdargs->data[i] = (IPTR)rdargs; } } } /* Init RDArgs CSource with our argument string */ argstring = vptr(msg->proc->vaddr_args); rdargs_real->RDA_Source.CS_Buffer = argstring; rdargs_real->RDA_Source.CS_Length = strlen((char *)argstring); rdargs_real->RDA_Source.CS_CurChr = 0; /* Prepare syscall */ msg->arg[0]._strptr = (STRPTR)controlStr; msg->arg[1]._aptr = (APTR)rdargs->data; msg->arg[2]._aptr = (APTR)rdargs_real; /* Remember the rdargs structure */ msg->internalPtr = rdargs; /* Do syscall */ return HOOK_SYSCALL; }