Project

General

Profile

Statistics
| Branch: | Revision:

scoutos / prex-0.9.0 / usr / sbin / diskutil / diskutil.c @ 03e9c04a

History | View | Annotate | Download (4.18 KB)

1
/*
2
 * Copyright (c) 2009, Kohsuke Ohtani
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
 * 1. Redistributions of source code must retain the above copyright
9
 *    notice, this list of conditions and the following disclaimer.
10
 * 2. Redistributions in binary form must reproduce the above copyright
11
 *    notice, this list of conditions and the following disclaimer in the
12
 *    documentation and/or other materials provided with the distribution.
13
 * 3. Neither the name of the author nor the names of any co-contributors
14
 *    may be used to endorse or promote products derived from this software
15
 *    without specific prior written permission.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27
 * SUCH DAMAGE.
28
 */
29

    
30
/*
31
 * diskutil.c - disk management utility
32
 *
33
 * Required capabilities:
34
 *      CAP_DISKADMIN
35
 */
36

    
37
#include <sys/prex.h>
38
#include <sys/ioctl.h>
39
#include <ipc/ipc.h>
40

    
41
#include <sys/mount.h>
42
#include <unistd.h>
43
#include <err.h>
44
#include <errno.h>
45
#include <stdlib.h>
46
#include <stdio.h>
47
#include <string.h>
48
#include <signal.h>
49

    
50
static void disk_list(int, char **);
51
static void disk_info(int, char **);
52
static void disk_mount(int, char **);
53
static void disk_unmount(int, char **);
54
static void disk_eject(int, char **);
55
static void disk_rename(int, char **);
56
static void disk_verify(int, char **);
57
static void disk_partition(int, char **);
58
static void disk_help(int, char **);
59
static void disk_null(int, char **);
60

    
61
struct cmdtab {
62
        const char        *cmd;
63
        void                (*func)(int, char **);
64
        const char        *usage;
65
};
66

    
67
static const struct cmdtab cmdtab[] = {
68
        { "list"        ,disk_list        ," list      - List the partitions of a disk.\n" },
69
        { "info"        ,disk_info        ," info      - Display information on a disk or volume.\n" },
70
        { "mount"        ,disk_mount        ," mount     - Mount a single volume.\n" },
71
        { "unmount"        ,disk_unmount        ," unmount   - Unmount a single volume.\n" },
72
        { "eject"        ,disk_eject        ," eject     - Eject a disk.\n" },
73
        { "rename"        ,disk_rename        ," rename    - Rename a volume.\n" },
74
        { "verify"        ,disk_verify        ," verify    - Verify the structure of a volume.\n" },
75
        { "partition"        ,disk_partition        ," partition - Partitiona disk, removing all volume.\n" },
76
        { "-?"                ,disk_help        ," -?        - This help.\n" },
77
        { NULL                ,disk_null        ,NULL },
78
};
79

    
80
static void
81
disk_null(int argc, char **argv)
82
{
83
}
84

    
85
static void
86
disk_help(int argc, char **argv)
87
{
88
        int i = 0;
89

    
90
        fputs("usage: diskutil command\n", stderr);
91
        fputs("commands:\n", stderr);
92
        while (cmdtab[i].cmd != NULL) {
93
                if (cmdtab[i].usage)
94
                        fputs(cmdtab[i].usage, stderr);
95
                i++;
96
        }
97
}
98

    
99
static void
100
disk_list(int argc, char **argv)
101
{
102
}
103

    
104
static void
105
disk_info(int argc, char **argv)
106
{
107
}
108

    
109
static void
110
disk_mount(int argc, char **argv)
111
{
112

    
113
        if (argc != 6) {
114
                fputs("usage: diskutil mount -t vfstype device dir\n", stderr);
115
                exit(1);
116
        }
117
        if (mount(argv[4], argv[5], argv[3], 0, NULL) < 0) {
118
                perror("mount");
119
                exit(1);
120
        }
121
}
122

    
123
static void
124
disk_unmount(int argc, char **argv)
125
{
126
}
127

    
128
static void
129
disk_eject(int argc, char **argv)
130
{
131
}
132

    
133
static void
134
disk_rename(int argc, char **argv)
135
{
136
}
137

    
138
static void
139
disk_verify(int argc, char **argv)
140
{
141
}
142

    
143
static void
144
disk_partition(int argc, char **argv)
145
{
146
}
147

    
148
int
149
main(int argc, char *argv[])
150
{
151
        int i = 0;
152
        int found = 0;
153

    
154
        if (argc < 2) {
155
                disk_help(1, NULL);
156
                exit(1);
157
        }
158

    
159
        while (cmdtab[i].cmd != NULL) {
160
                if (!strncmp(argv[1], cmdtab[i].cmd, LINE_MAX)) {
161
                        (cmdtab[i].func)(argc, argv);
162
                        found = 1;
163
                        break;
164
                }
165
                i++;
166
        }
167
        if (!found)
168
                disk_help(1, NULL);
169
        exit(1);
170
}