[372df8f] | 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 Dummy label (for disks that have no recognized label)
|
---|
| 34 | */
|
---|
| 35 |
|
---|
| 36 | #include <errno.h>
|
---|
| 37 | #include <mem.h>
|
---|
| 38 | #include <stdlib.h>
|
---|
| 39 |
|
---|
| 40 | #include "dummy.h"
|
---|
| 41 |
|
---|
[b7fd2a0] | 42 | static errno_t dummy_open(label_bd_t *, label_t **);
|
---|
| 43 | static errno_t dummy_create(label_bd_t *, label_t **);
|
---|
[372df8f] | 44 | static void dummy_close(label_t *);
|
---|
[b7fd2a0] | 45 | static errno_t dummy_destroy(label_t *);
|
---|
| 46 | static errno_t dummy_get_info(label_t *, label_info_t *);
|
---|
[372df8f] | 47 | static label_part_t *dummy_part_first(label_t *);
|
---|
| 48 | static label_part_t *dummy_part_next(label_part_t *);
|
---|
| 49 | static void dummy_part_get_info(label_part_t *, label_part_info_t *);
|
---|
[b7fd2a0] | 50 | static errno_t dummy_part_create(label_t *, label_part_spec_t *, label_part_t **);
|
---|
| 51 | static errno_t dummy_part_destroy(label_part_t *);
|
---|
| 52 | static errno_t dummy_suggest_ptype(label_t *, label_pcnt_t, label_ptype_t *);
|
---|
[372df8f] | 53 |
|
---|
| 54 | label_ops_t dummy_label_ops = {
|
---|
| 55 | .open = dummy_open,
|
---|
| 56 | .create = dummy_create,
|
---|
| 57 | .close = dummy_close,
|
---|
| 58 | .destroy = dummy_destroy,
|
---|
| 59 | .get_info = dummy_get_info,
|
---|
| 60 | .part_first = dummy_part_first,
|
---|
| 61 | .part_next = dummy_part_next,
|
---|
| 62 | .part_get_info = dummy_part_get_info,
|
---|
| 63 | .part_create = dummy_part_create,
|
---|
| 64 | .part_destroy = dummy_part_destroy,
|
---|
| 65 | .suggest_ptype = dummy_suggest_ptype
|
---|
| 66 | };
|
---|
| 67 |
|
---|
[b7fd2a0] | 68 | static errno_t dummy_open(label_bd_t *bd, label_t **rlabel)
|
---|
[372df8f] | 69 | {
|
---|
| 70 | label_t *label = NULL;
|
---|
| 71 | label_part_t *part = NULL;
|
---|
| 72 | size_t bsize;
|
---|
| 73 | aoff64_t nblocks;
|
---|
| 74 | uint64_t ba_min, ba_max;
|
---|
[b7fd2a0] | 75 | errno_t rc;
|
---|
[372df8f] | 76 |
|
---|
[deacc58d] | 77 | rc = bd->ops->get_bsize(bd->arg, &bsize);
|
---|
[372df8f] | 78 | if (rc != EOK) {
|
---|
| 79 | rc = EIO;
|
---|
| 80 | goto error;
|
---|
| 81 | }
|
---|
| 82 |
|
---|
[deacc58d] | 83 | rc = bd->ops->get_nblocks(bd->arg, &nblocks);
|
---|
[372df8f] | 84 | if (rc != EOK) {
|
---|
| 85 | rc = EIO;
|
---|
| 86 | goto error;
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | label = calloc(1, sizeof(label_t));
|
---|
| 90 | if (label == NULL)
|
---|
| 91 | return ENOMEM;
|
---|
| 92 |
|
---|
| 93 | list_initialize(&label->parts);
|
---|
| 94 | list_initialize(&label->pri_parts);
|
---|
| 95 | list_initialize(&label->log_parts);
|
---|
| 96 |
|
---|
| 97 | ba_min = 0;
|
---|
| 98 | ba_max = nblocks;
|
---|
| 99 |
|
---|
| 100 | label->ops = &dummy_label_ops;
|
---|
| 101 | label->ltype = lt_none;
|
---|
[deacc58d] | 102 | label->bd = *bd;
|
---|
[372df8f] | 103 | label->ablock0 = ba_min;
|
---|
| 104 | label->anblocks = ba_max - ba_min + 1;
|
---|
| 105 | label->pri_entries = 0;
|
---|
| 106 | label->block_size = bsize;
|
---|
| 107 |
|
---|
| 108 | part = calloc(1, sizeof(label_part_t));
|
---|
| 109 | if (part == NULL)
|
---|
| 110 | return ENOMEM;
|
---|
| 111 |
|
---|
| 112 | part->index = 0;
|
---|
| 113 | part->block0 = ba_min;
|
---|
| 114 | part->nblocks = ba_max - ba_min;
|
---|
| 115 | part->ptype.fmt = lptf_num;
|
---|
| 116 |
|
---|
| 117 | part->label = label;
|
---|
| 118 | list_append(&part->lparts, &label->parts);
|
---|
| 119 | list_append(&part->lpri, &label->pri_parts);
|
---|
| 120 |
|
---|
| 121 | *rlabel = label;
|
---|
| 122 | return EOK;
|
---|
| 123 | error:
|
---|
| 124 | free(part);
|
---|
| 125 | free(label);
|
---|
| 126 | return rc;
|
---|
| 127 | }
|
---|
| 128 |
|
---|
[b7fd2a0] | 129 | static errno_t dummy_create(label_bd_t *bd, label_t **rlabel)
|
---|
[372df8f] | 130 | {
|
---|
| 131 | return ENOTSUP;
|
---|
| 132 | }
|
---|
| 133 |
|
---|
| 134 | static void dummy_close(label_t *label)
|
---|
| 135 | {
|
---|
| 136 | label_part_t *part;
|
---|
| 137 |
|
---|
| 138 | part = dummy_part_first(label);
|
---|
| 139 | while (part != NULL) {
|
---|
| 140 | list_remove(&part->lparts);
|
---|
| 141 | list_remove(&part->lpri);
|
---|
| 142 | free(part);
|
---|
| 143 | part = dummy_part_first(label);
|
---|
| 144 | }
|
---|
| 145 |
|
---|
| 146 | free(label);
|
---|
| 147 | }
|
---|
| 148 |
|
---|
[b7fd2a0] | 149 | static errno_t dummy_destroy(label_t *label)
|
---|
[372df8f] | 150 | {
|
---|
| 151 | return ENOTSUP;
|
---|
| 152 | }
|
---|
| 153 |
|
---|
[b7fd2a0] | 154 | static errno_t dummy_get_info(label_t *label, label_info_t *linfo)
|
---|
[372df8f] | 155 | {
|
---|
| 156 | memset(linfo, 0, sizeof(label_info_t));
|
---|
| 157 | linfo->ltype = lt_none;
|
---|
| 158 | linfo->flags = 0;
|
---|
| 159 | linfo->ablock0 = label->ablock0;
|
---|
| 160 | linfo->anblocks = label->anblocks;
|
---|
| 161 | return EOK;
|
---|
| 162 | }
|
---|
| 163 |
|
---|
| 164 | static label_part_t *dummy_part_first(label_t *label)
|
---|
| 165 | {
|
---|
| 166 | link_t *link;
|
---|
| 167 |
|
---|
| 168 | link = list_first(&label->parts);
|
---|
| 169 | if (link == NULL)
|
---|
| 170 | return NULL;
|
---|
| 171 |
|
---|
| 172 | return list_get_instance(link, label_part_t, lparts);
|
---|
| 173 | }
|
---|
| 174 |
|
---|
| 175 | static label_part_t *dummy_part_next(label_part_t *part)
|
---|
| 176 | {
|
---|
| 177 | link_t *link;
|
---|
| 178 |
|
---|
| 179 | link = list_next(&part->lparts, &part->label->parts);
|
---|
| 180 | if (link == NULL)
|
---|
| 181 | return NULL;
|
---|
| 182 |
|
---|
| 183 | return list_get_instance(link, label_part_t, lparts);
|
---|
| 184 | }
|
---|
| 185 |
|
---|
| 186 | static void dummy_part_get_info(label_part_t *part, label_part_info_t *pinfo)
|
---|
| 187 | {
|
---|
| 188 | pinfo->index = part->index;
|
---|
| 189 | pinfo->pkind = lpk_primary;
|
---|
| 190 | pinfo->block0 = part->block0;
|
---|
| 191 | pinfo->nblocks = part->nblocks;
|
---|
| 192 | }
|
---|
| 193 |
|
---|
[b7fd2a0] | 194 | static errno_t dummy_part_create(label_t *label, label_part_spec_t *pspec,
|
---|
[372df8f] | 195 | label_part_t **rpart)
|
---|
| 196 | {
|
---|
| 197 | return ENOTSUP;
|
---|
| 198 | }
|
---|
| 199 |
|
---|
[b7fd2a0] | 200 | static errno_t dummy_part_destroy(label_part_t *part)
|
---|
[372df8f] | 201 | {
|
---|
| 202 | return ENOTSUP;
|
---|
| 203 | }
|
---|
| 204 |
|
---|
[b7fd2a0] | 205 | static errno_t dummy_suggest_ptype(label_t *label, label_pcnt_t pcnt,
|
---|
[372df8f] | 206 | label_ptype_t *ptype)
|
---|
| 207 | {
|
---|
| 208 | return ENOTSUP;
|
---|
| 209 | }
|
---|
| 210 |
|
---|
| 211 | /** @}
|
---|
| 212 | */
|
---|