Chapter 6.0 Continues...

Back to Sections 6.0 through 6.5.4
6.6 Mounting Macintosh Volumes
6.6.1 Mounting Permissions
6.6.2 Automatic Mounting of Removable Media
6.6.3 Unmounting Macintosh Volumes
6.6.4 Automatic Unmounting
6.6.5 Formatting Floppies
6.7 Accessing Macintosh Files from UNIX Applications
6.7.1 AppleSingle Encapsulation
6.7.2 Differentiating UNIX and Macintosh Files
6.7.3 Utilities for Manipulating Macintosh Files
6.7.3.1 dfork and rfork
6.7.3.2 finderinfo
6.7.3.3 restool
6.8 Text File Manipulation
6.8.1 Alternating Between Macintosh and UNIX Text
6.8.1.1 mactext
6.8.1.2 unixtext
6.8.1.3 Unix <-> Text
6.8.1.4 dfork.text
6.8.2 Editing Tools
6.8.2.1 Unix Editors
6.8.2.2 Macintosh Editing Applications
6.8.3 UNIX to Macintosh "Copy and Paste"
6.9 File System Administration
6.9.1 Creating File Systems
6.9.1.1 Creating an FFS Within a File
6.9.1.2 Creating an FFS on a Partition
6.9.2 Checking/Repairing File Systems
6.9.2.1 fsck
6.9.2.2 Fast File First Aid
6.9.3 Mounting File Systems
6.9.3.1 Mounting an FFS Within a File
6.9.3.2 Mounting an FFS on a Partition
6.9.3.3 Mounting a Macintosh Volume
6.9.4 Unmounting File Systems
6.9.5 Removing File Systems
6.9.5.1 Removing an FFS Within a File
6.9.5.2 Removing an FFS on a Partition
6.9.6 Space Management
6.9.7 Backing Up and Archiving File Systems
6.9.7.1 Tape Devices
6.9.7.2 tar
6.9.7.3 dump and restore


6.6 Mounting Macintosh Volumes

CodeBuilder stores UNIX files on Macintosh volumes alongside Macintosh files. Since all Macintosh volumes are formatted with the Macintosh Hierarchical File System (HFS), it is not necessary to use the traditional UNIX file system formatting commands (mkfs, fsck, etc.).

In CodeBuilder, the mount(8) command has been modified to accept a Macintosh volume name in addition to a UNIX device name for mounting local file systems. When CodeBuilder is started, the root folder of the volume from which CodeBuilder was launched is automatically mounted as "//".

Once CodeBuilder is running, any other Macintosh volume may be mounted. For example, to mount an external hard disk named "External Disk" on the path /external and to mount a floppy disk named "Untitled" on the path /volume/Untitled, the following commands may be used:
mkdir /external /volume/Untitled
mount "External Disk" /external
mount Untitled /volume/Untitled
Note that the path where the volume is to be mounted must exist (/volume is created by the CodeBuilder installation program), and that volume names with spaces must be contained within quotes.

UNIX provides a database file (/etc/fstab) to specify the path on which each file system is to be mounted. In CodeBuilder, the format of this file has also been extended to accept Macintosh volume names, just like the mount command. (See fstab(5).)


6.6.1 Mounting Permissions

Since CodeBuilder is targeted for a single user, non-networked system, the mount and umount commands have been set to run as root. This allows you to login as a normal user and still be able to mount or unmount file systems without having to su to gain temporary root privileges.


6.6.2 Automatic Mounting of Removable Media

CodeBuilder provides a special UNIX daemon - macmntd(8) - to handle automatic mounting of removable media like floppies, CDs, and Bernoulli, Jaz, Syquest, and Zip disks. Macmntd watches for disk inserted events and passes the volume name of the inserted disk to the mount command. If an entry for this volume exists in the /etc/fstab file, the volume will be automatically mounted on the specified path. If no entry exists, macmntd will create a directory named /volume/<volume name> and mount the volume on this directory.

Once mounted, whether automatically or explicitly by the mount command, the volume can be used as a normal UNIX file system. If you look in the /volume directory, you will see the floppy_name directory. To change to the directory to see the files on your floppy, the commands are as follows:
cd /volume/<volume_name>
ls
Now you can perform any valid operation on those files, such as copying (cp(1)), moving (mv(1)), or executing (by typing the name of the file followed by a carriage return).


6.6.3 Unmounting Macintosh Volumes

