示例#1
0
文件: filesystem.c 项目: BigEd/pyldin
static int wrap_fs_readdir_r(struct _reent *r, void *dirp, struct dirent *entry, struct dirent **result)
{
    DirList *list = dirp;
    if (ls_getNext(list) != 0) {
	*result = NULL;
	return 0;
    }
//    strncpy(entry->d_name, (char *)list->currentEntry.FileName, NAME_MAX - 1);
// OMG we use 8+3!
    strncpy(entry->d_name, (char *)list->currentEntry.FileName, 8 + 3);
    entry->d_name[8 + 3] = 0;
    entry->d_size = list->currentEntry.FileSize;
    if (list->currentEntry.Attribute & ATTR_DIRECTORY)
	entry->d_type |= DT_DIR;
    else
	entry->d_type |= DT_REG;
    *result = entry;
    return 0;
}
示例#2
0
void ls_fnt(int argc, char** argv)
{
//	MESSAGE("Directory of root\n\r");
	if(argc != 2)
	{
		MESSAGE("usage: ls {path_name}\n\r");
		return;

	}
	MESSAGE("listing directory %s:\n\r", argv[1]);
	ls_openDir( &list, &(efs.myFs) , argv[1]);
	while ( ls_getNext( &list ) == 0 ) {
		list.currentEntry.FileName[LIST_MAXLENFILENAME-1] = '\0';
		MESSAGE( "%s ( %d bytes )\n\r", list.currentEntry.FileName,list.currentEntry.FileSize ) ;
		}

	
	return;
}
示例#3
0
文件: efs.c 项目: samkrew/nxp-lpc
/**
 * This function will set a hook function, which will be invoked when a memory 
 * block is allocated from heap memory.
 * 
 * @param hook the hook function
 */
