Beispiel #1
0
int
main(
int argc,	/* Number of arguments */
char *argv[])	/* Argument pointer list */
{
#if defined(REMOTE)
	char *rpchost = NULL;
#endif /* defined(REMOTE) */
	int errors = 0;
	int c;

	/*
	 * Process arguments.
	 */
	while ((c = getopt(argc, argv, "h:")) != EOF) {
		switch (c) {

#if defined(REMOTE)
		case 'h':
			rpchost = strdup(optarg);
			break;
#endif /* defined(REMOTE) */

		case '?':
		default:
			errors++;
			break;
		}
	}

	if (optind  == argc || errors != 0) {
		(void)fprintf(stderr, "Usage:  %s [-h samhost] filename ...\n",
				argv[0]);
		exit(2);
	}
	
	
#if defined(REMOTE)
	if (sam_initrpc(rpchost) < 0) {
		perror("sam_initrpc");
		exit(1);
	}
#endif /* defined(REMOTE) */

	/*
	 * Do sam_stat() for all the files.
	 */
	while (optind < argc) {
		struct sam_stat sb;
		char *fname;
		int n;
	
		fname = argv[optind++];
		if (sam_stat(fname, &sb, sizeof(struct sam_stat)) == -1) {
			perror("sam_stat");
			exit(1);
		}
	
		/*
		 * Print out the POSIX stat() information.
		 */
		(void)printf("\nsam_stat of file:  %s\n", fname);
		(void)printf("mode=0%lo, ino=%ld, dev=%ld, nlink=%ld\n",
				sb.st_mode, sb.st_ino, sb.st_dev, sb.st_nlink);
		(void)printf("uid=%ld, gid=%ld\n",
				sb.st_uid, sb.st_gid);
		(void)printf("atime=%ld, mtime=%ld, ctime=%ld\n",
				sb.st_atime, sb.st_mtime, sb.st_ctime);
		if (!SS_ISSAMFS(sb.attr)) {
			(void)printf("\n");
			return(0);
		}
	
		/*
		 * Print out the SAM-FS information.
		 */
		(void)printf("attr:  %05x %s\n", sb.attr,
				sam_attrtoa(sb.attr, NULL));
		(void)printf("\n");
	
		/*
		 * Print out the information for each of the archive copies.
		 */
		(void)printf("copy  flags  vsns   posn.offset      media  vsn\n");
		for (n = 0; n < MAX_ARCHIVE; n++) {
			if (!(sb.copy[n].flags & CF_ARCHIVED))  continue;
			(void)printf("%d     %5x  %4d   0x%llx.%lx      %-5s  %s\n",
					n + 1, sb.copy[n].flags,
					sb.copy[n].n_vsns,
					sb.copy[n].position, sb.copy[n].offset,
					sb.copy[n].media, sb.copy[n].vsn);
		}
	}
#if defined(REMOTE)
	sam_closerpc();
#endif /* defined(REMOTE) */
	return(0);
}
Beispiel #2
0
int
main(
	int argc,	/* Number of arguments */
	char *argv[])	/* Argument pointer list */
{
	extern int optind;
	int c;
#if defined(REMOTE)
	char *opts = "h:dn";
	char *rpchost = NULL;
#else /* defined(REMOTE) */
	char *opts = "dn";
#endif /* defined(REMOTE) */

	/*
	 * Process arguments.
	 */
	while ((c = getopt(argc, argv, opts)) != EOF) {
		switch (c) {
		case 'd':
			Default = TRUE;
			break;

		case 'n':
			n_opt = TRUE;
			break;

#if defined(REMOTE)
		case 'h':
			rpchost = strdup(optarg);
			break;
#endif /* defined(REMOTE) */

		case '?':
		default:
			exit_status++;
		}
	}

	if (optind == argc)
		exit_status++;	/* No file name */

	if (exit_status != 0) {
		(void) fprintf(stderr,
		    "Usage: %s [-h samhost] [-d] [-n] filename", argv[0]);
		exit(2);
	}
#if defined(REMOTE)
	if (sam_initrpc(rpchost) < 0) {
		(void) fprintf(stderr, "sam_initrpc failed, errno %d.\n",
		    errno);
		exit(2);
	}
#endif /* defined(REMOTE) */

	/*
	 * Set up action.
	 */
	(void) memset(opns, 0, sizeof (opns));
	if (Default)
		*opn++ = 'd';
	if (n_opt)
		*opn++ = 'n';
	if (!Default && !n_opt)
		*opn++ = 'i';

	/*
	 * Process all file names.
	 */
	while (optind < argc) {
		char    *name = argv[optind++];

		(void) strncpy(fullpath, name, sizeof (fullpath) - 2);
		if (sam_lstat(fullpath, &sb, sizeof (struct sam_stat)) < 0) {
			perror("sam_lstat");
			continue;
		}
		if (!SS_ISSAMFS(sb.attr)) {
			perror("Not a SAM-FS file");
			continue;
		}
		if (sam_archive(name, opns) < 0) {
			perror("sam_archive");
			continue;
		}
	}
#if defined(REMOTE)
	sam_closerpc();
#endif /* defined(REMOTE) */
	return (exit_status);
}