diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libdisk/Makefile | 7 | ||||
-rw-r--r-- | lib/libdisk/change.c | 17 | ||||
-rw-r--r-- | lib/libdisk/chunk.c | 6 | ||||
-rw-r--r-- | lib/libdisk/disk.c | 27 | ||||
-rw-r--r-- | lib/libdisk/libdisk.h | 9 | ||||
-rw-r--r-- | lib/libdisk/rules.c | 33 | ||||
-rw-r--r-- | lib/libdisk/tst01.c | 128 |
7 files changed, 181 insertions, 46 deletions
diff --git a/lib/libdisk/Makefile b/lib/libdisk/Makefile index 6a5fcdb..8f55911 100644 --- a/lib/libdisk/Makefile +++ b/lib/libdisk/Makefile @@ -1,11 +1,14 @@ .PATH: /usr/src/sbin/disklabel OBJS= tst01.o blocks.o disklabel.o dkcksum.o chunk.o disk.o change.o \ create_chunk.o rules.o -CFLAGS+= -Wall +CFLAGS+= -Wall -g test: tst01 cp tst01 /0 ./tst01 sd0 tst01: ${OBJS} - cc ${CFLAGS} -static -o tst01 ${OBJS} + cc ${CFLAGS} -static -o tst01 ${OBJS} -lreadline -ltermcap + +clean: + rm -f *.o *.core tst01 diff --git a/lib/libdisk/change.c b/lib/libdisk/change.c index b1db61c..76d28cf 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$ + * $Id: change.c,v 1.2 1995/04/29 01:55:18 phk Exp $ * */ @@ -42,3 +42,18 @@ Set_Bios_Geom(struct disk *disk, u_long cyl, u_long hd, u_long sect) disk->bios_sect = sect; Bios_Limit_Chunk(disk->chunks,1024*hd*sect); } + +void +All_FreeBSD(struct disk *d) +{ + struct chunk *c; + + again: + for (c=d->chunks->part;c;c=c->next) + if (c->type != unused) { + Delete_Chunk(d,c); + goto again; + } + c=d->chunks; + Create_Chunk(d,c->offset,c->size,freebsd,0,0); +} diff --git a/lib/libdisk/chunk.c b/lib/libdisk/chunk.c index a286cb1..e81c646 100644 --- a/lib/libdisk/chunk.c +++ b/lib/libdisk/chunk.c @@ -6,7 +6,7 @@ * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp * ---------------------------------------------------------------------------- * - * $Id$ + * $Id: chunk.c,v 1.2 1995/04/29 01:55:19 phk Exp $ * */ @@ -228,8 +228,8 @@ Print_Chunk(struct chunk *c1,int offset) if(!c1) return; for(i=0;i<offset;i++) putchar('>'); for(;i<10;i++) putchar(' '); - printf("%10lu %10lu %10lu %-8s %d %-8s %d %lx\n", - c1->offset, c1->size, c1->end, c1->name, + printf("%p %10lu %10lu %10lu %-8s %d %-8s %d %lx\n", + c1, c1->offset, c1->size, c1->end, c1->name, c1->type, chunk_n[c1->type],c1->subtype,c1->flags); Print_Chunk(c1->part,offset + 2); Print_Chunk(c1->next,offset); diff --git a/lib/libdisk/disk.c b/lib/libdisk/disk.c index 4f78c5a..154e687 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$ + * $Id: disk.c,v 1.2 1995/04/29 01:55:21 phk Exp $ * */ @@ -65,9 +65,10 @@ Int_Open_Disk(char *name, u_long size) size = ds.dss_slices[WHOLE_DISK_SLICE].ds_size; Add_Chunk(d, 0, size, name,whole,0,0); - Add_Chunk(d, 0, 1, "-",reserved,0,0); + if (ds.dss_slices[COMPATIBILITY_SLICE].ds_offset) + Add_Chunk(d, 0, 1, "-",reserved,0,0); - for(i=2;i<ds.dss_nslices;i++) { + for(i=BASE_SLICE;i<ds.dss_nslices;i++) { char sname[20]; chunk_e ce; u_long flags=0; @@ -164,23 +165,3 @@ Collapse_Disk(struct disk *d) while(Collapse_Chunk(d,d->chunks)) ; } - -int -Aligned(struct disk *d, u_long offset) -{ - if (offset % d->bios_sect) - return 0; - return 1; -} - -u_long -Prev_Aligned(struct disk *d, u_long offset) -{ - return (offset / d->bios_sect) * d->bios_sect; -} - -u_long -Next_Aligned(struct disk *d, u_long offset) -{ - return Prev_Aligned(d,offset + d->bios_sect); -} diff --git a/lib/libdisk/libdisk.h b/lib/libdisk/libdisk.h index 2946f90..e4412cf 100644 --- a/lib/libdisk/libdisk.h +++ b/lib/libdisk/libdisk.h @@ -6,14 +6,14 @@ * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp * ---------------------------------------------------------------------------- * - * $Id$ + * $Id: libdisk.h,v 1.2 1995/04/29 01:55:23 phk Exp $ * */ typedef enum {whole, foo, fat, freebsd, extended, part, unused, reserved} chunk_e; #define CHAR_N static char *chunk_n[] = { \ - "whole","foo","fat","freebsd","extended","part","unused","reserved"}; + "whole","foo","fat","freebsd","extended","part","unused","reserved",0}; struct disk { char *name; @@ -103,6 +103,11 @@ Create_Chunk(struct disk *disk, u_long offset, u_long size, chunk_e type, int su /* Create a chunk with the specified paramters */ +void +All_FreeBSD(struct disk *d); + /* Make one FreeBSD chunk covering the entire disk + */ + char * CheckRules(struct disk *); /* Return char* to warnings about broken design rules in this disklayout diff --git a/lib/libdisk/rules.c b/lib/libdisk/rules.c index 7db89ea..447c6de 100644 --- a/lib/libdisk/rules.c +++ b/lib/libdisk/rules.c @@ -6,7 +6,7 @@ * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp * ---------------------------------------------------------------------------- * - * $Id$ + * $Id: rules.c,v 1.1 1995/04/29 01:55:24 phk Exp $ * */ @@ -20,6 +20,32 @@ #include <err.h> #include "libdisk.h" +int +Aligned(struct disk *d, u_long offset) +{ + if (!d->bios_sect) + return 1; + if (offset % d->bios_sect) + return 0; + return 1; +} + +u_long +Prev_Aligned(struct disk *d, u_long offset) +{ + if (!d->bios_sect) + return offset; + return (offset / d->bios_sect) * d->bios_sect; +} + +u_long +Next_Aligned(struct disk *d, u_long offset) +{ + if (!d->bios_sect) + return offset; + return Prev_Aligned(d,offset + d->bios_sect); +} + /* * Rule#0: * Chunks of type 'whole' can have max NDOSPART children. @@ -44,7 +70,8 @@ Rule_000(struct disk *d, struct chunk *c, char *msg) /* * Rule#1: - * All children of 'whole' must be track-aligned + * All children of 'whole' must be track-aligned. + * Exception: the end can be unaligned if it matches the end of 'whole' */ void Rule_001(struct disk *d, struct chunk *c, char *msg) @@ -63,7 +90,7 @@ Rule_001(struct disk *d, struct chunk *c, char *msg) sprintf(msg+strlen(msg), "chunk '%s' [%ld..%ld] does not start on a track boundary\n", c1->name,c1->offset,c1->end); - if (!Aligned(d,c1->end+1)) + if (c->end != c1->end && !Aligned(d,c1->end+1)) sprintf(msg+strlen(msg), "chunk '%s' [%ld..%ld] does not end on a track boundary\n", c1->name,c1->offset,c1->end); diff --git a/lib/libdisk/tst01.c b/lib/libdisk/tst01.c index 9320356..8ed705a 100644 --- a/lib/libdisk/tst01.c +++ b/lib/libdisk/tst01.c @@ -6,32 +6,136 @@ * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp * ---------------------------------------------------------------------------- * - * $Id$ + * $Id: tst01.c,v 1.2 1995/04/29 01:55:25 phk Exp $ * */ #include <stdio.h> #include <stdlib.h> #include <unistd.h> +#include <err.h> +#include <readline/readline.h> +#include <readline/history.h> #include <sys/types.h> #include "libdisk.h" +CHAR_N; + int main(int argc, char **argv) { - int i; - struct disk *d; + struct disk *d,*db; + char myprompt[BUFSIZ]; + char *p,*q=0; + char **cp,*cmds[200]; + int ncmd,i; - for(i=1;i<argc;i++) { - d = Open_Disk(argv[i]); - if (!d) continue; - Debug_Disk(d); - if (d->chunks->size == 1411200) - Set_Bios_Geom(d,1024,15,63); - else - Set_Bios_Geom(d,2003,64,32); + if (argc < 2) { + fprintf(stderr,"Usage:\n\t%s diskname\n",argv[0]); + exit(1); + } + d = Open_Disk(argv[1]); + if (!d) + err(1,"Coudn't open disk %s",argv[1]); + + sprintf(myprompt,"%s %s> ",argv[0],argv[1]); + while(1) { + printf("\n\n\n\n"); Debug_Disk(d); - printf("<%s>\n",CheckRules(d)); + p = CheckRules(d); + if (p) { + printf("%s",p); + free(p); + } + if (q) + free(q); + q = p = readline(myprompt); + if(!p) + break; + for(cp = cmds; (*cp = strsep(&p, " \t")) != NULL;) + if (**cp != '\0') + cp++; + ncmd = cp - cmds; + if(!ncmd) + continue; + if (!strcasecmp(*cmds,"quit")) { break; } + if (!strcasecmp(*cmds,"exit")) { break; } + if (!strcasecmp(*cmds,"q")) { break; } + if (!strcasecmp(*cmds,"x")) { break; } + if (!strcasecmp(*cmds,"delete") && ncmd == 2) { + printf("delete = %d\n", + Delete_Chunk(d, + (struct chunk *)strtol(cmds[1],0,0))); + continue; + } + if (!strcasecmp(*cmds,"allfreebsd")) { + All_FreeBSD(d); + 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)); + continue; + } + if (!strcasecmp(*cmds,"phys") && ncmd == 4) { + d = Set_Phys_Geom(d, + strtol(cmds[1],0,0), + strtol(cmds[2],0,0), + strtol(cmds[3],0,0)); + continue; + } + if (!strcasecmp(*cmds,"collapse")) { + if (cmds[1]) + while (Collapse_Chunk(d, + (struct chunk *)strtol(cmds[1],0,0))) + ; + else + Collapse_Disk(d); + continue; + } + if (!strcasecmp(*cmds,"read")) { + db=d; + if (cmds[1]) + d = Open_Disk(cmds[1]); + else + d = Open_Disk(db->name); + if (!d) { + fprintf(stderr,"Failed to open %s\n",argv[1]); + d = db; + } else { + Free_Disk(db); + } + continue; + } + if (!strcasecmp(*cmds,"create") && ncmd == 6) { + + printf("Create=%d\n", + Create_Chunk(d, + strtol(cmds[1],0,0), + strtol(cmds[2],0,0), + strtol(cmds[3],0,0), + strtol(cmds[4],0,0), + strtol(cmds[5],0,0))); + continue; + } + if (strcasecmp(*cmds,"help")) + printf("\007ERROR\n"); + printf("CMDS:\n"); + printf("\tallfreebsd\n"); + printf("\tbios cyl hd sect\n"); + printf("\tcollapse [pointer]\n"); + printf("\tcreate offset size enum subtype flags\n"); + printf("\tdelete pointer\n"); + printf("\tphys cyl hd sect\n"); + printf("\tquit\n"); + printf("\tread [disk]\n"); + printf("\nENUM:\n\t"); + for(i=0;chunk_n[i];i++) + printf("%d = %s%s",i,chunk_n[i],i == 4 ? "\n\t" : " "); + printf("\n"); + } exit (0); } |