In CodeBuilder, the umount(8) command has been modified to accept Macintosh Volume Names for unmounting file systems. To unmount the volumes mounted in the example above, use:
umount "External Disk"
umount Untitled (floppy will not eject)

6.6.4 Automatic Unmounting

In CodeBuilder, Macintosh volumes will be automatically unmounted when the Finder is used to drag the disk to the Trash.


6.6.5 Formatting Floppies

In UNIX, it is often desirable to write directly to a device (disk) without regard for file system structures. CodeBuilder permits this type of raw access. Under CodeBuilder you can format a floppy for use as a raw device. If you do not give the floppy a Macintosh volume name, the floppy will automatically be formatted as a raw device. If CodeBuilder is the front application when you insert an unformatted floppy, a dialog box will prompt you to supply a name; simply choose Cancel. If, instead, you name the floppy, it will get a Macintosh volume name. Beware that using a null name results in a floppy with "???" for a Macintosh volume name. Raw floppies are not seen by the Finder, so no icon will appear on the Finder desktop.

To eject a raw floppy, use the eject(1) command. The eject command is:
eject 1 (floppy will eject)
CodeBuilder devices for accessing floppies are /dev/rfd0 and /dev/rfd1 to provide traditional raw access, and /dev/fd0 and /dev/fd1 to buffer floppy accesses in 512 byte blocks. You can determine what number device you have by experimenting with the eject command. A Macintosh with a single floppy drive typically uses the fd1/rfd1 device. Raw floppies may be accessed via tar(1), for example, but they cannot be mounted.


6.7 Accessing Macintosh Files from UNIX Applications

6.7.1 AppleSingle Encapsulation

In contrast to UNIX files which have only one stream of data, Macintosh files may have two streams (or forks) of data. These streams are called the data fork and the resource fork. In order to preserve all of the data in a Macintosh file when it is accessed by a UNIX application, it is necessary to encapsulate the two streams of data into a single stream. Consider the case of using the UNIX cp(1) command to copy a Macintosh file. It is most desirable that both forks of the file be copied from the source to the destination. Apple has defined a standard for the encapsulation of Macintosh files into a single stream known as the AppleSingle format. CodeBuilder uses this method of encapsulation.


6.7.2 Differentiating UNIX and Macintosh Files

In order to determine whether or not a file must be encapsulated in the AppleSingle format, it is necessary to be able differentiate UNIX files from Macintosh files. Since CodeBuilder uses the file creator 'MUMM' for all UNIX files, all files with any creator other than 'MUMM' must be Macintosh files. Therefore any file with a creator other than "MUMM' is automatically encapsulated in the AppleSingle format by CodeBuilder when the file is accessed by UNIX applications. Conversely, when an AppleSingle format file is written by a UNIX application, such as tar(1), CodeBuilder automatically recreates a proper Macintosh file, with the specified data and/or resource forks.


6.7.3 Utilities for Manipulating Macintosh Files

6.7.3.1 dfork and rfork

CodeBuilder provides a UNIX filter - dfork(1) - which reads an AppleSingle format file from its standard input and writes only the data fork to the standard output. CodeBuilder also provides a filter - rfork(1) - which reads an AppleSingle format file from its standard input and writes only the Resource Fork to the standard output.


6.7.3.2 finderinfo

CodeBuilder provides a UNIX utility - finderinfo(1) - for accessing and changing the Finder information of a Macintosh file, such as creator and type. Options to finderinfo specify the which Finder information fields to change. The following command illustrates changing the creator to 'MUMM' and type to 'TEXT' for a Macintosh file:
finderinfo -C MUMM -T TEXT Macintosh_file
Note that using this utility does not change the data in either fork of a file in any way.


6.7.3.3 restool

CodeBuilder provides a UNIX utility - restool(1) - for merging the resources of one (or more) Macintosh file(s) into another. restool requires the services of the Macintosh Resource Manager, thus can only work with UFS files.


6.8 Text File Manipulation

CodeBuilder gives you the capability to integrate UNIX-created ASCII text files into documents that have been created by Macintosh word processor programs, such as Microsoft Word, and to export Macintosh-created text to UNIX applications.


6.8.1 Alternating Between Macintosh and UNIX Text

Since the Macintosh and UNIX text file formats differ in the choice of line terminator, it may in some cases be necessary to translate the data from one format to the other. CodeBuilder provides several mechanisms to convert text files from the Macintosh format to the UNIX format. Choosing the mechanism that works best depends upon the particular situation. Factors such as how the text is created, how it is most often accessed, and how it is archived may influence your decision on which tools work best for you.

