Sync usage with man page.
[netbsd-mini2440.git] / sys / arch / atari / stand / ahdilabel / check.c
blob2938ded7a9010870769ebc7fb8d3e92989baaf48
1 /* $NetBSD: check.c,v 1.5 2008/04/28 20:23:15 martin Exp $ */
3 /*
4 * Copyright (c) 1999 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Julian Coleman, Waldi Ravens and Leo Weppelman.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include "privahdi.h"
34 /* Partitions which have errors */
35 int ahdi_errp1;
36 int ahdi_errp2;
39 * Check partitions for consistency :
40 * GEM vs BGM
41 * Start sector > 2
42 * End sector < secperunit
43 * other partition overlap
44 * auxiliary root overlap
45 * Number of partitions in root/auxiliary root
47 int
48 ahdi_checklabel (struct ahdi_ptable *ptable)
50 int i, j, rcount, acount;
51 u_int32_t i_end, j_end;
53 ahdi_errp1 = -1;
54 ahdi_errp2 = -1;
56 if (ptable->nparts < 1 || ptable->nparts > MAXPARTITIONS)
57 return (-2);
59 rcount = 0;
60 acount = 0;
62 for (i = 0; i < ptable->nparts; i++) {
64 /* GEM vs BGM */
65 if (ptable->parts[i].size > 32768) {
66 if (AHDI_MKPID (ptable->parts[i].id[0],
67 ptable->parts[i].id[1], ptable->parts[i].id[2])
68 == AHDI_PID_GEM) {
69 ahdi_errp1 = i;
70 return (-3);
72 } else {
73 if (AHDI_MKPID (ptable->parts[i].id[0],
74 ptable->parts[i].id[1], ptable->parts[i].id[2])
75 == AHDI_PID_BGM) {
76 ahdi_errp1 = i;
77 return (-3);
81 /* Need 2 free sectors at start for root and bad sector list */
82 if (ptable->parts[i].start < 2) {
83 ahdi_errp1 = i;
84 return (-4);
87 i_end = ptable->parts[i].start + ptable->parts[i].size - 1;
89 /* Check partition does not extend past end of disk */
90 if (i_end >= ptable->secperunit) {
91 ahdi_errp1 = i;
92 return (-5);
95 for (j = i + 1; j < ptable->nparts; j++) {
96 /* Check for overlap with other partitions */
97 j_end = ptable->parts[j].start + ptable->parts[j].size
98 - 1;
99 if ((ptable->parts[j].start >= ptable->parts[i].start
100 && ptable->parts[j].start <= i_end) ||
101 (j_end >= ptable->parts[i].start &&
102 j_end <= i_end)) {
103 ahdi_errp1 = i;
104 ahdi_errp2 = j;
105 return (-6);
107 /* Check number of partitions in auxiliary root */
108 if (ptable->parts[i].root &&
109 ptable->parts[i].root == ptable->parts[j].root) {
110 ahdi_errp1 = i;
111 ahdi_errp2 = j;
112 return (-9);
116 for (j = i; j < ptable->nparts; j++)
117 /* Check for overlap with auxiliary root(s) */
118 if (ptable->parts[j].root >= ptable->parts[i].start &&
119 ptable->parts[j].root <= i_end) {
120 ahdi_errp1 = i;
121 return (-7);
124 /* Count partitions in root/auxiliary roots */
125 if (ptable->parts[i].root)
126 acount++;
127 else
128 rcount++;
131 /* Check number of partitions in root sector */
132 if (acount)
133 rcount++;
134 if (rcount > 4)
135 return (-8);
136 else
137 return (1);