Merge branch '2121_dir_symlink'
[kaloumi3.git] / lib / vfs / mc-vfs / cpio.c
blob82283e49295208ad14e44bd7a6722b1a0218ac45
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 if ((fd = mc_open (name, O_RDONLY)) == -1) {
169 message (D_ERROR, MSG_ERROR, _("Cannot open cpio archive\n%s"), name);
170 return -1;
173 super->name = g_strdup (name);
174 super->u.arch.fd = -1; /* for now */
175 mc_stat (name, &(super->u.arch.st));
176 super->u.arch.type = CPIO_UNKNOWN;
178 type = get_compression_type (fd, name);
179 if (type != COMPRESSION_NONE) {
180 char *s;
182 mc_close (fd);
183 s = g_strconcat (name, decompress_extension (type), (char *) NULL);
184 if ((fd = mc_open (s, O_RDONLY)) == -1) {
185 message (D_ERROR, MSG_ERROR, _("Cannot open cpio archive\n%s"), s);
186 g_free (s);
187 return -1;
189 g_free (s);
192 super->u.arch.fd = fd;
193 mode = super->u.arch.st.st_mode & 07777;
194 mode |= (mode & 0444) >> 2; /* set eXec where Read is */
195 mode |= S_IFDIR;
197 root = vfs_s_new_inode (me, super, &(super->u.arch.st));
198 root->st.st_mode = mode;
199 root->data_offset = -1;
200 root->st.st_nlink++;
201 root->st.st_dev = MEDATA->rdev++;
203 super->root = root;
205 CPIO_SEEK_SET (super, 0);
207 return fd;
210 static ssize_t cpio_read_head(struct vfs_class *me, struct vfs_s_super *super)
212 switch(cpio_find_head(me, super)) {
213 case CPIO_UNKNOWN:
214 return -1;
215 case CPIO_BIN:
216 case CPIO_BINRE:
217 return cpio_read_bin_head(me, super);
218 case CPIO_OLDC:
219 return cpio_read_oldc_head(me, super);
220 case CPIO_NEWC:
221 case CPIO_CRC:
222 return cpio_read_crc_head(me, super);
223 default:
224 g_assert_not_reached();
225 return 42; /* & the compiler is happy :-) */
229 #define MAGIC_LENGTH (6) /* How many bytes we have to read ahead */
230 #define SEEKBACK CPIO_SEEK_CUR(super, ptr - top)
231 #define RETURN(x) return(super->u.arch.type = (x))
232 #define TYPEIS(x) ((super->u.arch.type == CPIO_UNKNOWN) || (super->u.arch.type == (x)))
233 static int cpio_find_head(struct vfs_class *me, struct vfs_s_super *super)
235 char buf[256];
236 int ptr = 0;
237 ssize_t top;
238 ssize_t tmp;
240 top = mc_read (super->u.arch.fd, buf, 256);
241 if (top > 0)
242 CPIO_POS (super) += top;
243 for(;;) {
244 if(ptr + MAGIC_LENGTH >= top) {
245 if(top > 128) {
246 memmove(buf, buf + top - 128, 128);
247 ptr -= top - 128;
248 top = 128;
250 if((tmp = mc_read(super->u.arch.fd, buf, top)) == 0 || tmp == -1) {
251 message (D_ERROR, MSG_ERROR, _("Premature end of cpio archive\n%s"), super->name);
252 cpio_free_archive(me, super);
253 return CPIO_UNKNOWN;
255 top += tmp;
257 if(TYPEIS(CPIO_BIN) && ((*(unsigned short *)(buf + ptr)) == 070707)) {
258 SEEKBACK; RETURN(CPIO_BIN);
259 } else if(TYPEIS(CPIO_BINRE) && ((*(unsigned short *)(buf + ptr)) == GUINT16_SWAP_LE_BE_CONSTANT(070707))) {
260 SEEKBACK; RETURN(CPIO_BINRE);
261 } else if(TYPEIS(CPIO_OLDC) && (!strncmp(buf + ptr, "070707", 6))) {
262 SEEKBACK; RETURN(CPIO_OLDC);
263 } else if(TYPEIS(CPIO_NEWC) && (!strncmp(buf + ptr, "070701", 6))) {
264 SEEKBACK; RETURN(CPIO_NEWC);
265 } else if(TYPEIS(CPIO_CRC) && (!strncmp(buf + ptr, "070702", 6))) {
266 SEEKBACK; RETURN(CPIO_CRC);
268 ptr++;
271 #undef RETURN
272 #undef SEEKBACK
274 static int
275 cpio_create_entry (struct vfs_class *me, struct vfs_s_super *super,
276 struct stat *st, char *name)
278 struct vfs_s_inode *inode = NULL;
279 struct vfs_s_inode *root = super->root;
280 struct vfs_s_entry *entry = NULL;
281 char *tn;
283 switch (st->st_mode & S_IFMT) { /* For case of HP/UX archives */
284 case S_IFCHR:
285 case S_IFBLK:
286 #ifdef S_IFSOCK
287 case S_IFSOCK:
288 #endif
289 #ifdef S_IFIFO
290 case S_IFIFO:
291 #endif
292 #ifdef S_IFNAM
293 case S_IFNAM:
294 #endif
295 if ((st->st_size != 0) && (st->st_rdev == 0x0001)) {
296 /* FIXME: representation of major/minor differs between */
297 /* different operating systems. */
298 st->st_rdev = (unsigned) st->st_size;
299 st->st_size = 0;
301 break;
302 default:
303 break;
306 if ((st->st_nlink > 1)
307 && ((super->u.arch.type == CPIO_NEWC)
308 || (super->u.arch.type == CPIO_CRC))) { /* For case of hardlinked files */
309 struct defer_inode i, *l;
310 i.inumber = st->st_ino;
311 i.device = st->st_dev;
312 i.inode = NULL;
314 l = cpio_defer_find (super->u.arch.deferred, &i);
315 if (l != NULL) {
316 inode = l->inode;
317 if (inode->st.st_size != 0 && st->st_size != 0
318 && (inode->st.st_size != st->st_size)) {
319 message (D_ERROR, MSG_ERROR,
320 _("Inconsistent hardlinks of\n%s\nin cpio archive\n%s"),
321 name, super->name);
322 inode = NULL;
323 } else if (inode->st.st_size == 0)
324 inode->st.st_size = st->st_size;
328 /* remove trailing slashes */
329 for (tn = name + strlen (name) - 1; tn >= name && *tn == PATH_SEP; tn--)
330 *tn = '\0';
332 tn = strrchr (name, PATH_SEP);
333 if (tn == NULL)
334 tn = name;
335 else if (tn == name + 1) {
336 /* started with "./" -- directory in the root of archive */
337 tn++;
338 } else {
339 *tn = '\0';
340 root = vfs_s_find_inode (me, super, name, LINK_FOLLOW, FL_MKDIR);
341 *tn = PATH_SEP;
342 tn++;
345 entry = MEDATA->find_entry (me, root, tn, LINK_FOLLOW, FL_NONE); /* In case entry is already there */
347 if (entry != NULL) {
348 /* This shouldn't happen! (well, it can happen if there is a record for a
349 file and than a record for a directory it is in; cpio would die with
350 'No such file or directory' is such case) */
352 if (!S_ISDIR (entry->ino->st.st_mode)) {
353 /* This can be considered archive inconsistency */
354 message (D_ERROR, MSG_ERROR,
355 _("%s contains duplicate entries! Skipping!"),
356 super->name);
357 } else {
358 entry->ino->st.st_mode = st->st_mode;
359 entry->ino->st.st_uid = st->st_uid;
360 entry->ino->st.st_gid = st->st_gid;
361 entry->ino->st.st_atime = st->st_atime;
362 entry->ino->st.st_mtime = st->st_mtime;
363 entry->ino->st.st_ctime = st->st_ctime;
366 g_free (name);
367 } else { /* !entry */
368 if (inode == NULL) {
369 inode = vfs_s_new_inode (me, super, st);
370 if ((st->st_nlink > 0)
371 && ((super->u.arch.type == CPIO_NEWC)
372 || (super->u.arch.type == CPIO_CRC))) {
373 /* For case of hardlinked files */
374 struct defer_inode *i;
375 i = g_new (struct defer_inode, 1);
376 i->inumber = st->st_ino;
377 i->device = st->st_dev;
378 i->inode = inode;
379 i->next = super->u.arch.deferred;
380 super->u.arch.deferred = i;
384 if (st->st_size != 0)
385 inode->data_offset = CPIO_POS (super);
387 entry = vfs_s_new_entry (me, tn, inode);
388 vfs_s_insert_entry (me, root, entry);
390 g_free (name);
392 if (!S_ISLNK (st->st_mode))
393 CPIO_SEEK_CUR (super, st->st_size);
394 else {
395 inode->linkname = g_malloc (st->st_size + 1);
397 if (mc_read (super->u.arch.fd, inode->linkname, st->st_size) < st->st_size) {
398 inode->linkname[0] = '\0';
399 return STATUS_EOF;
402 inode->linkname[st->st_size] = '\0'; /* Linkname stored without terminating \0 !!! */
403 CPIO_POS (super) += st->st_size;
404 cpio_skip_padding (super);
406 } /* !entry */
408 return STATUS_OK;
411 #define HEAD_LENGTH (26)
412 static ssize_t cpio_read_bin_head(struct vfs_class *me, struct vfs_s_super *super)
414 union {
415 struct old_cpio_header buf;
416 short shorts[HEAD_LENGTH >> 1];
417 } u;
418 ssize_t len;
419 char *name;
420 struct stat st;
422 if((len = mc_read(super->u.arch.fd, (char *)&u.buf, HEAD_LENGTH)) < HEAD_LENGTH)
423 return STATUS_EOF;
424 CPIO_POS(super) += len;
425 if(super->u.arch.type == CPIO_BINRE) {
426 int i;
427 for(i = 0; i < (HEAD_LENGTH >> 1); i++)
428 u.shorts[i] = GUINT16_SWAP_LE_BE_CONSTANT(u.shorts[i]);
431 if (u.buf.c_magic != 070707 ||
432 u.buf.c_namesize == 0 || u.buf.c_namesize > MC_MAXPATHLEN) {
433 message (D_ERROR, MSG_ERROR, _("Corrupted cpio header encountered in\n%s"),
434 super->name);
435 return STATUS_FAIL;
437 name = g_malloc(u.buf.c_namesize);
438 if((len = mc_read(super->u.arch.fd, name, u.buf.c_namesize)) < u.buf.c_namesize) {
439 g_free(name);
440 return STATUS_EOF;
442 name[u.buf.c_namesize - 1] = '\0';
443 CPIO_POS(super) += len;
444 cpio_skip_padding(super);
446 if(!strcmp("TRAILER!!!", name)) { /* We got to the last record */
447 g_free(name);
448 return STATUS_TRAIL;
451 st.st_dev = u.buf.c_dev;
452 st.st_ino = u.buf.c_ino;
453 st.st_mode = u.buf.c_mode;
454 st.st_nlink = u.buf.c_nlink;
455 st.st_uid = u.buf.c_uid;
456 st.st_gid = u.buf.c_gid;
457 st.st_rdev = u.buf.c_rdev;
458 st.st_size = (u.buf.c_filesizes[0] << 16) | u.buf.c_filesizes[1];
459 st.st_atime = st.st_mtime = st.st_ctime = (u.buf.c_mtimes[0] << 16) | u.buf.c_mtimes[1];
461 return cpio_create_entry(me, super, &st, name);
463 #undef HEAD_LENGTH
465 #define HEAD_LENGTH (76)
466 static ssize_t cpio_read_oldc_head(struct vfs_class *me, struct vfs_s_super *super)
468 struct new_cpio_header hd;
469 union {
470 struct stat st;
471 char buf[HEAD_LENGTH + 1];
472 } u;
473 ssize_t len;
474 char *name;
476 if (mc_read (super->u.arch.fd, u.buf, HEAD_LENGTH) != HEAD_LENGTH)
477 return STATUS_EOF;
478 CPIO_POS (super) += HEAD_LENGTH;
479 u.buf[HEAD_LENGTH] = 0;
481 if (sscanf (u.buf, "070707%6lo%6lo%6lo%6lo%6lo%6lo%6lo%11lo%6lo%11lo",
482 (unsigned long *)&hd.c_dev, &hd.c_ino, &hd.c_mode, &hd.c_uid, &hd.c_gid,
483 &hd.c_nlink, (unsigned long *)&hd.c_rdev, &hd.c_mtime,
484 &hd.c_namesize, &hd.c_filesize) < 10) {
485 message (D_ERROR, MSG_ERROR, _("Corrupted cpio header encountered in\n%s"),
486 super->name);
487 return STATUS_FAIL;
490 if (hd.c_namesize == 0 || hd.c_namesize > MC_MAXPATHLEN) {
491 message (D_ERROR, MSG_ERROR, _("Corrupted cpio header encountered in\n%s"),
492 super->name);
493 return STATUS_FAIL;
495 name = g_malloc(hd.c_namesize);
496 if((len = mc_read(super->u.arch.fd, name, hd.c_namesize)) == -1 ||
497 (unsigned long) len < hd.c_namesize) {
498 g_free (name);
499 return STATUS_EOF;
501 name[hd.c_namesize - 1] = '\0';
502 CPIO_POS(super) += len;
503 cpio_skip_padding(super);
505 if(!strcmp("TRAILER!!!", name)) { /* We got to the last record */
506 g_free(name);
507 return STATUS_TRAIL;
510 u.st.st_dev = hd.c_dev;
511 u.st.st_ino = hd.c_ino;
512 u.st.st_mode = hd.c_mode;
513 u.st.st_nlink = hd.c_nlink;
514 u.st.st_uid = hd.c_uid;
515 u.st.st_gid = hd.c_gid;
516 u.st.st_rdev = hd.c_rdev;
517 u.st.st_size = hd.c_filesize;
518 u.st.st_atime = u.st.st_mtime = u.st.st_ctime = hd.c_mtime;
520 return cpio_create_entry (me, super, &u.st, name);
522 #undef HEAD_LENGTH
524 #define HEAD_LENGTH (110)
525 static ssize_t
526 cpio_read_crc_head (struct vfs_class *me, struct vfs_s_super *super)
528 struct new_cpio_header hd;
529 union {
530 struct stat st;
531 char buf[HEAD_LENGTH + 1];
532 } u;
533 ssize_t len;
534 char *name;
536 if (mc_read (super->u.arch.fd, u.buf, HEAD_LENGTH) != HEAD_LENGTH)
537 return STATUS_EOF;
539 CPIO_POS (super) += HEAD_LENGTH;
540 u.buf[HEAD_LENGTH] = '\0';
542 if (sscanf (u.buf, "%6ho%8lx%8lx%8lx%8lx%8lx%8lx%8lx%8lx%8lx%8lx%8lx%8lx%8lx",
543 &hd.c_magic, &hd.c_ino, &hd.c_mode, &hd.c_uid, &hd.c_gid,
544 &hd.c_nlink, &hd.c_mtime, &hd.c_filesize,
545 (unsigned long *)&hd.c_dev, (unsigned long *)&hd.c_devmin,
546 (unsigned long *)&hd.c_rdev, (unsigned long *)&hd.c_rdevmin,
547 &hd.c_namesize, &hd.c_chksum) < 14) {
548 message (D_ERROR, MSG_ERROR, _("Corrupted cpio header encountered in\n%s"),
549 super->name);
550 return STATUS_FAIL;
553 if((super->u.arch.type == CPIO_NEWC && hd.c_magic != 070701) ||
554 (super->u.arch.type == CPIO_CRC && hd.c_magic != 070702))
555 return STATUS_FAIL;
557 if (hd.c_namesize == 0 || hd.c_namesize > MC_MAXPATHLEN) {
558 message (D_ERROR, MSG_ERROR, _("Corrupted cpio header encountered in\n%s"),
559 super->name);
560 return STATUS_FAIL;
563 name = g_malloc(hd.c_namesize);
564 len = mc_read (super->u.arch.fd, name, hd.c_namesize);
566 if ((len == -1) || ((unsigned long) len < hd.c_namesize)) {
567 g_free (name);
568 return STATUS_EOF;
570 name[hd.c_namesize - 1] = '\0';
571 CPIO_POS(super) += len;
572 cpio_skip_padding(super);
574 if (strcmp ("TRAILER!!!", name) == 0) { /* We got to the last record */
575 g_free(name);
576 return STATUS_TRAIL;
579 u.st.st_dev = makedev (hd.c_dev, hd.c_devmin);
580 u.st.st_ino = hd.c_ino;
581 u.st.st_mode = hd.c_mode;
582 u.st.st_nlink = hd.c_nlink;
583 u.st.st_uid = hd.c_uid;
584 u.st.st_gid = hd.c_gid;
585 u.st.st_rdev = makedev (hd.c_rdev, hd.c_rdevmin);
586 u.st.st_size = hd.c_filesize;
587 u.st.st_atime = u.st.st_mtime = u.st.st_ctime = hd.c_mtime;
589 return cpio_create_entry (me, super, &u.st, name);
592 /* Need to CPIO_SEEK_CUR to skip the file at the end of add entry!!!! */
594 static int
595 cpio_open_archive (struct vfs_class *me, struct vfs_s_super *super,
596 const char *name, char *op)
598 int status = STATUS_START;
600 (void) op;
602 if (cpio_open_cpio_file (me, super, name) == -1)
603 return -1;
605 for (;;) {
606 status = cpio_read_head (me, super);
608 switch (status) {
609 case STATUS_EOF:
610 message (D_ERROR, MSG_ERROR, _("Unexpected end of file\n%s"), name);
611 return 0;
612 case STATUS_OK:
613 continue;
614 case STATUS_TRAIL:
615 break;
617 break;
620 return 0;
623 /* Remaining functions are exactly same as for tarfs (and were in fact just copied) */
624 static void *
625 cpio_super_check (struct vfs_class *me, const char *archive_name, char *op)
627 static struct stat sb;
629 (void) me;
630 (void) op;
632 if (mc_stat (archive_name, &sb))
633 return NULL;
634 return &sb;
637 static int
638 cpio_super_same (struct vfs_class *me, struct vfs_s_super *parc,
639 const char *archive_name, char *op, void *cookie)
641 struct stat *archive_stat = cookie; /* stat of main archive */
643 (void) me;
644 (void) op;
646 if (strcmp (parc->name, archive_name))
647 return 0;
649 /* Has the cached archive been changed on the disk? */
650 if (parc->u.arch.st.st_mtime < archive_stat->st_mtime) {
651 /* Yes, reload! */
652 (*vfs_cpiofs_ops.free) ((vfsid) parc);
653 vfs_rmstamp (&vfs_cpiofs_ops, (vfsid) parc);
654 return 2;
656 /* Hasn't been modified, give it a new timeout */
657 vfs_stamp (&vfs_cpiofs_ops, (vfsid) parc);
658 return 1;
661 static ssize_t cpio_read(void *fh, char *buffer, int count)
663 off_t begin = FH->ino->data_offset;
664 int fd = FH_SUPER->u.arch.fd;
665 struct vfs_class *me = FH_SUPER->me;
667 if (mc_lseek (fd, begin + FH->pos, SEEK_SET) !=
668 begin + FH->pos) ERRNOR (EIO, -1);
670 count = MIN(count, FH->ino->st.st_size - FH->pos);
672 if ((count = mc_read (fd, buffer, count)) == -1) ERRNOR (errno, -1);
674 FH->pos += count;
675 return count;
678 static int cpio_fh_open(struct vfs_class *me, struct vfs_s_fh *fh, int flags, int mode)
680 (void) fh;
681 (void) mode;
683 if ((flags & O_ACCMODE) != O_RDONLY) ERRNOR (EROFS, -1);
684 return 0;
687 void
688 init_cpiofs (void)
690 static struct vfs_s_subclass cpio_subclass;
692 cpio_subclass.flags = VFS_S_READONLY;
693 cpio_subclass.archive_check = cpio_super_check;
694 cpio_subclass.archive_same = cpio_super_same;
695 cpio_subclass.open_archive = cpio_open_archive;
696 cpio_subclass.free_archive = cpio_free_archive;
697 cpio_subclass.fh_open = cpio_fh_open;
699 vfs_s_init_class (&vfs_cpiofs_ops, &cpio_subclass);
700 vfs_cpiofs_ops.name = "cpiofs";
701 vfs_cpiofs_ops.prefix = "ucpio";
702 vfs_cpiofs_ops.read = cpio_read;
703 vfs_cpiofs_ops.setctl = NULL;
704 vfs_register_class (&vfs_cpiofs_ops);