source: mainline/uspace/srv/volsrv/mkfs.c@ cecba66e

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

ExFAT volume label support.

  • Property mode set to 100644
File size: 3.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 volsrv
30 * @{
31 */
32/**
33 * @file Filesystem creation
34 * @brief
35 */
36
37#include <errno.h>
38#include <io/log.h>
39#include <loc.h>
40#include <stdarg.h>
41#include <stdlib.h>
42#include <str.h>
43#include <str_error.h>
44#include <task.h>
45#include <types/vol.h>
46
47#include "mkfs.h"
48
49static int cmd_runl(const char *path, ...)
50{
51 va_list ap;
52 const char *arg;
53 int cnt = 0;
54
55 va_start(ap, path);
56 do {
57 arg = va_arg(ap, const char *);
58 cnt++;
59 } while (arg != NULL);
60 va_end(ap);
61
62 va_start(ap, path);
63 task_id_t id;
64 task_wait_t wait;
65 int rc = task_spawn(&id, &wait, path, cnt, ap);
66 va_end(ap);
67
68 if (rc != EOK) {
69 log_msg(LOG_DEFAULT, LVL_ERROR, "Error spawning %s (%s)",
70 path, str_error(rc));
71 return rc;
72 }
73
74 if (!id) {
75 log_msg(LOG_DEFAULT, LVL_ERROR, "Error spawning %s "
76 "(invalid task ID)", path);
77 return EINVAL;
78 }
79
80 task_exit_t texit;
81 int retval;
82 rc = task_wait(&wait, &texit, &retval);
83 if (rc != EOK) {
84 log_msg(LOG_DEFAULT, LVL_ERROR, "Error waiting for %s (%s)",
85 path, str_error(rc));
86 return rc;
87 }
88
89 if (texit != TASK_EXIT_NORMAL) {
90 log_msg(LOG_DEFAULT, LVL_ERROR, "Command %s unexpectedly "
91 "terminated", path);
92 return EINVAL;
93 }
94
95 if (retval != 0) {
96 log_msg(LOG_DEFAULT, LVL_ERROR, "Command %s returned non-zero "
97 "exit code %d)", path, retval);
98 }
99
100 return retval;
101}
102
103
104int volsrv_part_mkfs(service_id_t sid, vol_fstype_t fstype, const char *label)
105{
106 const char *cmd;
107 char *svc_name;
108 int rc;
109
110 cmd = NULL;
111 switch (fstype) {
112 case fs_exfat:
113 cmd = "/app/mkexfat";
114 break;
115 case fs_fat:
116 cmd = "/app/mkfat";
117 break;
118 case fs_minix:
119 cmd = "/app/mkmfs";
120 break;
121 case fs_ext4:
122 case fs_cdfs:
123 cmd = NULL;
124 break;
125 }
126
127 if (cmd == NULL)
128 return ENOTSUP;
129
130 rc = loc_service_get_name(sid, &svc_name);
131 if (rc != EOK)
132 return rc;
133
134 if (str_size(label) > 0)
135 rc = cmd_runl(cmd, cmd, "--label", label, svc_name, NULL);
136 else
137 rc = cmd_runl(cmd, cmd, svc_name, NULL);
138
139 free(svc_name);
140 return rc;
141}
142
143void volsrv_part_get_lsupp(vol_fstype_t fstype, vol_label_supp_t *vlsupp)
144{
145 vlsupp->supported = false;
146
147 switch (fstype) {
148 case fs_exfat:
149 case fs_fat:
150 vlsupp->supported = true;
151 break;
152 case fs_minix:
153 case fs_ext4:
154 case fs_cdfs:
155 break;
156 }
157}
158
159/** @}
160 */
Note: See TracBrowser for help on using the repository browser.