6.8.1.1 mactext

CodeBuilder provides a common text file format which permits UNIX text files to be successfully accessed by both UNIX and Macintosh applications. These files have the creator 'MUMM' and type 'TEXT' and are referred to as MUMM/TEXT files. These files are stored on the file system in the Macintosh text file format, so Macintosh applications can access them normally. CodeBuilder automatically translates MUMM/TEXT files to the UNIX text file format when they are accessed by UNIX applications. The mactext(1) utility program will create MUMM/TEXT files from traditional UNIX files (type 'BINA', 'nl' termination). The resultant file will be recognizable by UNIX and Macintosh applications.


6.8.1.2 unixtext

The unixtext(1) utility program will convert a standard Macintosh text file (type 'TEXT') with 'cr' character line termination to a standard UNIX text file (MUMM/BINA) with 'nl' character line termination. The resultant file will not be accessible by Macintosh word processors. This command is useful when copying a Macintosh text file to a remote non-CodeBuilder UNIX system for access by the remote system.


6.8.1.3 Unix <-> Text

The Unix <-> Text application in the Utilities folder on the CodeBuilder CD performs the functions of mactext and unixtext using a Macintosh user interface. You can use the Finder to drag MUMM/BINA files on top of the Unix <-> Text icon to create CodeBuilder common text file format files or to convert Macintosh text files to MUMM/BINA files. Unix <-> Text only works on Macintosh files that have been saved in "Text Only" mode. In most applications this is done by choosing "Save As ..." from the File menu.


6.8.1.4 dfork.text

CodeBuilder provides the UNIX utility program dfork.text(1) which extracts the data fork from its standard input (typically a Macintosh text file), translates the 'cr' character to 'nl', and produces the results on its standard output. This utility is useful if you want to leave the original Macintosh file untouched and make a copy of its text for access by some UNIX utilities. For example, to search for a specific word in a Macintosh text file using the UNIX utility grep(1), try:
dfork.text <Macintosh file> | grep <pattern>

6.8.2 Editing Tools

6.8.2.1 Unix Editors

UNIX provides a number of text editing programs such as vi(1), ex(1), and ed(1). Another popular UNIX editor is GNU Emacs. UNIX text editing programs will operate correctly on all CodeBuilder text files of type 'BINA', as well as files in the CodeBuilder common text format (MUMM/TEXT). They will not recognize Macintosh TEXT files due to the line termination differences described above.


6.8.2.2 Macintosh Editing Applications

A few Macintosh editing applications may be found on the CodeBuilder CD in the subfolder "Utilities: Text Utilities". Please be sure to register any shareware that you decide to use on an ongoing basis.


6.8.3 UNIX to Macintosh "Copy and Paste"

Using conventional Macintosh "copy-and-paste" techniques, you can copy text from a UNIX terminal screen directly to a Macintosh application.


6.9 File System Administration

6.9.1 Creating File Systems

To create an FFS you must decide how large you want it, and whether to place it within a file or on a partition. When sizing the file system, keep in mind that about 4% of space goes to overhead and that (by default) 10% is held as a reserve. When free space falls below the reserve, new files may only be opened by root. A different reserve percentage may be set during file system creation.

Since UFS file systems are simply Macintosh HFS volumes viewed through a UNIX lens, there are no CodeBuilder activities to take other than creating the directories on which to mount them.


6.9.1.1 Creating an FFS Within a File

To create an FFS within a file, first decide on the amount of storage you need. Identify the HFS volume that will accommodate it, and if necessary, mount it for access under CodeBuilder. Then use the newfsf(8) command as follows:
newfsf -s size FSFile_pathname
where size is the number of 512 byte blocks that provide the desired storage, and pathname specifies the name of the FFS file to create.

Following creation, an FFS within a file must be mounted under CodeBuilder before it can be used. If necessary, create the directory on which you will mount it. The mount command syntax is as follows:
/sbin/mount -t ffs FSFile-pathname directory
If you plan on using this file system on a regular basis, consider entering an entry in /etc/fstab so that it is automatically mounted on each launch of CodeBuilder. Beware that the start-up script /etc/rc will stop if any FFS specified in /etc/fstab is not available during launch.


6.9.1.2 Creating an FFS on a Partition

