[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 |
|
---|
| 122 | *rlabel = label;
|
---|
| 123 | return EOK;
|
---|
| 124 | error:
|
---|
| 125 | free(part);
|
---|
| 126 | free(label);
|
---|
| 127 | return rc;
|
---|
| 128 | }
|
---|
| 129 |
|
---|
[b7fd2a0] | 130 | static errno_t dummy_create(label_bd_t *bd, label_t **rlabel)
|
---|
[372df8f] | 131 | {
|
---|
| 132 | return ENOTSUP;
|
---|
| 133 | }
|
---|
| 134 |
|
---|
| 135 | static void dummy_close(label_t *label)
|
---|
| 136 | {
|
---|
| 137 | label_part_t *part;
|
---|
| 138 |
|
---|
| 139 | part = dummy_part_first(label);
|
---|
| 140 | while (part != NULL) {
|
---|
| 141 | list_remove(&part->lparts);
|
---|
| 142 | list_remove(&part->lpri);
|
---|
| 143 | free(part);
|
---|
| 144 | part = dummy_part_first(label);
|
---|
| 145 | }
|
---|
| 146 |
|
---|
| 147 | free(label);
|
---|
| 148 | }
|
---|
| 149 |
|
---|
[b7fd2a0] | 150 | static errno_t dummy_destroy(label_t *label)
|
---|
[372df8f] | 151 | {
|
---|
| 152 | return ENOTSUP;
|
---|
| 153 | }
|
---|
| 154 |
|
---|
[b7fd2a0] | 155 | static errno_t dummy_get_info(label_t *label, label_info_t *linfo)
|
---|
[372df8f] | 156 | {
|
---|
| 157 | memset(linfo, 0, sizeof(label_info_t));
|
---|
| 158 | linfo->ltype = lt_none;
|
---|
| 159 | linfo->flags = 0;
|
---|
| 160 | linfo->ablock0 = label->ablock0;
|
---|
| 161 | linfo->anblocks = label->anblocks;
|
---|
| 162 | return EOK;
|
---|
| 163 | }
|
---|
| 164 |
|
---|
| 165 | static label_part_t *dummy_part_first(label_t *label)
|
---|
| 166 | {
|
---|
| 167 | link_t *link;
|
---|
| 168 |
|
---|
| 169 | link = list_first(&label->parts);
|
---|
| 170 | if (link == NULL)
|
---|
| 171 | return NULL;
|
---|
| 172 |
|
---|
| 173 | return list_get_instance(link, label_part_t, lparts);
|
---|
| 174 | }
|
---|
| 175 |
|
---|
| 176 | static label_part_t *dummy_part_next(label_part_t *part)
|
---|
| 177 | {
|
---|
| 178 | link_t *link;
|
---|
| 179 |
|
---|
| 180 | link = list_next(&part->lparts, &part->label->parts);
|
---|
| 181 | if (link == NULL)
|
---|
| 182 | return NULL;
|
---|
| 183 |
|
---|
| 184 | return list_get_instance(link, label_part_t, lparts);
|
---|
| 185 | }
|
---|
| 186 |
|
---|
| 187 | static void dummy_part_get_info(label_part_t *part, label_part_info_t *pinfo)
|
---|
| 188 | {
|
---|
| 189 | pinfo->index = part->index;
|
---|
| 190 | pinfo->pkind = lpk_primary;
|
---|
| 191 | pinfo->block0 = part->block0;
|
---|
| 192 | pinfo->nblocks = part->nblocks;
|
---|
| 193 | }
|
---|
| 194 |
|
---|
[b7fd2a0] | 195 | static errno_t dummy_part_create(label_t *label, label_part_spec_t *pspec,
|
---|
[372df8f] | 196 | label_part_t **rpart)
|
---|
| 197 | {
|
---|
| 198 | return ENOTSUP;
|
---|
| 199 | }
|
---|
| 200 |
|
---|
[b7fd2a0] | 201 | static errno_t dummy_part_destroy(label_part_t *part)
|
---|
[372df8f] | 202 | {
|
---|
| 203 | return ENOTSUP;
|
---|
| 204 | }
|
---|
| 205 |
|
---|
[b7fd2a0] | 206 | static errno_t dummy_suggest_ptype(label_t *label, label_pcnt_t pcnt,
|
---|
[372df8f] | 207 | label_ptype_t *ptype)
|
---|
| 208 | {
|
---|
| 209 | return ENOTSUP;
|
---|
| 210 | }
|
---|
| 211 |
|
---|
| 212 | /** @}
|
---|
| 213 | */
|
---|