Changes in uspace/srv/bd/file_bd/file_bd.c [45df59a:991f645] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/bd/file_bd/file_bd.c
r45df59a r991f645 56 56 #define NAME "file_bd" 57 57 58 #define DEFAULT_BLOCK_SIZE 512 59 60 static size_t block_size; 58 static const size_t block_size = 512; 61 59 static aoff64_t num_blocks; 62 60 static FILE *img; … … 65 63 static fibril_mutex_t dev_lock; 66 64 67 static void print_usage(void);68 65 static int file_bd_init(const char *fname); 69 66 static void file_bd_connection(ipc_callid_t iid, ipc_call_t *icall); … … 74 71 { 75 72 int rc; 76 char *image_name;77 char *device_name;78 73 79 74 printf(NAME ": File-backed block device driver\n"); 80 75 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"); 111 78 return -1; 112 79 } 113 80 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) 118 82 return -1; 119 83 120 rc = devmap_device_register( device_name, &devmap_handle);84 rc = devmap_device_register(argv[2], &devmap_handle); 121 85 if (rc != EOK) { 122 86 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]); 125 89 return rc; 126 90 } … … 132 96 /* Not reached */ 133 97 return 0; 134 }135 136 static void print_usage(void)137 {138 printf("Usage: " NAME " [-b <block_size>] <image_file> <device_name>\n");139 98 } 140 99
Note:
See TracChangeset
for help on using the changeset viewer.