http://prdownloads.sourceforge.net/lufs/lufs-0.9.7.tar.gz?download
[lufs.git] / filesystems / wavfs / fs_modules.cpp
1 #include <fcntl.h>
2 #include <unistd.h>
3
4 #include <vector>
5 #include <string>
6
7 #include <lufs/proto.h>
8 #include <lufs/fs.h>
9
10 using namespace std;
11
12 #include "tools.h"
13 #include "file_handle.h"
14 #include "fs_modules.h"
15
16
17 /********* FSModule methods **************/
18
19 string FSModule::GetVirtualFilename(const char* fname)
20 {
21         if(endswith(fname, GetRealExtension()))
22                 return string(fname)+GetVirtualExtension();
23         else
24                 return string();
25 }
26
27 bool FSModule::IsMyVirtualFilename(const char* fname)
28 {
29         // ends with virtual extension ?
30         string real_candidate = removeend( fname, GetVirtualExtension() );
31         if( real_candidate.size() == 0 )
32                 return false;
33         
34         // real filename ends with real extension corresponding to the compression we use ?
35         return endswith(real_candidate.c_str(),GetRealExtension());
36 }
37
38 string FSModule::GetRealFilename( const char* virtuel )
39 {
40         return removeend( virtuel, GetVirtualExtension() );
41 }
42
43 FileHandle*     FSModule::Open( const char* path )
44 {
45         TRACE(Identity()<<" tries to open "<<path);
46         
47         if( !IsMyVirtualFilename(path) )
48                 return NULL;
49         
50         string real_path = GetRealFilename(path);
51         TRACE(Identity()<<" => name matches, i'll look closer at "<<path<<" ** "<<real_path);
52         
53         FileHandle *handle = CreateHandle(path,real_path.c_str());
54         if( handle->Open()<0 )
55         {
56                 delete handle;
57                 return 0;
58         }
59         else
60                 return handle;
61 }
62
63
64 /********* FSModule_Default methods **************/
65
66 string FSModule_Default::GetVirtualFilename(const char* fname)
67 {
68         return string(fname);
69 }
70
71 bool FSModule_Default::IsMyVirtualFilename(const char* fname)
72 {
73         return true;
74 }
75
76 string FSModule_Default::GetRealFilename( const char* virtuel )
77 {
78         return virtuel;
79 }
80
81 /********* FSModule_Flac methods **************/