diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2005-01-19 15:48:21 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2005-01-19 15:48:21 +0000 |
commit | 3d950ae7b18a74e68d00f7aa1aeedc0de767a37f (patch) | |
tree | 9a9f84b4c929cc44515b66e7b11577924a0b040d /sbin/fdisk | |
parent | 32ae4c7606813925856a8f6d568185dce44029ef (diff) |
add a swap primitive; ok various, will be polished after by tom
Diffstat (limited to 'sbin/fdisk')
-rw-r--r-- | sbin/fdisk/cmd.c | 44 | ||||
-rw-r--r-- | sbin/fdisk/cmd.h | 3 | ||||
-rw-r--r-- | sbin/fdisk/fdisk.8 | 4 | ||||
-rw-r--r-- | sbin/fdisk/user.c | 3 |
4 files changed, 50 insertions, 4 deletions
diff --git a/sbin/fdisk/cmd.c b/sbin/fdisk/cmd.c index beb47b9f35b..435b8a56b7b 100644 --- a/sbin/fdisk/cmd.c +++ b/sbin/fdisk/cmd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd.c,v 1.37 2004/11/06 18:57:59 otto Exp $ */ +/* $OpenBSD: cmd.c,v 1.38 2005/01/19 15:48:20 deraadt Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -95,6 +95,48 @@ Xdisk(cmd_t *cmd, disk_t *disk, mbr_t *mbr, mbr_t *tt, int offset) /* ARGSUSED */ int +Xswap(cmd_t *cmd, disk_t *disk, mbr_t *mbr, mbr_t *tt, int offset) +{ + int pf, pt, ret; + prt_t pp; + + ret = CMD_CONT; + + if (!isdigit(cmd->args[0])) { + printf("Invalid argument: %s <from partition number>\n", + cmd->cmd); + return (ret); + } + + pf = atoi(cmd->args); + if (pf < 0 || pf > 3) { + printf("Invalid partition number %d.\n", pf); + return (ret); + } + + pt = ask_num("Swap with what paritition?", ASK_DEC, + -1, 0, 3, NULL); + if (pt < 0 || pt > 3) { + printf("Invalid partition number %d.\n", pt); + return (ret); + } + + if (pt == pf) { + printf("%d same partition as %d, doing nothing.\n", pt, pf); + return (ret); + } + + pp = mbr->part[pt]; + mbr->part[pt] = mbr->part[pf]; + mbr->part[pf] = pp; + + ret = CMD_DIRTY; + return (ret); +} + + +/* ARGSUSED */ +int Xedit(cmd_t *cmd, disk_t *disk, mbr_t *mbr, mbr_t *tt, int offset) { int pn, num, ret; diff --git a/sbin/fdisk/cmd.h b/sbin/fdisk/cmd.h index 05e7088fe38..0d2d824b8c8 100644 --- a/sbin/fdisk/cmd.h +++ b/sbin/fdisk/cmd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd.h,v 1.8 2003/06/03 01:13:19 weingart Exp $ */ +/* $OpenBSD: cmd.h,v 1.9 2005/01/19 15:48:20 deraadt Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -63,6 +63,7 @@ int Xmanual(cmd_t *, disk_t *, mbr_t *, mbr_t *, int); int Xedit(cmd_t *, disk_t *, mbr_t *, mbr_t *, int); int Xsetpid(cmd_t *, disk_t *, mbr_t *, mbr_t *, int); int Xselect(cmd_t *, disk_t *, mbr_t *, mbr_t *, int); +int Xswap(cmd_t *, disk_t *, mbr_t *, mbr_t *, int); int Xprint(cmd_t *, disk_t *, mbr_t *, mbr_t *, int); int Xwrite(cmd_t *, disk_t *, mbr_t *, mbr_t *, int); int Xexit(cmd_t *, disk_t *, mbr_t *, mbr_t *, int); diff --git a/sbin/fdisk/fdisk.8 b/sbin/fdisk/fdisk.8 index d7858a78541..6c88a3b7c22 100644 --- a/sbin/fdisk/fdisk.8 +++ b/sbin/fdisk/fdisk.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: fdisk.8,v 1.43 2004/06/26 11:45:40 jmc Exp $ +.\" $OpenBSD: fdisk.8,v 1.44 2005/01/19 15:48:20 deraadt Exp $ .\" .\" Copyright (c) 1997 Tobias Weingartner .\" All rights reserved. @@ -234,6 +234,8 @@ Update the machine code and 0xAA55 signature in the memory copy of the currently selected boot block. Note that this option will overwrite the NT disk signature, if present. +.It Em swap +Swap two MBR entries. .It Em select Select and load into memory the boot block pointed to by the extended partition table entry in the current boot block. diff --git a/sbin/fdisk/user.c b/sbin/fdisk/user.c index 7be29c73636..3727ae4988d 100644 --- a/sbin/fdisk/user.c +++ b/sbin/fdisk/user.c @@ -1,4 +1,4 @@ -/* $OpenBSD: user.c,v 1.21 2003/06/11 06:22:12 deraadt Exp $ */ +/* $OpenBSD: user.c,v 1.22 2005/01/19 15:48:20 deraadt Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -53,6 +53,7 @@ static cmd_table_t cmd_table[] = { {"flag", Xflag, "Flag given table entry as bootable"}, {"update", Xupdate, "Update machine code in loaded MBR"}, {"select", Xselect, "Select extended partition table entry MBR"}, + {"swap", Xswap, "Swap two partition entries"}, {"print", Xprint, "Print loaded MBR partition table"}, {"write", Xwrite, "Write loaded MBR to disk"}, {"exit", Xexit, "Exit edit of current MBR, without saving changes"}, |