version 1.9, 2005/02/27 10:44:25
|
version 1.13, 2005/03/18 00:28:59
|
|
|
#include <stdio.h> | #include <stdio.h> |
#include <stdarg.h> | #include <stdarg.h> |
| |
/* |
|
#define TVFS_MAIN |
|
#define TVFS_DEBUG |
|
*/ |
|
|
|
#define SEEK_SET 0 | #define SEEK_SET 0 |
#define SEEK_CUR 1 | #define SEEK_CUR 1 |
#define SEEK_END 2 | #define SEEK_END 2 |
|
|
#define _O_BINARY 0 | #define _O_BINARY 0 |
#endif | #endif |
| |
|
/* |
|
#define TVFS_MAIN |
|
*/ |
|
|
#ifndef STANDALONE | #ifndef STANDALONE |
|
#include "wine/test.h" |
|
#define ok2 ok |
#else | #else |
static void trace(const char *s, ...) |
#include "standalone.h" |
{ |
#undef START_TEST |
va_list elipsis; |
|
va_start (elipsis, s); |
|
vprintf(s, elipsis); |
|
va_end(elipsis); |
|
} |
|
#endif | #endif |
| |
struct tvfs_file { | struct tvfs_file { |
|
|
int inode; | int inode; |
struct tvfs_file *f; | struct tvfs_file *f; |
| |
#ifdef TVFS_DEBUG |
|
trace("tvfs_create called with %s, %d, %d\n", fname, buf, len); | trace("tvfs_create called with %s, %d, %d\n", fname, buf, len); |
#endif |
|
| |
if (nfiles >= MAXFILES) | if (nfiles >= MAXFILES) |
return -1; | return -1; |
|
|
int inode; | int inode; |
struct tvfs_fcb *handler; | struct tvfs_fcb *handler; |
| |
#ifdef TVFS_DEBUG |
|
trace("tvfs_open called with %s, %d, %d\n", fname, flags, mode); | trace("tvfs_open called with %s, %d, %d\n", fname, flags, mode); |
#endif |
|
| |
/* Existing file? */ | /* Existing file? */ |
for (inode=0; inode<nfiles; inode++) { | for (inode=0; inode<nfiles; inode++) { |
|
|
/* File did not exist */ | /* File did not exist */ |
if ((flags & O_CREAT) == 0) { | if ((flags & O_CREAT) == 0) { |
/* ENOENT */ | /* ENOENT */ |
#ifdef TVFS_DEBUG |
|
trace("tvfs_open returning -1\n"); | trace("tvfs_open returning -1\n"); |
#endif |
|
return -1; | return -1; |
} | } |
| |
|
|
h = nhandles++; | h = nhandles++; |
handles[h] = handler; | handles[h] = handler; |
| |
#ifdef TVFS_DEBUG |
|
trace("tvfs_open returning with %d\n", h); | trace("tvfs_open returning with %d\n", h); |
#endif |
|
| |
return h; | return h; |
} | } |
|
|
int pos = handles[h]->pos; | int pos = handles[h]->pos; |
int size = files[inode]->bytes_used; | int size = files[inode]->bytes_used; |
| |
#ifdef TVFS_DEBUG |
|
trace("tvfs_read called with %d, %d, %d\n", h, buf, len); | trace("tvfs_read called with %d, %d, %d\n", h, buf, len); |
#endif |
|
| |
/* Edge Case 1 : Request beyond boundary of file */ | /* Edge Case 1 : Request beyond boundary of file */ |
if (pos + len > size) { | if (pos + len > size) { |
|
|
int inode; | int inode; |
int handle; | int handle; |
| |
#ifdef TVFS_DEBUG |
|
trace("tvfs_free\n"); | trace("tvfs_free\n"); |
#endif |
|
| |
nfiles=0; | nfiles=0; |
nhandles=0; | nhandles=0; |
|
|
| |
int inode; | int inode; |
| |
#ifdef TVFS_DEBUG |
|
trace("tvfs_compare called with %s, %d, %d\n", fname, buf, len); | trace("tvfs_compare called with %s, %d, %d\n", fname, buf, len); |
#endif |
|
| |
for (inode=0; inode<nfiles; inode++) { | for (inode=0; inode<nfiles; inode++) { |
if (!files[inode]) | if (!files[inode]) |
|
|
| |
if (inode == nfiles) { | if (inode == nfiles) { |
/* File did not exist */ | /* File did not exist */ |
#ifdef TVFS_DEBUG |
|
trace("tvfs_compare returning -1 (FAILURE)\n"); | trace("tvfs_compare returning -1 (FAILURE)\n"); |
#endif |
|
return -1; | return -1; |
} | } |
| |
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 ) |
|
|
| |
int inode = handles[h]->inode; | int inode = handles[h]->inode; |
int size = files[inode]->bytes_used; | int size = files[inode]->bytes_used; |
#ifdef TVFS_DEBUG |
|
trace("tvfs_lseek called with %d, %d, %d\n", h, whither, whence); | trace("tvfs_lseek called with %d, %d, %d\n", h, whither, whence); |
#endif |
|
| |
/* 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: { |
|
|
handles[h]->pos = size+whence; | handles[h]->pos = size+whence; |
break; | break; |
} | } |
case 44: { |
|
handles[h]->pos = size+whence; |
|
break; |
|
} |
|
default: | default: |
{ | { |
trace("lseek was called with an invalid whither %d\n",whither); | trace("lseek was called with an invalid whither %d\n",whither); |
|
|
return handles[h]->pos; | return handles[h]->pos; |
} | } |
| |
int tvfs_close(int h){ |
int tvfs_close(int h) |
|
{ |
int inode = handles[h]->inode; | int inode = handles[h]->inode; |
#ifdef TVFS_DEBUG |
|
trace("tvfs_close called with %d\n", h); | trace("tvfs_close called with %d\n", h); |
#endif |
|
if (!files[inode]){ | if (!files[inode]){ |
return -1; | return -1; |
} | } |
|
|
| |
int inode = handles[h]->inode; | int inode = handles[h]->inode; |
int pos = handles[h]->pos; | int pos = handles[h]->pos; |
#ifdef TVFS_DEBUG |
|
trace("tvfs_write called with %d, %d, %d\n", h, buf, len); | trace("tvfs_write called with %d, %d, %d\n", h, buf, len); |
#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; | handles[h]->pos += len; |
|
|
} | } |
| |
| |
|
START_TEST(tvfs){ |
|
printf("dummy!"); |
|
} |
| |
| |
#ifdef TVFS_MAIN | #ifdef TVFS_MAIN |
|
|
const static char file_test_txt[] = "This is a test. Don't Panic!"; | const static char file_test_txt[] = "This is a test. Don't Panic!"; |
const static int size_test_txt = sizeof(file_test_txt); | const static int size_test_txt = sizeof(file_test_txt); |
| |
main(){ |
/* If TVFSMain is defined, this compiles a test of the TVFS suite */ |
|
main() |
|
{ |
int result; | int result; |
int active_handler; | int active_handler; |
| |
|
|
| |
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); |