@ -5,6 +5,7 @@
# include <lib/logging.h>
# include <lib/dump.h>
# include <stdlib.h>
# include "../tests.h"
void disk_tb_install ( const char * path ) ;
@ -44,57 +45,70 @@ static void log_tree(const char *path, int level)
// read & seek test function
static inline
void test_file_read_seek ( void ) {
file_handle_t * f = vfs_open_file ( " /fs/file.dat " ) ;
void test_write ( void ) {
file_handle_t * f = vfs_open_file ( " /fs/file.dat " ) ;
assert ( f ) ;
assert ( ! vfs_seek_file ( f , 512 , SEEK_SET ) ) ;
assert ( ! vfs_seek_file ( f , 0 , SEEK_END ) ) ;
log_warn ( " FILE SIZE = %u " , vfs_tell_file ( f ) ) ;
vfs_seek_file ( f , 50 , SEEK_CUR ) ;
vfs_seek_file ( f , 234567 , SEEK_SET ) ;
char rd [ 513 ] ;
assert ( vfs_read_file ( rd , 512 , 1 , f ) = = 1 ) ;
rd [ 512 ] = 0 ;
printf ( " READ: %512s " , rd ) ;
dump ( rd , 512 , 32 , DUMP_HEX8 ) ;
vfs_seek_file ( f , 50 , SEEK_CUR ) ;
char buf [ 512 ] =
uint8_t buf [ 512 ] = { 0xff } ;
for ( int i = 0 ; i < 512 ; i + + )
buf [ i ] = 0xff ;
/*
" Une balle pourtant, mieux ajustée ou plus traître que les autres, finit par atteindre "
" l'enfant feu follet. On vit Gavroche chanceler, puis il s'affaissa. Toute la barricade "
" poussa un cri ; mais il y avait de l'Antée dans ce pygmée ; pour le gamin toucher le "
" pavé, c'est comme pour le géant toucher la terre ; Gavroche n'était tombé que pour se "
" redresser ; il resta assis sur son séant, un long filet de sang rayait son visage, "
" il éleva ses deux bras en l'air, regarda du côté d'où était venu le coup, et se mit à " ;
" il éleva ses deux bras en l'air, regarda du côté d'où était venu le coup " ;
*/
vfs_write_file ( buf , 512 , 1 , f ) ;
vfs_seek_file ( f , 234567 , SEEK_SET ) ;
char rd [ 1025 ] ;
assert ( vfs_read_file ( rd , 1024 , 1 , f ) = = 1 ) ;
rd [ 1024 ] = 0 ;
printf ( " READ: %s \n \n " , rd ) ;
printf ( " READ: %c \n \n " , * rd ) ;
dump ( rd , 1024 , 32 , DUMP_HEX8 ) ;
vfs_close_file ( f ) ;
return ;
# define SIZE 512
/*
}
int read_seek_big_file ( size_t SIZE ) {
assert ( SIZE < 1024 * 1024 ) ;
file_handle_t * f = vfs_open_file ( " /fs/file.dat " ) ;
vfs_seek_file ( f , 0 , SEEK_END ) ;
assert ( vfs_tell_file ( f ) = = 1024 * 1024 ) ;
vfs_seek_file ( f , 0 , SEEK_SET ) ;
char * buf = malloc ( SIZE + 1 ) ;
int read = 0 ;
int x = 531 ;
for ( int i = 0 ; i < 200 ; i + + )
{
x = ( x * 411 + 1431 ) % ( 1024 * 1024 / 4 - SIZE ) ;
x = ( x * 411 + 1431 ) % ( 1024 * 1024 / 4 - SIZE / 4 ) ;
size_t y = x * 4 ;
//x < 1024 * 1024 / 4 - SIZE
///y < 1024 * 1024 - SIZE*4 < 1024**2
log_info ( " test %u " , y ) ;
vfs_seek_file ( f , y , SEEK_SET ) ;
@ -115,19 +129,31 @@ file_handle_t* f = vfs_open_file("/fs/file.dat");
//dump(buf, SIZE, 8, DUMP_DEC32);
}
vfs_close_file ( f ) ;
*/
}
# ifndef DISKFILE
# error DISKFILE should be defined.
# endif
int main ( ) {
vfs_init ( ) ;
disk_tb_install ( " ../../disk.bin " ) ;
disk_tb_install ( DISKFILE ) ;
disk_part_t * part = search_partition ( " Bincows " ) ;
assert ( part ) ;
printf ( " MOUNT " ) ;
vfs_mount ( part , " /fs " ) ;
test_file_read_seek ( ) ;
//TEST(read_seek_big_file(1));
//TEST(read_seek_big_file(234));
//TEST(read_seek_big_file(512));
//TEST(read_seek_big_file(513));
//TEST(read_seek_big_file(456523));
//TEST(read_seek_big_file(145652));
test_write ( ) ;
shutdown ( ) ;
}