e2fsck/e2fsprogs: answer yes/no to a group of questions
PATCH 1/1 e2fsck/e2fsprogs: answer yes/no to a group of questions
Hi,
saying yes or no to all e2fsck questions can be rather annoying (yes I know -p and -y), so here's a patch to answer yes or no to a group of questions.
Cheers,
Bernd
e2fsck/e2fsck.h +8 -0
@@ -349,6 +349,14 @@ extern int e2fsck_strnlen(const char * sextern int e2fsck_strnlen (const char * s,int count);#endif +typedef enum answer { +NO =0 , +YES =1 , +YES_TO_ALL =2 , +NO_TO_ALL =3 +}answer_t ; + +/* * Procedure declarations */
e2fsck/problem.c +25 -8
@@ -1608,7 +1608,8 @@ int fix_problem(e2fsck_t ctx, problem_tstruct e2fsck_problem *ptr;struct latch_descr *ldesc =0 ;const char *message; -int def_yn, answer, ans; +int def_yn, ans; +answer_t answer;int print_answer =0 ;int suppress =0 ;
@@ -1617,6 +1618,15 @@ int fix_problem(e2fsck_t ctx, problem_tprintf (_ ("Unhandled error code (0x%x)!\n" ), code);return 0 ; } + +if (ptr->flags &PR_YES_TO_ALL ) { +printf ("%s: yes\n" ,_ (prompt[(int ) ptr->prompt])); +return YES ; + }else if (ptr->flags &PR_NO_TO_ALL ) { +printf ("%s: no\n" ,_ (prompt[(int ) ptr->prompt])); +return NO ; + } +if (!(ptr->flags &PR_CONFIG )) {char key[9 ], *new_desc;
@@ -1638,11 +1648,11 @@ int fix_problem(e2fsck_t ctx, problem_t ptr->flags |=PR_CONFIG ; } - def_yn =1 ; + def_yn =YES ;if ((ptr->flags &PR_NO_DEFAULT ) || ((ptr->flags &PR_PREEN_NO ) && (ctx->options &E2F_OPT_PREEN )) || (ctx->options &E2F_OPT_NO )) - def_yn=0 ; + def_yn=NO ;/* * Do special latch processing. This is where we ask the
@@ -1652,9 +1662,9 @@ int fix_problem(e2fsck_t ctx, problem_t ldesc =find_latch (ptr->flags &PR_LATCH_MASK );if (ldesc->question && !(ldesc->flags &PRL_LATCHED )) { ans =fix_problem (ctx, ldesc->question, pctx); -if (ans ==1 ) +if (ans ==YES ) ldesc->flags |=PRL_YES ; -if (ans ==0 ) +if (ans ==NO ) ldesc->flags |=PRL_NO ; ldesc->flags |=PRL_LATCHED ; }
@@ -1698,9 +1708,9 @@ int fix_problem(e2fsck_t ctx, problem_tif (!suppress) print_answer =1 ;if (ldesc->flags &PRL_YES ) - answer =1 ; + answer =YES ;else - answer =0 ; + answer =NO ; }else answer =ask (ctx,_ (prompt[(int ) ptr->prompt]), def_yn);if (!answer && !(ptr->flags &PR_NO_OK ))
@@ -1709,7 +1719,14 @@ int fix_problem(e2fsck_t ctx, problem_tif (print_answer)printf ("%s.\n" , answer ?_ (preen_msg[(int ) ptr->prompt]) :_ ("IGNORED" )); - + +if (answer ==YES_TO_ALL ) { + ptr->flags |=PR_YES_TO_ALL ; + answer =YES ; + }else if (answer ==NO_TO_ALL ) { + ptr->flags |=PR_NO_TO_ALL ; + answer =YES ; + } }if ((ptr->prompt ==PROMPT_ABORT ) && answer)
e2fsck/problemP.h +2 -0
@@ -41,3 +41,5 @@ struct latch_descr {#define PR_PREEN_NOHDR 0x040000/* Don't print the preen header */ #define PR_CONFIG 0x080000/* This problem has been customized from the config file */ +#define PR_NO_TO_ALL 0x100000/* Yes to all questions of this type */ +#define PR_YES_TO_ALL 0x200000/* Yes to all questions of this type */
e2fsck/util.c +37 -15
79 lines not on this page · raw message
Quoted 3 lines · Bernd Schubert
saying yes or no to all e2fsck questions can be rather annoying (yes I know -p and -y), so here's a patch to answer yes or no to a group of questions.
I've wanted something like this for quite a while already.
What would be more useful, however, is having the yes-to-all or no-to-all apply to a particular problem instead of being generic. Otherwise it isn't really different from using -y or -n. The reason that is useful is that often there is a particular problem that should all be fixed or skipped, but you want to be prompted how to fix a different problem type.
I haven't investigated, but maybe this could be implemented in the same way as a latch for every problem?
e2fsck/problem.c int fix_problem(e2fsck_t ctx, problem_t · line 1628
Quoted 7 lines
e2fsck/problem.c +7
-0+if (ptr->flags &PR_YES_TO_ALL ) { +printf ("%s: yes\n" ,_ (prompt[(int ) ptr->prompt])); +return YES ; + }else if (ptr->flags &PR_NO_TO_ALL ) { +printf ("%s: no\n" ,_ (prompt[(int ) ptr->prompt])); +return NO ; + }
The "yes" and "no" here should be "_("yes")" and "_("no")" like in ask() so they are translated.
Cheers, Andreas
--
Andreas Dilger
Principal Software Engineer
Cluster File Systems, Inc.
Quoted 5 lines · Andreas Dilger
Quoted 3 lines · Bernd Schubert
saying yes or no to all e2fsck questions can be rather annoying (yes I know -p and -y), so here's a patch to answer yes or no to a group of questions.
Quoted 7 lines
I've wanted something like this for quite a while already.
What would be more useful, however, is having the yes-to-all or no-to-all apply to a particular problem instead of being generic. Otherwise it isn't really different from using -y or -n. The reason that is useful is that often there is a particular problem that should all be fixed or skipped, but you want to be prompted how to fix a different problem type.
But isn't that what the patch is going to do?
int fix_problem(e2fsck_t ctx, problem_t code, struct problem_context *pctx) {
...
ptr = find_problem(code); // So ptr is problem specific
}
Actually there was already everything prepared, it seems someone just forgot to add a patch like this.
Quoted 12 lines
I haven't investigated, but maybe this could be implemented in the same way as a latch for every problem?
e2fsck/problem.c int fix_problem(e2fsck_t ctx, problem_t · line 1628
Quoted 7 lines
e2fsck/problem.c +7
-0+if (ptr->flags &PR_YES_TO_ALL ) { +printf ("%s: yes\n" ,_ (prompt[(int ) ptr->prompt])); +return YES ; + }else if (ptr->flags &PR_NO_TO_ALL ) { +printf ("%s: no\n" ,_ (prompt[(int ) ptr->prompt])); +return NO ; + }
Quoted 2 lines
The "yes" and "no" here should be "
_("yes")" and "_("no")" like inask()so they are translated.
Thanks, going to correct this.
Cheers,
Bernd
Quoted 2 lines · On Thursday 02 August 2007 00:28:56 Andreas Dilger wrote:
The "yes" and "no" here should be "
_("yes")" and "_("no")" like inask()so they are translated.
Corrected version attached.
Cheers,
Bernd
Signature · 2 lines
Bernd Schubert Q-Leap Networks GmbH
e2fsck/e2fsck.h +8 -0
@@ -349,6 +349,14 @@ extern int e2fsck_strnlen(const char * sextern int e2fsck_strnlen (const char * s,int count);#endif +typedef enum answer { +NO =0 , +YES =1 , +YES_TO_ALL =2 , +NO_TO_ALL =3 +}answer_t ; + +/* * Procedure declarations */
e2fsck/problem.c +25 -8
@@ -1608,7 +1608,8 @@ int fix_problem(e2fsck_t ctx, problem_tstruct e2fsck_problem *ptr;struct latch_descr *ldesc =0 ;const char *message; -int def_yn, answer, ans; +int def_yn, ans; +answer_t answer;int print_answer =0 ;int suppress =0 ;
@@ -1617,6 +1618,15 @@ int fix_problem(e2fsck_t ctx, problem_tprintf (_ ("Unhandled error code (0x%x)!\n" ), code);return 0 ; } + +if (ptr->flags &PR_YES_TO_ALL ) { +printf ("%s: %s\n" ,_ (prompt[(int ) ptr->prompt]),_ ("yes" )); +return YES ; + }else if (ptr->flags &PR_NO_TO_ALL ) { +printf (_ ("%s: %s\n" ),_ (prompt[(int ) ptr->prompt]),_ ("no" )); +return NO ; + } +if (!(ptr->flags &PR_CONFIG )) {char key[9 ], *new_desc;
@@ -1638,11 +1648,11 @@ int fix_problem(e2fsck_t ctx, problem_t ptr->flags |=PR_CONFIG ; } - def_yn =1 ; + def_yn =YES ;if ((ptr->flags &PR_NO_DEFAULT ) || ((ptr->flags &PR_PREEN_NO ) && (ctx->options &E2F_OPT_PREEN )) || (ctx->options &E2F_OPT_NO )) - def_yn=0 ; + def_yn=NO ;/* * Do special latch processing. This is where we ask the
@@ -1652,9 +1662,9 @@ int fix_problem(e2fsck_t ctx, problem_t ldesc =find_latch (ptr->flags &PR_LATCH_MASK );if (ldesc->question && !(ldesc->flags &PRL_LATCHED )) { ans =fix_problem (ctx, ldesc->question, pctx); -if (ans ==1 ) +if (ans ==YES ) ldesc->flags |=PRL_YES ; -if (ans ==0 ) +if (ans ==NO ) ldesc->flags |=PRL_NO ; ldesc->flags |=PRL_LATCHED ; }
@@ -1698,9 +1708,9 @@ int fix_problem(e2fsck_t ctx, problem_tif (!suppress) print_answer =1 ;if (ldesc->flags &PRL_YES ) - answer =1 ; + answer =YES ;else - answer =0 ; + answer =NO ; }else answer =ask (ctx,_ (prompt[(int ) ptr->prompt]), def_yn);if (!answer && !(ptr->flags &PR_NO_OK ))
@@ -1709,7 +1719,14 @@ int fix_problem(e2fsck_t ctx, problem_tif (print_answer)printf ("%s.\n" , answer ?_ (preen_msg[(int ) ptr->prompt]) :_ ("IGNORED" )); - + +if (answer ==YES_TO_ALL ) { + ptr->flags |=PR_YES_TO_ALL ; + answer =YES ; + }else if (answer ==NO_TO_ALL ) { + ptr->flags |=PR_NO_TO_ALL ; + answer =YES ; + } }if ((ptr->prompt ==PROMPT_ABORT ) && answer)
e2fsck/problemP.h +2 -0
@@ -41,3 +41,5 @@ struct latch_descr {#define PR_PREEN_NOHDR 0x040000/* Don't print the preen header */ #define PR_CONFIG 0x080000/* This problem has been customized from the config file */ +#define PR_NO_TO_ALL 0x100000/* Yes to all questions of this type */ +#define PR_YES_TO_ALL 0x200000/* Yes to all questions of this type */
e2fsck/util.c +37 -15
79 lines not on this page · raw message