OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cgpt.h" | 5 #include "cgpt.h" |
6 | 6 |
7 #include <getopt.h> | 7 #include <getopt.h> |
8 #include <stdio.h> | 8 #include <stdio.h> |
9 #include <stdlib.h> | 9 #include <stdlib.h> |
10 #include <string.h> | 10 #include <string.h> |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
191 | 191 |
192 if (CGPT_OK != DriveOpen(argv[optind], &drive)) | 192 if (CGPT_OK != DriveOpen(argv[optind], &drive)) |
193 return CGPT_FAILED; | 193 return CGPT_FAILED; |
194 | 194 |
195 if (GPT_SUCCESS != (gpt_retval = GptSanityCheck(&drive.gpt))) { | 195 if (GPT_SUCCESS != (gpt_retval = GptSanityCheck(&drive.gpt))) { |
196 Error("GptSanityCheck() returned %d: %s\n", | 196 Error("GptSanityCheck() returned %d: %s\n", |
197 gpt_retval, GptError(gpt_retval)); | 197 gpt_retval, GptError(gpt_retval)); |
198 return CGPT_FAILED; | 198 return CGPT_FAILED; |
199 } | 199 } |
200 | 200 |
201 if ((drive.gpt.valid_headers != MASK_BOTH) || | |
Hung-Te
2010/11/17 10:37:04
it looks a little weird for me to compare a variab
Louis
2010/11/18 01:51:29
Good catch. Modified as:
(valid_header & MASK_BO
| |
202 (drive.gpt.valid_entries != MASK_BOTH)) { | |
203 Error("one of the GPT header/entries is invalid.\n" | |
204 "please run 'cgpt repair' before adding anything.\n"); | |
205 return CGPT_FAILED; | |
206 } | |
207 | |
201 uint32_t max_part = GetNumberOfEntries(&drive.gpt); | 208 uint32_t max_part = GetNumberOfEntries(&drive.gpt); |
202 if (partition) { | 209 if (partition) { |
203 if (partition > max_part) { | 210 if (partition > max_part) { |
204 Error("invalid partition number: %d\n", partition); | 211 Error("invalid partition number: %d\n", partition); |
205 goto bad; | 212 goto bad; |
206 } | 213 } |
207 index = partition - 1; | 214 index = partition - 1; |
208 entry = GetEntry(&drive.gpt, PRIMARY, index); | 215 entry = GetEntry(&drive.gpt, PRIMARY, index); |
209 } else { | 216 } else { |
210 // find next empty partition | 217 // find next empty partition |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
266 UpdateCrc(&drive.gpt); | 273 UpdateCrc(&drive.gpt); |
267 | 274 |
268 | 275 |
269 // Write it all out | 276 // Write it all out |
270 return DriveClose(&drive, 1); | 277 return DriveClose(&drive, 1); |
271 | 278 |
272 bad: | 279 bad: |
273 (void) DriveClose(&drive, 0); | 280 (void) DriveClose(&drive, 0); |
274 return CGPT_FAILED; | 281 return CGPT_FAILED; |
275 } | 282 } |
OLD | NEW |