X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=blobdiff_plain;f=src%2Fgenerator.ml;h=1032a1a2f05106927a84388ee895ab59a22c8f83;hp=32a814003a3247d16be83e4bd69b085df57feec1;hb=9be89728f2a0ff17d54a0dba981015fa6405eb50;hpb=1214b321621e7750c67423ecf4d9528809e1eeac diff --git a/src/generator.ml b/src/generator.ml index 32a8140..1032a1a 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -575,7 +575,7 @@ The first character of C string must be a C<-> (dash). C can be NULL."); - ("set_qemu", (RErr, [String "qemu"]), -1, [FishAlias "qemu"], + ("set_qemu", (RErr, [OptString "qemu"]), -1, [FishAlias "qemu"], [], "set the qemu binary", "\ @@ -607,7 +607,7 @@ Return the current qemu binary. This is always non-NULL. If it wasn't set already, then this will return the default qemu binary name."); - ("set_path", (RErr, [String "searchpath"]), -1, [FishAlias "path"], + ("set_path", (RErr, [OptString "searchpath"]), -1, [FishAlias "path"], [], "set the search path", "\ @@ -4455,7 +4455,7 @@ This command writes zeroes over the entire C. Compare with C which just zeroes the first few blocks of a device."); - ("txz_in", (RErr, [FileIn "tarball"; Pathname "directory"]), 229, [], + ("txz_in", (RErr, [FileIn "tarball"; Pathname "directory"]), 229, [Optional "xz"], [InitBasicFS, Always, TestOutput ( [["txz_in"; "../images/helloworld.tar.xz"; "/"]; ["cat"; "/hello"]], "hello\n")], @@ -4464,7 +4464,7 @@ a device."); This command uploads and unpacks local file C (an I tar file) into C."); - ("txz_out", (RErr, [Pathname "directory"; FileOut "tarball"]), 230, [], + ("txz_out", (RErr, [Pathname "directory"; FileOut "tarball"]), 230, [Optional "xz"], [], "pack directory into compressed tarball", "\ @@ -4686,6 +4686,20 @@ unlikely for regular files in ordinary circumstances. See also C."); + ("resize2fs_size", (RErr, [Device "device"; Int64 "size"]), 248, [], + [], + "resize an ext2/ext3 filesystem (with size)", + "\ +This command is the same as C except that it +allows you to specify the new size (in bytes) explicitly."); + + ("pvresize_size", (RErr, [Device "device"; Int64 "size"]), 249, [Optional "lvm2"], + [], + "resize an LVM physical volume (with size)", + "\ +This command is the same as C except that it +allows you to specify the new size (in bytes) explicitly."); + ] let all_functions = non_daemon_functions @ daemon_functions @@ -5835,6 +5849,50 @@ check_state (guestfs_h *g, const char *caller) "; + let error_code_of = function + | RErr | RInt _ | RInt64 _ | RBool _ -> "-1" + | RConstString _ | RConstOptString _ + | RString _ | RStringList _ + | RStruct _ | RStructList _ + | RHashtable _ | RBufferOut _ -> "NULL" + in + + (* Generate code to check String-like parameters are not passed in + * as NULL (returning an error if they are). + *) + let check_null_strings shortname style = + let pr_newline = ref false in + List.iter ( + function + (* parameters which should not be NULL *) + | String n + | Device n + | Pathname n + | Dev_or_Path n + | FileIn n + | FileOut n + | BufferIn n + | StringList n + | DeviceList n -> + pr " if (%s == NULL) {\n" n; + pr " error (g, \"%%s: %%s: parameter cannot be NULL\",\n"; + pr " \"%s\", \"%s\");\n" shortname n; + pr " return %s;\n" (error_code_of (fst style)); + pr " }\n"; + pr_newline := true + + (* can be NULL *) + | OptString _ + + (* not applicable *) + | Bool _ + | Int _ + | Int64 _ -> () + ) (snd style); + + if !pr_newline then pr "\n"; + in + (* Generate code to generate guestfish call traces. *) let trace_call shortname style = pr " if (guestfs__get_trace (g)) {\n"; @@ -5892,6 +5950,7 @@ check_state (guestfs_h *g, const char *caller) generate_prototype ~extern:false ~semicolon:false ~newline:true ~handle:"g" name style; pr "{\n"; + check_null_strings shortname style; trace_call shortname style; pr " return guestfs__%s " shortname; generate_c_call_args ~handle:"g" style; @@ -5904,21 +5963,12 @@ check_state (guestfs_h *g, const char *caller) List.iter ( fun (shortname, style, _, _, _, _, _) -> let name = "guestfs_" ^ shortname in + let error_code = error_code_of (fst style) in (* Generate the action stub. *) generate_prototype ~extern:false ~semicolon:false ~newline:true ~handle:"g" name style; - let error_code = - match fst style with - | RErr | RInt _ | RInt64 _ | RBool _ -> "-1" - | RConstString _ | RConstOptString _ -> - failwithf "RConstString|RConstOptString cannot be used by daemon functions" - | RString _ | RStringList _ - | RStruct _ | RStructList _ - | RHashtable _ | RBufferOut _ -> - "NULL" in - pr "{\n"; (match snd style with @@ -5943,6 +5993,7 @@ check_state (guestfs_h *g, const char *caller) pr " int serial;\n"; pr " int r;\n"; pr "\n"; + check_null_strings shortname style; trace_call shortname style; pr " if (check_state (g, \"%s\") == -1) return %s;\n" shortname error_code; @@ -7419,6 +7470,9 @@ and generate_fish_cmds () = pr "#include \"xstrtol.h\"\n"; pr "#include \"fish.h\"\n"; pr "\n"; + pr "/* Valid suffixes allowed for numbers. See Gnulib xstrtol function. */\n"; + pr "static const char *xstrtol_suffixes = \"0kKMGTPEZY\";\n"; + pr "\n"; (* list_commands function, which implements guestfish -h *) pr "void list_commands (void)\n"; @@ -7637,7 +7691,7 @@ and generate_fish_cmds () = pr " strtol_error xerr;\n"; pr " %s r;\n" fntyp; pr "\n"; - pr " xerr = %s (argv[%d], NULL, 0, &r, \"\");\n" fn i; + pr " xerr = %s (argv[%d], NULL, 0, &r, xstrtol_suffixes);\n" fn i; pr " if (xerr != LONGINT_OK) {\n"; pr " fprintf (stderr,\n"; pr " _(\"%%s: %%s: invalid integer parameter (%%s returned %%d)\\n\"),\n";