FreeBSD/Linux Kernel Cross Reference
sys/device/dk_label.c
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 Software.Distribution@CS.CMU.EDU
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 * HISTORY
28 * $Log: dk_label.c,v $
29 * Revision 2.2 93/08/10 15:45:43 mrt
30 * Taken from rz_disk.c -- generic label code.
31 * [93/08/10 rvb]
32 *
33 */
34 /*
35 * File: rz_disk.c
36 * Author: Alessandro Forin, Carnegie Mellon University
37 * Date: 10/90
38 *
39 */
40
41 #include <sys/types.h>
42 #include <sys/ioctl.h>
43 #include <device/device_types.h>
44 #include <device/disk_status.h>
45
46 /* Checksum a disk label */
47 unsigned
48 dkcksum(lp)
49 struct disklabel *lp;
50 {
51 register unsigned short *start, *end, sum = 0;
52
53 start = (unsigned short *)lp;
54 end = (unsigned short*)&lp->d_partitions[lp->d_npartitions];
55 while (start < end) sum ^= *start++;
56 return sum;
57 }
58
59 /* Perform some checks and then copy a disk label */
60 setdisklabel(lp, nlp)
61 struct disklabel *lp, *nlp;
62 {
63 if (nlp->d_magic != DISKMAGIC || nlp->d_magic2 != DISKMAGIC ||
64 (dkcksum(nlp) != 0))
65 return D_INVALID_OPERATION;
66 *lp = *nlp;
67 return D_SUCCESS;
68 }
69
70 dkgetlabel(lp, flavor, data, count)
71 struct disklabel *lp;
72 int flavor;
73 int * data; /* pointer to OUT array */
74 unsigned int *count; /* OUT */
75 {
76
77 switch (flavor) {
78 /* get */
79 case DIOCGDINFO:
80 *(struct disklabel *)data = *lp;
81 *count = sizeof(struct disklabel)/sizeof(int);
82 break;
83 case DIOCGDINFO - (0x10<<16):
84 *(struct disklabel *)data = *lp;
85 *count = sizeof(struct disklabel)/sizeof(int) - 4;
86 break;
87 }
88 }
89
90 print_bsd_label(lp, str)
91 struct disklabel *lp;
92 char *str;
93 {
94 int i;
95 printf("%s sectors %d, tracks %d, cylinders %d\n",
96 str, lp->d_nsectors, lp->d_ntracks, lp->d_ncylinders);
97 printf("%s secpercyl %d, secperunit %d, npartitions %d\n",
98 str, lp->d_secpercyl, lp->d_secperunit, lp->d_npartitions);
99
100 for (i = 0; i < lp->d_npartitions; i++) {
101 printf("%s %c: size = %d, offset = %d\n",
102 str, 'a'+i,
103 lp->d_partitions[i].p_size,
104 lp->d_partitions[i].p_offset);
105 }
106 }
Cache object: 8999c0c4dc0dcfa100c704453e67fae1
|