⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fat.cod

📁 EP9315的BSP包(WINCE下的BSP,内有各种驱动的详细的代码)
💻 COD
📖 第 1 页 / 共 2 页
字号:
; 216  :       
; 217  :         // TODO - can optimize reads here by avoiding intermediate buffer copy...
; 218  :         // Otherwise - read full sectors into buffer
; 219  : 	    sectstoread = bytestoread / SECTOR_SIZE;
; 220  : 	    bytestoread = bytestoread % SECTOR_SIZE;
; 221  : 
; 222  :         while (sectstoread)
; 223  :         {
; 224  :             // EOF?
; 225  :             if (g_fileinfo.curclust >= 0xfff8 && g_fileinfo.curclust <= 0xffff)
; 226  :                 return(FAT_EOF);
; 227  : 
; 228  :             memset(&g_bsect[0], 0, SECTOR_SIZE);
; 229  :             if (read_sector(g_fileinfo.cursect, &g_bsect[0]))
; 230  :             {
; 231  :                 RETAILMSG(1, (TEXT("ERROR: Couldn't read data sector\r\n")));
; 232  :                 return(-1);
; 233  :             }
; 234  : 
; 235  :             // jump to next cluster if we've read all the sectors in the current
; 236  :             g_fileinfo.sectreminclust--;
; 237  :             g_fileinfo.cursect++;
; 238  :             if (g_fileinfo.sectreminclust == 0)
; 239  :             {
; 240  :                 ++g_fileinfo.clusttlbofst;
; 241  :                 g_fileinfo.sectreminclust = g_fatparms.sectspclust;
; 242  :                 g_fileinfo.curclust = *((USHORT *)CLUST_LIST_START + g_fileinfo.clusttlbofst);
; 243  :                 g_fileinfo.cursect = clust_to_lba(g_fileinfo.curclust);
; 244  :             }
; 245  : 
; 246  : 	    memcpy(ptmp, &g_bsect[0], SECTOR_SIZE);
; 247  : 	    ptmp += SECTOR_SIZE;
; 248  : 	    g_fileinfo.bytesreminsect = 0;
; 249  : 	    --sectstoread;
; 250  :         }
; 251  :     }
; 252  :     #endif // 0
; 253  : 
; 254  :     return(0);

  00000	e3a00000	 mov       r0, #0

; 255  : }

  00004	e12fff1e	 bx        lr
  00008		 |$M36697|

			 ENDP  ; |file_read|

	EXPORT	|file_open|

  00000			 AREA	 |.text| { |file_open| }, CODE, ARM, SELECTION=1 ; comdat noduplicate

  00000			 AREA	 |.pdata$$file_open|, PDATA, SELECTION=5, ASSOC=|.text| { |file_open| } ; comdat associative
|$T36705| DCD	|file_open|
	DCD	0x40000200
; Function compile flags: /Ogsy

  00000			 AREA	 |.text| { |file_open| }, CODE, ARM, SELECTION=1 ; comdat noduplicate

  00000		 |file_open| PROC

