Facts:
- VTOC (or EFI) is required to access slices of a disk device
- s2 slice is used to access whole disk (including VTOC on the disk beginning)
- new disk device comes without VTOC
- system: Solaris 10 OS, on SPARC architecture
Question: How can it be, that format is able write VTOC to a disk if it does not have a VTOC?
Question in detail: To create VTOC, format needs to write s2. To write s2, VTOC needs to exist. Simplified: to create VTOC, VTOC needs to exist. How this chicken and egg problem is avoided by format?
ext #1: if I label an un-labeled disk (c2t5006016041E076B0d8s2), the following happens:
[...]
11157: open("/dev/rdsk/c2t5006016041E076B0d8s2", O_RDWR|O_NDELAY) = 3
[...]
11157/1: write(1, " D i s k n o t l a b".., 33) = 33
11157/1: read(0, 0xFF2B9CD0, 1024) (sleeping...)
11157/1: read(0, " y\n", 1024) = 2
11157/1: open("/dev/rdsk/c3t5006016141E076B0d8s0", O_RDONLY|O_NDELAY) = 4
11157/1: ioctl(4, 0x0417, 0xFFBFED80) Err#22 EINVAL
11157/1: close(4) = 0
11157/1: ioctl(3, 0x04C9, 0xFFBFF52C) = 0
11157/1: ioctl(3, 0x0402, 0xFFBFF644) = 0
11157/1: ioctl(3, 0x0418, 0xFFBFF670) = 0
11157/1: ioctl(3, 0x04C9, 0xFFBFF5B4) = 0
11157/1: ioctl(3, 0x04C9, 0xFFBFF5B4) = 0
11157/1: ioctl(3, 0x04C9, 0xFFBFF5B4) = 0
11157/1: ioctl(3, 0x04C9, 0xFFBFF5B4) = 0
11157/1: ioctl(3, 0x04C9, 0xFFBFF5B4) = 0
11157/1: write(1, "\n\n F O R M A T M E N".., 15) = 15
[...]
what are those ioctl() calls? They cleanly do the job, but what are these calls actually?
The OS doesn't use read/write calls to read or write the vtoc. It just need to be able to successfully open the s2 device (which is just a symlink to the real device) to know if a disk is there. There is hopefully no need for the s2 slice to exist on the disk for this open to succeed. The format command then uses low level functions implemented in the device driver to access and write the vtoc. The ioctls you observed are precisely these calls.
eg.
At the raw level, the VTOC is just another block on the disk. However, it is always in the same location. format(1m) and fmthard(1m) manipulate the disk through the raw disk device (
/dev/rdsk/c...
) and directly access the sectors which should contain the VTOC - if one does not exist, they simply overwrite the existing contents of that sector.format(1M) does not need slices to work, it access the raw disk device and labels it. After the disk is labelled, the s2 slice is one way of addressing the whole disk.
On the other hand, fmthard cannot write a VTOC to a disk that isn't labelled. You have to label it first with format(1M).
I believe there is no chicken and egg problem, it's just that some utilities know to access a raw disk and write what's needed and other need more guidance with slices.