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

Annotation of src/sbin/gpt/restore.c, Revision 1.18

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.4       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/create.c,v 1.11 2005/08/31 01:47:19 marcel Exp $");
                     34: #endif
                     35: #ifdef __RCSID
1.18    ! jnemeth    36: __RCSID("$NetBSD: restore.c,v 1.17 2017/09/07 10:23:33 christos Exp $");
1.1       jnemeth    37: #endif
                     38:
                     39: #include <sys/types.h>
                     40: #include <sys/bootblock.h>
1.2       jnemeth    41: #include <sys/disklabel_gpt.h>
1.1       jnemeth    42:
                     43: #include <err.h>
                     44: #include <stddef.h>
                     45: #include <stdio.h>
                     46: #include <stdlib.h>
                     47: #include <string.h>
                     48: #include <unistd.h>
1.2       jnemeth    49: #include <prop/proplib.h>
1.1       jnemeth    50:
                     51: #include "map.h"
                     52: #include "gpt.h"
1.10      christos   53: #include "gpt_private.h"
1.1       jnemeth    54:
1.11      christos   55: static int cmd_restore(gpt_t, int, char *[]);
1.1       jnemeth    56:
1.11      christos   57: static const char *restorehelp[] = {
1.15      christos   58:        "[-F] [-i infile]",
1.11      christos   59: };
                     60:
                     61: struct gpt_cmd c_restore = {
                     62:        "restore",
                     63:        cmd_restore,
                     64:        restorehelp, __arraycount(restorehelp),
1.18    ! jnemeth    65:        GPT_SYNC,
1.11      christos   66: };
1.1       jnemeth    67:
1.11      christos   68: #define usage() gpt_usage(NULL, &c_restore)
1.1       jnemeth    69:
1.10      christos   70: #define PROP_ERR(x)     if (!(x)) {            \
                     71:        gpt_warnx(gpt, "proplib failure");      \
                     72:        return -1;                              \
                     73: }
1.2       jnemeth    74:
1.16      christos   75: #define prop_uint(a) (u_int)prop_number_unsigned_integer_value(a)
                     76: #define prop_uint16_t(a) (uint16_t)prop_number_unsigned_integer_value(a)
                     77: #define prop_uint8_t(a) (uint8_t)prop_number_unsigned_integer_value(a)
