[comp.sys.mac.programmer] Ram Disks...

sonenbli@oxy.edu (Andrew D. Sonenblick) (01/12/90)

I would like to implement my own ram disk, being dissatisfied with those
I've encountered on the Mac.  However, the only manner I could come up with
on a moment's notice was to patch every trap in the file manager...
something very unwise.	Other than this, I am at a loss as to how to
implement a ram disk.  For example, how does one get the finder to display
a disk icon associated with an 800k Handle...  and so forth.  If you've
investigated this type of program please relay any pointers or suggestions.

Thanks, much.  Ando Moon: sonenbli@oxy.edu

ts@cup.portal.com (Tim W Smith) (01/14/90)

You don't patch anything.  You write a device driver and install it,
and then put an entry in the drive queue that references your driver.
Then you post a disk insertion event.

Probably the best way to go about this is to get the SCSI development
package from APDA which contains a sample SCSI disk driver.  Your driver
will be similar, except that it doesn't make any SCSI calls.

You will probably want an INIT to set up your RAM disk.  This INIT would
handle allocating the RAM and installing the driver and opening the
driver.

Be sure to write the part that transfers data in assembly language.
I hacked up my SCSI driver to be a RAM disk driver one day, and for
the first version I just did a byte-at-a-time copy from C, and the
RAM disk was only about 4 times as fast as my Quantum drive!

						Tim Smith

ps: once you have written a disk driver, you can then do all kinds of
fun things.  For example, I modified my RAM disk driver once to use my
FastNet III card to talk to another Mac II which had a FastNet III card
and a Surfboard.  Each disk request caused an Ethernet packet to be
sent to the other machine.  My protocol handler on that machine would
use the Surfboard to perform the requested action.

Stick a CD-ROM on the Surfboard at this point, and you have a simple
way to share a CD-ROM among multiple machines.  Not bad for something
that took less than two days to implement, eh?

urlichs@smurf.ira.uka.de (01/16/90)

In comp.sys.mac.programmer ts@cup.portal.com (Tim W Smith) writes:
< 
< Be sure to write the part that transfers data in assembly language.
< I hacked up my SCSI driver to be a RAM disk driver one day, and for
< the first version I just did a byte-at-a-time copy from C, and the
< RAM disk was only about 4 times as fast as my Quantum drive!
< 
I don't know what this friendly programmer recommends.
I recommend _BlockMove. (No assembly language, no hassle...)

Having written a (rather hacked-together) volume-partitioning piece of code
myself, I can attest to the fact that the actual reading and writing code is
_simple_. It's rather more involved to get async requests, and immediate
requests, and R/W requests relative to the current position, to work
correctly. (I think the MPW driver glue code still isn't up to standard in the
former two cases, but I didn't check lately. The latter, you'll of course have
to handle yourself. And don't forget to check for the fact that your RAM disk
isn't infinite...)

And then of course you'll have to initialize the RAM disk, mount it, copy
stuff onto it, handling all kinds of wierd errors you never thought could
possibly happen before -- good luck!

< Stick a CD-ROM on the Surfboard at this point, and you have a simple
< way to share a CD-ROM among multiple machines.  Not bad for something
< that took less than two days to implement, eh?

If sharing read/write disks were only half that easy... ;-)
-- 
Matthias Urlichs