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); }
bool_t xdr_int64(register XDR *xdrs, int64 *objp) { if (!xdr_longlong_t(xdrs, objp)) return (FALSE); return (TRUE); }
bool_t xdr_int64(XDR *xdrs, int64 *objp) { register int32_t *buf; if (!xdr_longlong_t(xdrs, objp)) { return (FALSE); } return (TRUE); }
void ltspfs_truncate (int sockfd, XDR *in) { char path[PATH_MAX]; off_t offset; if (!xdr_longlong_t(in, &offset)) { /* Get the mode */ eacces(sockfd); return; } if (get_fn(sockfd, in, path)) { /* Get the path */ eacces(sockfd); return; } status_return (sockfd, truncate (path, offset)); }
void ltspfs_write (int sockfd, XDR *in) { XDR out; char path[PATH_MAX]; char output[LTSP_MAXBUF]; int i; int fd; int result; size_t size; off_t offset; char *buf; if (!xdr_u_int(in, &size)) { /* Get the size */ eacces(sockfd); return; } if (!xdr_longlong_t(in, &offset)) { /* Get the offset */ eacces(sockfd); return; } if (get_fn(sockfd, in, path)) { /* Get the path */ eacces(sockfd); return; } buf = malloc (size); /* * Check result of malloc */ if (!buf) { status_return(sockfd, FAIL); return; } fd = open (path, O_WRONLY); if (fd == -1) { status_return(sockfd, FAIL); free (buf); return; } readn (sockfd, buf, size); lseek (fd, offset, SEEK_SET); result = write (fd, buf, size); if (result < 0) status_return(sockfd, FAIL); else { 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, &result); /* Write out the result */ 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 %s", output); writen(sockfd, output, i); } close (fd); free (buf); }