source: mainline/uspace/lib/label/src/label.c@ 6ff23ff

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 6ff23ff was b7fd2a0, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 7 years ago

Use errno_t in all uspace and kernel code.

Change type of every variable, parameter and return value that holds an
<errno.h> constant to either errno_t (the usual case), or sys_errno_t
(some places in kernel). This is for the purpose of self-documentation,
as well as for type-checking with a bit of type definition hackery.

Although this is a massive commit, it is a simple text replacement, and thus
is very easy to verify. Simply do the following:

`
git checkout <this commit's hash>
git reset HEAD
git add .
tools/srepl '\berrno_t\b' int
git add .
tools/srepl '\bsys_errno_t\b' sysarg_t
git reset
git diff
`

While this doesn't ensure that the replacements are correct, it does ensure
that the commit doesn't do anything except those replacements. Since errno_t
is typedef'd to int in the usual case (and sys_errno_t to sysarg_t), even if
incorrect, this commit cannot change behavior.

  • Property mode set to 100644
File size: 3.4 KB
RevLine 
[1356f85a]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
[78d50bd]36#include <adt/list.h>
[28ed0d9]37#include <errno.h>
[5772aa1]38#include <label/label.h>
[28ed0d9]39#include <mem.h>
40#include <stdlib.h>
41
[372df8f]42#include "dummy.h"
[3faa03d]43#include "gpt.h"
[603c1d1f]44#include "mbr.h"
[28ed0d9]45
[3faa03d]46static label_ops_t *probe_list[] = {
47 &gpt_label_ops,
[603c1d1f]48 &mbr_label_ops,
[372df8f]49 &dummy_label_ops,
[3faa03d]50 NULL
51};
[28ed0d9]52
[b7fd2a0]53errno_t label_open(label_bd_t *bd, label_t **rlabel)
[3faa03d]54{
55 label_ops_t **ops;
[b7fd2a0]56 errno_t rc;
[3faa03d]57
58 ops = &probe_list[0];
59 while (ops[0] != NULL) {
[deacc58d]60 rc = ops[0]->open(bd, rlabel);
[3faa03d]61 if (rc == EOK)
62 return EOK;
63 ++ops;
64 }
65
66 return ENOTSUP;
[28ed0d9]67}
68
[b7fd2a0]69errno_t label_create(label_bd_t *bd, label_type_t ltype, label_t **rlabel)
[28ed0d9]70{
[3faa03d]71 label_ops_t *ops = NULL;
[28ed0d9]72
[3faa03d]73 switch (ltype) {
[372df8f]74 case lt_none:
75 return EINVAL;
[3faa03d]76 case lt_gpt:
77 ops = &gpt_label_ops;
78 break;
79 case lt_mbr:
[603c1d1f]80 ops = &mbr_label_ops;
[3faa03d]81 break;
82 }
[28ed0d9]83
[3faa03d]84 if (ops == NULL)
85 return ENOTSUP;
86
[deacc58d]87 return ops->create(bd, rlabel);
[28ed0d9]88}
89
90void label_close(label_t *label)
91{
[78d50bd]92 if (label == NULL)
93 return;
94
[3faa03d]95 label->ops->close(label);
[28ed0d9]96}
97
[b7fd2a0]98errno_t label_destroy(label_t *label)
[28ed0d9]99{
[3faa03d]100 return label->ops->destroy(label);
[28ed0d9]101}
102
[b7fd2a0]103errno_t label_get_info(label_t *label, label_info_t *linfo)
[28ed0d9]104{
[1626cd4]105 return label->ops->get_info(label, linfo);
[28ed0d9]106}
107
108label_part_t *label_part_first(label_t *label)
109{
[3faa03d]110 return label->ops->part_first(label);
[28ed0d9]111}
112
[78d50bd]113label_part_t *label_part_next(label_part_t *part)
[28ed0d9]114{
[3faa03d]115 return part->label->ops->part_next(part);
[28ed0d9]116}
117
[78d50bd]118void label_part_get_info(label_part_t *part, label_part_info_t *pinfo)
119{
[3faa03d]120 return part->label->ops->part_get_info(part, pinfo);
[78d50bd]121}
[28ed0d9]122
[b7fd2a0]123errno_t label_part_create(label_t *label, label_part_spec_t *pspec,
[28ed0d9]124 label_part_t **rpart)
125{
[3faa03d]126 return label->ops->part_create(label, pspec, rpart);
[28ed0d9]127}
128
[b7fd2a0]129errno_t label_part_destroy(label_part_t *part)
[28ed0d9]130{
[3faa03d]131 return part->label->ops->part_destroy(part);
[28ed0d9]132}
133
134void label_pspec_init(label_part_spec_t *pspec)
135{
136 memset(pspec, 0, sizeof(label_part_spec_t));
137}
138
[b7fd2a0]139errno_t label_suggest_ptype(label_t *label, label_pcnt_t pcnt,
[f57ccb5]140 label_ptype_t *ptype)
141{
142 return label->ops->suggest_ptype(label, pcnt, ptype);
143}
144
[1356f85a]145/** @}
146 */
Note: See TracBrowser for help on using the repository browser.