17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate */ 227c478bd9Sstevel@tonic-gate /* 237c478bd9Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #include <stdio.h> 307c478bd9Sstevel@tonic-gate #include <stdlib.h> 317c478bd9Sstevel@tonic-gate #include <libgen.h> 327c478bd9Sstevel@tonic-gate #include <malloc.h> 337c478bd9Sstevel@tonic-gate #include <string.h> 347c478bd9Sstevel@tonic-gate #include <sys/types.h> 357c478bd9Sstevel@tonic-gate #include <sys/stat.h> 367c478bd9Sstevel@tonic-gate #include <fcntl.h> 377c478bd9Sstevel@tonic-gate #include <unistd.h> 387c478bd9Sstevel@tonic-gate #include <strings.h> 397c478bd9Sstevel@tonic-gate #include <sys/mount.h> 407c478bd9Sstevel@tonic-gate #include <sys/mnttab.h> 417c478bd9Sstevel@tonic-gate #include <sys/dktp/fdisk.h> 427c478bd9Sstevel@tonic-gate 437c478bd9Sstevel@tonic-gate #include <libintl.h> 447c478bd9Sstevel@tonic-gate #include <locale.h> 457c478bd9Sstevel@tonic-gate #include "message.h" 46*c6fe1048Sjongkis #include <errno.h> 477c478bd9Sstevel@tonic-gate 487c478bd9Sstevel@tonic-gate #ifndef TEXT_DOMAIN 497c478bd9Sstevel@tonic-gate #define TEXT_DOMAIN "SUNW_OST_OSCMD" 507c478bd9Sstevel@tonic-gate #endif 517c478bd9Sstevel@tonic-gate 527c478bd9Sstevel@tonic-gate #define SECTOR_SIZE 0x200 537c478bd9Sstevel@tonic-gate #define STAGE2_MEMADDR 0x8000 /* loading addr of stage2 */ 547c478bd9Sstevel@tonic-gate 557c478bd9Sstevel@tonic-gate #define STAGE1_BPB_OFFSET 0x3 567c478bd9Sstevel@tonic-gate #define STAGE1_BPB_SIZE 0x3B 577c478bd9Sstevel@tonic-gate #define STAGE1_BOOT_DRIVE 0x40 587c478bd9Sstevel@tonic-gate #define STAGE1_FORCE_LBA 0x41 597c478bd9Sstevel@tonic-gate #define STAGE1_STAGE2_ADDRESS 0x42 607c478bd9Sstevel@tonic-gate #define STAGE1_STAGE2_SECTOR 0x44 617c478bd9Sstevel@tonic-gate #define STAGE1_STAGE2_SEGMENT 0x48 627c478bd9Sstevel@tonic-gate 637c478bd9Sstevel@tonic-gate #define STAGE2_BLOCKLIST (SECTOR_SIZE - 0x8) 647c478bd9Sstevel@tonic-gate #define STAGE2_INSTALLPART (SECTOR_SIZE + 0x8) 657c478bd9Sstevel@tonic-gate #define STAGE2_FORCE_LBA (SECTOR_SIZE + 0x11) 667c478bd9Sstevel@tonic-gate #define STAGE2_VER_STRING (SECTOR_SIZE + 0x12) 677c478bd9Sstevel@tonic-gate #define STAGE2_BLKOFF 50 /* offset from start of fdisk part */ 687c478bd9Sstevel@tonic-gate 697c478bd9Sstevel@tonic-gate static int nowrite = 0; 707c478bd9Sstevel@tonic-gate static int write_mboot = 0; 717c478bd9Sstevel@tonic-gate static int force_mboot = 0; 727c478bd9Sstevel@tonic-gate static int is_floppy = 0; 737c478bd9Sstevel@tonic-gate static int is_bootpar = 0; 747c478bd9Sstevel@tonic-gate static int stage2_fd; 757c478bd9Sstevel@tonic-gate static int partition, slice = 0xff; 767c478bd9Sstevel@tonic-gate static int stage2_first_sector, stage2_second_sector; 777c478bd9Sstevel@tonic-gate 787c478bd9Sstevel@tonic-gate 797c478bd9Sstevel@tonic-gate static char bpb_sect[SECTOR_SIZE]; 807c478bd9Sstevel@tonic-gate static char boot_sect[SECTOR_SIZE]; 817c478bd9Sstevel@tonic-gate static char stage1_buffer[SECTOR_SIZE]; 827c478bd9Sstevel@tonic-gate static char stage2_buffer[2 * SECTOR_SIZE]; 837c478bd9Sstevel@tonic-gate static int blocklist[SECTOR_SIZE / sizeof (int)]; 847c478bd9Sstevel@tonic-gate 857c478bd9Sstevel@tonic-gate static int open_device(char *); 867c478bd9Sstevel@tonic-gate static void read_bpb_sect(int); 877c478bd9Sstevel@tonic-gate static void read_boot_sect(char *); 887c478bd9Sstevel@tonic-gate static void write_boot_sect(char *); 897c478bd9Sstevel@tonic-gate static void read_stage1_stage2(char *, char *); 907c478bd9Sstevel@tonic-gate static void modify_and_write_stage1(int); 917c478bd9Sstevel@tonic-gate static void modify_and_write_stage2(int); 927c478bd9Sstevel@tonic-gate static int get_start_sector(); 937c478bd9Sstevel@tonic-gate static void copy_stage2(int, char *); 947c478bd9Sstevel@tonic-gate static char *get_raw_partition(char *); 957c478bd9Sstevel@tonic-gate static void usage(char *); 967c478bd9Sstevel@tonic-gate 977c478bd9Sstevel@tonic-gate extern int read_stage2_blocklist(int, int *); 987c478bd9Sstevel@tonic-gate 997c478bd9Sstevel@tonic-gate int 1007c478bd9Sstevel@tonic-gate main(int argc, char *argv[]) 1017c478bd9Sstevel@tonic-gate { 1027c478bd9Sstevel@tonic-gate int dev_fd, opt; 1037c478bd9Sstevel@tonic-gate char *stage1, *stage2, *device; 1047c478bd9Sstevel@tonic-gate 1057c478bd9Sstevel@tonic-gate (void) setlocale(LC_ALL, ""); 1067c478bd9Sstevel@tonic-gate (void) textdomain(TEXT_DOMAIN); 1077c478bd9Sstevel@tonic-gate 1087c478bd9Sstevel@tonic-gate while ((opt = getopt(argc, argv, "fmn")) != EOF) { 1097c478bd9Sstevel@tonic-gate switch (opt) { 1107c478bd9Sstevel@tonic-gate case 'm': 1117c478bd9Sstevel@tonic-gate write_mboot = 1; 1127c478bd9Sstevel@tonic-gate break; 1137c478bd9Sstevel@tonic-gate case 'n': 1147c478bd9Sstevel@tonic-gate nowrite = 1; 1157c478bd9Sstevel@tonic-gate break; 1167c478bd9Sstevel@tonic-gate case 'f': 1177c478bd9Sstevel@tonic-gate force_mboot = 1; 1187c478bd9Sstevel@tonic-gate break; 1197c478bd9Sstevel@tonic-gate default: 1207c478bd9Sstevel@tonic-gate /* fall through to process non-optional args */ 1217c478bd9Sstevel@tonic-gate break; 1227c478bd9Sstevel@tonic-gate } 1237c478bd9Sstevel@tonic-gate } 1247c478bd9Sstevel@tonic-gate 1257c478bd9Sstevel@tonic-gate /* check arguments */ 1267c478bd9Sstevel@tonic-gate if (argc != optind + 3) { 1277c478bd9Sstevel@tonic-gate usage(argv[0]); 1287c478bd9Sstevel@tonic-gate } 1297c478bd9Sstevel@tonic-gate 1307c478bd9Sstevel@tonic-gate if (nowrite) { 1317c478bd9Sstevel@tonic-gate (void) fprintf(stdout, DRY_RUN); 1327c478bd9Sstevel@tonic-gate } 1337c478bd9Sstevel@tonic-gate 1347c478bd9Sstevel@tonic-gate stage1 = strdup(argv[optind]); 1357c478bd9Sstevel@tonic-gate stage2 = strdup(argv[optind + 1]); 1367c478bd9Sstevel@tonic-gate device = strdup(argv[optind + 2]); 1377c478bd9Sstevel@tonic-gate 1387c478bd9Sstevel@tonic-gate if (!stage1 || !stage2 || !device) { 1397c478bd9Sstevel@tonic-gate usage(argv[0]); 1407c478bd9Sstevel@tonic-gate } 1417c478bd9Sstevel@tonic-gate 1427c478bd9Sstevel@tonic-gate /* open and check device type */ 1437c478bd9Sstevel@tonic-gate dev_fd = open_device(device); 1447c478bd9Sstevel@tonic-gate 1457c478bd9Sstevel@tonic-gate /* read in stage1 and stage2 into buffer */ 1467c478bd9Sstevel@tonic-gate read_stage1_stage2(stage1, stage2); 1477c478bd9Sstevel@tonic-gate 1487c478bd9Sstevel@tonic-gate /* In the pcfs case, write a fresh stage2 */ 1497c478bd9Sstevel@tonic-gate if (is_floppy || is_bootpar) { 1507c478bd9Sstevel@tonic-gate copy_stage2(dev_fd, device); 1517c478bd9Sstevel@tonic-gate read_bpb_sect(dev_fd); 1527c478bd9Sstevel@tonic-gate } 1537c478bd9Sstevel@tonic-gate 1547c478bd9Sstevel@tonic-gate /* read in boot sector */ 1557c478bd9Sstevel@tonic-gate if (!is_floppy) 1567c478bd9Sstevel@tonic-gate read_boot_sect(device); 1577c478bd9Sstevel@tonic-gate 1587c478bd9Sstevel@tonic-gate /* modify stage1 based on grub needs */ 1597c478bd9Sstevel@tonic-gate modify_and_write_stage1(dev_fd); 1607c478bd9Sstevel@tonic-gate 1617c478bd9Sstevel@tonic-gate /* modify stage2 and write to media */ 1627c478bd9Sstevel@tonic-gate modify_and_write_stage2(dev_fd); 1637c478bd9Sstevel@tonic-gate 1647c478bd9Sstevel@tonic-gate if (!is_floppy && write_mboot) 1657c478bd9Sstevel@tonic-gate write_boot_sect(device); 1667c478bd9Sstevel@tonic-gate (void) close(dev_fd); 1677c478bd9Sstevel@tonic-gate 1687c478bd9Sstevel@tonic-gate return (0); 1697c478bd9Sstevel@tonic-gate } 1707c478bd9Sstevel@tonic-gate 1717c478bd9Sstevel@tonic-gate static int 1727c478bd9Sstevel@tonic-gate get_start_sector() 1737c478bd9Sstevel@tonic-gate { 1747c478bd9Sstevel@tonic-gate static int start_sect = 0; 1757c478bd9Sstevel@tonic-gate 1767c478bd9Sstevel@tonic-gate int i; 1777c478bd9Sstevel@tonic-gate struct mboot *mboot; 1787c478bd9Sstevel@tonic-gate struct ipart *part; 1797c478bd9Sstevel@tonic-gate 1807c478bd9Sstevel@tonic-gate if (start_sect) 1817c478bd9Sstevel@tonic-gate return (start_sect); 1827c478bd9Sstevel@tonic-gate 1837c478bd9Sstevel@tonic-gate mboot = (struct mboot *)boot_sect; 1847c478bd9Sstevel@tonic-gate for (i = 0; i < FD_NUMPART; i++) { 1857c478bd9Sstevel@tonic-gate part = (struct ipart *)mboot->parts + i; 1867c478bd9Sstevel@tonic-gate if (is_bootpar) { 1877c478bd9Sstevel@tonic-gate if (part->systid == 0xbe) 1887c478bd9Sstevel@tonic-gate break; 1897c478bd9Sstevel@tonic-gate } else { 1907c478bd9Sstevel@tonic-gate if (part->systid == 0x82 || part->systid == 0xbf) 1917c478bd9Sstevel@tonic-gate break; 1927c478bd9Sstevel@tonic-gate } 1937c478bd9Sstevel@tonic-gate } 1947c478bd9Sstevel@tonic-gate 1957c478bd9Sstevel@tonic-gate if (i == FD_NUMPART) { 1967c478bd9Sstevel@tonic-gate (void) fprintf(stderr, BOOTPAR); 1977c478bd9Sstevel@tonic-gate exit(-1); 1987c478bd9Sstevel@tonic-gate } 1997c478bd9Sstevel@tonic-gate 2007c478bd9Sstevel@tonic-gate /* get confirmation for -m */ 2017c478bd9Sstevel@tonic-gate if (write_mboot && !force_mboot) { 2027c478bd9Sstevel@tonic-gate (void) fprintf(stdout, MBOOT_PROMPT); 2037c478bd9Sstevel@tonic-gate if (getchar() != 'y') { 2047c478bd9Sstevel@tonic-gate write_mboot = 0; 2057c478bd9Sstevel@tonic-gate (void) fprintf(stdout, MBOOT_NOT_UPDATED); 2067c478bd9Sstevel@tonic-gate } 2077c478bd9Sstevel@tonic-gate } 2087c478bd9Sstevel@tonic-gate 2097c478bd9Sstevel@tonic-gate start_sect = part->relsect; 2107c478bd9Sstevel@tonic-gate if (part->bootid != 128 && write_mboot == 0) { 2117c478bd9Sstevel@tonic-gate (void) fprintf(stdout, BOOTPAR_INACTIVE, i + 1); 2127c478bd9Sstevel@tonic-gate } 2137c478bd9Sstevel@tonic-gate 2147c478bd9Sstevel@tonic-gate partition = i; 2157c478bd9Sstevel@tonic-gate return (start_sect); 2167c478bd9Sstevel@tonic-gate } 2177c478bd9Sstevel@tonic-gate 2187c478bd9Sstevel@tonic-gate static void 2197c478bd9Sstevel@tonic-gate usage(char *progname) 2207c478bd9Sstevel@tonic-gate { 2217c478bd9Sstevel@tonic-gate (void) fprintf(stderr, USAGE, basename(progname)); 2227c478bd9Sstevel@tonic-gate exit(-1); 2237c478bd9Sstevel@tonic-gate } 2247c478bd9Sstevel@tonic-gate 2257c478bd9Sstevel@tonic-gate static int 2267c478bd9Sstevel@tonic-gate open_device(char *device) 2277c478bd9Sstevel@tonic-gate { 2287c478bd9Sstevel@tonic-gate int dev_fd; 2297c478bd9Sstevel@tonic-gate struct stat stat; 2307c478bd9Sstevel@tonic-gate char *raw_part; 2317c478bd9Sstevel@tonic-gate 2327c478bd9Sstevel@tonic-gate is_floppy = strncmp(device, "/dev/rdsk", strlen("/dev/rdsk")) && 2337c478bd9Sstevel@tonic-gate strncmp(device, "/dev/dsk", strlen("/dev/dsk")); 2347c478bd9Sstevel@tonic-gate 2357c478bd9Sstevel@tonic-gate /* handle boot partition specification */ 2367c478bd9Sstevel@tonic-gate if (!is_floppy && strstr(device, "p0:boot")) { 2377c478bd9Sstevel@tonic-gate is_bootpar = 1; 2387c478bd9Sstevel@tonic-gate } 2397c478bd9Sstevel@tonic-gate 2407c478bd9Sstevel@tonic-gate raw_part = get_raw_partition(device); 2417c478bd9Sstevel@tonic-gate 2427c478bd9Sstevel@tonic-gate if (nowrite) 2437c478bd9Sstevel@tonic-gate dev_fd = open(raw_part, O_RDONLY); 2447c478bd9Sstevel@tonic-gate else 2457c478bd9Sstevel@tonic-gate dev_fd = open(raw_part, O_RDWR); 2467c478bd9Sstevel@tonic-gate 2477c478bd9Sstevel@tonic-gate if (dev_fd == -1 || fstat(dev_fd, &stat) != 0) { 2487c478bd9Sstevel@tonic-gate (void) fprintf(stderr, OPEN_FAIL, raw_part); 2497c478bd9Sstevel@tonic-gate exit(-1); 2507c478bd9Sstevel@tonic-gate } 2517c478bd9Sstevel@tonic-gate if (S_ISCHR(stat.st_mode) == 0) { 2527c478bd9Sstevel@tonic-gate (void) fprintf(stderr, NOT_RAW_DEVICE, raw_part); 2537c478bd9Sstevel@tonic-gate exit(-1); 2547c478bd9Sstevel@tonic-gate } 2557c478bd9Sstevel@tonic-gate 2567c478bd9Sstevel@tonic-gate return (dev_fd); 2577c478bd9Sstevel@tonic-gate } 2587c478bd9Sstevel@tonic-gate 2597c478bd9Sstevel@tonic-gate static void 2607c478bd9Sstevel@tonic-gate read_stage1_stage2(char *stage1, char *stage2) 2617c478bd9Sstevel@tonic-gate { 2627c478bd9Sstevel@tonic-gate int fd; 2637c478bd9Sstevel@tonic-gate 2647c478bd9Sstevel@tonic-gate /* read the stage1 file from filesystem */ 2657c478bd9Sstevel@tonic-gate fd = open(stage1, O_RDONLY); 2667c478bd9Sstevel@tonic-gate if (fd == -1 || read(fd, stage1_buffer, SECTOR_SIZE) != SECTOR_SIZE) { 2677c478bd9Sstevel@tonic-gate (void) fprintf(stderr, READ_FAIL_STAGE1, stage1); 2687c478bd9Sstevel@tonic-gate exit(-1); 2697c478bd9Sstevel@tonic-gate } 2707c478bd9Sstevel@tonic-gate (void) close(fd); 2717c478bd9Sstevel@tonic-gate 2727c478bd9Sstevel@tonic-gate /* read first two blocks of stage 2 from filesystem */ 2737c478bd9Sstevel@tonic-gate stage2_fd = open(stage2, O_RDONLY); 2747c478bd9Sstevel@tonic-gate if (stage2_fd == -1 || 2757c478bd9Sstevel@tonic-gate read(stage2_fd, stage2_buffer, 2 * SECTOR_SIZE) 2767c478bd9Sstevel@tonic-gate != 2 * SECTOR_SIZE) { 2777c478bd9Sstevel@tonic-gate (void) fprintf(stderr, READ_FAIL_STAGE2, stage2); 2787c478bd9Sstevel@tonic-gate exit(-1); 2797c478bd9Sstevel@tonic-gate } 2807c478bd9Sstevel@tonic-gate /* leave the stage2 file open for later */ 2817c478bd9Sstevel@tonic-gate } 2827c478bd9Sstevel@tonic-gate 2837c478bd9Sstevel@tonic-gate static void 2847c478bd9Sstevel@tonic-gate read_bpb_sect(int dev_fd) 2857c478bd9Sstevel@tonic-gate { 2867c478bd9Sstevel@tonic-gate if (pread(dev_fd, bpb_sect, SECTOR_SIZE, 0) != SECTOR_SIZE) { 2877c478bd9Sstevel@tonic-gate (void) fprintf(stderr, READ_FAIL_BPB); 2887c478bd9Sstevel@tonic-gate exit(-1); 2897c478bd9Sstevel@tonic-gate } 2907c478bd9Sstevel@tonic-gate } 2917c478bd9Sstevel@tonic-gate 2927c478bd9Sstevel@tonic-gate static void 2937c478bd9Sstevel@tonic-gate read_boot_sect(char *device) 2947c478bd9Sstevel@tonic-gate { 2957c478bd9Sstevel@tonic-gate static int read_mbr = 0; 2967c478bd9Sstevel@tonic-gate int i, fd; 2977c478bd9Sstevel@tonic-gate char save[2]; 2987c478bd9Sstevel@tonic-gate 2997c478bd9Sstevel@tonic-gate if (read_mbr) 3007c478bd9Sstevel@tonic-gate return; 3017c478bd9Sstevel@tonic-gate read_mbr = 1; 3027c478bd9Sstevel@tonic-gate 3037c478bd9Sstevel@tonic-gate /* get the whole disk (p0) */ 3047c478bd9Sstevel@tonic-gate i = strlen(device); 3057c478bd9Sstevel@tonic-gate save[0] = device[i - 2]; 3067c478bd9Sstevel@tonic-gate save[1] = device[i - 1]; 3077c478bd9Sstevel@tonic-gate device[i - 2] = 'p'; 3087c478bd9Sstevel@tonic-gate device[i - 1] = '0'; 3097c478bd9Sstevel@tonic-gate 3107c478bd9Sstevel@tonic-gate fd = open(device, O_RDONLY); 3117c478bd9Sstevel@tonic-gate if (fd == -1 || read(fd, boot_sect, SECTOR_SIZE) != SECTOR_SIZE) { 3127c478bd9Sstevel@tonic-gate (void) fprintf(stderr, READ_FAIL_MBR, device); 3137c478bd9Sstevel@tonic-gate if (fd == -1) 3147c478bd9Sstevel@tonic-gate perror("open"); 3157c478bd9Sstevel@tonic-gate else 3167c478bd9Sstevel@tonic-gate perror("read"); 3177c478bd9Sstevel@tonic-gate exit(-1); 3187c478bd9Sstevel@tonic-gate } 3197c478bd9Sstevel@tonic-gate (void) close(fd); 3207c478bd9Sstevel@tonic-gate device[i - 2] = save[0]; 3217c478bd9Sstevel@tonic-gate device[i - 1] = save[1]; 3227c478bd9Sstevel@tonic-gate } 3237c478bd9Sstevel@tonic-gate 3247c478bd9Sstevel@tonic-gate static void 3257c478bd9Sstevel@tonic-gate write_boot_sect(char *device) 3267c478bd9Sstevel@tonic-gate { 3277c478bd9Sstevel@tonic-gate int fd, len; 3287c478bd9Sstevel@tonic-gate char *raw, *end; 3297c478bd9Sstevel@tonic-gate struct stat stat; 3307c478bd9Sstevel@tonic-gate 3317c478bd9Sstevel@tonic-gate /* make a copy and chop off ":boot" */ 3327c478bd9Sstevel@tonic-gate raw = strdup(device); 3337c478bd9Sstevel@tonic-gate end = strstr(raw, "p0:boot"); 3347c478bd9Sstevel@tonic-gate if (end) 3357c478bd9Sstevel@tonic-gate end[2] = 0; 3367c478bd9Sstevel@tonic-gate 3377c478bd9Sstevel@tonic-gate /* open p0 (whole disk) */ 3387c478bd9Sstevel@tonic-gate len = strlen(raw); 3397c478bd9Sstevel@tonic-gate raw[len - 2] = 'p'; 3407c478bd9Sstevel@tonic-gate raw[len - 1] = '0'; 3417c478bd9Sstevel@tonic-gate fd = open(raw, O_WRONLY); 3427c478bd9Sstevel@tonic-gate if (fd == -1 || fstat(fd, &stat) != 0) { 3437c478bd9Sstevel@tonic-gate (void) fprintf(stderr, OPEN_FAIL, raw); 3447c478bd9Sstevel@tonic-gate exit(-1); 3457c478bd9Sstevel@tonic-gate } 3467c478bd9Sstevel@tonic-gate if (!nowrite && 3477c478bd9Sstevel@tonic-gate pwrite(fd, stage1_buffer, SECTOR_SIZE, 0) != SECTOR_SIZE) { 3487c478bd9Sstevel@tonic-gate (void) fprintf(stderr, WRITE_FAIL_BOOTSEC); 3497c478bd9Sstevel@tonic-gate exit(-1); 3507c478bd9Sstevel@tonic-gate } 3517c478bd9Sstevel@tonic-gate (void) fprintf(stdout, WRITE_MBOOT); 3527c478bd9Sstevel@tonic-gate (void) close(fd); 3537c478bd9Sstevel@tonic-gate } 3547c478bd9Sstevel@tonic-gate 3557c478bd9Sstevel@tonic-gate static void 3567c478bd9Sstevel@tonic-gate modify_and_write_stage1(int dev_fd) 3577c478bd9Sstevel@tonic-gate { 3587c478bd9Sstevel@tonic-gate if (is_floppy) { 3597c478bd9Sstevel@tonic-gate stage2_first_sector = blocklist[0]; 3607c478bd9Sstevel@tonic-gate /* copy bios parameter block (for fat fs) */ 3617c478bd9Sstevel@tonic-gate bcopy(bpb_sect + STAGE1_BPB_OFFSET, 3627c478bd9Sstevel@tonic-gate stage1_buffer + STAGE1_BPB_OFFSET, STAGE1_BPB_SIZE); 3637c478bd9Sstevel@tonic-gate } else if (is_bootpar) { 3647c478bd9Sstevel@tonic-gate stage2_first_sector = get_start_sector() + blocklist[0]; 3657c478bd9Sstevel@tonic-gate /* copy bios parameter block (for fat fs) and MBR */ 3667c478bd9Sstevel@tonic-gate bcopy(bpb_sect + STAGE1_BPB_OFFSET, 3677c478bd9Sstevel@tonic-gate stage1_buffer + STAGE1_BPB_OFFSET, STAGE1_BPB_SIZE); 3687c478bd9Sstevel@tonic-gate bcopy(boot_sect + BOOTSZ, stage1_buffer + BOOTSZ, 512 - BOOTSZ); 3697c478bd9Sstevel@tonic-gate *((unsigned char *)(stage1_buffer + STAGE1_FORCE_LBA)) = 1; 3707c478bd9Sstevel@tonic-gate } else { 3717c478bd9Sstevel@tonic-gate stage2_first_sector = get_start_sector() + STAGE2_BLKOFF; 3727c478bd9Sstevel@tonic-gate /* copy MBR to stage1 in case of overwriting MBR sector */ 3737c478bd9Sstevel@tonic-gate bcopy(boot_sect + BOOTSZ, stage1_buffer + BOOTSZ, 512 - BOOTSZ); 3747c478bd9Sstevel@tonic-gate *((unsigned char *)(stage1_buffer + STAGE1_FORCE_LBA)) = 1; 3757c478bd9Sstevel@tonic-gate } 3767c478bd9Sstevel@tonic-gate 3777c478bd9Sstevel@tonic-gate /* modify default stage1 file generated by GRUB */ 3787c478bd9Sstevel@tonic-gate *((ulong_t *)(stage1_buffer + STAGE1_STAGE2_SECTOR)) 3797c478bd9Sstevel@tonic-gate = stage2_first_sector; 3807c478bd9Sstevel@tonic-gate *((ushort_t *)(stage1_buffer + STAGE1_STAGE2_ADDRESS)) 3817c478bd9Sstevel@tonic-gate = STAGE2_MEMADDR; 3827c478bd9Sstevel@tonic-gate *((ushort_t *)(stage1_buffer + STAGE1_STAGE2_SEGMENT)) 3837c478bd9Sstevel@tonic-gate = STAGE2_MEMADDR >> 4; 3847c478bd9Sstevel@tonic-gate 3857c478bd9Sstevel@tonic-gate /* 3867c478bd9Sstevel@tonic-gate * XXX the default grub distribution also: 3877c478bd9Sstevel@tonic-gate * - Copy the possible MBR/extended part table 3887c478bd9Sstevel@tonic-gate * - Set the boot drive of stage1 3897c478bd9Sstevel@tonic-gate */ 3907c478bd9Sstevel@tonic-gate 3917c478bd9Sstevel@tonic-gate /* write stage1/pboot to 1st sector */ 3927c478bd9Sstevel@tonic-gate if (!nowrite && 3937c478bd9Sstevel@tonic-gate pwrite(dev_fd, stage1_buffer, SECTOR_SIZE, 0) != SECTOR_SIZE) { 3947c478bd9Sstevel@tonic-gate (void) fprintf(stderr, WRITE_FAIL_PBOOT); 3957c478bd9Sstevel@tonic-gate exit(-1); 3967c478bd9Sstevel@tonic-gate } 3977c478bd9Sstevel@tonic-gate 3987c478bd9Sstevel@tonic-gate if (is_floppy) { 3997c478bd9Sstevel@tonic-gate (void) fprintf(stdout, WRITE_BOOTSEC_FLOPPY); 4007c478bd9Sstevel@tonic-gate } else { 4017c478bd9Sstevel@tonic-gate (void) fprintf(stdout, WRITE_PBOOT, 4027c478bd9Sstevel@tonic-gate partition, get_start_sector()); 4037c478bd9Sstevel@tonic-gate } 4047c478bd9Sstevel@tonic-gate } 4057c478bd9Sstevel@tonic-gate 4067c478bd9Sstevel@tonic-gate #define START_BLOCK(pos) (*(ulong_t *)(pos)) 4077c478bd9Sstevel@tonic-gate #define NUM_BLOCK(pos) (*(ushort_t *)((pos) + 4)) 4087c478bd9Sstevel@tonic-gate #define START_SEG(pos) (*(ushort_t *)((pos) + 6)) 4097c478bd9Sstevel@tonic-gate 4107c478bd9Sstevel@tonic-gate static void 4117c478bd9Sstevel@tonic-gate modify_and_write_stage2(int dev_fd) 4127c478bd9Sstevel@tonic-gate { 4137c478bd9Sstevel@tonic-gate int nrecord; 4147c478bd9Sstevel@tonic-gate off_t offset; 4157c478bd9Sstevel@tonic-gate 4167c478bd9Sstevel@tonic-gate if (is_floppy || is_bootpar) { 4177c478bd9Sstevel@tonic-gate int i = 0; 4187c478bd9Sstevel@tonic-gate uint_t partition_offset; 4197c478bd9Sstevel@tonic-gate uint_t install_addr = 0x8200; 4207c478bd9Sstevel@tonic-gate uchar_t *pos = (uchar_t *)stage2_buffer + STAGE2_BLOCKLIST; 4217c478bd9Sstevel@tonic-gate 4227c478bd9Sstevel@tonic-gate stage2_first_sector = blocklist[0]; 4237c478bd9Sstevel@tonic-gate 4247c478bd9Sstevel@tonic-gate /* figure out the second sector */ 4257c478bd9Sstevel@tonic-gate if (blocklist[1] > 1) { 4267c478bd9Sstevel@tonic-gate blocklist[0]++; 4277c478bd9Sstevel@tonic-gate blocklist[1]--; 4287c478bd9Sstevel@tonic-gate } else { 4297c478bd9Sstevel@tonic-gate i += 2; 4307c478bd9Sstevel@tonic-gate } 4317c478bd9Sstevel@tonic-gate stage2_second_sector = blocklist[i]; 4327c478bd9Sstevel@tonic-gate 4337c478bd9Sstevel@tonic-gate if (is_floppy) 4347c478bd9Sstevel@tonic-gate partition_offset = 0; 4357c478bd9Sstevel@tonic-gate else /* solaris boot partition */ 4367c478bd9Sstevel@tonic-gate partition_offset = get_start_sector(); 4377c478bd9Sstevel@tonic-gate 4387c478bd9Sstevel@tonic-gate /* install the blocklist at the end of stage2_buffer */ 4397c478bd9Sstevel@tonic-gate while (blocklist[i]) { 4407c478bd9Sstevel@tonic-gate if (START_BLOCK(pos - 8) != 0 && 4417c478bd9Sstevel@tonic-gate START_BLOCK(pos - 8) != blocklist[i + 2]) { 4427c478bd9Sstevel@tonic-gate (void) fprintf(stderr, PCFS_FRAGMENTED); 4437c478bd9Sstevel@tonic-gate exit(-1); 4447c478bd9Sstevel@tonic-gate } 4457c478bd9Sstevel@tonic-gate START_BLOCK(pos) = blocklist[i] + partition_offset; 4467c478bd9Sstevel@tonic-gate START_SEG(pos) = (ushort_t)(install_addr >> 4); 4477c478bd9Sstevel@tonic-gate NUM_BLOCK(pos) = blocklist[i + 1]; 4487c478bd9Sstevel@tonic-gate install_addr += blocklist[i + 1] * SECTOR_SIZE; 4497c478bd9Sstevel@tonic-gate pos -= 8; 4507c478bd9Sstevel@tonic-gate i += 2; 4517c478bd9Sstevel@tonic-gate } 4527c478bd9Sstevel@tonic-gate 4537c478bd9Sstevel@tonic-gate } else { 4547c478bd9Sstevel@tonic-gate /* 4557c478bd9Sstevel@tonic-gate * In a solaris partition, stage2 is written to contiguous 4567c478bd9Sstevel@tonic-gate * blocks. So we update the starting block only. 4577c478bd9Sstevel@tonic-gate */ 4587c478bd9Sstevel@tonic-gate *((ulong_t *)(stage2_buffer + STAGE2_BLOCKLIST)) = 4597c478bd9Sstevel@tonic-gate stage2_first_sector + 1; 4607c478bd9Sstevel@tonic-gate } 4617c478bd9Sstevel@tonic-gate 4627c478bd9Sstevel@tonic-gate if (is_floppy) { 4637c478bd9Sstevel@tonic-gate /* modify the config file to add (fd0) */ 4647c478bd9Sstevel@tonic-gate char *config_file = stage2_buffer + STAGE2_VER_STRING; 4657c478bd9Sstevel@tonic-gate while (*config_file++) 4667c478bd9Sstevel@tonic-gate ; 4677c478bd9Sstevel@tonic-gate strcpy(config_file, "(fd0)/boot/grub/menu.lst"); 4687c478bd9Sstevel@tonic-gate } else { 4697c478bd9Sstevel@tonic-gate /* force lba and set disk partition */ 4707c478bd9Sstevel@tonic-gate *((unsigned char *) (stage2_buffer + STAGE2_FORCE_LBA)) = 1; 4717c478bd9Sstevel@tonic-gate *((long *)(stage2_buffer + STAGE2_INSTALLPART)) 4727c478bd9Sstevel@tonic-gate = (partition << 16) | (slice << 8) | 0xff; 4737c478bd9Sstevel@tonic-gate } 4747c478bd9Sstevel@tonic-gate 4757c478bd9Sstevel@tonic-gate /* modification done, now do the writing */ 4767c478bd9Sstevel@tonic-gate if (is_floppy || is_bootpar) { 4777c478bd9Sstevel@tonic-gate /* we rewrite block 0 and 1 and that's it */ 4787c478bd9Sstevel@tonic-gate if (!nowrite && 4797c478bd9Sstevel@tonic-gate (pwrite(dev_fd, stage2_buffer, SECTOR_SIZE, 4807c478bd9Sstevel@tonic-gate stage2_first_sector * SECTOR_SIZE) != SECTOR_SIZE || 4817c478bd9Sstevel@tonic-gate pwrite(dev_fd, stage2_buffer + SECTOR_SIZE, SECTOR_SIZE, 4827c478bd9Sstevel@tonic-gate stage2_second_sector * SECTOR_SIZE) != SECTOR_SIZE)) { 4837c478bd9Sstevel@tonic-gate (void) fprintf(stderr, WRITE_FAIL_STAGE2); 4847c478bd9Sstevel@tonic-gate exit(-1); 4857c478bd9Sstevel@tonic-gate } 4867c478bd9Sstevel@tonic-gate (void) fprintf(stdout, WRITE_STAGE2_PCFS); 4877c478bd9Sstevel@tonic-gate return; 4887c478bd9Sstevel@tonic-gate } 4897c478bd9Sstevel@tonic-gate 4907c478bd9Sstevel@tonic-gate /* for disk, write stage2 starting at STAGE2_BLKOFF sector */ 4917c478bd9Sstevel@tonic-gate offset = STAGE2_BLKOFF; 4927c478bd9Sstevel@tonic-gate 4937c478bd9Sstevel@tonic-gate /* write the modified first two sectors */ 4947c478bd9Sstevel@tonic-gate if (!nowrite && pwrite(dev_fd, stage2_buffer, 2 * SECTOR_SIZE, 4957c478bd9Sstevel@tonic-gate offset * SECTOR_SIZE) != 2 * SECTOR_SIZE) { 4967c478bd9Sstevel@tonic-gate (void) fprintf(stderr, WRITE_FAIL_STAGE2); 4977c478bd9Sstevel@tonic-gate exit(-1); 4987c478bd9Sstevel@tonic-gate } 4997c478bd9Sstevel@tonic-gate 5007c478bd9Sstevel@tonic-gate /* write the remaining sectors */ 5017c478bd9Sstevel@tonic-gate nrecord = 2; 5027c478bd9Sstevel@tonic-gate offset += 2; 5037c478bd9Sstevel@tonic-gate for (;;) { 5047c478bd9Sstevel@tonic-gate int nread, nwrite; 5057c478bd9Sstevel@tonic-gate nread = pread(stage2_fd, stage2_buffer, SECTOR_SIZE, 5067c478bd9Sstevel@tonic-gate nrecord * SECTOR_SIZE); 5077c478bd9Sstevel@tonic-gate if (nread > 0 && !nowrite) 5087c478bd9Sstevel@tonic-gate nwrite = pwrite(dev_fd, stage2_buffer, SECTOR_SIZE, 5097c478bd9Sstevel@tonic-gate offset * SECTOR_SIZE); 5107c478bd9Sstevel@tonic-gate else 5117c478bd9Sstevel@tonic-gate nwrite = SECTOR_SIZE; 5127c478bd9Sstevel@tonic-gate if (nread < 0 || nwrite != SECTOR_SIZE) { 5137c478bd9Sstevel@tonic-gate (void) fprintf(stderr, WRITE_FAIL_STAGE2_BLOCKS, 5147c478bd9Sstevel@tonic-gate nread, nwrite); 5157c478bd9Sstevel@tonic-gate break; 5167c478bd9Sstevel@tonic-gate } 517*c6fe1048Sjongkis if (nread > 0) { 5187c478bd9Sstevel@tonic-gate nrecord ++; 5197c478bd9Sstevel@tonic-gate offset ++; 520*c6fe1048Sjongkis } 5217c478bd9Sstevel@tonic-gate if (nread < SECTOR_SIZE) 5227c478bd9Sstevel@tonic-gate break; /* end of file */ 5237c478bd9Sstevel@tonic-gate } 5247c478bd9Sstevel@tonic-gate (void) fprintf(stdout, WRITE_STAGE2_DISK, 5257c478bd9Sstevel@tonic-gate partition, nrecord, STAGE2_BLKOFF, stage2_first_sector); 5267c478bd9Sstevel@tonic-gate } 5277c478bd9Sstevel@tonic-gate 5287c478bd9Sstevel@tonic-gate static char * 5297c478bd9Sstevel@tonic-gate get_raw_partition(char *device) 5307c478bd9Sstevel@tonic-gate { 5317c478bd9Sstevel@tonic-gate int len; 5327c478bd9Sstevel@tonic-gate struct mboot *mboot; 5337c478bd9Sstevel@tonic-gate static char *raw = NULL; 5347c478bd9Sstevel@tonic-gate 5357c478bd9Sstevel@tonic-gate if (raw) 5367c478bd9Sstevel@tonic-gate return (raw); 5377c478bd9Sstevel@tonic-gate raw = strdup(device); 5387c478bd9Sstevel@tonic-gate 5397c478bd9Sstevel@tonic-gate if (is_floppy) 5407c478bd9Sstevel@tonic-gate return (raw); 5417c478bd9Sstevel@tonic-gate 5427c478bd9Sstevel@tonic-gate if (is_bootpar) { 5437c478bd9Sstevel@tonic-gate int i; 5447c478bd9Sstevel@tonic-gate char *end = strstr(raw, "p0:boot"); 5457c478bd9Sstevel@tonic-gate 5467c478bd9Sstevel@tonic-gate end[2] = 0; /* chop off :boot */ 5477c478bd9Sstevel@tonic-gate read_boot_sect(raw); 5487c478bd9Sstevel@tonic-gate mboot = (struct mboot *)boot_sect; 5497c478bd9Sstevel@tonic-gate for (i = 0; i < FD_NUMPART; i++) { 5507c478bd9Sstevel@tonic-gate struct ipart *part = (struct ipart *)mboot->parts + i; 5517c478bd9Sstevel@tonic-gate if (part->systid == 0xbe) /* solaris boot part */ 5527c478bd9Sstevel@tonic-gate break; 5537c478bd9Sstevel@tonic-gate } 5547c478bd9Sstevel@tonic-gate 5557c478bd9Sstevel@tonic-gate if (i == FD_NUMPART) { 5567c478bd9Sstevel@tonic-gate (void) fprintf(stderr, BOOTPAR_NOTFOUND, device); 5577c478bd9Sstevel@tonic-gate exit(-1); 5587c478bd9Sstevel@tonic-gate } 5597c478bd9Sstevel@tonic-gate end[1] = '1' + i; /* set partition name */ 5607c478bd9Sstevel@tonic-gate return (raw); 5617c478bd9Sstevel@tonic-gate } 5627c478bd9Sstevel@tonic-gate 5637c478bd9Sstevel@tonic-gate /* For disk, remember slice and return whole fdisk partition */ 5647c478bd9Sstevel@tonic-gate len = strlen(raw); 5657c478bd9Sstevel@tonic-gate if (raw[len - 2] != 's' || raw[len - 1] == '2') { 5667c478bd9Sstevel@tonic-gate (void) fprintf(stderr, NOT_ROOT_SLICE); 5677c478bd9Sstevel@tonic-gate exit(-1); 5687c478bd9Sstevel@tonic-gate } 5697c478bd9Sstevel@tonic-gate slice = atoi(&raw[len - 1]); 5707c478bd9Sstevel@tonic-gate 5717c478bd9Sstevel@tonic-gate raw[len - 2] = 's'; 5727c478bd9Sstevel@tonic-gate raw[len - 1] = '2'; 5737c478bd9Sstevel@tonic-gate return (raw); 5747c478bd9Sstevel@tonic-gate } 5757c478bd9Sstevel@tonic-gate 5767c478bd9Sstevel@tonic-gate #define TMP_MNTPT "/tmp/installgrub_pcfs" 5777c478bd9Sstevel@tonic-gate static void 5787c478bd9Sstevel@tonic-gate copy_stage2(int dev_fd, char *device) 5797c478bd9Sstevel@tonic-gate { 5807c478bd9Sstevel@tonic-gate FILE *mntfp; 5817c478bd9Sstevel@tonic-gate int i, pcfs_fp; 5827c478bd9Sstevel@tonic-gate char buf[SECTOR_SIZE]; 5837c478bd9Sstevel@tonic-gate char *cp; 5847c478bd9Sstevel@tonic-gate struct mnttab mp = {0}, mpref = {0}; 5857c478bd9Sstevel@tonic-gate 5867c478bd9Sstevel@tonic-gate /* convert raw to block device name by removing the first 'r' */ 5877c478bd9Sstevel@tonic-gate (void) strncpy(buf, device, sizeof (buf)); 5887c478bd9Sstevel@tonic-gate buf[sizeof (buf) - 1] = 0; 5897c478bd9Sstevel@tonic-gate cp = strchr(buf, 'r'); 5907c478bd9Sstevel@tonic-gate if (cp == NULL) { 5917c478bd9Sstevel@tonic-gate (void) fprintf(stderr, CONVERT_FAIL, device); 5927c478bd9Sstevel@tonic-gate exit(-1); 5937c478bd9Sstevel@tonic-gate } 5947c478bd9Sstevel@tonic-gate do { 5957c478bd9Sstevel@tonic-gate *cp = *(cp + 1); 5967c478bd9Sstevel@tonic-gate } while (*(++cp)); 5977c478bd9Sstevel@tonic-gate 5987c478bd9Sstevel@tonic-gate /* get the mount point, if any */ 5997c478bd9Sstevel@tonic-gate mntfp = fopen("/etc/mnttab", "r"); 6007c478bd9Sstevel@tonic-gate if (mntfp == NULL) { 6017c478bd9Sstevel@tonic-gate (void) fprintf(stderr, OPEN_FAIL_FILE, "/etc/mnttab"); 6027c478bd9Sstevel@tonic-gate exit(-1); 6037c478bd9Sstevel@tonic-gate } 6047c478bd9Sstevel@tonic-gate 6057c478bd9Sstevel@tonic-gate mpref.mnt_special = buf; 6067c478bd9Sstevel@tonic-gate if (getmntany(mntfp, &mp, &mpref) != 0) { 6077c478bd9Sstevel@tonic-gate char cmd[128]; 6087c478bd9Sstevel@tonic-gate 6097c478bd9Sstevel@tonic-gate /* not mounted, try remount */ 6107c478bd9Sstevel@tonic-gate (void) mkdir(TMP_MNTPT, S_IRWXU); 6117c478bd9Sstevel@tonic-gate (void) snprintf(cmd, sizeof (cmd), "mount -F pcfs %s %s", 6127c478bd9Sstevel@tonic-gate buf, TMP_MNTPT); 6137c478bd9Sstevel@tonic-gate (void) system(cmd); 6147c478bd9Sstevel@tonic-gate rewind(mntfp); 6157c478bd9Sstevel@tonic-gate bzero(&mp, sizeof (mp)); 6167c478bd9Sstevel@tonic-gate if (getmntany(mntfp, &mp, &mpref) != 0) { 6177c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MOUNT_FAIL, buf); 6187c478bd9Sstevel@tonic-gate exit(-1); 6197c478bd9Sstevel@tonic-gate } 6207c478bd9Sstevel@tonic-gate } 6217c478bd9Sstevel@tonic-gate 6227c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), 6237c478bd9Sstevel@tonic-gate "%s/boot", mp.mnt_mountp); 6247c478bd9Sstevel@tonic-gate (void) mkdir(buf, S_IRWXU); 6257c478bd9Sstevel@tonic-gate (void) strcat(buf, "/grub"); 6267c478bd9Sstevel@tonic-gate (void) mkdir(buf, S_IRWXU); 6277c478bd9Sstevel@tonic-gate 6287c478bd9Sstevel@tonic-gate (void) strcat(buf, "/stage2"); 6297c478bd9Sstevel@tonic-gate pcfs_fp = open(buf, O_WRONLY | O_CREAT, S_IRWXU); 6307c478bd9Sstevel@tonic-gate if (pcfs_fp == -1) { 6317c478bd9Sstevel@tonic-gate (void) fprintf(stderr, OPEN_FAIL_FILE, buf); 6327c478bd9Sstevel@tonic-gate perror("open:"); 6337c478bd9Sstevel@tonic-gate (void) umount(TMP_MNTPT); 6347c478bd9Sstevel@tonic-gate exit(-1); 6357c478bd9Sstevel@tonic-gate } 6367c478bd9Sstevel@tonic-gate 6377c478bd9Sstevel@tonic-gate /* write stage2 to pcfs */ 6387c478bd9Sstevel@tonic-gate for (i = 0; ; i++) { 6397c478bd9Sstevel@tonic-gate int nread, nwrite; 6407c478bd9Sstevel@tonic-gate nread = pread(stage2_fd, buf, SECTOR_SIZE, i * SECTOR_SIZE); 6417c478bd9Sstevel@tonic-gate if (nowrite) 6427c478bd9Sstevel@tonic-gate nwrite = nread; 6437c478bd9Sstevel@tonic-gate else 6447c478bd9Sstevel@tonic-gate nwrite = pwrite(pcfs_fp, buf, nread, i * SECTOR_SIZE); 6457c478bd9Sstevel@tonic-gate if (nread < 0 || nwrite != nread) { 6467c478bd9Sstevel@tonic-gate (void) fprintf(stderr, WRITE_FAIL_STAGE2_BLOCKS, 6477c478bd9Sstevel@tonic-gate nread, nwrite); 6487c478bd9Sstevel@tonic-gate break; 6497c478bd9Sstevel@tonic-gate } 6507c478bd9Sstevel@tonic-gate if (nread < SECTOR_SIZE) 6517c478bd9Sstevel@tonic-gate break; /* end of file */ 6527c478bd9Sstevel@tonic-gate } 6537c478bd9Sstevel@tonic-gate (void) close(pcfs_fp); 6547c478bd9Sstevel@tonic-gate (void) umount(TMP_MNTPT); 6557c478bd9Sstevel@tonic-gate 6567c478bd9Sstevel@tonic-gate /* 6577c478bd9Sstevel@tonic-gate * Now, get the blocklist from the device. 6587c478bd9Sstevel@tonic-gate */ 6597c478bd9Sstevel@tonic-gate bzero(blocklist, sizeof (blocklist)); 6607c478bd9Sstevel@tonic-gate if (read_stage2_blocklist(dev_fd, blocklist) != 0) 6617c478bd9Sstevel@tonic-gate exit(-1); 6627c478bd9Sstevel@tonic-gate } 663