[comp.sys.amiga.tech] Help - Asynchronous I/O to/from files

duncant@mbunix.mitre.org (Thomson) (02/26/90)

Can anyone tell me how to do asynchronous I/O to/from AmigaDOS files?

That is,I want to issue a Read() or Write() request and not block, but
be notified with a signal later when the I/O completes.  I know that
it's possible to send I/O request packets asynchonoushly to any device
driver, but I don't want to deal with device drivers, I want to deal with
the file system.  Isn't there a way to do this?  I can't find it in my RKMs.
Any help would be appreciated?

Thanks
Duncan Thomson

mks@cbmvax.commodore.com (Michael Sinz - CATS) (02/27/90)

In article <99009@linus.UUCP> duncant@mbunix.mitre.org (Thomson) writes:
>
>Can anyone tell me how to do asynchronous I/O to/from AmigaDOS files?
>
>That is,I want to issue a Read() or Write() request and not block, but
>be notified with a signal later when the I/O completes.  I know that
>it's possible to send I/O request packets asynchonoushly to any device
>driver, but I don't want to deal with device drivers, I want to deal with
>the file system.  Isn't there a way to do this?  I can't find it in my RKMs.
>Any help would be appreciated?

Yes, you send packets to AmigaDos directly.  These are documented in the
AmigaDos manual (BANTAM Books, ISBN 0-553-34294-0)  The packets are
actually sent to the FileSystem and this all works wonderfully.

>Thanks
>Duncan Thomson

/----------------------------------------------------------------------\
|      /// Michael Sinz -- CATS/Amiga Software Engineer                |
|     ///  PHONE 215-431-9422  UUCP ( uunet | rutgers ) !cbmvax!mks    |
|    ///                                                               |
|\\\///          When people are free to do as they please,            |
| \XX/                they usually imitate each other.                 |
\----------------------------------------------------------------------/

apang@undergrad.cs.ubc.ca (Anthon 'Amiga' Pang) (02/28/90)

In article <9830@cbmvax.commodore.com> mks@cbmvax.commodore.com (Michael Sinz - CATS) writes:
>In article <99009@linus.UUCP> duncant@mbunix.mitre.org (Thomson) writes:
>>
>>Can anyone tell me how to do asynchronous I/O to/from AmigaDOS files?
>>
>>That is,I want to issue a Read() or Write() request and not block, but
>>be notified with a signal later when the I/O completes.  I know that
>>it's possible to send I/O request packets asynchonoushly to any device
>>driver, but I don't want to deal with device drivers, I want to deal with
>>the file system.  Isn't there a way to do this?  I can't find it in my RKMs.
>>Any help would be appreciated?
>
>Yes, you send packets to AmigaDos directly.  These are documented in the
>AmigaDos manual (BANTAM Books, ISBN 0-553-34294-0)  The packets are
>actually sent to the FileSystem and this all works wonderfully.

I guess you'll miss all that BCPL stuff in 1.4 :)

Personally, I would have spawned a couple of tasks, which only used the upper
level AmigaDOS routines--Open, Close, Read, Write, Lock, etc.  Then, throw in
a few message ports to handle the I/O request "packets".  (In fact I did this
for one of my courses last term, to demonstrate double buffered i/o--BTW, I
wrote it in Modula-2.)

a464@mindlink.UUCP (Bruce Dawson) (03/01/90)

> duncant writes:
> 
> Am I off track here?  Can tasks in fact call Read(), Write() and so on?
> Or can processes be spawned without having to do a disk access?
> 
> I was just getting set to launch into doing it by sending packets to
> the filesystem handler - but if there is an easier way...
> 
> Thanks
> Duncan Thomson (would-be Amiga ssytem programmer!)
> 
> --
> (Please excuse the typos and garbage caused by line noise.)


     Tasks can not do file i/o, or anything else AmigaDosish.  Processes can.
However, spawning a process does _not_ imply doing a LoadSeg.  You can spawn a
process and give it the code in one of your subroutines in your already loaded
program to execute.  You do have to deal with a few uglies like making it long
word aligned for the usual BCPL reasons, but it is possible.

.Bruce Dawson.

duncant@mbunix.mitre.org (Thomson) (03/02/90)

My original question was:
> How do I do asynchronous I/O to/from files?

Someone answered:
>
>Personally, I would have spawned a couple of tasks, which only used the upper
>level AmigaDOS routines--Open, Close, Read, Write, Lock, etc.  Then, throw in
>a few message ports to handle the I/O request "packets".  (In fact I did this
>for one of my courses last term, to demonstrate double buffered i/o--BTW, I
>wrote it in Modula-2.)

