Exemplo 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);
}
Exemplo n.º 2
0
int main(int argc, char *argv[])
{
	struct hsfs_inode hi;
	struct hsfs_super hs;
	char *cliname = NULL;
	char *svraddr = NULL;
	CLIENT *mclntp = NULL;
	char * fpath = NULL;
	int mask = 0;

	if (argc < 3) {
		printf("MISSING args in running program access!\n");
		//goto out;
	}
	memset(&hi, 0, sizeof(struct hsfs_inode));
	memset(&hs, 0, sizeof(struct hsfs_super));
	hi.sb = &hs;
	cliname = basename(argv[0]);
	svraddr = argv[1];
	fpath = argv[2];
	mclntp = clnt_create(svraddr, NFS_PROGRAM, NFS_V3, "TCP");
	perror("4");
	if (NULL == mclntp) {
		printf("ERROR occur while executing <clnt_create> process\n");
		goto out;
	}
	hi.sb->clntp = mclntp;

	size_t fhlen;
	unsigned char *fhvalp;
	map_path_to_nfs3fh(svraddr, fpath, &fhlen, &fhvalp);
	hi.fh.data.data_len = fhlen;
	hi.fh.data.data_val = fhvalp;
	//mask = 0x1;
	mask = 0x3F;
	while (mask & 0x3F) {
		printf("Result for %x:%d\n", mask, hsi_nfs3_access(&hi, mask));
		mask = mask >> 1;

	}
	return 0;
out:
	perror("Hello, this is out!\n");
}
Exemplo n.º 3
0
int main(int argc, char *argv[])
{	
	char *svraddr = NULL;
	CLIENT *clntp = NULL;
	char *fpath = NULL;
	char *name = NULL;
	struct mkdir3args args;
	struct diropres3 res;
	/*struct fattr *fattrp = NULL;*/
	struct timeval to = {120, 0};
	enum clnt_stat st;
	int err = 0;
	int argv_len = 0;
	struct hsfs_inode *parent = NULL ;
	struct hsfs_inode *new;
	cliname = basename (argv[0]);
	if (argc < 3) {
			err = EINVAL;
			fprintf(stderr, "%s $svraddr $fpath.\n", cliname);
			goto out;
		}
	parent = (struct hsfs_inode *) malloc(sizeof(struct hsfs_inode));
	svraddr = argv[1];
	fpath = argv[2];
	name = argv[3];
	clntp = clnt_create(svraddr, 100003, NFS_V3, "tcp");
	if (NULL == clntp)
	{
		fprintf(stderr, "%s: Create handle to RPC server (%s, %u, %u) failed: (%s).\n", cliname,svraddr, NFSPROC3_MKDIR, NFS_V3, clnt_spcreateerror(cliname));
		err = ENXIO;
		goto out;
	} 
	memset (&args, 0, sizeof(args));
	memset (&res, 0, sizeof(res));
	args.where.name = fpath;
	//args.path.fpath_len = strlen(fpath);
	int st_tmp;
	size_t fh_len = 0;
	unsigned char *fh;
	st_tmp = map_path_to_nfs3fh(svraddr, fpath, &fh_len, &fh);
	args.where.dir.data.data_len  = fh_len;
	args.where.dir.data.data_val = fh;
	parent->sb = (struct hsfs_super *) malloc(sizeof(struct hsfs_super));
	if (NULL == parent->sb)
	{
		printf("No memory:parent->sb.\n");
	}
	parent->sb->clntp = clntp;
	parent->fh.data.data_len = args.where.dir.data.data_len;
	parent->fh.data.data_val = args.where.dir.data.data_val;
	st = hsi_nfs3_rmdir(parent, name);
	if (st) {
		err = EIO;
		fprintf (stderr, "%s: Call RPC Server (%s, %u, %u) failure: (%s).\n", cliname, svraddr, NFSPROC3_MKDIR, NFS_V3,clnt_sperrno(st));
		goto out;
	}
	if (0 == st){
		printf("Rm ok!\n");
	}

out:
	free(parent->sb);
	free(parent);
	if (NULL != clntp)
		clnt_destroy(clntp);
	exit(st);
}
Exemplo n.º 4
0
int main (int argc, char *argv[])
{
	int err;
	nfs_fh3 fh;
	size_t length;
	char *fh_v;
	char *svraddr = NULL;
	CLIENT *p_clntp = NULL;
	char *fpath =NULL;
	struct hsfs_inode root;    
	struct hsfs_super super;
	struct statvfs stbuf;
	root.sb = &super;
	char *cliname = basename (argv[0]);

	if (argc <3){
		err = EINVAL;
		fprintf(stderr, "%s $svraddr $fpath.\n", cliname);
		goto exit;
	}
	svraddr = argv[1];
	fpath = argv[2];
	p_clntp = clnt_create(svraddr, NFS_PROGRAM, NFS_V3,"udp");
	if (NULL == p_clntp){
		fprintf(stderr, "%s: Create handle to RPC server"\
				"(%s, %u, %u) failed: (%s).\n",cliname,
				svraddr, NFSPROC3_FSSTAT, NFS_V3,clnt_spcreateerror(cliname));
		err = ENXIO;
		goto exit;

	}
	err = map_path_to_nfs3fh (svraddr, fpath, &length, &fh_v);
	if (err!= 0){
		printf("map_path_to_nfs3fh failed! err:%d\n",err);
		goto exit;
	}
	memset (&fh,0,sizeof(fh));
	fh.data.data_len=length;
	fh.data.data_val=fh_v;
	root.fh = fh;

	super.clntp = p_clntp;
	err = hsi_nfs3_statfs(&root);
	if (err){
		printf("hsi_nfs3_statfs failed! err:%d\n",err);
		goto exit;
	}
	printf ("\ttbytes=%u\n\tfbytes=%u\n\tabytes=%u\n\ttfiles=%u\n\tffiles=%u\n\tafiles=%u\n",
			root.sb->tbytes,root.sb->fbytes,root.sb->abytes,root.sb->tfiles,root.sb->ffiles,root.sb->afiles);

	err = hsi_super2statvfs (root.sb, &stbuf);
	if (err){
		goto exit;
	}
	printf ("\tf_bsize=%u\n\tf_frsize=%u\n\tf_blocks=%u\n\tf_bfree=%u\n\tf_bavail=%u\n\tf_files=%u\n",
			stbuf.f_bsize,stbuf.f_frsize,stbuf.f_blocks,stbuf.f_bfree,stbuf.f_bavail,stbuf.f_files);
	printf ("\tf_ffree=%u\n\tf_favail=%u\n\tf_fsid=%u\n\tf_flag=%u\n\tf_namemax=%u\n",
			stbuf.f_ffree,stbuf.f_favail,stbuf.f_fsid,stbuf.f_flag,stbuf.f_namemax);

exit:
	exit (err);
}