MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / dfs_mkfs

Function dfs_mkfs

components/dfs/dfs_v2/src/dfs_fs.c:553–604  ·  view source on GitHub ↗

* @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]

Source from the content-addressed store, hash-verified

551 * - The filesystem doesn't implement mkfs operation
552 */
553int 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

Callers

nothing calls this directly

Calls 6

_find_filesystemFunction · 0.85
rt_kprintfFunction · 0.85
rt_device_findFunction · 0.85
rt_set_errnoFunction · 0.85
dfs_mnt_dev_lookupFunction · 0.85
dfs_pcache_unmountFunction · 0.85

Tested by

no test coverage detected