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 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 <ipxe/timer.h>
  26. #include <ipxe/pending.h>
  27. /** @file
  28. *
  29. * "sync" command
  30. *
  31. */
  32. /** "sync" options */
  33. struct sync_options {
  34. /** Timeout */
  35. unsigned int timeout;
  36. };
  37. /** "sync" option list */
  38. static struct option_descriptor sync_opts[] = {
  39. OPTION_DESC ( "timeout", 't', required_argument,
  40. struct sync_options, timeout, parse_integer ),
  41. };
  42. /** "sync" command descriptor */
  43. static struct command_descriptor sync_cmd =
  44. COMMAND_DESC ( struct sync_options, sync_opts, 0, 0,
  45. "[--timeout <timeout>]" );
  46. /**
  47. * "sync" command
  48. *
  49. * @v argc Argument count
  50. * @v argv Argument list
  51. * @ret rc Return status code
  52. */
  53. static int sync_exec ( int argc, char **argv ) {
  54. struct sync_options opts;
  55. unsigned long timeout;
  56. int rc;
  57. /* Parse options */
  58. if ( ( rc = parse_options ( argc, argv, &sync_cmd, &opts ) ) != 0 )
  59. return rc;
  60. /* Wait for pending operations to complete */
  61. timeout = ( ( opts.timeout * TICKS_PER_SEC ) / 1000 );
  62. if ( ( rc = pending_wait ( timeout ) ) != 0 ) {
  63. printf ( "Operations did not complete: %s\n", strerror ( rc ) );
  64. return rc;
  65. }
  66. return 0;
  67. }
  68. /** Sync commands */
  69. struct command sync_command __command = {
  70. .name = "sync",
  71. .exec = sync_exec,
  72. };