freemyipod r782 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r781‎ | r782 | r783 >
Date:06:15, 17 November 2011
Author:user890104
Status:new
Tags:
Comment:
emCOREFS: add support for mkdir, rmdir, create, mknod and unlink syscalls. write not supported yet.
Modified paths:
  • /emcore/trunk/tools/emcorefs/cache.c (modified) (history)
  • /emcore/trunk/tools/emcorefs/cache.h (modified) (history)
  • /emcore/trunk/tools/emcorefs/emcore.c (modified) (history)
  • /emcore/trunk/tools/emcorefs/emcore.h (modified) (history)
  • /emcore/trunk/tools/emcorefs/emcorefs.c (modified) (history)
  • /emcore/trunk/tools/emcorefs/emcorefs.h (modified) (history)
  • /emcore/trunk/tools/emcorefs/fuse.c (modified) (history)
  • /emcore/trunk/tools/emcorefs/fuse.h (modified) (history)

Diff [purge]

Index: emcore/trunk/tools/emcorefs/emcore.h
@@ -119,6 +119,8 @@
120120 int emcore_dir_read(struct emcore_dir_entry* entry, const uint32_t handle);
121121 int emcore_dir_close(const uint32_t handle);
122122 int emcore_dir_close_all(uint32_t* count);
 123+int emcore_dir_create(const char* name);
 124+int emcore_dir_remove(const char* name);
123125 int emcore_errno(uint32_t* emcore_errno_value);
124126 int emcore_malloc(uint32_t* ptr, const uint32_t size);
125127 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 @@
3030 #include "emcore.h"
3131
3232
 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+
3350 int emcorefs_getattr(const char* path, struct stat* stbuf)
3451 {
3552 int res = 0;
@@ -38,6 +55,12 @@
3956
4057 memset(stbuf, 0, sizeof(*stbuf));
4158
 59+#ifdef DEBUG2
 60+ if (0 == strcmp(path, "/__cache_dump"))
 61+ {
 62+ cache_dump();
 63+ }
 64+#endif
4265 entry = cache_get(path);
4366
4467 if (NULL == entry)
@@ -200,7 +223,11 @@
201224 {
202225 int res;
203226 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+
205232 res = emcore_file_open(&handle, path, fi->flags);
206233
207234 if (EMCORE_ERROR_IO == res)
@@ -354,3 +381,122 @@
355382
356383 return 0;
357384 }
 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 @@
6464 for (i = 0; i < emcore_dir_cache_length; ++i)
6565 {
6666 #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));
6868 #endif
6969 if (0 == strcmp(name, emcore_dir_entry_cache[i].name))
7070 {
@@ -138,6 +138,43 @@
139139 ++emcore_dir_cache_length;
140140 }
141141
 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+
142179 void cache_destroy(void)
143180 {
144181 #ifdef DEBUG
@@ -153,3 +190,20 @@
154191 fprintf(stderr, "Cache destroyed!\n");
155192 #endif
156193 }
 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 @@
4141 .open = emcorefs_open,
4242 .read = emcorefs_read,
4343 .release = emcorefs_release,
 44+ .mkdir = emcorefs_mkdir,
 45+ .rmdir = emcorefs_rmdir,
 46+ .create = emcorefs_create,
 47+ .mknod = emcorefs_mknod,
 48+ .unlink = emcorefs_unlink,
4449 };
4550
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 -
6351 int main(int argc, char* argv[])
6452 {
6553 int res, res2;
Index: emcore/trunk/tools/emcorefs/fuse.h
@@ -26,7 +26,7 @@
2727
2828 #include "global.h"
2929
30 -
 30+int emcorefs_init(void);
3131 int emcorefs_getattr(const char* path, struct stat* stbuf);
3232 int emcorefs_opendir(const char* path, struct fuse_file_info* fi);
3333 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 @@
3535 int emcorefs_open(const char* path, struct fuse_file_info* fi);
3636 int emcorefs_read(const char* path, char* buf, uint32_t size, off_t offset, struct fuse_file_info* fi);
3737 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);
3843
3944 #endif /* __FUSE_H__ */
Index: emcore/trunk/tools/emcorefs/cache.h
@@ -30,6 +30,11 @@
3131 void cache_init(void);
3232 struct emcore_dir_entry* cache_get(const char* name);
3333 void cache_insert(const char* dir_name, const struct emcore_dir_entry* entry);
 34+void cache_remove(const char* dir_name);
3435 void cache_destroy(void);
3536
 37+#ifdef DEBUG2
 38+void cache_dump(void);
 39+#endif
 40+
3641 #endif /* __CACHE_H__ */
Index: emcore/trunk/tools/emcorefs/emcorefs.h
@@ -27,7 +27,6 @@
2828 #include "global.h"
2929
3030
31 -int emcorefs_init(void);
3231 int main(int argc, char* argv[]);
3332
3433 #endif /* __EMCOREFS_H__ */
Index: emcore/trunk/tools/emcorefs/emcore.c
@@ -375,6 +375,7 @@
376376 {
377377 int res;
378378 uint32_t str_length, data_length, in[4], *out;
 379+ int flags_emcore = 0;
379380
380381 *handle = 0;
381382
@@ -389,8 +390,38 @@
390391 out = calloc(sizeof(char), data_length);
391392
392393 *(out) = 30;
393 - *(out + 1) = flags;
394394
 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+
395426 strncpy(((char*)(out + 4)), path, str_length);
396427
397428 res = emcore_monitor_command(out, in, data_length, 16);
@@ -746,8 +777,8 @@
747778 {
748779 return res;
749780 }
750 -
751 - if (EMCORE_SUCCESS != emcore_errno_value)
 781+
 782+ if (EMCORE_SUCCESS != emcore_errno_value && 2 != emcore_errno_value)
752783 {
753784 return EMCORE_ERROR_IO;
754785 }
@@ -836,6 +867,74 @@
837868 return EMCORE_SUCCESS;
838869 }
839870
 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+
840939 int emcore_errno(uint32_t* emcore_errno_value)
841940 {
842941 int res;