Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/bd/file_bd/file_bd.c

    r45df59a r991f645  
    5656#define NAME "file_bd"
    5757
    58 #define DEFAULT_BLOCK_SIZE 512
    59 
    60 static size_t block_size;
     58static const size_t block_size = 512;
    6159static aoff64_t num_blocks;
    6260static FILE *img;
     
    6563static fibril_mutex_t dev_lock;
    6664
    67 static void print_usage(void);
    6865static int file_bd_init(const char *fname);
    6966static void file_bd_connection(ipc_callid_t iid, ipc_call_t *icall);
     
    7471{
    7572        int rc;
    76         char *image_name;
    77         char *device_name;
    7873
    7974        printf(NAME ": File-backed block device driver\n");
    8075
    81         block_size = DEFAULT_BLOCK_SIZE;
    82 
    83         ++argv; --argc;
    84         while (*argv != NULL && (*argv)[0] == '-') {
    85                 /* Option */
    86                 if (str_cmp(*argv, "-b") == 0) {
    87                         if (argc < 2) {
    88                                 printf("Argument missing.\n");
    89                                 print_usage();
    90                                 return -1;
    91                         }
    92 
    93                         rc = str_size_t(argv[1], NULL, 10, true, &block_size);
    94                         if (rc != EOK || block_size == 0) {
    95                                 printf("Invalid block size '%s'.\n", argv[1]);
    96                                 print_usage();
    97                                 return -1;
    98                         }
    99                         ++argv; --argc;
    100                 } else {
    101                         printf("Invalid option '%s'.\n", *argv);
    102                         print_usage();
    103                         return -1;
    104                 }
    105                 ++argv; --argc;
    106         }
    107 
    108         if (argc < 2) {
    109                 printf("Missing arguments.\n");
    110                 print_usage();
     76        if (argc != 3) {
     77                printf("Expected two arguments (image name, device name).\n");
    11178                return -1;
    11279        }
    11380
    114         image_name = argv[0];
    115         device_name = argv[1];
    116 
    117         if (file_bd_init(image_name) != EOK)
     81        if (file_bd_init(argv[1]) != EOK)
    11882                return -1;
    11983
    120         rc = devmap_device_register(device_name, &devmap_handle);
     84        rc = devmap_device_register(argv[2], &devmap_handle);
    12185        if (rc != EOK) {
    12286                devmap_hangup_phone(DEVMAP_DRIVER);
    123                 printf(NAME ": Unable to register device '%s'.\n",
    124                         device_name);
     87                printf(NAME ": Unable to register device %s.\n",
     88                        argv[2]);
    12589                return rc;
    12690        }
     
    13296        /* Not reached */
    13397        return 0;
    134 }
    135 
    136 static void print_usage(void)
    137 {
    138         printf("Usage: " NAME " [-b <block_size>] <image_file> <device_name>\n");
    13998}
    14099
Note: See TracChangeset for help on using the changeset viewer.