[comp.sys.amiga.tech] FileInfoBlock

phil@adam.adelaide.edu.au (Phil Kernick) (10/26/90)

If I use the following stub of code:

getinfo()
{
  BPTR fred;
  struct FileInfoBlock *fib;

  lock = Lock("fred", ACCESS_READ);
  Examine(lock, fib);
}

I can get information on the file protection from fib->fib_Protection and
date from fib->fib_FileDate (this is from my memory, ie don't tell me that
I have the structure members wrong :-), but how can I set them?

I wan't to know how the programs "protect" from WB 1.3.2 and "touch"
from the SAS C 5.05 work.  It would seem that they simply change the
fields that they want in the fib and then write it back.  How is this
done?  I have the RKM but it is *very* old (only deals with KS 1.1).

Thanks,

Phil.


  
-- 
Phil Kernick                            EMail:  phil@adam.adelaide.edu.au
Departmental Engineer                   Phone:  +618 228 5914
Dept. of Psychology                     Fax:    +618 224 0464
University of Adelaide                  Mail:   GPO Box 498 Adelaide SA 5001

ken@cbmvax.commodore.com (Ken Farinsky - CATS) (10/26/90)

In article <phil.656904446@adam.adelaide.edu.au> phil@adam.adelaide.edu.au (Phil Kernick) writes:
>If I use the following stub of code:
>
>getinfo()
>{
>  BPTR fred;
>  struct FileInfoBlock *fib;
>
>  lock = Lock("fred", ACCESS_READ);
>  Examine(lock, fib);
>}

AACK!!  You have to allocate the memory for the file info block.

something like:

if (NULL != (fib = (struct FileInfoBlock *)
             AllocMem(sizeof(*fib),MEMF_CLEAR | MEMF_PUBLIC)))
    {
    /* use the fib here */
    FreeMem(fib, sizeof(*fib));
    }

Note that AllocMem() guarantees longword alignment.  Sorry for any
errors, I'm doing this from memory.  Here's the info on Examine():

    SYNOPSIS
        success = Examine( lock, infoBlock )
        D0                 D1    D2

        BOOL success;
        struct FileLock *lock;
        struct FileInfoBlock *infoBlock

    FUNCTION
        Examine() fills in information in the FileInfoBlock concerning the
        file or directory associated with the lock. This information
        includes the name, size, creation date and whether it is a file or
        directory. FileInfoBlock must be longword aligned. Examine() gives
        a return code of zero if it fails.

        You may make a local copy of the FileInfoBlock, as long as it is
        never passed back to the operating system.

    INPUTS
        lock - BCPL pointer to a lock
        infoBlock - pointer to a FileInfoBlock (must be longword aligned)

    OUTPUTS
        success - boolean

-- 
--
Ken Farinsky - CATS - (215) 431-9421 - Commodore Business Machines
uucp: ken@cbmvax.commodore.com   or  ...{uunet,rutgers}!cbmvax!ken
bix:  kfarinsky

markv@kuhub.cc.ukans.edu (11/08/90)

In article <15413@cbmvax.commodore.com>, ken@cbmvax.commodore.com (Ken Farinsky - CATS) writes:
>>  struct FileInfoBlock *fib;
>>
>>  lock = Lock("fred", ACCESS_READ);
>>  Examine(lock, fib); 
> AACK!!  You have to allocate the memory for the file info block.
> something like: 
> if (NULL != (fib = (struct FileInfoBlock *)
>              AllocMem(sizeof(*fib),MEMF_CLEAR | MEMF_PUBLIC)))
>...

Or if you have SAS C 5.1 you can say:

	struct FileInfoBlock _aligned fib;

and use &fib.  The _aligned is nice because it eliminates the need for
lots of otherwise uneeded Alloc/Free code just so you can get longword
alignment.  Obviously such a variable can't be auto storage class.
-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Mark Gooderum			Only...		\    Good Cheer !!!
Academic Computing Services	       ///	  \___________________________
University of Kansas		     ///  /|         __    _
Bix:	  markgood	      \\\  ///  /__| |\/| | | _   /_\  makes it
Bitnet:   MARKV@UKANVAX		\/\/  /    | |  | | |__| /   \ possible...
Internet: markv@kuhub.cc.ukans.edu
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

