Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:19

0001 /**
0002  * @file
0003  * 
0004  * @brief RM Shell Command Implmentation
0005  */
0006 
0007 /*
0008  * Copyright (c) 2001 Fernando Ruiz Casas <fruizcasas@gmail.com>
0009  *
0010  *  The license and distribution terms for this file may be
0011  *  found in the file LICENSE in this distribution or at
0012  *  http://www.rtems.org/license/LICENSE.
0013  */
0014 
0015 #ifdef HAVE_CONFIG_H
0016 #include "config.h"
0017 #endif
0018 
0019 #include <stdio.h>
0020 #include <unistd.h>
0021 #include <string.h>
0022 #include <errno.h>
0023 #include <fcntl.h>
0024 
0025 #include <rtems.h>
0026 #include <rtems/shell.h>
0027 #include <rtems/bdbuf.h>
0028 #include <rtems/blkdev.h>
0029 #include "internal.h"
0030 
0031 static int rtems_shell_main_blksync(
0032   int argc,
0033   char *argv[]
0034 )
0035 {
0036   const char* driver = NULL;
0037   int         arg;
0038   int         fd;
0039 
0040   for (arg = 1; arg < argc; arg++) {
0041     if (argv[arg][0] == '-') {
0042       fprintf( stderr, "%s: invalid option: %s\n", argv[0], argv[arg]);
0043       return 1;
0044     } else {
0045       if (!driver)
0046         driver = argv[arg];
0047       else {
0048         fprintf( stderr, "%s: only one driver name allowed: %s\n",
0049           argv[0], argv[arg]);
0050         return 1;
0051       }
0052     }
0053   }
0054 
0055   fd = open (driver, O_WRONLY, 0);
0056   if (fd < 0) {
0057     fprintf( stderr, "%s: driver open failed: %s\n", argv[0], strerror (errno));
0058     return 1;
0059   }
0060 
0061   if (rtems_disk_fd_sync (fd) < 0) {
0062     fprintf( stderr, "%s: driver sync failed: %s\n", argv[0], strerror (errno));
0063     close (fd);
0064     return 1;
0065   }
0066 
0067   close (fd);
0068   return 0;
0069 }
0070 
0071 rtems_shell_cmd_t rtems_shell_BLKSYNC_Command = {
0072   "blksync",                                 /* name */
0073   "blksync driver # sync the block driver",  /* usage */
0074   "files",                                   /* topic */
0075   rtems_shell_main_blksync,                  /* command */
0076   NULL,                                      /* alias */
0077   NULL                                       /* next */
0078 };