Chameleon

Chameleon Commit Details

Date:2015-03-15 10:43:46 (5 years 8 months ago)
Author:ErmaC
Commit:2635
Parents: 2634
Message:Update util/fdisk (credits to cparm)
Changes:
M/trunk/i386/util/fdisk/part.c
M/trunk/i386/util/fdisk/disk.c
M/trunk/i386/util/fdisk/user.c
M/trunk/i386/util/fdisk/fdisk.c
M/trunk/i386/util/fdisk/mbr.c

File differences

trunk/i386/util/fdisk/fdisk.c
239239
240240
241241
242
243
242244
243245
244246
......
259261
260262
261263
264
262265
263266
264267
}
mbr_binary = (char *)malloc(MBR_CODE_SIZE);
if (!mbr_binary) errx(1, "out of memory");
if ((fd = open(mbrfile, O_RDONLY)) == -1) {
warn("could not open MBR file %s", mbrfile);
bzero(mbr_binary, MBR_CODE_SIZE);
} else if (i_flag) {
/* If they didn't specify -a, they'll get the default auto style */
mp = MBR_alloc(NULL);
if (!mp) errx(1, "out of memory");
if (AUTO_init(&disk, auto_style, mp) != AUTO_OK) {
errx(1, "error initializing disk");
}
trunk/i386/util/fdisk/part.c
241241
242242
243243
244
244
245245
246246
247247
......
353353
354354
355355
356
356
357357
358358
359359
......
390390
391391
392392
393
393
394394
395395
396396
/* Zero out entry if not used */
if (partn->id == DOSPTYP_UNUSED ) {
memset(partn, 0, sizeof(*partn));
memset(partn, 0, sizeof(prt_t));
}
}
/* Zero out entry if not used */
if (part->id == DOSPTYP_UNUSED ) {
memset(part, 0, sizeof(*part));
memset(part, 0, sizeof(prt_t));
return;
}
/* Zero out entry if not used */
if (part->id == DOSPTYP_UNUSED ) {
memset(part, 0, sizeof(*part));
memset(part, 0, sizeof(prt_t));
return;
}
trunk/i386/util/fdisk/user.c
145145
146146
147147
148
148
149149
150150
151151
......
156156
157157
158158
159
159160
161
162
160163
161164
162165
......
166169
167170
168171
169
172
170173
171
174
172175
173176
174177
......
189192
190193
191194
192
195
193196
194197
195198
......
197200
198201
199202
200
203
201204
202205
203206
......
252255
253256
254257
255
258
256259
257260
258261
259
262
263
264
260265
261266
262267
static int editlevel;
mbr_t *mbr;
cmd_t cmd;
int i, st, fd;
int i, st = CMD_EXIT, fd;
int modified = 0;
/* One level deeper */
/* Read MBR & partition */
mbr = MBR_alloc(NULL);
if (!mbr) errx(1, "out of memory");
fd = DISK_open(disk->name, O_RDONLY);
if (fd == -1)
err(1, "Could not open %s", disk->name);
MBR_read(disk, fd, offset, mbr);
DISK_close(fd);
if (mbr->signature != MBR_SIGNATURE) {
int yn = ask_yn("The signature for this MBR is invalid.\nWould you like to initialize the partition table?", 1);
if (yn) {
strcpy(cmd.cmd, "erase");
strlcpy(cmd.cmd, "erase", sizeof(cmd.cmd));
cmd.args[0] = '\0';
st = Xerase(&cmd, disk, mbr, tt, offset);
Xerase(&cmd, disk, mbr, tt, offset);
modified = 1;
}
}
break;
/* Quick hack to put in '?' == 'help' */
if (!strcmp(cmd.cmd, "?"))
if (!strncmp(cmd.cmd, "?", sizeof("?")))
i = 0;
/* Check for valid command */
printf("Invalid command '%s'. Try 'help'.\n", cmd.cmd);
continue;
} else
strcpy(cmd.cmd, cmd_table[i].cmd);
strlcpy(cmd.cmd, cmd_table[i].cmd, sizeof(cmd.cmd));
/* Call function */
st = cmd_table[i].fcn(&cmd, disk, mbr, tt, offset);
disk_t *disk;
int do_dump;
{
int fd, offset, firstoff;
int fd /*, offset, firstoff*/;
mbr_t *mbr;
fd = DISK_open(disk->name, O_RDONLY);
offset = firstoff = 0;
if (fd == -1)
err(1, "Could not open %s", disk->name);
/*offset = firstoff = 0;*/
if (!do_dump)
DISK_printmetrics(disk);
trunk/i386/util/fdisk/mbr.c
237237
238238
239239
240
240241
242
243
241244
242245
243246
......
393396
394397
395398
399
396400
397401
398402
......
446450
447451
448452
453
449454
450455
451456
......
475480
476481
477482
483
484
478485
479486
480487
488
481489
482490
483491
......
511519
512520
513521
522
523
514524
515525
516526
mbr_t *mbrd;
mbrd = MBR_alloc(NULL);
if (!mbr) errx(1, "out of memory");
fd = DISK_open(disk->name, O_RDONLY);
if (fd == -1)
err(1, "Could not open %s", disk->name);
MBR_read(disk, fd, offset, mbrd);
DISK_close(fd);
MBR_parse(disk, offset, reloff, mbrd);
if (mbr == NULL) {
mbr = MBR_alloc(prev_mbr);
if (!mbr) errx(1, "out of memory");
if (head == NULL)
head = mbr;
}
MBR_alloc(mbr_t *parent)
{
mbr_t *mbr = (mbr_t *)malloc(sizeof(mbr_t));
if (!mbr) return NULL;
bzero(mbr, sizeof(mbr_t));
if (parent) {
parent->next = mbr;
int i, fd, offset, firstoff;
fd = DISK_open(disk->name, O_RDONLY);
if (fd == -1)
err(1, "Could not open %s", disk->name);
firstoff = offset = 0;
do {
mbr = MBR_alloc(mbr);
if (!mbr) errx(1, "out of memory");
if (head == NULL) {
head = mbr;
}
int fd;
fd = DISK_open(disk->name, O_RDWR);
if (fd == -1)
err(1, "Could not open %s", disk->name);
while (mbr) {
MBR_make(mbr);
result = MBR_write(disk, fd, mbr);
trunk/i386/util/fdisk/disk.c
167167
168168
169169
170
170
171
172
173
171174
172175
173176
......
265268
266269
267270
268
271
269272
270273
271274
272275
273276
274
275277
276278
277279
/* Get label metrics */
if ((fd = DISK_open(name, O_RDONLY)) != -1) {
lm = malloc(sizeof(DISK_metrics));
if (!lm) {
err(1, "DISK_getlabelmetrics: Could not allocate memory");
return NULL;
}
if (fstat(fd, &st) == -1)
err(1, "%s", name);
if (!S_ISREG(st.st_mode) || S_ISBLK(st.st_mode)) {
disk_t *disk;
DISK_metrics *user;
{
int ret;
int ret = 1;
int fd;
uint32_t sector_size;
/* Default to 512 bytes per sector, in case of failure. */
user->sector_size = 512;
ret = 1;
fd = DISK_open(disk->name, O_RDONLY);
if (fd == -1) {

Archive Download the corresponding diff file

Revision: 2635