* make a file system on the special device * * @param fs_name the file system name * @param device_name the special device name * * @return 0 on successful, otherwise failed. */
| 430 | * @return 0 on successful, otherwise failed. |
| 431 | */ |
| 432 | int dfs_mkfs(const char *fs_name, const char *device_name) |
| 433 | { |
| 434 | int index; |
| 435 | rt_device_t dev_id = NULL; |
| 436 | |
| 437 | /* check device name, and it should not be NULL */ |
| 438 | if (device_name != NULL) |
| 439 | dev_id = rt_device_find(device_name); |
| 440 | |
| 441 | if (dev_id == NULL) |
| 442 | { |
| 443 | rt_set_errno(-ENODEV); |
| 444 | LOG_E("Device (%s) was not found", device_name); |
| 445 | return -1; |
| 446 | } |
| 447 | |
| 448 | /* lock file system */ |
| 449 | dfs_lock(); |
| 450 | /* find the file system operations */ |
| 451 | for (index = 0; index < DFS_FILESYSTEM_TYPES_MAX; index ++) |
| 452 | { |
| 453 | if (filesystem_operation_table[index] != NULL && |
| 454 | strncmp(filesystem_operation_table[index]->name, fs_name, |
| 455 | strlen(filesystem_operation_table[index]->name)) == 0) |
| 456 | break; |
| 457 | } |
| 458 | dfs_unlock(); |
| 459 | |
| 460 | if (index < DFS_FILESYSTEM_TYPES_MAX) |
| 461 | { |
| 462 | /* find file system operation */ |
| 463 | const struct dfs_filesystem_ops *ops = filesystem_operation_table[index]; |
| 464 | if (ops->mkfs == NULL) |
| 465 | { |
| 466 | LOG_E("The file system (%s) mkfs function was not implement", fs_name); |
| 467 | rt_set_errno(-ENOSYS); |
| 468 | return -1; |
| 469 | } |
| 470 | |
| 471 | return ops->mkfs(dev_id, fs_name); |
| 472 | } |
| 473 | |
| 474 | LOG_E("File system (%s) was not found.", fs_name); |
| 475 | |
| 476 | return -1; |
| 477 | } |
| 478 | |
| 479 | /** |
| 480 | * this function will return the information about a mounted file system. |