cpio.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  1. /* Virtual File System: GNU Tar file system.
  2. Copyright (C) 2000 The Free Software Foundation
  3. Written by: 2000 Jan Hudec
  4. $Id$
  5. This program is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Library General Public License
  7. as published by the Free Software Foundation; either version 2 of
  8. the License, or (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU Library General Public License for more details.
  13. You should have received a copy of the GNU Library General Public
  14. License along with this program; if not, write to the Free Software
  15. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  16. #include "xdirentry.h"
  17. #include "utilvfs.h"
  18. #include <glib.h>
  19. #include <errno.h>
  20. /* #include "utilvfs.h" */
  21. #include "../src/dialog.h"
  22. /* #include "cpio.h" */
  23. #include "names.h"
  24. enum {
  25. STATUS_START,
  26. STATUS_OK,
  27. STATUS_TRAIL,
  28. STATUS_FAIL,
  29. STATUS_EOF
  30. };
  31. enum {
  32. CPIO_UNKNOWN = 0, /* Not determined yet */
  33. CPIO_BIN, /* Binary format */
  34. CPIO_BINRE, /* Binary format, reverse endianity */
  35. CPIO_OLDC, /* Old ASCII format */
  36. CPIO_NEWC, /* New ASCII format */
  37. CPIO_CRC /* New ASCII format + CRC */
  38. };
  39. struct old_cpio_header
  40. {
  41. unsigned short c_magic;
  42. short c_dev;
  43. unsigned short c_ino;
  44. unsigned short c_mode;
  45. unsigned short c_uid;
  46. unsigned short c_gid;
  47. unsigned short c_nlink;
  48. short c_rdev;
  49. unsigned short c_mtimes[2];
  50. unsigned short c_namesize;
  51. unsigned short c_filesizes[2];
  52. };
  53. struct new_cpio_header
  54. {
  55. unsigned short c_magic;
  56. unsigned long c_ino;
  57. unsigned long c_mode;
  58. unsigned long c_uid;
  59. unsigned long c_gid;
  60. unsigned long c_nlink;
  61. unsigned long c_mtime;
  62. unsigned long c_filesize;
  63. long c_dev;
  64. long c_devmin;
  65. long c_rdev;
  66. long c_rdevmin;
  67. unsigned long c_namesize;
  68. unsigned long c_chksum;
  69. };
  70. struct defer_inode {
  71. struct defer_inode *next;
  72. unsigned long inumber;
  73. unsigned short device;
  74. vfs_s_inode *inode;
  75. };
  76. static int cpio_position;
  77. static int cpio_find_head(vfs *me, vfs_s_super *super);
  78. static int cpio_read_bin_head(vfs *me, vfs_s_super *super);
  79. static int cpio_read_oldc_head(vfs *me, vfs_s_super *super);
  80. static int cpio_read_crc_head(vfs *me, vfs_s_super *super);
  81. static int cpio_create_entry(vfs *me, vfs_s_super *super, struct stat *stat, char *name);
  82. static int cpio_read(void *fh, char *buffer, int count);
  83. #define CPIO_POS(super) cpio_position
  84. /* If some time reentrancy should be needed change it to */
  85. /* #define CPIO_POS(super) (super)->u.cpio.fd */
  86. #define CPIO_SEEK_SET(super, where) mc_lseek((super)->u.cpio.fd, CPIO_POS(super) = (where), SEEK_SET)
  87. #define CPIO_SEEK_CUR(super, where) mc_lseek((super)->u.cpio.fd, CPIO_POS(super) += (where), SEEK_SET)
  88. struct defer_inode * defer_find(struct defer_inode *l, struct defer_inode *i)
  89. {
  90. if(!l) return NULL;
  91. return l->inumber == i->inumber && l->device == i->device ? l :
  92. defer_find(l->next, i);
  93. }
  94. static int cpio_skip_padding(vfs_s_super *super)
  95. {
  96. switch(super->u.cpio.type) {
  97. case CPIO_BIN:
  98. case CPIO_BINRE:
  99. return CPIO_SEEK_CUR(super, (2 - (CPIO_POS(super) % 2)) % 2);
  100. case CPIO_NEWC:
  101. case CPIO_CRC:
  102. return CPIO_SEEK_CUR(super, (4 - (CPIO_POS(super) % 4)) % 4);
  103. default:
  104. g_assert_not_reached();
  105. return 42; /* & the compiler is happy :-) */
  106. }
  107. }
  108. static void cpio_free_archive(vfs *me, vfs_s_super *super)
  109. {
  110. if(super->u.cpio.fd != -1)
  111. mc_close(super->u.cpio.fd);
  112. }
  113. static int cpio_open_cpio_file(vfs *me, vfs_s_super *super, char *name)
  114. {
  115. int fd, size, type;
  116. mode_t mode;
  117. vfs_s_inode *root;
  118. if((fd = mc_open(name, O_RDONLY)) == -1) {
  119. message_2s(1, MSG_ERROR, _("Couldn't open cpio archive\n%s"), name);
  120. return -1;
  121. }
  122. super->name = g_strdup(name);
  123. super->u.cpio.fd = -1; /* for now */
  124. mc_stat(name, &(super->u.cpio.stat));
  125. super->u.cpio.type = CPIO_UNKNOWN;
  126. size = is_gunzipable(fd, &type);
  127. if(size > 0) {
  128. char *s;
  129. mc_close(fd);
  130. s = g_strconcat(name, decompress_extension(type), NULL);
  131. if((fd = mc_open(s, O_RDONLY)) == -1) {
  132. message_2s(1, MSG_ERROR, _("Couldn't open cpio archive\n%s"), s);
  133. g_free(s);
  134. return -1;
  135. }
  136. g_free(s);
  137. }
  138. super->u.cpio.fd = fd;
  139. mode = super->u.cpio.stat.st_mode & 07777;
  140. mode |= (mode & 0444) >> 2; /* set eXec where Read is */
  141. mode |= S_IFDIR;
  142. root = vfs_s_new_inode(me, super, &(super->u.cpio.stat));
  143. root->st.st_mode = mode;
  144. root->u.cpio.offset = -1;
  145. root->st.st_nlink++;
  146. root->st.st_dev = MEDATA->rdev++;
  147. vfs_s_add_dots(me, root, NULL);
  148. super->root = root;
  149. CPIO_SEEK_SET(super, 0);
  150. return fd;
  151. }
  152. static int cpio_read_head(vfs *me, vfs_s_super *super)
  153. {
  154. cpio_find_head(me, super);
  155. switch(super->u.cpio.type) {
  156. case CPIO_UNKNOWN:
  157. return -1;
  158. case CPIO_BIN:
  159. case CPIO_BINRE:
  160. return cpio_read_bin_head(me, super);
  161. case CPIO_OLDC:
  162. return cpio_read_oldc_head(me, super);
  163. case CPIO_NEWC:
  164. case CPIO_CRC:
  165. return cpio_read_crc_head(me, super);
  166. default:
  167. g_assert_not_reached();
  168. return 42; /* & the compiler is happy :-) */
  169. }
  170. }
  171. #define MAGIC_LENGTH (6) /* How many bytes we have to read ahead */
  172. #define SEEKBACK CPIO_SEEK_CUR(super, ptr - top)
  173. #define RETURN(x) return(super->u.cpio.type = (x))
  174. #define TYPEIS(x) ((super->u.cpio.type == CPIO_UNKNOWN) || (super->u.cpio.type == (x)))
  175. static int cpio_find_head(vfs *me, vfs_s_super *super)
  176. {
  177. char buf[256];
  178. int ptr = 0;
  179. int top = 0;
  180. int tmp;
  181. top = mc_read(super->u.cpio.fd, buf, 256);
  182. CPIO_POS(super) += top;
  183. for(;;) {
  184. if(ptr + MAGIC_LENGTH >= top) {
  185. if(top > 128) {
  186. memmove(buf, buf + top - 128, 128);
  187. top = 128;
  188. ptr -= top - 128;
  189. }
  190. if((tmp = mc_read(super->u.cpio.fd, buf, top)) == 0 || tmp == -1) {
  191. message_2s(1, MSG_ERROR, _("Premature end of cpio archive\n%s"), super->name);
  192. cpio_free_archive(me, super);
  193. return CPIO_UNKNOWN;
  194. }
  195. top += tmp;
  196. }
  197. if(TYPEIS(CPIO_BIN) && ((*(unsigned short *)(buf + ptr)) == 070707)) {
  198. SEEKBACK; RETURN(CPIO_BIN);
  199. } else if(TYPEIS(CPIO_BINRE) && ((*(unsigned short *)(buf + ptr)) == GUINT16_SWAP_LE_BE_CONSTANT(070707))) {
  200. SEEKBACK; RETURN(CPIO_BINRE);
  201. } else if(TYPEIS(CPIO_OLDC) && (!strncmp(buf + ptr, "070707", 6))) {
  202. SEEKBACK; RETURN(CPIO_OLDC);
  203. } else if(TYPEIS(CPIO_NEWC) && (!strncmp(buf + ptr, "070701", 6))) {
  204. SEEKBACK; RETURN(CPIO_NEWC);
  205. } else if(TYPEIS(CPIO_CRC) && (!strncmp(buf + ptr, "070702", 6))) {
  206. SEEKBACK; RETURN(CPIO_CRC);
  207. };
  208. ptr++;
  209. }
  210. }
  211. #undef RETURN
  212. #undef SEEKBACK
  213. #define HEAD_LENGTH (26)
  214. static int cpio_read_bin_head(vfs *me, vfs_s_super *super)
  215. {
  216. struct old_cpio_header buf;
  217. int len;
  218. char *name;
  219. struct stat stat;
  220. if((len = mc_read(super->u.cpio.fd, (char *)&buf, HEAD_LENGTH)) < HEAD_LENGTH)
  221. return STATUS_EOF;
  222. CPIO_POS(super) += len;
  223. if(super->u.cpio.type == CPIO_BINRE) {
  224. int i;
  225. for(i = 0; i < (HEAD_LENGTH >> 1); i++)
  226. ((short *)&buf)[i] = GUINT16_SWAP_LE_BE(((short *)&buf)[i]);
  227. }
  228. g_assert(buf.c_magic == 070707);
  229. name = g_malloc(buf.c_namesize);
  230. if((len = mc_read(super->u.cpio.fd, name, buf.c_namesize)) < buf.c_namesize)
  231. return STATUS_EOF;
  232. CPIO_POS(super) += len;
  233. cpio_skip_padding(super);
  234. if(!strcmp("TRAILER!!!", name)) { /* We got to the last record */
  235. g_free(name);
  236. return STATUS_TRAIL;
  237. }
  238. stat.st_dev = buf.c_dev;
  239. stat.st_ino = buf.c_ino;
  240. stat.st_mode = buf.c_mode;
  241. stat.st_nlink = buf.c_nlink;
  242. stat.st_uid = buf.c_uid;
  243. stat.st_gid = buf.c_gid;
  244. stat.st_rdev = buf.c_rdev;
  245. stat.st_size = (buf.c_filesizes[0] << 16) | buf.c_filesizes[1];
  246. stat.st_atime = stat.st_mtime = stat.st_ctime = (buf.c_mtimes[0] << 16) | buf.c_mtimes[1];
  247. return cpio_create_entry(me, super, &stat, name);
  248. }
  249. #undef HEAD_LENGTH
  250. #define HEAD_LENGTH (76)
  251. static int cpio_read_oldc_head(vfs *me, vfs_s_super *super)
  252. {
  253. struct new_cpio_header hd;
  254. struct stat stat;
  255. char *buf[HEAD_LENGTH + 1];
  256. int len;
  257. char *name;
  258. if((len = mc_read(super->u.cpio.fd, (void *)buf, HEAD_LENGTH)) < HEAD_LENGTH)
  259. return STATUS_EOF;
  260. CPIO_POS(super) += len;
  261. buf[HEAD_LENGTH + 1] = 0;
  262. if(sscanf((void *)buf, "070707%6lo%6lo%6lo%6lo%6lo%6lo%6lo%11lo%6lo%11lo",
  263. &hd.c_dev, &hd.c_ino, &hd.c_mode, &hd.c_uid, &hd.c_gid,
  264. &hd.c_nlink, &hd.c_rdev, &hd.c_mtime,
  265. &hd.c_namesize, &hd.c_filesize) < 10) {
  266. message_2s(1, MSG_ERROR, _("Corrupt cpio header encountered in\n%s"), super->name);
  267. return STATUS_FAIL;
  268. }
  269. name = g_malloc(hd.c_namesize);
  270. if((len = mc_read(super->u.cpio.fd, name, hd.c_namesize)) < hd.c_namesize)
  271. return STATUS_EOF;
  272. CPIO_POS(super) += len;
  273. cpio_skip_padding(super);
  274. if(!strcmp("TRAILER!!!", name)) { /* We got to the last record */
  275. g_free(name);
  276. return STATUS_TRAIL;
  277. }
  278. stat.st_dev = hd.c_dev;
  279. stat.st_ino = hd.c_ino;
  280. stat.st_mode = hd.c_mode;
  281. stat.st_nlink = hd.c_nlink;
  282. stat.st_uid = hd.c_uid;
  283. stat.st_gid = hd.c_gid;
  284. stat.st_rdev = hd.c_rdev;
  285. stat.st_size = hd.c_filesize;
  286. stat.st_atime = stat.st_mtime = stat.st_ctime = hd.c_mtime;
  287. return cpio_create_entry(me, super, &stat, name);
  288. }
  289. #undef HEAD_LENGTH
  290. #define HEAD_LENGTH (110)
  291. static int cpio_read_crc_head(vfs *me, vfs_s_super *super)
  292. {
  293. struct new_cpio_header hd;
  294. struct stat stat;
  295. char buf[HEAD_LENGTH + 1];
  296. int len;
  297. char *name;
  298. if((len = mc_read(super->u.cpio.fd, buf, HEAD_LENGTH)) < HEAD_LENGTH)
  299. return STATUS_EOF;
  300. CPIO_POS(super) += len;
  301. buf[HEAD_LENGTH + 1] = 0;
  302. if(sscanf(buf, "%6ho%8lx%8lx%8lx%8lx%8lx%8lx%8lx%8lx%8lx%8lx%8lx%8lx%8lx",
  303. &hd.c_magic, &hd.c_ino, &hd.c_mode, &hd.c_uid, &hd.c_gid,
  304. &hd.c_nlink, &hd.c_mtime, &hd.c_filesize,
  305. &hd.c_dev, &hd.c_devmin, &hd.c_rdev, &hd.c_rdevmin,
  306. &hd.c_namesize, &hd.c_chksum) < 14) {
  307. message_2s(1, MSG_ERROR, _("Corrupt cpio header encountered in\n%s"), super->name);
  308. return STATUS_FAIL;
  309. }
  310. if((super->u.cpio.type == CPIO_NEWC && hd.c_magic != 070701) ||
  311. (super->u.cpio.type == CPIO_CRC && hd.c_magic != 070702))
  312. return STATUS_FAIL;
  313. name = g_malloc(hd.c_namesize);
  314. if((len = mc_read(super->u.cpio.fd, name, hd.c_namesize)) < hd.c_namesize)
  315. return STATUS_EOF;
  316. CPIO_POS(super) += len;
  317. cpio_skip_padding(super);
  318. if(!strcmp("TRAILER!!!", name)) { /* We got to the last record */
  319. g_free(name);
  320. return STATUS_TRAIL;
  321. }
  322. stat.st_dev = (hd.c_dev << 8) + hd.c_devmin;
  323. stat.st_ino = hd.c_ino;
  324. stat.st_mode = hd.c_mode;
  325. stat.st_nlink = hd.c_nlink;
  326. stat.st_uid = hd.c_uid;
  327. stat.st_gid = hd.c_gid;
  328. stat.st_rdev = (hd.c_rdev << 8) + hd.c_rdevmin;
  329. stat.st_size = hd.c_filesize;
  330. stat.st_atime = stat.st_mtime = stat.st_ctime = hd.c_mtime;
  331. return cpio_create_entry(me, super, &stat, name);
  332. }
  333. static int cpio_create_entry(vfs *me, vfs_s_super *super, struct stat *stat, char *name)
  334. {
  335. vfs_s_inode *inode = NULL;
  336. vfs_s_inode *root = super->root;
  337. vfs_s_entry *entry = NULL;
  338. char *tn;
  339. switch (stat->st_mode & S_IFMT) { /* For case of HP/UX archives */
  340. case S_IFCHR:
  341. case S_IFBLK:
  342. #ifdef S_IFSOCK
  343. case S_IFSOCK:
  344. #endif
  345. #ifdef S_IFIFO
  346. case S_IFIFO:
  347. #endif
  348. if((stat->st_size != 0) &&
  349. (stat->st_rdev == 0x0001)) {
  350. stat->st_rdev = (unsigned) stat->st_size;
  351. stat->st_size = 0;
  352. }
  353. break;
  354. default:
  355. break;
  356. }
  357. if((stat->st_nlink > 1) &&
  358. (super->u.cpio.type == CPIO_NEWC ||
  359. super->u.cpio.type == CPIO_CRC)) { /* For case of harlinked files */
  360. struct defer_inode i, *l;
  361. i.inumber = stat->st_ino;
  362. i.device = stat->st_dev;
  363. i.inode = NULL;
  364. if((l = defer_find(super->u.cpio.defered, &i)) != NULL) {
  365. inode = l->inode;
  366. if(inode->st.st_size && stat->st_size && (inode->st.st_size != stat->st_size)) {
  367. message_3s(1, MSG_ERROR, _("Inconsistent hardlinks of\n%s\nin cpio archive\n%s"),
  368. name, super->name);
  369. inode = NULL;
  370. }
  371. }
  372. }
  373. while(name[strlen(name)-1] == PATH_SEP) name[strlen(name)-1] = 0;
  374. if((tn = strrchr(name, PATH_SEP))) {
  375. *tn = 0;
  376. root = vfs_s_find_inode(me, root, name, LINK_FOLLOW, FL_MKDIR); /* CHECKME! What function here? */
  377. *tn = PATH_SEP;
  378. tn++;
  379. } else
  380. tn = name;
  381. entry = vfs_s_find_entry_tree(me, root, tn, LINK_FOLLOW, FL_NONE); /* In case entry is already there */
  382. if(entry) { /* This shouldn't happen! (well, it can happen if there is a record for a
  383. file and than a record for a directory it is in; cpio would die with
  384. 'No such file or directory' is such case) */
  385. if(!S_ISDIR(entry->ino->st.st_mode)) { /* This can be considered archive inconsistency */
  386. message_2s(1, MSG_ERROR, _("%s contains duplicit entries! Skiping!"), super->name);
  387. } else {
  388. entry->ino->st.st_mode = stat->st_mode;
  389. entry->ino->st.st_uid = stat->st_uid;
  390. entry->ino->st.st_gid = stat->st_gid;
  391. entry->ino->st.st_atime = stat->st_atime;
  392. entry->ino->st.st_mtime = stat->st_mtime;
  393. entry->ino->st.st_ctime = stat->st_ctime;
  394. }
  395. } else { /* !entry */
  396. if(!inode) {
  397. inode = vfs_s_new_inode(me, super, stat);
  398. if((stat->st_nlink > 0) &&
  399. (super->u.cpio.type == CPIO_NEWC ||
  400. super->u.cpio.type == CPIO_CRC)) { /* For case of hardlinked files */
  401. struct defer_inode *i;
  402. i = g_new(struct defer_inode, 1);
  403. i->inumber = stat->st_ino;
  404. i->device = stat->st_dev;
  405. i->inode = inode;
  406. i->next = super->u.cpio.defered;
  407. super->u.cpio.defered = i;
  408. }
  409. }
  410. if(stat->st_size)
  411. inode->u.cpio.offset = CPIO_POS(super);
  412. entry = vfs_s_new_entry(me, tn, inode);
  413. vfs_s_insert_entry(me, root, entry);
  414. if(S_ISDIR(stat->st_mode))
  415. vfs_s_add_dots(me, inode, root);
  416. if(S_ISLNK(stat->st_mode)) {
  417. inode->linkname = g_malloc(stat->st_size + 1);
  418. if(mc_read(super->u.cpio.fd, inode->linkname, stat->st_size) < stat->st_size) {
  419. inode->linkname[0] = 0;
  420. return STATUS_EOF;
  421. }
  422. inode->linkname[stat->st_size] = 0; /* Linkname stored without terminating \0 !!! */
  423. cpio_skip_padding(super);
  424. } else {
  425. CPIO_SEEK_CUR(super, stat->st_size);
  426. }
  427. } /* !entry */
  428. return STATUS_OK;
  429. }
  430. /* Need to CPIO_SEEK_CUR to skip the file at the end of add entry!!!! */
  431. static int cpio_open_archive(vfs *me, vfs_s_super *super, char *name, char *op)
  432. {
  433. int status = STATUS_START;
  434. if(cpio_open_cpio_file(me, super, name) == -1)
  435. return -1;
  436. for(;;) {
  437. status = cpio_read_head(me, super);
  438. switch(status) {
  439. case STATUS_EOF:
  440. message_2s(1, MSG_ERROR, _("Unexpected end of file\n%s"), name);
  441. return 0;
  442. case STATUS_OK:
  443. continue;
  444. case STATUS_TRAIL:
  445. break;
  446. }
  447. break;
  448. }
  449. return 0;
  450. }
  451. /* Remaining functions are exactly same as for tarfs (and were in fact just copied) */
  452. void *cpio_super_check(vfs *me, char *archive_name, char *op)
  453. {
  454. static struct stat sb;
  455. if(mc_stat(archive_name, &sb))
  456. return NULL;
  457. return &sb;
  458. }
  459. int cpio_super_same(vfs *me, struct vfs_s_super *parc, char *archive_name, char *op, void *cookie)
  460. {
  461. struct stat *archive_stat = cookie; /* stat of main archive */
  462. if(strcmp(parc->name, archive_name)) return 0;
  463. if(vfs_uid && (!(archive_stat->st_mode & 0004)))
  464. if((archive_stat->st_gid != vfs_gid) || !(archive_stat->st_mode & 0040))
  465. if((archive_stat->st_uid != vfs_uid) || !(archive_stat->st_mode & 0400))
  466. return 0;
  467. /* Has the cached archive been changed on the disk? */
  468. if(parc->u.cpio.stat.st_mtime < archive_stat->st_mtime) { /* Yes, reload! */
  469. (*vfs_cpiofs_ops.free) ((vfsid) parc);
  470. vfs_rmstamp (&vfs_cpiofs_ops, (vfsid) parc, 0);
  471. return 2;
  472. }
  473. /* Hasn't been modified, give it a new timeout */
  474. vfs_stamp (&vfs_cpiofs_ops, (vfsid) parc);
  475. return 1;
  476. }
  477. static int cpio_read(void *fh, char *buffer, int count)
  478. {
  479. off_t begin = FH->ino->u.tar.data_offset;
  480. int fd = FH_SUPER->u.tar.fd;
  481. vfs *me = FH_SUPER->me;
  482. if (mc_lseek (fd, begin + FH->pos, SEEK_SET) !=
  483. begin + FH->pos) ERRNOR (EIO, -1);
  484. count = MIN(count, FH->ino->st.st_size - FH->pos);
  485. if ((count = mc_read (fd, buffer, count)) == -1) ERRNOR (errno, -1);
  486. FH->pos += count;
  487. return count;
  488. }
  489. static int cpio_ungetlocalcopy(vfs *me, char *path, char *local, int has_changed)
  490. {
  491. /* We do just nothing. (We are read only and do not need to free local,
  492. since it will be freed when tar archive will be freed */
  493. return 0;
  494. }
  495. static int cpio_fh_open(vfs *me, vfs_s_fh *fh, int flags, int mode)
  496. {
  497. if ((flags & O_ACCMODE) != O_RDONLY) ERRNOR (EROFS, -1);
  498. return 0;
  499. }
  500. static struct vfs_s_data cpiofs_data = {
  501. NULL,
  502. 0,
  503. 0,
  504. NULL,
  505. NULL, /* init inode */
  506. NULL, /* free inode */
  507. NULL, /* init entry */
  508. cpio_super_check,
  509. cpio_super_same,
  510. cpio_open_archive,
  511. cpio_free_archive,
  512. cpio_fh_open,
  513. NULL,
  514. vfs_s_find_entry_tree,
  515. NULL,
  516. NULL
  517. /* ??? */
  518. };
  519. vfs vfs_cpiofs_ops = {
  520. NULL, /* next pointer */
  521. "CPIO dearchiver",
  522. 0, /* flags */
  523. "ucpio", /* prefix */
  524. &cpiofs_data, /* vfs_s_data */
  525. 0, /* errno */
  526. NULL,
  527. NULL,
  528. vfs_s_fill_names,
  529. NULL,
  530. vfs_s_open,
  531. vfs_s_close,
  532. cpio_read,
  533. NULL,
  534. vfs_s_opendir,
  535. vfs_s_readdir,
  536. vfs_s_closedir,
  537. vfs_s_telldir,
  538. vfs_s_seekdir,
  539. vfs_s_stat,
  540. vfs_s_lstat,
  541. vfs_s_fstat,
  542. NULL,
  543. NULL,
  544. NULL,
  545. vfs_s_readlink,
  546. NULL,
  547. NULL,
  548. NULL,
  549. NULL,
  550. vfs_s_chdir,
  551. vfs_s_ferrno,
  552. vfs_s_lseek,
  553. NULL,
  554. vfs_s_getid,
  555. vfs_s_nothingisopen,
  556. vfs_s_free,
  557. vfs_s_getlocalcopy,
  558. cpio_ungetlocalcopy,
  559. NULL,
  560. NULL,
  561. NULL,
  562. NULL
  563. MMAPNULL
  564. };