int cyg_start(void) { #if defined(CYGPKG_FS_FAT) int err; int existingdirents=-1; #endif DBG("Start USB MSD application\n\r"); #if defined(CYGPKG_FS_FAT) // Mount RAM disk partition 1 err = mount( "/dev/ramdisk0/1", "/", "fatfs" ); if( err < 0 ) SHOW_RESULT( mount, err ); err = chdir( "/" ); if( err < 0 ) SHOW_RESULT( chdir, err ); checkcwd( "/" ); // Display list of all files/directories from root listdir( "/", true, -1, &existingdirents ); // Play around with the file-system, create / copy / // compare files createfile( "/foo", 1000 ); checkfile( "foo" ); copyfile( "foo", "fee" ); checkfile( "fee" ); comparefiles( "foo", "/fee" ); DBG("<INFO>: mkdir bar\n"); // Create new directory err = mkdir( "/bar", 0 ); if( err < 0 ) SHOW_RESULT( mkdir, err ); // Display list of all files/directories from root listdir( "/" , true, existingdirents+3, NULL ); // Umount file-system err = umount( "/" ); if( err < 0 ) SHOW_RESULT( umount, err ); #endif // Start Mass Storage Service usbs_msd_start(); // Start scheduler cyg_scheduler_start(); }
int main( int argc, char **argv ) { int err; //int i; int existingdirents=-1; CYG_TEST_INIT(); // -------------------------------------------------------------- err = mount( CYGDAT_IO_FLASH_BLOCK_DEVICE_NAME_1, "/", "jffs2" ); if( err < 0 ) SHOW_RESULT( mount, err ); err = chdir( "/" ); if( err < 0 ) SHOW_RESULT( chdir, err ); checkcwd( "/" ); listdir( "/", true, -1, &existingdirents ); if ( existingdirents < 2 ) CYG_TEST_FAIL("Not enough dir entries\n"); // -------------------------------------------------------------- createfile( "/foo", 202 ); checkfile( "foo" ); copyfile( "foo", "fee"); checkfile( "fee" ); comparefiles( "foo", "/fee" ); diag_printf("<INFO>: mkdir bar\n"); err = mkdir( "/bar", 0 ); if( err < 0 ) SHOW_RESULT( mkdir, err ); listdir( "/" , true, existingdirents+3, NULL ); copyfile( "fee", "/bar/fum" ); checkfile( "bar/fum" ); comparefiles( "/fee", "bar/fum" ); diag_printf("<INFO>: cd bar\n"); err = chdir( "bar" ); if( err < 0 ) SHOW_RESULT( chdir, err ); checkcwd( "/bar" ); diag_printf("<INFO>: rename /foo bundy\n"); err = rename( "/foo", "bundy" ); if( err < 0 ) SHOW_RESULT( rename, err ); listdir( "/", true, existingdirents+2, NULL ); listdir( "" , true, 4, NULL ); checkfile( "/bar/bundy" ); comparefiles("/fee", "bundy" ); // -------------------------------------------------------------- createfile( LONGNAME1, 123 ); checkfile( LONGNAME1 ); copyfile( LONGNAME1, LONGNAME2 ); listdir( "", false, 6, NULL ); diag_printf("<INFO>: unlink " LONGNAME1 "\n"); err = unlink( LONGNAME1 ); if( err < 0 ) SHOW_RESULT( unlink, err ); diag_printf("<INFO>: unlink " LONGNAME2 "\n"); err = unlink( LONGNAME2 ); if( err < 0 ) SHOW_RESULT( unlink, err ); // -------------------------------------------------------------- diag_printf("<INFO>: unlink fee\n"); err = unlink( "/fee" ); if( err < 0 ) SHOW_RESULT( unlink, err ); diag_printf("<INFO>: unlink fum\n"); err = unlink( "fum" ); if( err < 0 ) SHOW_RESULT( unlink, err ); diag_printf("<INFO>: unlink /bar/bundy\n"); err = unlink( "/bar/bundy" ); if( err < 0 ) SHOW_RESULT( unlink, err ); diag_printf("<INFO>: cd /\n"); err = chdir( "/" ); if( err < 0 ) SHOW_RESULT( chdir, err ); checkcwd( "/" ); diag_printf("<INFO>: rmdir /bar\n"); err = rmdir( "/bar" ); if( err < 0 ) SHOW_RESULT( rmdir, err ); listdir( "/", false, existingdirents, NULL ); // -------------------------------------------------------------- diag_printf("<INFO>: mount /jffs2 \n"); err = mount( CYGDAT_IO_FLASH_BLOCK_DEVICE_NAME_1, "/jffs2", "jffs2" ); if( err < 0 ) SHOW_RESULT( mount, err ); createfile( "/jffs2/tinky", 456 ); copyfile( "/jffs2/tinky", "/jffs2/laalaa" ); checkfile( "/jffs2/tinky"); checkfile( "/jffs2/laalaa"); comparefiles( "/jffs2/tinky", "/jffs2/laalaa" ); diag_printf("<INFO>: cd /jffs2\n"); err = chdir( "/jffs2" ); if( err < 0 ) SHOW_RESULT( chdir, err ); checkcwd( "/jffs2" ); diag_printf("<INFO>: mkdir noonoo\n"); err = mkdir( "noonoo", 0 ); if( err < 0 ) SHOW_RESULT( mkdir, err ); listdir( "." , true, existingdirents+3, NULL); diag_printf("<INFO>: cd noonoo\n"); err = chdir( "noonoo" ); if( err < 0 ) SHOW_RESULT( chdir, err ); checkcwd( "/jffs2/noonoo" ); createfile( "tinky", 678 ); checkfile( "tinky" ); createfile( "dipsy", 3456 ); checkfile( "dipsy" ); copyfile( "dipsy", "po" ); checkfile( "po" ); comparefiles( "dipsy", "po" ); /*for(i=0;i<2048;i++) { diag_printf("<INFO>: churningchurningchurning................................ITERATION = %d\n", i); createfile( "churningchurningchurning", 4096 ); diag_printf("<INFO>: unlink churningchurningchurning\n"); err = unlink( "churningchurningchurning" ); if( err < 0 ) SHOW_RESULT( unlink, err ); }*/ listdir( ".", true, 5, NULL ); listdir( "", true, 5, NULL ); listdir( "..", true, existingdirents+3, NULL ); // -------------------------------------------------------------- diag_printf("<INFO>: unlink tinky\n"); err = unlink( "tinky" ); if( err < 0 ) SHOW_RESULT( unlink, err ); diag_printf("<INFO>: unlink dipsy\n"); err = unlink( "dipsy" ); if( err < 0 ) SHOW_RESULT( unlink, err ); diag_printf("<INFO>: unlink po\n"); err = unlink( "po" ); if( err < 0 ) SHOW_RESULT( unlink, err ); diag_printf("<INFO>: cd ..\n"); err = chdir( ".." ); if( err < 0 ) SHOW_RESULT( chdir, err ); checkcwd( "/jffs2" ); diag_printf("<INFO>: rmdir noonoo\n"); err = rmdir( "noonoo" ); if( err < 0 ) SHOW_RESULT( rmdir, err ); // -------------------------------------------------------------- err = mkdir( "x", 0 ); if( err < 0 ) SHOW_RESULT( mkdir, err ); err = mkdir( "x/y", 0 ); if( err < 0 ) SHOW_RESULT( mkdir, err ); err = mkdir( "x/y/z", 0 ); if( err < 0 ) SHOW_RESULT( mkdir, err ); err = mkdir( "x/y/z/w", 0 ); if( err < 0 ) SHOW_RESULT( mkdir, err ); diag_printf("<INFO>: cd /jffs2/x/y/z/w\n"); err = chdir( "/jffs2/x/y/z/w" ); if( err < 0 ) SHOW_RESULT( chdir, err ); checkcwd( "/jffs2/x/y/z/w" ); diag_printf("<INFO>: cd ..\n"); err = chdir( ".." ); if( err < 0 ) SHOW_RESULT( chdir, err ); checkcwd( "/jffs2/x/y/z" ); diag_printf("<INFO>: cd .\n"); err = chdir( "." ); if( err < 0 ) SHOW_RESULT( chdir, err ); checkcwd( "/jffs2/x/y/z" ); diag_printf("<INFO>: cd ../../y\n"); err = chdir( "../../y" ); if( err < 0 ) SHOW_RESULT( chdir, err ); checkcwd( "/jffs2/x/y" ); diag_printf("<INFO>: cd ../..\n"); err = chdir( "../.." ); if( err < 0 ) SHOW_RESULT( chdir, err ); checkcwd( "/jffs2" ); diag_printf("<INFO>: rmdir x/y/z/w\n"); err = rmdir( "x/y/z/w" ); if( err < 0 ) SHOW_RESULT( rmdir, err ); diag_printf("<INFO>: rmdir x/y/z\n"); err = rmdir( "x/y/z" ); if( err < 0 ) SHOW_RESULT( rmdir, err ); diag_printf("<INFO>: rmdir x/y\n"); err = rmdir( "x/y" ); if( err < 0 ) SHOW_RESULT( rmdir, err ); diag_printf("<INFO>: rmdir x\n"); err = rmdir( "x" ); if( err < 0 ) SHOW_RESULT( rmdir, err ); // -------------------------------------------------------------- diag_printf("<INFO>: unlink tinky\n"); err = unlink( "tinky" ); if( err < 0 ) SHOW_RESULT( unlink, err ); diag_printf("<INFO>: unlink laalaa\n"); err = unlink( "laalaa" ); if( err < 0 ) SHOW_RESULT( unlink, err ); diag_printf("<INFO>: cd /\n"); err = chdir( "/" ); if( err < 0 ) SHOW_RESULT( chdir, err ); checkcwd( "/" ); diag_printf("<INFO>: umount /jffs2\n"); err = umount( "/jffs2" ); if( err < 0 ) SHOW_RESULT( umount, err ); diag_printf("<INFO>: umount /\n"); err = umount( "/" ); if( err < 0 ) SHOW_RESULT( umount, err ); CYG_TEST_PASS_FINISH("jffs2_1"); }
int main( int argc, char **argv ) { int err; int existingdirents=-1; #if defined(CYGSEM_FILEIO_BLOCK_USAGE) struct cyg_fs_block_usage usage; #endif CYG_TEST_INIT(); // -------------------------------------------------------------- err = mount( "/dev/disk0/1", "/", "fatfs" ); if( err < 0 ) SHOW_RESULT( mount, err ); err = chdir( "/" ); if( err < 0 ) SHOW_RESULT( chdir, err ); checkcwd( "/" ); listdir( "/", true, -1, &existingdirents ); // -------------------------------------------------------------- #if defined(CYGSEM_FILEIO_BLOCK_USAGE) err = cyg_fs_getinfo("/", FS_INFO_BLOCK_USAGE, &usage, sizeof(usage)); if( err < 0 ) SHOW_RESULT( cyg_fs_getinfo, err ); diag_printf("<INFO>: total size: %6lld blocks, %10lld bytes\n", usage.total_blocks, usage.total_blocks * usage.block_size); diag_printf("<INFO>: free size: %6lld blocks, %10lld bytes\n", usage.free_blocks, usage.free_blocks * usage.block_size); diag_printf("<INFO>: block size: %6u bytes\n", usage.block_size); #endif // -------------------------------------------------------------- createfile( "/foo", 20257 ); checkfile( "foo" ); copyfile( "foo", "fee"); checkfile( "fee" ); comparefiles( "foo", "/fee" ); diag_printf("<INFO>: mkdir bar\n"); err = mkdir( "/bar", 0 ); if( err < 0 ) SHOW_RESULT( mkdir, err ); listdir( "/" , true, existingdirents+3, NULL ); copyfile( "fee", "/bar/fum" ); checkfile( "bar/fum" ); comparefiles( "/fee", "bar/fum" ); diag_printf("<INFO>: cd bar\n"); err = chdir( "bar" ); if( err < 0 ) SHOW_RESULT( chdir, err ); checkcwd( "/bar" ); diag_printf("<INFO>: rename /foo bundy\n"); err = rename( "/foo", "bundy" ); if( err < 0 ) SHOW_RESULT( rename, err ); listdir( "/", true, existingdirents+2, NULL ); listdir( "" , true, 4, NULL ); checkfile( "/bar/bundy" ); comparefiles("/fee", "bundy" ); #if defined(CYGSEM_FILEIO_BLOCK_USAGE) err = cyg_fs_getinfo("/", FS_INFO_BLOCK_USAGE, &usage, sizeof(usage)); if( err < 0 ) SHOW_RESULT( cyg_fs_getinfo, err ); diag_printf("<INFO>: total size: %6lld blocks, %10lld bytes\n", usage.total_blocks, usage.total_blocks * usage.block_size); diag_printf("<INFO>: free size: %6lld blocks, %10lld bytes\n", usage.free_blocks, usage.free_blocks * usage.block_size); diag_printf("<INFO>: block size: %6u bytes\n", usage.block_size); #endif // -------------------------------------------------------------- diag_printf("<INFO>: unlink fee\n"); err = unlink( "/fee" ); if( err < 0 ) SHOW_RESULT( unlink, err ); diag_printf("<INFO>: unlink fum\n"); err = unlink( "fum" ); if( err < 0 ) SHOW_RESULT( unlink, err ); diag_printf("<INFO>: unlink /bar/bundy\n"); err = unlink( "/bar/bundy" ); if( err < 0 ) SHOW_RESULT( unlink, err ); diag_printf("<INFO>: cd /\n"); err = chdir( "/" ); if( err < 0 ) SHOW_RESULT( chdir, err ); checkcwd( "/" ); diag_printf("<INFO>: rmdir /bar\n"); err = rmdir( "/bar" ); if( err < 0 ) SHOW_RESULT( rmdir, err ); listdir( "/", false, existingdirents, NULL ); // -------------------------------------------------------------- #if 0 diag_printf("<INFO>: mkdir disk2\n"); err = mkdir( "/disk2", 0 ); if( err < 0 ) SHOW_RESULT( mkdir, err ); #else diag_printf("<INFO>: mount /disk2\n"); err = mount( "/dev/disk0/2", "/disk2", "fatfs" ); if( err < 0 ) SHOW_RESULT( mount, err ); #endif listdir( "/disk2" , true, -1, &existingdirents); createfile( "/disk2/tinky", 4567 ); copyfile( "/disk2/tinky", "/disk2/laalaa" ); checkfile( "/disk2/tinky"); checkfile( "/disk2/laalaa"); comparefiles( "/disk2/tinky", "/disk2/laalaa" ); diag_printf("<INFO>: cd /disk2\n"); err = chdir( "/disk2" ); if( err < 0 ) SHOW_RESULT( chdir, err ); checkcwd( "/disk2" ); diag_printf("<INFO>: mkdir noonoo\n"); err = mkdir( "noonoo", 0 ); if( err < 0 ) SHOW_RESULT( mkdir, err ); listdir( "/disk2" , true, existingdirents+3, NULL); diag_printf("<INFO>: cd noonoo\n"); err = chdir( "noonoo" ); if( err < 0 ) SHOW_RESULT( chdir, err ); checkcwd( "/disk2/noonoo" ); createfile( "tinky", 6789 ); checkfile( "tinky" ); createfile( "dipsy", 34567 ); checkfile( "dipsy" ); copyfile( "dipsy", "po" ); checkfile( "po" ); comparefiles( "dipsy", "po" ); listdir( ".", true, 5, NULL ); listdir( "", true, 5, NULL ); listdir( "..", true, existingdirents+3, NULL ); // -------------------------------------------------------------- diag_printf("<INFO>: unlink tinky\n"); err = unlink( "tinky" ); if( err < 0 ) SHOW_RESULT( unlink, err ); diag_printf("<INFO>: unlink dipsy\n"); err = unlink( "dipsy" ); if( err < 0 ) SHOW_RESULT( unlink, err ); diag_printf("<INFO>: unlink po\n"); err = unlink( "po" ); if( err < 0 ) SHOW_RESULT( unlink, err ); diag_printf("<INFO>: cd ..\n"); err = chdir( ".." ); if( err < 0 ) SHOW_RESULT( chdir, err ); checkcwd( "/disk2" ); diag_printf("<INFO>: rmdir noonoo\n"); err = rmdir( "noonoo" ); if( err < 0 ) SHOW_RESULT( rmdir, err ); // -------------------------------------------------------------- err = mkdir( "x", 0 ); if( err < 0 ) SHOW_RESULT( mkdir, err ); err = mkdir( "x/y", 0 ); if( err < 0 ) SHOW_RESULT( mkdir, err ); err = mkdir( "x/y/z", 0 ); if( err < 0 ) SHOW_RESULT( mkdir, err ); err = mkdir( "x/y/z/w", 0 ); if( err < 0 ) SHOW_RESULT( mkdir, err ); diag_printf("<INFO>: cd /disk2/x/y/z/w\n"); err = chdir( "/disk2/x/y/z/w" ); if( err < 0 ) SHOW_RESULT( chdir, err ); checkcwd( "/disk2/x/y/z/w" ); diag_printf("<INFO>: cd ..\n"); err = chdir( ".." ); if( err < 0 ) SHOW_RESULT( chdir, err ); checkcwd( "/disk2/x/y/z" ); diag_printf("<INFO>: cd .\n"); err = chdir( "." ); if( err < 0 ) SHOW_RESULT( chdir, err ); checkcwd( "/disk2/x/y/z" ); diag_printf("<INFO>: cd ../../y\n"); err = chdir( "../../y" ); if( err < 0 ) SHOW_RESULT( chdir, err ); checkcwd( "/disk2/x/y" ); diag_printf("<INFO>: cd ../..\n"); err = chdir( "../.." ); if( err < 0 ) SHOW_RESULT( chdir, err ); checkcwd( "/disk2" ); diag_printf("<INFO>: rmdir x/y/z/w\n"); err = rmdir( "x/y/z/w" ); if( err < 0 ) SHOW_RESULT( rmdir, err ); diag_printf("<INFO>: rmdir x/y/z\n"); err = rmdir( "x/y/z" ); if( err < 0 ) SHOW_RESULT( rmdir, err ); diag_printf("<INFO>: rmdir x/y\n"); err = rmdir( "x/y" ); if( err < 0 ) SHOW_RESULT( rmdir, err ); diag_printf("<INFO>: rmdir x\n"); err = rmdir( "x" ); if( err < 0 ) SHOW_RESULT( rmdir, err ); // -------------------------------------------------------------- checkcwd( "/disk2" ); diag_printf("<INFO>: unlink tinky\n"); err = unlink( "tinky" ); if( err < 0 ) SHOW_RESULT( unlink, err ); diag_printf("<INFO>: unlink laalaa\n"); err = unlink( "laalaa" ); if( err < 0 ) SHOW_RESULT( unlink, err ); diag_printf("<INFO>: cd /\n"); err = chdir( "/" ); if( err < 0 ) SHOW_RESULT( chdir, err ); checkcwd( "/" ); listdir( "/disk2", true, -1, NULL ); #if 0 diag_printf("<INFO>: rmdir dir\n"); err = rmdir( "disk2" ); if( err < 0 ) SHOW_RESULT( rmdir, err ); #else diag_printf("<INFO>: umount /disk2\n"); err = umount( "/disk2" ); if( err < 0 ) SHOW_RESULT( umount, err ); #endif #ifdef CYGCFG_FS_FAT_USE_ATTRIBUTES // Create file diag_printf("<INFO>: create /foo\n"); createfile( "/foo", 20257 ); // Verify it is created with archive bit set checkattrib( "/foo", S_FATFS_ARCHIVE ); // Make it System diag_printf("<INFO>: attrib -A+S /foo\n"); err = cyg_fs_set_attrib( "/foo", S_FATFS_SYSTEM ); if( err < 0 ) SHOW_RESULT( chmod system , err ); // Verify it is now System checkattrib( "/foo", S_FATFS_SYSTEM ); // Make it Hidden diag_printf("<INFO>: attrib -S+H /foo\n"); err = cyg_fs_set_attrib( "/foo", S_FATFS_HIDDEN ); if( err < 0 ) SHOW_RESULT( chmod system , err ); // Verify it is now Hidden checkattrib( "/foo", S_FATFS_HIDDEN ); // Make it Read-only diag_printf("<INFO>: attrib -H+R /foo\n"); err = cyg_fs_set_attrib( "/foo", S_FATFS_RDONLY ); if( err < 0 ) SHOW_RESULT( chmod system , err ); // Verify it is now Read-only checkattrib( "/foo", S_FATFS_RDONLY ); // Verify we cannot unlink a read-only file diag_printf("<INFO>: unlink /foo\n"); err = unlink( "/foo" ); if( (err != -1) || (errno != EPERM) ) SHOW_RESULT( unlink, err ); // Verify we cannot rename a read-only file diag_printf("<INFO>: rename /foo bundy\n"); err = rename( "/foo", "bundy" ); if( (err != -1) || (errno != EPERM) ) SHOW_RESULT( rename, err ); // Verify we cannot open read-only file for writing int fd; diag_printf("<INFO>: create file /foo\n"); fd = open( "/foo", O_WRONLY ); if( (err != -1) || (errno != EACCES) ) SHOW_RESULT( open, err ); if( err > 0 ) close(fd); // Make it Normal diag_printf("<INFO>: attrib -H /foo\n"); err = cyg_fs_set_attrib( "/foo", 0 ); if( err < 0 ) SHOW_RESULT( chmod none , err ); // Verify it is now nothing checkattrib( "/foo", 0 ); // Now delete our test file diag_printf("<INFO>: unlink /foo\n"); err = unlink( "/foo" ); if( err < 0 ) SHOW_RESULT( unlink, err ); #endif // CYGCFG_FS_FAT_USE_ATTRIBUTES maxfile("file.max"); listdir( "/", true, -1, NULL ); diag_printf("<INFO>: unlink file.max\n"); err = unlink( "file.max" ); if( err < 0 ) SHOW_RESULT( unlink, err ); diag_printf("<INFO>: umount /\n"); err = umount( "/" ); if( err < 0 ) SHOW_RESULT( umount, err ); CYG_TEST_PASS_FINISH("fatfs1"); }