[futurebasic] Re: Volume Reference Numbers

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : November 1997 : Group Archive : Group : All Groups

From: Rick Brown <rbrown@...>
Date: Sat, 22 Nov 1997 15:35:33 -0600
Mike wrote:

> There's been a lot of talk recently about vrefnums, so I got a few
> questions:
> 
> 1)  What exactly is a volume reference number, how are they assigned, etc.

Ah, yes, the famous "vrefnum."

First let me say that a "vrefnum" is not necessarily the same thing as a
volume reference number.  The thing that FutureBasic doc's call a
vrefnum or volrefnum is _usually_ really a "working directory reference
number," which is a different thing altogether.  The reason why the two
concepts get mixed up is because many Mac Toolbox calls are set up in
such a way that you can pass either a working directory ref. num. or a
volume ref. num. in the same parameter field.  It's a long story.

Anyway, a _true_ volume reference number is a unique number that is
assigned to a volume at the time it is mounted.  This includes your
startup volume (which is usually your internal HD), any external HD's,
any floppy you insert, any CD you insert, and any remote network
"volumes" that you connect to, and any other types that I haven't
thought of.  Each of these gets its own volume ref. num.  A volume ref.
num. is always a small negative number, and as far as I can tell the
number increments (negatively) as each volume is mounted: that is, your
startup volume is almost certain to be "-1", the next volume to mount
will be "-2", and so on.  However, I don't think that Apple guarantees
that they'll always be assigned in that order.

Note that the volume ref. num. is _only_ valid for as long as the volume
stays mounted (i.e., visible on your desktop).  When you mount a floppy
disk now, it may get a volume ref. num. of "-4".  If you drag that
floppy to the trash, and mount that same floppy again an hour from now
(even in the same disk drive), it may get a volume ref. num. of "-2" or
"-5" or something else.

> 2)  How can you get the vrefnum of a volume if you know it's name and/or
>     SCSI address?

If you know its name, then I would use the Toolbox function FN HGETVINFO
(called PBHGetVInfo in Inside Mac).  I can give you more info about the
calling parameters to use, if you want.  Note that this method is not
foolproof, since it's perfectly acceptable to have two (or more)
identically-named volumes mounted at the same time.

I'm not sure how you'd do it if you know the SCSI address.  There's a
different number called the "drive number" which is unique to each
connected disk drive (whether it's a SCSI device or not).  If you (or
someone) can figure out how to associate a SCSI address with a drive
number, then I can tell you how to associate the drive number with a
volume reference number.  Realize, though, that not every active SCSI
address is necessarily a disk drive, and not every SCSI disk drive
necessarily has a volume ref. num. associated with it (for example, it
might be a CD-ROM drive that's currently empty).  But if you're strictly
talking about non-ejectable SCSI hard drives, then there's probably a
1-to-1 correspondence between SCSI addresses and volume ref. numbers (at
least during the current session).

> 3)  How do you get the vrefnum of the startup disk?

It's _probably_ always safe to assume that the vrefnum of the startup
disk is "-1".  However, if you want to play it strictly by the rules,
you should probably do something like call FN FINDFOLDER to locate the
system folder's volume, as follows:

OSErr = FN FINDFOLDER(_kOnSystemDisk, _kSystemFolderType,
_kDontCreateFolder, vRefNum, dirID&)

This call will return the volume ref. num. of the startup volume into
vRefNum.

> 4)  How do vrefnums on shared disks work?

They work just fine. :-)
As mentioned above, when you mount a remote shared "volume" on your
desktop, it gets a unique volume ref. num. assigned to it like any other
volume.  Using a variation of FN HGETVINFO, you can index through all
the currently mounted volumes (including any remote ones) and get the
volume ref. num's for all of them.

Note that, if Fred shares "Fred's Hard Disk" on the network, and you
connect to it and mount it on your desktop, it will most likely _not_
have the same volume ref. num. on your system as it does when Fred looks
at it from _his_ system.  Indeed, "Fred's Hard Disk" might in reality
even be just a _folder_ (not a volume) on Fred's system, even though it
"looks" like a volume to your system when you connect to it.  The volume
reference number is a _local_ number that is good on the local system
only, even though the volume it refers to may physically be located on
another machine.  There is no way (that I know of) to find out what the
volume reference number is as seen from the _server's_ side (assuming it
even _is_ a volume from the server's point of view).

> 5)  What's the answer to the ultimate question of life, the universe, and
>     everything?

42.

Hope this is enlightening.
- Rick