static int xbsd_writelabel(struct partition *p) { struct xbsd_disklabel *d = &xbsd_dlabel; unsigned int sector; #if !defined(__alpha__) && !defined(__powerpc__) && !defined(__hppa__) sector = get_start_sect(p) + BSD_LABELSECTOR; #else (void)p; /* silence warning */ 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. */ memmove(&disklabelbuffer[BSD_LABELSECTOR * SECTOR_SIZE + BSD_LABELOFFSET], d, sizeof(struct xbsd_disklabel)); #if defined(__alpha__) && BSD_LABELSECTOR == 0 alpha_bootblock_checksum(disklabelbuffer); seek_sector(0); xwrite(dev_fd, disklabelbuffer, BSD_BBSIZE); #else seek_sector(sector); lseek(dev_fd, BSD_LABELOFFSET, SEEK_CUR); xwrite(dev_fd, d, sizeof(*d)); #endif sync_disks(); return 1; }
static PedDisk* bsd_alloc (const PedDevice* dev) { PedDisk* disk; BSDDiskData* bsd_specific; BSDRawLabel* label; PED_ASSERT(dev->sector_size % PED_SECTOR_SIZE_DEFAULT == 0); disk = _ped_disk_alloc ((PedDevice*)dev, &bsd_disk_type); if (!disk) goto error; disk->disk_specific = bsd_specific = ped_malloc (sizeof (BSDDiskData)); if (!bsd_specific) goto error_free_disk; /* Initialize the first byte to zero, so that the code in bsd_write knows to call _probe_and_add_boot_code. Initializing all of the remaining buffer is a little wasteful, but the alternative is to figure out why a block at offset 340 would otherwise be used uninitialized. */ memset(bsd_specific->boot_code, 0, sizeof (bsd_specific->boot_code)); label = (BSDRawLabel*) (bsd_specific->boot_code + BSD_LABEL_OFFSET); label->d_magic = PED_CPU_TO_LE32 (BSD_DISKMAGIC); label->d_type = PED_CPU_TO_LE16 (BSD_DTYPE_SCSI); label->d_flags = 0; label->d_secsize = PED_CPU_TO_LE16 (dev->sector_size); label->d_nsectors = PED_CPU_TO_LE32 (dev->bios_geom.sectors); label->d_ntracks = PED_CPU_TO_LE32 (dev->bios_geom.heads); label->d_ncylinders = PED_CPU_TO_LE32 (dev->bios_geom.cylinders); label->d_secpercyl = PED_CPU_TO_LE32 (dev->bios_geom.sectors * dev->bios_geom.heads); label->d_secperunit = PED_CPU_TO_LE32 (dev->bios_geom.sectors * dev->bios_geom.heads * dev->bios_geom.cylinders); label->d_rpm = PED_CPU_TO_LE16 (3600); label->d_interleave = PED_CPU_TO_LE16 (1);; label->d_trackskew = 0; label->d_cylskew = 0; label->d_headswitch = 0; label->d_trkseek = 0; label->d_magic2 = PED_CPU_TO_LE32 (BSD_DISKMAGIC); label->d_bbsize = PED_CPU_TO_LE32 (BSD_BBSIZE); label->d_sbsize = PED_CPU_TO_LE32 (BSD_SBSIZE); label->d_npartitions = 0; label->d_checksum = xbsd_dkcksum (label); return disk; error_free_disk: free (disk); error: return NULL; }
static int bsd_write (const PedDisk* disk) { BSDDiskData* bsd_specific; BSDRawLabel* label; BSDPartitionData* bsd_data; PedPartition* part; int i; int max_part = 0; PED_ASSERT (disk != NULL); PED_ASSERT (disk->dev != NULL); bsd_specific = (BSDDiskData*) disk->disk_specific; label = (BSDRawLabel *) (bsd_specific->boot_code + BSD_LABEL_OFFSET); if (!bsd_specific->boot_code [0]) _probe_and_add_boot_code (disk); memset (label->d_partitions, 0, sizeof (BSDRawPartition) * BSD_MAXPARTITIONS); for (i = 1; i <= BSD_MAXPARTITIONS; i++) { part = ped_disk_get_partition (disk, i); if (!part) continue; bsd_data = part->disk_specific; label->d_partitions[i - 1].p_fstype = bsd_data->type; label->d_partitions[i - 1].p_offset = PED_CPU_TO_LE32 (part->geom.start); label->d_partitions[i - 1].p_size = PED_CPU_TO_LE32 (part->geom.length); max_part = i; } label->d_npartitions = PED_CPU_TO_LE16 (max_part) + 1; label->d_checksum = xbsd_dkcksum (label); alpha_bootblock_checksum (bsd_specific->boot_code); if (!ptt_write_sector (disk, bsd_specific->boot_code, sizeof (BSDDiskData))) goto error; return ped_device_sync (disk->dev); error: return 0; }
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; }