dfs_init.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. }
  60. void dfs_lock()
  61. {
  62. rt_err_t result;
  63. result = rt_mutex_take(&dlock, RT_WAITING_FOREVER);
  64. RT_ASSERT(result == RT_EOK);
  65. }
  66. void dfs_unlock()
  67. {
  68. rt_mutex_release(&dlock);
  69. }