1.14      christos   78:
                     79: static int
                     80: restore_mbr(gpt_t gpt, struct mbr *mbr, prop_dictionary_t mbr_dict, off_t last)
                     81: {
                     82:        unsigned int i;
                     83:        prop_number_t propnum;
                     84:        struct mbr_part *part;
                     85:
                     86:        propnum = prop_dictionary_get(mbr_dict, "index");
                     87:        PROP_ERR(propnum);
                     88:
1.16      christos   89:        i = prop_uint(propnum);
1.14      christos   90:        propnum = prop_dictionary_get(mbr_dict, "flag");
                     91:        PROP_ERR(propnum);
                     92:        part = &mbr->mbr_part[i];
                     93:
1.16      christos   94:        part->part_flag = prop_uint8_t(propnum);
1.14      christos   95:        propnum = prop_dictionary_get(mbr_dict, "start_head");
                     96:        PROP_ERR(propnum);
1.16      christos   97:        part->part_shd = prop_uint8_t(propnum);
1.14      christos   98:        propnum = prop_dictionary_get(mbr_dict, "start_sector");
                     99:        PROP_ERR(propnum);
1.16      christos  100:        part->part_ssect = prop_uint8_t(propnum);
1.14      christos  101:        propnum = prop_dictionary_get(mbr_dict, "start_cylinder");
                    102:        PROP_ERR(propnum);
1.16      christos  103:        part->part_scyl = prop_uint8_t(propnum);
1.14      christos  104:        propnum = prop_dictionary_get(mbr_dict, "type");
                    105:        PROP_ERR(propnum);
1.16      christos  106:        part->part_typ = prop_uint8_t(propnum);
1.14      christos  107:        propnum = prop_dictionary_get(mbr_dict, "end_head");
                    108:        PROP_ERR(propnum);
1.16      christos  109:        part->part_ehd = prop_uint8_t(propnum);
1.14      christos  110:        propnum = prop_dictionary_get(mbr_dict, "end_sector");
                    111:        PROP_ERR(propnum);
1.16      christos  112:        part->part_esect = prop_uint8_t(propnum);
1.14      christos  113:        propnum = prop_dictionary_get(mbr_dict, "end_cylinder");
                    114:        PROP_ERR(propnum);
1.16      christos  115:        part->part_ecyl = prop_uint8_t(propnum);
1.14      christos  116:        propnum = prop_dictionary_get(mbr_dict, "lba_start_low");
                    117:        PROP_ERR(propnum);
1.16      christos  118:        part->part_start_lo = htole16(prop_uint16_t(propnum));
1.14      christos  119:        propnum = prop_dictionary_get(mbr_dict, "lba_start_high");
                    120:        PROP_ERR(propnum);
1.16      christos  121:        part->part_start_hi = htole16(prop_uint16_t(propnum));
1.14      christos  122:        /* adjust PMBR size to size of device */
                    123:        if (part->part_typ == MBR_PTYPE_PMBR) {
                    124:                if (last > 0xffffffff) {
                    125:                        mbr->mbr_part[0].part_size_lo = htole16(0xffff);
                    126:                        mbr->mbr_part[0].part_size_hi = htole16(0xffff);
                    127:                } else {
1.16      christos  128:                        mbr->mbr_part[0].part_size_lo = htole16((uint16_t)last);
                    129:                        mbr->mbr_part[0].part_size_hi = htole16(
                    130:                            (uint16_t)(last >> 16));
1.14      christos  131:                }
                    132:        } else {
                    133:                propnum = prop_dictionary_get(mbr_dict, "lba_size_low");
                    134:                PROP_ERR(propnum);
1.16      christos  135:                part->part_size_lo = htole16(prop_uint16_t(propnum));
1.14      christos  136:                propnum = prop_dictionary_get(mbr_dict, "lba_size_high");
                    137:                PROP_ERR(propnum);
1.16      christos  138:                part->part_size_hi = htole16(prop_uint16_t(propnum));
1.14      christos  139:        }
                    140:        return 0;
                    141: }
                    142:
                    143: static int
                    144: restore_ent(gpt_t gpt, prop_dictionary_t gpt_dict, void *secbuf, u_int gpt_size,
                    145:     u_int entries)
                    146: {
                    147:        unsigned int i;
                    148:        struct gpt_ent ent;
                    149:        const char *s;
                    150:        prop_string_t propstr;
                    151:        prop_number_t propnum;
                    152:
                    153:        memset(&ent, 0, sizeof(ent));
                    154:        propstr = prop_dictionary_get(gpt_dict, "type");
                    155:        PROP_ERR(propstr);
                    156:        s = prop_string_cstring_nocopy(propstr);
                    157:        if (gpt_uuid_parse(s, ent.ent_type) != 0) {
                    158:                gpt_warnx(gpt, "%s: not able to convert to an UUID", s);
                    159:                return -1;
                    160:        }
                    161:        propstr = prop_dictionary_get(gpt_dict, "guid");
                    162:        PROP_ERR(propstr);
                    163:        s = prop_string_cstring_nocopy(propstr);
                    164:        if (gpt_uuid_parse(s, ent.ent_guid) != 0) {
                    165:                gpt_warnx(gpt, "%s: not able to convert to an UUID", s);
                    166:                return -1;
                    167:        }
                    168:        propnum = prop_dictionary_get(gpt_dict, "start");
                    169:        PROP_ERR(propnum);
                    170:        ent.ent_lba_start = htole64(prop_uint(propnum));
                    171:        propnum = prop_dictionary_get(gpt_dict, "end");
                    172:        PROP_ERR(propnum);
                    173:        ent.ent_lba_end = htole64(prop_uint(propnum));
                    174:        propnum = prop_dictionary_get(gpt_dict, "attributes");
                    175:        PROP_ERR(propnum);
                    176:        ent.ent_attr = htole64(prop_uint(propnum));
                    177:        propstr = prop_dictionary_get(gpt_dict, "name");
                    178:        if (propstr != NULL) {
                    179:                s = prop_string_cstring_nocopy(propstr);
                    180:                utf8_to_utf16((const uint8_t *)s, ent.ent_name,
1.17      christos  181:                    __arraycount(ent.ent_name));
1.14      christos  182:        }
                    183:        propnum = prop_dictionary_get(gpt_dict, "index");
                    184:        PROP_ERR(propnum);
1.16      christos  185:        i = prop_uint(propnum);
1.14      christos  186:        if (i > entries) {
                    187:                gpt_warnx(gpt, "Entity index out of bounds %u > %u\n",
                    188:                    i, entries);
                    189:                return -1;
                    190:        }
                    191:        memcpy((char *)secbuf + gpt->secsz + ((i - 1) * sizeof(ent)),
                    192:            &ent, sizeof(ent));
                    193:        return 0;
                    194: }
                    195:
