terminate directories) is the name the file or directory will get on the
new file system.
Next comes its mode, with the first character being
-\fB\-dbc\fR for regular files, directories, block special files and character
-special files, respectively.
+\fB\-dbcs\fR for regular files, directories, block special files and character
+special files, symlinks, respectively.
The next two characters are used to specify the SETUID and SETGID bits, as
shown above.
The last three characters of the mode are the
sizeup_dir();
} else if (*p == 'b' || *p == 'c') {
+ } else if (*p == 's') {
+ zonecount++; /* Symlink contents is always stored a block */
} else {
if ((f = fopen(token[4], "r")) == NULL) {
fprintf(stderr, "%s: Can't open %s: %s\n",
incr_link(inode);
}
+void enter_symlink(ino_t inode, char *link)
+{
+ zone_t z;
+ char *buf;
+
+ buf = alloc_block();
+ z = alloc_zone();
+ strcpy(buf, link);
+ put_block((z << zone_shift), buf);
+
+ add_zone(inode, z, (size_t) strlen(link), current_time);
+
+ free(buf);
+}
+
/*================================================================
* eat_dir - recursively install directory
if (token[6]) size = atoi(token[6]);
size = block_size * size;
add_zone(n, (zone_t) (makedev(maj,min)), size, current_time);
+ } else if (*p == 's') {
+ enter_symlink(n, token[4]);
} else {
/* Regular file. Go read it. */
if ((f = open(token[4], O_RDONLY)) < 0) {
free(buf);
}
-
-
/*================================================================
* directory & inode management assist group
*===============================================================*/
if (c1 == 'd') mode |= S_IFDIR;
if (c1 == 'b') mode |= S_IFBLK;
if (c1 == 'c') mode |= S_IFCHR;
+ if (c1 == 's') mode |= S_IFLNK;
if (c1 == '-') mode |= S_IFREG;
if (c2 == 'u') mode |= S_ISUID;
if (c3 == 'g') mode |= S_ISGID;
count++;
strcpy(tempend, name);
- if (stat(temp, &st) == -1) {
+ if (lstat(temp, &st) == -1) {
fprintf(stderr, "cant get status of '%s' \n", temp);
continue;
}
fprintf(outfile, "\n");
continue;
}
+ if (mode == S_IFLNK) {
+ char linkcontent[PATH_MAX];
+ memset(linkcontent, 0, sizeof(linkcontent));
+ if(readlink(temp, linkcontent, sizeof(linkcontent)) < 0) {
+ perror("readlink");
+ exit(1);
+ }
+ fprintf(outfile, "%s%s\n", indentstr, linkcontent);
+ continue;
+ }
fprintf(outfile, " /dev/null");
fprintf(stderr,"File\n\t%s\n has an invalid mode, made empty.\n",temp);
}
(st->st_mode & S_IFMT) == S_IFDIR ? 'd' :
(st->st_mode & S_IFMT) == S_IFCHR ? 'c' :
(st->st_mode & S_IFMT) == S_IFBLK ? 'b' :
+ (st->st_mode & S_IFMT) == S_IFLNK ? 's' :
'-', /* file type */
(st->st_mode & S_ISUID) ? 'u' : '-', /* set uid */
(st->st_mode & S_ISGID) ? 'g' : '-', /* set gid */