There are several steps to creating an FFS on a partition. The partition must reside on a SCSI disk. If you don't already have an A/UX partition of desired size, use a Macintosh formatting application to create one. Create the character and block device files for the target SCSI id if they don't already exist. Use disklabel to review the mapping of Macintosh disk partition names to UNIX partition letters. Then create the file system. Execute the following commands as root, as necessary:
cd /dev; ./MAKEDEV sd#
/sbin/disklabel sd#
/sbin/newfs sd#P
where '#' represents the numeric SCSI device number, and 'P' represents the partition.

Following creation, an FFS on a partition must be mounted under CodeBuilder before it can be used. If necessary, create the directory on which you will mount it. The mount command syntax is as follows:
/sbin/mount -t ffs /dev/sd#P directory
If you plan on using this file system on a regular basis, consider entering an entry in /etc/fstab so that it is automatically mounted on each launch of CodeBuilder. Beware that the start-up script /etc/rc will stop if any FFS specified in /etc/fstab is not available during launch.


6.9.2 Checking/Repairing File Systems

A chief FFS maintenance activity is the periodic checking and repairing of FFS bookkeeping structures using the fsck(8) utility. During start-up, CodeBuilder automatically checks each FFS registered in /etc/fstab unless the file /clean_start exists. This file is only present if CodeBuilder was cleanly shutdown on the prior launch.

The Macintosh File Manager assumes responsibility for checking and make minor repairs to Macintosh HFS volumes. Other Macintosh applications, such as Disk First Aid, perform more extensive checks and repairs. Therefore, CodeBuilder takes no additional action to check or repair UFS file systems.


6.9.2.1 fsck

Whenever the state of an FFS is in doubt, run fsck(8) to check and correct the consistency of the FFS bookkeeping information. The following two commands illustrate how to check an FFS within a file, and an FFS on a partition:
/sbin/fsck FSFile_pathname
/sbin/fsck /dev/rsd#P
where '#' represents the numeric SCSI device number, and 'P' represents the partition.


6.9.2.2 Fast File First Aid

The fsck utility is also available as the stand-alone Macintosh application 'Fast File First Aid', located on the CodeBuilder CD in the subfolder "Utilities: Fast File Utilities". It should be used when CodeBuilder in unable to boot due to root file system damage. It performs a more aggressive and interactive repair of specified FFS files. The document fsck.pdf on the CodeBuilder CD in the subfolder "Documentation: CodeBuilder UNIX Docs: SysAdmin's Docs(smm)" contains some information that may be useful in this process.


6.9.3 Mounting File Systems

File systems must be mounted before they may be accessed under CodeBuilder. During start-up, CodeBuilder kernel automatically mounts the root file system ("/") and the root folder of the Macintosh volume on which CodeBuilder resides ("//"). The /etc/rc script optionally mounts file systems registered in /etc/fstab. If CodeBuilder is not running on the boot volume, the boot volume will be mounted on /bootvol by the /etc/rc script.


6.9.3.1 Mounting an FFS Within a File

To mount an FFS within a file:
/sbin/mount -t ffs FSFile_pathname directory

6.9.3.2 Mounting an FFS on a Partition

To mount an FFS on a partition:
/sbin/mount -t ffs /dev/sd#P directory

6.9.3.3 Mounting a Macintosh Volume

To mount a Macintosh volume:
/sbin/mount "Mac Volume" directory

6.9.4 Unmounting File Systems

Unmounting FFS and UFS file systems is done with the umount command. Its argument may be a mount point pathname, an FFS filename, a partition's device name, or a Macintosh volume name. Any argument that contains special characters, such as a space, should be quoted.
/sbin/umount /mnt
/sbin/umount FSFile_pathname
/sbin/umount /dev/sd#P
/sbin/umount "Mac Volume"

6.9.5 Removing File Systems

When an FFS is no longer needed, its space should be returned for other purposes. The first action is to unmount it. The second is to remove any entry in /etc/fstab that automatically mounts it. The third is to remove it as described in the appropriate section below.


6.9.5.1 Removing an FFS Within a File

Delete an FFS file with Finder, or the command:
rm -f FSFile_pathname

6.9.5.2 Removing an FFS on a Partition

To reuse the partition for a new FFS, the suggested procedure is to completely reinitialize the file system:
/sbin/newfs sd#P
For non-CodeBuilder use, you may find it necessary to use a Macintosh formatting application to initialize the partition.


6.9.6 Space Management

When running any UNIX system, the percentage of disk space used under normal operation can increase until all of the allocated space is used up. When the file system becomes full, processes run very slowly, if at all, and the system is kept busy notifying the user that the file system is full. The main general administrative role, with respect to the file system, is keeping the size (and number) of temporary UNIX working files under control.

