Tools/udisetup - Switched back to udiprops_end instead of _size
[tpg/acess2.git] / Tools / DiskTool / main.c
1 /*
2  */
3 #include <stdlib.h>
4 #include <stdio.h>
5 #include <errno.h>
6 #include <stdint.h>
7 #include <string.h>
8 #include <disktool_common.h>
9
10 // === CODE ===
11 void PrintUsage(void)
12 {
13         fprintf(stderr,
14                 "Usage:\n"
15                 " disktool <commands...>\n"
16                 "\n"
17                 "Commands:\n"
18                 " lvm <image> <ident>\n"
19                 " - Register an image with LVM\n"
20                 "  e.g.\n"
21                 "   `lvm ../AcessHDD.img HDD`\n"
22                 " mount <image> <mountname>\n"
23                 " - Bind an image to a name.\n"
24                 "  e.g.\n"
25                 "   `mount ../AcessFDD.img FDD`\n"
26                 "   `mount :HDD/0 hda1`\n"
27                 " ls <dir>\n"
28                 " - List a directory\n"
29                 "  e.g.\n"
30                 "   `ls ../`\n"
31                 "   `ls FDD:/`\n"
32                 "\n"
33                 );
34 }
35
36 int main(int argc, char *argv[])
37 {
38         // Parse arguments
39         for( int i = 1; i < argc; i ++ )
40         {
41                 if( strcmp("mount", argv[i]) == 0 || strcmp("-i", argv[i]) == 0 ) {
42                         // Mount an image
43                         if( argc - i < 3 ) {
44                                 fprintf(stderr, "mount takes 2 arguments (image and mountpoint)\n");
45                                 PrintUsage();
46                                 exit(-1);
47                         }
48
49                         if( DiskTool_MountImage(argv[i+2], argv[i+1]) ) {
50                                 fprintf(stderr, "Unable to mount '%s' as '%s'\n", argv[i+1], argv[i+2]);
51                                 break;
52                         }
53
54                         i += 2;
55                         continue ;
56                 }
57                 
58                 if( strcmp("mountlvm", argv[i]) == 0 || strcmp("lvm", argv[i]) == 0 ) {
59                         
60                         if( argc - i < 3 ) {
61                                 fprintf(stderr, "lvm takes 2 arguments (iamge and ident)\n");
62                                 PrintUsage();
63                                 exit(-1);
64                         }
65
66                         if( DiskTool_RegisterLVM(argv[i+2], argv[i+1]) ) {
67                                 fprintf(stderr, "Unable to register '%s' as LVM '%s'\n", argv[i+1], argv[i+2]);
68                                 break;
69                         }
70                         
71                         i += 2;
72                         continue ;
73                 }
74                 
75                 if( strcmp("ls", argv[i]) == 0 ) {
76                         if( argc - i < 2 ) {
77                                 fprintf(stderr, "ls takes 1 argument (path)\n");
78                                 PrintUsage();
79                                 break;
80                         }
81
82                         DiskTool_ListDirectory(argv[i+1]);
83                         i += 1;
84                         continue ;
85                 }
86                 
87                 if( strcmp("cp", argv[i]) == 0 ) {
88                         
89                         if( argc - i < 3 ) {
90                                 fprintf(stderr, "cp takes 2 arguments (source and destination)\n");
91                                 PrintUsage();
92                                 break;
93                         }
94
95                         DiskTool_Copy(argv[i+1], argv[i+2]);                    
96
97                         i += 2;
98                         continue ;
99                 }
100
101                 if( strcmp("cat", argv[i]) == 0 ) {
102
103                         if( argc - 1 < 2 ) {
104                                 fprintf(stderr, "cat takes 1 argument (path)\n");
105                                 PrintUsage();
106                                 break;
107                         }
108
109                         DiskTool_Cat(argv[i+1]);
110
111                         i += 1;
112                         continue;
113                 }
114         
115                 fprintf(stderr, "Unknown command '%s'\n", argv[i]);
116                 PrintUsage();
117         }
118         
119         DiskTool_Cleanup();
120         
121         return 0;
122 }
123
124 // NOTE: This is in a native compiled file because it needs access to the real errno macro
125 int *Threads_GetErrno(void)
126 {
127         return &errno;
128 }
129
130 size_t _fwrite_stdout(size_t bytes, const void *data)
131 {
132         return fwrite(data, bytes, 1, stdout);
133 }

UCC git Repository :: git.ucc.asn.au