Merge branch 'master' of git://git.ucc.asn.au/tpg/acess2
[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 int main(int argc, char *argv[])
12 {
13         // Parse arguments
14         for( int i = 1; i < argc; i ++ )
15         {
16                 if( strcmp("mount", argv[i]) == 0 || strcmp("-i", argv[i]) == 0 ) {
17                         // Mount an image
18                         if( argc - i < 3 ) {
19                                 fprintf(stderr, "mount takes 2 arguments (image and mountpoint)\n");
20                                 exit(-1);
21                         }
22
23                         if( DiskTool_MountImage(argv[i+2], argv[i+1]) ) {
24                                 fprintf(stderr, "Unable to mount '%s' as '%s'\n", argv[i+1], argv[i+2]);
25                                 break;
26                         }
27
28                         i += 2;
29                         continue ;
30                 }
31                 
32                 if( strcmp("mountlvm", argv[i]) == 0 || strcmp("lvm", argv[i]) == 0 ) {
33                         
34                         if( argc - i < 3 ) {
35                                 fprintf(stderr, "lvm takes 2 arguments (iamge and ident)\n");
36                                 exit(-1);
37                         }
38
39                         if( DiskTool_RegisterLVM(argv[i+2], argv[i+1]) ) {
40                                 fprintf(stderr, "Unable to register '%s' as LVM '%s'\n", argv[i+1], argv[i+2]);
41                                 break;
42                         }
43                         
44                         i += 2;
45                         continue ;
46                 }
47                 
48                 if( strcmp("ls", argv[i]) == 0 ) {
49                         if( argc - i < 2 ) {
50                                 fprintf(stderr, "ls takes 1 argument (path)\n");
51                                 break;
52                         }
53
54                         DiskTool_ListDirectory(argv[i+1]);
55                         i += 1;
56                         continue ;
57                 }
58                 
59                 if( strcmp("cp", argv[i]) == 0 ) {
60                         
61                         if( argc - i < 3 ) {
62                                 fprintf(stderr, "cp takes 2 arguments (source and destination)\n");
63                                 break;
64                         }
65
66                         DiskTool_Copy(argv[i+1], argv[i+2]);                    
67
68                         i += 2;
69                         continue ;
70                 }
71
72                 if( strcmp("cat", argv[i]) == 0 ) {
73
74                         if( argc - 1 < 2 ) {
75                                 fprintf(stderr, "cat takes 1 argument (path)\n");
76                                 break;
77                         }
78
79                         DiskTool_Cat(argv[i+1]);
80
81                         i += 1;
82                         continue;
83                 }
84         
85                 fprintf(stderr, "Unknown command '%s'\n", argv[i]);
86         }
87         
88         DiskTool_Cleanup();
89         
90         return 0;
91 }
92
93 // NOTE: This is in a native compiled file because it needs access to the real errno macro
94 int *Threads_GetErrno(void)
95 {
96         return &errno;
97 }
98
99 size_t _fwrite_stdout(size_t bytes, const void *data)
100 {
101         return fwrite(data, bytes, 1, stdout);
102 }

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