Changeset fb7e5a9a in mainline for uspace/lib
- Timestamp:
- 2011-09-06T20:03:31Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 038b289, f7d6b30
- Parents:
- 7a46bfe (diff), 7e9fce6 (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. - Location:
- uspace/lib
- Files:
-
- 9 edited
-
block/libblock.c (modified) (3 diffs)
-
block/libblock.h (modified) (3 diffs)
-
c/generic/str.c (modified) (1 diff)
-
c/include/ipc/devman.h (modified) (1 diff)
-
c/include/str.h (modified) (1 diff)
-
drv/generic/driver.c (modified) (2 diffs)
-
drv/include/ddf/driver.h (modified) (1 diff)
-
fs/libfs.c (modified) (1 diff)
-
fs/libfs.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/block/libblock.c
r7a46bfe rfb7e5a9a 93 93 static int get_block_size(async_sess_t *, size_t *); 94 94 static int get_num_blocks(async_sess_t *, aoff64_t *); 95 static int read_toc(async_sess_t *, uint8_t);96 95 static aoff64_t ba_ltop(devcon_t *, aoff64_t); 97 96 … … 896 895 * @param service_id Service ID of the block device. 897 896 * @param session Starting session. 898 * @param data Buffer to read TOC into. 899 * 900 * @return EOK on success. 901 * @return Error code on failure. 902 * 903 */ 904 int block_get_toc(service_id_t service_id, uint8_t session, void *data) 897 * 898 * @return Allocated TOC structure. 899 * @return NULL on failure. 900 * 901 */ 902 toc_block_t *block_get_toc(service_id_t service_id, uint8_t session) 905 903 { 906 904 devcon_t *devcon = devcon_search(service_id); 907 905 assert(devcon); 908 906 907 toc_block_t *toc = NULL; 908 909 909 fibril_mutex_lock(&devcon->comm_area_lock); 910 910 911 int rc = read_toc(devcon->sess, session); 912 if (rc == EOK) 913 memcpy(data, devcon->comm_area, devcon->pblock_size); 911 async_exch_t *exch = async_exchange_begin(devcon->sess); 912 int rc = async_req_1_0(exch, BD_READ_TOC, session); 913 async_exchange_end(exch); 914 915 if (rc == EOK) { 916 toc = (toc_block_t *) malloc(sizeof(toc_block_t)); 917 if (toc != NULL) { 918 memset(toc, 0, sizeof(toc_block_t)); 919 memcpy(toc, devcon->comm_area, 920 min(devcon->pblock_size, sizeof(toc_block_t))); 921 } 922 } 923 914 924 915 925 fibril_mutex_unlock(&devcon->comm_area_lock); 916 926 917 return rc;927 return toc; 918 928 } 919 929 … … 1008 1018 } 1009 1019 1010 /** Get TOC from block device. */1011 static int read_toc(async_sess_t *sess, uint8_t session)1012 {1013 async_exch_t *exch = async_exchange_begin(sess);1014 int rc = async_req_1_0(exch, BD_READ_TOC, session);1015 async_exchange_end(exch);1016 1017 return rc;1018 }1019 1020 1020 /** Convert logical block address to physical block address. */ 1021 1021 static aoff64_t ba_ltop(devcon_t *devcon, aoff64_t lba) -
uspace/lib/block/libblock.h
r7a46bfe rfb7e5a9a 97 97 }; 98 98 99 typedef struct { 100 uint16_t size; 101 uint8_t first_session; 102 uint8_t last_session; 103 104 uint8_t res0; 105 uint8_t adr_ctrl; 106 uint8_t first_track; 107 uint8_t res1; 108 109 uint32_t first_lba; 110 } __attribute__((packed)) toc_block_t; 111 99 112 extern int block_init(exch_mgmt_t, service_id_t, size_t); 100 113 extern void block_fini(service_id_t); … … 114 127 extern int block_get_bsize(service_id_t, size_t *); 115 128 extern int block_get_nblocks(service_id_t, aoff64_t *); 116 extern int block_get_toc(service_id_t, uint8_t, void *);129 extern toc_block_t *block_get_toc(service_id_t, uint8_t); 117 130 extern int block_read_direct(service_id_t, aoff64_t, size_t, void *); 118 131 extern int block_read_bytes_direct(service_id_t, aoff64_t, size_t, void *); … … 123 136 /** @} 124 137 */ 125 -
uspace/lib/c/generic/str.c
r7a46bfe rfb7e5a9a 1291 1291 } 1292 1292 1293 /** Convert string to uint8_t. 1294 * 1295 * @param nptr Pointer to string. 1296 * @param endptr If not NULL, pointer to the first invalid character 1297 * is stored here. 1298 * @param base Zero or number between 2 and 36 inclusive. 1299 * @param strict Do not allow any trailing characters. 1300 * @param result Result of the conversion. 1301 * 1302 * @return EOK if conversion was successful. 1303 * 1304 */ 1305 int str_uint8_t(const char *nptr, char **endptr, unsigned int base, 1306 bool strict, uint8_t *result) 1307 { 1308 assert(result != NULL); 1309 1310 bool neg; 1311 char *lendptr; 1312 uint64_t res; 1313 int ret = str_uint(nptr, &lendptr, base, &neg, &res); 1314 1315 if (endptr != NULL) 1316 *endptr = (char *) lendptr; 1317 1318 if (ret != EOK) 1319 return ret; 1320 1321 /* Do not allow negative values */ 1322 if (neg) 1323 return EINVAL; 1324 1325 /* Check whether we are at the end of 1326 the string in strict mode */ 1327 if ((strict) && (*lendptr != 0)) 1328 return EINVAL; 1329 1330 /* Check for overflow */ 1331 uint8_t _res = (uint8_t) res; 1332 if (_res != res) 1333 return EOVERFLOW; 1334 1335 *result = _res; 1336 1337 return EOK; 1338 } 1339 1340 /** Convert string to uint16_t. 1341 * 1342 * @param nptr Pointer to string. 1343 * @param endptr If not NULL, pointer to the first invalid character 1344 * is stored here. 1345 * @param base Zero or number between 2 and 36 inclusive. 1346 * @param strict Do not allow any trailing characters. 1347 * @param result Result of the conversion. 1348 * 1349 * @return EOK if conversion was successful. 1350 * 1351 */ 1352 int str_uint16_t(const char *nptr, char **endptr, unsigned int base, 1353 bool strict, uint16_t *result) 1354 { 1355 assert(result != NULL); 1356 1357 bool neg; 1358 char *lendptr; 1359 uint64_t res; 1360 int ret = str_uint(nptr, &lendptr, base, &neg, &res); 1361 1362 if (endptr != NULL) 1363 *endptr = (char *) lendptr; 1364 1365 if (ret != EOK) 1366 return ret; 1367 1368 /* Do not allow negative values */ 1369 if (neg) 1370 return EINVAL; 1371 1372 /* Check whether we are at the end of 1373 the string in strict mode */ 1374 if ((strict) && (*lendptr != 0)) 1375 return EINVAL; 1376 1377 /* Check for overflow */ 1378 uint16_t _res = (uint16_t) res; 1379 if (_res != res) 1380 return EOVERFLOW; 1381 1382 *result = _res; 1383 1384 return EOK; 1385 } 1386 1387 /** Convert string to uint32_t. 1388 * 1389 * @param nptr Pointer to string. 1390 * @param endptr If not NULL, pointer to the first invalid character 1391 * is stored here. 1392 * @param base Zero or number between 2 and 36 inclusive. 1393 * @param strict Do not allow any trailing characters. 1394 * @param result Result of the conversion. 1395 * 1396 * @return EOK if conversion was successful. 1397 * 1398 */ 1399 int str_uint32_t(const char *nptr, char **endptr, unsigned int base, 1400 bool strict, uint32_t *result) 1401 { 1402 assert(result != NULL); 1403 1404 bool neg; 1405 char *lendptr; 1406 uint64_t res; 1407 int ret = str_uint(nptr, &lendptr, base, &neg, &res); 1408 1409 if (endptr != NULL) 1410 *endptr = (char *) lendptr; 1411 1412 if (ret != EOK) 1413 return ret; 1414 1415 /* Do not allow negative values */ 1416 if (neg) 1417 return EINVAL; 1418 1419 /* Check whether we are at the end of 1420 the string in strict mode */ 1421 if ((strict) && (*lendptr != 0)) 1422 return EINVAL; 1423 1424 /* Check for overflow */ 1425 uint32_t _res = (uint32_t) res; 1426 if (_res != res) 1427 return EOVERFLOW; 1428 1429 *result = _res; 1430 1431 return EOK; 1432 } 1433 1293 1434 /** Convert string to uint64_t. 1294 1435 * -
uspace/lib/c/include/ipc/devman.h
r7a46bfe rfb7e5a9a 147 147 DRIVER_DEV_ADD = IPC_FIRST_USER_METHOD, 148 148 DRIVER_DEV_REMOVE, 149 DRIVER_DEV_GONE, 149 150 DRIVER_FUN_ONLINE, 150 151 DRIVER_FUN_OFFLINE, 151 152 152 } devman_to_driver_t; 153 153 -
uspace/lib/c/include/str.h
r7a46bfe rfb7e5a9a 97 97 extern char *str_ndup(const char *, size_t max_size); 98 98 99 extern int str_uint8_t(const char *, char **, unsigned int, bool, uint8_t *); 100 extern int str_uint16_t(const char *, char **, unsigned int, bool, uint16_t *); 101 extern int str_uint32_t(const char *, char **, unsigned int, bool, uint32_t *); 99 102 extern int str_uint64(const char *, char **, unsigned int, bool, uint64_t *); 100 103 extern int str_size_t(const char *, char **, unsigned int, bool, size_t *); -
uspace/lib/drv/generic/driver.c
r7a46bfe rfb7e5a9a 333 333 } 334 334 335 static void driver_dev_gone(ipc_callid_t iid, ipc_call_t *icall) 336 { 337 devman_handle_t devh; 338 ddf_dev_t *dev; 339 int rc; 340 341 devh = IPC_GET_ARG1(*icall); 342 343 fibril_mutex_lock(&devices_mutex); 344 dev = driver_get_device(devh); 345 if (dev != NULL) 346 dev_add_ref(dev); 347 fibril_mutex_unlock(&devices_mutex); 348 349 if (dev == NULL) { 350 async_answer_0(iid, ENOENT); 351 return; 352 } 353 354 if (driver->driver_ops->dev_gone != NULL) 355 rc = driver->driver_ops->dev_gone(dev); 356 else 357 rc = ENOTSUP; 358 359 if (rc == EOK) 360 dev_del_ref(dev); 361 362 async_answer_0(iid, (sysarg_t) rc); 363 } 364 335 365 static void driver_fun_online(ipc_callid_t iid, ipc_call_t *icall) 336 366 { … … 423 453 case DRIVER_DEV_REMOVE: 424 454 driver_dev_remove(callid, &call); 455 break; 456 case DRIVER_DEV_GONE: 457 driver_dev_gone(callid, &call); 425 458 break; 426 459 case DRIVER_FUN_ONLINE: -
uspace/lib/drv/include/ddf/driver.h
r7a46bfe rfb7e5a9a 139 139 /** Ask driver to remove a device */ 140 140 int (*dev_remove)(ddf_dev_t *); 141 /** Inform driver a device disappeared */ 142 int (*dev_gone)(ddf_dev_t *); 141 143 /** Ask driver to online a specific function */ 142 144 int (*fun_online)(ddf_fun_t *); -
uspace/lib/fs/libfs.c
r7a46bfe rfb7e5a9a 837 837 stat.is_directory = ops->is_directory(fn); 838 838 stat.size = ops->size_get(fn); 839 stat.service = ops-> device_get(fn);839 stat.service = ops->service_get(fn); 840 840 841 841 ops->node_put(fn); -
uspace/lib/fs/libfs.h
r7a46bfe rfb7e5a9a 92 92 bool (* is_directory)(fs_node_t *); 93 93 bool (* is_file)(fs_node_t *); 94 service_id_t (* device_get)(fs_node_t *);94 service_id_t (* service_get)(fs_node_t *); 95 95 } libfs_ops_t; 96 96
Note:
See TracChangeset
for help on using the changeset viewer.