walker@unx.sas.com (Doug Walker) (11/08/90)

In article <phil.656904446@adam.adelaide.edu.au> phil@adam.adelaide.edu.au (Phil Kernick) writes:
>If I use the following stub of code:
>
>getinfo()
>{
>  BPTR fred;
>  struct FileInfoBlock *fib;
>
>  lock = Lock("fred", ACCESS_READ);
>  Examine(lock, fib);
>}
>
>I can get information on the file protection from fib->fib_Protection and
>date from fib->fib_FileDate (this is from my memory, ie don't tell me that
>I have the structure members wrong :-), but how can I set them?

This code WILL NOT WORK.  You'd better actually allocate the FileInfoBlock,
or declare an instance using the __aligned keyword in 5.10 SAS/C:

struct FileInfoBlock __aligned fib;
lock=Lock...
Examine(lock, &fib);

or

struct FileInfoBlock *fib;
fib = (struct FileInfoBlock *)AllocMem(sizeof(struct FileInfoBlock), 0);
lock = Lock...
Examine(lock, fib);



>
>I wan't to know how the programs "protect" from WB 1.3.2 and "touch"
>from the SAS C 5.05 work.  It would seem that they simply change the
>fields that they want in the fib and then write it back.  How is this
>done?  I have the RKM but it is *very* old (only deals with KS 1.1).
>
>Thanks,
>
>Phil.

To set the fields, you have to call the appropriate DOS functions
(SetProtection, SetDate) or send DOS packets to the file system
instructing it to do this.  You can't just 'write back' the FIB.
Get a copy of the AmigaDOS programmer's guide for the version of
the operating system you are running on and read up on the other
DOS calls.
 
Actually, after a quick look at the prototypes in my 1.3 include files,
it looks like SetProtection exists in 1.3, but SetFileDate doesn't
get added until 2.0.  You'll have to look into the DOS packet interface
to set the file date under 1.3.  Alternatively, you could just open
the file for read/write, read a byte, and write it back if you just
want to set the file date to the current date like touch.
 

  *****
=*|_o_o|\\=====Doug Walker, Software Distiller====== BBS: (919)460-7430 =
 *|. o.| ||                                          1200/2400/9600 Dual
  | o  |//     For all you do, this bug's for you!
  ====== 
usenet: ...mcnc!rti!sas!walker   plink: dwalker  bix: djwalker 

aycock@cpsc.ucalgary.ca (aycock) (11/10/90)

Mark Gooderum (markv@kuhub.cc.ukans.edu) writes:
| Or if you have SAS C 5.1 you can say:
| 
| 	struct FileInfoBlock _aligned fib;
| 
| and use &fib.  The _aligned is nice because it eliminates the need for
| lots of otherwise uneeded Alloc/Free code just so you can get longword
| alignment.

Or, if you don't have Lattice, or refuse to never ever ever use another of
their compilers again, you could use:

unsigned char space[sizeof(struct FileInfoBlock) + 4];
struct FileInfoBlock *fib;

fib = (struct FileInfoBlock *) (((unsigned long)space+4)&~3);

I agree, though, it's much nicer than using AllocMem() and FreeMem().
:ja
--

  //\|_||\|	John D. Aycock		aycock@cpsc.ucalgary.ca
\/ \/| || |	(403) 285-8727

walker@unx.sas.com (Doug Walker) (11/27/90)

>Or if you have SAS C 5.1 you can say:
>
>	struct FileInfoBlock _aligned fib;
>
>and use &fib.  The _aligned is nice because it eliminates the need for
>lots of otherwise uneeded Alloc/Free code just so you can get longword
>alignment.  Obviously such a variable can't be auto storage class.
>-- 

It's __aligned, not _aligned.  And the variable CAN be auto storage
class, or any other storage class.  It can even be a member of a
structure - pad bytes will be added to the structure if needed.


  *****
=*|_o_o|\\=====Doug Walker, Software Distiller====== BBS: (919)460-7430 =
 *|. o.| ||                                          1200/2400/9600 Dual
  | o  |//     For all you do, this bug's for you!
  ====== 
usenet: ...mcnc!rti!sas!walker   plink: dwalker  bix: djwalker 

peter@sugar.hackercorp.com (Peter da Silva) (11/28/90)

