source: mainline/uspace/lib/c/generic/io/label.c@ 5e801dc

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

Add volume administration utility.

  • Property mode set to 100644
File size: 2.6 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 libc
30 * @{
31 */
32/** @file Volume service API
33 */
34
35#include <errno.h>
36#include <io/label.h>
37#include <stdlib.h>
38#include <str.h>
39
40/** Format label type as string.
41 *
42 * @param ltype Label type
43 * @param rstr Place to return pointer to newly allocated string
44 * @return EOK on success, ENOMEM if out of memory
45 */
46int label_type_format(label_type_t ltype, char **rstr)
47{
48 const char *sltype;
49 char *s;
50
51 sltype = NULL;
52 switch (ltype) {
53 case lt_none:
54 sltype = "None";
55 break;
56 case lt_mbr:
57 sltype = "MBR";
58 break;
59 case lt_gpt:
60 sltype = "GPT";
61 break;
62 }
63
64 s = str_dup(sltype);
65 if (s == NULL)
66 return ENOMEM;
67
68 *rstr = s;
69 return EOK;
70}
71
72/** Format partition kind as string.
73 *
74 * @param pkind Partition kind
75 * @param rstr Place to return pointer to newly allocated string
76 * @return EOK on success, ENOMEM if out of memory
77 */
78int label_pkind_format(label_pkind_t pkind, char **rstr)
79{
80 const char *spkind;
81 char *s;
82
83 spkind = NULL;
84 switch (pkind) {
85 case lpk_primary:
86 spkind = "Primary";
87 break;
88 case lpk_extended:
89 spkind = "Extended";
90 break;
91 case lpk_logical:
92 spkind = "Logical";
93 break;
94 }
95
96 s = str_dup(spkind);
97 if (s == NULL)
98 return ENOMEM;
99
100 *rstr = s;
101 return EOK;
102}
103
104/** @}
105 */
Note: See TracBrowser for help on using the repository browser.