1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
/*
* Copyright (C) 2005-2010 by CERN/IT/GD/SC
* All rights reserved
*/
#ifndef lint
static char sccsid[] = "@(#)$RCSfile: dpm_getspacemd.c,v $ $Revision: 3444 $ $Date: 2010-02-24 08:53:25 +0100 (Wed, 24 Feb 2010) $ CERN IT-GD/SC Jean-Philippe Baud";
#endif /* not lint */
/* dpm_getspacemd - get space metadata */
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#if defined(_WIN32)
#include <winsock2.h>
#else
#include <unistd.h>
#include <netinet/in.h>
#endif
#include "dpm_api.h"
#include "dpm.h"
#include "marshall.h"
#include "serrno.h"
int DLL_DECL
dpm_getspacemd (int nbtokens, char **s_tokens, int *nbreplies, struct dpm_space_metadata **spacemd)
{
int c;
char errstring[256];
char func[16];
gid_t gid;
int i;
int msglen;
char *rbp;
char repbuf[4+256];
char *sbp;
char *sendbuf;
struct dpm_api_thread_info *thip;
uid_t uid;
strcpy (func, "dpm_getspacemd");
if (dpm_apiinit (&thip))
return (-1);
uid = geteuid();
gid = getegid();
#if defined(_WIN32)
if (uid < 0 || gid < 0) {
dpm_errmsg (func, DP053);
serrno = SENOMAPFND;
return (-1);
}
#endif
if (nbtokens <= 0) {
serrno = EINVAL;
return (-1);
}
if (! s_tokens || ! nbreplies || ! spacemd) {
serrno = EFAULT;
return (-1);
}
/* Compute size of send buffer */
msglen = 6 * LONGSIZE;
for (i = 0; i < nbtokens; i++) {
msglen += strlen (s_tokens[i]) + 1;
}
/* Allocate send buffer */
if ((sendbuf = malloc (msglen)) == NULL) {
serrno = ENOMEM;
return (-1);
}
/* Build request header */
sbp = sendbuf;
marshall_LONG (sbp, DPM_MAGIC3);
marshall_LONG (sbp, DPM_GETSPACEMD);
marshall_LONG (sbp, msglen);
/* Build request body */
marshall_LONG (sbp, uid);
marshall_LONG (sbp, gid);
marshall_LONG (sbp, nbtokens);
for (i = 0; i < nbtokens; i++) {
marshall_STRING (sbp, s_tokens[i]);
}
c = send2dpm (NULL, sendbuf, msglen, repbuf, sizeof(repbuf),
(void **)spacemd, nbreplies);
free (sendbuf);
if (c == 0) {
rbp = repbuf;
unmarshall_LONG (rbp, c);
if (c) {
serrno = c - DPM_FAILED;
c = -1;
}
unmarshall_STRING (rbp, errstring);
if (*errstring)
dpm_errmsg (func, "%s\n", errstring);
}
return (c);
}
|