[BACK]Return to unset.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / sbin / gpt

Annotation of src/sbin/gpt/unset.c, Revision 1.15

1.1       jnemeth     1: /*-
                      2:  * Copyright (c) 2002 Marcel Moolenaar
                      3:  * All rights reserved.
                      4:  *
                      5:  * Redistribution and use in source and binary forms, with or without
                      6:  * modification, are permitted provided that the following conditions
                      7:  * are met:
                      8:  *
                      9:  * 1. Redistributions of source code must retain the above copyright
                     10:  *    notice, this list of conditions and the following disclaimer.
                     11:  * 2. Redistributions in binary form must reproduce the above copyright
                     12:  *    notice, this list of conditions and the following disclaimer in the
                     13:  *    documentation and/or other materials provided with the distribution.
                     14:  *
                     15:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
                     16:  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
                     17:  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
                     18:  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
                     19:  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
                     20:  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
                     21:  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
                     22:  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
                     23:  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
                     24:  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
                     25:  */
                     26:
1.3       christos   27: #if HAVE_NBTOOL_CONFIG_H
                     28: #include "nbtool_config.h"
                     29: #endif
                     30:
1.1       jnemeth    31: #include <sys/cdefs.h>
                     32: #ifdef __FBSDID
                     33: __FBSDID("$FreeBSD: src/sbin/gpt/add.c,v 1.14 2006/06/22 22:05:28 marcel Exp $");
                     34: #endif
                     35: #ifdef __RCSID
1.15    ! martin     36: __RCSID("$NetBSD: unset.c,v 1.14 2018/03/19 09:06:20 mlelstv Exp $");
1.1       jnemeth    37: #endif
                     38:
                     39: #include <sys/types.h>
                     40:
                     41: #include <err.h>
                     42: #include <stddef.h>
                     43: #include <stdio.h>
                     44: #include <stdlib.h>
                     45: #include <string.h>
                     46: #include <unistd.h>
                     47:
                     48: #include "map.h"
                     49: #include "gpt.h"
1.7       christos   50: #include "gpt_private.h"
1.1       jnemeth    51:
1.8       christos   52: static int cmd_unset(gpt_t, int, char *[]);
1.1       jnemeth    53:
1.8       christos   54: static const char *unsethelp[] = {
1.10      christos   55:        "-a attribute -i index",
1.15    ! martin     56:        "-a attribute -b startsec",
1.14      mlelstv    57:        "-l",
1.8       christos   58: };
                     59:
                     60: struct gpt_cmd c_unset = {
                     61:        "unset",
                     62:        cmd_unset,
                     63:        unsethelp, __arraycount(unsethelp),
1.14      mlelstv    64:        GPT_OPTDEV,
1.8       christos   65: };
1.1       jnemeth    66:
1.8       christos   67: #define usage() gpt_usage(NULL, &c_unset)
1.1       jnemeth    68:
1.7       christos   69: static int
                     70: cmd_unset(gpt_t gpt, int argc, char *argv[])
1.1       jnemeth    71: {
1.7       christos   72:        int ch;
1.9       christos   73:        unsigned int entry = 0;
                     74:        uint64_t attributes = 0;
1.15    ! martin     75:        off_t start = 0;
        !            76:        map_t m;
1.1       jnemeth    77:
1.15    ! martin     78:        while ((ch = getopt(argc, argv, "a:b:i:l")) != -1) {
1.1       jnemeth    79:                switch(ch) {
                     80:                case 'a':
1.14      mlelstv    81:                        if (gpt == NULL || gpt_attr_get(gpt, &attributes) == -1)
1.8       christos   82:                                return usage();
1.1       jnemeth    83:                        break;
1.15    ! martin     84:                case 'b':
        !            85:                        if (gpt == NULL || gpt_human_get(gpt, &start) == -1)
        !            86:                                return usage();
        !            87:                        break;
1.1       jnemeth    88:                case 'i':
1.14      mlelstv    89:                        if (gpt == NULL || gpt_uint_get(gpt, &entry) == -1)
1.8       christos   90:                                return usage();
1.1       jnemeth    91:                        break;
1.12      christos   92:                case 'l':
                     93:                        gpt_attr_help("\t");
                     94:                        return 0;
1.1       jnemeth    95:                default:
1.8       christos   96:                        return usage();
1.1       jnemeth    97:                }
                     98:        }
                     99:
1.15    ! martin    100:        if (start > 0) {
        !           101:                for (m = map_first(gpt); m != NULL; m = m->map_next) {
        !           102:                        if (m->map_type != MAP_TYPE_GPT_PART ||
        !           103:                            m->map_index < 1)
        !           104:                                continue;
        !           105:                        if (start != m->map_start)
        !           106:                                continue;
        !           107:                        entry = m->map_index;
        !           108:                        break;
        !           109:                }
        !           110:        }
        !           111:
1.14      mlelstv   112:        if (gpt == NULL || argc != optind)
1.8       christos  113:                return usage();
1.1       jnemeth   114:
1.9       christos  115:        return gpt_attr_update(gpt, entry, 0, attributes);
1.1       jnemeth   116: }

CVSweb <webmaster@jp.NetBSD.org>