static void xbsd_link_part(void) { int k, i; struct partition *p; k = get_partition(1, g_partitions); if (!xbsd_check_new_partition(&i)) return; p = get_part_table(k); xbsd_dlabel.d_partitions[i].p_size = get_nr_sects(p); xbsd_dlabel.d_partitions[i].p_offset = get_start_sect(p); xbsd_dlabel.d_partitions[i].p_fstype = xbsd_translate_fstype(p->sys_ind); }
static void create_sgilabel(void) { struct hd_geometry geometry; struct { unsigned int start; unsigned int nsect; int sysid; } old[4]; int i = 0; long longsectors; /* the number of sectors on the device */ int res; /* the result from the ioctl */ int sec_fac; /* the sector factor */ sec_fac = sector_size / 512; /* determine the sector factor */ printf(msg_building_new_label, "SGI disklabel"); sgi_other_endian = (BYTE_ORDER == LITTLE_ENDIAN); res = ioctl(fd, BLKGETSIZE, &longsectors); if (!ioctl(fd, HDIO_GETGEO, &geometry)) { heads = geometry.heads; sectors = geometry.sectors; if (res == 0) { /* the get device size ioctl was successful */ cylinders = longsectors / (heads * sectors); cylinders /= sec_fac; } else { /* otherwise print error and use truncated version */ cylinders = geometry.cylinders; printf( "Warning: BLKGETSIZE ioctl failed on %s. Using geometry cylinder value of %d.\n" "This value may be truncated for devices > 33.8 GB.\n", disk_device, cylinders); } } for (i = 0; i < 4; i++) { old[i].sysid = 0; if (valid_part_table_flag(MBRbuffer)) { if (get_part_table(i)->sys_ind) { old[i].sysid = get_part_table(i)->sys_ind; old[i].start = get_start_sect(get_part_table(i)); old[i].nsect = get_nr_sects(get_part_table(i)); printf("Trying to keep parameters of partition %d\n", i); if (debug) printf("ID=%02x\tSTART=%d\tLENGTH=%d\n", old[i].sysid, old[i].start, old[i].nsect); } } } memset(MBRbuffer, 0, sizeof(MBRbuffer)); /* fields with '//' are already zeroed out by memset above */ sgilabel->magic = SGI_SSWAP32(SGI_LABEL_MAGIC); //sgilabel->boot_part = SGI_SSWAP16(0); sgilabel->swap_part = SGI_SSWAP16(1); //memset(sgilabel->boot_file, 0, 16); strcpy((char*)sgilabel->boot_file, "/unix"); /* sizeof(sgilabel->boot_file) == 16 > 6 */ //sgilabel->devparam.skew = (0); //sgilabel->devparam.gap1 = (0); //sgilabel->devparam.gap2 = (0); //sgilabel->devparam.sparecyl = (0); sgilabel->devparam.pcylcount = SGI_SSWAP16(geometry.cylinders); //sgilabel->devparam.head_vol0 = SGI_SSWAP16(0); /* tracks/cylinder (heads) */ sgilabel->devparam.ntrks = SGI_SSWAP16(geometry.heads); //sgilabel->devparam.cmd_tag_queue_depth = (0); //sgilabel->devparam.unused0 = (0); //sgilabel->devparam.unused1 = SGI_SSWAP16(0); /* sectors/track */ sgilabel->devparam.nsect = SGI_SSWAP16(geometry.sectors); sgilabel->devparam.bytes = SGI_SSWAP16(512); sgilabel->devparam.ilfact = SGI_SSWAP16(1); sgilabel->devparam.flags = SGI_SSWAP32(TRACK_FWD| IGNORE_ERRORS|RESEEK); //sgilabel->devparam.datarate = SGI_SSWAP32(0); sgilabel->devparam.retries_on_error = SGI_SSWAP32(1); //sgilabel->devparam.ms_per_word = SGI_SSWAP32(0); //sgilabel->devparam.xylogics_gap1 = SGI_SSWAP16(0); //sgilabel->devparam.xylogics_syncdelay = SGI_SSWAP16(0); //sgilabel->devparam.xylogics_readdelay = SGI_SSWAP16(0); //sgilabel->devparam.xylogics_gap2 = SGI_SSWAP16(0); //sgilabel->devparam.xylogics_readgate = SGI_SSWAP16(0); //sgilabel->devparam.xylogics_writecont = SGI_SSWAP16(0); //memset( &(sgilabel->directory), 0, sizeof(struct volume_directory)*15 ); //memset( &(sgilabel->partitions), 0, sizeof(struct sgi_partinfo)*16 ); current_label_type = label_sgi; partitions = 16; sgi_volumes = 15; sgi_set_entire(); sgi_set_volhdr(); for (i = 0; i < 4; i++) { if (old[i].sysid) { sgi_set_partition(i, old[i].start, old[i].nsect, old[i].sysid); } } }
static void bsd_select(void) { #if !defined(__alpha__) int t, ss; struct partition *p; for (t = 0; t < 4; t++) { p = get_part_table(t); if (p && is_bsd_partition_type(p->sys_ind)) { xbsd_part = p; xbsd_part_index = t; ss = get_start_sect(xbsd_part); if (ss == 0) { printf("Partition %s has invalid starting sector 0\n", partname(disk_device, t+1, 0)); return; } printf("Reading disklabel of %s at sector %u\n", partname(disk_device, t+1, 0), ss + BSD_LABELSECTOR); if (xbsd_readlabel(xbsd_part) == 0) { if (xbsd_create_disklabel() == 0) return; break; } } } if (t == 4) { printf("There is no *BSD partition on %s\n", disk_device); return; } #elif defined(__alpha__) if (xbsd_readlabel(NULL) == 0) if (xbsd_create_disklabel() == 0) exit(EXIT_SUCCESS); #endif while (1) { bb_putchar('\n'); switch (tolower(read_nonempty("BSD disklabel command (m for help): "))) { case 'd': xbsd_delete_part(); break; case 'e': xbsd_edit_disklabel(); break; case 'i': xbsd_write_bootstrap(); break; case 'l': xbsd_list_types(); break; case 'n': xbsd_new_part(); break; case 'p': xbsd_print_disklabel(0); break; case 'q': if (ENABLE_FEATURE_CLEAN_UP) close_dev_fd(); exit(EXIT_SUCCESS); case 'r': return; case 's': xbsd_print_disklabel(1); break; case 't': xbsd_change_fstype(); break; case 'u': change_units(); break; case 'w': xbsd_write_disklabel(); break; #if !defined(__alpha__) case 'x': xbsd_link_part(); break; #endif default: bsd_menu(); break; } } }
/* 功能: 通过系统设备编号和分区类型获得该设备的所有分区信息 参数: device:系统设备编号 type:分区类型(主分区、扩展分区) 返回值: (无) */ static void partition(int index){ /* int driver=DRIVER(device); */ /* int sdevice=SDEVICE_HD(device); */ /* int prim=PRIM_HD(device); */ /* int logical=LOGICAL_HD(device); */ /* int devie=DEVICE(index); */ int hd_index=HD_INDEX(index); /* int hd_part_index=HD_PART_INDEX(index); */ struct s_hd_info *hdi=&hd_info[hd_index]; /*一个硬盘设备所有分区表项信息*/ struct s_hd_part_entry prim_part_table[HD_ENT_PER_PRIM_PART]; struct s_hd_part_entry logical_part_table[HD_ENT_PER_LOGICAL_PART]; //获得该硬盘分区表信息 get_part_table(index,HD_PRIM_TABLE_SECTOR,prim_part_table,HD_ENT_PER_PRIM_PART); /* get_part_table(index,20001,prim_part_table,HD_ENT_PER_PRIM_PART); */ int prim_index=0;//用于遍历所有主分区 int logical_index=0;//用于遍历所有逻辑分区 int extended_index=0;//记录主分区中对应扩展分区的序号 /*遍历所有主分区*/ for(prim_index=1;prim_index<=HD_PART_PRIM_COUNT;prim_index++){ int prim_table_index=prim_index-1; if(prim_part_table[prim_table_index].part_type==NO_PART) continue; hdi->primary[prim_index].base=prim_part_table[prim_table_index].begin_sector_lba; hdi->primary[prim_index].size=prim_part_table[prim_table_index].sectors_count; #ifdef DEBUG printl("prim %d:base=%d length=%d part_type=%d\n",prim_index,hdi->primary[prim_index].base,hdi->primary[prim_index].size,prim_part_table[prim_table_index].part_type); #endif if(prim_part_table[prim_table_index].part_type==EXTENDED_PART){ assert(extended_index==0,"only one extended part can exist!"); int extended_index=prim_index; int logical_begin_sector=hdi->primary[extended_index].base; for(logical_index=0;logical_index<HD_PART_LOGICAL_COUNT;logical_index++){ get_part_table(index,logical_begin_sector,logical_part_table,HD_ENT_PER_LOGICAL_PART); hdi->logical[logical_index].base=logical_begin_sector+logical_part_table[0].begin_sector_lba; hdi->logical[logical_index].size=logical_part_table[0].sectors_count; #ifdef DEBUG printl("logical %d: base=%d length=%d part_type=%d \nnext_part_type=%d\n",logical_index,hdi->logical[logical_index].base,logical_index,hdi->logical[logical_index].size,logical_part_table[0],logical_part_table[1].part_type); #endif if(logical_part_table[1].part_type==NO_PART){ break; } else{ logical_begin_sector=hdi->primary[extended_index].base+logical_part_table[1].begin_sector_lba; } } } } }
static int sgi_create_disklabel(struct fdisk_context *cxt) { struct hd_geometry geometry; struct { unsigned int start; unsigned int nsect; int sysid; } old[4]; int i=0; sector_t llsectors; int res; /* the result from the ioctl */ int sec_fac; /* the sector factor */ sec_fac = cxt->sector_size / 512; /* determine the sector factor */ fprintf(stderr, _("Building a new SGI disklabel.\n")); other_endian = (BYTE_ORDER == LITTLE_ENDIAN); res = blkdev_get_sectors(cxt->dev_fd, &llsectors); #ifdef HDIO_GETGEO if (ioctl(cxt->dev_fd, HDIO_GETGEO, &geometry) < 0) err(EXIT_FAILURE, _("HDIO_GETGEO ioctl failed on %s"), cxt->dev_path); cxt->geom.heads = geometry.heads; cxt->geom.sectors = geometry.sectors; if (res == 0) { /* the get device size ioctl was successful */ sector_t llcyls; llcyls = llsectors / (cxt->geom.heads * cxt->geom.sectors * sec_fac); cxt->geom.cylinders = llcyls; if (cxt->geom.cylinders != llcyls) /* truncated? */ cxt->geom.cylinders = ~0; } else { /* otherwise print error and use truncated version */ cxt->geom.cylinders = geometry.cylinders; fprintf(stderr, _("Warning: BLKGETSIZE ioctl failed on %s. " "Using geometry cylinder value of %llu.\n" "This value may be truncated for devices" " > 33.8 GB.\n"), cxt->dev_path, cxt->geom.cylinders); } #endif /* * Convert old MBR to SGI label, make it DEPRECATED, this feature * has to be handled in by any top-level fdisk command. */ for (i = 0; i < 4; i++) { old[i].sysid = 0; if (mbr_is_valid_magic(cxt->firstsector)) { if (get_part_table(i)->sys_ind) { old[i].sysid = get_part_table(i)->sys_ind; old[i].start = get_start_sect(get_part_table(i)); old[i].nsect = get_nr_sects(get_part_table(i)); if (debug) printf(_("ID=%02x\tSTART=%d\tLENGTH=%d\n"), old[i].sysid, old[i].start, old[i].nsect); } } } for (i = 0; i < 4; i++) if (old[i].sysid) { printf(_("Trying to keep parameters of partitions already set.\n")); break; } fdisk_zeroize_firstsector(cxt); sgilabel->magic = SSWAP32(SGI_LABEL_MAGIC); sgilabel->boot_part = SSWAP16(0); sgilabel->swap_part = SSWAP16(1); /* sizeof(sgilabel->boot_file) = 16 > 6 */ memset(sgilabel->boot_file, 0, 16); strcpy((char *) sgilabel->boot_file, "/unix"); sgilabel->devparam.skew = (0); sgilabel->devparam.gap1 = (0); sgilabel->devparam.gap2 = (0); sgilabel->devparam.sparecyl = (0); sgilabel->devparam.pcylcount = SSWAP16(geometry.cylinders); sgilabel->devparam.head_vol0 = SSWAP16(0); sgilabel->devparam.ntrks = SSWAP16(geometry.heads); /* tracks/cylinder (heads) */ sgilabel->devparam.cmd_tag_queue_depth = (0); sgilabel->devparam.unused0 = (0); sgilabel->devparam.unused1 = SSWAP16(0); sgilabel->devparam.nsect = SSWAP16(geometry.sectors); /* sectors/track */ sgilabel->devparam.bytes = SSWAP16(cxt->sector_size); sgilabel->devparam.ilfact = SSWAP16(1); sgilabel->devparam.flags = SSWAP32(TRACK_FWD|\ IGNORE_ERRORS|RESEEK); sgilabel->devparam.datarate = SSWAP32(0); sgilabel->devparam.retries_on_error = SSWAP32(1); sgilabel->devparam.ms_per_word = SSWAP32(0); sgilabel->devparam.xylogics_gap1 = SSWAP16(0); sgilabel->devparam.xylogics_syncdelay = SSWAP16(0); sgilabel->devparam.xylogics_readdelay = SSWAP16(0); sgilabel->devparam.xylogics_gap2 = SSWAP16(0); sgilabel->devparam.xylogics_readgate = SSWAP16(0); sgilabel->devparam.xylogics_writecont = SSWAP16(0); memset(&(sgilabel->directory), 0, sizeof(struct volume_directory)*15); memset(&(sgilabel->partitions), 0, sizeof(struct sgi_partition)*16); cxt->disklabel = FDISK_DISKLABEL_SGI; partitions = 16; volumes = 15; sgi_set_entire(cxt); sgi_set_volhdr(cxt); for (i = 0; i < 4; i++) { if (old[i].sysid) { sgi_set_partition(cxt, i, old[i].start, old[i].nsect, old[i].sysid); } } return 0; }
void create_sgilabel(void) { struct hd_geometry geometry; struct { unsigned int start; unsigned int nsect; int sysid; } old[4]; int i=0; unsigned long long llsectors; int res; /* the result from the ioctl */ int sec_fac; /* the sector factor */ sec_fac = sector_size / 512; /* determine the sector factor */ fprintf(stderr, _("Building a new SGI disklabel.\n")); other_endian = (BYTE_ORDER == LITTLE_ENDIAN); res = blkdev_get_sectors(fd, &llsectors); #ifdef HDIO_GETGEO if (!ioctl(fd, HDIO_GETGEO, &geometry)) { heads = geometry.heads; sectors = geometry.sectors; if (res == 0) { /* the get device size ioctl was successful */ unsigned long long llcyls; llcyls = llsectors / (heads * sectors * sec_fac); cylinders = llcyls; if (cylinders != llcyls) /* truncated? */ cylinders = ~0; } else { /* otherwise print error and use truncated version */ cylinders = geometry.cylinders; fprintf(stderr, _("Warning: BLKGETSIZE ioctl failed on %s. " "Using geometry cylinder value of %d.\n" "This value may be truncated for devices" " > 33.8 GB.\n"), disk_device, cylinders); } } #endif for (i = 0; i < 4; i++) { old[i].sysid = 0; if (valid_part_table_flag(MBRbuffer)) { if (get_part_table(i)->sys_ind) { old[i].sysid = get_part_table(i)->sys_ind; old[i].start = get_start_sect(get_part_table(i)); old[i].nsect = get_nr_sects(get_part_table(i)); if (debug) printf(_("ID=%02x\tSTART=%d\tLENGTH=%d\n"), old[i].sysid, old[i].start, old[i].nsect); } } } for (i = 0; i < 4; i++) if (old[i].sysid) { printf(_("Trying to keep parameters of partitions already set.\n")); break; } zeroize_mbr_buffer(); sgilabel->magic = SSWAP32(SGI_LABEL_MAGIC); sgilabel->boot_part = SSWAP16(0); sgilabel->swap_part = SSWAP16(1); /* sizeof(sgilabel->boot_file) = 16 > 6 */ memset(sgilabel->boot_file, 0, 16); strcpy((char *) sgilabel->boot_file, "/unix"); sgilabel->devparam.skew = (0); sgilabel->devparam.gap1 = (0); sgilabel->devparam.gap2 = (0); sgilabel->devparam.sparecyl = (0); sgilabel->devparam.pcylcount = SSWAP16(geometry.cylinders); sgilabel->devparam.head_vol0 = SSWAP16(0); sgilabel->devparam.ntrks = SSWAP16(geometry.heads); /* tracks/cylinder (heads) */ sgilabel->devparam.cmd_tag_queue_depth = (0); sgilabel->devparam.unused0 = (0); sgilabel->devparam.unused1 = SSWAP16(0); sgilabel->devparam.nsect = SSWAP16(geometry.sectors); /* sectors/track */ sgilabel->devparam.bytes = SSWAP16(sector_size); sgilabel->devparam.ilfact = SSWAP16(1); sgilabel->devparam.flags = SSWAP32(TRACK_FWD|\ IGNORE_ERRORS|RESEEK); sgilabel->devparam.datarate = SSWAP32(0); sgilabel->devparam.retries_on_error = SSWAP32(1); sgilabel->devparam.ms_per_word = SSWAP32(0); sgilabel->devparam.xylogics_gap1 = SSWAP16(0); sgilabel->devparam.xylogics_syncdelay = SSWAP16(0); sgilabel->devparam.xylogics_readdelay = SSWAP16(0); sgilabel->devparam.xylogics_gap2 = SSWAP16(0); sgilabel->devparam.xylogics_readgate = SSWAP16(0); sgilabel->devparam.xylogics_writecont = SSWAP16(0); memset(&(sgilabel->directory), 0, sizeof(struct volume_directory)*15); memset(&(sgilabel->partitions), 0, sizeof(struct sgi_partition)*16); disklabel = SGI_LABEL; partitions = 16; volumes = 15; sgi_set_entire(); sgi_set_volhdr(); for (i = 0; i < 4; i++) { if (old[i].sysid) { sgi_set_partition(i, old[i].start, old[i].nsect, old[i].sysid); } } }