version 1.8, 2005/02/27 09:37:56
|
version 1.11, 2005/03/11 07:38:58
|
|
|
#include "tvfs.h" | #include "tvfs.h" |
#include <string.h> | #include <string.h> |
| |
#define MAXFILES 10 |
#define MAXFILES 20 |
#define MAXHANDLES 10 |
#define MAXHANDLES 20 |
#define MAXFNAME 255 | #define MAXFNAME 255 |
#define MAXFLEN 65536 |
#define MAXFLEN 65536*2 |
| |
#include <fcntl.h> | #include <fcntl.h> |
#include <stdlib.h> | #include <stdlib.h> |
|
|
#endif | #endif |
| |
#ifndef STANDALONE | #ifndef STANDALONE |
|
#include "wine/test.h" |
|
#define ok2 ok |
#else | #else |
static void trace(const char *s, ...) | static void trace(const char *s, ...) |
{ | { |
va_list elipsis; |
va_list ellipsis; |
va_start (elipsis, s); |
va_start (ellipsis, s); |
vprintf(s, elipsis); |
vprintf(s, ellipsis); |
va_end(elipsis); |
va_end(ellipsis); |
} | } |
#endif | #endif |
| |
|
|
handler = malloc(sizeof(struct tvfs_fcb)); | handler = malloc(sizeof(struct tvfs_fcb)); |
handler->inode = inode; | handler->inode = inode; |
handler->pos=0; | handler->pos=0; |
h = nfiles++; |
h = nhandles++; |
handles[h] = handler; | handles[h] = handler; |
| |
#ifdef TVFS_DEBUG | #ifdef TVFS_DEBUG |
|
|
| |
void tvfs_free() | void tvfs_free() |
{ | { |
|
|
int inode; | int inode; |
|
int handle; |
| |
#ifdef TVFS_DEBUG | #ifdef TVFS_DEBUG |
trace("tvfs_free\n"); | trace("tvfs_free\n"); |
|
|
continue; | continue; |
free(files[inode]); | free(files[inode]); |
} | } |
|
|
|
for (handle=0; handle<nhandles; handle++) { |
|
if (!handles[handle]) |
|
continue; |
|
free(handles[handle]); |
|
} |
|
|
} | } |
| |
/* Compare given file with given contents, return 0 on equal, else nonzero */ | /* Compare given file with given contents, return 0 on equal, else nonzero */ |
|
|
if (!strcmp(files[inode]->fname, fname)) | if (!strcmp(files[inode]->fname, fname)) |
break; | break; |
} | } |
|
|
if (inode == nfiles) { | if (inode == nfiles) { |
/* File did not exist */ | /* File did not exist */ |
#ifdef TVFS_DEBUG | #ifdef TVFS_DEBUG |
|
|
} | } |
| |
return (memcmp(files[inode]->buf,buf,len)); | return (memcmp(files[inode]->buf,buf,len)); |
/* doesnt check for out of bound */ |
/* does not check for out of bound */ |
} | } |
| |
long tvfs_lseek(int h, long whence, int whither ) | long tvfs_lseek(int h, long whence, int whither ) |
|
|
| |
/* if (whence > size) | /* if (whence > size) |
whence = size;*/ | whence = size;*/ |
/* Legit lseek does NOT do boundry checking */ |
/* Legit lseek does NOT do boundary checking */ |
| |
switch(whither) { | switch(whither) { |
case SEEK_SET: { | case SEEK_SET: { |
|
|
#endif | #endif |
memcpy(files[inode]->buf+pos, buf, len); | memcpy(files[inode]->buf+pos, buf, len); |
files[inode]->bytes_used += len; | files[inode]->bytes_used += len; |
|
handles[h]->pos += len; |
| |
return len; | return len; |
/* return -1 to simulate diskfull or some other error */ | /* return -1 to simulate diskfull or some other error */ |
} | } |
| |
| |
|
START_TEST(tvfs){ |
|
printf("dummy!"); |
|
} |
| |
| |
#ifdef TVFS_MAIN | #ifdef TVFS_MAIN |
|
|
| |
filebuf = malloc(MAXFLEN); | filebuf = malloc(MAXFLEN); |
| |
printf("Testing TVFS implementation, creating %s\n",name_test_txt); |
trace("Testing TVFS implementation, creating %s\n",name_test_txt); |
result = tvfs_create( dummy_filename, file_test_txt, size_test_txt); | result = tvfs_create( dummy_filename, file_test_txt, size_test_txt); |
result = tvfs_create( name_test_txt, file_test_txt,size_test_txt); | result = tvfs_create( name_test_txt, file_test_txt,size_test_txt); |
printf("Created virtual file with inode %d\n",result); |
trace("Created virtual file with inode %d\n",result); |
| |
printf("Attempting to open non-existant file\n"); |
trace("Attempting to open non-existent file\n"); |
result = tvfs_open(bad_filename, _O_BINARY, 0 ); | result = tvfs_open(bad_filename, _O_BINARY, 0 ); |
printf("Result code %d\n",result); |
trace("Result code %d\n",result); |
printf("Attempting to open existant file\n"); |
trace("Attempting to open existent file\n"); |
result = tvfs_open(name_test_txt, _O_BINARY, 0 ); | result = tvfs_open(name_test_txt, _O_BINARY, 0 ); |
printf("Result code %d\n",result); |
trace("Result code %d\n",result); |
| |
active_handler = result; | active_handler = result; |
| |
memset (filebuf,0,MAXFLEN); | memset (filebuf,0,MAXFLEN); |
| |
printf("Testing reading from file %s\n",name_test_txt); |
trace("Testing reading from file %s\n",name_test_txt); |
result = tvfs_read(active_handler, filebuf, 9); | result = tvfs_read(active_handler, filebuf, 9); |
printf("Read _%s_\n", filebuf); |
trace("Read _%s_\n", filebuf); |
if ( strcmp(filebuf,"This is a")) | if ( strcmp(filebuf,"This is a")) |
printf("File read check failed!\n"); |
trace("File read check failed!\n"); |
| |
printf("Testing sequential reading from file %s\n",name_test_txt); |
trace("Testing sequential reading from file %s\n",name_test_txt); |
result = tvfs_read(active_handler, filebuf, 12); | result = tvfs_read(active_handler, filebuf, 12); |
printf("Read _%s_\n", filebuf); |
trace("Read _%s_\n", filebuf); |
if ( strcmp(filebuf," test. Don't")) | if ( strcmp(filebuf," test. Don't")) |
printf("File read check failed!\n"); |
trace("File read check failed!\n"); |
| |
printf("Testing edge reading from file %s\n",name_test_txt); |
trace("Testing edge reading from file %s\n",name_test_txt); |
result = tvfs_read(active_handler, filebuf, 42); | result = tvfs_read(active_handler, filebuf, 42); |
printf("Read %d bytes - _%s_\n", result, filebuf); |
trace("Read %d bytes - _%s_\n", result, filebuf); |
if ( result != 8 ) | if ( result != 8 ) |
printf("File read check failed!\n"); |
trace("File read check failed!\n"); |
| |
printf("Testing direct file compare and lseek of %s\n", name_test_txt); |
trace("Testing direct file compare and lseek of %s\n", name_test_txt); |
printf("Seeking to 0 (not needed) - "); |
trace("Seeking to 0 (not needed) - "); |
tvfs_lseek( active_handler, SEEK_SET, 0); | tvfs_lseek( active_handler, SEEK_SET, 0); |
printf("Comparing file\n"); |
trace("Comparing file\n"); |
result = tvfs_compare( name_test_txt , file_test_txt, size_test_txt); | result = tvfs_compare( name_test_txt , file_test_txt, size_test_txt); |
if (result) | if (result) |
printf ("File compare failed!\n"); |
trace ("File compare failed!\n"); |
| |
| |
printf("Closing %s\n",name_test_txt); |
trace("Closing %s\n",name_test_txt); |
tvfs_close(active_handler); | tvfs_close(active_handler); |
if (result) | if (result) |
printf ("File close failed!\n"); |
trace ("File close failed!\n"); |
| |
tvfs_free(); | tvfs_free(); |
free(filebuf); | free(filebuf); |