1 /* dracut-install.c -- install files and executables
3 Copyright (C) 2012 Harald Hoyer
4 Copyright (C) 2012 Red Hat, Inc. All rights reserved.
6 This program is free software: you can redistribute it and/or modify
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with this program; If not, see <http://www.gnu.org/licenses/>.
20 #define PROGRAM_VERSION_STRING "1"
32 #define CPIO_END "TRAILER!!!"
33 #define CPIO_ENDLEN (sizeof(CPIO_END)-1)
35 static char buf
[CPIO_ENDLEN
* 2 + 1];
37 int main(int argc
, char **argv
)
43 fprintf(stderr
, "Usage: %s <file>\n", argv
[0]);
47 f
= fopen(argv
[1], "r");
50 fprintf(stderr
, "Cannot open file '%s'\n", argv
[1]);
54 s
= fread(buf
, 6, 1, f
);
56 fprintf(stderr
, "Read error from file '%s'\n", argv
[1]);
60 fseek(f
, 0, SEEK_SET
);
62 /* check, if this is a cpio archive */
63 if ((buf
[0] == 0x71 && buf
[1] == 0xc7)
64 || (buf
[0] == '0' && buf
[1] == '7' && buf
[2] == '0' && buf
[3] == '7' && buf
[4] == '0' && buf
[5] == '1')) {
67 /* Search for CPIO_END */
70 fseek(f
, pos
, SEEK_SET
);
71 buf
[sizeof(buf
) - 1] = 0;
72 s
= fread(buf
, CPIO_ENDLEN
, 2, f
);
76 h
= strstr(buf
, CPIO_END
);
78 pos
= (h
- buf
) + pos
+ CPIO_ENDLEN
;
79 fseek(f
, pos
, SEEK_SET
);
86 /* CPIO_END not found, just cat the whole file */
87 fseek(f
, 0, SEEK_SET
);
93 buf
[sizeof(buf
) - 1] = 0;
94 s
= fread(buf
, 1, sizeof(buf
) - 1, f
);
98 for (i
= 0; (i
< s
) && (buf
[i
] == 0); i
++) ;
102 fseek(f
, pos
, SEEK_SET
);
110 /* cat out the rest */
112 s
= fread(buf
, 1, sizeof(buf
), f
);
116 s
= fwrite(buf
, 1, s
, stdout
);