How can Solaris format write to a disk without a vtoc being present

hard drivesolaris

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?

Best Answer

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.

  • 0x0417 = DKIOCGEXTVTOC (get extended vtoc)
  • 0x0402 = DKIOCSGEOM (set geometry)
  • 0x0418 = DKIOCSEXTVTOC (write extended vtoc to disk)