Subversion Repositories freemyipod

Rev

Rev 785 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 785 Rev 898
Line 1... Line 1...
1
//
1
//
2
//
2
//
3
//    Copyright 2011 user890104
3
//    Copyright 2013 user890104
4
//
4
//
5
//
5
//
6
//    This file is part of emCORE.
6
//    This file is part of emCORE.
7
//
7
//
8
//    emCORE is free software: you can redistribute it and/or
8
//    emCORE is free software: you can redistribute it and/or
Line 18... Line 18...
18
//    You should have received a copy of the GNU General Public License along
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/>.
19
//    with emCORE.  If not, see <http://www.gnu.org/licenses/>.
20
//
20
//
21
//
21
//
22
 
22
 
23
 
-
 
24
#include "global.h"
23
#include "global.h"
25
 
24
 
26
#include "fuse.h"
25
#include "fuse.h"
27
#include "util.h"
26
#include "util.h"
28
#include "cache.h"
27
#include "cache.h"
29
#include "emcore.h"
28
#include "emcore.h"
30
 
29
 
31
 
-
 
32
int emcorefs_init(void)
30
int32_t emcorefs_init(void) {
33
{
-
 
34
    int res;
31
    int32_t res;
35
    uint32_t count;
32
    uint32_t count;
36
 
33
 
37
    res = emcore_file_close_all(&count);
34
    res = emcore_file_close_all(&count);
38
 
35
 
39
    if (EMCORE_SUCCESS != res)
36
    if (res != EMCORE_SUCCESS) {
40
    {
-
 
41
        return res;
37
        return res;
42
    }
38
    }
43
 
39
 
44
    res = emcore_dir_close_all(&count);
40
    res = emcore_dir_close_all(&count);
45
 
41
 
46
    return res;
42
    return res;
47
}
43
}
48
 
44
 
