diff -urN e2fsimage-0.2.0/src/e2fsimage.h e2fsimage-0.2.0.symlinks/src/e2fsimage.h --- e2fsimage-0.2.0/src/e2fsimage.h 2004-03-23 16:24:31 +0300 +++ e2fsimage-0.2.0.symlinks/src/e2fsimage.h 2004-12-07 22:02:26 +0300 @@ -90,7 +90,7 @@ ext2_filsys fs; ext2_ino_t curr_e2dir; const char *curr_path; - + const char *root_path; inodb_t *ino_db; uiddb_t *uid_db; uiddb_t *passwd; diff -urN e2fsimage-0.2.0/src/main.c e2fsimage-0.2.0.symlinks/src/main.c --- e2fsimage-0.2.0/src/main.c 2004-03-23 16:55:38 +0300 +++ e2fsimage-0.2.0.symlinks/src/main.c 2004-12-07 22:03:12 +0300 @@ -96,7 +96,7 @@ case 'u': e2c.default_uid = atoi(optarg); break; case 'g': e2c.default_gid = atoi(optarg); break; case 'f': e2fsfile = optarg; break; - case 'd': e2c.curr_path = optarg; break; + case 'd': e2c.root_path = e2c.curr_path = optarg; break; case 'h': usage(argv[0]); return 0; case 'n': create = 0; break; case 's': ksize = atoi(optarg); break; diff -urN e2fsimage-0.2.0/src/symlink.c e2fsimage-0.2.0.symlinks/src/symlink.c --- e2fsimage-0.2.0/src/symlink.c 2004-03-12 17:20:17 +0300 +++ e2fsimage-0.2.0.symlinks/src/symlink.c 2004-12-07 22:42:19 +0300 @@ -56,6 +56,8 @@ struct ext2_inode inode; int ret, written; char buf[BUF_SIZE]; + char * root_ptr; + char *tmpptr; off_t size = 0; struct stat s; @@ -74,6 +76,30 @@ /* populate the new inode */ ext2fs_inode_alloc_stats(e2c->fs, e2ino, 1); + + /* open the source file */ + size = readlink(e2c->curr_path, buf, BUF_SIZE); + if (size < 0 || size >= BUF_SIZE) { + fprintf(stderr, "Error reading symlink '%s': %s\n", e2c->curr_path, strerror(errno)); + return -1; + } + + e2c->cnt->softln++; + + if (e2c->root_path != NULL) { + root_ptr = strstr(buf, e2c->root_path); + if (root_ptr != buf) { + tmpptr = buf; + } else { + tmpptr = buf + strlen(e2c->root_path); + } + strcpy(buf, tmpptr); + } + + if (e2c->verbose) + printf("Copying symlink %s -> %s\n",e2c->curr_path,buf); + + s.st_size = strlen(buf); init_inode(e2c, &inode, &s); @@ -91,12 +117,23 @@ return -1; } + e2c->cnt->softln++; + + if (e2c->root_path != NULL) { + root_ptr = strstr(buf, e2c->root_path); + if (root_ptr != buf) { + tmpptr = buf; + } else { + tmpptr = buf + strlen(e2c->root_path); + } + strcpy(buf, tmpptr); + } + if (e2c->verbose) - printf("Copying symlink %s\n",e2c->curr_path); + printf("Copying symlink %i %i %s -> %s\n",strlen(buf), size, e2c->curr_path,buf); - e2c->cnt->softln++; - ret = ext2fs_file_write(e2file, buf, size, &written); + ret = ext2fs_file_write(e2file, buf, strlen(buf), &written); if (ret) { fprintf(stderr, "Error writing ext2 symlink (%s)\n", error_message(ret)); ext2fs_file_close(e2file); @@ -106,7 +143,7 @@ ext2fs_file_close(e2file); /* if this sizes differ its an inconsistency in the base filesystem */ - if (size != written) { + if (strlen(buf) != written) { fprintf(stderr, "Error 'size matters' Size:%ld, Written:%d\n", size, written); return -1; }