; 259  : {

  00000		 |$M36703|

; 260  :     #if 0
; 261  :     USHORT i = 0;
; 262  :     USHORT j = 0;
; 263  :     UCHAR fname[11] = {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '};
; 264  :     UCHAR bsect[SECTOR_SIZE];
; 265  :     PDIRENTRY pdirentry = NULL;
; 266  :     ULONG dirlba = 0;
; 267  :     UCHAR found = 0;
; 268  : 
; 269  :     if (pfname == NULL)
; 270  :         return(-1);
; 271  : 
; 272  :     for (i = 0 ; i < 8 && *(pfname + i) != '\0' && *(pfname + i) != '.' ; i++)
; 273  :         fname[i] = TO_UPPER(*(pfname + i));
; 274  :     if (*(pfname + i) == '.')
; 275  :     {
; 276  :         i++;
; 277  :         for (j=0 ; i < 12 && *(pfname + i) != '\0' ; i++, j++)
; 278  :         fname[8 + j] = TO_UPPER(*(pfname + i));
; 279  :     }
; 280  : 
; 281  :     // Look for filename in directory list
; 282  :     for (found=0, i=0, dirlba=g_fatparms.rootdirlba ; !found && i < g_fatparms.numrootentry ; dirlba++)
; 283  :     {
; 284  :         memset(&bsect[0], 0, SECTOR_SIZE);
; 285  : 
; 286  :         DEBUGMSG(ZONE_INFO, (TEXT("INFO: Reading root dir sector (LBA=0x%x).\r\n"), dirlba));
; 287  : 
; 288  :         if (read_sector(dirlba, &bsect[0]))
; 289  :         {
; 290  :             RETAILMSG(1, (TEXT("ERROR: Couldn't read root dir sector.\r\n")));
; 291  :             return(-1);
; 292  :         }
; 293  : 
; 294  :         for (pdirentry = (PDIRENTRY)&bsect[0], j=0 ; j < (SECTOR_SIZE / sizeof(DIRENTRY)) && i < g_fatparms.numrootentry ; j++, i++, pdirentry++)
; 295  :         {
; 296  :             DEBUGMSG(ZONE_INFO, (TEXT("INFO: %d: fname '%s' fsize = 0x%x.\r\n"), j, &(pdirentry->fname[0]), pdirentry->fsize));
; 297  : 
; 298  :             if (!memcmp(&fname[0], &(pdirentry->fname[0]), 11))
; 299  :             {
; 300  :                 found=1;
; 301  :                 break;
; 302  :             }
; 303  :         }
; 304  :     } 
; 305  : 
; 306  : 
; 307  :     if (!found || !pdirentry)
; 308  :     {
; 309  :         RETAILMSG(1, (TEXT("ERROR: Couldn't find file '%s'.\r\n"), pfname)); 
; 310  :         return(-1);
; 311  :     }
; 312  :     else
; 313  :     {
; 314  :         DEBUGMSG(ZONE_INFO, (TEXT("INFO: Found file '%s' (Start clust = 0x%x  size = 0x%x).\r\n"), pfname, pdirentry->fclust, pdirentry->fsize)); 
; 315  :     }
; 316  :    
; 317  :     // Save file parameters
; 318  :     g_fileinfo.curclust = pdirentry->fclust;
; 319  :     g_fileinfo.cursect = clust_to_lba(g_fileinfo.curclust);
; 320  :     g_fileinfo.fsize = pdirentry->fsize;
; 321  :     g_fileinfo.bytesreminsect = 0;
; 322  :     g_fileinfo.clusttlbofst  = 0;
; 323  :     g_fileinfo.sectreminclust = g_fatparms.sectspclust;
; 324  :     g_fileinfo.byteofst = 0;
; 325  : 
; 326  :     // Build cluster list from FAT for file
; 327  :     if (build_clust_list())
; 328  :     {
; 329  :         RETAILMSG(1, (TEXT("ERROR: Couldn't build cluster list for '%s'.\r\n"), pfname)); 
; 330  :         return(-1);
; 331  :     }
; 332  :     #endif // 0
; 333  :     return(0);

  00000	e3a00000	 mov       r0, #0

; 334  : }

  00004	e12fff1e	 bx        lr
  00008		 |$M36704|

			 ENDP  ; |file_open|

	EXPORT	|file_close|

  00000			 AREA	 |.text| { |file_close| }, CODE, ARM, SELECTION=1 ; comdat noduplicate

  00000			 AREA	 |.pdata$$file_close|, PDATA, SELECTION=5, ASSOC=|.text| { |file_close| } ; comdat associative
|$T36712| DCD	|file_close|
	DCD	0x40000200
; Function compile flags: /Ogsy

  00000			 AREA	 |.text| { |file_close| }, CODE, ARM, SELECTION=1 ; comdat noduplicate

  00000		 |file_close| PROC

; 338  : {

  00000		 |$M36710|

; 339  :     #if 0
; 340  :     USHORT *pclustlist = (USHORT *)CLUST_LIST_START;
; 341  : 
; 342  :     *pclustlist = 0xffff;
; 343  : 
; 344  :     memset(&g_fileinfo, 0, sizeof(g_fileinfo));
; 345  :     #endif // 0
; 346  : 
; 347  :     return(0);

  00000	e3a00000	 mov       r0, #0

; 348  : }

  00004	e12fff1e	 bx        lr
  00008		 |$M36711|

			 ENDP  ; |file_close|

	EXPORT	|build_clust_list|

  00000			 AREA	 |.text| { |build_clust_list| }, CODE, ARM, SELECTION=1 ; comdat noduplicate

  00000			 AREA	 |.pdata$$build_clust_list|, PDATA, SELECTION=5, ASSOC=|.text| { |build_clust_list| } ; comdat associative
|$T36719| DCD	|build_clust_list|
	DCD	0x40000200
; Function compile flags: /Ogsy

  00000			 AREA	 |.text| { |build_clust_list| }, CODE, ARM, SELECTION=1 ; comdat noduplicate

  00000		 |build_clust_list| PROC

; 352  : {

  00000		 |$M36717|

; 353  :     #if 0
; 354  :     USHORT curclust = g_fileinfo.curclust;
; 355  :     USHORT cnt = 0; 
; 356  :     USHORT *pclustlist = (USHORT *)CLUST_LIST_START;
; 357  :     ULONG curlba = 0;
; 358  :     UCHAR bsect[SECTOR_SIZE];
; 359  :     ULONG tmp = 0;
; 360  :     USHORT byteofst = 0;
; 361  : 
; 362  :     // While we point at a valid cluster value, walk the list and build a 
; 363  :     // linear summary...
; 364  :     while (curclust >= 0x2 && curclust <= 0xffef)
; 365  :     {
; 366  :         // Save cluster value
; 367  :         *(pclustlist + cnt) = curclust;
; 368  :         ++cnt;
; 369  : 
; 370  :         // Determine FAT LBA address and byte offset into sector for lookup
; 371  :         tmp = curclust * sizeof(USHORT);
; 372  :         byteofst = (USHORT)tmp % SECTOR_SIZE;
; 373  :         tmp /= SECTOR_SIZE;
; 374  :         tmp += g_fatparms.fatlba;
; 375  : 
; 376  :         // We haven't read needed sector yet - do it.
; 377  :         if (tmp != curlba)
; 378  :         {
; 379  :             memset(&bsect[0], 0, SECTOR_SIZE);
; 380  :             if (read_sector(tmp, &bsect[0]))
; 381  :             {
; 382  :                 RETAILMSG(1, (TEXT("ERROR: Couldn't read FAT.\r\n")));
; 383  :                 return(-1);
; 384  :             }
; 385  :             curlba = tmp; 
; 386  :         }
; 387  : 
; 388  :         // Look up next cluster in list
; 389  :         curclust = *((USHORT *)(&bsect[0] + byteofst));
; 390  :     }
; 391  : 
; 392  :     // Done - set end of list cluster tag.
; 393  :     if (curclust >= 0xfff8 && curclust <= 0xffff)
; 394  :     {
; 395  :         *(pclustlist + cnt) = curclust;
; 396  :         ++cnt;
; 397  :     }
; 398  :     else
; 399  :     {
; 400  :         RETAILMSG(1, (TEXT("ERROR: Failed to build cluster list.\r\n")));
; 401  :         return(-1);
; 402  :     }
; 403  : 
; 404  :     DEBUGMSG(ZONE_INFO, (TEXT("INFO: Built cluster list (size = 0x%x).\r\n"), cnt));
; 405  :     #endif // 0
; 406  : 
; 407  :     return(0);    

  00000	e3a00000	 mov       r0, #0

; 408  : }

  00004	e12fff1e	 bx        lr
  00008		 |$M36718|

			 ENDP  ; |build_clust_list|

	END

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -