Vfs.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #ifndef __NDE_VFS_H
  2. #define __NDE_VFS_H
  3. #include <bfc/platform/types.h>
  4. #include <windows.h>
  5. //#define NDE_ALLOW_NONCACHED
  6. /*
  7. #ifdef NDE_ALLOW_NONCACHED
  8. #ifndef NDE_NOWIN32FILEIO
  9. #error NDE_ALLOW_NONCACHED at least for now requires NDE_NOWIN32FILEIO
  10. #endif
  11. #endif
  12. */
  13. #define VFILE_INC 65536
  14. #define VFS_READ 1
  15. #define VFS_WRITE 2
  16. #define VFS_SEEKEOF 4
  17. #define VFS_CREATE 8
  18. #define VFS_NEWCONTENT 16
  19. #define VFS_MUSTEXIST 32
  20. #if defined(NDE_ALLOW_NONCACHED)
  21. #include "../nu/RingBuffer.h"
  22. #endif
  23. typedef struct VFILEStruct
  24. {
  25. void VFILE()
  26. {
  27. data = 0;
  28. ptr = 0;
  29. filesize = 0;
  30. maxsize = 0;
  31. filename = 0;
  32. mode = 0;
  33. cached = FALSE;
  34. dirty = 0;
  35. #ifdef NDE_ALLOW_NONCACHED
  36. #ifdef NDE_NOWIN32FILEIO
  37. rfile = 0;
  38. #else
  39. hfile = NULL;
  40. endoffile = false;
  41. r = 0;
  42. #endif
  43. #endif
  44. mutex = NULL;
  45. locks = 0;
  46. }
  47. uint8_t *data;
  48. uint32_t ptr;
  49. uint32_t filesize;
  50. uint32_t maxsize;
  51. wchar_t *filename;
  52. char mode;
  53. BOOL cached;
  54. int dirty;
  55. #ifdef NDE_ALLOW_NONCACHED
  56. #ifdef NDE_NOWIN32FILEIO
  57. FILE *rfile;
  58. #else
  59. HANDLE hfile;
  60. bool endoffile;
  61. RingBuffer r;
  62. #endif
  63. #endif
  64. HANDLE mutex;
  65. int locks;
  66. } VFILE;
  67. #ifdef __cplusplus
  68. extern "C" {
  69. #endif
  70. VFILE *Vfnew(const wchar_t *filename, const char *mode, BOOL Cached);
  71. VFILE *Vfopen(VFILE *f, wchar_t *filename, const char *mode, BOOL Cached); // filename must be an NDE string
  72. size_t Vfread(void *ptr, size_t size, VFILE *buf);
  73. void Vfseek(VFILE *fl, uint32_t i, int whence);
  74. uint32_t Vftell(VFILE *fl);
  75. void Vfclose(VFILE *fl);
  76. void Vfdestroy(VFILE *fl); // benski> TODO:
  77. void Vfwrite(const void *ptr, size_t size, VFILE *f);
  78. int Vfeof(VFILE *fl);
  79. int Vsync(VFILE *fl); // 1 on error updating
  80. int Vflock(VFILE *fl, BOOL is_sync=TRUE); // returns 0 on failure
  81. void Vfunlock(VFILE *fl, BOOL is_sync=TRUE);
  82. #ifdef __cplusplus
  83. }
  84. #endif
  85. #endif