/****************************************************************** * 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; }
// Handle a notify message void lister_handle_notify(Lister *lister,DOpusNotify *notify,char *name) { BOOL show=0; // Lock buffer buffer_lock(lister->cur_buffer,TRUE); // Create dir? if (notify->dn_Flags&DNF_DOS_CREATEDIR) { DirEntry *entry; BPTR lock; struct FileInfoBlock __aligned fib; // Lock directory if (lock=Lock(name,ACCESS_READ)) { // Examine it Examine(lock,&fib); UnLock(lock); // Create entry if (entry=create_file_entry( lister->cur_buffer,0, fib.fib_FileName, fib.fib_Size, fib.fib_DirEntryType, &fib.fib_Date, fib.fib_Comment, fib.fib_Protection, 0,0,0,0)) { // Add to buffer add_file_entry(lister->cur_buffer,entry,0); // Save date in buffer (assume this is the latest thing!) lister->cur_buffer->buf_DirectoryDate=fib.fib_Date; // Mark for refresh show=1; } } } // Unlock buffer buffer_unlock(lister->cur_buffer); // Refresh? if (show) lister_refresh_display(lister,REFRESHF_SLIDERS|REFRESHF_STATUS); }
int main(int argc, char *argv[]) { struct FileInfoBlock fib; UBYTE buf[256]; BPTR lock; BOOL ok; ok = GetProgramName(buf, 255); Printf("%08lx %s\n", ok, buf); lock = GetProgramDir(); ok = Examine(lock, &fib); Printf("%08lx %s\n", ok, fib.fib_FileName); return 0; }
static boolean isAmigaDirectory (const char *const name) { boolean result = FALSE; struct FileInfoBlock *const fib = xMalloc (1, struct FileInfoBlock); if (fib != NULL) { const BPTR flock = Lock ((UBYTE *) name, (long) ACCESS_READ); if (flock != (BPTR) NULL) { if (Examine (flock, fib)) result = ((fib->fib_DirEntryType >= 0) ? TRUE : FALSE); UnLock (flock); } eFree (fib); } return result; }
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; }
char *open_dir(const char *dirname) /* open a directory for examination */ { struct Dir *d; if (d = malloc(sizeof(struct Dir))) { strcpy(d->name,dirname); if (!strcmp(d->name,".")) { /* current directory? */ d->name[0] = 0; } if (d->lock = Lock(d->name,ACCESS_READ)) { if (Examine(d->lock,&(d->fib))) { return (char *)d; } UnLock(d->lock); } free(d); } return NULL; }
/* 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; }
void ReadAll(BPTR lock) { struct FileInfoBlock * FIB = AllocVec(sizeof(struct FileInfoBlock), MEMF_CLEAR); BOOL success; int count = 1; success = Examine(lock, FIB); if (FIB->fib_DirEntryType < 0) success = FALSE; if (success) success = ExNext(lock, FIB); while (success) { printf("%s",FIB->fib_FileName); if (FIB->fib_DirEntryType > 0) { printf(" (Dir)\n"); count++; if (count > 1) { char * name = AllocVec(1024,0); BPTR tmplock; NameFromLock(lock,name,1024); AddPart(name,FIB->fib_FileName,1024); printf("Entering %s\n",name); tmplock = Lock(name , ACCESS_READ); ReadAll(tmplock); NameFromLock(lock,name,1024); printf("Returning to %s\n",name); UnLock(tmplock); FreeVec(name); } } else { printf("\n"); } success = ExNext(lock,FIB); } FreeVec(FIB); }
// Copy a file for the build operation BOOL theme_copy_file(char *source,char *dest) { BPTR in,out; D_S(struct FileInfoBlock, fib) BOOL ret=0; // See if source exists if ((in=Lock(source,ACCESS_READ))) { Examine(in,fib); UnLock(in); // Won't try to copy a directory if (fib->fib_DirEntryType>0) return 1; } else return 0; // Open files if ((in=Open(source,MODE_OLDFILE)) && (out=Open(dest,MODE_NEWFILE))) { char *buf; // Allocate buffer if ((buf=AllocVec(8192,0))) { long len; // Copy file while ((len=Read(in,buf,8192))>0) Write(out,buf,len); FreeVec(buf); ret=1; } Close(out); } if (in) Close(in); return ret; }
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; }
char *GetComment(char *filename) { BPTR lk; static struct FileInfoBlock *fib = NULL; if (!filename) { if (fib) FreeMem(fib, sizeof(*fib)); fib = NULL; return NULL; } if (!fib) { if (!(fib = AllocMem(sizeof(*fib), MEMF_PUBLIC))) ziperr(ZE_MEM, "was checking filenotes"); } if (!(lk = Lock(filename, ACCESS_READ))) return NULL; if (!Examine(lk, fib)) fib->fib_Comment[0] = '\0'; UnLock(lk); return fib->fib_Comment[0] ? &fib->fib_Comment[0] : NULL; }
/* 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; }
void createDirOrDie(char *dirname) { BPTR lock; struct FileInfoBlock __aligned fib; if(lock = Lock(dirname, ACCESS_READ)) { if(!Examine(lock, &fib)) { printf("Could not examine %s\n", dirname); UnLock(lock); exit(10); } UnLock(lock); if(fib.fib_DirEntryType <= 0) { printf("Can't create dir %s, there is a file with the same name.\n", dirname); exit(10); } return; } if(!(lock=CreateDir(dirname))) { printf("Couldn't create directory %s\n", dirname); exit(10); } UnLock(lock); printf("Created directory %s\n", dirname); }
LONG GetPath(UBYTE * path, UBYTE * buffer, LONG buffersize) { UBYTE *pathpart, *filepart; UBYTE *tmp1, *tmp2; BPTR lock; struct FileInfoBlock *fib; LONG error = 0; /* * If there seems to be no path, the pathpart will point to the filepart too, so we * need to check for that. */ filepart = FilePart(path); pathpart = PathPart(path); /* * This also handles cases where there is only a volume/device name, only a * directory name or a combo of those. */ if (pathpart == path) { /* * There seems to be only one component. Copy it if it is not wild. Caller will * have to check whether if it exists and if it is a file or directory. */ if (!(ItsWild(pathpart))) pathpart = NULL; } if (pathpart != path) { /* * If pathpart equals filepart (pointer wise) then there is only one component * (possible preceeded by a volume name). */ if (pathpart == filepart) { if (!(ItsWild(pathpart))) pathpart = NULL; } else { /* Try to lock it to determine if the last component is a directory. */ if (lock = Lock(path, SHARED_LOCK)) { if (fib = AllocVec(sizeof(struct FileInfoBlock), MEMF_CLEAR)) { if ((Examine(lock, fib)) == DOSTRUE) { /* Hey it's a directory after all */ if (fib->fib_DirEntryType > 0) pathpart = NULL; } FreeVec(fib); } UnLock(lock); } /* else treat it as a filename */ } /* Copy the pathpart in the buffer */ tmp1 = buffer; tmp2 = path; while ((*tmp1++ = *tmp2++) && (tmp2 != pathpart)) { if (tmp1 == (buffer + buffersize)) { error = ERROR_NO_FREE_STORE; break; } } *tmp1 = '\0'; /* NULL terminate. */ } return (error); }
/* virtual */ OP_STATUS ES_RemoteDebugFrontend::Received(ES_DebugMessage *message) { OpAutoPtr<ES_DebugMessage> anchor(message); ES_DebugMessagePart *part = message->GetFirstPart(); if (part->GetType() == ES_DebugMessagePart::BODY_CONTINUE) { ES_ContinueMessagePart *body = (ES_ContinueMessagePart *) part; return Continue(body->runtime_id, (ES_DebugFrontend::Mode) body->mode); } else if (part->GetType() == ES_DebugMessagePart::BODY_EVAL) { ES_EvalMessagePart *body = (ES_EvalMessagePart *) part; OpString script; RETURN_IF_ERROR(script.SetFromUTF8(body->script, body->script_length)); unsigned variables_count = 0; ES_DebugMessagePart *iter = (ES_DebugMessagePart *) part->Suc(); while (iter) { if (iter->GetType() == ES_DebugMessagePart::AUXILIARY_EVAL_VARIABLE) ++variables_count; iter = (ES_DebugMessagePart *) iter->Suc(); } ES_DebugVariable *variables; if (variables_count != 0) { variables = new ES_DebugVariable[variables_count]; if (variables) { unsigned index = 0; iter = (ES_DebugMessagePart *) part->Suc(); while (iter) { if (iter->GetType() == ES_DebugMessagePart::AUXILIARY_EVAL_VARIABLE) { ES_EvalVariableMessagePart *evalvariable = (ES_EvalVariableMessagePart *) iter; variables[index].name = evalvariable->name; variables[index].name_length = evalvariable->name_length; variables[index].value = evalvariable->value; ++index; } iter = (ES_DebugMessagePart *) iter->Suc(); } } else variables_count = 0; } else variables = NULL; OP_STATUS status = Eval(body->tag, body->runtime_id, body->thread_id, body->frame_index, script.CStr(), script.Length(), variables, variables_count); delete[] variables; if (status == OpStatus::ERR) { ES_DebugValue value; return EvalReply(body->tag, EVAL_STATUS_ABORTED, value); } else return status; } else if (part->GetType() == ES_DebugMessagePart::BODY_EXAMINE) { ES_ExamineMessagePart *body = (ES_ExamineMessagePart *) part; return Examine(body->tag, body->runtime_id, body->in_scope, body->thread_id, body->frame_index, body->objects_count, body->object_ids); } else if (part->GetType() == ES_DebugMessagePart::BODY_BACKTRACE) { ES_BacktraceMessagePart *body = (ES_BacktraceMessagePart *) part; return Backtrace(body->tag, body->runtime_id, body->thread_id, body->max_frames); } else if (part->GetType() == ES_DebugMessagePart::BODY_ADD_BREAKPOINT || part->GetType() == ES_DebugMessagePart::BODY_REMOVE_BREAKPOINT) { ES_ChangeBreakpointMessagePart *body = (ES_ChangeBreakpointMessagePart *) part; if (body->add) return AddBreakpoint(body->id, body->bpdata); else return RemoveBreakpoint(body->id); } else if (part->GetType() == ES_DebugMessagePart::BODY_SET_CONFIGURATION) { ES_SetConfigurationMessagePart *body = (ES_SetConfigurationMessagePart *) part; return SetStopAt(body->stop_at_script, body->stop_at_exception, body->stop_at_error, body->stop_at_abort, body->stop_at_gc); } else if (part->GetType() == ES_DebugMessagePart::BODY_BREAK) { ES_BreakMessagePart *body = (ES_BreakMessagePart *) part; return Break(body->runtime_id, body->thread_id); } OP_ASSERT(FALSE); return OpStatus::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; }
// Update the datestamp for a buffered directory // Called from LISTER PROCESS void update_buffer_stamp(Lister *lister) { BPTR lock; struct FileInfoBlock __aligned info; char path[512]; /* DirBuffer *buffer=0; */ #ifdef DEBUG if (lister) check_call("update_buffer_stamp",lister); #endif // Invalid window? if (!lister) return; // Get current path and disk stamp strcpy(path,lister->cur_buffer->buf_Path); // Lock the path if (lock=Lock(path,ACCESS_READ)) { // Examine and unlock Examine(lock,&info); UnLock(lock); // Store new stamp lister->cur_buffer->buf_DirectoryDate=info.fib_Date; } /* // Couldn't lock, use zero datestamp else { info.fib_Date.ds_Days=0; info.fib_Date.ds_Minute=0; info.fib_Date.ds_Tick=0; } // Lock buffer list lock_listlock(&GUI->buffer_list,TRUE); // Find all instances of this path while (buffer= (lister_find_buffer( lister, buffer, path, &lister->cur_buffer->buf_VolumeDate, 0, LISTER_BFPF_DONT_MOVE|LISTER_BFPF_DONT_LOCK|LISTER_BFPF_DONT_TEST))) { // Not the original buffer? if (buffer!=lister->cur_buffer) { // If buffer is locked, tell its lister to get this copy if (buffer->buf_CurrentLister) { IPC_Command( buffer->buf_CurrentLister->ipc, LISTER_COPY_BUFFER, 0, lister->cur_buffer, 0, 0); } // Otherwise, copy into the buffer else { buffer_copy(lister->cur_buffer,buffer,0); } } // Get next buffer=(DirBuffer *)buffer->node.ln_Succ; } // While there's parents to look for while (path_parent(path)) { // Initialise buffer=0; lock=0; // Look for all parents while (buffer= (lister_find_buffer( lister, buffer, path, &lister->cur_buffer->buf_VolumeDate, 0, LISTER_BFPF_DONT_MOVE|LISTER_BFPF_DONT_LOCK|LISTER_BFPF_DONT_TEST))) { // Need to get date? if (!lock) { // Lock the path if (!(lock=Lock(path,ACCESS_READ))) break; // Examine and unlock Examine(lock,&info); UnLock(lock); } // Store datestamp buffer->buf_DirectoryDate=info.fib_Date; // Get next buffer=(DirBuffer *)buffer->node.ln_Succ; } } // Unlock buffer list unlock_listlock(&GUI->buffer_list); */ }
// Display a buffer in a lister // Called from LISTER PROCESS void lister_show_buffer(Lister *lister,DirBuffer *buffer,int show,BOOL active) { // Different to current buffer? if (lister->cur_buffer!=buffer) { // End a direct edit lister_end_edit(lister,0); // Clear lock pointer in current buffer buffer_clear_lock(lister->cur_buffer,0); // Free icons backdrop_free_list(lister->backdrop_info); // Store new buffer pointer lister->cur_buffer=buffer; buffer->buf_CurrentLister=lister; // Remove buffer and add to head of list Remove(&buffer->node); AddHead(&GUI->buffer_list.list,&buffer->node); // See if buffer needs to be resorted lister_resort(lister,0); // Clear save status flag lister->flags&=~LISTERF_SAVE_STATUS; // Does new buffer have a custom handler? if (lister->cur_buffer->buf_CustomHandler[0] && active) { // Send active message buffer_active(lister->cur_buffer,0); } // Add to history list lister_add_history(lister); } // Initialise path field if (show && lister_valid_window(lister)) { // Is volume present? if (!lister->cur_buffer->buf_CustomHandler[0] && VolumePresent(buffer)) { BPTR lock; struct FileInfoBlock __aligned fib; // Lock path if (lock=Lock(buffer->buf_Path,ACCESS_READ)) { // Store full path NameFromLock(lock,buffer->buf_ExpandedPath,512); AddPart(buffer->buf_ExpandedPath,"",512); // Examine object Examine(lock,&fib); UnLock(lock); // Save object name if (fib.fib_FileName[0]) strcpy(buffer->buf_ObjectName,fib.fib_FileName); else { if (buffer->flags&DWF_ROOT) { char *ptr; stccpy(buffer->buf_ObjectName,buffer->buf_ExpandedPath,GUI->def_filename_length-1); if (ptr=strchr(buffer->buf_ObjectName,':')) *ptr=0; } else stccpy(buffer->buf_ObjectName,FilePart(buffer->buf_ExpandedPath),GUI->def_filename_length-1); } } // Failed to lock else strcpy(buffer->buf_ExpandedPath,buffer->buf_Path); // Update disk name and size lister_update_name(lister); } // No, refresh disk name from buffer else lister_show_name(lister); // Not showing icons? if (!(lister->flags&LISTERF_VIEW_ICONS) || lister->flags&LISTERF_ICON_ACTION) { // Update path field lister_update_pathfield(lister); // Refresh window lister_refresh_display(lister,REFRESHF_SLIDERS|REFRESHF_STATUS|REFRESHF_CLEAR_ICONS); // Show selection information select_show_info(lister,1); } } }
int fs64_mediatype (uchar *path) { /* find out the media type for the path media_BAD will be returned if the path is bad and media_NOTFS if the path points to a file which is not a file system If the end of the path is a subdirectory then it will be media_UFS If the end of the path is a .D64 it will be media_D64 If the end of the path is a .T64 it will be media_T64 */ /* BUGS: This routine should parse through each slash seperately, as at present a subdirectory in a disk image, or a subdirectory itself for that matter, ending in .D64 or .T64 will mistakenly be recognuised as a disk/tape image */ #ifdef AMIGA BPTR filelock; struct FileInfoBlock myFIB; #else struct stat buf; #endif int n; uchar temp[1024]; /* get file info */ /* BUGS: The following is *very* kludgy! */ if (path[0] == '@') { /* @ sounds like a good way to start the internet file system :) */ return (media_NET); } #ifdef AMIGA if ((filelock = Lock (path, ACCESS_READ)) != 0) { if (!Examine (filelock, &myFIB)) { UnLock (filelock); /* try stripping the / off the end */ if (path[strlen (path) - 1] == '/') { strcpy (temp, path); temp[strlen (path) - 1] = 0; return (fs64_mediatype (temp)); } else /* no go */ return (media_BAD); /* file/path not found */ } } #else if (stat ((char*)path, &buf)) { /* try stripping the / off the end */ if (path[strlen (path) - 1] == '/') { strcpy ((char*)temp, (char*)path); temp[strlen (path) - 1] = 0; return (fs64_mediatype (temp)); } else /* no go */ return (media_BAD); /* file/path not found */ } #endif /* Check for file types now */ /* Check for media_UFS */ #ifdef AMIGA if (myFIB.fib_DirEntryType > 0) { UnLock (filelock); return (media_UFS); /* dir = unix filesystem */ } #else if (buf.st_mode & S_IFDIR) return (media_UFS); /* dir = unix filesystem */ #endif n = strlen (path); if ((path[n - 4] == '.') && (toupper (path[n - 3]) == 'D') && (path[n - 2] == '7') && (path[n - 1] == '1')) return (media_D71); if ((path[n - 4] == '.') && (toupper (path[n - 3]) == 'D') && (path[n - 2] == '8') && (path[n - 1] == '1')) return (media_D81); if ((path[n - 4] == '.') && (toupper (path[n - 3]) == 'D') && (toupper (path[n - 2]) == 'H') && (toupper (path[n - 1]) == 'D')) return (media_DHD); if ((path[n - 4] == '.') && (path[n - 2] == '6') && (path[n - 1] == '4')) { /* the end of the filename is '.?64' */ /* this routine doesnt seem to check for .N64s, and yet N64's can still be accessed .. hmmm */ /* Check for .D64 */ if ((path[n - 3] == 'd') || (path[n - 3] == 'D')) { /* its a D64 file! */ return (media_D64); } if ((path[n - 3] == 't') || (path[n - 3] == 'T')) { /* Its a T64 file! */ return (media_T64); } /* it matches no known archive type - so its a media_NOTFS */ return (media_NOTFS); } if ((path[n - 4] == '.') && (toupper (path[n - 3]) == 'L') && (toupper (path[n - 2]) == 'N') && (toupper (path[n - 1]) == 'X')) { /* .LNX file */ return (media_LNX); } /* no match */ /* default = unix's native FS */ return (media_UFS); }
int main (void) { IPTR args[ARG_NUM] = { (IPTR) NULL, (IPTR) NULL, (IPTR) NULL, FALSE, FALSE}; struct RDArgs *rda; ULONG error = 0; locale = OpenLocale(NULL); if (!locale) { PutStr("Could not open locale!\n"); return -1; } rda = ReadArgs(TEMPLATE, args, NULL); if (rda) { BPTR lock_in; lock_in = Lock((STRPTR)args[ARG_FROM], ACCESS_READ); if (lock_in) { BPTR file_out = Open((STRPTR)args[ARG_TO], MODE_NEWFILE); if (NULL != file_out) { struct FileInfoBlock fib; UBYTE * data = NULL; BOOL success = Examine(lock_in, &fib); /* ** Read the input file into memory */ if (fib.fib_Size && DOSTRUE == success) data = AllocVec(fib.fib_Size, MEMF_ANY); if (data) { ULONG read = Read(lock_in, data, fib.fib_Size); if (-1 != read) { struct sorted_data * sd; sd = sort(data, fib.fib_Size, (STRPTR)args[ARG_COLSTART], (BOOL)args[ARG_CASE], (BOOL)args[ARG_NUMERIC]); error = write_data(sd, file_out); } FreeVec(data); }/* if (data) */ Close(file_out); } /* if (file_out) */ UnLock(lock_in); } /* if (lock_in) */ FreeArgs(rda); } else error=RETURN_FAIL; if (error) PrintFault(IoErr(), "Sort"); return error; }
int __stat_from_path(const char *path, struct stat *sb) { int len; char *mypath; int cwdsize = FILENAME_MAX; char *cwd = NULL; char *abspath = NULL; char *filepart = NULL; char *split; struct FileInfoBlock *fib = NULL; BPTR lock = BNULL; BPTR cwdlock; int fallback_to_defaults = 0; BOOL loop; int res = -1; /* copy path and strip trailing slash */ len = strlen(path); if (!(mypath = AllocVec(len + 1, MEMF_ANY))) { errno = ENOMEM; goto out; } strcpy(mypath, path); if (len && mypath[len-1] == '/') mypath[len-1] = '\0'; /* do we have an absolute path */ if (!strchr(mypath, ':')) { /* no, then create one */ cwdlock = CurrentDir(BNULL); CurrentDir(cwdlock); do { if (!(cwd = AllocVec(cwdsize, MEMF_ANY))) { errno = ENOMEM; goto out; } if (NameFromLock(cwdlock, cwd, cwdsize)) break; else if (IoErr() != ERROR_LINE_TOO_LONG) { errno = __stdc_ioerr2errno(IoErr()); goto out; } FreeVec(cwd); cwdsize *= 2; } while (TRUE); /* get memory for current dir + '/' + input path + zero byte */ len = strlen(cwd) + 1 + len + 1; abspath = AllocVec(len, MEMF_ANY); if (!abspath) { errno = ENOMEM; goto out; } strcpy(abspath, cwd); AddPart(abspath, mypath, len); FreeVec(mypath); } else abspath = mypath; /* split into path part and file part */ split = FilePart(abspath); filepart = AllocVec(strlen(split) + 1, MEMF_ANY); if (!filepart) { errno = ENOMEM; goto out; } strcpy(filepart, split); *split = '\0'; if ( !(fib = AllocDosObject(DOS_FIB, NULL)) || !(lock = Lock(abspath, SHARED_LOCK))) { errno = __stdc_ioerr2errno(IoErr()); goto out; } /* examine parent directory of object to stat */ if (!Examine(lock, fib)) { if (IoErr() == ERROR_NOT_IMPLEMENTED || IoErr() == ERROR_ACTION_NOT_KNOWN) fallback_to_defaults = 1; else { errno = __stdc_ioerr2errno(IoErr()); goto out; } } if (*filepart == '\0' || fallback_to_defaults) __fill_statbuffer(sb, abspath, fib, fallback_to_defaults, lock); else /* examine entries of parent directory until we find the object to stat */ do { loop = ExNext(lock, fib); if (loop) { if (stricmp(fib->fib_FileName, filepart) == 0) { __fill_statbuffer(sb, abspath, fib, 0, lock); res = 0; break; } continue; } if (IoErr() != ERROR_NO_MORE_ENTRIES) errno = __stdc_ioerr2errno(IoErr()); else /* nothing found to stat */ errno = ENOENT; } while (loop); out: if (lock) UnLock(lock); FreeVec(cwd); /* if we had absolute path as input, mypath is free'd here */ FreeVec(abspath); FreeVec(filepart); if (fib) FreeDosObject(DOS_FIB, fib); return res; }
int access ( /* SYNOPSIS */ const char *path, int mode) /* FUNCTION Check access permissions of a file or pathname INPUTS path - the path of the file being checked mode - the bitwise inclusive OR of the access permissions to be checked: W_OK - for write permission R_OK - for readpermissions X_OK - for execute permission F_OK - Just to see whether the file exists RESULT If path cannot be found or if any of the desired access modes would not be granted, then a -1 value is returned; otherwise a 0 value is returned. NOTES EXAMPLE BUGS SEE ALSO open(), ftruncate() INTERNALS ******************************************************************************/ { BPTR lock = NULL; struct FileInfoBlock *fib = NULL; int result = -1; char vol[32]; struct DosList *dl = NULL; if (!path) /* safety check */ { errno = EFAULT; return -1; } if (!strlen(path)) /* empty path */ { errno = ENOENT; return -1; } /* Check if the volume exists. Calling Lock on non-existing volume will bring up System Requester */ if (SplitName(__path_u2a(path), ':', vol, 0, sizeof(vol)-1) != -1) { if(strcmp(vol, "PROGDIR") != 0) { dl = LockDosList(LDF_ALL | LDF_READ); dl = FindDosEntry(dl, vol, LDF_ALL); UnLockDosList(LDF_ALL | LDF_READ); /* Volume / Assign / Device not found */ if (dl == NULL) { errno = ENOENT; return -1; } } } /* Create a lock and examine a lock */ lock = Lock(__path_u2a(path), SHARED_LOCK); if (lock == NULL) { errno = IoErr2errno(IoErr()); return -1; } fib = AllocDosObject(DOS_FIB, NULL); if (!fib) { errno = IoErr2errno(IoErr()); UnLock(lock); return -1; } if (Examine(lock, fib)) { /* Notice : protection flags are 'low-active' (0 means access is granted) */ result = 0; if ((mode & R_OK) && (result == 0) && (fib->fib_Protection & (1 << FIBB_READ))) { errno = EACCES; result = -1; } if ((mode & W_OK) && (result == 0) && (fib->fib_Protection & (1 << FIBB_WRITE))) { errno = EACCES; result = -1; } if ((mode & X_OK) && (result == 0) && (fib->fib_Protection & (1 << FIBB_EXECUTE))) { errno = EACCES; result = -1; } } else { errno = EBADF; result = -1; } FreeDosObject(DOS_FIB, fib); fib = NULL; UnLock(lock); return result; }
// Read program groups (icon list must be locked) void backdrop_read_groups(BackdropInfo *info) { BPTR lock; struct FileInfoBlock __aligned fib; struct AnchorPath *anchor; short error; // Allocate anchor if (!(anchor=AllocVec(sizeof(struct AnchorPath)+256,MEMF_CLEAR))) return; // Initialise anchor anchor->ap_Strlen=256; // Search for icons error=MatchFirst("dopus5:groups/#?.info",anchor); // Continue while there's files while (!error) { char *ptr; // Strip .info suffix if (ptr=sufcmp(anchor->ap_Buf,".info")) *ptr=0; // See if directory exists to go with it if (lock=Lock(anchor->ap_Buf,ACCESS_READ)) { // Examine file Examine(lock,&fib); UnLock(lock); // Is it a directory? if (fib.fib_DirEntryType>0) { BackdropObject *object; struct List *search; // Lock icon list lock_listlock(&info->objects,FALSE); // See if group already exists search=&info->objects.list; while (object=(BackdropObject *)FindNameI(search,fib.fib_FileName)) { // Is it a group? if (object->type==BDO_GROUP) break; // Continue search search=(struct List *)object; } // Unlock icon list unlock_listlock(&info->objects); // Didn't have it already? if (!object) { // Create a new icon for this if (object=backdrop_leftout_new(info,anchor->ap_Buf,0,0)) { // Change type to group object->type=BDO_GROUP; // Get icon backdrop_get_icon(info,object,GETICON_CD); } } } } // Get next entry error=MatchNext(anchor); } // Clean up MatchEnd(anchor); FreeVec(anchor); }
//*********************************************************************** //* Procedure: full_path //* Synopsis: path = full_path(name) //* Purpose: Constructs a fully expanded filename //* Note, we can not assume that the file exists, so it will //* not be possible to actually lock it. We can assume that //* the directory it is part of does exist. Note that it can //* return NULL if there is no memory available. //*********************************************************************** char *full_path(char *name) { BPTR lock; __aligned struct FileInfoBlock fib; char *tail, *p; int pos; // // Step 1 - split out any directory information from the actual name // p = strrchr(name, '/'); if (p == NULL) p = strrchr(name, ':'); if (p != NULL) { // // There was some directory information involved // char c; tail = strdup(p+1); c = p[1]; p[1] = 0; lock = Lock(name, SHARED_LOCK); p[1] = c; } else { // // No directory information involved, just the name relative to the // current directory // lock = Lock("", SHARED_LOCK); tail = strdup(name); } // // Step 2 - we have the lock on the directory and the tail part of the name // We want to construct a fully qualified path for the directory. // If for some reason the lock on the directory returned 0, we want to just // return the name they gave us to begin with. // if (lock == 0) { free(tail); return(strdup(name)); } // // Step 3 - Fully qualify the directory portion into the buffer // if (DOSBase->dl_lib.lib_Version >= 36) { if (!NameFromLock(lock, buf, MAX_FILENAME)) { // // Either the name is too long or there was something else wrong with // the file name, just return what they gave us as a start // UnLock(lock); free(tail); return(strdup(name)); } UnLock(lock); pos = 0; } else { // Running under 1.3, we have to do this the old fashion way // // Just so we don't have to do any inserts/extra copies, we will work // from the end of the buffer and insert as we go // pos = MAX_FILENAME-1; // Leave room for a '/' on the end sometimes buf[--pos] = 0; while(lock != 0) { BPTR parent; int len; // // Examine the lock to get the name for it // Examine(lock, &fib); // // Find the parent of this directory // parent = ParentDir(lock); UnLock(lock); lock = parent; len = strlen(fib.fib_FileName); pos -= 1; if (len > pos) { // // oops, not enough room, just return the name they gave us // UnLock(lock); free(tail); return(strdup(name)); } buf[pos] = lock ? ':' : '/'; pos -= len; memcpy(buf+pos, fib.fib_FileName, len); } } // // We have the path part in the buffer and the name part in the tail // All that is left is to concatenate them together correctly // { int len; // // Successful, the buf holds the path for the directory. We will need // to add a / to the end if it doesn't end in a colon // len = strlen(buf+pos); if ((buf[pos+len-1] != ':') && (buf[pos+len-1] != '/')) { buf[pos+len++] = '/'; buf[pos+len] = 0; } name = malloc(len+strlen(tail)+1); if (name != NULL) { strcpy(name, buf+pos); strcpy(name+len, tail); } } return(name); }
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; }
int __stat(BPTR lock, struct stat *sb, BOOL filehandle) { struct FileInfoBlock *fib; UBYTE *buffer; int buffersize = 256; int fallback_to_defaults = 0; BOOL Examined; fib = AllocDosObject(DOS_FIB, NULL); if (!fib) { errno = __stdc_ioerr2errno(IoErr()); return -1; } Examined = filehandle ? ExamineFH(lock, fib) : Examine(lock, fib); if (!Examined) { if(IoErr() == ERROR_NOT_IMPLEMENTED || IoErr() == ERROR_ACTION_NOT_KNOWN) { fallback_to_defaults = 1; } else { errno = __stdc_ioerr2errno(IoErr()); FreeDosObject(DOS_FIB, fib); return -1; } } /* Get the full path of the stated filesystem object and use it to compute hash value */ do { BOOL GotName; if(!(buffer = AllocVec(buffersize, MEMF_ANY))) { errno = ENOMEM; FreeDosObject(DOS_FIB, fib); return -1; } GotName = filehandle ? NameFromFH(lock, buffer, buffersize) : NameFromLock(lock, buffer, buffersize); if(GotName) break; else if( IoErr() == ERROR_OBJECT_IN_USE || IoErr() == ERROR_NOT_IMPLEMENTED || IoErr() == ERROR_ACTION_NOT_KNOWN || (IoErr() == ERROR_OBJECT_NOT_FOUND && fib->fib_EntryType == ST_PIPEFILE)) { /* We can't retrieve name because lock is an exclusive lock or Examine is not implemented in this handler or the lock refers to an XPIPE: file having always empty name */ buffer[0] = '\0'; break; } else if(IoErr() != ERROR_LINE_TOO_LONG) { errno = __stdc_ioerr2errno(IoErr()); FreeDosObject(DOS_FIB, fib); FreeVec(buffer); return -1; } FreeVec(buffer); buffersize *= 2; } while(TRUE); // We need a FileLock. Otherwise a call of Info() within __fill_statbuffer() will crash // FIXME: how can we get a lock on an exclusive file? if (filehandle) { BPTR filelock = DupLockFromFH(lock); __fill_statbuffer(sb, (char*) buffer, fib, fallback_to_defaults, filelock); UnLock(filelock); } else { __fill_statbuffer(sb, (char*) buffer, fib, fallback_to_defaults, lock); } FreeVec(buffer); FreeDosObject(DOS_FIB, fib); return 0; }
void Verb_Parser(int *tokens) { switch(tokens[0]) { case Action_move: { Move(tokens); break; } case Action_pick: { Pick(tokens); break; } case Action_put: { Put(tokens); break; } case Action_look: { Look(tokens); break; } case Action_inventory: { Inventory(tokens); break; } case Action_examine: { Examine(tokens); break; } case Action_talk: { Talk(tokens); break; } case Action_save: { Save(tokens); break; } case Action_restore: { Restore(tokens); break; } case Action_exit: { Exit(tokens); break; } default: { printf("You must start a sentence with an action verb.\n"); break; } } }
// Checks buffers to see if they need re-reading // Called from the LISTER PROCESS void lister_check_old_buffer( Lister *lister, BOOL force) { int reread=0; #ifdef DEBUG if (lister) check_call("lister_check_old_buffer",lister); #endif // If re-read flag is set, and buffer is valid if ((force || environment->env->settings.dir_flags&DIRFLAGS_REREAD_CHANGED) && lister->cur_buffer->flags&DWF_VALID && lister->cur_buffer->buf_Path[0] && !lister->cur_buffer->buf_CustomHandler[0]) { DirBuffer *buffer; BPTR lock; // Get current buffer buffer=lister->cur_buffer; // Return on a device list if (!(IsListEmpty((struct List *)&buffer->entry_list)) && ((DirEntry *)buffer->entry_list.mlh_Head)->de_Node.dn_Type==ENTRY_DEVICE) return; // Lock and examine directory if (lock=Lock(buffer->buf_Path,ACCESS_READ)) { // Examine and unlock Examine(lock,lister->fib); UnLock(lock); // Make sure it's a directory if (lister->fib->fib_DirEntryType>0) { // See if datestamp has changed if (CompareDates(&buffer->buf_DirectoryDate,&lister->fib->fib_Date)>0) reread=1; // Or, see if disk has changed else if (buffer->buf_VolumeLabel[0]) { char rootname[512]; // Get root of current directory if (get_path_root(buffer->buf_Path,rootname,0)) { // See if disk name is not the same if (strcmp(rootname,buffer->buf_VolumeLabel)!=0) reread=1; } } } } // Did we need to re-read? if (reread) { // Re-read directory read_directory( lister, buffer->buf_Path, GETDIRF_RESELECT); } } }
static int findFirstMatch( char * pFileName, char * wpName ) { static BOOL isfirst=TRUE; BPTR dirlock; struct Node * newnode; /* char * onefname; */ char * point; unsigned len; /* printf("Called findFirstMatch: %s %s\n", pFileName, wpName); */ if(isfirst) { isfirst=FALSE; NewListPPC(&filelist); fib = AllocDosObject(DOS_FIB, NULL); strcpy(filepart, FilePart(pFileName)); if((point=PathPart(pFileName)) == pFileName) /* Current directory */ { dirlock=DupLock(((struct Process *)FindTask(NULL))->pr_CurrentDir); *pathpart=0; } else { len =(unsigned) (point-pFileName); strncpy(pathpart, pFileName, len); pathpart[len]=0; dirlock=Lock(pathpart, ACCESS_READ); } if(dirlock) { if(Examine(dirlock, fib)) { while(ExNext(dirlock, fib)) { if(fib->fib_DirEntryType == ST_FILE || fib->fib_DirEntryType == ST_LINKFILE) { /* printf("%s\n", fib->fib_FileName); */ newnode=malloc(sizeof(struct Node)); newnode->ln_Type = NT_USER; newnode->ln_Name=malloc(strlen(fib->fib_FileName)+1); strcpy(newnode->ln_Name, fib->fib_FileName); AddTailPPC(&filelist, newnode); } } } UnLock(dirlock); FreeDosObject(DOS_FIB, fib); } else return FALSE; } if(ParsePatternNoCase(filepart, parsebuf, PARSEBUFLEN)) { for(currentnode = filelist.lh_Head; currentnode->ln_Succ; currentnode = currentnode->ln_Succ) { /* printf("Match %s %s\n", parsebuf, currentnode->ln_Name); */ if(MatchPatternNoCase(parsebuf, currentnode->ln_Name)) { /* printf("Trovato %s\n", currentnode->ln_Name); */ strcpy(wpName, pathpart); AddPart(wpName, currentnode->ln_Name, MAX_NAMELEN); currentnode = currentnode->ln_Succ; return TRUE; } } /* return FALSE; */ } return FALSE; }