Index: emcore/trunk/tools/emcorefs/emcore.h |
— | — | @@ -119,6 +119,8 @@ |
120 | 120 | int emcore_dir_read(struct emcore_dir_entry* entry, const uint32_t handle);
|
121 | 121 | int emcore_dir_close(const uint32_t handle);
|
122 | 122 | int emcore_dir_close_all(uint32_t* count);
|
| 123 | +int emcore_dir_create(const char* name);
|
| 124 | +int emcore_dir_remove(const char* name);
|
123 | 125 | int emcore_errno(uint32_t* emcore_errno_value);
|
124 | 126 | int emcore_malloc(uint32_t* ptr, const uint32_t size);
|
125 | 127 | int emcore_memalign(uint32_t* ptr, const uint32_t align, const uint32_t size);
|
Index: emcore/trunk/tools/emcorefs/fuse.c |
— | — | @@ -29,6 +29,23 @@ |
30 | 30 | #include "emcore.h"
|
31 | 31 |
|
32 | 32 |
|
| 33 | +int emcorefs_init(void)
|
| 34 | +{
|
| 35 | + int res;
|
| 36 | + uint32_t count;
|
| 37 | +
|
| 38 | + res = emcore_file_close_all(&count);
|
| 39 | +
|
| 40 | + if (EMCORE_SUCCESS != res)
|
| 41 | + {
|
| 42 | + return res;
|
| 43 | + }
|
| 44 | +
|
| 45 | + res = emcore_dir_close_all(&count);
|
| 46 | +
|
| 47 | + return res;
|
| 48 | +}
|
| 49 | +
|
33 | 50 | int emcorefs_getattr(const char* path, struct stat* stbuf)
|
34 | 51 | {
|
35 | 52 | int res = 0;
|
— | — | @@ -38,6 +55,12 @@ |
39 | 56 |
|
40 | 57 | memset(stbuf, 0, sizeof(*stbuf));
|
41 | 58 |
|
| 59 | +#ifdef DEBUG2
|
| 60 | + if (0 == strcmp(path, "/__cache_dump"))
|
| 61 | + {
|
| 62 | + cache_dump();
|
| 63 | + }
|
| 64 | +#endif
|
42 | 65 | entry = cache_get(path);
|
43 | 66 |
|
44 | 67 | if (NULL == entry)
|
— | — | @@ -200,7 +223,11 @@ |
201 | 224 | {
|
202 | 225 | int res;
|
203 | 226 | uint32_t handle, emcore_errno_value;
|
204 | | -
|
| 227 | +
|
| 228 | +#ifdef DEBUG
|
| 229 | + fprintf(stderr, "FILE OPEN: [%s], 0x%08x\n", path, fi->flags);
|
| 230 | +#endif
|
| 231 | +
|
205 | 232 | res = emcore_file_open(&handle, path, fi->flags);
|
206 | 233 |
|
207 | 234 | if (EMCORE_ERROR_IO == res)
|
— | — | @@ -354,3 +381,122 @@ |
355 | 382 |
|
356 | 383 | return 0;
|
357 | 384 | }
|
| 385 | +
|
| 386 | +int emcorefs_mkdir(const char* path, mode_t mode)
|
| 387 | +{
|
| 388 | + (void)mode;
|
| 389 | + int res;
|
| 390 | + uint32_t emcore_errno_value;
|
| 391 | +
|
| 392 | + res = emcore_dir_create(path);
|
| 393 | +
|
| 394 | + if (EMCORE_ERROR_IO == res)
|
| 395 | + {
|
| 396 | + res = emcore_errno(&emcore_errno_value);
|
| 397 | +
|
| 398 | + if (EMCORE_SUCCESS != res)
|
| 399 | + {
|
| 400 | + return -EIO;
|
| 401 | + }
|
| 402 | +
|
| 403 | + if (EMCORE_SUCCESS != emcore_errno_value)
|
| 404 | + {
|
| 405 | + return -emcore_errno_value;
|
| 406 | + }
|
| 407 | + }
|
| 408 | +
|
| 409 | + if (EMCORE_SUCCESS != res)
|
| 410 | + {
|
| 411 | + return -EIO;
|
| 412 | + }
|
| 413 | +
|
| 414 | + return 0;
|
| 415 | +}
|
| 416 | +
|
| 417 | +int emcorefs_rmdir(const char* path)
|
| 418 | +{
|
| 419 | + int res;
|
| 420 | + uint32_t emcore_errno_value;
|
| 421 | +
|
| 422 | + res = emcore_dir_remove(path);
|
| 423 | +
|
| 424 | + if (EMCORE_ERROR_IO == res)
|
| 425 | + {
|
| 426 | + res = emcore_errno(&emcore_errno_value);
|
| 427 | +
|
| 428 | + if (EMCORE_SUCCESS != res)
|
| 429 | + {
|
| 430 | + return -EIO;
|
| 431 | + }
|
| 432 | +
|
| 433 | + if (EMCORE_SUCCESS != emcore_errno_value)
|
| 434 | + {
|
| 435 | + return -emcore_errno_value;
|
| 436 | + }
|
| 437 | + }
|
| 438 | +
|
| 439 | + if (EMCORE_SUCCESS != res)
|
| 440 | + {
|
| 441 | + return -EIO;
|
| 442 | + }
|
| 443 | +
|
| 444 | + cache_remove(path);
|
| 445 | +
|
| 446 | + return 0;
|
| 447 | +}
|
| 448 | +
|
| 449 | +int emcorefs_create(const char* path, mode_t mode, struct fuse_file_info* fi)
|
| 450 | +{
|
| 451 | + (void)mode;
|
| 452 | + return emcorefs_open(path, fi);
|
| 453 | +}
|
| 454 | +
|
| 455 | +int emcorefs_mknod(const char* path, mode_t mode, dev_t dev)
|
| 456 | +{
|
| 457 | + (void)dev;
|
| 458 | + int res;
|
| 459 | + struct fuse_file_info fi;
|
| 460 | +
|
| 461 | + fi.flags = O_WRONLY | O_CREAT | O_TRUNC;
|
| 462 | +
|
| 463 | + res = emcorefs_create(path, mode, &fi);
|
| 464 | +
|
| 465 | + if (0 != res) {
|
| 466 | + return res;
|
| 467 | + }
|
| 468 | +
|
| 469 | + return emcorefs_release(path, &fi);
|
| 470 | +}
|
| 471 | +
|
| 472 | +int emcorefs_unlink(const char* path)
|
| 473 | +{
|
| 474 | +
|
| 475 | + int res;
|
| 476 | + uint32_t emcore_errno_value;
|
| 477 | +
|
| 478 | + res = emcore_file_unlink(path);
|
| 479 | +
|
| 480 | + if (EMCORE_ERROR_IO == res)
|
| 481 | + {
|
| 482 | + res = emcore_errno(&emcore_errno_value);
|
| 483 | +
|
| 484 | + if (EMCORE_SUCCESS != res)
|
| 485 | + {
|
| 486 | + return -EIO;
|
| 487 | + }
|
| 488 | +
|
| 489 | + if (EMCORE_SUCCESS != emcore_errno_value)
|
| 490 | + {
|
| 491 | + return -emcore_errno_value;
|
| 492 | + }
|
| 493 | + }
|
| 494 | +
|
| 495 | + if (EMCORE_SUCCESS != res)
|
| 496 | + {
|
| 497 | + return -EIO;
|
| 498 | + }
|
| 499 | +
|
| 500 | + cache_remove(path);
|
| 501 | +
|
| 502 | + return 0;
|
| 503 | +} |
\ No newline at end of file |
Index: emcore/trunk/tools/emcorefs/cache.c |
— | — | @@ -63,7 +63,7 @@ |
64 | 64 | for (i = 0; i < emcore_dir_cache_length; ++i) |
65 | 65 | { |
66 | 66 | #ifdef DEBUG2 |
67 | | - fprintf(stderr, "strcmp([%s], [%s]) == %d\n", name, emcore_dir_entry_cache[i].name, strcmp(name, emcore_dir_entry_cache[i].name)); |
| 67 | + fprintf(stderr, "cache_get: strcmp([%s], [%s]) == %d\n", name, emcore_dir_entry_cache[i].name, strcmp(name, emcore_dir_entry_cache[i].name)); |
68 | 68 | #endif |
69 | 69 | if (0 == strcmp(name, emcore_dir_entry_cache[i].name)) |
70 | 70 | { |
— | — | @@ -138,6 +138,43 @@ |
139 | 139 | ++emcore_dir_cache_length; |
140 | 140 | } |
141 | 141 | |
| 142 | +void cache_remove(const char* name) |
| 143 | +{ |
| 144 | + size_t i; |
| 145 | + void* new_ptr; |
| 146 | + |
| 147 | + for (i = 0; i < emcore_dir_cache_length; ++i) |
| 148 | + { |
| 149 | +#ifdef DEBUG2 |
| 150 | + fprintf(stderr, "cache_remove: strcmp([%s], [%s]) == %d\n", name, emcore_dir_entry_cache[i].name, strcmp(name, emcore_dir_entry_cache[i].name)); |
| 151 | +#endif |
| 152 | + if (0 == strcmp(name, emcore_dir_entry_cache[i].name)) |
| 153 | + { |
| 154 | +#ifdef DEBUG2 |
| 155 | + fprintf(stderr, "CACHE REMOVE: [%s]\n", name); |
| 156 | +#endif |
| 157 | + free(emcore_dir_entry_cache[i].name); |
| 158 | + |
| 159 | + if (emcore_dir_cache_length > i + 1) { |
| 160 | + memcpy(emcore_dir_entry_cache + i, emcore_dir_entry_cache + i + 1, (emcore_dir_cache_length - i - 1) * sizeof(*emcore_dir_entry_cache)); |
| 161 | + } |
| 162 | + |
| 163 | + --emcore_dir_cache_length; |
| 164 | + |
| 165 | + new_ptr = realloc(emcore_dir_entry_cache, |
| 166 | + sizeof(*emcore_dir_entry_cache) * (emcore_dir_cache_length)); |
| 167 | + |
| 168 | + if (!new_ptr) |
| 169 | + { |
| 170 | + return; |
| 171 | + } |
| 172 | + |
| 173 | + emcore_dir_entry_cache = new_ptr; |
| 174 | + } |
| 175 | + } |
| 176 | + |
| 177 | +} |
| 178 | + |
142 | 179 | void cache_destroy(void) |
143 | 180 | { |
144 | 181 | #ifdef DEBUG |
— | — | @@ -153,3 +190,20 @@ |
154 | 191 | fprintf(stderr, "Cache destroyed!\n"); |
155 | 192 | #endif |
156 | 193 | } |
| 194 | + |
| 195 | +#ifdef DEBUG2 |
| 196 | +void cache_dump(void) |
| 197 | +{ |
| 198 | + size_t i; |
| 199 | + |
| 200 | + if (!emcore_dir_cache_length) |
| 201 | + { |
| 202 | + return; |
| 203 | + } |
| 204 | + |
| 205 | + for (i = 0; i < emcore_dir_cache_length; ++i) |
| 206 | + { |
| 207 | + fprintf(stderr, "cache_dump: [%s] 0x%08x %d %d %lu\n", emcore_dir_entry_cache[i].name, emcore_dir_entry_cache[i].attributes, emcore_dir_entry_cache[i].size, emcore_dir_entry_cache[i].startcluster, fat_time_to_unix_ts(emcore_dir_entry_cache[i].wrtdate, emcore_dir_entry_cache[i].wrttime)); |
| 208 | + } |
| 209 | +} |
| 210 | +#endif |
Index: emcore/trunk/tools/emcorefs/emcorefs.c |
— | — | @@ -40,25 +40,13 @@ |
41 | 41 | .open = emcorefs_open, |
42 | 42 | .read = emcorefs_read, |
43 | 43 | .release = emcorefs_release, |
| 44 | + .mkdir = emcorefs_mkdir, |
| 45 | + .rmdir = emcorefs_rmdir, |
| 46 | + .create = emcorefs_create, |
| 47 | + .mknod = emcorefs_mknod, |
| 48 | + .unlink = emcorefs_unlink, |
44 | 49 | }; |
45 | 50 | |
46 | | -int emcorefs_init(void) |
47 | | -{ |
48 | | - int res; |
49 | | - uint32_t count; |
50 | | - |
51 | | - res = emcore_file_close_all(&count); |
52 | | - |
53 | | - if (EMCORE_SUCCESS != res) |
54 | | - { |
55 | | - return res; |
56 | | - } |
57 | | - |
58 | | - res = emcore_dir_close_all(&count); |
59 | | - |
60 | | - return res; |
61 | | -} |
62 | | - |
63 | 51 | int main(int argc, char* argv[]) |
64 | 52 | { |
65 | 53 | int res, res2; |
Index: emcore/trunk/tools/emcorefs/fuse.h |
— | — | @@ -26,7 +26,7 @@ |
27 | 27 |
|
28 | 28 | #include "global.h"
|
29 | 29 |
|
30 | | -
|
| 30 | +int emcorefs_init(void);
|
31 | 31 | int emcorefs_getattr(const char* path, struct stat* stbuf);
|
32 | 32 | int emcorefs_opendir(const char* path, struct fuse_file_info* fi);
|
33 | 33 | int emcorefs_readdir(const char* path, void* buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info* fi);
|
— | — | @@ -34,5 +34,10 @@ |
35 | 35 | int emcorefs_open(const char* path, struct fuse_file_info* fi);
|
36 | 36 | int emcorefs_read(const char* path, char* buf, uint32_t size, off_t offset, struct fuse_file_info* fi);
|
37 | 37 | int emcorefs_release(const char* path, struct fuse_file_info* fi);
|
| 38 | +int emcorefs_mkdir(const char* path, mode_t mode);
|
| 39 | +int emcorefs_rmdir(const char* path);
|
| 40 | +int emcorefs_create(const char* path, mode_t mode, struct fuse_file_info* fi);
|
| 41 | +int emcorefs_mknod(const char* path, mode_t mode, dev_t dev);
|
| 42 | +int emcorefs_unlink(const char* path);
|
38 | 43 |
|
39 | 44 | #endif /* __FUSE_H__ */
|
Index: emcore/trunk/tools/emcorefs/cache.h |
— | — | @@ -30,6 +30,11 @@ |
31 | 31 | void cache_init(void); |
32 | 32 | struct emcore_dir_entry* cache_get(const char* name); |
33 | 33 | void cache_insert(const char* dir_name, const struct emcore_dir_entry* entry); |
| 34 | +void cache_remove(const char* dir_name); |
34 | 35 | void cache_destroy(void); |
35 | 36 | |
| 37 | +#ifdef DEBUG2 |
| 38 | +void cache_dump(void); |
| 39 | +#endif |
| 40 | + |
36 | 41 | #endif /* __CACHE_H__ */ |
Index: emcore/trunk/tools/emcorefs/emcorefs.h |
— | — | @@ -27,7 +27,6 @@ |
28 | 28 | #include "global.h"
|
29 | 29 |
|
30 | 30 |
|
31 | | -int emcorefs_init(void);
|
32 | 31 | int main(int argc, char* argv[]);
|
33 | 32 |
|
34 | 33 | #endif /* __EMCOREFS_H__ */
|
Index: emcore/trunk/tools/emcorefs/emcore.c |
— | — | @@ -375,6 +375,7 @@ |
376 | 376 | {
|
377 | 377 | int res;
|
378 | 378 | uint32_t str_length, data_length, in[4], *out;
|
| 379 | + int flags_emcore = 0;
|
379 | 380 |
|
380 | 381 | *handle = 0;
|
381 | 382 |
|
— | — | @@ -389,8 +390,38 @@ |
390 | 391 | out = calloc(sizeof(char), data_length);
|
391 | 392 |
|
392 | 393 | *(out) = 30;
|
393 | | - *(out + 1) = flags;
|
394 | 394 |
|
| 395 | + /*
|
| 396 | + #define O_RDONLY 0
|
| 397 | + #define O_WRONLY 1
|
| 398 | + #define O_RDWR 2
|
| 399 | + #define O_CREAT 4
|
| 400 | + #define O_APPEND 8
|
| 401 | + #define O_TRUNC 0x10
|
| 402 | + */
|
| 403 | +
|
| 404 | + if (flags & O_WRONLY) {
|
| 405 | + flags_emcore |= 0x01;
|
| 406 | + }
|
| 407 | +
|
| 408 | + if (flags & O_RDWR) {
|
| 409 | + flags_emcore |= 0x02;
|
| 410 | + }
|
| 411 | +
|
| 412 | + if (flags & O_CREAT) {
|
| 413 | + flags_emcore |= 0x04;
|
| 414 | + }
|
| 415 | +
|
| 416 | + if (flags & O_APPEND) {
|
| 417 | + flags_emcore |= 0x08;
|
| 418 | + }
|
| 419 | +
|
| 420 | + if (flags & O_TRUNC) {
|
| 421 | + flags_emcore |= 0x10;
|
| 422 | + }
|
| 423 | +
|
| 424 | + *(out + 1) = flags_emcore;
|
| 425 | +
|
395 | 426 | strncpy(((char*)(out + 4)), path, str_length);
|
396 | 427 |
|
397 | 428 | res = emcore_monitor_command(out, in, data_length, 16);
|
— | — | @@ -746,8 +777,8 @@ |
747 | 778 | {
|
748 | 779 | return res;
|
749 | 780 | }
|
750 | | -
|
751 | | - if (EMCORE_SUCCESS != emcore_errno_value)
|
| 781 | +
|
| 782 | + if (EMCORE_SUCCESS != emcore_errno_value && 2 != emcore_errno_value)
|
752 | 783 | {
|
753 | 784 | return EMCORE_ERROR_IO;
|
754 | 785 | }
|
— | — | @@ -836,6 +867,74 @@ |
837 | 868 | return EMCORE_SUCCESS;
|
838 | 869 | }
|
839 | 870 |
|
| 871 | +int emcore_dir_create(const char* name)
|
| 872 | +{
|
| 873 | + int res;
|
| 874 | + uint32_t str_length, data_length, in[4], *out;
|
| 875 | +
|
| 876 | + str_length = strlen(name);
|
| 877 | + data_length = str_length + 1 + EMCORE_HEADER_SIZE;
|
| 878 | +
|
| 879 | + if (data_length > emcore_usb_eps_mps.cout)
|
| 880 | + {
|
| 881 | + return EMCORE_ERROR_OVERFLOW;
|
| 882 | + }
|
| 883 | +
|
| 884 | + out = calloc(sizeof(char), data_length);
|
| 885 | +
|
| 886 | + *(out) = 47;
|
| 887 | +
|
| 888 | + strncpy(((char*)(out + 4)), name, str_length);
|
| 889 | +
|
| 890 | + res = emcore_monitor_command(out, in, data_length, 16);
|
| 891 | +
|
| 892 | + if (EMCORE_SUCCESS != res)
|
| 893 | + {
|
| 894 | + return res;
|
| 895 | + }
|
| 896 | +
|
| 897 | + if (in[1] > 0x80000000)
|
| 898 | + {
|
| 899 | + return EMCORE_ERROR_IO;
|
| 900 | + }
|
| 901 | +
|
| 902 | + return EMCORE_SUCCESS;
|
| 903 | +}
|
| 904 | +
|
| 905 | +int emcore_dir_remove(const char* name)
|
| 906 | +{
|
| 907 | + int res;
|
| 908 | + uint32_t str_length, data_length, in[4], *out;
|
| 909 | +
|
| 910 | + str_length = strlen(name);
|
| 911 | + data_length = str_length + 1 + EMCORE_HEADER_SIZE;
|
| 912 | +
|
| 913 | + if (data_length > emcore_usb_eps_mps.cout)
|
| 914 | + {
|
| 915 | + return EMCORE_ERROR_OVERFLOW;
|
| 916 | + }
|
| 917 | +
|
| 918 | + out = calloc(sizeof(char), data_length);
|
| 919 | +
|
| 920 | + *(out) = 48;
|
| 921 | +
|
| 922 | + strncpy(((char*)(out + 4)), name, str_length);
|
| 923 | +
|
| 924 | + res = emcore_monitor_command(out, in, data_length, 16);
|
| 925 | +
|
| 926 | + if (EMCORE_SUCCESS != res)
|
| 927 | + {
|
| 928 | + return res;
|
| 929 | + }
|
| 930 | +
|
| 931 | + if (in[1] > 0x80000000)
|
| 932 | + {
|
| 933 | + return EMCORE_ERROR_IO;
|
| 934 | + }
|
| 935 | +
|
| 936 | + return EMCORE_SUCCESS;
|
| 937 | +}
|
| 938 | +
|
840 | 939 | int emcore_errno(uint32_t* emcore_errno_value)
|
841 | 940 | {
|
842 | 941 | int res;
|