00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include <Basics.H>
00039 #include "FS.H"
00040 #include "AtomicFile.H"
00041
00042 using std::cerr;
00043 using std::endl;
00044 using std::ios;
00045
00046 void Syntax(char *msg) {
00047 cerr << "Error: " << msg << endl;
00048 cerr << "Syntax: TestFullDisk [ -useFS ] filename size" << endl;
00049 exit(1);
00050 }
00051
00052 void Test(bool useFS, char *filename, int size) throw (FS::Failure) {
00053
00054 AtomicFile ofs;
00055 ofs.open(filename, ios::out);
00056 if (ofs.fail()) {
00057 throw(FS::Failure(Text("AtomicFile::open"), filename));
00058 }
00059
00060
00061 const int BuffSz = 1024 * 8;
00062 char buff[BuffSz];
00063 while (size > 0) {
00064 int toWrite = min(BuffSz, size);
00065 if (useFS) {
00066 FS::Write(ofs, buff, toWrite);
00067 } else {
00068 ofs.write(buff, toWrite);
00069 }
00070 size -= toWrite;
00071 }
00072
00073
00074 FS::Close(ofs);
00075 }
00076
00077 int main(int argc, char *argv[]) {
00078
00079 if (argc != 3 && argc != 4) {
00080 Syntax("incorrect number of arguments");
00081 }
00082 int arg = 1;
00083 bool useFS = false;
00084 if (strcmp(argv[arg], "-useFS") == 0) {
00085 arg++;
00086 useFS = true;
00087 }
00088 char *filename = argv[arg++];
00089 int size;
00090 if (sscanf(argv[arg++], "%d", &size) != 1) {
00091 Syntax("'size' argument not an integer");
00092 }
00093
00094
00095 try {
00096 Test(useFS, filename, size);
00097 } catch (const FS::Failure &f) {
00098
00099 cerr << f;
00100 assert(false);
00101 }
00102 return 0;
00103 }
00104