Example #1
0
/*
 * Get the allocation info for a file. We pick some small number
 * of extents to get the residency info on at one time
 */
int
alloc_info(
	dm_sessid_t	 sid,
	void		*hanp,
	size_t		 hlen)
{
	int		i, more;
	dm_off_t	offset;
	u_int		nextents, nret;
	dm_extent_t	ext[NUM_EXTENTS];


	nextents = NUM_EXTENTS;
	offset   = 0;
	printf("\n\tAllocation info \n");
	do {
		more = dm_get_allocinfo(sid, hanp, hlen, DM_NO_TOKEN, &offset, 
					nextents, ext, &nret);
		if (more == -1) {
			errno_msg("Can't get alloc info for file");
			return(1);
		}
		for (i=0; i<nret; i++) {
			printf("\t\tExtent %d ", i);
			if (ext[i].ex_type == DM_EXTENT_RES)
				printf("(resident): ");
			if (ext[i].ex_type == DM_EXTENT_HOLE)
				printf("(hole): ");
			printf("offset %lld, ", (long long) ext[i].ex_offset);
			printf("len %llu\n", (unsigned long long) ext[i].ex_length);
		}
	} while (more == 1);
	return(0);
}
Example #2
0
int
main(int argc, char **argv) {
     
        dm_sessid_t	sid = DM_NO_SESSION;
	dm_token_t	token[NUM_TOKENS];
	dm_token_t	test_token;
	void		*fs_hanp;
	size_t		fs_hlen;
	void		*dir_hanp;
	size_t		dir_hlen;
	void		*ap;
	size_t		alen;
	void		*bp;
	size_t		blen;
	void		*cp;
	size_t		clen;
	char		*name;
	char		*ls_path;
	char		*pathname;
	char            fname_a[100];
	char            fname_b[100];
	char            fname_c[100];
	char            command[150];
	int		opt;
	int             i=0;

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

	opterr = 0;
	while ((opt = getopt(argc, argv, "vn:s:")) != EOF) {
		switch (opt) {
		case 'v':
		         Vflag++;
			 break;
		case 's': 
		         sid = atol(optarg);
			 break;
		case '?':
		         usage();
		}
	}
	if (optind + 2 != argc) {
		usage();
	}
	ls_path = argv[optind];
	pathname = argv[optind+1];

	if (dm_init_service(&name) == -1)  {
		fprintf(stderr, "Can't inititalize the DMAPI\n");
		exit(1);
	}
	if (sid == DM_NO_SESSION)
		find_test_session(&sid);
	
	printf("Beginning access rights testing...\n");

	sprintf(fname_a, "%s/DMAPI_rights_test_file_a", pathname);
	sprintf(command, "cp %s %s\n", ls_path, fname_a); 
	system(command);

	if (dm_path_to_handle(fname_a, &ap, &alen)) {
	  fprintf(stderr, "ERROR: can't get handle for %s; %s\n",
		  fname_a, ERR_NAME);
	  goto abort_test;
	}

	sprintf(fname_b, "%s/DMAPI_rights_test_file_b", pathname);
	sprintf(command, "cp %s %s\n", ls_path, fname_b); 
	system(command);
	
	if (dm_path_to_handle(fname_b, &bp, &blen)) {
	  fprintf(stderr, "ERROR: can't get handle for %s; %s\n",
		  fname_b, ERR_NAME);
	  goto abort_test;
	}

	sprintf(fname_c, "%s/DMAPI_rights_test_file_c", pathname);
	sprintf(command, "cp %s %s\n", ls_path, fname_c); 
	system(command);
	
	if (dm_path_to_handle(fname_c, &cp, &clen)) {
	  fprintf(stderr, "ERROR: can't get handle for %s; %s\n",
		  fname_c, ERR_NAME);
	  goto abort_test;
	}

	if (dm_path_to_fshandle(pathname, &fs_hanp, &fs_hlen)) {
	  fprintf(stderr, "ERROR: can't get handle for %s; %s\n",
		  pathname, ERR_NAME);
	  goto abort_test;
	}

	sprintf(pathname, "%s/DMAPI_rights_test_dir", pathname); 
	sprintf(command, "mkdir %s\n", pathname); 
	system(command);

	if (dm_path_to_handle(pathname, &dir_hanp, &dir_hlen)) {
	  fprintf(stderr, "ERROR: can't get handle for %s; %s\n",
		  pathname, ERR_NAME);
	  goto abort_test;
	}

	/* Test remaining functions for appropriate 
	 * right requirements...
	 *------------------------------------------------------------*/
	{ 
	  dm_off_t off = (dm_off_t)0;
	  dm_extent_t extent;
	  u_int nelem_ret;
	  SHAREDTEST("get_allocinfo", ap, alen, test_token,
		   dm_get_allocinfo(sid, ap, alen, test_token, 
				    &off, 1, &extent, &nelem_ret))
	}
	/*------------------------------------------------------------*/
	{ 
	  void *bufp=(void*)malloc(5*sizeof(dm_attrlist_t));
	  size_t rlen;
	  SHAREDTEST("getall_dmattr", ap, alen, test_token,
		   dm_getall_dmattr(sid, ap, alen, test_token, 
				    5, bufp, &rlen))
	}
	/*------------------------------------------------------------*/
	{ 
	  dm_attrloc_t loc;
	  SHAREDTEST("init_attrloc", dir_hanp, dir_hlen, test_token,
		     dm_init_attrloc(sid, dir_hanp, dir_hlen, test_token,
				     &loc))
	}
	/*------------------------------------------------------------*/
#if 0
	mkdir_by_handle is NOT SUPPORTED in current SGI DMAPI 

 	{ 
	  SHAREDTEST("mkdir_by_handle", fs_hanp, fs_hlen, test_token,
		     dm_mkdir_by_handle(sid, fs_hanp, fs_hlen, test_token,
					dir_hanp, dir_hlen, "FUBAR_DIR"))
	}
#endif
	/*------------------------------------------------------------*/
	{ dm_eventset_t eventset;
	  DMEV_ZERO(eventset);
	  EXCLTEST("set_disp", fs_hanp, fs_hlen, test_token,
		   dm_set_disp(sid, fs_hanp, fs_hlen, test_token,
			       &eventset, DM_EVENT_MAX))
	}
Example #3
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);
}
Example #4
0
static int
print_alloc(
	dm_sessid_t	sid,
	void		*hanp,
	size_t		hlen,
	char		*pathname,
	dm_off_t	startoff,
	u_int		nelem)
{
	dm_off_t	endoff;
	dm_extent_t	*extent;
	u_int		nelemp;
	u_int		num = 0;
	u_int		i;
	char		*type = NULL;
	int		rc;
	
	if (Dflag) fprintf(stdout, "%s: starting offset %lld\n", pathname, startoff);

	/* Allocate space for the number of extents requested by the user. */

	if ((extent = malloc(nelem * sizeof(*extent))) == NULL) {
		fprintf(stderr, "can't malloc extent structures\n");
		return(1);
	}

	rc = 1;
	endoff = startoff;

	while (rc != 0) {
	  rc = dm_get_allocinfo(sid, hanp, hlen, DM_NO_TOKEN, &startoff,
				nelem, extent, &nelemp);
	  if (rc < 0) {
	    fprintf(stderr, "dm_get_allocinfo failed, %s\n",
		    strerror(errno));
	    return(1);
	  }
	  
	  if (Dflag) fprintf(stdout, "\treturned %d, nelemp %d\n", rc, nelemp);
	  
	  if (Dflag && nelemp)
	    fprintf(stdout, " ex_type    ex_offset       ex_length\n");
		
	  /* Note: it is possible for nelemp to be zero! */
	  
	  for (i = 0; i < nelemp; i++) {
	    /* The extent must either be reserved space or a hole. */
	    switch (extent[i].ex_type) {
	    case DM_EXTENT_RES:
	      type = "resv";
	      break;
	    case DM_EXTENT_HOLE:
	      type = "hole";
	      break;
	    default:
	      fprintf(stderr, "invalid extent type %d\n",
		      extent[i].ex_type);
	      return(1);
	    }
	    
	    if (i!=nelemp-1 || rc!=0) {
	      if (!Dflag) {
		fprintf(stdout, "\t%d: [%lld..%lld]: %s", num,
			extent[i].ex_offset / 512,
			(extent[i].ex_offset +
			 extent[i].ex_length - 1) / 512, type);
		if ((extent[i].ex_offset % 512 != 0) ||
				    (endoff % 512 != 0)) {
		  fprintf(stdout, "\t[%lld..%lld]\n",
			  extent[i].ex_offset % 512,
			  (endoff-1) % 512);
		} else {
		  fprintf(stdout, "\n");
		}
	      } else {
		fprintf(stdout, "%5s	%13lld	%13lld\n",
			type, extent[i].ex_offset,
			extent[i].ex_length);
	      }
	    }
	    /* The ex_offset of the first extent should match the
	       'startoff' specified by the caller.  The ex_offset
	       in subsequent extents should always match
	       (ex_offset + ex_length) of the previous extent,
	       and should always start on a 512 byte boundary.
	       */
	    
	    if (extent[i].ex_offset != endoff) {
	      fprintf(stderr, "new extent (%lld)is not "
		      "adjacent to previous one (%lld)\n",
		      extent[i].ex_offset, endoff);
	      return(1);
	    }
	    if (num && (extent[i].ex_offset % 512) != 0) {
	      fprintf(stderr, "non-initial ex_offset (%lld) "
		      "is not a 512-byte multiple\n",
		      extent[i].ex_offset);
	      return(1);
	    }
	    
	    /* Non-initial extents should have ex_length values
	       that are an even multiple of 512.  The initial
	       extent should be a multiple of 512 less the offset
	       into the starting 512-byte block.
	       */
	    
	    if (((extent[i].ex_offset % 512) + extent[i].ex_length) % 512 != 0) { 
	      fprintf(stderr, "ex_length is incorrect based "
		      "upon the ex_offset\n");
	      return(1);
	    }
	    
	    endoff = extent[i].ex_offset + extent[i].ex_length;
	    num++;		/* count of extents printed */
	  }
	  
	  /* If not yet at end of file, the startoff parameter should
	     match the ex_offset plus ex_length of the last extent
	     retrieved.
	     */
	  
	  if (rc && startoff != endoff) {
	    fprintf(stderr, "startoff is %lld, should be %lld\n",
		    startoff, endoff);
	    return(1);
	  }
	  
	  /* If we are at end of file, the last extent should be a
	     hole.
	     */
	  
	  if (!rc && type && strcmp(type, "hole")) {
	    fprintf(stderr, "file didn't end with a hole\n");
	    return(1);
	  }
	}

	/* At end of file, startoff should always equal zero. */
	
	if (startoff != 0) {
	  fprintf(stderr, "startoff was not zero at end of file\n");
	  return(1);
	}
	return(0);
}