* @brief Create a filesystem on the specified device * * This function creates a filesystem of the specified type on the given device. * It performs the following operations: * 1. Looks up the filesystem type * 2. Validates device requirements * 3. Calls the filesystem-specific mkfs operation * 4. Handles page cache cleanup if successful (when RT_USING_PAGECACHE is enabled) * * @param[in]
| 551 | * - The filesystem doesn't implement mkfs operation |
| 552 | */ |
| 553 | int dfs_mkfs(const char *fs_name, const char *device_name) |
| 554 | { |
| 555 | rt_device_t dev_id = NULL; |
| 556 | struct dfs_filesystem_type *type; |
| 557 | int ret = -RT_ERROR; |
| 558 | |
| 559 | type = *_find_filesystem(fs_name); |
| 560 | if (!type) |
| 561 | { |
| 562 | rt_kprintf("no file system: %s found!\n", fs_name); |
| 563 | return ret; |
| 564 | } |
| 565 | else |
| 566 | { |
| 567 | if (type->fs_ops->flags & FS_NEED_DEVICE) |
| 568 | { |
| 569 | /* check device name, and it should not be NULL */ |
| 570 | if (device_name != NULL) |
| 571 | dev_id = rt_device_find(device_name); |
| 572 | |
| 573 | if (dev_id == NULL) |
| 574 | { |
| 575 | rt_set_errno(-ENODEV); |
| 576 | rt_kprintf("Device (%s) was not found", device_name); |
| 577 | return ret; |
| 578 | } |
| 579 | } |
| 580 | else |
| 581 | { |
| 582 | dev_id = RT_NULL; |
| 583 | } |
| 584 | } |
| 585 | |
| 586 | if (type->fs_ops->mkfs) |
| 587 | { |
| 588 | ret = type->fs_ops->mkfs(dev_id, type->fs_ops->name); |
| 589 | #ifdef RT_USING_PAGECACHE |
| 590 | if (ret == RT_EOK) |
| 591 | { |
| 592 | struct dfs_mnt *mnt = RT_NULL; |
| 593 | |
| 594 | mnt = dfs_mnt_dev_lookup(dev_id); |
| 595 | if (mnt) |
| 596 | { |
| 597 | dfs_pcache_unmount(mnt); |
| 598 | } |
| 599 | } |
| 600 | #endif |
| 601 | } |
| 602 | |
| 603 | return ret; |
| 604 | } |
| 605 | |
| 606 | /** |
| 607 | * @brief Get filesystem statistics for the specified path |
nothing calls this directly
no test coverage detected