static int xbsd_readlabel (struct partition *p, struct xbsd_disklabel *d) { int t, sector; #if !defined (__alpha__) sector = (p ? get_start_sect(p) : 0); #elif defined (__alpha__) sector = 0; #endif if (ext2_llseek (fd, (ext2_loff_t) sector * SECTOR_SIZE, SEEK_SET) == -1) fatal (unable_to_seek); if (BSD_BBSIZE != read (fd, disklabelbuffer, BSD_BBSIZE)) fatal (unable_to_read); bcopy (&disklabelbuffer[BSD_LABELSECTOR * SECTOR_SIZE + BSD_LABELOFFSET], d, sizeof (struct xbsd_disklabel)); for (t = d -> d_npartitions; t < BSD_MAXPARTITIONS; t++) { d -> d_partitions[t].p_size = 0; d -> d_partitions[t].p_offset = 0; d -> d_partitions[t].p_fstype = BSD_FS_UNUSED; } if (d -> d_magic != BSD_DISKMAGIC || d -> d_magic2 != BSD_DISKMAGIC) return 0; if (d -> d_npartitions > BSD_MAXPARTITIONS) fprintf (stderr, _("Warning: too many partitions (%d, maximum is %d).\n"), d -> d_npartitions, BSD_MAXPARTITIONS); return 1; }
static int valid_offset (int fd, ext2_loff_t offset) { char ch; if (ext2_llseek (fd, offset, 0) < 0) return 0; if (read (fd, &ch, 1) < 1) return 0; return 1; }
static int xbsd_writelabel (struct partition *p, struct xbsd_disklabel *d) { int sector; #if !defined (__alpha__) && !defined (__powerpc__) sector = get_start_sect(p) + BSD_LABELSECTOR; #elif defined (__alpha__) || defined (__powerpc__) sector = BSD_LABELSECTOR; #endif d -> d_checksum = 0; d -> d_checksum = xbsd_dkcksum (d); /* This is necessary if we want to write the bootstrap later, otherwise we'd write the old disklabel with the bootstrap. */ bcopy (d, &disklabelbuffer[BSD_LABELSECTOR * SECTOR_SIZE + BSD_LABELOFFSET], sizeof (struct xbsd_disklabel)); #if defined (__alpha__) && BSD_LABELSECTOR == 0 alpha_bootblock_checksum (disklabelbuffer); if (ext2_llseek (fd, (ext2_loff_t) 0, SEEK_SET) == -1) fatal (unable_to_seek); if (BSD_BBSIZE != write (fd, disklabelbuffer, BSD_BBSIZE)) fatal (unable_to_write); #else if (ext2_llseek (fd, (ext2_loff_t) sector * SECTOR_SIZE + BSD_LABELOFFSET, SEEK_SET) == -1) fatal (unable_to_seek); if (sizeof (struct xbsd_disklabel) != write (fd, d, sizeof (struct xbsd_disklabel))) fatal (unable_to_write); #endif sync_disks (); return 1; }
static void xbsd_write_bootstrap (void) { char *bootdir = BSD_LINUX_BOOTDIR; char path[MAXPATHLEN]; char *dkbasename; struct xbsd_disklabel dl; char *d, *p, *e; int sector; if (xbsd_dlabel.d_type == BSD_DTYPE_SCSI) dkbasename = "sd"; else dkbasename = "wd"; printf (_("Bootstrap: %sboot -> boot%s (%s): "), dkbasename, dkbasename, dkbasename); if (read_line ()) { line_ptr[strlen (line_ptr)-1] = '\0'; dkbasename = line_ptr; } sprintf (path, "%s/%sboot", bootdir, dkbasename); if (!xbsd_get_bootstrap (path, disklabelbuffer, (int) xbsd_dlabel.d_secsize)) return; /* We need a backup of the disklabel (xbsd_dlabel might have changed). */ d = &disklabelbuffer[BSD_LABELSECTOR * SECTOR_SIZE]; bcopy (d, &dl, sizeof (struct xbsd_disklabel)); /* The disklabel will be overwritten by 0's from bootxx anyway */ bzero (d, sizeof (struct xbsd_disklabel)); sprintf (path, "%s/boot%s", bootdir, dkbasename); if (!xbsd_get_bootstrap (path, &disklabelbuffer[xbsd_dlabel.d_secsize], (int) xbsd_dlabel.d_bbsize - xbsd_dlabel.d_secsize)) return; e = d + sizeof (struct xbsd_disklabel); for (p=d; p < e; p++) if (*p) { fprintf (stderr, _("Bootstrap overlaps with disk label!\n")); exit ( EXIT_FAILURE ); } bcopy (&dl, d, sizeof (struct xbsd_disklabel)); #if defined (__powerpc__) sector = 0; #elif defined (__alpha__) sector = 0; alpha_bootblock_checksum (disklabelbuffer); #else sector = get_start_sect(xbsd_part); #endif if (ext2_llseek (fd, (ext2_loff_t) sector * SECTOR_SIZE, SEEK_SET) == -1) fatal (unable_to_seek); if (BSD_BBSIZE != write (fd, disklabelbuffer, BSD_BBSIZE)) fatal (unable_to_write); #if defined (__alpha__) printf (_("Bootstrap installed on %s.\n"), disk_device); #else printf (_("Bootstrap installed on %s.\n"), partname (disk_device, xbsd_part_index+1, 0)); #endif sync_disks (); }