gfs2-utils build: Fix reporting lack of check
PATCH 1/7 gfs2-utils build: Fix reporting lack of check
Make configure.ac test the correct variable to conditionally warn of the absence of 'check'.
--- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
configure.ac +1 -1
@@ -278,4 +278,4 @@ AC_CONFIG_FILES([Makefile AC_OUTPUT -test x"$BUILD_TESTS" = x && AC_MSG_NOTICE([package 'check' not found; unit tests will not be built]) +test x"$have_check" = "xyes" || AC_MSG_NOTICE([package 'check' not found; unit tests will not be built])
Signature · 1 line
1.8.1.4
PATCH 2/7 gfs2l: Improve usage message and opt handling
Tweak the usage message and add a help option to print it on demand.
--- gfs2/libgfs2/gfs2l.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-)
gfs2/libgfs2/gfs2l.c +17 -4
@@ -5,19 +5,23 @@static void usage (const char *cmd) { -fprintf (stderr,"Usage: %s -f <script_path> <fs_path>\n" , cmd); -fprintf (stderr,"Use -f - for stdin\n" ); +printf ("A language for modifying and querying a gfs2 file system.\n" ); +printf ("Usage: %s [options] <fs_path>\n" , cmd); +printf ("Available options:\n" ); +printf (" -h Print this help message and exit\n" ); +printf (" -f <script_path> Path to script file or '-' for stdin\n" ); }struct cmdopts {char *fspath;FILE *src; +unsigned help:1 ; };static int getopts (int argc,char *argv[],struct cmdopts *opts) {int opt; -while ((opt =getopt (argc, argv,"f:" )) !=-1 ) { +while ((opt =getopt (argc, argv,"f:h" )) !=-1 ) {switch (opt) {case 'f' :if (!strcmp ("-" , optarg)) {
@@ -30,14 +34,18 @@ static int getopts(int argc, char *argv[], struct cmdopts *opts) } }break ; +case 'h' : + opts->help =1 ; +return 0 ;default : -usage (argv[0 ]); +fprintf (stderr,"Use -h for help\n" );return 1 ; } }if (argc - optind !=1 ) {usage (argv[0 ]); +fprintf (stderr,"Missing file system path. Use -h for help.\n" );return 1 ; }
@@ -106,6 +114,11 @@ int main(int argc, char *argv[])exit (1 ); } +if (opts.help) { +usage (argv[0 ]); +exit (0 ); + } + sdp =openfs (argv[optind]);if (sdp ==NULL ) {exit (1 );
Signature · 1 line
1.8.1.4
PATCH 3/7 gfs2l: Enable setting the type of a block
In reply to Andrew PriceThis adds an optional type specifier to the set statement so that when you do
set 12345 <type> { ... }
the block's meta header fields will be set to that of <type> where <type> is a structure name e.g. gfs2_rgrp.
This is useful for setting unallocated blocks to a certain block type as the type can't be inferred from an existing meta header.
--- gfs2/libgfs2/lang.c | 41 ++++++++++++++++++++++++++++++++++------- gfs2/libgfs2/lang.h | 1 + gfs2/libgfs2/libgfs2.h | 1 + gfs2/libgfs2/meta.c | 15 +++++++++++++++ gfs2/libgfs2/parser.y | 12 ++++++++++++ 5 files changed, 63 insertions(+), 7 deletions(-)
gfs2/libgfs2/lang.c +34 -7
@@ -27,6 +27,7 @@ const char* ast_type_string[] = { [AST_EX_BLOCKSPEC] = "BLOCKSPEC", [AST_EX_STRUCTSPEC] = "STRUCTSPEC", [AST_EX_FIELDSPEC] = "FIELDSPEC", + [AST_EX_TYPESPEC] = "TYPESPEC",// Keywords [AST_KW_STATE] = "STATE",
@@ -64,6 +65,7 @@ static int ast_expr_init(struct ast_node *expr, ast_node_t type, const char *strcase AST_EX_BLOCKSPEC :case AST_EX_STRUCTSPEC :case AST_EX_FIELDSPEC : +case AST_EX_TYPESPEC :case AST_KW_STATE :break ;default :
@@ -173,7 +175,6 @@ static uint64_t ast_lookup_path(char *path, struct gfs2_sbd *sbd) segment =strtok_r (NULL ,"/" , &c); } -perror ("Path lookup" );return 0 ; }
@@ -263,6 +264,8 @@ static uint64_t ast_lookup_block_num(struct ast_node *ast, struct gfs2_sbd *sbd) bn =ast_lookup_block_num (ast->ast_left, sbd) + ast->ast_num;break ;case AST_EX_ADDRESS : +if (gfs2_check_range (sbd, ast->ast_num)) +break ; bn = ast->ast_num;break ;case AST_EX_PATH :
@@ -284,6 +287,7 @@ static struct gfs2_buffer_head *ast_lookup_block(struct ast_node *node, struct g {uint64_t bn =ast_lookup_block_num (node, sbd);if (bn ==0 ) { +fprintf (stderr,"Block not found: %s\n" , node->ast_text);return NULL ; }
@@ -526,6 +530,23 @@ static int ast_field_set(struct gfs2_buffer_head *bh, const struct lgfs2_metafiereturn AST_INTERP_INVAL ; } +static const struct lgfs2_metadata *lang_find_mtype (struct ast_node *node,struct gfs2_buffer_head *bh,unsigned ver) +{ +const struct lgfs2_metadata *mtype =NULL ; + +if (node->ast_type ==AST_EX_TYPESPEC ) { + mtype =lgfs2_find_mtype_name (node->ast_str, ver); +if (mtype ==NULL ) +fprintf (stderr,"Invalid block type: %s\n" , node->ast_text); + }else { + mtype =lgfs2_find_mtype (lgfs2_get_block_type (bh), ver); +if (mtype ==NULL ) +fprintf (stderr,"Unrecognised block at: %s\n" , node->ast_text); + } + +return mtype; +} +/** * Interpret an assignment (set) */
@@ -536,9 +557,9 @@ static struct lgfs2_lang_result *ast_interp_set(struct lgfs2_lang_state *state,struct ast_node *fieldspec;struct ast_node *fieldname;struct ast_node *fieldval; -uint32_t mh_type =0 ;int i =0 ;int ret =0 ; +unsigned ver = sbd->gfs1 ?LGFS2_MD_GFS1 :LGFS2_MD_GFS2 ;struct lgfs2_lang_result *result =calloc (1 ,sizeof (struct lgfs2_lang_result ));if (result ==NULL ) {
@@ -551,14 +572,20 @@ static struct lgfs2_lang_result *ast_interp_set(struct lgfs2_lang_state *state, goto out_err; } - mh_type =lgfs2_get_block_type (result->lr_bh); -if (mh_type ==0 ) { + result->lr_mtype =lang_find_mtype (lookup->ast_right, result->lr_bh, ver); +if (result->lr_mtype ==NULL ) { +fprintf (stderr,"Unrecognised block at: %s\n" , lookup->ast_str); goto out_err; } - result->lr_mtype =lgfs2_find_mtype (mh_type, sbd->gfs1 ?LGFS2_MD_GFS1 :LGFS2_MD_GFS2 ); -if (result->lr_mtype ==NULL ) { - goto out_err; +if (lookup->ast_right->ast_type ==AST_EX_TYPESPEC ) { +struct gfs2_meta_header mh = { + .mh_magic =GFS2_MAGIC , + .mh_type = result->lr_mtype->mh_type, + .mh_format = result->lr_mtype->mh_format, + }; +gfs2_meta_header_out (&mh, result->lr_bh->iov.iov_base); + lookup = lookup->ast_right; } for (fieldspec = lookup->ast_right;
gfs2/libgfs2/lang.h +1 -0
@@ -30,6 +30,7 @@ typedef enum {AST_EX_BLOCKSPEC ,AST_EX_STRUCTSPEC ,AST_EX_FIELDSPEC , +AST_EX_TYPESPEC ,// Keywords AST_KW_STATE,
gfs2/libgfs2/libgfs2.h +1 -0
@@ -356,6 +356,7 @@ extern const struct lgfs2_symbolic lgfs2_ld1_types[];extern const unsigned lgfs2_ld1_type_size;extern int lgfs2_selfcheck (void );extern const struct lgfs2_metadata *lgfs2_find_mtype (uint32_t mh_type,const unsigned versions); +extern const struct lgfs2_metadata *lgfs2_find_mtype_name (const char *name,const unsigned versions);/* bitmap.c */ struct gfs2_bmap {
gfs2/libgfs2/meta.c +15 -0
@@ -1,4 +1,5 @@#include <stdint.h> +#include <string.h> #include "libgfs2.h" #define ARRAY_SIZE (x) (sizeof(x)/sizeof(x[0]))
@@ -821,3 +822,17 @@ const struct lgfs2_metadata *lgfs2_find_mtype(uint32_t mh_type, const unsigned vreturn NULL ; } + +const struct lgfs2_metadata *lgfs2_find_mtype_name (const char *name,const unsigned versions) +{ +const struct lgfs2_metadata *m = lgfs2_metadata; +unsigned n =0 ; + +do { +if ((m[n].versions & versions) && !strcmp (m[n].name, name)) +return &m[n]; + n++; + }while (n < lgfs2_metadata_size); + +return NULL ; +}
gfs2/libgfs2/parser.y +12 -0
@@ -65,6 +65,12 @@ set_stmt: TOK_SET blockspec structspec { $2->ast_right = $3; $$ = $1; } + | TOK_SET blockspec typespec structspec { + $1->ast_right = $2; + $2->ast_right = $3; + $3->ast_right = $4; + $$ = $1; + } ; get_stmt: TOK_GET blockspec { $1->ast_right = $2; $$ = $1; } | TOK_GET blockspec TOK_STATE {
@@ -84,6 +90,11 @@ offset: blockspec TOK_OFFSET { $$ = $2; } ; +typespec: identifier { + $1->ast_type = AST_EX_TYPESPEC; + $$ = $1; + } +; block_literal: identifier { $$ = $1; } ; subscript: block_literal TOK_LBRACKET index TOK_RBRACKET {
@@ -107,6 +118,7 @@ path: string { } ; structspec: TOK_LBRACE fieldspecs TOK_RBRACE { $$ = $2; } +structspec: TOK_LBRACE TOK_RBRACE { $$ = NULL; } ; fieldspecs: fieldspecs TOK_COMMA fieldspec { $1->ast_left = $3; $$ = $1; } | fieldspec { $$ = $1; }
Signature · 1 line
1.8.1.4
PATCH 4/7 gfs2l: Add hash comments
In reply to Andrew Pricegfs2l now recognises # as a line comment. This was added in order to enable writing executable scripts with "#!gfs2l -f" at the top of the file.
--- gfs2/libgfs2/lexer.l | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
gfs2/libgfs2/lexer.l +3 -1
@@ -32,7 +32,9 @@ number ({decnumber}|{hexnumber}) offset \+{number} id {letter}({letter}|{decdigit}|\.)* string \'([^\']|\\\')*\' -comment \/\/.*\n +ccomment \/\/.*\n +shcomment \#.*\n +comment ({ccomment}|{shcomment}) whitespace [ \t\r]+ %%
Signature · 1 line
1.8.1.4
PATCH 5/7 gfs2l: Add options to print block types and fields
In reply to Andrew PriceThis adds a -T option which prints out the list of possible meta header types to be used in gfs2l scripts. It also adds -F <type> which prints a list of fields in a block type given by <type>. The fields are prefixed by their offset in the structure.
--- gfs2/libgfs2/gfs2l.c | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-)
gfs2/libgfs2/gfs2l.c +41 -1
@@ -10,6 +10,8 @@ static void usage(const char *cmd)printf ("Available options:\n" );printf (" -h Print this help message and exit\n" );printf (" -f <script_path> Path to script file or '-' for stdin\n" ); +printf (" -T Print a list of gfs2 structure types and exit\n" ); +printf (" -F <type> Print a list of fields belonging to a type and exit\n" ); }struct cmdopts {
@@ -18,10 +20,42 @@ struct cmdopts { unsigned help:1; }; +static int metastrcmp (const void *a,const void *b) +{ +const struct lgfs2_metadata *m1 = *(struct lgfs2_metadata **)a; +const struct lgfs2_metadata *m2 = *(struct lgfs2_metadata **)b; +return strcmp (m1->name, m2->name); +} + +static void print_structs (void ) +{ +const struct lgfs2_metadata *mlist[lgfs2_metadata_size]; +int i; +for (i =0 ; i < lgfs2_metadata_size; i++) + mlist[i] = &lgfs2_metadata[i]; + +qsort (mlist, lgfs2_metadata_size,sizeof (struct lgfs2_metadata *), metastrcmp); +for (i =0 ; i < lgfs2_metadata_size; i++) +if (mlist[i]->mh_type !=GFS2_METATYPE_NONE ) +printf ("%s\n" , mlist[i]->name); +} + +static void print_fields (const char *name) +{ +const struct lgfs2_metadata *m =lgfs2_find_mtype_name (name,LGFS2_MD_GFS1 |LGFS2_MD_GFS2 ); +if (m !=NULL ) { +const struct lgfs2_metafield *fields = m->fields; +const unsigned nfields = m->nfields; +int i; +for (i =0 ; i < nfields; i++) +printf ("0x%.4x %s\n" , fields[i].offset, fields[i].name); + } +} +static int getopts (int argc,char *argv[],struct cmdopts *opts) {int opt; -while ((opt =getopt (argc, argv,"f:h" )) !=-1 ) { +while ((opt =getopt (argc, argv,"F:f:hT" )) !=-1 ) {switch (opt) {case 'f' :if (!strcmp ("-" , optarg)) {
@@ -34,6 +68,12 @@ static int getopts(int argc, char *argv[], struct cmdopts *opts) } }break ; +case 'T' : +print_structs (); +exit (0 ); +case 'F' : +print_fields (optarg); +exit (0 );case 'h' : opts->help =1 ;return 0 ;
Signature · 1 line
1.8.1.4
PATCH 6/7 gfs2l: Read from stdin by default
In reply to Andrew PriceInstead of requiring -f - in order to read from stdin, do that by default.
--- gfs2/libgfs2/gfs2l.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
gfs2/libgfs2/gfs2l.c +3 -4
@@ -9,7 +9,7 @@ static void usage(const char *cmd)printf ("Usage: %s [options] <fs_path>\n" , cmd);printf ("Available options:\n" );printf (" -h Print this help message and exit\n" ); -printf (" -f <script_path> Path to script file or '-' for stdin\n" ); +printf (" -f <script_path> Path to script file or '-' for stdin (the default)\n" );printf (" -T Print a list of gfs2 structure types and exit\n" );printf (" -F <type> Print a list of fields belonging to a type and exit\n" ); }
@@ -55,12 +55,11 @@ static void print_fields(const char *name)static int getopts (int argc,char *argv[],struct cmdopts *opts) {int opt; + opts->src = stdin;while ((opt =getopt (argc, argv,"F:f:hT" )) !=-1 ) {switch (opt) {case 'f' : -if (!strcmp ("-" , optarg)) { - opts->src = stdin; - }else { +if (strcmp ("-" , optarg)) { opts->src =fopen (optarg,"r" );if (opts->src ==NULL ) {perror ("Failed to open source file" );
Signature · 1 line
1.8.1.4
PATCH 7/7 gfs2l: Improve grammar layout and path parsing
In reply to Andrew PriceThis makes a path a lexical entity so we don't have to kludge from a string in the parse stage. It also tidies up the grammar layout and simplifies the indentation to make it easier to maintain.
--- gfs2/libgfs2/lexer.l | 5 ++ gfs2/libgfs2/parser.y | 196 +++++++++++++++++++++++++------------------------- 2 files changed, 103 insertions(+), 98 deletions(-)
gfs2/libgfs2/lexer.l +5 -0
@@ -32,6 +32,7 @@ number ({decnumber}|{hexnumber}) offset \+{number} id {letter}({letter}|{decdigit}|\.)* string \'([^\']|\\\')*\' +path \'\/([^\']|\\\')*\' ccomment \/\/.*\n shcomment \#.*\n comment ({ccomment}|{shcomment})
@@ -69,6 +70,10 @@ get { state { P(STATE, AST_KW_STATE, yytext); } +{path} { + yytext[yyleng-1] = '\0'; + P(PATH, AST_EX_PATH, yytext + 1); + } {string} { yytext[yyleng-1] = '\0'; P(STRING, AST_EX_STRING, yytext + 1);
gfs2/libgfs2/parser.y +98 -98
204 lines not on this page · raw message
Signature · 1 line
1.8.1.4
PATCH 1/7 gfs2-utils build: Fix reporting lack of check
In reply to Andrew PriceHi,
All looks good to me,
Steve.
Quoted 18 lines · Andrew Price
Make configure.ac test the correct variable to conditionally warn of the absence of 'check'.
Signed-off-by Andrew Price <[email protected]>--- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)configure.ac +1
-1@@ -278,4 +278,4 @@ AC_CONFIG_FILES([Makefile AC_OUTPUT -test x"$BUILD_TESTS" = x && AC_MSG_NOTICE([package 'check' not found; unit tests will not be built]) +test x"$have_check" = "xyes" || AC_MSG_NOTICE([package 'check' not found; unit tests will not be built])