int DLL_DECL Cns_delfilesbyguid(int nbguids, const char **guids, int force, int *nbstatuses, int **statuses) { int argtype = 0; int c; char func[19]; gid_t gid; int i; int msglen; char *q; char *rbp; char repbuf[4]; char *sbp; char *sendbuf; struct Cns_api_thread_info *thip; uid_t uid; strcpy (func, "Cns_delfilesbyguid"); if (Cns_apiinit (&thip)) return (-1); uid = geteuid(); gid = getegid(); #if defined(_WIN32) if (uid < 0 || gid < 0) { Cns_errmsg (func, NS053); serrno = SENOMAPFND; return (-1); } #endif if (nbguids <= 0) { serrno = EINVAL; return (-1); } if (! guids || ! nbstatuses || ! statuses) { serrno = EFAULT; return (-1); } /* Compute size of send buffer */ msglen = 5 * LONGSIZE; msglen += WORDSIZE; msglen += WORDSIZE; msglen += LONGSIZE; for (i = 0; i < nbguids; i++) { msglen += strlen (guids[i]) + 1; } /* Allocate send buffer */ if ((sendbuf = malloc (msglen)) == NULL) { serrno = ENOMEM; return (-1); } /* Build request header */ sbp = sendbuf; marshall_LONG (sbp, CNS_MAGIC); marshall_LONG (sbp, CNS_DELFILES); q = sbp; /* save pointer. The next field will be updated */ msglen = 3 * LONGSIZE; marshall_LONG (sbp, msglen); /* Build request body */ marshall_LONG (sbp, uid); marshall_LONG (sbp, gid); marshall_WORD (sbp, argtype); marshall_WORD (sbp, force); marshall_LONG (sbp, nbguids); for (i = 0; i < nbguids; i++) { marshall_STRING (sbp, guids[i]); } msglen = sbp - sendbuf; marshall_LONG (q, msglen); /* update length field */ c = send2nsdx (NULL, NULL, sendbuf, msglen, repbuf, sizeof(repbuf), (void **)statuses, nbstatuses); free (sendbuf); if (c == 0) { rbp = repbuf; unmarshall_LONG (rbp, *nbstatuses); if (*nbstatuses == 0) { *statuses = NULL; return (0); } } return (c); }
struct Cns_direnrep DLL_DECL * Cns_readdirxr(Cns_DIR *dirp, char *se) { int c; int direntsz; struct Cns_direnrep *dp; char func[16]; int getattr = 5; gid_t gid; int i; struct Cns_rep_info *ir; int msglen; int n; int nbentries; char *q; char *rbp; struct Cns_rep_info *rep_entries; char repbuf[DIRBUFSZ+4]; char *sbp; char sendbuf[REQBUFSZ]; uid_t uid; strcpy (func, "Cns_readdirxr"); uid = geteuid(); gid = getegid(); #if defined(_WIN32) if (uid < 0 || gid < 0) { Cns_errmsg (func, NS053); serrno = SENOMAPFND; return (NULL); } #endif if (! dirp) { serrno = EFAULT; return (NULL); } if (se && strlen (se) > CA_MAXHOSTNAMELEN) { serrno = EINVAL; return (NULL); } /* compute size of client machine Cns_direnrep structure excluding d_name */ dp = (struct Cns_direnrep *) dirp->dd_buf; direntsz = &dp->d_name[0] - (char *) dp; if (dirp->dd_size == 0) { /* no data in the cache */ if (dirp->replicas) { /* free previous replica information */ ir = (struct Cns_rep_info *) dirp->replicas; for (i = 0; i < dirp->nbreplicas; i++) { free (ir->host); free (ir->sfn); ir++; } free (dirp->replicas); dirp->nbreplicas = 0; dirp->replicas = NULL; } if (dirp->eod) return (NULL); /* Build request header */ sbp = sendbuf; marshall_LONG (sbp, CNS_MAGIC); marshall_LONG (sbp, CNS_READDIR); q = sbp; /* save pointer. The next field will be updated */ msglen = 3 * LONGSIZE; marshall_LONG (sbp, msglen); /* Build request body */ marshall_LONG (sbp, uid); marshall_LONG (sbp, gid); marshall_WORD (sbp, getattr); marshall_WORD (sbp, direntsz); marshall_HYPER (sbp, dirp->fileid); marshall_WORD (sbp, dirp->bod); if (se) { marshall_STRING (sbp, se); } else { marshall_STRING (sbp, ""); } msglen = sbp - sendbuf; marshall_LONG (q, msglen); /* update length field */ c = send2nsdx (&dirp->dd_fd, NULL, sendbuf, msglen, repbuf, sizeof(repbuf), (void **) &dirp->replicas, &dirp->nbreplicas); if (c < 0) return (NULL); rbp = repbuf; unmarshall_WORD (rbp, nbentries); if (nbentries == 0) return (NULL); /* end of directory */ /* unmarshall reply into the Cns_direnrep structures */ dp = (struct Cns_direnrep *) dirp->dd_buf; i = 0; rep_entries = (struct Cns_rep_info *) dirp->replicas; while (nbentries--) { unmarshall_HYPER (rbp, dp->fileid); unmarshall_STRING (rbp, dp->guid); unmarshall_WORD (rbp, dp->filemode); unmarshall_HYPER (rbp, dp->filesize); dp->nbreplicas = 0; dp->rep = NULL; for ( ; i < dirp->nbreplicas; i++) { if (dp->fileid != (rep_entries+i)->fileid) break; dp->nbreplicas++; if (dp->nbreplicas == 1) dp->rep = rep_entries + i; } unmarshall_STRING (rbp, dp->d_name); dp->d_reclen = ((direntsz + strlen (dp->d_name) + 8) / 8) * 8; dp = (struct Cns_direnrep *) ((char *) dp + dp->d_reclen); } dirp->bod = 0; unmarshall_WORD (rbp, dirp->eod); dirp->dd_size = (char *) dp - dirp->dd_buf; } dp = (struct Cns_direnrep *) (dirp->dd_buf + dirp->dd_loc); dirp->dd_loc += dp->d_reclen; if (dirp->dd_loc >= dirp->dd_size) { /* must refill next time */ dirp->dd_loc = 0; dirp->dd_size = 0; } return (dp); }
int DLL_DECL Cns_registerfiles(int nbfiles, struct Cns_filereg *files, int *nbstatuses, int **statuses) { int c; char func[18]; gid_t gid; int i; int msglen; char *q; char *rbp; char repbuf[4]; char *sbp; char *sendbuf; struct Cns_api_thread_info *thip; uid_t uid; strcpy (func, "Cns_registerfiles"); if (Cns_apiinit (&thip)) return (-1); uid = geteuid(); gid = getegid(); #if defined(_WIN32) if (uid < 0 || gid < 0) { Cns_errmsg (func, NS053); serrno = SENOMAPFND; return (-1); } #endif if (nbfiles <= 0) { serrno = EINVAL; return (-1); } if (! files || ! nbstatuses || ! statuses) { serrno = EFAULT; return (-1); } /* Compute size of send buffer */ msglen = 5 * LONGSIZE; msglen += WORDSIZE; msglen += HYPERSIZE; msglen += LONGSIZE; for (i = 0; i < nbfiles; i++) { msglen += strlen ((files+i)->lfn) + 1; if ((files+i)->guid) { msglen += strlen ((files+i)->guid) + 1; } else { msglen++; } msglen += LONGSIZE; msglen += HYPERSIZE; if ((files+i)->csumtype) { msglen += strlen ((files+i)->csumtype) + 1; } else { msglen++; } if ((files+i)->csumvalue) { msglen += strlen ((files+i)->csumvalue) + 1; } else { msglen++; } msglen += strlen ((files+i)->server) + 1; msglen += strlen ((files+i)->sfn) + 1; } /* Allocate send buffer */ if ((sendbuf = malloc (msglen)) == NULL) { serrno = ENOMEM; return (-1); } /* Build request header */ sbp = sendbuf; marshall_LONG (sbp, CNS_MAGIC); marshall_LONG (sbp, CNS_REGFILES); q = sbp; /* save pointer. The next field will be updated */ msglen = 3 * LONGSIZE; marshall_LONG (sbp, msglen); /* Build request body */ marshall_LONG (sbp, uid); marshall_LONG (sbp, gid); marshall_WORD (sbp, thip->mask); marshall_HYPER (sbp, thip->cwd); marshall_LONG (sbp, nbfiles); for (i = 0; i < nbfiles; i++) { marshall_STRING (sbp, (files+i)->lfn); if ((files+i)->guid) { marshall_STRING (sbp, (files+i)->guid); } else { marshall_STRING (sbp, ""); } marshall_LONG (sbp, (files+i)->mode); marshall_HYPER (sbp, (files+i)->size); if ((files+i)->guid) { marshall_STRING (sbp, (files+i)->csumtype); } else { marshall_STRING (sbp, ""); } if ((files+i)->guid) { marshall_STRING (sbp, (files+i)->csumvalue); } else { marshall_STRING (sbp, ""); } marshall_STRING (sbp, (files+i)->server); marshall_STRING (sbp, (files+i)->sfn); } msglen = sbp - sendbuf; marshall_LONG (q, msglen); /* update length field */ c = send2nsdx (NULL, NULL, sendbuf, msglen, repbuf, sizeof(repbuf), (void **)statuses, nbstatuses); free (sendbuf); if (c == 0) { rbp = repbuf; unmarshall_LONG (rbp, *nbstatuses); if (*nbstatuses == 0) { *statuses = NULL; return (0); } } return (c); }