diff options
Diffstat (limited to 'lib/libdisk/write_pc98_disk.c')
-rw-r--r-- | lib/libdisk/write_pc98_disk.c | 72 |
1 files changed, 36 insertions, 36 deletions
diff --git a/lib/libdisk/write_pc98_disk.c b/lib/libdisk/write_pc98_disk.c index bc18e4c..14ebda5 100644 --- a/lib/libdisk/write_pc98_disk.c +++ b/lib/libdisk/write_pc98_disk.c @@ -25,56 +25,55 @@ __FBSDID("$FreeBSD$"); #include <paths.h> #include "libdisk.h" -/* XXX: A lot of hardcoded 512s probably should be foo->sector_size; - I'm not sure which, so I leave it like it worked before. --schweikh */ +/* + * XXX: A lot of hardcoded 512s probably should be foo->sector_size; + * I'm not sure which, so I leave it like it worked before. --schweikh + */ static int -Write_FreeBSD(int fd, const struct disk *new, const struct disk *old, const struct chunk *c1) +Write_FreeBSD(int fd, const struct disk *new, const struct disk *old, + const struct chunk *c1) { struct disklabel *dl; int i; void *p; u_char buf[BBSIZE]; - for(i = 0; i < BBSIZE/512; i++) { + for (i = 0; i < BBSIZE / 512; i++) { p = read_block(fd, i + c1->offset, 512); memcpy(buf + 512 * i, p, 512); free(p); } - if(new->boot1) + if (new->boot1) memcpy(buf, new->boot1, 512); - if(new->boot2) - memcpy(buf + 512, new->boot2, BBSIZE-512); + if (new->boot2) + memcpy(buf + 512, new->boot2, BBSIZE - 512); dl = (struct disklabel *)(buf + 512 * LABELSECTOR + LABELOFFSET); Fill_Disklabel(dl, new, old, c1); - - for(i=0;i<BBSIZE/512;i++) { + for (i = 0; i < BBSIZE / 512; i++) write_block(fd, i + c1->offset, buf + 512 * i, 512); - } return 0; } - int Write_Disk(const struct disk *d1) { - int fd,i; - int j; - struct disk *old = 0; + int fd, i, j; + struct disk *old = NULL; struct chunk *c1; int ret = 0; char device[64]; u_char *mbr; - struct dos_partition *dp,work[NDOSPART]; + struct dos_partition *dp, work[NDOSPART]; int s[7]; int PC98_EntireDisk = 0; - strcpy(device,_PATH_DEV); - strcat(device,d1->name); + strcpy(device, _PATH_DEV); + strcat(device, d1->name); /* XXX - for entire FreeBSD(98) */ for (c1 = d1->chunks->part; c1; c1 = c1->next) { @@ -82,23 +81,25 @@ Write_Disk(const struct disk *d1) device[9] = 0; } - fd = open(device,O_RDWR); - if (fd < 0) { + fd = open(device, O_RDWR); + if (fd < 0) { #ifdef DEBUG - warn("open(%s) failed", device); + warn("open(%s) failed", device); #endif - return 1; - } + return 1; + } - memset(s,0,sizeof s); + memset(s, 0, sizeof s); mbr = read_block(fd, 1, d1->sector_size); - dp = (struct dos_partition*)(mbr + DOSPARTOFF); + dp = (struct dos_partition *)(mbr + DOSPARTOFF); memcpy(work, dp, sizeof work); dp = work; free(mbr); for (c1 = d1->chunks->part; c1; c1 = c1->next) { - if (c1->type == unused) continue; - if (!strcmp(c1->name, "X")) continue; + if (c1->type == unused) + continue; + if (!strcmp(c1->name, "X")) + continue; j = c1->name[strlen(d1->name) + 1] - '1'; if (j < 0 || j > 7) continue; @@ -106,7 +107,6 @@ Write_Disk(const struct disk *d1) if (c1->type == freebsd) ret += Write_FreeBSD(fd, d1, old, c1); - i = c1->offset; dp[j].dp_ssect = dp[j].dp_ipl_sct = i % d1->bios_sect; i -= dp[j].dp_ssect; @@ -115,10 +115,9 @@ Write_Disk(const struct disk *d1) i -= dp[j].dp_shd; i /= d1->bios_hd; dp[j].dp_scyl = dp[j].dp_ipl_cyl = i; - #ifdef DEBUG - printf("S:%lu = (%x/%x/%x)", - c1->offset, dp[j].dp_scyl, dp[j].dp_shd, dp[j].dp_ssect); + printf("S:%lu = (%x/%x/%x)", c1->offset, + dp[j].dp_scyl, dp[j].dp_shd, dp[j].dp_ssect); #endif i = c1->end; @@ -129,15 +128,14 @@ Write_Disk(const struct disk *d1) 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; + dp[j].dp_ehd = i % d1->bios_hd; i -= dp[j].dp_ehd; i /= d1->bios_hd; dp[j].dp_ecyl = i; #endif - #ifdef DEBUG - printf(" E:%lu = (%x/%x/%x)\n", - c1->end, dp[j].dp_ecyl, dp[j].dp_ehd, dp[j].dp_esect); + printf(" E:%lu = (%x/%x/%x)\n", c1->end, + dp[j].dp_ecyl, dp[j].dp_ehd, dp[j].dp_esect); #endif dp[j].dp_mid = c1->subtype & 0xff; @@ -148,7 +146,7 @@ Write_Disk(const struct disk *d1) strncpy(dp[j].dp_name, c1->sname, 16); } j = 0; - for(i = 0; i < NDOSPART; i++) { + for (i = 0; i < NDOSPART; i++) { if (!s[i]) memset(dp + i, 0, sizeof *dp); } @@ -168,7 +166,9 @@ Write_Disk(const struct disk *d1) if (d1->bootmenu) for (i = 0; i * d1->sector_size < d1->bootmenu_size; i++) - write_block(fd, 2 + i, &d1->bootmenu[i * d1->sector_size], d1->sector_size); + write_block(fd, 2 + i, + &d1->bootmenu[i * d1->sector_size], + d1->sector_size); close(fd); return 0; |