1.10      christos  196: static int
1.15      christos  197: restore(gpt_t gpt, const char *infile, int force)
1.1       jnemeth   198: {
1.7       jnemeth   199:        gpt_uuid_t gpt_guid, uuid;
1.2       jnemeth   200:        off_t firstdata, last, lastdata, gpe_start, gpe_end;
1.10      christos  201:        map_t map;
1.1       jnemeth   202:        struct mbr *mbr;
                    203:        struct gpt_hdr *hdr;
1.14      christos  204:        unsigned int i, gpt_size;
1.2       jnemeth   205:        prop_dictionary_t props, gpt_dict, mbr_dict, type_dict;
                    206:        prop_object_iterator_t propiter;
                    207:        prop_data_t propdata;
                    208:        prop_array_t mbr_array, gpt_array;
                    209:        prop_number_t propnum;
                    210:        prop_string_t propstr;
1.14      christos  211:        unsigned int entries;
1.2       jnemeth   212:        const char *s;
1.14      christos  213:        void *secbuf = NULL;;
                    214:        int rv = -1;
1.1       jnemeth   215:
1.10      christos  216:        last = gpt->mediasz / gpt->secsz - 1LL;
1.1       jnemeth   217:
1.10      christos  218:        if (map_find(gpt, MAP_TYPE_PRI_GPT_HDR) != NULL ||
                    219:            map_find(gpt, MAP_TYPE_SEC_GPT_HDR) != NULL) {
1.2       jnemeth   220:                if (!force) {
1.10      christos  221:                        gpt_warnx(gpt, "Device contains a GPT");
                    222:                        return -1;
1.2       jnemeth   223:                }
1.1       jnemeth   224:        }
1.10      christos  225:        map = map_find(gpt, MAP_TYPE_MBR);
1.1       jnemeth   226:        if (map != NULL) {
                    227:                if (!force) {
1.10      christos  228:                        gpt_warnx(gpt, "Device contains an MBR");
                    229:                        return -1;
1.1       jnemeth   230:                }
                    231:                /* Nuke the MBR in our internal map. */
                    232:                map->map_type = MAP_TYPE_UNUSED;
                    233:        }
                    234:
1.15      christos  235:        props = prop_dictionary_internalize_from_file(
                    236:            strcmp(infile, "-") == 0 ? "/dev/stdin" : infile);
1.3       jnemeth   237:        if (props == NULL) {
1.10      christos  238:                gpt_warnx(gpt, "Unable to read/parse backup file");
                    239:                return -1;
1.3       jnemeth   240:        }
1.2       jnemeth   241:
                    242:        propnum = prop_dictionary_get(props, "sector_size");
                    243:        PROP_ERR(propnum);
1.10      christos  244:        if (!prop_number_equals_integer(propnum, gpt->secsz)) {
                    245:                gpt_warnx(gpt, "Sector size does not match backup");
1.2       jnemeth   246:                prop_object_release(props);
1.10      christos  247:                return -1;
1.1       jnemeth   248:        }
                    249:
1.2       jnemeth   250:        gpt_dict = prop_dictionary_get(props, "GPT_HDR");
                    251:        PROP_ERR(gpt_dict);
                    252:
                    253:        propnum = prop_dictionary_get(gpt_dict, "revision");
                    254:        PROP_ERR(propnum);
                    255:        if (!prop_number_equals_unsigned_integer(propnum, 0x10000)) {
1.10      christos  256:                gpt_warnx(gpt, "backup is not revision 1.0");
1.2       jnemeth   257:                prop_object_release(gpt_dict);
                    258:                prop_object_release(props);
1.10      christos  259:                return -1;
1.1       jnemeth   260:        }
                    261:
1.2       jnemeth   262:        propnum = prop_dictionary_get(gpt_dict, "entries");
                    263:        PROP_ERR(propnum);
1.14      christos  264:        entries = prop_uint(propnum);
1.16      christos  265:        gpt_size = (u_int)(entries * sizeof(struct gpt_ent) / gpt->secsz);
1.10      christos  266:        if (gpt_size * sizeof(struct gpt_ent) % gpt->secsz)
1.3       jnemeth   267:                gpt_size++;
                    268:
1.2       jnemeth   269:        propstr = prop_dictionary_get(gpt_dict, "guid");
                    270:        PROP_ERR(propstr);
                    271:        s = prop_string_cstring_nocopy(propstr);
1.7       jnemeth   272:        if (gpt_uuid_parse(s, gpt_guid) != 0) {
1.10      christos  273:                gpt_warnx(gpt, "%s: not able to convert to an UUID", s);
1.14      christos  274:                goto out;
1.1       jnemeth   275:        }
1.2       jnemeth   276:        firstdata = gpt_size + 2;               /* PMBR and GPT header */
                    277:        lastdata = last - gpt_size - 1;         /* alt. GPT table and header */
                    278:
                    279:        type_dict = prop_dictionary_get(props, "GPT_TBL");
                    280:        PROP_ERR(type_dict);
                    281:        gpt_array = prop_dictionary_get(type_dict, "gpt_array");
                    282:        PROP_ERR(gpt_array);
                    283:        propiter = prop_array_iterator(gpt_array);
                    284:        PROP_ERR(propiter);
                    285:        while ((gpt_dict = prop_object_iterator_next(propiter)) != NULL) {
                    286:                propstr = prop_dictionary_get(gpt_dict, "type");
                    287:                PROP_ERR(propstr);
                    288:                s = prop_string_cstring_nocopy(propstr);
1.6       christos  289:                if (gpt_uuid_parse(s, uuid) != 0) {
1.10      christos  290:                        gpt_warnx(gpt, "%s: not able to convert to an UUID", s);
1.14      christos  291:                        goto out;
1.2       jnemeth   292:                }
1.6       christos  293:                if (gpt_uuid_is_nil(uuid))
1.2       jnemeth   294:                        continue;
                    295:                propnum = prop_dictionary_get(gpt_dict, "start");
                    296:                PROP_ERR(propnum);
1.14      christos  297:                gpe_start = prop_uint(propnum);
1.2       jnemeth   298:                propnum = prop_dictionary_get(gpt_dict, "end");
                    299:                PROP_ERR(propnum);
1.14      christos  300:                gpe_end = prop_uint(propnum);
1.2       jnemeth   301:                if (gpe_start < firstdata || gpe_end > lastdata) {
1.10      christos  302:                        gpt_warnx(gpt, "Backup GPT doesn't fit");
1.14      christos  303:                        goto out;
1.2       jnemeth   304:                }
                    305:        }
                    306:        prop_object_iterator_release(propiter);
                    307:
1.14      christos  308:        /* GPT TABLE + GPT HEADER */
                    309:        if ((secbuf = calloc(gpt_size + 1, gpt->secsz)) == NULL) {
                    310:                gpt_warn(gpt, "not enough memory to create a sector buffer");
                    311:                goto out;
1.2       jnemeth   312:        }
1.3       jnemeth   313:
1.10      christos  314:        if (lseek(gpt->fd, 0LL, SEEK_SET) == -1) {
1.14      christos  315:                gpt_warn(gpt, "Can't seek to beginning");
                    316:                goto out;
1.3       jnemeth   317:        }
                    318:        for (i = 0; i < firstdata; i++) {
1.14      christos  319:                if (write(gpt->fd, secbuf, gpt->secsz) != (ssize_t)gpt->secsz) {
                    320:                        gpt_warn(gpt, "Error writing");
                    321:                        goto out;
1.3       jnemeth   322:                }
                    323:        }
1.10      christos  324:        if (lseek(gpt->fd, (lastdata + 1) * gpt->secsz, SEEK_SET) == -1) {
1.14      christos  325:                gpt_warn(gpt, "Can't seek to end");
                    326:                goto out;
1.3       jnemeth   327:        }
1.16      christos  328:        for (i = (u_int)(lastdata + 1); i <= (u_int)last; i++) {
1.14      christos  329:                if (write(gpt->fd, secbuf, gpt->secsz) != (ssize_t)gpt->secsz) {
                    330:                        gpt_warn(gpt, "Error writing");
                    331:                        goto out;
1.3       jnemeth   332:                }
                    333:        }
1.2       jnemeth   334:
1.14      christos  335:        mbr = secbuf;
1.2       jnemeth   336:        type_dict = prop_dictionary_get(props, "MBR");
                    337:        PROP_ERR(type_dict);
                    338:        propdata = prop_dictionary_get(type_dict, "code");
                    339:        PROP_ERR(propdata);
                    340:        memcpy(mbr->mbr_code, prop_data_data_nocopy(propdata),
                    341:            sizeof(mbr->mbr_code));
                    342:        mbr_array = prop_dictionary_get(type_dict, "mbr_array");
                    343:        PROP_ERR(mbr_array);
                    344:        propiter = prop_array_iterator(mbr_array);
                    345:        PROP_ERR(propiter);
                    346:        while ((mbr_dict = prop_object_iterator_next(propiter)) != NULL) {
1.14      christos  347:                if (restore_mbr(gpt, mbr, mbr_dict, last) == -1)
                    348:                        goto out;
1.2       jnemeth   349:        }
1.14      christos  350:
1.2       jnemeth   351:        prop_object_iterator_release(propiter);
                    352:        mbr->mbr_sig = htole16(MBR_SIG);
1.10      christos  353:        if (lseek(gpt->fd, 0LL, SEEK_SET) == -1 ||
1.14      christos  354:            write(gpt->fd, mbr, gpt->secsz) != (ssize_t)gpt->secsz) {
                    355:                gpt_warn(gpt, "Unable to seek/write MBR");
1.10      christos  356:                return -1;
1.3       jnemeth   357:        }
1.2       jnemeth   358:
                    359:        propiter = prop_array_iterator(gpt_array);
                    360:        PROP_ERR(propiter);
1.14      christos  361:
1.2       jnemeth   362:        while ((gpt_dict = prop_object_iterator_next(propiter)) != NULL) {
1.14      christos  363:                if (restore_ent(gpt, gpt_dict, secbuf, gpt_size, entries) == -1)
                    364:                        goto out;
1.2       jnemeth   365:        }
                    366:        prop_object_iterator_release(propiter);
1.14      christos  367:
                    368:        size_t len = gpt_size * gpt->secsz;
1.10      christos  369:        if (lseek(gpt->fd, 2 * gpt->secsz, SEEK_SET) == -1 ||
1.14      christos  370:            write(gpt->fd, (char *)secbuf + gpt->secsz, len) != (ssize_t) len) {
                    371:                gpt_warn(gpt, "Unable to write primary GPT");
                    372:                goto out;
1.10      christos  373:        }
1.14      christos  374:
1.10      christos  375:        if (lseek(gpt->fd, (lastdata + 1) * gpt->secsz, SEEK_SET) == -1 ||
1.14      christos  376:            write(gpt->fd, (char *)secbuf + gpt->secsz, len) != (ssize_t) len) {
                    377:                gpt_warn(gpt, "Unable to write secondary GPT");
                    378:                goto out;
1.3       jnemeth   379:        }
1.1       jnemeth   380:
1.10      christos  381:        memset(secbuf, 0, gpt->secsz);
1.14      christos  382:        hdr = secbuf;
1.1       jnemeth   383:        memcpy(hdr->hdr_sig, GPT_HDR_SIG, sizeof(hdr->hdr_sig));
                    384:        hdr->hdr_revision = htole32(GPT_HDR_REVISION);
1.2       jnemeth   385:        hdr->hdr_size = htole32(GPT_HDR_SIZE);
                    386:        hdr->hdr_lba_self = htole64(GPT_HDR_BLKNO);
1.16      christos  387:        hdr->hdr_lba_alt = htole64((uint64_t)last);
                    388:        hdr->hdr_lba_start = htole64((uint64_t)firstdata);
                    389:        hdr->hdr_lba_end = htole64((uint64_t)lastdata);
1.7       jnemeth   390:        gpt_uuid_copy(hdr->hdr_guid, gpt_guid);
1.2       jnemeth   391:        hdr->hdr_lba_table = htole64(2);
                    392:        hdr->hdr_entries = htole32(entries);
1.1       jnemeth   393:        hdr->hdr_entsz = htole32(sizeof(struct gpt_ent));
1.14      christos  394:        hdr->hdr_crc_table = htole32(crc32((char *)secbuf + gpt->secsz, len));
1.2       jnemeth   395:        hdr->hdr_crc_self = htole32(crc32(hdr, GPT_HDR_SIZE));
1.14      christos  396:        if (lseek(gpt->fd, gpt->secsz, SEEK_SET) == -1 ||
                    397:            write(gpt->fd, hdr, gpt->secsz) != (ssize_t)gpt->secsz) {
                    398:                gpt_warn(gpt, "Unable to write primary header");
                    399:                goto out;
1.3       jnemeth   400:        }
                    401:
1.16      christos  402:        hdr->hdr_lba_self = htole64((uint64_t)last);
1.2       jnemeth   403:        hdr->hdr_lba_alt = htole64(GPT_HDR_BLKNO);
1.16      christos  404:        hdr->hdr_lba_table = htole64((uint64_t)(lastdata + 1));
1.2       jnemeth   405:        hdr->hdr_crc_self = 0;
                    406:        hdr->hdr_crc_self = htole32(crc32(hdr, GPT_HDR_SIZE));
1.10      christos  407:        if (lseek(gpt->fd, last * gpt->secsz, SEEK_SET) == -1 ||
1.14      christos  408:            write(gpt->fd, hdr, gpt->secsz) != (ssize_t)gpt->secsz) {
                    409:                gpt_warn(gpt, "Unable to write secondary header");
                    410:                goto out;
1.3       jnemeth   411:        }
1.14      christos  412:        rv = 0;
1.1       jnemeth   413:
1.14      christos  414: out:
                    415:        free(secbuf);
1.3       jnemeth   416:        prop_object_release(props);
1.14      christos  417:        return rv;
1.1       jnemeth   418: }
                    419:
1.11      christos  420: static int
1.10      christos  421: cmd_restore(gpt_t gpt, int argc, char *argv[])
1.1       jnemeth   422: {
1.10      christos  423:        int ch;
1.15      christos  424:        int force = 0;
                    425:        const char *infile = "-";
1.1       jnemeth   426:
1.13      christos  427:        while ((ch = getopt(argc, argv, "Fi:")) != -1) {
1.1       jnemeth   428:                switch(ch) {
1.13      christos  429:                case 'i':
                    430:                        infile = optarg;
                    431:                        break;
1.1       jnemeth   432:                case 'F':
                    433:                        force = 1;
                    434:                        break;
                    435:                default:
1.11      christos  436:                        return usage();
1.1       jnemeth   437:                }
                    438:        }
                    439:
1.10      christos  440:        if (argc != optind)
1.11      christos  441:                return usage();
1.1       jnemeth   442:
1.15      christos  443:        return restore(gpt, infile, force);
1.1       jnemeth   444: }

CVSweb <webmaster@jp.NetBSD.org>