stub.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #include <linux/kernel.h>
  2. #include "nodelist.h"
  3. #include <linux/pagemap.h>
  4. #include <linux/crc32.h>
  5. #include "compr.h"
  6. //#include <errno.h>
  7. #include <string.h>
  8. extern struct cyg_fstab_entry jffs2_fste;
  9. MTAB_ENTRY(jffs2_mte,
  10. "/",
  11. "jffs2",
  12. NULL,
  13. 0);
  14. #include "flash.h"
  15. extern int file_handle;
  16. extern int FLASH_SIZE;
  17. extern int flash_file_init(void);
  18. extern int jffs2_mount(cyg_fstab_entry * fste, cyg_mtab_entry * mte);
  19. extern int jffs2_open(cyg_mtab_entry * mte, cyg_dir dir, const char *name,
  20. int mode, cyg_file * file);
  21. extern int jffs2_fo_read(struct CYG_FILE_TAG *fp, struct CYG_UIO_TAG *uio);
  22. char buffer[1024];
  23. int jffs2_main()
  24. {
  25. int res;
  26. cyg_file file;
  27. struct CYG_UIO_TAG uio_s;
  28. struct CYG_IOVEC_TAG iovec;
  29. // res = flash_file_init();
  30. if (res != 0)
  31. goto out;
  32. //mount file system
  33. res = jffs2_mount(&jffs2_fste, &jffs2_mte);
  34. if (res < 0)
  35. {
  36. printf("jffs2_mount error!\n");
  37. goto out;
  38. }
  39. printf("jffs2 mount ok!\n");
  40. //read a file or dirs "src/dfs.c"
  41. //res = jffs2_open(&jffs2_mte, 0, "dfs_uffs.c", O_RDWR, &file);
  42. //res = jffs2_open(&jffs2_mte, 0, "SConscript", O_RDWR, &file);
  43. // res = jffs2_open(&jffs2_mte, 0, "filesystems/devfs/console.c" , O_RDWR, &file);
  44. if (res != 0)
  45. {
  46. printf("jffs2_open file error: %d", res);
  47. goto out;
  48. }
  49. memset(buffer, 0, sizeof(buffer));
  50. uio_s.uio_iov = &iovec;
  51. uio_s.uio_iov->iov_base = buffer;
  52. uio_s.uio_iov->iov_len = 1024;
  53. uio_s.uio_iovcnt = 1; //must be 1
  54. //uio_s.uio_offset //not used...
  55. uio_s.uio_resid = uio_s.uio_iov->iov_len; //seem no use in ecos;
  56. //uio_s.uio_segflg = UIO_USERSPACE;
  57. //uio_s.uio_rw = ;
  58. res = jffs2_fo_read(&file, &uio_s);
  59. if (res != 0)
  60. {
  61. printf("jffs2_fo_read file error: %d", res);
  62. goto out;
  63. }
  64. printf("\n\n=====================================================================\n");
  65. printf("the uffs/dfs_uffs.c file content is:\n\n");
  66. printf("%s", buffer);
  67. out:
  68. #if defined (MSVC)
  69. printf("\n\npress any key to colose this console...\n");
  70. getch();
  71. #endif
  72. return 0;
  73. }