PageRenderTime 93ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 1ms

/libguestfs-1.19.22/generator/generator_actions.ml

#
OCaml | 9342 lines | 8738 code | 454 blank | 150 comment | 1 complexity | e6a678e96285aaeab3f4f9d219dc8f30 MD5 | raw file
Possible License(s): LGPL-2.0, GPL-3.0, GPL-2.0
  1. (* libguestfs
  2. * Copyright (C) 2009-2012 Red Hat Inc.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. *)
  18. (* Please read generator/README first. *)
  19. open Generator_types
  20. open Generator_utils
  21. (* Default settings for all action fields. So we copy and override
  22. * this struct by writing '{ defaults with name = &c }'
  23. *)
  24. let defaults = { name = ""; style = RErr, [], []; proc_nr = None;
  25. tests = []; shortdesc = ""; longdesc = "";
  26. protocol_limit_warning = false; fish_alias = [];
  27. fish_output = None; in_fish = true; in_docs = true;
  28. deprecated_by = None; optional = None;
  29. progress = false; camel_name = "";
  30. cancellable = false; config_only = false;
  31. once_had_no_optargs = false;
  32. c_name = ""; c_function = ""; c_optarg_prefix = "";
  33. non_c_aliases = [] }
  34. (* These test functions are used in the language binding tests. *)
  35. let test_all_args = [
  36. String "str";
  37. OptString "optstr";
  38. StringList "strlist";
  39. Bool "b";
  40. Int "integer";
  41. Int64 "integer64";
  42. FileIn "filein";
  43. FileOut "fileout";
  44. BufferIn "bufferin";
  45. ]
  46. let test_all_optargs = [
  47. OBool "obool";
  48. OInt "oint";
  49. OInt64 "oint64";
  50. OString "ostring"
  51. ]
  52. let test_all_rets = [
  53. (* except for RErr, which is tested thoroughly elsewhere *)
  54. "internal_test_rint", RInt "valout";
  55. "internal_test_rint64", RInt64 "valout";
  56. "internal_test_rbool", RBool "valout";
  57. "internal_test_rconststring", RConstString "valout";
  58. "internal_test_rconstoptstring", RConstOptString "valout";
  59. "internal_test_rstring", RString "valout";
  60. "internal_test_rstringlist", RStringList "valout";
  61. "internal_test_rstruct", RStruct ("valout", "lvm_pv");
  62. "internal_test_rstructlist", RStructList ("valout", "lvm_pv");
  63. "internal_test_rhashtable", RHashtable "valout";
  64. "internal_test_rbufferout", RBufferOut "valout";
  65. ]
  66. let test_functions = [
  67. { defaults with
  68. name = "internal_test";
  69. style = RErr, test_all_args, test_all_optargs;
  70. in_fish = false; in_docs = false; cancellable = true;
  71. shortdesc = "internal test function - do not use";
  72. longdesc = "\
  73. This is an internal test function which is used to test whether
  74. the automatically generated bindings can handle every possible
  75. parameter type correctly.
  76. It echos the contents of each parameter to stdout.
  77. You probably don't want to call this function." }
  78. ] @ List.flatten (
  79. List.map (
  80. fun (name, ret) -> [
  81. { defaults with
  82. name = name;
  83. style = ret, [String "val"], [];
  84. in_fish = false; in_docs = false;
  85. shortdesc = "internal test function - do not use";
  86. longdesc = "\
  87. This is an internal test function which is used to test whether
  88. the automatically generated bindings can handle every possible
  89. return type correctly.
  90. It converts string C<val> to the return type.
  91. You probably don't want to call this function." };
  92. { defaults with
  93. name = name ^ "err";
  94. style = ret, [], [];
  95. in_fish = false; in_docs = false;
  96. shortdesc = "internal test function - do not use";
  97. longdesc = "\
  98. This is an internal test function which is used to test whether
  99. the automatically generated bindings can handle every possible
  100. return type correctly.
  101. This function always returns an error.
  102. You probably don't want to call this function." }
  103. ]
  104. ) test_all_rets
  105. )
  106. (* non_daemon_functions are any functions which don't get processed
  107. * in the daemon, eg. functions for setting and getting local
  108. * configuration values.
  109. *)
  110. let non_daemon_functions = test_functions @ [
  111. { defaults with
  112. name = "launch";
  113. style = RErr, [], [];
  114. fish_alias = ["run"]; progress = true; config_only = true;
  115. shortdesc = "launch the qemu subprocess";
  116. longdesc = "\
  117. Internally libguestfs is implemented by running a virtual machine
  118. using L<qemu(1)>.
  119. You should call this after configuring the handle
  120. (eg. adding drives) but before performing any actions." };
  121. { defaults with
  122. name = "wait_ready";
  123. style = RErr, [], [];
  124. in_fish = false; deprecated_by = Some "launch";
  125. shortdesc = "wait until the qemu subprocess launches (no op)";
  126. longdesc = "\
  127. This function is a no op.
  128. In versions of the API E<lt> 1.0.71 you had to call this function
  129. just after calling C<guestfs_launch> to wait for the launch
  130. to complete. However this is no longer necessary because
  131. C<guestfs_launch> now does the waiting.
  132. If you see any calls to this function in code then you can just
  133. remove them, unless you want to retain compatibility with older
  134. versions of the API." };
  135. { defaults with
  136. name = "kill_subprocess";
  137. style = RErr, [], [];
  138. deprecated_by = Some "shutdown";
  139. shortdesc = "kill the qemu subprocess";
  140. longdesc = "\
  141. This kills the qemu subprocess.
  142. Do not call this. See: C<guestfs_shutdown> instead." };
  143. { defaults with
  144. name = "add_cdrom";
  145. style = RErr, [String "filename"], [];
  146. deprecated_by = Some "add_drive"; config_only = true;
  147. shortdesc = "add a CD-ROM disk image to examine";
  148. longdesc = "\
  149. This function adds a virtual CD-ROM disk image to the guest.
  150. This is equivalent to the qemu parameter I<-cdrom filename>.
  151. Notes:
  152. =over 4
  153. =item *
  154. This call checks for the existence of C<filename>. This
  155. stops you from specifying other types of drive which are supported
  156. by qemu such as C<nbd:> and C<http:> URLs. To specify those, use
  157. the general C<guestfs_config> call instead.
  158. =item *
  159. If you just want to add an ISO file (often you use this as an
  160. efficient way to transfer large files into the guest), then you
  161. should probably use C<guestfs_add_drive_ro> instead.
  162. =back" };
  163. { defaults with
  164. name = "add_drive_ro";
  165. style = RErr, [String "filename"], [];
  166. fish_alias = ["add-ro"]; config_only = true;
  167. shortdesc = "add a drive in snapshot mode (read-only)";
  168. longdesc = "\
  169. This function is the equivalent of calling C<guestfs_add_drive_opts>
  170. with the optional parameter C<GUESTFS_ADD_DRIVE_OPTS_READONLY> set to 1,
  171. so the disk is added read-only, with the format being detected
  172. automatically." };
  173. { defaults with
  174. name = "config";
  175. style = RErr, [String "qemuparam"; OptString "qemuvalue"], [];
  176. config_only = true;
  177. shortdesc = "add qemu parameters";
  178. longdesc = "\
  179. This can be used to add arbitrary qemu command line parameters
  180. of the form I<-param value>. Actually it's not quite arbitrary - we
  181. prevent you from setting some parameters which would interfere with
  182. parameters that we use.
  183. The first character of C<param> string must be a C<-> (dash).
  184. C<value> can be NULL." };
  185. { defaults with
  186. name = "set_qemu";
  187. style = RErr, [OptString "qemu"], [];
  188. fish_alias = ["qemu"]; config_only = true;
  189. shortdesc = "set the qemu binary";
  190. longdesc = "\
  191. Set the qemu binary that we will use.
  192. The default is chosen when the library was compiled by the
  193. configure script.
  194. You can also override this by setting the C<LIBGUESTFS_QEMU>
  195. environment variable.
  196. Setting C<qemu> to C<NULL> restores the default qemu binary.
  197. Note that you should call this function as early as possible
  198. after creating the handle. This is because some pre-launch
  199. operations depend on testing qemu features (by running C<qemu -help>).
  200. If the qemu binary changes, we don't retest features, and
  201. so you might see inconsistent results. Using the environment
  202. variable C<LIBGUESTFS_QEMU> is safest of all since that picks
  203. the qemu binary at the same time as the handle is created." };
  204. { defaults with
  205. name = "get_qemu";
  206. style = RConstString "qemu", [], [];
  207. tests = [
  208. InitNone, Always, TestRun (
  209. [["get_qemu"]])
  210. ];
  211. shortdesc = "get the qemu binary";
  212. longdesc = "\
  213. Return the current qemu binary.
  214. This is always non-NULL. If it wasn't set already, then this will
  215. return the default qemu binary name." };
  216. { defaults with
  217. name = "set_path";
  218. style = RErr, [OptString "searchpath"], [];
  219. fish_alias = ["path"]; config_only = true;
  220. shortdesc = "set the search path";
  221. longdesc = "\
  222. Set the path that libguestfs searches for kernel and initrd.img.
  223. The default is C<$libdir/guestfs> unless overridden by setting
  224. C<LIBGUESTFS_PATH> environment variable.
  225. Setting C<path> to C<NULL> restores the default path." };
  226. { defaults with
  227. name = "get_path";
  228. style = RConstString "path", [], [];
  229. tests = [
  230. InitNone, Always, TestRun (
  231. [["get_path"]])
  232. ];
  233. shortdesc = "get the search path";
  234. longdesc = "\
  235. Return the current search path.
  236. This is always non-NULL. If it wasn't set already, then this will
  237. return the default path." };
  238. { defaults with
  239. name = "set_append";
  240. style = RErr, [OptString "append"], [];
  241. fish_alias = ["append"]; config_only = true;
  242. shortdesc = "add options to kernel command line";
  243. longdesc = "\
  244. This function is used to add additional options to the
  245. guest kernel command line.
  246. The default is C<NULL> unless overridden by setting
  247. C<LIBGUESTFS_APPEND> environment variable.
  248. Setting C<append> to C<NULL> means I<no> additional options
  249. are passed (libguestfs always adds a few of its own)." };
  250. { defaults with
  251. name = "get_append";
  252. style = RConstOptString "append", [], [];
  253. (* This cannot be tested with the current framework. The
  254. * function can return NULL in normal operations, which the
  255. * test framework interprets as an error.
  256. *)
  257. tests = [];
  258. shortdesc = "get the additional kernel options";
  259. longdesc = "\
  260. Return the additional kernel options which are added to the
  261. guest kernel command line.
  262. If C<NULL> then no options are added." };
  263. { defaults with
  264. name = "set_autosync";
  265. style = RErr, [Bool "autosync"], [];
  266. fish_alias = ["autosync"];
  267. shortdesc = "set autosync mode";
  268. longdesc = "\
  269. If C<autosync> is true, this enables autosync. Libguestfs will make a
  270. best effort attempt to make filesystems consistent and synchronized
  271. when the handle is closed
  272. (also if the program exits without closing handles).
  273. This is enabled by default (since libguestfs 1.5.24, previously it was
  274. disabled by default)." };
  275. { defaults with
  276. name = "get_autosync";
  277. style = RBool "autosync", [], [];
  278. tests = [
  279. InitNone, Always, TestOutputTrue (
  280. [["get_autosync"]])
  281. ];
  282. shortdesc = "get autosync mode";
  283. longdesc = "\
  284. Get the autosync flag." };
  285. { defaults with
  286. name = "set_verbose";
  287. style = RErr, [Bool "verbose"], [];
  288. fish_alias = ["verbose"];
  289. shortdesc = "set verbose mode";
  290. longdesc = "\
  291. If C<verbose> is true, this turns on verbose messages.
  292. Verbose messages are disabled unless the environment variable
  293. C<LIBGUESTFS_DEBUG> is defined and set to C<1>.
  294. Verbose messages are normally sent to C<stderr>, unless you
  295. register a callback to send them somewhere else (see
  296. C<guestfs_set_event_callback>)." };
  297. { defaults with
  298. name = "get_verbose";
  299. style = RBool "verbose", [], [];
  300. shortdesc = "get verbose mode";
  301. longdesc = "\
  302. This returns the verbose messages flag." };
  303. { defaults with
  304. name = "is_ready";
  305. style = RBool "ready", [], [];
  306. tests = [
  307. InitNone, Always, TestOutputTrue (
  308. [["is_ready"]])
  309. ];
  310. shortdesc = "is ready to accept commands";
  311. longdesc = "\
  312. This returns true iff this handle is ready to accept commands
  313. (in the C<READY> state).
  314. For more information on states, see L<guestfs(3)>." };
  315. { defaults with
  316. name = "is_config";
  317. style = RBool "config", [], [];
  318. tests = [
  319. InitNone, Always, TestOutputFalse (
  320. [["is_config"]])
  321. ];
  322. shortdesc = "is in configuration state";
  323. longdesc = "\
  324. This returns true iff this handle is being configured
  325. (in the C<CONFIG> state).
  326. For more information on states, see L<guestfs(3)>." };
  327. { defaults with
  328. name = "is_launching";
  329. style = RBool "launching", [], [];
  330. tests = [
  331. InitNone, Always, TestOutputFalse (
  332. [["is_launching"]])
  333. ];
  334. shortdesc = "is launching subprocess";
  335. longdesc = "\
  336. This returns true iff this handle is launching the subprocess
  337. (in the C<LAUNCHING> state).
  338. For more information on states, see L<guestfs(3)>." };
  339. { defaults with
  340. name = "is_busy";
  341. style = RBool "busy", [], [];
  342. in_docs = false;
  343. tests = [
  344. InitNone, Always, TestOutputFalse (
  345. [["is_busy"]])
  346. ];
  347. shortdesc = "is busy processing a command";
  348. longdesc = "\
  349. This always returns false. Do not use this function.
  350. For more information on states, see L<guestfs(3)>." };
  351. { defaults with
  352. name = "get_state";
  353. style = RInt "state", [], [];
  354. shortdesc = "get the current state";
  355. longdesc = "\
  356. This returns the current state as an opaque integer. This is
  357. only useful for printing debug and internal error messages.
  358. For more information on states, see L<guestfs(3)>." };
  359. { defaults with
  360. name = "set_memsize";
  361. style = RErr, [Int "memsize"], [];
  362. fish_alias = ["memsize"]; config_only = true;
  363. shortdesc = "set memory allocated to the qemu subprocess";
  364. longdesc = "\
  365. This sets the memory size in megabytes allocated to the
  366. qemu subprocess. This only has any effect if called before
  367. C<guestfs_launch>.
  368. You can also change this by setting the environment
  369. variable C<LIBGUESTFS_MEMSIZE> before the handle is
  370. created.
  371. For more information on the architecture of libguestfs,
  372. see L<guestfs(3)>." };
  373. { defaults with
  374. name = "get_memsize";
  375. style = RInt "memsize", [], [];
  376. tests = [
  377. InitNone, Always, TestOutputIntOp (
  378. [["get_memsize"]], ">=", 256)
  379. ];
  380. shortdesc = "get memory allocated to the qemu subprocess";
  381. longdesc = "\
  382. This gets the memory size in megabytes allocated to the
  383. qemu subprocess.
  384. If C<guestfs_set_memsize> was not called
  385. on this handle, and if C<LIBGUESTFS_MEMSIZE> was not set,
  386. then this returns the compiled-in default value for memsize.
  387. For more information on the architecture of libguestfs,
  388. see L<guestfs(3)>." };
  389. { defaults with
  390. name = "get_pid";
  391. style = RInt "pid", [], [];
  392. fish_alias = ["pid"];
  393. tests = [
  394. InitNone, Always, TestOutputIntOp (
  395. [["get_pid"]], ">=", 1)
  396. ];
  397. shortdesc = "get PID of qemu subprocess";
  398. longdesc = "\
  399. Return the process ID of the qemu subprocess. If there is no
  400. qemu subprocess, then this will return an error.
  401. This is an internal call used for debugging and testing." };
  402. { defaults with
  403. name = "version";
  404. style = RStruct ("version", "version"), [], [];
  405. tests = [
  406. InitNone, Always, TestOutputStruct (
  407. [["version"]], [CompareWithInt ("major", 1)])
  408. ];
  409. shortdesc = "get the library version number";
  410. longdesc = "\
  411. Return the libguestfs version number that the program is linked
  412. against.
  413. Note that because of dynamic linking this is not necessarily
  414. the version of libguestfs that you compiled against. You can
  415. compile the program, and then at runtime dynamically link
  416. against a completely different C<libguestfs.so> library.
  417. This call was added in version C<1.0.58>. In previous
  418. versions of libguestfs there was no way to get the version
  419. number. From C code you can use dynamic linker functions
  420. to find out if this symbol exists (if it doesn't, then
  421. it's an earlier version).
  422. The call returns a structure with four elements. The first
  423. three (C<major>, C<minor> and C<release>) are numbers and
  424. correspond to the usual version triplet. The fourth element
  425. (C<extra>) is a string and is normally empty, but may be
  426. used for distro-specific information.
  427. To construct the original version string:
  428. C<$major.$minor.$release$extra>
  429. See also: L<guestfs(3)/LIBGUESTFS VERSION NUMBERS>.
  430. I<Note:> Don't use this call to test for availability
  431. of features. In enterprise distributions we backport
  432. features from later versions into earlier versions,
  433. making this an unreliable way to test for features.
  434. Use C<guestfs_available> instead." };
  435. { defaults with
  436. name = "set_selinux";
  437. style = RErr, [Bool "selinux"], [];
  438. fish_alias = ["selinux"]; config_only = true;
  439. shortdesc = "set SELinux enabled or disabled at appliance boot";
  440. longdesc = "\
  441. This sets the selinux flag that is passed to the appliance
  442. at boot time. The default is C<selinux=0> (disabled).
  443. Note that if SELinux is enabled, it is always in
  444. Permissive mode (C<enforcing=0>).
  445. For more information on the architecture of libguestfs,
  446. see L<guestfs(3)>." };
  447. { defaults with
  448. name = "get_selinux";
  449. style = RBool "selinux", [], [];
  450. shortdesc = "get SELinux enabled flag";
  451. longdesc = "\
  452. This returns the current setting of the selinux flag which
  453. is passed to the appliance at boot time. See C<guestfs_set_selinux>.
  454. For more information on the architecture of libguestfs,
  455. see L<guestfs(3)>." };
  456. { defaults with
  457. name = "set_trace";
  458. style = RErr, [Bool "trace"], [];
  459. fish_alias = ["trace"];
  460. tests = [
  461. InitNone, Always, TestOutputFalse (
  462. [["set_trace"; "false"];
  463. ["get_trace"]])
  464. ];
  465. shortdesc = "enable or disable command traces";
  466. longdesc = "\
  467. If the command trace flag is set to 1, then libguestfs
  468. calls, parameters and return values are traced.
  469. If you want to trace C API calls into libguestfs (and
  470. other libraries) then possibly a better way is to use
  471. the external ltrace(1) command.
  472. Command traces are disabled unless the environment variable
  473. C<LIBGUESTFS_TRACE> is defined and set to C<1>.
  474. Trace messages are normally sent to C<stderr>, unless you
  475. register a callback to send them somewhere else (see
  476. C<guestfs_set_event_callback>)." };
  477. { defaults with
  478. name = "get_trace";
  479. style = RBool "trace", [], [];
  480. shortdesc = "get command trace enabled flag";
  481. longdesc = "\
  482. Return the command trace flag." };
  483. { defaults with
  484. name = "set_direct";
  485. style = RErr, [Bool "direct"], [];
  486. fish_alias = ["direct"]; config_only = true;
  487. shortdesc = "enable or disable direct appliance mode";
  488. longdesc = "\
  489. If the direct appliance mode flag is enabled, then stdin and
  490. stdout are passed directly through to the appliance once it
  491. is launched.
  492. One consequence of this is that log messages aren't caught
  493. by the library and handled by C<guestfs_set_log_message_callback>,
  494. but go straight to stdout.
  495. You probably don't want to use this unless you know what you
  496. are doing.
  497. The default is disabled." };
  498. { defaults with
  499. name = "get_direct";
  500. style = RBool "direct", [], [];
  501. shortdesc = "get direct appliance mode flag";
  502. longdesc = "\
  503. Return the direct appliance mode flag." };
  504. { defaults with
  505. name = "set_recovery_proc";
  506. style = RErr, [Bool "recoveryproc"], [];
  507. fish_alias = ["recovery-proc"]; config_only = true;
  508. shortdesc = "enable or disable the recovery process";
  509. longdesc = "\
  510. If this is called with the parameter C<false> then
  511. C<guestfs_launch> does not create a recovery process. The
  512. purpose of the recovery process is to stop runaway qemu
  513. processes in the case where the main program aborts abruptly.
  514. This only has any effect if called before C<guestfs_launch>,
  515. and the default is true.
  516. About the only time when you would want to disable this is
  517. if the main process will fork itself into the background
  518. (\"daemonize\" itself). In this case the recovery process
  519. thinks that the main program has disappeared and so kills
  520. qemu, which is not very helpful." };
  521. { defaults with
  522. name = "get_recovery_proc";
  523. style = RBool "recoveryproc", [], [];
  524. shortdesc = "get recovery process enabled flag";
  525. longdesc = "\
  526. Return the recovery process enabled flag." };
  527. { defaults with
  528. name = "add_drive_with_if";
  529. style = RErr, [String "filename"; String "iface"], [];
  530. deprecated_by = Some "add_drive"; config_only = true;
  531. shortdesc = "add a drive specifying the QEMU block emulation to use";
  532. longdesc = "\
  533. This is the same as C<guestfs_add_drive> but it allows you
  534. to specify the QEMU interface emulation to use at run time." };
  535. { defaults with
  536. name = "add_drive_ro_with_if";
  537. style = RErr, [String "filename"; String "iface"], [];
  538. deprecated_by = Some "add_drive"; config_only = true;
  539. shortdesc = "add a drive read-only specifying the QEMU block emulation to use";
  540. longdesc = "\
  541. This is the same as C<guestfs_add_drive_ro> but it allows you
  542. to specify the QEMU interface emulation to use at run time." };
  543. { defaults with
  544. name = "file_architecture";
  545. style = RString "arch", [Pathname "filename"], [];
  546. tests = [
  547. InitISOFS, Always, TestOutput (
  548. [["file_architecture"; "/bin-i586-dynamic"]], "i386");
  549. InitISOFS, Always, TestOutput (
  550. [["file_architecture"; "/bin-sparc-dynamic"]], "sparc");
  551. InitISOFS, Always, TestOutput (
  552. [["file_architecture"; "/bin-win32.exe"]], "i386");
  553. InitISOFS, Always, TestOutput (
  554. [["file_architecture"; "/bin-win64.exe"]], "x86_64");
  555. InitISOFS, Always, TestOutput (
  556. [["file_architecture"; "/bin-x86_64-dynamic"]], "x86_64");
  557. InitISOFS, Always, TestOutput (
  558. [["file_architecture"; "/lib-i586.so"]], "i386");
  559. InitISOFS, Always, TestOutput (
  560. [["file_architecture"; "/lib-sparc.so"]], "sparc");
  561. InitISOFS, Always, TestOutput (
  562. [["file_architecture"; "/lib-win32.dll"]], "i386");
  563. InitISOFS, Always, TestOutput (
  564. [["file_architecture"; "/lib-win64.dll"]], "x86_64");
  565. InitISOFS, Always, TestOutput (
  566. [["file_architecture"; "/lib-x86_64.so"]], "x86_64");
  567. InitISOFS, Always, TestOutput (
  568. [["file_architecture"; "/initrd-x86_64.img"]], "x86_64");
  569. InitISOFS, Always, TestOutput (
  570. [["file_architecture"; "/initrd-x86_64.img.gz"]], "x86_64");
  571. ];
  572. shortdesc = "detect the architecture of a binary file";
  573. longdesc = "\
  574. This detects the architecture of the binary C<filename>,
  575. and returns it if known.
  576. Currently defined architectures are:
  577. =over 4
  578. =item \"i386\"
  579. This string is returned for all 32 bit i386, i486, i586, i686 binaries
  580. irrespective of the precise processor requirements of the binary.
  581. =item \"x86_64\"
  582. 64 bit x86-64.
  583. =item \"sparc\"
  584. 32 bit SPARC.
  585. =item \"sparc64\"
  586. 64 bit SPARC V9 and above.
  587. =item \"ia64\"
  588. Intel Itanium.
  589. =item \"ppc\"
  590. 32 bit Power PC.
  591. =item \"ppc64\"
  592. 64 bit Power PC.
  593. =back
  594. Libguestfs may return other architecture strings in future.
  595. The function works on at least the following types of files:
  596. =over 4
  597. =item *
  598. many types of Un*x and Linux binary
  599. =item *
  600. many types of Un*x and Linux shared library
  601. =item *
  602. Windows Win32 and Win64 binaries
  603. =item *
  604. Windows Win32 and Win64 DLLs
  605. Win32 binaries and DLLs return C<i386>.
  606. Win64 binaries and DLLs return C<x86_64>.
  607. =item *
  608. Linux kernel modules
  609. =item *
  610. Linux new-style initrd images
  611. =item *
  612. some non-x86 Linux vmlinuz kernels
  613. =back
  614. What it can't do currently:
  615. =over 4
  616. =item *
  617. static libraries (libfoo.a)
  618. =item *
  619. Linux old-style initrd as compressed ext2 filesystem (RHEL 3)
  620. =item *
  621. x86 Linux vmlinuz kernels
  622. x86 vmlinuz images (bzImage format) consist of a mix of 16-, 32- and
  623. compressed code, and are horribly hard to unpack. If you want to find
  624. the architecture of a kernel, use the architecture of the associated
  625. initrd or kernel module(s) instead.
  626. =back" };
  627. { defaults with
  628. name = "inspect_os";
  629. style = RStringList "roots", [], [];
  630. shortdesc = "inspect disk and return list of operating systems found";
  631. longdesc = "\
  632. This function uses other libguestfs functions and certain
  633. heuristics to inspect the disk(s) (usually disks belonging to
  634. a virtual machine), looking for operating systems.
  635. The list returned is empty if no operating systems were found.
  636. If one operating system was found, then this returns a list with
  637. a single element, which is the name of the root filesystem of
  638. this operating system. It is also possible for this function
  639. to return a list containing more than one element, indicating
  640. a dual-boot or multi-boot virtual machine, with each element being
  641. the root filesystem of one of the operating systems.
  642. You can pass the root string(s) returned to other
  643. C<guestfs_inspect_get_*> functions in order to query further
  644. information about each operating system, such as the name
  645. and version.
  646. This function uses other libguestfs features such as
  647. C<guestfs_mount_ro> and C<guestfs_umount_all> in order to mount
  648. and unmount filesystems and look at the contents. This should
  649. be called with no disks currently mounted. The function may also
  650. use Augeas, so any existing Augeas handle will be closed.
  651. This function cannot decrypt encrypted disks. The caller
  652. must do that first (supplying the necessary keys) if the
  653. disk is encrypted.
  654. Please read L<guestfs(3)/INSPECTION> for more details.
  655. See also C<guestfs_list_filesystems>." };
  656. { defaults with
  657. name = "inspect_get_type";
  658. style = RString "name", [Device "root"], [];
  659. shortdesc = "get type of inspected operating system";
  660. longdesc = "\
  661. This returns the type of the inspected operating system.
  662. Currently defined types are:
  663. =over 4
  664. =item \"linux\"
  665. Any Linux-based operating system.
  666. =item \"windows\"
  667. Any Microsoft Windows operating system.
  668. =item \"freebsd\"
  669. FreeBSD.
  670. =item \"netbsd\"
  671. NetBSD.
  672. =item \"hurd\"
  673. GNU/Hurd.
  674. =item \"dos\"
  675. MS-DOS, FreeDOS and others.
  676. =item \"unknown\"
  677. The operating system type could not be determined.
  678. =back
  679. Future versions of libguestfs may return other strings here.
  680. The caller should be prepared to handle any string.
  681. Please read L<guestfs(3)/INSPECTION> for more details." };
  682. { defaults with
  683. name = "inspect_get_arch";
  684. style = RString "arch", [Device "root"], [];
  685. shortdesc = "get architecture of inspected operating system";
  686. longdesc = "\
  687. This returns the architecture of the inspected operating system.
  688. The possible return values are listed under
  689. C<guestfs_file_architecture>.
  690. If the architecture could not be determined, then the
  691. string C<unknown> is returned.
  692. Please read L<guestfs(3)/INSPECTION> for more details." };
  693. { defaults with
  694. name = "inspect_get_distro";
  695. style = RString "distro", [Device "root"], [];
  696. shortdesc = "get distro of inspected operating system";
  697. longdesc = "\
  698. This returns the distro (distribution) of the inspected operating
  699. system.
  700. Currently defined distros are:
  701. =over 4
  702. =item \"archlinux\"
  703. Arch Linux.
  704. =item \"buildroot\"
  705. Buildroot-derived distro, but not one we specifically recognize.
  706. =item \"centos\"
  707. CentOS.
  708. =item \"cirros\"
  709. Cirros.
  710. =item \"debian\"
  711. Debian.
  712. =item \"fedora\"
  713. Fedora.
  714. =item \"freedos\"
  715. FreeDOS.
  716. =item \"gentoo\"
  717. Gentoo.
  718. =item \"linuxmint\"
  719. Linux Mint.
  720. =item \"mageia\"
  721. Mageia.
  722. =item \"mandriva\"
  723. Mandriva.
  724. =item \"meego\"
  725. MeeGo.
  726. =item \"opensuse\"
  727. OpenSUSE.
  728. =item \"pardus\"
  729. Pardus.
  730. =item \"redhat-based\"
  731. Some Red Hat-derived distro.
  732. =item \"rhel\"
  733. Red Hat Enterprise Linux.
  734. =item \"scientificlinux\"
  735. Scientific Linux.
  736. =item \"slackware\"
  737. Slackware.
  738. =item \"ttylinux\"
  739. ttylinux.
  740. =item \"ubuntu\"
  741. Ubuntu.
  742. =item \"unknown\"
  743. The distro could not be determined.
  744. =item \"windows\"
  745. Windows does not have distributions. This string is
  746. returned if the OS type is Windows.
  747. =back
  748. Future versions of libguestfs may return other strings here.
  749. The caller should be prepared to handle any string.
  750. Please read L<guestfs(3)/INSPECTION> for more details." };
  751. { defaults with
  752. name = "inspect_get_major_version";
  753. style = RInt "major", [Device "root"], [];
  754. shortdesc = "get major version of inspected operating system";
  755. longdesc = "\
  756. This returns the major version number of the inspected operating
  757. system.
  758. Windows uses a consistent versioning scheme which is I<not>
  759. reflected in the popular public names used by the operating system.
  760. Notably the operating system known as \"Windows 7\" is really
  761. version 6.1 (ie. major = 6, minor = 1). You can find out the
  762. real versions corresponding to releases of Windows by consulting
  763. Wikipedia or MSDN.
  764. If the version could not be determined, then C<0> is returned.
  765. Please read L<guestfs(3)/INSPECTION> for more details." };
  766. { defaults with
  767. name = "inspect_get_minor_version";
  768. style = RInt "minor", [Device "root"], [];
  769. shortdesc = "get minor version of inspected operating system";
  770. longdesc = "\
  771. This returns the minor version number of the inspected operating
  772. system.
  773. If the version could not be determined, then C<0> is returned.
  774. Please read L<guestfs(3)/INSPECTION> for more details.
  775. See also C<guestfs_inspect_get_major_version>." };
  776. { defaults with
  777. name = "inspect_get_product_name";
  778. style = RString "product", [Device "root"], [];
  779. shortdesc = "get product name of inspected operating system";
  780. longdesc = "\
  781. This returns the product name of the inspected operating
  782. system. The product name is generally some freeform string
  783. which can be displayed to the user, but should not be
  784. parsed by programs.
  785. If the product name could not be determined, then the
  786. string C<unknown> is returned.
  787. Please read L<guestfs(3)/INSPECTION> for more details." };
  788. { defaults with
  789. name = "inspect_get_mountpoints";
  790. style = RHashtable "mountpoints", [Device "root"], [];
  791. shortdesc = "get mountpoints of inspected operating system";
  792. longdesc = "\
  793. This returns a hash of where we think the filesystems
  794. associated with this operating system should be mounted.
  795. Callers should note that this is at best an educated guess
  796. made by reading configuration files such as C</etc/fstab>.
  797. I<In particular note> that this may return filesystems
  798. which are non-existent or not mountable and callers should
  799. be prepared to handle or ignore failures if they try to
  800. mount them.
  801. Each element in the returned hashtable has a key which
  802. is the path of the mountpoint (eg. C</boot>) and a value
  803. which is the filesystem that would be mounted there
  804. (eg. C</dev/sda1>).
  805. Non-mounted devices such as swap devices are I<not>
  806. returned in this list.
  807. For operating systems like Windows which still use drive
  808. letters, this call will only return an entry for the first
  809. drive \"mounted on\" C</>. For information about the
  810. mapping of drive letters to partitions, see
  811. C<guestfs_inspect_get_drive_mappings>.
  812. Please read L<guestfs(3)/INSPECTION> for more details.
  813. See also C<guestfs_inspect_get_filesystems>." };
  814. { defaults with
  815. name = "inspect_get_filesystems";
  816. style = RStringList "filesystems", [Device "root"], [];
  817. shortdesc = "get filesystems associated with inspected operating system";
  818. longdesc = "\
  819. This returns a list of all the filesystems that we think
  820. are associated with this operating system. This includes
  821. the root filesystem, other ordinary filesystems, and
  822. non-mounted devices like swap partitions.
  823. In the case of a multi-boot virtual machine, it is possible
  824. for a filesystem to be shared between operating systems.
  825. Please read L<guestfs(3)/INSPECTION> for more details.
  826. See also C<guestfs_inspect_get_mountpoints>." };
  827. { defaults with
  828. name = "set_network";
  829. style = RErr, [Bool "network"], [];
  830. fish_alias = ["network"]; config_only = true;
  831. shortdesc = "set enable network flag";
  832. longdesc = "\
  833. If C<network> is true, then the network is enabled in the
  834. libguestfs appliance. The default is false.
  835. This affects whether commands are able to access the network
  836. (see L<guestfs(3)/RUNNING COMMANDS>).
  837. You must call this before calling C<guestfs_launch>, otherwise
  838. it has no effect." };
  839. { defaults with
  840. name = "get_network";
  841. style = RBool "network", [], [];
  842. shortdesc = "get enable network flag";
  843. longdesc = "\
  844. This returns the enable network flag." };
  845. { defaults with
  846. name = "list_filesystems";
  847. style = RHashtable "fses", [], [];
  848. shortdesc = "list filesystems";
  849. longdesc = "\
  850. This inspection command looks for filesystems on partitions,
  851. block devices and logical volumes, returning a list of devices
  852. containing filesystems and their type.
  853. The return value is a hash, where the keys are the devices
  854. containing filesystems, and the values are the filesystem types.
  855. For example:
  856. \"/dev/sda1\" => \"ntfs\"
  857. \"/dev/sda2\" => \"ext2\"
  858. \"/dev/vg_guest/lv_root\" => \"ext4\"
  859. \"/dev/vg_guest/lv_swap\" => \"swap\"
  860. The value can have the special value \"unknown\", meaning the
  861. content of the device is undetermined or empty.
  862. \"swap\" means a Linux swap partition.
  863. This command runs other libguestfs commands, which might include
  864. C<guestfs_mount> and C<guestfs_umount>, and therefore you should
  865. use this soon after launch and only when nothing is mounted.
  866. Not all of the filesystems returned will be mountable. In
  867. particular, swap partitions are returned in the list. Also
  868. this command does not check that each filesystem
  869. found is valid and mountable, and some filesystems might
  870. be mountable but require special options. Filesystems may
  871. not all belong to a single logical operating system
  872. (use C<guestfs_inspect_os> to look for OSes)." };
  873. { defaults with
  874. name = "add_drive";
  875. style = RErr, [String "filename"], [OBool "readonly"; OString "format"; OString "iface"; OString "name"];
  876. once_had_no_optargs = true;
  877. fish_alias = ["add"]; config_only = true;
  878. shortdesc = "add an image to examine or modify";
  879. longdesc = "\
  880. This function adds a virtual machine disk image C<filename> to
  881. libguestfs. The first time you call this function, the disk
  882. appears as C</dev/sda>, the second time as C</dev/sdb>, and
  883. so on.
  884. You don't necessarily need to be root when using libguestfs. However
  885. you obviously do need sufficient permissions to access the filename
  886. for whatever operations you want to perform (ie. read access if you
  887. just want to read the image or write access if you want to modify the
  888. image).
  889. This call checks that C<filename> exists.
  890. The optional arguments are:
  891. =over 4
  892. =item C<readonly>
  893. If true then the image is treated as read-only. Writes are still
  894. allowed, but they are stored in a temporary snapshot overlay which
  895. is discarded at the end. The disk that you add is not modified.
  896. =item C<format>
  897. This forces the image format. If you omit this (or use C<guestfs_add_drive>
  898. or C<guestfs_add_drive_ro>) then the format is automatically detected.
  899. Possible formats include C<raw> and C<qcow2>.
  900. Automatic detection of the format opens you up to a potential
  901. security hole when dealing with untrusted raw-format images.
  902. See CVE-2010-3851 and RHBZ#642934. Specifying the format closes
  903. this security hole.
  904. =item C<iface>
  905. This rarely-used option lets you emulate the behaviour of the
  906. deprecated C<guestfs_add_drive_with_if> call (q.v.)
  907. =item C<name>
  908. The name the drive had in the original guest, e.g. /dev/sdb. This is used as a
  909. hint to the guest inspection process if it is available.
  910. =back
  911. C<filename> can have the special value C</dev/null>, which means
  912. to add a null (zero length) raw format device. You can add C</dev/null>
  913. multiple times." };
  914. { defaults with
  915. name = "inspect_get_windows_systemroot";
  916. style = RString "systemroot", [Device "root"], [];
  917. shortdesc = "get Windows systemroot of inspected operating system";
  918. longdesc = "\
  919. This returns the Windows systemroot of the inspected guest.
  920. The systemroot is a directory path such as C</WINDOWS>.
  921. This call assumes that the guest is Windows and that the
  922. systemroot could be determined by inspection. If this is not
  923. the case then an error is returned.
  924. Please read L<guestfs(3)/INSPECTION> for more details." };
  925. { defaults with
  926. name = "inspect_get_roots";
  927. style = RStringList "roots", [], [];
  928. shortdesc = "return list of operating systems found by last inspection";
  929. longdesc = "\
  930. This function is a convenient way to get the list of root
  931. devices, as returned from a previous call to C<guestfs_inspect_os>,
  932. but without redoing the whole inspection process.
  933. This returns an empty list if either no root devices were
  934. found or the caller has not called C<guestfs_inspect_os>.
  935. Please read L<guestfs(3)/INSPECTION> for more details." };
  936. { defaults with
  937. name = "debug_cmdline";
  938. style = RStringList "cmdline", [], [];
  939. in_docs = false;
  940. shortdesc = "debug the QEMU command line (internal use only)";
  941. longdesc = "\
  942. This returns the internal QEMU command line. 'debug' commands are
  943. not part of the formal API and can be removed or changed at any time." };
  944. { defaults with
  945. name = "debug_drives";
  946. style = RStringList "cmdline", [], [];
  947. in_docs = false;
  948. shortdesc = "debug the drives (internal use only)";
  949. longdesc = "\
  950. This returns the internal list of drives. 'debug' commands are
  951. not part of the formal API and can be removed or changed at any time." };
  952. { defaults with
  953. name = "add_domain";
  954. style = RInt "nrdisks", [String "dom"], [OString "libvirturi"; OBool "readonly"; OString "iface"; OBool "live"; OBool "allowuuid"; OString "readonlydisk"];
  955. fish_alias = ["domain"]; config_only = true;
  956. shortdesc = "add the disk(s) from a named libvirt domain";
  957. longdesc = "\
  958. This function adds the disk(s) attached to the named libvirt
  959. domain C<dom>. It works by connecting to libvirt, requesting
  960. the domain and domain XML from libvirt, parsing it for disks,
  961. and calling C<guestfs_add_drive_opts> on each one.
  962. The number of disks added is returned. This operation is atomic:
  963. if an error is returned, then no disks are added.
  964. This function does some minimal checks to make sure the libvirt
  965. domain is not running (unless C<readonly> is true). In a future
  966. version we will try to acquire the libvirt lock on each disk.
  967. Disks must be accessible locally. This often means that adding disks
  968. from a remote libvirt connection (see L<http://libvirt.org/remote.html>)
  969. will fail unless those disks are accessible via the same device path
  970. locally too.
  971. The optional C<libvirturi> parameter sets the libvirt URI
  972. (see L<http://libvirt.org/uri.html>). If this is not set then
  973. we connect to the default libvirt URI (or one set through an
  974. environment variable, see the libvirt documentation for full
  975. details).
  976. The optional C<live> flag controls whether this call will try
  977. to connect to a running virtual machine C<guestfsd> process if
  978. it sees a suitable E<lt>channelE<gt> element in the libvirt
  979. XML definition. The default (if the flag is omitted) is never
  980. to try. See L<guestfs(3)/ATTACHING TO RUNNING DAEMONS> for more
  981. information.
  982. If the C<allowuuid> flag is true (default is false) then a UUID
  983. I<may> be passed instead of the domain name. The C<dom> string is
  984. treated as a UUID first and looked up, and if that lookup fails
  985. then we treat C<dom> as a name as usual.
  986. The optional C<readonlydisk> parameter controls what we do for
  987. disks which are marked E<lt>readonly/E<gt> in the libvirt XML.
  988. Possible values are:
  989. =over 4
  990. =item readonlydisk = \"error\"
  991. If C<readonly> is false:
  992. The whole call is aborted with an error if any disk with
  993. the E<lt>readonly/E<gt> flag is found.
  994. If C<readonly> is true:
  995. Disks with the E<lt>readonly/E<gt> flag are added read-only.
  996. =item readonlydisk = \"read\"
  997. If C<readonly> is false:
  998. Disks with the E<lt>readonly/E<gt> flag are added read-only.
  999. Other disks are added read/write.
  1000. If C<readonly> is true:
  1001. Disks with the E<lt>readonly/E<gt> flag are added read-only.
  1002. =item readonlydisk = \"write\" (default)
  1003. If C<readonly> is false:
  1004. Disks with the E<lt>readonly/E<gt> flag are added read/write.
  1005. If C<readonly> is true:
  1006. Disks with the E<lt>readonly/E<gt> flag are added read-only.
  1007. =item readonlydisk = \"ignore\"
  1008. If C<readonly> is true or false:
  1009. Disks with the E<lt>readonly/E<gt> flag are skipped.
  1010. =back
  1011. The other optional parameters are passed directly through to
  1012. C<guestfs_add_drive_opts>." };
  1013. (*
  1014. This interface is not quite baked yet. -- RWMJ 2010-11-11
  1015. { defaults with
  1016. name = "add_libvirt_dom";
  1017. style = RInt "nrdisks", [Pointer ("virDomainPtr", "dom")], [Bool "readonly"; String "iface"; Bool "live"; String "readonlydisk"];
  1018. in_fish = false;
  1019. shortdesc = "add the disk(s) from a libvirt domain";
  1020. longdesc = "\
  1021. This function adds the disk(s) attached to the libvirt domain C<dom>.
  1022. It works by requesting the domain XML from libvirt, parsing it for
  1023. disks, and calling C<guestfs_add_drive_opts> on each one.
  1024. In the C API we declare C<void *dom>, but really it has type
  1025. C<virDomainPtr dom>. This is so we don't need E<lt>libvirt.hE<gt>.
  1026. The number of disks added is returned. This operation is atomic:
  1027. if an error is returned, then no disks are added.
  1028. This function does some minimal checks to make sure the libvirt
  1029. domain is not running (unless C<readonly> is true). In a future
  1030. version we will try to acquire the libvirt lock on each disk.
  1031. Disks must be accessible locally. This often means that adding disks
  1032. from a remote libvirt connection (see L<http://libvirt.org/remote.html>)
  1033. will fail unless those disks are accessible via the same device path
  1034. locally too.
  1035. The optional C<live> flag controls whether this call will try
  1036. to connect to a running virtual machine C<guestfsd> process if
  1037. it sees a suitable E<lt>channelE<gt> element in the libvirt
  1038. XML definition. The default (if the flag is omitted) is never
  1039. to try. See L<guestfs(3)/ATTACHING TO RUNNING DAEMONS> for more
  1040. information.
  1041. The optional C<readonlydisk> parameter controls what we do for
  1042. disks which are marked E<lt>readonly/E<gt> in the libvirt XML.
  1043. See C<guestfs_add_domain> for possible values.
  1044. The other optional parameters are passed directly through to
  1045. C<guestfs_add_drive_opts>." };
  1046. *)
  1047. { defaults with
  1048. name = "inspect_get_package_format";
  1049. style = RString "packageformat", [Device "root"], [];
  1050. shortdesc = "get package format used by the operating system";
  1051. longdesc = "\
  1052. This function and C<guestfs_inspect_get_package_management> return
  1053. the package format and package management tool used by the
  1054. inspected operating system. For example for Fedora these
  1055. functions would return C<rpm> (package format) and
  1056. C<yum> (package management).
  1057. This returns the string C<unknown> if we could not determine the
  1058. package format I<or> if the operating system does not have
  1059. a real packaging system (eg. Windows).
  1060. Possible strings include:
  1061. C<rpm>, C<deb>, C<ebuild>, C<pisi>, C<pacman>, C<pkgsrc>.
  1062. Future versions of libguestfs may return other strings.
  1063. Please read L<guestfs(3)/INSPECTION> for more details." };
  1064. { defaults with
  1065. name = "inspect_get_package_management";
  1066. style = RString "packagemanagement", [Device "root"], [];
  1067. shortdesc = "get package management tool used by the operating system";
  1068. longdesc = "\
  1069. C<guestfs_inspect_get_package_format> and this function return
  1070. the package format and package management tool used by the
  1071. inspected operating system. For example for Fedora these
  1072. functions would return C<rpm> (package format) and
  1073. C<yum> (package management).
  1074. This returns the string C<unknown> if we could not determine the
  1075. package management tool I<or> if the operating system does not have
  1076. a real packaging system (eg. Windows).
  1077. Possible strings include: C<yum>, C<up2date>,
  1078. C<apt> (for all Debian derivatives),
  1079. C<portage>, C<pisi>, C<pacman>, C<urpmi>, C<zypper>.
  1080. Future versions of libguestfs may return other strings.
  1081. Please read L<guestfs(3)/INSPECTION> for more details." };
  1082. { defaults with
  1083. name = "inspect_list_applications";
  1084. style = RStructList ("applications", "application"), [Device "root"], [];
  1085. shortdesc = "get list of applications installed in the operating system";
  1086. longdesc = "\
  1087. Return the list of applications installed in the operating system.
  1088. I<Note:> This call works differently from other parts of the
  1089. inspection API. You have to call C<guestfs_inspect_os>, then
  1090. C<guestfs_inspect_get_mountpoints>, then mount up the disks,
  1091. before calling this. Listing applications is a significantly
  1092. more difficult operation which requires access to the full
  1093. filesystem. Also note that unlike the other
  1094. C<guestfs_inspect_get_*> calls which are just returning
  1095. data cached in the libguestfs handle, this call actually reads
  1096. parts of the mounted filesystems during the call.
  1097. This returns an empty list if the inspection code was not able
  1098. to determine the list of applications.
  1099. The application structure contains the following fields:
  1100. =over 4
  1101. =item C<app_name>
  1102. The name of the application. For Red Hat-derived and Debian-derived
  1103. Linux guests, this is the package name.
  1104. =item C<app_display_name>
  1105. The display name of the application, sometimes localized to the
  1106. install language of the guest operating system.
  1107. If unavailable this is returned as an empty string C<\"\">.
  1108. Callers needing to display something can use C<app_name> instead.
  1109. =item C<app_epoch>
  1110. For package managers which use epochs, this contains the epoch of
  1111. the package (an integer). If unavailable, this is returned as C<0>.
  1112. =item C<app_version>
  1113. The version string of the application or package. If unavailable
  1114. this is returned as an empty string C<\"\">.
  1115. =item C<app_release>
  1116. The release string of the application or package, for package
  1117. managers that use this. If unavailable this is returned as an
  1118. empty string C<\"\">.
  1119. =item C<app_install_path>
  1120. The installation path of the application (on operating systems
  1121. such as Windows which use installation paths). This path is
  1122. in the format used by the guest operating system, it is not
  1123. a libguestfs path.
  1124. If unavailable this is returned as an empty string C<\"\">.
  1125. =item C<app_trans_path>
  1126. The install path translated into a libguestfs path.
  1127. If unavailable this is returned as an empty string C<\"\">.
  1128. =item C<app_publisher>
  1129. The name of the publisher of the application, for package
  1130. managers that use this. If unavailable this is returned
  1131. as an empty string C<\"\">.
  1132. =item C<app_url>
  1133. The URL (eg. upstream URL) of the application.
  1134. If unavailable this is returned as an empty string C<\"\">.
  1135. =item C<app_source_package>
  1136. For packaging systems which support this, the name of the source
  1137. package. If unavailable this is returned as an empty string C<\"\">.
  1138. =item C<app_summary>
  1139. A short (usually one line) description of the application or package.
  1140. If unavailable this is returned as an empty string C<\"\">.
  1141. =item C<app_description>
  1142. A longer description of the application or package.
  1143. If unavailable this is returned as an empty string C<\"\">.
  1144. =back
  1145. Please read L<guestfs(3)/INSPECTION> for more details." };
  1146. { defaults with
  1147. name = "inspect_get_hostname";
  1148. style = RString "hostname", [Device "root"], [];
  1149. shortdesc = "get hostname of the operating system";
  1150. longdesc = "\
  1151. This function returns the hostname of the operating system
  1152. as found by inspection of the guest's configuration files.
  1153. If the hostname could not be determined, then the
  1154. string C<unknown> is returned.
  1155. Please read L<guestfs(3)/INSPECTION> for more details." };
  1156. { defaults with
  1157. name = "inspect_get_format";
  1158. style = RString "format", [Device "root"], [];
  1159. shortdesc = "get format of inspected operating system";
  1160. longdesc = "\
  1161. This returns the format of the inspected operating system. You
  1162. can use it to detect install images, live CDs and similar.
  1163. Currently defined formats are:
  1164. =over 4
  1165. =item \"installed\"
  1166. This is an installed operating system.
  1167. =item \"installer\"
  1168. The disk image being inspected is not an installed operating system,
  1169. but a I<bootable> install disk, live CD, or similar.
  1170. =item \"unknown\"
  1171. The format of this disk image is not known.
  1172. =back
  1173. Future versions of libguestfs may return other strings here.
  1174. The caller should be prepared to handle any string.
  1175. Please read L<guestfs(3)/INSPECTION> for more details." };
  1176. { defaults with
  1177. name = "inspect_is_live";
  1178. style = RBool "live", [Device "root"], [];
  1179. shortdesc = "get live flag for install disk";
  1180. longdesc = "\
  1181. If C<guestfs_inspect_get_format> returns C<installer> (this
  1182. is an install disk), then this returns true if a live image
  1183. was detected on the disk.
  1184. Please read L<guestfs(3)/INSPECTION> for more details." };
  1185. { defaults with
  1186. name = "inspect_is_netinst";
  1187. style = RBool "netinst", [Device "root"], [];
  1188. shortdesc = "get netinst (network installer) flag for install disk";
  1189. longdesc = "\
  1190. If C<guestfs_inspect_get_format> returns C<installer> (this
  1191. is an install disk), then this returns true if the disk is
  1192. a network installer, ie. not a self-contained install CD but
  1193. one which is likely to require network access to complete
  1194. the install.
  1195. Please read L<guestfs(3)/INSPECTION> for more details." };
  1196. { defaults with
  1197. name = "inspect_is_multipart";
  1198. style = RBool "multipart", [Device "root"], [];
  1199. shortdesc = "get multipart flag for install disk";
  1200. longdesc = "\
  1201. If C<guestfs_inspect_get_format> returns C<installer> (this
  1202. is an install disk), then this returns true if the disk is
  1203. part of a set.
  1204. Please read L<guestfs(3)/INSPECTION> for more details." };
  1205. { defaults with
  1206. name = "set_attach_method";
  1207. style = RErr, [String "attachmethod"], [];
  1208. fish_alias = ["attach-method"]; config_only = true;
  1209. shortdesc = "set the attach method";
  1210. longdesc = "\
  1211. Set the method that libguestfs uses to connect to the back end
  1212. guestfsd daemon. Possible methods are:
  1213. =over 4
  1214. =item C<appliance>
  1215. Launch an appliance and connect to it. This is the ordinary method
  1216. and the default.
  1217. =item C<unix:I<path>>
  1218. Connect to the Unix domain socket I<path>.
  1219. This method lets you connect to an existing daemon or (using
  1220. virtio-serial) to a live guest. For more information, see
  1221. L<guestfs(3)/ATTACHING TO RUNNING DAEMONS>.
  1222. =back" };
  1223. { defaults with
  1224. name = "get_attach_method";
  1225. style = RString "attachmethod", [], [];
  1226. tests = [
  1227. InitNone, Always, TestOutput (
  1228. [["get_attach_method"]], "appliance")
  1229. ];
  1230. shortdesc = "get the attach method";
  1231. longdesc = "\
  1232. Return the current attach method. See C<guestfs_set_attach_method>." };
  1233. { defaults with
  1234. name = "inspect_get_product_variant";
  1235. style = RString "variant", [Device "root"], [];
  1236. shortdesc = "get product variant of inspected operating system";
  1237. longdesc = "\
  1238. This returns the product variant of the inspected operating
  1239. system.
  1240. For Windows guests, this returns the contents of the Registry key
  1241. C<HKLM\\Software\\Microsoft\\Windows NT\\CurrentVersion>
  1242. C<InstallationType> which is usually a string such as
  1243. C<Client> or C<Server> (other values are possible). This
  1244. can be used to distinguish consumer and enterprise versions
  1245. of Windows that have the same version number (for example,
  1246. Windows 7 and Windows 2008 Server are both version 6.1,
  1247. but the former is C<Client> and the latter is C<Server>).
  1248. For enterprise Linux guests, in future we intend this to return
  1249. the product variant such as C<Desktop>, C<Server> and so on. But
  1250. this is not implemented at present.
  1251. If the product variant could not be determined, then the
  1252. string C<unknown> is returned.
  1253. Please read L<guestfs(3)/INSPECTION> for more details.
  1254. See also C<guestfs_inspect_get_product_name>,
  1255. C<guestfs_inspect_get_major_version>." };
  1256. { defaults with
  1257. name = "inspect_get_windows_current_control_set";
  1258. style = RString "controlset", [Device "root"], [];
  1259. shortdesc = "get Windows CurrentControlSet of inspected operating system";
  1260. longdesc = "\
  1261. This returns the Windows CurrentControlSet of the inspected guest.
  1262. The CurrentControlSet is a registry key name such as C<ControlSet001>.
  1263. This call assumes that the guest is Windows and that the
  1264. Registry could be examined by inspection. If this is not
  1265. the case then an error is returned.
  1266. Please read L<guestfs(3)/INSPECTION> for more details." };
  1267. { defaults with
  1268. name = "inspect_get_drive_mappings";
  1269. style = RHashtable "drives", [Device "root"], [];
  1270. shortdesc = "get drive letter mappings";
  1271. longdesc = "\
  1272. This call is useful for Windows which uses a primitive system
  1273. of assigning drive letters (like \"C:\") to partitions.
  1274. This inspection API examines the Windows Registry to find out
  1275. how disks/partitions are mapped to drive letters, and returns
  1276. a hash table as in the example below:
  1277. C => /dev/vda2
  1278. E => /dev/vdb1
  1279. F => /dev/vdc1
  1280. Note that keys are drive letters. For Windows, the key is
  1281. case insensitive and just contains the drive letter, without
  1282. the customary colon separator character.
  1283. In future we may support other operating systems that also used drive
  1284. letters, but the keys for those might not be case insensitive
  1285. and might be longer than 1 character. For example in OS-9,
  1286. hard drives were named C<h0>, C<h1> etc.
  1287. For Windows guests, currently only hard drive mappings are
  1288. returned. Removable disks (eg. DVD-ROMs) are ignored.
  1289. For guests that do not use drive mappings, or if the drive mappings
  1290. could not be determined, this returns an empty hash table.
  1291. Please read L<guestfs(3)/INSPECTION> for more details.
  1292. See also C<guestfs_inspect_get_mountpoints>,
  1293. C<guestfs_inspect_get_filesystems>." };
  1294. { defaults with
  1295. name = "inspect_get_icon";
  1296. style = RBufferOut "icon", [Device "root"], [OBool "favicon"; OBool "highquality"];
  1297. shortdesc = "get the icon corresponding to this operating system";
  1298. longdesc = "\
  1299. This function returns an icon corresponding to the inspected
  1300. operating system. The icon is returned as a buffer containing a
  1301. PNG image (re-encoded to PNG if necessary).
  1302. If it was not possible to get an icon this function returns a
  1303. zero-length (non-NULL) buffer. I<Callers must check for this case>.
  1304. Libguestfs will start by looking for a file called
  1305. C</etc/favicon.png> or C<C:\\etc\\favicon.png>
  1306. and if it has the correct format, the contents of this file will
  1307. be returned. You can disable favicons by passing the
  1308. optional C<favicon> boolean as false (default is true).
  1309. If finding the favicon fails, then we look in other places in the
  1310. guest for a suitable icon.
  1311. If the optional C<highquality> boolean is true then
  1312. only high quality icons are returned, which means only icons of
  1313. high resolution with an alpha channel. The default (false) is
  1314. to return any icon we can, even if it is of substandard quality.
  1315. Notes:
  1316. =over 4
  1317. =item *
  1318. Unlike most other inspection API calls, the guest's disks must be
  1319. mounted up before you call this, since it needs to read information
  1320. from the guest filesystem during the call.
  1321. =item *
  1322. B<Security:> The icon data comes from the untrusted guest,
  1323. and should be treated with caution. PNG files have been
  1324. known to contain exploits. Ensure that libpng (or other relevant
  1325. libraries) are fully up to date before trying to process or
  1326. display the icon.
  1327. =item *
  1328. The PNG image returned can be any size. It might not be square.
  1329. Libguestfs tries to return the largest, highest quality
  1330. icon available. The application must scale the icon to the
  1331. required size.
  1332. =item *
  1333. Extracting icons from Windows guests requires the external
  1334. C<wrestool> program from the C<icoutils> package, and
  1335. several programs (C<bmptopnm>, C<pnmtopng>, C<pamcut>)
  1336. from the C<netpbm> package. These must be installed separately.
  1337. =item *
  1338. Operating system icons are usually trademarks. Seek legal
  1339. advice before using trademarks in applications.
  1340. =back" };
  1341. { defaults with
  1342. name = "set_pgroup";
  1343. style = RErr, [Bool "pgroup"], [];
  1344. fish_alias = ["pgroup"]; config_only = true;
  1345. shortdesc = "set process group flag";
  1346. longdesc = "\
  1347. If C<pgroup> is true, child processes are placed into
  1348. their own process group.
  1349. The practical upshot of this is that signals like C<SIGINT> (from
  1350. users pressing C<^C>) won't be received by the child process.
  1351. The default for this flag is false, because usually you want
  1352. C<^C> to kill the subprocess. Guestfish sets this flag to
  1353. true when used interactively, so that C<^C> can cancel
  1354. long-running commands gracefully (see C<guestfs_user_cancel>)." };
  1355. { defaults with
  1356. name = "get_pgroup";
  1357. style = RBool "pgroup", [], [];
  1358. shortdesc = "get process group flag";
  1359. longdesc = "\
  1360. This returns the process group flag." };
  1361. { defaults with
  1362. name = "set_smp";
  1363. style = RErr, [Int "smp"], [];
  1364. fish_alias = ["smp"]; config_only = true;
  1365. shortdesc = "set number of virtual CPUs in appliance";
  1366. longdesc = "\
  1367. Change the number of virtual CPUs assigned to the appliance. The
  1368. default is C<1>. Increasing this may improve performance, though
  1369. often it has no effect.
  1370. This function must be called before C<guestfs_launch>." };
  1371. { defaults with
  1372. name = "get_smp";
  1373. style = RInt "smp", [], [];
  1374. shortdesc = "get number of virtual CPUs in appliance";
  1375. longdesc = "\
  1376. This returns the number of virtual CPUs assigned to the appliance." };
  1377. { defaults with
  1378. name = "mount_local";
  1379. style = RErr, [String "localmountpoint"], [OBool "readonly"; OString "options"; OInt "cachetimeout"; OBool "debugcalls"];
  1380. shortdesc = "mount on the local filesystem";
  1381. longdesc = "\
  1382. This call exports the libguestfs-accessible filesystem to
  1383. a local mountpoint (directory) called C<localmountpoint>.
  1384. Ordinary reads and writes to files and directories under
  1385. C<localmountpoint> are redirected through libguestfs.
  1386. If the optional C<readonly> flag is set to true, then
  1387. writes to the filesystem return error C<EROFS>.
  1388. C<options> is a comma-separated list of mount options.
  1389. See L<guestmount(1)> for some useful options.
  1390. C<cachetimeout> sets the timeout (in seconds) for cached directory
  1391. entries. The default is 60 seconds. See L<guestmount(1)>
  1392. for further information.
  1393. If C<debugcalls> is set to true, then additional debugging
  1394. information is generated for every FUSE call.
  1395. When C<guestfs_mount_local> returns, the filesystem is ready,
  1396. but is not processing requests (access to it will block). You
  1397. have to call C<guestfs_mount_local_run> to run the main loop.
  1398. See L<guestfs(3)/MOUNT LOCAL> for full documentation." };
  1399. { defaults with
  1400. name = "mount_local_run";
  1401. style = RErr, [], [];
  1402. cancellable = true (* in a future version *);
  1403. shortdesc = "run main loop of mount on the local filesystem";
  1404. longdesc = "\
  1405. Run the main loop which translates kernel calls to libguestfs
  1406. calls.
  1407. This should only be called after C<guestfs_mount_local>
  1408. returns successfully. The call will not return until the
  1409. filesystem is unmounted.
  1410. B<Note> you must I<not> make concurrent libguestfs calls
  1411. on the same handle from another thread,
  1412. with the exception of C<guestfs_umount_local>.
  1413. You may call this from a different thread than the one which
  1414. called C<guestfs_mount_local>, subject to the usual rules
  1415. for threads and libguestfs (see
  1416. L<guestfs(3)/MULTIPLE HANDLES AND MULTIPLE THREADS>).
  1417. See L<guestfs(3)/MOUNT LOCAL> for full documentation." };
  1418. { defaults with
  1419. name = "umount_local";
  1420. style = RErr, [], [OBool "retry"];
  1421. tests = [] (* tests in fuse subdirectory *);
  1422. shortdesc = "unmount a locally mounted filesystem";
  1423. longdesc = "\
  1424. If libguestfs is exporting the filesystem on a local
  1425. mountpoint, then this unmounts it.
  1426. See L<guestfs(3)/MOUNT LOCAL> for full documentation." };
  1427. { defaults with
  1428. name = "max_disks";
  1429. style = RInt "disks", [], [];
  1430. shortdesc = "maximum number of disks that may be added";
  1431. longdesc = "\
  1432. Return the maximum number of disks that may be added to a
  1433. handle (eg. by C<guestfs_add_drive_opts> and similar calls).
  1434. This function was added in libguestfs 1.19.7. In previous
  1435. versions of libguestfs the limit was 25.
  1436. See L<guestfs(3)/MAXIMUM NUMBER OF DISKS> for additional
  1437. information on this topic." };
  1438. { defaults with
  1439. name = "canonical_device_name";
  1440. style = RString "canonical", [String "device"], [];
  1441. shortdesc = "return canonical device name";
  1442. longdesc = "\
  1443. This utility function is useful when displaying device names to
  1444. the user. It takes a number of irregular device names and
  1445. returns them in a consistent format:
  1446. =over 4
  1447. =item C</dev/hdX>
  1448. =item C</dev/vdX>
  1449. These are returned as C</dev/sdX>. Note this works for device
  1450. names and partition names. This is approximately the reverse of
  1451. the algorithm described in L<guestfs(3)/BLOCK DEVICE NAMING>.
  1452. =item C</dev/mapper/VG-LV>
  1453. =item C</dev/dm-N>
  1454. Converted to C</dev/VG/LV> form using C<guestfs_lvm_canonical_lvm_name>.
  1455. =back
  1456. Other strings are returned unmodified." };
  1457. { defaults with
  1458. name = "shutdown";
  1459. style = RErr, [], [];
  1460. shortdesc = "shutdown the qemu subprocess";
  1461. longdesc = "\
  1462. This is the opposite of C<guestfs_launch>. It performs an orderly
  1463. shutdown of the backend process(es). If the autosync flag is set
  1464. (which is the default) then the disk image is synchronized.
  1465. If the subprocess exits with an error then this function will return
  1466. an error, which should I<not> be ignored (it may indicate that the
  1467. disk image could not be written out properly).
  1468. It is safe to call this multiple times. Extra calls are ignored.
  1469. This call does I<not> close or free up the handle. You still
  1470. need to call C<guestfs_close> afterwards.
  1471. C<guestfs_close> will call this if you don't do it explicitly,
  1472. but note that any errors are ignored in that case." };
  1473. ]
  1474. (* daemon_functions are any functions which cause some action
  1475. * to take place in the daemon.
  1476. *)
  1477. let daemon_functions = [
  1478. { defaults with
  1479. name = "mount";
  1480. style = RErr, [Device "device"; String "mountpoint"], [];
  1481. proc_nr = Some 1;
  1482. tests = [
  1483. InitEmpty, Always, TestOutput (
  1484. [["part_disk"; "/dev/sda"; "mbr"];
  1485. ["mkfs"; "ext2"; "/dev/sda1"; ""; "NOARG"; ""; ""];
  1486. ["mount"; "/dev/sda1"; "/"];
  1487. ["write"; "/new"; "new file contents"];
  1488. ["cat"; "/new"]], "new file contents")
  1489. ];
  1490. shortdesc = "mount a guest disk at a position in the filesystem";
  1491. longdesc = "\
  1492. Mount a guest disk at a position in the filesystem. Block devices
  1493. are named C</dev/sda>, C</dev/sdb> and so on, as they were added to
  1494. the guest. If those block devices contain partitions, they will have
  1495. the usual names (eg. C</dev/sda1>). Also LVM C</dev/VG/LV>-style
  1496. names can be used.
  1497. The rules are the same as for L<mount(2)>: A filesystem must
  1498. first be mounted on C</> before others can be mounted. Other
  1499. filesystems can only be mounted on directories which already
  1500. exist.
  1501. The mounted filesystem is writable, if we have sufficient permissions
  1502. on the underlying device.
  1503. Before libguestfs 1.13.16, this call implicitly added the options
  1504. C<sync> and C<noatime>. The C<sync> option greatly slowed
  1505. writes and caused many problems for users. If your program
  1506. might need to work with older versions of libguestfs, use
  1507. C<guestfs_mount_options> instead (using an empty string for the
  1508. first parameter if you don't want any options)." };
  1509. { defaults with
  1510. name = "sync";
  1511. style = RErr, [], [];
  1512. proc_nr = Some 2;
  1513. tests = [
  1514. InitEmpty, Always, TestRun [["sync"]]
  1515. ];
  1516. shortdesc = "sync disks, writes are flushed through to the disk image";
  1517. longdesc = "\
  1518. This syncs the disk, so that any writes are flushed through to the
  1519. underlying disk image.
  1520. You should always call this if you have modified a disk image, before
  1521. closing the handle." };
  1522. { defaults with
  1523. name = "touch";
  1524. style = RErr, [Pathname "path"], [];
  1525. proc_nr = Some 3;
  1526. tests = [
  1527. InitScratchFS, Always, TestOutputTrue (
  1528. [["touch"; "/touch"];
  1529. ["exists"; "/touch"]])
  1530. ];
  1531. shortdesc = "update file timestamps or create a new file";
  1532. longdesc = "\
  1533. Touch acts like the L<touch(1)> command. It can be used to
  1534. update the timestamps on a file, or, if the file does not exist,
  1535. to create a new zero-length file.
  1536. This command only works on regular files, and will fail on other
  1537. file types such as directories, symbolic links, block special etc." };
  1538. { defaults with
  1539. name = "cat";
  1540. style = RString "content", [Pathname "path"], [];
  1541. proc_nr = Some 4;
  1542. protocol_limit_warning = true;
  1543. tests = [
  1544. InitISOFS, Always, TestOutput (
  1545. [["cat"; "/known-2"]], "abcdef\n")
  1546. ];
  1547. shortdesc = "list the contents of a file";
  1548. longdesc = "\
  1549. Return the contents of the file named C<path>.
  1550. Note that this function cannot correctly handle binary files
  1551. (specifically, files containing C<\\0> character which is treated
  1552. as end of string). For those you need to use the C<guestfs_read_file>
  1553. or C<guestfs_download> functions which have a more complex interface." };
  1554. { defaults with
  1555. name = "ll";
  1556. style = RString "listing", [Pathname "directory"], [];
  1557. proc_nr = Some 5;
  1558. tests = []; (* XXX Tricky to test because it depends on the exact format
  1559. * of the 'ls -l' command, which changes between F10 and F11.
  1560. *)
  1561. shortdesc = "list the files in a directory (long format)";
  1562. longdesc = "\
  1563. List the files in C<directory> (relative to the root directory,
  1564. there is no cwd) in the format of 'ls -la'.
  1565. This command is mostly useful for interactive sessions. It
  1566. is I<not> intended that you try to parse the output string." };
  1567. { defaults with
  1568. name = "ls";
  1569. style = RStringList "listing", [Pathname "directory"], [];
  1570. proc_nr = Some 6;
  1571. tests = [
  1572. InitScratchFS, Always, TestOutputList (
  1573. [["mkdir"; "/ls"];
  1574. ["touch"; "/ls/new"];
  1575. ["touch"; "/ls/newer"];
  1576. ["touch"; "/ls/newest"];
  1577. ["ls"; "/ls"]], ["new"; "newer"; "newest"])
  1578. ];
  1579. shortdesc = "list the files in a directory";
  1580. longdesc = "\
  1581. List the files in C<directory> (relative to the root directory,
  1582. there is no cwd). The '.' and '..' entries are not returned, but
  1583. hidden files are shown.
  1584. This command is mostly useful for interactive sessions. Programs
  1585. should probably use C<guestfs_readdir> instead." };
  1586. { defaults with
  1587. name = "list_devices";
  1588. style = RStringList "devices", [], [];
  1589. proc_nr = Some 7;
  1590. tests = [
  1591. InitEmpty, Always, TestOutputListOfDevices (
  1592. [["list_devices"]], ["/dev/sda"; "/dev/sdb"; "/dev/sdc"; "/dev/sdd"])
  1593. ];
  1594. shortdesc = "list the block devices";
  1595. longdesc = "\
  1596. List all the block devices.
  1597. The full block device names are returned, eg. C</dev/sda>.
  1598. See also C<guestfs_list_filesystems>." };
  1599. { defaults with
  1600. name = "list_partitions";
  1601. style = RStringList "partitions", [], [];
  1602. proc_nr = Some 8;
  1603. tests = [
  1604. InitBasicFS, Always, TestOutputListOfDevices (
  1605. [["list_partitions"]], ["/dev/sda1"; "/dev/sdb1"]);
  1606. InitEmpty, Always, TestOutputListOfDevices (
  1607. [["part_init"; "/dev/sda"; "mbr"];
  1608. ["part_add"; "/dev/sda"; "p"; "64"; "204799"];
  1609. ["part_add"; "/dev/sda"; "p"; "204800"; "409599"];
  1610. ["part_add"; "/dev/sda"; "p"; "409600"; "-64"];
  1611. ["list_partitions"]], ["/dev/sda1"; "/dev/sda2"; "/dev/sda3"; "/dev/sdb1"])
  1612. ];
  1613. shortdesc = "list the partitions";
  1614. longdesc = "\
  1615. List all the partitions detected on all block devices.
  1616. The full partition device names are returned, eg. C</dev/sda1>
  1617. This does not return logical volumes. For that you will need to
  1618. call C<guestfs_lvs>.
  1619. See also C<guestfs_list_filesystems>." };
  1620. { defaults with
  1621. name = "pvs";
  1622. style = RStringList "physvols", [], [];
  1623. proc_nr = Some 9;
  1624. optional = Some "lvm2";
  1625. tests = [
  1626. InitBasicFSonLVM, Always, TestOutputListOfDevices (
  1627. [["pvs"]], ["/dev/sda1"]);
  1628. InitEmpty, Always, TestOutputListOfDevices (
  1629. [["part_init"; "/dev/sda"; "mbr"];
  1630. ["part_add"; "/dev/sda"; "p"; "64"; "204799"];
  1631. ["part_add"; "/dev/sda"; "p"; "204800"; "409599"];
  1632. ["part_add"; "/dev/sda"; "p"; "409600"; "-64"];
  1633. ["pvcreate"; "/dev/sda1"];
  1634. ["pvcreate"; "/dev/sda2"];
  1635. ["pvcreate"; "/dev/sda3"];
  1636. ["pvs"]], ["/dev/sda1"; "/dev/sda2"; "/dev/sda3"])
  1637. ];
  1638. shortdesc = "list the LVM physical volumes (PVs)";
  1639. longdesc = "\
  1640. List all the physical volumes detected. This is the equivalent
  1641. of the L<pvs(8)> command.
  1642. This returns a list of just the device names that contain
  1643. PVs (eg. C</dev/sda2>).
  1644. See also C<guestfs_pvs_full>." };
  1645. { defaults with
  1646. name = "vgs";
  1647. style = RStringList "volgroups", [], [];
  1648. proc_nr = Some 10;
  1649. optional = Some "lvm2";
  1650. tests = [
  1651. InitBasicFSonLVM, Always, TestOutputList (
  1652. [["vgs"]], ["VG"]);
  1653. InitEmpty, Always, TestOutputList (
  1654. [["part_init"; "/dev/sda"; "mbr"];
  1655. ["part_add"; "/dev/sda"; "p"; "64"; "204799"];
  1656. ["part_add"; "/dev/sda"; "p"; "204800"; "409599"];
  1657. ["part_add"; "/dev/sda"; "p"; "409600"; "-64"];
  1658. ["pvcreate"; "/dev/sda1"];
  1659. ["pvcreate"; "/dev/sda2"];
  1660. ["pvcreate"; "/dev/sda3"];
  1661. ["vgcreate"; "VG1"; "/dev/sda1 /dev/sda2"];
  1662. ["vgcreate"; "VG2"; "/dev/sda3"];
  1663. ["vgs"]], ["VG1"; "VG2"])
  1664. ];
  1665. shortdesc = "list the LVM volume groups (VGs)";
  1666. longdesc = "\
  1667. List all the volumes groups detected. This is the equivalent
  1668. of the L<vgs(8)> command.
  1669. This returns a list of just the volume group names that were
  1670. detected (eg. C<VolGroup00>).
  1671. See also C<guestfs_vgs_full>." };
  1672. { defaults with
  1673. name = "lvs";
  1674. style = RStringList "logvols", [], [];
  1675. proc_nr = Some 11;
  1676. optional = Some "lvm2";
  1677. tests = [
  1678. InitBasicFSonLVM, Always, TestOutputList (
  1679. [["lvs"]], ["/dev/VG/LV"]);
  1680. InitEmpty, Always, TestOutputList (
  1681. [["part_init"; "/dev/sda"; "mbr"];
  1682. ["part_add"; "/dev/sda"; "p"; "64"; "204799"];
  1683. ["part_add"; "/dev/sda"; "p"; "204800"; "409599"];
  1684. ["part_add"; "/dev/sda"; "p"; "409600"; "-64"];
  1685. ["pvcreate"; "/dev/sda1"];
  1686. ["pvcreate"; "/dev/sda2"];
  1687. ["pvcreate"; "/dev/sda3"];
  1688. ["vgcreate"; "VG1"; "/dev/sda1 /dev/sda2"];
  1689. ["vgcreate"; "VG2"; "/dev/sda3"];
  1690. ["lvcreate"; "LV1"; "VG1"; "50"];
  1691. ["lvcreate"; "LV2"; "VG1"; "50"];
  1692. ["lvcreate"; "LV3"; "VG2"; "50"];
  1693. ["lvs"]], ["/dev/VG1/LV1"; "/dev/VG1/LV2"; "/dev/VG2/LV3"])
  1694. ];
  1695. shortdesc = "list the LVM logical volumes (LVs)";
  1696. longdesc = "\
  1697. List all the logical volumes detected. This is the equivalent
  1698. of the L<lvs(8)> command.
  1699. This returns a list of the logical volume device names
  1700. (eg. C</dev/VolGroup00/LogVol00>).
  1701. See also C<guestfs_lvs_full>, C<guestfs_list_filesystems>." };
  1702. { defaults with
  1703. name = "pvs_full";
  1704. style = RStructList ("physvols", "lvm_pv"), [], [];
  1705. proc_nr = Some 12;
  1706. optional = Some "lvm2";
  1707. shortdesc = "list the LVM physical volumes (PVs)";
  1708. longdesc = "\
  1709. List all the physical volumes detected. This is the equivalent
  1710. of the L<pvs(8)> command. The \"full\" version includes all fields." };
  1711. { defaults with
  1712. name = "vgs_full";
  1713. style = RStructList ("volgroups", "lvm_vg"), [], [];
  1714. proc_nr = Some 13;
  1715. optional = Some "lvm2";
  1716. shortdesc = "list the LVM volume groups (VGs)";
  1717. longdesc = "\
  1718. List all the volumes groups detected. This is the equivalent
  1719. of the L<vgs(8)> command. The \"full\" version includes all fields." };
  1720. { defaults with
  1721. name = "lvs_full";
  1722. style = RStructList ("logvols", "lvm_lv"), [], [];
  1723. proc_nr = Some 14;
  1724. optional = Some "lvm2";
  1725. shortdesc = "list the LVM logical volumes (LVs)";
  1726. longdesc = "\
  1727. List all the logical volumes detected. This is the equivalent
  1728. of the L<lvs(8)> command. The \"full\" version includes all fields." };
  1729. { defaults with
  1730. name = "read_lines";
  1731. style = RStringList "lines", [Pathname "path"], [];
  1732. proc_nr = Some 15;
  1733. tests = [
  1734. InitISOFS, Always, TestOutputList (
  1735. [["read_lines"; "/known-4"]], ["abc"; "def"; "ghi"]);
  1736. InitISOFS, Always, TestOutputList (
  1737. [["read_lines"; "/empty"]], [])
  1738. ];
  1739. shortdesc = "read file as lines";
  1740. longdesc = "\
  1741. Return the contents of the file named C<path>.
  1742. The file contents are returned as a list of lines. Trailing
  1743. C<LF> and C<CRLF> character sequences are I<not> returned.
  1744. Note that this function cannot correctly handle binary files
  1745. (specifically, files containing C<\\0> character which is treated
  1746. as end of line). For those you need to use the C<guestfs_read_file>
  1747. function which has a more complex interface." };
  1748. { defaults with
  1749. name = "aug_init";
  1750. style = RErr, [Pathname "root"; Int "flags"], [];
  1751. proc_nr = Some 16;
  1752. optional = Some "augeas";
  1753. shortdesc = "create a new Augeas handle";
  1754. longdesc = "\
  1755. Create a new Augeas handle for editing configuration files.
  1756. If there was any previous Augeas handle associated with this
  1757. guestfs session, then it is closed.
  1758. You must call this before using any other C<guestfs_aug_*>
  1759. commands.
  1760. C<root> is the filesystem root. C<root> must not be NULL,
  1761. use C</> instead.
  1762. The flags are the same as the flags defined in
  1763. E<lt>augeas.hE<gt>, the logical I<or> of the following
  1764. integers:
  1765. =over 4
  1766. =item C<AUG_SAVE_BACKUP> = 1
  1767. Keep the original file with a C<.augsave> extension.
  1768. =item C<AUG_SAVE_NEWFILE> = 2
  1769. Save changes into a file with extension C<.augnew>, and
  1770. do not overwrite original. Overrides C<AUG_SAVE_BACKUP>.
  1771. =item C<AUG_TYPE_CHECK> = 4
  1772. Typecheck lenses.
  1773. This option is only useful when debugging Augeas lenses. Use
  1774. of this option may require additional memory for the libguestfs
  1775. appliance. You may need to set the C<LIBGUESTFS_MEMSIZE>
  1776. environment variable or call C<guestfs_set_memsize>.
  1777. =item C<AUG_NO_STDINC> = 8
  1778. Do not use standard load path for modules.
  1779. =item C<AUG_SAVE_NOOP> = 16
  1780. Make save a no-op, just record what would have been changed.
  1781. =item C<AUG_NO_LOAD> = 32
  1782. Do not load the tree in C<guestfs_aug_init>.
  1783. =back
  1784. To close the handle, you can call C<guestfs_aug_close>.
  1785. To find out more about Augeas, see L<http://augeas.net/>." };
  1786. { defaults with
  1787. name = "aug_close";
  1788. style = RErr, [], [];
  1789. proc_nr = Some 26;
  1790. optional = Some "augeas";
  1791. shortdesc = "close the current Augeas handle";
  1792. longdesc = "\
  1793. Close the current Augeas handle and free up any resources
  1794. used by it. After calling this, you have to call
  1795. C<guestfs_aug_init> again before you can use any other
  1796. Augeas functions." };
  1797. { defaults with
  1798. name = "aug_defvar";
  1799. style = RInt "nrnodes", [String "name"; OptString "expr"], [];
  1800. proc_nr = Some 17;
  1801. optional = Some "augeas";
  1802. shortdesc = "define an Augeas variable";
  1803. longdesc = "\
  1804. Defines an Augeas variable C<name> whose value is the result
  1805. of evaluating C<expr>. If C<expr> is NULL, then C<name> is
  1806. undefined.
  1807. On success this returns the number of nodes in C<expr>, or
  1808. C<0> if C<expr> evaluates to something which is not a nodeset." };
  1809. { defaults with
  1810. name = "aug_defnode";
  1811. style = RStruct ("nrnodescreated", "int_bool"), [String "name"; String "expr"; String "val"], [];
  1812. proc_nr = Some 18;
  1813. optional = Some "augeas";
  1814. shortdesc = "define an Augeas node";
  1815. longdesc = "\
  1816. Defines a variable C<name> whose value is the result of
  1817. evaluating C<expr>.
  1818. If C<expr> evaluates to an empty nodeset, a node is created,
  1819. equivalent to calling C<guestfs_aug_set> C<expr>, C<value>.
  1820. C<name> will be the nodeset containing that single node.
  1821. On success this returns a pair containing the
  1822. number of nodes in the nodeset, and a boolean flag
  1823. if a node was created." };
  1824. { defaults with
  1825. name = "aug_get";
  1826. style = RString "val", [String "augpath"], [];
  1827. proc_nr = Some 19;
  1828. optional = Some "augeas";
  1829. shortdesc = "look up the value of an Augeas path";
  1830. longdesc = "\
  1831. Look up the value associated with C<path>. If C<path>
  1832. matches exactly one node, the C<value> is returned." };
  1833. { defaults with
  1834. name = "aug_set";
  1835. style = RErr, [String "augpath"; String "val"], [];
  1836. proc_nr = Some 20;
  1837. optional = Some "augeas";
  1838. shortdesc = "set Augeas path to value";
  1839. longdesc = "\
  1840. Set the value associated with C<path> to C<val>.
  1841. In the Augeas API, it is possible to clear a node by setting
  1842. the value to NULL. Due to an oversight in the libguestfs API
  1843. you cannot do that with this call. Instead you must use the
  1844. C<guestfs_aug_clear> call." };
  1845. { defaults with
  1846. name = "aug_insert";
  1847. style = RErr, [String "augpath"; String "label"; Bool "before"], [];
  1848. proc_nr = Some 21;
  1849. optional = Some "augeas";
  1850. shortdesc = "insert a sibling Augeas node";
  1851. longdesc = "\
  1852. Create a new sibling C<label> for C<path>, inserting it into
  1853. the tree before or after C<path> (depending on the boolean
  1854. flag C<before>).
  1855. C<path> must match exactly one existing node in the tree, and
  1856. C<label> must be a label, ie. not contain C</>, C<*> or end
  1857. with a bracketed index C<[N]>." };
  1858. { defaults with
  1859. name = "aug_rm";
  1860. style = RInt "nrnodes", [String "augpath"], [];
  1861. proc_nr = Some 22;
  1862. optional = Some "augeas";
  1863. shortdesc = "remove an Augeas path";
  1864. longdesc = "\
  1865. Remove C<path> and all of its children.
  1866. On success this returns the number of entries which were removed." };
  1867. { defaults with
  1868. name = "aug_mv";
  1869. style = RErr, [String "src"; String "dest"], [];
  1870. proc_nr = Some 23;
  1871. optional = Some "augeas";
  1872. shortdesc = "move Augeas node";
  1873. longdesc = "\
  1874. Move the node C<src> to C<dest>. C<src> must match exactly
  1875. one node. C<dest> is overwritten if it exists." };
  1876. { defaults with
  1877. name = "aug_match";
  1878. style = RStringList "matches", [String "augpath"], [];
  1879. proc_nr = Some 24;
  1880. optional = Some "augeas";
  1881. shortdesc = "return Augeas nodes which match augpath";
  1882. longdesc = "\
  1883. Returns a list of paths which match the path expression C<path>.
  1884. The returned paths are sufficiently qualified so that they match
  1885. exactly one node in the current tree." };
  1886. { defaults with
  1887. name = "aug_save";
  1888. style = RErr, [], [];
  1889. proc_nr = Some 25;
  1890. optional = Some "augeas";
  1891. shortdesc = "write all pending Augeas changes to disk";
  1892. longdesc = "\
  1893. This writes all pending changes to disk.
  1894. The flags which were passed to C<guestfs_aug_init> affect exactly
  1895. how files are saved." };
  1896. { defaults with
  1897. name = "aug_load";
  1898. style = RErr, [], [];
  1899. proc_nr = Some 27;
  1900. optional = Some "augeas";
  1901. shortdesc = "load files into the tree";
  1902. longdesc = "\
  1903. Load files into the tree.
  1904. See C<aug_load> in the Augeas documentation for the full gory
  1905. details." };
  1906. { defaults with
  1907. name = "aug_ls";
  1908. style = RStringList "matches", [String "augpath"], [];
  1909. proc_nr = Some 28;
  1910. optional = Some "augeas";
  1911. shortdesc = "list Augeas nodes under augpath";
  1912. longdesc = "\
  1913. This is just a shortcut for listing C<guestfs_aug_match>
  1914. C<path/*> and sorting the resulting nodes into alphabetical order." };
  1915. { defaults with
  1916. name = "rm";
  1917. style = RErr, [Pathname "path"], [];
  1918. proc_nr = Some 29;
  1919. tests = [
  1920. InitScratchFS, Always, TestRun
  1921. [["mkdir"; "/rm"];
  1922. ["touch"; "/rm/new"];
  1923. ["rm"; "/rm/new"]];
  1924. InitScratchFS, Always, TestLastFail
  1925. [["rm"; "/nosuchfile"]];
  1926. InitScratchFS, Always, TestLastFail
  1927. [["mkdir"; "/rm2"];
  1928. ["rm"; "/rm2"]]
  1929. ];
  1930. shortdesc = "remove a file";
  1931. longdesc = "\
  1932. Remove the single file C<path>." };
  1933. { defaults with
  1934. name = "rmdir";
  1935. style = RErr, [Pathname "path"], [];
  1936. proc_nr = Some 30;
  1937. tests = [
  1938. InitScratchFS, Always, TestRun
  1939. [["mkdir"; "/rmdir"];
  1940. ["rmdir"; "/rmdir"]];
  1941. InitScratchFS, Always, TestLastFail
  1942. [["rmdir"; "/rmdir2"]];
  1943. InitScratchFS, Always, TestLastFail
  1944. [["mkdir"; "/rmdir3"];
  1945. ["touch"; "/rmdir3/new"];
  1946. ["rmdir"; "/rmdir3/new"]]
  1947. ];
  1948. shortdesc = "remove a directory";
  1949. longdesc = "\
  1950. Remove the single directory C<path>." };
  1951. { defaults with
  1952. name = "rm_rf";
  1953. style = RErr, [Pathname "path"], [];
  1954. proc_nr = Some 31;
  1955. tests = [
  1956. InitScratchFS, Always, TestOutputFalse
  1957. [["mkdir"; "/rm_rf"];
  1958. ["mkdir"; "/rm_rf/foo"];
  1959. ["touch"; "/rm_rf/foo/bar"];
  1960. ["rm_rf"; "/rm_rf"];
  1961. ["exists"; "/rm_rf"]]
  1962. ];
  1963. shortdesc = "remove a file or directory recursively";
  1964. longdesc = "\
  1965. Remove the file or directory C<path>, recursively removing the
  1966. contents if its a directory. This is like the C<rm -rf> shell
  1967. command." };
  1968. { defaults with
  1969. name = "mkdir";
  1970. style = RErr, [Pathname "path"], [];
  1971. proc_nr = Some 32;
  1972. tests = [
  1973. InitScratchFS, Always, TestOutputTrue
  1974. [["mkdir"; "/mkdir"];
  1975. ["is_dir"; "/mkdir"]];
  1976. InitScratchFS, Always, TestLastFail
  1977. [["mkdir"; "/mkdir2/foo/bar"]]
  1978. ];
  1979. shortdesc = "create a directory";
  1980. longdesc = "\
  1981. Create a directory named C<path>." };
  1982. { defaults with
  1983. name = "mkdir_p";
  1984. style = RErr, [Pathname "path"], [];
  1985. proc_nr = Some 33;
  1986. tests = [
  1987. InitScratchFS, Always, TestOutputTrue
  1988. [["mkdir_p"; "/mkdir_p/foo/bar"];
  1989. ["is_dir"; "/mkdir_p/foo/bar"]];
  1990. InitScratchFS, Always, TestOutputTrue
  1991. [["mkdir_p"; "/mkdir_p2/foo/bar"];
  1992. ["is_dir"; "/mkdir_p2/foo"]];
  1993. InitScratchFS, Always, TestOutputTrue
  1994. [["mkdir_p"; "/mkdir_p3/foo/bar"];
  1995. ["is_dir"; "/mkdir_p3"]];
  1996. (* Regression tests for RHBZ#503133: *)
  1997. InitScratchFS, Always, TestRun
  1998. [["mkdir"; "/mkdir_p4"];
  1999. ["mkdir_p"; "/mkdir_p4"]];
  2000. InitScratchFS, Always, TestLastFail
  2001. [["touch"; "/mkdir_p5"];
  2002. ["mkdir_p"; "/mkdir_p5"]]
  2003. ];
  2004. shortdesc = "create a directory and parents";
  2005. longdesc = "\
  2006. Create a directory named C<path>, creating any parent directories
  2007. as necessary. This is like the C<mkdir -p> shell command." };
  2008. { defaults with
  2009. name = "chmod";
  2010. style = RErr, [Int "mode"; Pathname "path"], [];
  2011. proc_nr = Some 34;
  2012. tests = [] (* XXX Need stat command to test *);
  2013. shortdesc = "change file mode";
  2014. longdesc = "\
  2015. Change the mode (permissions) of C<path> to C<mode>. Only
  2016. numeric modes are supported.
  2017. I<Note>: When using this command from guestfish, C<mode>
  2018. by default would be decimal, unless you prefix it with
  2019. C<0> to get octal, ie. use C<0700> not C<700>.
  2020. The mode actually set is affected by the umask." };
  2021. { defaults with
  2022. name = "chown";
  2023. style = RErr, [Int "owner"; Int "group"; Pathname "path"], [];
  2024. proc_nr = Some 35;
  2025. tests = [] (* XXX Need stat command to test *);
  2026. shortdesc = "change file owner and group";
  2027. longdesc = "\
  2028. Change the file owner to C<owner> and group to C<group>.
  2029. Only numeric uid and gid are supported. If you want to use
  2030. names, you will need to locate and parse the password file
  2031. yourself (Augeas support makes this relatively easy)." };
  2032. { defaults with
  2033. name = "exists";
  2034. style = RBool "existsflag", [Pathname "path"], [];
  2035. proc_nr = Some 36;
  2036. tests = [
  2037. InitISOFS, Always, TestOutputTrue (
  2038. [["exists"; "/empty"]]);
  2039. InitISOFS, Always, TestOutputTrue (
  2040. [["exists"; "/directory"]])
  2041. ];
  2042. shortdesc = "test if file or directory exists";
  2043. longdesc = "\
  2044. This returns C<true> if and only if there is a file, directory
  2045. (or anything) with the given C<path> name.
  2046. See also C<guestfs_is_file>, C<guestfs_is_dir>, C<guestfs_stat>." };
  2047. { defaults with
  2048. name = "is_file";
  2049. style = RBool "fileflag", [Pathname "path"], [];
  2050. proc_nr = Some 37;
  2051. tests = [
  2052. InitISOFS, Always, TestOutputTrue (
  2053. [["is_file"; "/known-1"]]);
  2054. InitISOFS, Always, TestOutputFalse (
  2055. [["is_file"; "/directory"]])
  2056. ];
  2057. shortdesc = "test if a regular file";
  2058. longdesc = "\
  2059. This returns C<true> if and only if there is a regular file
  2060. with the given C<path> name. Note that it returns false for
  2061. other objects like directories.
  2062. See also C<guestfs_stat>." };
  2063. { defaults with
  2064. name = "is_dir";
  2065. style = RBool "dirflag", [Pathname "path"], [];
  2066. proc_nr = Some 38;
  2067. tests = [
  2068. InitISOFS, Always, TestOutputFalse (
  2069. [["is_dir"; "/known-3"]]);
  2070. InitISOFS, Always, TestOutputTrue (
  2071. [["is_dir"; "/directory"]])
  2072. ];
  2073. shortdesc = "test if a directory";
  2074. longdesc = "\
  2075. This returns C<true> if and only if there is a directory
  2076. with the given C<path> name. Note that it returns false for
  2077. other objects like files.
  2078. See also C<guestfs_stat>." };
  2079. { defaults with
  2080. name = "pvcreate";
  2081. style = RErr, [Device "device"], [];
  2082. proc_nr = Some 39;
  2083. optional = Some "lvm2";
  2084. tests = [
  2085. InitEmpty, Always, TestOutputListOfDevices (
  2086. [["part_init"; "/dev/sda"; "mbr"];
  2087. ["part_add"; "/dev/sda"; "p"; "64"; "204799"];
  2088. ["part_add"; "/dev/sda"; "p"; "204800"; "409599"];
  2089. ["part_add"; "/dev/sda"; "p"; "409600"; "-64"];
  2090. ["pvcreate"; "/dev/sda1"];
  2091. ["pvcreate"; "/dev/sda2"];
  2092. ["pvcreate"; "/dev/sda3"];
  2093. ["pvs"]], ["/dev/sda1"; "/dev/sda2"; "/dev/sda3"])
  2094. ];
  2095. shortdesc = "create an LVM physical volume";
  2096. longdesc = "\
  2097. This creates an LVM physical volume on the named C<device>,
  2098. where C<device> should usually be a partition name such
  2099. as C</dev/sda1>." };
  2100. { defaults with
  2101. name = "vgcreate";
  2102. style = RErr, [String "volgroup"; DeviceList "physvols"], [];
  2103. proc_nr = Some 40;
  2104. optional = Some "lvm2";
  2105. tests = [
  2106. InitEmpty, Always, TestOutputList (
  2107. [["part_init"; "/dev/sda"; "mbr"];
  2108. ["part_add"; "/dev/sda"; "p"; "64"; "204799"];
  2109. ["part_add"; "/dev/sda"; "p"; "204800"; "409599"];
  2110. ["part_add"; "/dev/sda"; "p"; "409600"; "-64"];
  2111. ["pvcreate"; "/dev/sda1"];
  2112. ["pvcreate"; "/dev/sda2"];
  2113. ["pvcreate"; "/dev/sda3"];
  2114. ["vgcreate"; "VG1"; "/dev/sda1 /dev/sda2"];
  2115. ["vgcreate"; "VG2"; "/dev/sda3"];
  2116. ["vgs"]], ["VG1"; "VG2"])
  2117. ];
  2118. shortdesc = "create an LVM volume group";
  2119. longdesc = "\
  2120. This creates an LVM volume group called C<volgroup>
  2121. from the non-empty list of physical volumes C<physvols>." };
  2122. { defaults with
  2123. name = "lvcreate";
  2124. style = RErr, [String "logvol"; String "volgroup"; Int "mbytes"], [];
  2125. proc_nr = Some 41;
  2126. optional = Some "lvm2";
  2127. tests = [
  2128. InitEmpty, Always, TestOutputList (
  2129. [["part_init"; "/dev/sda"; "mbr"];
  2130. ["part_add"; "/dev/sda"; "p"; "64"; "204799"];
  2131. ["part_add"; "/dev/sda"; "p"; "204800"; "409599"];
  2132. ["part_add"; "/dev/sda"; "p"; "409600"; "-64"];
  2133. ["pvcreate"; "/dev/sda1"];
  2134. ["pvcreate"; "/dev/sda2"];
  2135. ["pvcreate"; "/dev/sda3"];
  2136. ["vgcreate"; "VG1"; "/dev/sda1 /dev/sda2"];
  2137. ["vgcreate"; "VG2"; "/dev/sda3"];
  2138. ["lvcreate"; "LV1"; "VG1"; "50"];
  2139. ["lvcreate"; "LV2"; "VG1"; "50"];
  2140. ["lvcreate"; "LV3"; "VG2"; "50"];
  2141. ["lvcreate"; "LV4"; "VG2"; "50"];
  2142. ["lvcreate"; "LV5"; "VG2"; "50"];
  2143. ["lvs"]],
  2144. ["/dev/VG1/LV1"; "/dev/VG1/LV2";
  2145. "/dev/VG2/LV3"; "/dev/VG2/LV4"; "/dev/VG2/LV5"])
  2146. ];
  2147. shortdesc = "create an LVM logical volume";
  2148. longdesc = "\
  2149. This creates an LVM logical volume called C<logvol>
  2150. on the volume group C<volgroup>, with C<size> megabytes." };
  2151. { defaults with
  2152. name = "sfdisk";
  2153. style = RErr, [Device "device";
  2154. Int "cyls"; Int "heads"; Int "sectors";
  2155. StringList "lines"], [];
  2156. proc_nr = Some 43;
  2157. deprecated_by = Some "part_add";
  2158. shortdesc = "create partitions on a block device";
  2159. longdesc = "\
  2160. This is a direct interface to the L<sfdisk(8)> program for creating
  2161. partitions on block devices.
  2162. C<device> should be a block device, for example C</dev/sda>.
  2163. C<cyls>, C<heads> and C<sectors> are the number of cylinders, heads
  2164. and sectors on the device, which are passed directly to sfdisk as
  2165. the I<-C>, I<-H> and I<-S> parameters. If you pass C<0> for any
  2166. of these, then the corresponding parameter is omitted. Usually for
  2167. 'large' disks, you can just pass C<0> for these, but for small
  2168. (floppy-sized) disks, sfdisk (or rather, the kernel) cannot work
  2169. out the right geometry and you will need to tell it.
  2170. C<lines> is a list of lines that we feed to C<sfdisk>. For more
  2171. information refer to the L<sfdisk(8)> manpage.
  2172. To create a single partition occupying the whole disk, you would
  2173. pass C<lines> as a single element list, when the single element being
  2174. the string C<,> (comma).
  2175. See also: C<guestfs_sfdisk_l>, C<guestfs_sfdisk_N>,
  2176. C<guestfs_part_init>" };
  2177. { defaults with
  2178. name = "write_file";
  2179. style = RErr, [Pathname "path"; String "content"; Int "size"], [];
  2180. proc_nr = Some 44;
  2181. protocol_limit_warning = true; deprecated_by = Some "write";
  2182. (* Regression test for RHBZ#597135. *)
  2183. tests = [
  2184. InitScratchFS, Always, TestLastFail
  2185. [["write_file"; "/write_file"; "abc"; "10000"]]
  2186. ];
  2187. shortdesc = "create a file";
  2188. longdesc = "\
  2189. This call creates a file called C<path>. The contents of the
  2190. file is the string C<content> (which can contain any 8 bit data),
  2191. with length C<size>.
  2192. As a special case, if C<size> is C<0>
  2193. then the length is calculated using C<strlen> (so in this case
  2194. the content cannot contain embedded ASCII NULs).
  2195. I<NB.> Owing to a bug, writing content containing ASCII NUL
  2196. characters does I<not> work, even if the length is specified." };
  2197. { defaults with
  2198. name = "umount";
  2199. style = RErr, [String "pathordevice"], [];
  2200. proc_nr = Some 45;
  2201. fish_alias = ["unmount"];
  2202. tests = [
  2203. InitEmpty, Always, TestOutputListOfDevices (
  2204. [["part_disk"; "/dev/sda"; "mbr"];
  2205. ["mkfs"; "ext2"; "/dev/sda1"; ""; "NOARG"; ""; ""];
  2206. ["mount_options"; ""; "/dev/sda1"; "/"];
  2207. ["mounts"]], ["/dev/sda1"]);
  2208. InitEmpty, Always, TestOutputList (
  2209. [["part_disk"; "/dev/sda"; "mbr"];
  2210. ["mkfs"; "ext2"; "/dev/sda1"; ""; "NOARG"; ""; ""];
  2211. ["mount_options"; ""; "/dev/sda1"; "/"];
  2212. ["umount"; "/"];
  2213. ["mounts"]], [])
  2214. ];
  2215. shortdesc = "unmount a filesystem";
  2216. longdesc = "\
  2217. This unmounts the given filesystem. The filesystem may be
  2218. specified either by its mountpoint (path) or the device which
  2219. contains the filesystem." };
  2220. { defaults with
  2221. name = "mounts";
  2222. style = RStringList "devices", [], [];
  2223. proc_nr = Some 46;
  2224. tests = [
  2225. InitScratchFS, Always, TestOutputListOfDevices (
  2226. [["mounts"]], ["/dev/sdb1"])
  2227. ];
  2228. shortdesc = "show mounted filesystems";
  2229. longdesc = "\
  2230. This returns the list of currently mounted filesystems. It returns
  2231. the list of devices (eg. C</dev/sda1>, C</dev/VG/LV>).
  2232. Some internal mounts are not shown.
  2233. See also: C<guestfs_mountpoints>" };
  2234. { defaults with
  2235. name = "umount_all";
  2236. style = RErr, [], [];
  2237. proc_nr = Some 47;
  2238. fish_alias = ["unmount-all"];
  2239. tests = [
  2240. InitScratchFS, Always, TestOutputList (
  2241. [["umount_all"];
  2242. ["mounts"]], []);
  2243. (* check that umount_all can unmount nested mounts correctly: *)
  2244. InitEmpty, Always, TestOutputList (
  2245. [["part_init"; "/dev/sda"; "mbr"];
  2246. ["part_add"; "/dev/sda"; "p"; "64"; "204799"];
  2247. ["part_add"; "/dev/sda"; "p"; "204800"; "409599"];
  2248. ["part_add"; "/dev/sda"; "p"; "409600"; "-64"];
  2249. ["mkfs"; "ext2"; "/dev/sda1"; ""; "NOARG"; ""; ""];
  2250. ["mkfs"; "ext2"; "/dev/sda2"; ""; "NOARG"; ""; ""];
  2251. ["mkfs"; "ext2"; "/dev/sda3"; ""; "NOARG"; ""; ""];
  2252. ["mount_options"; ""; "/dev/sda1"; "/"];
  2253. ["mkdir"; "/mp1"];
  2254. ["mount_options"; ""; "/dev/sda2"; "/mp1"];
  2255. ["mkdir"; "/mp1/mp2"];
  2256. ["mount_options"; ""; "/dev/sda3"; "/mp1/mp2"];
  2257. ["mkdir"; "/mp1/mp2/mp3"];
  2258. ["umount_all"];
  2259. ["mounts"]], [])
  2260. ];
  2261. shortdesc = "unmount all filesystems";
  2262. longdesc = "\
  2263. This unmounts all mounted filesystems.
  2264. Some internal mounts are not unmounted by this call." };
  2265. { defaults with
  2266. name = "lvm_remove_all";
  2267. style = RErr, [], [];
  2268. proc_nr = Some 48;
  2269. optional = Some "lvm2";
  2270. shortdesc = "remove all LVM LVs, VGs and PVs";
  2271. longdesc = "\
  2272. This command removes all LVM logical volumes, volume groups
  2273. and physical volumes." };
  2274. { defaults with
  2275. name = "file";
  2276. style = RString "description", [Dev_or_Path "path"], [];
  2277. proc_nr = Some 49;
  2278. tests = [
  2279. InitISOFS, Always, TestOutput (
  2280. [["file"; "/empty"]], "empty");
  2281. InitISOFS, Always, TestOutput (
  2282. [["file"; "/known-1"]], "ASCII text");
  2283. InitISOFS, Always, TestLastFail (
  2284. [["file"; "/notexists"]]);
  2285. InitISOFS, Always, TestOutput (
  2286. [["file"; "/abssymlink"]], "symbolic link");
  2287. InitISOFS, Always, TestOutput (
  2288. [["file"; "/directory"]], "directory")
  2289. ];
  2290. shortdesc = "determine file type";
  2291. longdesc = "\
  2292. This call uses the standard L<file(1)> command to determine
  2293. the type or contents of the file.
  2294. This call will also transparently look inside various types
  2295. of compressed file.
  2296. The exact command which runs is C<file -zb path>. Note in
  2297. particular that the filename is not prepended to the output
  2298. (the I<-b> option).
  2299. The output depends on the output of the underlying L<file(1)>
  2300. command and it can change in future in ways beyond our control.
  2301. In other words, the output is not guaranteed by the ABI.
  2302. See also: L<file(1)>, C<guestfs_vfs_type>, C<guestfs_lstat>,
  2303. C<guestfs_is_file>, C<guestfs_is_blockdev> (etc), C<guestfs_is_zero>." };
  2304. { defaults with
  2305. name = "command";
  2306. style = RString "output", [StringList "arguments"], [];
  2307. proc_nr = Some 50;
  2308. protocol_limit_warning = true;
  2309. tests = [
  2310. InitScratchFS, Always, TestOutput (
  2311. [["mkdir"; "/command"];
  2312. ["upload"; "test-command"; "/command/test-command"];
  2313. ["chmod"; "0o755"; "/command/test-command"];
  2314. ["command"; "/command/test-command 1"]], "Result1");
  2315. InitScratchFS, Always, TestOutput (
  2316. [["mkdir"; "/command2"];
  2317. ["upload"; "test-command"; "/command2/test-command"];
  2318. ["chmod"; "0o755"; "/command2/test-command"];
  2319. ["command"; "/command2/test-command 2"]], "Result2\n");
  2320. InitScratchFS, Always, TestOutput (
  2321. [["mkdir"; "/command3"];
  2322. ["upload"; "test-command"; "/command3/test-command"];
  2323. ["chmod"; "0o755"; "/command3/test-command"];
  2324. ["command"; "/command3/test-command 3"]], "\nResult3");
  2325. InitScratchFS, Always, TestOutput (
  2326. [["mkdir"; "/command4"];
  2327. ["upload"; "test-command"; "/command4/test-command"];
  2328. ["chmod"; "0o755"; "/command4/test-command"];
  2329. ["command"; "/command4/test-command 4"]], "\nResult4\n");
  2330. InitScratchFS, Always, TestOutput (
  2331. [["mkdir"; "/command5"];
  2332. ["upload"; "test-command"; "/command5/test-command"];
  2333. ["chmod"; "0o755"; "/command5/test-command"];
  2334. ["command"; "/command5/test-command 5"]], "\nResult5\n\n");
  2335. InitScratchFS, Always, TestOutput (
  2336. [["mkdir"; "/command6"];
  2337. ["upload"; "test-command"; "/command6/test-command"];
  2338. ["chmod"; "0o755"; "/command6/test-command"];
  2339. ["command"; "/command6/test-command 6"]], "\n\nResult6\n\n");
  2340. InitScratchFS, Always, TestOutput (
  2341. [["mkdir"; "/command7"];
  2342. ["upload"; "test-command"; "/command7/test-command"];
  2343. ["chmod"; "0o755"; "/command7/test-command"];
  2344. ["command"; "/command7/test-command 7"]], "");
  2345. InitScratchFS, Always, TestOutput (
  2346. [["mkdir"; "/command8"];
  2347. ["upload"; "test-command"; "/command8/test-command"];
  2348. ["chmod"; "0o755"; "/command8/test-command"];
  2349. ["command"; "/command8/test-command 8"]], "\n");
  2350. InitScratchFS, Always, TestOutput (
  2351. [["mkdir"; "/command9"];
  2352. ["upload"; "test-command"; "/command9/test-command"];
  2353. ["chmod"; "0o755"; "/command9/test-command"];
  2354. ["command"; "/command9/test-command 9"]], "\n\n");
  2355. InitScratchFS, Always, TestOutput (
  2356. [["mkdir"; "/command10"];
  2357. ["upload"; "test-command"; "/command10/test-command"];
  2358. ["chmod"; "0o755"; "/command10/test-command"];
  2359. ["command"; "/command10/test-command 10"]], "Result10-1\nResult10-2\n");
  2360. InitScratchFS, Always, TestOutput (
  2361. [["mkdir"; "/command11"];
  2362. ["upload"; "test-command"; "/command11/test-command"];
  2363. ["chmod"; "0o755"; "/command11/test-command"];
  2364. ["command"; "/command11/test-command 11"]], "Result11-1\nResult11-2");
  2365. InitScratchFS, Always, TestLastFail (
  2366. [["mkdir"; "/command12"];
  2367. ["upload"; "test-command"; "/command12/test-command"];
  2368. ["chmod"; "0o755"; "/command12/test-command"];
  2369. ["command"; "/command12/test-command"]])
  2370. ];
  2371. shortdesc = "run a command from the guest filesystem";
  2372. longdesc = "\
  2373. This call runs a command from the guest filesystem. The
  2374. filesystem must be mounted, and must contain a compatible
  2375. operating system (ie. something Linux, with the same
  2376. or compatible processor architecture).
  2377. The single parameter is an argv-style list of arguments.
  2378. The first element is the name of the program to run.
  2379. Subsequent elements are parameters. The list must be
  2380. non-empty (ie. must contain a program name). Note that
  2381. the command runs directly, and is I<not> invoked via
  2382. the shell (see C<guestfs_sh>).
  2383. The return value is anything printed to I<stdout> by
  2384. the command.
  2385. If the command returns a non-zero exit status, then
  2386. this function returns an error message. The error message
  2387. string is the content of I<stderr> from the command.
  2388. The C<$PATH> environment variable will contain at least
  2389. C</usr/bin> and C</bin>. If you require a program from
  2390. another location, you should provide the full path in the
  2391. first parameter.
  2392. Shared libraries and data files required by the program
  2393. must be available on filesystems which are mounted in the
  2394. correct places. It is the caller's responsibility to ensure
  2395. all filesystems that are needed are mounted at the right
  2396. locations." };
  2397. { defaults with
  2398. name = "command_lines";
  2399. style = RStringList "lines", [StringList "arguments"], [];
  2400. proc_nr = Some 51;
  2401. protocol_limit_warning = true;
  2402. tests = [
  2403. InitScratchFS, Always, TestOutputList (
  2404. [["mkdir"; "/command_lines"];
  2405. ["upload"; "test-command"; "/command_lines/test-command"];
  2406. ["chmod"; "0o755"; "/command_lines/test-command"];
  2407. ["command_lines"; "/command_lines/test-command 1"]], ["Result1"]);
  2408. InitScratchFS, Always, TestOutputList (
  2409. [["mkdir"; "/command_lines2"];
  2410. ["upload"; "test-command"; "/command_lines2/test-command"];
  2411. ["chmod"; "0o755"; "/command_lines2/test-command"];
  2412. ["command_lines"; "/command_lines2/test-command 2"]], ["Result2"]);
  2413. InitScratchFS, Always, TestOutputList (
  2414. [["mkdir"; "/command_lines3"];
  2415. ["upload"; "test-command"; "/command_lines3/test-command"];
  2416. ["chmod"; "0o755"; "/command_lines3/test-command"];
  2417. ["command_lines"; "/command_lines3/test-command 3"]], ["";"Result3"]);
  2418. InitScratchFS, Always, TestOutputList (
  2419. [["mkdir"; "/command_lines4"];
  2420. ["upload"; "test-command"; "/command_lines4/test-command"];
  2421. ["chmod"; "0o755"; "/command_lines4/test-command"];
  2422. ["command_lines"; "/command_lines4/test-command 4"]], ["";"Result4"]);
  2423. InitScratchFS, Always, TestOutputList (
  2424. [["mkdir"; "/command_lines5"];
  2425. ["upload"; "test-command"; "/command_lines5/test-command"];
  2426. ["chmod"; "0o755"; "/command_lines5/test-command"];
  2427. ["command_lines"; "/command_lines5/test-command 5"]], ["";"Result5";""]);
  2428. InitScratchFS, Always, TestOutputList (
  2429. [["mkdir"; "/command_lines6"];
  2430. ["upload"; "test-command"; "/command_lines6/test-command"];
  2431. ["chmod"; "0o755"; "/command_lines6/test-command"];
  2432. ["command_lines"; "/command_lines6/test-command 6"]], ["";"";"Result6";""]);
  2433. InitScratchFS, Always, TestOutputList (
  2434. [["mkdir"; "/command_lines7"];
  2435. ["upload"; "test-command"; "/command_lines7/test-command"];
  2436. ["chmod"; "0o755"; "/command_lines7/test-command"];
  2437. ["command_lines"; "/command_lines7/test-command 7"]], []);
  2438. InitScratchFS, Always, TestOutputList (
  2439. [["mkdir"; "/command_lines8"];
  2440. ["upload"; "test-command"; "/command_lines8/test-command"];
  2441. ["chmod"; "0o755"; "/command_lines8/test-command"];
  2442. ["command_lines"; "/command_lines8/test-command 8"]], [""]);
  2443. InitScratchFS, Always, TestOutputList (
  2444. [["mkdir"; "/command_lines9"];
  2445. ["upload"; "test-command"; "/command_lines9/test-command"];
  2446. ["chmod"; "0o755"; "/command_lines9/test-command"];
  2447. ["command_lines"; "/command_lines9/test-command 9"]], ["";""]);
  2448. InitScratchFS, Always, TestOutputList (
  2449. [["mkdir"; "/command_lines10"];
  2450. ["upload"; "test-command"; "/command_lines10/test-command"];
  2451. ["chmod"; "0o755"; "/command_lines10/test-command"];
  2452. ["command_lines"; "/command_lines10/test-command 10"]], ["Result10-1";"Result10-2"]);
  2453. InitScratchFS, Always, TestOutputList (
  2454. [["mkdir"; "/command_lines11"];
  2455. ["upload"; "test-command"; "/command_lines11/test-command"];
  2456. ["chmod"; "0o755"; "/command_lines11/test-command"];
  2457. ["command_lines"; "/command_lines11/test-command 11"]], ["Result11-1";"Result11-2"])
  2458. ];
  2459. shortdesc = "run a command, returning lines";
  2460. longdesc = "\
  2461. This is the same as C<guestfs_command>, but splits the
  2462. result into a list of lines.
  2463. See also: C<guestfs_sh_lines>" };
  2464. { defaults with
  2465. name = "stat";
  2466. style = RStruct ("statbuf", "stat"), [Pathname "path"], [];
  2467. proc_nr = Some 52;
  2468. tests = [
  2469. InitISOFS, Always, TestOutputStruct (
  2470. [["stat"; "/empty"]], [CompareWithInt ("size", 0)])
  2471. ];
  2472. shortdesc = "get file information";
  2473. longdesc = "\
  2474. Returns file information for the given C<path>.
  2475. This is the same as the C<stat(2)> system call." };
  2476. { defaults with
  2477. name = "lstat";
  2478. style = RStruct ("statbuf", "stat"), [Pathname "path"], [];
  2479. proc_nr = Some 53;
  2480. tests = [
  2481. InitISOFS, Always, TestOutputStruct (
  2482. [["lstat"; "/empty"]], [CompareWithInt ("size", 0)])
  2483. ];
  2484. shortdesc = "get file information for a symbolic link";
  2485. longdesc = "\
  2486. Returns file information for the given C<path>.
  2487. This is the same as C<guestfs_stat> except that if C<path>
  2488. is a symbolic link, then the link is stat-ed, not the file it
  2489. refers to.
  2490. This is the same as the C<lstat(2)> system call." };
  2491. { defaults with
  2492. name = "statvfs";
  2493. style = RStruct ("statbuf", "statvfs"), [Pathname "path"], [];
  2494. proc_nr = Some 54;
  2495. tests = [
  2496. InitISOFS, Always, TestOutputStruct (
  2497. [["statvfs"; "/"]], [CompareWithInt ("namemax", 255)])
  2498. ];
  2499. shortdesc = "get file system statistics";
  2500. longdesc = "\
  2501. Returns file system statistics for any mounted file system.
  2502. C<path> should be a file or directory in the mounted file system
  2503. (typically it is the mount point itself, but it doesn't need to be).
  2504. This is the same as the C<statvfs(2)> system call." };
  2505. { defaults with
  2506. name = "tune2fs_l";
  2507. style = RHashtable "superblock", [Device "device"], [];
  2508. proc_nr = Some 55;
  2509. tests = [
  2510. InitScratchFS, Always, TestOutputHashtable (
  2511. [["tune2fs_l"; "/dev/sdb1"]],
  2512. ["Filesystem magic number", "0xEF53";
  2513. "Filesystem OS type", "Linux"])
  2514. ];
  2515. shortdesc = "get ext2/ext3/ext4 superblock details";
  2516. longdesc = "\
  2517. This returns the contents of the ext2, ext3 or ext4 filesystem
  2518. superblock on C<device>.
  2519. It is the same as running C<tune2fs -l device>. See L<tune2fs(8)>
  2520. manpage for more details. The list of fields returned isn't
  2521. clearly defined, and depends on both the version of C<tune2fs>
  2522. that libguestfs was built against, and the filesystem itself." };
  2523. { defaults with
  2524. name = "blockdev_setro";
  2525. style = RErr, [Device "device"], [];
  2526. proc_nr = Some 56;
  2527. tests = [
  2528. InitEmpty, Always, TestOutputTrue (
  2529. [["blockdev_setro"; "/dev/sda"];
  2530. ["blockdev_getro"; "/dev/sda"]])
  2531. ];
  2532. shortdesc = "set block device to read-only";
  2533. longdesc = "\
  2534. Sets the block device named C<device> to read-only.
  2535. This uses the L<blockdev(8)> command." };
  2536. { defaults with
  2537. name = "blockdev_setrw";
  2538. style = RErr, [Device "device"], [];
  2539. proc_nr = Some 57;
  2540. tests = [
  2541. InitEmpty, Always, TestOutputFalse (
  2542. [["blockdev_setrw"; "/dev/sda"];
  2543. ["blockdev_getro"; "/dev/sda"]])
  2544. ];
  2545. shortdesc = "set block device to read-write";
  2546. longdesc = "\
  2547. Sets the block device named C<device> to read-write.
  2548. This uses the L<blockdev(8)> command." };
  2549. { defaults with
  2550. name = "blockdev_getro";
  2551. style = RBool "ro", [Device "device"], [];
  2552. proc_nr = Some 58;
  2553. tests = [
  2554. InitEmpty, Always, TestOutputTrue (
  2555. [["blockdev_setro"; "/dev/sda"];
  2556. ["blockdev_getro"; "/dev/sda"]])
  2557. ];
  2558. shortdesc = "is block device set to read-only";
  2559. longdesc = "\
  2560. Returns a boolean indicating if the block device is read-only
  2561. (true if read-only, false if not).
  2562. This uses the L<blockdev(8)> command." };
  2563. { defaults with
  2564. name = "blockdev_getss";
  2565. style = RInt "sectorsize", [Device "device"], [];
  2566. proc_nr = Some 59;
  2567. tests = [
  2568. InitEmpty, Always, TestOutputInt (
  2569. [["blockdev_getss"; "/dev/sda"]], 512)
  2570. ];
  2571. shortdesc = "get sectorsize of block device";
  2572. longdesc = "\
  2573. This returns the size of sectors on a block device.
  2574. Usually 512, but can be larger for modern devices.
  2575. (Note, this is not the size in sectors, use C<guestfs_blockdev_getsz>
  2576. for that).
  2577. This uses the L<blockdev(8)> command." };
  2578. { defaults with
  2579. name = "blockdev_getbsz";
  2580. style = RInt "blocksize", [Device "device"], [];
  2581. proc_nr = Some 60;
  2582. (* cannot be tested because output differs depending on page size *)
  2583. tests = [];
  2584. shortdesc = "get blocksize of block device";
  2585. longdesc = "\
  2586. This returns the block size of a device.
  2587. (Note this is different from both I<size in blocks> and
  2588. I<filesystem block size>).
  2589. This uses the L<blockdev(8)> command." };
  2590. { defaults with
  2591. name = "blockdev_setbsz";
  2592. style = RErr, [Device "device"; Int "blocksize"], [];
  2593. proc_nr = Some 61;
  2594. shortdesc = "set blocksize of block device";
  2595. longdesc = "\
  2596. This sets the block size of a device.
  2597. (Note this is different from both I<size in blocks> and
  2598. I<filesystem block size>).
  2599. This uses the L<blockdev(8)> command." };
  2600. { defaults with
  2601. name = "blockdev_getsz";
  2602. style = RInt64 "sizeinsectors", [Device "device"], [];
  2603. proc_nr = Some 62;
  2604. tests = [
  2605. InitEmpty, Always, TestOutputInt (
  2606. [["blockdev_getsz"; "/dev/sda"]], 1024000)
  2607. ];
  2608. shortdesc = "get total size of device in 512-byte sectors";
  2609. longdesc = "\
  2610. This returns the size of the device in units of 512-byte sectors
  2611. (even if the sectorsize isn't 512 bytes ... weird).
  2612. See also C<guestfs_blockdev_getss> for the real sector size of
  2613. the device, and C<guestfs_blockdev_getsize64> for the more
  2614. useful I<size in bytes>.
  2615. This uses the L<blockdev(8)> command." };
  2616. { defaults with
  2617. name = "blockdev_getsize64";
  2618. style = RInt64 "sizeinbytes", [Device "device"], [];
  2619. proc_nr = Some 63;
  2620. tests = [
  2621. InitEmpty, Always, TestOutputInt (
  2622. [["blockdev_getsize64"; "/dev/sda"]], 524288000)
  2623. ];
  2624. shortdesc = "get total size of device in bytes";
  2625. longdesc = "\
  2626. This returns the size of the device in bytes.
  2627. See also C<guestfs_blockdev_getsz>.
  2628. This uses the L<blockdev(8)> command." };
  2629. { defaults with
  2630. name = "blockdev_flushbufs";
  2631. style = RErr, [Device "device"], [];
  2632. proc_nr = Some 64;
  2633. tests = [
  2634. InitEmpty, Always, TestRun
  2635. [["blockdev_flushbufs"; "/dev/sda"]]
  2636. ];
  2637. shortdesc = "flush device buffers";
  2638. longdesc = "\
  2639. This tells the kernel to flush internal buffers associated
  2640. with C<device>.
  2641. This uses the L<blockdev(8)> command." };
  2642. { defaults with
  2643. name = "blockdev_rereadpt";
  2644. style = RErr, [Device "device"], [];
  2645. proc_nr = Some 65;
  2646. tests = [
  2647. InitEmpty, Always, TestRun
  2648. [["blockdev_rereadpt"; "/dev/sda"]]
  2649. ];
  2650. shortdesc = "reread partition table";
  2651. longdesc = "\
  2652. Reread the partition table on C<device>.
  2653. This uses the L<blockdev(8)> command." };
  2654. { defaults with
  2655. name = "upload";
  2656. style = RErr, [FileIn "filename"; Dev_or_Path "remotefilename"], [];
  2657. proc_nr = Some 66;
  2658. progress = true; cancellable = true;
  2659. tests = [
  2660. InitScratchFS, Always, TestOutput (
  2661. (* Pick a file from cwd which isn't likely to change. *)
  2662. [["mkdir"; "/upload"];
  2663. ["upload"; "../../COPYING.LIB"; "/upload/COPYING.LIB"];
  2664. ["checksum"; "md5"; "/upload/COPYING.LIB"]],
  2665. Digest.to_hex (Digest.file "COPYING.LIB"))
  2666. ];
  2667. shortdesc = "upload a file from the local machine";
  2668. longdesc = "\
  2669. Upload local file C<filename> to C<remotefilename> on the
  2670. filesystem.
  2671. C<filename> can also be a named pipe.
  2672. See also C<guestfs_download>." };
  2673. { defaults with
  2674. name = "download";
  2675. style = RErr, [Dev_or_Path "remotefilename"; FileOut "filename"], [];
  2676. proc_nr = Some 67;
  2677. progress = true; cancellable = true;
  2678. tests = [
  2679. InitScratchFS, Always, TestOutput (
  2680. (* Pick a file from cwd which isn't likely to change. *)
  2681. [["mkdir"; "/download"];
  2682. ["upload"; "../../COPYING.LIB"; "/download/COPYING.LIB"];
  2683. ["download"; "/download/COPYING.LIB"; "testdownload.tmp"];
  2684. ["upload"; "testdownload.tmp"; "/download/upload"];
  2685. ["checksum"; "md5"; "/download/upload"]],
  2686. Digest.to_hex (Digest.file "COPYING.LIB"))
  2687. ];
  2688. shortdesc = "download a file to the local machine";
  2689. longdesc = "\
  2690. Download file C<remotefilename> and save it as C<filename>
  2691. on the local machine.
  2692. C<filename> can also be a named pipe.
  2693. See also C<guestfs_upload>, C<guestfs_cat>." };
  2694. { defaults with
  2695. name = "checksum";
  2696. style = RString "checksum", [String "csumtype"; Pathname "path"], [];
  2697. proc_nr = Some 68;
  2698. tests = [
  2699. InitISOFS, Always, TestOutput (
  2700. [["checksum"; "crc"; "/known-3"]], "2891671662");
  2701. InitISOFS, Always, TestLastFail (
  2702. [["checksum"; "crc"; "/notexists"]]);
  2703. InitISOFS, Always, TestOutput (
  2704. [["checksum"; "md5"; "/known-3"]], "46d6ca27ee07cdc6fa99c2e138cc522c");
  2705. InitISOFS, Always, TestOutput (
  2706. [["checksum"; "sha1"; "/known-3"]], "b7ebccc3ee418311091c3eda0a45b83c0a770f15");
  2707. InitISOFS, Always, TestOutput (
  2708. [["checksum"; "sha224"; "/known-3"]], "d2cd1774b28f3659c14116be0a6dc2bb5c4b350ce9cd5defac707741");
  2709. InitISOFS, Always, TestOutput (
  2710. [["checksum"; "sha256"; "/known-3"]], "75bb71b90cd20cb13f86d2bea8dad63ac7194e7517c3b52b8d06ff52d3487d30");
  2711. InitISOFS, Always, TestOutput (
  2712. [["checksum"; "sha384"; "/known-3"]], "5fa7883430f357b5d7b7271d3a1d2872b51d73cba72731de6863d3dea55f30646af2799bef44d5ea776a5ec7941ac640");
  2713. InitISOFS, Always, TestOutput (
  2714. [["checksum"; "sha512"; "/known-3"]], "2794062c328c6b216dca90443b7f7134c5f40e56bd0ed7853123275a09982a6f992e6ca682f9d2fba34a4c5e870d8fe077694ff831e3032a004ee077e00603f6");
  2715. (* Test for RHBZ#579608, absolute symbolic links. *)
  2716. InitISOFS, Always, TestOutput (
  2717. [["checksum"; "sha512"; "/abssymlink"]], "5f57d0639bc95081c53afc63a449403883818edc64da48930ad6b1a4fb49be90404686877743fbcd7c99811f3def7df7bc22635c885c6a8cf79c806b43451c1a")
  2718. ];
  2719. shortdesc = "compute MD5, SHAx or CRC checksum of file";
  2720. longdesc = "\
  2721. This call computes the MD5, SHAx or CRC checksum of the
  2722. file named C<path>.
  2723. The type of checksum to compute is given by the C<csumtype>
  2724. parameter which must have one of the following values:
  2725. =over 4
  2726. =item C<crc>
  2727. Compute the cyclic redundancy check (CRC) specified by POSIX
  2728. for the C<cksum> command.
  2729. =item C<md5>
  2730. Compute the MD5 hash (using the C<md5sum> program).
  2731. =item C<sha1>
  2732. Compute the SHA1 hash (using the C<sha1sum> program).
  2733. =item C<sha224>
  2734. Compute the SHA224 hash (using the C<sha224sum> program).
  2735. =item C<sha256>
  2736. Compute the SHA256 hash (using the C<sha256sum> program).
  2737. =item C<sha384>
  2738. Compute the SHA384 hash (using the C<sha384sum> program).
  2739. =item C<sha512>
  2740. Compute the SHA512 hash (using the C<sha512sum> program).
  2741. =back
  2742. The checksum is returned as a printable string.
  2743. To get the checksum for a device, use C<guestfs_checksum_device>.
  2744. To get the checksums for many files, use C<guestfs_checksums_out>." };
  2745. { defaults with
  2746. name = "tar_in";
  2747. style = RErr, [FileIn "tarfile"; Pathname "directory"], [];
  2748. proc_nr = Some 69;
  2749. cancellable = true;
  2750. tests = [
  2751. InitScratchFS, Always, TestOutput (
  2752. [["mkdir"; "/tar_in"];
  2753. ["tar_in"; "../data/helloworld.tar"; "/tar_in"];
  2754. ["cat"; "/tar_in/hello"]], "hello\n")
  2755. ];
  2756. shortdesc = "unpack tarfile to directory";
  2757. longdesc = "\
  2758. This command uploads and unpacks local file C<tarfile> (an
  2759. I<uncompressed> tar file) into C<directory>.
  2760. To upload a compressed tarball, use C<guestfs_tgz_in>
  2761. or C<guestfs_txz_in>." };
  2762. { defaults with
  2763. name = "tar_out";
  2764. style = RErr, [String "directory"; FileOut "tarfile"], [];
  2765. proc_nr = Some 70;
  2766. cancellable = true;
  2767. shortdesc = "pack directory into tarfile";
  2768. longdesc = "\
  2769. This command packs the contents of C<directory> and downloads
  2770. it to local file C<tarfile>.
  2771. To download a compressed tarball, use C<guestfs_tgz_out>
  2772. or C<guestfs_txz_out>." };
  2773. { defaults with
  2774. name = "tgz_in";
  2775. style = RErr, [FileIn "tarball"; Pathname "directory"], [];
  2776. proc_nr = Some 71;
  2777. cancellable = true;
  2778. tests = [
  2779. InitScratchFS, Always, TestOutput (
  2780. [["mkdir"; "/tgz_in"];
  2781. ["tgz_in"; "../data/helloworld.tar.gz"; "/tgz_in"];
  2782. ["cat"; "/tgz_in/hello"]], "hello\n")
  2783. ];
  2784. shortdesc = "unpack compressed tarball to directory";
  2785. longdesc = "\
  2786. This command uploads and unpacks local file C<tarball> (a
  2787. I<gzip compressed> tar file) into C<directory>.
  2788. To upload an uncompressed tarball, use C<guestfs_tar_in>." };
  2789. { defaults with
  2790. name = "tgz_out";
  2791. style = RErr, [Pathname "directory"; FileOut "tarball"], [];
  2792. proc_nr = Some 72;
  2793. cancellable = true;
  2794. shortdesc = "pack directory into compressed tarball";
  2795. longdesc = "\
  2796. This command packs the contents of C<directory> and downloads
  2797. it to local file C<tarball>.
  2798. To download an uncompressed tarball, use C<guestfs_tar_out>." };
  2799. { defaults with
  2800. name = "mount_ro";
  2801. style = RErr, [Device "device"; String "mountpoint"], [];
  2802. proc_nr = Some 73;
  2803. tests = [
  2804. InitBasicFS, Always, TestLastFail (
  2805. [["umount"; "/"];
  2806. ["mount_ro"; "/dev/sda1"; "/"];
  2807. ["touch"; "/new"]]);
  2808. InitBasicFS, Always, TestOutput (
  2809. [["write"; "/new"; "data"];
  2810. ["umount"; "/"];
  2811. ["mount_ro"; "/dev/sda1"; "/"];
  2812. ["cat"; "/new"]], "data")
  2813. ];
  2814. shortdesc = "mount a guest disk, read-only";
  2815. longdesc = "\
  2816. This is the same as the C<guestfs_mount> command, but it
  2817. mounts the filesystem with the read-only (I<-o ro>) flag." };
  2818. { defaults with
  2819. name = "mount_options";
  2820. style = RErr, [String "options"; Device "device"; String "mountpoint"], [];
  2821. proc_nr = Some 74;
  2822. shortdesc = "mount a guest disk with mount options";
  2823. longdesc = "\
  2824. This is the same as the C<guestfs_mount> command, but it
  2825. allows you to set the mount options as for the
  2826. L<mount(8)> I<-o> flag.
  2827. If the C<options> parameter is an empty string, then
  2828. no options are passed (all options default to whatever
  2829. the filesystem uses)." };
  2830. { defaults with
  2831. name = "mount_vfs";
  2832. style = RErr, [String "options"; String "vfstype"; Device "device"; String "mountpoint"], [];
  2833. proc_nr = Some 75;
  2834. shortdesc = "mount a guest disk with mount options and vfstype";
  2835. longdesc = "\
  2836. This is the same as the C<guestfs_mount> command, but it
  2837. allows you to set both the mount options and the vfstype
  2838. as for the L<mount(8)> I<-o> and I<-t> flags." };
  2839. { defaults with
  2840. name = "debug";
  2841. style = RString "result", [String "subcmd"; StringList "extraargs"], [];
  2842. proc_nr = Some 76;
  2843. in_docs = false;
  2844. shortdesc = "debugging and internals";
  2845. longdesc = "\
  2846. The C<guestfs_debug> command exposes some internals of
  2847. C<guestfsd> (the guestfs daemon) that runs inside the
  2848. qemu subprocess.
  2849. There is no comprehensive help for this command. You have
  2850. to look at the file C<daemon/debug.c> in the libguestfs source
  2851. to find out what you can do." };
  2852. { defaults with
  2853. name = "lvremove";
  2854. style = RErr, [Device "device"], [];
  2855. proc_nr = Some 77;
  2856. optional = Some "lvm2";
  2857. tests = [
  2858. InitEmpty, Always, TestOutputList (
  2859. [["part_disk"; "/dev/sda"; "mbr"];
  2860. ["pvcreate"; "/dev/sda1"];
  2861. ["vgcreate"; "VG"; "/dev/sda1"];
  2862. ["lvcreate"; "LV1"; "VG"; "50"];
  2863. ["lvcreate"; "LV2"; "VG"; "50"];
  2864. ["lvremove"; "/dev/VG/LV1"];
  2865. ["lvs"]], ["/dev/VG/LV2"]);
  2866. InitEmpty, Always, TestOutputList (
  2867. [["part_disk"; "/dev/sda"; "mbr"];
  2868. ["pvcreate"; "/dev/sda1"];
  2869. ["vgcreate"; "VG"; "/dev/sda1"];
  2870. ["lvcreate"; "LV1"; "VG"; "50"];
  2871. ["lvcreate"; "LV2"; "VG"; "50"];
  2872. ["lvremove"; "/dev/VG"];
  2873. ["lvs"]], []);
  2874. InitEmpty, Always, TestOutputList (
  2875. [["part_disk"; "/dev/sda"; "mbr"];
  2876. ["pvcreate"; "/dev/sda1"];
  2877. ["vgcreate"; "VG"; "/dev/sda1"];
  2878. ["lvcreate"; "LV1"; "VG"; "50"];
  2879. ["lvcreate"; "LV2"; "VG"; "50"];
  2880. ["lvremove"; "/dev/VG"];
  2881. ["vgs"]], ["VG"])
  2882. ];
  2883. shortdesc = "remove an LVM logical volume";
  2884. longdesc = "\
  2885. Remove an LVM logical volume C<device>, where C<device> is
  2886. the path to the LV, such as C</dev/VG/LV>.
  2887. You can also remove all LVs in a volume group by specifying
  2888. the VG name, C</dev/VG>." };
  2889. { defaults with
  2890. name = "vgremove";
  2891. style = RErr, [String "vgname"], [];
  2892. proc_nr = Some 78;
  2893. optional = Some "lvm2";
  2894. tests = [
  2895. InitEmpty, Always, TestOutputList (
  2896. [["part_disk"; "/dev/sda"; "mbr"];
  2897. ["pvcreate"; "/dev/sda1"];
  2898. ["vgcreate"; "VG"; "/dev/sda1"];
  2899. ["lvcreate"; "LV1"; "VG"; "50"];
  2900. ["lvcreate"; "LV2"; "VG"; "50"];
  2901. ["vgremove"; "VG"];
  2902. ["lvs"]], []);
  2903. InitEmpty, Always, TestOutputList (
  2904. [["part_disk"; "/dev/sda"; "mbr"];
  2905. ["pvcreate"; "/dev/sda1"];
  2906. ["vgcreate"; "VG"; "/dev/sda1"];
  2907. ["lvcreate"; "LV1"; "VG"; "50"];
  2908. ["lvcreate"; "LV2"; "VG"; "50"];
  2909. ["vgremove"; "VG"];
  2910. ["vgs"]], [])
  2911. ];
  2912. shortdesc = "remove an LVM volume group";
  2913. longdesc = "\
  2914. Remove an LVM volume group C<vgname>, (for example C<VG>).
  2915. This also forcibly removes all logical volumes in the volume
  2916. group (if any)." };
  2917. { defaults with
  2918. name = "pvremove";
  2919. style = RErr, [Device "device"], [];
  2920. proc_nr = Some 79;
  2921. optional = Some "lvm2";
  2922. tests = [
  2923. InitEmpty, Always, TestOutputListOfDevices (
  2924. [["part_disk"; "/dev/sda"; "mbr"];
  2925. ["pvcreate"; "/dev/sda1"];
  2926. ["vgcreate"; "VG"; "/dev/sda1"];
  2927. ["lvcreate"; "LV1"; "VG"; "50"];
  2928. ["lvcreate"; "LV2"; "VG"; "50"];
  2929. ["vgremove"; "VG"];
  2930. ["pvremove"; "/dev/sda1"];
  2931. ["lvs"]], []);
  2932. InitEmpty, Always, TestOutputListOfDevices (
  2933. [["part_disk"; "/dev/sda"; "mbr"];
  2934. ["pvcreate"; "/dev/sda1"];
  2935. ["vgcreate"; "VG"; "/dev/sda1"];
  2936. ["lvcreate"; "LV1"; "VG"; "50"];
  2937. ["lvcreate"; "LV2"; "VG"; "50"];
  2938. ["vgremove"; "VG"];
  2939. ["pvremove"; "/dev/sda1"];
  2940. ["vgs"]], []);
  2941. InitEmpty, Always, TestOutputListOfDevices (
  2942. [["part_disk"; "/dev/sda"; "mbr"];
  2943. ["pvcreate"; "/dev/sda1"];
  2944. ["vgcreate"; "VG"; "/dev/sda1"];
  2945. ["lvcreate"; "LV1"; "VG"; "50"];
  2946. ["lvcreate"; "LV2"; "VG"; "50"];
  2947. ["vgremove"; "VG"];
  2948. ["pvremove"; "/dev/sda1"];
  2949. ["pvs"]], [])
  2950. ];
  2951. shortdesc = "remove an LVM physical volume";
  2952. longdesc = "\
  2953. This wipes a physical volume C<device> so that LVM will no longer
  2954. recognise it.
  2955. The implementation uses the C<pvremove> command which refuses to
  2956. wipe physical volumes that contain any volume groups, so you have
  2957. to remove those first." };
  2958. { defaults with
  2959. name = "set_e2label";
  2960. style = RErr, [Device "device"; String "label"], [];
  2961. proc_nr = Some 80;
  2962. deprecated_by = Some "set_label";
  2963. tests = [
  2964. InitBasicFS, Always, TestOutput (
  2965. [["set_e2label"; "/dev/sda1"; "testlabel"];
  2966. ["get_e2label"; "/dev/sda1"]], "testlabel")
  2967. ];
  2968. shortdesc = "set the ext2/3/4 filesystem label";
  2969. longdesc = "\
  2970. This sets the ext2/3/4 filesystem label of the filesystem on
  2971. C<device> to C<label>. Filesystem labels are limited to
  2972. 16 characters.
  2973. You can use either C<guestfs_tune2fs_l> or C<guestfs_get_e2label>
  2974. to return the existing label on a filesystem." };
  2975. { defaults with
  2976. name = "get_e2label";
  2977. style = RString "label", [Device "device"], [];
  2978. proc_nr = Some 81;
  2979. deprecated_by = Some "vfs_label";
  2980. shortdesc = "get the ext2/3/4 filesystem label";
  2981. longdesc = "\
  2982. This returns the ext2/3/4 filesystem label of the filesystem on
  2983. C<device>." };
  2984. { defaults with
  2985. name = "set_e2uuid";
  2986. style = RErr, [Device "device"; String "uuid"], [];
  2987. proc_nr = Some 82;
  2988. tests =
  2989. (let uuid = uuidgen () in [
  2990. InitBasicFS, Always, TestOutput (
  2991. [["set_e2uuid"; "/dev/sda1"; uuid];
  2992. ["get_e2uuid"; "/dev/sda1"]], uuid);
  2993. InitBasicFS, Always, TestOutput (
  2994. [["set_e2uuid"; "/dev/sda1"; "clear"];
  2995. ["get_e2uuid"; "/dev/sda1"]], "");
  2996. (* We can't predict what UUIDs will be, so just check
  2997. the commands run. *)
  2998. InitBasicFS, Always, TestRun (
  2999. [["set_e2uuid"; "/dev/sda1"; "random"]]);
  3000. InitBasicFS, Always, TestRun (
  3001. [["set_e2uuid"; "/dev/sda1"; "time"]])
  3002. ]);
  3003. shortdesc = "set the ext2/3/4 filesystem UUID";
  3004. longdesc = "\
  3005. This sets the ext2/3/4 filesystem UUID of the filesystem on
  3006. C<device> to C<uuid>. The format of the UUID and alternatives
  3007. such as C<clear>, C<random> and C<time> are described in the
  3008. L<tune2fs(8)> manpage.
  3009. You can use either C<guestfs_tune2fs_l> or C<guestfs_get_e2uuid>
  3010. to return the existing UUID of a filesystem." };
  3011. { defaults with
  3012. name = "get_e2uuid";
  3013. style = RString "uuid", [Device "device"], [];
  3014. proc_nr = Some 83;
  3015. deprecated_by = Some "vfs_uuid";
  3016. tests =
  3017. (* Regression test for RHBZ#597112. *)
  3018. (let uuid = uuidgen () in [
  3019. InitNone, Always, TestOutput (
  3020. [["mke2journal"; "1024"; "/dev/sdc"];
  3021. ["set_e2uuid"; "/dev/sdc"; uuid];
  3022. ["get_e2uuid"; "/dev/sdc"]], uuid)
  3023. ]);
  3024. shortdesc = "get the ext2/3/4 filesystem UUID";
  3025. longdesc = "\
  3026. This returns the ext2/3/4 filesystem UUID of the filesystem on
  3027. C<device>." };
  3028. { defaults with
  3029. name = "fsck";
  3030. style = RInt "status", [String "fstype"; Device "device"], [];
  3031. proc_nr = Some 84;
  3032. fish_output = Some FishOutputHexadecimal;
  3033. tests = [
  3034. InitBasicFS, Always, TestOutputInt (
  3035. [["umount"; "/dev/sda1"];
  3036. ["fsck"; "ext2"; "/dev/sda1"]], 0);
  3037. InitBasicFS, Always, TestOutputInt (
  3038. [["umount"; "/dev/sda1"];
  3039. ["zero"; "/dev/sda1"];
  3040. ["fsck"; "ext2"; "/dev/sda1"]], 8)
  3041. ];
  3042. shortdesc = "run the filesystem checker";
  3043. longdesc = "\
  3044. This runs the filesystem checker (fsck) on C<device> which
  3045. should have filesystem type C<fstype>.
  3046. The returned integer is the status. See L<fsck(8)> for the
  3047. list of status codes from C<fsck>.
  3048. Notes:
  3049. =over 4
  3050. =item *
  3051. Multiple status codes can be summed together.
  3052. =item *
  3053. A non-zero return code can mean \"success\", for example if
  3054. errors have been corrected on the filesystem.
  3055. =item *
  3056. Checking or repairing NTFS volumes is not supported
  3057. (by linux-ntfs).
  3058. =back
  3059. This command is entirely equivalent to running C<fsck -a -t fstype device>." };
  3060. { defaults with
  3061. name = "zero";
  3062. style = RErr, [Device "device"], [];
  3063. proc_nr = Some 85;
  3064. progress = true;
  3065. tests = [
  3066. InitBasicFS, Always, TestRun (
  3067. [["umount"; "/dev/sda1"];
  3068. ["zero"; "/dev/sda1"]])
  3069. ];
  3070. shortdesc = "write zeroes to the device";
  3071. longdesc = "\
  3072. This command writes zeroes over the first few blocks of C<device>.
  3073. How many blocks are zeroed isn't specified (but it's I<not> enough
  3074. to securely wipe the device). It should be sufficient to remove
  3075. any partition tables, filesystem superblocks and so on.
  3076. If blocks are already zero, then this command avoids writing
  3077. zeroes. This prevents the underlying device from becoming non-sparse
  3078. or growing unnecessarily.
  3079. See also: C<guestfs_zero_device>, C<guestfs_scrub_device>,
  3080. C<guestfs_is_zero_device>" };
  3081. { defaults with
  3082. name = "grub_install";
  3083. style = RErr, [Pathname "root"; Device "device"], [];
  3084. proc_nr = Some 86;
  3085. optional = Some "grub";
  3086. (* See:
  3087. * https://bugzilla.redhat.com/show_bug.cgi?id=484986
  3088. * https://bugzilla.redhat.com/show_bug.cgi?id=479760
  3089. *)
  3090. tests = [
  3091. InitBasicFS, Always, TestOutputTrue (
  3092. [["mkdir_p"; "/boot/grub"];
  3093. ["write"; "/boot/grub/device.map"; "(hd0) /dev/vda"];
  3094. ["grub_install"; "/"; "/dev/vda"];
  3095. ["is_dir"; "/boot"]])
  3096. ];
  3097. shortdesc = "install GRUB 1";
  3098. longdesc = "\
  3099. This command installs GRUB 1 (the Grand Unified Bootloader) on
  3100. C<device>, with the root directory being C<root>.
  3101. Notes:
  3102. =over 4
  3103. =item *
  3104. There is currently no way in the API to install grub2, which
  3105. is used by most modern Linux guests. It is possible to run
  3106. the grub2 command from the guest, although see the
  3107. caveats in L<guestfs(3)/RUNNING COMMANDS>.
  3108. =item *
  3109. This uses C<grub-install> from the host. Unfortunately grub is
  3110. not always compatible with itself, so this only works in rather
  3111. narrow circumstances. Careful testing with each guest version
  3112. is advisable.
  3113. =item *
  3114. If grub-install reports the error
  3115. \"No suitable drive was found in the generated device map.\"
  3116. it may be that you need to create a C</boot/grub/device.map>
  3117. file first that contains the mapping between grub device names
  3118. and Linux device names. It is usually sufficient to create
  3119. a file containing:
  3120. (hd0) /dev/vda
  3121. replacing C</dev/vda> with the name of the installation device.
  3122. =back" };
  3123. { defaults with
  3124. name = "cp";
  3125. style = RErr, [Pathname "src"; Pathname "dest"], [];
  3126. proc_nr = Some 87;
  3127. tests = [
  3128. InitScratchFS, Always, TestOutput (
  3129. [["mkdir"; "/cp"];
  3130. ["write"; "/cp/old"; "file content"];
  3131. ["cp"; "/cp/old"; "/cp/new"];
  3132. ["cat"; "/cp/new"]], "file content");
  3133. InitScratchFS, Always, TestOutputTrue (
  3134. [["mkdir"; "/cp2"];
  3135. ["write"; "/cp2/old"; "file content"];
  3136. ["cp"; "/cp2/old"; "/cp2/new"];
  3137. ["is_file"; "/cp2/old"]]);
  3138. InitScratchFS, Always, TestOutput (
  3139. [["mkdir"; "/cp3"];
  3140. ["write"; "/cp3/old"; "file content"];
  3141. ["mkdir"; "/cp3/dir"];
  3142. ["cp"; "/cp3/old"; "/cp3/dir/new"];
  3143. ["cat"; "/cp3/dir/new"]], "file content")
  3144. ];
  3145. shortdesc = "copy a file";
  3146. longdesc = "\
  3147. This copies a file from C<src> to C<dest> where C<dest> is
  3148. either a destination filename or destination directory." };
  3149. { defaults with
  3150. name = "cp_a";
  3151. style = RErr, [Pathname "src"; Pathname "dest"], [];
  3152. proc_nr = Some 88;
  3153. tests = [
  3154. InitScratchFS, Always, TestOutput (
  3155. [["mkdir"; "/cp_a1"];
  3156. ["mkdir"; "/cp_a2"];
  3157. ["write"; "/cp_a1/file"; "file content"];
  3158. ["cp_a"; "/cp_a1"; "/cp_a2"];
  3159. ["cat"; "/cp_a2/cp_a1/file"]], "file content")
  3160. ];
  3161. shortdesc = "copy a file or directory recursively";
  3162. longdesc = "\
  3163. This copies a file or directory from C<src> to C<dest>
  3164. recursively using the C<cp -a> command." };
  3165. { defaults with
  3166. name = "mv";
  3167. style = RErr, [Pathname "src"; Pathname "dest"], [];
  3168. proc_nr = Some 89;
  3169. tests = [
  3170. InitScratchFS, Always, TestOutput (
  3171. [["mkdir"; "/mv"];
  3172. ["write"; "/mv/old"; "file content"];
  3173. ["mv"; "/mv/old"; "/mv/new"];
  3174. ["cat"; "/mv/new"]], "file content");
  3175. InitScratchFS, Always, TestOutputFalse (
  3176. [["mkdir"; "/mv2"];
  3177. ["write"; "/mv2/old"; "file content"];
  3178. ["mv"; "/mv2/old"; "/mv2/new"];
  3179. ["is_file"; "/mv2/old"]])
  3180. ];
  3181. shortdesc = "move a file";
  3182. longdesc = "\
  3183. This moves a file from C<src> to C<dest> where C<dest> is
  3184. either a destination filename or destination directory." };
  3185. { defaults with
  3186. name = "drop_caches";
  3187. style = RErr, [Int "whattodrop"], [];
  3188. proc_nr = Some 90;
  3189. tests = [
  3190. InitEmpty, Always, TestRun (
  3191. [["drop_caches"; "3"]])
  3192. ];
  3193. shortdesc = "drop kernel page cache, dentries and inodes";
  3194. longdesc = "\
  3195. This instructs the guest kernel to drop its page cache,
  3196. and/or dentries and inode caches. The parameter C<whattodrop>
  3197. tells the kernel what precisely to drop, see
  3198. L<http://linux-mm.org/Drop_Caches>
  3199. Setting C<whattodrop> to 3 should drop everything.
  3200. This automatically calls L<sync(2)> before the operation,
  3201. so that the maximum guest memory is freed." };
  3202. { defaults with
  3203. name = "dmesg";
  3204. style = RString "kmsgs", [], [];
  3205. proc_nr = Some 91;
  3206. tests = [
  3207. InitEmpty, Always, TestRun (
  3208. [["dmesg"]])
  3209. ];
  3210. shortdesc = "return kernel messages";
  3211. longdesc = "\
  3212. This returns the kernel messages (C<dmesg> output) from
  3213. the guest kernel. This is sometimes useful for extended
  3214. debugging of problems.
  3215. Another way to get the same information is to enable
  3216. verbose messages with C<guestfs_set_verbose> or by setting
  3217. the environment variable C<LIBGUESTFS_DEBUG=1> before
  3218. running the program." };
  3219. { defaults with
  3220. name = "ping_daemon";
  3221. style = RErr, [], [];
  3222. proc_nr = Some 92;
  3223. tests = [
  3224. InitEmpty, Always, TestRun (
  3225. [["ping_daemon"]])
  3226. ];
  3227. shortdesc = "ping the guest daemon";
  3228. longdesc = "\
  3229. This is a test probe into the guestfs daemon running inside
  3230. the qemu subprocess. Calling this function checks that the
  3231. daemon responds to the ping message, without affecting the daemon
  3232. or attached block device(s) in any other way." };
  3233. { defaults with
  3234. name = "equal";
  3235. style = RBool "equality", [Pathname "file1"; Pathname "file2"], [];
  3236. proc_nr = Some 93;
  3237. tests = [
  3238. InitScratchFS, Always, TestOutputTrue (
  3239. [["mkdir"; "/equal"];
  3240. ["write"; "/equal/file1"; "contents of a file"];
  3241. ["cp"; "/equal/file1"; "/equal/file2"];
  3242. ["equal"; "/equal/file1"; "/equal/file2"]]);
  3243. InitScratchFS, Always, TestOutputFalse (
  3244. [["mkdir"; "/equal2"];
  3245. ["write"; "/equal2/file1"; "contents of a file"];
  3246. ["write"; "/equal2/file2"; "contents of another file"];
  3247. ["equal"; "/equal2/file1"; "/equal2/file2"]]);
  3248. InitScratchFS, Always, TestLastFail (
  3249. [["mkdir"; "/equal3"];
  3250. ["equal"; "/equal3/file1"; "/equal3/file2"]])
  3251. ];
  3252. shortdesc = "test if two files have equal contents";
  3253. longdesc = "\
  3254. This compares the two files C<file1> and C<file2> and returns
  3255. true if their content is exactly equal, or false otherwise.
  3256. The external L<cmp(1)> program is used for the comparison." };
  3257. { defaults with
  3258. name = "strings";
  3259. style = RStringList "stringsout", [Pathname "path"], [];
  3260. proc_nr = Some 94;
  3261. protocol_limit_warning = true;
  3262. tests = [
  3263. InitISOFS, Always, TestOutputList (
  3264. [["strings"; "/known-5"]], ["abcdefghi"; "jklmnopqr"]);
  3265. InitISOFS, Always, TestOutputList (
  3266. [["strings"; "/empty"]], []);
  3267. (* Test for RHBZ#579608, absolute symbolic links. *)
  3268. InitISOFS, Always, TestRun (
  3269. [["strings"; "/abssymlink"]])
  3270. ];
  3271. shortdesc = "print the printable strings in a file";
  3272. longdesc = "\
  3273. This runs the L<strings(1)> command on a file and returns
  3274. the list of printable strings found." };
  3275. { defaults with
  3276. name = "strings_e";
  3277. style = RStringList "stringsout", [String "encoding"; Pathname "path"], [];
  3278. proc_nr = Some 95;
  3279. protocol_limit_warning = true;
  3280. tests = [
  3281. InitISOFS, Always, TestOutputList (
  3282. [["strings_e"; "b"; "/known-5"]], []);
  3283. InitScratchFS, Always, TestOutputList (
  3284. [["write"; "/strings_e"; "\000h\000e\000l\000l\000o\000\n\000w\000o\000r\000l\000d\000\n"];
  3285. ["strings_e"; "b"; "/strings_e"]], ["hello"; "world"])
  3286. ];
  3287. shortdesc = "print the printable strings in a file";
  3288. longdesc = "\
  3289. This is like the C<guestfs_strings> command, but allows you to
  3290. specify the encoding of strings that are looked for in
  3291. the source file C<path>.
  3292. Allowed encodings are:
  3293. =over 4
  3294. =item s
  3295. Single 7-bit-byte characters like ASCII and the ASCII-compatible
  3296. parts of ISO-8859-X (this is what C<guestfs_strings> uses).
  3297. =item S
  3298. Single 8-bit-byte characters.
  3299. =item b
  3300. 16-bit big endian strings such as those encoded in
  3301. UTF-16BE or UCS-2BE.
  3302. =item l (lower case letter L)
  3303. 16-bit little endian such as UTF-16LE and UCS-2LE.
  3304. This is useful for examining binaries in Windows guests.
  3305. =item B
  3306. 32-bit big endian such as UCS-4BE.
  3307. =item L
  3308. 32-bit little endian such as UCS-4LE.
  3309. =back
  3310. The returned strings are transcoded to UTF-8." };
  3311. { defaults with
  3312. name = "hexdump";
  3313. style = RString "dump", [Pathname "path"], [];
  3314. proc_nr = Some 96;
  3315. protocol_limit_warning = true;
  3316. tests = [
  3317. InitISOFS, Always, TestOutput (
  3318. [["hexdump"; "/known-4"]], "00000000 61 62 63 0a 64 65 66 0a 67 68 69 |abc.def.ghi|\n0000000b\n");
  3319. (* Test for RHBZ#501888c2 regression which caused large hexdump
  3320. * commands to segfault.
  3321. *)
  3322. InitISOFS, Always, TestRun (
  3323. [["hexdump"; "/100krandom"]]);
  3324. (* Test for RHBZ#579608, absolute symbolic links. *)
  3325. InitISOFS, Always, TestRun (
  3326. [["hexdump"; "/abssymlink"]])
  3327. ];
  3328. shortdesc = "dump a file in hexadecimal";
  3329. longdesc = "\
  3330. This runs C<hexdump -C> on the given C<path>. The result is
  3331. the human-readable, canonical hex dump of the file." };
  3332. { defaults with
  3333. name = "zerofree";
  3334. style = RErr, [Device "device"], [];
  3335. proc_nr = Some 97;
  3336. optional = Some "zerofree";
  3337. tests = [
  3338. InitNone, Always, TestOutput (
  3339. [["part_disk"; "/dev/sda"; "mbr"];
  3340. ["mkfs"; "ext3"; "/dev/sda1"; ""; "NOARG"; ""; ""];
  3341. ["mount_options"; ""; "/dev/sda1"; "/"];
  3342. ["write"; "/new"; "test file"];
  3343. ["umount"; "/dev/sda1"];
  3344. ["zerofree"; "/dev/sda1"];
  3345. ["mount_options"; ""; "/dev/sda1"; "/"];
  3346. ["cat"; "/new"]], "test file")
  3347. ];
  3348. shortdesc = "zero unused inodes and disk blocks on ext2/3 filesystem";
  3349. longdesc = "\
  3350. This runs the I<zerofree> program on C<device>. This program
  3351. claims to zero unused inodes and disk blocks on an ext2/3
  3352. filesystem, thus making it possible to compress the filesystem
  3353. more effectively.
  3354. You should B<not> run this program if the filesystem is
  3355. mounted.
  3356. It is possible that using this program can damage the filesystem
  3357. or data on the filesystem." };
  3358. { defaults with
  3359. name = "pvresize";
  3360. style = RErr, [Device "device"], [];
  3361. proc_nr = Some 98;
  3362. optional = Some "lvm2";
  3363. shortdesc = "resize an LVM physical volume";
  3364. longdesc = "\
  3365. This resizes (expands or shrinks) an existing LVM physical
  3366. volume to match the new size of the underlying device." };
  3367. { defaults with
  3368. name = "sfdisk_N";
  3369. style = RErr, [Device "device"; Int "partnum";
  3370. Int "cyls"; Int "heads"; Int "sectors";
  3371. String "line"], [];
  3372. proc_nr = Some 99;
  3373. deprecated_by = Some "part_add";
  3374. shortdesc = "modify a single partition on a block device";
  3375. longdesc = "\
  3376. This runs L<sfdisk(8)> option to modify just the single
  3377. partition C<n> (note: C<n> counts from 1).
  3378. For other parameters, see C<guestfs_sfdisk>. You should usually
  3379. pass C<0> for the cyls/heads/sectors parameters.
  3380. See also: C<guestfs_part_add>" };
  3381. { defaults with
  3382. name = "sfdisk_l";
  3383. style = RString "partitions", [Device "device"], [];
  3384. proc_nr = Some 100;
  3385. deprecated_by = Some "part_list";
  3386. shortdesc = "display the partition table";
  3387. longdesc = "\
  3388. This displays the partition table on C<device>, in the
  3389. human-readable output of the L<sfdisk(8)> command. It is
  3390. not intended to be parsed.
  3391. See also: C<guestfs_part_list>" };
  3392. { defaults with
  3393. name = "sfdisk_kernel_geometry";
  3394. style = RString "partitions", [Device "device"], [];
  3395. proc_nr = Some 101;
  3396. shortdesc = "display the kernel geometry";
  3397. longdesc = "\
  3398. This displays the kernel's idea of the geometry of C<device>.
  3399. The result is in human-readable format, and not designed to
  3400. be parsed." };
  3401. { defaults with
  3402. name = "sfdisk_disk_geometry";
  3403. style = RString "partitions", [Device "device"], [];
  3404. proc_nr = Some 102;
  3405. shortdesc = "display the disk geometry from the partition table";
  3406. longdesc = "\
  3407. This displays the disk geometry of C<device> read from the
  3408. partition table. Especially in the case where the underlying
  3409. block device has been resized, this can be different from the
  3410. kernel's idea of the geometry (see C<guestfs_sfdisk_kernel_geometry>).
  3411. The result is in human-readable format, and not designed to
  3412. be parsed." };
  3413. { defaults with
  3414. name = "vg_activate_all";
  3415. style = RErr, [Bool "activate"], [];
  3416. proc_nr = Some 103;
  3417. optional = Some "lvm2";
  3418. shortdesc = "activate or deactivate all volume groups";
  3419. longdesc = "\
  3420. This command activates or (if C<activate> is false) deactivates
  3421. all logical volumes in all volume groups.
  3422. This command is the same as running C<vgchange -a y|n>" };
  3423. { defaults with
  3424. name = "vg_activate";
  3425. style = RErr, [Bool "activate"; StringList "volgroups"], [];
  3426. proc_nr = Some 104;
  3427. optional = Some "lvm2";
  3428. shortdesc = "activate or deactivate some volume groups";
  3429. longdesc = "\
  3430. This command activates or (if C<activate> is false) deactivates
  3431. all logical volumes in the listed volume groups C<volgroups>.
  3432. This command is the same as running C<vgchange -a y|n volgroups...>
  3433. Note that if C<volgroups> is an empty list then B<all> volume groups
  3434. are activated or deactivated." };
  3435. { defaults with
  3436. name = "lvresize";
  3437. style = RErr, [Device "device"; Int "mbytes"], [];
  3438. proc_nr = Some 105;
  3439. optional = Some "lvm2";
  3440. tests = [
  3441. InitNone, Always, TestOutput (
  3442. [["part_disk"; "/dev/sda"; "mbr"];
  3443. ["pvcreate"; "/dev/sda1"];
  3444. ["vgcreate"; "VG"; "/dev/sda1"];
  3445. ["lvcreate"; "LV"; "VG"; "10"];
  3446. ["mkfs"; "ext2"; "/dev/VG/LV"; ""; "NOARG"; ""; ""];
  3447. ["mount_options"; ""; "/dev/VG/LV"; "/"];
  3448. ["write"; "/new"; "test content"];
  3449. ["umount"; "/"];
  3450. ["lvresize"; "/dev/VG/LV"; "20"];
  3451. ["e2fsck_f"; "/dev/VG/LV"];
  3452. ["e2fsck"; "/dev/VG/LV"; "true"; "false"];
  3453. ["e2fsck"; "/dev/VG/LV"; "false"; "true"];
  3454. ["resize2fs"; "/dev/VG/LV"];
  3455. ["mount_options"; ""; "/dev/VG/LV"; "/"];
  3456. ["cat"; "/new"]], "test content");
  3457. InitNone, Always, TestRun (
  3458. (* Make an LV smaller to test RHBZ#587484. *)
  3459. [["part_disk"; "/dev/sda"; "mbr"];
  3460. ["pvcreate"; "/dev/sda1"];
  3461. ["vgcreate"; "VG"; "/dev/sda1"];
  3462. ["lvcreate"; "LV"; "VG"; "20"];
  3463. ["lvresize"; "/dev/VG/LV"; "10"]])
  3464. ];
  3465. shortdesc = "resize an LVM logical volume";
  3466. longdesc = "\
  3467. This resizes (expands or shrinks) an existing LVM logical
  3468. volume to C<mbytes>. When reducing, data in the reduced part
  3469. is lost." };
  3470. { defaults with
  3471. name = "resize2fs";
  3472. style = RErr, [Device "device"], [];
  3473. proc_nr = Some 106;
  3474. shortdesc = "resize an ext2, ext3 or ext4 filesystem";
  3475. longdesc = "\
  3476. This resizes an ext2, ext3 or ext4 filesystem to match the size of
  3477. the underlying device.
  3478. See also L<guestfs(3)/RESIZE2FS ERRORS>." };
  3479. { defaults with
  3480. name = "find";
  3481. style = RStringList "names", [Pathname "directory"], [];
  3482. proc_nr = Some 107;
  3483. protocol_limit_warning = true;
  3484. tests = [
  3485. InitBasicFS, Always, TestOutputList (
  3486. [["find"; "/"]], ["lost+found"]);
  3487. InitBasicFS, Always, TestOutputList (
  3488. [["touch"; "/a"];
  3489. ["mkdir"; "/b"];
  3490. ["touch"; "/b/c"];
  3491. ["find"; "/"]], ["a"; "b"; "b/c"; "lost+found"]);
  3492. InitScratchFS, Always, TestOutputList (
  3493. [["mkdir_p"; "/find/b/c"];
  3494. ["touch"; "/find/b/c/d"];
  3495. ["find"; "/find/b/"]], ["c"; "c/d"])
  3496. ];
  3497. shortdesc = "find all files and directories";
  3498. longdesc = "\
  3499. This command lists out all files and directories, recursively,
  3500. starting at C<directory>. It is essentially equivalent to
  3501. running the shell command C<find directory -print> but some
  3502. post-processing happens on the output, described below.
  3503. This returns a list of strings I<without any prefix>. Thus
  3504. if the directory structure was:
  3505. /tmp/a
  3506. /tmp/b
  3507. /tmp/c/d
  3508. then the returned list from C<guestfs_find> C</tmp> would be
  3509. 4 elements:
  3510. a
  3511. b
  3512. c
  3513. c/d
  3514. If C<directory> is not a directory, then this command returns
  3515. an error.
  3516. The returned list is sorted.
  3517. See also C<guestfs_find0>." };
  3518. { defaults with
  3519. name = "e2fsck_f";
  3520. style = RErr, [Device "device"], [];
  3521. proc_nr = Some 108;
  3522. deprecated_by = Some "e2fsck";
  3523. shortdesc = "check an ext2/ext3 filesystem";
  3524. longdesc = "\
  3525. This runs C<e2fsck -p -f device>, ie. runs the ext2/ext3
  3526. filesystem checker on C<device>, noninteractively (I<-p>),
  3527. even if the filesystem appears to be clean (I<-f>)." };
  3528. { defaults with
  3529. name = "sleep";
  3530. style = RErr, [Int "secs"], [];
  3531. proc_nr = Some 109;
  3532. tests = [
  3533. InitNone, Always, TestRun (
  3534. [["sleep"; "1"]])
  3535. ];
  3536. shortdesc = "sleep for some seconds";
  3537. longdesc = "\
  3538. Sleep for C<secs> seconds." };
  3539. { defaults with
  3540. name = "ntfs_3g_probe";
  3541. style = RInt "status", [Bool "rw"; Device "device"], [];
  3542. proc_nr = Some 110;
  3543. optional = Some "ntfs3g";
  3544. tests = [
  3545. InitNone, Always, TestOutputInt (
  3546. [["part_disk"; "/dev/sda"; "mbr"];
  3547. ["mkfs"; "ntfs"; "/dev/sda1"; ""; "NOARG"; ""; ""];
  3548. ["ntfs_3g_probe"; "true"; "/dev/sda1"]], 0);
  3549. InitNone, Always, TestOutputInt (
  3550. [["part_disk"; "/dev/sda"; "mbr"];
  3551. ["mkfs"; "ext2"; "/dev/sda1"; ""; "NOARG"; ""; ""];
  3552. ["ntfs_3g_probe"; "true"; "/dev/sda1"]], 12)
  3553. ];
  3554. shortdesc = "probe NTFS volume";
  3555. longdesc = "\
  3556. This command runs the L<ntfs-3g.probe(8)> command which probes
  3557. an NTFS C<device> for mountability. (Not all NTFS volumes can
  3558. be mounted read-write, and some cannot be mounted at all).
  3559. C<rw> is a boolean flag. Set it to true if you want to test
  3560. if the volume can be mounted read-write. Set it to false if
  3561. you want to test if the volume can be mounted read-only.
  3562. The return value is an integer which C<0> if the operation
  3563. would succeed, or some non-zero value documented in the
  3564. L<ntfs-3g.probe(8)> manual page." };
  3565. { defaults with
  3566. name = "sh";
  3567. style = RString "output", [String "command"], [];
  3568. proc_nr = Some 111;
  3569. tests = [] (* XXX needs tests *);
  3570. shortdesc = "run a command via the shell";
  3571. longdesc = "\
  3572. This call runs a command from the guest filesystem via the
  3573. guest's C</bin/sh>.
  3574. This is like C<guestfs_command>, but passes the command to:
  3575. /bin/sh -c \"command\"
  3576. Depending on the guest's shell, this usually results in
  3577. wildcards being expanded, shell expressions being interpolated
  3578. and so on.
  3579. All the provisos about C<guestfs_command> apply to this call." };
  3580. { defaults with
  3581. name = "sh_lines";
  3582. style = RStringList "lines", [String "command"], [];
  3583. proc_nr = Some 112;
  3584. tests = [] (* XXX needs tests *);
  3585. shortdesc = "run a command via the shell returning lines";
  3586. longdesc = "\
  3587. This is the same as C<guestfs_sh>, but splits the result
  3588. into a list of lines.
  3589. See also: C<guestfs_command_lines>" };
  3590. { defaults with
  3591. name = "glob_expand";
  3592. (* Use Pathname here, and hence ABS_PATH (pattern,...) in
  3593. * generated code in stubs.c, since all valid glob patterns must
  3594. * start with "/". There is no concept of "cwd" in libguestfs,
  3595. * hence no "."-relative names.
  3596. *)
  3597. style = RStringList "paths", [Pathname "pattern"], [];
  3598. proc_nr = Some 113;
  3599. tests = [
  3600. InitScratchFS, Always, TestOutputList (
  3601. [["mkdir_p"; "/glob_expand/b/c"];
  3602. ["touch"; "/glob_expand/b/c/d"];
  3603. ["touch"; "/glob_expand/b/c/e"];
  3604. ["glob_expand"; "/glob_expand/b/c/*"]], ["/glob_expand/b/c/d"; "/glob_expand/b/c/e"]);
  3605. InitScratchFS, Always, TestOutputList (
  3606. [["mkdir_p"; "/glob_expand2/b/c"];
  3607. ["touch"; "/glob_expand2/b/c/d"];
  3608. ["touch"; "/glob_expand2/b/c/e"];
  3609. ["glob_expand"; "/glob_expand2/*/c/*"]], ["/glob_expand2/b/c/d"; "/glob_expand2/b/c/e"]);
  3610. InitScratchFS, Always, TestOutputList (
  3611. [["mkdir_p"; "/glob_expand3/b/c"];
  3612. ["touch"; "/glob_expand3/b/c/d"];
  3613. ["touch"; "/glob_expand3/b/c/e"];
  3614. ["glob_expand"; "/glob_expand3/*/x/*"]], [])
  3615. ];
  3616. shortdesc = "expand a wildcard path";
  3617. longdesc = "\
  3618. This command searches for all the pathnames matching
  3619. C<pattern> according to the wildcard expansion rules
  3620. used by the shell.
  3621. If no paths match, then this returns an empty list
  3622. (note: not an error).
  3623. It is just a wrapper around the C L<glob(3)> function
  3624. with flags C<GLOB_MARK|GLOB_BRACE>.
  3625. See that manual page for more details.
  3626. Notice that there is no equivalent command for expanding a device
  3627. name (eg. C</dev/sd*>). Use C<guestfs_list_devices>,
  3628. C<guestfs_list_partitions> etc functions instead." };
  3629. { defaults with
  3630. name = "scrub_device";
  3631. style = RErr, [Device "device"], [];
  3632. proc_nr = Some 114;
  3633. optional = Some "scrub";
  3634. tests = [
  3635. InitNone, Always, TestRun ( (* use /dev/sdc because it's smaller *)
  3636. [["scrub_device"; "/dev/sdc"]])
  3637. ];
  3638. shortdesc = "scrub (securely wipe) a device";
  3639. longdesc = "\
  3640. This command writes patterns over C<device> to make data retrieval
  3641. more difficult.
  3642. It is an interface to the L<scrub(1)> program. See that
  3643. manual page for more details." };
  3644. { defaults with
  3645. name = "scrub_file";
  3646. style = RErr, [Pathname "file"], [];
  3647. proc_nr = Some 115;
  3648. optional = Some "scrub";
  3649. tests = [
  3650. InitScratchFS, Always, TestRun (
  3651. [["write"; "/scrub_file"; "content"];
  3652. ["scrub_file"; "/scrub_file"]])
  3653. ];
  3654. shortdesc = "scrub (securely wipe) a file";
  3655. longdesc = "\
  3656. This command writes patterns over a file to make data retrieval
  3657. more difficult.
  3658. The file is I<removed> after scrubbing.
  3659. It is an interface to the L<scrub(1)> program. See that
  3660. manual page for more details." };
  3661. { defaults with
  3662. name = "scrub_freespace";
  3663. style = RErr, [Pathname "dir"], [];
  3664. proc_nr = Some 116;
  3665. optional = Some "scrub";
  3666. tests = [] (* XXX needs testing *);
  3667. shortdesc = "scrub (securely wipe) free space";
  3668. longdesc = "\
  3669. This command creates the directory C<dir> and then fills it
  3670. with files until the filesystem is full, and scrubs the files
  3671. as for C<guestfs_scrub_file>, and deletes them.
  3672. The intention is to scrub any free space on the partition
  3673. containing C<dir>.
  3674. It is an interface to the L<scrub(1)> program. See that
  3675. manual page for more details." };
  3676. { defaults with
  3677. name = "mkdtemp";
  3678. style = RString "dir", [Pathname "tmpl"], [];
  3679. proc_nr = Some 117;
  3680. tests = [
  3681. InitScratchFS, Always, TestRun (
  3682. [["mkdir"; "/mkdtemp"];
  3683. ["mkdtemp"; "/mkdtemp/tmpXXXXXX"]])
  3684. ];
  3685. shortdesc = "create a temporary directory";
  3686. longdesc = "\
  3687. This command creates a temporary directory. The
  3688. C<tmpl> parameter should be a full pathname for the
  3689. temporary directory name with the final six characters being
  3690. \"XXXXXX\".
  3691. For example: \"/tmp/myprogXXXXXX\" or \"/Temp/myprogXXXXXX\",
  3692. the second one being suitable for Windows filesystems.
  3693. The name of the temporary directory that was created
  3694. is returned.
  3695. The temporary directory is created with mode 0700
  3696. and is owned by root.
  3697. The caller is responsible for deleting the temporary
  3698. directory and its contents after use.
  3699. See also: L<mkdtemp(3)>" };
  3700. { defaults with
  3701. name = "wc_l";
  3702. style = RInt "lines", [Pathname "path"], [];
  3703. proc_nr = Some 118;
  3704. tests = [
  3705. InitISOFS, Always, TestOutputInt (
  3706. [["wc_l"; "/10klines"]], 10000);
  3707. (* Test for RHBZ#579608, absolute symbolic links. *)
  3708. InitISOFS, Always, TestOutputInt (
  3709. [["wc_l"; "/abssymlink"]], 10000)
  3710. ];
  3711. shortdesc = "count lines in a file";
  3712. longdesc = "\
  3713. This command counts the lines in a file, using the
  3714. C<wc -l> external command." };
  3715. { defaults with
  3716. name = "wc_w";
  3717. style = RInt "words", [Pathname "path"], [];
  3718. proc_nr = Some 119;
  3719. tests = [
  3720. InitISOFS, Always, TestOutputInt (
  3721. [["wc_w"; "/10klines"]], 10000)
  3722. ];
  3723. shortdesc = "count words in a file";
  3724. longdesc = "\
  3725. This command counts the words in a file, using the
  3726. C<wc -w> external command." };
  3727. { defaults with
  3728. name = "wc_c";
  3729. style = RInt "chars", [Pathname "path"], [];
  3730. proc_nr = Some 120;
  3731. tests = [
  3732. InitISOFS, Always, TestOutputInt (
  3733. [["wc_c"; "/100kallspaces"]], 102400)
  3734. ];
  3735. shortdesc = "count characters in a file";
  3736. longdesc = "\
  3737. This command counts the characters in a file, using the
  3738. C<wc -c> external command." };
  3739. { defaults with
  3740. name = "head";
  3741. style = RStringList "lines", [Pathname "path"], [];
  3742. proc_nr = Some 121;
  3743. protocol_limit_warning = true;
  3744. tests = [
  3745. InitISOFS, Always, TestOutputList (
  3746. [["head"; "/10klines"]], ["0abcdefghijklmnopqrstuvwxyz";"1abcdefghijklmnopqrstuvwxyz";"2abcdefghijklmnopqrstuvwxyz";"3abcdefghijklmnopqrstuvwxyz";"4abcdefghijklmnopqrstuvwxyz";"5abcdefghijklmnopqrstuvwxyz";"6abcdefghijklmnopqrstuvwxyz";"7abcdefghijklmnopqrstuvwxyz";"8abcdefghijklmnopqrstuvwxyz";"9abcdefghijklmnopqrstuvwxyz"]);
  3747. (* Test for RHBZ#579608, absolute symbolic links. *)
  3748. InitISOFS, Always, TestOutputList (
  3749. [["head"; "/abssymlink"]], ["0abcdefghijklmnopqrstuvwxyz";"1abcdefghijklmnopqrstuvwxyz";"2abcdefghijklmnopqrstuvwxyz";"3abcdefghijklmnopqrstuvwxyz";"4abcdefghijklmnopqrstuvwxyz";"5abcdefghijklmnopqrstuvwxyz";"6abcdefghijklmnopqrstuvwxyz";"7abcdefghijklmnopqrstuvwxyz";"8abcdefghijklmnopqrstuvwxyz";"9abcdefghijklmnopqrstuvwxyz"])
  3750. ];
  3751. shortdesc = "return first 10 lines of a file";
  3752. longdesc = "\
  3753. This command returns up to the first 10 lines of a file as
  3754. a list of strings." };
  3755. { defaults with
  3756. name = "head_n";
  3757. style = RStringList "lines", [Int "nrlines"; Pathname "path"], [];
  3758. proc_nr = Some 122;
  3759. protocol_limit_warning = true;
  3760. tests = [
  3761. InitISOFS, Always, TestOutputList (
  3762. [["head_n"; "3"; "/10klines"]], ["0abcdefghijklmnopqrstuvwxyz";"1abcdefghijklmnopqrstuvwxyz";"2abcdefghijklmnopqrstuvwxyz"]);
  3763. InitISOFS, Always, TestOutputList (
  3764. [["head_n"; "-9997"; "/10klines"]], ["0abcdefghijklmnopqrstuvwxyz";"1abcdefghijklmnopqrstuvwxyz";"2abcdefghijklmnopqrstuvwxyz"]);
  3765. InitISOFS, Always, TestOutputList (
  3766. [["head_n"; "0"; "/10klines"]], [])
  3767. ];
  3768. shortdesc = "return first N lines of a file";
  3769. longdesc = "\
  3770. If the parameter C<nrlines> is a positive number, this returns the first
  3771. C<nrlines> lines of the file C<path>.
  3772. If the parameter C<nrlines> is a negative number, this returns lines
  3773. from the file C<path>, excluding the last C<nrlines> lines.
  3774. If the parameter C<nrlines> is zero, this returns an empty list." };
  3775. { defaults with
  3776. name = "tail";
  3777. style = RStringList "lines", [Pathname "path"], [];
  3778. proc_nr = Some 123;
  3779. protocol_limit_warning = true;
  3780. tests = [
  3781. InitISOFS, Always, TestOutputList (
  3782. [["tail"; "/10klines"]], ["9990abcdefghijklmnopqrstuvwxyz";"9991abcdefghijklmnopqrstuvwxyz";"9992abcdefghijklmnopqrstuvwxyz";"9993abcdefghijklmnopqrstuvwxyz";"9994abcdefghijklmnopqrstuvwxyz";"9995abcdefghijklmnopqrstuvwxyz";"9996abcdefghijklmnopqrstuvwxyz";"9997abcdefghijklmnopqrstuvwxyz";"9998abcdefghijklmnopqrstuvwxyz";"9999abcdefghijklmnopqrstuvwxyz"])
  3783. ];
  3784. shortdesc = "return last 10 lines of a file";
  3785. longdesc = "\
  3786. This command returns up to the last 10 lines of a file as
  3787. a list of strings." };
  3788. { defaults with
  3789. name = "tail_n";
  3790. style = RStringList "lines", [Int "nrlines"; Pathname "path"], [];
  3791. proc_nr = Some 124;
  3792. protocol_limit_warning = true;
  3793. tests = [
  3794. InitISOFS, Always, TestOutputList (
  3795. [["tail_n"; "3"; "/10klines"]], ["9997abcdefghijklmnopqrstuvwxyz";"9998abcdefghijklmnopqrstuvwxyz";"9999abcdefghijklmnopqrstuvwxyz"]);
  3796. InitISOFS, Always, TestOutputList (
  3797. [["tail_n"; "-9998"; "/10klines"]], ["9997abcdefghijklmnopqrstuvwxyz";"9998abcdefghijklmnopqrstuvwxyz";"9999abcdefghijklmnopqrstuvwxyz"]);
  3798. InitISOFS, Always, TestOutputList (
  3799. [["tail_n"; "0"; "/10klines"]], [])
  3800. ];
  3801. shortdesc = "return last N lines of a file";
  3802. longdesc = "\
  3803. If the parameter C<nrlines> is a positive number, this returns the last
  3804. C<nrlines> lines of the file C<path>.
  3805. If the parameter C<nrlines> is a negative number, this returns lines
  3806. from the file C<path>, starting with the C<-nrlines>th line.
  3807. If the parameter C<nrlines> is zero, this returns an empty list." };
  3808. { defaults with
  3809. name = "df";
  3810. style = RString "output", [], [];
  3811. proc_nr = Some 125;
  3812. tests = [] (* XXX Tricky to test because it depends on the exact format
  3813. * of the 'df' command and other imponderables.
  3814. *);
  3815. shortdesc = "report file system disk space usage";
  3816. longdesc = "\
  3817. This command runs the C<df> command to report disk space used.
  3818. This command is mostly useful for interactive sessions. It
  3819. is I<not> intended that you try to parse the output string.
  3820. Use C<guestfs_statvfs> from programs." };
  3821. { defaults with
  3822. name = "df_h";
  3823. style = RString "output", [], [];
  3824. proc_nr = Some 126;
  3825. tests = [] (* XXX Tricky to test because it depends on the exact format
  3826. * of the 'df' command and other imponderables.
  3827. *);
  3828. shortdesc = "report file system disk space usage (human readable)";
  3829. longdesc = "\
  3830. This command runs the C<df -h> command to report disk space used
  3831. in human-readable format.
  3832. This command is mostly useful for interactive sessions. It
  3833. is I<not> intended that you try to parse the output string.
  3834. Use C<guestfs_statvfs> from programs." };
  3835. { defaults with
  3836. name = "du";
  3837. style = RInt64 "sizekb", [Pathname "path"], [];
  3838. proc_nr = Some 127;
  3839. progress = true;
  3840. tests = [
  3841. InitISOFS, Always, TestOutputInt (
  3842. [["du"; "/directory"]], 2 (* ISO fs blocksize is 2K *))
  3843. ];
  3844. shortdesc = "estimate file space usage";
  3845. longdesc = "\
  3846. This command runs the C<du -s> command to estimate file space
  3847. usage for C<path>.
  3848. C<path> can be a file or a directory. If C<path> is a directory
  3849. then the estimate includes the contents of the directory and all
  3850. subdirectories (recursively).
  3851. The result is the estimated size in I<kilobytes>
  3852. (ie. units of 1024 bytes)." };
  3853. { defaults with
  3854. name = "initrd_list";
  3855. style = RStringList "filenames", [Pathname "path"], [];
  3856. proc_nr = Some 128;
  3857. tests = [
  3858. InitISOFS, Always, TestOutputList (
  3859. [["initrd_list"; "/initrd"]], ["empty";"known-1";"known-2";"known-3";"known-4"; "known-5"])
  3860. ];
  3861. shortdesc = "list files in an initrd";
  3862. longdesc = "\
  3863. This command lists out files contained in an initrd.
  3864. The files are listed without any initial C</> character. The
  3865. files are listed in the order they appear (not necessarily
  3866. alphabetical). Directory names are listed as separate items.
  3867. Old Linux kernels (2.4 and earlier) used a compressed ext2
  3868. filesystem as initrd. We I<only> support the newer initramfs
  3869. format (compressed cpio files)." };
  3870. { defaults with
  3871. name = "mount_loop";
  3872. style = RErr, [Pathname "file"; Pathname "mountpoint"], [];
  3873. proc_nr = Some 129;
  3874. shortdesc = "mount a file using the loop device";
  3875. longdesc = "\
  3876. This command lets you mount C<file> (a filesystem image
  3877. in a file) on a mount point. It is entirely equivalent to
  3878. the command C<mount -o loop file mountpoint>." };
  3879. { defaults with
  3880. name = "mkswap";
  3881. style = RErr, [Device "device"], [];
  3882. proc_nr = Some 130;
  3883. tests = [
  3884. InitEmpty, Always, TestRun (
  3885. [["part_disk"; "/dev/sda"; "mbr"];
  3886. ["mkswap"; "/dev/sda1"]])
  3887. ];
  3888. shortdesc = "create a swap partition";
  3889. longdesc = "\
  3890. Create a swap partition on C<device>." };
  3891. { defaults with
  3892. name = "mkswap_L";
  3893. style = RErr, [String "label"; Device "device"], [];
  3894. proc_nr = Some 131;
  3895. tests = [
  3896. InitEmpty, Always, TestRun (
  3897. [["part_disk"; "/dev/sda"; "mbr"];
  3898. ["mkswap_L"; "hello"; "/dev/sda1"]])
  3899. ];
  3900. shortdesc = "create a swap partition with a label";
  3901. longdesc = "\
  3902. Create a swap partition on C<device> with label C<label>.
  3903. Note that you cannot attach a swap label to a block device
  3904. (eg. C</dev/sda>), just to a partition. This appears to be
  3905. a limitation of the kernel or swap tools." };
  3906. { defaults with
  3907. name = "mkswap_U";
  3908. style = RErr, [String "uuid"; Device "device"], [];
  3909. proc_nr = Some 132;
  3910. optional = Some "linuxfsuuid";
  3911. tests =
  3912. (let uuid = uuidgen () in [
  3913. InitEmpty, Always, TestRun (
  3914. [["part_disk"; "/dev/sda"; "mbr"];
  3915. ["mkswap_U"; uuid; "/dev/sda1"]])
  3916. ]);
  3917. shortdesc = "create a swap partition with an explicit UUID";
  3918. longdesc = "\
  3919. Create a swap partition on C<device> with UUID C<uuid>." };
  3920. { defaults with
  3921. name = "mknod";
  3922. style = RErr, [Int "mode"; Int "devmajor"; Int "devminor"; Pathname "path"], [];
  3923. proc_nr = Some 133;
  3924. optional = Some "mknod";
  3925. tests = [
  3926. InitScratchFS, Always, TestOutputStruct (
  3927. [["mknod"; "0o10777"; "0"; "0"; "/mknod"];
  3928. (* NB: default umask 022 means 0777 -> 0755 in these tests *)
  3929. ["stat"; "/mknod"]], [CompareWithInt ("mode", 0o10755)]);
  3930. InitScratchFS, Always, TestOutputStruct (
  3931. [["mknod"; "0o60777"; "66"; "99"; "/mknod2"];
  3932. ["stat"; "/mknod2"]], [CompareWithInt ("mode", 0o60755)])
  3933. ];
  3934. shortdesc = "make block, character or FIFO devices";
  3935. longdesc = "\
  3936. This call creates block or character special devices, or
  3937. named pipes (FIFOs).
  3938. The C<mode> parameter should be the mode, using the standard
  3939. constants. C<devmajor> and C<devminor> are the
  3940. device major and minor numbers, only used when creating block
  3941. and character special devices.
  3942. Note that, just like L<mknod(2)>, the mode must be bitwise
  3943. OR'd with S_IFBLK, S_IFCHR, S_IFIFO or S_IFSOCK (otherwise this call
  3944. just creates a regular file). These constants are
  3945. available in the standard Linux header files, or you can use
  3946. C<guestfs_mknod_b>, C<guestfs_mknod_c> or C<guestfs_mkfifo>
  3947. which are wrappers around this command which bitwise OR
  3948. in the appropriate constant for you.
  3949. The mode actually set is affected by the umask." };
  3950. { defaults with
  3951. name = "mkfifo";
  3952. style = RErr, [Int "mode"; Pathname "path"], [];
  3953. proc_nr = Some 134;
  3954. optional = Some "mknod";
  3955. tests = [
  3956. InitScratchFS, Always, TestOutputStruct (
  3957. [["mkfifo"; "0o777"; "/mkfifo"];
  3958. ["stat"; "/mkfifo"]], [CompareWithInt ("mode", 0o10755)])
  3959. ];
  3960. shortdesc = "make FIFO (named pipe)";
  3961. longdesc = "\
  3962. This call creates a FIFO (named pipe) called C<path> with
  3963. mode C<mode>. It is just a convenient wrapper around
  3964. C<guestfs_mknod>.
  3965. The mode actually set is affected by the umask." };
  3966. { defaults with
  3967. name = "mknod_b";
  3968. style = RErr, [Int "mode"; Int "devmajor"; Int "devminor"; Pathname "path"], [];
  3969. proc_nr = Some 135;
  3970. optional = Some "mknod";
  3971. tests = [
  3972. InitScratchFS, Always, TestOutputStruct (
  3973. [["mknod_b"; "0o777"; "99"; "66"; "/mknod_b"];
  3974. ["stat"; "/mknod_b"]], [CompareWithInt ("mode", 0o60755)])
  3975. ];
  3976. shortdesc = "make block device node";
  3977. longdesc = "\
  3978. This call creates a block device node called C<path> with
  3979. mode C<mode> and device major/minor C<devmajor> and C<devminor>.
  3980. It is just a convenient wrapper around C<guestfs_mknod>.
  3981. The mode actually set is affected by the umask." };
  3982. { defaults with
  3983. name = "mknod_c";
  3984. style = RErr, [Int "mode"; Int "devmajor"; Int "devminor"; Pathname "path"], [];
  3985. proc_nr = Some 136;
  3986. optional = Some "mknod";
  3987. tests = [
  3988. InitScratchFS, Always, TestOutputStruct (
  3989. [["mknod_c"; "0o777"; "99"; "66"; "/mknod_c"];
  3990. ["stat"; "/mknod_c"]], [CompareWithInt ("mode", 0o20755)])
  3991. ];
  3992. shortdesc = "make char device node";
  3993. longdesc = "\
  3994. This call creates a char device node called C<path> with
  3995. mode C<mode> and device major/minor C<devmajor> and C<devminor>.
  3996. It is just a convenient wrapper around C<guestfs_mknod>.
  3997. The mode actually set is affected by the umask." };
  3998. { defaults with
  3999. name = "umask";
  4000. style = RInt "oldmask", [Int "mask"], [];
  4001. proc_nr = Some 137;
  4002. fish_output = Some FishOutputOctal;
  4003. tests = [
  4004. InitEmpty, Always, TestOutputInt (
  4005. [["umask"; "0o22"]], 0o22)
  4006. ];
  4007. shortdesc = "set file mode creation mask (umask)";
  4008. longdesc = "\
  4009. This function sets the mask used for creating new files and
  4010. device nodes to C<mask & 0777>.
  4011. Typical umask values would be C<022> which creates new files
  4012. with permissions like \"-rw-r--r--\" or \"-rwxr-xr-x\", and
  4013. C<002> which creates new files with permissions like
  4014. \"-rw-rw-r--\" or \"-rwxrwxr-x\".
  4015. The default umask is C<022>. This is important because it
  4016. means that directories and device nodes will be created with
  4017. C<0644> or C<0755> mode even if you specify C<0777>.
  4018. See also C<guestfs_get_umask>,
  4019. L<umask(2)>, C<guestfs_mknod>, C<guestfs_mkdir>.
  4020. This call returns the previous umask." };
  4021. { defaults with
  4022. name = "readdir";
  4023. style = RStructList ("entries", "dirent"), [Pathname "dir"], [];
  4024. proc_nr = Some 138;
  4025. shortdesc = "read directories entries";
  4026. longdesc = "\
  4027. This returns the list of directory entries in directory C<dir>.
  4028. All entries in the directory are returned, including C<.> and
  4029. C<..>. The entries are I<not> sorted, but returned in the same
  4030. order as the underlying filesystem.
  4031. Also this call returns basic file type information about each
  4032. file. The C<ftyp> field will contain one of the following characters:
  4033. =over 4
  4034. =item 'b'
  4035. Block special
  4036. =item 'c'
  4037. Char special
  4038. =item 'd'
  4039. Directory
  4040. =item 'f'
  4041. FIFO (named pipe)
  4042. =item 'l'
  4043. Symbolic link
  4044. =item 'r'
  4045. Regular file
  4046. =item 's'
  4047. Socket
  4048. =item 'u'
  4049. Unknown file type
  4050. =item '?'
  4051. The L<readdir(3)> call returned a C<d_type> field with an
  4052. unexpected value
  4053. =back
  4054. This function is primarily intended for use by programs. To
  4055. get a simple list of names, use C<guestfs_ls>. To get a printable
  4056. directory for human consumption, use C<guestfs_ll>." };
  4057. { defaults with
  4058. name = "sfdiskM";
  4059. style = RErr, [Device "device"; StringList "lines"], [];
  4060. proc_nr = Some 139;
  4061. deprecated_by = Some "part_add";
  4062. shortdesc = "create partitions on a block device";
  4063. longdesc = "\
  4064. This is a simplified interface to the C<guestfs_sfdisk>
  4065. command, where partition sizes are specified in megabytes
  4066. only (rounded to the nearest cylinder) and you don't need
  4067. to specify the cyls, heads and sectors parameters which
  4068. were rarely if ever used anyway.
  4069. See also: C<guestfs_sfdisk>, the L<sfdisk(8)> manpage
  4070. and C<guestfs_part_disk>" };
  4071. { defaults with
  4072. name = "zfile";
  4073. style = RString "description", [String "meth"; Pathname "path"], [];
  4074. proc_nr = Some 140;
  4075. deprecated_by = Some "file";
  4076. shortdesc = "determine file type inside a compressed file";
  4077. longdesc = "\
  4078. This command runs C<file> after first decompressing C<path>
  4079. using C<method>.
  4080. C<method> must be one of C<gzip>, C<compress> or C<bzip2>.
  4081. Since 1.0.63, use C<guestfs_file> instead which can now
  4082. process compressed files." };
  4083. { defaults with
  4084. name = "getxattrs";
  4085. style = RStructList ("xattrs", "xattr"), [Pathname "path"], [];
  4086. proc_nr = Some 141;
  4087. optional = Some "linuxxattrs";
  4088. shortdesc = "list extended attributes of a file or directory";
  4089. longdesc = "\
  4090. This call lists the extended attributes of the file or directory
  4091. C<path>.
  4092. At the system call level, this is a combination of the
  4093. L<listxattr(2)> and L<getxattr(2)> calls.
  4094. See also: C<guestfs_lgetxattrs>, L<attr(5)>." };
  4095. { defaults with
  4096. name = "lgetxattrs";
  4097. style = RStructList ("xattrs", "xattr"), [Pathname "path"], [];
  4098. proc_nr = Some 142;
  4099. optional = Some "linuxxattrs";
  4100. shortdesc = "list extended attributes of a file or directory";
  4101. longdesc = "\
  4102. This is the same as C<guestfs_getxattrs>, but if C<path>
  4103. is a symbolic link, then it returns the extended attributes
  4104. of the link itself." };
  4105. { defaults with
  4106. name = "setxattr";
  4107. style = RErr, [String "xattr";
  4108. String "val"; Int "vallen"; (* will be BufferIn *)
  4109. Pathname "path"], [];
  4110. proc_nr = Some 143;
  4111. optional = Some "linuxxattrs";
  4112. shortdesc = "set extended attribute of a file or directory";
  4113. longdesc = "\
  4114. This call sets the extended attribute named C<xattr>
  4115. of the file C<path> to the value C<val> (of length C<vallen>).
  4116. The value is arbitrary 8 bit data.
  4117. See also: C<guestfs_lsetxattr>, L<attr(5)>." };
  4118. { defaults with
  4119. name = "lsetxattr";
  4120. style = RErr, [String "xattr";
  4121. String "val"; Int "vallen"; (* will be BufferIn *)
  4122. Pathname "path"], [];
  4123. proc_nr = Some 144;
  4124. optional = Some "linuxxattrs";
  4125. shortdesc = "set extended attribute of a file or directory";
  4126. longdesc = "\
  4127. This is the same as C<guestfs_setxattr>, but if C<path>
  4128. is a symbolic link, then it sets an extended attribute
  4129. of the link itself." };
  4130. { defaults with
  4131. name = "removexattr";
  4132. style = RErr, [String "xattr"; Pathname "path"], [];
  4133. proc_nr = Some 145;
  4134. optional = Some "linuxxattrs";
  4135. shortdesc = "remove extended attribute of a file or directory";
  4136. longdesc = "\
  4137. This call removes the extended attribute named C<xattr>
  4138. of the file C<path>.
  4139. See also: C<guestfs_lremovexattr>, L<attr(5)>." };
  4140. { defaults with
  4141. name = "lremovexattr";
  4142. style = RErr, [String "xattr"; Pathname "path"], [];
  4143. proc_nr = Some 146;
  4144. optional = Some "linuxxattrs";
  4145. shortdesc = "remove extended attribute of a file or directory";
  4146. longdesc = "\
  4147. This is the same as C<guestfs_removexattr>, but if C<path>
  4148. is a symbolic link, then it removes an extended attribute
  4149. of the link itself." };
  4150. { defaults with
  4151. name = "mountpoints";
  4152. style = RHashtable "mps", [], [];
  4153. proc_nr = Some 147;
  4154. shortdesc = "show mountpoints";
  4155. longdesc = "\
  4156. This call is similar to C<guestfs_mounts>. That call returns
  4157. a list of devices. This one returns a hash table (map) of
  4158. device name to directory where the device is mounted." };
  4159. { defaults with
  4160. name = "mkmountpoint";
  4161. (* This is a special case: while you would expect a parameter
  4162. * of type "Pathname", that doesn't work, because it implies
  4163. * NEED_ROOT in the generated calling code in stubs.c, and
  4164. * this function cannot use NEED_ROOT.
  4165. *)
  4166. style = RErr, [String "exemptpath"], [];
  4167. proc_nr = Some 148;
  4168. shortdesc = "create a mountpoint";
  4169. longdesc = "\
  4170. C<guestfs_mkmountpoint> and C<guestfs_rmmountpoint> are
  4171. specialized calls that can be used to create extra mountpoints
  4172. before mounting the first filesystem.
  4173. These calls are I<only> necessary in some very limited circumstances,
  4174. mainly the case where you want to mount a mix of unrelated and/or
  4175. read-only filesystems together.
  4176. For example, live CDs often contain a \"Russian doll\" nest of
  4177. filesystems, an ISO outer layer, with a squashfs image inside, with
  4178. an ext2/3 image inside that. You can unpack this as follows
  4179. in guestfish:
  4180. add-ro Fedora-11-i686-Live.iso
  4181. run
  4182. mkmountpoint /cd
  4183. mkmountpoint /sqsh
  4184. mkmountpoint /ext3fs
  4185. mount /dev/sda /cd
  4186. mount-loop /cd/LiveOS/squashfs.img /sqsh
  4187. mount-loop /sqsh/LiveOS/ext3fs.img /ext3fs
  4188. The inner filesystem is now unpacked under the /ext3fs mountpoint.
  4189. C<guestfs_mkmountpoint> is not compatible with C<guestfs_umount_all>.
  4190. You may get unexpected errors if you try to mix these calls. It is
  4191. safest to manually unmount filesystems and remove mountpoints after use.
  4192. C<guestfs_umount_all> unmounts filesystems by sorting the paths
  4193. longest first, so for this to work for manual mountpoints, you
  4194. must ensure that the innermost mountpoints have the longest
  4195. pathnames, as in the example code above.
  4196. For more details see L<https://bugzilla.redhat.com/show_bug.cgi?id=599503>
  4197. Autosync [see C<guestfs_set_autosync>, this is set by default on
  4198. handles] can cause C<guestfs_umount_all> to be called when the handle
  4199. is closed which can also trigger these issues." };
  4200. { defaults with
  4201. name = "rmmountpoint";
  4202. style = RErr, [String "exemptpath"], [];
  4203. proc_nr = Some 149;
  4204. shortdesc = "remove a mountpoint";
  4205. longdesc = "\
  4206. This calls removes a mountpoint that was previously created
  4207. with C<guestfs_mkmountpoint>. See C<guestfs_mkmountpoint>
  4208. for full details." };
  4209. { defaults with
  4210. name = "read_file";
  4211. style = RBufferOut "content", [Pathname "path"], [];
  4212. proc_nr = Some 150;
  4213. protocol_limit_warning = true;
  4214. tests = [
  4215. InitISOFS, Always, TestOutputBuffer (
  4216. [["read_file"; "/known-4"]], "abc\ndef\nghi");
  4217. (* Test various near large, large and too large files (RHBZ#589039). *)
  4218. InitScratchFS, Always, TestLastFail (
  4219. [["touch"; "/read_file"];
  4220. ["truncate_size"; "/read_file"; "4194303"]; (* GUESTFS_MESSAGE_MAX - 1 *)
  4221. ["read_file"; "/read_file"]]);
  4222. InitScratchFS, Always, TestLastFail (
  4223. [["touch"; "/read_file2"];
  4224. ["truncate_size"; "/read_file2"; "4194304"]; (* GUESTFS_MESSAGE_MAX *)
  4225. ["read_file"; "/read_file2"]]);
  4226. InitScratchFS, Always, TestLastFail (
  4227. [["touch"; "/read_file3"];
  4228. ["truncate_size"; "/read_file3"; "41943040"]; (* GUESTFS_MESSAGE_MAX * 10 *)
  4229. ["read_file"; "/read_file3"]])
  4230. ];
  4231. shortdesc = "read a file";
  4232. longdesc = "\
  4233. This calls returns the contents of the file C<path> as a
  4234. buffer.
  4235. Unlike C<guestfs_cat>, this function can correctly
  4236. handle files that contain embedded ASCII NUL characters.
  4237. However unlike C<guestfs_download>, this function is limited
  4238. in the total size of file that can be handled." };
  4239. { defaults with
  4240. name = "grep";
  4241. style = RStringList "lines", [String "regex"; Pathname "path"], [];
  4242. proc_nr = Some 151;
  4243. protocol_limit_warning = true;
  4244. tests = [
  4245. InitISOFS, Always, TestOutputList (
  4246. [["grep"; "abc"; "/test-grep.txt"]], ["abc"; "abc123"]);
  4247. InitISOFS, Always, TestOutputList (
  4248. [["grep"; "nomatch"; "/test-grep.txt"]], []);
  4249. (* Test for RHBZ#579608, absolute symbolic links. *)
  4250. InitISOFS, Always, TestOutputList (
  4251. [["grep"; "nomatch"; "/abssymlink"]], [])
  4252. ];
  4253. shortdesc = "return lines matching a pattern";
  4254. longdesc = "\
  4255. This calls the external C<grep> program and returns the
  4256. matching lines." };
  4257. { defaults with
  4258. name = "egrep";
  4259. style = RStringList "lines", [String "regex"; Pathname "path"], [];
  4260. proc_nr = Some 152;
  4261. protocol_limit_warning = true;
  4262. tests = [
  4263. InitISOFS, Always, TestOutputList (
  4264. [["egrep"; "abc"; "/test-grep.txt"]], ["abc"; "abc123"])
  4265. ];
  4266. shortdesc = "return lines matching a pattern";
  4267. longdesc = "\
  4268. This calls the external C<egrep> program and returns the
  4269. matching lines." };
  4270. { defaults with
  4271. name = "fgrep";
  4272. style = RStringList "lines", [String "pattern"; Pathname "path"], [];
  4273. proc_nr = Some 153;
  4274. protocol_limit_warning = true;
  4275. tests = [
  4276. InitISOFS, Always, TestOutputList (
  4277. [["fgrep"; "abc"; "/test-grep.txt"]], ["abc"; "abc123"])
  4278. ];
  4279. shortdesc = "return lines matching a pattern";
  4280. longdesc = "\
  4281. This calls the external C<fgrep> program and returns the
  4282. matching lines." };
  4283. { defaults with
  4284. name = "grepi";
  4285. style = RStringList "lines", [String "regex"; Pathname "path"], [];
  4286. proc_nr = Some 154;
  4287. protocol_limit_warning = true;
  4288. tests = [
  4289. InitISOFS, Always, TestOutputList (
  4290. [["grepi"; "abc"; "/test-grep.txt"]], ["abc"; "abc123"; "ABC"])
  4291. ];
  4292. shortdesc = "return lines matching a pattern";
  4293. longdesc = "\
  4294. This calls the external C<grep -i> program and returns the
  4295. matching lines." };
  4296. { defaults with
  4297. name = "egrepi";
  4298. style = RStringList "lines", [String "regex"; Pathname "path"], [];
  4299. proc_nr = Some 155;
  4300. protocol_limit_warning = true;
  4301. tests = [
  4302. InitISOFS, Always, TestOutputList (
  4303. [["egrepi"; "abc"; "/test-grep.txt"]], ["abc"; "abc123"; "ABC"])
  4304. ];
  4305. shortdesc = "return lines matching a pattern";
  4306. longdesc = "\
  4307. This calls the external C<egrep -i> program and returns the
  4308. matching lines." };
  4309. { defaults with
  4310. name = "fgrepi";
  4311. style = RStringList "lines", [String "pattern"; Pathname "path"], [];
  4312. proc_nr = Some 156;
  4313. protocol_limit_warning = true;
  4314. tests = [
  4315. InitISOFS, Always, TestOutputList (
  4316. [["fgrepi"; "abc"; "/test-grep.txt"]], ["abc"; "abc123"; "ABC"])
  4317. ];
  4318. shortdesc = "return lines matching a pattern";
  4319. longdesc = "\
  4320. This calls the external C<fgrep -i> program and returns the
  4321. matching lines." };
  4322. { defaults with
  4323. name = "zgrep";
  4324. style = RStringList "lines", [String "regex"; Pathname "path"], [];
  4325. proc_nr = Some 157;
  4326. protocol_limit_warning = true;
  4327. tests = [
  4328. InitISOFS, Always, TestOutputList (
  4329. [["zgrep"; "abc"; "/test-grep.txt.gz"]], ["abc"; "abc123"])
  4330. ];
  4331. shortdesc = "return lines matching a pattern";
  4332. longdesc = "\
  4333. This calls the external C<zgrep> program and returns the
  4334. matching lines." };
  4335. { defaults with
  4336. name = "zegrep";
  4337. style = RStringList "lines", [String "regex"; Pathname "path"], [];
  4338. proc_nr = Some 158;
  4339. protocol_limit_warning = true;
  4340. tests = [
  4341. InitISOFS, Always, TestOutputList (
  4342. [["zegrep"; "abc"; "/test-grep.txt.gz"]], ["abc"; "abc123"])
  4343. ];
  4344. shortdesc = "return lines matching a pattern";
  4345. longdesc = "\
  4346. This calls the external C<zegrep> program and returns the
  4347. matching lines." };
  4348. { defaults with
  4349. name = "zfgrep";
  4350. style = RStringList "lines", [String "pattern"; Pathname "path"], [];
  4351. proc_nr = Some 159;
  4352. protocol_limit_warning = true;
  4353. tests = [
  4354. InitISOFS, Always, TestOutputList (
  4355. [["zfgrep"; "abc"; "/test-grep.txt.gz"]], ["abc"; "abc123"])
  4356. ];
  4357. shortdesc = "return lines matching a pattern";
  4358. longdesc = "\
  4359. This calls the external C<zfgrep> program and returns the
  4360. matching lines." };
  4361. { defaults with
  4362. name = "zgrepi";
  4363. style = RStringList "lines", [String "regex"; Pathname "path"], [];
  4364. proc_nr = Some 160;
  4365. protocol_limit_warning = true;
  4366. tests = [
  4367. InitISOFS, Always, TestOutputList (
  4368. [["zgrepi"; "abc"; "/test-grep.txt.gz"]], ["abc"; "abc123"; "ABC"])
  4369. ];
  4370. shortdesc = "return lines matching a pattern";
  4371. longdesc = "\
  4372. This calls the external C<zgrep -i> program and returns the
  4373. matching lines." };
  4374. { defaults with
  4375. name = "zegrepi";
  4376. style = RStringList "lines", [String "regex"; Pathname "path"], [];
  4377. proc_nr = Some 161;
  4378. protocol_limit_warning = true;
  4379. tests = [
  4380. InitISOFS, Always, TestOutputList (
  4381. [["zegrepi"; "abc"; "/test-grep.txt.gz"]], ["abc"; "abc123"; "ABC"])
  4382. ];
  4383. shortdesc = "return lines matching a pattern";
  4384. longdesc = "\
  4385. This calls the external C<zegrep -i> program and returns the
  4386. matching lines." };
  4387. { defaults with
  4388. name = "zfgrepi";
  4389. style = RStringList "lines", [String "pattern"; Pathname "path"], [];
  4390. proc_nr = Some 162;
  4391. protocol_limit_warning = true;
  4392. tests = [
  4393. InitISOFS, Always, TestOutputList (
  4394. [["zfgrepi"; "abc"; "/test-grep.txt.gz"]], ["abc"; "abc123"; "ABC"])
  4395. ];
  4396. shortdesc = "return lines matching a pattern";
  4397. longdesc = "\
  4398. This calls the external C<zfgrep -i> program and returns the
  4399. matching lines." };
  4400. { defaults with
  4401. name = "realpath";
  4402. style = RString "rpath", [Pathname "path"], [];
  4403. proc_nr = Some 163;
  4404. optional = Some "realpath";
  4405. tests = [
  4406. InitISOFS, Always, TestOutput (
  4407. [["realpath"; "/../directory"]], "/directory")
  4408. ];
  4409. shortdesc = "canonicalized absolute pathname";
  4410. longdesc = "\
  4411. Return the canonicalized absolute pathname of C<path>. The
  4412. returned path has no C<.>, C<..> or symbolic link path elements." };
  4413. { defaults with
  4414. name = "ln";
  4415. style = RErr, [String "target"; Pathname "linkname"], [];
  4416. proc_nr = Some 164;
  4417. tests = [
  4418. InitScratchFS, Always, TestOutputStruct (
  4419. [["mkdir"; "/ln"];
  4420. ["touch"; "/ln/a"];
  4421. ["ln"; "/ln/a"; "/ln/b"];
  4422. ["stat"; "/ln/b"]], [CompareWithInt ("nlink", 2)])
  4423. ];
  4424. shortdesc = "create a hard link";
  4425. longdesc = "\
  4426. This command creates a hard link using the C<ln> command." };
  4427. { defaults with
  4428. name = "ln_f";
  4429. style = RErr, [String "target"; Pathname "linkname"], [];
  4430. proc_nr = Some 165;
  4431. tests = [
  4432. InitScratchFS, Always, TestOutputStruct (
  4433. [["mkdir"; "/ln_f"];
  4434. ["touch"; "/ln_f/a"];
  4435. ["touch"; "/ln_f/b"];
  4436. ["ln_f"; "/ln_f/a"; "/ln_f/b"];
  4437. ["stat"; "/ln_f/b"]], [CompareWithInt ("nlink", 2)])
  4438. ];
  4439. shortdesc = "create a hard link";
  4440. longdesc = "\
  4441. This command creates a hard link using the C<ln -f> command.
  4442. The I<-f> option removes the link (C<linkname>) if it exists already." };
  4443. { defaults with
  4444. name = "ln_s";
  4445. style = RErr, [String "target"; Pathname "linkname"], [];
  4446. proc_nr = Some 166;
  4447. tests = [
  4448. InitScratchFS, Always, TestOutputStruct (
  4449. [["mkdir"; "/ln_s"];
  4450. ["touch"; "/ln_s/a"];
  4451. ["ln_s"; "a"; "/ln_s/b"];
  4452. ["lstat"; "/ln_s/b"]], [CompareWithInt ("mode", 0o120777)])
  4453. ];
  4454. shortdesc = "create a symbolic link";
  4455. longdesc = "\
  4456. This command creates a symbolic link using the C<ln -s> command." };
  4457. { defaults with
  4458. name = "ln_sf";
  4459. style = RErr, [String "target"; Pathname "linkname"], [];
  4460. proc_nr = Some 167;
  4461. tests = [
  4462. InitScratchFS, Always, TestOutput (
  4463. [["mkdir_p"; "/ln_sf/b"];
  4464. ["touch"; "/ln_sf/b/c"];
  4465. ["ln_sf"; "../d"; "/ln_sf/b/c"];
  4466. ["readlink"; "/ln_sf/b/c"]], "../d")
  4467. ];
  4468. shortdesc = "create a symbolic link";
  4469. longdesc = "\
  4470. This command creates a symbolic link using the C<ln -sf> command,
  4471. The I<-f> option removes the link (C<linkname>) if it exists already." };
  4472. { defaults with
  4473. name = "readlink";
  4474. style = RString "link", [Pathname "path"], [];
  4475. proc_nr = Some 168;
  4476. shortdesc = "read the target of a symbolic link";
  4477. longdesc = "\
  4478. This command reads the target of a symbolic link." };
  4479. { defaults with
  4480. name = "fallocate";
  4481. style = RErr, [Pathname "path"; Int "len"], [];
  4482. proc_nr = Some 169;
  4483. deprecated_by = Some "fallocate64";
  4484. tests = [
  4485. InitScratchFS, Always, TestOutputStruct (
  4486. [["fallocate"; "/fallocate"; "1000000"];
  4487. ["stat"; "/fallocate"]], [CompareWithInt ("size", 1_000_000)])
  4488. ];
  4489. shortdesc = "preallocate a file in the guest filesystem";
  4490. longdesc = "\
  4491. This command preallocates a file (containing zero bytes) named
  4492. C<path> of size C<len> bytes. If the file exists already, it
  4493. is overwritten.
  4494. Do not confuse this with the guestfish-specific
  4495. C<alloc> command which allocates a file in the host and
  4496. attaches it as a device." };
  4497. { defaults with
  4498. name = "swapon_device";
  4499. style = RErr, [Device "device"], [];
  4500. proc_nr = Some 170;
  4501. tests = [
  4502. InitPartition, Always, TestRun (
  4503. [["mkswap"; "/dev/sda1"];
  4504. ["swapon_device"; "/dev/sda1"];
  4505. ["swapoff_device"; "/dev/sda1"]])
  4506. ];
  4507. shortdesc = "enable swap on device";
  4508. longdesc = "\
  4509. This command enables the libguestfs appliance to use the
  4510. swap device or partition named C<device>. The increased
  4511. memory is made available for all commands, for example
  4512. those run using C<guestfs_command> or C<guestfs_sh>.
  4513. Note that you should not swap to existing guest swap
  4514. partitions unless you know what you are doing. They may
  4515. contain hibernation information, or other information that
  4516. the guest doesn't want you to trash. You also risk leaking
  4517. information about the host to the guest this way. Instead,
  4518. attach a new host device to the guest and swap on that." };
  4519. { defaults with
  4520. name = "swapoff_device";
  4521. style = RErr, [Device "device"], [];
  4522. proc_nr = Some 171;
  4523. shortdesc = "disable swap on device";
  4524. longdesc = "\
  4525. This command disables the libguestfs appliance swap
  4526. device or partition named C<device>.
  4527. See C<guestfs_swapon_device>." };
  4528. { defaults with
  4529. name = "swapon_file";
  4530. style = RErr, [Pathname "file"], [];
  4531. proc_nr = Some 172;
  4532. tests = [
  4533. InitScratchFS, Always, TestRun (
  4534. [["fallocate"; "/swapon_file"; "8388608"];
  4535. ["mkswap_file"; "/swapon_file"];
  4536. ["swapon_file"; "/swapon_file"];
  4537. ["swapoff_file"; "/swapon_file"];
  4538. ["rm"; "/swapon_file"]])
  4539. ];
  4540. shortdesc = "enable swap on file";
  4541. longdesc = "\
  4542. This command enables swap to a file.
  4543. See C<guestfs_swapon_device> for other notes." };
  4544. { defaults with
  4545. name = "swapoff_file";
  4546. style = RErr, [Pathname "file"], [];
  4547. proc_nr = Some 173;
  4548. shortdesc = "disable swap on file";
  4549. longdesc = "\
  4550. This command disables the libguestfs appliance swap on file." };
  4551. { defaults with
  4552. name = "swapon_label";
  4553. style = RErr, [String "label"], [];
  4554. proc_nr = Some 174;
  4555. tests = [
  4556. InitEmpty, Always, TestRun (
  4557. [["part_disk"; "/dev/sda"; "mbr"];
  4558. ["mkswap_L"; "swapit"; "/dev/sda1"];
  4559. ["swapon_label"; "swapit"];
  4560. ["swapoff_label"; "swapit"];
  4561. ["zero"; "/dev/sda"];
  4562. ["blockdev_rereadpt"; "/dev/sda"]])
  4563. ];
  4564. shortdesc = "enable swap on labeled swap partition";
  4565. longdesc = "\
  4566. This command enables swap to a labeled swap partition.
  4567. See C<guestfs_swapon_device> for other notes." };
  4568. { defaults with
  4569. name = "swapoff_label";
  4570. style = RErr, [String "label"], [];
  4571. proc_nr = Some 175;
  4572. shortdesc = "disable swap on labeled swap partition";
  4573. longdesc = "\
  4574. This command disables the libguestfs appliance swap on
  4575. labeled swap partition." };
  4576. { defaults with
  4577. name = "swapon_uuid";
  4578. style = RErr, [String "uuid"], [];
  4579. proc_nr = Some 176;
  4580. optional = Some "linuxfsuuid";
  4581. tests =
  4582. (let uuid = uuidgen () in [
  4583. InitEmpty, Always, TestRun (
  4584. [["mkswap_U"; uuid; "/dev/sdc"];
  4585. ["swapon_uuid"; uuid];
  4586. ["swapoff_uuid"; uuid]])
  4587. ]);
  4588. shortdesc = "enable swap on swap partition by UUID";
  4589. longdesc = "\
  4590. This command enables swap to a swap partition with the given UUID.
  4591. See C<guestfs_swapon_device> for other notes." };
  4592. { defaults with
  4593. name = "swapoff_uuid";
  4594. style = RErr, [String "uuid"], [];
  4595. proc_nr = Some 177;
  4596. optional = Some "linuxfsuuid";
  4597. shortdesc = "disable swap on swap partition by UUID";
  4598. longdesc = "\
  4599. This command disables the libguestfs appliance swap partition
  4600. with the given UUID." };
  4601. { defaults with
  4602. name = "mkswap_file";
  4603. style = RErr, [Pathname "path"], [];
  4604. proc_nr = Some 178;
  4605. tests = [
  4606. InitScratchFS, Always, TestRun (
  4607. [["fallocate"; "/mkswap_file"; "8388608"];
  4608. ["mkswap_file"; "/mkswap_file"];
  4609. ["rm"; "/mkswap_file"]])
  4610. ];
  4611. shortdesc = "create a swap file";
  4612. longdesc = "\
  4613. Create a swap file.
  4614. This command just writes a swap file signature to an existing
  4615. file. To create the file itself, use something like C<guestfs_fallocate>." };
  4616. { defaults with
  4617. name = "inotify_init";
  4618. style = RErr, [Int "maxevents"], [];
  4619. proc_nr = Some 179;
  4620. optional = Some "inotify";
  4621. tests = [
  4622. InitISOFS, Always, TestRun (
  4623. [["inotify_init"; "0"]])
  4624. ];
  4625. shortdesc = "create an inotify handle";
  4626. longdesc = "\
  4627. This command creates a new inotify handle.
  4628. The inotify subsystem can be used to notify events which happen to
  4629. objects in the guest filesystem.
  4630. C<maxevents> is the maximum number of events which will be
  4631. queued up between calls to C<guestfs_inotify_read> or
  4632. C<guestfs_inotify_files>.
  4633. If this is passed as C<0>, then the kernel (or previously set)
  4634. default is used. For Linux 2.6.29 the default was 16384 events.
  4635. Beyond this limit, the kernel throws away events, but records
  4636. the fact that it threw them away by setting a flag
  4637. C<IN_Q_OVERFLOW> in the returned structure list (see
  4638. C<guestfs_inotify_read>).
  4639. Before any events are generated, you have to add some
  4640. watches to the internal watch list. See: C<guestfs_inotify_add_watch> and
  4641. C<guestfs_inotify_rm_watch>.
  4642. Queued up events should be read periodically by calling
  4643. C<guestfs_inotify_read>
  4644. (or C<guestfs_inotify_files> which is just a helpful
  4645. wrapper around C<guestfs_inotify_read>). If you don't
  4646. read the events out often enough then you risk the internal
  4647. queue overflowing.
  4648. The handle should be closed after use by calling
  4649. C<guestfs_inotify_close>. This also removes any
  4650. watches automatically.
  4651. See also L<inotify(7)> for an overview of the inotify interface
  4652. as exposed by the Linux kernel, which is roughly what we expose
  4653. via libguestfs. Note that there is one global inotify handle
  4654. per libguestfs instance." };
  4655. { defaults with
  4656. name = "inotify_add_watch";
  4657. style = RInt64 "wd", [Pathname "path"; Int "mask"], [];
  4658. proc_nr = Some 180;
  4659. optional = Some "inotify";
  4660. tests = [
  4661. InitScratchFS, Always, TestOutputList (
  4662. [["mkdir"; "/inotify_add_watch"];
  4663. ["inotify_init"; "0"];
  4664. ["inotify_add_watch"; "/inotify_add_watch"; "1073741823"];
  4665. ["touch"; "/inotify_add_watch/a"];
  4666. ["touch"; "/inotify_add_watch/b"];
  4667. ["inotify_files"]], ["a"; "b"])
  4668. ];
  4669. shortdesc = "add an inotify watch";
  4670. longdesc = "\
  4671. Watch C<path> for the events listed in C<mask>.
  4672. Note that if C<path> is a directory then events within that
  4673. directory are watched, but this does I<not> happen recursively
  4674. (in subdirectories).
  4675. Note for non-C or non-Linux callers: the inotify events are
  4676. defined by the Linux kernel ABI and are listed in
  4677. C</usr/include/sys/inotify.h>." };
  4678. { defaults with
  4679. name = "inotify_rm_watch";
  4680. style = RErr, [Int(*XXX64*) "wd"], [];
  4681. proc_nr = Some 181;
  4682. optional = Some "inotify";
  4683. shortdesc = "remove an inotify watch";
  4684. longdesc = "\
  4685. Remove a previously defined inotify watch.
  4686. See C<guestfs_inotify_add_watch>." };
  4687. { defaults with
  4688. name = "inotify_read";
  4689. style = RStructList ("events", "inotify_event"), [], [];
  4690. proc_nr = Some 182;
  4691. optional = Some "inotify";
  4692. shortdesc = "return list of inotify events";
  4693. longdesc = "\
  4694. Return the complete queue of events that have happened
  4695. since the previous read call.
  4696. If no events have happened, this returns an empty list.
  4697. I<Note>: In order to make sure that all events have been
  4698. read, you must call this function repeatedly until it
  4699. returns an empty list. The reason is that the call will
  4700. read events up to the maximum appliance-to-host message
  4701. size and leave remaining events in the queue." };
  4702. { defaults with
  4703. name = "inotify_files";
  4704. style = RStringList "paths", [], [];
  4705. proc_nr = Some 183;
  4706. optional = Some "inotify";
  4707. shortdesc = "return list of watched files that had events";
  4708. longdesc = "\
  4709. This function is a helpful wrapper around C<guestfs_inotify_read>
  4710. which just returns a list of pathnames of objects that were
  4711. touched. The returned pathnames are sorted and deduplicated." };
  4712. { defaults with
  4713. name = "inotify_close";
  4714. style = RErr, [], [];
  4715. proc_nr = Some 184;
  4716. optional = Some "inotify";
  4717. shortdesc = "close the inotify handle";
  4718. longdesc = "\
  4719. This closes the inotify handle which was previously
  4720. opened by inotify_init. It removes all watches, throws
  4721. away any pending events, and deallocates all resources." };
  4722. { defaults with
  4723. name = "setcon";
  4724. style = RErr, [String "context"], [];
  4725. proc_nr = Some 185;
  4726. optional = Some "selinux";
  4727. shortdesc = "set SELinux security context";
  4728. longdesc = "\
  4729. This sets the SELinux security context of the daemon
  4730. to the string C<context>.
  4731. See the documentation about SELINUX in L<guestfs(3)>." };
  4732. { defaults with
  4733. name = "getcon";
  4734. style = RString "context", [], [];
  4735. proc_nr = Some 186;
  4736. optional = Some "selinux";
  4737. shortdesc = "get SELinux security context";
  4738. longdesc = "\
  4739. This gets the SELinux security context of the daemon.
  4740. See the documentation about SELINUX in L<guestfs(3)>,
  4741. and C<guestfs_setcon>" };
  4742. { defaults with
  4743. name = "mkfs_b";
  4744. style = RErr, [String "fstype"; Int "blocksize"; Device "device"], [];
  4745. proc_nr = Some 187;
  4746. deprecated_by = Some "mkfs";
  4747. tests = [
  4748. InitEmpty, Always, TestOutput (
  4749. [["part_disk"; "/dev/sda"; "mbr"];
  4750. ["mkfs_b"; "ext2"; "4096"; "/dev/sda1"];
  4751. ["mount_options"; ""; "/dev/sda1"; "/"];
  4752. ["write"; "/new"; "new file contents"];
  4753. ["cat"; "/new"]], "new file contents");
  4754. InitEmpty, Always, TestRun (
  4755. [["part_disk"; "/dev/sda"; "mbr"];
  4756. ["mkfs_b"; "vfat"; "32768"; "/dev/sda1"]]);
  4757. InitEmpty, Always, TestLastFail (
  4758. [["part_disk"; "/dev/sda"; "mbr"];
  4759. ["mkfs_b"; "vfat"; "32769"; "/dev/sda1"]]);
  4760. InitEmpty, Always, TestLastFail (
  4761. [["part_disk"; "/dev/sda"; "mbr"];
  4762. ["mkfs_b"; "vfat"; "33280"; "/dev/sda1"]]);
  4763. InitEmpty, IfAvailable "ntfsprogs", TestRun (
  4764. [["part_disk"; "/dev/sda"; "mbr"];
  4765. ["mkfs_b"; "ntfs"; "32768"; "/dev/sda1"]])
  4766. ];
  4767. shortdesc = "make a filesystem with block size";
  4768. longdesc = "\
  4769. This call is similar to C<guestfs_mkfs>, but it allows you to
  4770. control the block size of the resulting filesystem. Supported
  4771. block sizes depend on the filesystem type, but typically they
  4772. are C<1024>, C<2048> or C<4096> only.
  4773. For VFAT and NTFS the C<blocksize> parameter is treated as
  4774. the requested cluster size." };
  4775. { defaults with
  4776. name = "mke2journal";
  4777. style = RErr, [Int "blocksize"; Device "device"], [];
  4778. proc_nr = Some 188;
  4779. tests = [
  4780. InitEmpty, Always, TestOutput (
  4781. [["part_init"; "/dev/sda"; "mbr"];
  4782. ["part_add"; "/dev/sda"; "p"; "64"; "204799"];
  4783. ["part_add"; "/dev/sda"; "p"; "204800"; "-64"];
  4784. ["mke2journal"; "4096"; "/dev/sda1"];
  4785. ["mke2fs_J"; "ext2"; "4096"; "/dev/sda2"; "/dev/sda1"];
  4786. ["mount_options"; ""; "/dev/sda2"; "/"];
  4787. ["write"; "/new"; "new file contents"];
  4788. ["cat"; "/new"]], "new file contents")
  4789. ];
  4790. shortdesc = "make ext2/3/4 external journal";
  4791. longdesc = "\
  4792. This creates an ext2 external journal on C<device>. It is equivalent
  4793. to the command:
  4794. mke2fs -O journal_dev -b blocksize device" };
  4795. { defaults with
  4796. name = "mke2journal_L";
  4797. style = RErr, [Int "blocksize"; String "label"; Device "device"], [];
  4798. proc_nr = Some 189;
  4799. tests = [
  4800. InitEmpty, Always, TestOutput (
  4801. [["part_init"; "/dev/sda"; "mbr"];
  4802. ["part_add"; "/dev/sda"; "p"; "64"; "204799"];
  4803. ["part_add"; "/dev/sda"; "p"; "204800"; "-64"];
  4804. ["mke2journal_L"; "4096"; "JOURNAL"; "/dev/sda1"];
  4805. ["mke2fs_JL"; "ext2"; "4096"; "/dev/sda2"; "JOURNAL"];
  4806. ["mount_options"; ""; "/dev/sda2"; "/"];
  4807. ["write"; "/new"; "new file contents"];
  4808. ["cat"; "/new"]], "new file contents")
  4809. ];
  4810. shortdesc = "make ext2/3/4 external journal with label";
  4811. longdesc = "\
  4812. This creates an ext2 external journal on C<device> with label C<label>." };
  4813. { defaults with
  4814. name = "mke2journal_U";
  4815. style = RErr, [Int "blocksize"; String "uuid"; Device "device"], [];
  4816. proc_nr = Some 190;
  4817. optional = Some "linuxfsuuid";
  4818. tests =
  4819. (let uuid = uuidgen () in [
  4820. InitEmpty, Always, TestOutput (
  4821. [["part_init"; "/dev/sda"; "mbr"];
  4822. ["part_add"; "/dev/sda"; "p"; "64"; "204799"];
  4823. ["part_add"; "/dev/sda"; "p"; "204800"; "-64"];
  4824. ["mke2journal_U"; "4096"; uuid; "/dev/sda1"];
  4825. ["mke2fs_JU"; "ext2"; "4096"; "/dev/sda2"; uuid];
  4826. ["mount_options"; ""; "/dev/sda2"; "/"];
  4827. ["write"; "/new"; "new file contents"];
  4828. ["cat"; "/new"]], "new file contents")
  4829. ]);
  4830. shortdesc = "make ext2/3/4 external journal with UUID";
  4831. longdesc = "\
  4832. This creates an ext2 external journal on C<device> with UUID C<uuid>." };
  4833. { defaults with
  4834. name = "mke2fs_J";
  4835. style = RErr, [String "fstype"; Int "blocksize"; Device "device"; Device "journal"], [];
  4836. proc_nr = Some 191;
  4837. shortdesc = "make ext2/3/4 filesystem with external journal";
  4838. longdesc = "\
  4839. This creates an ext2/3/4 filesystem on C<device> with
  4840. an external journal on C<journal>. It is equivalent
  4841. to the command:
  4842. mke2fs -t fstype -b blocksize -J device=<journal> <device>
  4843. See also C<guestfs_mke2journal>." };
  4844. { defaults with
  4845. name = "mke2fs_JL";
  4846. style = RErr, [String "fstype"; Int "blocksize"; Device "device"; String "label"], [];
  4847. proc_nr = Some 192;
  4848. shortdesc = "make ext2/3/4 filesystem with external journal";
  4849. longdesc = "\
  4850. This creates an ext2/3/4 filesystem on C<device> with
  4851. an external journal on the journal labeled C<label>.
  4852. See also C<guestfs_mke2journal_L>." };
  4853. { defaults with
  4854. name = "mke2fs_JU";
  4855. style = RErr, [String "fstype"; Int "blocksize"; Device "device"; String "uuid"], [];
  4856. proc_nr = Some 193;
  4857. optional = Some "linuxfsuuid";
  4858. shortdesc = "make ext2/3/4 filesystem with external journal";
  4859. longdesc = "\
  4860. This creates an ext2/3/4 filesystem on C<device> with
  4861. an external journal on the journal with UUID C<uuid>.
  4862. See also C<guestfs_mke2journal_U>." };
  4863. { defaults with
  4864. name = "modprobe";
  4865. style = RErr, [String "modulename"], [];
  4866. proc_nr = Some 194;
  4867. optional = Some "linuxmodules";
  4868. tests = [
  4869. InitNone, Always, TestRun [["modprobe"; "fat"]]
  4870. ];
  4871. shortdesc = "load a kernel module";
  4872. longdesc = "\
  4873. This loads a kernel module in the appliance.
  4874. The kernel module must have been whitelisted when libguestfs
  4875. was built (see C<appliance/kmod.whitelist.in> in the source)." };
  4876. { defaults with
  4877. name = "echo_daemon";
  4878. style = RString "output", [StringList "words"], [];
  4879. proc_nr = Some 195;
  4880. tests = [
  4881. InitNone, Always, TestOutput (
  4882. [["echo_daemon"; "This is a test"]], "This is a test"
  4883. )
  4884. ];
  4885. shortdesc = "echo arguments back to the client";
  4886. longdesc = "\
  4887. This command concatenates the list of C<words> passed with single spaces
  4888. between them and returns the resulting string.
  4889. You can use this command to test the connection through to the daemon.
  4890. See also C<guestfs_ping_daemon>." };
  4891. { defaults with
  4892. name = "find0";
  4893. style = RErr, [Pathname "directory"; FileOut "files"], [];
  4894. proc_nr = Some 196;
  4895. cancellable = true;
  4896. tests = [] (* There is a regression test for this. *);
  4897. shortdesc = "find all files and directories, returning NUL-separated list";
  4898. longdesc = "\
  4899. This command lists out all files and directories, recursively,
  4900. starting at C<directory>, placing the resulting list in the
  4901. external file called C<files>.
  4902. This command works the same way as C<guestfs_find> with the
  4903. following exceptions:
  4904. =over 4
  4905. =item *
  4906. The resulting list is written to an external file.
  4907. =item *
  4908. Items (filenames) in the result are separated
  4909. by C<\\0> characters. See L<find(1)> option I<-print0>.
  4910. =item *
  4911. This command is not limited in the number of names that it
  4912. can return.
  4913. =item *
  4914. The result list is not sorted.
  4915. =back" };
  4916. { defaults with
  4917. name = "case_sensitive_path";
  4918. style = RString "rpath", [Pathname "path"], [];
  4919. proc_nr = Some 197;
  4920. tests = [
  4921. InitISOFS, Always, TestOutput (
  4922. [["case_sensitive_path"; "/DIRECTORY"]], "/directory");
  4923. InitISOFS, Always, TestOutput (
  4924. [["case_sensitive_path"; "/DIRECTORY/"]], "/directory");
  4925. InitISOFS, Always, TestOutput (
  4926. [["case_sensitive_path"; "/Known-1"]], "/known-1");
  4927. InitISOFS, Always, TestLastFail (
  4928. [["case_sensitive_path"; "/Known-1/"]]);
  4929. InitScratchFS, Always, TestOutput (
  4930. [["mkdir"; "/case_sensitive_path"];
  4931. ["mkdir"; "/case_sensitive_path/bbb"];
  4932. ["touch"; "/case_sensitive_path/bbb/c"];
  4933. ["case_sensitive_path"; "/CASE_SENSITIVE_path/bbB/C"]], "/case_sensitive_path/bbb/c");
  4934. InitScratchFS, Always, TestOutput (
  4935. [["mkdir"; "/case_sensitive_path2"];
  4936. ["mkdir"; "/case_sensitive_path2/bbb"];
  4937. ["touch"; "/case_sensitive_path2/bbb/c"];
  4938. ["case_sensitive_path"; "/case_sensitive_PATH2////bbB/C"]], "/case_sensitive_path2/bbb/c");
  4939. InitScratchFS, Always, TestLastFail (
  4940. [["mkdir"; "/case_sensitive_path3"];
  4941. ["mkdir"; "/case_sensitive_path3/bbb"];
  4942. ["touch"; "/case_sensitive_path3/bbb/c"];
  4943. ["case_sensitive_path"; "/case_SENSITIVE_path3/bbb/../bbb/C"]]);
  4944. InitScratchFS, Always, TestOutput (
  4945. [["mkdir"; "/case_sensitive_path4"];
  4946. ["case_sensitive_path"; "/case_SENSITIVE_path4/new_file"]], "/case_sensitive_path4/new_file")
  4947. ];
  4948. shortdesc = "return true path on case-insensitive filesystem";
  4949. longdesc = "\
  4950. This can be used to resolve case insensitive paths on
  4951. a filesystem which is case sensitive. The use case is
  4952. to resolve paths which you have read from Windows configuration
  4953. files or the Windows Registry, to the true path.
  4954. The command handles a peculiarity of the Linux ntfs-3g
  4955. filesystem driver (and probably others), which is that although
  4956. the underlying filesystem is case-insensitive, the driver
  4957. exports the filesystem to Linux as case-sensitive.
  4958. One consequence of this is that special directories such
  4959. as C<c:\\windows> may appear as C</WINDOWS> or C</windows>
  4960. (or other things) depending on the precise details of how
  4961. they were created. In Windows itself this would not be
  4962. a problem.
  4963. Bug or feature? You decide:
  4964. L<http://www.tuxera.com/community/ntfs-3g-faq/#posixfilenames1>
  4965. This function resolves the true case of each element in the
  4966. path and returns the case-sensitive path.
  4967. Thus C<guestfs_case_sensitive_path> (\"/Windows/System32\")
  4968. might return C<\"/WINDOWS/system32\"> (the exact return value
  4969. would depend on details of how the directories were originally
  4970. created under Windows).
  4971. I<Note>:
  4972. This function does not handle drive names, backslashes etc.
  4973. See also C<guestfs_realpath>." };
  4974. { defaults with
  4975. name = "vfs_type";
  4976. style = RString "fstype", [Device "device"], [];
  4977. proc_nr = Some 198;
  4978. tests = [
  4979. InitScratchFS, Always, TestOutput (
  4980. [["vfs_type"; "/dev/sdb1"]], "ext2")
  4981. ];
  4982. shortdesc = "get the Linux VFS type corresponding to a mounted device";
  4983. longdesc = "\
  4984. This command gets the filesystem type corresponding to
  4985. the filesystem on C<device>.
  4986. For most filesystems, the result is the name of the Linux
  4987. VFS module which would be used to mount this filesystem
  4988. if you mounted it without specifying the filesystem type.
  4989. For example a string such as C<ext3> or C<ntfs>." };
  4990. { defaults with
  4991. name = "truncate";
  4992. style = RErr, [Pathname "path"], [];
  4993. proc_nr = Some 199;
  4994. tests = [
  4995. InitScratchFS, Always, TestOutputStruct (
  4996. [["write"; "/truncate"; "some stuff so size is not zero"];
  4997. ["truncate"; "/truncate"];
  4998. ["stat"; "/truncate"]], [CompareWithInt ("size", 0)])
  4999. ];
  5000. shortdesc = "truncate a file to zero size";
  5001. longdesc = "\
  5002. This command truncates C<path> to a zero-length file. The
  5003. file must exist already." };
  5004. { defaults with
  5005. name = "truncate_size";
  5006. style = RErr, [Pathname "path"; Int64 "size"], [];
  5007. proc_nr = Some 200;
  5008. tests = [
  5009. InitScratchFS, Always, TestOutputStruct (
  5010. [["touch"; "/truncate_size"];
  5011. ["truncate_size"; "/truncate_size"; "1000"];
  5012. ["stat"; "/truncate_size"]], [CompareWithInt ("size", 1000)])
  5013. ];
  5014. shortdesc = "truncate a file to a particular size";
  5015. longdesc = "\
  5016. This command truncates C<path> to size C<size> bytes. The file
  5017. must exist already.
  5018. If the current file size is less than C<size> then
  5019. the file is extended to the required size with zero bytes.
  5020. This creates a sparse file (ie. disk blocks are not allocated
  5021. for the file until you write to it). To create a non-sparse
  5022. file of zeroes, use C<guestfs_fallocate64> instead." };
  5023. { defaults with
  5024. name = "utimens";
  5025. style = RErr, [Pathname "path"; Int64 "atsecs"; Int64 "atnsecs"; Int64 "mtsecs"; Int64 "mtnsecs"], [];
  5026. proc_nr = Some 201;
  5027. (* Test directories, named pipes etc (RHBZ#761451, RHBZ#761460) *)
  5028. tests = [
  5029. InitScratchFS, Always, TestOutputStruct (
  5030. [["touch"; "/utimens-file"];
  5031. ["utimens"; "/utimens-file"; "12345"; "67890"; "9876"; "5432"];
  5032. ["stat"; "/utimens-file"]], [CompareWithInt ("mtime", 9876)]);
  5033. InitScratchFS, Always, TestOutputStruct (
  5034. [["mkdir"; "/utimens-dir"];
  5035. ["utimens"; "/utimens-dir"; "12345"; "67890"; "9876"; "5432"];
  5036. ["stat"; "/utimens-dir"]], [CompareWithInt ("mtime", 9876)]);
  5037. InitScratchFS, Always, TestOutputStruct (
  5038. [["mkfifo"; "0o644"; "/utimens-fifo"];
  5039. ["utimens"; "/utimens-fifo"; "12345"; "67890"; "9876"; "5432"];
  5040. ["stat"; "/utimens-fifo"]], [CompareWithInt ("mtime", 9876)]);
  5041. InitScratchFS, Always, TestOutputStruct (
  5042. [["ln_sf"; "/utimens-file"; "/utimens-link"];
  5043. ["utimens"; "/utimens-link"; "12345"; "67890"; "9876"; "5432"];
  5044. ["stat"; "/utimens-link"]], [CompareWithInt ("mtime", 9876)]);
  5045. InitScratchFS, Always, TestOutputStruct (
  5046. [["mknod_b"; "0o644"; "8"; "0"; "/utimens-block"];
  5047. ["utimens"; "/utimens-block"; "12345"; "67890"; "9876"; "5432"];
  5048. ["stat"; "/utimens-block"]], [CompareWithInt ("mtime", 9876)]);
  5049. InitScratchFS, Always, TestOutputStruct (
  5050. [["mknod_c"; "0o644"; "1"; "3"; "/utimens-char"];
  5051. ["utimens"; "/utimens-char"; "12345"; "67890"; "9876"; "5432"];
  5052. ["stat"; "/utimens-char"]], [CompareWithInt ("mtime", 9876)])
  5053. ];
  5054. shortdesc = "set timestamp of a file with nanosecond precision";
  5055. longdesc = "\
  5056. This command sets the timestamps of a file with nanosecond
  5057. precision.
  5058. C<atsecs, atnsecs> are the last access time (atime) in secs and
  5059. nanoseconds from the epoch.
  5060. C<mtsecs, mtnsecs> are the last modification time (mtime) in
  5061. secs and nanoseconds from the epoch.
  5062. If the C<*nsecs> field contains the special value C<-1> then
  5063. the corresponding timestamp is set to the current time. (The
  5064. C<*secs> field is ignored in this case).
  5065. If the C<*nsecs> field contains the special value C<-2> then
  5066. the corresponding timestamp is left unchanged. (The
  5067. C<*secs> field is ignored in this case)." };
  5068. { defaults with
  5069. name = "mkdir_mode";
  5070. style = RErr, [Pathname "path"; Int "mode"], [];
  5071. proc_nr = Some 202;
  5072. tests = [
  5073. InitScratchFS, Always, TestOutputStruct (
  5074. [["mkdir_mode"; "/mkdir_mode"; "0o111"];
  5075. ["stat"; "/mkdir_mode"]], [CompareWithInt ("mode", 0o40111)])
  5076. ];
  5077. shortdesc = "create a directory with a particular mode";
  5078. longdesc = "\
  5079. This command creates a directory, setting the initial permissions
  5080. of the directory to C<mode>.
  5081. For common Linux filesystems, the actual mode which is set will
  5082. be C<mode & ~umask & 01777>. Non-native-Linux filesystems may
  5083. interpret the mode in other ways.
  5084. See also C<guestfs_mkdir>, C<guestfs_umask>" };
  5085. { defaults with
  5086. name = "lchown";
  5087. style = RErr, [Int "owner"; Int "group"; Pathname "path"], [];
  5088. proc_nr = Some 203;
  5089. shortdesc = "change file owner and group";
  5090. longdesc = "\
  5091. Change the file owner to C<owner> and group to C<group>.
  5092. This is like C<guestfs_chown> but if C<path> is a symlink then
  5093. the link itself is changed, not the target.
  5094. Only numeric uid and gid are supported. If you want to use
  5095. names, you will need to locate and parse the password file
  5096. yourself (Augeas support makes this relatively easy)." };
  5097. { defaults with
  5098. name = "lstatlist";
  5099. style = RStructList ("statbufs", "stat"), [Pathname "path"; StringList "names"], [];
  5100. proc_nr = Some 204;
  5101. shortdesc = "lstat on multiple files";
  5102. longdesc = "\
  5103. This call allows you to perform the C<guestfs_lstat> operation
  5104. on multiple files, where all files are in the directory C<path>.
  5105. C<names> is the list of files from this directory.
  5106. On return you get a list of stat structs, with a one-to-one
  5107. correspondence to the C<names> list. If any name did not exist
  5108. or could not be lstat'd, then the C<ino> field of that structure
  5109. is set to C<-1>.
  5110. This call is intended for programs that want to efficiently
  5111. list a directory contents without making many round-trips.
  5112. See also C<guestfs_lxattrlist> for a similarly efficient call
  5113. for getting extended attributes. Very long directory listings
  5114. might cause the protocol message size to be exceeded, causing
  5115. this call to fail. The caller must split up such requests
  5116. into smaller groups of names." };
  5117. { defaults with
  5118. name = "lxattrlist";
  5119. style = RStructList ("xattrs", "xattr"), [Pathname "path"; StringList "names"], [];
  5120. proc_nr = Some 205;
  5121. optional = Some "linuxxattrs";
  5122. shortdesc = "lgetxattr on multiple files";
  5123. longdesc = "\
  5124. This call allows you to get the extended attributes
  5125. of multiple files, where all files are in the directory C<path>.
  5126. C<names> is the list of files from this directory.
  5127. On return you get a flat list of xattr structs which must be
  5128. interpreted sequentially. The first xattr struct always has a zero-length
  5129. C<attrname>. C<attrval> in this struct is zero-length
  5130. to indicate there was an error doing C<lgetxattr> for this
  5131. file, I<or> is a C string which is a decimal number
  5132. (the number of following attributes for this file, which could
  5133. be C<\"0\">). Then after the first xattr struct are the
  5134. zero or more attributes for the first named file.
  5135. This repeats for the second and subsequent files.
  5136. This call is intended for programs that want to efficiently
  5137. list a directory contents without making many round-trips.
  5138. See also C<guestfs_lstatlist> for a similarly efficient call
  5139. for getting standard stats. Very long directory listings
  5140. might cause the protocol message size to be exceeded, causing
  5141. this call to fail. The caller must split up such requests
  5142. into smaller groups of names." };
  5143. { defaults with
  5144. name = "readlinklist";
  5145. style = RStringList "links", [Pathname "path"; StringList "names"], [];
  5146. proc_nr = Some 206;
  5147. shortdesc = "readlink on multiple files";
  5148. longdesc = "\
  5149. This call allows you to do a C<readlink> operation
  5150. on multiple files, where all files are in the directory C<path>.
  5151. C<names> is the list of files from this directory.
  5152. On return you get a list of strings, with a one-to-one
  5153. correspondence to the C<names> list. Each string is the
  5154. value of the symbolic link.
  5155. If the C<readlink(2)> operation fails on any name, then
  5156. the corresponding result string is the empty string C<\"\">.
  5157. However the whole operation is completed even if there
  5158. were C<readlink(2)> errors, and so you can call this
  5159. function with names where you don't know if they are
  5160. symbolic links already (albeit slightly less efficient).
  5161. This call is intended for programs that want to efficiently
  5162. list a directory contents without making many round-trips.
  5163. Very long directory listings might cause the protocol
  5164. message size to be exceeded, causing
  5165. this call to fail. The caller must split up such requests
  5166. into smaller groups of names." };
  5167. { defaults with
  5168. name = "pread";
  5169. style = RBufferOut "content", [Pathname "path"; Int "count"; Int64 "offset"], [];
  5170. proc_nr = Some 207;
  5171. protocol_limit_warning = true;
  5172. tests = [
  5173. InitISOFS, Always, TestOutputBuffer (
  5174. [["pread"; "/known-4"; "1"; "3"]], "\n");
  5175. InitISOFS, Always, TestOutputBuffer (
  5176. [["pread"; "/empty"; "0"; "100"]], "")
  5177. ];
  5178. shortdesc = "read part of a file";
  5179. longdesc = "\
  5180. This command lets you read part of a file. It reads C<count>
  5181. bytes of the file, starting at C<offset>, from file C<path>.
  5182. This may read fewer bytes than requested. For further details
  5183. see the L<pread(2)> system call.
  5184. See also C<guestfs_pwrite>, C<guestfs_pread_device>." };
  5185. { defaults with
  5186. name = "part_init";
  5187. style = RErr, [Device "device"; String "parttype"], [];
  5188. proc_nr = Some 208;
  5189. tests = [
  5190. InitEmpty, Always, TestRun (
  5191. [["part_init"; "/dev/sda"; "gpt"]])
  5192. ];
  5193. shortdesc = "create an empty partition table";
  5194. longdesc = "\
  5195. This creates an empty partition table on C<device> of one of the
  5196. partition types listed below. Usually C<parttype> should be
  5197. either C<msdos> or C<gpt> (for large disks).
  5198. Initially there are no partitions. Following this, you should
  5199. call C<guestfs_part_add> for each partition required.
  5200. Possible values for C<parttype> are:
  5201. =over 4
  5202. =item B<efi>
  5203. =item B<gpt>
  5204. Intel EFI / GPT partition table.
  5205. This is recommended for >= 2 TB partitions that will be accessed
  5206. from Linux and Intel-based Mac OS X. It also has limited backwards
  5207. compatibility with the C<mbr> format.
  5208. =item B<mbr>
  5209. =item B<msdos>
  5210. The standard PC \"Master Boot Record\" (MBR) format used
  5211. by MS-DOS and Windows. This partition type will B<only> work
  5212. for device sizes up to 2 TB. For large disks we recommend
  5213. using C<gpt>.
  5214. =back
  5215. Other partition table types that may work but are not
  5216. supported include:
  5217. =over 4
  5218. =item B<aix>
  5219. AIX disk labels.
  5220. =item B<amiga>
  5221. =item B<rdb>
  5222. Amiga \"Rigid Disk Block\" format.
  5223. =item B<bsd>
  5224. BSD disk labels.
  5225. =item B<dasd>
  5226. DASD, used on IBM mainframes.
  5227. =item B<dvh>
  5228. MIPS/SGI volumes.
  5229. =item B<mac>
  5230. Old Mac partition format. Modern Macs use C<gpt>.
  5231. =item B<pc98>
  5232. NEC PC-98 format, common in Japan apparently.
  5233. =item B<sun>
  5234. Sun disk labels.
  5235. =back" };
  5236. { defaults with
  5237. name = "part_add";
  5238. style = RErr, [Device "device"; String "prlogex"; Int64 "startsect"; Int64 "endsect"], [];
  5239. proc_nr = Some 209;
  5240. tests = [
  5241. InitEmpty, Always, TestRun (
  5242. [["part_init"; "/dev/sda"; "mbr"];
  5243. ["part_add"; "/dev/sda"; "primary"; "1"; "-1"]]);
  5244. InitEmpty, Always, TestRun (
  5245. [["part_init"; "/dev/sda"; "gpt"];
  5246. ["part_add"; "/dev/sda"; "primary"; "34"; "127"];
  5247. ["part_add"; "/dev/sda"; "primary"; "128"; "-34"]]);
  5248. InitEmpty, Always, TestRun (
  5249. [["part_init"; "/dev/sda"; "mbr"];
  5250. ["part_add"; "/dev/sda"; "primary"; "32"; "127"];
  5251. ["part_add"; "/dev/sda"; "primary"; "128"; "255"];
  5252. ["part_add"; "/dev/sda"; "primary"; "256"; "511"];
  5253. ["part_add"; "/dev/sda"; "primary"; "512"; "-1"]])
  5254. ];
  5255. shortdesc = "add a partition to the device";
  5256. longdesc = "\
  5257. This command adds a partition to C<device>. If there is no partition
  5258. table on the device, call C<guestfs_part_init> first.
  5259. The C<prlogex> parameter is the type of partition. Normally you
  5260. should pass C<p> or C<primary> here, but MBR partition tables also
  5261. support C<l> (or C<logical>) and C<e> (or C<extended>) partition
  5262. types.
  5263. C<startsect> and C<endsect> are the start and end of the partition
  5264. in I<sectors>. C<endsect> may be negative, which means it counts
  5265. backwards from the end of the disk (C<-1> is the last sector).
  5266. Creating a partition which covers the whole disk is not so easy.
  5267. Use C<guestfs_part_disk> to do that." };
  5268. { defaults with
  5269. name = "part_disk";
  5270. style = RErr, [Device "device"; String "parttype"], [];
  5271. proc_nr = Some 210;
  5272. tests = [
  5273. InitEmpty, Always, TestRun (
  5274. [["part_disk"; "/dev/sda"; "mbr"]]);
  5275. InitEmpty, Always, TestRun (
  5276. [["part_disk"; "/dev/sda"; "gpt"]])
  5277. ];
  5278. shortdesc = "partition whole disk with a single primary partition";
  5279. longdesc = "\
  5280. This command is simply a combination of C<guestfs_part_init>
  5281. followed by C<guestfs_part_add> to create a single primary partition
  5282. covering the whole disk.
  5283. C<parttype> is the partition table type, usually C<mbr> or C<gpt>,
  5284. but other possible values are described in C<guestfs_part_init>." };
  5285. { defaults with
  5286. name = "part_set_bootable";
  5287. style = RErr, [Device "device"; Int "partnum"; Bool "bootable"], [];
  5288. proc_nr = Some 211;
  5289. tests = [
  5290. InitEmpty, Always, TestRun (
  5291. [["part_disk"; "/dev/sda"; "mbr"];
  5292. ["part_set_bootable"; "/dev/sda"; "1"; "true"]])
  5293. ];
  5294. shortdesc = "make a partition bootable";
  5295. longdesc = "\
  5296. This sets the bootable flag on partition numbered C<partnum> on
  5297. device C<device>. Note that partitions are numbered from 1.
  5298. The bootable flag is used by some operating systems (notably
  5299. Windows) to determine which partition to boot from. It is by
  5300. no means universally recognized." };
  5301. { defaults with
  5302. name = "part_set_name";
  5303. style = RErr, [Device "device"; Int "partnum"; String "name"], [];
  5304. proc_nr = Some 212;
  5305. tests = [
  5306. InitEmpty, Always, TestRun (
  5307. [["part_disk"; "/dev/sda"; "gpt"];
  5308. ["part_set_name"; "/dev/sda"; "1"; "thepartname"]])
  5309. ];
  5310. shortdesc = "set partition name";
  5311. longdesc = "\
  5312. This sets the partition name on partition numbered C<partnum> on
  5313. device C<device>. Note that partitions are numbered from 1.
  5314. The partition name can only be set on certain types of partition
  5315. table. This works on C<gpt> but not on C<mbr> partitions." };
  5316. { defaults with
  5317. name = "part_list";
  5318. style = RStructList ("partitions", "partition"), [Device "device"], [];
  5319. proc_nr = Some 213;
  5320. tests = [] (* XXX Add a regression test for this. *);
  5321. shortdesc = "list partitions on a device";
  5322. longdesc = "\
  5323. This command parses the partition table on C<device> and
  5324. returns the list of partitions found.
  5325. The fields in the returned structure are:
  5326. =over 4
  5327. =item B<part_num>
  5328. Partition number, counting from 1.
  5329. =item B<part_start>
  5330. Start of the partition I<in bytes>. To get sectors you have to
  5331. divide by the device's sector size, see C<guestfs_blockdev_getss>.
  5332. =item B<part_end>
  5333. End of the partition in bytes.
  5334. =item B<part_size>
  5335. Size of the partition in bytes.
  5336. =back" };
  5337. { defaults with
  5338. name = "part_get_parttype";
  5339. style = RString "parttype", [Device "device"], [];
  5340. proc_nr = Some 214;
  5341. tests = [
  5342. InitEmpty, Always, TestOutput (
  5343. [["part_disk"; "/dev/sda"; "gpt"];
  5344. ["part_get_parttype"; "/dev/sda"]], "gpt")
  5345. ];
  5346. shortdesc = "get the partition table type";
  5347. longdesc = "\
  5348. This command examines the partition table on C<device> and
  5349. returns the partition table type (format) being used.
  5350. Common return values include: C<msdos> (a DOS/Windows style MBR
  5351. partition table), C<gpt> (a GPT/EFI-style partition table). Other
  5352. values are possible, although unusual. See C<guestfs_part_init>
  5353. for a full list." };
  5354. { defaults with
  5355. name = "fill";
  5356. style = RErr, [Int "c"; Int "len"; Pathname "path"], [];
  5357. proc_nr = Some 215;
  5358. progress = true;
  5359. tests = [
  5360. InitScratchFS, Always, TestOutputBuffer (
  5361. [["fill"; "0x63"; "10"; "/fill"];
  5362. ["read_file"; "/fill"]], "cccccccccc")
  5363. ];
  5364. shortdesc = "fill a file with octets";
  5365. longdesc = "\
  5366. This command creates a new file called C<path>. The initial
  5367. content of the file is C<len> octets of C<c>, where C<c>
  5368. must be a number in the range C<[0..255]>.
  5369. To fill a file with zero bytes (sparsely), it is
  5370. much more efficient to use C<guestfs_truncate_size>.
  5371. To create a file with a pattern of repeating bytes
  5372. use C<guestfs_fill_pattern>." };
  5373. { defaults with
  5374. name = "available";
  5375. style = RErr, [StringList "groups"], [];
  5376. proc_nr = Some 216;
  5377. tests = [
  5378. InitNone, Always, TestRun [["available"; ""]]
  5379. ];
  5380. shortdesc = "test availability of some parts of the API";
  5381. longdesc = "\
  5382. This command is used to check the availability of some
  5383. groups of functionality in the appliance, which not all builds of
  5384. the libguestfs appliance will be able to provide.
  5385. The libguestfs groups, and the functions that those
  5386. groups correspond to, are listed in L<guestfs(3)/AVAILABILITY>.
  5387. You can also fetch this list at runtime by calling
  5388. C<guestfs_available_all_groups>.
  5389. The argument C<groups> is a list of group names, eg:
  5390. C<[\"inotify\", \"augeas\"]> would check for the availability of
  5391. the Linux inotify functions and Augeas (configuration file
  5392. editing) functions.
  5393. The command returns no error if I<all> requested groups are available.
  5394. It fails with an error if one or more of the requested
  5395. groups is unavailable in the appliance.
  5396. If an unknown group name is included in the
  5397. list of groups then an error is always returned.
  5398. I<Notes:>
  5399. =over 4
  5400. =item *
  5401. You must call C<guestfs_launch> before calling this function.
  5402. The reason is because we don't know what groups are
  5403. supported by the appliance/daemon until it is running and can
  5404. be queried.
  5405. =item *
  5406. If a group of functions is available, this does not necessarily
  5407. mean that they will work. You still have to check for errors
  5408. when calling individual API functions even if they are
  5409. available.
  5410. =item *
  5411. It is usually the job of distro packagers to build
  5412. complete functionality into the libguestfs appliance.
  5413. Upstream libguestfs, if built from source with all
  5414. requirements satisfied, will support everything.
  5415. =item *
  5416. This call was added in version C<1.0.80>. In previous
  5417. versions of libguestfs all you could do would be to speculatively
  5418. execute a command to find out if the daemon implemented it.
  5419. See also C<guestfs_version>.
  5420. =back
  5421. See also C<guestfs_filesystem_available>." };
  5422. { defaults with
  5423. name = "dd";
  5424. style = RErr, [Dev_or_Path "src"; Dev_or_Path "dest"], [];
  5425. proc_nr = Some 217;
  5426. deprecated_by = Some "copy_device_to_device";
  5427. tests = [
  5428. InitScratchFS, Always, TestOutputBuffer (
  5429. [["mkdir"; "/dd"];
  5430. ["write"; "/dd/src"; "hello, world"];
  5431. ["dd"; "/dd/src"; "/dd/dest"];
  5432. ["read_file"; "/dd/dest"]], "hello, world")
  5433. ];
  5434. shortdesc = "copy from source to destination using dd";
  5435. longdesc = "\
  5436. This command copies from one source device or file C<src>
  5437. to another destination device or file C<dest>. Normally you
  5438. would use this to copy to or from a device or partition, for
  5439. example to duplicate a filesystem.
  5440. If the destination is a device, it must be as large or larger
  5441. than the source file or device, otherwise the copy will fail.
  5442. This command cannot do partial copies
  5443. (see C<guestfs_copy_device_to_device>)." };
  5444. { defaults with
  5445. name = "filesize";
  5446. style = RInt64 "size", [Pathname "file"], [];
  5447. proc_nr = Some 218;
  5448. tests = [
  5449. InitScratchFS, Always, TestOutputInt (
  5450. [["write"; "/filesize"; "hello, world"];
  5451. ["filesize"; "/filesize"]], 12)
  5452. ];
  5453. shortdesc = "return the size of the file in bytes";
  5454. longdesc = "\
  5455. This command returns the size of C<file> in bytes.
  5456. To get other stats about a file, use C<guestfs_stat>, C<guestfs_lstat>,
  5457. C<guestfs_is_dir>, C<guestfs_is_file> etc.
  5458. To get the size of block devices, use C<guestfs_blockdev_getsize64>." };
  5459. { defaults with
  5460. name = "lvrename";
  5461. style = RErr, [String "logvol"; String "newlogvol"], [];
  5462. proc_nr = Some 219;
  5463. tests = [
  5464. InitBasicFSonLVM, Always, TestOutputList (
  5465. [["lvrename"; "/dev/VG/LV"; "/dev/VG/LV2"];
  5466. ["lvs"]], ["/dev/VG/LV2"])
  5467. ];
  5468. shortdesc = "rename an LVM logical volume";
  5469. longdesc = "\
  5470. Rename a logical volume C<logvol> with the new name C<newlogvol>." };
  5471. { defaults with
  5472. name = "vgrename";
  5473. style = RErr, [String "volgroup"; String "newvolgroup"], [];
  5474. proc_nr = Some 220;
  5475. tests = [
  5476. InitBasicFSonLVM, Always, TestOutputList (
  5477. [["umount"; "/"];
  5478. ["vg_activate"; "false"; "VG"];
  5479. ["vgrename"; "VG"; "VG2"];
  5480. ["vg_activate"; "true"; "VG2"];
  5481. ["mount_options"; ""; "/dev/VG2/LV"; "/"];
  5482. ["vgs"]], ["VG2"])
  5483. ];
  5484. shortdesc = "rename an LVM volume group";
  5485. longdesc = "\
  5486. Rename a volume group C<volgroup> with the new name C<newvolgroup>." };
  5487. { defaults with
  5488. name = "initrd_cat";
  5489. style = RBufferOut "content", [Pathname "initrdpath"; String "filename"], [];
  5490. proc_nr = Some 221;
  5491. protocol_limit_warning = true;
  5492. tests = [
  5493. InitISOFS, Always, TestOutputBuffer (
  5494. [["initrd_cat"; "/initrd"; "known-4"]], "abc\ndef\nghi")
  5495. ];
  5496. shortdesc = "list the contents of a single file in an initrd";
  5497. longdesc = "\
  5498. This command unpacks the file C<filename> from the initrd file
  5499. called C<initrdpath>. The filename must be given I<without> the
  5500. initial C</> character.
  5501. For example, in guestfish you could use the following command
  5502. to examine the boot script (usually called C</init>)
  5503. contained in a Linux initrd or initramfs image:
  5504. initrd-cat /boot/initrd-<version>.img init
  5505. See also C<guestfs_initrd_list>." };
  5506. { defaults with
  5507. name = "pvuuid";
  5508. style = RString "uuid", [Device "device"], [];
  5509. proc_nr = Some 222;
  5510. shortdesc = "get the UUID of a physical volume";
  5511. longdesc = "\
  5512. This command returns the UUID of the LVM PV C<device>." };
  5513. { defaults with
  5514. name = "vguuid";
  5515. style = RString "uuid", [String "vgname"], [];
  5516. proc_nr = Some 223;
  5517. shortdesc = "get the UUID of a volume group";
  5518. longdesc = "\
  5519. This command returns the UUID of the LVM VG named C<vgname>." };
  5520. { defaults with
  5521. name = "lvuuid";
  5522. style = RString "uuid", [Device "device"], [];
  5523. proc_nr = Some 224;
  5524. shortdesc = "get the UUID of a logical volume";
  5525. longdesc = "\
  5526. This command returns the UUID of the LVM LV C<device>." };
  5527. { defaults with
  5528. name = "vgpvuuids";
  5529. style = RStringList "uuids", [String "vgname"], [];
  5530. proc_nr = Some 225;
  5531. shortdesc = "get the PV UUIDs containing the volume group";
  5532. longdesc = "\
  5533. Given a VG called C<vgname>, this returns the UUIDs of all
  5534. the physical volumes that this volume group resides on.
  5535. You can use this along with C<guestfs_pvs> and C<guestfs_pvuuid>
  5536. calls to associate physical volumes and volume groups.
  5537. See also C<guestfs_vglvuuids>." };
  5538. { defaults with
  5539. name = "vglvuuids";
  5540. style = RStringList "uuids", [String "vgname"], [];
  5541. proc_nr = Some 226;
  5542. shortdesc = "get the LV UUIDs of all LVs in the volume group";
  5543. longdesc = "\
  5544. Given a VG called C<vgname>, this returns the UUIDs of all
  5545. the logical volumes created in this volume group.
  5546. You can use this along with C<guestfs_lvs> and C<guestfs_lvuuid>
  5547. calls to associate logical volumes and volume groups.
  5548. See also C<guestfs_vgpvuuids>." };
  5549. { defaults with
  5550. name = "copy_size";
  5551. style = RErr, [Dev_or_Path "src"; Dev_or_Path "dest"; Int64 "size"], [];
  5552. proc_nr = Some 227;
  5553. progress = true; deprecated_by = Some "copy_device_to_device";
  5554. tests = [
  5555. InitScratchFS, Always, TestOutputBuffer (
  5556. [["mkdir"; "/copy_size"];
  5557. ["write"; "/copy_size/src"; "hello, world"];
  5558. ["copy_size"; "/copy_size/src"; "/copy_size/dest"; "5"];
  5559. ["read_file"; "/copy_size/dest"]], "hello")
  5560. ];
  5561. shortdesc = "copy size bytes from source to destination using dd";
  5562. longdesc = "\
  5563. This command copies exactly C<size> bytes from one source device
  5564. or file C<src> to another destination device or file C<dest>.
  5565. Note this will fail if the source is too short or if the destination
  5566. is not large enough." };
  5567. { defaults with
  5568. name = "zero_device";
  5569. style = RErr, [Device "device"], [];
  5570. proc_nr = Some 228;
  5571. progress = true;
  5572. tests = [
  5573. InitBasicFSonLVM, Always, TestRun (
  5574. [["zero_device"; "/dev/VG/LV"]])
  5575. ];
  5576. shortdesc = "write zeroes to an entire device";
  5577. longdesc = "\
  5578. This command writes zeroes over the entire C<device>. Compare
  5579. with C<guestfs_zero> which just zeroes the first few blocks of
  5580. a device.
  5581. If blocks are already zero, then this command avoids writing
  5582. zeroes. This prevents the underlying device from becoming non-sparse
  5583. or growing unnecessarily." };
  5584. { defaults with
  5585. name = "txz_in";
  5586. style = RErr, [FileIn "tarball"; Pathname "directory"], [];
  5587. proc_nr = Some 229;
  5588. optional = Some "xz"; cancellable = true;
  5589. tests = [
  5590. InitScratchFS, Always, TestOutput (
  5591. [["mkdir"; "/txz_in"];
  5592. ["txz_in"; "../data/helloworld.tar.xz"; "/txz_in"];
  5593. ["cat"; "/txz_in/hello"]], "hello\n")
  5594. ];
  5595. shortdesc = "unpack compressed tarball to directory";
  5596. longdesc = "\
  5597. This command uploads and unpacks local file C<tarball> (an
  5598. I<xz compressed> tar file) into C<directory>." };
  5599. { defaults with
  5600. name = "txz_out";
  5601. style = RErr, [Pathname "directory"; FileOut "tarball"], [];
  5602. proc_nr = Some 230;
  5603. optional = Some "xz"; cancellable = true;
  5604. shortdesc = "pack directory into compressed tarball";
  5605. longdesc = "\
  5606. This command packs the contents of C<directory> and downloads
  5607. it to local file C<tarball> (as an xz compressed tar archive)." };
  5608. { defaults with
  5609. name = "vgscan";
  5610. style = RErr, [], [];
  5611. proc_nr = Some 232;
  5612. tests = [
  5613. InitEmpty, Always, TestRun (
  5614. [["vgscan"]])
  5615. ];
  5616. shortdesc = "rescan for LVM physical volumes, volume groups and logical volumes";
  5617. longdesc = "\
  5618. This rescans all block devices and rebuilds the list of LVM
  5619. physical volumes, volume groups and logical volumes." };
  5620. { defaults with
  5621. name = "part_del";
  5622. style = RErr, [Device "device"; Int "partnum"], [];
  5623. proc_nr = Some 233;
  5624. tests = [
  5625. InitEmpty, Always, TestRun (
  5626. [["part_init"; "/dev/sda"; "mbr"];
  5627. ["part_add"; "/dev/sda"; "primary"; "1"; "-1"];
  5628. ["part_del"; "/dev/sda"; "1"]])
  5629. ];
  5630. shortdesc = "delete a partition";
  5631. longdesc = "\
  5632. This command deletes the partition numbered C<partnum> on C<device>.
  5633. Note that in the case of MBR partitioning, deleting an
  5634. extended partition also deletes any logical partitions
  5635. it contains." };
  5636. { defaults with
  5637. name = "part_get_bootable";
  5638. style = RBool "bootable", [Device "device"; Int "partnum"], [];
  5639. proc_nr = Some 234;
  5640. tests = [
  5641. InitEmpty, Always, TestOutputTrue (
  5642. [["part_init"; "/dev/sda"; "mbr"];
  5643. ["part_add"; "/dev/sda"; "primary"; "1"; "-1"];
  5644. ["part_set_bootable"; "/dev/sda"; "1"; "true"];
  5645. ["part_get_bootable"; "/dev/sda"; "1"]])
  5646. ];
  5647. shortdesc = "return true if a partition is bootable";
  5648. longdesc = "\
  5649. This command returns true if the partition C<partnum> on
  5650. C<device> has the bootable flag set.
  5651. See also C<guestfs_part_set_bootable>." };
  5652. { defaults with
  5653. name = "part_get_mbr_id";
  5654. style = RInt "idbyte", [Device "device"; Int "partnum"], [];
  5655. proc_nr = Some 235;
  5656. fish_output = Some FishOutputHexadecimal;
  5657. tests = [
  5658. InitEmpty, Always, TestOutputInt (
  5659. [["part_init"; "/dev/sda"; "mbr"];
  5660. ["part_add"; "/dev/sda"; "primary"; "1"; "-1"];
  5661. ["part_set_mbr_id"; "/dev/sda"; "1"; "0x7f"];
  5662. ["part_get_mbr_id"; "/dev/sda"; "1"]], 0x7f)
  5663. ];
  5664. shortdesc = "get the MBR type byte (ID byte) from a partition";
  5665. longdesc = "\
  5666. Returns the MBR type byte (also known as the ID byte) from
  5667. the numbered partition C<partnum>.
  5668. Note that only MBR (old DOS-style) partitions have type bytes.
  5669. You will get undefined results for other partition table
  5670. types (see C<guestfs_part_get_parttype>)." };
  5671. { defaults with
  5672. name = "part_set_mbr_id";
  5673. style = RErr, [Device "device"; Int "partnum"; Int "idbyte"], [];
  5674. proc_nr = Some 236;
  5675. shortdesc = "set the MBR type byte (ID byte) of a partition";
  5676. longdesc = "\
  5677. Sets the MBR type byte (also known as the ID byte) of
  5678. the numbered partition C<partnum> to C<idbyte>. Note
  5679. that the type bytes quoted in most documentation are
  5680. in fact hexadecimal numbers, but usually documented
  5681. without any leading \"0x\" which might be confusing.
  5682. Note that only MBR (old DOS-style) partitions have type bytes.
  5683. You will get undefined results for other partition table
  5684. types (see C<guestfs_part_get_parttype>)." };
  5685. { defaults with
  5686. name = "checksum_device";
  5687. style = RString "checksum", [String "csumtype"; Device "device"], [];
  5688. proc_nr = Some 237;
  5689. tests = [
  5690. InitISOFS, Always, TestOutputFileMD5 (
  5691. [["checksum_device"; "md5"; "/dev/sdd"]],
  5692. "../data/test.iso")
  5693. ];
  5694. shortdesc = "compute MD5, SHAx or CRC checksum of the contents of a device";
  5695. longdesc = "\
  5696. This call computes the MD5, SHAx or CRC checksum of the
  5697. contents of the device named C<device>. For the types of
  5698. checksums supported see the C<guestfs_checksum> command." };
  5699. { defaults with
  5700. name = "lvresize_free";
  5701. style = RErr, [Device "lv"; Int "percent"], [];
  5702. proc_nr = Some 238;
  5703. optional = Some "lvm2";
  5704. tests = [
  5705. InitNone, Always, TestRun (
  5706. [["part_disk"; "/dev/sda"; "mbr"];
  5707. ["pvcreate"; "/dev/sda1"];
  5708. ["vgcreate"; "VG"; "/dev/sda1"];
  5709. ["lvcreate"; "LV"; "VG"; "10"];
  5710. ["lvresize_free"; "/dev/VG/LV"; "100"]])
  5711. ];
  5712. shortdesc = "expand an LV to fill free space";
  5713. longdesc = "\
  5714. This expands an existing logical volume C<lv> so that it fills
  5715. C<pc>% of the remaining free space in the volume group. Commonly
  5716. you would call this with pc = 100 which expands the logical volume
  5717. as much as possible, using all remaining free space in the volume
  5718. group." };
  5719. { defaults with
  5720. name = "aug_clear";
  5721. style = RErr, [String "augpath"], [];
  5722. proc_nr = Some 239;
  5723. optional = Some "augeas";
  5724. shortdesc = "clear Augeas path";
  5725. longdesc = "\
  5726. Set the value associated with C<path> to C<NULL>. This
  5727. is the same as the L<augtool(1)> C<clear> command." };
  5728. { defaults with
  5729. name = "get_umask";
  5730. style = RInt "mask", [], [];
  5731. proc_nr = Some 240;
  5732. fish_output = Some FishOutputOctal;
  5733. tests = [
  5734. InitEmpty, Always, TestOutputInt (
  5735. [["get_umask"]], 0o22)
  5736. ];
  5737. shortdesc = "get the current umask";
  5738. longdesc = "\
  5739. Return the current umask. By default the umask is C<022>
  5740. unless it has been set by calling C<guestfs_umask>." };
  5741. { defaults with
  5742. name = "debug_upload";
  5743. style = RErr, [FileIn "filename"; String "tmpname"; Int "mode"], [];
  5744. proc_nr = Some 241;
  5745. in_docs = false; cancellable = true;
  5746. shortdesc = "upload a file to the appliance (internal use only)";
  5747. longdesc = "\
  5748. The C<guestfs_debug_upload> command uploads a file to
  5749. the libguestfs appliance.
  5750. There is no comprehensive help for this command. You have
  5751. to look at the file C<daemon/debug.c> in the libguestfs source
  5752. to find out what it is for." };
  5753. { defaults with
  5754. name = "base64_in";
  5755. style = RErr, [FileIn "base64file"; Pathname "filename"], [];
  5756. proc_nr = Some 242;
  5757. cancellable = true;
  5758. tests = [
  5759. InitScratchFS, Always, TestOutput (
  5760. [["base64_in"; "../data/hello.b64"; "/base64_in"];
  5761. ["cat"; "/base64_in"]], "hello\n")
  5762. ];
  5763. shortdesc = "upload base64-encoded data to file";
  5764. longdesc = "\
  5765. This command uploads base64-encoded data from C<base64file>
  5766. to C<filename>." };
  5767. { defaults with
  5768. name = "base64_out";
  5769. style = RErr, [Pathname "filename"; FileOut "base64file"], [];
  5770. proc_nr = Some 243;
  5771. cancellable = true;
  5772. shortdesc = "download file and encode as base64";
  5773. longdesc = "\
  5774. This command downloads the contents of C<filename>, writing
  5775. it out to local file C<base64file> encoded as base64." };
  5776. { defaults with
  5777. name = "checksums_out";
  5778. style = RErr, [String "csumtype"; Pathname "directory"; FileOut "sumsfile"], [];
  5779. proc_nr = Some 244;
  5780. cancellable = true;
  5781. shortdesc = "compute MD5, SHAx or CRC checksum of files in a directory";
  5782. longdesc = "\
  5783. This command computes the checksums of all regular files in
  5784. C<directory> and then emits a list of those checksums to
  5785. the local output file C<sumsfile>.
  5786. This can be used for verifying the integrity of a virtual
  5787. machine. However to be properly secure you should pay
  5788. attention to the output of the checksum command (it uses
  5789. the ones from GNU coreutils). In particular when the
  5790. filename is not printable, coreutils uses a special
  5791. backslash syntax. For more information, see the GNU
  5792. coreutils info file." };
  5793. { defaults with
  5794. name = "fill_pattern";
  5795. style = RErr, [String "pattern"; Int "len"; Pathname "path"], [];
  5796. proc_nr = Some 245;
  5797. progress = true;
  5798. tests = [
  5799. InitScratchFS, Always, TestOutputBuffer (
  5800. [["fill_pattern"; "abcdefghijklmnopqrstuvwxyz"; "28"; "/fill_pattern"];
  5801. ["read_file"; "/fill_pattern"]], "abcdefghijklmnopqrstuvwxyzab")
  5802. ];
  5803. shortdesc = "fill a file with a repeating pattern of bytes";
  5804. longdesc = "\
  5805. This function is like C<guestfs_fill> except that it creates
  5806. a new file of length C<len> containing the repeating pattern
  5807. of bytes in C<pattern>. The pattern is truncated if necessary
  5808. to ensure the length of the file is exactly C<len> bytes." };
  5809. { defaults with
  5810. name = "write";
  5811. style = RErr, [Pathname "path"; BufferIn "content"], [];
  5812. proc_nr = Some 246;
  5813. protocol_limit_warning = true;
  5814. tests = [
  5815. InitScratchFS, Always, TestOutput (
  5816. [["write"; "/write"; "new file contents"];
  5817. ["cat"; "/write"]], "new file contents");
  5818. InitScratchFS, Always, TestOutput (
  5819. [["write"; "/write2"; "\nnew file contents\n"];
  5820. ["cat"; "/write2"]], "\nnew file contents\n");
  5821. InitScratchFS, Always, TestOutput (
  5822. [["write"; "/write3"; "\n\n"];
  5823. ["cat"; "/write3"]], "\n\n");
  5824. InitScratchFS, Always, TestOutput (
  5825. [["write"; "/write4"; ""];
  5826. ["cat"; "/write4"]], "");
  5827. InitScratchFS, Always, TestOutput (
  5828. [["write"; "/write5"; "\n\n\n"];
  5829. ["cat"; "/write5"]], "\n\n\n");
  5830. InitScratchFS, Always, TestOutput (
  5831. [["write"; "/write6"; "\n"];
  5832. ["cat"; "/write6"]], "\n")
  5833. ];
  5834. shortdesc = "create a new file";
  5835. longdesc = "\
  5836. This call creates a file called C<path>. The content of the
  5837. file is the string C<content> (which can contain any 8 bit data).
  5838. See also C<guestfs_write_append>." };
  5839. { defaults with
  5840. name = "pwrite";
  5841. style = RInt "nbytes", [Pathname "path"; BufferIn "content"; Int64 "offset"], [];
  5842. proc_nr = Some 247;
  5843. protocol_limit_warning = true;
  5844. tests = [
  5845. InitScratchFS, Always, TestOutput (
  5846. [["write"; "/pwrite"; "new file contents"];
  5847. ["pwrite"; "/pwrite"; "data"; "4"];
  5848. ["cat"; "/pwrite"]], "new data contents");
  5849. InitScratchFS, Always, TestOutput (
  5850. [["write"; "/pwrite2"; "new file contents"];
  5851. ["pwrite"; "/pwrite2"; "is extended"; "9"];
  5852. ["cat"; "/pwrite2"]], "new file is extended");
  5853. InitScratchFS, Always, TestOutput (
  5854. [["write"; "/pwrite3"; "new file contents"];
  5855. ["pwrite"; "/pwrite3"; ""; "4"];
  5856. ["cat"; "/pwrite3"]], "new file contents")
  5857. ];
  5858. shortdesc = "write to part of a file";
  5859. longdesc = "\
  5860. This command writes to part of a file. It writes the data
  5861. buffer C<content> to the file C<path> starting at offset C<offset>.
  5862. This command implements the L<pwrite(2)> system call, and like
  5863. that system call it may not write the full data requested. The
  5864. return value is the number of bytes that were actually written
  5865. to the file. This could even be 0, although short writes are
  5866. unlikely for regular files in ordinary circumstances.
  5867. See also C<guestfs_pread>, C<guestfs_pwrite_device>." };
  5868. { defaults with
  5869. name = "resize2fs_size";
  5870. style = RErr, [Device "device"; Int64 "size"], [];
  5871. proc_nr = Some 248;
  5872. shortdesc = "resize an ext2, ext3 or ext4 filesystem (with size)";
  5873. longdesc = "\
  5874. This command is the same as C<guestfs_resize2fs> except that it
  5875. allows you to specify the new size (in bytes) explicitly.
  5876. See also L<guestfs(3)/RESIZE2FS ERRORS>." };
  5877. { defaults with
  5878. name = "pvresize_size";
  5879. style = RErr, [Device "device"; Int64 "size"], [];
  5880. proc_nr = Some 249;
  5881. optional = Some "lvm2";
  5882. shortdesc = "resize an LVM physical volume (with size)";
  5883. longdesc = "\
  5884. This command is the same as C<guestfs_pvresize> except that it
  5885. allows you to specify the new size (in bytes) explicitly." };
  5886. { defaults with
  5887. name = "ntfsresize_size";
  5888. style = RErr, [Device "device"; Int64 "size"], [];
  5889. proc_nr = Some 250;
  5890. optional = Some "ntfsprogs"; deprecated_by = Some "ntfsresize";
  5891. shortdesc = "resize an NTFS filesystem (with size)";
  5892. longdesc = "\
  5893. This command is the same as C<guestfs_ntfsresize> except that it
  5894. allows you to specify the new size (in bytes) explicitly." };
  5895. { defaults with
  5896. name = "available_all_groups";
  5897. style = RStringList "groups", [], [];
  5898. proc_nr = Some 251;
  5899. tests = [
  5900. InitNone, Always, TestRun [["available_all_groups"]]
  5901. ];
  5902. shortdesc = "return a list of all optional groups";
  5903. longdesc = "\
  5904. This command returns a list of all optional groups that this
  5905. daemon knows about. Note this returns both supported and unsupported
  5906. groups. To find out which ones the daemon can actually support
  5907. you have to call C<guestfs_available> on each member of the
  5908. returned list.
  5909. See also C<guestfs_available> and L<guestfs(3)/AVAILABILITY>." };
  5910. { defaults with
  5911. name = "fallocate64";
  5912. style = RErr, [Pathname "path"; Int64 "len"], [];
  5913. proc_nr = Some 252;
  5914. tests = [
  5915. InitScratchFS, Always, TestOutputStruct (
  5916. [["fallocate64"; "/fallocate64"; "1000000"];
  5917. ["stat"; "/fallocate64"]], [CompareWithInt ("size", 1_000_000)])
  5918. ];
  5919. shortdesc = "preallocate a file in the guest filesystem";
  5920. longdesc = "\
  5921. This command preallocates a file (containing zero bytes) named
  5922. C<path> of size C<len> bytes. If the file exists already, it
  5923. is overwritten.
  5924. Note that this call allocates disk blocks for the file.
  5925. To create a sparse file use C<guestfs_truncate_size> instead.
  5926. The deprecated call C<guestfs_fallocate> does the same,
  5927. but owing to an oversight it only allowed 30 bit lengths
  5928. to be specified, effectively limiting the maximum size
  5929. of files created through that call to 1GB.
  5930. Do not confuse this with the guestfish-specific
  5931. C<alloc> and C<sparse> commands which create
  5932. a file in the host and attach it as a device." };
  5933. { defaults with
  5934. name = "vfs_label";
  5935. style = RString "label", [Device "device"], [];
  5936. proc_nr = Some 253;
  5937. tests = [
  5938. InitBasicFS, Always, TestOutput (
  5939. [["set_label"; "/dev/sda1"; "LTEST"];
  5940. ["vfs_label"; "/dev/sda1"]], "LTEST")
  5941. ];
  5942. shortdesc = "get the filesystem label";
  5943. longdesc = "\
  5944. This returns the filesystem label of the filesystem on
  5945. C<device>.
  5946. If the filesystem is unlabeled, this returns the empty string.
  5947. To find a filesystem from the label, use C<guestfs_findfs_label>." };
  5948. { defaults with
  5949. name = "vfs_uuid";
  5950. style = RString "uuid", [Device "device"], [];
  5951. proc_nr = Some 254;
  5952. tests =
  5953. (let uuid = uuidgen () in [
  5954. InitBasicFS, Always, TestOutput (
  5955. [["set_e2uuid"; "/dev/sda1"; uuid];
  5956. ["vfs_uuid"; "/dev/sda1"]], uuid)
  5957. ]);
  5958. shortdesc = "get the filesystem UUID";
  5959. longdesc = "\
  5960. This returns the filesystem UUID of the filesystem on
  5961. C<device>.
  5962. If the filesystem does not have a UUID, this returns the empty string.
  5963. To find a filesystem from the UUID, use C<guestfs_findfs_uuid>." };
  5964. { defaults with
  5965. name = "lvm_set_filter";
  5966. style = RErr, [DeviceList "devices"], [];
  5967. proc_nr = Some 255;
  5968. optional = Some "lvm2";
  5969. (* Can't be tested with the current framework because
  5970. * the VG is being used by the mounted filesystem, so
  5971. * the vgchange -an command we do first will fail.
  5972. *)
  5973. tests = [];
  5974. shortdesc = "set LVM device filter";
  5975. longdesc = "\
  5976. This sets the LVM device filter so that LVM will only be
  5977. able to \"see\" the block devices in the list C<devices>,
  5978. and will ignore all other attached block devices.
  5979. Where disk image(s) contain duplicate PVs or VGs, this
  5980. command is useful to get LVM to ignore the duplicates, otherwise
  5981. LVM can get confused. Note also there are two types
  5982. of duplication possible: either cloned PVs/VGs which have
  5983. identical UUIDs; or VGs that are not cloned but just happen
  5984. to have the same name. In normal operation you cannot
  5985. create this situation, but you can do it outside LVM, eg.
  5986. by cloning disk images or by bit twiddling inside the LVM
  5987. metadata.
  5988. This command also clears the LVM cache and performs a volume
  5989. group scan.
  5990. You can filter whole block devices or individual partitions.
  5991. You cannot use this if any VG is currently in use (eg.
  5992. contains a mounted filesystem), even if you are not
  5993. filtering out that VG." };
  5994. { defaults with
  5995. name = "lvm_clear_filter";
  5996. style = RErr, [], [];
  5997. proc_nr = Some 256;
  5998. tests = [] (* see note on lvm_set_filter *);
  5999. shortdesc = "clear LVM device filter";
  6000. longdesc = "\
  6001. This undoes the effect of C<guestfs_lvm_set_filter>. LVM
  6002. will be able to see every block device.
  6003. This command also clears the LVM cache and performs a volume
  6004. group scan." };
  6005. { defaults with
  6006. name = "luks_open";
  6007. style = RErr, [Device "device"; Key "key"; String "mapname"], [];
  6008. proc_nr = Some 257;
  6009. optional = Some "luks";
  6010. shortdesc = "open a LUKS-encrypted block device";
  6011. longdesc = "\
  6012. This command opens a block device which has been encrypted
  6013. according to the Linux Unified Key Setup (LUKS) standard.
  6014. C<device> is the encrypted block device or partition.
  6015. The caller must supply one of the keys associated with the
  6016. LUKS block device, in the C<key> parameter.
  6017. This creates a new block device called C</dev/mapper/mapname>.
  6018. Reads and writes to this block device are decrypted from and
  6019. encrypted to the underlying C<device> respectively.
  6020. If this block device contains LVM volume groups, then
  6021. calling C<guestfs_vgscan> followed by C<guestfs_vg_activate_all>
  6022. will make them visible.
  6023. Use C<guestfs_list_dm_devices> to list all device mapper
  6024. devices." };
  6025. { defaults with
  6026. name = "luks_open_ro";
  6027. style = RErr, [Device "device"; Key "key"; String "mapname"], [];
  6028. proc_nr = Some 258;
  6029. optional = Some "luks";
  6030. shortdesc = "open a LUKS-encrypted block device read-only";
  6031. longdesc = "\
  6032. This is the same as C<guestfs_luks_open> except that a read-only
  6033. mapping is created." };
  6034. { defaults with
  6035. name = "luks_close";
  6036. style = RErr, [Device "device"], [];
  6037. proc_nr = Some 259;
  6038. optional = Some "luks";
  6039. shortdesc = "close a LUKS device";
  6040. longdesc = "\
  6041. This closes a LUKS device that was created earlier by
  6042. C<guestfs_luks_open> or C<guestfs_luks_open_ro>. The
  6043. C<device> parameter must be the name of the LUKS mapping
  6044. device (ie. C</dev/mapper/mapname>) and I<not> the name
  6045. of the underlying block device." };
  6046. { defaults with
  6047. name = "luks_format";
  6048. style = RErr, [Device "device"; Key "key"; Int "keyslot"], [];
  6049. proc_nr = Some 260;
  6050. optional = Some "luks";
  6051. shortdesc = "format a block device as a LUKS encrypted device";
  6052. longdesc = "\
  6053. This command erases existing data on C<device> and formats
  6054. the device as a LUKS encrypted device. C<key> is the
  6055. initial key, which is added to key slot C<slot>. (LUKS
  6056. supports 8 key slots, numbered 0-7)." };
  6057. { defaults with
  6058. name = "luks_format_cipher";
  6059. style = RErr, [Device "device"; Key "key"; Int "keyslot"; String "cipher"], [];
  6060. proc_nr = Some 261;
  6061. optional = Some "luks";
  6062. shortdesc = "format a block device as a LUKS encrypted device";
  6063. longdesc = "\
  6064. This command is the same as C<guestfs_luks_format> but
  6065. it also allows you to set the C<cipher> used." };
  6066. { defaults with
  6067. name = "luks_add_key";
  6068. style = RErr, [Device "device"; Key "key"; Key "newkey"; Int "keyslot"], [];
  6069. proc_nr = Some 262;
  6070. optional = Some "luks";
  6071. shortdesc = "add a key on a LUKS encrypted device";
  6072. longdesc = "\
  6073. This command adds a new key on LUKS device C<device>.
  6074. C<key> is any existing key, and is used to access the device.
  6075. C<newkey> is the new key to add. C<keyslot> is the key slot
  6076. that will be replaced.
  6077. Note that if C<keyslot> already contains a key, then this
  6078. command will fail. You have to use C<guestfs_luks_kill_slot>
  6079. first to remove that key." };
  6080. { defaults with
  6081. name = "luks_kill_slot";
  6082. style = RErr, [Device "device"; Key "key"; Int "keyslot"], [];
  6083. proc_nr = Some 263;
  6084. optional = Some "luks";
  6085. shortdesc = "remove a key from a LUKS encrypted device";
  6086. longdesc = "\
  6087. This command deletes the key in key slot C<keyslot> from the
  6088. encrypted LUKS device C<device>. C<key> must be one of the
  6089. I<other> keys." };
  6090. { defaults with
  6091. name = "is_lv";
  6092. style = RBool "lvflag", [Device "device"], [];
  6093. proc_nr = Some 264;
  6094. optional = Some "lvm2";
  6095. tests = [
  6096. InitBasicFSonLVM, IfAvailable "lvm2", TestOutputTrue (
  6097. [["is_lv"; "/dev/VG/LV"]]);
  6098. InitBasicFSonLVM, IfAvailable "lvm2", TestOutputFalse (
  6099. [["is_lv"; "/dev/sda1"]])
  6100. ];
  6101. shortdesc = "test if device is a logical volume";
  6102. longdesc = "\
  6103. This command tests whether C<device> is a logical volume, and
  6104. returns true iff this is the case." };
  6105. { defaults with
  6106. name = "findfs_uuid";
  6107. style = RString "device", [String "uuid"], [];
  6108. proc_nr = Some 265;
  6109. shortdesc = "find a filesystem by UUID";
  6110. longdesc = "\
  6111. This command searches the filesystems and returns the one
  6112. which has the given UUID. An error is returned if no such
  6113. filesystem can be found.
  6114. To find the UUID of a filesystem, use C<guestfs_vfs_uuid>." };
  6115. { defaults with
  6116. name = "findfs_label";
  6117. style = RString "device", [String "label"], [];
  6118. proc_nr = Some 266;
  6119. shortdesc = "find a filesystem by label";
  6120. longdesc = "\
  6121. This command searches the filesystems and returns the one
  6122. which has the given label. An error is returned if no such
  6123. filesystem can be found.
  6124. To find the label of a filesystem, use C<guestfs_vfs_label>." };
  6125. { defaults with
  6126. name = "is_chardev";
  6127. style = RBool "flag", [Pathname "path"], [];
  6128. proc_nr = Some 267;
  6129. tests = [
  6130. InitISOFS, Always, TestOutputFalse (
  6131. [["is_chardev"; "/directory"]]);
  6132. InitScratchFS, Always, TestOutputTrue (
  6133. [["mknod_c"; "0o777"; "99"; "66"; "/is_chardev"];
  6134. ["is_chardev"; "/is_chardev"]])
  6135. ];
  6136. shortdesc = "test if character device";
  6137. longdesc = "\
  6138. This returns C<true> if and only if there is a character device
  6139. with the given C<path> name.
  6140. See also C<guestfs_stat>." };
  6141. { defaults with
  6142. name = "is_blockdev";
  6143. style = RBool "flag", [Pathname "path"], [];
  6144. proc_nr = Some 268;
  6145. tests = [
  6146. InitISOFS, Always, TestOutputFalse (
  6147. [["is_blockdev"; "/directory"]]);
  6148. InitScratchFS, Always, TestOutputTrue (
  6149. [["mknod_b"; "0o777"; "99"; "66"; "/is_blockdev"];
  6150. ["is_blockdev"; "/is_blockdev"]])
  6151. ];
  6152. shortdesc = "test if block device";
  6153. longdesc = "\
  6154. This returns C<true> if and only if there is a block device
  6155. with the given C<path> name.
  6156. See also C<guestfs_stat>." };
  6157. { defaults with
  6158. name = "is_fifo";
  6159. style = RBool "flag", [Pathname "path"], [];
  6160. proc_nr = Some 269;
  6161. tests = [
  6162. InitISOFS, Always, TestOutputFalse (
  6163. [["is_fifo"; "/directory"]]);
  6164. InitScratchFS, Always, TestOutputTrue (
  6165. [["mkfifo"; "0o777"; "/is_fifo"];
  6166. ["is_fifo"; "/is_fifo"]])
  6167. ];
  6168. shortdesc = "test if FIFO (named pipe)";
  6169. longdesc = "\
  6170. This returns C<true> if and only if there is a FIFO (named pipe)
  6171. with the given C<path> name.
  6172. See also C<guestfs_stat>." };
  6173. { defaults with
  6174. name = "is_symlink";
  6175. style = RBool "flag", [Pathname "path"], [];
  6176. proc_nr = Some 270;
  6177. tests = [
  6178. InitISOFS, Always, TestOutputFalse (
  6179. [["is_symlink"; "/directory"]]);
  6180. InitISOFS, Always, TestOutputTrue (
  6181. [["is_symlink"; "/abssymlink"]])
  6182. ];
  6183. shortdesc = "test if symbolic link";
  6184. longdesc = "\
  6185. This returns C<true> if and only if there is a symbolic link
  6186. with the given C<path> name.
  6187. See also C<guestfs_stat>." };
  6188. { defaults with
  6189. name = "is_socket";
  6190. style = RBool "flag", [Pathname "path"], [];
  6191. proc_nr = Some 271;
  6192. (* XXX Need a positive test for sockets. *)
  6193. tests = [
  6194. InitISOFS, Always, TestOutputFalse (
  6195. [["is_socket"; "/directory"]])
  6196. ];
  6197. shortdesc = "test if socket";
  6198. longdesc = "\
  6199. This returns C<true> if and only if there is a Unix domain socket
  6200. with the given C<path> name.
  6201. See also C<guestfs_stat>." };
  6202. { defaults with
  6203. name = "part_to_dev";
  6204. style = RString "device", [Device "partition"], [];
  6205. proc_nr = Some 272;
  6206. tests = [
  6207. InitPartition, Always, TestOutputDevice (
  6208. [["part_to_dev"; "/dev/sda1"]], "/dev/sda");
  6209. InitEmpty, Always, TestLastFail (
  6210. [["part_to_dev"; "/dev/sda"]])
  6211. ];
  6212. shortdesc = "convert partition name to device name";
  6213. longdesc = "\
  6214. This function takes a partition name (eg. \"/dev/sdb1\") and
  6215. removes the partition number, returning the device name
  6216. (eg. \"/dev/sdb\").
  6217. The named partition must exist, for example as a string returned
  6218. from C<guestfs_list_partitions>.
  6219. See also C<guestfs_part_to_partnum>, C<guestfs_device_index>." };
  6220. { defaults with
  6221. name = "upload_offset";
  6222. style = RErr, [FileIn "filename"; Dev_or_Path "remotefilename"; Int64 "offset"], [];
  6223. proc_nr = Some 273;
  6224. progress = true; cancellable = true;
  6225. tests =
  6226. (let md5 = Digest.to_hex (Digest.file "COPYING.LIB") in [
  6227. InitScratchFS, Always, TestOutput (
  6228. [["upload_offset"; "../../COPYING.LIB"; "/upload_offset"; "0"];
  6229. ["checksum"; "md5"; "/upload_offset"]], md5)
  6230. ]);
  6231. shortdesc = "upload a file from the local machine with offset";
  6232. longdesc = "\
  6233. Upload local file C<filename> to C<remotefilename> on the
  6234. filesystem.
  6235. C<remotefilename> is overwritten starting at the byte C<offset>
  6236. specified. The intention is to overwrite parts of existing
  6237. files or devices, although if a non-existant file is specified
  6238. then it is created with a \"hole\" before C<offset>. The
  6239. size of the data written is implicit in the size of the
  6240. source C<filename>.
  6241. Note that there is no limit on the amount of data that
  6242. can be uploaded with this call, unlike with C<guestfs_pwrite>,
  6243. and this call always writes the full amount unless an
  6244. error occurs.
  6245. See also C<guestfs_upload>, C<guestfs_pwrite>." };
  6246. { defaults with
  6247. name = "download_offset";
  6248. style = RErr, [Dev_or_Path "remotefilename"; FileOut "filename"; Int64 "offset"; Int64 "size"], [];
  6249. proc_nr = Some 274;
  6250. progress = true; cancellable = true;
  6251. tests =
  6252. (let md5 = Digest.to_hex (Digest.file "COPYING.LIB") in
  6253. let offset = string_of_int 100 in
  6254. let size = string_of_int ((Unix.stat "COPYING.LIB").Unix.st_size - 100) in
  6255. [
  6256. InitScratchFS, Always, TestOutput (
  6257. (* Pick a file from cwd which isn't likely to change. *)
  6258. [["mkdir"; "/download_offset"];
  6259. ["upload"; "../../COPYING.LIB"; "/download_offset/COPYING.LIB"];
  6260. ["download_offset"; "/download_offset/COPYING.LIB"; "testdownload.tmp"; offset; size];
  6261. ["upload_offset"; "testdownload.tmp"; "/download_offset/COPYING.LIB"; offset];
  6262. ["checksum"; "md5"; "/download_offset/COPYING.LIB"]], md5)
  6263. ]);
  6264. shortdesc = "download a file to the local machine with offset and size";
  6265. longdesc = "\
  6266. Download file C<remotefilename> and save it as C<filename>
  6267. on the local machine.
  6268. C<remotefilename> is read for C<size> bytes starting at C<offset>
  6269. (this region must be within the file or device).
  6270. Note that there is no limit on the amount of data that
  6271. can be downloaded with this call, unlike with C<guestfs_pread>,
  6272. and this call always reads the full amount unless an
  6273. error occurs.
  6274. See also C<guestfs_download>, C<guestfs_pread>." };
  6275. { defaults with
  6276. name = "pwrite_device";
  6277. style = RInt "nbytes", [Device "device"; BufferIn "content"; Int64 "offset"], [];
  6278. proc_nr = Some 275;
  6279. protocol_limit_warning = true;
  6280. tests = [
  6281. InitPartition, Always, TestOutputListOfDevices (
  6282. [["pwrite_device"; "/dev/sda"; "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"; "446"];
  6283. ["blockdev_rereadpt"; "/dev/sda"];
  6284. ["list_partitions"]], ["/dev/sdb1"])
  6285. ];
  6286. shortdesc = "write to part of a device";
  6287. longdesc = "\
  6288. This command writes to part of a device. It writes the data
  6289. buffer C<content> to C<device> starting at offset C<offset>.
  6290. This command implements the L<pwrite(2)> system call, and like
  6291. that system call it may not write the full data requested
  6292. (although short writes to disk devices and partitions are
  6293. probably impossible with standard Linux kernels).
  6294. See also C<guestfs_pwrite>." };
  6295. { defaults with
  6296. name = "pread_device";
  6297. style = RBufferOut "content", [Device "device"; Int "count"; Int64 "offset"], [];
  6298. proc_nr = Some 276;
  6299. protocol_limit_warning = true;
  6300. tests = [
  6301. InitEmpty, Always, TestOutputBuffer (
  6302. [["pread_device"; "/dev/sdd"; "8"; "32768"]], "\001CD001\001\000")
  6303. ];
  6304. shortdesc = "read part of a device";
  6305. longdesc = "\
  6306. This command lets you read part of a file. It reads C<count>
  6307. bytes of C<device>, starting at C<offset>.
  6308. This may read fewer bytes than requested. For further details
  6309. see the L<pread(2)> system call.
  6310. See also C<guestfs_pread>." };
  6311. { defaults with
  6312. name = "lvm_canonical_lv_name";
  6313. style = RString "lv", [Device "lvname"], [];
  6314. proc_nr = Some 277;
  6315. tests = [
  6316. InitBasicFSonLVM, IfAvailable "lvm2", TestOutput (
  6317. [["lvm_canonical_lv_name"; "/dev/mapper/VG-LV"]], "/dev/VG/LV");
  6318. InitBasicFSonLVM, IfAvailable "lvm2", TestOutput (
  6319. [["lvm_canonical_lv_name"; "/dev/VG/LV"]], "/dev/VG/LV")
  6320. ];
  6321. shortdesc = "get canonical name of an LV";
  6322. longdesc = "\
  6323. This converts alternative naming schemes for LVs that you
  6324. might find to the canonical name. For example, C</dev/mapper/VG-LV>
  6325. is converted to C</dev/VG/LV>.
  6326. This command returns an error if the C<lvname> parameter does
  6327. not refer to a logical volume.
  6328. See also C<guestfs_is_lv>, C<guestfs_canonical_device_name>." };
  6329. { defaults with
  6330. name = "mkfs";
  6331. style = RErr, [String "fstype"; Device "device"], [OInt "blocksize"; OString "features"; OInt "inode"; OInt "sectorsize"];
  6332. proc_nr = Some 278;
  6333. once_had_no_optargs = true;
  6334. tests = [
  6335. InitEmpty, Always, TestOutput (
  6336. [["part_disk"; "/dev/sda"; "mbr"];
  6337. ["mkfs"; "ext2"; "/dev/sda1"; ""; "NOARG"; ""; ""];
  6338. ["mount_options"; ""; "/dev/sda1"; "/"];
  6339. ["write"; "/new"; "new file contents"];
  6340. ["cat"; "/new"]], "new file contents")
  6341. ];
  6342. shortdesc = "make a filesystem";
  6343. longdesc = "\
  6344. This function creates a filesystem on C<device>. The filesystem
  6345. type is C<fstype>, for example C<ext3>.
  6346. The optional arguments are:
  6347. =over 4
  6348. =item C<blocksize>
  6349. The filesystem block size. Supported block sizes depend on the
  6350. filesystem type, but typically they are C<1024>, C<2048> or C<4096>
  6351. for Linux ext2/3 filesystems.
  6352. For VFAT and NTFS the C<blocksize> parameter is treated as
  6353. the requested cluster size.
  6354. For UFS block sizes, please see L<mkfs.ufs(8)>.
  6355. =item C<features>
  6356. This passes the I<-O> parameter to the external mkfs program.
  6357. For certain filesystem types, this allows extra filesystem
  6358. features to be selected. See L<mke2fs(8)> and L<mkfs.ufs(8)>
  6359. for more details.
  6360. You cannot use this optional parameter with the C<gfs> or
  6361. C<gfs2> filesystem type.
  6362. =item C<inode>
  6363. This passes the I<-I> parameter to the external L<mke2fs(8)> program
  6364. which sets the inode size (only for ext2/3/4 filesystems at present).
  6365. =item C<sectorsize>
  6366. This passes the I<-S> parameter to external L<mkfs.ufs(8)> program,
  6367. which sets sector size for ufs filesystem.
  6368. =back" };
  6369. { defaults with
  6370. name = "getxattr";
  6371. style = RBufferOut "xattr", [Pathname "path"; String "name"], [];
  6372. proc_nr = Some 279;
  6373. optional = Some "linuxxattrs";
  6374. shortdesc = "get a single extended attribute";
  6375. longdesc = "\
  6376. Get a single extended attribute from file C<path> named C<name>.
  6377. This call follows symlinks. If you want to lookup an extended
  6378. attribute for the symlink itself, use C<guestfs_lgetxattr>.
  6379. Normally it is better to get all extended attributes from a file
  6380. in one go by calling C<guestfs_getxattrs>. However some Linux
  6381. filesystem implementations are buggy and do not provide a way to
  6382. list out attributes. For these filesystems (notably ntfs-3g)
  6383. you have to know the names of the extended attributes you want
  6384. in advance and call this function.
  6385. Extended attribute values are blobs of binary data. If there
  6386. is no extended attribute named C<name>, this returns an error.
  6387. See also: C<guestfs_getxattrs>, C<guestfs_lgetxattr>, L<attr(5)>." };
  6388. { defaults with
  6389. name = "lgetxattr";
  6390. style = RBufferOut "xattr", [Pathname "path"; String "name"], [];
  6391. proc_nr = Some 280;
  6392. optional = Some "linuxxattrs";
  6393. shortdesc = "get a single extended attribute";
  6394. longdesc = "\
  6395. Get a single extended attribute from file C<path> named C<name>.
  6396. If C<path> is a symlink, then this call returns an extended
  6397. attribute from the symlink.
  6398. Normally it is better to get all extended attributes from a file
  6399. in one go by calling C<guestfs_getxattrs>. However some Linux
  6400. filesystem implementations are buggy and do not provide a way to
  6401. list out attributes. For these filesystems (notably ntfs-3g)
  6402. you have to know the names of the extended attributes you want
  6403. in advance and call this function.
  6404. Extended attribute values are blobs of binary data. If there
  6405. is no extended attribute named C<name>, this returns an error.
  6406. See also: C<guestfs_lgetxattrs>, C<guestfs_getxattr>, L<attr(5)>." };
  6407. { defaults with
  6408. name = "resize2fs_M";
  6409. style = RErr, [Device "device"], [];
  6410. proc_nr = Some 281;
  6411. shortdesc = "resize an ext2, ext3 or ext4 filesystem to the minimum size";
  6412. longdesc = "\
  6413. This command is the same as C<guestfs_resize2fs>, but the filesystem
  6414. is resized to its minimum size. This works like the I<-M> option
  6415. to the C<resize2fs> command.
  6416. To get the resulting size of the filesystem you should call
  6417. C<guestfs_tune2fs_l> and read the C<Block size> and C<Block count>
  6418. values. These two numbers, multiplied together, give the
  6419. resulting size of the minimal filesystem in bytes.
  6420. See also L<guestfs(3)/RESIZE2FS ERRORS>." };
  6421. { defaults with
  6422. name = "internal_autosync";
  6423. style = RErr, [], [];
  6424. proc_nr = Some 282;
  6425. in_fish = false; in_docs = false;
  6426. shortdesc = "internal autosync operation";
  6427. longdesc = "\
  6428. This command performs the autosync operation just before the
  6429. handle is closed. You should not call this command directly.
  6430. Instead, use the autosync flag (C<guestfs_set_autosync>) to
  6431. control whether or not this operation is performed when the
  6432. handle is closed." };
  6433. { defaults with
  6434. name = "is_zero";
  6435. style = RBool "zeroflag", [Pathname "path"], [];
  6436. proc_nr = Some 283;
  6437. tests = [
  6438. InitISOFS, Always, TestOutputTrue (
  6439. [["is_zero"; "/100kallzeroes"]]);
  6440. InitISOFS, Always, TestOutputFalse (
  6441. [["is_zero"; "/100kallspaces"]])
  6442. ];
  6443. shortdesc = "test if a file contains all zero bytes";
  6444. longdesc = "\
  6445. This returns true iff the file exists and the file is empty or
  6446. it contains all zero bytes." };
  6447. { defaults with
  6448. name = "is_zero_device";
  6449. style = RBool "zeroflag", [Device "device"], [];
  6450. proc_nr = Some 284;
  6451. tests = [
  6452. InitBasicFS, Always, TestOutputTrue (
  6453. [["umount"; "/dev/sda1"];
  6454. ["zero_device"; "/dev/sda1"];
  6455. ["is_zero_device"; "/dev/sda1"]]);
  6456. InitBasicFS, Always, TestOutputFalse (
  6457. [["is_zero_device"; "/dev/sda1"]])
  6458. ];
  6459. shortdesc = "test if a device contains all zero bytes";
  6460. longdesc = "\
  6461. This returns true iff the device exists and contains all zero bytes.
  6462. Note that for large devices this can take a long time to run." };
  6463. { defaults with
  6464. name = "list_9p";
  6465. style = RStringList "mounttags", [], [];
  6466. proc_nr = Some 285;
  6467. shortdesc = "list 9p filesystems";
  6468. longdesc = "\
  6469. List all 9p filesystems attached to the guest. A list of
  6470. mount tags is returned." };
  6471. { defaults with
  6472. name = "mount_9p";
  6473. style = RErr, [String "mounttag"; String "mountpoint"], [OString "options"];
  6474. proc_nr = Some 286;
  6475. camel_name = "Mount9P";
  6476. shortdesc = "mount 9p filesystem";
  6477. longdesc = "\
  6478. Mount the virtio-9p filesystem with the tag C<mounttag> on the
  6479. directory C<mountpoint>.
  6480. If required, C<trans=virtio> will be automatically added to the options.
  6481. Any other options required can be passed in the optional C<options>
  6482. parameter." };
  6483. { defaults with
  6484. name = "list_dm_devices";
  6485. style = RStringList "devices", [], [];
  6486. proc_nr = Some 287;
  6487. shortdesc = "list device mapper devices";
  6488. longdesc = "\
  6489. List all device mapper devices.
  6490. The returned list contains C</dev/mapper/*> devices, eg. ones created
  6491. by a previous call to C<guestfs_luks_open>.
  6492. Device mapper devices which correspond to logical volumes are I<not>
  6493. returned in this list. Call C<guestfs_lvs> if you want to list logical
  6494. volumes." };
  6495. { defaults with
  6496. name = "ntfsresize";
  6497. style = RErr, [Device "device"], [OInt64 "size"; OBool "force"];
  6498. once_had_no_optargs = true;
  6499. proc_nr = Some 288;
  6500. optional = Some "ntfsprogs"; camel_name = "NTFSResizeOpts";
  6501. shortdesc = "resize an NTFS filesystem";
  6502. longdesc = "\
  6503. This command resizes an NTFS filesystem, expanding or
  6504. shrinking it to the size of the underlying device.
  6505. The optional parameters are:
  6506. =over 4
  6507. =item C<size>
  6508. The new size (in bytes) of the filesystem. If omitted, the filesystem
  6509. is resized to fit the container (eg. partition).
  6510. =item C<force>
  6511. If this option is true, then force the resize of the filesystem
  6512. even if the filesystem is marked as requiring a consistency check.
  6513. After the resize operation, the filesystem is always marked
  6514. as requiring a consistency check (for safety). You have to boot
  6515. into Windows to perform this check and clear this condition.
  6516. If you I<don't> set the C<force> option then it is not
  6517. possible to call C<guestfs_ntfsresize> multiple times on a
  6518. single filesystem without booting into Windows between each resize.
  6519. =back
  6520. See also L<ntfsresize(8)>." };
  6521. { defaults with
  6522. name = "btrfs_filesystem_resize";
  6523. style = RErr, [Pathname "mountpoint"], [OInt64 "size"];
  6524. proc_nr = Some 289;
  6525. optional = Some "btrfs"; camel_name = "BTRFSFilesystemResize";
  6526. shortdesc = "resize a btrfs filesystem";
  6527. longdesc = "\
  6528. This command resizes a btrfs filesystem.
  6529. Note that unlike other resize calls, the filesystem has to be
  6530. mounted and the parameter is the mountpoint not the device
  6531. (this is a requirement of btrfs itself).
  6532. The optional parameters are:
  6533. =over 4
  6534. =item C<size>
  6535. The new size (in bytes) of the filesystem. If omitted, the filesystem
  6536. is resized to the maximum size.
  6537. =back
  6538. See also L<btrfs(8)>." };
  6539. { defaults with
  6540. name = "write_append";
  6541. style = RErr, [Pathname "path"; BufferIn "content"], [];
  6542. proc_nr = Some 290;
  6543. protocol_limit_warning = true;
  6544. tests = [
  6545. InitScratchFS, Always, TestOutput (
  6546. [["write"; "/write_append"; "line1\n"];
  6547. ["write_append"; "/write_append"; "line2\n"];
  6548. ["write_append"; "/write_append"; "line3a"];
  6549. ["write_append"; "/write_append"; "line3b\n"];
  6550. ["cat"; "/write_append"]], "line1\nline2\nline3aline3b\n")
  6551. ];
  6552. shortdesc = "append content to end of file";
  6553. longdesc = "\
  6554. This call appends C<content> to the end of file C<path>. If
  6555. C<path> does not exist, then a new file is created.
  6556. See also C<guestfs_write>." };
  6557. { defaults with
  6558. name = "compress_out";
  6559. style = RErr, [String "ctype"; Pathname "file"; FileOut "zfile"], [OInt "level"];
  6560. proc_nr = Some 291;
  6561. cancellable = true;
  6562. shortdesc = "output compressed file";
  6563. longdesc = "\
  6564. This command compresses C<file> and writes it out to the local
  6565. file C<zfile>.
  6566. The compression program used is controlled by the C<ctype> parameter.
  6567. Currently this includes: C<compress>, C<gzip>, C<bzip2>, C<xz> or C<lzop>.
  6568. Some compression types may not be supported by particular builds of
  6569. libguestfs, in which case you will get an error containing the
  6570. substring \"not supported\".
  6571. The optional C<level> parameter controls compression level. The
  6572. meaning and default for this parameter depends on the compression
  6573. program being used." };
  6574. { defaults with
  6575. name = "compress_device_out";
  6576. style = RErr, [String "ctype"; Device "device"; FileOut "zdevice"], [OInt "level"];
  6577. proc_nr = Some 292;
  6578. cancellable = true;
  6579. shortdesc = "output compressed device";
  6580. longdesc = "\
  6581. This command compresses C<device> and writes it out to the local
  6582. file C<zdevice>.
  6583. The C<ctype> and optional C<level> parameters have the same meaning
  6584. as in C<guestfs_compress_out>." };
  6585. { defaults with
  6586. name = "part_to_partnum";
  6587. style = RInt "partnum", [Device "partition"], [];
  6588. proc_nr = Some 293;
  6589. tests = [
  6590. InitPartition, Always, TestOutputInt (
  6591. [["part_to_partnum"; "/dev/sda1"]], 1);
  6592. InitEmpty, Always, TestLastFail (
  6593. [["part_to_partnum"; "/dev/sda"]])
  6594. ];
  6595. shortdesc = "convert partition name to partition number";
  6596. longdesc = "\
  6597. This function takes a partition name (eg. \"/dev/sdb1\") and
  6598. returns the partition number (eg. C<1>).
  6599. The named partition must exist, for example as a string returned
  6600. from C<guestfs_list_partitions>.
  6601. See also C<guestfs_part_to_dev>." };
  6602. { defaults with
  6603. name = "copy_device_to_device";
  6604. style = RErr, [Device "src"; Device "dest"], [OInt64 "srcoffset"; OInt64 "destoffset"; OInt64 "size"];
  6605. proc_nr = Some 294;
  6606. progress = true;
  6607. shortdesc = "copy from source device to destination device";
  6608. longdesc = "\
  6609. The four calls C<guestfs_copy_device_to_device>,
  6610. C<guestfs_copy_device_to_file>,
  6611. C<guestfs_copy_file_to_device>, and
  6612. C<guestfs_copy_file_to_file>
  6613. let you copy from a source (device|file) to a destination
  6614. (device|file).
  6615. Partial copies can be made since you can specify optionally
  6616. the source offset, destination offset and size to copy. These
  6617. values are all specified in bytes. If not given, the offsets
  6618. both default to zero, and the size defaults to copying as much
  6619. as possible until we hit the end of the source.
  6620. The source and destination may be the same object. However
  6621. overlapping regions may not be copied correctly.
  6622. If the destination is a file, it is created if required. If
  6623. the destination file is not large enough, it is extended." };
  6624. { defaults with
  6625. name = "copy_device_to_file";
  6626. style = RErr, [Device "src"; Pathname "dest"], [OInt64 "srcoffset"; OInt64 "destoffset"; OInt64 "size"];
  6627. proc_nr = Some 295;
  6628. progress = true;
  6629. shortdesc = "copy from source device to destination file";
  6630. longdesc = "\
  6631. See C<guestfs_copy_device_to_device> for a general overview
  6632. of this call." };
  6633. { defaults with
  6634. name = "copy_file_to_device";
  6635. style = RErr, [Pathname "src"; Device "dest"], [OInt64 "srcoffset"; OInt64 "destoffset"; OInt64 "size"];
  6636. proc_nr = Some 296;
  6637. progress = true;
  6638. shortdesc = "copy from source file to destination device";
  6639. longdesc = "\
  6640. See C<guestfs_copy_device_to_device> for a general overview
  6641. of this call." };
  6642. { defaults with
  6643. name = "copy_file_to_file";
  6644. style = RErr, [Pathname "src"; Pathname "dest"], [OInt64 "srcoffset"; OInt64 "destoffset"; OInt64 "size"];
  6645. proc_nr = Some 297;
  6646. progress = true;
  6647. tests = [
  6648. InitScratchFS, Always, TestOutputBuffer (
  6649. [["mkdir"; "/copyff"];
  6650. ["write"; "/copyff/src"; "hello, world"];
  6651. ["copy_file_to_file"; "/copyff/src"; "/copyff/dest"; ""; ""; ""];
  6652. ["read_file"; "/copyff/dest"]], "hello, world")
  6653. ];
  6654. shortdesc = "copy from source file to destination file";
  6655. longdesc = "\
  6656. See C<guestfs_copy_device_to_device> for a general overview
  6657. of this call.
  6658. This is B<not> the function you want for copying files. This
  6659. is for copying blocks within existing files. See C<guestfs_cp>,
  6660. C<guestfs_cp_a> and C<guestfs_mv> for general file copying and
  6661. moving functions." };
  6662. { defaults with
  6663. name = "tune2fs";
  6664. style = RErr, [Device "device"], [OBool "force"; OInt "maxmountcount"; OInt "mountcount"; OString "errorbehavior"; OInt64 "group"; OInt "intervalbetweenchecks"; OInt "reservedblockspercentage"; OString "lastmounteddirectory"; OInt64 "reservedblockscount"; OInt64 "user"];
  6665. proc_nr = Some 298;
  6666. camel_name = "Tune2FS";
  6667. tests = [
  6668. InitScratchFS, Always, TestOutputHashtable (
  6669. [["tune2fs"; "/dev/sdb1"; "false"; "0"; ""; "NOARG"; ""; "0"; ""; "NOARG"; ""; ""];
  6670. ["tune2fs_l"; "/dev/sdb1"]],
  6671. ["Check interval", "0 (<none>)";
  6672. "Maximum mount count", "-1"]);
  6673. InitScratchFS, Always, TestOutputHashtable (
  6674. [["tune2fs"; "/dev/sdb1"; "false"; "0"; ""; "NOARG"; ""; "86400"; ""; "NOARG"; ""; ""];
  6675. ["tune2fs_l"; "/dev/sdb1"]],
  6676. ["Check interval", "86400 (1 day)";
  6677. "Maximum mount count", "-1"]);
  6678. InitScratchFS, Always, TestOutputHashtable (
  6679. [["tune2fs"; "/dev/sdb1"; "false"; ""; ""; "NOARG"; "1"; ""; ""; "NOARG"; ""; "1"];
  6680. ["tune2fs_l"; "/dev/sdb1"]],
  6681. ["Reserved blocks uid", "1 (user bin)";
  6682. "Reserved blocks gid", "1 (group bin)"]);
  6683. InitScratchFS, Always, TestOutputHashtable (
  6684. [["tune2fs"; "/dev/sdb1"; "false"; ""; ""; "NOARG"; "0"; ""; ""; "NOARG"; ""; "0"];
  6685. ["tune2fs_l"; "/dev/sdb1"]],
  6686. ["Reserved blocks uid", "0 (user root)";
  6687. "Reserved blocks gid", "0 (group root)"])
  6688. ];
  6689. shortdesc = "adjust ext2/ext3/ext4 filesystem parameters";
  6690. longdesc = "\
  6691. This call allows you to adjust various filesystem parameters of
  6692. an ext2/ext3/ext4 filesystem called C<device>.
  6693. The optional parameters are:
  6694. =over 4
  6695. =item C<force>
  6696. Force tune2fs to complete the operation even in the face of errors.
  6697. This is the same as the tune2fs C<-f> option.
  6698. =item C<maxmountcount>
  6699. Set the number of mounts after which the filesystem is checked
  6700. by L<e2fsck(8)>. If this is C<0> then the number of mounts is
  6701. disregarded. This is the same as the tune2fs C<-c> option.
  6702. =item C<mountcount>
  6703. Set the number of times the filesystem has been mounted.
  6704. This is the same as the tune2fs C<-C> option.
  6705. =item C<errorbehavior>
  6706. Change the behavior of the kernel code when errors are detected.
  6707. Possible values currently are: C<continue>, C<remount-ro>, C<panic>.
  6708. In practice these options don't really make any difference,
  6709. particularly for write errors.
  6710. This is the same as the tune2fs C<-e> option.
  6711. =item C<group>
  6712. Set the group which can use reserved filesystem blocks.
  6713. This is the same as the tune2fs C<-g> option except that it
  6714. can only be specified as a number.
  6715. =item C<intervalbetweenchecks>
  6716. Adjust the maximal time between two filesystem checks
  6717. (in seconds). If the option is passed as C<0> then
  6718. time-dependent checking is disabled.
  6719. This is the same as the tune2fs C<-i> option.
  6720. =item C<reservedblockspercentage>
  6721. Set the percentage of the filesystem which may only be allocated
  6722. by privileged processes.
  6723. This is the same as the tune2fs C<-m> option.
  6724. =item C<lastmounteddirectory>
  6725. Set the last mounted directory.
  6726. This is the same as the tune2fs C<-M> option.
  6727. =item C<reservedblockscount>
  6728. Set the number of reserved filesystem blocks.
  6729. This is the same as the tune2fs C<-r> option.
  6730. =item C<user>
  6731. Set the user who can use the reserved filesystem blocks.
  6732. This is the same as the tune2fs C<-u> option except that it
  6733. can only be specified as a number.
  6734. =back
  6735. To get the current values of filesystem parameters, see
  6736. C<guestfs_tune2fs_l>. For precise details of how tune2fs
  6737. works, see the L<tune2fs(8)> man page." };
  6738. { defaults with
  6739. name = "md_create";
  6740. style = RErr, [String "name"; DeviceList "devices"], [OInt64 "missingbitmap"; OInt "nrdevices"; OInt "spare"; OInt64 "chunk"; OString "level"];
  6741. proc_nr = Some 299;
  6742. optional = Some "mdadm"; camel_name = "MDCreate";
  6743. shortdesc = "create a Linux md (RAID) device";
  6744. longdesc = "\
  6745. Create a Linux md (RAID) device named C<name> on the devices
  6746. in the list C<devices>.
  6747. The optional parameters are:
  6748. =over 4
  6749. =item C<missingbitmap>
  6750. A bitmap of missing devices. If a bit is set it means that a
  6751. missing device is added to the array. The least significant bit
  6752. corresponds to the first device in the array.
  6753. As examples:
  6754. If C<devices = [\"/dev/sda\"]> and C<missingbitmap = 0x1> then
  6755. the resulting array would be C<[E<lt>missingE<gt>, \"/dev/sda\"]>.
  6756. If C<devices = [\"/dev/sda\"]> and C<missingbitmap = 0x2> then
  6757. the resulting array would be C<[\"/dev/sda\", E<lt>missingE<gt>]>.
  6758. This defaults to C<0> (no missing devices).
  6759. The length of C<devices> + the number of bits set in
  6760. C<missingbitmap> must equal C<nrdevices> + C<spare>.
  6761. =item C<nrdevices>
  6762. The number of active RAID devices.
  6763. If not set, this defaults to the length of C<devices> plus
  6764. the number of bits set in C<missingbitmap>.
  6765. =item C<spare>
  6766. The number of spare devices.
  6767. If not set, this defaults to C<0>.
  6768. =item C<chunk>
  6769. The chunk size in bytes.
  6770. =item C<level>
  6771. The RAID level, which can be one of:
  6772. I<linear>, I<raid0>, I<0>, I<stripe>, I<raid1>, I<1>, I<mirror>,
  6773. I<raid4>, I<4>, I<raid5>, I<5>, I<raid6>, I<6>, I<raid10>, I<10>.
  6774. Some of these are synonymous, and more levels may be added in future.
  6775. If not set, this defaults to C<raid1>.
  6776. =back" };
  6777. { defaults with
  6778. name = "list_md_devices";
  6779. style = RStringList "devices", [], [];
  6780. proc_nr = Some 300;
  6781. shortdesc = "list Linux md (RAID) devices";
  6782. longdesc = "\
  6783. List all Linux md devices." };
  6784. { defaults with
  6785. name = "md_detail";
  6786. style = RHashtable "info", [Device "md"], [];
  6787. proc_nr = Some 301;
  6788. optional = Some "mdadm";
  6789. shortdesc = "obtain metadata for an MD device";
  6790. longdesc = "\
  6791. This command exposes the output of 'mdadm -DY E<lt>mdE<gt>'.
  6792. The following fields are usually present in the returned hash.
  6793. Other fields may also be present.
  6794. =over
  6795. =item C<level>
  6796. The raid level of the MD device.
  6797. =item C<devices>
  6798. The number of underlying devices in the MD device.
  6799. =item C<metadata>
  6800. The metadata version used.
  6801. =item C<uuid>
  6802. The UUID of the MD device.
  6803. =item C<name>
  6804. The name of the MD device.
  6805. =back" };
  6806. { defaults with
  6807. name = "md_stop";
  6808. style = RErr, [Device "md"], [];
  6809. proc_nr = Some 302;
  6810. optional = Some "mdadm";
  6811. shortdesc = "stop a Linux md (RAID) device";
  6812. longdesc = "\
  6813. This command deactivates the MD array named C<md>. The
  6814. device is stopped, but it is not destroyed or zeroed." };
  6815. { defaults with
  6816. name = "blkid";
  6817. style = RHashtable "info", [Device "device"], [];
  6818. proc_nr = Some 303;
  6819. tests = [
  6820. InitScratchFS, Always, TestOutputHashtable (
  6821. [["blkid"; "/dev/sdb1"]],
  6822. ["TYPE", "ext2";
  6823. "USAGE", "filesystem";
  6824. "PART_ENTRY_NUMBER", "1";
  6825. "PART_ENTRY_TYPE", "0x83";
  6826. "PART_ENTRY_OFFSET", "128";
  6827. "PART_ENTRY_SIZE", "102145"])
  6828. ];
  6829. shortdesc = "print block device attributes";
  6830. longdesc = "\
  6831. This command returns block device attributes for C<device>. The following fields are
  6832. usually present in the returned hash. Other fields may also be present.
  6833. =over
  6834. =item C<UUID>
  6835. The uuid of this device.
  6836. =item C<LABEL>
  6837. The label of this device.
  6838. =item C<VERSION>
  6839. The version of blkid command.
  6840. =item C<TYPE>
  6841. The filesystem type or RAID of this device.
  6842. =item C<USAGE>
  6843. The usage of this device, for example C<filesystem> or C<raid>.
  6844. =back" };
  6845. { defaults with
  6846. name = "e2fsck";
  6847. style = RErr, [Device "device"], [OBool "correct"; OBool "forceall"];
  6848. proc_nr = Some 304;
  6849. shortdesc = "check an ext2/ext3 filesystem";
  6850. longdesc = "\
  6851. This runs the ext2/ext3 filesystem checker on C<device>.
  6852. It can take the following optional arguments:
  6853. =over 4
  6854. =item C<correct>
  6855. Automatically repair the file system. This option will cause e2fsck
  6856. to automatically fix any filesystem problems that can be safely
  6857. fixed without human intervention.
  6858. This option may not be specified at the same time as the C<forceall> option.
  6859. =item C<forceall>
  6860. Assume an answer of 'yes' to all questions; allows e2fsck to be used
  6861. non-interactively.
  6862. This option may not be specified at the same time as the C<correct> option.
  6863. =back" };
  6864. { defaults with
  6865. name = "llz";
  6866. style = RString "listing", [Pathname "directory"], [];
  6867. proc_nr = Some 305;
  6868. shortdesc = "list the files in a directory (long format with SELinux contexts)";
  6869. longdesc = "\
  6870. List the files in C<directory> in the format of 'ls -laZ'.
  6871. This command is mostly useful for interactive sessions. It
  6872. is I<not> intended that you try to parse the output string." };
  6873. { defaults with
  6874. name = "wipefs";
  6875. style = RErr, [Device "device"], [];
  6876. proc_nr = Some 306;
  6877. optional = Some "wipefs";
  6878. tests = [
  6879. InitBasicFSonLVM, Always, TestRun (
  6880. [["wipefs"; "/dev/VG/LV"]])
  6881. ];
  6882. shortdesc = "wipe a filesystem signature from a device";
  6883. longdesc = "\
  6884. This command erases filesystem or RAID signatures from
  6885. the specified C<device> to make the filesystem invisible to libblkid.
  6886. This does not erase the filesystem itself nor any other data from the
  6887. C<device>.
  6888. Compare with C<guestfs_zero> which zeroes the first few blocks of a
  6889. device." };
  6890. { defaults with
  6891. name = "ntfsfix";
  6892. style = RErr, [Device "device"], [OBool "clearbadsectors"];
  6893. proc_nr = Some 307;
  6894. optional = Some "ntfs3g";
  6895. tests = [
  6896. InitPartition, IfAvailable "ntfs3g", TestRun (
  6897. [["mkfs"; "ntfs"; "/dev/sda1"; ""; "NOARG"; ""; ""];
  6898. ["ntfsfix"; "/dev/sda1"; "false"]])
  6899. ];
  6900. shortdesc = "fix common errors and force Windows to check NTFS";
  6901. longdesc = "\
  6902. This command repairs some fundamental NTFS inconsistencies,
  6903. resets the NTFS journal file, and schedules an NTFS consistency
  6904. check for the first boot into Windows.
  6905. This is I<not> an equivalent of Windows C<chkdsk>. It does I<not>
  6906. scan the filesystem for inconsistencies.
  6907. The optional C<clearbadsectors> flag clears the list of bad sectors.
  6908. This is useful after cloning a disk with bad sectors to a new disk." };
  6909. { defaults with
  6910. name = "ntfsclone_out";
  6911. style = RErr, [Device "device"; FileOut "backupfile"], [OBool "metadataonly"; OBool "rescue"; OBool "ignorefscheck"; OBool "preservetimestamps"; OBool "force"];
  6912. proc_nr = Some 308;
  6913. optional = Some "ntfs3g"; cancellable = true;
  6914. tests = [] (* tested in tests/ntfsclone *);
  6915. shortdesc = "save NTFS to backup file";
  6916. longdesc = "\
  6917. Stream the NTFS filesystem C<device> to the local file
  6918. C<backupfile>. The format used for the backup file is a
  6919. special format used by the L<ntfsclone(8)> tool.
  6920. If the optional C<metadataonly> flag is true, then I<only> the
  6921. metadata is saved, losing all the user data (this is useful
  6922. for diagnosing some filesystem problems).
  6923. The optional C<rescue>, C<ignorefscheck>, C<preservetimestamps>
  6924. and C<force> flags have precise meanings detailed in the
  6925. L<ntfsclone(8)> man page.
  6926. Use C<guestfs_ntfsclone_in> to restore the file back to a
  6927. libguestfs device." };
  6928. { defaults with
  6929. name = "ntfsclone_in";
  6930. style = RErr, [FileIn "backupfile"; Device "device"], [];
  6931. proc_nr = Some 309;
  6932. optional = Some "ntfs3g"; cancellable = true;
  6933. tests = [] (* tested in tests/ntfsclone *);
  6934. shortdesc = "restore NTFS from backup file";
  6935. longdesc = "\
  6936. Restore the C<backupfile> (from a previous call to
  6937. C<guestfs_ntfsclone_out>) to C<device>, overwriting
  6938. any existing contents of this device." };
  6939. { defaults with
  6940. name = "set_label";
  6941. style = RErr, [Device "device"; String "label"], [];
  6942. proc_nr = Some 310;
  6943. tests = [
  6944. InitBasicFS, Always, TestOutput (
  6945. [["set_label"; "/dev/sda1"; "testlabel"];
  6946. ["vfs_label"; "/dev/sda1"]], "testlabel");
  6947. InitPartition, IfAvailable "ntfs3g", TestOutput (
  6948. [["mkfs"; "ntfs"; "/dev/sda1"; ""; "NOARG"; ""; ""];
  6949. ["set_label"; "/dev/sda1"; "testlabel2"];
  6950. ["vfs_label"; "/dev/sda1"]], "testlabel2");
  6951. InitPartition, Always, TestLastFail (
  6952. [["zero"; "/dev/sda1"];
  6953. ["set_label"; "/dev/sda1"; "testlabel2"]])
  6954. ];
  6955. shortdesc = "set filesystem label";
  6956. longdesc = "\
  6957. Set the filesystem label on C<device> to C<label>.
  6958. Only some filesystem types support labels, and libguestfs supports
  6959. setting labels on only a subset of these.
  6960. On ext2/3/4 filesystems, labels are limited to 16 bytes.
  6961. On NTFS filesystems, labels are limited to 128 unicode characters.
  6962. To read the label on a filesystem, call C<guestfs_vfs_label>." };
  6963. { defaults with
  6964. name = "zero_free_space";
  6965. style = RErr, [Pathname "directory"], [];
  6966. proc_nr = Some 311;
  6967. progress = true;
  6968. tests = [
  6969. InitScratchFS, Always, TestRun (
  6970. [["zero_free_space"; "/"]])
  6971. ];
  6972. shortdesc = "zero free space in a filesystem";
  6973. longdesc = "\
  6974. Zero the free space in the filesystem mounted on C<directory>.
  6975. The filesystem must be mounted read-write.
  6976. The filesystem contents are not affected, but any free space
  6977. in the filesystem is freed.
  6978. Free space is not \"trimmed\". You may want to call
  6979. C<guestfs_fstrim> either as an alternative to this,
  6980. or after calling this, depending on your requirements." };
  6981. { defaults with
  6982. name = "lvcreate_free";
  6983. style = RErr, [String "logvol"; String "volgroup"; Int "percent"], [];
  6984. proc_nr = Some 312;
  6985. optional = Some "lvm2";
  6986. tests = [
  6987. InitEmpty, Always, TestOutputList (
  6988. [["part_disk"; "/dev/sda"; "mbr"];
  6989. ["pvcreate"; "/dev/sda1"];
  6990. ["vgcreate"; "VG"; "/dev/sda1"];
  6991. ["lvcreate_free"; "LV1"; "VG"; "50"];
  6992. ["lvcreate_free"; "LV2"; "VG"; "50"];
  6993. ["lvcreate_free"; "LV3"; "VG"; "50"];
  6994. ["lvcreate_free"; "LV4"; "VG"; "100"];
  6995. ["lvs"]],
  6996. ["/dev/VG/LV1"; "/dev/VG/LV2"; "/dev/VG/LV3"; "/dev/VG/LV4"])
  6997. ];
  6998. shortdesc = "create an LVM logical volume in % remaining free space";
  6999. longdesc = "\
  7000. Create an LVM logical volume called C</dev/volgroup/logvol>,
  7001. using approximately C<percent> % of the free space remaining
  7002. in the volume group. Most usefully, when C<percent> is C<100>
  7003. this will create the largest possible LV." };
  7004. { defaults with
  7005. name = "isoinfo_device";
  7006. style = RStruct ("isodata", "isoinfo"), [Device "device"], [];
  7007. proc_nr = Some 313;
  7008. tests = [
  7009. InitNone, Always, TestOutputStruct (
  7010. [["isoinfo_device"; "/dev/sdd"]],
  7011. [CompareWithString ("iso_system_id", "LINUX");
  7012. CompareWithString ("iso_volume_id", "CDROM");
  7013. CompareWithString ("iso_volume_set_id", "");
  7014. CompareWithInt ("iso_volume_set_size", 1);
  7015. CompareWithInt ("iso_volume_sequence_number", 1);
  7016. CompareWithInt ("iso_logical_block_size", 2048)])
  7017. ];
  7018. shortdesc = "get ISO information from primary volume descriptor of device";
  7019. longdesc = "\
  7020. C<device> is an ISO device. This returns a struct of information
  7021. read from the primary volume descriptor (the ISO equivalent of the
  7022. superblock) of the device.
  7023. Usually it is more efficient to use the L<isoinfo(1)> command
  7024. with the I<-d> option on the host to analyze ISO files,
  7025. instead of going through libguestfs.
  7026. For information on the primary volume descriptor fields, see
  7027. L<http://wiki.osdev.org/ISO_9660#The_Primary_Volume_Descriptor>" };
  7028. { defaults with
  7029. name = "isoinfo";
  7030. style = RStruct ("isodata", "isoinfo"), [Pathname "isofile"], [];
  7031. proc_nr = Some 314;
  7032. shortdesc = "get ISO information from primary volume descriptor of ISO file";
  7033. longdesc = "\
  7034. This is the same as C<guestfs_isoinfo_device> except that it
  7035. works for an ISO file located inside some other mounted filesystem.
  7036. Note that in the common case where you have added an ISO file
  7037. as a libguestfs device, you would I<not> call this. Instead
  7038. you would call C<guestfs_isoinfo_device>." };
  7039. { defaults with
  7040. name = "vgmeta";
  7041. style = RBufferOut "metadata", [String "vgname"], [];
  7042. proc_nr = Some 315;
  7043. optional = Some "lvm2";
  7044. shortdesc = "get volume group metadata";
  7045. longdesc = "\
  7046. C<vgname> is an LVM volume group. This command examines the
  7047. volume group and returns its metadata.
  7048. Note that the metadata is an internal structure used by LVM,
  7049. subject to change at any time, and is provided for information only." };
  7050. { defaults with
  7051. name = "md_stat";
  7052. style = RStructList ("devices", "mdstat"), [Device "md"], [];
  7053. proc_nr = Some 316;
  7054. optional = Some "mdadm";
  7055. shortdesc = "get underlying devices from an MD device";
  7056. longdesc = "\
  7057. This call returns a list of the underlying devices which make
  7058. up the single software RAID array device C<md>.
  7059. To get a list of software RAID devices, call C<guestfs_list_md_devices>.
  7060. Each structure returned corresponds to one device along with
  7061. additional status information:
  7062. =over 4
  7063. =item C<mdstat_device>
  7064. The name of the underlying device.
  7065. =item C<mdstat_index>
  7066. The index of this device within the array.
  7067. =item C<mdstat_flags>
  7068. Flags associated with this device. This is a string containing
  7069. (in no specific order) zero or more of the following flags:
  7070. =over 4
  7071. =item C<W>
  7072. write-mostly
  7073. =item C<F>
  7074. device is faulty
  7075. =item C<S>
  7076. device is a RAID spare
  7077. =item C<R>
  7078. replacement
  7079. =back
  7080. =back" };
  7081. { defaults with
  7082. name = "mkfs_btrfs";
  7083. style = RErr, [DeviceList "devices"], [OInt64 "allocstart"; OInt64 "bytecount"; OString "datatype"; OInt "leafsize"; OString "label"; OString "metadata"; OInt "nodesize"; OInt "sectorsize"];
  7084. proc_nr = Some 317;
  7085. optional = Some "btrfs";
  7086. tests = [
  7087. InitEmpty, Always, TestRun (
  7088. [["part_disk"; "/dev/sda"; "mbr"];
  7089. ["mkfs_btrfs"; "/dev/sda1"; "0"; "268435456"; "single"; "4096"; "test"; "single"; "4096"; "512"]])
  7090. ];
  7091. shortdesc = "create a btrfs filesystem";
  7092. longdesc = "\
  7093. Create a btrfs filesystem, allowing all configurables to be set.
  7094. For more information on the optional arguments, see L<mkfs.btrfs(8)>.
  7095. Since btrfs filesystems can span multiple devices, this takes a
  7096. non-empty list of devices.
  7097. To create general filesystems, use C<guestfs_mkfs>." };
  7098. { defaults with
  7099. name = "get_e2attrs";
  7100. style = RString "attrs", [Pathname "file"], [];
  7101. proc_nr = Some 318;
  7102. tests = [
  7103. InitScratchFS, Always, TestOutput (
  7104. [["touch"; "/e2attrs1"];
  7105. ["get_e2attrs"; "/e2attrs1"]], "");
  7106. InitScratchFS, Always, TestOutput (
  7107. [["touch"; "/e2attrs2"];
  7108. ["set_e2attrs"; "/e2attrs2"; "is"; "false"];
  7109. ["get_e2attrs"; "/e2attrs2"]], "is");
  7110. InitScratchFS, Always, TestOutput (
  7111. [["touch"; "/e2attrs3"];
  7112. ["set_e2attrs"; "/e2attrs3"; "is"; "false"];
  7113. ["set_e2attrs"; "/e2attrs3"; "i"; "true"];
  7114. ["get_e2attrs"; "/e2attrs3"]], "s");
  7115. InitScratchFS, Always, TestOutput (
  7116. [["touch"; "/e2attrs4"];
  7117. ["set_e2attrs"; "/e2attrs4"; "adst"; "false"];
  7118. ["set_e2attrs"; "/e2attrs4"; "iS"; "false"];
  7119. ["set_e2attrs"; "/e2attrs4"; "i"; "true"];
  7120. ["set_e2attrs"; "/e2attrs4"; "ad"; "true"];
  7121. ["set_e2attrs"; "/e2attrs4"; ""; "false"];
  7122. ["set_e2attrs"; "/e2attrs4"; ""; "true"];
  7123. ["get_e2attrs"; "/e2attrs4"]], "Sst");
  7124. InitScratchFS, Always, TestLastFail (
  7125. [["touch"; "/e2attrs5"];
  7126. ["set_e2attrs"; "/e2attrs5"; "R"; "false"]]);
  7127. InitScratchFS, Always, TestLastFail (
  7128. [["touch"; "/e2attrs6"];
  7129. ["set_e2attrs"; "/e2attrs6"; "v"; "false"]]);
  7130. InitScratchFS, Always, TestLastFail (
  7131. [["touch"; "/e2attrs7"];
  7132. ["set_e2attrs"; "/e2attrs7"; "aa"; "false"]]);
  7133. InitScratchFS, Always, TestLastFail (
  7134. [["touch"; "/e2attrs8"];
  7135. ["set_e2attrs"; "/e2attrs8"; "BabcdB"; "false"]])
  7136. ];
  7137. shortdesc = "get ext2 file attributes of a file";
  7138. longdesc = "\
  7139. This returns the file attributes associated with C<file>.
  7140. The attributes are a set of bits associated with each
  7141. inode which affect the behaviour of the file. The attributes
  7142. are returned as a string of letters (described below). The
  7143. string may be empty, indicating that no file attributes are
  7144. set for this file.
  7145. These attributes are only present when the file is located on
  7146. an ext2/3/4 filesystem. Using this call on other filesystem
  7147. types will result in an error.
  7148. The characters (file attributes) in the returned string are
  7149. currently:
  7150. =over 4
  7151. =item 'A'
  7152. When the file is accessed, its atime is not modified.
  7153. =item 'a'
  7154. The file is append-only.
  7155. =item 'c'
  7156. The file is compressed on-disk.
  7157. =item 'D'
  7158. (Directories only.) Changes to this directory are written
  7159. synchronously to disk.
  7160. =item 'd'
  7161. The file is not a candidate for backup (see L<dump(8)>).
  7162. =item 'E'
  7163. The file has compression errors.
  7164. =item 'e'
  7165. The file is using extents.
  7166. =item 'h'
  7167. The file is storing its blocks in units of the filesystem blocksize
  7168. instead of sectors.
  7169. =item 'I'
  7170. (Directories only.) The directory is using hashed trees.
  7171. =item 'i'
  7172. The file is immutable. It cannot be modified, deleted or renamed.
  7173. No link can be created to this file.
  7174. =item 'j'
  7175. The file is data-journaled.
  7176. =item 's'
  7177. When the file is deleted, all its blocks will be zeroed.
  7178. =item 'S'
  7179. Changes to this file are written synchronously to disk.
  7180. =item 'T'
  7181. (Directories only.) This is a hint to the block allocator
  7182. that subdirectories contained in this directory should be
  7183. spread across blocks. If not present, the block allocator
  7184. will try to group subdirectories together.
  7185. =item 't'
  7186. For a file, this disables tail-merging.
  7187. (Not used by upstream implementations of ext2.)
  7188. =item 'u'
  7189. When the file is deleted, its blocks will be saved, allowing
  7190. the file to be undeleted.
  7191. =item 'X'
  7192. The raw contents of the compressed file may be accessed.
  7193. =item 'Z'
  7194. The compressed file is dirty.
  7195. =back
  7196. More file attributes may be added to this list later. Not all
  7197. file attributes may be set for all kinds of files. For
  7198. detailed information, consult the L<chattr(1)> man page.
  7199. See also C<guestfs_set_e2attrs>.
  7200. Don't confuse these attributes with extended attributes
  7201. (see C<guestfs_getxattr>)." };
  7202. { defaults with
  7203. name = "set_e2attrs";
  7204. style = RErr, [Pathname "file"; String "attrs"], [OBool "clear"];
  7205. proc_nr = Some 319;
  7206. shortdesc = "set ext2 file attributes of a file";
  7207. longdesc = "\
  7208. This sets or clears the file attributes C<attrs>
  7209. associated with the inode C<file>.
  7210. C<attrs> is a string of characters representing
  7211. file attributes. See C<guestfs_get_e2attrs> for a list of
  7212. possible attributes. Not all attributes can be changed.
  7213. If optional boolean C<clear> is not present or false, then
  7214. the C<attrs> listed are set in the inode.
  7215. If C<clear> is true, then the C<attrs> listed are cleared
  7216. in the inode.
  7217. In both cases, other attributes not present in the C<attrs>
  7218. string are left unchanged.
  7219. These attributes are only present when the file is located on
  7220. an ext2/3/4 filesystem. Using this call on other filesystem
  7221. types will result in an error." };
  7222. { defaults with
  7223. name = "get_e2generation";
  7224. style = RInt64 "generation", [Pathname "file"], [];
  7225. proc_nr = Some 320;
  7226. tests = [
  7227. InitScratchFS, Always, TestOutputInt (
  7228. [["touch"; "/e2generation"];
  7229. ["set_e2generation"; "/e2generation"; "123456"];
  7230. ["get_e2generation"; "/e2generation"]], 123456)
  7231. ];
  7232. shortdesc = "get ext2 file generation of a file";
  7233. longdesc = "\
  7234. This returns the ext2 file generation of a file. The generation
  7235. (which used to be called the \"version\") is a number associated
  7236. with an inode. This is most commonly used by NFS servers.
  7237. The generation is only present when the file is located on
  7238. an ext2/3/4 filesystem. Using this call on other filesystem
  7239. types will result in an error.
  7240. See C<guestfs_set_e2generation>." };
  7241. { defaults with
  7242. name = "set_e2generation";
  7243. style = RErr, [Pathname "file"; Int64 "generation"], [];
  7244. proc_nr = Some 321;
  7245. shortdesc = "set ext2 file generation of a file";
  7246. longdesc = "\
  7247. This sets the ext2 file generation of a file.
  7248. See C<guestfs_get_e2generation>." };
  7249. { defaults with
  7250. name = "btrfs_subvolume_snapshot";
  7251. style = RErr, [Pathname "source"; Pathname "dest"], [];
  7252. proc_nr = Some 322;
  7253. optional = Some "btrfs"; camel_name = "BTRFSSubvolumeSnapshot";
  7254. tests = [
  7255. InitPartition, IfAvailable "btrfs", TestRun (
  7256. [["mkfs_btrfs"; "/dev/sda1"; ""; ""; "NOARG"; ""; "NOARG"; "NOARG"; ""; ""];
  7257. ["mount"; "/dev/sda1"; "/"];
  7258. ["mkdir"; "/dir"];
  7259. ["btrfs_subvolume_create"; "/test1"];
  7260. ["btrfs_subvolume_create"; "/test2"];
  7261. ["btrfs_subvolume_create"; "/dir/test3"];
  7262. ["btrfs_subvolume_snapshot"; "/dir/test3"; "/dir/test4"]])
  7263. ];
  7264. shortdesc = "create a writable btrfs snapshot";
  7265. longdesc = "\
  7266. Create a writable snapshot of the btrfs subvolume C<source>.
  7267. The C<dest> argument is the destination directory and the name
  7268. of the snapshot, in the form C</path/to/dest/name>." };
  7269. { defaults with
  7270. name = "btrfs_subvolume_delete";
  7271. style = RErr, [Pathname "subvolume"], [];
  7272. proc_nr = Some 323;
  7273. optional = Some "btrfs"; camel_name = "BTRFSSubvolumeDelete";
  7274. tests = [
  7275. InitPartition, IfAvailable "btrfs", TestRun (
  7276. [["mkfs_btrfs"; "/dev/sda1"; ""; ""; "NOARG"; ""; "NOARG"; "NOARG"; ""; ""];
  7277. ["mount"; "/dev/sda1"; "/"];
  7278. ["btrfs_subvolume_create"; "/test1"];
  7279. ["btrfs_subvolume_delete"; "/test1"]])
  7280. ];
  7281. shortdesc = "delete a btrfs snapshot";
  7282. longdesc = "\
  7283. Delete the named btrfs subvolume." };
  7284. { defaults with
  7285. name = "btrfs_subvolume_create";
  7286. style = RErr, [Pathname "dest"], [];
  7287. proc_nr = Some 324;
  7288. optional = Some "btrfs"; camel_name = "BTRFSSubvolumeCreate";
  7289. shortdesc = "create a btrfs snapshot";
  7290. longdesc = "\
  7291. Create a btrfs subvolume. The C<dest> argument is the destination
  7292. directory and the name of the snapshot, in the form C</path/to/dest/name>." };
  7293. { defaults with
  7294. name = "btrfs_subvolume_list";
  7295. style = RStructList ("subvolumes", "btrfssubvolume"), [Pathname "fs"], [];
  7296. proc_nr = Some 325;
  7297. optional = Some "btrfs"; camel_name = "BTRFSSubvolumeList";
  7298. tests = [] (* tested in tests/btrfs *);
  7299. shortdesc = "list btrfs snapshots and subvolumes";
  7300. longdesc = "\
  7301. List the btrfs snapshots and subvolumes of the btrfs filesystem
  7302. which is mounted at C<fs>." };
  7303. { defaults with
  7304. name = "btrfs_subvolume_set_default";
  7305. style = RErr, [Int64 "id"; Pathname "fs"], [];
  7306. proc_nr = Some 326;
  7307. optional = Some "btrfs"; camel_name = "BTRFSSubvolumeSetDefault";
  7308. tests = [] (* tested in tests/btrfs *);
  7309. shortdesc = "set default btrfs subvolume";
  7310. longdesc = "\
  7311. Set the subvolume of the btrfs filesystem C<fs> which will
  7312. be mounted by default. See C<guestfs_btrfs_subvolume_list> to
  7313. get a list of subvolumes." };
  7314. { defaults with
  7315. name = "btrfs_filesystem_sync";
  7316. style = RErr, [Pathname "fs"], [];
  7317. proc_nr = Some 327;
  7318. optional = Some "btrfs"; camel_name = "BTRFSFilesystemSync";
  7319. tests = [
  7320. InitPartition, IfAvailable "btrfs", TestRun (
  7321. [["mkfs_btrfs"; "/dev/sda1"; ""; ""; "NOARG"; ""; "NOARG"; "NOARG"; ""; ""];
  7322. ["mount"; "/dev/sda1"; "/"];
  7323. ["btrfs_subvolume_create"; "/test1"];
  7324. ["btrfs_filesystem_sync"; "/test1"];
  7325. ["btrfs_filesystem_balance"; "/test1"]])
  7326. ];
  7327. shortdesc = "sync a btrfs filesystem";
  7328. longdesc = "\
  7329. Force sync on the btrfs filesystem mounted at C<fs>." };
  7330. { defaults with
  7331. name = "btrfs_filesystem_balance";
  7332. style = RErr, [Pathname "fs"], [];
  7333. proc_nr = Some 328;
  7334. optional = Some "btrfs"; camel_name = "BTRFSFilesystemBalance";
  7335. shortdesc = "balance a btrfs filesystem";
  7336. longdesc = "\
  7337. Balance the chunks in the btrfs filesystem mounted at C<fs>
  7338. across the underlying devices." };
  7339. { defaults with
  7340. name = "btrfs_device_add";
  7341. style = RErr, [DeviceList "devices"; Pathname "fs"], [];
  7342. proc_nr = Some 329;
  7343. optional = Some "btrfs"; camel_name = "BTRFSDeviceAdd";
  7344. tests = [] (* test disk isn't large enough to test this
  7345. thoroughly, so there is an external test in
  7346. 'tests/btrfs' directory. *);
  7347. shortdesc = "add devices to a btrfs filesystem";
  7348. longdesc = "\
  7349. Add the list of device(s) in C<devices> to the btrfs filesystem
  7350. mounted at C<fs>. If C<devices> is an empty list, this does nothing." };
  7351. { defaults with
  7352. name = "btrfs_device_delete";
  7353. style = RErr, [DeviceList "devices"; Pathname "fs"], [];
  7354. proc_nr = Some 330;
  7355. optional = Some "btrfs"; camel_name = "BTRFSDeviceDelete";
  7356. tests = [] (* test disk isn't large enough to test this
  7357. thoroughly, so there is an external test in
  7358. 'tests/btrfs' directory. *);
  7359. shortdesc = "remove devices from a btrfs filesystem";
  7360. longdesc = "\
  7361. Remove the C<devices> from the btrfs filesystem mounted at C<fs>.
  7362. If C<devices> is an empty list, this does nothing." };
  7363. { defaults with
  7364. name = "btrfs_set_seeding";
  7365. style = RErr, [Device "device"; Bool "seeding"], [];
  7366. proc_nr = Some 331;
  7367. optional = Some "btrfs";
  7368. tests = [
  7369. InitPartition, IfAvailable "btrfs", TestRun (
  7370. [["mkfs_btrfs"; "/dev/sda1"; ""; ""; "NOARG"; ""; "NOARG"; "NOARG"; ""; ""];
  7371. ["btrfs_set_seeding"; "/dev/sda1"; "true"];
  7372. ["btrfs_set_seeding"; "/dev/sda1"; "false"]])
  7373. ];
  7374. shortdesc = "enable or disable the seeding feature of device";
  7375. longdesc = "\
  7376. Enable or disable the seeding feature of a device that contains
  7377. a btrfs filesystem." };
  7378. { defaults with
  7379. name = "btrfs_fsck";
  7380. style = RErr, [Device "device"], [OInt64 "superblock"; OBool "repair"];
  7381. proc_nr = Some 332;
  7382. optional = Some "btrfs";
  7383. tests = [
  7384. InitPartition, IfAvailable "btrfs", TestRun (
  7385. [["mkfs_btrfs"; "/dev/sda1"; ""; ""; "NOARG"; ""; "NOARG"; "NOARG"; ""; ""];
  7386. ["btrfs_fsck"; "/dev/sda1"; ""; ""]])
  7387. ];
  7388. shortdesc = "check a btrfs filesystem";
  7389. longdesc = "\
  7390. Used to check a btrfs filesystem, C<device> is the device file where the
  7391. filesystem is stored." };
  7392. { defaults with
  7393. name = "filesystem_available";
  7394. style = RBool "fsavail", [String "filesystem"], [];
  7395. proc_nr = Some 333;
  7396. shortdesc = "check if filesystem is available";
  7397. longdesc = "\
  7398. Check whether libguestfs supports the named filesystem.
  7399. The argument C<filesystem> is a filesystem name, such as
  7400. C<ext3>.
  7401. You must call C<guestfs_launch> before using this command.
  7402. This is mainly useful as a negative test. If this returns true,
  7403. it doesn't mean that a particular filesystem can be mounted,
  7404. since filesystems can fail for other reasons such as it being
  7405. a later version of the filesystem, or having incompatible features.
  7406. See also C<guestfs_available>, L<guestfs(3)/AVAILABILITY>." };
  7407. { defaults with
  7408. name = "fstrim";
  7409. style = RErr, [Pathname "mountpoint"], [OInt64 "offset"; OInt64 "length"; OInt64 "minimumfreeextent"];
  7410. proc_nr = Some 334;
  7411. optional = Some "fstrim";
  7412. shortdesc = "trim free space in a filesystem";
  7413. longdesc = "\
  7414. Trim the free space in the filesystem mounted on C<mountpoint>.
  7415. The filesystem must be mounted read-write.
  7416. The filesystem contents are not affected, but any free space
  7417. in the filesystem is \"trimmed\", that is, given back to the host
  7418. device, thus making disk images more sparse, allowing unused space
  7419. in qcow2 files to be reused, etc.
  7420. This operation requires support in libguestfs, the mounted
  7421. filesystem, the host filesystem, qemu and the host kernel.
  7422. If this support isn't present it may give an error or even
  7423. appear to run but do nothing.
  7424. See also C<guestfs_zero_free_space>. That is a slightly
  7425. different operation that turns free space in the filesystem
  7426. into zeroes. It is valid to call C<guestfs_fstrim> either
  7427. instead of, or after calling C<guestfs_zero_free_space>." };
  7428. { defaults with
  7429. name = "device_index";
  7430. style = RInt "index", [Device "device"], [];
  7431. proc_nr = Some 335;
  7432. tests = [
  7433. InitEmpty, Always, TestOutputInt (
  7434. [["device_index"; "/dev/sda"]], 0)
  7435. ];
  7436. shortdesc = "convert device to index";
  7437. longdesc = "\
  7438. This function takes a device name (eg. \"/dev/sdb\") and
  7439. returns the index of the device in the list of devices.
  7440. Index numbers start from 0. The named device must exist,
  7441. for example as a string returned from C<guestfs_list_devices>.
  7442. See also C<guestfs_list_devices>, C<guestfs_part_to_dev>." };
  7443. { defaults with
  7444. name = "nr_devices";
  7445. style = RInt "nrdisks", [], [];
  7446. proc_nr = Some 336;
  7447. tests = [
  7448. InitEmpty, Always, TestOutputInt (
  7449. [["nr_devices"]], 4)
  7450. ];
  7451. shortdesc = "return number of whole block devices (disks) added";
  7452. longdesc = "\
  7453. This returns the number of whole block devices that were
  7454. added. This is the same as the number of devices that would
  7455. be returned if you called C<guestfs_list_devices>.
  7456. To find out the maximum number of devices that could be added,
  7457. call C<guestfs_max_disks>." };
  7458. { defaults with
  7459. name = "xfs_info";
  7460. style = RStruct ("info", "xfsinfo"), [Pathname "path"], [];
  7461. proc_nr = Some 337;
  7462. optional = Some "xfs";
  7463. tests = [
  7464. InitEmpty, IfAvailable "xfs", TestOutputStruct (
  7465. [["part_disk"; "/dev/sda"; "mbr"];
  7466. ["mkfs"; "xfs"; "/dev/sda1"; ""; "NOARG"; ""; ""];
  7467. ["mount_options"; ""; "/dev/sda1"; "/"];
  7468. ["xfs_info"; "/"]],
  7469. [CompareWithInt ("xfs_blocksize", 4096);
  7470. ])
  7471. ];
  7472. shortdesc = "get geometry of XFS filesystem";
  7473. longdesc = "\
  7474. C<path> is a mounted XFS filesystem. This command returns the
  7475. geometry of the filesystem.
  7476. The returned struct contains geometry information. Missing
  7477. fields are returned as C<-1> (for numeric fields) or empty
  7478. string." };
  7479. ]
  7480. (* Non-API meta-commands available only in guestfish.
  7481. *
  7482. * Note (1): The only fields which are actually used are the
  7483. * shortname, fish_alias, shortdesc and longdesc.
  7484. *
  7485. * Note (2): to refer to other commands, use L</shortname>.
  7486. *
  7487. * Note (3): keep this list sorted by shortname.
  7488. *)
  7489. let fish_commands = [
  7490. { defaults with
  7491. name = "alloc";
  7492. fish_alias = ["allocate"];
  7493. shortdesc = "allocate and add a disk file";
  7494. longdesc = " alloc filename size
  7495. This creates an empty (zeroed) file of the given size, and then adds
  7496. so it can be further examined.
  7497. For more advanced image creation, see L<qemu-img(1)> utility.
  7498. Size can be specified using standard suffixes, eg. C<1M>.
  7499. To create a sparse file, use L</sparse> instead. To create a
  7500. prepared disk image, see L</PREPARED DISK IMAGES>." };
  7501. { defaults with
  7502. name = "copy_in";
  7503. shortdesc = "copy local files or directories into an image";
  7504. longdesc = " copy-in local [local ...] /remotedir
  7505. C<copy-in> copies local files or directories recursively into the disk
  7506. image, placing them in the directory called C</remotedir> (which must
  7507. exist). This guestfish meta-command turns into a sequence of
  7508. L</tar-in> and other commands as necessary.
  7509. Multiple local files and directories can be specified, but the last
  7510. parameter must always be a remote directory. Wildcards cannot be
  7511. used." };
  7512. { defaults with
  7513. name = "copy_out";
  7514. shortdesc = "copy remote files or directories out of an image";
  7515. longdesc = " copy-out remote [remote ...] localdir
  7516. C<copy-out> copies remote files or directories recursively out of the
  7517. disk image, placing them on the host disk in a local directory called
  7518. C<localdir> (which must exist). This guestfish meta-command turns
  7519. into a sequence of L</download>, L</tar-out> and other commands as
  7520. necessary.
  7521. Multiple remote files and directories can be specified, but the last
  7522. parameter must always be a local directory. To download to the
  7523. current directory, use C<.> as in:
  7524. copy-out /home .
  7525. Wildcards cannot be used in the ordinary command, but you can use
  7526. them with the help of L</glob> like this:
  7527. glob copy-out /home/* ." };
  7528. { defaults with
  7529. name = "delete_event";
  7530. shortdesc = "delete a previously registered event handler";
  7531. longdesc = " delete-event name
  7532. Delete the event handler which was previously registered as C<name>.
  7533. If multiple event handlers were registered with the same name, they
  7534. are all deleted.
  7535. See also the guestfish commands C<event> and C<list-events>." };
  7536. { defaults with
  7537. name = "display";
  7538. shortdesc = "display an image";
  7539. longdesc = " display filename
  7540. Use C<display> (a graphical display program) to display an image
  7541. file. It downloads the file, and runs C<display> on it.
  7542. To use an alternative program, set the C<GUESTFISH_DISPLAY_IMAGE>
  7543. environment variable. For example to use the GNOME display program:
  7544. export GUESTFISH_DISPLAY_IMAGE=eog
  7545. See also L<display(1)>." };
  7546. { defaults with
  7547. name = "echo";
  7548. shortdesc = "display a line of text";
  7549. longdesc = " echo [params ...]
  7550. This echos the parameters to the terminal." };
  7551. { defaults with
  7552. name = "edit";
  7553. fish_alias = ["vi"; "emacs"];
  7554. shortdesc = "edit a file";
  7555. longdesc = " edit filename
  7556. This is used to edit a file. It downloads the file, edits it
  7557. locally using your editor, then uploads the result.
  7558. The editor is C<$EDITOR>. However if you use the alternate
  7559. commands C<vi> or C<emacs> you will get those corresponding
  7560. editors." };
  7561. { defaults with
  7562. name = "event";
  7563. shortdesc = "register a handler for an event or events";
  7564. longdesc = " event name eventset \"shell script ...\"
  7565. Register a shell script fragment which is executed when an
  7566. event is raised. See L<guestfs(3)/guestfs_set_event_callback>
  7567. for a discussion of the event API in libguestfs.
  7568. The C<name> parameter is a name that you give to this event
  7569. handler. It can be any string (even the empty string) and is
  7570. simply there so you can delete the handler using the guestfish
  7571. C<delete-event> command.
  7572. The C<eventset> parameter is a comma-separated list of one
  7573. or more events, for example C<close> or C<close,trace>. The
  7574. special value C<*> means all events.
  7575. The third and final parameter is the shell script fragment
  7576. (or any external command) that is executed when any of the
  7577. events in the eventset occurs. It is executed using
  7578. C<$SHELL -c>, or if C<$SHELL> is not set then C</bin/sh -c>.
  7579. The shell script fragment receives callback parameters as
  7580. arguments C<$1>, C<$2> etc. The actual event that was
  7581. called is available in the environment variable C<$EVENT>.
  7582. event \"\" close \"echo closed\"
  7583. event messages appliance,library,trace \"echo $@\"
  7584. event \"\" progress \"echo progress: $3/$4\"
  7585. event \"\" * \"echo $EVENT $@\"
  7586. See also the guestfish commands C<delete-event> and C<list-events>." };
  7587. { defaults with
  7588. name = "glob";
  7589. shortdesc = "expand wildcards in command";
  7590. longdesc = " glob command args...
  7591. Expand wildcards in any paths in the args list, and run C<command>
  7592. repeatedly on each matching path.
  7593. See L</WILDCARDS AND GLOBBING>." };
  7594. { defaults with
  7595. name = "hexedit";
  7596. shortdesc = "edit with a hex editor";
  7597. longdesc = " hexedit <filename|device>
  7598. hexedit <filename|device> <max>
  7599. hexedit <filename|device> <start> <max>
  7600. Use hexedit (a hex editor) to edit all or part of a binary file
  7601. or block device.
  7602. This command works by downloading potentially the whole file or
  7603. device, editing it locally, then uploading it. If the file or
  7604. device is large, you have to specify which part you wish to edit
  7605. by using C<max> and/or C<start> C<max> parameters.
  7606. C<start> and C<max> are specified in bytes, with the usual
  7607. modifiers allowed such as C<1M> (1 megabyte).
  7608. For example to edit the first few sectors of a disk you
  7609. might do:
  7610. hexedit /dev/sda 1M
  7611. which would allow you to edit anywhere within the first megabyte
  7612. of the disk.
  7613. To edit the superblock of an ext2 filesystem on C</dev/sda1>, do:
  7614. hexedit /dev/sda1 0x400 0x400
  7615. (assuming the superblock is in the standard location).
  7616. This command requires the external L<hexedit(1)> program. You
  7617. can specify another program to use by setting the C<HEXEDITOR>
  7618. environment variable.
  7619. See also L</hexdump>." };
  7620. { defaults with
  7621. name = "lcd";
  7622. shortdesc = "change working directory";
  7623. longdesc = " lcd directory
  7624. Change the local directory, ie. the current directory of guestfish
  7625. itself.
  7626. Note that C<!cd> won't do what you might expect." };
  7627. { defaults with
  7628. name = "list_events";
  7629. shortdesc = "list event handlers";
  7630. longdesc = " list-events
  7631. List the event handlers registered using the guestfish
  7632. C<event> command." };
  7633. { defaults with
  7634. name = "man";
  7635. fish_alias = ["manual"];
  7636. shortdesc = "open the manual";
  7637. longdesc = " man
  7638. Opens the manual page for guestfish." };
  7639. { defaults with
  7640. name = "more";
  7641. fish_alias = ["less"];
  7642. shortdesc = "view a file";
  7643. longdesc = " more filename
  7644. less filename
  7645. This is used to view a file.
  7646. The default viewer is C<$PAGER>. However if you use the alternate
  7647. command C<less> you will get the C<less> command specifically." };
  7648. { defaults with
  7649. name = "reopen";
  7650. shortdesc = "close and reopen libguestfs handle";
  7651. longdesc = " reopen
  7652. Close and reopen the libguestfs handle. It is not necessary to use
  7653. this normally, because the handle is closed properly when guestfish
  7654. exits. However this is occasionally useful for testing." };
  7655. { defaults with
  7656. name = "setenv";
  7657. shortdesc = "set an environment variable";
  7658. longdesc = " setenv VAR value
  7659. Set the environment variable C<VAR> to the string C<value>.
  7660. To print the value of an environment variable use a shell command
  7661. such as:
  7662. !echo $VAR" };
  7663. { defaults with
  7664. name = "sparse";
  7665. shortdesc = "create a sparse disk image and add";
  7666. longdesc = " sparse filename size
  7667. This creates an empty sparse file of the given size, and then adds
  7668. so it can be further examined.
  7669. In all respects it works the same as the L</alloc> command, except that
  7670. the image file is allocated sparsely, which means that disk blocks are
  7671. not assigned to the file until they are needed. Sparse disk files
  7672. only use space when written to, but they are slower and there is a
  7673. danger you could run out of real disk space during a write operation.
  7674. For more advanced image creation, see L<qemu-img(1)> utility.
  7675. Size can be specified using standard suffixes, eg. C<1M>." };
  7676. { defaults with
  7677. name = "supported";
  7678. shortdesc = "list supported groups of commands";
  7679. longdesc = " supported
  7680. This command returns a list of the optional groups
  7681. known to the daemon, and indicates which ones are
  7682. supported by this build of the libguestfs appliance.
  7683. See also L<guestfs(3)/AVAILABILITY>." };
  7684. { defaults with
  7685. name = "time";
  7686. shortdesc = "print elapsed time taken to run a command";
  7687. longdesc = " time command args...
  7688. Run the command as usual, but print the elapsed time afterwards. This
  7689. can be useful for benchmarking operations." };
  7690. { defaults with
  7691. name = "unsetenv";
  7692. shortdesc = "unset an environment variable";
  7693. longdesc = " unsetenv VAR
  7694. Remove C<VAR> from the environment." };
  7695. ]
  7696. (*----------------------------------------------------------------------*)
  7697. (* Some post-processing of the basic lists of actions. *)
  7698. (* Add the name of the C function:
  7699. * c_name = short name, used by C bindings so we know what to export
  7700. * c_function = full name that non-C bindings should call
  7701. * c_optarg_prefix = prefix for optarg / bitmask names
  7702. *)
  7703. let non_daemon_functions, daemon_functions =
  7704. let make_c_function f =
  7705. match f with
  7706. | { style = _, _, [] } ->
  7707. { f with
  7708. c_name = f.name;
  7709. c_function = "guestfs_" ^ f.name;
  7710. c_optarg_prefix = "GUESTFS_" ^ String.uppercase f.name }
  7711. | { style = _, _, (_::_); once_had_no_optargs = false } ->
  7712. { f with
  7713. c_name = f.name;
  7714. c_function = "guestfs_" ^ f.name ^ "_argv";
  7715. c_optarg_prefix = "GUESTFS_" ^ String.uppercase f.name }
  7716. | { style = _, _, (_::_); once_had_no_optargs = true } ->
  7717. { f with
  7718. c_name = f.name ^ "_opts";
  7719. c_function = "guestfs_" ^ f.name ^ "_opts_argv";
  7720. c_optarg_prefix = "GUESTFS_" ^ String.uppercase f.name ^ "_OPTS";
  7721. non_c_aliases = [ f.name ^ "_opts" ] }
  7722. in
  7723. let non_daemon_functions = List.map make_c_function non_daemon_functions in
  7724. let daemon_functions = List.map make_c_function daemon_functions in
  7725. non_daemon_functions, daemon_functions
  7726. (* Create a camel-case version of each name, unless the camel_name
  7727. * field was set above.
  7728. *)
  7729. let non_daemon_functions, daemon_functions =
  7730. let make_camel_case name =
  7731. List.fold_left (
  7732. fun a b ->
  7733. a ^ String.uppercase (Str.first_chars b 1) ^ Str.string_after b 1
  7734. ) "" (Str.split (Str.regexp "_") name)
  7735. in
  7736. let make_camel_case_if_not_set f =
  7737. if f.camel_name = "" then
  7738. { f with camel_name = make_camel_case f.name }
  7739. else
  7740. f
  7741. in
  7742. let non_daemon_functions =
  7743. List.map make_camel_case_if_not_set non_daemon_functions in
  7744. let daemon_functions =
  7745. List.map make_camel_case_if_not_set daemon_functions in
  7746. non_daemon_functions, daemon_functions
  7747. (* All functions. *)
  7748. let all_functions = non_daemon_functions @ daemon_functions
  7749. (* In some places we want the functions to be displayed sorted
  7750. * alphabetically, so this is useful:
  7751. *)
  7752. let all_functions_sorted = List.sort action_compare all_functions
  7753. (* This is used to generate the src/MAX_PROC_NR file which
  7754. * contains the maximum procedure number, a surrogate for the
  7755. * ABI version number. See src/Makefile.am for the details.
  7756. *)
  7757. let max_proc_nr =
  7758. let proc_nrs = List.map (
  7759. function { proc_nr = Some n } -> n | { proc_nr = None } -> 0
  7760. ) daemon_functions in
  7761. List.fold_left max 0 proc_nrs