4 * Covert partition type. $Revision: 1.5 $
6 * Copyright (c) 1999, Eryk Vershen
10 * Revision 1.2 2000/05/16 13:56:11 eryk
13 * Revision 1.1 2000/02/13 22:04:08 eryk
25 #include "partition_map.h"
32 #define CFLAG_DEFAULT 0
33 #define DFLAG_DEFAULT 0
34 #define HFLAG_DEFAULT 0
35 #define INTERACT_DEFAULT 0
36 #define RFLAG_DEFAULT 0
47 int hflag
= HFLAG_DEFAULT
; /* show help */
48 int dflag
= DFLAG_DEFAULT
; /* turn on debugging commands and printout */
49 int rflag
= RFLAG_DEFAULT
; /* open device read Only */
50 int interactive
= INTERACT_DEFAULT
;
51 int cflag
= CFLAG_DEFAULT
; /* compute device size */
55 * Forward declarations
57 void process(char *filename
);
64 main(int argc
, char **argv
)
69 extern char *optarg
; /* pointer to argument */
70 extern int optind
; /* next argv index */
71 extern int opterr
; /* who does error messages */
72 extern int optopt
; /* char that caused the error */
73 int getopt_error
; /* getopt choked */
74 char option_error
[100]; /* buffer for error message */
81 init_program_name(argv
);
84 opterr
= 0; /* tell getopt to be quiet */
87 * Changes to getopt's last argument should
88 * be reflected in the string printed by the
91 while ((c
= getopt(argc
, argv
, "a:b")) != EOF
) {
102 usage("missing argument");
111 snprintf(option_error
, sizeof(option_error
),
112 "no such option as -%c", c
);
118 if (optind
>= argc
) {
119 usage("no file argument");
121 for (i
= optind
; i
< argc
; i
++) {
134 for (t
= s
; *t
; t
++) {
137 for (t
--; t
>= s
; t
--) {
138 if (!isdigit((unsigned char)*t
)) {
154 * The operation to apply to each file ...
157 process(char *filename
)
161 partition_map_header
*map
;
163 partition_map
* entry
;
165 //printf("Processing %s\n", filename);
167 // 1) strip off number from end of filename
168 s
= strdup(filename
);
172 fatal(-1, "%s does not end in a number", filename
);
175 // 2) open prefix of filename as partition map
176 map
= open_partition_map(s
, &valid_file
, 0);
178 fatal(-1, "%s does not have a partition map", s
);
182 // 3) verify the type for the partition;
184 if (map
->writable
== 0) {
185 fatal(-1, "The map is not writable");
189 // 4) find partition and change it
190 entry
= find_entry_by_disk_address(index
, map
);
192 fatal(-1, "No such partition");
193 } else if (strcmp(entry
->data
->dpme_type
, kHFSType
) != 0) {
194 fatal(-1, "Can't convert a partition with type %s",
195 entry
->data
->dpme_type
);
197 // 4a) modify the type
198 strncpy(entry
->data
->dpme_type
, kUnixType
, DPISTRLEN
);
200 // 5) and write back.
201 write_partition_map(map
);