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 * Update GPT attribute bits. | 5 * Update GPT attribute bits. |
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 "cgpt.h" | 10 #include "cgpt.h" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 } | 100 } |
101 } | 101 } |
102 return CGPT_OK; | 102 return CGPT_OK; |
103 } | 103 } |
104 | 104 |
105 int OpenDriveInLastArgument(const int argc, | 105 int OpenDriveInLastArgument(const int argc, |
106 char *const *argv, | 106 char *const *argv, |
107 struct drive *drive) { | 107 struct drive *drive) { |
108 /* Then, we need a non-option argument. */ | 108 /* Then, we need a non-option argument. */ |
109 if (optind == (argc - 1)) { | 109 if (optind == (argc - 1)) { |
110 char *drive_path; | 110 char *path, drive_path[256]; |
111 drive_path = argv[optind]; | 111 path = argv[optind]; |
| 112 switch (path[0]) { |
| 113 case '.': |
| 114 case '/': |
| 115 snprintf(drive_path, sizeof(drive_path), "%s", path); |
| 116 break; |
| 117 default: |
| 118 snprintf(drive_path, sizeof(drive_path), "/dev/%s", path); |
| 119 break; |
| 120 } |
112 if (CGPT_OK != DriveOpen(drive_path, drive)) { | 121 if (CGPT_OK != DriveOpen(drive_path, drive)) { |
113 printf("[ERROR] DriveOpen(%s) error!\n", drive_path); | 122 printf("[ERROR] DriveOpen(%s) error!\n", drive_path); |
114 return CGPT_FAILED; | 123 return CGPT_FAILED; |
115 } | 124 } |
116 } else { | 125 } else { |
117 printf("[ERROR] One (and only one) non-option argument is required.\n"); | 126 printf("[ERROR] One (and only one) non-option argument is required.\n"); |
118 return CGPT_FAILED; | 127 return CGPT_FAILED; |
119 } | 128 } |
120 | 129 |
121 return CGPT_OK; | 130 return CGPT_OK; |
122 } | 131 } |
OLD | NEW |