Index: /branches/eam_branches/ipp-20111122/Ohana/src/photdbc/include/dvodist.h
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/photdbc/include/dvodist.h	(revision 33222)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/photdbc/include/dvodist.h	(revision 33223)
@@ -29,7 +29,6 @@
 
 // these should be moved to dvo.h?
-# define DATA_ON_TGT       0x4000
-# define DATA_COPY_FAILURE 0x8000
-# define DATA_HOST_ID      0x3fff
+# define DATA_ON_TGT       0x01
+# define DATA_COPY_FAILURE 0x02
 
 /* global variables */
@@ -44,4 +43,6 @@
 void          LockDatabase (char *catdir);
 HostTable    *HostTableLoad (char *catdir, char *rootname);
+int           CheckHostsAndPaths (HostTable *table);
+
 int           AssignSkyToHost (SkyList *skylist, HostTable *table);
 int           CopyToHostLocation (char *catdir, SkyList *skylist, HostTable *table);
Index: /branches/eam_branches/ipp-20111122/Ohana/src/photdbc/src/AssignSkyToHost.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/photdbc/src/AssignSkyToHost.c	(revision 33222)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/photdbc/src/AssignSkyToHost.c	(revision 33223)
@@ -18,5 +18,5 @@
     // XXX some options;
 # if (0)
-    if (CLEAR_ERRORS && (skylist->regions[i]->hostID & DATA_COPY_FAILURE)) {
+    if (CLEAR_ERRORS && (skylist->regions[i]->hostFlags & DATA_COPY_FAILURE)) {
       skylist->regions[i]->hostID = 0;
     }
@@ -30,6 +30,9 @@
 
     // assign all regions to one of the Nhost hosts
-    int N = MAX(table->Nhosts - 1, table->Nhosts * drand48());
+    float f = drand48();
+    float n = table->Nhosts * f;
+    int N = MIN(table->Nhosts - 1, n);
     skylist->regions[i]->hostID = table->hosts[N].hostID;
+    // fprintf  (stderr, "%f  %f  %d  %d\n", f, n, N, skylist->regions[i]->hostID);
   }    
 
Index: /branches/eam_branches/ipp-20111122/Ohana/src/photdbc/src/CopyFromHostLocation.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/photdbc/src/CopyFromHostLocation.c	(revision 33222)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/photdbc/src/CopyFromHostLocation.c	(revision 33223)
@@ -29,11 +29,11 @@
 
     // skip catalogs which have not been copied back
-    if (skylist->regions[i]->hostID & DATA_ON_TGT) continue;
+    if (skylist->regions[i]->hostFlags & DATA_ON_TGT) continue;
 
     // skip catalogs which have an uncleared error
-    if (skylist->regions[i]->hostID & DATA_COPY_FAILURE) continue;
+    if (skylist->regions[i]->hostFlags & DATA_COPY_FAILURE) continue;
 
     // find the host for the table
-    int realID = (skylist->regions[i]->hostID & DATA_HOST_ID);
+    int realID = skylist->regions[i]->hostID;
     short index = table->index[realID];
     HostInfo *host = &table->hosts[index];
@@ -111,5 +111,5 @@
       // if we failed to make a copy, 
 	  
