From: Stef B. <st...@gm...> - 2010-12-23 17:11:04
|
Hi all, my fs able to handle different underlying fs's/backends. Standard the backend is the local filesystem (every object can be reached/described using an absolute path or a fd and a path relative to this fd). Im working on making it possible to use other backends as well, like an audio cdrom using the library cd paranoia. Happily there is already a fs for that I can use as example, cddfs. Now when opening and reading a file from an audio cd it's possible to make fi->fh point to a custom struct, I've called struct cdromaudio_file_info_struct When opening a file the fs determines the path, finds out the backend, and then calls the right open command for the backend, which creates the right file handle backend, and tries to set some parameters, for example the wavheader. Now when reading an audio cdrom file is there an easy way to determine the backend when looking at fi and fi->fh only? Stef |
From: Stef B. <st...@gm...> - 2010-12-24 13:12:30
|
I've found a sollution. I make fi->fh a pointer to struct xmpfs_generic_fileinfo_struct { int backend; union { struct localhost_fi_struct *localhost; struct cdromaudio_fi_struct *cdromaudio; } underfs_fi; }; with backends: struct cdromaudio_fi_struct { struct md5key_resource_struct *md5key_resource; int filesize; char *buffer; char *buffer2keep; int sizebuf2keep; off_t offset; int tracknr; cdrom_paranoia *cdpointer; char *wavheader; int sectornr; } struct localhost_fi_struct { int fd; } and #define BACKEND_NOTSET 0 #define BACKEND_CDROMAUDIO 1 #define BACKEND_LOCALHOST 2 simular sollution I've got for the dirp (for opendir and readdir) and pathinformation. The pathinfo for the localhost is different than that for a track on a audio cd, a dirp on the localhost is a directory stream, for an audio cd it's not that, but a simple while loop adding the tracknames to the buffer. This construction is simple to extend with other backends. Stef |
From: Goswin v. B. <gos...@we...> - 2010-12-26 14:09:38
|
Stef Bon <st...@gm...> writes: > I've found a sollution. > > I make fi->fh a pointer to > > struct xmpfs_generic_fileinfo_struct { > int backend; > union { > struct localhost_fi_struct *localhost; > struct cdromaudio_fi_struct *cdromaudio; > } underfs_fi; > }; > > with backends: > > struct cdromaudio_fi_struct { > struct md5key_resource_struct *md5key_resource; > int filesize; > char *buffer; > char *buffer2keep; > int sizebuf2keep; > off_t offset; > int tracknr; > cdrom_paranoia *cdpointer; > char *wavheader; > int sectornr; > } > > struct localhost_fi_struct { > int fd; > } > > and > > #define BACKEND_NOTSET 0 > #define BACKEND_CDROMAUDIO 1 > #define BACKEND_LOCALHOST 2 Don't use an int and defines. Use an enum: enum backend = { NOTSET, CDROMAUDIO, LOCALHOST } That way gcc can warn you when you forget a case in the switch(fi->fh->backend) block. MfG Goswin |
From: Stef B. <st...@gm...> - 2010-12-27 16:57:35
|
Thanks a lot for your remark. I understand what you mean and why you suggest an enum. Nevertheless, I will still use defines, I consider myself as a lazy programmer if I forget a define. That would be very silly! And if I would, this would give serious errors, and it should! But thanks anyway, Stef 2010/12/26 Goswin von Brederlow <gos...@we...>: >> >> #define BACKEND_NOTSET 0 >> #define BACKEND_CDROMAUDIO 1 >> #define BACKEND_LOCALHOST 2 > > Don't use an int and defines. Use an enum: > > enum backend = { NOTSET, CDROMAUDIO, LOCALHOST } > > That way gcc can warn you when you forget a case in the > switch(fi->fh->backend) block. > > MfG > Goswin > |
From: Stef B. <st...@gm...> - 2010-12-28 22:56:47
|
No please I'm sorry for the misunderstanding! I'm not a superman and I also make mistakes, and I responded to Goswin that in the case of using an enum the compiler gives warnings, in some errornous cases. I prefer using the defines, cause this wil give errors a different way, and I prefer that. That was all. Stef 2010/12/28 Sven Utcke <sve...@gm...>: > Hello Stef, > >> Thanks a lot for your remark. I understand what you mean and why you >> suggest an enum. >> >> Nevertheless, I will still use defines, I consider myself as a lazy >> programmer if I forget a define. That would be very silly! And if I >> would, this would give serious errors, and it should! > > Hmm. Then you are, no doubt, a better man than many of us. You never > would use an '=' instead of an '==' either, and therefore haven't > switched on compiler warnings, I'm sure. > > May the power be with you... > > Sven > -- > __ _ _ __ __ __ > / _` || ' \ \ \ / > \__, ||_|_|_|/_\_\ http://kogs-www.informatik.uni-hamburg.de/~utcke/Private/ > |___/ Key fingerprint = 6F F8 55 1C F9 E3 A8 F7 09 DF F7 2C 25 0C 54 53 > |