Re: __aligned in a structure.

What if you have a structure with an __aligned member and allocate an instance
of this structure on the stack. Does this force the compiler to allocate an
__aligned structure or do you have to __align it as well?
-- 
Peter da Silva.   `-_-'
<peter@sugar.hackercorp.com>.

walker@unx.sas.com (Doug Walker) (11/30/90)

>Or, if you don't have Lattice, or refuse to never ever ever use another of
>their compilers again, you could use:

A perfect opportunity, you can now use SAS/C instead!  Seriously, it
sounds to me like you haven't tried the compiler environment in the 
last couple of years.  It's changed a tremendous amount.  Come 
see it in the booth at an AmiExpo sometime.

>
>unsigned char space[sizeof(struct FileInfoBlock) + 4];
>struct FileInfoBlock *fib;
>
>fib = (struct FileInfoBlock *) (((unsigned long)space+4)&~3);
>

Or do this:

#define DCL(name, type) char c_##name[sizeof(type)+3];\
                        type * name = (type *)((((long)c_##name+3)>>2)<<2);

DCL(fib, struct FileInfoBlock);

Then fib will automagically be initialized to point to an aligned
FileInfoBlock.  This works for autos, statics or externs, as long
as the compiler you are using supports ANSI token pasting (##) which
I know SAS/C does and I'm pretty sure Manx does.


  *****
=*|_o_o|\\=====Doug Walker, Software Distiller====== BBS: (919)460-7430 =
 *|. o.| ||                                          1200/2400/9600 Dual
  | o  |//     For all you do, this bug's for you!
  ====== 
usenet: ...mcnc!rti!sas!walker   plink: dwalker  bix: djwalker 

markv@kuhub.cc.ukans.edu (12/06/90)

In article <7155@sugar.hackercorp.com>, peter@sugar.hackercorp.com (Peter da Silva) writes:
> Re: __aligned in a structure. 
> What if you have a structure with an__aligned member and allocate an instance
> of this structure on the stack. Does this force the compiler to allocate an
> __aligned structure or do you have to __align it as well?

You will get an error.  You must use a static storage class for an
__aligned structure for somewhat obvious reasons.  Just like you cant
have a __chip object on the stack.

> -- 
> Peter da Silva.   `-_-'
> <peter@sugar.hackercorp.com>.
-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Mark Gooderum                 /\     \ | /     H a p p y  
Academic Computing Services  / v\   -- * --         H o l i d a y s ! :-)
University of Kansas        /v  v\   / | \    ///
                           /__v___\   Only  ///  /|         __    _  
Bitnet:   MARKV@UKANVAX       ||     \\\  ///  /__| |\/| | | _   /_\  makes it
Internet: markv@kuhub.cc.ukans.edu     \/\/  /    | |  | | |__| /   \ possible
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

peter@sugar.hackercorp.com (Peter da Silva) (12/07/90)

In article <27257.275ce563@kuhub.cc.ukans.edu> markv@kuhub.cc.ukans.edu writes:
> You will get an error.  You must use a static storage class for an
> __aligned structure for somewhat obvious reasons.  Just like you cant
> have a __chip object on the stack.

I don't see why you can't have an __aligned structure on the stack... it'd
just take an extra instruction on subroutine entry. But that doesn't address
the question I asked: that is if you have a structure with an __aligned
element is that whole structure forced __aligned:

typedef struct {
	struct FileInfoBlock __aligned fib;
	blah blah blah;
} baz;

Now what if you do this:

	foo()
	{
		baz zot;
		...
	}

Is this illegal?
> 
> > -- 
> > Peter da Silva.   `-_-'
> > <peter@sugar.hackercorp.com>.
> -- 
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Mark Gooderum                 /\     \ | /     H a p p y  
> Academic Computing Services  / v\   -- * --         H o l i d a y s ! :-)
> University of Kansas        /v  v\   / | \    ///
>                            /__v___\   Only  ///  /|         __    _  
> Bitnet:   MARKV@UKANVAX       ||     \\\  ///  /__| |\/| | | _   /_\  makes it
> Internet: markv@kuhub.cc.ukans.edu     \/\/  /    | |  | | |__| /   \ possible
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


-- 
Peter da Silva.   `-_-'
<peter@sugar.hackercorp.com>.