Esempio n. 1
0
void
ltspfs_getattr (int sockfd, XDR *in)
{
  XDR         out;
  char        path[PATH_MAX];
  char 	      output[LTSP_MAXBUF];
  int         i;
  struct stat stbuf;

  if (get_fn(sockfd, in, path)) {
    if (debug)
      info ("get_fn failed\n");
    eacces(sockfd);
    return;
  }

  if (lstat (path, &stbuf) == -1) {
    status_return(sockfd, FAIL);
    return;
  }

  xdrmem_create(&out, output, LTSP_MAXBUF, XDR_ENCODE);
  i = 0;
  xdr_int(&out, &i);	 			/* First, the dummy length */
  xdr_int(&out, &i);				/* Then the 0 status return */
  xdr_u_longlong_t(&out, &(stbuf.st_dev));	/* device */
  xdr_u_longlong_t(&out, &(stbuf.st_ino));	/* inode */
  xdr_u_int(&out, &(stbuf.st_mode));		/* protection */
  xdr_u_int(&out, &(stbuf.st_nlink));		/* number of hard links */
  xdr_u_int(&out, &(stbuf.st_uid));		/* user ID of owner */
  xdr_u_int(&out, &(stbuf.st_gid));		/* group ID of owner */
  xdr_u_longlong_t(&out, &(stbuf.st_rdev));	/* device type */
  xdr_longlong_t(&out, &(stbuf.st_size));	/* total size, in bytes */
  xdr_long(&out, &(stbuf.st_blksize));		/* blocksize for fs I/O */
  xdr_longlong_t(&out, &(stbuf.st_blocks));	/* number of blocks allocated */
  xdr_long(&out, &(stbuf.st_atime));		/* time of last access */
  xdr_long(&out, &(stbuf.st_mtime));		/* time of last modification */
  xdr_long(&out, &(stbuf.st_ctime));		/* time of last status change */
  i = xdr_getpos(&out);				/* Get our position */
  xdr_setpos(&out, 0);				/* Rewind to the beginning */
  xdr_int(&out, &i);				/* Rewrite with proper length */
  xdr_destroy(&out);

  if (debug)
    info("returning OK");

  writen(sockfd, output, i);
}
Esempio n. 2
0
bool_t
xdr_uint64(register XDR *xdrs, uint64 *objp)
{
	if (!xdr_u_longlong_t(xdrs, objp))
		return (FALSE);
	return (TRUE);
}
Esempio n. 3
0
void
ltspfs_statfs (int sockfd, XDR *in)
{
  XDR out;
  char path[PATH_MAX];
  char output[LTSP_MAXBUF];
  struct statfs stbuf;
  int i;

  if (get_fn(sockfd, in, path)) {		/* Get the path */
    eacces(sockfd);
    return;
  }


  if (statfs (path, &stbuf) == -1) {
    status_return(sockfd, FAIL);
    return;
  }

  xdrmem_create(&out, output, LTSP_MAXBUF, XDR_ENCODE);
  i = 0;
  xdr_int(&out, &i);				/* dummy length */
  i = LTSP_STATUS_OK;				/* OK status */
  xdr_int(&out, &i);
  xdr_int(&out, &stbuf.f_type);       		/* type of fs */
  xdr_int(&out, &stbuf.f_bsize); 		/* optimal transfer block sz */
  xdr_u_longlong_t(&out, &stbuf.f_blocks);	/* total data blocks in fs */
  xdr_u_longlong_t(&out, &stbuf.f_bfree);	/* free blks in fs */
  xdr_u_longlong_t(&out, &stbuf.f_bavail);      /* free blks avail to non-su */
  xdr_u_longlong_t(&out, &stbuf.f_files);       /* total file nodes in fs */
  xdr_u_longlong_t(&out, &stbuf.f_ffree);	/* free file nodes in fs */
  xdr_int(&out, &stbuf.f_namelen); 		/* max length of filenames */
  i = xdr_getpos(&out);	 			/* Get current position */
  xdr_setpos(&out, 0);	 			/* rewind to the beginning */
  xdr_int(&out, &i);				/* re-write proper length */
  xdr_destroy(&out);				/* Clean up the XDR structs */

  if (debug)
    info("returning OK");

  writen(sockfd, output, i);
}
Esempio n. 4
0
bool_t
xdr_uint64(XDR *xdrs, uint64 *objp)
{

	 register int32_t *buf;

	 if (!xdr_u_longlong_t(xdrs, objp)) {
		 return (FALSE);
	 }
	return (TRUE);
}
Esempio n. 5
0
void
ltspfs_readdir (int sockfd, XDR *in)
{
  XDR  out;
  char path[PATH_MAX];
  char output[LTSP_MAXBUF];
  DIR  *dp;
  char *nameptr;
  struct dirent *de;
  int  i;

  if (get_fn(sockfd, in, path)) {		/* Get the dir name */ 
    eacces(sockfd);
    return;
  }

  dp = opendir (path);

  if (dp == NULL) {
    status_return(sockfd, FAIL);		/* opendir failed */
    return;
  }

  while ((de = readdir (dp)) != NULL) {
    xdrmem_create(&out, output, LTSP_MAXBUF, XDR_ENCODE);
    i = 0;
    xdr_int(&out, &i);	 			/* First, the dummy length */
    i = LTSP_STATUS_CONT;
    xdr_int(&out, &i);				/* Then the 2 status return */
    xdr_u_longlong_t(&out, &(de->d_ino));	/* Inode */
    xdr_u_char(&out, &(de->d_type));		/* type */
    nameptr = de->d_name;
    xdr_string(&out, &nameptr, PATH_MAX);	/* filename */
    i = xdr_getpos(&out);			/* Get our position */
    xdr_setpos(&out, 0);			/* Rewind to the beginning */
    xdr_int(&out, &i);				/* Rewrite with proper length */
    xdr_destroy(&out);

    if (debug)
      info("returning %s", de->d_name);

    writen(sockfd, output, i);
  }

  closedir (dp);

  status_return(sockfd, OK);
}
Esempio n. 6
0
void
ltspfs_mknod (int sockfd, XDR *in)
{
  char   path[PATH_MAX];
  mode_t mode;
  dev_t  rdev;

  if (!xdr_u_int(in, &mode)) {			/* Get the mode */
    eacces(sockfd);
    return;
  }
  
  if (!xdr_u_longlong_t(in, &rdev)) {		/* Get the device type */
    eacces(sockfd);
    return;
  }

  if (get_fn(sockfd, in, path)) {		/* Get the dir name */
    eacces(sockfd);
    return;
  }

  status_return (sockfd, mknod (path, mode, rdev));
}
Esempio n. 7
0
static int
nd_send_data(TIUSER *tiptr, caddr_t addr, int offset, XDR *xdrp, uint32_t *xidp)
{
	static struct rpc_msg		call_msg;
	static uchar_t			header[HDR_SIZE];
	static struct t_kunitdata	sudata;
	static uchar_t			*dumpbuf;
	int				procnum;
	stable_how			stable = FILE_SYNC;
	mblk_t				*mblk_p;
	int				error;
	int				tsize = ptob(1);
	uint64				offset3;

	if (!dumpbuf) {
		call_msg.rm_direction = CALL;
		call_msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
		call_msg.rm_call.cb_prog = NFS_PROGRAM;
		call_msg.rm_call.cb_vers = nfsdump_version;

		if (!(dumpbuf = kmem_alloc(ptob(1), KM_NOSLEEP))) {
		cmn_err(CE_WARN, "\tnfs_dump: cannot allocate dump buffer");
			return (ENOMEM);
		}
	}

	nd_log("nfs_dump: calling esballoc for header\n");

	if (!(mblk_p = esballoc(header, HDR_SIZE, BPRI_HI, &frnop))) {
		cmn_err(CE_WARN, "\tnfs_dump: out of mblks");
		return (ENOBUFS);
	}

	xdrmem_create(xdrp, (caddr_t)header, HDR_SIZE, XDR_ENCODE);

	call_msg.rm_xid = alloc_xid();
	*xidp = call_msg.rm_xid;

	if (!xdr_callhdr(xdrp, &call_msg)) {
		cmn_err(CE_WARN, "\tnfs_dump: cannot serialize header");
		return (EIO);
	}

	if (nfsdump_maxcount) {
		/*
		 * Do not extend the dump file if it is also
		 * the swap file.
		 */
		if (offset >= nfsdump_maxcount) {
			cmn_err(CE_WARN, "\tnfs_dump: end of file");
			return (EIO);
		}
		if (offset + tsize > nfsdump_maxcount)
			tsize = nfsdump_maxcount - offset;
	}
	switch (nfsdump_version) {
	case NFS_VERSION:
		procnum = RFS_WRITE;
		if (!XDR_PUTINT32(xdrp, (int32_t *)&procnum) ||
		    !nd_auth_marshall(xdrp) ||
		    !xdr_fhandle(xdrp, &nfsdump_fhandle2) ||
			/*
			 *  Following four values are:
			 *	beginoffset
			 *	offset
			 *	length
			 *	bytes array length
			 */
		    !XDR_PUTINT32(xdrp, (int32_t *)&offset) ||
		    !XDR_PUTINT32(xdrp, (int32_t *)&offset) ||
		    !XDR_PUTINT32(xdrp, (int32_t *)&tsize) ||
		    !XDR_PUTINT32(xdrp, (int32_t *)&tsize)) {
			cmn_err(CE_WARN, "\tnfs_dump: serialization failed");
			return (EIO);
		}
		break;
	case NFS_V3:
		procnum = NFSPROC3_WRITE;
		offset3 = offset;
		if (!XDR_PUTINT32(xdrp, (int32_t *)&procnum) ||
		    !nd_auth_marshall(xdrp) ||
		    !xdr_nfs_fh3(xdrp, &nfsdump_fhandle3) ||
			/*
			 *  Following four values are:
			 *	offset
			 *	count
			 *	stable
			 *	bytes array length
			 */
		    !xdr_u_longlong_t(xdrp, &offset3) ||
		    !XDR_PUTINT32(xdrp, (int32_t *)&tsize) ||
		    !XDR_PUTINT32(xdrp, (int32_t *)&stable) ||
		    !XDR_PUTINT32(xdrp, (int32_t *)&tsize)) {
			cmn_err(CE_WARN, "\tnfs_dump: serialization failed");
			return (EIO);
		}
		break;
	default:
		return (EIO);
	}

	bcopy(addr, (caddr_t)dumpbuf, tsize);

	mblk_p->b_wptr += (int)XDR_GETPOS(xdrp);

	mblk_p->b_cont = esballoc((uchar_t *)dumpbuf, ptob(1), BPRI_HI, &frnop);

	if (!mblk_p->b_cont) {
		cmn_err(CE_WARN, "\tnfs_dump: out of mblks");
		return (ENOBUFS);
	}
	mblk_p->b_cont->b_wptr += ptob(1);

	sudata.addr = nfsdump_addr;		/* structure copy */
	sudata.udata.buf = (char *)NULL;
	sudata.udata.maxlen = 0;
	sudata.udata.len = 1;			/* needed for t_ksndudata */
	sudata.udata.udata_mp = mblk_p;

	nd_log("nfs_dump: calling t_ksndudata\n");

	if (error = t_ksndudata(tiptr, &sudata, (frtn_t *)NULL)) {
		nfs_perror(error, "\nnfs_dump: t_ksndudata failed: %m\n");
		return (error);
	}
	return (0);
}