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 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754
|
/*
* $Id: mstat.c,v 1.4 2007/12/04 11:25:43 dhsmith Exp $
*/
/*
* Copyright (C) 1995-2005 by CERN/IT/PDP/DM
* All rights reserved
*/
#ifndef lint
static char sccsid[] = "@(#)$RCSfile: mstat.c,v $ $Revision: 1.4 $ $Date: 2007/12/04 11:25:43 $ CERN/IT/PDP/DM Felix Hassine";
#endif /* not lint */
#include "Cmutex.h"
#include "Castor_limits.h"
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <osdep.h>
#include "log.h"
#define RFIO_KERNEL 1
#include "rfio.h"
#include <Cglobals.h>
#include <Cpwd.h>
#include <net.h>
typedef struct socks {
char host[CA_MAXHOSTNAMELEN+1];
int s ;
int Tid;
} mstat_connects ;
static mstat_connects mstat_tab[MAXMCON]; /* UP TO MAXMCON connections simultaneously */
EXTERN_C int DLL_DECL rfio_smstat _PROTO((int, char *, struct stat *, int));
static int rfio_mstat_allocentry _PROTO((char *, int, int));
static int rfio_mstat_findentry _PROTO((char *,int));
static int rfio_end_this _PROTO((int,int));
extern int rfio_newhost _PROTO((char *));
int DLL_DECL rfio_mstat(file,statb)
char *file ;
struct stat *statb;
{
#if (defined(__alpha) && defined(__osf__))
return (rfio_mstat64(file,statb));
#else
int rc, parserc ;
#if defined(IRIX64) || defined(__ia64__) || defined(__x86_64) || defined(__ppc64__)
struct stat64 statb64;
if ((rc = rfio_mstat64(file,&statb64)) == 0)
(void) stat64tostat(&statb64, statb);
return (rc);
#else
int rt ,i ,fd, rfindex, Tid;
char *host , *filename ;
INIT_TRACE("RFIO_TRACE");
Cglobals_getTid(&Tid);
TRACE(1, "rfio", "rfio_mstat(%s, %x), Tid=%d", file, statb, Tid);
if (!(parserc = rfio_parseln(file,&host,&filename,NORDLINKS))) {
/* if not a remote file, must be local or HSM */
if ( host != NULL ) {
/*
* HSM file
*/
rfio_errno = 0;
rc = rfio_HsmIf_stat(filename,statb);
END_TRACE();
return(rc);
}
/* The file is local */
rc = stat(filename,statb) ;
if ( rc < 0 ) serrno = 0;
rfio_errno = 0;
END_TRACE();
return (rc) ;
} else {
if (parserc < 0) {
END_TRACE();
return(-1);
}
/* Look if already in */
serrno = 0;
rfindex = rfio_mstat_findentry(host,Tid);
TRACE(2, "rfio", "rfio_mstat: rfio_mstat_findentry(host=%s,Tid=%d) returns %d", host, Tid, rfindex);
if (rfindex >= 0) {
rc = rfio_smstat(mstat_tab[rfindex].s,filename,statb,RQST_MSTAT_SEC ) ;
END_TRACE();
return (rc) ;
}
/*
* Open a connection
*/
rfio_errno = 0;
fd=rfio_connect(host,&rt) ;
if ( fd < 0 ) {
END_TRACE();
return (-1) ;
}
rfindex = rfio_mstat_allocentry(host,Tid,fd);
TRACE(2, "rfio", "rfio_mstat: rfio_mstat_allocentry(host=%s,Tid=%d,s=%d) returns %d", host, Tid, fd, rfindex);
serrno = 0;
rc = rfio_smstat(fd,filename,statb,RQST_MSTAT_SEC);
if ( rfindex < 0 ) {
if ( (rc != -1) || (rc == -1 && rfio_errno != 0) ) {
TRACE(2,"rfio","rfio_mstat() overflow connect table, host=%s, Tid=%d. Closing %d",host,Tid,fd);
netclose(fd);
}
}
END_TRACE();
return (rc) ;
}
#endif
#endif
}
/*
* Simplest operation in stat() : just do a stat()
* for 1 filename
*/
static int pw_key = -1;
static int old_uid_key = -1;
int DLL_DECL rfio_smstat(s,filename,statbuf,reqst)
int s ;
char * filename ;
struct stat *statbuf ;
int reqst ;
{
char buf[BUFSIZ];
int status; /* remote fopen() status */
int len;
int rc;
int save_errno, save_serrno;
char *p=buf;
int uid;
int gid;
int *old_uid = NULL;
struct passwd *pw_tmp;
struct passwd *pw = NULL;
/* Avoiding Valgrind error messages about uninitialized data */
memset(buf, 0, BUFSIZ);
INIT_TRACE("RFIO_TRACE");
TRACE(1, "rfio", "rfio_stat(%s, %x)", filename, statbuf);
if ( Cglobals_get(&old_uid_key, (void**)&old_uid, sizeof(int)) > 0 )
*old_uid = -1;
Cglobals_get(&pw_key, (void**)&pw, sizeof(struct passwd));
len = strlen(filename)+1;
if (reqst != RQST_MSTAT_SEC && reqst != RQST_STAT_SEC) {
END_TRACE();
return (-1) ;
}
TRACE(2,"rfio","rfio_stat: preparing stat() request");
marshall_WORD(p, B_RFIO_MAGIC);
uid = geteuid() ;
gid = getegid () ;
if ( uid != *old_uid ) {
TRACE(2,"rfio","rfio_stat: uid=%d != *old_uid=%d\n", (int) uid, (int) *old_uid);
pw_tmp = Cgetpwuid(uid);
if( pw_tmp == NULL ) {
TRACE(2, "rfio" ,"rfio_stat: Cgetpwuid(): ERROR occured (errno=%d)",errno);
rfio_end_this(s,1);
END_TRACE();
return(-1);
}
memcpy(pw, pw_tmp, sizeof(struct passwd));
*old_uid = uid;
}
marshall_WORD(p, reqst);
len+=2*WORDSIZE + strlen(pw->pw_name) + 1;
if ( len > BUFSIZ ) {
TRACE(2,"rfio","rfio_stat: request too long %d (max %d)",len,BUFSIZ);
END_TRACE();
serrno = E2BIG;
return(-1);
}
marshall_LONG(p, len);
p= buf + RQSTSIZE;
TRACE(2,"rfio","rfio_stat: using (uid=%d,gid=%d)\n",(int) uid, (int) gid);
marshall_WORD(p, uid);
marshall_WORD(p, gid);
marshall_STRING(p,pw->pw_name);
marshall_STRING(p, filename);
TRACE(2,"rfio","rfio_stat: sending %d bytes",RQSTSIZE+len) ;
if (netwrite_timeout(s,buf,RQSTSIZE+len,RFIO_CTRL_TIMEOUT) != (RQSTSIZE+len)) {
TRACE(2, "rfio", "rfio_stat: write(): ERROR occured (errno=%d)", errno);
rfio_end_this(s,0);
END_TRACE();
return(-1);
}
p = buf;
TRACE(2, "rfio", "rfio_stat: reading %d bytes", 8*LONGSIZE+5*WORDSIZE);
rc = netread_timeout(s, buf, 8*LONGSIZE+5*WORDSIZE, RFIO_CTRL_TIMEOUT);
if (rc != 8*LONGSIZE+5*WORDSIZE) {
save_errno = errno, save_serrno = serrno;
#if !defined(_WIN32)
if (rc == 0 || (rc<0 && errno == ECONNRESET))
#else
if (rc == 0 || (rc<0 && serrno == SETIMEDOUT))
#endif
TRACE(2, "rfio", "rfio_stat: The connection with the server has been broken");
else
TRACE(2, "rfio", "rfio_stat: read(): ERROR occured (errno=%d)", errno);
rfio_end_this(s, (rc <= 0 ? 0 : 1));
END_TRACE();
errno = save_errno; serrno = save_serrno;
return(-1);
}
unmarshall_WORD(p, statbuf->st_dev);
unmarshall_LONG(p, statbuf->st_ino);
unmarshall_WORD(p, statbuf->st_mode);
unmarshall_WORD(p, statbuf->st_nlink);
unmarshall_WORD(p, statbuf->st_uid);
unmarshall_WORD(p, statbuf->st_gid);
unmarshall_LONG(p, statbuf->st_size);
unmarshall_LONG(p, statbuf->st_atime);
unmarshall_LONG(p, statbuf->st_mtime);
unmarshall_LONG(p, statbuf->st_ctime);
unmarshall_LONG(p, status);
/*
* Inserted here to preserve
* backward compatibility with
* former stat () protocol
*/
#if !defined(_WIN32)
unmarshall_LONG(p, statbuf->st_blksize);
unmarshall_LONG(p, statbuf->st_blocks);
#endif
TRACE(1, "rfio", "rfio_stat: return %d",status);
rfio_errno = status;
if (status) {
END_TRACE();
return(-1);
}
END_TRACE();
return(0);
}
int DLL_DECL rfio_end()
{
int i,Tid, j=0 ;
char buf[RQSTSIZE];
char *p=buf ;
int rc = 0;
/* Avoiding Valgrind error messages about uninitialized data */
memset(buf, 0, RQSTSIZE);
INIT_TRACE("RFIO_TRACE");
Cglobals_getTid(&Tid);
TRACE(3,"rfio","rfio_end entered, Tid=%d", Tid);
TRACE(3,"rfio","rfio_end: Lock mstat_tab");
if (Cmutex_lock((void *) mstat_tab,-1) != 0) {
TRACE(3,"rfio","rfio_end: Cmutex_lock(mstat_tab,-1) error No %d (%s)", errno, strerror(errno));
END_TRACE();
return(-1);
}
for (i = 0; i < MAXMCON; i++) {
if (mstat_tab[i].Tid == Tid) {
if ((mstat_tab[i].s >= 0) && (mstat_tab[i].host[0] != '\0')) {
p = buf;
marshall_WORD(p, RFIO_MAGIC);
marshall_WORD(p, RQST_END);
marshall_LONG(p, j);
TRACE(3,"rfio","rfio_end: close(mstat_tab[%d].s=%d), host=%s, Tid=%d",i,mstat_tab[i].s, mstat_tab[i].host, Tid);
if (netwrite_timeout(mstat_tab[i].s,buf,RQSTSIZE,RFIO_CTRL_TIMEOUT) != RQSTSIZE) {
TRACE(3, "rfio", "rfio_end: netwrite_timeout(): ERROR occured (errno=%d), Tid=%d", errno, Tid);
rc = -1;
}
netclose(mstat_tab[i].s);
}
mstat_tab[i].s = -1;
mstat_tab[i].host[0] = '\0';
mstat_tab[i].Tid = -1;
}
}
TRACE(3,"rfio","rfio_end: Unlock mstat_tab");
if (Cmutex_unlock((void *) mstat_tab) != 0) {
TRACE(3,"rfio","rfio_end: Cmutex_unlock(mstat_tab) error No %d (%s)", errno, strerror(errno));
rc = -1;
}
END_TRACE();
return(rc);
}
/* This is a simplified version of rfio_end() that just free entry in the table */
/* If flag is set a clean close is tried (write on the socket) */
static int rfio_end_this(s,flag)
int s;
int flag;
{
int i,Tid, j=0 ;
char buf[RQSTSIZE];
int found = 0;
char *p=buf ;
int rc = 0;
/* Avoiding Valgrind error messages about uninitialized data */
memset(buf, 0, RQSTSIZE);
Cglobals_getTid(&Tid);
TRACE(3,"rfio","rfio_end_this(s=%d,flag=%d) entered, Tid=%d", s, flag, Tid);
TRACE(3,"rfio","rfio_end: Lock mstat_tab");
if (Cmutex_lock((void *) mstat_tab,-1) != 0) {
TRACE(3,"rfio","rfio_end_this: Cmutex_lock(mstat_tab,-1) error No %d (%s)", errno, strerror(errno));
return(-1);
}
for (i = 0; i < MAXMCON; i++) {
if (mstat_tab[i].Tid == Tid) {
if ((mstat_tab[i].s == s) && (mstat_tab[i].host[0] != '\0')) {
found++;
if (flag) {
marshall_WORD(p, RFIO_MAGIC);
marshall_WORD(p, RQST_END);
marshall_LONG(p, j);
TRACE(3,"rfio","rfio_end_this: close(mstat_tab[%d].s=%d), host=%s, Tid=%d",i,mstat_tab[i].s, mstat_tab[i].host, Tid);
if (netwrite_timeout(mstat_tab[i].s,buf,RQSTSIZE,RFIO_CTRL_TIMEOUT) != RQSTSIZE) {
TRACE(3, "rfio", "rfio_end_this: netwrite_timeout(): ERROR occured (errno=%d), Tid=%d", errno, Tid);
}
}
netclose(mstat_tab[i].s);
mstat_tab[i].s = -1;
mstat_tab[i].host[0] = '\0';
mstat_tab[i].Tid = -1;
}
}
}
if (! found) netclose(s);
TRACE(3,"rfio","rfio_end: Unlock mstat_tab");
if (Cmutex_unlock((void *) mstat_tab) != 0) {
TRACE(3,"rfio","rfio_end_this: Cmutex_unlock(mstat_tab) error No %d (%s)", errno, strerror(errno));
rc = -1;
}
return(rc);
}
/*
* Seach for a free index in the mstat_tab table
*/
static int rfio_mstat_allocentry(hostname,Tid,s)
char *hostname;
int Tid;
int s;
{
int i;
int rc;
TRACE(3,"rfio","rfio_mstat_allocentry entered, Tid=%d", Tid);
TRACE(3,"rfio","rfio_mstat_allocentry: Lock mstat_tab");
if (Cmutex_lock((void *) mstat_tab,-1) != 0) {
TRACE(3,"rfio","rfio_mstat_allocentry: Cmutex_lock(mstat_tab,-1) error No %d (%s)", errno, strerror(errno));
return(-1);
}
/* Scan it */
for (i = 0; i < MAXMCON; i++) {
if (mstat_tab[i].host[0] == '\0') {
rc = i;
strncpy(mstat_tab[i].host,hostname,CA_MAXHOSTNAMELEN);
mstat_tab[i].host[CA_MAXHOSTNAMELEN] = '\0';
mstat_tab[i].Tid = Tid;
mstat_tab[i].s = s;
goto _rfio_mstat_allocentry_return;
}
}
serrno = ENOENT;
rc = -1;
_rfio_mstat_allocentry_return:
TRACE(3,"rfio","rfio_mstat_allocentry: Unlock mstat_tab");
if (Cmutex_unlock((void *) mstat_tab) != 0) {
TRACE(3,"rfio","rfio_mstat_allocentry: Cmutex_unlock(mstat_tab) error No %d (%s)", errno, strerror(errno));
return(-1);
}
return(rc);
}
/*
* Seach for a given index in the mstat_tab table
*/
static int rfio_mstat_findentry(hostname,Tid)
char *hostname;
int Tid;
{
int i;
int rc;
TRACE(3,"rfio","rfio_mstat_findentry entered, Tid=%d", Tid);
TRACE(3,"rfio","rfio_mstat_findentry: Lock mstat_tab");
if (Cmutex_lock((void *) mstat_tab,-1) != 0) {
TRACE(3,"rfio","rfio_mstat_findentry: Cmutex_lock(mstat_tab,-1) error No %d (%s)", errno, strerror(errno));
return(-1);
}
/* Scan it */
for (i = 0; i < MAXMCON; i++) {
if ((strcmp(mstat_tab[i].host,hostname) == 0) && (mstat_tab[i].Tid == Tid)) {
rc = i;
/* Lie to rfio_lasthost() */
rfio_newhost(hostname);
goto _rfio_mstat_findentry_return;
}
}
serrno = ENOENT;
rc = -1;
_rfio_mstat_findentry_return:
TRACE(3,"rfio","rfio_mstat_findentry: Unlock mstat_tab");
if (Cmutex_unlock((void *) mstat_tab) != 0) {
TRACE(3,"rfio","rfio_mstat_findentry: Cmutex_unlock(mstat_tab) error No %d (%s)", errno, strerror(errno));
return(-1);
}
return(rc);
}
int DLL_DECL rfio_mstat_reset()
{
int i,Tid;
int rc = 0;
INIT_TRACE("RFIO_TRACE");
Cglobals_getTid(&Tid);
TRACE(3,"rfio","rfio_mstat_reset entered, Tid=%d", Tid);
TRACE(3,"rfio","rfio_mstat_reset: Lock mstat_tab");
if (Cmutex_lock((void *) mstat_tab,-1) != 0) {
TRACE(3,"rfio","rfio_mstat_reset: Cmutex_lock(mstat_tab,-1) error No %d (%s)", errno, strerror(errno));
END_TRACE();
return(-1);
}
for (i = 0; i < MAXMCON; i++) {
if ((mstat_tab[i].s >= 0) && (mstat_tab[i].host[0] != '\0')) {
TRACE(3,"rfio","rfio_mstat_reset: Resetting socket fd=%d, host=%s\n", mstat_tab[i].s, mstat_tab[i].host);
netclose(mstat_tab[i].s);
}
mstat_tab[i].s = -1;
mstat_tab[i].host[0] = '\0';
mstat_tab[i].Tid = -1;
}
TRACE(3,"rfio","rfio_mstat_reset: Unlock mstat_tab");
if (Cmutex_unlock((void *) mstat_tab) != 0) {
TRACE(3,"rfio","rfio_mstat_reset: Cmutex_unlock(mstat_tab) error No %d (%s)", errno, strerror(errno));
rc = -1;
}
END_TRACE();
return(rc);
}
int DLL_DECL rfio_mstat64(file,statb)
char *file ;
struct stat64 *statb;
{
int rt ,rc ,i ,fd, rfindex, Tid;
char *host , *filename ;
int fitreqst; /*Fitted request */
int parserc;
INIT_TRACE("RFIO_TRACE");
Cglobals_getTid(&Tid);
TRACE(1, "rfio", "rfio_mstat64(%s, %x), Tid=%d", file, statb, Tid);
if (!(parserc = rfio_parseln(file,&host,&filename,NORDLINKS))) {
/* if not a remote file, must be local or HSM */
if ( host != NULL ) {
/*
* HSM file
*/
rfio_errno = 0;
rc = rfio_HsmIf_stat64(filename,statb);
END_TRACE();
return(rc);
}
/* The file is local */
rc = stat64(filename, statb) ;
if ( rc < 0 ) serrno = 0;
rfio_errno = 0;
END_TRACE();
return (rc) ;
} else {
if (parserc < 0) {
END_TRACE();
return(-1);
}
/* Look if already in */
serrno = 0;
rfindex = rfio_mstat_findentry(host,Tid);
TRACE(2, "rfio", "rfio_mstat64: rfio_mstat_findentry(host=%s,Tid=%d) returns %d", host, Tid, rfindex);
if (rfindex >= 0) {
rc = rfio_smstat64( mstat_tab[rfindex].s, filename, statb, RQST_MSTAT64 ) ;
END_TRACE();
return (rc) ;
}
/*
* Open a connection
*/
rfio_errno = 0;
fd = rfio_connect(host,&rt) ;
if ( fd < 0 ) {
END_TRACE();
return (-1) ;
}
rfindex = rfio_mstat_allocentry(host,Tid,fd);
TRACE(2, "rfio", "rfio_mstat64: rfio_mstat_allocentry(host=%s,Tid=%d,s=%d) returns %d", host, Tid, fd, rfindex);
serrno = 0;
rc = rfio_smstat64(fd, filename, statb, RQST_MSTAT64);
if (rfindex<0) {
if ( (rc != -1) || (rc == -1 && rfio_errno != 0) ) {
TRACE(2,"rfio","rfio_mstat() overflow connect table, Tid=%d. Closing %d",Tid,fd);
netclose(fd);
}
}
END_TRACE();
return (rc) ;
}
}
/* Do the remote stat64() and lstat64() */
int DLL_DECL rfio_smstat64(s,filename,statbuf,reqst)
int s ;
char * filename ;
struct stat64 *statbuf ;
int reqst ;
{
char buf[BUFSIZ];
int status; /* remote fopen() status */
int len;
int replen;
int rc;
int save_errno, save_serrno;
char *p=buf;
int uid;
int gid;
int m64;
int *old_uid = NULL;
long i32 ;
struct passwd *pw_tmp;
struct passwd *pw = NULL;
/* Avoiding Valgrind error messages about uninitialized data */
memset(buf, 0, BUFSIZ);
INIT_TRACE("RFIO_TRACE");
TRACE(1, "rfio", "rfio_smstat64(%s, %x)", filename, statbuf);
if ( Cglobals_get(&old_uid_key, (void**)&old_uid, sizeof(int)) > 0 )
*old_uid = -1;
Cglobals_get(&pw_key, (void**)&pw, sizeof(struct passwd));
len = strlen(filename)+1;
switch ( reqst ) {
case RQST_MSTAT64:
case RQST_STAT64:
case RQST_LSTAT64:
TRACE(2,"rfio","rfio_smstat64: trying (l)stat64()");
m64 = 1;
break;
case RQST_MSTAT_SEC:
case RQST_STAT_SEC:
case RQST_LSTAT_SEC:
TRACE(2,"rfio","rfio_smstat64: trying secure (l)stat()");
m64 = 0;
break;
default:
TRACE(2,"rfio","rfio_smstat64: Invalid request %x", reqst);
END_TRACE();
return (-1) ;
}
if (!m64) {
marshall_WORD(p, B_RFIO_MAGIC);
}
else {
marshall_WORD(p, RFIO_MAGIC);
}
marshall_WORD(p, reqst);
uid = geteuid() ;
gid = getegid () ;
if ( uid != *old_uid ) {
TRACE(2,"rfio","rfio_smstat64: uid=%d != *old_uid=%d\n", (int) uid, (int) *old_uid);
pw_tmp = Cgetpwuid(uid);
if( pw_tmp == NULL ) {
TRACE(2, "rfio" ,"rfio_smstat64: Cgetpwuid(): ERROR occured (errno=%d)", errno);
rfio_end_this(s,1);
END_TRACE();
return(-1);
}
memcpy(pw, pw_tmp, sizeof(struct passwd));
*old_uid = uid;
}
len += 2*WORDSIZE + strlen(pw->pw_name) + 1;
if ( len > BUFSIZ ) {
TRACE(2,"rfio","rfio_smstat64: request too long %d (max %d)",len,BUFSIZ);
rfio_end_this(s,0);
END_TRACE();
serrno = E2BIG;
return(-1);
}
marshall_LONG(p, len);
p= buf + RQSTSIZE;
TRACE(2,"rfio","rfio_smstat64: using (uid=%d,gid=%d)\n",(int) uid, (int) gid);
marshall_WORD(p, uid);
marshall_WORD(p, gid);
marshall_STRING(p,pw->pw_name);
marshall_STRING(p, filename);
TRACE(2,"rfio","rfio_smstat64: sending %d bytes", RQSTSIZE+len) ;
if (netwrite_timeout(s,buf,RQSTSIZE+len,RFIO_CTRL_TIMEOUT) != (RQSTSIZE+len)) {
TRACE(2, "rfio", "rfio_smstat64: write(): ERROR occured (errno=%d)", errno);
rfio_end_this(s,0);
END_TRACE();
return(-1);
}
p = buf;
if ( m64 )
replen = 3*HYPERSIZE+5*LONGSIZE+5*WORDSIZE;
else {
if (reqst == RQST_LSTAT_SEC)
replen = 6*LONGSIZE+5*WORDSIZE;
else
replen = 8*LONGSIZE+5*WORDSIZE;
}
TRACE(2, "rfio", "rfio_smstat64: reading %d bytes", replen);
rc = netread_timeout(s, buf, replen, RFIO_CTRL_TIMEOUT);
if ( rc != replen) {
save_errno = errno; save_serrno = serrno;
#if !defined(_WIN32)
if (rc == 0 || (rc<0 && errno == ECONNRESET))
#else
if (rc == 0 || (rc<0 && serrno == SETIMEDOUT))
#endif
TRACE(2, "rfio", "rfio_smstat64: The connection with the server has been broken");
else
TRACE(2, "rfio", "rfio_smstat64: read(): ERROR received %d/%d bytes (errno=%d)",
rc, replen, errno);
rfio_end_this(s, (rc <= 0 ? 0 : 1));
END_TRACE();
errno = save_errno; serrno = save_serrno;
return(-1);
}
if (m64) {
unmarshall_WORD(p, statbuf->st_dev);
unmarshall_HYPER(p, statbuf->st_ino);
unmarshall_WORD(p, statbuf->st_mode);
unmarshall_WORD(p, statbuf->st_nlink);
unmarshall_WORD(p, statbuf->st_uid);
unmarshall_WORD(p, statbuf->st_gid);
unmarshall_HYPER(p, statbuf->st_size);
unmarshall_LONG(p, statbuf->st_atime);
unmarshall_LONG(p, statbuf->st_mtime);
unmarshall_LONG(p, statbuf->st_ctime);
unmarshall_LONG(p, status);
#if !defined(_WIN32)
unmarshall_LONG(p, statbuf->st_blksize);
unmarshall_HYPER(p, statbuf->st_blocks);
#endif
}
else {
unmarshall_WORD(p, statbuf->st_dev);
unmarshall_LONG(p, statbuf->st_ino);
unmarshall_WORD(p, statbuf->st_mode);
unmarshall_WORD(p, statbuf->st_nlink);
unmarshall_WORD(p, statbuf->st_uid);
unmarshall_WORD(p, statbuf->st_gid);
unmarshall_LONG(p, statbuf->st_size);
unmarshall_LONG(p, statbuf->st_atime);
unmarshall_LONG(p, statbuf->st_mtime);
unmarshall_LONG(p, statbuf->st_ctime);
unmarshall_LONG(p, status);
#if !defined(_WIN32)
if ( reqst != RQST_LSTAT_SEC ) {
unmarshall_LONG(p, statbuf->st_blksize);
unmarshall_LONG(p, statbuf->st_blocks);
}
#endif
}
TRACE(1, "rfio", "rfio_smstat64: return %d", status);
rfio_errno = status;
if (status) {
END_TRACE();
serrno = 0;
return(-1);
}
END_TRACE();
return (0);
}
int DLL_DECL stat64tostat(statb64, statb)
const struct stat64 *statb64;
struct stat *statb;
{
statb->st_dev = statb64->st_dev;
statb->st_ino = (ino_t) statb64->st_ino;
statb->st_mode = statb64->st_mode;
statb->st_nlink = statb64->st_nlink;
statb->st_uid = statb64->st_uid;
statb->st_gid = statb64->st_gid;
statb->st_size = statb64->st_size;
statb->st_atime = statb64->st_atime;
statb->st_mtime = statb64->st_mtime;
statb->st_ctime = statb64->st_ctime;
#if !defined(_WIN32)
statb->st_blksize= statb64->st_blksize;
statb->st_blocks = (int) statb64->st_blocks;
#endif
return (0);
}
|