Ejemplo n.º 1
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);
}
Ejemplo n.º 2
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);
}
Ejemplo n.º 3
0
extern int
HsmInitFileContext(
	hsm_f_ctxt_t	*contextp,
const	xfs_bstat_t	*statp)
{
	dmf_f_ctxt_t	*dmf_f_ctxtp = (dmf_f_ctxt_t *)contextp;
	XFSattrvalue1_t	*dmfattrp;
	int		attrlen;
	void		*hanp;
	size_t		hlen;
	dm_ino_t	ino;
	dm_igen_t	igen;
	int		fd;
	int		error;

	dmf_f_ctxtp->candidate = 0; /* assume file will NOT be of interest */

	/* Try and rule out a dualstate inode by doing some quick tests. */

	if ((statp->bs_mode & S_IFMT) != S_IFREG) {
		return 0;	/* not a regular file */
	}
	if ((statp->bs_xflags & XFS_XFLAG_HASATTR) == 0) {
		return 0;	/* no DMF attribute exists */
	}
	if ((statp->bs_dmevmask & DUALSTATE_BITS) != DUALSTATE_BITS) {
		return 0;	/* non-dualstate managed region bits */
	}

	/* We have a likely candidate, so we have to pay the price and look
	   for the DMF attribute.  (It could be in a disk block separate from
	   the inode.)
	*/

	ino = (dm_ino_t)statp->bs_ino;
	igen = (dm_igen_t)statp->bs_gen;
	if (dm_make_handle(&dmf_f_ctxtp->fsys.fsid, &ino, &igen, &hanp, &hlen) != 0) {
		return 0;	/* can't make a proper handle */
	}

	/* The following code should eventually be replaced with the
	   attr_multif-by-handle call when it is available.
	*/

	fd = open_by_handle(hanp, hlen, O_RDONLY);
	dm_handle_free(hanp, hlen);
	if (fd < 0) {
                return 0;
	}
	attrlen = sizeof(dmf_f_ctxtp->attrval);
	error = attr_getf(fd, DMF_ATTR_NAME, dmf_f_ctxtp->attrval,
		&attrlen, ATTR_ROOT);
	(void)close(fd);
	if (error) {
		return 0;
 	}

	if (attrlen != DMF_ATTR_LEN) {
                return 0;	/* not the right length to be the attribute */
	}

	dmfattrp = (XFSattrvalue1_t *)dmf_f_ctxtp->attrval;
	if (dmfattrp->version != XFS_ATTR_VERSION_1) {
		return 0;	/* we don't support this version */
	}
	if (dmfattrp->state[0] != '\0') {
		return 0;	/* should be zero */
	}
	if (dmfattrp->state[1] != DMF_ST_DUALSTATE &&
	    dmfattrp->state[1] != DMF_ST_UNMIGRATING) {
		return 0;
	}

	/* We have a DMF dual state file. */

	dmf_f_ctxtp->candidate = 1;
	dmf_f_ctxtp->filesize = BTOBB(statp->bs_size);
	return 0;
}