diff options
author | Poul-Henning Kamp <phk@FreeBSD.org> | 1995-04-29 07:21:14 +0000 |
---|---|---|
committer | Poul-Henning Kamp <phk@FreeBSD.org> | 1995-04-29 07:21:14 +0000 |
commit | a29b6fccc0d480a9f4fed41056a2f357aaf1101b (patch) | |
tree | fa70e13b20375cea9c33bb00b43511f4b3042b5e /lib | |
parent | 65b36cbb7d3d450ecf2b93a137bf4d42d65effa6 (diff) | |
download | src-a29b6fccc0d480a9f4fed41056a2f357aaf1101b.tar.gz src-a29b6fccc0d480a9f4fed41056a2f357aaf1101b.zip |
Names are assigned when chunks are created.
Rules for only one fat & one extended in MBR.
Notes
Notes:
svn path=/head/; revision=8160
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libdisk/Makefile | 4 | ||||
-rw-r--r-- | lib/libdisk/create_chunk.c | 112 | ||||
-rw-r--r-- | lib/libdisk/disk.c | 18 | ||||
-rw-r--r-- | lib/libdisk/libdisk.h | 8 | ||||
-rw-r--r-- | lib/libdisk/rules.c | 50 | ||||
-rw-r--r-- | lib/libdisk/tst01.c | 22 | ||||
-rw-r--r-- | lib/libdisk/write_disk.c | 34 |
7 files changed, 238 insertions, 10 deletions
diff --git a/lib/libdisk/Makefile b/lib/libdisk/Makefile index 8f55911b2355..4128a2966cf8 100644 --- a/lib/libdisk/Makefile +++ b/lib/libdisk/Makefile @@ -1,11 +1,11 @@ .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 + create_chunk.o rules.o write_disk.o CFLAGS+= -Wall -g test: tst01 cp tst01 /0 - ./tst01 sd0 + ./tst01 wd1 tst01: ${OBJS} cc ${CFLAGS} -static -o tst01 ${OBJS} -lreadline -ltermcap diff --git a/lib/libdisk/create_chunk.c b/lib/libdisk/create_chunk.c index 7abcac9a0e2d..82c0082d82c2 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$ + * $Id: create_chunk.c,v 1.2 1995/04/29 01:55:20 phk Exp $ * */ @@ -15,11 +15,119 @@ #include <unistd.h> #include <string.h> #include <sys/types.h> +#include <sys/disklabel.h> +#include <sys/diskslice.h> +#include <sys/types.h> #include <err.h> #include "libdisk.h" +void +Fixup_FreeBSD_Names(struct disk *d, struct chunk *c) +{ + struct chunk *c1, *c2, *c3; + int j; + char *p=0; + + for (c1 = c->part; c1 ; c1 = c1->next) { + if (c1->type == unused) continue; + if (c1->type == reserved) continue; + if (strcmp(c1->name, "X")) continue; + for(j=0;j<=8;j++) { + if (j == 2) + continue; + p = malloc(12); + if(!p) err(1,"malloc failed"); + sprintf(p,"%s%c",c->name,j+'a'); + for(c3 = c->part; c3 ; c3 = c3->next) + if (c3 != c1 && !strcmp(c3->name, p)) + goto match; + free(c1->name); + c1->name = p; + p = 0; + break; + match: + continue; + } + if(p) + free(p); + } +} + +void +Fixup_Extended_Names(struct disk *d, struct chunk *c) +{ + struct chunk *c1, *c2, *c3; + int j; + char *p=0; + + for (c1 = c->part; c1 ; c1 = c1->next) { + if (c1->type == freebsd) + Fixup_FreeBSD_Names(d,c1); + if (c1->type == unused) continue; + if (c1->type == reserved) continue; + if (strcmp(c1->name, "X")) continue; + for(j=5;j<=29;j++) { + p = malloc(12); + if(!p) err(1,"malloc failed"); + sprintf(p,"%ss%d",c->name,j); + for(c3 = c->part; c3 ; c3 = c3->next) + if (c3 != c1 && !strcmp(c3->name, p)) + goto match; + free(c1->name); + c1->name = p; + p = 0; + break; + match: + continue; + } + if(p) + free(p); + } +} + +void +Fixup_Names(struct disk *d) +{ + struct chunk *c1, *c2, *c3; + int i,j; + char *p=0; + + c1 = d->chunks; + for(i=1,c2 = c1->part; c2 ; c2 = c2->next) { + if (c2->type == freebsd) + Fixup_FreeBSD_Names(d,c2); + if (c2->type == extended) + Fixup_Extended_Names(d,c2); + if (c2->type == unused) + continue; + if (c2->type == reserved) + continue; + if (strcmp(c2->name,"X")) + continue; + p = malloc(12); + if(!p) err(1,"malloc failed"); + for(j=1;j<=NDOSPART;j++) { + sprintf(p,"%ss%d",c1->name,j); + for(c3 = c1->part; c3 ; c3 = c3->next) + if (c3 != c2 && !strcmp(c3->name, p)) + goto match; + free(c2->name); + c2->name = p; + p = 0; + break; + match: + continue; + } + if(p) + free(p); + } +} + int Create_Chunk(struct disk *d, u_long offset, u_long size, chunk_e type, int subtype, u_long flags) { - return Add_Chunk(d,offset,size,"X",type,subtype,flags); + int i; + i = Add_Chunk(d,offset,size,"X",type,subtype,flags); + Fixup_Names(d); + return i; } diff --git a/lib/libdisk/disk.c b/lib/libdisk/disk.c index 482a9cd87874..24d2657036aa 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.3 1995/04/29 04:00:55 phk Exp $ + * $Id: disk.c,v 1.4 1995/04/29 04:50:37 phk Exp $ * */ @@ -37,6 +37,7 @@ Int_Open_Disk(char *name, u_long size) { int i,fd; struct diskslices ds; + struct disklabel dl; char device[64]; struct disk *d; @@ -48,9 +49,15 @@ Int_Open_Disk(char *name, u_long size) warn("open(%s) failed",device); return 0; } + i = ioctl(fd,DIOCGDINFO,&dl); + if (i < 0) { + warn("DIOCGDINFO(%s) failed",device); + close(fd); + return 0; + } i = ioctl(fd,DIOCGSLICEINFO,&ds); if (i < 0) { - warn("DIOCSLICEINFO(%s) failed",device); + warn("DIOCGSLICEINFO(%s) failed",device); close(fd); return 0; } @@ -60,13 +67,20 @@ Int_Open_Disk(char *name, u_long size) memset(d,0,sizeof *d); + d->bios_sect = dl.d_nsectors; + d->bios_hd = dl.d_ntracks; + d->name = strdup(name); if (!size) size = ds.dss_slices[WHOLE_DISK_SLICE].ds_size; + if (dl.d_ntracks && dl.d_nsectors) + d->bios_cyl = size/(dl.d_ntracks*dl.d_nsectors); + if (Add_Chunk(d, 0, size, name,whole,0,0)) warn("Failed to add 'whole' chunk"); + if (ds.dss_slices[COMPATIBILITY_SLICE].ds_offset) if (Add_Chunk(d, 0, 1, "-",reserved,0,0)) warn("Failed to add MBR chunk"); diff --git a/lib/libdisk/libdisk.h b/lib/libdisk/libdisk.h index 8561bf04320f..a84481450eb0 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.3 1995/04/29 04:00:55 phk Exp $ + * $Id: libdisk.h,v 1.4 1995/04/29 04:50:38 phk Exp $ * */ @@ -137,6 +137,11 @@ Set_Boot_Blocks(struct disk *d, u_char *boot1, u_char *boot2); * is called */ +int +Write_Disk(struct disk *d); + /* Write all the MBRs, disklabels, bootblocks and boot managers + */ + /* * Implementation details >>> DO NOT USE <<< */ @@ -175,6 +180,7 @@ struct disk * Int_Open_Disk(char *name, u_long size); * * Make Create_DWIM(). * + * Make Is_Unchanged(struct disk *d1, struct chunk *c1) * *Sample output from tst01: * diff --git a/lib/libdisk/rules.c b/lib/libdisk/rules.c index 447c6de4f58e..9a53b4ef3bd2 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: rules.c,v 1.1 1995/04/29 01:55:24 phk Exp $ + * $Id: rules.c,v 1.2 1995/04/29 04:00:56 phk Exp $ * */ @@ -97,11 +97,59 @@ Rule_001(struct disk *d, struct chunk *c, char *msg) } } +/* + * Rule#2: + * Max one 'fat' as child of 'whole' + */ +void +Rule_002(struct disk *d, struct chunk *c, char *msg) +{ + int i; + struct chunk *c1; + + if (c->type != whole) + return; + for (i=0, c1=c->part; c1; c1=c1->next) { + if (c1->type != fat) + continue; + i++; + } + if (i > 1) { + sprintf(msg+strlen(msg), + "Max one 'fat' allowed as child of 'whole'\n"); + } +} + +/* + * Rule#3: + * Max one extended as child of 'whole' + */ +void +Rule_003(struct disk *d, struct chunk *c, char *msg) +{ + int i; + struct chunk *c1; + + if (c->type != whole) + return; + for (i=0, c1=c->part; c1; c1=c1->next) { + if (c1->type != extended) + continue; + i++; + } + if (i > 1) { + sprintf(msg+strlen(msg), + "Max one 'extended' allowed as child of 'whole'\n"); + } +} + void Check_Chunk(struct disk *d, struct chunk *c, char *msg) { Rule_000(d,c,msg); Rule_001(d,c,msg); + Rule_002(d,c,msg); + Rule_003(d,c,msg); if (c->part) Check_Chunk(d,c->part,msg); if (c->next) diff --git a/lib/libdisk/tst01.c b/lib/libdisk/tst01.c index 887c4ea54a16..4a866ba4d4b7 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.3 1995/04/29 04:00:57 phk Exp $ + * $Id: tst01.c,v 1.4 1995/04/29 04:50:39 phk Exp $ * */ @@ -24,7 +24,7 @@ CHAR_N; int main(int argc, char **argv) { - struct disk *d; + struct disk *d,*db; char myprompt[BUFSIZ]; char *p,*q=0; char **cp,*cmds[200]; @@ -116,6 +116,23 @@ main(int argc, char **argv) strtol(cmds[5],0,0))); continue; } + if (!strcasecmp(*cmds,"read")) { + db = d; + if (ncmd > 1) + d = Open_Disk(cmds[1]); + else + d = Open_Disk(argv[1]); + if (d) + Free_Disk(db); + else + d = db; + continue; + } + if (!strcasecmp(*cmds,"write")) { + printf("Write=%d\n", + Write_Disk(d)); + continue; + } if (strcasecmp(*cmds,"help")) printf("\007ERROR\n"); printf("CMDS:\n"); @@ -128,6 +145,7 @@ main(int argc, char **argv) printf("\tphys cyl hd sect\n"); printf("\tquit\n"); printf("\tread [disk]\n"); + printf("\twrite\n"); printf("\nENUM:\n\t"); for(i=0;chunk_n[i];i++) printf("%d = %s%s",i,chunk_n[i],i == 4 ? "\n\t" : " "); diff --git a/lib/libdisk/write_disk.c b/lib/libdisk/write_disk.c new file mode 100644 index 000000000000..aa7190503a0b --- /dev/null +++ b/lib/libdisk/write_disk.c @@ -0,0 +1,34 @@ +/* + * ---------------------------------------------------------------------------- + * "THE BEER-WARE LICENSE" (Revision 42): + * <phk@login.dknet.dk> wrote this file. As long as you retain this notice you + * can do whatever you want with this stuff. If we meet some day, and you think + * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp + * ---------------------------------------------------------------------------- + * + * $Id$ + * + */ + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <fcntl.h> +#include <string.h> +#include <err.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/ioctl.h> +#include <sys/disklabel.h> +#include <sys/diskslice.h> +#include "libdisk.h" + +#define DOSPTYP_EXTENDED 5 +#define DOSPTYP_ONTRACK 84 + +int +Write_Disk(struct disk *d1) +{ + return 0; +} + |