basic-lib.h 872 B

123456789101112131415161718192021222324252627282930313233343536
  1. #include <stdint.h>
  2. #include <sys/types.h>
  3. typedef uint32_t ino_t;
  4. #define GNU_ATTRIBUTE(attr) __attribute__((attr))
  5. #define NORETURN GNU_ATTRIBUTE(noreturn)
  6. #define O_RDONLY (0)
  7. #define O_DIRECTORY (0x4)
  8. // dirent file types
  9. #define DT_UNKNOWN 0
  10. #define DT_FIFO 1
  11. #define DT_CHR 2
  12. #define DT_DIR 4
  13. #define DT_BLK 6
  14. #define DT_REG 8
  15. #define DT_LNK 10
  16. #define DT_SOCK 12
  17. #define DT_WHT 14
  18. #define DT_MAX (S_DT_MASK + 1) /* 16 */
  19. struct __attribute__((__packed__)) user_dirent {
  20. ino_t d_ino; // inode number
  21. uint32_t d_off; // ignored
  22. uint16_t d_reclen; // length of this struct user_dirent
  23. char d_name[1]; // file name with a padding zero
  24. // uint8_t d_type; // file type, with offset of (d_reclen - 1)
  25. };
  26. // static inline size_t getdents(int fd, struct user_dirent* buf, size_t cnt)
  27. // {
  28. // return syscall(0x08, fd, (uint32_t)buf, cnt);
  29. // }