49
int emcorefs_getattr(const char* path, struct stat* stbuf)
45
int32_t emcorefs_getattr(const char *path, struct stat *stbuf) {
50
{
-
 
51
    int res = 0;
46
    int32_t res = 0;
52
    struct emcore_dir_entry *entry = NULL, curr_entry;
47
    struct emcore_dir_entry *entry = NULL, curr_entry;
53
    uint32_t dir_handle;
48
    uint32_t dir_handle;
54
    char *parent, *filename;
49
    char *parent, *filename;
55
 
50
 
56
    memset(stbuf, 0, sizeof(*stbuf));
51
    memset(stbuf, 0, sizeof(*stbuf));
57
 
52
 
58
#ifdef DEBUG2
53
#ifdef DEBUG2
59
    if (0 == strcmp(path, "/__cache_dump"))
54
    if (strcmp(path, "/__cache_dump") == 0) {
60
    {
-
 
61
        cache_dump();
55
        cache_dump();
62
    }
56
    }
63
#endif
57
#endif
64
    entry = cache_get(path);
58
    entry = cache_get(path);
65
 
59
 
66
    if (NULL == entry)
60
    if (!entry) {
67
    {
-
 
68
        parent = strdup(path);
61
        parent = strdup(path);
69
        dirname(parent);
62
        dirname(parent);
70
        filename = basename((char*)path);
63
        filename = basename((char *) path);
71
 
64
 
72
        res = emcore_dir_open(&dir_handle, parent);
65
        res = emcore_dir_open(&dir_handle, parent);
73
 
66
 
74
        if (EMCORE_SUCCESS == res)
67
        if (res == EMCORE_SUCCESS) {
75
        {
-
 
76
            while (1)
68
            while (1) {
77
            {
-
 
78
                res = emcore_dir_read(&curr_entry, dir_handle);
69
                res = emcore_dir_read(&curr_entry, dir_handle);
79
 
70
 
80
                if (EMCORE_ERROR_NO_MORE_ENTRIES == res)
71
                if (res == EMCORE_ERROR_NO_MORE_ENTRIES) {
81
                {
-
 
82
                    break;
72
                    break;
83
                }
73
                }
84
 
74
 
85
                if (EMCORE_SUCCESS != res)
75
                if (res != EMCORE_SUCCESS) {
86
                {
-
 
87
                    break;
76
                    break;
88
                }
77
                }
89
                
78
                
90
                cache_insert(parent, &curr_entry);
79
                cache_insert(parent, &curr_entry);
91
 
80
 
92
                if (0 == strcmp(filename, curr_entry.name))
81
                if (strcmp(filename, curr_entry.name) == 0) {
93
                {
-
 
94
                    entry = malloc(sizeof(*entry));
82
                    entry = malloc(sizeof(*entry));
95
 
83
 
96
                    memcpy(entry, &curr_entry, sizeof(curr_entry));
84
                    memcpy(entry, &curr_entry, sizeof(curr_entry));
97
 
85
 
98
                    break;
86
                    break;
Line 103... Line 91...
103
        }
91
        }
104
 
92
 
105
        free(parent);
93
        free(parent);
106
    }
94
    }
107
 
95
 
108
    if (NULL == entry) {
96
    if (!entry) {
109
        if (EMCORE_ERROR_NO_MORE_ENTRIES == res)
97
        if (res == EMCORE_ERROR_NO_MORE_ENTRIES) {
110
        {
-
 
111
            return -ENOENT;
98
            return -ENOENT;
112
        }
99
        }
113
 
100
 
114
        return -EIO;
101
        return -EIO;
115
    }
102
    }
116
    else
103
    else {
117
    {
-
 
118
        stbuf->st_uid = getuid();
104
        stbuf->st_uid = getuid();
119
        stbuf->st_gid = getgid();
105
        stbuf->st_gid = getgid();
120
        stbuf->st_mtime = fat_time_to_unix_ts(entry->wrttime, entry->wrtdate);
106
        stbuf->st_mtime = fat_time_to_unix_ts(entry->wrttime, entry->wrtdate);
121
 
107
 
122
        if (entry->attributes & 0x10)
108
        if (entry->attributes & 0x10) {
123
        {
-
 
124
            stbuf->st_mode = S_IFDIR | 0755;
109
            stbuf->st_mode = S_IFDIR | 0755;
125
            stbuf->st_nlink = 2;
110
            stbuf->st_nlink = 2;
126
            stbuf->st_size = 0x1000;
111
            stbuf->st_size = 0x1000;
127
        }
112
        }
128
        else
113
        else {
129
        {
-
 
130
            stbuf->st_mode = S_IFREG | 0644;
114
            stbuf->st_mode = S_IFREG | 0644;
131
            stbuf->st_nlink = 1;
115
            stbuf->st_nlink = 1;
132
            stbuf->st_size = entry->size;
116
            stbuf->st_size = entry->size;
133
        }
117
        }
134
    }
118
    }
135
 
119
 
136
    return 0;
120
    return 0;
137
}
121
}
138
 
122
 
139
int emcorefs_opendir(const char* path, struct fuse_file_info* fi)
123
int32_t emcorefs_opendir(const char *path, struct fuse_file_info *fi) {
140
{
-
 
141
    int res;
124
    int32_t res;
142
    uint32_t handle;
125
    uint32_t handle;
143
 
126
 
144
    res = emcore_dir_open(&handle, path);
127
    res = emcore_dir_open(&handle, path);
145
 
128
 
146
    if (EMCORE_SUCCESS != res)
129
    if (res != EMCORE_SUCCESS) {
147
    {
-
 
148
        return -EIO;
130
        return -EIO;
149
    }
131
    }
150
    
132
    
151
    fi->fh = handle;
133
    fi->fh = handle;
152
 
134
 
153
    return 0;
135
    return 0;
154
}
136
}
155
 
137
 
156
int emcorefs_readdir(const char* path, void* buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info* fi)
138
int32_t emcorefs_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi) {
157
{
-
 
158
    int res;
139
    int32_t res;
159
    struct emcore_dir_entry entry;
140
    struct emcore_dir_entry entry;
160
    (void) offset;
141
    (void) offset;
161
    (void) fi;
142
    (void) fi;
162
 
143
 
163
    if (strcmp(path, "/") == 0)
144
    if (strcmp(path, "/") == 0) {
164
    {
-
 
165
        filler(buf, ".", NULL, 0);
145
        filler(buf, ".", NULL, 0);
166
        filler(buf, "..", NULL, 0);
146
        filler(buf, "..", NULL, 0);
167
    }
147
    }
168
 
148
 
169
    while (1)
149
    while (1) {
170
    {
-
 
171
        res = emcore_dir_read(&entry, fi->fh);
150
        res = emcore_dir_read(&entry, fi->fh);
172
 
151
 
173
        if (EMCORE_ERROR_NO_MORE_ENTRIES == res)
152
        if (res == EMCORE_ERROR_NO_MORE_ENTRIES) {
174
        {
-
 
175
            break;
153
            break;
176
        }
154
        }
177
 
155
 
178
        if (EMCORE_SUCCESS != res)
156
        if (res != EMCORE_SUCCESS) {
179
        {
-
 
180
            return -EIO;
157
            return -EIO;
181
        }
158
        }
182
 
159
 
183
        cache_insert(path, &entry);
160
        cache_insert(path, &entry);
184
 
161
 
Line 186... Line 163...
186
    }
163
    }
187
 
164
 
188
    return 0;
165
    return 0;
189
}
166
}
190
 
167
 
191
int emcorefs_releasedir(const char* path, struct fuse_file_info* fi)
168
int32_t emcorefs_releasedir(const char *path, struct fuse_file_info *fi) {
192
{
-
 
193
    int res;
169
    int32_t res;
194
    uint32_t emcore_errno_value;
170
    uint32_t emcore_errno_value;
195
    (void)path;
171
    (void)path;
196
 
172
 
197
    res = emcore_dir_close(fi->fh);
173
    res = emcore_dir_close(fi->fh);
198
 
174
 
199
    if (EMCORE_ERROR_IO == res)
175
    if (res == EMCORE_ERROR_IO) {
200
    {
-
 
201
        res = emcore_errno(&emcore_errno_value);
176
        res = emcore_errno(&emcore_errno_value);
202
 
177
 
203
        if (EMCORE_SUCCESS != res)
178
        if (res != EMCORE_SUCCESS) {
204
        {
-
 
205
            return -EIO;
179
            return -EIO;
206
        }
180
        }
207
 
181
 
208
        if (EMCORE_SUCCESS != emcore_errno_value)
182
        if (emcore_errno_value == EMCORE_SUCCESS) {
209
        {
-
 
210
            return -emcore_errno_value;
183
            return -emcore_errno_value;
211
        }
184
        }
212
    }
185
    }
213
    
186
    
214
    if (EMCORE_SUCCESS != res)
187
    if (res != EMCORE_SUCCESS) {
215
    {
-
 
216
        return -EIO;
188
        return -EIO;
217
    }
189
    }
218
    
190
    
219
    return 0;
191
    return 0;
220
}
192
}
221
 
193
 
222
int emcorefs_open(const char* path, struct fuse_file_info* fi)
194
int32_t emcorefs_open(const char *path, struct fuse_file_info *fi) {
223
{
-
 
224
    int res;
195
    int32_t res;
225
    uint32_t handle, emcore_errno_value;
196
    uint32_t handle, emcore_errno_value;
226
    
197
    
227
#ifdef DEBUG
198
#ifdef DEBUG
228
    fprintf(stderr, "FILE OPEN: [%s], 0x%08x\n", path, fi->flags);
199
    fprintf(stderr, "FILE OPEN: [%s], 0x%08x\n", path, fi->flags);
229
#endif
200
#endif
230
    
201
    
231
    res = emcore_file_open(&handle, path, fi->flags);
202
    res = emcore_file_open(&handle, path, fi->flags);
232
    
203
    
233
    if (EMCORE_ERROR_IO == res)
204
    if (res == EMCORE_ERROR_IO) {
234
    {
-
 
235
        res = emcore_errno(&emcore_errno_value);
205
        res = emcore_errno(&emcore_errno_value);
236
 
206
 
237
        if (EMCORE_SUCCESS != res)
207
        if (res != EMCORE_SUCCESS) {
238
        {
-
 
239
            return -EIO;
208
            return -EIO;
240
        }
209
        }
241
 
210
 
242
        if (EMCORE_SUCCESS != emcore_errno_value)
211
        if (emcore_errno_value != EMCORE_SUCCESS) {
243
        {
-
 
244
            return -emcore_errno_value;
212
            return -emcore_errno_value;
245
        }
213
        }
246
    }
214
    }
247
    
215
    
248
    if (EMCORE_SUCCESS != res)
216
    if (res != EMCORE_SUCCESS) {
249
    {
-
 
250
        return -EIO;
217
        return -EIO;
251
    }
218
    }
252
    
219
    
253
    fi->fh = handle;
220
    fi->fh = handle;
254
    
221
    
255
    return 0;
222
    return 0;
256
}
223
}
257
 
224
 
258
int emcorefs_read(const char* path, char* buf, size_t size, off_t offset, struct fuse_file_info* fi) {
225
int32_t emcorefs_read(const char *path, char *buf, size_t size, off_t offset, struct fuse_file_info *fi) {
259
#ifdef DEBUG2
226
#ifdef DEBUG2
260
    fprintf(stderr, "FUSE_READ: path=[%s] size=[%d] offset=[%jd] fi->flags=[%d]\n", path, size, offset, fi->flags);
227
    fprintf(stderr, "FUSE_READ: path=[%s] size=[%d] offset=[%jd] fi->flags=[%d]\n", path, size, offset, fi->flags);
261
#else
228
#else
262
    (void)path;
229
    (void)path;
263
#endif
230
#endif
264
    int res;
231
    int32_t res;
265
    uint32_t emcore_errno_value, addr, nread = size;
232
    uint32_t emcore_errno_value, addr, nread = size;
266
 
233
 
267
    if (!fi->fh)
234
    if (!fi->fh) {
268
    {
-
 
269
        return -EIO;
235
        return -EIO;
270
    }
236
    }
271
    
237
    
272
    res = emcore_malloc(&addr, size);
238
    res = emcore_malloc(&addr, size);
273
    
239
    
274
    if (EMCORE_SUCCESS != res)
240
    if (res != EMCORE_SUCCESS) {
275
    {
-
 
276
        return -EIO;
241
        return -EIO;
277
    }
242
    }
278
    
243
    
279
    do {
244
    do {
280
        if (offset) {
245
        if (offset) {
281
            res = emcore_file_seek(fi->fh, offset, SEEK_SET);
246
            res = emcore_file_seek(fi->fh, offset, SEEK_SET);
282
            
247
            
283
            if (EMCORE_ERROR_IO == res)
248
            if (res == EMCORE_ERROR_IO) {
284
            {
-
 
285
                res = emcore_errno(&emcore_errno_value);
249
                res = emcore_errno(&emcore_errno_value);
286
 
250
 
287
                if (EMCORE_SUCCESS != res)
251
                if (res != EMCORE_SUCCESS) {
288
                {
-
 
289
                    nread = -EIO;
252
                    nread = -EIO;
290
                    break;
253
                    break;
291
                }
254
                }
292
 
255
 
293
                if (EMCORE_SUCCESS != emcore_errno_value)
256
                if (emcore_errno_value != EMCORE_SUCCESS) {
294
                {
-
 
295
                    nread = -emcore_errno_value;
257
                    nread = -emcore_errno_value;
296
                    break;
258
                    break;
297
                }
259
                }
298
            }
260
            }
299
        
261
        
300
            if (EMCORE_SUCCESS != res)
262
            if (res != EMCORE_SUCCESS) {
301
            {
-
 
302
                nread = -EIO;
263
                nread = -EIO;
303
                break;
264
                break;
304
            }
265
            }
305
        }
266
        }
306
        
267
        
307
        res = emcore_file_read(&nread, fi->fh, addr, size);
268
        res = emcore_file_read(&nread, fi->fh, addr, size);
308
        
269
        
309
        if (EMCORE_ERROR_IO == res)
270
        if (res == EMCORE_ERROR_IO) {
310
        {
-
 
311
            res = emcore_errno(&emcore_errno_value);
271
            res = emcore_errno(&emcore_errno_value);
312
 
272
 
313
            if (EMCORE_SUCCESS != res)
273
            if (res != EMCORE_SUCCESS) {
314
            {
-
 
315
                nread = -EIO;
274
                nread = -EIO;
316
                break;
275
                break;
317
            }
276
            }
318
 
277
 
319
            if (EMCORE_SUCCESS != emcore_errno_value)
278
            if (emcore_errno_value != EMCORE_SUCCESS) {
320
            {
-
 
321
                nread = -emcore_errno_value;
279
                nread = -emcore_errno_value;
322
                break;
280
                break;
323
            }
281
            }
324
        }
282
        }
325
    
283
    
326
        if (EMCORE_SUCCESS != res)
284
        if (res != EMCORE_SUCCESS) {
327
        {
-
 
328
            nread = -EIO;
285
            nread = -EIO;
329
            break;
286
            break;
330
        }
287
        }
331
        
288
        
332
        res = emcore_read(buf, addr, nread);
289
        res = emcore_read(buf, addr, nread);
333
        
290
        
334
        if (EMCORE_SUCCESS != res)
291
        if (res != EMCORE_SUCCESS) {
335
        {
-
 
336
            nread = -EIO;
292
            nread = -EIO;
337
        }
293
        }
338
        
-
 
339
    }
294
    }
340
    while(0);
295
    while(0);
341
    
296
    
342
    res = emcore_free(addr);
297
    res = emcore_free(addr);
343
    
298
    
344
    if (EMCORE_SUCCESS != res)
299
    if (res != EMCORE_SUCCESS) {
345
    {
-
 
346
        return -EIO;
300
        return -EIO;
347
    }
301
    }
348
    
302
    
349
    return nread;
303
    return nread;
350
}
304
}
351
 
305
 
352
int emcorefs_write(const char* path, const char* buf, size_t size, off_t offset, struct fuse_file_info* fi) {
306
int32_t emcorefs_write(const char *path, const char *buf, size_t size, off_t offset, struct fuse_file_info *fi) {
353
#ifdef DEBUG2
307
#ifdef DEBUG2
354
    fprintf(stderr, "FUSE_WRITE: path=[%s] size=[%d] offset=[%jd] fi->flags=[%d]\n", path, size, offset, fi->flags);
308
    fprintf(stderr, "FUSE_WRITE: path=[%s] size=[%d] offset=[%jd] fi->flags=[%d]\n", path, size, offset, fi->flags);
355
#else
309
#else
356
    (void)path;
310
    (void)path;
357
#endif
311
#endif
358
    int res;
312
    int32_t res;
359
    uint32_t emcore_errno_value, addr, nwrite = size;
313
    uint32_t emcore_errno_value, addr, nwrite = size;
360
 
314
 
361
    if (!fi->fh)
315
    if (!fi->fh) {
362
    {
-
 
363
        return -EIO;
316
        return -EIO;
364
    }
317
    }
365
    
318
    
366
    res = emcore_malloc(&addr, size);
319
    res = emcore_malloc(&addr, size);
367
    
320
    
368
    if (EMCORE_SUCCESS != res)
321
    if (res != EMCORE_SUCCESS) {
369
    {
-
 
370
        return -EIO;
322
        return -EIO;
371
    }
323
    }
372
    
324
    
373
    do {
325
    do {
374
        if (offset) {
326
        if (offset) {
375
            res = emcore_file_seek(fi->fh, offset, SEEK_SET);
327
            res = emcore_file_seek(fi->fh, offset, SEEK_SET);
376
            
328
            
377
            if (EMCORE_ERROR_IO == res)
329
            if (res == EMCORE_ERROR_IO) {
378
            {
-
 
379
                res = emcore_errno(&emcore_errno_value);
330
                res = emcore_errno(&emcore_errno_value);
380
 
331
 
381
                if (EMCORE_SUCCESS != res)
332
                if (res != EMCORE_SUCCESS) {
382
                {
-
 
383
                    nwrite = -EIO;
333
                    nwrite = -EIO;
384
                    break;
334
                    break;
385
                }
335
                }
386
 
336
 
387
                if (EMCORE_SUCCESS != emcore_errno_value)
337
                if (emcore_errno_value != EMCORE_SUCCESS) {
388
                {
-
 
389
                    nwrite = -emcore_errno_value;
338
                    nwrite = -emcore_errno_value;
390
                    break;
339
                    break;
391
                }
340
                }
392
            }
341
            }
393
        
342
        
394
            if (EMCORE_SUCCESS != res)
343
            if (res != EMCORE_SUCCESS) {
395
            {
-
 
396
                nwrite = -EIO;
344
                nwrite = -EIO;
397
                break;
345
                break;
398
            }
346
            }
399
        }
347
        }
400
        
348
        
401
        res = emcore_write(buf, addr, nwrite);
349
        res = emcore_write(buf, addr, nwrite);
402
        
350
        
403
        if (EMCORE_SUCCESS != res)
351
        if (res != EMCORE_SUCCESS) {
404
        {
-
 
405
            nwrite = -EIO;
352
            nwrite = -EIO;
406
            break;
353
            break;
407
        }
354
        }
408
        
355
        
409
        res = emcore_file_write(&nwrite, fi->fh, addr, size);
356
        res = emcore_file_write(&nwrite, fi->fh, addr, size);
410
        
357
        
411
        if (EMCORE_ERROR_IO == res)
358
        if (res == EMCORE_ERROR_IO) {
412
        {
-
 
413
            res = emcore_errno(&emcore_errno_value);
359
            res = emcore_errno(&emcore_errno_value);
414
 
360
 
415
            if (EMCORE_SUCCESS != res)
361
            if (res != EMCORE_SUCCESS) {
416
            {
-
 
417
                nwrite = -EIO;
362
                nwrite = -EIO;
418
                break;
363
                break;
419
            }
364
            }
420
 
365
 
421
            if (EMCORE_SUCCESS != emcore_errno_value)
366
            if (emcore_errno_value != EMCORE_SUCCESS) {
422
            {
-
 
423
                nwrite = -emcore_errno_value;
367
                nwrite = -emcore_errno_value;
424
                break;
368
                break;
425
            }
369
            }
426
        }
370
        }
427
    
371
    
428
        if (EMCORE_SUCCESS != res)
372
        if (res != EMCORE_SUCCESS) {
429
        {
-
 
430
            nwrite = -EIO;
373
            nwrite = -EIO;
431
        }
374
        }
432
    }
375
    }
433
    while(0);
376
    while(0);
434
    
377
    
435
    res = emcore_free(addr);
378
    res = emcore_free(addr);
436
    
379
    
437
    if (EMCORE_SUCCESS != res)
380
    if (res != EMCORE_SUCCESS) {
438
    {
-
 
439
        return -EIO;
381
        return -EIO;
440
    }
382
    }
441
    
383
    
442
    cache_remove(path);
384
    cache_remove(path);
443
    
385
    
444
    return nwrite;
386
    return nwrite;
445
}
387
}
446
 
388
 
447
int emcorefs_release(const char* path, struct fuse_file_info* fi)
389
int32_t emcorefs_release(const char *path, struct fuse_file_info *fi) {
448
{
-
 
449
    int res;
390
    int32_t res;
450
    uint32_t emcore_errno_value;
391
    uint32_t emcore_errno_value;
451
    (void)path;
392
    (void)path;
452
 
393
 
453
    if (!fi->fh)
394
    if (!fi->fh) {
454
    {
-
 
455
        return -EIO;
395
        return -EIO;
456
    }
396
    }
457
    
397
    
458
    res = emcore_file_close(fi->fh);
398
    res = emcore_file_close(fi->fh);
459
    
399
    
460
    if (EMCORE_ERROR_IO == res)
400
    if (EMCORE_ERROR_IO == res) {
461
    {
-
 
462
        res = emcore_errno(&emcore_errno_value);
401
        res = emcore_errno(&emcore_errno_value);
463
 
402
 
464
        if (EMCORE_SUCCESS != res)
403
        if (res != EMCORE_SUCCESS) {
465
        {
-
 
466
            return -EIO;
404
            return -EIO;
467
        }
405
        }
468
 
406
 
469
        if (EMCORE_SUCCESS != emcore_errno_value)
407
        if (emcore_errno_value != EMCORE_SUCCESS) {
470
        {
-
 
471
            return -emcore_errno_value;
408
            return -emcore_errno_value;
472
        }
409
        }
473
    }
410
    }
474
    
411
    
475
    if (EMCORE_SUCCESS != res)
412
    if (res != EMCORE_SUCCESS) {
476
    {
-
 
477
        return -EIO;
413
        return -EIO;
478
    }
414
    }
479
    
415
    
480
    return 0;
416
    return 0;
481
}
417
}
482
 
418
 
483
int emcorefs_mkdir(const char* path, mode_t mode)
419
int32_t emcorefs_mkdir(const char *path, mode_t mode) {
484
{
-
 
485
    (void)mode;
420
    (void)mode;
486
    int res;
421
    int32_t res;
487
    uint32_t emcore_errno_value;
422
    uint32_t emcore_errno_value;
488
 
423
 
489
    res = emcore_dir_create(path);
424
    res = emcore_dir_create(path);
490
    
425
    
491
    if (EMCORE_ERROR_IO == res)
426
    if (res == EMCORE_ERROR_IO) {
492
    {
-
 
493
        res = emcore_errno(&emcore_errno_value);
427
        res = emcore_errno(&emcore_errno_value);
494
 
428
 
495
        if (EMCORE_SUCCESS != res)
429
        if (res != EMCORE_SUCCESS) {
496
        {
-
 
497
            return -EIO;
430
            return -EIO;
498
        }
431
        }
499
 
432
 
500
        if (EMCORE_SUCCESS != emcore_errno_value)
433
        if (emcore_errno_value != EMCORE_SUCCESS) {
501
        {
-
 
502
            return -emcore_errno_value;
434
            return -emcore_errno_value;
503
        }
435
        }
504
    }
436
    }
505
    
437
    
506
    if (EMCORE_SUCCESS != res)
438
    if (res != EMCORE_SUCCESS) {
507
    {
-
 
508
        return -EIO;
439
        return -EIO;
509
    }
440
    }
510
    
441
    
511
    return 0;
442
    return 0;
512
}
443
}
513
 
444
 
514
int emcorefs_rmdir(const char* path)
445
int32_t emcorefs_rmdir(const char *path) {
515
{
-
 
516
    int res;
446
    int32_t res;
517
    uint32_t emcore_errno_value;
447
    uint32_t emcore_errno_value;
518
 
448
 
519
    res = emcore_dir_remove(path);
449
    res = emcore_dir_remove(path);
520
    
450
    
521
    if (EMCORE_ERROR_IO == res)
451
    if (res == EMCORE_ERROR_IO) {
522
    {
-
 
523
        res = emcore_errno(&emcore_errno_value);
452
        res = emcore_errno(&emcore_errno_value);
524
 
453
 
525
        if (EMCORE_SUCCESS != res)
454
        if (res != EMCORE_SUCCESS) {
526
        {
-
 
527
            return -EIO;
455
            return -EIO;
528
        }
456
        }
529
 
457
 
530
        if (EMCORE_SUCCESS != emcore_errno_value)
458
        if (emcore_errno_value != EMCORE_SUCCESS) {
531
        {
-
 
532
            return -emcore_errno_value;
459
            return -emcore_errno_value;
533
        }
460
        }
534
    }
461
    }
535
    
462
    
536
    if (EMCORE_SUCCESS != res)
463
    if (res != EMCORE_SUCCESS) {
537
    {
-
 
538
        return -EIO;
464
        return -EIO;
539
    }
465
    }
540
    
466
    
541
    cache_remove(path);
467
    cache_remove(path);
542
    
468
    
543
    return 0;
469
    return 0;
544
}
470
}
545
 
471
 
546
int emcorefs_create(const char* path, mode_t mode, struct fuse_file_info* fi)
472
int32_t emcorefs_create(const char *path, mode_t mode, struct fuse_file_info *fi) {
547
{
-
 
548
    (void)mode;
473
    (void)mode;
549
    return emcorefs_open(path, fi);
474
    return emcorefs_open(path, fi);
550
}
475
}
551
 
476
 
552
int emcorefs_mknod(const char* path, mode_t mode, dev_t dev)
477
int32_t emcorefs_mknod(const char *path, mode_t mode, dev_t dev) {
553
{
-
 
554
    (void)dev;
478
    (void)dev;
555
    int res;
479
    int32_t res;
556
    struct fuse_file_info fi;
480
    struct fuse_file_info fi;
557
    
481
    
558
    fi.flags = O_WRONLY | O_CREAT | O_TRUNC;
482
    fi.flags = O_WRONLY | O_CREAT | O_TRUNC;
559
    
483
    
560
    res = emcorefs_create(path, mode, &fi);
484
    res = emcorefs_create(path, mode, &fi);
561
    
485
    
562
    if (0 != res) {
486
    if (res) {
563
        return res;
487
        return res;
564
    }
488
    }
565
    
489
    
566
    return emcorefs_release(path, &fi);
490
    return emcorefs_release(path, &fi);
567
}
491
}
568
 
492
 
569
int emcorefs_unlink(const char* path)
493
int32_t emcorefs_unlink(const char *path)
570
{
494
{
571
    int res;
495
    int32_t res;
572
    uint32_t emcore_errno_value;
496
    uint32_t emcore_errno_value;
573
 
497
 
574
    res = emcore_file_unlink(path);
498
    res = emcore_file_unlink(path);
575
    
499
    
576
    if (EMCORE_ERROR_IO == res)
500
    if (res == EMCORE_ERROR_IO) {
577
    {
-
 
578
        res = emcore_errno(&emcore_errno_value);
501
        res = emcore_errno(&emcore_errno_value);
579
 
502
 
580
        if (EMCORE_SUCCESS != res)
503
        if (res != EMCORE_SUCCESS) {
581
        {
-
 
582
            return -EIO;
504
            return -EIO;
583
        }
505
        }
584
 
506
 
585
        if (EMCORE_SUCCESS != emcore_errno_value)
507
        if (emcore_errno_value != EMCORE_SUCCESS) {
586
        {
-
 
587
            return -emcore_errno_value;
508
            return -emcore_errno_value;
588
        }
509
        }
589
    }
510
    }
590
    
511
    
591
    if (EMCORE_SUCCESS != res)
512
    if (res != EMCORE_SUCCESS) {
592
    {
-
 
593
        return -EIO;
513
        return -EIO;
594
    }
514
    }
595
    
515
    
596
    cache_remove(path);
516
    cache_remove(path);
597
    
517
    
598
    return 0;
518
    return 0;
599
}
519
}
600
 
520
 
601
int emcorefs_rename(const char* path, const char* new_path)
521
int32_t emcorefs_rename(const char *path, const char *new_path) {
602
{
-
 
603
    int res;
522
    int32_t res;
604
    uint32_t emcore_errno_value;
523
    uint32_t emcore_errno_value;
605
 
524
 
606
    res = emcore_file_rename(path, new_path);
525
    res = emcore_file_rename(path, new_path);
607
    
526
 
608
    if (EMCORE_ERROR_IO == res)
527
    if (res == EMCORE_ERROR_IO) {
609
    {
-
 
610
        res = emcore_errno(&emcore_errno_value);
528
        res = emcore_errno(&emcore_errno_value);
611
 
529
 
612
        if (EMCORE_SUCCESS != res)
530
        if (res != EMCORE_SUCCESS) {
613
        {
-
 
614
            return -EIO;
531
            return -EIO;
615
        }
532
        }
616
 
533
 
617
        if (EMCORE_SUCCESS != emcore_errno_value)
534
        if (emcore_errno_value != EMCORE_SUCCESS) {
618
        {
-
 
619
            return -emcore_errno_value;
535
            return -emcore_errno_value;
620
        }
536
        }
621
    }
537
    }
622
    
538
    
623
    if (EMCORE_SUCCESS != res)
539
    if (res != EMCORE_SUCCESS) {
624
    {
-
 
625
        return -EIO;
540
        return -EIO;
626
    }
541
    }
627
    
542
    
628
    cache_remove(path);
543
    cache_remove(path);
629
    
544
    
630
    return 0;
545
    return 0;
631
}
546
}
632
 
547
 
633
int emcorefs_truncate(const char* path, off_t size)
548
int32_t emcorefs_truncate(const char *path, off_t size) {
634
{
-
 
635
    int res;
549
    int32_t res;
636
    struct fuse_file_info fi;
550
    struct fuse_file_info fi;
637
    
551
    
638
    res = emcorefs_open(path, &fi);
552
    res = emcorefs_open(path, &fi);
639
    
553
    
640
    if (0 != res) {
554
    if (res) {
641
        return res;
555
        return res;
642
    }
556
    }
643
    
557
    
644
    res = emcorefs_ftruncate(path, size, &fi);
558
    res = emcorefs_ftruncate(path, size, &fi);
645
    
559
    
646
    if (0 != res) {
560
    if (res) {
647
        return res;
561
        return res;
648
    }
562
    }
649
    
563
    
650
    return emcorefs_release(path, &fi);
564
    return emcorefs_release(path, &fi);
651
}
565
}
652
 
566
 
653
int emcorefs_ftruncate(const char* path, off_t size, struct fuse_file_info* fi)
567
int32_t emcorefs_ftruncate(const char *path, off_t size, struct fuse_file_info *fi) {
654
{
-
 
655
    int res;
568
    int32_t res;
656
    uint32_t emcore_errno_value;
569
    uint32_t emcore_errno_value;
657
    (void)path;
570
    (void)path;
658
 
571
 
659
    if (!fi->fh)
572
    if (!fi->fh) {
660
    {
-
 
661
        return -EIO;
573
        return -EIO;
662
    }
574
    }
663
    
575
    
664
    res = emcore_file_truncate(fi->fh, size);
576
    res = emcore_file_truncate(fi->fh, size);
665
    
577
    
666
    if (EMCORE_ERROR_IO == res)
578
    if (res == EMCORE_ERROR_IO) {
667
    {
-
 
668
        res = emcore_errno(&emcore_errno_value);
579
        res = emcore_errno(&emcore_errno_value);
669
 
580
 
670
        if (EMCORE_SUCCESS != res)
581
        if (res != EMCORE_SUCCESS) {
671
        {
-
 
672
            return -EIO;
582
            return -EIO;
673
        }
583
        }
674
 
584
 
675
        if (EMCORE_SUCCESS != emcore_errno_value)
585
        if (emcore_errno_value != EMCORE_SUCCESS) {
676
        {
-
 
677
            return -emcore_errno_value;
586
            return -emcore_errno_value;
678
        }
587
        }
679
    }
588
    }
680
    
589
    
681
    if (EMCORE_SUCCESS != res)
590
    if (res != EMCORE_SUCCESS) {
682
    {
-
 
683
        return -EIO;
591
        return -EIO;
684
    }
592
    }
685
    
593
    
686
    cache_remove(path);
594
    cache_remove(path);
687
    
595
    
688
    return 0;
596
    return 0;
689
}
597
}
690
 
-