2 * partitiontype.c, aeb, 2001-09-10
4 * call: partitiontype device
6 * either exit(1), or exit(0) with a single line of output
7 * DOS: sector 0 has a DOS signature.
18 #define AIX_LABEL_MAGIC 0xc9c2d4c1
19 #define AIX_LABEL_MAGIC_SWAPPED 0xc1d4c2c9
23 unsigned char stuff[128];
28 #define BSD_LABEL_MAGIC 0x82564557
35 #define SGI_LABEL_MAGIC 0x0be5a941
36 #define SGI_LABEL_MAGIC_SWAPPED 0x41a9e50b
39 unsigned char stuff[508];
40 unsigned short magic; /* Magic number */
41 unsigned short csum; /* Label xor'd checksum */
44 #define SUN_LABEL_MAGIC 0xDABE
45 #define SUN_LABEL_MAGIC_SWAPPED 0xBEDA
48 main(int argc, char **argv) {
50 unsigned char buf[1024];
51 struct aix_label *paix;
52 struct bsd_label *pbsd;
53 struct sgi_label *psgi;
54 struct sun_label *psun;
57 fprintf(stderr, "call: %s device\n", argv[0]);
60 fd = open(argv[1], O_RDONLY);
63 fprintf(stderr, "%s: cannot open device %s\n",
67 n = read(fd, buf, sizeof(buf));
68 if (n != sizeof(buf)) {
71 fprintf(stderr, "%s: cannot read device %s\n",
76 psun = (struct sun_label *)(&buf);
77 if (psun->magic == SUN_LABEL_MAGIC ||
78 psun->magic == SUN_LABEL_MAGIC_SWAPPED) {
79 unsigned short csum = 0, *p;
82 for (p = (unsigned short *)(&buf);
83 p < (unsigned short *)(&buf[512]); p++)
92 pbsd = (struct bsd_label *)(&buf[512]);
93 if (pbsd->magic == BSD_LABEL_MAGIC &&
94 pbsd->magic2 == BSD_LABEL_MAGIC) {
99 pbsd = (struct bsd_label *)(&buf[64]);
100 if (pbsd->magic == BSD_LABEL_MAGIC &&
101 pbsd->magic2 == BSD_LABEL_MAGIC) {
106 paix = (struct aix_label *)(&buf);
107 if (paix->magic == AIX_LABEL_MAGIC ||
108 paix->magic == AIX_LABEL_MAGIC_SWAPPED) {
113 psgi = (struct sgi_label *)(&buf);
114 if (psgi->magic == SGI_LABEL_MAGIC ||
115 psgi->magic == SGI_LABEL_MAGIC_SWAPPED) {
120 if (buf[510] == 0x55 && buf[511] == 0xaa) {
125 fprintf(stderr, "%s: do not recognize any label on %s\n",
128 exit(1); /* unknown */