-      skylist->regions[i]->hostID |= DATA_COPY_FAILURE;
+      skylist->regions[i]->hostFlags |= DATA_COPY_FAILURE;
       for (j = 0; success && (j < 4); j++) {
 	sprintf (tgtname, "%s/%s.%s", catdir, skylist->regions[i]->name, extname[j]);
@@ -118,5 +118,5 @@
       Nfailure ++;
     } else {
-      skylist->regions[i]->hostID &= ~DATA_ON_TGT;
+      skylist->regions[i]->hostFlags &= ~DATA_ON_TGT;
       for (j = 0; success && (j < 4); j++) {
 	sprintf (srcname, "%s/%s.%s", host->pathname, skylist->regions[i]->name, extname[j]);
Index: /branches/eam_branches/ipp-20111122/Ohana/src/photdbc/src/CopyToHostLocation.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/photdbc/src/CopyToHostLocation.c	(revision 33222)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/photdbc/src/CopyToHostLocation.c	(revision 33223)
@@ -12,4 +12,5 @@
   char srcname[1024];
   char tgtname[1024];
+  char outdir[1024];
 
   md5_byte_t srcDigest[NDIGEST];
@@ -29,11 +30,11 @@
 
     // skip catalogs which have already been copied
-    if (skylist->regions[i]->hostID & DATA_ON_TGT) continue;
+    if (skylist->regions[i]->hostFlags & DATA_ON_TGT) continue;
 
     // skip catalogs which have an uncleared error
-    if (skylist->regions[i]->hostID & DATA_COPY_FAILURE) continue;
+    if (skylist->regions[i]->hostFlags & DATA_COPY_FAILURE) continue;
 
     // find the host for the table
-    int realID = (skylist->regions[i]->hostID & DATA_HOST_ID);
+    int realID = skylist->regions[i]->hostID;
     short index = table->index[realID];
     HostInfo *host = &table->hosts[index];
@@ -41,4 +42,14 @@
     // have to succeed on all 4 tables; if we fail on any one, 
     int success = TRUE;
+
+    char *subdir = pathname (skylist->regions[i]->name);
+    sprintf (outdir, "%s/%s", host->pathname, subdir);
+    free (subdir);
+
+    int status = check_dir_access (outdir, DEBUG);
+    if (!status) {
+      fprintf (stderr, "failed to find / create target path\n");
+      exit (2);
+    }
 
     char extname[4][16] = {"cpm", "cpt", "cps", "cpn"};
@@ -52,6 +63,6 @@
 
       // check permission to read file 
-      int status = stat (srcname, &filestat);
-      if (!status) {
+      status = stat (srcname, &filestat);
+      if (status) {
 	if (errno == ENOENT) continue;  // file does not exist (handle broken table with cpt + cpm but no cpn,cps?)
 	perror ("stat:");
@@ -111,5 +122,5 @@
       // if we failed to make a copy, 
 	  
-      skylist->regions[i]->hostID |= DATA_COPY_FAILURE;
+      skylist->regions[i]->hostFlags |= DATA_COPY_FAILURE;
       for (j = 0; success && (j < 4); j++) {
 	sprintf (tgtname, "%s/%s.%s", host->pathname, skylist->regions[i]->name, extname[j]);
@@ -118,5 +129,5 @@
       Nfailure ++;
     } else {
-      skylist->regions[i]->hostID |= DATA_ON_TGT;
+      skylist->regions[i]->hostFlags |= DATA_ON_TGT;
       for (j = 0; success && (j < 4); j++) {
 	sprintf (srcname, "%s/%s.%s", catdir, skylist->regions[i]->name, extname[j]);
Index: /branches/eam_branches/ipp-20111122/Ohana/src/photdbc/src/HostTableLoad.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/photdbc/src/HostTableLoad.c	(revision 33222)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/photdbc/src/HostTableLoad.c	(revision 33223)
@@ -75,5 +75,5 @@
       exit (1);
     }
-    if (ID > 65535) {
+    if (ID > 255) {
       fprintf (stderr, "invalid host ID %d\n", ID);
       exit (1);
Index: /branches/eam_branches/ipp-20111122/Ohana/src/photdbc/src/dvodist.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/photdbc/src/dvodist.c	(revision 33222)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/photdbc/src/dvodist.c	(revision 33223)
@@ -15,5 +15,5 @@
   char *catdir = strcreate (argv[1]);
 
-  LockDatabase (catdir);
+  // LockDatabase (catdir);
   
   // load the current SkyTable. If SkyTable does not exist, we must fail
@@ -26,4 +26,6 @@
     Shutdown ("failed to load Host Table %s for %s\n", catdir, sky->hosts);
   }
+
+  CheckHostsAndPaths(hosts);
 
   switch (MODE) {
Index: /branches/eam_branches/ipp-20111122/Ohana/src/photdbc/src/initialize_dvodist.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/photdbc/src/initialize_dvodist.c	(revision 33222)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/photdbc/src/initialize_dvodist.c	(revision 33223)
@@ -66,5 +66,5 @@
   }
   if ((N = get_argument (argc, argv, "-out"))) {
-    if (!MODE) {
+    if (MODE) {
       fprintf (stderr, "ERROR: cannot use both -in and -out options!\n");
       usage();
Index: /branches/eam_branches/ipp-20111122/Ohana/src/photdbc/src/md5_ops.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/photdbc/src/md5_ops.c	(revision 33222)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/photdbc/src/md5_ops.c	(revision 33223)
@@ -28,6 +28,5 @@
     md5_append (&state, buffer, nbytes);
     if (output) {
-      int nbytesOut = write (fdOutput, buffer, NBUFFER);
-      // XXX check that we actually write out all nbytes...
+      int nbytesOut = write (fdOutput, buffer, nbytes);
       if (nbytesOut != nbytes) {
 	return FALSE;
@@ -36,4 +35,12 @@
   }
   md5_finish (&state, digest);
+
+# if (0)
+  int i;
+  for (i = 0; i < NDIGEST; i++) {
+    fprintf (stderr, "%02x", digest[i]);
+  }
+  fprintf (stderr, " : %s\n", input);
+# endif
 	
   fclose (fInput);
