/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* |_o_o|\\ Copyright (c) 1987 The Software Distillery.  All Rights Reserved */
/* |. o.| || This program may not be distributed without the permission of   */
/* | .  | || the authors:                                          BBS:      */
/* | o  | ||   John Toebes     Dave Baker    John Mainwaring                 */
/* |  . |//                                                                  */
/* ======                                                                    */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* Directory Manipulation */
/*  ActCreateDir ActExamine ActExNext ActParent */
#include "handler.h"


void ActCreateDir(global,pkt)
GLOBAL global;
struct DosPacket *pkt;              /* a pointer to the dos packet sent      */
/* Arg1 - Lock */
/* Arg2 - name */
/* Arg3 (optional) Attributes */
{
   struct FileLock *lock;
   long key;

   BUG(("ActCreateDir\n"));

   lock = (struct FileLock *)pkt->dp_Arg1;

   key = CreateEntry(global, GetKey(global,lock),
                    (char *)pkt->dp_Arg2, NEWFILE, ST_USERDIR);

   pkt->dp_Res1 = MKBADDR(CreateLock(global, key, ACCESS_READ));
}

/*---------------------------------------------------------------------------*/
/* Structure of the FileInfoBlock                                            */
/* struct FileInfoBlock {                                                    */
/*    LONG fib_DiskKey;           Location on disk of entry                  */
/*    LONG fib_DirEntryType;      <0 plain file, >0 a directory              */
/*    char fib_FileName[108];     Null terminated name of file               */
/*    LONG fib_Protection;        Protection bits for the file               */
/*    LONG fib_EntryType;         Internal for Dos use                       */
/*    LONG fib_Size;              Length of file in bytes                    */
/*    LONG fib_NumBlocks;         Length of file in blocks                   */
/*    struct DateStamp fib_Date;  File creation date                         */
/*    char fib_Comment[116];      Comment associated with file               */
/*    };                                                                     */
/*---------------------------------------------------------------------------*/
void ActExamine(global, pkt)
GLOBAL global;
struct DosPacket *pkt;              /* a pointer to the dos packet sent      */
/* Arg1: Lock of object to examine */
/* Arg2: FileInfoBlock to fill in */
{
   struct FileInfoBlock *info;
   long key;

   BUG(("ActExamine\n"));
   info = (struct FileInfoBlock *)pkt->dp_Arg2;

   /* get the block associated with the lock */
   key = GetKey(global, (struct FileLock *)pkt->dp_Arg1);

   pkt->dp_Res1 = GetInfo(global, key, info);
}

void ActExNext(global,pkt)
GLOBAL global;
struct DosPacket *pkt;              /* a pointer to the dos packet sent      */
/* ARG1 - Lock */
/* ARG2 - BPTR FileInfoBlock */
{
   struct FileInfoBlock *info;
   KEY key, rootkey;

   BUG(("ActExNext\n"));
   rootkey = GetKey(global, (struct FileLock *)pkt->dp_Arg1);
   info = (struct FileInfoBlock *)pkt->dp_Arg2;

   /* See if they are going for the first time */
   if (rootkey == info->fib_DiskKey)
      {
      if (GetProtect(global,rootkey) & FIBF_READ)
         {
         pkt->dp_Res1 = DOS_FALSE;
         pkt->dp_Res2 = ERROR_READ_PROTECTED;
         return;
         }

      BUG(("First time through\n"));
      /* First time, initiate for the next entry */
      key = 0;
      }
   else
      {
      BUG(("Going for next key from %ld\n", info->fib_DiskKey))
      key = info->fib_DiskKey;
      }

   /* find next key in directory */
   key = NextKey(global, key, info, rootkey);

   pkt->dp_Res2 = ERROR_NO_MORE_ENTRIES;
   pkt->dp_Res1 = GetInfo(global, key, info);
}

void ActParent(global,pkt)
GLOBAL global;
struct DosPacket *pkt;              /* a pointer to the dos packet sent      */
/* Arg1 - Lock */
{
   long key;
   struct FileLock *lock;

   BUG(("ActParent\n"));

   key = ParentKey(global, GetKey(global, (struct FileLock *)pkt->dp_Arg1));

   lock = CreateLock(global, key, ACCESS_READ);

   BUG(("Parent is %ld lock is %08lx\n", key, lock));

   pkt->dp_Res1 = MKBADDR(lock);
}
