Esempio n. 1
0
int main(int argc, char *argv[])
{
	int err = 0;
	struct hsfs_super sb;
	progname = basename(argv[0]);
	sb.addr.sin_addr.s_addr = inet_addr("10.10.211.154");
	svraddr = inet_ntoa(*(struct in_addr *)&sb.addr.sin_addr);
	sb.clntp = clnt_create(svraddr,	NFS_PROGRAM, NFS_V3, "udp");
	if (NULL == sb.clntp) {
		fprintf(stderr, "%s: Create handle to RPC server "
				"(%s, %u, %u) failed: (%s).\n", progname,
				svraddr, NFS_PROGRAM, NFS_V3,
				clnt_spcreateerror(progname));
		err = ENXIO;
		goto out;
	}
	char *fpath = "/rpcdir/";
	unsigned char *nfs3fhp = NULL;
	size_t fhlen;
	if ((err = map_path_to_nfs3fh(svraddr, fpath, &fhlen, &nfs3fhp))){
		fprintf(stderr, "%s: Mapping %s on server to its FH feiled.%d\n",
				progname, fpath, err);
		goto out;
	}
	struct hsfs_inode *hi = NULL;
	if (!(hi = (struct hsfs_inode *)malloc(sizeof(struct hsfs_inode)))) {
		fprintf(stderr, "%s: No enough core\n", progname);
	}
	sb.timeo = 10;
	hi->sb = &sb;
	hi->fh.data.data_len = fhlen;
	hi->fh.data.data_val = nfs3fhp;

	fpath = "/rpcdir/test/";
	unsigned char *nfs3fhp2 = NULL;
	if ((err = map_path_to_nfs3fh(svraddr, fpath, &fhlen, &nfs3fhp2))){
		fprintf(stderr, "%s: Mapping %s on server to its FH feiled.%d\n",
				progname, fpath, err);
		goto out;
	}
	struct hsfs_inode *newhi = NULL;
	if (!(newhi = (struct hsfs_inode *)malloc(sizeof(struct hsfs_inode)))) {
		fprintf(stderr, "%s: No enough core\n", progname);
	}
	newhi->sb = &sb;
	newhi->fh.data.data_len = fhlen;
	newhi->fh.data.data_val = nfs3fhp2;

	hsi_nfs3_rename(hi, argv[1], newhi, argv[2]);
out:
	exit(err);
}
Esempio n. 2
0
void hsx_fuse_rename(fuse_req_t req, fuse_ino_t parent, const char *name,
				fuse_ino_t newparent, const char *newname)
{
	int err = 0;
	struct hsfs_super *sb = NULL;
	struct hsfs_inode *hi = NULL, *newhi = NULL;

	DEBUG_IN(" %s to %s", name, newname);

	if (name == NULL) {
		ERR("Source name is NULL\n");
		err = EINVAL;
		goto out;
	}
	else if (newname == NULL) {
		ERR("Target name is NULL\n");
		err = EINVAL;
		goto out;
	}
	else if (!(strcmp(name, ""))) {
		ERR("Source name is empty\n");
		err = EINVAL;
		goto out;
	}
	else if (!(strcmp(newname, ""))) {
		ERR("Target name is empty\n");
		err = EINVAL;
		goto out;
	}
	else if (strlen(name) > NAME_MAX) {
		ERR("Source name is too long\n");
		err = ENAMETOOLONG;
		goto out;
	}
	else if (strlen(newname) > NAME_MAX) {
		ERR("Target name is too long\n");
		err = ENAMETOOLONG;
		goto out;
	}

	if (!(sb = fuse_req_userdata(req))) {
		ERR("Get user data failed\n");
		err = EIO;
		goto out;
	}
	if (!(hi = hsx_fuse_iget(sb, parent))) {
		ERR("Get hsfs inode failed\n");
		err = ENOENT;
		goto out;
	}
	if (!(newhi = hsx_fuse_iget(sb, newparent))) {
		ERR("Get hsfs inode failed\n");
		err = ENOENT;
		goto out;
	}

	if ((err = hsi_nfs3_rename(hi, name, newhi, newname))) {
		goto out;
	}
out:
	fuse_reply_err(req, err);
	DEBUG_OUT(" %s to %s errno:%d", name, newname, err);
}