Example #1
0
static int
chproj_f(
	int		argc,
	char		**argv)
{
	int		c;

	recurse_all = recurse_dir = 0;
	while ((c = getopt(argc, argv, "DR")) != EOF) {
		switch (c) {
		case 'D':
			recurse_all = 0;
			recurse_dir = 1;
			break;
		case 'R':
			recurse_all = 1;
			recurse_dir = 0;
			break;
		default:
			return command_usage(&chproj_cmd);
		}
	}

	if (argc != optind + 1)
		return command_usage(&chproj_cmd);

	prid = prid_from_string(argv[optind]);
	if (prid == -1) {
		printf(_("invalid project ID -- %s\n"), argv[optind]);
		return 0;
	}

	if (recurse_all || recurse_dir)
		nftw(file->name, chproj_callback,
			100, FTW_PHYS | FTW_MOUNT | FTW_DEPTH);
	else if (setprojid(file->name, file->fd, prid) < 0)
		perror("setprojid");
	return 0;
}
Example #2
0
static int
fs_table_initialise_projects(
	char		*project)
{
	fs_project_path_t *path;
	fs_path_t	*fs;
	prid_t		prid = 0;
	int		error = 0, found = 0;

	if (project)
		prid = prid_from_string(project);

	setprpathent();
	while ((path = getprpathent()) != NULL) {
		if (project && prid != path->pp_prid)
			continue;
		fs = fs_mount_point_from_path(path->pp_pathname);
		if (!fs) {
			fprintf(stderr, _("%s: cannot find mount point for path `%s': %s\n"),
					progname, path->pp_pathname, strerror(errno));
			continue;
		}
		(void) fs_table_insert(path->pp_pathname, path->pp_prid,
					FS_PROJECT_PATH, fs->fs_name,
					NULL, NULL);
		if (project) {
			found = 1;
			break;
		}
	}
	endprpathent();

	if (project && !found)
		error = ENOENT;

	return error;
}
Example #3
0
static int
project_f(
	int		argc,
	char		**argv)
{
	int		c, type = 0, ispath = 0;

	while ((c = getopt(argc, argv, "cd:p:sC")) != EOF) {
		switch (c) {
		case 'c':
			type = CHECK_PROJECT;
			break;
		case 'd':
			recurse_depth = atoi(optarg);
			if (recurse_depth < 0)
				recurse_depth = -1;
			break;
		case 'p':
			ispath = 1;
			fs_table_insert_project_path(optarg, -1);
			break;
		case 's':
			type = SETUP_PROJECT;
			break;
		case 'C':
			type = CLEAR_PROJECT;
			break;
		default:
			return command_usage(&project_cmd);
		}
	}

	if (argc == optind)
		return command_usage(&project_cmd);

	/* no options - just check the given projects */
	if (!type)
		type = CHECK_PROJECT;

	setprfiles();
	if (!ispath && access(projects_file, F_OK) != 0) {
		exitcode = 1;
		fprintf(stderr, _("projects file \"%s\" doesn't exist\n"),
			projects_file);
		return 0;
	}

	if (ispath && argc - optind > 1) {
		exitcode = 1;
		fprintf(stderr, _("%s: only one projid/name can be specified "
			    "when using -p <path>, %d found.\n"),
			progname, argc - optind);
		return 0;
	}

        while (argc > optind) {
		prid = prid_from_string(argv[optind]);
		if (prid == -1) {
			exitcode = 1;
			fprintf(stderr, _("%s - no such project in %s "
				    "or invalid project number\n"),
				argv[optind], projects_file);
		} else
	                project(argv[optind], type);
		optind++;
	}

	return 0;
}