source: mainline/uspace/lib/label/src/label.c@ 1626cd4

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

Propagate label and partition block ranges and other info up through the stack.

  • Property mode set to 100644
File size: 3.1 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 Disk label library.
34 */
35
36#include <adt/list.h>
37#include <errno.h>
38#include <label.h>
39#include <mem.h>
40#include <stdlib.h>
41
42#include "gpt.h"
43
44static label_ops_t *probe_list[] = {
45 &gpt_label_ops,
46 NULL
47};
48
49int 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;
63}
64
65int label_create(service_id_t sid, label_type_t ltype, label_t **rlabel)
66{
67 label_ops_t *ops = NULL;
68
69 switch (ltype) {
70 case lt_gpt:
71 ops = &gpt_label_ops;
72 break;
73 case lt_mbr:
74 ops = NULL;
75 break;
76 }
77
78 if (ops == NULL)
79 return ENOTSUP;
80
81 return ops->create(sid, rlabel);
82}
83
84void label_close(label_t *label)
85{
86 if (label == NULL)
87 return;
88
89 label->ops->close(label);
90}
91
92int label_destroy(label_t *label)
93{
94 return label->ops->destroy(label);
95}
96
97int label_get_info(label_t *label, label_info_t *linfo)
98{
99 return label->ops->get_info(label, linfo);
100}
101
102label_part_t *label_part_first(label_t *label)
103{
104 return label->ops->part_first(label);
105}
106
107label_part_t *label_part_next(label_part_t *part)
108{
109 return part->label->ops->part_next(part);
110}
111
112void label_part_get_info(label_part_t *part, label_part_info_t *pinfo)
113{
114 return part->label->ops->part_get_info(part, pinfo);
115}
116
117int label_part_create(label_t *label, label_part_spec_t *pspec,
118 label_part_t **rpart)
119{
120 return label->ops->part_create(label, pspec, rpart);
121}
122
123int label_part_destroy(label_part_t *part)
124{
125 return part->label->ops->part_destroy(part);
126}
127
128void label_pspec_init(label_part_spec_t *pspec)
129{
130 memset(pspec, 0, sizeof(label_part_spec_t));
131}
132
133/** @}
134 */
Note: See TracBrowser for help on using the repository browser.