source: S-port/trunk/Middlewares/Third_Party/FatFs/src/ff_gen_drv.c

Last change on this file was 1, checked in by AlexLir, 3 years ago
File size: 3.8 KB
Line 
1/**
2 ******************************************************************************
3 * @file ff_gen_drv.c
4 * @author MCD Application Team
5 * @brief FatFs generic low level driver.
6 *****************************************************************************
7 * @attention
8 *
9 * Copyright (c) 2017 STMicroelectronics. All rights reserved.
10 *
11 * This software component is licensed by ST under BSD 3-Clause license,
12 * the "License"; You may not use this file except in compliance with the
13 * License. You may obtain a copy of the License at:
14 * opensource.org/licenses/BSD-3-Clause
15 *
16 ******************************************************************************
17**/
18/* Includes ------------------------------------------------------------------*/
19#include "ff_gen_drv.h"
20
21/* Private typedef -----------------------------------------------------------*/
22/* Private define ------------------------------------------------------------*/
23/* Private variables ---------------------------------------------------------*/
24Disk_drvTypeDef disk = {{0},{0},{0},0};
25
26/* Private function prototypes -----------------------------------------------*/
27/* Private functions ---------------------------------------------------------*/
28
29/**
30 * @brief Links a compatible diskio driver/lun id and increments the number of active
31 * linked drivers.
32 * @note The number of linked drivers (volumes) is up to 10 due to FatFs limits.
33 * @param drv: pointer to the disk IO Driver structure
34 * @param path: pointer to the logical drive path
35 * @param lun : only used for USB Key Disk to add multi-lun management
36 else the parameter must be equal to 0
37 * @retval Returns 0 in case of success, otherwise 1.
38 */
39uint8_t FATFS_LinkDriverEx(const Diskio_drvTypeDef *drv, char *path, uint8_t lun)
40{
41 uint8_t ret = 1;
42 uint8_t DiskNum = 0;
43
44 if(disk.nbr < _VOLUMES)
45 {
46 disk.is_initialized[disk.nbr] = 0;
47 disk.drv[disk.nbr] = drv;
48 disk.lun[disk.nbr] = lun;
49 DiskNum = disk.nbr++;
50 path[0] = DiskNum + '0';
51 path[1] = ':';
52 path[2] = '/';
53 path[3] = 0;
54 ret = 0;
55 }
56
57 return ret;
58}
59
60/**
61 * @brief Links a compatible diskio driver and increments the number of active
62 * linked drivers.
63 * @note The number of linked drivers (volumes) is up to 10 due to FatFs limits
64 * @param drv: pointer to the disk IO Driver structure
65 * @param path: pointer to the logical drive path
66 * @retval Returns 0 in case of success, otherwise 1.
67 */
68uint8_t FATFS_LinkDriver(const Diskio_drvTypeDef *drv, char *path)
69{
70 return FATFS_LinkDriverEx(drv, path, 0);
71}
72
73/**
74 * @brief Unlinks a diskio driver and decrements the number of active linked
75 * drivers.
76 * @param path: pointer to the logical drive path
77 * @param lun : not used
78 * @retval Returns 0 in case of success, otherwise 1.
79 */
80uint8_t FATFS_UnLinkDriverEx(char *path, uint8_t lun)
81{
82 uint8_t DiskNum = 0;
83 uint8_t ret = 1;
84
85 if(disk.nbr >= 1)
86 {
87 DiskNum = path[0] - '0';
88 if(disk.drv[DiskNum] != 0)
89 {
90 disk.drv[DiskNum] = 0;
91 disk.lun[DiskNum] = 0;
92 disk.nbr--;
93 ret = 0;
94 }
95 }
96
97 return ret;
98}
99
100/**
101 * @brief Unlinks a diskio driver and decrements the number of active linked
102 * drivers.
103 * @param path: pointer to the logical drive path
104 * @retval Returns 0 in case of success, otherwise 1.
105 */
106uint8_t FATFS_UnLinkDriver(char *path)
107{
108 return FATFS_UnLinkDriverEx(path, 0);
109}
110
111/**
112 * @brief Gets number of linked drivers to the FatFs module.
113 * @param None
114 * @retval Number of attached drivers.
115 */
116uint8_t FATFS_GetAttachedDriversNbr(void)
117{
118 return disk.nbr;
119}
120
121/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
122
Note: See TracBrowser for help on using the repository browser.