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.
This commit is contained in:
parent
44f34e53d5
commit
dca81e0581
1 changed files with 20 additions and 6 deletions
|
@ -25,12 +25,13 @@
|
||||||
enum entry_type
|
enum entry_type
|
||||||
{ ENTRY_DIR, ENTRY_FILE, ENTRY_LINK };
|
{ ENTRY_DIR, ENTRY_FILE, ENTRY_LINK };
|
||||||
|
|
||||||
|
|
||||||
struct entry
|
struct entry
|
||||||
{
|
{
|
||||||
char *path;
|
char *path;
|
||||||
char *filename; /* point to last component in the path */
|
char *filename; /* point to last component in the path */
|
||||||
enum entry_type type; /* entry type */
|
enum entry_type type; /* entry type */
|
||||||
char *mode; /* unix mode e.g. 0755 */
|
int mode; /* unix mode e.g. 0755 */
|
||||||
char *uid;
|
char *uid;
|
||||||
char *gid;
|
char *gid;
|
||||||
char *time; /* time 1365836670.000000000 */
|
char *time; /* time 1365836670.000000000 */
|
||||||
|
@ -101,7 +102,7 @@ convert_to_entry(char *line, struct entry *entry)
|
||||||
value);
|
value);
|
||||||
}
|
}
|
||||||
} else if (strncmp(key, "mode", 5) == 0) {
|
} 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) {
|
} else if (strncmp(key, "uid", 4) == 0) {
|
||||||
entry->uid = strndup(value, MAX_LINE_SIZE);
|
entry->uid = strndup(value, MAX_LINE_SIZE);
|
||||||
} else if (strncmp(key, "gid", 4) == 0) {
|
} else if (strncmp(key, "gid", 4) == 0) {
|
||||||
|
@ -275,6 +276,19 @@ create_entries(int handle)
|
||||||
return 0;
|
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
|
static int
|
||||||
dump_entry(FILE * out, int index, char *base_dir)
|
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) {
|
if (entries[index].depth > 0) {
|
||||||
fprintf(out, "%s ", entry->filename);
|
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->uid) ? entry->uid : "0");
|
||||||
fprintf(out, " %s", (entry->gid) ? entry->gid : "0");
|
fprintf(out, " %s", (entry->gid) ? entry->gid : "0");
|
||||||
fprintf(out, "\n");
|
fprintf(out, "\n");
|
||||||
|
@ -308,15 +322,15 @@ dump_entry(FILE * out, int index, char *base_dir)
|
||||||
fprintf(out, " ");
|
fprintf(out, " ");
|
||||||
}
|
}
|
||||||
/* hack skipping the first . in the path */
|
/* hack skipping the first . in the path */
|
||||||
fprintf(out, "%s ---%s %s %s %s%s\n", entry->filename,
|
fprintf(out, "%s -%s %s %s %s%s\n", entry->filename,
|
||||||
entry->mode, entry->uid, entry->gid, base_dir,
|
parse_mode(entry->mode), entry->uid, entry->gid, base_dir,
|
||||||
&entry->path[1]);
|
&entry->path[1]);
|
||||||
} else if (entry->type == ENTRY_LINK) {
|
} else if (entry->type == ENTRY_LINK) {
|
||||||
for (space = 0; space < entries[index].depth; space++) {
|
for (space = 0; space < entries[index].depth; space++) {
|
||||||
fprintf(out, " ");
|
fprintf(out, " ");
|
||||||
}
|
}
|
||||||
/* hack skipping the first . in the path */
|
/* 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);
|
entry->link);
|
||||||
} else {
|
} else {
|
||||||
/* missing "b" and "c" for block and char device? */
|
/* missing "b" and "c" for block and char device? */
|
||||||
|
|
Loading…
Reference in a new issue