com32/chain: Add unhide and unhideall options
authorMichal Soltys <soltys@ziu.info>
Thu, 30 Sep 2010 21:21:11 +0000 (23:21 +0200)
committerMichal Soltys <soltys@ziu.info>
Fri, 8 Oct 2010 10:40:51 +0000 (12:40 +0200)
It could be useful to be able to simply unhide partitions. This short
patch adds such functionality.

Signed-off-by: Michal Soltys <soltys@ziu.info>
com32/chain/chain.c
com32/chain/options.c
doc/chain.txt

index cb619fb..ae46fec 100644 (file)
@@ -349,7 +349,7 @@ static int pem_sethide(struct part_iter *miter, struct part_iter *iter)
 
     if ((t <= 0x1f) && ((mask >> (t & ~0x10u)) & 1)) {
        /* It's a hideable partition type */
-       if (miter->index == iter->index)
+       if (miter->index == iter->index || opt.hide & 4)
            t &= (uint8_t)(~0x10u);     /* unhide */
        else
            t |= 0x10u; /* hide */
@@ -398,22 +398,22 @@ static int pentry_mangle(struct part_iter *miter)
     int ridx;
 
     if (miter->type != typedos) {
-       error("Partition entry mangling ('hide[all]', 'mbrchs')\n"
+       error("Partition entry mangling ('[un]hide[all]', 'mbrchs')\n"
              "is meaningful only for legacy partition scheme.");
        goto bail;
     }
-    if ((miter->index < 1 || miter->index > 4) && opt.hide == 1)
-       error("WARNING: option 'hide' specified with a non-primary partition.\n");
+    if ((miter->index < 1 || miter->index > 4) && opt.hide & 1)
+       error("WARNING: option '[un]hide' specified with a non-primary partition.\n");
 
     if (!(iter = pi_begin(&miter->di, 1)))  /* turn on stepall */
        goto bail;
 
-    while (!pi_next(&iter) && !werr && (opt.hide == 2 || opt.mbrchs)) {
+    while (!pi_next(&iter) && !werr && (opt.hide & 2 || opt.mbrchs)) {
        ridx = iter->rawindex;
        dp = (struct disk_dos_part_entry *)iter->record;
 
        if (dp->ostype) {
-           if (opt.hide == 2 || (opt.hide == 1 && ridx <= 4)) {
+           if (opt.hide & 2 || (opt.hide & 1 && ridx <= 4)) {
                wb |= pem_sethide(miter, iter);
            }
            if (opt.mbrchs) {
@@ -436,7 +436,7 @@ bail:
     pi_del(&iter);
     if (werr)
        error("WARNING: failed to write E/MBR for partition\n"
-             "mangling options ('hide[all]', 'mbrchs').\n");
+             "mangling options ('[un]hide[all]', 'mbrchs').\n");
     return 0;
 }
 
index 14c96d7..2c3d0ff 100644 (file)
@@ -225,13 +225,16 @@ int parse_args(int argc, char *argv[])
            opt.swap = true;
        } else if (!strcmp(argv[i], "noswap")) {
            opt.swap = false;
-       } else if (!strcmp(argv[i], "nohide") ||
-                   !strcmp(argv[i], "nohideall")) {
+       } else if (!strcmp(argv[i], "nohide")) {
            opt.hide = 0;
        } else if (!strcmp(argv[i], "hide")) {
-           opt.hide = 1;
+           opt.hide = 1; /* 001b */
        } else if (!strcmp(argv[i], "hideall")) {
-           opt.hide = 2;
+           opt.hide = 2; /* 010b */
+       } else if (!strcmp(argv[i], "unhide")) {
+           opt.hide = 5; /* 101b */
+       } else if (!strcmp(argv[i], "unhideall")) {
+           opt.hide = 6; /* 110b */
        } else if (!strcmp(argv[i], "setbpb")) {
            opt.setbpb = true;
        } else if (!strcmp(argv[i], "nosetbpb")) {
index 886625d..76234f1 100644 (file)
@@ -181,13 +181,15 @@ This option will install a tiny stub code used to swap drive numbers, if the
 drive we use during chainloading is not fd0 or hd0.
 
        hide[all]
+       unhide[all]
        *nohide
 
 In certain situations it's useful to hide partitions - for example to make sure
 DOS gets C:. 'hide' will hide hidable primary partitions, except the one we're
 booting from. Similary, 'hideall' will hide all hidable partitions, except the
-one we're booting from. Hiding is performed only on the boot drive.
-Writing is only performed, if the values actually got changed.
+one we're booting from. Hiding is performed only on the booting drive. Options
+starting with 'un' will simply unhide every partition (primary ones or all).
+Writing is only performed, if the os type values actually changed.
 
        mbrchs
        *nombrchs