summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSinthu Raja M2018-11-16 06:21:53 -0600
committerM V Pratap Reddy2018-12-04 15:28:03 -0600
commit952afffb83642c4c158bc0252c0fd77b6457aebd (patch)
tree383410f0a0eb94237fa8e0d5c62dcfd5a70df22e
parentdbf6b5969bb2d16256f508f3312018df85381e40 (diff)
downloadfatfs-952afffb83642c4c158bc0252c0fd77b6457aebd.tar.gz
fatfs-952afffb83642c4c158bc0252c0fd77b6457aebd.tar.xz
fatfs-952afffb83642c4c158bc0252c0fd77b6457aebd.zip
PRSDK-4440 Add volume status variable to indicate the application
Add FATFS_volumeStaus variable to indicate the application of the VolToPart table is full and no further partition can be added.
-rw-r--r--FATFS.h25
-rw-r--r--src/FATFS_drv.c54
2 files changed, 59 insertions, 20 deletions
diff --git a/FATFS.h b/FATFS.h
index a6cafc8..507e512 100644
--- a/FATFS.h
+++ b/FATFS.h
@@ -68,6 +68,20 @@ extern "C" {
68 */ 68 */
69#define FATFS_ERR (-(1)) 69#define FATFS_ERR (-(1))
70 70
71/**
72 * @def FATFS_VOLUME_FULL_ERR
73 * FATFS return code -- VolToPart structure is full and
74 * no index to add more partitions
75 */
76#define FATFS_VOLUME_FULL_ERR (-(10))
77
78/**
79 * @def FATFS_VOLUME_DISK_AVL
80 * FATFS status code -- VolToPart structure is available
81 * to add partitions
82 */
83#define FATFS_VOLUME_DISK_AVL (0)
84
71/*Offset macros of MBR table */ 85/*Offset macros of MBR table */
72/** 86/**
73 * @def FATFS_MBR_TABLE 87 * @def FATFS_MBR_TABLE
@@ -95,9 +109,15 @@ extern "C" {
95 109
96/** 110/**
97 * @def FATFS_DFLT_VOLUME_INDEX 111 * @def FATFS_DFLT_VOLUME_INDEX
98 * Default value of the VolToPart structure variable 112 * Default value of the VolToPart structure variable: partition disk
99 */ 113 */
100#define FATFS_DFLT_VOLUME_INDEX 0xf 114#define FATFS_DFLT_VOLUME_PD 0xf
115
116/**
117 * @def FATFS_DFLT_VOLUME_INDEX
118 * Default value of the VolToPart structure variable: partition number
119 */
120#define FATFS_DFLT_VOLUME_PT 0xf
101 121
102/*@}*/ 122/*@}*/
103/** @} */ 123/** @} */
@@ -250,6 +270,7 @@ typedef struct FATFS_Object_s {
250 FATFS_ConfigParams FATFSConfigParams; /*! Stores SD parameters */ 270 FATFS_ConfigParams FATFSConfigParams; /*! Stores SD parameters */
251 271
252 uint32_t isOpen; /*! flag to indicate module is open */ 272 uint32_t isOpen; /*! flag to indicate module is open */
273
253} FATFS_Object; 274} FATFS_Object;
254 275
255/*! 276/*!
diff --git a/src/FATFS_drv.c b/src/FATFS_drv.c
index 175c182..b631876 100644
--- a/src/FATFS_drv.c
+++ b/src/FATFS_drv.c
@@ -52,10 +52,10 @@
52 52
53/* Table to map multi-partition with multi-storage device*/ 53/* Table to map multi-partition with multi-storage device*/
54PARTITION VolToPart[FATFS_NUM_OF_PARTITIONS] = { 54PARTITION VolToPart[FATFS_NUM_OF_PARTITIONS] = {
55 {FATFS_DFLT_VOLUME_INDEX /*pd */,FATFS_DFLT_VOLUME_INDEX /* pt */}, 55 {FATFS_DFLT_VOLUME_PD /*pd */,FATFS_DFLT_VOLUME_PT /* pt */},
56 {FATFS_DFLT_VOLUME_INDEX /*pd */,FATFS_DFLT_VOLUME_INDEX /* pt */}, 56 {FATFS_DFLT_VOLUME_PD /*pd */,FATFS_DFLT_VOLUME_PT /* pt */},
57 {FATFS_DFLT_VOLUME_INDEX /*pd */,FATFS_DFLT_VOLUME_INDEX /* pt */}, 57 {FATFS_DFLT_VOLUME_PD /*pd */,FATFS_DFLT_VOLUME_PT /* pt */},
58 {FATFS_DFLT_VOLUME_INDEX /*pd */,FATFS_DFLT_VOLUME_INDEX /* pt */}, 58 {FATFS_DFLT_VOLUME_PD /*pd */,FATFS_DFLT_VOLUME_PT /* pt */},
59}; 59};
60 60
61/* Function prototypes */ 61/* Function prototypes */
@@ -76,6 +76,9 @@ extern const FATFSConfigList FATFS_config;
76/* Used to check status and initialization */ 76/* Used to check status and initialization */
77static int32_t FATFS_count = -1; 77static int32_t FATFS_count = -1;
78 78
79/* Used to check the status of the VolToPart table availability */
80static int32_t FATFS_volumeStatus = 0;
81
79/* Default SD parameters structure */ 82/* Default SD parameters structure */
80const FATFS_ConfigParams FATFS_defaultParams = { 83const FATFS_ConfigParams FATFS_defaultParams = {
81 NULL, 84 NULL,
@@ -121,11 +124,15 @@ FATFS_Error FATFS_close(FATFS_Handle handle)
121 snprintf(drive_path,sizeof(drive_path),"%d:",(int)volIndex); 124 snprintf(drive_path,sizeof(drive_path),"%d:",(int)volIndex);
122 fresult = f_mount(NULL,drive_path,0); 125 fresult = f_mount(NULL,drive_path,0);
123 126
124 VolToPart[volIndex].pd = FATFS_DFLT_VOLUME_INDEX; 127 /*Reset the VolToPart index to default value */
125 VolToPart[volIndex].pt = FATFS_DFLT_VOLUME_INDEX; 128 VolToPart[volIndex].pd = FATFS_DFLT_VOLUME_PD;
129 VolToPart[volIndex].pt = FATFS_DFLT_VOLUME_PT;
126 } 130 }
127 } 131 }
128 132
133 /* Set Volume status for availability */
134 FATFS_volumeStatus = FATFS_VOLUME_DISK_AVL;
135
129 if (fresult != FR_OK) { 136 if (fresult != FR_OK) {
130#ifdef LOG_EN 137#ifdef LOG_EN
131 Log_print2(Diags_USER1, 138 Log_print2(Diags_USER1,
@@ -208,9 +215,9 @@ FATFS_Error FATFS_open(uint32_t index,
208 215
209 /*Verify there is free index available in VolToPart for mapping this disk partitions */ 216 /*Verify there is free index available in VolToPart for mapping this disk partitions */
210 volIndex = FATFS_getFreeVolIndex(); 217 volIndex = FATFS_getFreeVolIndex();
211 if(FATFS_ERR == volIndex) 218 if(volIndex < 0)
212 { 219 {
213 return ret; 220 return FATFS_VOLUME_FULL_ERR;
214 } 221 }
215 222
216 /* Get handle for this driver instance */ 223 /* Get handle for this driver instance */
@@ -266,9 +273,9 @@ FATFS_Error FATFS_open(uint32_t index,
266#endif 273#endif
267 FATFS_close(handle); 274 FATFS_close(handle);
268 275
269 /*Restore VolToPart to remove the previous entry*/ 276 /*Restore VolToPart to remove the entry*/
270 VolToPart[volIndex].pt = FATFS_DFLT_VOLUME_INDEX; 277 VolToPart[volIndex].pt = FATFS_DFLT_VOLUME_PD;
271 VolToPart[volIndex].pd = FATFS_DFLT_VOLUME_INDEX; 278 VolToPart[volIndex].pd = FATFS_DFLT_VOLUME_PT;
272 ret = FATFS_ERR; 279 ret = FATFS_ERR;
273 } 280 }
274 } 281 }
@@ -290,10 +297,18 @@ FATFS_Error FATFS_open(uint32_t index,
290#endif 297#endif
291 FATFS_close(handle); 298 FATFS_close(handle);
292 299
293 /*Restore VolToPart to remove the previous entry*/ 300 /*Restore VolToPart to remove the entry*/
294 VolToPart[volIndex].pt = FATFS_DFLT_VOLUME_INDEX; 301 VolToPart[volIndex].pt = FATFS_DFLT_VOLUME_PD;
295 VolToPart[volIndex].pd = FATFS_DFLT_VOLUME_INDEX; 302 VolToPart[volIndex].pd = FATFS_DFLT_VOLUME_PT;
296 ret = FATFS_ERR; 303
304 if(FATFS_volumeStatus == FATFS_VOLUME_FULL_ERR)
305 {
306 ret = FATFS_VOLUME_FULL_ERR;
307 }
308 else
309 {
310 ret = FATFS_ERR;
311 }
297 } 312 }
298 313
299 } 314 }
@@ -386,6 +401,9 @@ static DSTATUS FATFS_diskInitialize(BYTE drv)
386 { 401 {
387 FATFS_drv_log("\r\nReading MBR failed \r\n"); 402 FATFS_drv_log("\r\nReading MBR failed \r\n");
388 res = STA_NOINIT; 403 res = STA_NOINIT;
404
405 /* To indicate the the FATFS_open function about the VolToPart table full */
406 FATFS_volumeStatus = FATFS_VOLUME_FULL_ERR;
389 } 407 }
390 408
391 return ((DSTATUS)res); 409 return ((DSTATUS)res);
@@ -649,7 +667,7 @@ static FATFS_Error FATFS_readBootSector(BYTE drv)
649 } 667 }
650 else 668 else
651 { 669 {
652 res = FR_DISK_ERR; 670 res = FATFS_VOLUME_FULL_ERR;
653 break; 671 break;
654 } 672 }
655 } 673 }
@@ -674,11 +692,11 @@ static int32_t FATFS_getFreeVolIndex()
674 692
675 for (index = 0; index < FATFS_NUM_OF_PARTITIONS; index++) 693 for (index = 0; index < FATFS_NUM_OF_PARTITIONS; index++)
676 { 694 {
677 if(VolToPart[index].pd == FATFS_DFLT_VOLUME_INDEX) 695 if(VolToPart[index].pd == FATFS_DFLT_VOLUME_PD)
678 { 696 {
679 return index; 697 return index;
680 } 698 }
681 } 699 }
682 700
683 return FATFS_ERR; 701 return FATFS_VOLUME_FULL_ERR;
684} 702}