version 1.4, 2005/02/25 10:35:55
|
version 1.7, 2005/02/27 05:21:08
|
|
|
#define TVFS_MAIN | #define TVFS_MAIN |
*/ | */ |
#include <fcntl.h> | #include <fcntl.h> |
#include <stdlib.h> /* For _MAX_PATH definition */ |
#include <stdlib.h> |
#include <stdio.h> | #include <stdio.h> |
#include <malloc.h> | #include <malloc.h> |
|
/* |
#define DEBUG | #define 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 |
|
|
/* File did not exist */ | /* File did not exist */ |
if ((flags & O_CREAT) == 0) { | if ((flags & O_CREAT) == 0) { |
/* ENOENT */ | /* ENOENT */ |
|
#ifdef DEBUG |
|
printf("tvfs_open returning -1\n"); |
|
#endif |
return -1; | return -1; |
} | } |
inode = tvfs_create(fname, 0, 0); | inode = tvfs_create(fname, 0, 0); |
|
|
handler->pos=0; | handler->pos=0; |
h = nfiles++; | h = nfiles++; |
handles[h] = handler; | handles[h] = handler; |
|
#ifdef DEBUG |
|
printf("tvfs_open returning with %d\n", h); |
|
#endif |
|
|
return h; | return h; |
} | } |
| |
|
|
printf("tvfs_free\n"); | printf("tvfs_free\n"); |
#endif | #endif |
| |
|
nfiles=0; |
|
nhandles=0; |
|
|
for (inode=0; inode<nfiles; inode++) { | for (inode=0; inode<nfiles; inode++) { |
if (!files[inode]) | if (!files[inode]) |
continue; | continue; |
|
|
| |
/* Compare given file with given contents, return 0 on equal, else nonzero */ | /* Compare given file with given contents, return 0 on equal, else nonzero */ |
int tvfs_compare(const char *fname, const char *buf, int len){ | int tvfs_compare(const char *fname, const char *buf, int len){ |
|
|
|
int inode; |
|
|
#ifdef DEBUG | #ifdef DEBUG |
printf("tvfs_compare called with %s, %d, %d\n", fname, buf, len); | printf("tvfs_compare called with %s, %d, %d\n", fname, buf, len); |
#endif | #endif |
| |
return (memcmp(fname,buf,len)); |
for (inode=0; inode<nfiles; inode++) { |
|
if (!files[inode]) |
|
continue; |
|
if (!strcmp(files[inode]->fname, fname)) |
|
break; } |
|
if (inode == nfiles) { |
|
/* File did not exist */ |
|
#ifdef DEBUG |
|
printf("tvfs_compare returning -1 (FAILURE)\n"); |
|
#endif |
|
return -1; |
|
} |
|
|
|
return (memcmp(files[inode]->buf,buf,len)); |
/* doesnt check for out of bound */ | /* doesnt check for out of bound */ |
} | } |
| |
long tvfs_lseek(int h, long whither, int whence){ |
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; |
|
|
| |
unsigned int tvfs_write(int h, void *buf, unsigned int len) | unsigned int tvfs_write(int h, void *buf, unsigned int len) |
{ | { |
|
|
|
int inode = handles[h]->inode; |
|
int pos = handles[h]->pos; |
|
|
printf("tvfs_write called with %d, %d, %d\n", h, buf, len); | printf("tvfs_write called with %d, %d, %d\n", h, buf, len); |
|
|
|
memcpy(files[inode]->buf+pos, buf, len); |
|
files[inode]->bytes_used += len; |
|
|
return len; | return len; |
/* return -1 to simulate diskfull or some other error */ | /* return -1 to simulate diskfull or some other error */ |
} | } |
|
|
printf("File read check failed!\n"); | printf("File read check failed!\n"); |
| |
printf("Testing direct file compare and lseek of %s\n", name_test_txt); | printf("Testing direct file compare and lseek of %s\n", name_test_txt); |
printf("Seeking to 0 - "); |
printf("Seeking to 0 (not needed) - "); |
tvfs_lseek( active_handler, SEEK_SET, 0); | tvfs_lseek( active_handler, SEEK_SET, 0); |
printf("Reading and comparing file\n"); |
printf("Comparing file\n"); |
result = tvfs_read(active_handler, filebuf, size_test_txt); |
result = tvfs_compare( name_test_txt , file_test_txt, size_test_txt); |
result = tvfs_compare( filebuf , file_test_txt, size_test_txt); |
|
if (result) | if (result) |
printf ("File compare failed!\n"); | printf ("File compare failed!\n"); |
| |