From 05ba62283064c2394339fa3975fe9a4da67c12a9 Mon Sep 17 00:00:00 2001 From: bde Date: Tue, 12 Sep 1995 16:38:16 +0000 Subject: Output a zero rdev except for bdevs, cdevs, fifos and sockets. This stops regular files with unrepresentable rdevs from being rejected and makes the output independent of unpreservable metadata. --- gnu/usr.bin/cpio/copyout.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'gnu/usr.bin/cpio') diff --git a/gnu/usr.bin/cpio/copyout.c b/gnu/usr.bin/cpio/copyout.c index 933e4da..77053d9 100644 --- a/gnu/usr.bin/cpio/copyout.c +++ b/gnu/usr.bin/cpio/copyout.c @@ -294,8 +294,32 @@ process_copy_out () file_hdr.c_uid = file_stat.st_uid; file_hdr.c_gid = file_stat.st_gid; file_hdr.c_nlink = file_stat.st_nlink; - file_hdr.c_rdev_maj = major (file_stat.st_rdev); - file_hdr.c_rdev_min = minor (file_stat.st_rdev); + + /* The rdev is meaningless except for block and character + special files (POSIX standard) and perhaps fifos and + sockets. Clear it for other types of files so that + check_rdev() doesn't reject files just because stat() + put garbage in st_rdev and so that the output doesn't + depend on the garbage. */ + switch (file_hdr.c_mode & CP_IFMT) + { + case CP_IFBLK: + case CP_IFCHR: +#ifdef CP_IFIFO + case CP_IFIFO: +#endif +#ifdef CP_IFSOCK + case CP_IFSOCK: +#endif + file_hdr.c_rdev_maj = major (file_stat.st_rdev); + file_hdr.c_rdev_min = minor (file_stat.st_rdev); + break; + default: + file_hdr.c_rdev_maj = 0; + file_hdr.c_rdev_min = 0; + break; + } + file_hdr.c_mtime = file_stat.st_mtime; file_hdr.c_filesize = file_stat.st_size; file_hdr.c_chksum = 0; -- cgit v1.1