Пример #1
0
int
main(
	int		argc,
	char		**argv)
{
	char		*han_str;
	char		*name;
	void		*hanp, *fshanp;
	size_t		hlen, fshlen;
	char		buffer[100];
	int		error;

	if (Progname = strrchr(argv[0], '/')) {
		Progname++;
	} else {
		Progname = argv[0];
	}

	if (argc != 2)
		usage();
	han_str = argv[1];

	(void)dm_init_service(&name);

	if ((error = atohan(han_str, &hanp, &hlen)) != 0) {
		fprintf(stderr, "atohan() failed, %s\n", strerror(error));
		return(1);
	}

	if (dm_handle_to_fshandle(hanp, hlen, &fshanp, &fshlen) != 0) {
		fprintf(stderr, "dm_handle_to_fshandle failed, %s\n",
			strerror(errno));
		return(1);
	}
	hantoa(fshanp, fshlen, buffer);
	fprintf(stdout, "%s\n", buffer);

	dm_handle_free(hanp, hlen);
	dm_handle_free(fshanp, fshlen);
	return(0);
}
Пример #2
0
int
main(
	int	argc,
	char	**argv)
{
	dm_sessid_t	sid = DM_NO_SESSION;
	dm_token_t	token;
	dm_right_t	right;
	char		*object;
	void		*hanp;
	size_t	 	hlen;
	int		Fflag = 0;
	char		*name;
	int		opt;

	Progname = strrchr(argv[0], '/');
	if (Progname) {
		Progname++;
	} else {
		Progname = argv[0];
	}

	/* Crack and validate the command line options. */

	while ((opt = getopt(argc, argv, "Fs:")) != EOF) {
		switch (opt) {
		case 'F':
			Fflag++;
			break;
		case 's':
			sid = atol(optarg);
			break;
		case '?':
			usage();
		}
	}
	if (optind + 2 != argc)
		usage();
	token = atol(argv[optind++]);
	object = argv[optind++];

	if (dm_init_service(&name) == -1)  {
		fprintf(stderr, "Can't initialize the DMAPI\n");
		exit(1);
	}
	if (sid == DM_NO_SESSION)
		find_test_session(&sid);

	/* Get the file or filesystem's handle. */

	if (opaque_to_handle(object, &hanp, &hlen)) {
		fprintf(stderr, "can't get handle from %s\n", object);
		exit(1);
	}
	if (Fflag) {
		void	*fshanp;
		size_t	fshlen;

		if (dm_handle_to_fshandle(hanp, hlen, &fshanp, &fshlen)) {
			fprintf(stderr, "can't get filesystem handle from %s\n",
				object);
			exit(1);
		}
		dm_handle_free(hanp, hlen);
		hanp = fshanp;
		hlen = fshlen;
	}

	if (dm_query_right(sid, hanp, hlen, token, &right)) {
		fprintf(stderr, "dm_query_right failed, %s\n",
			strerror(errno));
		return(1);
	}

	fprintf(stderr, "right is %s\n", rt_value_to_name(right));

	dm_handle_free(hanp, hlen);
	exit(0);
}
Пример #3
0
int
main(
	int	argc, 
	char	**argv)
{
	dm_sessid_t	 sid = DM_NO_SESSION;
	dm_token_t	token = DM_NO_TOKEN;
	u_int		nelem = DM_EVENT_MAX;
	char		*object;
	dm_eventset_t	eventset;
	void		*hanp;
	size_t	 	 hlen;
	u_int		nelemp;
	char		*name;
	int		Fflag = 0;
	int		error;
	int		opt;
	int		i;

	if (Progname = strrchr(argv[0], '/')) {
		Progname++;
	} else {
		Progname = argv[0];
	}

	/* Crack and validate the command line options. */

	while ((opt = getopt(argc, argv, "Fn:s:t:")) != EOF) {
		switch (opt) {
		case 'F':
			Fflag++;
			break;
		case 'n':
			nelem = atol(optarg);
			break;
		case 's':
			sid = atol(optarg);
			break;
		case 't':
			token = atol(optarg);
			break;
		case '?':
			usage();
		}
	}
	if (optind + 1 != argc)
		usage();
	object = argv[optind];

	if (dm_init_service(&name) == -1)  {
		fprintf(stderr, "Can't initialize the DMAPI\n");
		exit(1);
	}

	if ((error = opaque_to_handle(object, &hanp, &hlen)) != 0) {
		fprintf(stderr, "can't get a handle from %s, %s\n",
			object, strerror(error));
		return(1);
	}

	if (Fflag) {
		void	*fshanp;
		size_t	fshlen;

		if (dm_handle_to_fshandle(hanp, hlen, &fshanp, &fshlen)) {
			fprintf(stderr, "can't get filesystem handle from %s\n",
				object);
			exit(1);
		}
		dm_handle_free(hanp, hlen);
		hanp = fshanp;
		hlen = fshlen;
	}

	if (sid == DM_NO_SESSION)
		find_test_session(&sid);

	DMEV_ZERO(eventset);

	if (dm_get_eventlist(sid, hanp, hlen, token, nelem,
	    &eventset, &nelemp)) {
		fprintf(stderr, "dm_get_eventlist failed, %s\n",
			strerror(errno));
		return(1);
	}

#ifdef	VERITAS_21
	fprintf(stdout, "Events on object %s (0x%x), nelemp %d:\n",
#else
	fprintf(stdout, "Events on object %s (0x%llx), nelemp %d:\n",
#endif
		object, eventset, nelemp);

	for (i = 0; i < nelemp; i++) {
		if (!DMEV_ISSET(i, eventset))
			continue;
		switch (i) {
		case DM_EVENT_CANCEL:
			fprintf(stdout, "DM_EVENT_CANCEL");
			break;
		case DM_EVENT_MOUNT:
			fprintf(stdout, "DM_EVENT_MOUNT");
			break;
		case DM_EVENT_PREUNMOUNT:
			fprintf(stdout, "DM_EVENT_PREUNMOUNT");
			break;
		case DM_EVENT_UNMOUNT:
			fprintf(stdout, "DM_EVENT_UNMOUNT");
			break;
		case DM_EVENT_DEBUT:
			fprintf(stdout, "DM_EVENT_DEBUT");
			break;
		case DM_EVENT_CREATE:
			fprintf(stdout, "DM_EVENT_CREATE");
			break;
		case DM_EVENT_CLOSE:
			fprintf(stdout, "DM_EVENT_CLOSE");
			break;
		case DM_EVENT_POSTCREATE:
			fprintf(stdout, "DM_EVENT_POSTCREATE");
			break;
		case DM_EVENT_REMOVE:
			fprintf(stdout, "DM_EVENT_REMOVE");
			break;
		case DM_EVENT_POSTREMOVE:
			fprintf(stdout, "DM_EVENT_POSTREMOVE");
			break;
		case DM_EVENT_RENAME:
			fprintf(stdout, "DM_EVENT_RENAME");
			break;
		case DM_EVENT_POSTRENAME:
			fprintf(stdout, "DM_EVENT_POSTRENAME");
			break;
		case DM_EVENT_LINK:
			fprintf(stdout, "DM_EVENT_LINK");
			break;
		case DM_EVENT_POSTLINK:
			fprintf(stdout, "DM_EVENT_POSTLINK");
			break;
		case DM_EVENT_SYMLINK:
			fprintf(stdout, "DM_EVENT_SYMLINK");
			break;
		case DM_EVENT_POSTSYMLINK:
			fprintf(stdout, "DM_EVENT_POSTSYMLINK");
			break;
		case DM_EVENT_READ:
			fprintf(stdout, "DM_EVENT_READ");
			break;
		case DM_EVENT_WRITE:
			fprintf(stdout, "DM_EVENT_WRITE");
			break;
		case DM_EVENT_TRUNCATE:
			fprintf(stdout, "DM_EVENT_TRUNCATE");
			break;
		case DM_EVENT_ATTRIBUTE:
			fprintf(stdout, "DM_EVENT_ATTRIBUTE");
			break;
		case DM_EVENT_DESTROY:
			fprintf(stdout, "DM_EVENT_DESTROY");
			break;
		case DM_EVENT_NOSPACE:
			fprintf(stdout, "DM_EVENT_NOSPACE");
			break;
		case DM_EVENT_USER:
			fprintf(stdout, "DM_EVENT_USER");
			break;
		case DM_EVENT_MAX:
			fprintf(stdout, "DM_EVENT_23");
			break;
		}
		fprintf(stdout, " (%d)\n", i);
	}

	dm_handle_free(hanp, hlen);
	return(0);
}
Пример #4
0
int
main(
	int	argc,
	char	**argv)
{
	dm_sessid_t	sid, oldsid, targetsid, *newsidp, *sidbufp;
	dm_token_t	token, *tokenp, *rtokenp, *tokenbufp;
	dm_attrname_t	*attrnamep;
	dm_off_t	off, *offp, *roffp;
	dm_extent_t	*extentp;
	dm_inherit_t	*inheritbufp;
	dm_stat_t	*statp;
	dm_size_t	len, *dmrlenp, *retvalp;
	dm_attrloc_t	*locp;
	dm_eventset_t	*eventsetp;
	dm_config_t	flagname;
	dm_region_t	*regbufp;
	dm_response_t	response;
	dm_right_t	right, *rightp;
	dm_igen_t	igen, *igenp;
	dm_msgtype_t	msgtype;
	dm_fileattr_t	*attrp;
	dm_boolean_t	enable, *exactflagp;
	dm_timestruct_t	*delay;
	mode_t		mode;
	size_t		hlen, dirhlen, hlen1, hlen2, targhlen, *fshlenp, *hlenp;
	size_t		msglen, buflen, *rlenp;
	u_int		nelem, mask, maxmsgs, uflags, *nelemp, maxevent;
	void		*hanp, *dirhanp, *hanp1, *hanp2, *targhanp;
	void		*msgdatap, *bufp, **hanpp, *respbufp, **fshanpp;
	dm_fsid_t	fsid, *fsidp;
	dm_ino_t	ino, *inop;
	char		*cname, *sessinfop, *path, *pathbufp, **versionstrpp;
	int		flags, fd, setdtime, reterror;
	u_int	urc;
	int	rc;
	dm_ssize_t	ssrc;

/* Definitions per the prototypes in dmport.h, in the same order. */

	rc = dm_clear_inherit(sid, hanp, hlen, token, attrnamep);
	rc = dm_create_by_handle(sid, dirhanp, dirhlen, token,
		hanp, hlen, cname);
	rc = dm_create_session(oldsid, sessinfop, newsidp);
	rc = dm_create_userevent(sid, msglen, msgdatap, tokenp);
	rc = dm_destroy_session(sid);
	rc = dm_downgrade_right(sid, hanp, hlen, token);
	rc = dm_fd_to_handle(fd, hanpp, hlenp);
	rc = dm_find_eventmsg(sid, token, buflen, bufp, rlenp);
	rc = dm_get_allocinfo(sid, hanp, hlen,
		token, offp, nelem, extentp, nelemp);
	rc = dm_get_bulkall(sid, hanp, hlen, token, mask, attrnamep,
		locp, buflen, bufp, rlenp);
	rc = dm_get_bulkattr(sid, hanp, hlen, token, mask, locp, buflen, 
		bufp, rlenp);
	rc = dm_get_config(hanp, hlen, flagname, retvalp);
	rc = dm_get_config_events(hanp, hlen, nelem, eventsetp, nelemp);
	rc = dm_get_dirattrs(sid, hanp, hlen, token, mask, locp, buflen,
		bufp, rlenp);
	rc = dm_get_dmattr(sid, hanp, hlen, token, attrnamep, buflen,
		bufp, rlenp);
	rc = dm_get_eventlist(sid, hanp, hlen, token, nelem, eventsetp, nelemp);
	rc = dm_get_events(sid, maxmsgs, flags, buflen, bufp, rlenp);
	rc = dm_get_fileattr(sid, hanp, hlen, token, mask, statp);
	rc = dm_get_mountinfo(sid, hanp, hlen, token, buflen, bufp, rlenp);
	rc = dm_get_region(sid, hanp, hlen, token, nelem, regbufp, nelemp);
	rc = dm_getall_disp(sid, buflen, bufp, rlenp);
	rc = dm_getall_dmattr(sid, hanp, hlen, token, buflen, bufp, rlenp);
	rc = dm_getall_inherit(sid, hanp, hlen,
		token, nelem, inheritbufp, nelemp);
	rc = dm_getall_sessions(nelem, sidbufp, nelemp);
	rc = dm_getall_tokens(sid, nelem, tokenbufp, nelemp);
	rc = dm_handle_cmp(hanp1, hlen1, hanp2, hlen2);
	dm_handle_free(hanp, hlen);
	urc = dm_handle_hash(hanp, hlen);
	rc = dm_handle_is_valid(hanp, hlen);
	rc = dm_handle_to_fshandle(hanp, hlen, fshanpp, fshlenp);
	rc = dm_handle_to_fsid(hanp, hlen, fsidp);
	rc = dm_handle_to_igen(hanp, hlen, igenp);
	rc = dm_handle_to_ino(hanp, hlen, inop);
	rc = dm_handle_to_path(dirhanp, dirhlen, targhanp, targhlen, 
		buflen, pathbufp, rlenp);
	rc = dm_init_attrloc(sid, hanp, hlen, token, locp);
	rc = dm_init_service(versionstrpp);
	rc = dm_make_handle(&fsid, &ino, &igen, hanpp, hlenp);
	rc = dm_make_fshandle(&fsid, hanpp, hlenp);
	rc = dm_mkdir_by_handle(sid, dirhanp, dirhlen, token,
		hanp, hlen, cname); 
	rc = dm_move_event(sid, token, targetsid, rtokenp);
	rc = dm_obj_ref_hold(sid, token, hanp, hlen);
	rc = dm_obj_ref_query(sid, token, hanp, hlen);
	rc = dm_obj_ref_rele(sid, token, hanp, hlen);
	rc = dm_path_to_fshandle(path, hanpp, hlenp);
	rc = dm_path_to_handle(path, hanpp, hlenp);
	rc = dm_pending(sid, token, delay);
	rc = dm_probe_hole(sid, hanp, hlen, token, off, len, roffp, dmrlenp);
	rc = dm_punch_hole(sid, hanp, hlen, token, off, len);
	rc = dm_query_right(sid, hanp, hlen, token, rightp);
	rc = dm_query_session(sid, buflen, bufp, rlenp);
	ssrc = dm_read_invis(sid, hanp, hlen, token, off, len, bufp);
	rc =  dm_release_right(sid, hanp, hlen, token);
	rc = dm_remove_dmattr(sid, hanp, hlen, token, setdtime, attrnamep);
	rc = dm_request_right(sid, hanp, hlen, token, uflags, right);
	rc = dm_respond_event(sid, token, response, reterror, buflen, respbufp);
	rc = dm_send_msg(sid, msgtype, buflen, bufp);
	rc = dm_set_disp(sid, hanp, hlen, token, eventsetp, maxevent);
	rc = dm_set_dmattr(sid, hanp, hlen,
		token, attrnamep, setdtime, buflen, bufp);
	rc = dm_set_eventlist(sid, hanp, hlen, token, eventsetp, maxevent);
	rc = dm_set_fileattr(sid, hanp, hlen, token, mask, attrp);
	rc = dm_set_inherit(sid, hanp, hlen, token, attrnamep, mode);
	rc = dm_set_region(sid, hanp, hlen, token, nelem, regbufp, exactflagp);
	rc = dm_set_return_on_destroy(sid, hanp, hlen,
		token,  attrnamep, enable);
	rc = dm_symlink_by_handle(sid, dirhanp, dirhlen, token,
		hanp, hlen, cname, path); 
	rc = dm_sync_by_handle(sid, hanp, hlen, token);
	rc = dm_upgrade_right(sid, hanp, hlen, token);
	ssrc = dm_write_invis(sid, hanp, hlen, flags, token, off, len, bufp);
	exit(0);
}
Пример #5
0
int
main(
	int	argc, 
	char	**argv)
{
	dm_sessid_t	sid = DM_NO_SESSION;
	dm_token_t	token = DM_NO_TOKEN;
	char		*object;
	dm_eventset_t	eventset;
	void		*hanp;
	size_t	 	hlen;
	int		Fflag = 0;
	u_int		maxevent = DM_EVENT_MAX;
	char		*name;
	int		opt;

	Progname = strrchr(argv[0], '/');
	if (Progname) {
		Progname++;
	} else {
		Progname = argv[0];
	}

	/* Crack and validate the command line options. */

	while ((opt = getopt(argc, argv, "Fm:s:t:")) != EOF) {
		switch (opt) {
		case 'F':
			Fflag++;
			break;
		case 'm':
			maxevent = atol(optarg);
			break;
		case 's':
			sid = atol(optarg);
			break;
		case 't':
			token = atol(optarg);
			break;
		case '?':
			usage();
		}
	}
	if (optind + 1 > argc)
		usage();
	object = argv[optind++];

	if (dm_init_service(&name) == -1)  {
		fprintf(stderr, "Can't initialize the DMAPI\n");
		exit(1);
	}
	if (sid == DM_NO_SESSION)
		find_test_session(&sid);

	DMEV_ZERO(eventset);

	/* Get the file's handle or convert the external handle. */

	if (opaque_to_handle(object, &hanp, &hlen)) {
		fprintf(stderr, "can't get handle for %s\n", object);
		exit(1);
	}

	if (Fflag) {
		void	*fshanp;
		size_t	fshlen;

		if (dm_handle_to_fshandle(hanp, hlen, &fshanp, &fshlen)) {
			fprintf(stderr, "can't get filesystem handle from %s\n",
				object);
			exit(1);
		}
		dm_handle_free(hanp, hlen);
		hanp = fshanp;
		hlen = fshlen;
	}

	for (; optind < argc; optind++) {
		dm_eventtype_t	event;

		event = ev_name_to_value(argv[optind]);
		if (event == DM_EVENT_INVALID) {
			fprintf(stderr, "invalid event %s\n", argv[optind]);
			usage();
		}
		if ((event == DM_EVENT_READ) || (event == DM_EVENT_WRITE) ||
		    (event == DM_EVENT_TRUNCATE)) {
			fprintf(stderr, "Use set_region to twiddle read/write/trunc events\n");
			exit(1);
		}

		DMEV_SET(event, eventset);
	}

	if (dm_set_eventlist(sid, hanp, hlen, token, &eventset, maxevent)) {
		fprintf(stderr, "dm_set_eventlist failed, %s\n",
			strerror(errno));
		exit(1);
	}

	dm_handle_free(hanp, hlen);
	exit(0);
}
Пример #6
0
int
main(
    int		argc,
    char		**argv)
{
    char		*pathname;
    char		*name;
    void		*hanp1, *hanp2, *hanp3, *fshanp1, *fshanp2, *fshanp3;
    size_t		hlen1, hlen2, hlen3, fshlen1, fshlen2, fshlen3;
    u_int		hash1, hash2, hash3, fshash1, fshash2, fshash3;
    dm_fsid_t	fsid;
    dm_ino_t	ino;
    dm_igen_t	igen;
    char		buffer[100];
    char		buffer1[100];
    char		fsbuffer1[100];
    char		buffer2[100];
    char		fsbuffer2[100];
    char		buffer3[100];
    char		fsbuffer3[100];
    int		fd;

    if (Progname = strrchr(argv[0], '/')) {
        Progname++;
    } else {
        Progname = argv[0];
    }

    if (argc != 2) {
        fprintf(stderr, "usage:	%s path\n", argv[0]);
        exit(1);
    }
    pathname = argv[1];

    (void)dm_init_service(&name);

    if (dm_path_to_handle(pathname, &hanp1, &hlen1) != 0) {
        fprintf(stderr, "dm_path_to_handle failed, %s\n",
                strerror(errno));
        exit(1);
    }
    hash1 = dm_handle_hash(hanp1, hlen1);
    hantoa(hanp1, hlen1, buffer1);
    fprintf(stdout, "  han1:  hash %u  value %s  (dm_path_to_handle)\n",
            hash1, buffer1);
    if (dm_handle_is_valid(hanp1, hlen1) == DM_FALSE) {
        fprintf(stderr, "ERROR: han1 is not valid\n");
    }

    if (dm_path_to_fshandle(pathname, &fshanp1, &fshlen1) != 0) {
        fprintf(stderr, "dm_path_to_fshandle failed, %s\n",
                strerror(errno));
        exit(1);
    }
    fshash1 = dm_handle_hash(fshanp1, fshlen1);
    hantoa(fshanp1, fshlen1, fsbuffer1);
    fprintf(stdout, "fshan1:  hash %u  value %s  (dm_path_to_fshandle\n",
            fshash1, fsbuffer1);
    if (dm_handle_is_valid(fshanp1, fshlen1) == DM_FALSE) {
        fprintf(stderr, "ERROR: fshan1 is not valid\n");
    }

    if ((fd = open(pathname, O_RDONLY)) < 0) {
        fprintf(stderr, "open of %s failed, %s\n", pathname,
                strerror(errno));
        exit(1);
    }
    if (dm_fd_to_handle(fd, &hanp2, &hlen2) != 0) {
        fprintf(stderr, "dm_fd_to_handle failed, %s\n",
                strerror(errno));
        exit(1);
    }
    (void)close(fd);
    hash2 = dm_handle_hash(hanp2, hlen2);
    hantoa(hanp2, hlen2, buffer2);
    fprintf(stdout, "  han2:  hash %u  value %s  (dm_fd_to_handle)\n",
            hash2, buffer2);
    if (dm_handle_is_valid(hanp2, hlen2) == DM_FALSE) {
        fprintf(stderr, "ERROR: han2 is not valid\n");
    }

    if (dm_handle_to_fshandle(hanp2, hlen2, &fshanp2, &fshlen2) != 0) {
        fprintf(stderr, "dm_handle_to_fshandle failed, %s\n",
                strerror(errno));
        exit(1);
    }
    fshash2 = dm_handle_hash(fshanp2, fshlen2);
    hantoa(fshanp2, fshlen2, fsbuffer2);
    fprintf(stdout, "fshan2:  hash %u  value %s  (dm_handle_to_fshandle)\n",
            fshash2, fsbuffer2);
    if (dm_handle_is_valid(fshanp2, fshlen2) == DM_FALSE) {
        fprintf(stderr, "ERROR: fshan2 is not valid\n");
    }

    if (dm_handle_cmp(hanp1, hlen1, hanp2, hlen2)) {
        fprintf(stderr, "ERROR: han1 and han2 differ in dm_handle_cmp\n");
    }
    if (strcmp(buffer1, buffer2)) {
        fprintf(stderr, "ERROR: han1 and han2 differ in strcmp\n");
    }
    if (hash1 != hash2) {
        fprintf(stderr, "ERROR: hash1 and hash2 differ\n");
    }

    if (dm_handle_cmp(fshanp1, fshlen1, fshanp2, fshlen2)) {
        fprintf(stderr, "ERROR: fshan1 and fshan2 differ in dm_handle_cmp\n");
    }
    if (strcmp(fsbuffer1, fsbuffer2)) {
        fprintf(stderr, "ERROR: fshan1 and fshan2 differ in strcmp\n");
    }
    if (fshash1 != fshash2) {
        fprintf(stderr, "ERROR: fshash1 and fshash2 differ\n");
    }

    /* Break the handle into its component parts and display them.  Use
       hantoa() instead of printing the parts directly because some are
       32 bits on Veritas and 64 bits on SGI.
    */

    if (dm_handle_to_fsid(hanp1, hlen1, &fsid) != 0) {
        fprintf(stderr, "dm_handle_to_fsid failed, %s\n",
                strerror(errno));
        exit(1);
    }
    hantoa(&fsid, sizeof(fsid), buffer);
    fprintf(stdout, "fsid  %s	(dm_handle_to_fsid)\n", buffer);

    if (dm_handle_to_ino(hanp1, hlen1, &ino) != 0) {
        fprintf(stderr, "dm_handle_to_ino failed, %s\n",
                strerror(errno));
        exit(1);
    }
    hantoa(&ino, sizeof(ino), buffer);
    fprintf(stdout, "ino   %s	(dm_handle_to_ino)\n", buffer);

    if (dm_handle_to_igen(hanp1, hlen1, &igen) != 0) {
        fprintf(stderr, "dm_handle_to_igen failed, %s\n",
                strerror(errno));
        exit(1);
    }
    hantoa(&igen, sizeof(igen), buffer);
    fprintf(stdout, "igen  %s	(dm_handle_to_igen)\n", buffer);

    /* Now use the parts to remake the handle and verify we get the same
       answer.
    */

    if (dm_make_handle(&fsid, &ino, &igen, &hanp3, &hlen3) != 0) {
        fprintf(stderr, "dm_make_handle failed, %s\n",
                strerror(errno));
        exit(1);
    }
    hash3 = dm_handle_hash(hanp3, hlen3);
    hantoa(hanp3, hlen3, buffer3);
    fprintf(stdout, "  han3:  hash %u  value %s  (dm_make_handle)\n",
            hash3, buffer3);
    if (dm_handle_is_valid(hanp3, hlen3) == DM_FALSE) {
        fprintf(stderr, "ERROR: han3 is not valid\n");
    }

    if (dm_handle_cmp(hanp1, hlen1, hanp3, hlen3)) {
        fprintf(stderr, "ERROR: hanp1 and hanp3 differ in dm_handle_cmp\n");
    }
    if (strcmp(buffer1, buffer3)) {
        fprintf(stderr, "ERROR: hanp1 and hanp3 differ in strcmp\n");
    }
    if (hash1 != hash3) {
        fprintf(stderr, "ERROR: hash1 and hash3 differ\n");
    }

    if (dm_make_fshandle(&fsid, &fshanp3, &fshlen3) != 0) {
        fprintf(stderr, "dm_make_fshandle failed, %s\n",
                strerror(errno));
        exit(1);
    }
    fshash3 = dm_handle_hash(fshanp3, fshlen3);
    hantoa(fshanp3, fshlen3, fsbuffer3);
    fprintf(stdout, "fshan3:  hash %u  value %s  (dm_make_fshandle)\n",
            fshash3, fsbuffer3);
    if (dm_handle_is_valid(fshanp3, fshlen3) == DM_FALSE) {
        fprintf(stderr, "ERROR: fshan3 is not valid\n");
    }

    if (dm_handle_cmp(fshanp1, fshlen1, fshanp3, fshlen3)) {
        fprintf(stderr, "ERROR: fshan1 and fshan3 differ in dm_handle_cmp\n");
    }
    if (strcmp(fsbuffer1, fsbuffer3)) {
        fprintf(stderr, "ERROR: fshan1 and fshan3 differ in strcmp\n");
    }
    if (fshash1 != fshash3) {
        fprintf(stderr, "ERROR: fshash1 and fshash3 differ\n");
    }

    dm_handle_free(hanp1, hlen1);
    dm_handle_free(hanp2, hlen2);
    dm_handle_free(hanp3, hlen3);
    dm_handle_free(fshanp1, fshlen1);
    dm_handle_free(fshanp2, fshlen2);
    dm_handle_free(fshanp3, fshlen3);
    exit(0);
}
Пример #7
0
int
main(
	int	argc, 
	char	**argv)
{
	dm_sessid_t	sid = DM_NO_SESSION;
	dm_token_t	token = DM_NO_TOKEN;
	char		*pathname;
	dm_attrname_t	*attrnamep = NULL;
	dm_boolean_t	enable = DM_FALSE;
	void		*hanp;
	size_t	 	hlen;
	char		*name;
	int		opt;
	int		Fflag = 0;

	Progname = strrchr(argv[0], '/');
	if (Progname) {
		Progname++;
	} else {
		Progname = argv[0];
	}

	/* Crack and validate the command line options. */

	while ((opt = getopt(argc, argv, "Fs:t:")) != EOF) {
		switch (opt) {
		case 's':
			sid = atol(optarg);
			break;
		case 't':
			token = atol(optarg);
			break;
		case 'F':
			Fflag++;
			break;
		case '?':
			usage();
		}
	}
	if (optind == argc || optind + 2 < argc)
		usage();
	pathname = argv[optind++];
	if (optind < argc) {
		enable = DM_TRUE;
		attrnamep = (dm_attrname_t *)argv[optind++];
	}

	if (dm_init_service(&name) == -1)  {
		fprintf(stderr, "Can't initialize the DMAPI\n");
		exit(1);
	}
	if (sid == DM_NO_SESSION)
		find_test_session(&sid);

	if (opaque_to_handle(pathname, &hanp, &hlen)) {
		fprintf(stderr, "can't get handle for %s\n", pathname);
		exit(1);
	}

	/* Get the file's handle. */

	if (Fflag) {
		void *fshanp;
		size_t fshlen;

		if (dm_handle_to_fshandle(hanp, hlen, &fshanp, &fshlen)) {
			fprintf(stderr, "can't get filesystem handle for file %s, %s\n",
				pathname, strerror(errno));
			exit(1);
		}
		dm_handle_free(hanp, hlen);
		hanp = fshanp;
		hlen = fshlen;
	}

	if (dm_set_return_on_destroy(sid, hanp, hlen, token,
	    attrnamep, enable)) {
		fprintf(stderr, "dm_set_return_on_destroy failed, %s\n",
			strerror(errno));
		exit(1);
	}

	dm_handle_free(hanp, hlen);
	exit(0);
}