DiskTool - Compiling again, now with modules
[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 // === IMPORTS ===
14 extern int      NativeFS_Install(char **Arguments);
15
16 // === PROTOTYPES ===
17 void    DiskTool_Initialise(void)       __attribute__((constructor(101)));
18 size_t  DiskTool_int_TranslatePath(char *Buffer, const char *Path);
19  int    DiskTool_int_TranslateOpen(const char *File, int Mode);
20
21 // === CODE ===
22 void DiskTool_Initialise(void)
23 {
24         VFS_Init();
25         NativeFS_Install(NULL);
26         VFS_MkDir("/Native");
27         VFS_Mount("/", "/Native", "nativefs", "");
28 }
29
30 int DiskTool_MountImage(const char *Identifier, const char *Path)
31 {
32         // Validate Identifier and make mountpoint string
33         char mountpoint[sizeof("/Mount/") + strlen(Identifier) + 1];
34         strcpy(mountpoint, "/Mount/");
35         strcat(mountpoint, Identifier);
36         
37         // Translate path       
38         size_t tpath_len = DiskTool_int_TranslatePath(NULL, Path);
39         if(tpath_len == -1)
40                 return -1;
41         char tpath[tpath_len-1];
42         DiskTool_int_TranslatePath(tpath, Path);
43         
44         // Call mount
45         // TODO: Detect filesystem?
46         return VFS_Mount(tpath, mountpoint, "fat", "");
47 }
48
49 int DiskTool_Copy(const char *Source, const char *Destination)
50 {
51         return -1;
52 }
53
54 // --- Internal helpers ---
55 size_t DiskTool_int_TranslatePath(char *Buffer, const char *Path)
56 {
57         const char *colon = strchr(Path, ':');
58         if( colon )
59         {
60                 const char *pos;
61                 for(pos = Path; pos < colon; pos ++)
62                 {
63                         if( !isalpha(*pos) )
64                                 goto native_path;
65                 }
66                 
67                 return -1;
68         }
69         
70 native_path: {
71          int    len = strlen("/Native");
72         len += strlen( getenv("PWD") ) + 1;
73         len += strlen(Path);
74         if( Buffer ) {
75                 strcpy(Buffer, "/Native");
76                 strcat(Buffer, getenv("PWD"));
77                 strcat(Buffer, "/");
78                 strcat(Buffer, Path);
79         }
80         return len;
81         }
82 }
83
84 int DiskTool_int_TranslateOpen(const char *File, int Mode)
85 {
86         // Determine if the source is a mounted image or a file on the source FS
87         return -1;
88 }
89

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