cpiofs.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. #include <u.h>
  10. #include <libc.h>
  11. #include <auth.h>
  12. #include <fcall.h>
  13. #include "tapefs.h"
  14. /*
  15. * File system for cpio tapes (read-only)
  16. */
  17. #define TBLOCK 512
  18. #define NBLOCK 40 /* maximum blocksize */
  19. #define DBLOCK 20 /* default blocksize */
  20. #define TNAMSIZ 100
  21. union hblock {
  22. char dummy[TBLOCK];
  23. char tbuf[Maxbuf];
  24. struct header {
  25. char magic[6];
  26. char dev[6];
  27. char ino[6];
  28. char mode[6];
  29. char uid[6];
  30. char gid[6];
  31. char nlink[6];
  32. char rdev[6];
  33. char mtime[11];
  34. char namesize[6];
  35. char size[11];
  36. } dbuf;
  37. struct hname {
  38. struct header x;
  39. char name[1];
  40. } nbuf;
  41. } dblock;
  42. int tapefile;
  43. int64_t getoct(char*, int);
  44. void
  45. populate(char *name)
  46. {
  47. int64_t offset;
  48. int32_t isabs, magic, namesize, mode;
  49. Fileinf f;
  50. tapefile = open(name, OREAD);
  51. if (tapefile<0)
  52. error("Can't open argument file");
  53. replete = 1;
  54. for (offset = 0;;) {
  55. seek(tapefile, offset, 0);
  56. if (read(tapefile, (char *)&dblock.dbuf, TBLOCK)<TBLOCK)
  57. break;
  58. magic = getoct(dblock.dbuf.magic, sizeof(dblock.dbuf.magic));
  59. if (magic != 070707){
  60. print("%lo\n", magic);
  61. error("out of phase--get help");
  62. }
  63. if (dblock.nbuf.name[0]=='\0' || strcmp(dblock.nbuf.name, "TRAILER!!!")==0)
  64. break;
  65. mode = getoct(dblock.dbuf.mode, sizeof(dblock.dbuf.mode));
  66. f.mode = mode&0777;
  67. switch(mode & 0170000) {
  68. case 0040000:
  69. f.mode |= DMDIR;
  70. break;
  71. case 0100000:
  72. break;
  73. default:
  74. f.mode = 0;
  75. break;
  76. }
  77. f.uid = getoct(dblock.dbuf.uid, sizeof(dblock.dbuf.uid));
  78. f.gid = getoct(dblock.dbuf.gid, sizeof(dblock.dbuf.gid));
  79. f.size = getoct(dblock.dbuf.size, sizeof(dblock.dbuf.size));
  80. f.mdate = getoct(dblock.dbuf.mtime, sizeof(dblock.dbuf.mtime));
  81. namesize = getoct(dblock.dbuf.namesize, sizeof(dblock.dbuf.namesize));
  82. f.addr = offset+sizeof(struct header)+namesize;
  83. isabs = dblock.nbuf.name[0]=='/';
  84. f.name = &dblock.nbuf.name[isabs];
  85. poppath(f, 1);
  86. offset += sizeof(struct header)+namesize+f.size;
  87. }
  88. }
  89. int64_t
  90. getoct(char *p, int l)
  91. {
  92. int64_t r;
  93. for (r=0; l>0; p++, l--){
  94. r <<= 3;
  95. r += *p-'0';
  96. }
  97. return r;
  98. }
  99. void
  100. dotrunc(Ram *r)
  101. {
  102. USED(r);
  103. }
  104. void
  105. docreate(Ram *r)
  106. {
  107. USED(r);
  108. }
  109. char *
  110. doread(Ram *r, int64_t off, int32_t cnt)
  111. {
  112. seek(tapefile, r->addr+off, 0);
  113. if (cnt>sizeof(dblock.tbuf))
  114. error("read too big");
  115. read(tapefile, dblock.tbuf, cnt);
  116. return dblock.tbuf;
  117. }
  118. void
  119. popdir(Ram *r)
  120. {
  121. USED(r);
  122. }
  123. void
  124. dowrite(Ram *r, char *buf, int32_t off, int32_t cnt)
  125. {
  126. USED(r); USED(buf); USED(off); USED(cnt);
  127. }
  128. int
  129. dopermw(Ram *r)
  130. {
  131. USED(r);
  132. return 0;
  133. }