]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/ocaml/ocaml_toys/ext2_example/src/main.cc
Update
[l4.git] / l4 / pkg / ocaml / ocaml_toys / ext2_example / src / main.cc
1 /*
2  * (c) 2008-2009 Technische Universität Dresden
3  * This file is part of TUD:OS and distributed under the terms of the
4  * GNU General Public License 2.
5  * Please see the COPYING-GPL-2 file for details.
6  */
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <l4/ocaml/ext2.h>
10
11 int main(int argc, char** argv)
12 {
13         if (argc != 3) {
14                 fprintf (stderr,"usage: ext2_example <disk_image_name> <path_to_file>\n");
15                 return -1;
16         }
17
18         if (!open_disk_image (argv[1])) {
19                 fprintf (stderr,"open_disk_image '%s' failed\n",argv[1]);
20                 return -1;
21         }
22
23         int fd = open_file (argv[2]);
24         if (!fd) {
25                 fprintf (stderr,"open_file '%s' failed\n",argv[2]);
26                 return -1;
27         }
28
29         char* buffer = (char*)malloc(2<<12);
30         if (!buffer) {
31                 fprintf (stderr,"malloc(4k) failed\n");
32                 return -1;
33         }
34
35         if (!read_block (fd, 0, buffer)) {
36                 fprintf (stderr,"read_block failed\n");
37                 return -1;
38         }
39
40         printf ("dumping file '%s'\n",argv[2]);
41
42         // --- debug ---
43         for (int i=0; i<64; i++) {
44                 if (i%16 == 0)
45                         printf ("0x%04x : ",i);
46
47                 printf ("%02x ",buffer[i]);
48
49                 if (i%16 == 15)
50                         printf ("\n");
51         }
52
53         printf ("%s",buffer);
54
55         printf ("opening dir /\n");
56
57         unsigned dir = opendir("/");
58
59         if (!dir) {
60                 fprintf (stderr,"opendir / failed\n");
61                 return -1;
62         }
63
64         do {
65                 if (is_file (dir))
66                         printf ("File");
67                 else 
68                         printf ("Dir");
69
70                 printf (" '%s'\n",filename(dir));
71         } while (dir = readdir (dir));
72
73         return 0;
74 }