The following techniques are available to keep the file system manageable: On a single user system, you will monitor your own usage.

By default, /etc/rc contains commands to preserve editor temporary files before removing files from /tmp during system start-up.

The following directories and files should be watched for growth:
/tmp
/etc/wtmp (if created by the user)
/var/log/syslog
/var/adm/messages
The system administrator may need to create some directories that log administrative messages. If administrative files do not already exist, simply type:
touch <filename>
to create and timestamp a zero length file.


6.9.7 Backing Up and Archiving File Systems

Backing up and archiving are two methods of file system protection. Backing up involves making a complete copy of a file system onto another hard disk or a removable medium such as tape, Jaz, Zip, Bernoulli, or Syquest. Archiving usually involves storage of specific files, on similar media as for backups, or even Macintosh floppies. Archiving may be done for preserving development milestones, or for recapturing space consumed by large, infrequently used files that can be restored when required. Backups should be done on a regular basis to prevent losses due to disk failure or human error. Archives should be done as needed.

There are three programs that are useful for backup and archiving: tar, dump, and restore. tar may be used both to write and read backups or archives. It writes a portable, structured image that is independent of the source file system. dump and restore may be used for complete and incremental backups of FFS file systems. They are file system structure dependent.


6.9.7.1 Tape Devices

CodeBuilder supports DAT (4mm) and Exabyte (8mm) tape drives. The CodeBuilder tape interface has been designed to support a generic SCSI tape device and has been tested specifically using the following mechanisms:
DAT Models using the Archive Python tape drive
(e.g., "ClubMac" and "Wang DAT 2600")

Exabyte Model EXB-8200
CodeBuilder can be configured to simultaneously support up to four tape drives, and is configured by default for a single tape device (e.g., 'MAKEDEV mt0' in the following example has already been done). Additional tape device files may be created by executing the following commands (see mtio(4) and /dev/MAKEDEV):
# cd /dev
# ./MAKEDEV mt1
# ./MAKEDEV mt2
# ./MAKEDEV mt3
CodeBuilder uses four device files for each tape drive. For example, the following device files apply to the first tape drive, unit 0. CodeBuilder uses a scan of the SCSI chain (from ID-6 to ID-0) to identify tape subsystems and associate them with unit numbers. The first tape drive found is unit 0, the second is unit 1, and so on.
/dev/rmt0 -- unit 0, rewind on close
/dev/rmt4 -- unit 0, no rewind on close
/dev/rmt8 -- unit 0, compressed, rewind on close
/dev/rmt12 -- unit 0, compressed, no rewind on close
The minor device number encodes two attributes - whether or not to rewind the tape on completion, and whether or not to use compression (if supported by the tape hardware).


6.9.7.2 tar

The tape device files may be used to read and write tapes using tar, dd, and other utilities. Tar may be used to back up both FFS and local Mac volumes. Macintosh files will be written in AppleSingle format to preserve both the resource and data forks of the file.

An additional utility mt is provided with CodeBuilder to position, rewind, and off-load tapes. It may also be used to print out tape information (see mt(1)).

Example 1:
Example of archiving your entire CodeBuilder file system to tape using a blocking factor of 64, hardware compression, and rewinding the tape when the backup is finished:
# tar cvfb /dev/rmt8 64 /

Example 2:
Example of archiving two different volumes in two different save sets on a single tape using a blocking factor of 64, hardware compression, and then rewinding the tape when the second archive is finished.
# tar cvfb /dev/rmt12 64 /volumes/MacDisk1
# mt -f /dev/rmt12 eof 1
# tar cvfb /dev/rmt12 64 /volumes/MacDisk2
# mt -f /dev/rmt8 eof 1
Note that the mt utility is used to place an <End Of File> marker on the tape after each save set. Doing this enables the mt utility to find any of the save sets by searching for the <EOF> marker from the beginning of the tape. For example, use the following commands to find the start of the second save set in the above example, and then restore /volumes/MacDisk2:
# mt -f /dev/rmt12 fsf 1
# tar xvfbp /dev/rmt12 64

6.9.7.3 dump and restore

Complete and incremental backups of FFS file systems may be done with dump. Recovery of files is done using restore. These tools are not useful on UFS file systems. Details for using dump and restore are provided in the on-line man pages.



[ Top of Page ][ 7.0 Printing][ Table of Contents ]