dfs_init.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. +------------------------------------------------------------------------------
  3. | Project : Device Filesystem
  4. +------------------------------------------------------------------------------
  5. | Copyright 2004, 2005 www.fayfayspace.org.
  6. | All rights reserved.
  7. |------------------------------------------------------------------------------
  8. | File : dfs.c, the implementation of Device FileSystem
  9. |------------------------------------------------------------------------------
  10. | Chang Logs:
  11. | Date Author Notes
  12. | 2002-12-31 ffxz The first version.
  13. | 2005-01-22 ffxz Clean up the code.
  14. +------------------------------------------------------------------------------
  15. */
  16. #include <dfs_def.h>
  17. #include <dfs_config.h>
  18. #include <dfs_fs.h>
  19. #include <dfs_raw.h>
  20. #include <string.h>
  21. /* Global variables */
  22. struct dfs_filesystem_operation* filesystem_operation_table[DFS_FILESYSTEM_TYPES_MAX + 1];
  23. struct dfs_filesystem filesystem_table[DFS_FILESYSTEMS_MAX + 1];
  24. /* device filesystem lock */
  25. struct rt_mutex dlock;
  26. #ifdef DFS_USING_WORKDIR
  27. char working_directory[DFS_PATH_MAX + 1];
  28. #endif
  29. #ifdef DFS_USING_STDIO
  30. struct dfs_fd fd_table[3 + DFS_FD_MAX];
  31. #else
  32. struct dfs_fd fd_table[DFS_FD_MAX];
  33. #endif
  34. /*
  35. +------------------------------------------------------------------------------
  36. | Function : dfs_init
  37. +------------------------------------------------------------------------------
  38. | Description : Inits the Device Filesystem
  39. | Parameters : null
  40. | Returns : null
  41. +------------------------------------------------------------------------------
  42. */
  43. void dfs_init()
  44. {
  45. int index;
  46. /* clear filesystem operations table */
  47. for (index = 0; index < DFS_FILESYSTEM_TYPES_MAX + 1; index++)
  48. filesystem_operation_table[index] = RT_NULL;
  49. /* create device filesystem lock */
  50. rt_mutex_init(&dlock, "dlock", RT_IPC_FLAG_FIFO);
  51. /* clear filesystem table */
  52. rt_memset(filesystem_table, 0, sizeof(filesystem_table));
  53. #ifdef DFS_USING_WORKDIR
  54. /* set current working directory */
  55. strcpy(working_directory, "/");
  56. #endif
  57. /* clean fd table */
  58. rt_memset(fd_table, 0, sizeof(fd_table));
  59. #if defined(RT_USING_FINSH) && !defined(FINSH_USING_SYMTAB)
  60. dfs_export_finsh();
  61. #endif
  62. }
  63. void dfs_lock()
  64. {
  65. rt_err_t result;
  66. result = rt_mutex_take(&dlock, RT_WAITING_FOREVER);
  67. RT_ASSERT(result == RT_EOK);
  68. }
  69. void dfs_unlock()
  70. {
  71. rt_mutex_release(&dlock);
  72. }