View Single Post
Old 25 March 2018, 17:54   #2
thomas
Registered User
 
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 7,004
Code:
#include <proto/exec.h>
#include <proto/dos.h>

#include <dos/filehandler.h>

#include <string.h>



/* copy a BCPL string to a C string */

void bstrcpy (char *dest,UBYTE *src)
{
int len = *src++;
strncpy (dest,src,len);
dest[len] = 0;
}



/* get drive name, device and unit for a given path */

BOOL get_device_unit (const char *path,char *drive,char *device,long *unit)
{
BOOL ok = FALSE;
struct DevProc *proc;

if ((proc = GetDeviceProc (path,NULL)))
	{
	struct DosList *dl;

	dl = LockDosList (LDF_DEVICES | LDF_READ);

	while ((dl = NextDosEntry (dl,LDF_DEVICES)))
		{
		if (dl->dol_Task == proc->dvp_Port)
			break;
		}

	if (dl)
		{
		struct FileSysStartupMsg *fssm = BADDR(dl->dol_misc.dol_handler.dol_Startup);

		if (TypeOfMem(fssm) && (APTR)fssm > (APTR)1000)
			{
			bstrcpy (drive,BADDR(dl->dol_Name));
			bstrcpy (device,BADDR(fssm->fssm_Device));
			*unit = fssm->fssm_Unit;
			ok = TRUE;
			}
		}

	UnLockDosList (LDF_DEVICES | LDF_READ);

	FreeDeviceProc (proc);
	}

return (ok);
}



/* main program */

int main (void)
{
struct RDArgs *rdargs;
struct {
	char **path;
	} args;

if (!(rdargs = ReadArgs ("PATH/A/M",(APTR)&args,NULL)))
	PrintFault (IoErr(),NULL);
else
	{
	char name[256];
	char device[256];
	long unit;
	char **path;

	for (path = args.path; *path; path++)
		{
		if (!get_device_unit (*path,name,device,&unit))
			Printf ("could not find information for %s\n",*path);
		else
			{
			Printf ("info for %s: device=%s; unit=%ld\n",name,device,unit);
			}
		}

	FreeArgs (rdargs);
	}

return (RETURN_OK);
}
thomas is offline  
 
Page generated in 0.06311 seconds with 10 queries