bcache.h 797 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. typedef struct Bbuf Bbuf;
  2. typedef struct Bcache Bcache;
  3. enum
  4. {
  5. Nbcache= 32, /* number of blocks kept in pool */
  6. };
  7. /*
  8. * block cache descriptor
  9. */
  10. struct Bbuf
  11. {
  12. Lru; /* must be first in struct */
  13. ulong bno;
  14. int inuse;
  15. Bbuf *next; /* next in dirty list */
  16. int dirty;
  17. char *data;
  18. };
  19. /*
  20. * the buffer cache
  21. */
  22. struct Bcache
  23. {
  24. Lru;
  25. int bsize; /* block size in bytes */
  26. int f; /* fd to disk */
  27. Bbuf *dfirst; /* dirty list */
  28. Bbuf *dlast;
  29. Bbuf bb[Nbcache];
  30. };
  31. int bcinit(Bcache*, int, int);
  32. Bbuf* bcalloc(Bcache*, ulong);
  33. Bbuf* bcread(Bcache*, ulong);
  34. void bcmark(Bcache*, Bbuf*);
  35. int bcwrite(Bcache*, Bbuf*);
  36. int bcsync(Bcache*);
  37. int bread(Bcache*, ulong, void*);
  38. int bwrite(Bcache*, ulong, void*);
  39. int bref(Bcache*, Bbuf*);
  40. void error(char*, ...);
  41. void warning(char*);