I thought that tasks could not access AmigaDOS routines without causing a 
guru?  (I don't remember where I read this, but I know that in the figures
of the Amiga software architecture in the front of the RKMs Exec is
shown below - used by, not using - AmigaDos.)  I know that it is possible to
spawn a coule of _processes_ which can then use the upper level AmigaDOS 
routines - but the problem here is that spawning a process requires a
call to LoadSeg - which does a disk access!  The whole point of double-buffering
is to speed up disk access by doing input, output, and processing in parallel.
If you have to do additional disk accesses to get your double-buffering
going, that kind of defeats the purpose.  Also, its a bit messy - since 
loadseg has to know the path of the load module its going to load - which
means you have to be sure that the files will always be in the right place
when the program is run.

Am I off track here?  Can tasks in fact call Read(), Write() and so on?  
Or can processes be spawned without having to do a disk access?

I was just getting set to launch into doing it by sending packets to
the filesystem handler - but if there is an easier way...

Thanks
Duncan Thomson (would-be Amiga ssytem programmer!)

--
(Please excuse the typos and garbage caused by line noise.)

jeh@elmgate.UUCP (Ed Hanway) (03/03/90)

In article <1990Feb28.023511.4806@undergrad.cs.ubc.ca> apang@b0 (JVNIc7B7ktKDA) writes:
>In article <9830@cbmvax.commodore.com> mks@cbmvax.commodore.com (Michael Sinz - CATS) writes:
>>
>>Yes, you send packets to AmigaDos directly.  These are documented in the
>>AmigaDos manual (BANTAM Books, ISBN 0-553-34294-0)  The packets are
>>actually sent to the FileSystem and this all works wonderfully.
>
>I guess you'll miss all that BCPL stuff in 1.4 :)

The packet interface to AmigaDos devices has nothing to do with BCPL, other
than the fact that some of the fields in the packets are BPTRs. I highly
doubt that it will go away with 1.4.

Now the _real_ BCPL stuff, like global vectors and the secret BCPL run-time
library that some programs in the C: directory use -- the sooner that
goes away the better.

>Personally, I would have spawned a couple of tasks, which only used the upper
>level AmigaDOS routines--Open, Close, Read, Write, Lock, etc.  Then, throw in
>a few message ports to handle the I/O request "packets".  (In fact I did this
>for one of my courses last term, to demonstrate double buffered i/o--BTW, I
>wrote it in Modula-2.)

They must have been processes, not tasks.  This sounds fine for simple
double buffering, but since you're still using the synchronous DOS routines,
you would need a new process for each additional concurrent I/O operation.
If you send packets straight to the FileSystem, you can have as many
concurrent operations going on as you need.

What would be nice is a library with calls like async_Read(), async_Write(),
etc. that took care of the dirty work of assembling packets and sending them
to the DOS. In fact, I think Matt Dillon posted some code similar to this
last year.

Ed Hanway
Eastman Kodak Company	       ...!rochester!kodak!elmgate!jeh
#include <std_disclaimer.h>

apang@undergrad.cs.ubc.ca (Anthon 'Amiga' Pang) (03/03/90)

In article <99866@linus.UUCP> duncant@mbunix.mitre.org (Thomson) writes:
>My original question was:
>> How do I do asynchronous I/O to/from files?
>
>Someone answered:
>>
>>Personally, I would have spawned a couple of tasks, which only used the upper
>>[much deleted]
>I thought that tasks could not access AmigaDOS routines without causing a 
>guru?  (I don't remember where I read this, but I know that in the figures
>of the Amiga software architecture in the front of the RKMs Exec is
>shown below - used by, not using - AmigaDos.)  I know that it is possible to
>spawn a coule of _processes_ which can then use the upper level AmigaDOS 
>routines - but the problem here is that spawning a process requires a
>call to LoadSeg - which does a disk access!  The whole point of double-buffering
>is to speed up disk access by doing input, output, and processing in parallel.

Sorry, I should have said "spawned a couple of processes".  I used Chris
Zamara's "spawn.c" that appeared in AmiTransactor 2.2, which allows you to
spawn processes from procedures in your program...no need to LoadSegs here,
as the "process" is already in memory along with your main program.  It's
also pretty efficient when you spawn multiple copies from the same
procedure (only 1 copy in memory).  I found this easier than DOS packets and
a great learning experience--message ports, signals, tasks/processes, 
assembler, file systems theory...