FATFS 初学之 f_mkdir/ unlink

本文介绍了嵌入式开发中FATFS文件系统的两个关键函数:f_mkdir用于创建目录,f_unlink则用于删除文件或目录。这两个函数在_FAT_READONLY和_FS_MINIMIZE非零时可用。需要注意的是,f_unlink不能删除打开的对象或当前目录。文中提供了一个简要的示例参考。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

f_mkdir:

 1 /*-----------------------------------------------------------------------*/
 2 /* Create a Directory                                                    */
 3 /*-----------------------------------------------------------------------*/
 4 
 5 FRESULT f_mkdir (
 6     const TCHAR *path        /* Pointer to the directory path */
 7 )
 8 {
 9     FRESULT res;
10     DIR dj;
11     BYTE *dir, n;
12     DWORD dsc, dcl, pcl, tim = get_fattime();
13     DEF_NAMEBUF;
14 
15 
16     res = chk_mounted(&path, &dj.fs, 1);
17     if (res == FR_OK) {
18         INIT_BUF(dj);
19         res = follow_path(&dj, path);            /* Follow the file path */
20         if (res == FR_OK) res = FR_EXIST;        /* Any object with same name is already existing */
21         if (_FS_RPATH && res == FR_NO_FILE && (dj.fn[NS] & NS_DOT))
22             res = FR_INVALID_NAME;
23         if (res == FR_NO_FILE) {                /* Can create a new directory */
24             dcl = create_chain(dj.fs, 0);        /* Allocate a cluster for the new directory table */
25             res = FR_OK;
26             if (dcl == 0) res = FR_DENIED;        /* No space to allocate a new cluster */
27             if (dcl == 1) res = FR_INT_ERR;
28             if (dcl == 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值