Merge branch 'master' of ssh://Aleaxander@repo.or.cz/srv/git/fstk
[fstk.git] / fstk.c
blob2300f40f55cfd064e22df06c09946e63c072921c
1 /*
2 * The main file in fstk project
4 * Copyright (C) 2009 Liu Aleaxander -- All rights reserved. This file
5 * may be redistributed under the terms of the GNU Public License.
6 */
8 #include <stdio.h>
9 #include <string.h>
10 #include <stdlib.h>
11 #include <sys/stat.h>
12 #include <fcntl.h>
13 #include <unistd.h>
14 #include "version.h"
15 #include "fstk.h"
16 #include "fs.h"
17 #include "file.h"
18 #include "fstklib.h"
19 #include "fstk_malloc.h"
20 #include "cache.h"
21 #include "command.h"
24 static void usage(void)
26 printf("USAGE: fstk -t fs_type fs.img\n");
27 printf("OR fstk fs.img, fstk will recognise it correct for you\n");
28 exit(0);
32 * Initialize the envrionments used by fstk, like this_dentry...
34 void init_fstk_env(struct fstk *fs)
36 set_current_dentry(fs);
39 void free_fstk_env(void)
41 free_current_dentry();
44 int main(int argc, char *argv[])
47 struct fstk *fs;
48 char *fs_type;
49 char *fs_img;
50 int res;
52 mount_again:
53 fs_img = argv[1]; /* guess it first */
54 if (argc == 2)
55 fs_type = guess_fs(fs_img);
56 else if (argc == 4 && !strcmp(argv[1], "-t")) {
57 fs_type = argv[2];
58 fs_img = argv[3];
59 } else
60 usage();
62 if (fs_type == NULL)
63 usage();
65 /* Init fstk memory fisrt */
66 fstk_init_mem();
67 fs = init_fs(fs_type);
68 if (!fs) {
69 printf("Please input the correct file system type.\n");
70 printf("we currently suport EXT2/3/4 file systems\n\n");
71 usage();
73 if (fstk_mount(fs, fs_img)) {
74 printf("mount error, "
75 "maybe you haven't input the correct fs type\n");
76 usage();
78 /* Init the cache */
79 init_cache(fs);
81 /* Init the Environment used by fstk */
82 init_fstk_env(fs);
84 /* we all count on it */
85 res = fstk_shell("fstk:> ", fs);
86 if (res == MOUNT_AGAIN)
87 goto mount_again;
89 free_fstk_env();
90 fstk_unmount(fs);
91 check_mem(); /* for debug use to check how much memory we lose */
92 return 0;