summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJordan K. Hubbard <jkh@FreeBSD.org>1997-02-07 03:24:15 +0000
committerJordan K. Hubbard <jkh@FreeBSD.org>1997-02-07 03:24:15 +0000
commit864e2d4780fa9b9b86d7b18757c0be1e8bcb7bf1 (patch)
tree58b8eff5db35885e3bbe06d4e2e3f51b77de7dc8 /lib
parentd4cc0dd69888e0273db0326f6e0bec71caa0668b (diff)
Notes
Diffstat (limited to 'lib')
-rw-r--r--lib/libdisk/Makefile5
-rw-r--r--lib/libdisk/change.c60
-rw-r--r--lib/libdisk/create_chunk.c4
-rw-r--r--lib/libdisk/disk.c45
-rw-r--r--lib/libdisk/libdisk.321
-rw-r--r--lib/libdisk/libdisk.h27
-rw-r--r--lib/libdisk/tst01.c26
-rw-r--r--lib/libdisk/write_disk.c8
8 files changed, 126 insertions, 70 deletions
diff --git a/lib/libdisk/Makefile b/lib/libdisk/Makefile
index ff2ec6ec69c6..a2ac1be063e9 100644
--- a/lib/libdisk/Makefile
+++ b/lib/libdisk/Makefile
@@ -1,4 +1,4 @@
-# $Id: Makefile,v 1.11.4.6 1996/06/05 02:52:27 jkh Exp $
+# $Id: Makefile,v 1.11.4.7 1996/07/09 12:18:58 jkh Exp $
LIB= disk
SRCS= blocks.c disklabel.c dkcksum.c chunk.c disk.c change.c \
@@ -37,7 +37,8 @@ MLINKS+= libdisk.3 Open_Disk.3 \
libdisk.3 MakeDev.3 \
libdisk.3 MakeDevDisk.3 \
libdisk.3 ShowChunkFlags.3 \
- libdisk.3 ChunkCanBeRoot.3
+ libdisk.3 ChunkCanBeRoot.3 \
+ libdisk.3 slice_type_name.3
.include <bsd.lib.mk>
diff --git a/lib/libdisk/change.c b/lib/libdisk/change.c
index 4b2482239fbb..b75225d124e9 100644
--- a/lib/libdisk/change.c
+++ b/lib/libdisk/change.c
@@ -6,7 +6,7 @@
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
* ----------------------------------------------------------------------------
*
- * $Id: change.c,v 1.10 1995/12/07 10:33:18 peter Exp $
+ * $Id: change.c,v 1.9.2.2 1996/05/28 22:51:09 jkh Exp $
*
*/
@@ -19,23 +19,6 @@
#include <sys/types.h>
#include "libdisk.h"
-#if 0
-struct disk *
-Set_Phys_Geom(struct disk *disk, u_long cyl, u_long hd, u_long sect)
-{
- struct disk *d = Int_Open_Disk(disk->name,cyl*hd*sect);
- d->real_cyl = cyl;
- d->real_hd = hd;
- d->real_sect = sect;
- d->bios_cyl = disk->bios_cyl;
- d->bios_hd = disk->bios_hd;
- d->bios_sect = disk->bios_sect;
- d->flags = disk->flags;
- Free_Disk(disk);
- return d;
-}
-#endif
-
void
Set_Bios_Geom(struct disk *disk, u_long cyl, u_long hd, u_long sect)
{
@@ -46,6 +29,38 @@ Set_Bios_Geom(struct disk *disk, u_long cyl, u_long hd, u_long sect)
}
void
+Sanitize_Bios_Geom(struct disk *disk)
+{
+ int sane = 1;
+
+ if (disk->bios_cyl > 1024)
+ sane = 0;
+ if (disk->bios_hd > 16)
+ sane = 0;
+ if (disk->bios_sect > 63)
+ sane = 0;
+ if (disk->bios_cyl*disk->bios_hd*disk->bios_sect !=
+ disk->chunks->size)
+ sane = 0;
+ if (sane)
+ return;
+
+ /* First try something that IDE can handle */
+ disk->bios_sect = 63;
+ disk->bios_hd = 16;
+ disk->bios_cyl = disk->chunks->size/(disk->bios_sect*disk->bios_hd);
+
+ if (disk->bios_cyl < 1024)
+ return;
+
+ /* Hmm, try harder... */
+ disk->bios_hd = 255;
+ disk->bios_cyl = disk->chunks->size/(disk->bios_sect*disk->bios_hd);
+
+ return;
+}
+
+void
All_FreeBSD(struct disk *d, int force_all)
{
struct chunk *c;
@@ -57,6 +72,11 @@ All_FreeBSD(struct disk *d, int force_all)
goto again;
}
c=d->chunks;
- Create_Chunk(d,c->offset,c->size,freebsd,0xa5,
- force_all? CHUNK_FORCE_ALL: 0);
+ if (force_all) {
+ Sanitize_Bios_Geom(d);
+ Create_Chunk(d,c->offset,c->size,freebsd,0xa5,
+ CHUNK_FORCE_ALL);
+ } else {
+ Create_Chunk(d,c->offset,c->size,freebsd,0xa5, 0);
+ }
}
diff --git a/lib/libdisk/create_chunk.c b/lib/libdisk/create_chunk.c
index cf15f0e3187a..063f9079da02 100644
--- a/lib/libdisk/create_chunk.c
+++ b/lib/libdisk/create_chunk.c
@@ -6,7 +6,7 @@
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
* ----------------------------------------------------------------------------
*
- * $Id: create_chunk.c,v 1.24 1996/04/29 05:03:01 jkh Exp $
+ * $Id: create_chunk.c,v 1.21.2.8 1996/05/28 22:51:12 jkh Exp $
*
*/
@@ -257,6 +257,8 @@ MakeDev(struct chunk *c1, const char *path)
bmaj = 0, cmaj = 3;
else if (!strncmp(p, "sd", 2))
bmaj = 4, cmaj = 13;
+ else if (!strncmp(p, "od", 2))
+ bmaj = 20, cmaj = 70;
else {
return 0;
}
diff --git a/lib/libdisk/disk.c b/lib/libdisk/disk.c
index 6f672b694160..3dab99c1aa3e 100644
--- a/lib/libdisk/disk.c
+++ b/lib/libdisk/disk.c
@@ -6,7 +6,7 @@
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
* ----------------------------------------------------------------------------
*
- * $Id: disk.c,v 1.22 1996/04/29 05:03:02 jkh Exp $
+ * $Id: disk.c,v 1.20.2.2 1996/05/28 22:51:14 jkh Exp $
*
*/
@@ -231,7 +231,9 @@ Debug_Disk(struct disk *d)
#if 0
printf(" real_geom=%lu/%lu/%lu",d->real_cyl,d->real_hd,d->real_sect);
#endif
- printf(" bios_geom=%lu/%lu/%lu\n",d->bios_cyl,d->bios_hd,d->bios_sect);
+ printf(" bios_geom=%lu/%lu/%lu = %lu\n",
+ d->bios_cyl,d->bios_hd,d->bios_sect,
+ d->bios_cyl*d->bios_hd*d->bios_sect);
printf(" boot1=%p, boot2=%p, bootmgr=%p\n",
d->boot1,d->boot2,d->bootmgr);
Debug_Chunk(d->chunks);
@@ -283,7 +285,7 @@ Collapse_Disk(struct disk *d)
}
#endif
-static char * device_list[] = {"wd","sd",0};
+static char * device_list[] = {"wd","sd","od",0};
char **
Disk_Names()
@@ -345,3 +347,40 @@ Set_Boot_Blocks(struct disk *d, const u_char *b1, const u_char *b2)
if(!d->boot2) err(1,"malloc failed");
memcpy(d->boot2,b2,15*512);
}
+
+const char *
+slice_type_name( int type, int subtype )
+{
+ switch (type) {
+ case 0: return "whole";
+ case 1: switch (subtype) {
+ case 1: return "fat (12-bit)";
+ case 2: return "XENIX /";
+ case 3: return "XENIX /usr";
+ case 4: return "fat (16-bit)";
+ case 5: return "extended DOS";
+ case 6: return "fat (>32Mb)";
+ case 7: return "NTFS/HPFS";
+ case 10: return "OS/2 bootmgr";
+ case 84: return "OnTrack diskmgr";
+ case 100: return "Netware 2.x";
+ case 101: return "Netware 3.x";
+ case 128: return "Minix 1.1";
+ case 129: return "Minix 1.5";
+ case 130: return "linux_swap";
+ case 131: return "ext2fs";
+ case 183: return "bsd/os";
+ case 184: return "bsd/os swap";
+ default: return "unknown";
+ }
+ case 2: return "fat";
+ case 3: switch (subtype) {
+ case 165: return "freebsd";
+ default: return "unknown";
+ }
+ case 4: return "extended";
+ case 5: return "part";
+ case 6: return "unused";
+ default: return "unknown";
+ }
+}
diff --git a/lib/libdisk/libdisk.3 b/lib/libdisk/libdisk.3
index 419b999edf62..f942edc95f39 100644
--- a/lib/libdisk/libdisk.3
+++ b/lib/libdisk/libdisk.3
@@ -25,7 +25,7 @@
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.\" $Id: libdisk.3,v 1.2 1996/03/24 18:55:38 joerg Exp $
+.\" $Id: libdisk.3,v 1.1.2.2 1996/05/28 22:51:15 jkh Exp $
.\" "
.Dd March 15, 1996
.Dt LIBDISK 3
@@ -57,11 +57,19 @@
.Nm MakeDevDisk ,
.Nm ShowChunkFlags ,
.Nm ChunkCanBeRoot ,
+.Nm chunk_n ,
+.Nm slice_type_name
.Nd library interface to slice and partition labels
.Sh SYNOPSIS
.Fd #include <sys/types.h>
.Fd #include <libdisk.h>
.Dv extern const u_char *boot1, boot2;
+.\" What is the correct way to cause a single line break ???
+.Bd -literal
+.Dv extern const char *chunk_n[];
+.Ed
+.Ft const char *
+.Fn slice_type_name "int type" "int subtype"
.Ft struct disk *
.Fn Open_Disk "const char *devname"
.Ft struct disk *
@@ -310,6 +318,17 @@ returns a string to show flags.
.Pp
.Fn ChunkCanBeRoot
returns NULL if chunk can be
+.Pp
+Chunk name strings can be accessed directly using the external array
+.Va chunk_n .
+.Pp
+.Fn slice_type_name
+returns the name strings associated with the specified
+.Ql type .
+.Ql subtype .
+If
+.Fn slice_type_name
+returns "unknown" for slices it isn't familar with.
.Ql / .
.Sh AUTHOR
.Nm Libdisk
diff --git a/lib/libdisk/libdisk.h b/lib/libdisk/libdisk.h
index 92be9e9474e8..eecac4de05ab 100644
--- a/lib/libdisk/libdisk.h
+++ b/lib/libdisk/libdisk.h
@@ -6,7 +6,7 @@
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
* ----------------------------------------------------------------------------
*
-* $Id: libdisk.h,v 1.22 1996/04/29 06:45:33 jkh Exp $
+* $Id: libdisk.h,v 1.19.2.4 1996/05/28 22:51:17 jkh Exp $
*
*/
@@ -28,11 +28,6 @@ struct disk {
char *name;
u_long flags;
# define DISK_ON_TRACK 1
-#if 0
- u_long real_cyl;
- u_long real_hd;
- u_long real_sect;
-#endif
u_long bios_cyl;
u_long bios_hd;
u_long bios_sect;
@@ -91,6 +86,11 @@ struct chunk {
extern const char *chunk_n[];
extern const u_char boot1[], boot2[];
+const char *
+slice_type_name( int type, int subtype );
+/* "chunk_n" for subtypes too
+ */
+
struct disk *
Open_Disk(const char *devname);
/* Will open the named disk, and return populated tree.
@@ -111,19 +111,16 @@ Debug_Disk(struct disk *disk);
/* Print the content of the tree to stdout
*/
-#if 0
-struct disk *
-Set_Phys_Geom(struct disk *disk, u_long cyl, u_long heads, u_long sects);
-/* Use a different physical geometry. Makes sense for ST506 disks only.
- * The tree returned is read from the disk, using this geometry.
- */
-#endif
-
void
Set_Bios_Geom(struct disk *disk, u_long cyl, u_long heads, u_long sects);
/* Set the geometry the bios uses.
*/
+void
+Sanitize_Bios_Geom(struct disk *disk);
+/* Set the bios geometry to something sane
+ */
+
int
Delete_Chunk(struct disk *disk, struct chunk *);
/* Free a chunk of disk_space
@@ -278,7 +275,7 @@ __END_DECLS
*
*Sample output from tst01:
*
- * Debug_Disk(wd0) flags=0 real_geom=0/0/0 bios_geom=0/0/0
+ * Debug_Disk(wd0) flags=0 bios_geom=0/0/0
* >> 0x3d040 0 1411200 1411199 wd0 0 whole 0 0
* >>>> 0x3d080 0 960120 960119 wd0s1 3 freebsd 0 8
* >>>>>> 0x3d100 0 40960 40959 wd0s1a 5 part 0 0
diff --git a/lib/libdisk/tst01.c b/lib/libdisk/tst01.c
index c392259171d7..29dcf750e0e9 100644
--- a/lib/libdisk/tst01.c
+++ b/lib/libdisk/tst01.c
@@ -6,7 +6,7 @@
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
* ----------------------------------------------------------------------------
*
- * $Id: tst01.c,v 1.15.2.3 1996/05/28 22:51:18 jkh Exp $
+ * $Id: tst01.c,v 1.15.2.4 1996/07/09 12:19:03 jkh Exp $
*
*/
@@ -196,33 +196,17 @@ main(int argc, char **argv)
All_FreeBSD(d, 1);
continue;
}
- if (!strcasecmp(*cmds,"bios") && ncmd == 4) {
- Set_Bios_Geom(d,
- strtol(cmds[1],0,0),
- strtol(cmds[2],0,0),
- strtol(cmds[3],0,0));
+ if (!strcasecmp(*cmds,"sanitize")) {
+ Sanitize_Bios_Geom(d);
continue;
}
-#if 0
- if (!strcasecmp(*cmds,"phys") && ncmd == 4) {
- d = Set_Phys_Geom(d,
+ if (!strcasecmp(*cmds,"bios") && ncmd == 4) {
+ Set_Bios_Geom(d,
strtol(cmds[1],0,0),
strtol(cmds[2],0,0),
strtol(cmds[3],0,0));
continue;
}
-#endif
-#if 0
- if (!strcasecmp(*cmds,"collapse")) {
- if (cmds[1])
- while (Collapse_Chunk(d,
- (struct chunk *)strtol(cmds[1],0,0)))
- ;
- else
- Collapse_Disk(d);
- continue;
- }
-#endif
if (!strcasecmp(*cmds,"list")) {
cp = Disk_Names();
printf("Disks:");
diff --git a/lib/libdisk/write_disk.c b/lib/libdisk/write_disk.c
index 383f656bb3cd..fc348b378732 100644
--- a/lib/libdisk/write_disk.c
+++ b/lib/libdisk/write_disk.c
@@ -6,7 +6,7 @@
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
* ----------------------------------------------------------------------------
*
- * $Id: write_disk.c,v 1.17 1996/04/29 05:03:02 jkh Exp $
+ * $Id: write_disk.c,v 1.14.2.3 1996/05/28 22:51:19 jkh Exp $
*
*/
@@ -80,15 +80,9 @@ Write_FreeBSD(int fd, struct disk *new, struct disk *old, struct chunk *c1)
dl->d_secsize = 512;
dl->d_secperunit = new->chunks->size;
-#if 0
- dl->d_ncylinders = new->real_cyl ? new->real_cyl : new->bios_cyl;
- dl->d_ntracks = new->real_hd ? new->real_hd : new->bios_hd;
- dl->d_nsectors = new->real_sect ? new->real_sect : new->bios_sect;
-#else
dl->d_ncylinders = new->bios_cyl;
dl->d_ntracks = new->bios_hd;
dl->d_nsectors = new->bios_sect;
-#endif
dl->d_secpercyl = dl->d_ntracks * dl->d_nsectors;
dl->d_npartitions = MAXPARTITIONS;