libzfs: diff: print_what() can return the symbol => get_what()

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Rich Ercolani <rincebrain@gmail.com>
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Closes #12829
This commit is contained in:
наб 2021-12-09 23:44:51 +01:00 committed by Tony Hutter
parent 70b1b5bb98
commit e9897e542d
1 changed files with 18 additions and 37 deletions

View File

@ -129,48 +129,35 @@ stream_bytes(FILE *fp, const char *string)
} }
} }
static void static char
print_what(FILE *fp, mode_t what) get_what(mode_t what)
{ {
char symbol;
switch (what & S_IFMT) { switch (what & S_IFMT) {
case S_IFBLK: case S_IFBLK:
symbol = 'B'; return ('B');
break;
case S_IFCHR: case S_IFCHR:
symbol = 'C'; return ('C');
break;
case S_IFDIR: case S_IFDIR:
symbol = '/'; return ('/');
break;
#ifdef S_IFDOOR #ifdef S_IFDOOR
case S_IFDOOR: case S_IFDOOR:
symbol = '>'; return ('>');
break;
#endif #endif
case S_IFIFO: case S_IFIFO:
symbol = '|'; return ('|');
break;
case S_IFLNK: case S_IFLNK:
symbol = '@'; return ('@');
break;
#ifdef S_IFPORT #ifdef S_IFPORT
case S_IFPORT: case S_IFPORT:
symbol = 'P'; return ('P');
break;
#endif #endif
case S_IFSOCK: case S_IFSOCK:
symbol = '='; return ('=');
break;
case S_IFREG: case S_IFREG:
symbol = 'F'; return ('F');
break;
default: default:
symbol = '?'; return ('?');
break;
} }
(void) fprintf(fp, "%c", symbol);
} }
static void static void
@ -194,10 +181,8 @@ print_rename(FILE *fp, differ_info_t *di, const char *old, const char *new,
(longlong_t)isb->zs_ctime[0], (longlong_t)isb->zs_ctime[0],
(longlong_t)isb->zs_ctime[1]); (longlong_t)isb->zs_ctime[1]);
(void) fprintf(fp, "%c\t", ZDIFF_RENAMED); (void) fprintf(fp, "%c\t", ZDIFF_RENAMED);
if (di->classify) { if (di->classify)
print_what(fp, isb->zs_mode); (void) fprintf(fp, "%c\t", get_what(isb->zs_mode));
(void) fprintf(fp, "\t");
}
print_cmn(fp, di, old); print_cmn(fp, di, old);
if (di->scripted) if (di->scripted)
(void) fprintf(fp, "\t"); (void) fprintf(fp, "\t");
@ -216,10 +201,8 @@ print_link_change(FILE *fp, differ_info_t *di, int delta, const char *file,
(longlong_t)isb->zs_ctime[0], (longlong_t)isb->zs_ctime[0],
(longlong_t)isb->zs_ctime[1]); (longlong_t)isb->zs_ctime[1]);
(void) fprintf(fp, "%c\t", ZDIFF_MODIFIED); (void) fprintf(fp, "%c\t", ZDIFF_MODIFIED);
if (di->classify) { if (di->classify)
print_what(fp, isb->zs_mode); (void) fprintf(fp, "%c\t", get_what(isb->zs_mode));
(void) fprintf(fp, "\t");
}
print_cmn(fp, di, file); print_cmn(fp, di, file);
(void) fprintf(fp, "\t(%+d)", delta); (void) fprintf(fp, "\t(%+d)", delta);
(void) fprintf(fp, "\n"); (void) fprintf(fp, "\n");
@ -234,10 +217,8 @@ print_file(FILE *fp, differ_info_t *di, char type, const char *file,
(longlong_t)isb->zs_ctime[0], (longlong_t)isb->zs_ctime[0],
(longlong_t)isb->zs_ctime[1]); (longlong_t)isb->zs_ctime[1]);
(void) fprintf(fp, "%c\t", type); (void) fprintf(fp, "%c\t", type);
if (di->classify) { if (di->classify)
print_what(fp, isb->zs_mode); (void) fprintf(fp, "%c\t", get_what(isb->zs_mode));
(void) fprintf(fp, "\t");
}
print_cmn(fp, di, file); print_cmn(fp, di, file);
(void) fprintf(fp, "\n"); (void) fprintf(fp, "\n");
} }