fs.h 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042
  1. #ifndef __FS_H__
  2. #define __FS_H__
  3. #include "generic/typedef.h"
  4. #include "generic/list.h"
  5. #include "generic/ioctl.h"
  6. #include "generic/atomic.h"
  7. #include "system/task.h"
  8. #include "system/malloc.h"
  9. #include "system/sys_time.h"
  10. #include "stdarg.h"
  11. #include "fs_file_name.h"
  12. #define SEEK_SET 0 /* Seek from beginning of file. */
  13. #define SEEK_CUR 1 /* Seek from current position. */
  14. #define SEEK_END 2 /* Seek from end of file. */
  15. #include "sdfile.h"
  16. #define F_ATTR_RO 0x01
  17. #define F_ATTR_ARC 0x02
  18. #define F_ATTR_DIR 0x04
  19. #define F_ATTR_VOL 0x08
  20. #if (VFS_ENABLE == 1)
  21. #ifndef FSELECT_MODE
  22. #define FSELECT_MODE
  23. #define FSEL_FIRST_FILE 0
  24. #define FSEL_LAST_FILE 1
  25. #define FSEL_NEXT_FILE 2
  26. #define FSEL_PREV_FILE 3
  27. #define FSEL_CURR_FILE 4
  28. #define FSEL_BY_NUMBER 5
  29. #define FSEL_BY_SCLUST 6
  30. #define FSEL_AUTO_FILE 7
  31. #define FSEL_NEXT_FOLDER_FILE 8
  32. #define FSEL_PREV_FOLDER_FILE 9
  33. #define FSEL_BY_PATH 10
  34. #endif
  35. #ifndef FCYCLE_MODE
  36. #define FCYCLE_MODE
  37. #define FCYCLE_LIST 0
  38. #define FCYCLE_ALL 1
  39. #define FCYCLE_ONE 2
  40. #define FCYCLE_FOLDER 3
  41. #define FCYCLE_RANDOM 4
  42. #define FCYCLE_MAX 5
  43. #endif
  44. enum {
  45. FS_IOCTL_GET_FILE_NUM,
  46. FS_IOCTL_FILE_CHECK,
  47. FS_IOCTL_GET_ERR_CODE, //暂不支持
  48. FS_IOCTL_FREE_CACHE,
  49. FS_IOCTL_SET_NAME_FILTER, //设置文件过滤
  50. FS_IOCTL_GET_FOLDER_INFO, //获取文件夹序号和文件夹内文件数目
  51. FS_IOCTL_SET_LFN_BUF, // 512
  52. FS_IOCTL_SET_LDN_BUF, // 512
  53. FS_IOCTL_SET_EXT_TYPE, //设置后缀类型
  54. FS_IOCTL_OPEN_DIR, //打开目录
  55. FS_IOCTL_ENTER_DIR, //进入目录
  56. FS_IOCTL_EXIT_DIR, //退出
  57. FS_IOCTL_GET_DIR_INFO, //获取目录信息
  58. FS_IOCTL_GETFILE_BYNAME_INDIR, //由歌曲名称获得歌词
  59. FS_IOCTL_GET_DISP_INFO, //用于长文件名获取
  60. FS_IOCTL_MK_DIR, //创建文件夹
  61. FS_IOCTL_GET_ENCFOLDER_INFO, //获取录音文件信息
  62. FS_IOCTL_GET_OUTFLASH_ADDR, //获取外置flash实际物理地址(暂时用于手表case,特殊fat系统)
  63. FS_IOCTL_FLUSH_WBUF, //刷新wbuf
  64. FS_IOCTL_SAVE_FAT_TABLE, //seek加速处理
  65. FS_IOCTL_INSERT_FILE, //插入文件
  66. FS_IOCTL_DIVISION_FILE, //分割文件
  67. FS_IOCTL_STORE_CLUST_RANG, //存储CLUST_RANG 信息
  68. };
  69. struct vfs_devinfo;
  70. struct vfscan;
  71. struct vfs_operations;
  72. struct vfs_devinfo {
  73. void *fd;
  74. u32 sector_size;
  75. void *private_data;
  76. };
  77. #define VFS_PART_DIR_MAX 16
  78. struct vfs_partition {
  79. struct vfs_partition *next;
  80. u32 offset;
  81. u32 clust_size;
  82. u32 total_size;
  83. u8 fs_attr;
  84. u8 fs_type;
  85. char dir[VFS_PART_DIR_MAX];
  86. void *private_data;
  87. };
  88. struct fiter {
  89. u32 index;
  90. };
  91. struct ffolder {
  92. u16 fileStart;
  93. u16 fileTotal;
  94. };
  95. struct imount {
  96. int fd;
  97. const char *path;
  98. struct vfs_operations *ops;
  99. struct vfs_devinfo dev;
  100. struct vfs_partition part;
  101. struct list_head entry;
  102. atomic_t ref;
  103. OS_MUTEX mutex;
  104. u8 avaliable;
  105. u8 part_num;
  106. };
  107. struct vfs_attr {
  108. u8 attr;
  109. u32 fsize;
  110. u32 sclust;
  111. struct sys_time crt_time;
  112. struct sys_time wrt_time;
  113. struct sys_time acc_time;
  114. };
  115. typedef struct {
  116. struct imount *mt;
  117. struct vfs_devinfo *dev;
  118. struct vfs_partition *part;
  119. void *private_data;
  120. } FILE;
  121. struct vfscan {
  122. u8 scan_file;
  123. u8 subpath; //子目录,设置是否只扫描一层
  124. u8 scan_dir;
  125. u8 attr;
  126. u8 cycle_mode;
  127. char sort;
  128. char ftype[20 * 3 + 1];
  129. u16 file_number;
  130. u16 file_counter;
  131. u16 dir_totalnumber; // 文件夹总数
  132. u16 musicdir_counter; // 播放文件所在文件夹序号
  133. u16 fileTotalInDir; //文件夹下的文件数目
  134. void *priv;
  135. struct vfs_devinfo *dev;
  136. struct vfs_partition *part;
  137. char filt_dir[12];
  138. };
  139. struct vfs_operations {
  140. const char *fs_type;
  141. int (*mount)(struct imount *, int);
  142. int (*unmount)(struct imount *);
  143. int (*format)(struct vfs_devinfo *, struct vfs_partition *);
  144. int (*fset_vol)(struct vfs_partition *, const char *name);
  145. int (*fget_free_space)(struct vfs_devinfo *, struct vfs_partition *, u32 *space);
  146. int (*fopen)(FILE *, const char *path, const char *mode);
  147. int (*fread)(FILE *, void *buf, u32 len);
  148. int (*fread_fast)(FILE *, void *buf, u32 len);
  149. int (*fwrite)(FILE *, void *buf, u32 len);
  150. int (*fseek)(FILE *, int offset, int);
  151. int (*fseek_fast)(FILE *, int offset, int);
  152. int (*flen)(FILE *);
  153. int (*fpos)(FILE *);
  154. int (*fcopy)(FILE *, FILE *);
  155. int (*fget_name)(FILE *, u8 *name, int len);
  156. int (*fget_path)(FILE *, struct vfscan *, u8 *name, int len, u8 is_relative_path);
  157. int (*frename)(FILE *, const char *path);
  158. int (*fclose)(FILE *);
  159. int (*fdelete)(FILE *);
  160. int (*fscan)(struct vfscan *, const char *path, u8 max_deepth);
  161. int (*fscan_interrupt)(struct vfscan *, const char *path, u8 max_deepth, int (*callback)(void));
  162. void (*fscan_release)(struct vfscan *);
  163. int (*fsel)(struct vfscan *, int sel_mode, FILE *, int);
  164. int (*fget_attr)(FILE *, int *attr);
  165. int (*fset_attr)(FILE *, int attr);
  166. int (*fget_attrs)(FILE *, struct vfs_attr *);
  167. int (*fmove)(FILE *file, const char *path_dst, FILE *, int clr_attr, int path_len);
  168. int (*ioctl)(void *, int cmd, int arg);
  169. };
  170. #define REGISTER_VFS_OPERATIONS(ops) \
  171. const struct vfs_operations ops SEC(.vfs_operations)
  172. static inline struct vfs_partition *vfs_partition_next(struct vfs_partition *p)
  173. {
  174. struct vfs_partition *n = (struct vfs_partition *)zalloc(sizeof(*n));
  175. if (n) {
  176. p->next = n;
  177. }
  178. return n;
  179. }
  180. static inline void vfs_partition_free(struct vfs_partition *p)
  181. {
  182. struct vfs_partition *n = p->next;
  183. while (n) {
  184. p = n->next;
  185. free(n);
  186. n = p;
  187. }
  188. }
  189. /* --------------------------------------------------------------------------*/
  190. /**
  191. * @brief 挂载文件系统
  192. *
  193. * @param dev_name 设备名称
  194. * @param path 路径
  195. * @param fs_type 文件系统类型
  196. * @param cache_num 分区数
  197. * @param dev_arg 设备参数
  198. *
  199. * @return mt结构句柄
  200. */
  201. /* ----------------------------------------------------------------------------*/
  202. struct imount *mount(const char *dev_name, const char *path, const char *fs_type,
  203. int cache_num, void *dev_arg); //挂载
  204. /* --------------------------------------------------------------------------*/
  205. /**
  206. * @brief 卸载
  207. *
  208. * @param path 路径
  209. *
  210. * @return 返回相应的操作消息处理值 0为成功
  211. */
  212. /* ----------------------------------------------------------------------------*/
  213. int unmount(const char *path);
  214. /* --------------------------------------------------------------------------*/
  215. /**
  216. * @brief 格式化接口
  217. *
  218. * @param path 路径
  219. * @param fs_type 文件系统类型
  220. * @param clust_size 簇大小,簇为0时默认为卡本身簇大小。
  221. *
  222. * @return 0格式化成功,非0 失败
  223. */
  224. /* ----------------------------------------------------------------------------*/
  225. int f_format(const char *path, const char *fs_type, u32 clust_size); //格式化接口
  226. int f_free_cache(const char *path);
  227. #if 0
  228. /*----------------------------------------------------------------------------*/
  229. /** @brief:
  230. @param: fopen 扩展功能
  231. @note: fopen自动打开、创建文件夹和文件。
  232. 说明:
  233. 1. 设备路径+文件,其中文件传入格式:"music/test/1/2/3/pk*.wav" "JL_REC/AC69****.wav" "JL_REC/AC690000.wav"
  234. 2. 文件名带*号,带多少个*表示多少个可变数字,最多为8+3的大小,如表示可变数字名称变为XXX0001,XXXX002这样得格式,不带*号则只创建一个文件,写覆盖。
  235. @date: 2020-07-22
  236. */
  237. /*----------------------------------------------------------------------------*/
  238. #endif
  239. /* --------------------------------------------------------------------------*/
  240. /**
  241. * @brief 打开文件
  242. *
  243. * @param path 文件路径
  244. * @param mode 打开模式(只读("r"),写("w"),可创建("w+"))
  245. *
  246. * @return 返回获得得文件句柄
  247. */
  248. /* ----------------------------------------------------------------------------*/
  249. FILE *fopen(const char *path, const char *mode);
  250. /* --------------------------------------------------------------------------*/
  251. /**
  252. * @brief 读文件
  253. *
  254. * @param file 文件句柄
  255. * @param buf 读出内容放置buf
  256. * @param len 需要读出内容得长度(一般为buf长度)
  257. *
  258. * @return 返回读出得长度
  259. */
  260. /* ----------------------------------------------------------------------------*/
  261. int fread(FILE *file, void *buf, u32 len);
  262. /* --------------------------------------------------------------------------*/
  263. /**
  264. * @brief 写资源文件
  265. *
  266. * @param file 文件句柄
  267. * @param buf 写入得内容放置buf
  268. * @param len 需要写入内容得长度(一般为buf长度)
  269. *
  270. * @return 返回写入得长度
  271. */
  272. /* ----------------------------------------------------------------------------*/
  273. int fwrite(FILE *file, void *buf, u32 len);
  274. /* --------------------------------------------------------------------------*/
  275. /**
  276. * @brief Seek到相应得位置
  277. *
  278. * @param file 文件句柄
  279. * @param offset 偏移量
  280. * @param orig 偏移方式
  281. *
  282. * @return 返回偏移得值
  283. */
  284. /* ----------------------------------------------------------------------------*/
  285. int fseek(FILE *file, int offset, int orig);
  286. /* --------------------------------------------------------------------------*/
  287. /**
  288. * @brief 快速seek
  289. *
  290. * @param file 文件句柄
  291. * @param offset 偏移量
  292. * @param orig 偏移方式
  293. *
  294. * @note 一般手表case使用,去除互斥,设置ram里面跑
  295. * @return 返回偏移得值
  296. */
  297. /* ----------------------------------------------------------------------------*/
  298. int fseek_fast(FILE *file, int offset, int orig);// 快速seek
  299. /* --------------------------------------------------------------------------*/
  300. /**
  301. * @brief 快速read
  302. *
  303. * @param file 文件句柄
  304. * @param buf 读出内容放置buf
  305. * @param len 需要读出内容得长度(一般为buf长度)
  306. *
  307. * @note 一般手表case使用,去除互斥,设置ram里面跑
  308. * @return 返回读出得长度
  309. */
  310. /* ----------------------------------------------------------------------------*/
  311. int fread_fast(FILE *file, void *buf, u32 len); //快速read
  312. /* --------------------------------------------------------------------------*/
  313. /**
  314. * @brief 获取文件长度
  315. *
  316. * @param file 文件句柄
  317. *
  318. * @return 当前文件长度
  319. */
  320. /* ----------------------------------------------------------------------------*/
  321. int flen(FILE *file);
  322. /* --------------------------------------------------------------------------*/
  323. /**
  324. * @brief 获取文件指针位置
  325. *
  326. * @param file 文件句柄
  327. *
  328. * @return 当前文件指针位置
  329. */
  330. /* ----------------------------------------------------------------------------*/
  331. int fpos(FILE *file);
  332. int fcopy(const char *format, ...);
  333. /* --------------------------------------------------------------------------*/
  334. /**
  335. * @brief 获取当前文件名称
  336. *
  337. * @param file 文件句柄
  338. * @param name 文件名buf
  339. * @param len 长度
  340. *
  341. * @return 获取到的文件名长度
  342. */
  343. /* ----------------------------------------------------------------------------*/
  344. int fget_name(FILE *file, u8 *name, int len);
  345. /* --------------------------------------------------------------------------*/
  346. /**
  347. * @brief 重命名
  348. *
  349. * @param file 文件句柄
  350. * @param path 重命名的文件名
  351. *
  352. * @return 0成功,非0 失败
  353. */
  354. /* ----------------------------------------------------------------------------*/
  355. int frename(FILE *file, const char *path);
  356. /* --------------------------------------------------------------------------*/
  357. /**
  358. * @brief 关闭文件
  359. *
  360. * @param file 文件句柄
  361. *
  362. * @return 无意义
  363. */
  364. /* ----------------------------------------------------------------------------*/
  365. int fclose(FILE *file);
  366. /* --------------------------------------------------------------------------*/
  367. /**
  368. * @brief 删除文件
  369. *
  370. * @param file 文件句柄
  371. *
  372. * @return 无意义
  373. */
  374. /* ----------------------------------------------------------------------------*/
  375. int fdelete(FILE *file);
  376. int fdelete_by_name(const char *fname);
  377. /* --------------------------------------------------------------------------*/
  378. /**
  379. * @brief 获取设备剩余容量
  380. *
  381. * @param path 根路径
  382. * @param space 剩余空间 K 为单位
  383. *
  384. * @return 无意义
  385. */
  386. /* ----------------------------------------------------------------------------*/
  387. int fget_free_space(const char *path, u32 *space);
  388. /* --------------------------------------------------------------------------*/
  389. /**
  390. * @brief 获取当前文件相对路径和绝对路径
  391. *
  392. * @param file 文件句柄
  393. * @param fscan 扫描句柄
  394. * @param name 路径buf
  395. * @param len buf长度
  396. * @param is_relative_path 是否相对路径
  397. *
  398. * @return 获取到的文件名长度
  399. */
  400. /* ----------------------------------------------------------------------------*/
  401. int fget_path(FILE *file, struct vfscan *fscan, u8 *name, int len, u8 is_relative_path);
  402. /* arg:
  403. * -t 文件类型
  404. * -r 包含子目录
  405. * -d 扫描文件夹
  406. * -a 文件属性 r: 读, /: 非
  407. * -s 排序方式, t:按时间排序, n:按文件号排序
  408. */
  409. /* --------------------------------------------------------------------------*/
  410. /**
  411. * @brief 文件扫描
  412. *
  413. * @param path 路径
  414. * @param arg 扫描方式
  415. * @param max_deepth 扫描深度,最大为9
  416. *
  417. * @return vfscan句柄
  418. */
  419. /* ----------------------------------------------------------------------------*/
  420. struct vfscan *fscan(const char *path, const char *arg, u8 max_deepth); //扫描接口,参数配置如上。
  421. /* --------------------------------------------------------------------------*/
  422. /**
  423. * @brief 文件扫描,可打断。
  424. *
  425. * @param path 路径
  426. * @param arg 扫描方式
  427. * @param max_deepth 扫描深度,最大为9
  428. * @param callback 回调函数,用于打断、同时进行其他操作等
  429. *
  430. * @return vfscan句柄
  431. */
  432. /* ----------------------------------------------------------------------------*/
  433. struct vfscan *fscan_interrupt(const char *path, const char *arg, u8 max_deepth, int (*callback)(void)); //可打断扫描
  434. /* --------------------------------------------------------------------------*/
  435. /**
  436. * @brief 进入指定子目录,只扫此目录下文件信息
  437. *
  438. * @param fs vfscan句柄
  439. * @param path 子目录相对路径
  440. *
  441. * @return vfscan句柄
  442. */
  443. /* ----------------------------------------------------------------------------*/
  444. struct vfscan *fscan_enterdir(struct vfscan *fs, const char *path);//进入指定子目录,只扫此目录下文件信息
  445. /* --------------------------------------------------------------------------*/
  446. /**
  447. * @brief 返回上一层目录
  448. *
  449. * @param fs vfscan句柄
  450. *
  451. * @return vfscan句柄
  452. */
  453. /* ----------------------------------------------------------------------------*/
  454. struct vfscan *fscan_exitdir(struct vfscan *fs); //返回上一层
  455. /* --------------------------------------------------------------------------*/
  456. /**
  457. * @brief 释放句柄
  458. *
  459. * @param fs vfscan句柄
  460. */
  461. /* ----------------------------------------------------------------------------*/
  462. void fscan_release(struct vfscan *fs);
  463. /* --------------------------------------------------------------------------*/
  464. /**
  465. * @brief 选择指定文件打开
  466. *
  467. * @param fs vfscan句柄
  468. * @param selt_mode 按什么方式选择 (支持按簇号、序号、路径选择)
  469. * @param arg 传入选择的参数
  470. *
  471. * @return 文件句柄
  472. */
  473. /* ----------------------------------------------------------------------------*/
  474. FILE *fselect(struct vfscan *fs, int selt_mode, int arg); //选择指定文件
  475. /* --------------------------------------------------------------------------*/
  476. /**
  477. * @brief 检查挂载目录是否存在
  478. *
  479. * @param dir 目录路径
  480. *
  481. * @return 0存在 , 1不存在
  482. */
  483. /* ----------------------------------------------------------------------------*/
  484. int fdir_exist(const char *dir); //check 目录是否存在
  485. int fdir(FILE *file, const char *arg, char *name, int len, struct fiter *iter);//暂无此接口
  486. /* --------------------------------------------------------------------------*/
  487. /**
  488. * @brief 获取文件属性
  489. *
  490. * @param file 文件句柄
  491. * @param attr 属性
  492. *
  493. * @return 0成功, 非0错误。
  494. */
  495. /* ----------------------------------------------------------------------------*/
  496. int fget_attr(FILE *file, int *attr); //获取文件属性
  497. /* --------------------------------------------------------------------------*/
  498. /**
  499. * @brief 设置文件属性
  500. *
  501. * @param file 文件句柄
  502. * @param attr 属性
  503. *
  504. * @return 0成功, 非0错误。
  505. */
  506. /* ----------------------------------------------------------------------------*/
  507. int fset_attr(FILE *file, int attr); //设置文件属性
  508. /* --------------------------------------------------------------------------*/
  509. /**
  510. * @brief 获取文件相关信息
  511. *
  512. * @param file 文件句柄
  513. * @param attr 记录相应信息的结构体
  514. *
  515. * @return 0成功, 非0错误。
  516. */
  517. /* ----------------------------------------------------------------------------*/
  518. int fget_attrs(FILE *file, struct vfs_attr *attr);//获得文件相关信息如属性、簇号、大小等
  519. /* --------------------------------------------------------------------------*/
  520. /**
  521. * @brief 获取分区part
  522. *
  523. * @param path 路径
  524. *
  525. * @return vfs_partition句柄
  526. */
  527. /* ----------------------------------------------------------------------------*/
  528. struct vfs_partition *fget_partition(const char *path);//获得分区part
  529. /* --------------------------------------------------------------------------*/
  530. /**
  531. * @brief 设置卷标
  532. *
  533. * @param path 设备路径
  534. * @param name 卷标名字
  535. *
  536. * @return 0成功, 非0错误。
  537. */
  538. /* ----------------------------------------------------------------------------*/
  539. int fset_vol(const char *path, const char *name);//设置卷标
  540. int fmove(FILE *file, const char *path_dst, FILE **newFile, int clr_attr, int path_len);
  541. int fcheck(FILE *file);//暂不支持
  542. int fget_err_code(const char *path); //暂不支持
  543. int fset_name_filter(const char *path, void *name_filter);//暂不支持
  544. /* --------------------------------------------------------------------------*/
  545. /**
  546. * @brief 获取文件夹信息
  547. *
  548. * @param fs vfscan 结构句柄
  549. * @param arg 文件夹信息结构句柄
  550. *
  551. * @return 无意义
  552. */
  553. /* ----------------------------------------------------------------------------*/
  554. int fget_folder(struct vfscan *fs, struct ffolder *arg); //获取文件夹序号和文件夹内文件数目
  555. /* --------------------------------------------------------------------------*/
  556. /**
  557. * @brief 设置长文件名Buf (现已不常用)
  558. *
  559. * @param fs vfscan 句柄
  560. * @param arg buf
  561. *
  562. * @return 0成功, 非0错误。
  563. */
  564. /* ----------------------------------------------------------------------------*/
  565. int fset_lfn_buf(struct vfscan *fs, void *arg);//设置长文件名buf
  566. /* --------------------------------------------------------------------------*/
  567. /**
  568. * @brief 设置长文件夹名Buf (现已不常用)
  569. *
  570. * @param fs vfscan 句柄
  571. * @param arg buf
  572. *
  573. * @return 0成功, 非0错误。
  574. */
  575. /* ----------------------------------------------------------------------------*/
  576. int fset_ldn_buf(struct vfscan *fs, void *arg);//设置长文件夹名buf
  577. /* --------------------------------------------------------------------------*/
  578. /**
  579. * @brief 设置后缀名过滤(现已不常用)
  580. *
  581. * @param path 根路径
  582. * @param ext_type 后缀名
  583. *
  584. * @return 0成功, 非0错误。
  585. */
  586. /* ----------------------------------------------------------------------------*/
  587. int fset_ext_type(const char *path, void *ext_type);//设置后缀类型
  588. /* --------------------------------------------------------------------------*/
  589. /**
  590. * @brief 文件浏览使用,打开目录
  591. *
  592. * @param path 路径
  593. * @param pp_file 文件句柄
  594. * @param dir_dj 目录信息句柄
  595. *
  596. * @return 无意义
  597. */
  598. /* ----------------------------------------------------------------------------*/
  599. int fopen_dir_info(const char *path, FILE **pp_file, void *dir_dj); //打开目录
  600. /* --------------------------------------------------------------------------*/
  601. /**
  602. * @brief 文件浏览使用,进入目录
  603. *
  604. * @param file 文件句柄
  605. * @param dir_dj 目录信息句柄
  606. *
  607. * @return 目录项总数
  608. */
  609. /* ----------------------------------------------------------------------------*/
  610. int fenter_dir_info(FILE *file, void *dir_dj); //进入目录
  611. /* --------------------------------------------------------------------------*/
  612. /**
  613. * @brief 文件浏览使用,退出目录
  614. *
  615. * @param file 文件句柄
  616. *
  617. * @return 目录项总数
  618. */
  619. /* ----------------------------------------------------------------------------*/
  620. int fexit_dir_info(FILE *file); //退出
  621. /* --------------------------------------------------------------------------*/
  622. /**
  623. * @brief 文件浏览使用,获取目录信息
  624. *
  625. * @param file 文件句柄
  626. * @param start_num 起始位置
  627. * @param total_num 获取目录个数
  628. * @param buf_info 目录信息句柄
  629. *
  630. * @return 获取的目录数
  631. */
  632. /* ----------------------------------------------------------------------------*/
  633. int fget_dir_info(FILE *file, u32 start_num, u32 total_num, void *buf_info); ////获取目录信息
  634. /* --------------------------------------------------------------------------*/
  635. /**
  636. * @brief 存储文件簇信息
  637. *
  638. * @param file 文件句柄
  639. *
  640. * @note 一般手表case使用, 用于fget_fat_outflash_addr()之前调用,节省fget_fat_outflash_addr()时间
  641. * @return 0成功, 非0错误。
  642. */
  643. /* ----------------------------------------------------------------------------*/
  644. int fstore_clust_rang(FILE *file);
  645. /* --------------------------------------------------------------------------*/
  646. /**
  647. * @brief 获取外置flash实际物理地址
  648. *
  649. * @param file 文件句柄
  650. * @param name sdfile格式文件名
  651. * @param buf_info 存储相关信息结构buf指针
  652. * @param buf_len buf 长度
  653. *
  654. * @note 一般手表case使用
  655. * @return 0表示buf不够 大于 0 表示存储多少个信息结构,其他 错误
  656. */
  657. /* ----------------------------------------------------------------------------*/
  658. int fget_fat_outflash_addr(FILE *file, char *name, void *buf_info, int buf_len); //获取外置flash实际物理地址
  659. /* --------------------------------------------------------------------------*/
  660. /**
  661. * @brief 文件浏览使用,由歌曲名称获取歌词
  662. *
  663. * @param file 歌曲文件句柄
  664. * @param newFile 歌词文件句柄
  665. * @param ext_name 后缀名称
  666. *
  667. * @return 0成功, 非0错误。
  668. */
  669. /* ----------------------------------------------------------------------------*/
  670. int fget_file_byname_indir(FILE *file, FILE **newFile, void *ext_name); //由歌曲名称获得歌词
  671. /* --------------------------------------------------------------------------*/
  672. /**
  673. * @brief 获取长文件名和长文件夹名信息(现在不常使用)
  674. *
  675. * @param file 歌曲文件句柄
  676. * @param arg 长文件相关信息结构指针
  677. *
  678. * @note 需要先设置长文件名或者长文件夹名buf进去
  679. * @return 0成功, 非0错误。
  680. */
  681. /* ----------------------------------------------------------------------------*/
  682. int fget_disp_info(FILE *file, void *arg); //用于长文件名获取
  683. /* --------------------------------------------------------------------------*/
  684. /**
  685. * @brief 创建目录
  686. *
  687. * @param path 路径
  688. * @param folder 文件夹名称,不需要 /
  689. * @param mode 目录属性(1 设置为隐藏属性, 0 不设置 )
  690. *
  691. * @return 0成功,非0不成功
  692. */
  693. /* ----------------------------------------------------------------------------*/
  694. int fmk_dir(const char *path, char *folder, u8 mode); //创建目录
  695. /* --------------------------------------------------------------------------*/
  696. /**
  697. * @brief 获取录音文件信息(现在不常用)
  698. *
  699. * @param path 路径
  700. * @param folder 文件夹名称
  701. * @param ext 文件名后缀
  702. * @param last_num 可变数字最大数字
  703. * @param total_num 文件总数
  704. *
  705. * @return 0成功,非0不成功
  706. */
  707. /* ----------------------------------------------------------------------------*/
  708. int fget_encfolder_info(const char *path, char *folder, char *ext, u32 *last_num, u32 *total_num); //获取录音文件信息
  709. /* --------------------------------------------------------------------------*/
  710. /**
  711. * @brief 拼接字符
  712. *
  713. * @param result 最终结果指针
  714. * @param path 前路径指针
  715. * @param fname 需要拼接的字符
  716. * @param len fname长度
  717. *
  718. * @return 0成功,非0不成功
  719. */
  720. /* ----------------------------------------------------------------------------*/
  721. int fname_to_path(char *result, const char *path, const char *fname, int len); //把路径和文件名拼接
  722. /* --------------------------------------------------------------------------*/
  723. /**
  724. * @brief 截取path中根目录之后的文件名
  725. *
  726. * @param path 路径
  727. *
  728. * @return 文件名
  729. */
  730. /* ----------------------------------------------------------------------------*/
  731. const char *fname_after_root(const char *path); // 截取path中根目录之后的文件名
  732. /* --------------------------------------------------------------------------*/
  733. /**
  734. * @brief 获取文件系统类型
  735. *
  736. * @param path 路径
  737. *
  738. * @return 文件系统类型
  739. */
  740. /* ----------------------------------------------------------------------------*/
  741. const char *fget_fs_type(const char *path); // 获取文件系统类型
  742. /* --------------------------------------------------------------------------*/
  743. /**
  744. * @brief 录音获取最后序号
  745. *
  746. * @return 最后序号
  747. */
  748. /* ----------------------------------------------------------------------------*/
  749. int get_last_num(void); //录音获取最后序号。
  750. /* --------------------------------------------------------------------------*/
  751. /**
  752. * @brief 设置断点参数
  753. *
  754. * @param clust 记录的簇号
  755. * @param fsize 记录的文件大小
  756. * @param flag 文件是否存在标志
  757. *
  758. * @note 1.接口调用在扫描前
  759. * 2.使用完需要put_bp_info对应释放buf
  760. */
  761. /* ----------------------------------------------------------------------------*/
  762. void set_bp_info(u32 clust, u32 fsize, u32 *flag); //扫描前设置断点参数,需要put_bp_info对应释放buf.
  763. /* --------------------------------------------------------------------------*/
  764. /**
  765. * @brief 释放内存
  766. */
  767. /* ----------------------------------------------------------------------------*/
  768. void put_bp_info(void);
  769. /* --------------------------------------------------------------------------*/
  770. /**
  771. * @brief 优化扫盘速度
  772. *
  773. * @param enable 开关
  774. * @note 1.目的是是否去除获取文件夹内所有文件功能,默认enable 是1 获取数目,置0不获取,所以不需要切换文件夹操作的功能,可置0 关闭
  775. * 2.在扫描前调用接口
  776. */
  777. /* ----------------------------------------------------------------------------*/
  778. void ff_set_FileInDir_enable(u8 enable); // 优化文件打开速度,如果不需要切换文件夹的操作,可置0关闭
  779. /* --------------------------------------------------------------------------*/
  780. /**
  781. * @brief 设置目录项基点信息(用于加速)
  782. *
  783. * @param buf 存储基点buf (长度 12 * n)
  784. * @param n 基点数目
  785. * @note 1.加速序号选择文件,明显效果体现在上一曲加速
  786. * 2.注意buf使用
  787. */
  788. /* ----------------------------------------------------------------------------*/
  789. void ff_set_DirBaseInfo(void *buf, u16 n);
  790. /* --------------------------------------------------------------------------*/
  791. /**
  792. * @brief 设置文件的创建时间
  793. *
  794. * @param year 年
  795. * @param month 月
  796. * @param day 日
  797. * @param hour 小时
  798. * @param minute 分钟
  799. * @param second 秒
  800. */
  801. /* ----------------------------------------------------------------------------*/
  802. void fat_set_datetime_info(u16 year, u8 month, u8 day, u8 hour, u8 minute, u8 second);
  803. /* --------------------------------------------------------------------------*/
  804. /**
  805. * @brief 隐藏属性文件是否过滤
  806. *
  807. * @param flag 置1 为过滤
  808. */
  809. /* ----------------------------------------------------------------------------*/
  810. void hidden_file(u8 flag);
  811. /* --------------------------------------------------------------------------*/
  812. /**
  813. * @brief 是否保存预申请长度
  814. *
  815. * @param enable 1保存,0 不保存
  816. */
  817. /* ----------------------------------------------------------------------------*/
  818. void fat_save_already_size_enable(char enable);
  819. /* --------------------------------------------------------------------------*/
  820. /**
  821. * @brief 设置预申请簇数目
  822. *
  823. * @param num 数目(1-0x1fe)
  824. */
  825. /* ----------------------------------------------------------------------------*/
  826. void fat_set_pre_create_chain_num(u16 num);
  827. /* --------------------------------------------------------------------------*/
  828. /**
  829. * @brief 存储文件簇信息
  830. *
  831. * @param file 文件句柄
  832. * @param btr buf 长度
  833. * @param buf buf指针
  834. *
  835. * @note seek加速,4字节对齐
  836. * @return 0成功,非0不成功
  837. */
  838. /* ----------------------------------------------------------------------------*/
  839. int fsave_fat_table(FILE *file, u16 btr, u8 *buf);
  840. /* --------------------------------------------------------------------------*/
  841. /**
  842. * @brief 刷新文件系统缓存buf
  843. *
  844. * @param path 设备路径
  845. *
  846. * @return 0成功,非0不成功
  847. */
  848. /* ----------------------------------------------------------------------------*/
  849. int f_flush_wbuf(const char *path);
  850. /* --------------------------------------------------------------------------*/
  851. /**
  852. * @brief 插入文件
  853. *
  854. * @param file 源文件
  855. * @param i_file 需要插入的文件
  856. * @param fptr 源文件被插入的位置
  857. *
  858. * @return 0成功,非0不成功
  859. */
  860. /* ----------------------------------------------------------------------------*/
  861. int finsert_file(FILE *file, FILE *i_file, u32 fptr);
  862. /* --------------------------------------------------------------------------*/
  863. /**
  864. * @brief 分割文件
  865. *
  866. * @param file 源文件
  867. * @param file_name 分割后第二个文件文件名
  868. * @param fptr 源文件被分割位置
  869. *
  870. * @return 0成功,非0不成功
  871. */
  872. /* ----------------------------------------------------------------------------*/
  873. int fdicvision_file(FILE *file, char *file_name, u32 fptr);
  874. /* --------------------------------------------------------------------------*/
  875. /**
  876. * @brief 长文件名切割00 00 后面的数据
  877. *
  878. * @param str 数据buff
  879. * @param len 数据buff长度
  880. *
  881. * @return 切割后的长度
  882. */
  883. /* ----------------------------------------------------------------------------*/
  884. int long_name_fix(u8 *str, u16 len);
  885. /* --------------------------------------------------------------------------*/
  886. /**
  887. * @brief UFT8 转换 Unicode
  888. *
  889. * @param utf8_buf UTF8编码的字符串
  890. * @param pUniBuf short 类型Unicode字符串
  891. * @param utf8_len utf8数据长度
  892. *
  893. * @return 得到的unicode码大小
  894. */
  895. /* ----------------------------------------------------------------------------*/
  896. int UTF82Unicode(const char *utf8_buf, u16 *pUniBuf, int utf8_len);
  897. /* --------------------------------------------------------------------------*/
  898. /**
  899. * @brief Unicode 转 UTF8
  900. *
  901. *
  902. * @param utf8_buf UTF8编码的字符串
  903. * @param pUniBuf short 类型Unicode字符串
  904. * @param uni_len unicode数据长度
  905. *
  906. * @return 得到的UTF8码大小
  907. */
  908. /* ----------------------------------------------------------------------------*/
  909. int Unicode2UTF8(char *utf8_buf, u16 *pUniBuf, int uni_len);
  910. /* --------------------------------------------------------------------------*/
  911. /**
  912. * @brief 检查是否UTF8 码格式
  913. *
  914. * @param str 数据buff
  915. * @param length 数据buff长度
  916. *
  917. * @return 1:是UTF8 0:不是
  918. */
  919. /* ----------------------------------------------------------------------------*/
  920. bool utf8_check(const char *str, int length);
  921. #endif /* VFS_ENABLE */
  922. #endif /* __FS_H__ */