[net.micro.amiga] Does anyone know how to get directory info within a prog?

gary@mit-eddie.MIT.EDU (Gary Samad) (06/24/86)

<>

Have any of you out there in Amigaland learned how to read disk directories,
how to change directories, and how to get info about particular entries
(such as: file or directory, filesize, etc.) from within a program?
I glanced through the ROM Kernel Manual and found only very low level info
about tracks, sectors, etc. rather than about the directory structure.

I've been calling the Amiga tech line for a couple of weeks now and either
get their answering machine or nothing at all...anyone know what's up?

If you have the answers, please mail them to me as well as posting...I'm
having a hard time wrenching myself away from the machine to keep up with
the news! (I'm already 400 behind, sigh)

	Thanks,
	Gary


	ihnp4!         \
		        > mit-eddie!gary
	decvax!genrad! /

dillon@PAVEPAWS.BERKELEY.EDU (Matt Dillon) (06/24/86)

	I took this out of the code for my SHELL.  It should give you some
idea of how to get a directory.

/*
 * Disk directory routines
 *
 * dptr = dopen(name, stat)
 *    struct DPTR *dptr;
 *    char *name;
 *    int *stat;
 *
 * dnext(dptr, name, stat)
 *    struct DPTR *dptr;
 *    char **name;
 *    int  *stat;
 *
 * dclose(dptr)                  -may be called with NULL without harm
 *
 * dopen() returns a struct DPTR, or NULL if the given file does not
 * exist.  stat will be set to 1 if the file is a directory.  If the
 * name is "", then the current directory is openned.
 *
 * dnext() returns 1 until there are no more entries.  The **name and
 * *stat are set.  *stat = 1 if the file is a directory.
 *
 * dclose() closes a directory channel.
 *
 */


struct DPTR {                    /* Format of directory fetch pointer */
   struct FileLock *lock;        /* lock on directory   */
   struct FileInfoBlock *fib;    /* mod'd fib for entry */
};



struct DPTR *
dopen(name, stat)
char *name;
int *stat;
{
   struct DPTR *dp;
   int namelen, endslash = 0;

   namelen = strlen(name);
   if (namelen && name[namelen - 1] == '/') {
      name[namelen - 1] = '\0';
      endslash = 1;
   }
   *stat = 0;
   dp = (struct DPTR *)malloc(sizeof(struct DPTR));
   if (*name == '\0')
      dp->lock = DupLock (Clock);
   else
      dp->lock = Lock (name, ACCESS_READ);
   if (endslash)
      name[namelen - 1] = '/';
   if (dp->lock == NULL) {
      free (dp);
      return (NULL);
   }
   dp->fib = (struct FileInfoBlock *)
         AllocMem(sizeof(struct FileInfoBlock), MEMF_PUBLIC);
   if (!Examine (dp->lock, dp->fib)) {
      perror (name);
      dclose (dp);
      return (NULL);
   }
   if (dp->fib->fib_DirEntryType >= 0)
      *stat = 1;
   return (dp);
}

dnext(dp, pname, stat)
struct DPTR *dp;
char **pname;
int *stat;
{
   if (dp == NULL)
      return (0);
   if (ExNext (dp->lock, dp->fib)) {
      *stat = (dp->fib->fib_DirEntryType < 0) ? 0 : 1;
      *pname = dp->fib->fib_FileName;
      return (1);
   }
   return (0);
}


dclose(dp)
struct DPTR *dp;
{
   if (dp == NULL)
      return (1);
   if (dp->fib)
      FreeMem (dp->fib, sizeof(*dp->fib));
   if (dp->lock)
      UnLock (dp->lock);
   free (dp);
   return (1);
}


-----------------------------------------------------------------------------

do_dir(garbage, com)
char *garbage;
{
   struct DPTR          *dp;
   struct InfoData      *info;
   char *name;
   int i, stat;
   long total = 0;

   if (ac == 1) {
      ++ac;
      av[1] = "";
   }
   for (i = 1; i < ac; ++i) {
      if ((dp = dopen (av[i], &stat)) == NULL)
         continue;
      if (com < 0) {
         info = (struct InfoData *)AllocMem(sizeof(struct InfoData), MEMF_PUBLIC);
         if (Info (dp->lock, info)) {
            int bpb = info->id_BytesPerBlock;
            printf ("Unit:%2d  Errs:%3d  Bytes: %-7d Free: %-7d\n",
                  info->id_UnitNumber,
                  info->id_NumSoftErrors,
                  bpb * info->id_NumBlocks,
                  bpb * (info->id_NumBlocks - info->id_NumBlocksUsed));
         } else {
            perror (av[i]);
         }
         FreeMem (info, sizeof(*info));
      } else {
         if (stat) {
            while (dnext (dp, &name, &stat)) {
               total += disp_entry (dp->fib);
               if (CHECKBREAK())
                  break;
            }
         } else {
            total += disp_entry(dp->fib);
         }
      }
      dclose (dp);
   }
   printf ("TOTAL: %ld\n", total);
   return (1);
}


long
disp_entry(fib)
register struct FileInfoBlock *fib;
{
   char str[5];
   register char *dirstr;

   str[4] = '\0';
   str[0] = (fib->fib_Protection & FIBF_READ) ? '-' : 'r';
   str[1] = (fib->fib_Protection & FIBF_WRITE) ? '-' : 'w';
   str[2] = (fib->fib_Protection & FIBF_EXECUTE) ? '-' : 'x';
   str[3] = (fib->fib_Protection & FIBF_DELETE) ? '-' : 'd';
   dirstr = (fib->fib_DirEntryType < 0) ? "   " : "DIR";

   printf ("%s %6ld %s  %s\n", str, (long)fib->fib_Size, dirstr, fib->fib_FileName);
   return ((long)fib->fib_Size);
}

neil@amiga.UUCP (Neil Katin) (06/24/86)

In article <2360@mit-eddie.MIT.EDU> gary@mit-eddie.MIT.EDU (Gary Samad) writes:
>Have any of you out there in Amigaland learned how to read disk directories,
>how to change directories, and how to get info about particular entries
>(such as: file or directory, filesize, etc.) from within a program?
>I glanced through the ROM Kernel Manual and found only very low level info
>about tracks, sectors, etc. rather than about the directory structure.
>
>I've been calling the Amiga tech line for a couple of weeks now and either
>get their answering machine or nothing at all...anyone know what's up?
>
>If you have the answers, please mail them to me as well as posting...I'm
>having a hard time wrenching myself away from the machine to keep up with
>the news! (I'm already 400 behind, sigh)
>
>	Thanks,
>	Gary

Try reading the AmigaDOS developers manual.  All the answers are within.

	Neil Katin
	Commodore-Amiga Inc.

daveh@cbmvax.UUCP (06/24/86)

> 
> <>
> 
> Have any of you out there in Amigaland learned how to read disk directories,
> how to change directories, and how to get info about particular entries
> (such as: file or directory, filesize, etc.) from within a program?
> I glanced through the ROM Kernel Manual and found only very low level info
> about tracks, sectors, etc. rather than about the directory structure.
> 
> I've been calling the Amiga tech line for a couple of weeks now and either
> get their answering machine or nothing at all...anyone know what's up?
> 
> If you have the answers, please mail them to me as well as posting...I'm
> having a hard time wrenching myself away from the machine to keep up with
> the news! (I'm already 400 behind, sigh)
> 
> 	Thanks,
> 	Gary
> 
> 
> 	ihnp4!         \
> 		        > mit-eddie!gary
> 	decvax!genrad! /

You can find most of this information in the Amiga Developer's Manual, which
details all of the DOS level calls.  Lets you examine, delete, create, etc. 
directories and files.  Also has the low level Read(), Write(), and Seek()
functions which are the lowest DOS level interface functions, and likely
the fastest as well.  If you have the includes, most of the stuff is in
the dosextens.h file, including FileLocks for multiple access of the same
file, FileInfoBuffers that contain the stats on a given file or directory,
and the DOS versions of file headers, which are different than the FILE *
you get in Lattice C.

-- 
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
Dave Haynie    {caip,ihnp4,allegra,seismo}!cbmvax!daveh

   A quote usually goes here, but its currently being rennovated.

	These opinions are my own, though for a small fee they be yours too.
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

higgin@cbmvax.cbm.UUCP (Paul Higginbottom) (06/25/86)

In article <2360@mit-eddie.MIT.EDU> gary@mit-eddie.MIT.EDU (Gary Samad) writes:
>Have any of you out there in Amigaland learned how to read disk directories,
>how to change directories, and how to get info about particular entries
>(such as: file or directory, filesize, etc.) from within a program?
>	Thanks,
>	Gary
>	ihnp4!         \
>		        > mit-eddie!gary
>	decvax!genrad! /


Gary,
	You need to get the manuals on AmigaDOS.  RKM only covers Exec,
graphics, devices, and libraries.  If you find the manuals still as 3
separate ones, you need the AmigaDOS Developer's manual.  Otherwise, just
get the newer, all-in-one manual.
	All the answers you need are in there.

	Paul Higginbottom.

Disclaimer: I do not work for Commodore and opinions expressed are my own.

mitsu@well.UUCP (Mitsuharu Hadeishi) (06/26/86)

	In re: finding out about changing directories, getting info
on files, etc., from an application program . . .
	The place to go for that information is the AmigaDOS
technical reference manual.  The basic situation is that you can use
"high-level" calls to UNIX-like routines to do your file I/O, but if
you want to get into the nitty gritty (and speed up your file I/O
minutely) you can use direct AmigaDOS library calls.
				-Mitsu (mitsu@well.UUCP)