|
|
1.1 root 1: /*
2: * Mach Operating System
3: * Copyright (c) 1993,1991,1990 Carnegie Mellon University
4: * All Rights Reserved.
5: *
6: * Permission to use, copy, modify and distribute this software and its
7: * documentation is hereby granted, provided that both the copyright
8: * notice and this permission notice appear in all copies of the
9: * software, derivative works or modified versions, and any portions
10: * thereof, and that both notices appear in supporting documentation.
11: *
12: * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
13: * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
14: * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
15: *
16: * Carnegie Mellon requests users of this software to return to
17: *
18: * Software Distribution Coordinator or [email protected]
19: * School of Computer Science
20: * Carnegie Mellon University
21: * Pittsburgh PA 15213-3890
22: *
23: * any improvements or extensions that they make and grant Carnegie Mellon
24: * the rights to redistribute these changes.
25: */
26: /*
27: * File: rz_disk.c
28: * Author: Alessandro Forin, Carnegie Mellon University
29: * Date: 10/90
30: *
31: */
32:
33: #include <sys/types.h>
34: #include <sys/ioctl.h>
35: #include <device/device_types.h>
36: #include <device/disk_status.h>
37:
38: /* Checksum a disk label */
39: unsigned
40: dkcksum(lp)
41: struct disklabel *lp;
42: {
43: register unsigned short *start, *end, sum = 0;
44:
45: start = (unsigned short *)lp;
46: end = (unsigned short*)&lp->d_partitions[lp->d_npartitions];
47: while (start < end) sum ^= *start++;
48: return sum;
49: }
50:
51: /* Perform some checks and then copy a disk label */
52: setdisklabel(lp, nlp)
53: struct disklabel *lp, *nlp;
54: {
55: if (nlp->d_magic != DISKMAGIC || nlp->d_magic2 != DISKMAGIC ||
56: (dkcksum(nlp) != 0))
57: return D_INVALID_OPERATION;
58: *lp = *nlp;
59: return D_SUCCESS;
60: }
61:
62: dkgetlabel(lp, flavor, data, count)
63: struct disklabel *lp;
64: int flavor;
65: int * data; /* pointer to OUT array */
66: unsigned int *count; /* OUT */
67: {
68:
69: switch (flavor) {
70: /* get */
71: case DIOCGDINFO:
72: *(struct disklabel *)data = *lp;
73: *count = sizeof(struct disklabel)/sizeof(int);
74: break;
75: case DIOCGDINFO - (0x10<<16):
76: *(struct disklabel *)data = *lp;
77: *count = sizeof(struct disklabel)/sizeof(int) - 4;
78: break;
79: }
80: }
81:
82: print_bsd_label(lp, str)
83: struct disklabel *lp;
84: char *str;
85: {
86: int i;
87: printf("%s sectors %d, tracks %d, cylinders %d\n",
88: str, lp->d_nsectors, lp->d_ntracks, lp->d_ncylinders);
89: printf("%s secpercyl %d, secperunit %d, npartitions %d\n",
90: str, lp->d_secpercyl, lp->d_secperunit, lp->d_npartitions);
91:
92: for (i = 0; i < lp->d_npartitions; i++) {
93: printf("%s %c: size = %d, offset = %d\n",
94: str, 'a'+i,
95: lp->d_partitions[i].p_size,
96: lp->d_partitions[i].p_offset);
97: }
98: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.