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 #include "VestaSource.H"
00029 #include "VestaConfig.H"
00030 #include "VDirSurrogate.H"
00031 #include <stdlib.h>
00032 #include <pthread.h>
00033 #include <errno.h>
00034 #include <iomanip>
00035 #include <stdio.h>
00036
00037 using std::cout;
00038 using std::cin;
00039 using std::cerr;
00040 using std::endl;
00041 using std::setw;
00042 using std::setfill;
00043 using std::hex;
00044 using std::dec;
00045
00046 char *boolText[] = { "false", "true" };
00047
00048 bool
00049 myListCallback(void* closure, VestaSource::typeTag type, Arc arc,
00050 unsigned int index, Bit32 pseudoInode, ShortId filesid,
00051 bool master)
00052 {
00053 cout << setw(3) << index
00054 << " " << setw(1) << VestaSource::typeTagChar(type)
00055 << (master ? 'M' : ' ')
00056 << " " << setw(8) << hex << pseudoInode << dec
00057 << " " << setw(8) << hex << filesid << dec
00058 << " " << arc << endl;
00059 return true;
00060 }
00061
00062 bool
00063 valueCb(void* cl, const char* value)
00064 {
00065 cout << value << " ";
00066 return true;
00067 }
00068
00069 bool
00070 historyCb(void* cl, VestaSource::attribOp op, const char* name,
00071 const char* value, time_t timestamp)
00072 {
00073 cout << VestaSource::attribOpChar(op) << ", " << name << ", "
00074 << value << ", " << timestamp << endl;
00075 return true;
00076 }
00077
00078 void
00079 coutLongId(const LongId& longid)
00080 {
00081 int i;
00082 int len = longid.length();
00083 for (i=0; i<len; i++) {
00084 cout << setw(2) << setfill('0') << hex
00085 << (int) (longid.value.byte[i] & 0xff) << setfill(' ');
00086 }
00087 cout << dec;
00088 }
00089
00090 void
00091 cinLongId(LongId& longid)
00092 {
00093 char junk;
00094 char buf[256];
00095 cin >> buf;
00096 cin.get(junk);
00097 int i;
00098 for (i=0; i<32; i++) {
00099 int byte;
00100 if (sscanf(&buf[i*2], "%2x", &byte) != 1) break;
00101 longid.value.byte[i] = byte;
00102 if (buf[i*2 + 1] == '\0') {
00103 longid.value.byte[i] <<= 4;
00104 i++;
00105 break;
00106 }
00107 }
00108 for (; i<32; i++) {
00109 longid.value.byte[i] = 0;
00110 }
00111 }
00112
00113 void
00114 coutFPTag(FP::Tag& fptag)
00115 {
00116 int i;
00117 unsigned char* fpbytes = (unsigned char*) fptag.Words();
00118 for (i=0; i<FP::ByteCnt; i++) {
00119 cout << setw(2) << setfill('0') << hex
00120 << (int) (fpbytes[i] & 0xff) << setfill(' ');
00121 }
00122 cout << dec;
00123 }
00124
00125 void
00126 cinFPTag(FP::Tag& fptag)
00127 {
00128 for (;;) {
00129 char junk;
00130 char buf[256];
00131 cin >> buf;
00132 cin.get(junk);
00133 int i;
00134 unsigned char* fpbytes = (unsigned char*) fptag.Words();
00135 for (i=0; i<FP::ByteCnt; i++) {
00136 int byte;
00137 if (sscanf(&buf[i*2], "%2x", &byte) != 1) {
00138 cout << "Invalid fptag value; try again" << endl;
00139 break;
00140 }
00141 fpbytes[i] = byte;
00142 }
00143 if (i==FP::ByteCnt) return;
00144 }
00145 }
00146
00147 #if 0
00148 void
00149 default_identity(AccessControl::Identity who)
00150 {
00151 who->aup_time = time(NULL);
00152 static char machname[MAX_MACHINE_NAME + 1];
00153 gethostname(machname, sizeof(machname));
00154 who->aup_machname = machname;
00155 who->aup_uid = geteuid();
00156 who->aup_gid = getegid();
00157 static int groups[NGRPS];
00158 who->aup_len = getgroups(NGRPS, (gid_t*) groups);
00159 who->aup_gids = groups;
00160 }
00161
00162 void
00163 print_identity(AccessControl::Identity who)
00164 {
00165 cout << "Identity: ";
00166 cout << "[ time=0x" << hex << who->aup_time << dec
00167 << ", machname=" << who->aup_machname << "," << endl
00168 << " uid=" << who->aup_uid << ", gid=" << who->aup_gid
00169 << ", gids=";
00170 int i;
00171 for (i=0; i<who->aup_len; i++) {
00172 cout << who->aup_gids[i] << " ";
00173 }
00174 cout << "]" << endl;
00175 }
00176 #endif
00177
00178 int
00179 readSrcN(const int& nextSrcN)
00180 {
00181 for (;;) {
00182 int res;
00183 char typein[300];
00184 char junk;
00185 cout << "src#: ";
00186 cin.get(typein, sizeof(typein));
00187 cin.get(junk);
00188 res = atoi(typein);
00189 if (res >= nextSrcN) {
00190 cout << "Out of range; max src# is " << nextSrcN - 1 << endl;
00191 } else {
00192 return res;
00193 }
00194 }
00195 }
00196
00197 Text
00198 vsToFilename(VestaSource* vs)
00199 {
00200 Text ret = "";
00201 LongId longid_par;
00202 unsigned int index;
00203 VestaSource* vs_cur = vs;
00204 VestaSource* vs_par;
00205 VestaSource* vs_junk;
00206 VestaSource::errorCode err;
00207 char arcbuf[MAX_ARC_LEN+1];
00208 const Text& host = vs->host();
00209 const Text& port = vs->port();
00210 for (;;) {
00211 longid_par = vs_cur->longid.getParent(&index);
00212 if (longid_par == NullLongId) {
00213 Text prefix = "invalid longid/";
00214 if (vs_cur->longid.value.byte[0] == 0) {
00215 if (vs_cur->longid == RootLongId) {
00216 prefix = "/vesta/";
00217 } else if (vs_cur->longid == MutableRootLongId) {
00218 prefix = "/vesta-work/";
00219 } else if (vs_cur->longid == VolatileRootLongId) {
00220 prefix = "/vesta-work/.volatile/";
00221 } else if (vs_cur->longid == DirShortIdRootLongId) {
00222 prefix = "dir sid longid/";
00223 } else if (vs_cur->longid == FileShortIdRootLongId) {
00224 prefix = "file sid longid/";
00225 }
00226 }
00227 ret = prefix + ret;
00228 break;
00229 }
00230 vs_par = VDirSurrogate::LongIdLookup(longid_par, host, port);
00231 if (vs_par == NULL) {
00232 return "longid lookup failed";
00233 }
00234 err = vs_par->lookupIndex(index, vs_junk, arcbuf);
00235 if (err != VestaSource::ok) {
00236 return Text("longid lookup failed: ") +
00237 VestaSource::errorCodeString(err);
00238 }
00239 delete vs_junk;
00240 ret = Text(arcbuf) + PathnameSep + ret;
00241 if (vs_cur != vs) delete vs_cur;
00242 vs_cur = vs_par;
00243 }
00244 done:
00245
00246 ret = ret.Sub(0, ret.Length() - 1);
00247 if (vs_cur != vs) delete vs_cur;
00248 return ret;
00249 }
00250
00251 void *
00252 test_thread(void *arg)
00253 {
00254 VestaSource* src[100];
00255 int nextSrcN;
00256 AccessControl::Identity who = NULL;
00257
00258
00259 cout << "RepositoryRoot is source #0; MutableRoot is source #1" << endl;
00260 src[0] = VestaSource::repositoryRoot();
00261 src[1] = VestaSource::mutableRoot();
00262 nextSrcN = 2;
00263 for (;;) {
00264 char typein[300];
00265 char arc[300];
00266 char arc2[300];
00267 char arc3[300];
00268 char arc4[300];
00269 char arc5[300];
00270 char junk;
00271 long ltmp;
00272 int srcN, newSrcN, srcN2, srcN3, srcN4, i, master, tmp, chk;
00273 unsigned int index;
00274 VestaSource::errorCode err;
00275 ShortId sid;
00276 LongId longid, longid2;
00277 char* charstar;
00278 VestaSource* vs;
00279 Bit64 handle;
00280 time_t timestamp;
00281 VestaSource::attribOp op;
00282 FP::Tag fptag;
00283 Text rhost, rport;
00284
00285 cout << "command (? for help): ";
00286
00287 cin.get(typein, sizeof(typein));
00288 cin.get(junk);
00289 switch (typein[0]) {
00290 case '?':
00291 cout <<
00292 "res(Y)nc, (p)rint, (s)hortId, lookup (a)rc/(P)ath, (i)nsert, (d)elete, (l)ist\n"
00293 "makeM(u)table, longid app(e)nd/(g)etParent/loo(k)up/fromSh(o)rtId/(v)alid,\n"
00294 "(h)asAttribs, i(n)Attribs, getAttrib(1), getAttrib(2), lis(t)Attribs,\n"
00295 "getAttribHistor(y), writeAttri(b), get(N)FSInfo, make(f)ilesImmutable,\n"
00296 "create(V)olatile, (D)eleteVolatile, repli(c)ate, repli(C)ateAttribs\n"
00297 "identity (S)etNew/(R)esetToDefault, set(m)aster,\n"
00298 "(r)ead, (w)rite, e(x)ecutable, setE(X)ecutable, si(z)e, setSi(Z)e,\n"
00299 "(3)timestamp, (4)setTimestamp, get(B)ase, fpToS(H)ortId,\n"
00300 "(M)easureDirectory, c(O)llapseBase, read(W)hole,\n"
00301 "(q)uit\n";
00302 break;
00303
00304 case 'Y':
00305 srcN = readSrcN(nextSrcN);
00306 src[srcN]->resync();
00307 break;
00308
00309 case 'p':
00310 srcN = readSrcN(nextSrcN);
00311 cout << "rep " << hex << (PointerInt) src[srcN]->rep << dec
00312 << "\nattribs " << hex <<
00313 (PointerInt) src[srcN]->attribs << dec
00314 << "\ntype " << VestaSource::typeTagString(src[srcN]->type)
00315 << "\nlongid ";
00316 coutLongId(src[srcN]->longid);
00317 cout << "\ntimestamp " << src[srcN]->timestamp()
00318 << "\npseudoInode " << hex << src[srcN]->pseudoInode << dec
00319 << "\nmaster " << (int) src[srcN]->master
00320 << "\nfingerprint ";
00321 coutFPTag(src[srcN]->fptag);
00322
00323
00324
00325
00326 cout << endl;
00327 cout << vsToFilename(src[srcN]) << endl;
00328 break;
00329
00330 case 's':
00331 srcN = readSrcN(nextSrcN);
00332 cout << hex << src[srcN]->shortId() << dec << endl;
00333 break;
00334
00335 case 'a':
00336 cout << "in ";
00337 srcN = readSrcN(nextSrcN);
00338 cout << "arc: ";
00339 cin.get(arc, sizeof(arc));
00340 cin.get(junk);
00341 err = src[srcN]->lookup(arc, src[nextSrcN], who);
00342 if (err == VestaSource::ok) {
00343 newSrcN = nextSrcN++;
00344 cout << "src# = " << newSrcN << endl;
00345 } else {
00346 cout << "error " << VestaSource::errorCodeString(err) << endl;
00347 }
00348 break;
00349
00350 case 'P':
00351 cout << "in ";
00352 srcN = readSrcN(nextSrcN);
00353 cout << "pathname: ";
00354 cin.get(arc, sizeof(arc));
00355 cin.get(junk);
00356 err = src[srcN]->lookupPathname(arc, src[nextSrcN], who);
00357 if (err == VestaSource::ok) {
00358 newSrcN = nextSrcN++;
00359 cout << "src# = " << newSrcN << endl;
00360 } else {
00361 cout << "error " << VestaSource::errorCodeString(err) << endl;
00362 }
00363 break;
00364
00365 case 'i':
00366 cout << "in ";
00367 srcN = readSrcN(nextSrcN);
00368 cout << "arc: ";
00369 cin.get(arc, sizeof(arc));
00370 cin.get(junk);
00371 cout << "master (0 or 1): ";
00372 cin >> master;
00373 cin.get(junk);
00374 cout << "dupeCheck (0=dontR 1=rDiff): ";
00375 cin >> chk;
00376 cin.get(junk);
00377 cout << "(f)ile, m(u)File, (i)mDir, (a)pDir, (m)uDir, (g)host, (s)tub: ";
00378 cin.get(typein, sizeof(typein));
00379 cin.get(junk);
00380 switch (typein[0]) {
00381 case 'f':
00382 case 'u':
00383 cout << "shortId: ";
00384 cin >> hex >> sid >> dec;
00385 cin.get(junk);
00386 if (typein[0] == 'f') {
00387 err = src[srcN]->
00388 insertFile(arc, sid, (bool) master, who,
00389 (VestaSource::dupeCheck) chk,
00390 &src[nextSrcN]);
00391 } else {
00392 err = src[srcN]->
00393 insertMutableFile(arc, sid, (bool) master, who,
00394 (VestaSource::dupeCheck) chk,
00395 &src[nextSrcN]);
00396 }
00397 if (err == VestaSource::ok) {
00398 cout << "new src# = " << nextSrcN++;
00399 cout << endl;
00400 } else {
00401 cout << "error " << VestaSource::errorCodeString(err) << endl;
00402 }
00403 break;
00404
00405 case 'i':
00406 cout << "mutable directory (-1 for NULL) ";
00407 newSrcN = readSrcN(nextSrcN);
00408 err = src[srcN]->insertImmutableDirectory(arc,
00409 (newSrcN == -1 ? NULL : src[newSrcN]), (bool) master,
00410 who, (VestaSource::dupeCheck) chk, &src[nextSrcN]);
00411 if (err == VestaSource::ok) {
00412 cout << "new src# = " << nextSrcN++;
00413 cout << endl;
00414 } else {
00415 cout << "error " << VestaSource::errorCodeString(err) << endl;
00416 }
00417 break;
00418
00419 case 'a':
00420 err = src[srcN]->insertAppendableDirectory(
00421 arc, (bool) master, who,
00422 (VestaSource::dupeCheck) chk, &src[nextSrcN]);
00423 if (err == VestaSource::ok) {
00424 cout << "new src# = " << nextSrcN++;
00425 cout << endl;
00426 } else {
00427 cout << "error " << VestaSource::errorCodeString(err) << endl;
00428 }
00429 break;
00430
00431 case 'm':
00432 cout << "immutable directory (-1 for NULL) ";
00433 newSrcN = readSrcN(nextSrcN);
00434 err = src[srcN]->insertMutableDirectory(
00435 arc, newSrcN == -1 ? NULL : src[newSrcN],
00436 (bool) master, who,
00437 (VestaSource::dupeCheck) chk, &src[nextSrcN]);
00438 if (err == VestaSource::ok) {
00439 cout << "new src# = " << nextSrcN++;
00440 cout << endl;
00441 } else {
00442 cout << "error " << VestaSource::errorCodeString(err)
00443 << endl;
00444 }
00445 break;
00446
00447 case 'g':
00448 err =
00449 src[srcN]->insertGhost(arc, (bool) master, who,
00450 (VestaSource::dupeCheck) chk,
00451 &src[nextSrcN]);
00452 if (err == VestaSource::ok) {
00453 cout << "new src# = " << nextSrcN++;
00454 cout << endl;
00455 } else {
00456 cout << "error " << VestaSource::errorCodeString(err)
00457 << endl;
00458 }
00459 break;
00460
00461 case 's':
00462 err =
00463 src[srcN]->insertStub(arc, (bool) master, who,
00464 (VestaSource::dupeCheck) chk,
00465 &src[nextSrcN]);
00466 if (err == VestaSource::ok) {
00467 cout << "new src# = " << nextSrcN++;
00468 cout << endl;
00469 } else {
00470 cout << "error " << VestaSource::errorCodeString(err)
00471 << endl;
00472 }
00473 break;
00474
00475 default:
00476 break;
00477 }
00478 break;
00479
00480 case 'd':
00481 cout << "from";
00482 srcN = readSrcN(nextSrcN);
00483 cout << "arc: ";
00484 cin.get(arc, sizeof(arc));
00485 cin.get(junk);
00486 cout << "existCheck (0 or 1): ";
00487 cin >> chk;
00488 cin.get(junk);
00489 err = src[srcN]->reallyDelete(arc, who, (bool) chk);
00490 if (err == VestaSource::ok) {
00491 cout << "ok" << endl;
00492 } else {
00493 cout << "error " << VestaSource::errorCodeString(err) << endl;
00494 }
00495 break;
00496
00497 case 'l':
00498 srcN = readSrcN(nextSrcN);
00499 cout << "(d)eltaOnly, (a)ll entries: ";
00500 cin.get(typein, sizeof(typein));
00501 cin.get(junk);
00502 err = src[srcN]->list(0, myListCallback, NULL, who,
00503 typein[0] == 'd');
00504 if (err != VestaSource::ok) {
00505 cout << "error " << VestaSource::errorCodeString(err) << endl;
00506 }
00507 break;
00508
00509 case 'B':
00510 srcN = readSrcN(nextSrcN);
00511 err = src[srcN]->getBase(src[nextSrcN], who);
00512 if (err != VestaSource::ok) {
00513 cout << "error " << VestaSource::errorCodeString(err) << endl;
00514 } else {
00515 newSrcN = nextSrcN++;
00516 cout << "src# = " << newSrcN << endl;
00517 }
00518 break;
00519
00520 case 'u':
00521 srcN = readSrcN(nextSrcN);
00522 if (src[srcN]->type == VestaSource::immutableFile ||
00523 src[srcN]->type == VestaSource::mutableFile) {
00524 cout << "shortId: ";
00525 cin >> hex >> sid >> dec;
00526 cin.get(junk);
00527 }
00528 err = src[srcN]->makeMutable(src[nextSrcN], sid,
00529 (Basics::uint64) -1, who);
00530 if (err != VestaSource::ok) {
00531 cout << "error " << VestaSource::errorCodeString(err) << endl;
00532 } else {
00533 newSrcN = nextSrcN++;
00534 cout << "src# = " << newSrcN << endl;
00535 }
00536 break;
00537
00538 case 'e':
00539 cout << "longid: ";
00540 cinLongId(longid);
00541 cout << "index: ";
00542 cin >> index;
00543 cin.get(junk);
00544 cout << "child = ";
00545 coutLongId(longid.append(index));
00546 cout << endl;
00547 break;
00548
00549 case 'g':
00550 cout << "longid: ";
00551 cinLongId(longid);
00552 cout << "parent = ";
00553 coutLongId(longid.getParent(&index));
00554 cout << endl;
00555 cout << "index = " << index << endl;
00556 break;
00557
00558 case 'k':
00559 cout << "longid: ";
00560 cinLongId(longid);
00561 cout << "host: ";
00562 cin.get(arc, sizeof(arc));
00563 cin.get(junk);
00564 rhost = arc;
00565 cout << "port: ";
00566 cin.get(arc, sizeof(arc));
00567 cin.get(junk);
00568 rport = arc;
00569 try {
00570 src[nextSrcN] =
00571 VDirSurrogate::LongIdLookup(longid, rhost, rport);
00572 if (src[nextSrcN] != NULL) {
00573 newSrcN = nextSrcN++;
00574 cout << "src# = " << newSrcN << endl;
00575 } else {
00576 cout << "error " << endl;
00577 }
00578 } catch (SRPC::failure f) {
00579 cout << "error " << f.msg << " (" << f.r << ")" << endl;
00580 }
00581 break;
00582
00583 case 'v':
00584 cout << "longid: ";
00585 cinLongId(longid);
00586 cout << "host: ";
00587 cin.get(arc, sizeof(arc));
00588 cin.get(junk);
00589 rhost = arc;
00590 cout << "port: ";
00591 cin.get(arc, sizeof(arc));
00592 cin.get(junk);
00593 rport = arc;
00594 try {
00595 tmp = VDirSurrogate::LongIdValid(longid, rhost, rport);
00596 cout << (tmp ? "true" : "false") << endl;
00597 } catch (SRPC::failure f) {
00598 cout << "error " << f.msg << " (" << f.r << ")" << endl;
00599 }
00600 break;
00601
00602 case 'H':
00603 cout << "fptag: ";
00604 cinFPTag(fptag);
00605 cout << "host: ";
00606 cin.get(arc, sizeof(arc));
00607 cin.get(junk);
00608 rhost = arc;
00609 cout << "port: ";
00610 cin.get(arc, sizeof(arc));
00611 cin.get(junk);
00612 rport = arc;
00613 try {
00614 sid = VDirSurrogate::fpToShortId(fptag, rhost, rport);
00615 cout << "sid = " << setw(8) << hex << sid << dec << endl;
00616 } catch (SRPC::failure f) {
00617 cout << "error " << f.msg << " (" << f.r << ")" << endl;
00618 }
00619 break;
00620
00621 case 'o':
00622 cout << "shortId: ";
00623 cin >> hex >> sid >> dec;
00624 cin.get(junk);
00625 cout << "fptag: ";
00626 cinFPTag(fptag);
00627 longid = LongId::fromShortId(sid, &fptag);
00628 src[nextSrcN] = longid.lookup();
00629 if (src[nextSrcN] != NULL) {
00630 newSrcN = nextSrcN++;
00631 cout << "src# = " << newSrcN << endl;
00632 } else {
00633 cout << "error " << endl;
00634 }
00635 break;
00636
00637 case 'h':
00638 srcN = readSrcN(nextSrcN);
00639 cout << boolText[(int) src[srcN]->hasAttribs()] << endl;;
00640 break;
00641
00642 case 'n':
00643 srcN = readSrcN(nextSrcN);
00644 cout << "name: ";
00645 cin.get(arc, sizeof(arc));
00646 cin.get(junk);
00647 cout << "value: ";
00648 cin.get(arc2, sizeof(arc2));
00649 cin.get(junk);
00650 cout << boolText[(int) src[srcN]->inAttribs(arc, arc2)] << endl;
00651 break;
00652
00653 case '1':
00654 srcN = readSrcN(nextSrcN);
00655 cout << "name: ";
00656 cin.get(arc, sizeof(arc));
00657 cin.get(junk);
00658 charstar = src[srcN]->getAttrib(arc);
00659 if (charstar != NULL) {
00660 cout << charstar << endl;
00661 }
00662 break;
00663
00664 case '2':
00665 srcN = readSrcN(nextSrcN);
00666 cout << "name: ";
00667 cin.get(arc, sizeof(arc));
00668 cin.get(junk);
00669 src[srcN]->getAttrib(arc, valueCb, NULL);
00670 cout << endl;
00671 break;
00672
00673 case 't':
00674 srcN = readSrcN(nextSrcN);
00675 src[srcN]->listAttribs(valueCb, NULL);
00676 cout << endl;
00677 break;
00678
00679 case 'y':
00680 srcN = readSrcN(nextSrcN);
00681 src[srcN]->getAttribHistory(historyCb, NULL);
00682 break;
00683
00684 case 'b':
00685 srcN = readSrcN(nextSrcN);
00686 cout << "(s)et, (c)lear, (a)dd, (r)emove: ";
00687 cin.get(typein, sizeof(typein));
00688 cin.get(junk);
00689 switch (typein[0]) {
00690 case 's':
00691 op = VestaSource::opSet;
00692 break;
00693 case 'c':
00694 op = VestaSource::opClear;
00695 break;
00696 case 'a':
00697 op = VestaSource::opAdd;
00698 break;
00699 case 'r':
00700 op = VestaSource::opRemove;
00701 break;
00702 default:
00703 continue;
00704 }
00705 cout << "name: ";
00706 cin.get(arc, sizeof(arc));
00707 cin.get(junk);
00708 if (op == VestaSource::opClear) {
00709 arc2[0] = '\000';
00710 } else {
00711 cout << "value: ";
00712 cin.get(arc2, sizeof(arc2));
00713 cin.get(junk);
00714 }
00715 cout << "timestamp (0=now): ";
00716 cin >> timestamp;
00717 cin.get(junk);
00718 src[srcN]->writeAttrib(op, arc, arc2, who, timestamp);
00719 break;
00720
00721 case 'V':
00722 cout << "hostname: ";
00723 cin.get(arc, sizeof(arc));
00724 cin.get(junk);
00725 cout << "port: ";
00726 cin.get(arc2, sizeof(arc2));
00727 cin.get(junk);
00728 cout << "handle (hex): ";
00729 cin >> hex >> handle >> dec;
00730 cin.get(junk);
00731 cout << "readOnlyExisting (0/1): ";
00732 cin >> ltmp;
00733 cin.get(junk);
00734 err = VDirSurrogate::createVolatileDirectory
00735 (arc, arc2, handle, src[nextSrcN], (bool)ltmp);
00736 if (err == VestaSource::ok) {
00737 newSrcN = nextSrcN++;
00738 cout << "src# = " << newSrcN << endl;
00739 } else {
00740 cout << "error " << VestaSource::errorCodeString(err) << endl;
00741 }
00742 break;
00743
00744 case 'D':
00745 srcN = readSrcN(nextSrcN);
00746 err = VDirSurrogate::deleteVolatileDirectory(src[srcN]);
00747 if (err != VestaSource::ok) {
00748 cout << "error " << VestaSource::errorCodeString(err) << endl;
00749 }
00750 break;
00751
00752 case 'c':
00753 cout << "pathname: ";
00754 cin.get(typein, sizeof(typein));
00755 cin.get(junk);
00756 cout << "asStub (0/1): ";
00757 cin >> ltmp;
00758 cin.get(junk);
00759 cout << "asGhost (0/1): ";
00760 cin >> tmp;
00761 cin.get(junk);
00762 cout << "dstHost: ";
00763 cin.get(arc, sizeof(arc));
00764 cin.get(junk);
00765 cout << "dstPort: ";
00766 cin.get(arc2, sizeof(arc2));
00767 cin.get(junk);
00768 cout << "srcHost: ";
00769 cin.get(arc3, sizeof(arc3));
00770 cin.get(junk);
00771 cout << "srcPort: ";
00772 cin.get(arc4, sizeof(arc4));
00773 cin.get(junk);
00774 err = VDirSurrogate::replicate(typein, (bool)ltmp, (bool)tmp,
00775 arc, arc2, arc3, arc4,
00776 PathnameSep, who, who);
00777 if (err != VestaSource::ok) {
00778 cout << "error " << VestaSource::errorCodeString(err) << endl;
00779 }
00780 break;
00781
00782 case 'C':
00783 cout << "pathname: ";
00784 cin.get(typein, sizeof(typein));
00785 cin.get(junk);
00786 cout << "includeAccess (0/1): ";
00787 cin >> ltmp;
00788 cin.get(junk);
00789 cout << "dstHost: ";
00790 cin.get(arc, sizeof(arc));
00791 cin.get(junk);
00792 cout << "dstPort: ";
00793 cin.get(arc2, sizeof(arc2));
00794 cin.get(junk);
00795 cout << "srcHost: ";
00796 cin.get(arc3, sizeof(arc3));
00797 cin.get(junk);
00798 cout << "srcPort: ";
00799 cin.get(arc4, sizeof(arc4));
00800 cin.get(junk);
00801 err = VDirSurrogate::replicateAttribs(typein, (bool)ltmp,
00802 arc, arc2, arc3, arc4,
00803 PathnameSep, who, who);
00804 if (err != VestaSource::ok) {
00805 cout << "error " << VestaSource::errorCodeString(err) << endl;
00806 }
00807 break;
00808
00809 case 'N':
00810 VDirSurrogate::getNFSInfo(charstar, longid, longid2);
00811 cout << "socket " << charstar << endl << "root ";
00812 coutLongId(longid);
00813 cout << endl << "muRoot ";
00814 coutLongId(longid2);
00815 cout << endl;
00816 delete charstar;
00817 break;
00818
00819 case 'S':
00820 #if 0
00821 who->aup_time = time(NULL);
00822 cout << "machine name: ";
00823 cin.get(who->aup_machname, MAX_MACHINE_NAME);
00824 cin.get(junk);
00825 cout << "uid: ";
00826 cin >> who->aup_uid;
00827 cin.get(junk);
00828 cout << "gid: ";
00829 cin >> who->aup_gid;
00830 cin.get(junk);
00831 cout << "# of gids: ";
00832 cin >> who->aup_len;
00833 cin.get(junk);
00834 for (i=0; i<who->aup_len; i++) {
00835 cin >> who->aup_gids[i];
00836 }
00837 cin.get(junk);
00838 print_identity(who);
00839 #else
00840 cout << "not reimplemented yet" << endl;
00841 #endif
00842 break;
00843
00844 case 'R':
00845 #if 0
00846 default_identity(who);
00847 print_identity(who);
00848 #else
00849 who = NULL;
00850 #endif
00851 break;
00852
00853 case 'f':
00854 srcN = readSrcN(nextSrcN);
00855 cout << "threshold: ";
00856 cin >> ltmp;
00857 cin.get(junk);
00858 err = src[srcN]->makeFilesImmutable(ltmp, who);
00859 if (err != VestaSource::ok) {
00860 cout << "error " << VestaSource::errorCodeString(err) << endl;
00861 }
00862 break;
00863
00864 case 'm':
00865 srcN = readSrcN(nextSrcN);
00866 cout << "master (0 or 1): ";
00867 cin >> master;
00868 cin.get(junk);
00869 err = src[srcN]->setMaster(master, who);
00870 if (err != VestaSource::ok) {
00871 cout << "error " << VestaSource::errorCodeString(err) << endl;
00872 }
00873 break;
00874
00875 case 'r':
00876 srcN = readSrcN(nextSrcN);
00877 cout << "nbytes: ";
00878 cin >> i;
00879 cout << "offset: ";
00880 cin >> ltmp;
00881 cin.get(junk);
00882 charstar = (char *) malloc(i);
00883 err = src[srcN]->read(charstar, &i, ltmp);
00884 if (err != VestaSource::ok) {
00885 cout << "error " << VestaSource::errorCodeString(err) << endl;
00886 } else {
00887 cout << "read " << i << " bytes\n";
00888 cout << "============================================\n";
00889 cout.write(charstar, i);
00890 cout << "============================================\n";
00891 }
00892 free(charstar);
00893 break;
00894
00895 case 'w':
00896 srcN = readSrcN(nextSrcN);
00897 cout << "nbytes: ";
00898 cin >> i;
00899 cout << "offset: ";
00900 cin >> ltmp;
00901 cin.get(junk);
00902 charstar = (char *) malloc(i);
00903 cout << "data: ";
00904 cin.get(charstar, i);
00905 cin.get(junk);
00906 err = src[srcN]->write(charstar, &i, ltmp);
00907 if (err != VestaSource::ok) {
00908 cout << "error " << VestaSource::errorCodeString(err) << endl;
00909 } else {
00910 cout << "wrote " << i << " bytes\n";
00911 }
00912 free(charstar);
00913 break;
00914
00915 case 'x':
00916 srcN = readSrcN(nextSrcN);
00917 cout << boolText[(int) src[srcN]->executable()] << endl;
00918 break;
00919
00920 case 'X':
00921 srcN = readSrcN(nextSrcN);
00922 cout << "executable (0 or 1): ";
00923 cin >> tmp;
00924 cin.get(junk);
00925 err = src[srcN]->setExecutable(tmp);
00926 if (err != VestaSource::ok) {
00927 cout << "error " << VestaSource::errorCodeString(err) << endl;
00928 }
00929 break;
00930
00931 case 'z':
00932 srcN = readSrcN(nextSrcN);
00933 cout << "size " << src[srcN]->size() << endl;
00934 break;
00935
00936 case 'Z':
00937 srcN = readSrcN(nextSrcN);
00938 cout << "size: ";
00939 cin >> ltmp;
00940 cin.get(junk);
00941 err = src[srcN]->setSize(ltmp);
00942 if (err != VestaSource::ok) {
00943 cout << "error " << VestaSource::errorCodeString(err) << endl;
00944 }
00945 break;
00946
00947 case '3':
00948 srcN = readSrcN(nextSrcN);
00949 cout << "timestamp " << src[srcN]->timestamp() <<endl;
00950 break;
00951
00952 case '4':
00953 srcN = readSrcN(nextSrcN);
00954 cout << "timestamp (decimal): ";
00955 cin >> tmp;
00956 cin.get(junk);
00957 err = src[srcN]->setTimestamp((time_t)tmp);
00958 if (err != VestaSource::ok) {
00959 cout << "error " << VestaSource::errorCodeString(err) << endl;
00960 }
00961 break;
00962
00963 case 'M':
00964 srcN = readSrcN(nextSrcN);
00965 {
00966 VestaSource::directoryStats stats;
00967 err = src[srcN]->measureDirectory(stats);
00968 if (err != VestaSource::ok)
00969 {
00970 cout << "error " << VestaSource::errorCodeString(err) << endl;
00971 }
00972 else
00973 {
00974 cout
00975 << "base chain length = " << stats.baseChainLength << endl
00976 << "used entry count = " << stats.usedEntryCount << endl
00977 << "total entry count = " << stats.totalEntryCount << endl
00978 << "used entry size = " << stats.usedEntrySize << endl
00979 << "total entry size = " << stats.totalEntrySize << endl;
00980 }
00981 }
00982 cout << endl;
00983 break;
00984
00985 case 'O':
00986 srcN = readSrcN(nextSrcN);
00987 err = src[srcN]->collapseBase();
00988 if (err != VestaSource::ok) {
00989 cout << "error " << VestaSource::errorCodeString(err) << endl;
00990 }
00991 break;
00992
00993 case 'W':
00994 srcN = readSrcN(nextSrcN);
00995
00996 src[srcN]->readWhole(cout);
00997 break;
00998
00999 case 'q':
01000 exit(0);
01001
01002 default:
01003 break;
01004 }
01005 }
01006
01007
01008 }
01009
01010 int
01011 main(int argc, char *argv[])
01012 {
01013 int c;
01014
01015
01016 try {
01017 (void) test_thread((void *)NULL);
01018 } catch (VestaConfig::failure f) {
01019 cerr << f.msg << endl;
01020 exit(2);
01021 } catch (SRPC::failure f) {
01022 cerr << f.msg << " (" << f.r << ")" << endl;
01023 exit(3);
01024 }
01025 return 0;
01026 }