source: mainline/uspace/lib/label/src/label.c@ 1b23e33

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

Persistent partition table creation and destruction.

  • 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#include "mbr.h"
44
45static label_ops_t *probe_list[] = {
46 &gpt_label_ops,
47 &mbr_label_ops,
48 NULL
49};
50
51int label_open(service_id_t sid, label_t **rlabel)
52{
53 label_ops_t **ops;
54 int rc;
55
56 ops = &probe_list[0];
57 while (ops[0] != NULL) {
58 rc = ops[0]->open(sid, rlabel);
59 if (rc == EOK)
60 return EOK;
61 ++ops;
62 }
63
64 return ENOTSUP;
65}
66
67int label_create(service_id_t sid, label_type_t ltype, label_t **rlabel)
68{
69 label_ops_t *ops = NULL;
70
71 switch (ltype) {
72 case lt_gpt:
73 ops = &gpt_label_ops;
74 break;
75 case lt_mbr:
76 ops = &mbr_label_ops;
77 break;
78 }
79
80 if (ops == NULL)
81 return ENOTSUP;
82
83 return ops->create(sid, rlabel);
84}
85
86void label_close(label_t *label)
87{
88 if (label == NULL)
89 return;
90
91 label->ops->close(label);
92}
93
94int label_destroy(label_t *label)
95{
96 return label->ops->destroy(label);
97}
98
99int label_get_info(label_t *label, label_info_t *linfo)
100{
101 return label->ops->get_info(label, linfo);
102}
103
104label_part_t *label_part_first(label_t *label)
105{
106 return label->ops->part_first(label);
107}
108
109label_part_t *label_part_next(label_part_t *part)
110{
111 return part->label->ops->part_next(part);
112}
113
114void label_part_get_info(label_part_t *part, label_part_info_t *pinfo)
115{
116 return part->label->ops->part_get_info(part, pinfo);
117}
118
119int label_part_create(label_t *label, label_part_spec_t *pspec,
120 label_part_t **rpart)
121{
122 return label->ops->part_create(label, pspec, rpart);
123}
124
125int label_part_destroy(label_part_t *part)
126{
127 return part->label->ops->part_destroy(part);
128}
129
130void label_pspec_init(label_part_spec_t *pspec)
131{
132 memset(pspec, 0, sizeof(label_part_spec_t));
133}
134
135/** @}
136 */
Note: See TracBrowser for help on using the repository browser.