1
0

Vfs.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #ifndef __NDE_VFS_H
  2. #define __NDE_VFS_H
  3. #include <bfc/platform/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. BOOL 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, BOOL Cached);
  40. VFILE *Vfopen(VFILE *f, const char *fl, const char *mode, BOOL 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