home *** CD-ROM | disk | FTP | other *** search
/ PC-Online 1996 May / PCOnline_05_1996.bin / linux / source / n / tcpip / netkit-a.06 / netkit-a / NetKit-A-0.06 / nfs-server-2.0 / getattr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-04  |  3.1 KB  |  130 lines

  1. /*
  2.  * getattr    This module handles the NFS attributes.
  3.  *
  4.  * Authors:    Mark A. Shand, May 1988
  5.  *        Donald J. Becker, <becker@super.org>
  6.  *        Rick Sladkey, <jrs@world.std.com>
  7.  *        Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
  8.  *
  9.  *        Copyright 1988 Mark A. Shand
  10.  *        This software maybe be used for any purpose provided
  11.  *        the above copyright notice is retained.  It is supplied
  12.  *        as is, with no warranty expressed or implied.
  13.  */
  14.  
  15. #include "nfsd.h"
  16.  
  17. /* Use Mark Shand's ugid_map.c if you have differing uids on your machines. */
  18. #ifdef UGID_MAP
  19. extern clnt_param *client_param;
  20. extern struct svc_req *rqstp;
  21. #define ruid(uid) ruid(uid, client_param, rqstp)
  22. #define rgid(gid) rgid(gid, client_param, rqstp)
  23. #else
  24. #define ruid(uid) (uid)
  25. #define rgid(gid) (gid)
  26. #endif
  27.  
  28. /*
  29.  * The NFS version 2 specification fails to mention all of
  30.  * these file types, but they exist in the nfs_prot.x file.
  31.  */
  32. #define ftype_map(st_mode) (_ftype_map[((st_mode) & S_IFMT) >> 12])
  33.  
  34. ftype _ftype_map[16] =
  35. {
  36. #ifdef S_IFIFO
  37.     NFNON, NFFIFO, NFCHR, NFBAD,
  38. #else
  39.     NFNON, NFBAD, NFCHR, NFBAD,
  40. #endif
  41.     NFDIR, NFBAD, NFBLK, NFBAD,
  42.     NFREG, NFBAD, NFLNK, NFBAD,
  43.     NFSOCK, NFBAD, NFBAD, NFBAD,
  44. };
  45.  
  46. nfsstat getattr(fh, attr, stat_optimize)
  47. nfs_fh *fh;
  48. fattr *attr;
  49. struct stat *stat_optimize;
  50. {
  51. #if DEBUG
  52.     char buff[1024];
  53.     char *sp;
  54. #endif
  55.     nfsstat status;
  56.     char *path;
  57.     struct stat *s;
  58.     struct stat sbuf;
  59.  
  60.     if ((path = fh_path(fh, &status)) == NULL) {
  61.         dprintf(1, "getattr: failed! No such file.\n");
  62.         return (NFSERR_STALE);
  63.     }
  64.     if (stat_optimize != NULL)
  65.         s = stat_optimize;
  66.     else if (lstat(path, (s = &sbuf)) != 0) {
  67.         dprintf(1, "getattr(%s): failed!  errno=%d\n", path, errno);
  68.         return (nfs_errno());
  69.     }
  70.     attr->type = ftype_map(s->st_mode);
  71.     attr->mode = s->st_mode;
  72.     attr->nlink = s->st_nlink;
  73.     attr->uid = ruid(s->st_uid);
  74.     attr->gid = rgid(s->st_gid);
  75.  
  76. #ifdef S_ISLNK
  77.     if (S_ISLNK(s->st_mode))
  78.         attr->size = NFS_MAXPATHLEN;
  79.     else
  80. #endif
  81.         attr->size = s->st_size;
  82. #ifdef HAVE_ST_BLKSIZE
  83.     attr->blocksize = s->st_blksize;
  84. #else /* !HAVE_ST_BLKSIZE */
  85. #ifdef BUFSIZ
  86.     attr->blocksize = BUFSIZ;
  87. #else /* BUFSIZ */
  88.     attr->blocksize = 1024;
  89. #endif /* !BUFSIZ */
  90. #endif /* !HAVE_ST_BLKSIZE */
  91.     attr->rdev = s->st_rdev;
  92. #ifdef HAVE_ST_BLOCKS
  93.     attr->blocks = s->st_blocks;
  94. #else
  95.     attr->blocks = st_blocks(s);
  96. #endif
  97.     attr->fsid = 1;
  98.     attr->fileid = fh_psi(fh);
  99.     attr->atime.seconds = s->st_atime;
  100.     attr->atime.useconds = 0;
  101.     attr->mtime.seconds = s->st_mtime;
  102.     attr->mtime.useconds = 0;
  103.     attr->ctime.seconds = s->st_ctime;
  104.     attr->ctime.useconds = 0;
  105.  
  106. #ifdef DEBUG
  107.     sp = buff;
  108.     sprintf(sp, " t=%d, m=%o, lk=%d, u/g=%d/%d, sz=%d, bsz=%d",
  109.         attr->type, attr->mode, attr->nlink,
  110.         attr->uid, attr->gid, attr->size,
  111.         attr->blocksize);
  112.     sp += strlen(sp);
  113.     if (attr->type == NFCHR || attr->type == NFBLK) {
  114.         sprintf(sp, " rdev=%d/%d", (attr->rdev >> 8) & 0xff, attr->rdev & 0xff);
  115.         sp += strlen(sp);
  116.         sprintf(sp, "\n  blks=%d, fsid=%d, psi=%d, at=%d, mt=%d, ct=%d\n",
  117.             attr->blocks, attr->fsid, attr->fileid,
  118.             attr->atime.seconds,
  119.             attr->mtime.seconds,
  120.             attr->ctime.seconds);
  121.         sp += strlen(sp);
  122.     } else {
  123.         sprintf(sp, " >>> %s\n", sys_errlist[(int) status]);
  124.     }
  125.     dprintf(1, "%s", buff);
  126. #endif
  127.  
  128.     return (NFS_OK);
  129. }
  130.