Changeset b5e68c8 in mainline for uspace/srv/bd/file_bd/file_bd.c
- Timestamp:
- 2011-05-12T16:49:44Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f36787d7
- Parents:
- e80329d6 (diff), 750636a (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/bd/file_bd/file_bd.c
re80329d6 rb5e68c8 41 41 #include <stdio.h> 42 42 #include <unistd.h> 43 #include <ipc/ipc.h>44 43 #include <ipc/bd.h> 45 44 #include <async.h> … … 56 55 #define NAME "file_bd" 57 56 58 static const size_t block_size = 512; 57 #define DEFAULT_BLOCK_SIZE 512 58 59 static size_t block_size; 59 60 static aoff64_t num_blocks; 60 61 static FILE *img; 61 62 62 static dev _handle_t dev_handle;63 static devmap_handle_t devmap_handle; 63 64 static fibril_mutex_t dev_lock; 64 65 66 static void print_usage(void); 65 67 static int file_bd_init(const char *fname); 66 68 static void file_bd_connection(ipc_callid_t iid, ipc_call_t *icall); … … 71 73 { 72 74 int rc; 75 char *image_name; 76 char *device_name; 73 77 74 78 printf(NAME ": File-backed block device driver\n"); 75 79 76 if (argc != 3) { 77 printf("Expected two arguments (image name, device name).\n"); 80 block_size = DEFAULT_BLOCK_SIZE; 81 82 ++argv; --argc; 83 while (*argv != NULL && (*argv)[0] == '-') { 84 /* Option */ 85 if (str_cmp(*argv, "-b") == 0) { 86 if (argc < 2) { 87 printf("Argument missing.\n"); 88 print_usage(); 89 return -1; 90 } 91 92 rc = str_size_t(argv[1], NULL, 10, true, &block_size); 93 if (rc != EOK || block_size == 0) { 94 printf("Invalid block size '%s'.\n", argv[1]); 95 print_usage(); 96 return -1; 97 } 98 ++argv; --argc; 99 } else { 100 printf("Invalid option '%s'.\n", *argv); 101 print_usage(); 102 return -1; 103 } 104 ++argv; --argc; 105 } 106 107 if (argc < 2) { 108 printf("Missing arguments.\n"); 109 print_usage(); 78 110 return -1; 79 111 } 80 112 81 if (file_bd_init(argv[1]) != EOK) 113 image_name = argv[0]; 114 device_name = argv[1]; 115 116 if (file_bd_init(image_name) != EOK) 82 117 return -1; 83 118 84 rc = devmap_device_register( argv[2], &dev_handle);119 rc = devmap_device_register(device_name, &devmap_handle); 85 120 if (rc != EOK) { 86 devmap_hangup_phone(DEVMAP_DRIVER); 87 printf(NAME ": Unable to register device %s.\n", 88 argv[2]); 121 printf(NAME ": Unable to register device '%s'.\n", 122 device_name); 89 123 return rc; 90 124 } … … 96 130 /* Not reached */ 97 131 return 0; 132 } 133 134 static void print_usage(void) 135 { 136 printf("Usage: " NAME " [-b <block_size>] <image_file> <device_name>\n"); 98 137 } 99 138 … … 136 175 ipc_callid_t callid; 137 176 ipc_call_t call; 138 ipcarg_t method;177 sysarg_t method; 139 178 size_t comm_size; 140 int flags;179 unsigned int flags; 141 180 int retval; 142 181 uint64_t ba; … … 144 183 145 184 /* Answer the IPC_M_CONNECT_ME_TO call. */ 146 ipc_answer_0(iid, EOK);185 async_answer_0(iid, EOK); 147 186 148 187 if (!async_share_out_receive(&callid, &comm_size, &flags)) { 149 ipc_answer_0(callid, EHANGUP);188 async_answer_0(callid, EHANGUP); 150 189 return; 151 190 } … … 153 192 fs_va = as_get_mappable_page(comm_size); 154 193 if (fs_va == NULL) { 155 ipc_answer_0(callid, EHANGUP);194 async_answer_0(callid, EHANGUP); 156 195 return; 157 196 } … … 161 200 while (1) { 162 201 callid = async_get_call(&call); 163 method = IPC_GET_ METHOD(call);202 method = IPC_GET_IMETHOD(call); 164 203 switch (method) { 165 204 case IPC_M_PHONE_HUNGUP: 166 205 /* The other side has hung up. */ 167 ipc_answer_0(callid, EOK);206 async_answer_0(callid, EOK); 168 207 return; 169 208 case BD_READ_BLOCKS: … … 188 227 break; 189 228 case BD_GET_BLOCK_SIZE: 190 ipc_answer_1(callid, EOK, block_size);229 async_answer_1(callid, EOK, block_size); 191 230 continue; 192 231 case BD_GET_NUM_BLOCKS: 193 ipc_answer_2(callid, EOK, LOWER32(num_blocks),232 async_answer_2(callid, EOK, LOWER32(num_blocks), 194 233 UPPER32(num_blocks)); 195 234 continue; … … 198 237 break; 199 238 } 200 ipc_answer_0(callid, retval);239 async_answer_0(callid, retval); 201 240 } 202 241 }
Note:
See TracChangeset
for help on using the changeset viewer.