From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111c93,6c39670ee73399e3 X-Google-Attributes: gid111c93,public From: "B. James Phillippe" Subject: Re: convert DOS to BSD partitions? Date: 1999/12/30 Message-ID: <44C2247EAFF4D011B0BD00805F85B09C1C5B8F8E@news.maricopa.gov> X-Deja-AN: 566714476 Sender: bryan@neptune.terran References: <3868141F.93FF7309@oneguycoding.com> <386A65D5.EBF6F4C2@node102bd.a2000.nl> To: Raymond Doetjes Supersedes: <44C2247EAFF4D011B0BD00805F85B09C1C5B8F32@news.maricopa.gov> Content-Type: multipart/mixed; boundary="----_=_NextPart_000_01BF532B.CAEAC4E0" Organization: terran.org/darkforest.org MIME-Version: 1.0 Newsgroups: comp.os.linux.alpha This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. ------_=_NextPart_000_01BF532B.CAEAC4E0 Content-Type: text/plain; charset="windows-1252" On Wed, 29 Dec 1999, Raymond Doetjes wrote: > The only program that "might" do this is partiotion magic from Symantec. > If that can't do it than it can't be done. > > Raymond Richard Henderson might be offended. He posted a program to do this on axp-list@redhat.com several months ago. I have included his original email and the attachment, a small C program. YMMV... > Steeve McCauley wrote: > > > Somehow I have a feeling that this ain't possible. > > > > Anyone have any success converting a 'dos' partition > > to a BSD partition? > > > > Or do I just get to reinstall? > > > > -- > > :wq -bp -- # bryan at terran dot org # http://www.terran.org/~bryan ------_=_NextPart_000_01BF532B.CAEAC4E0 Content-Type: message/rfc822 Path: ElectronicBusinessCenter.MaricopaCounty.com!news.asu.edu!ennfs.eas.asu.edu!noao!ncar!news-out.cwix.com!newsfeed.cwix.com!wn3feed!worldnet.att.net!207.14.113.10!news.alt.net!oz.net!usenet NNTP-Posting-Host: 216.39.144.215 Newsgroups: comp.os.linux.alpha From: "B. James Phillippe" Subject: Re: convert DOS to BSD partitions? Message-ID: <44C2247EAFF4D011B0BD00805F85B09C1C5B8F61@news.maricopa.gov> Supersedes: <44C2247EAFF4D011B0BD00805F85B09C1C5B8F2A@news.maricopa.gov> Sender: bryan@neptune.terran To: Raymond Doetjes Cc: Steeve McCauley Date: Thu, 30 Dec 1999 18:08:12 -0700 MIME-Version: 1.0 Lines: 347 X-Newsreader: Microsoft (R) Exchange Internet News Service Version 5.5.2448.0 Organization: terran.org/darkforest.org References: <3868141F.93FF7309@oneguycoding.com> <386A65D5.EBF6F4C2@node102bd.a2000.nl> Content-Type: text/plain; charset="windows-1252" On Wed, 29 Dec 1999, Raymond Doetjes wrote: > The only program that "might" do this is partiotion magic from Symantec. > If that can't do it than it can't be done. > > Raymond Richard Henderson might be offended. He posted a program to do this on axp-list@redhat.com several months ago. I have included his original email and the attachment, a small C program. YMMV... > Steeve McCauley wrote: > > > Somehow I have a feeling that this ain't possible. > > > > Anyone have any success converting a 'dos' partition > > to a BSD partition? > > > > Or do I just get to reinstall? > > > > -- > > :wq -bp -- # bryan at terran dot org # http://www.terran.org/~bryan ------_=_NextPart_000_01BF532B.CAEAC4E0 Content-Type: message/rfc822 Path: ElectronicBusinessCenter.MaricopaCounty.com!news.asu.edu!ennfs.eas.asu.edu!noao!ncar!news-out.cwix.com!newsfeed.cwix.com!wn3feed!worldnet.att.net!207.14.113.10!news.alt.net!oz.net!usenet NNTP-Posting-Host: 216.39.144.215 Newsgroups: comp.os.linux.alpha From: "B. James Phillippe" Subject: Re: convert DOS to BSD partitions? Message-ID: <44C2247EAFF4D011B0BD00805F85B09C1C5B8F35@news.maricopa.gov> Supersedes: <44C2247EAFF4D011B0BD00805F85B09C1C5B8F21@news.maricopa.gov> Sender: bryan@neptune.terran To: Raymond Doetjes Cc: Steeve McCauley Date: Thu, 30 Dec 1999 18:08:12 -0700 MIME-Version: 1.0 Lines: 347 X-Newsreader: Microsoft (R) Exchange Internet News Service Version 5.5.2448.0 Organization: terran.org/darkforest.org References: <3868141F.93FF7309@oneguycoding.com> <386A65D5.EBF6F4C2@node102bd.a2000.nl> Content-Type: text/plain; charset="windows-1252" On Wed, 29 Dec 1999, Raymond Doetjes wrote: > The only program that "might" do this is partiotion magic from Symantec. > If that can't do it than it can't be done. > > Raymond Richard Henderson might be offended. He posted a program to do this on axp-list@redhat.com several months ago. I have included his original email and the attachment, a small C program. YMMV... > Steeve McCauley wrote: > > > Somehow I have a feeling that this ain't possible. > > > > Anyone have any success converting a 'dos' partition > > to a BSD partition? > > > > Or do I just get to reinstall? > > > > -- > > :wq -bp -- # bryan at terran dot org # http://www.terran.org/~bryan ------_=_NextPart_000_01BF532B.CAEAC4E0 Content-Type: message/rfc822 Path: ElectronicBusinessCenter.MaricopaCounty.com!news.asu.edu!ennfs.eas.asu.edu!noao!ncar!news-out.cwix.com!newsfeed.cwix.com!wn3feed!worldnet.att.net!207.14.113.10!news.alt.net!oz.net!usenet NNTP-Posting-Host: 216.39.144.215 Newsgroups: comp.os.linux.alpha From: "B. James Phillippe" Subject: Re: convert DOS to BSD partitions? Message-ID: <44C2247EAFF4D011B0BD00805F85B09C1C5B8F3F@news.maricopa.gov> Supersedes: <84gvls$roc$0@216.39.144.215> Sender: bryan@neptune.terran To: Raymond Doetjes Cc: Steeve McCauley Date: Thu, 30 Dec 1999 18:08:12 -0700 MIME-Version: 1.0 Lines: 347 X-Newsreader: Microsoft (R) Exchange Internet News Service Version 5.5.2448.0 Organization: terran.org/darkforest.org References: <3868141F.93FF7309@oneguycoding.com> <386A65D5.EBF6F4C2@node102bd.a2000.nl> Content-Type: multipart/mixed; boundary="----_=_NextPart_002_01BF532B.CAEAC4E0" ------_=_NextPart_002_01BF532B.CAEAC4E0 Content-Type: text/plain; charset="windows-1252" On Wed, 29 Dec 1999, Raymond Doetjes wrote: > The only program that "might" do this is partiotion magic from Symantec. > If that can't do it than it can't be done. > > Raymond Richard Henderson might be offended. He posted a program to do this on axp-list@redhat.com several months ago. I have included his original email and the attachment, a small C program. YMMV... > Steeve McCauley wrote: > > > Somehow I have a feeling that this ain't possible. > > > > Anyone have any success converting a 'dos' partition > > to a BSD partition? > > > > Or do I just get to reinstall? > > > > -- > > :wq -bp -- # bryan at terran dot org # http://www.terran.org/~bryan ------_=_NextPart_002_01BF532B.CAEAC4E0 Content-Type: TEXT/PLAIN; name="labelcvt.c" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="labelcvt.c" Content-ID: #include #include #include #include #include #define MAXPARTITIONS 16 #define MSDOS_LABEL_OFFSET 446 #define MSDOS_DISKMAGIC 0xAA55 #define MSDOS_FS_EMPTY 0 #define MSDOS_FS_DOS_12 1 #define MSDOS_FS_XENIX_ROOT 2 #define MSDOS_FS_XENIX_USR 3 #define MSDOS_FS_DOS_16 4 #define MSDOS_FS_DOS_EXT 5 #define MSDOS_FS_DOS_16_BIG 6 #define MSDOS_FS_OS2 7 #define MSDOS_FS_AIX 8 #define MSDOS_FS_AIX_BOOTABLE 9 #define MSDOS_FS_OS2_BOOTMAN 10 #define MSDOS_FS_WIN95_FAT32 11 #define MSDOS_FS_WIN98_EXT 15 #define MSDOS_FS_GNU_HURD 0x63 #define MSDOS_FS_MINIX 0x81 #define MSDOS_FS_LINUX_SWAP 0x82 #define MSDOS_FS_LINUX 0x83 #define MSDOS_FS_LINUX_EXT 0x85 #define MSDOS_FS_BSDI 0xb7 #define MSDOS_FS_BSDI_SWAP 0xb8 #define MSDOS_FS_UNKNOWN 0xf0 struct dos_partition { u_int8_t boot_ind; /* 0x80 - active */ u_int8_t head; /* starting head */ u_int8_t sector; /* starting sector */ u_int8_t cyl; /* starting cylinder */ u_int8_t sys_ind; /* What partition type */ u_int8_t end_head; /* end head */ u_int8_t end_sector; /* end sector */ u_int8_t end_cyl; /* end cylinder */ u_int32_t start_sect; /* starting sector counting from 0 */ u_int32_t nr_sects; /* nr of sectors in partition */ }; struct dos_disklabel { struct dos_partition d_partitions[4]; u_int16_t magic; }; #define BSD_LABEL_OFFSET 64 #define BSD_DISKMAGIC 0x82564557 #define BSD_FS_UNUSED 0 #define BSD_FS_SWAP 1 #define BSD_FS_V6 2 #define BSD_FS_V7 3 #define BSD_FS_SYSV 4 #define BSD_FS_V71K 5 #define BSD_FS_V8 6 #define BSD_FS_BSDFFS 7 #define BSD_FS_EXT2 8 #define BSD_FS_ADVFS 16 #define BSD_FS_LSMpubl 17 #define BSD_FS_LSMpriv 18 #define BSD_FS_LSMsimp 19 #define BSD_FS_UNKNOWN 2 #define BSD_DTYPE_SMD 1 #define BSD_DTYPE_MSCP 2 #define BSD_DTYPE_DEC 3 #define BSD_DTYPE_SCSI 4 #define BSD_DTYPE_ESDI 5 #define BSD_DTYPE_ST506 6 struct bsd_partition { u_int32_t p_size; /* number of sectors in partition */ u_int32_t p_offset; /* starting sector */ u_int32_t p_fsize; /* filesystem basic fragment size */ u_int8_t p_fstype; /* filesystem type, see below */ u_int8_t p_frag; /* filesystem fragments per block */ u_int16_t p_cpg; /* filesystem cylinders per group */ }; struct bsd_disklabel { u_int32_t d_magic; /* the magic number */ int16_t d_type; /* drive type */ int16_t d_subtype; /* controller/d_type specific */ char d_typename[16]; /* type name, e.g. "eagle" */ char d_packname[16]; /* pack identifier */=20 u_int32_t d_secsize; /* # of bytes per sector */ u_int32_t d_nsectors; /* # of data sectors per track */ u_int32_t d_ntracks; /* # of tracks per cylinder */ u_int32_t d_ncylinders; /* # of data cylinders per unit */ u_int32_t d_secpercyl; /* # of data sectors per cylinder = */ u_int32_t d_secperunit; /* # of data sectors per unit */ u_int16_t d_sparespertrack; /* # of spare sectors per track */ u_int16_t d_sparespercyl; /* # of spare sectors per cylinder = */ u_int32_t d_acylinders; /* # of alt. cylinders per unit */ u_int16_t d_rpm; /* rotational speed */ u_int16_t d_interleave; /* hardware sector interleave */ u_int16_t d_trackskew; /* sector 0 skew, per track */ u_int16_t d_cylskew; /* sector 0 skew, per cylinder */ u_int32_t d_headswitch; /* head switch time, usec */ u_int32_t d_trkseek; /* track-to-track seek, usec */ u_int32_t d_flags; /* generic flags */ u_int32_t d_drivedata[5]; /* drive-type specific information = */ u_int32_t d_spare[5]; /* reserved for future use */ u_int32_t d_magic2; /* the magic number (again) */ u_int16_t d_checksum; /* xor of data incl. partitions */ /* filesystem and partition information: */ u_int16_t d_npartitions; /* number of partitions in = following */ u_int32_t d_bbsize; /* size of boot area at sn0, bytes = */ u_int32_t d_sbsize; /* max size of fs superblock, = bytes */ struct bsd_partition d_partitions[MAXPARTITIONS]; /* actually may be = more */ }; struct canonical_partition { u_int64_t start, size; int type; }; static struct canonical_partition partitions[MAXPARTITIONS]; static int read_dos_disklabel(int fd, u_int64_t disk_size) { struct dos_disklabel disklabel; u_int64_t first_sector =3D 0; u_int64_t extended_offset =3D 0; int current_part =3D 0; while (1) { int i, extended =3D -1; if (lseek(fd, first_sector*512+MSDOS_LABEL_OFFSET, SEEK_SET) < 0) return -1; if (read(fd, &disklabel, sizeof(disklabel)) !=3D = sizeof(disklabel)) return -1; if (disklabel.magic !=3D MSDOS_DISKMAGIC) return -2; for (i =3D 0; i < 4; ++i) { u_int32_t p_start_sect, p_nr_sects, p_sys_ind; p_start_sect =3D disklabel.d_partitions[i].start_sect; p_nr_sects =3D disklabel.d_partitions[i].nr_sects; p_sys_ind =3D disklabel.d_partitions[i].sys_ind; if (p_nr_sects =3D=3D 0) continue; if (p_sys_ind =3D=3D MSDOS_FS_DOS_EXT || p_sys_ind =3D=3D MSDOS_FS_WIN98_EXT || p_sys_ind =3D=3D MSDOS_FS_LINUX_EXT) { if (extended =3D=3D -1) extended =3D i; continue; } /* Check the 3rd and 4th entries -- these sometimes contain random garbage. */ if (i >=3D 2 && (p_start_sect + p_nr_sects > disk_size || first_sector + p_start_sect < first_sector || first_sector + p_start_sect + p_nr_sects < first_sector)) continue; partitions[current_part].start =3D first_sector + p_start_sect; partitions[current_part].size =3D p_nr_sects; partitions[current_part].type =3D p_sys_ind; current_part++; } if (extended < 0) break; if (current_part < 4) current_part =3D 4; first_sector =3D extended_offset + disklabel.d_partitions[extended].start_sect; if (extended_offset =3D=3D 0) { disk_size =3D disklabel.d_partitions[extended].nr_sects; extended_offset =3D first_sector; } } return 0; } static int read_bsd_disklabel(int fd, u_int64_t disk_size) { struct bsd_disklabel disklabel; int max_partitions, i, j; if (lseek(fd, BSD_LABEL_OFFSET, SEEK_SET) < 0) return -1; if (read(fd, &disklabel, sizeof(disklabel)) !=3D sizeof(disklabel)) return -1; if (disklabel.d_magic !=3D BSD_DISKMAGIC || disklabel.d_magic2 !=3D BSD_DISKMAGIC) return -2; max_partitions =3D disklabel.d_npartitions; if (max_partitions > MAXPARTITIONS) max_partitions =3D MAXPARTITIONS; for (i =3D 0; i < max_partitions; ++i) { u_int64_t start, size; int type; if (disklabel.d_partitions[i].p_fstype =3D=3D BSD_FS_UNUSED) continue; start =3D disklabel.d_partitions[i].p_offset; size =3D disklabel.d_partitions[i].p_size; for (j =3D 0; j < i; ++j) { if (partitions[j].type =3D=3D 0) continue; /* No relationship -- try again. */ if (partitions[j].start + partitions[j].size <=3D start || partitions[j].start >=3D start + size) continue; /* Equal -- no need to add. */ if (partitions[j].start =3D=3D start && partitions[j].size =3D=3D size) goto no_add; /* BSD living in dos partition. */ if (partitions[j].start <=3D start && partitions[j].start + partitions[j].size >=3D start + size) goto add; /* Overlap. Don't try to add. */ goto no_add; } add: partitions[i].start =3D start; partitions[i].size =3D size; switch (disklabel.d_partitions[i].p_fstype) { case BSD_FS_SWAP: type =3D MSDOS_FS_LINUX_SWAP; break; case BSD_FS_EXT2: type =3D MSDOS_FS_LINUX; break; case BSD_FS_BSDFFS: type =3D MSDOS_FS_BSDI; break; default: type =3D MSDOS_FS_UNKNOWN; break; } partitions[i].type =3D type; no_add:; } return 0; } static int write_dos_disklabel(int fd) { return -2; } static int write_bsd_disklabel(int fd) { struct bsd_disklabel disklabel; int i, num_partitions; memset(&disklabel, 0, sizeof(disklabel)); disklabel.d_magic =3D BSD_DISKMAGIC; disklabel.d_magic2 =3D BSD_DISKMAGIC; disklabel.d_type =3D BSD_DTYPE_SCSI; memcpy(disklabel.d_typename, "SCSI", 4); disklabel.d_secsize =3D 512; num_partitions =3D 0; for (i =3D 0; i < MAXPARTITIONS; ++i) { int type =3D partitions[i].type; if (type =3D=3D 0) continue; switch (type) { case MSDOS_FS_LINUX: type =3D BSD_FS_EXT2; break; case MSDOS_FS_LINUX_SWAP: type =3D BSD_FS_SWAP; break; case MSDOS_FS_BSDI: type =3D BSD_FS_BSDFFS; break; default: type =3D BSD_FS_UNKNOWN; break; } disklabel.d_partitions[i].p_offset =3D partitions[i].start; disklabel.d_partitions[i].p_size =3D partitions[i].size; disklabel.d_partitions[i].p_fstype =3D type; num_partitions =3D i+1; } disklabel.d_npartitions =3D num_partitions; if (lseek(fd, BSD_LABEL_OFFSET, SEEK_SET) < 0) return -1; if (write(fd, &disklabel, sizeof(disklabel)) !=3D sizeof(disklabel)) return -1; return 0; } static void print_partitions(void) { int i; for (i =3D 0; i < MAXPARTITIONS; ++i) { if (partitions[i].type =3D=3D 0) continue; printf("%2d %9ld %9ld %02x\n", i+1, partitions[i].start, partitions[i].size, partitions[i].type); } } static void __attribute__((noreturn)) usage(void) { fprintf(stderr, "\ Usage: labelcvt