tapefs.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. #define g2byte(x) (((x)[1]<<8) + (x)[0]) /* little-endian */
  10. #define g3byte(x) (((x)[2]<<16) + ((x)[1]<<8) + (x)[0])
  11. #define g4byte(x) (((x)[3]<<24) + ((x)[2]<<16) + ((x)[1]<<8) + (x)[0])
  12. /* big endian */
  13. #define b4byte(x) (((x)[0]<<24) + ((x)[1]<<16) + ((x)[2]<<8) + (x)[3])
  14. #define b8byte(x) (((vlong)b4byte(x)<<32) | (u32int)b4byte((x)+4))
  15. enum
  16. {
  17. OPERM = 0x3, /* mask of all permission types in open mode */
  18. Nram = 512,
  19. Maxbuf = 8192, /* max buffer size */
  20. };
  21. typedef struct Fid Fid;
  22. typedef struct Ram Ram;
  23. struct Fid
  24. {
  25. short busy;
  26. short open;
  27. short rclose;
  28. int fid;
  29. Fid *next;
  30. char *user;
  31. Ram *ram;
  32. };
  33. struct Ram
  34. {
  35. char busy;
  36. char open;
  37. char replete;
  38. Ram *parent; /* parent directory */
  39. Ram *child; /* first member of directory */
  40. Ram *next; /* next member of file's directory */
  41. Qid qid;
  42. long perm;
  43. char *name;
  44. uint32_t atime;
  45. uint32_t mtime;
  46. char *user;
  47. char *group;
  48. vlong addr;
  49. void *data;
  50. vlong ndata;
  51. };
  52. enum
  53. {
  54. Pexec = 1,
  55. Pwrite = 2,
  56. Pread = 4,
  57. Pother = 1,
  58. Pgroup = 8,
  59. Powner = 64,
  60. };
  61. typedef struct idmap {
  62. char *name;
  63. int id;
  64. } Idmap;
  65. typedef struct fileinf {
  66. char *name;
  67. vlong addr;
  68. void *data;
  69. vlong size;
  70. int mode;
  71. int uid;
  72. int gid;
  73. long mdate;
  74. } Fileinf;
  75. extern uint32_t path; /* incremented for each new file */
  76. extern Ram *ram;
  77. extern char *user;
  78. extern Idmap *uidmap;
  79. extern Idmap *gidmap;
  80. extern int replete;
  81. extern int blocksize;
  82. void error(char*);
  83. void *erealloc(void*, uint32_t);
  84. void *emalloc(uint32_t);
  85. char *estrdup(char*);
  86. void populate(char *);
  87. void dotrunc(Ram*);
  88. void docreate(Ram*);
  89. char *doread(Ram*, vlong, long);
  90. void dowrite(Ram*, char*, long, long);
  91. int dopermw(Ram*);
  92. Idmap *getpass(char*);
  93. char *mapid(Idmap*,int);
  94. Ram *poppath(Fileinf fi, int new);
  95. Ram *popfile(Ram *dir, Fileinf fi);
  96. void popdir(Ram*);
  97. Ram *lookup(Ram*, char*);