summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org>2019-11-14 18:16:29 (GMT)
committer Sergey Poznyakoff <gray@gnu.org>2019-11-14 18:16:29 (GMT)
commitdf55fb19be545e22d023950263ed5d0756edf81e (patch) (side-by-side diff)
treedb1133594ca6db2344eb337cf123369b04211f30
parentb1c85839bf1381f749dd45bf6a5a38924e3315a0 (diff)
downloadcpio-df55fb19be545e22d023950263ed5d0756edf81e.tar.gz
cpio-df55fb19be545e22d023950263ed5d0756edf81e.tar.bz2
Fix handling of device numbers on copy out.
Device minor and major numbers are meaningful only for devices. Don't attempt to store them for other files. Instead fill the corresponding fields with zeros. * src/util.c (stat_to_cpio): Initialize c_rdev_maj and c_rdev_min from struct stat only if the file is a device, otherwise set them to zero.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--src/util.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/util.c b/src/util.c
index 4421b20..2c202b1 100644
--- a/src/util.c
+++ b/src/util.c
@@ -1140,8 +1140,16 @@ stat_to_cpio (struct cpio_file_stat *hdr, struct stat *st)
hdr->c_nlink = st->st_nlink;
hdr->c_uid = CPIO_UID (st->st_uid);
hdr->c_gid = CPIO_GID (st->st_gid);
- hdr->c_rdev_maj = major (st->st_rdev);
- hdr->c_rdev_min = minor (st->st_rdev);
+ if (S_ISBLK (st->st_mode) || S_ISCHR (st->st_mode))
+ {
+ hdr->c_rdev_maj = major (st->st_rdev);
+ hdr->c_rdev_min = minor (st->st_rdev);
+ }
+ else
+ {
+ hdr->c_rdev_maj = 0;
+ hdr->c_rdev_min = 0;
+ }
hdr->c_mtime = st->st_mtime;
hdr->c_filesize = st->st_size;
hdr->c_chksum = 0;

Return to:

Send suggestions and report system problems to the System administrator.