Bugzilla – Attachment 46324 Details for
Bug 103031
No operating system found
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
IDP Log In
|
Forgot Password
C program to check and maybe fix the problem
FixCHS.c (text/x-csrc), 3.38 KB, created by
Torsten Duwe
on 2005-08-17 14:35:16 UTC
(
hide
)
Description:
C program to check and maybe fix the problem
Filename:
MIME Type:
Creator:
Torsten Duwe
Created:
2005-08-17 14:35:16 UTC
Size:
3.38 KB
patch
obsolete
>#include <sys/types.h> >#include <stdio.h> >#include <stdlib.h> >#include <unistd.h> >#include <fcntl.h> >#include <err.h> > >unsigned char buf[512]; >#define PARTTAB_OFFSET 446 > >/* The BIOS' idea of the disk geometry */ >int cylinders, heads, sectors; > >/* -------------------- from fdisk.c --------------------*/ >#define sector(s) ((s) & 0x3f) >#define cylinder(s, c) ((c) | (((s) & 0xc0) << 2)) >#define hsc2sector(h,s,c) (sector(s) - 1 + sectors * \ > ((h) + heads * cylinder(s,c))) >#define set_hsc(h,s,c,sector) { \ > s = sector % sectors + 1; \ > sector /= sectors; \ > h = sector % heads; \ > sector /= heads; \ > c = sector & 0xff; \ > s |= (sector >> 2) & 0xc0; \ > } >/* -------------------- from fdisk.c --------------------*/ > >typedef struct >{ > unsigned char h; > unsigned char s; > unsigned char c; >} > chs_bytes; > > >typedef struct >{ > unsigned char flags; > chs_bytes start_chs; > unsigned char sysId; > chs_bytes end_chs; > /* XXX assumes wrong-endian native && sizeof(int)==4 */ > unsigned int lstart; > unsigned int lsize; >} > part_entry; > >int read_ascii(char * fname) >{ > FILE * F; > int ret = 0; > > if ((F = fopen(fname, "r")) == 0) > return 0; > > if (fscanf(F, "%d", &ret) < 1) > ret = 0; > > fclose(F); > return ret; >} > >int >check_part(int n, int do_fix) >{ > int c, h, s; > > part_entry * parttab = (part_entry *)(buf+PARTTAB_OFFSET); > n--; > > if(parttab[n].lstart / (heads*sectors) > 1023) /* out of range anyways */ > return 0; > if(parttab[n].sysId == 0) /* unused partition */ > return 0; > > set_hsc(h,s,c,parttab[n].lstart); > > if (c != parttab[n].start_chs.c || > h != parttab[n].start_chs.h || > s != parttab[n].start_chs.s) > { > printf("Partition %d mismatch\n", n+1); > printf("[ %02x %02x %02x ] ", > parttab[n].start_chs.h, > parttab[n].start_chs.s, > parttab[n].start_chs.c); > printf("[ %02x %02x %02x ] ", h, s, c); > if (do_fix) > { > parttab[n].start_chs.c = c; > parttab[n].start_chs.h = h; > parttab[n].start_chs.s = s; > printf("(Fixed)\n"); > return 1; > } > putchar('\n'); > } > return 0; >} > >int >main(int argc, char ** argv) >{ > > if (chdir("/sys/firmware/edd/int13_dev80") != 0) > err(1, "edd module loaded?\n chdir to /sys/firmware/edd/int13_dev80"); > > cylinders = read_ascii("legacy_max_cylinder"); > heads = read_ascii("legacy_max_head"); > sectors = read_ascii("legacy_sectors_per_track"); > heads++; > > if (cylinders*heads*sectors == 0) > errx(1, "cannot determine BIOS geometry"); > > // printf("%d/%d/%d\n", c, h, s); > > chdir("/dev"); > if (argc > 1) > { > int fd, i; > > fd = open(argv[1], O_RDWR, 0); > if (fd < 0) > err(1, "Cannot open %s", argv[1]); > > if (read(fd, buf, 512) < 512) > err(1, "Read from %s", argv[1]); > > if (lseek(fd, 0, SEEK_SET) != 0) > err(1, "%s not seekable", argv[1]); > > if (argc > 2) > { > int partno; > > partno = atoi(argv[2]); > if (partno < 1 || partno > 4) > errx(1, "Usage: %s <device> [primary_partition_number]", argv[0] ); > if (check_part(partno, 1) > 0) > { >#ifdef notyet > /* write(fd, buf, 512); */ >#endif > } > } > else > for (i=1; i<=4; i++) > check_part(i, 0); > } > > return 0; >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
Actions:
View
Attachments on
bug 103031
:
45848
|
45849
|
45850
|
45942
|
46137
| 46324 |
48344
|
48345
|
48346
|
48347
|
48815
|
49022
|
49023