bcache.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. typedef struct Bbuf Bbuf;
  10. typedef struct Bcache Bcache;
  11. enum
  12. {
  13. Nbcache= 32, /* number of blocks kept in pool */
  14. };
  15. /*
  16. * block cache descriptor
  17. */
  18. struct Bbuf
  19. {
  20. Lru; /* must be first in struct */
  21. ulong bno;
  22. int inuse;
  23. Bbuf *next; /* next in dirty list */
  24. int dirty;
  25. char *data;
  26. };
  27. /*
  28. * the buffer cache
  29. */
  30. struct Bcache
  31. {
  32. Lru;
  33. int bsize; /* block size in bytes */
  34. int f; /* fd to disk */
  35. Bbuf *dfirst; /* dirty list */
  36. Bbuf *dlast;
  37. Bbuf bb[Nbcache];
  38. };
  39. int bcinit(Bcache*, int, int);
  40. Bbuf* bcalloc(Bcache*, uint32_t);
  41. Bbuf* bcread(Bcache*, uint32_t);
  42. void bcmark(Bcache*, Bbuf*);
  43. int bcwrite(Bcache*, Bbuf*);
  44. int bcsync(Bcache*);
  45. int bread(Bcache*, uint32_t, void*);
  46. int bwrite(Bcache*, uint32_t, void*);
  47. int bref(Bcache*, Bbuf*);
  48. void error(char*, ...);
  49. void warning(char*);