diff --git a/files-reg.c b/files-reg.c index eb3c010bd..4045f935c 100644 --- a/files-reg.c +++ b/files-reg.c @@ -79,6 +79,17 @@ static int create_ghost(struct ghost_file *gf, GhostFileEntry *gfe, char *root, goto err; } ghost_flags = O_RDWR; /* To not block */ + } else if (S_ISCHR(gfe->mode) || S_ISBLK(gfe->mode)) { + if (!gfe->has_rdev) { + pr_err("No rdev for ghost device\n"); + goto err; + } + + if (mknod(gf->remap.path, gfe->mode, gfe->rdev)) { + pr_perror("Can't create node for ghost dev"); + goto err; + } + ghost_flags = O_WRONLY; } else ghost_flags = O_WRONLY | O_CREAT | O_EXCL; @@ -258,6 +269,11 @@ static int dump_ghost_file(int _fd, u32 id, const struct stat *st, dev_t phys_de gfe.dev = phys_dev; gfe.ino = st->st_ino; + if (S_ISCHR(st->st_mode) || S_ISBLK(st->st_mode)) { + gfe.has_rdev = true; + gfe.rdev = st->st_rdev; + } + if (pb_write_one(img, &gfe, PB_GHOST_FILE)) return -1; diff --git a/protobuf/ghost-file.proto b/protobuf/ghost-file.proto index d1946d8a8..3bfbbad49 100644 --- a/protobuf/ghost-file.proto +++ b/protobuf/ghost-file.proto @@ -5,4 +5,5 @@ message ghost_file_entry { optional uint32 dev = 4; optional uint64 ino = 5; + optional uint32 rdev = 6; }