------ORIGINAL POST IN THE SFS IMPLEMENTATION FORUM------
The source code I talk about is visible below or at the SVN repository of the SF.NET project simplefs-fuse
As some in the SFS community may know, I am writing a Linux SFS driver based on FUSE. However, I want the "-tools" package (currently just the mksimplefs utility) to work on as many systems as possible, so I don't have to port it should I want to write, for instance, a Mac OS X driver. My (foolish?) objective is working on all POSIX compliant systems.
One of the most important things mksimplefs does is figuring out how big the volume to be formatted is. For the sake of portability (I then thought), I implemented what any sane programmer would now call a "not-so-happy idea" - looks standard but is really system-dependant: I open the device to be formatted, seek to its end and get the current position. Simple as hell, isn't it? It wasn't. On Linux (my development platform), you can open block device nodes as binary streams and seek into them, but OpenBSD (and, I suspect, all BSD-like systems) are not so kind. On them, I get the fstream.failbit set even after trying to seek.
So the question is: how can I obtain the size of the volume to be formatted in a POSIX-standard way?
Very simple C++ code to test what I said:
Code: Select all
#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char* argv[])
{
fstream volume(argv[1], ios::in | ios::out | ios::binary);
if (volume.fail())
cerr << "Couldn't open " << argv[1] << endl;
else {
volume.seekp(0, ios::end);
cout << volume.tellp() << endl;
volume.close();
}
}
PS: Thanks BryNet-Inc for telling me about this quite big bug.