From dca81e0581b35bccd95baf373da040926d0c6a9e Mon Sep 17 00:00:00 2001 From: Kees Jongenburger Date: Tue, 23 Apr 2013 16:51:02 +0200 Subject: [PATCH] toproto:convert special execute bits to chars Convert the special execute bits of the METALOG file mode entries into mkfs.mfs compatible u and g flags. --- usr.bin/toproto/toproto.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/usr.bin/toproto/toproto.c b/usr.bin/toproto/toproto.c index 43d83484e..1747e284a 100644 --- a/usr.bin/toproto/toproto.c +++ b/usr.bin/toproto/toproto.c @@ -25,12 +25,13 @@ enum entry_type { ENTRY_DIR, ENTRY_FILE, ENTRY_LINK }; + struct entry { char *path; char *filename; /* point to last component in the path */ enum entry_type type; /* entry type */ - char *mode; /* unix mode e.g. 0755 */ + int mode; /* unix mode e.g. 0755 */ char *uid; char *gid; char *time; /* time 1365836670.000000000 */ @@ -101,7 +102,7 @@ convert_to_entry(char *line, struct entry *entry) value); } } else if (strncmp(key, "mode", 5) == 0) { - entry->mode = strndup(value, MAX_LINE_SIZE); + sscanf(value,"%o",&entry->mode); } else if (strncmp(key, "uid", 4) == 0) { entry->uid = strndup(value, MAX_LINE_SIZE); } else if (strncmp(key, "gid", 4) == 0) { @@ -275,6 +276,19 @@ create_entries(int handle) return 0; } +char * parse_mode(int mode){ + /* Convert a 4 digit octal number int a proto entry as described in + the mkfs.mfs man page e.g. [suid-char][guid-char]0777 mode */ + + static char m[6]; + memset(m,0,6); + char suid,guid; + suid = (mode & 04000)?'u':'-'; + guid = (mode & 02000)?'g':'-'; + snprintf(m,6,"%c%c%3o",suid,guid,mode & 0777); + return m; +} + static int dump_entry(FILE * out, int index, char *base_dir) { @@ -290,7 +304,7 @@ dump_entry(FILE * out, int index, char *base_dir) if (entries[index].depth > 0) { fprintf(out, "%s ", entry->filename); } - fprintf(out, "d--%s", entry->mode); + fprintf(out, "d%s", parse_mode(entry->mode)); fprintf(out, " %s", (entry->uid) ? entry->uid : "0"); fprintf(out, " %s", (entry->gid) ? entry->gid : "0"); fprintf(out, "\n"); @@ -308,15 +322,15 @@ dump_entry(FILE * out, int index, char *base_dir) fprintf(out, " "); } /* hack skipping the first . in the path */ - fprintf(out, "%s ---%s %s %s %s%s\n", entry->filename, - entry->mode, entry->uid, entry->gid, base_dir, + fprintf(out, "%s -%s %s %s %s%s\n", entry->filename, + parse_mode(entry->mode), entry->uid, entry->gid, base_dir, &entry->path[1]); } else if (entry->type == ENTRY_LINK) { for (space = 0; space < entries[index].depth; space++) { fprintf(out, " "); } /* hack skipping the first . in the path */ - fprintf(out, "%s s--%s 0 0 %s\n", entry->filename, entry->mode, + fprintf(out, "%s s%s 0 0 %s\n", entry->filename, parse_mode(entry->mode), entry->link); } else { /* missing "b" and "c" for block and char device? */ -- 2.44.0