1
0

vfs.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #ifndef __NDE_VFS_H
  2. #define __NDE_VFS_H
  3. #include <foundation/types.h>
  4. #include <stdio.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. typedef struct {
  21. uint8_t *data;
  22. unsigned long ptr;
  23. unsigned long filesize;
  24. unsigned long maxsize;
  25. char *filename;
  26. char mode;
  27. int cached;
  28. int dirty;
  29. #ifdef NDE_ALLOW_NONCACHED
  30. FILE *rfile;
  31. #endif
  32. FILE *lockFile;
  33. char lockname[1024];
  34. int locks;
  35. } VFILE;
  36. #ifdef __cplusplus
  37. extern "C" {
  38. #endif
  39. VFILE *Vfnew(const char *fl, const char *mode, int Cached);
  40. VFILE *Vfopen(VFILE *f, const char *fl, const char *mode, int Cached);
  41. size_t Vfread(void *ptr, size_t size, VFILE *buf);
  42. void Vfseek(VFILE *fl, long i, int whence);
  43. unsigned long Vftell(VFILE *fl);
  44. void Vfclose(VFILE *fl);
  45. void Vfdestroy(VFILE *fl); // benski> TODO:
  46. void Vfwrite(const void *ptr, size_t size, VFILE *f);
  47. int Vfeof(VFILE *fl);
  48. int Vsync(VFILE *fl); // 1 on error updating
  49. int Vflock(VFILE *fl, bool is_sync=true); // returns 0 on failure
  50. void Vfunlock(VFILE *fl, bool is_sync=true);
  51. #ifdef __cplusplus
  52. }
  53. #endif
  54. #endif