init.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /* Copyright (C) 2021 Rain */
  2. /* This file is part of XNIX. */
  3. /*
  4. XNIX is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) and later version.
  8. */
  9. /*
  10. XNIX is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. */
  15. /*
  16. You should have received a copy of the GNU General Public License
  17. along with XNIX. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. #ifndef INCLUDED_INIT_H
  20. #define INCLUDED_INIT_H
  21. #include <kernel/types.h>
  22. #include <kernel/errno.h>
  23. #define KERNEL_CS 0x0008
  24. #define KERNEL_DS 0x0010
  25. struct inode_desc {
  26. /* this struct is a general descriptor, so we must know
  27. * how big is it. */
  28. __uint32_t size;
  29. /* file descriptor */
  30. __uint32_t fd;
  31. /* this is optional (offset) */
  32. __uint32_t off;
  33. /* this is optional too */
  34. char *name;
  35. /* real inode saves here */
  36. void *real_inode;
  37. };
  38. struct file_operations {
  39. /* open a file */
  40. struct inode_desc * (* open) (char *, __uint32_t, __uint32_t, errno_t *);
  41. /* or create one */
  42. /* `creat` doesn't return file-descriptor, it returns errno */
  43. errno_t (* creat) (char *, __uint32_t, __uint32_t);
  44. /* `fill` fills a inode descriptor */
  45. errno_t (* fill) (char *, __uint32_t, __uint32_t, struct inode_desc *);
  46. /* read from file-descriptor */
  47. errno_t (* read) (struct inode_desc *, char *, __uint64_t);
  48. /* write to file-descriptor */
  49. errno_t (* write) (struct inode_desc *, char *, __uint64_t);
  50. /* change position */
  51. /* 'seg' = whence */
  52. #define SEEK_SET 0x0001
  53. #define SEEK_CUR 0x0002
  54. #define SEEK_END 0x0003
  55. __uint32_t (* lseek) (struct inode_desc *, __uint32_t, __uint32_t);
  56. /* close a file-descriptor */
  57. void (* close) (struct inode_desc *);
  58. };
  59. #endif