|
78 | 78 | #include "restore.h"
|
79 | 79 | #include "process_fragments.h"
|
80 | 80 | #include "fnmatch_compat.h"
|
| 81 | +#include "fakerootdb.h" |
81 | 82 |
|
82 | 83 | int delete = FALSE;
|
83 | 84 | int quiet = FALSE;
|
@@ -266,6 +267,9 @@ int logging=FALSE;
|
266 | 267 | int tarstyle = FALSE;
|
267 | 268 | int keep_as_directory = FALSE;
|
268 | 269 |
|
| 270 | +struct fakerootdb fakerootdb; |
| 271 | +char const *fakerootdb_filename = NULL; |
| 272 | + |
269 | 273 | static char *read_from_disk(long long start, unsigned int avail_bytes);
|
270 | 274 | static void add_old_root_entry(char *name, squashfs_inode inode, int inode_number,
|
271 | 275 | int type);
|
@@ -295,6 +299,18 @@ static void write_filesystem_tables(struct squashfs_super_block *sBlk, int nopad
|
295 | 299 | unsigned short get_checksum_mem(char *buff, int bytes);
|
296 | 300 | static void check_usable_phys_mem(int total_mem);
|
297 | 301 |
|
| 302 | +static int lstat_with_fakeroot(const char *path, struct stat *stbuf) |
| 303 | +{ |
| 304 | + int err; |
| 305 | + err = lstat(path, stbuf); |
| 306 | + if (err < 0) |
| 307 | + goto out; |
| 308 | + if (!fakerootdb.db || fakerootdb.count == 0) |
| 309 | + goto out; |
| 310 | + fakeroot_override_stat(stbuf, &fakerootdb); |
| 311 | +out: |
| 312 | + return err; |
| 313 | +} |
298 | 314 |
|
299 | 315 | void prep_exit()
|
300 | 316 | {
|
@@ -3014,7 +3030,7 @@ static squashfs_inode scan_single(char *pathname, int progress)
|
3014 | 3030 | * it to the root directory dir_info structure */
|
3015 | 3031 | dir_ent = create_dir_entry("", NULL, pathname, scan1_opendir("", "", 0));
|
3016 | 3032 |
|
3017 |
| - if(lstat(pathname, &buf) == -1) |
| 3033 | + if(lstat_with_fakeroot(pathname, &buf) == -1) |
3018 | 3034 | /* source directory has disappeared? */
|
3019 | 3035 | BAD_ERROR("Cannot stat source directory %s because %s\n",
|
3020 | 3036 | pathname, strerror(errno));
|
@@ -3056,6 +3072,7 @@ static squashfs_inode scan_encomp(int progress)
|
3056 | 3072 | buf.st_mtime = time(NULL);
|
3057 | 3073 | buf.st_dev = 0;
|
3058 | 3074 | buf.st_ino = 0;
|
| 3075 | + fakeroot_override_stat(&buf, &fakerootdb); |
3059 | 3076 | dir_ent->inode = lookup_inode2(&buf, PSEUDO_FILE_OTHER, 0);
|
3060 | 3077 | dir_ent->dir = root_dir;
|
3061 | 3078 | root_dir->dir_ent = dir_ent;
|
@@ -3252,7 +3269,7 @@ static struct dir_info *dir_scan1(char *filename, char *subpath,
|
3252 | 3269 | continue;
|
3253 | 3270 | }
|
3254 | 3271 |
|
3255 |
| - if(lstat(filename, &buf) == -1) { |
| 3272 | + if(lstat_with_fakeroot(filename, &buf) == -1) { |
3256 | 3273 | ERROR_START("Cannot stat dir/file %s because %s",
|
3257 | 3274 | filename, strerror(errno));
|
3258 | 3275 | ERROR_EXIT(", ignoring\n");
|
@@ -3997,7 +4014,7 @@ static struct dir_info *add_source(struct dir_info *sdir, char *source,
|
3997 | 4014 | goto failed_early;
|
3998 | 4015 | }
|
3999 | 4016 |
|
4000 |
| - res = lstat(file, &buf); |
| 4017 | + res = lstat_with_fakeroot(file, &buf); |
4001 | 4018 | if (res == -1) {
|
4002 | 4019 | ERROR("Error: Can't stat %s because %s", file, strerror(errno));
|
4003 | 4020 | goto failed_early;
|
@@ -4248,12 +4265,13 @@ static squashfs_inode process_source(int progress)
|
4248 | 4265 | buf.st_uid = getuid();
|
4249 | 4266 | buf.st_gid = getgid();
|
4250 | 4267 | buf.st_mtime = time(NULL);
|
| 4268 | + fakeroot_override_stat(&buf, &fakerootdb); |
4251 | 4269 | entry = create_dir_entry("", NULL, "", new);
|
4252 | 4270 | entry->inode = lookup_inode2(&buf, PSEUDO_FILE_OTHER, 0);
|
4253 | 4271 | } else {
|
4254 | 4272 | char *pathname = absolute ? "/" : ".";
|
4255 | 4273 |
|
4256 |
| - if(lstat(pathname, &buf) == -1) |
| 4274 | + if(lstat_with_fakeroot(pathname, &buf) == -1) |
4257 | 4275 | BAD_ERROR("Cannot stat %s because %s\n",
|
4258 | 4276 | pathname, strerror(errno));
|
4259 | 4277 |
|
@@ -5995,6 +6013,12 @@ int main(int argc, char *argv[])
|
5995 | 6013 | exit(1);
|
5996 | 6014 | }
|
5997 | 6015 | }
|
| 6016 | + } else if(strcmp(argv[i], "-fakerootdb") == 0) { |
| 6017 | + if(++i == argc) { |
| 6018 | + ERROR("%s: -fakerootdb: missing filename\n", argv[0]); |
| 6019 | + exit(1); |
| 6020 | + } |
| 6021 | + fakerootdb_filename = argv[i]; |
5998 | 6022 | } else if(strcmp(argv[i], "-noI") == 0 ||
|
5999 | 6023 | strcmp(argv[i], "-noInodeCompression") == 0)
|
6000 | 6024 | noI = TRUE;
|
@@ -6193,6 +6217,24 @@ int main(int argc, char *argv[])
|
6193 | 6217 | strcmp(argv[i], "-log") == 0)
|
6194 | 6218 | i++;
|
6195 | 6219 |
|
| 6220 | + if (fakerootdb_filename) { |
| 6221 | + int err; |
| 6222 | + FILE *fakedata = NULL; |
| 6223 | + fakedata = fopen(fakerootdb_filename, "r"); |
| 6224 | + if (!fakedata) { |
| 6225 | + ERROR("%s: -fakerootdb: failed to open fakeroot database %s\n", |
| 6226 | + argv[0], fakerootdb_filename); |
| 6227 | + EXIT_MKSQUASHFS(); |
| 6228 | + } |
| 6229 | + err = fakeroot_read_db(fakedata, &fakerootdb); |
| 6230 | + fclose(fakedata); |
| 6231 | + if (err) { |
| 6232 | + ERROR("%s: -fakerootdb: failed to read fakeroot database %s\n", |
| 6233 | + argv[0], fakerootdb_filename); |
| 6234 | + EXIT_MKSQUASHFS(); |
| 6235 | + } |
| 6236 | + } |
| 6237 | + |
6196 | 6238 | if(!delete) {
|
6197 | 6239 | comp = read_super(fd, &sBlk, argv[source + 1]);
|
6198 | 6240 | if(comp == NULL) {
|
|
0 commit comments