You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

sync_cmd.c 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright (C) 2012 Michael Brown <mbrown@fensystems.co.uk>.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of the
  7. * License, or any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * 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
  17. * 02110-1301, USA.
  18. */
  19. FILE_LICENCE ( GPL2_OR_LATER );
  20. #include <string.h>
  21. #include <stdio.h>
  22. #include <getopt.h>
  23. #include <ipxe/command.h>
  24. #include <ipxe/parseopt.h>
  25. #include <usr/sync.h>
  26. /** @file
  27. *
  28. * "sync" command
  29. *
  30. */
  31. /** "sync" options */
  32. struct sync_options {
  33. /** Timeout */
  34. unsigned long timeout;
  35. };
  36. /** "sync" option list */
  37. static struct option_descriptor sync_opts[] = {
  38. OPTION_DESC ( "timeout", 't', required_argument,
  39. struct sync_options, timeout, parse_timeout ),
  40. };
  41. /** "sync" command descriptor */
  42. static struct command_descriptor sync_cmd =
  43. COMMAND_DESC ( struct sync_options, sync_opts, 0, 0, NULL );
  44. /**
  45. * "sync" command
  46. *
  47. * @v argc Argument count
  48. * @v argv Argument list
  49. * @ret rc Return status code
  50. */
  51. static int sync_exec ( int argc, char **argv ) {
  52. struct sync_options opts;
  53. int rc;
  54. /* Parse options */
  55. if ( ( rc = parse_options ( argc, argv, &sync_cmd, &opts ) ) != 0 )
  56. return rc;
  57. /* Wait for pending operations to complete */
  58. if ( ( rc = sync ( opts.timeout ) ) != 0 ) {
  59. printf ( "Operations did not complete: %s\n", strerror ( rc ) );
  60. return rc;
  61. }
  62. return 0;
  63. }
  64. /** Sync commands */
  65. struct command sync_command __command = {
  66. .name = "sync",
  67. .exec = sync_exec,
  68. };