diff options
author | kato <kato@FreeBSD.org> | 2000-03-29 15:10:28 +0000 |
---|---|---|
committer | kato <kato@FreeBSD.org> | 2000-03-29 15:10:28 +0000 |
commit | 54a7094e5d5167a75913c05a4f511539b4708145 (patch) | |
tree | cfae1f8e5958bfc393694cb6e4d74178598c314a /lib/libdisk | |
parent | 40b6681aab0adb2ea899c21bc949625878abfbcc (diff) | |
download | FreeBSD-src-54a7094e5d5167a75913c05a4f511539b4708145.zip FreeBSD-src-54a7094e5d5167a75913c05a4f511539b4708145.tar.gz |
Changes for PC-98.
Diffstat (limited to 'lib/libdisk')
-rw-r--r-- | lib/libdisk/Makefile | 3 | ||||
-rw-r--r-- | lib/libdisk/change.c | 12 | ||||
-rw-r--r-- | lib/libdisk/chunk.c | 71 | ||||
-rw-r--r-- | lib/libdisk/create_chunk.c | 22 | ||||
-rw-r--r-- | lib/libdisk/disk.c | 76 | ||||
-rw-r--r-- | lib/libdisk/libdisk.h | 12 | ||||
-rw-r--r-- | lib/libdisk/rules.c | 28 | ||||
-rw-r--r-- | lib/libdisk/tst01.c | 13 | ||||
-rw-r--r-- | lib/libdisk/write_disk.c | 85 |
9 files changed, 322 insertions, 0 deletions
diff --git a/lib/libdisk/Makefile b/lib/libdisk/Makefile index f901a76..3711085 100644 --- a/lib/libdisk/Makefile +++ b/lib/libdisk/Makefile @@ -6,6 +6,9 @@ SRCS= blocks.c disklabel.c dkcksum.c chunk.c disk.c change.c \ INCS= libdisk.h CFLAGS+= -Wall +.if ${MACHINE} == "pc98" +CFLAGS+= -DPC98 +.endif CLEANFILES+= tmp.c tst01 tst01.o VPATH= ${.CURDIR}/../../sbin/disklabel NOPROFILE= yes diff --git a/lib/libdisk/change.c b/lib/libdisk/change.c index 6a506f8..acee5f1 100644 --- a/lib/libdisk/change.c +++ b/lib/libdisk/change.c @@ -25,9 +25,12 @@ Set_Bios_Geom(struct disk *disk, u_long cyl, u_long hd, u_long sect) disk->bios_cyl = cyl; disk->bios_hd = hd; disk->bios_sect = sect; +#ifndef PC98 Bios_Limit_Chunk(disk->chunks,1024*hd*sect); +#endif } +/* XXX - parameters should change to fit for PC-98, but I'm not sure */ void Sanitize_Bios_Geom(struct disk *disk) { @@ -74,9 +77,18 @@ All_FreeBSD(struct disk *d, int force_all) c=d->chunks; if (force_all) { Sanitize_Bios_Geom(d); +#ifdef PC98 + Create_Chunk(d,c->offset,c->size,freebsd,0x494, + CHUNK_FORCE_ALL,"FreeBSD"); +#else Create_Chunk(d,c->offset,c->size,freebsd,0xa5, CHUNK_FORCE_ALL); +#endif } else { +#ifdef PC98 + Create_Chunk(d,c->offset,c->size,freebsd,0x494, 0,"FreeBSD"); +#else Create_Chunk(d,c->offset,c->size,freebsd,0xa5, 0); +#endif } } diff --git a/lib/libdisk/chunk.c b/lib/libdisk/chunk.c index 6116f54..d8f4a10 100644 --- a/lib/libdisk/chunk.c +++ b/lib/libdisk/chunk.c @@ -44,6 +44,7 @@ Find_Mother_Chunk(struct chunk *chunks, u_long offset, u_long end, chunk_e type) case whole: if (Chunk_Inside(chunks,&ct)) return chunks; +#ifndef PC98 case extended: for(c1=chunks->part;c1;c1=c1->next) { if (c1->type != type) @@ -52,6 +53,7 @@ Find_Mother_Chunk(struct chunk *chunks, u_long offset, u_long end, chunk_e type) return c1; } return 0; +#endif case freebsd: for(c1=chunks->part;c1;c1=c1->next) { if (c1->type == type) @@ -82,6 +84,9 @@ Free_Chunk(struct chunk *c1) if(c1->next) Free_Chunk(c1->next); free(c1->name); +#ifdef PC98 + free(c1->sname); +#endif free(c1); } @@ -97,14 +102,22 @@ Clone_Chunk(struct chunk *c1) if (c1->private_data && c1->private_clone) c2->private_data = c2->private_clone(c2->private_data); c2->name = strdup(c2->name); +#ifdef PC98 + c2->sname = strdup(c2->sname); +#endif c2->next = Clone_Chunk(c2->next); c2->part = Clone_Chunk(c2->part); return c2; } int +#ifdef PC98 +Insert_Chunk(struct chunk *c2, u_long offset, u_long size, const char *name, + chunk_e type, int subtype, u_long flags, const char *sname) +#else Insert_Chunk(struct chunk *c2, u_long offset, u_long size, const char *name, chunk_e type, int subtype, u_long flags) +#endif { struct chunk *ct,*cs; @@ -120,6 +133,9 @@ Insert_Chunk(struct chunk *c2, u_long offset, u_long size, const char *name, ct->size = size; ct->end = offset + size - 1; ct->type = type; +#ifdef PC98 + ct->sname = strdup(sname); +#endif ct->name = strdup(name); ct->subtype = subtype; ct->flags = flags; @@ -138,6 +154,9 @@ Insert_Chunk(struct chunk *c2, u_long offset, u_long size, const char *name, cs->size = size; cs->end = offset + size - 1; cs->type = unused; +#ifdef PC98 + cs->sname = strdup(sname); +#endif cs->name = strdup("-"); ct->part = cs; } @@ -150,6 +169,10 @@ Insert_Chunk(struct chunk *c2, u_long offset, u_long size, const char *name, cs->disk = c2->disk; cs->offset = ct->end + 1; cs->size = c2->end - ct->end; +#ifdef PC98 + if(c2->sname) + cs->sname = strdup(c2->sname); +#endif if(c2->name) cs->name = strdup(c2->name); c2->next = cs; @@ -158,11 +181,17 @@ Insert_Chunk(struct chunk *c2, u_long offset, u_long size, const char *name, } /* If no leading unused space just occupy the old chunk */ if (c2->offset == ct->offset) { +#ifdef PC98 + c2->sname = ct->sname; +#endif c2->name = ct->name; c2->type = ct->type; c2->part = ct->part; c2->subtype = ct->subtype; c2->flags = ct->flags; +#ifdef PC98 + ct->sname = 0; +#endif ct->name = 0; ct->part = 0; Free_Chunk(ct); @@ -177,8 +206,13 @@ Insert_Chunk(struct chunk *c2, u_long offset, u_long size, const char *name, } int +#ifdef PC98 +Add_Chunk(struct disk *d, long offset, u_long size, const char *name, + chunk_e type, int subtype, u_long flags, const char *sname) +#else Add_Chunk(struct disk *d, long offset, u_long size, const char *name, chunk_e type, int subtype, u_long flags) +#endif { struct chunk *c1,*c2,ct; u_long end = offset + size - 1; @@ -197,6 +231,10 @@ Add_Chunk(struct disk *d, long offset, u_long size, const char *name, c2->offset = c1->offset = offset; c2->size = c1->size = size; c2->end = c1->end = end; +#ifdef PC98 + c1->sname = strdup(sname); + c2->sname = strdup("-"); +#endif c1->name = strdup(name); c2->name = strdup("-"); c1->type = type; @@ -206,14 +244,22 @@ Add_Chunk(struct disk *d, long offset, u_long size, const char *name, return 0; } if (type == freebsd) +#ifdef PC98 + subtype = 0xc494; +#else subtype = 0xa5; +#endif c1 = 0; +#ifndef PC98 if(!c1 && (type == freebsd || type == fat || type == unknown)) c1 = Find_Mother_Chunk(d->chunks,offset,end,extended); +#endif if(!c1 && (type == freebsd || type == fat || type == unknown)) c1 = Find_Mother_Chunk(d->chunks,offset,end,whole); +#ifndef PC98 if(!c1 && type == extended) c1 = Find_Mother_Chunk(d->chunks,offset,end,whole); +#endif if(!c1 && type == part) c1 = Find_Mother_Chunk(d->chunks,offset,end,freebsd); if(!c1) @@ -255,8 +301,13 @@ Add_Chunk(struct disk *d, long offset, u_long size, const char *name, size -= offset; doit: +#ifdef PC98 + return Insert_Chunk(c2,offset,size,name, + type,subtype,flags,sname); +#else return Insert_Chunk(c2,offset,size,name, type,subtype,flags); +#endif } } return __LINE__; @@ -271,7 +322,9 @@ ShowChunkFlags(struct chunk *c) if (c->flags & CHUNK_BSD_COMPAT) ret[i++] = 'C'; if (c->flags & CHUNK_ACTIVE) ret[i++] = 'A'; if (c->flags & CHUNK_ALIGN) ret[i++] = '='; +#ifndef PC98 if (c->flags & CHUNK_PAST_1024) ret[i++] = '>'; +#endif if (c->flags & CHUNK_IS_ROOT) ret[i++] = 'R'; ret[i++] = '\0'; return ret; @@ -286,8 +339,13 @@ Print_Chunk(struct chunk *c1,int offset) for(;i<offset;i++) putchar('-'); putchar('>'); for(;i<10;i++) putchar(' '); +#ifdef PC98 + printf("%p %8ld %8lu %8lu %-8s %-16s %-8s 0x%02x %s", + c1, c1->offset, c1->size, c1->end, c1->name, c1->sname, +#else printf("%p %8ld %8lu %8lu %-8s %-8s 0x%02x %s", c1, c1->offset, c1->size, c1->end, c1->name, +#endif chunk_n[c1->type],c1->subtype, ShowChunkFlags(c1)); putchar('\n'); @@ -301,6 +359,7 @@ Debug_Chunk(struct chunk *c1) Print_Chunk(c1,2); } +#ifndef PC98 void Bios_Limit_Chunk(struct chunk *c1, u_long limit) { @@ -314,6 +373,7 @@ Bios_Limit_Chunk(struct chunk *c1, u_long limit) c1->flags &= ~CHUNK_PAST_1024; } } +#endif int Delete_Chunk(struct disk *d, struct chunk *c) @@ -323,12 +383,16 @@ Delete_Chunk(struct disk *d, struct chunk *c) if(type == whole) return 1; +#ifndef PC98 if(!c1 && (type == freebsd || type == fat || type == unknown)) c1 = Find_Mother_Chunk(d->chunks,c->offset,c->end,extended); +#endif if(!c1 && (type == freebsd || type == fat || type == unknown)) c1 = Find_Mother_Chunk(d->chunks,c->offset,c->end,whole); +#ifndef PC98 if(!c1 && type == extended) c1 = Find_Mother_Chunk(d->chunks,c->offset,c->end,whole); +#endif if(!c1 && type == part) c1 = Find_Mother_Chunk(d->chunks,c->offset,c->end,freebsd); if(!c1) @@ -338,6 +402,10 @@ Delete_Chunk(struct disk *d, struct chunk *c) c2->type = unused; c2->subtype = 0; c2->flags = 0; +#ifdef PC98 + free(c2->sname); + c2->sname = strdup("-"); +#endif free(c2->name); c2->name = strdup("-"); Free_Chunk(c2->part); @@ -403,6 +471,9 @@ Collapse_Chunk(struct disk *d, struct chunk *c1) *c2 = *c1; c1->next = c2; c1->disk = d; +#ifdef PC98 + c1->sname = strdup("-"); +#endif c1->name = strdup("-"); c1->part = 0; c1->type = unused; diff --git a/lib/libdisk/create_chunk.c b/lib/libdisk/create_chunk.c index 04e2a55..2241811 100644 --- a/lib/libdisk/create_chunk.c +++ b/lib/libdisk/create_chunk.c @@ -184,31 +184,49 @@ Fixup_Names(struct disk *d) for(c2 = c1->part; c2 ; c2 = c2->next) { if (c2->type == freebsd) Fixup_FreeBSD_Names(d,c2); +#ifndef PC98 if (c2->type == extended) Fixup_Extended_Names(d,c2); +#endif } } int +#ifdef PC98 +Create_Chunk(struct disk *d, u_long offset, u_long size, chunk_e type, int subtype, u_long flags, const char *sname) +#else Create_Chunk(struct disk *d, u_long offset, u_long size, chunk_e type, int subtype, u_long flags) +#endif { int i; u_long l; if(!(flags & CHUNK_FORCE_ALL)) { +#ifdef PC98 + /* Never use the first cylinder */ + if (!offset) { + offset += (d->bios_sect * d->bios_hd); + size -= (d->bios_sect * d->bios_hd); + } +#else /* Never use the first track */ if (!offset) { offset += d->bios_sect; size -= d->bios_sect; } +#endif /* Always end on cylinder boundary */ l = (offset+size) % (d->bios_sect * d->bios_hd); size -= l; } +#ifdef PC98 + i = Add_Chunk(d,offset,size,"X",type,subtype,flags,sname); +#else i = Add_Chunk(d,offset,size,"X",type,subtype,flags); +#endif Fixup_Names(d); return i; } @@ -230,7 +248,11 @@ Create_Chunk_DWIM(struct disk *d, struct chunk *parent , u_long size, chunk_e ty } return 0; found: +#ifdef PC98 + i = Add_Chunk(d,offset,size,"X",type,subtype,flags,"-"); +#else i = Add_Chunk(d,offset,size,"X",type,subtype,flags); +#endif if (i) return 0; Fixup_Names(d); diff --git a/lib/libdisk/disk.c b/lib/libdisk/disk.c index 0263149..78241f2 100644 --- a/lib/libdisk/disk.c +++ b/lib/libdisk/disk.c @@ -58,8 +58,12 @@ Int_Open_Disk(const char *name, u_long size) struct disklabel dl; char device[64]; struct disk *d; +#ifdef PC98 + unsigned char *p; +#else struct dos_partition *dp; void *p; +#endif u_long offset = 0; strcpy(device,"/dev/r"); @@ -96,9 +100,18 @@ Int_Open_Disk(const char *name, u_long size) printf("\n"); #endif +/* XXX --- ds.dss_slice[WHOLE_DISK_SLCIE].ds.size of MO disk is wrong!!! */ +#ifdef PC98 + if (!size) + size = dl.d_ncylinders * dl.d_ntracks * dl.d_nsectors; +#else if (!size) size = ds.dss_slices[WHOLE_DISK_SLICE].ds_size; +#endif +#ifdef PC98 + p = (unsigned char*)read_block(fd,1); +#else p = read_block(fd,0); dp = (struct dos_partition*)(p+DOSPARTOFF); for (i=0; i < NDOSPART; i++) { @@ -116,6 +129,7 @@ Int_Open_Disk(const char *name, u_long size) } free(p); +#endif d->bios_sect = dl.d_nsectors; d->bios_hd = dl.d_ntracks; @@ -126,7 +140,11 @@ Int_Open_Disk(const char *name, u_long size) if (dl.d_ntracks && dl.d_nsectors) d->bios_cyl = size/(dl.d_ntracks*dl.d_nsectors); +#ifdef PC98 + if (Add_Chunk(d, -offset, size, name, whole, 0, 0, "-")) +#else if (Add_Chunk(d, -offset, size, name, whole, 0, 0)) +#endif #ifdef DEBUG warn("Failed to add 'whole' chunk"); #else @@ -134,6 +152,19 @@ Int_Open_Disk(const char *name, u_long size) #endif #ifdef __i386__ +#ifdef PC98 + /* XXX -- Quick Hack! + * Check MS-DOG MO + */ + if ((*p == 0xf0 || *p == 0xf8) && + (*(p+1) == 0xff) && + (*(p+2) == 0xff)) { + Add_Chunk(d, 0, size, name, fat, 0xa0a0, 0, name); + free(p); + goto pc98_mo_done; + } + free(p); +#endif /* PC98 */ for(i=BASE_SLICE;i<ds.dss_nslices;i++) { char sname[20]; chunk_e ce; @@ -143,6 +174,20 @@ Int_Open_Disk(const char *name, u_long size) continue; ds.dss_slices[i].ds_offset -= offset; sprintf(sname,"%ss%d",name,i-1); +#ifdef PC98 + subtype = ds.dss_slices[i].ds_type | + ds.dss_slices[i].ds_subtype << 8; + switch (ds.dss_slices[i].ds_type & 0x7f) { + case 0x14: + ce = freebsd; + break; + case 0x20: + case 0x21: + case 0x22: + case 0x23: + ce = fat; + break; +#else /* IBM-PC */ subtype = ds.dss_slices[i].ds_type; switch (ds.dss_slices[i].ds_type) { case 0xa5: @@ -160,19 +205,30 @@ Int_Open_Disk(const char *name, u_long size) case 0xf: ce = extended; break; +#endif default: ce = unknown; break; } +#ifdef PC98 + if (Add_Chunk(d,ds.dss_slices[i].ds_offset, + ds.dss_slices[i].ds_size, sname, ce, subtype, flags, + ds.dss_slices[i].ds_name)) +#else if (Add_Chunk(d, ds.dss_slices[i].ds_offset, ds.dss_slices[i].ds_size, sname, ce, subtype, flags)) +#endif #ifdef DEBUG warn("failed to add chunk for slice %d", i - 1); #else {} #endif +#ifdef PC98 + if ((ds.dss_slices[i].ds_type & 0x7f) != 0x14) +#else if (ds.dss_slices[i].ds_type != 0xa5) +#endif continue; { struct disklabel dl; @@ -220,7 +276,12 @@ Int_Open_Disk(const char *name, u_long size) dl.d_partitions[j].p_size, pname,part, dl.d_partitions[j].p_fstype, +#ifdef PC98 + 0, + ds.dss_slices[i].ds_name) && j != 3) +#else 0) && j != 3) +#endif #ifdef DEBUG warn( "Failed to add chunk for partition %c [%lu,%lu]", @@ -293,9 +354,14 @@ Int_Open_Disk(const char *name, u_long size) nolabel:; } #endif /* __alpha__ */ +#ifdef PC98 +pc98_mo_done: +#endif close(fd); Fixup_Names(d); +#ifndef PC98 Bios_Limit_Chunk(d->chunks,1024*d->bios_hd*d->bios_sect); +#endif return d; } @@ -418,6 +484,7 @@ Disk_Names() void Set_Boot_Mgr(struct disk *d, const u_char *b) { +#ifndef PC98 if (d->bootmgr) free(d->bootmgr); if (!b) { @@ -427,6 +494,7 @@ Set_Boot_Mgr(struct disk *d, const u_char *b) if(!d->bootmgr) err(1,"malloc failed"); memcpy(d->bootmgr,b,DOSPARTOFF); } +#endif } void @@ -454,6 +522,7 @@ slice_type_name( int type, int subtype ) { switch (type) { case 0: return "whole"; +#ifndef PC98 case 1: switch (subtype) { case 1: return "fat (12-bit)"; case 2: return "XENIX /"; @@ -485,14 +554,21 @@ slice_type_name( int type, int subtype ) case 184: return "bsd/os swap"; default: return "unknown"; } +#endif case 2: return "fat"; case 3: switch (subtype) { +#ifdef PC98 + case 0xc494: return "freebsd"; +#else case 165: return "freebsd"; +#endif default: return "unknown"; } +#ifndef PC98 case 4: return "extended"; case 5: return "part"; case 6: return "unused"; +#endif default: return "unknown"; } } diff --git a/lib/libdisk/libdisk.h b/lib/libdisk/libdisk.h index bf9eff1..fc8a247 100644 --- a/lib/libdisk/libdisk.h +++ b/lib/libdisk/libdisk.h @@ -46,6 +46,9 @@ struct chunk { long offset; u_long size; u_long end; +#ifdef PC98 + char *sname; +#endif char *name; char *oname; /* Used during Fixup_Names() to avoid renaming more than @@ -135,8 +138,13 @@ Collapse_Chunk(struct disk *disk, struct chunk *chunk); */ int +#ifdef PC98 +Create_Chunk(struct disk *disk, u_long offset, u_long size, chunk_e type, + int subtype, u_long flags, const char *); +#else Create_Chunk(struct disk *disk, u_long offset, u_long size, chunk_e type, int subtype, u_long flags); +#endif /* Create a chunk with the specified paramters */ @@ -239,7 +247,11 @@ ChunkCanBeRoot(struct chunk *c); void Debug_Chunk(struct chunk *); void Free_Chunk(struct chunk *); struct chunk * Clone_Chunk(struct chunk *); +#ifdef PC98 +int Add_Chunk(struct disk *, long, u_long, const char *, chunk_e, int, u_long, const char *); +#else int Add_Chunk(struct disk *, long, u_long, const char *, chunk_e, int, u_long); +#endif void Bios_Limit_Chunk(struct chunk *, u_long); void * read_block(int, daddr_t); void write_block(int fd, daddr_t block, void *foo); diff --git a/lib/libdisk/rules.c b/lib/libdisk/rules.c index fcc3d3b..6424556 100644 --- a/lib/libdisk/rules.c +++ b/lib/libdisk/rules.c @@ -80,24 +80,32 @@ Next_Cyl_Aligned(struct disk *d, u_long offset) void Rule_000(struct disk *d, struct chunk *c, char *msg) { +#ifdef PC98 + int i=0; +#else int i=0,j=0; +#endif struct chunk *c1; if (c->type != whole) return; for (c1=c->part; c1; c1=c1->next) { if (c1->type != unused) continue; +#ifndef PC98 if (c1->flags & CHUNK_ACTIVE) j++; +#endif i++; } if (i > NDOSPART) sprintf(msg+strlen(msg), "%d is too many children of the 'whole' chunk. Max is %d\n", i, NDOSPART); +#ifndef PC98 if (j > 1) sprintf(msg+strlen(msg), "Too many active children of 'whole'"); +#endif } /* @@ -116,9 +124,17 @@ Rule_001(struct disk *d, struct chunk *c, char *msg) for (i=0, c1=c->part; c1; c1=c1->next) { if (c1->type == unused) continue; c1->flags |= CHUNK_ALIGN; +#ifdef PC98 + if (!Cyl_Aligned(d,c1->offset)) +#else if (!Track_Aligned(d,c1->offset)) +#endif sprintf(msg+strlen(msg), +#ifdef PC98 + "chunk '%s' [%ld..%ld] does not start on a cylinder boundary\n", +#else "chunk '%s' [%ld..%ld] does not start on a track boundary\n", +#endif c1->name,c1->offset,c1->end); if ((c->type == whole || c->end == c1->end) || Cyl_Aligned(d,c1->end+1)) @@ -137,6 +153,7 @@ Rule_001(struct disk *d, struct chunk *c, char *msg) void Rule_002(struct disk *d, struct chunk *c, char *msg) { +#ifndef PC98 int i; struct chunk *c1; @@ -151,6 +168,7 @@ Rule_002(struct disk *d, struct chunk *c, char *msg) sprintf(msg+strlen(msg), "Max one 'fat' allowed as child of 'whole'\n"); } +#endif } /* @@ -160,6 +178,7 @@ Rule_002(struct disk *d, struct chunk *c, char *msg) void Rule_003(struct disk *d, struct chunk *c, char *msg) { +#ifndef PC98 int i; struct chunk *c1; @@ -174,6 +193,7 @@ Rule_003(struct disk *d, struct chunk *c, char *msg) sprintf(msg+strlen(msg), "Max one 'extended' allowed as child of 'whole'\n"); } +#endif } /* @@ -197,9 +217,11 @@ Rule_004(struct disk *d, struct chunk *c, char *msg) continue; if (c1->flags & CHUNK_IS_ROOT) { k++; +#ifndef PC98 if (c1->flags & CHUNK_PAST_1024) sprintf(msg+strlen(msg), "Root filesystem extends past cylinder 1024, and cannot be booted from\n"); +#endif } i++; } @@ -226,10 +248,12 @@ Check_Chunk(struct disk *d, struct chunk *c, char *msg) if (c->next) Check_Chunk(d,c->next,msg); +#ifndef PC98 if (c->end >= 1024*d->bios_hd*d->bios_sect) c->flags |= CHUNK_PAST_1024; else c->flags &= ~CHUNK_PAST_1024; +#endif } char * @@ -252,6 +276,7 @@ ChunkCanBeRoot(struct chunk *c) char msg[BUFSIZ]; *msg = '\0'; +#ifndef PC98 if (c->flags & CHUNK_PAST_1024) { strcat(msg, "The root partition must end before cylinder 1024 seen from\n"); @@ -259,6 +284,7 @@ ChunkCanBeRoot(struct chunk *c) "the BIOS' point of view, or it cannot be booted from.\n"); return strdup(msg); } +#endif for (c1=d->chunks->part;;) { for (; c1; c1=c1->next) if (c1->offset <= c->offset && c1->end >= c->end) @@ -273,6 +299,7 @@ ChunkCanBeRoot(struct chunk *c) c1 = c1->part; } +#ifndef PC98 if (c1->type != freebsd) { strcat(msg, "The root partition must be in a FreeBSD slice, otherwise\n"); @@ -280,6 +307,7 @@ ChunkCanBeRoot(struct chunk *c) "the kernel cannot be booted from it\n"); return strdup(msg); } +#endif return NULL; } diff --git a/lib/libdisk/tst01.c b/lib/libdisk/tst01.c index e8c34d9..c23169a 100644 --- a/lib/libdisk/tst01.c +++ b/lib/libdisk/tst01.c @@ -217,7 +217,11 @@ main(int argc, char **argv) free(cp); continue; } +#ifdef PC98 + if (!strcasecmp(*cmds,"create") && ncmd == 7) { +#else if (!strcasecmp(*cmds,"create") && ncmd == 6) { +#endif printf("Create=%d\n", Create_Chunk(d, @@ -225,7 +229,12 @@ main(int argc, char **argv) strtol(cmds[2],0,0), strtol(cmds[3],0,0), strtol(cmds[4],0,0), +#ifdef PC98 + strtol(cmds[5],0,0), + cmds[6])); +#else strtol(cmds[5],0,0))); +#endif continue; } if (!strcasecmp(*cmds,"read")) { @@ -276,7 +285,11 @@ main(int argc, char **argv) #if 0 printf("\tcollapse [pointer]\n"); #endif +#ifdef PC98 + printf("\tcreate offset size enum subtype flags name\n"); +#else printf("\tcreate offset size enum subtype flags\n"); +#endif printf("\t\tsubtype(part): swap=1, ffs=7\n"); printf("\tdelete pointer\n"); printf("\tlist\n"); diff --git a/lib/libdisk/write_disk.c b/lib/libdisk/write_disk.c index 5ac0ea7..3e8ad8a 100644 --- a/lib/libdisk/write_disk.c +++ b/lib/libdisk/write_disk.c @@ -29,7 +29,11 @@ #define DEF_RPM 3600 #define DEF_INTERLEAVE 1 +#ifdef PC98 +#define WHERE(offset,disk) (offset) +#else #define WHERE(offset,disk) (disk->flags & DISK_ON_TRACK ? offset + 63 : offset) +#endif int Write_FreeBSD(int fd, struct disk *new, struct disk *old, struct chunk *c1) { @@ -103,11 +107,17 @@ Write_FreeBSD(int fd, struct disk *new, struct disk *old, struct chunk *c1) new->name[0] == 'o' ? DTYPE_SCSI : DTYPE_ESDI; dl->d_partitions[RAW_PART].p_size = c1->size; dl->d_partitions[RAW_PART].p_offset = c1->offset; +#ifdef PC98 + dl->d_rpm = 3600; + dl->d_interleave = 1; +#endif +#ifndef PC98 if(new->flags & DISK_ON_TRACK) for(i=0;i<MAXPARTITIONS;i++) if (dl->d_partitions[i].p_size) dl->d_partitions[i].p_offset += 63; +#endif dl->d_magic = DISKMAGIC; dl->d_magic2 = DISKMAGIC; dl->d_checksum = dkcksum(dl); @@ -162,13 +172,26 @@ Write_Disk(struct disk *d1) char device[64]; u_char *mbr; struct dos_partition *dp,work[NDOSPART]; +#ifdef PC98 + int s[7]; + int PC98_EntireDisk = 0; +#else int s[4]; +#endif int one = 1; int zero = 0; strcpy(device,"/dev/r"); strcat(device,d1->name); +#ifdef PC98 + /* XXX - for entire FreeBSD(98) */ + for (c1 = d1->chunks->part; c1; c1 = c1->next) { + if ((c1->type == freebsd) || (c1->offset == 0)) + device[9] = 0; + } +#endif + fd = open(device,O_RDWR); if (fd < 0) { #ifdef DEBUG @@ -179,7 +202,11 @@ Write_Disk(struct disk *d1) ioctl(fd, DIOCWLABEL, &one); memset(s,0,sizeof s); +#ifdef PC98 + mbr = read_block(fd,WHERE(1,d1)); +#else mbr = read_block(fd,WHERE(0,d1)); +#endif dp = (struct dos_partition*) (mbr + DOSPARTOFF); memcpy(work,dp,sizeof work); dp = work; @@ -190,20 +217,37 @@ Write_Disk(struct disk *d1) #ifndef __alpha__ j = c1->name[4] - '1'; j = c1->name[strlen(d1->name) + 1] - '1'; +#ifdef PC98 + if (j < 0 || j > 7) +#else if (j < 0 || j > 3) +#endif continue; s[j]++; #endif +#ifndef PC98 if (c1->type == extended) ret += Write_Extended(fd, d1,old,c1); +#endif if (c1->type == freebsd) ret += Write_FreeBSD(fd, d1,old,c1); #ifndef __alpha__ +#ifndef PC98 Write_Int32(&dp[j].dp_start, c1->offset); Write_Int32(&dp[j].dp_size, c1->size); +#endif i = c1->offset; +#ifdef PC98 + dp[j].dp_ssect = dp[j].dp_ipl_sct = i % d1->bios_sect; + i -= dp[j].dp_ssect; + i /= d1->bios_sect; + dp[j].dp_shd = dp[j].dp_ipl_head = i % d1->bios_hd; + i -= dp[j].dp_shd; + i /= d1->bios_hd; + dp[j].dp_scyl = dp[j].dp_ipl_cyl = i; +#else if (i >= 1024*d1->bios_sect*d1->bios_hd) { dp[j].dp_ssect = 0xff; dp[j].dp_shd = 0xff; @@ -219,6 +263,7 @@ Write_Disk(struct disk *d1) i -= dp[j].dp_scyl; dp[j].dp_ssect |= i >> 2; } +#endif #ifdef DEBUG printf("S:%lu = (%x/%x/%x)", @@ -226,6 +271,20 @@ Write_Disk(struct disk *d1) #endif i = c1->end; +#ifdef PC98 +#if 1 + dp[j].dp_esect = dp[j].dp_ehd = 0; + dp[j].dp_ecyl = i / (d1->bios_sect * d1->bios_hd); +#else + dp[j].dp_esect = i % d1->bios_sect; + i -= dp[j].dp_esect; + i /= d1->bios_sect; + dp[j].dp_ehd = i % d1->bios_hd; + i -= dp[j].dp_ehd; + i /= d1->bios_hd; + dp[j].dp_ecyl = i; +#endif +#else dp[j].dp_esect = i % d1->bios_sect; i -= dp[j].dp_esect++; i /= d1->bios_sect; @@ -236,32 +295,57 @@ Write_Disk(struct disk *d1) dp[j].dp_ecyl = i; i -= dp[j].dp_ecyl; dp[j].dp_esect |= i >> 2; +#endif #ifdef DEBUG printf(" E:%lu = (%x/%x/%x)\n", c1->end,dp[j].dp_ecyl,dp[j].dp_ehd,dp[j].dp_esect); #endif +#ifdef PC98 + dp[j].dp_mid = c1->subtype & 0xff; + dp[j].dp_sid = c1->subtype >> 8; + if (c1->flags & CHUNK_ACTIVE) + dp[j].dp_mid |= 0x80; + + strncpy(dp[j].dp_name, c1->sname, 16); +#else dp[j].dp_typ = c1->subtype; if (c1->flags & CHUNK_ACTIVE) dp[j].dp_flag = 0x80; else dp[j].dp_flag = 0; #endif +#endif } #ifndef __alpha__ j = 0; for(i=0;i<NDOSPART;i++) { if (!s[i]) memset(dp+i,0,sizeof *dp); +#ifndef PC98 if (dp[i].dp_flag) j++; +#endif } +#ifndef PC98 if (!j) for(i=0;i<NDOSPART;i++) if (dp[i].dp_typ == 0xa5) dp[i].dp_flag = 0x80; +#endif +#ifdef PC98 + mbr = read_block(fd,WHERE(1,d1)); + memcpy(mbr+DOSPARTOFF,dp,sizeof *dp * NDOSPART); + /* XXX - for entire FreeBSD(98) */ + for (c1 = d1->chunks->part; c1; c1 = c1->next) + if (((c1->type == freebsd) || (c1->type == fat)) + && (c1->offset == 0)) + PC98_EntireDisk = 1; + if (PC98_EntireDisk == 0) + write_block(fd,WHERE(1,d1),mbr); +#else mbr = read_block(fd,WHERE(0,d1)); if (d1->bootmgr) memcpy(mbr,d1->bootmgr,DOSPARTOFF); @@ -270,6 +354,7 @@ Write_Disk(struct disk *d1) mbr[512-1] = 0xaa; write_block(fd,WHERE(0,d1),mbr); #endif +#endif i = 1; i = ioctl(fd,DIOCSYNCSLICEINFO,&i); |