int efs_getdents(struct dfs_fd* file, struct dfs_dirent* dirp, rt_uint32_t count)
{
	DirList* efsdir = (DirList*)file->data;
	struct dfs_dirent* d;
	int result = 0;

	/* fd check */
	if ( efsdir == RT_NULL) return -DFS_STATUS_EBADF;

	/* flags check */
	if(!(file->flags & DFS_F_DIRECTORY)) return -DFS_STATUS_EBADF;

	/* make integer count */
	count = (count / sizeof(struct dfs_dirent)) * sizeof(struct dfs_dirent);
	if ( count == 0 ) return -DFS_STATUS_EINVAL;

	while(1)
	{
		/* it's the end of file */
		if(ls_getNext(efsdir) < 0) return 0;

		d = dirp + result;
    		/* copy dirent name */
		fat_ShortnameToString(efsdir->currentEntry.FileName, d->d_name);
		d->d_reclen = (euint16)sizeof(struct dfs_dirent);	

		/* set type */
		d->d_type = DFS_DT_UNKNOWN;
		if (efsdir->currentEntry.Attribute & ATTR_DIRECTORY ) d->d_type &= DFS_DT_DIR;
		else d->d_type &= DFS_DT_REG;

		result ++;

		/* is it enough? */
		if ( result * sizeof(struct dfs_dirent) >= count )
			break;
	}

	return result * sizeof(struct dfs_dirent);
}
示例#4
0
int
cfs_readdir (struct cfs_dir *dirp, struct cfs_dirent *dirent)
{
  euint8 *start;
  euint8 *end;
  char *to = dirent->name;
  DirList *dirs = *(DirList**)dirp;
  if (sdcard_efs.myCard.sectorCount == 0) return 1;
  if (ls_getNext(dirs) != 0) return 1;
  start = dirs->currentEntry.FileName;
  end = start + 7;
  while(end > start) {
    if (*end > ' ') {
      end++;
      break;
    }
    end--;
  }
  while(start < end) {
    *to++ = *start++;
  }
  start = dirs->currentEntry.FileName + 8;
  end = start + 3;
  if (*start > ' ') {
    *to++ = '.';
    *to++ = *start++;
    while(start < end && *start > ' ') {
      *to++ = *start++;
    }
  }
  *to = '\0';
  if (dirs->currentEntry.Attribute & ATTR_DIRECTORY) {
    dirent->size = 0;
  } else {
    dirent->size = dirs->currentEntry.FileSize;
  }
  return 0;
}
int main()
{
	int8_t res;
    uint32_t n, m, p, cnt;
    uint32_t cclk = CLKPWR_GetCLK(CLKPWR_CLKTYPE_CPU);
    uint32_t filesize = 0;
    uint32_t time_end;

//	SystemInit();
    SysTick_Config(cclk/1000 - 1); /* Generate interrupt each 1 ms   */

	debug_frmwrk_init(); // UART0
    xfunc_out = put_char;
	xfunc_in  = get_char; 

    xprintf("%s",mciFsMenu);

	xprintf("\nMMC/SD Card Filesystem Test (P:LPC1788 L:EFSL)\n");

	xprintf("\nCARD init...");

	// init file system
	if ( ( res = efs_init( &efs, 0 ) ) != 0 ) {
		xprintf("failed with %d\n",res);
	}
	else 
	{
		xprintf("ok\n");

        xprintf("Card type: ");
        switch (CardConfig.CardType)
        {
            case MCI_MMC_CARD:
                xprintf("MMC\n");
                break;
            case MCI_SDSC_V1_CARD:
                xprintf("Version 1.x Standard Capacity SD card.\n");
                break;
            case MCI_SDSC_V2_CARD:
                xprintf("Version 2.0 or later Standard Capacity SD card.\n");
                break;
            case MCI_SDHC_SDXC_CARD:
                xprintf("Version 2.0 or later High/eXtended Capacity SD card.\n");
                break;
            default:
                break;            
        }
        xprintf("Sector size: %d bytes\n", CardConfig.SectorSize);
        xprintf("Sector count: %d\n", CardConfig.SectorCount);
        xprintf("Block size: %d sectors\n", CardConfig.BlockSize);
        xprintf("Card capacity: %d MByte\n\n", (((CardConfig.SectorCount >> 10) * CardConfig.SectorSize)) >> 10);
		xprintf("\nDirectory of 'root':\n");
		
		/* list files in root directory */
		ls_openDir( &list, &(efs.myFs) , "/");
		while ( ls_getNext( &list ) == 0 ) {
			// list.currentEntry is the current file
			list.currentEntry.FileName[LIST_MAXLENFILENAME-1] = '\0';
			xprintf("%s, 0x%x bytes\n", list.currentEntry.FileName, list.currentEntry.FileSize ) ;
		}
#if READ_TEST_ENABLED!=0
        /* Read test */
        xprintf("\nFile read test:\n");
        xprintf("Open file %s ...", FILE_NAME_R);
        xmemset(Buff,0,sizeof(Buff));
        if (file_fopen( &filer, &efs.myFs , FILE_NAME_R , 'r' ) == 0 )
        {
            xprintf(" OK. \nReading %lu bytes ...\n", FILE_RW_SIZE);

            n=FILE_RW_SIZE; 
            m = 0;
            Timer = 0;
            xprintf("File's content:\n");
            while (n)
            {
                if (n>=blen) {cnt = blen; n -= blen;}
                else         {cnt = n; n = 0;}

                p =  file_read( &filer, cnt, &Buff[m] );
                xprintf("%s",&Buff[m]);
                m += p;
                if (p != cnt) break;                
            }
            filesize = m;
            time_end = Timer;
            xprintf("\n%lu bytes read in %lu milisec.\n", m, time_end);
            file_fclose( &filer ); 

        } else
        {
            xprintf (" Failed.\n");    
        }
#endif
#if WRITE_TEST_ENABLED!=0
        /* Write test*/  
        xprintf("\nFile write test:\n");
        xprintf("Open file %s ...", FILE_NAME_W);
        if (file_fopen( &filew, &efs.myFs , FILE_NAME_W , 'a' ) == 0 )
        {
            xprintf(" OK. \nWriting %lu bytes ...\n", filesize);
            n=filesize;
            m = 0;
            Timer = 0;
            while (n)
            {
                if (n>=blen) {
                    cnt = blen;
                    n -= blen;
                } else {
                    cnt = n;
                    n = 0;
                }
                p = file_write( &filew, cnt, &Buff[m] );
                m += p;
                if (p != cnt) break;
            }
            time_end = Timer;
            xprintf("%lu bytes written in %lu milisec.\n", m, time_end);

            file_fclose( &filew );                          

        } else {
            xprintf (" Failed.\n");
        }
#endif
#if READ_TEST_ENABLED!=0
        /* Read test */
        xprintf("\nFile read test:\n");
        xprintf("Open file %s ...", FILE_NAME_W);
        xmemset(Buff,0,sizeof(Buff));
        if (file_fopen( &filer, &efs.myFs , FILE_NAME_W , 'r' ) == 0 )
        {
            xprintf(" OK. \nReading %lu bytes ...\n", FILE_RW_SIZE);

            n=FILE_RW_SIZE; 
            m = 0;
            Timer = 0;
            xprintf("File's content:\n");
            while (n)
            {
                if (n>=blen) {cnt = blen; n -= blen;}
                else         {cnt = n; n = 0;}

                p =  file_read( &filer, cnt, &Buff[m] );
                xprintf("%s",&Buff[m]);
                m += p;
                if (p != cnt) break;                
            }
            filesize = m;
            time_end = Timer;
            xprintf("\n%lu bytes read in %lumiliseconds.\n", m, time_end);
            file_fclose( &filer ); 

        } else
        {
            xprintf (" Failed.\n");    
        }
#endif
        /* close file system */
	    fs_umount( &efs.myFs ) ;
    }

	xprintf("\nEFSL test complete.\n");

	while (1);
}
示例#6
0
int main()
{
	int8_t res;
    uint32_t n, m, p, cnt;

//	SystemInit();
    SysTick_Config(SystemCoreClock/1000 - 1); /* Generate interrupt each 1 ms   */

	LPC17xx_UART_Init(115200); // UART0
    xfunc_out = LPC17xx_UART_PutChar;
	xfunc_in  = LPC17xx_UART_GetChar; 

	xprintf("\nMMC/SD Card Filesystem Test (P:LPC1768 L:EFSL)\n");

	xprintf("\nCARD init...");

	// init file system
	if ( ( res = efs_init( &efs, 0 ) ) != 0 ) {
		xprintf("failed with %i\n",res);
	}
	else 
	{
		xprintf("ok\n");

        xprintf("Card type: ");
        switch (CardType)
        {
            case CARDTYPE_MMC:
                xprintf("MMC\n");
                break;
            case CARDTYPE_SDV1:
                xprintf("Version 1.x Standard Capacity SD card.\n");
                break;
            case CARDTYPE_SDV2_SC:
                xprintf("Version 2.0 or later Standard Capacity SD card.\n");
                break;
            case CARDTYPE_SDV2_HC:
                xprintf("Version 2.0 or later High/eXtended Capacity SD card.\n");
                break;
            default:
                break;            
        }
        xprintf("Sector size: %d bytes\n", CardConfig.sectorsize);
        xprintf("Sector count: %d\n", CardConfig.sectorcnt);
        xprintf("Block size: %d sectors\n", CardConfig.blocksize);
        xprintf("Card capacity: %d MByte\n\n", (((CardConfig.sectorcnt >> 10) * CardConfig.sectorsize)) >> 10);

		xprintf("\nDirectory of 'root':\n");
		
		/* list files in root directory */
		ls_openDir( &list, &(efs.myFs) , "/");
		while ( ls_getNext( &list ) == 0 ) {
			// list.currentEntry is the current file
			list.currentEntry.FileName[LIST_MAXLENFILENAME-1] = '\0';
			xprintf("%s, 0x%x bytes\n", list.currentEntry.FileName, list.currentEntry.FileSize ) ;
		}

#if WRITE_TEST_ENABLED!=0
        /* Write test*/  
        xprintf("\nFile write test:\n");
        xprintf("Open file %s ...", FILE_NAME);
        if (file_fopen( &filew, &efs.myFs , FILE_NAME , 'a' ) == 0 )
        {
            xprintf(" OK. \nWriting %lu bytes ...\n", FILE_RW_SIZE);

            xmemset(Buff, 0xAA, blen);
            n=FILE_RW_SIZE;
            m = 0;
            Timer = 0;
            while (n)
            {
                if (n>=blen) {
                    cnt = blen;
                    n -= blen;
                } else {
                    cnt = n;
                    n = 0;
                }
                p = file_write( &filew, cnt, Buff );
                m += p;
                if (p != cnt) break;
            }
            xprintf("%lu bytes written with %lu kB/sec.\n", m, Timer ? (m / Timer) : 0);

            file_fclose( &filew );                          

        } else {
            xprintf (" Failed.\n");
        }
#endif

#if READ_TEST_ENABLED!=0
        /* Read test */
        xprintf("\nFile read test:\n");
        xprintf("Open file %s ...", FILE_NAME);
        if (file_fopen( &filer, &efs.myFs , FILE_NAME , 'r' ) == 0 )
        {
            xprintf(" OK. \nReading %lu bytes ...\n", FILE_RW_SIZE);

            n=FILE_RW_SIZE; 
            m = 0;
            Timer = 0;
            while (n)
            {
                if (n>=blen) {cnt = blen; n -= blen;}
                else         {cnt = n; n = 0;}

                p =  file_read( &filer, cnt, Buff );
                m += p;
                if (p != cnt) break;                
            }
            xprintf("%lu bytes read with %lu kB/sec.\n", m, Timer ? (m / Timer) : 0);

            file_fclose( &filer ); 

        } else
        {
            xprintf (" Failed.\n");    
        }
#endif

        /* close file system */
	    fs_umount( &efs.myFs ) ;
    }

	xprintf("\nEFSL test complete.\n");

	while (1);
}
示例#7
0
int main(void)
{
	int ch;
	int8_t res;
	
	systemInit();
	gpioInit();
	
	uart1Init(UART_BAUD(BAUD), UART_8N1, UART_FIFO_8); // setup the UART
		
	uart1Puts("\r\nMMC/SD Card Filesystem Test (P:LPC2138 L:EFSL)\r\n");
	uart1Puts("efsl LPC2000-port and this Demo-Application\r\n");
	uart1Puts("done by Martin Thomas, Kaiserslautern, Germany\r\n");
	
	/* init efsl debug-output */
	lpc2000_debug_devopen(uart1Putch);
		
	ledToggle();
	
	rprintf("CARD init...");
	if ( ( res = efs_init( &efs, 0 ) ) != 0 ) {
		rprintf("failed with %i\n",res);
	}
	else {
		rprintf("ok\n");
		rprintf("Directory of 'root':\n");
		ls_openDir( &list, &(efs.myFs) , "/");
		while ( ls_getNext( &list ) == 0 ) {
			list.currentEntry.FileName[LIST_MAXLENFILENAME-1] = '\0';
			rprintf( "%s ( %li bytes )\n" ,
				list.currentEntry.FileName,
				list.currentEntry.FileSize ) ;
		}
		
		if ( file_fopen( &filer, &efs.myFs , LogFileName , 'r' ) == 0 ) {
			rprintf("File %s open. Content:\n", LogFileName);
			while ( ( e = file_read( &filer, 512, buf ) ) != 0 ) {
				buf[e]='\0';
				uart1Puts((char*)buf);
			}
			rprintf("\n");
			file_fclose( &filer );
		}
		
		if ( file_fopen( &filew, &efs.myFs , LogFileName , 'a' ) == 0 ) {
			rprintf("File %s open for append. Appending...", LogFileName);
			strcpy((char*)buf, "Martin hat's angehaengt\r\n");
			if ( file_write( &filew, strlen((char*)buf), buf ) == strlen((char*)buf) ) {
				rprintf("ok\n");
			}
			else {
				rprintf("fail\n");
			}
			file_fclose( &filew );
		}
		
		if ( file_fopen( &filer, &efs.myFs , LogFileName , 'r' ) == 0 ) {
			rprintf("File %s open. Content:\n", LogFileName);
			while ( ( e = file_read( &filer, 512, buf ) ) != 0 ) {
				buf[e]='\0';
				uart1Puts((char*)buf);
			}
			rprintf("\n");
			file_fclose( &filer );
		}
		
		fs_umount( &efs.myFs ) ;
	}
	
	while(1) {
		if ((ch = uart1Getch()) >= 0) {
			uart1Puts("You pressed : ");
			uart1Putch(ch);
			uart1Puts("\r\n");
			if ( ch == 'M' ) {
				rprintf("Creating FS\n");
				mkfs_makevfat(&efs.myPart);
			}
			ledToggle();
		}
	}
	
	return 0; /* never reached */
}