10 static unsigned int offset
;
11 static unsigned int ino
= 721;
13 static void push_string(const char *name
)
15 unsigned int name_len
= strlen(name
) + 1;
22 static void push_pad (void)
30 static void push_rest(const char *name
)
32 unsigned int name_len
= strlen(name
) + 1;
39 tmp_ofs
= name_len
+ 110;
47 static void push_hdr(const char *s
)
53 static void cpio_trailer(void)
56 const char name
[] = "TRAILER!!!";
58 sprintf(s
, "%s%08X%08X%08lX%08lX%08X%08lX"
59 "%08X%08X%08X%08X%08X%08X%08X",
72 (unsigned)strlen(name
) + 1, /* namesize */
77 while (offset
% 512) {
83 static void cpio_mkdir(const char *name
, unsigned int mode
,
87 time_t mtime
= time(NULL
);
89 sprintf(s
,"%s%08X%08X%08lX%08lX%08X%08lX"
90 "%08X%08X%08X%08X%08X%08X%08X",
93 S_IFDIR
| mode
, /* mode */
97 (long) mtime
, /* mtime */
103 (unsigned)strlen(name
) + 1,/* namesize */
109 static void cpio_mknod(const char *name
, unsigned int mode
,
110 uid_t uid
, gid_t gid
, int dev_type
,
111 unsigned int maj
, unsigned int min
)
114 time_t mtime
= time(NULL
);
121 sprintf(s
,"%s%08X%08X%08lX%08lX%08X%08lX"
122 "%08X%08X%08X%08X%08X%08X%08X",
123 "070701", /* magic */
126 (long) uid
, /* uid */
127 (long) gid
, /* gid */
129 (long) mtime
, /* mtime */
135 (unsigned)strlen(name
) + 1,/* namesize */
141 /* Not marked static to keep the compiler quiet, as no one uses this yet... */
142 void cpio_mkfile(const char *filename
, const char *location
,
143 unsigned int mode
, uid_t uid
, gid_t gid
)
154 retval
= stat (filename
, &buf
);
156 fprintf (stderr
, "Filename %s could not be located\n", filename
);
160 file
= open (filename
, O_RDONLY
);
162 fprintf (stderr
, "Filename %s could not be opened for reading\n", filename
);
166 filebuf
= malloc(buf
.st_size
);
168 fprintf (stderr
, "out of memory\n");
172 retval
= read (file
, filebuf
, buf
.st_size
);
174 fprintf (stderr
, "Can not read %s file\n", filename
);
178 sprintf(s
,"%s%08X%08X%08lX%08lX%08X%08lX"
179 "%08X%08X%08X%08X%08X%08X%08X",
180 "070701", /* magic */
183 (long) uid
, /* uid */
184 (long) gid
, /* gid */
186 (long) buf
.st_mtime
, /* mtime */
187 (int) buf
.st_size
, /* filesize */
192 (unsigned)strlen(location
) + 1,/* namesize */
195 push_string(location
);
198 for (i
= 0; i
< buf
.st_size
; ++i
)
199 fputc(filebuf
[i
], stdout
);
200 offset
+= buf
.st_size
;
214 int main (int argc
, char *argv
[])
216 cpio_mkdir("/dev", 0755, 0, 0);
217 cpio_mknod("/dev/console", 0600, 0, 0, 'c', 5, 1);
218 cpio_mkdir("/root", 0700, 0, 0);
223 /* silence compiler warnings */