source: mainline/uspace/lib/label/src/dummy.c@ 63e27ef

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 63e27ef was 0ecfc62, checked in by Jiri Svoboda <jiri@…>, 10 years ago

Information structures need updating to new model.

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