diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2019-11-14 20:16:29 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2019-11-14 20:16:29 +0200 |
commit | df55fb19be545e22d023950263ed5d0756edf81e (patch) | |
tree | db1133594ca6db2344eb337cf123369b04211f30 | |
parent | b1c85839bf1381f749dd45bf6a5a38924e3315a0 (diff) | |
download | cpio-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.
-rw-r--r-- | src/util.c | 12 |
1 files changed, 10 insertions, 2 deletions
@@ -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; |