Boot Disk Icon
Volume Number: | | 5
|
Issue Number: | | 5
|
Column Tag: | | Programmer's Forum
|
Related Info: Finder Interface Device Manager
Change the Boot Disk Icon
By David Dunham, Goleta, CA
Ive been asked several times how my bootDiskIcon INIT works. I told the questioners that Id answer in MacTutor.
Also, this is a short article. MacTutor needs more of them -- I know how to initialize Managers and handle events, and I certainly dont need to see pictures in hexadecimal. (This isnt just a snide remark directed at the editor, its a plea to those with nifty ideas that dont need an entire application to show them off. Write a one or two page article!)
bootDiskIcon is a hack that came about because I dont own an HD20. Apple insists on portraying their internal hard disk as an HD 20 on my desktop. I got so disgusted with this that I wrote an INIT to show something else, anything but an HD 20. ICN# 256, in fact. bootDiskIcon is inferior to programs like Façade-- its less flexible, and may not work with all hard disks -- but it was better than nothing, and its easy to understand.
The key to bootDiskIcon is the way the Finder handles disk icons. A pedantic digression: how does one find out how Finder handles icons? Its not in Inside Macintosh. Therefore, it must be in a Technical Note. But Finder isnt a category in the table of contents. So its off to the index but its not listed under icon. Luckily, it was one of the Finder Tech Notes, number 28. How did I know to keep looking? Because Id seen it years ago when it came out, and knew it was there somewhere. Always skim every Tech Note -- not to memorize them, but to remember that theyre there.
When the Finder wants a disk icon, it gives the disk driver a Control call with csCode = 21. The driver returns a pointer to an ICN#. My first inclination was, why write code when you can change data? The ICN# must be part of the disk driver. The disk driver is part of Apple HD SC Setup. I found it there (its not a resource), changed it, and reinstalled the driver. This failed utterly -- theres apparently a checksum.
If I couldnt change the ICN# on disk, how about changing it in memory? I can get its address in memory by giving the driver a csCode = 21 call, then simply change the data. This is what bootDiskIcon does.
Before I get to what youre all waiting for, the source code, Ill mention the difference between patches and INITs. A patch is a change to a piece of code, almost always one of the traps. An INIT resource is any piece of code that runs at startup time (typically in a file of type INIT, cdev, or rdev). An INIT frequently installs a patch, but it could do anything at all, like playing a tune or subverting a disk drivers icon.
More ideological baggage: INITs should announce their presence. Paul Mercer has a good way to do this, called ShowINIT. Im told the source codes available on AppleLink. Ive modified it to handle color icons, and compiled the whole thing as a separate resource, SHOW 0. bootDiskIcon calls this code. Youre welcome to use it in any non-commercial (free or shareware) programs -- just use ResEdit to paste SHOW 0 into your own INIT file. You may not use it in public domain programs. These are those without a copyright holder, and I dont want my code in the public domain. Dont make the mistake of calling your free program public domain. Once you do, you cant get it back (despite what Adobe thinks).
We can almost get to the code, but you might be wondering how to test it. Its real inconvenient to reboot, just to see if a change worked. Luckily, you dont have to. Remember that an INIT is just a piece of code that happens to get executed at boot time. You can often execute the same code at any time, and instruct your development system to make an INIT resource when youre finished debugging. In bootDiskIcons case, I simply executed it, juggled into the Finder layer, and verified that Id chant the code. It starts out by calling my SHOW resource -- the parameters are reversed from the way theyre defined because my ShowICON is defined as a Pascal procedure. My sloppiness in not defining it as such in this C program probably works only because this is an INIT -- if I trash the stack, it doesnt much matter, since Ill be returning to INIT 31 very soon.
The real work begins with finding out the driver refNum and drive of the first mounted disk (now you know why its called bootDiskIcon -- I told you it was a quick hack). I then find the address of the drivers ICN#, get an ICN# of my own choice, and overwrite the drivers using BlockMove.
#include <deviceMgr.h>
#include <hfs.h>
#define NIL 0L
void main(void);/* Always use prototypes! */
void main() {
Ptr icn;
int error; /* Shouldnt really be write-only */
HParamBlockRec pb;
cntrlParam cpb;
Handle handle;
/* Show icon on the bottom of the screen */
handle = GetResource(SHOW,0); /* Get handle to the PROC */
if (handle == 0L) { /* Somethings wrong (couldnt load) */
SysBeep(32); /* Let somebody know */
return;/* Dont try to call it! */
}
HLock(handle); /* Hold down the PROC */
(**(ProcPtr *)handle)(-1,128);
/* ShowICON() -- note reversed parameters */
HUnlock(handle);/* Let it float in the heap again */
/* Change the icon */
pb.volumeParam.ioNamePtr = NIL;
pb.volumeParam.ioVolIndex = 1; /* First mounted volume */
error = PBHGetVInfo(&pb,FALSE);
cpb.ioRefNum = pb.volumeParam.ioVDRefNum;
cpb.ioVRefNum = pb.volumeParam.ioVDrvInfo;
/* drive (ioDrvNum) */
cpb.csCode = 21;
error = PBControl(&cpb,FALSE);
icn = *(Ptr *)(&cpb.csParam[0]);
handle = GetResource(ICN#,256);
BlockMove(*handle,icn,256L);
}
Known Bugs
Actually, these are rumored bugs, because it works for me! Im told it doesnt work with Jasmine disks where the driver puts the SCSI ID inside the flower. It probably doesnt work with a boot floppy, because the Finder normally special cases the disk icon. (Furthermore, Finder probably doesnt consider floppies to be foreign drives.)