[1356f85a] | 1 | /*
|
---|
| 2 | * Copyright (c) 2015 Jiri Svoboda
|
---|
| 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 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - 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 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | /** @addtogroup liblabel
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /**
|
---|
| 33 | * @file Disk label library.
|
---|
| 34 | */
|
---|
| 35 |
|
---|
[78d50bd] | 36 | #include <adt/list.h>
|
---|
[28ed0d9] | 37 | #include <errno.h>
|
---|
| 38 | #include <label.h>
|
---|
| 39 | #include <mem.h>
|
---|
| 40 | #include <stdlib.h>
|
---|
| 41 |
|
---|
[3faa03d] | 42 | #include "gpt.h"
|
---|
[28ed0d9] | 43 |
|
---|
[3faa03d] | 44 | static label_ops_t *probe_list[] = {
|
---|
| 45 | &gpt_label_ops,
|
---|
| 46 | NULL
|
---|
| 47 | };
|
---|
[28ed0d9] | 48 |
|
---|
[3faa03d] | 49 | int label_open(service_id_t sid, label_t **rlabel)
|
---|
| 50 | {
|
---|
| 51 | label_ops_t **ops;
|
---|
| 52 | int rc;
|
---|
| 53 |
|
---|
| 54 | ops = &probe_list[0];
|
---|
| 55 | while (ops[0] != NULL) {
|
---|
| 56 | rc = ops[0]->open(sid, rlabel);
|
---|
| 57 | if (rc == EOK)
|
---|
| 58 | return EOK;
|
---|
| 59 | ++ops;
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | return ENOTSUP;
|
---|
[28ed0d9] | 63 | }
|
---|
| 64 |
|
---|
| 65 | int label_create(service_id_t sid, label_type_t ltype, label_t **rlabel)
|
---|
| 66 | {
|
---|
[3faa03d] | 67 | label_ops_t *ops = NULL;
|
---|
[28ed0d9] | 68 |
|
---|
[3faa03d] | 69 | switch (ltype) {
|
---|
| 70 | case lt_gpt:
|
---|
| 71 | ops = &gpt_label_ops;
|
---|
| 72 | break;
|
---|
| 73 | case lt_mbr:
|
---|
| 74 | ops = NULL;
|
---|
| 75 | break;
|
---|
| 76 | }
|
---|
[28ed0d9] | 77 |
|
---|
[3faa03d] | 78 | if (ops == NULL)
|
---|
| 79 | return ENOTSUP;
|
---|
| 80 |
|
---|
| 81 | return ops->create(sid, rlabel);
|
---|
[28ed0d9] | 82 | }
|
---|
| 83 |
|
---|
| 84 | void label_close(label_t *label)
|
---|
| 85 | {
|
---|
[78d50bd] | 86 | if (label == NULL)
|
---|
| 87 | return;
|
---|
| 88 |
|
---|
[3faa03d] | 89 | label->ops->close(label);
|
---|
[28ed0d9] | 90 | }
|
---|
| 91 |
|
---|
| 92 | int label_destroy(label_t *label)
|
---|
| 93 | {
|
---|
[3faa03d] | 94 | return label->ops->destroy(label);
|
---|
[28ed0d9] | 95 | }
|
---|
| 96 |
|
---|
| 97 | int label_get_info(label_t *label, label_info_t *linfo)
|
---|
| 98 | {
|
---|
| 99 | memset(linfo, 0, sizeof(label_info_t));
|
---|
[3faa03d] | 100 | linfo->dcnt = dc_label;
|
---|
| 101 | linfo->ltype = label->ltype;
|
---|
[28ed0d9] | 102 | return EOK;
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | label_part_t *label_part_first(label_t *label)
|
---|
| 106 | {
|
---|
[3faa03d] | 107 | return label->ops->part_first(label);
|
---|
[28ed0d9] | 108 | }
|
---|
| 109 |
|
---|
[78d50bd] | 110 | label_part_t *label_part_next(label_part_t *part)
|
---|
[28ed0d9] | 111 | {
|
---|
[3faa03d] | 112 | return part->label->ops->part_next(part);
|
---|
[28ed0d9] | 113 | }
|
---|
| 114 |
|
---|
[78d50bd] | 115 | void label_part_get_info(label_part_t *part, label_part_info_t *pinfo)
|
---|
| 116 | {
|
---|
[3faa03d] | 117 | return part->label->ops->part_get_info(part, pinfo);
|
---|
[78d50bd] | 118 | }
|
---|
[28ed0d9] | 119 |
|
---|
| 120 | int label_part_create(label_t *label, label_part_spec_t *pspec,
|
---|
| 121 | label_part_t **rpart)
|
---|
| 122 | {
|
---|
[3faa03d] | 123 | return label->ops->part_create(label, pspec, rpart);
|
---|
[28ed0d9] | 124 | }
|
---|
| 125 |
|
---|
| 126 | int label_part_destroy(label_part_t *part)
|
---|
| 127 | {
|
---|
[3faa03d] | 128 | return part->label->ops->part_destroy(part);
|
---|
[28ed0d9] | 129 | }
|
---|
| 130 |
|
---|
| 131 | void label_pspec_init(label_part_spec_t *pspec)
|
---|
| 132 | {
|
---|
| 133 | memset(pspec, 0, sizeof(label_part_spec_t));
|
---|
| 134 | }
|
---|
| 135 |
|
---|
[1356f85a] | 136 | /** @}
|
---|
| 137 | */
|
---|