Changeset 7bdcc45 in mainline for uspace/srv/bd/file_bd/file_bd.c


Ignore:
Timestamp:
2010-12-16T16:38:49Z (14 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7837101
Parents:
8e58f94 (diff), eb221e5 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

File:
1 edited

Legend:

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

    r8e58f94 r7bdcc45  
    5656#define NAME "file_bd"
    5757
    58 static const size_t block_size = 512;
     58#define DEFAULT_BLOCK_SIZE 512
     59
     60static size_t block_size;
    5961static aoff64_t num_blocks;
    6062static FILE *img;
     
    6365static fibril_mutex_t dev_lock;
    6466
     67static void print_usage(void);
    6568static int file_bd_init(const char *fname);
    6669static void file_bd_connection(ipc_callid_t iid, ipc_call_t *icall);
     
    7174{
    7275        int rc;
     76        char *image_name;
     77        char *device_name;
    7378
    7479        printf(NAME ": File-backed block device driver\n");
    7580
    76         if (argc != 3) {
    77                 printf("Expected two arguments (image name, device name).\n");
     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();
    78111                return -1;
    79112        }
    80113
    81         if (file_bd_init(argv[1]) != EOK)
     114        image_name = argv[0];
     115        device_name = argv[1];
     116
     117        if (file_bd_init(image_name) != EOK)
    82118                return -1;
    83119
    84         rc = devmap_device_register(argv[2], &devmap_handle);
     120        rc = devmap_device_register(device_name, &devmap_handle);
    85121        if (rc != EOK) {
    86122                devmap_hangup_phone(DEVMAP_DRIVER);
    87                 printf(NAME ": Unable to register device %s.\n",
    88                         argv[2]);
     123                printf(NAME ": Unable to register device '%s'.\n",
     124                        device_name);
    89125                return rc;
    90126        }
     
    96132        /* Not reached */
    97133        return 0;
     134}
     135
     136static void print_usage(void)
     137{
     138        printf("Usage: " NAME " [-b <block_size>] <image_file> <device_name>\n");
    98139}
    99140
     
    136177        ipc_callid_t callid;
    137178        ipc_call_t call;
    138         ipcarg_t method;
     179        sysarg_t method;
    139180        size_t comm_size;
    140181        int flags;
     
    161202        while (1) {
    162203                callid = async_get_call(&call);
    163                 method = IPC_GET_METHOD(call);
     204                method = IPC_GET_IMETHOD(call);
    164205                switch (method) {
    165206                case IPC_M_PHONE_HUNGUP:
Note: See TracChangeset for help on using the changeset viewer.