testfs.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * File : application.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006, RT-Thread Development Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2009-01-05 Bernard the first version
  13. */
  14. #include <rtthread.h>
  15. #include <stdio.h>
  16. #include <board.h>
  17. #ifdef RT_USING_DFS
  18. /* dfs init */
  19. #include <dfs_init.h>
  20. /* dfs filesystem:ELM filesystem init */
  21. #include <dfs_elm.h>
  22. /* dfs Filesystem APIs */
  23. #include <dfs_fs.h>
  24. #endif
  25. #include <dfs_posix.h>
  26. int testfat(void)
  27. {
  28. int Fd,i;
  29. int res;
  30. Fd = open("/nor/test.txt", O_WRONLY | O_CREAT | O_TRUNC, 0); //打开文件
  31. if (Fd>=0)
  32. {
  33. rt_kprintf("begin\n");
  34. for (i = 0; i < 94520 ; i++)
  35. //for (i = 0; i < 512 ; i++)
  36. {
  37. res = write(Fd, &i, 1);
  38. if (res < 0)
  39. {
  40. rt_kprintf("write %d bytes, then meet a error, break\n", i);
  41. break;
  42. }
  43. }
  44. close(Fd);
  45. rt_kprintf("over\n");
  46. }
  47. else
  48. {
  49. rt_kprintf("failed\n");
  50. }
  51. return 0;
  52. }
  53. static char buf[94520];
  54. int testfat2(void)
  55. {
  56. int Fd,i;
  57. Fd = open("/nor/test2.txt", O_WRONLY | O_CREAT | O_TRUNC, 0); //打开文件
  58. if (Fd>=0)
  59. {
  60. rt_kprintf("begin\n");
  61. for (i = 0; i < 94520 ; i++)
  62. {
  63. write(Fd, buf, 1);
  64. }
  65. close(Fd);
  66. rt_kprintf("over\n");
  67. }
  68. else
  69. {
  70. rt_kprintf("failed\n");
  71. }
  72. return 0;
  73. }
  74. int testfat3(void)
  75. {
  76. int Fd,i;
  77. Fd = open("/nor/test3.txt", O_WRONLY | O_CREAT | O_TRUNC, 0); //打开文件
  78. if (Fd>=0)
  79. {
  80. rt_kprintf("begin\n");
  81. {
  82. write(Fd, buf, 94520);
  83. }
  84. close(Fd);
  85. rt_kprintf("over\n");
  86. }
  87. else
  88. {
  89. rt_kprintf("failed\n");
  90. }
  91. return 0;
  92. }
  93. #include <finsh.h>
  94. FINSH_FUNCTION_EXPORT(testfat, test fs);
  95. FINSH_FUNCTION_EXPORT(testfat2, test fs);
  96. FINSH_FUNCTION_EXPORT(testfat3, test fs);