Subversion Repositories freemyipod

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
770 user890104 1
//
2
//
3
//    Copyright 2011 user890104
4
//
5
//
6
//    This file is part of emCORE.
7
//
8
//    emCORE is free software: you can redistribute it and/or
9
//    modify it under the terms of the GNU General Public License as
10
//    published by the Free Software Foundation, either version 2 of the
11
//    License, or (at your option) any later version.
12
//
13
//    emCORE is distributed in the hope that it will be useful,
14
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
//    See the GNU General Public License for more details.
17
//
18
//    You should have received a copy of the GNU General Public License along
19
//    with emCORE.  If not, see <http://www.gnu.org/licenses/>.
20
//
21
//
22
 
23
 
24
#include "global.h"
25
 
26
#include "usb.h"
27
#include "cache.h"
28
#include "emcore.h"
29
#include "fuse.h"
30
#include "util.h"
31
#include "emcorefs.h"
32
 
33
 
34
struct fuse_operations emcorefs_oper =
35
{
36
    .getattr    = emcorefs_getattr,
37
    .opendir    = emcorefs_opendir,
38
    .readdir    = emcorefs_readdir,
39
    .releasedir = emcorefs_releasedir,
40
    .open       = emcorefs_open,
41
    .read       = emcorefs_read,
42
    .release    = emcorefs_release,
43
};
44
 
45
int emcorefs_init(void)
46
{
47
    int res;
48
    uint32_t count;
49
 
50
    res = emcore_file_close_all(&count);
51
 
52
    if (EMCORE_SUCCESS != res)
53
    {
54
        return res;
55
    }
56
 
57
    res = emcore_dir_close_all(&count);
58
 
59
    return res;
60
}
61
 
62
int main(int argc, char* argv[])
63
{
64
    int res, res2;
65
    uint8_t reattach = 0;
66
 
67
    res = usb_init();
68
 
69
    if (LIBUSB_SUCCESS == res)
70
    {
71
        res = usb_find(EMCORE_USB_VID, EMCORE_USB_PID, &reattach);
72
    }
73
 
74
    if (LIBUSB_SUCCESS == res)
75
    {
76
        res = emcorefs_init();
77
    }
78
 
79
    if (EMCORE_SUCCESS == res)
80
    {
81
#ifdef TEST_ONLY
82
        /* gcc complains about unused vars */
83
        (void)(argc);
84
        (void)(argv);
85
 
86
        res = emcore_test();
87
#else
88
        cache_init();
89
 
90
        res = fuse_main(argc, argv, &emcorefs_oper, NULL);
91
 
92
        cache_destroy();
93
#endif
94
    }
95
 
96
    if (EMCORE_SUCCESS != res)
97
    {
98
        print_error(res);
99
    }
100
 
101
    res2 = usb_destroy(reattach);
102
 
103
    if (LIBUSB_SUCCESS != res2)
104
    {
105
        print_error(res2);
106
    }
107
 
108
    if (res < 0)
109
    {
110
        res = -res;
111
    }
112
 
113
    return res;
114
}