My favorites
|
Sign in
zumastor
Enterprise Network Storage for Linux
Project Home
Downloads
Wiki
Issues
Source
Checkout
|
Browse
|
Changes
|
r1735
Source path:
svn
/
www
/
ddsetup
/
ddcreate.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <inttypes.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include "ddsetup.h"
int main(int argc, char *argv[])
{
struct ddresult result;
int dd, dm, len, i, mode = DMREAD|DMWRITE;
char text[100], *prog = argv[0], *name = argv[1];
if (argc < 4) {
printf("usage: %s <name> <sectors> <type> args...\n", prog);
return 1;
}
if ((dm = open("/dev/mapper/control", O_RDONLY)) == -1)
goto whoops;
if ((dd = ioctl(dm, DDLINK)) == -1)
goto whoops;
if (ioctl(dd, DMTABLE, &(struct ddtable){ .targets = 1, .mode = mode }) == -1)
goto report;
for (i = 3; i < argc; i++)
if (write(dd, argv[i], strlen(argv[i])) == -1)
goto report;
if (ioctl(dd, DMTARGET, &(struct ddtarget){ .sectors = atoi(argv[2]) }) == -1)
goto report;
if (write(dd, name, strlen(name)) == -1)
goto report;
if (ioctl(dd, DMCREATE) == -1)
goto report;
if ((len = read(dd, &result, sizeof(result))) == -1)
goto report;
if (len != sizeof result && (errno = EINVAL))
goto whoops;
snprintf(text, sizeof(text), "/dev/mapper/%s", name);
if (unlink(text) == -1 && errno != ENOENT)
goto remove;
if (mknod(text, S_IFBLK, makedev(result.dev.major, result.dev.minor)) == -1)
goto remove;
return 0;
report:
if ((len = read(dd, text, sizeof(text))) == -1 || !len)
goto whoops;
printf("%s: %s (%.*s)\n", prog, strerror(errno), len, text);
return 1;
remove:
ioctl(dd, DMREMOVE, name);
whoops:
printf("%s: %s (%i)\n", prog, strerror(errno), errno);
return 1;
}
Show details
Hide details
Change log
r1427
by Daniel.Raymond.Phillips on Mar 04, 2008
Diff
Really add the ddsetup files
Go to:
/www/ddsetup/ddcreate.c
/www/ddsetup/ddsetup-2.6.23.12
/www/ddsetup/ddsetup.c
Project members,
sign in
to write a code review
Older revisions
All revisions of this file
File info
Size: 1596 bytes, 70 lines
View raw file
Hosted by