d5c75ef300fca35536022e9c9bc7dffb06e0311c
[tpg/acess2.git] / Tools / DiskTool / src / actions.c
1 /*
2  * Acess2 DiskTool
3  * - By John Hodge (thePowersGang)
4  *
5  * actions.c
6  * - High level actions that call the VFS
7  * # Kernel-space compiled
8  */
9 #include <acess.h>
10 #include <disktool_common.h>
11 #include <ctype.h>
12
13 // === PROTOTYPES ===
14 size_t  DiskTool_int_TranslatePath(char *Buffer, const char *Path);
15  int    DiskTool_int_TranslateOpen(const char *File, int Mode);
16
17 // === CODE ===
18 int DiskTool_MountImage(const char *Identifier, const char *Path)
19 {
20         // Validate Identifier and make mountpoint string
21         char mountpoint[sizeof("/Mount/") + strlen(Identifier) + 1];
22         strcpy(mountpoint, "/Mount/");
23         strcat(mountpoint, Identifier);
24         
25         // Translate path       
26         size_t tpath_len = DiskTool_int_TranslatePath(NULL, Path);
27         if(tpath_len == -1)
28                 return -1;
29         char tpath[tpath_len-1];
30         DiskTool_int_TranslatePath(tpath, Path);
31         
32         // Call mount
33         // TODO: Detect filesystem?
34         return VFS_Mount(tpath, mountpoint, "fat", "");
35 }
36
37 int DiskTool_Copy(const char *Source, const char *Destination)
38 {
39         return -1;
40 }
41
42 // --- Internal helpers ---
43 size_t DiskTool_int_TranslatePath(char *Buffer, const char *Path)
44 {
45         const char *colon = strchr(Path, ':');
46         if( colon )
47         {
48                 const char *pos;
49                 for(pos = Path; pos < colon; pos ++)
50                 {
51                         if( !isalpha(*pos) )
52                                 goto native_path;
53                 }
54                 
55                 return -1;
56         }
57         
58 native_path:
59         if( Buffer )
60                 strcpy(Buffer, Path);
61         return strlen(Path);
62 }
63
64 int DiskTool_int_TranslateOpen(const char *File, int Mode)
65 {
66         // Determine if the source is a mounted image or a file on the source FS
67         return -1;
68 }
69

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