dirent.rst 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. dirent.h
  2. ====================================
  3. 简介
  4. ====
  5. 与文件夹有关的头文件。
  6. 结构体列表:
  7. ===========================
  8. ``struct DIR`` :
  9. 变量列表:
  10. ``int fd`` : 文件夹id(不推荐修改)
  11. ``int buf_pos`` : 文件夹缓冲区指针的位置
  12. ``int buf_len`` : 文件夹缓冲区的大小(默认为256)
  13. ``struct dirent`` :
  14. 变量列表:
  15. ``ino_t(see libc/sys/types.h) ino`` : 文件序列号(不推荐修改)
  16. ``off_t d_off`` : dir偏移量(不推荐修改)
  17. ``unsigned short d_reclen`` : 文件夹中的记录数
  18. ``unsigned char d_type`` : 目标的类型(有可能是文件,文件夹,磁盘)
  19. ``char d_name[]`` : 目标的名字
  20. 函数列表(这里只列出已实现的函数):
  21. ===========================
  22. ``DIR opendir(const char *path)``
  23. 传入文件夹的路径,返回文件夹结构体
  24. ``int closedir(DIR *dirp)``
  25. 传入文件夹结构体,关闭文件夹,释放内存
  26. 若失败,返回-1
  27. ``dirent readdir(DIR *dir)``
  28. 传入文件夹结构体,读入文件夹里的内容,并打包为dirent结构体返回
  29. 宏定义:
  30. ===========================
  31. 文件夹类型:
  32. ``#define VFS_ATTR_FILE (1UL << 0)``
  33. ``#define VFS_ATTR_DIR (1UL << 1)``
  34. ``#define VFS_ATTR_DEVICE (1UL << 2)``
  35. 缓冲区长度的默认值
  36. ``#define DIR_BUF_SIZE 256``