-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
77 lines (70 loc) · 1.78 KB
/
main.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
71
72
73
74
75
76
77
//
// Created by sjw on 2018/2/28.
//
#include "hdtd.h"
int main()
{
hd_context *ctx;
hd_disk *disk;
hd_part *part;
ctx = hd_new_context(NULL);
if (!ctx)
{
fprintf(stderr, "cannot create diskclone context\n");
return 0;
}
/* Register the default disk types to handle. */
hd_try(ctx)
hd_register_disk_handlers(ctx);
hd_catch(ctx)
{
fprintf(stderr, "cannot register disk handlers: %s\n", hd_caught_message(ctx));
hd_drop_context(ctx);
return 0;
}
/* Open the part. */
hd_try(ctx)
disk = hd_open_disk(ctx, "/dev/sdb", "/dev/sdc");
hd_catch(ctx) {
fprintf(stderr, "cannot open disk: %s\n", hd_caught_message(ctx));
hd_drop_context(ctx);
return 0;
}
/* Register the default part types to handle. */
hd_try(ctx)
hd_register_part_handlers(ctx);
hd_catch(ctx)
{
fprintf(stderr, "cannot register part handlers: %s\n", hd_caught_message(ctx));
hd_drop_disk(ctx, disk);
hd_drop_context(ctx);
return 0;
}
/* Open the disk. */
hd_try(ctx)
part = hd_open_part(ctx, disk, "/dev/sdb1");
hd_catch(ctx) {
fprintf(stderr, "cannot open part: %s\n", hd_caught_message(ctx));
hd_drop_disk(ctx, disk);
hd_drop_context(ctx);
return 0;
}
hd_try(ctx)
{
hd_clone_part(ctx, disk, part);
hd_clone_part_info(ctx, disk, part);
}
hd_catch(ctx)
{
fprintf(stderr, "cannot clone part: %s\n", hd_caught_message(ctx));
hd_drop_part(ctx, part);
hd_drop_disk(ctx, disk);
hd_drop_context(ctx);
return 0;
}
hd_drop_part(ctx, part);
hd_drop_disk(ctx, disk);
hd_drop_context(ctx);
printf("main is end\n");
return 0;
}