00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "copyright.h"
00016
00017 #include "utility.h"
00018 #include "filesys.h"
00019 #include "system.h"
00020 #include "thread.h"
00021 #include "disk.h"
00022 #include "stats.h"
00023
00024 #define TransferSize 10 // make it small, just to be difficult
00025
00026
00027
00028
00029
00030
00031 void
00032 Copy(char *from, char *to)
00033 {
00034 FILE *fp;
00035 OpenFile* openFile;
00036 int amountRead, fileLength;
00037 char *buffer;
00038
00039
00040 if ((fp = fopen(from, "r")) == NULL) {
00041 printf("Copy: couldn't open input file %s\n", from);
00042 return;
00043 }
00044
00045
00046 fseek(fp, 0, 2);
00047 fileLength = ftell(fp);
00048 fseek(fp, 0, 0);
00049
00050
00051 DEBUG('f', "Copying file %s, size %d, to file %s\n", from, fileLength, to);
00052 if (!fileSystem->Create(to, fileLength)) {
00053 printf("Copy: couldn't create output file %s\n", to);
00054 fclose(fp);
00055 return;
00056 }
00057
00058 openFile = fileSystem->Open(to);
00059 ASSERT(openFile != NULL);
00060
00061
00062 buffer = new char[TransferSize];
00063 while ((amountRead = fread(buffer, sizeof(char), TransferSize, fp)) > 0)
00064 openFile->Write(buffer, amountRead);
00065 delete [] buffer;
00066
00067
00068 delete openFile;
00069 fclose(fp);
00070 }
00071
00072
00073
00074
00075
00076
00077 void
00078 Print(char *name)
00079 {
00080 OpenFile *openFile;
00081 int i, amountRead;
00082 char *buffer;
00083
00084 if ((openFile = fileSystem->Open(name)) == NULL) {
00085 printf("Print: unable to open file %s\n", name);
00086 return;
00087 }
00088
00089 buffer = new char[TransferSize];
00090 while ((amountRead = openFile->Read(buffer, TransferSize)) > 0)
00091 for (i = 0; i < amountRead; i++)
00092 printf("%c", buffer[i]);
00093 delete [] buffer;
00094
00095 delete openFile;
00096 return;
00097 }
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111 #define FileName "TestFile"
00112 #define Contents "1234567890"
00113 #define ContentSize strlen(Contents)
00114 #define FileSize ((int)(ContentSize * 5000))
00115
00116 static void
00117 FileWrite()
00118 {
00119 OpenFile *openFile;
00120 int i, numBytes;
00121
00122 printf("Sequential write of %d byte file, in %d byte chunks\n",
00123 FileSize, (int) ContentSize);
00124 if (!fileSystem->Create(FileName, 0)) {
00125 printf("Perf test: can't create %s\n", FileName);
00126 return;
00127 }
00128 openFile = fileSystem->Open(FileName);
00129 if (openFile == NULL) {
00130 printf("Perf test: unable to open %s\n", FileName);
00131 return;
00132 }
00133 for (i = 0; i < FileSize; i += ContentSize) {
00134 numBytes = openFile->Write(Contents, ContentSize);
00135 if (numBytes < 10) {
00136 printf("Perf test: unable to write %s\n", FileName);
00137 delete openFile;
00138 return;
00139 }
00140 }
00141 delete openFile;
00142 }
00143
00144 static void
00145 FileRead()
00146 {
00147 OpenFile *openFile;
00148 char *buffer = new char[ContentSize];
00149 int i, numBytes;
00150
00151 printf("Sequential read of %d byte file, in %d byte chunks\n",
00152 FileSize, (int) ContentSize);
00153
00154 if ((openFile = fileSystem->Open(FileName)) == NULL) {
00155 printf("Perf test: unable to open file %s\n", FileName);
00156 delete [] buffer;
00157 return;
00158 }
00159 for (i = 0; i < FileSize; i += ContentSize) {
00160 numBytes = openFile->Read(buffer, ContentSize);
00161 if ((numBytes < 10) || strncmp(buffer, Contents, ContentSize)) {
00162 printf("Perf test: unable to read %s\n", FileName);
00163 delete openFile;
00164 delete [] buffer;
00165 return;
00166 }
00167 }
00168 delete [] buffer;
00169 delete openFile;
00170 }
00171
00172 void
00173 PerformanceTest()
00174 {
00175 printf("Starting file system performance test:\n");
00176 stats->Print();
00177 FileWrite();
00178 FileRead();
00179 if (!fileSystem->Remove(FileName)) {
00180 printf("Perf test: unable to remove %s\n", FileName);
00181 return;
00182 }
00183 stats->Print();
00184 }
00185
The University of Southern California does not screen or control the content on this website and thus does not guarantee the accuracy, integrity, or quality of such content. All content on this website is provided by and is the sole responsibility of the person from which such content originated, and such content does not necessarily reflect the opinions of the University administration or the Board of Trustees