Ticket #2097: clean up before 4.7.2 release.
[midnight-commander.git] / lib / vfs / mc-vfs / cpio.c
blobf08b0b8f61e69cc6962ec3bc05214f1a585d1b49
1 /* Virtual File System: GNU Tar file system.
2 Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2007
3 Free Software Foundation, Inc.
5 Written by: 2000 Jan Hudec
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public License
9 as published by the Free Software Foundation; either version 2 of
10 the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Library General Public License for more details.
17 You should have received a copy of the GNU Library General Public
18 License along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
21 /** \file
22 * \brief Source: Virtual File System: GNU Tar file system.
23 * \author Jan Hudec
24 * \date 2000
27 #include <config.h>
29 #include <errno.h>
30 #include <fcntl.h>
32 #include "lib/global.h"
33 #include "lib/unixcompat.h"
35 #include "src/wtools.h" /* message() */
36 #include "src/main.h" /* print_vfs_message */
37 #include "vfs.h"
39 #include "utilvfs.h"
40 #include "vfs-impl.h"
41 #include "gc.h" /* vfs_rmstamp */
42 #include "xdirentry.h"
44 enum {
45 STATUS_START,
46 STATUS_OK,
47 STATUS_TRAIL,
48 STATUS_FAIL,
49 STATUS_EOF
52 enum {
53 CPIO_UNKNOWN = 0, /* Not determined yet */
54 CPIO_BIN, /* Binary format */
55 CPIO_BINRE, /* Binary format, reverse endianity */
56 CPIO_OLDC, /* Old ASCII format */
57 CPIO_NEWC, /* New ASCII format */
58 CPIO_CRC /* New ASCII format + CRC */
61 static struct vfs_class vfs_cpiofs_ops;
63 struct old_cpio_header
65 unsigned short c_magic;
66 short c_dev;
67 unsigned short c_ino;
68 unsigned short c_mode;
69 unsigned short c_uid;
70 unsigned short c_gid;
71 unsigned short c_nlink;
72 short c_rdev;
73 unsigned short c_mtimes[2];
74 unsigned short c_namesize;
75 unsigned short c_filesizes[2];
78 struct new_cpio_header
80 unsigned short c_magic;
81 unsigned long c_ino;
82 unsigned long c_mode;
83 unsigned long c_uid;
84 unsigned long c_gid;
85 unsigned long c_nlink;
86 unsigned long c_mtime;
87 unsigned long c_filesize;
88 long c_dev;
89 long c_devmin;
90 long c_rdev;
91 long c_rdevmin;
92 unsigned long c_namesize;
93 unsigned long c_chksum;
96 struct defer_inode {
97 struct defer_inode *next;
98 unsigned long inumber;
99 unsigned short device;
100 struct vfs_s_inode *inode;
103 /* FIXME: should be off_t instead of int. */
104 static int cpio_position;
106 static int cpio_find_head(struct vfs_class *me, struct vfs_s_super *super);
107 static ssize_t cpio_read_bin_head(struct vfs_class *me, struct vfs_s_super *super);
108 static ssize_t cpio_read_oldc_head(struct vfs_class *me, struct vfs_s_super *super);
109 static ssize_t cpio_read_crc_head(struct vfs_class *me, struct vfs_s_super *super);
110 static ssize_t cpio_read(void *fh, char *buffer, int count);
112 #define CPIO_POS(super) cpio_position
113 /* If some time reentrancy should be needed change it to */
114 /* #define CPIO_POS(super) (super)->u.arch.fd */
116 #define CPIO_SEEK_SET(super, where) mc_lseek((super)->u.arch.fd, CPIO_POS(super) = (where), SEEK_SET)
117 #define CPIO_SEEK_CUR(super, where) mc_lseek((super)->u.arch.fd, CPIO_POS(super) += (where), SEEK_SET)
119 static struct defer_inode *
120 cpio_defer_find (struct defer_inode *l, struct defer_inode *i)
122 while (l && (l->inumber != i->inumber || l->device != i->device))
123 l = l->next;
124 return l;
127 static int cpio_skip_padding(struct vfs_s_super *super)
129 switch(super->u.arch.type) {
130 case CPIO_BIN:
131 case CPIO_BINRE:
132 return CPIO_SEEK_CUR(super, (2 - (CPIO_POS(super) % 2)) % 2);
133 case CPIO_NEWC:
134 case CPIO_CRC:
135 return CPIO_SEEK_CUR(super, (4 - (CPIO_POS(super) % 4)) % 4);
136 case CPIO_OLDC:
137 return CPIO_POS(super);
138 default:
139 g_assert_not_reached();
140 return 42; /* & the compiler is happy :-) */
144 static void cpio_free_archive(struct vfs_class *me, struct vfs_s_super *super)
146 struct defer_inode *l, *lnext;
148 (void) me;
150 if(super->u.arch.fd != -1)
151 mc_close(super->u.arch.fd);
152 super->u.arch.fd = -1;
153 for (l = super->u.arch.deferred; l; l = lnext) {
154 lnext = l->next;
155 g_free (l);
157 super->u.arch.deferred = NULL;
160 static int
161 cpio_open_cpio_file (struct vfs_class *me, struct vfs_s_super *super,
162 const char *name)
164 int fd, type;
165 mode_t mode;
166 struct vfs_s_inode *root;
168 fd = mc_open (name, O_RDONLY);
169 if (fd == -1) {
170 message (D_ERROR, MSG_ERROR, _("Cannot open cpio archive\n%s"), name);
171 return -1;
174 super->name = g_strdup (name);
175 super->u.arch.fd = -1; /* for now */
176 mc_stat (name, &(super->u.arch.st));
177 super->u.arch.type = CPIO_UNKNOWN;
179 type = get_compression_type (fd, name);
180 if (type != COMPRESSION_NONE) {
181 char *s;
183 mc_close (fd);
184 s = g_strconcat (name, decompress_extension (type), (char *) NULL);
185 fd = mc_open (s, O_RDONLY);
186 if (fd == -1) {
187 message (D_ERROR, MSG_ERROR, _("Cannot open cpio archive\n%s"), s);
188 g_free (s);
189 return -1;
191 g_free (s);
194 super->u.arch.fd = fd;
195 mode = super->u.arch.st.st_mode & 07777;
196 mode |= (mode & 0444) >> 2; /* set eXec where Read is */
197 mode |= S_IFDIR;
199 root = vfs_s_new_inode (me, super, &(super->u.arch.st));
200 root->st.st_mode = mode;
201 root->data_offset = -1;
202 root->st.st_nlink++;
203 root->st.st_dev = MEDATA->rdev++;
205 super->root = root;
207 CPIO_SEEK_SET (super, 0);
209 return fd;
212 static ssize_t cpio_read_head(struct vfs_class *me, struct vfs_s_super *super)
214 switch(cpio_find_head(me, super)) {
215 case CPIO_UNKNOWN:
216 return -1;
217 case CPIO_BIN:
218 case CPIO_BINRE:
219 return cpio_read_bin_head(me, super);
220 case CPIO_OLDC:
221 return cpio_read_oldc_head(me, super);
222 case CPIO_NEWC:
223 case CPIO_CRC:
224 return cpio_read_crc_head(me, super);
225 default:
226 g_assert_not_reached();
227 return 42; /* & the compiler is happy :-) */
231 #define MAGIC_LENGTH (6) /* How many bytes we have to read ahead */
232 #define SEEKBACK CPIO_SEEK_CUR(super, ptr - top)
233 #define RETURN(x) return(super->u.arch.type = (x))
234 #define TYPEIS(x) ((super->u.arch.type == CPIO_UNKNOWN) || (super->u.arch.type == (x)))
235 static int cpio_find_head(struct vfs_class *me, struct vfs_s_super *super)
237 char buf[256];
238 int ptr = 0;
239 ssize_t top;
240 ssize_t tmp;
242 top = mc_read (super->u.arch.fd, buf, 256);
243 if (top > 0)
244 CPIO_POS (super) += top;
245 for(;;) {
246 if(ptr + MAGIC_LENGTH >= top) {
247 if(top > 128) {
248 memmove(buf, buf + top - 128, 128);
249 ptr -= top - 128;
250 top = 128;
252 tmp = mc_read (super->u.arch.fd, buf, top);
253 if (tmp == 0 || tmp == -1) {
254 message (D_ERROR, MSG_ERROR, _("Premature end of cpio archive\n%s"), super->name);
255 cpio_free_archive(me, super);
256 return CPIO_UNKNOWN;
258 top += tmp;
260 if(TYPEIS(CPIO_BIN) && ((*(unsigned short *)(buf + ptr)) == 070707)) {
261 SEEKBACK; RETURN(CPIO_BIN);
262 } else if(TYPEIS(CPIO_BINRE) && ((*(unsigned short *)(buf + ptr)) == GUINT16_SWAP_LE_BE_CONSTANT(070707))) {
263 SEEKBACK; RETURN(CPIO_BINRE);
264 } else if(TYPEIS(CPIO_OLDC) && (!strncmp(buf + ptr, "070707", 6))) {
265 SEEKBACK; RETURN(CPIO_OLDC);
266 } else if(TYPEIS(CPIO_NEWC) && (!strncmp(buf + ptr, "070701", 6))) {
267 SEEKBACK; RETURN(CPIO_NEWC);
268 } else if(TYPEIS(CPIO_CRC) && (!strncmp(buf + ptr, "070702", 6))) {
269 SEEKBACK; RETURN(CPIO_CRC);
271 ptr++;
274 #undef RETURN
275 #undef SEEKBACK
277 static int
278 cpio_create_entry (struct vfs_class *me, struct vfs_s_super *super,
279 struct stat *st, char *name)
281 struct vfs_s_inode *inode = NULL;
282 struct vfs_s_inode *root = super->root;
283 struct vfs_s_entry *entry = NULL;
284 char *tn;
286 switch (st->st_mode & S_IFMT) { /* For case of HP/UX archives */
287 case S_IFCHR:
288 case S_IFBLK:
289 #ifdef S_IFSOCK
290 case S_IFSOCK:
291 #endif
292 #ifdef S_IFIFO
293 case S_IFIFO:
294 #endif
295 #ifdef S_IFNAM
296 case S_IFNAM:
297 #endif
298 if ((st->st_size != 0) && (st->st_rdev == 0x0001)) {
299 /* FIXME: representation of major/minor differs between */
300 /* different operating systems. */
301 st->st_rdev = (unsigned) st->st_size;
302 st->st_size = 0;
304 break;
305 default:
306 break;
309 if ((st->st_nlink > 1)
310 && ((super->u.arch.type == CPIO_NEWC)
311 || (super->u.arch.type == CPIO_CRC))) { /* For case of hardlinked files */
312 struct defer_inode i, *l;
313 i.inumber = st->st_ino;
314 i.device = st->st_dev;
315 i.inode = NULL;
317 l = cpio_defer_find (super->u.arch.deferred, &i);
318 if (l != NULL) {
319 inode = l->inode;
320 if (inode->st.st_size != 0 && st->st_size != 0
321 && (inode->st.st_size != st->st_size)) {
322 message (D_ERROR, MSG_ERROR,
323 _("Inconsistent hardlinks of\n%s\nin cpio archive\n%s"),
324 name, super->name);
325 inode = NULL;
326 } else if (inode->st.st_size == 0)
327 inode->st.st_size = st->st_size;
331 /* remove trailing slashes */
332 for (tn = name + strlen (name) - 1; tn >= name && *tn == PATH_SEP; tn--)
333 *tn = '\0';
335 tn = strrchr (name, PATH_SEP);
336 if (tn == NULL)
337 tn = name;
338 else if (tn == name + 1) {
339 /* started with "./" -- directory in the root of archive */
340 tn++;
341 } else {
342 *tn = '\0';
343 root = vfs_s_find_inode (me, super, name, LINK_FOLLOW, FL_MKDIR);
344 *tn = PATH_SEP;
345 tn++;
348 entry = MEDATA->find_entry (me, root, tn, LINK_FOLLOW, FL_NONE); /* In case entry is already there */
350 if (entry != NULL) {
351 /* This shouldn't happen! (well, it can happen if there is a record for a
352 file and than a record for a directory it is in; cpio would die with
353 'No such file or directory' is such case) */
355 if (!S_ISDIR (entry->ino->st.st_mode)) {
356 /* This can be considered archive inconsistency */
357 message (D_ERROR, MSG_ERROR,
358 _("%s contains duplicate entries! Skipping!"),
359 super->name);
360 } else {
361 entry->ino->st.st_mode = st->st_mode;
362 entry->ino->st.st_uid = st->st_uid;
363 entry->ino->st.st_gid = st->st_gid;
364 entry->ino->st.st_atime = st->st_atime;
365 entry->ino->st.st_mtime = st->st_mtime;
366 entry->ino->st.st_ctime = st->st_ctime;
369 g_free (name);
370 } else { /* !entry */
371 if (inode == NULL) {
372 inode = vfs_s_new_inode (me, super, st);
373 if ((st->st_nlink > 0)
374 && ((super->u.arch.type == CPIO_NEWC)
375 || (super->u.arch.type == CPIO_CRC))) {
376 /* For case of hardlinked files */
377 struct defer_inode *i;
378 i = g_new (struct defer_inode, 1);
379 i->inumber = st->st_ino;
380 i->device = st->st_dev;
381 i->inode = inode;
382 i->next = super->u.arch.deferred;
383 super->u.arch.deferred = i;
387 if (st->st_size != 0)
388 inode->data_offset = CPIO_POS (super);
390 entry = vfs_s_new_entry (me, tn, inode);
391 vfs_s_insert_entry (me, root, entry);
393 g_free (name);
395 if (!S_ISLNK (st->st_mode))
396 CPIO_SEEK_CUR (super, st->st_size);
397 else {
398 inode->linkname = g_malloc (st->st_size + 1);
400 if (mc_read (super->u.arch.fd, inode->linkname, st->st_size) < st->st_size) {
401 inode->linkname[0] = '\0';
402 return STATUS_EOF;
405 inode->linkname[st->st_size] = '\0'; /* Linkname stored without terminating \0 !!! */
406 CPIO_POS (super) += st->st_size;
407 cpio_skip_padding (super);
409 } /* !entry */
411 return STATUS_OK;
414 #define HEAD_LENGTH (26)
415 static ssize_t cpio_read_bin_head(struct vfs_class *me, struct vfs_s_super *super)
417 union {
418 struct old_cpio_header buf;
419 short shorts[HEAD_LENGTH >> 1];
420 } u;
421 ssize_t len;
422 char *name;
423 struct stat st;
425 len = mc_read (super->u.arch.fd, (char *)&u.buf, HEAD_LENGTH);
426 if (len < HEAD_LENGTH)
427 return STATUS_EOF;
428 CPIO_POS(super) += len;
429 if(super->u.arch.type == CPIO_BINRE) {
430 int i;
431 for(i = 0; i < (HEAD_LENGTH >> 1); i++)
432 u.shorts[i] = GUINT16_SWAP_LE_BE_CONSTANT(u.shorts[i]);
435 if (u.buf.c_magic != 070707 ||
436 u.buf.c_namesize == 0 || u.buf.c_namesize > MC_MAXPATHLEN) {
437 message (D_ERROR, MSG_ERROR, _("Corrupted cpio header encountered in\n%s"),
438 super->name);
439 return STATUS_FAIL;
441 name = g_malloc(u.buf.c_namesize);
442 len = mc_read (super->u.arch.fd, name, u.buf.c_namesize);
443 if (len < u.buf.c_namesize) {
444 g_free(name);
445 return STATUS_EOF;
447 name[u.buf.c_namesize - 1] = '\0';
448 CPIO_POS(super) += len;
449 cpio_skip_padding(super);
451 if(!strcmp("TRAILER!!!", name)) { /* We got to the last record */
452 g_free(name);
453 return STATUS_TRAIL;
456 st.st_dev = u.buf.c_dev;
457 st.st_ino = u.buf.c_ino;
458 st.st_mode = u.buf.c_mode;
459 st.st_nlink = u.buf.c_nlink;
460 st.st_uid = u.buf.c_uid;
461 st.st_gid = u.buf.c_gid;
462 st.st_rdev = u.buf.c_rdev;
463 st.st_size = (u.buf.c_filesizes[0] << 16) | u.buf.c_filesizes[1];
464 st.st_atime = st.st_mtime = st.st_ctime = (u.buf.c_mtimes[0] << 16) | u.buf.c_mtimes[1];
466 return cpio_create_entry(me, super, &st, name);
468 #undef HEAD_LENGTH
470 #define HEAD_LENGTH (76)
471 static ssize_t cpio_read_oldc_head(struct vfs_class *me, struct vfs_s_super *super)
473 struct new_cpio_header hd;
474 union {
475 struct stat st;
476 char buf[HEAD_LENGTH + 1];
477 } u;
478 ssize_t len;
479 char *name;
481 if (mc_read (super->u.arch.fd, u.buf, HEAD_LENGTH) != HEAD_LENGTH)
482 return STATUS_EOF;
483 CPIO_POS (super) += HEAD_LENGTH;
484 u.buf[HEAD_LENGTH] = 0;
486 if (sscanf (u.buf, "070707%6lo%6lo%6lo%6lo%6lo%6lo%6lo%11lo%6lo%11lo",
487 (unsigned long *)&hd.c_dev, &hd.c_ino, &hd.c_mode, &hd.c_uid, &hd.c_gid,
488 &hd.c_nlink, (unsigned long *)&hd.c_rdev, &hd.c_mtime,
489 &hd.c_namesize, &hd.c_filesize) < 10) {
490 message (D_ERROR, MSG_ERROR, _("Corrupted cpio header encountered in\n%s"),
491 super->name);
492 return STATUS_FAIL;
495 if (hd.c_namesize == 0 || hd.c_namesize > MC_MAXPATHLEN) {
496 message (D_ERROR, MSG_ERROR, _("Corrupted cpio header encountered in\n%s"),
497 super->name);
498 return STATUS_FAIL;
500 name = g_malloc(hd.c_namesize);
501 len = mc_read (super->u.arch.fd, name, hd.c_namesize);
502 if ((len == -1) || ((unsigned long) len < hd.c_namesize)) {
503 g_free (name);
504 return STATUS_EOF;
506 name[hd.c_namesize - 1] = '\0';
507 CPIO_POS(super) += len;
508 cpio_skip_padding(super);
510 if(!strcmp("TRAILER!!!", name)) { /* We got to the last record */
511 g_free(name);
512 return STATUS_TRAIL;
515 u.st.st_dev = hd.c_dev;
516 u.st.st_ino = hd.c_ino;
517 u.st.st_mode = hd.c_mode;
518 u.st.st_nlink = hd.c_nlink;
519 u.st.st_uid = hd.c_uid;
520 u.st.st_gid = hd.c_gid;
521 u.st.st_rdev = hd.c_rdev;
522 u.st.st_size = hd.c_filesize;
523 u.st.st_atime = u.st.st_mtime = u.st.st_ctime = hd.c_mtime;
525 return cpio_create_entry (me, super, &u.st, name);
527 #undef HEAD_LENGTH
529 #define HEAD_LENGTH (110)
530 static ssize_t
531 cpio_read_crc_head (struct vfs_class *me, struct vfs_s_super *super)
533 struct new_cpio_header hd;
534 union {
535 struct stat st;
536 char buf[HEAD_LENGTH + 1];
537 } u;
538 ssize_t len;
539 char *name;
541 if (mc_read (super->u.arch.fd, u.buf, HEAD_LENGTH) != HEAD_LENGTH)
542 return STATUS_EOF;
544 CPIO_POS (super) += HEAD_LENGTH;
545 u.buf[HEAD_LENGTH] = '\0';
547 if (sscanf (u.buf, "%6ho%8lx%8lx%8lx%8lx%8lx%8lx%8lx%8lx%8lx%8lx%8lx%8lx%8lx",
548 &hd.c_magic, &hd.c_ino, &hd.c_mode, &hd.c_uid, &hd.c_gid,
549 &hd.c_nlink, &hd.c_mtime, &hd.c_filesize,
550 (unsigned long *)&hd.c_dev, (unsigned long *)&hd.c_devmin,
551 (unsigned long *)&hd.c_rdev, (unsigned long *)&hd.c_rdevmin,
552 &hd.c_namesize, &hd.c_chksum) < 14) {
553 message (D_ERROR, MSG_ERROR, _("Corrupted cpio header encountered in\n%s"),
554 super->name);
555 return STATUS_FAIL;
558 if((super->u.arch.type == CPIO_NEWC && hd.c_magic != 070701) ||
559 (super->u.arch.type == CPIO_CRC && hd.c_magic != 070702))
560 return STATUS_FAIL;
562 if (hd.c_namesize == 0 || hd.c_namesize > MC_MAXPATHLEN) {
563 message (D_ERROR, MSG_ERROR, _("Corrupted cpio header encountered in\n%s"),
564 super->name);
565 return STATUS_FAIL;
568 name = g_malloc(hd.c_namesize);
569 len = mc_read (super->u.arch.fd, name, hd.c_namesize);
571 if ((len == -1) || ((unsigned long) len < hd.c_namesize)) {
572 g_free (name);
573 return STATUS_EOF;
575 name[hd.c_namesize - 1] = '\0';
576 CPIO_POS(super) += len;
577 cpio_skip_padding(super);
579 if (strcmp ("TRAILER!!!", name) == 0) { /* We got to the last record */
580 g_free(name);
581 return STATUS_TRAIL;
584 u.st.st_dev = makedev (hd.c_dev, hd.c_devmin);
585 u.st.st_ino = hd.c_ino;
586 u.st.st_mode = hd.c_mode;
587 u.st.st_nlink = hd.c_nlink;
588 u.st.st_uid = hd.c_uid;
589 u.st.st_gid = hd.c_gid;
590 u.st.st_rdev = makedev (hd.c_rdev, hd.c_rdevmin);
591 u.st.st_size = hd.c_filesize;
592 u.st.st_atime = u.st.st_mtime = u.st.st_ctime = hd.c_mtime;
594 return cpio_create_entry (me, super, &u.st, name);
597 /* Need to CPIO_SEEK_CUR to skip the file at the end of add entry!!!! */
599 static int
600 cpio_open_archive (struct vfs_class *me, struct vfs_s_super *super,
601 const char *name, char *op)
603 int status = STATUS_START;
605 (void) op;
607 if (cpio_open_cpio_file (me, super, name) == -1)
608 return -1;
610 for (;;) {
611 status = cpio_read_head (me, super);
613 switch (status) {
614 case STATUS_EOF:
615 message (D_ERROR, MSG_ERROR, _("Unexpected end of file\n%s"), name);
616 return 0;
617 case STATUS_OK:
618 continue;
619 case STATUS_TRAIL:
620 break;
622 break;
625 return 0;
628 /* Remaining functions are exactly same as for tarfs (and were in fact just copied) */
629 static void *
630 cpio_super_check (struct vfs_class *me, const char *archive_name, char *op)
632 static struct stat sb;
634 (void) me;
635 (void) op;
637 if (mc_stat (archive_name, &sb))
638 return NULL;
639 return &sb;
642 static int
643 cpio_super_same (struct vfs_class *me, struct vfs_s_super *parc,
644 const char *archive_name, char *op, void *cookie)
646 struct stat *archive_stat = cookie; /* stat of main archive */
648 (void) me;
649 (void) op;
651 if (strcmp (parc->name, archive_name))
652 return 0;
654 /* Has the cached archive been changed on the disk? */
655 if (parc->u.arch.st.st_mtime < archive_stat->st_mtime) {
656 /* Yes, reload! */
657 (*vfs_cpiofs_ops.free) ((vfsid) parc);
658 vfs_rmstamp (&vfs_cpiofs_ops, (vfsid) parc);
659 return 2;
661 /* Hasn't been modified, give it a new timeout */
662 vfs_stamp (&vfs_cpiofs_ops, (vfsid) parc);
663 return 1;
666 static ssize_t cpio_read(void *fh, char *buffer, int count)
668 off_t begin = FH->ino->data_offset;
669 int fd = FH_SUPER->u.arch.fd;
670 struct vfs_class *me = FH_SUPER->me;
672 if (mc_lseek (fd, begin + FH->pos, SEEK_SET) !=
673 begin + FH->pos) ERRNOR (EIO, -1);
675 count = MIN(count, FH->ino->st.st_size - FH->pos);
677 count = mc_read (fd, buffer, count);
678 if (count == -1)
679 ERRNOR (errno, -1);
681 FH->pos += count;
682 return count;
685 static int cpio_fh_open(struct vfs_class *me, struct vfs_s_fh *fh, int flags, int mode)
687 (void) fh;
688 (void) mode;
690 if ((flags & O_ACCMODE) != O_RDONLY) ERRNOR (EROFS, -1);
691 return 0;
694 void
695 init_cpiofs (void)
697 static struct vfs_s_subclass cpio_subclass;
699 cpio_subclass.flags = VFS_S_READONLY;
700 cpio_subclass.archive_check = cpio_super_check;
701 cpio_subclass.archive_same = cpio_super_same;
702 cpio_subclass.open_archive = cpio_open_archive;
703 cpio_subclass.free_archive = cpio_free_archive;
704 cpio_subclass.fh_open = cpio_fh_open;
706 vfs_s_init_class (&vfs_cpiofs_ops, &cpio_subclass);
707 vfs_cpiofs_ops.name = "cpiofs";
708 vfs_cpiofs_ops.prefix = "ucpio";
709 vfs_cpiofs_ops.read = cpio_read;
710 vfs_cpiofs_ops.setctl = NULL;
711 vfs_register_class (&vfs_cpiofs_ops);