Beispiel #1
0
static void
each_contact (const char *email, const char *name, gboolean personal,
	      time_t tstamp, ECData *ecdata)
{
	if (ecdata->personal && !personal)
		return;

	if (tstamp < ecdata->after)
		return;

	switch (ecdata->format) {
	case MU_CONFIG_FORMAT_MUTT_ALIAS:
		each_contact_mutt_alias (email, name);
		break;
	case MU_CONFIG_FORMAT_MUTT_AB:
		mu_util_print_encoded ("%s\t%s\t\n",
				       email, name ? name : "");
		break;
	case MU_CONFIG_FORMAT_WL:
		each_contact_wl (email, name);
		break;
	case MU_CONFIG_FORMAT_ORG_CONTACT:
		each_contact_org_contact (email, name);
		break;
	case MU_CONFIG_FORMAT_BBDB:
		each_contact_bbdb (email, name, tstamp);
		break;
        case MU_CONFIG_FORMAT_CSV:
		mu_util_print_encoded ("%s,%s\n", name ? name : "", email);
		break;
	default:
		print_plain (email, name, ecdata->color);
	}
}
Beispiel #2
0
int
fiemap_f(
	int		argc,
	char		**argv)
{
	struct fiemap	*fiemap;
	int		max_extents = 0;
	int		num_extents = 32;
	int		last = 0;
	int		lflag = 0;
	int		vflag = 0;
	int		fiemap_flags = FIEMAP_FLAG_SYNC;
	int		c;
	int		i;
	int		map_size;
	int		ret;
	int		cur_extent = 0;
	int		foff_w = 16;	/* 16 just for a good minimum range */
	int		boff_w = 16;
	int		tot_w = 5;	/* 5 since its just one number */
	int		flg_w = 5;
	__u64		blocksize = 512;
	__u64		last_logical = 0;
	struct stat	st;

	while ((c = getopt(argc, argv, "aln:v")) != EOF) {
		switch (c) {
		case 'a':
			fiemap_flags |= FIEMAP_FLAG_XATTR;
			break;
		case 'l':
			lflag = 1;
			break;
		case 'n':
			max_extents = atoi(optarg);
			break;
		case 'v':
			vflag++;
			break;
		default:
			return command_usage(&fiemap_cmd);
		}
	}

	if (max_extents)
		num_extents = min(num_extents, max_extents);
	map_size = sizeof(struct fiemap) +
		(num_extents * sizeof(struct fiemap_extent));
	fiemap = malloc(map_size);
	if (!fiemap) {
		fprintf(stderr, _("%s: malloc of %d bytes failed.\n"),
			progname, map_size);
		exitcode = 1;
		return 0;
	}

	printf("%s:\n", file->name);

	while (!last && ((cur_extent + 1) != max_extents)) {
		if (max_extents)
			num_extents = min(num_extents,
					  max_extents - (cur_extent + 1));

		memset(fiemap, 0, map_size);
		fiemap->fm_flags = fiemap_flags;
		fiemap->fm_start = last_logical;
		fiemap->fm_length = -1LL;
		fiemap->fm_extent_count = num_extents;

		ret = ioctl(file->fd, FS_IOC_FIEMAP, (unsigned long)fiemap);
		if (ret < 0) {
			fprintf(stderr, "%s: ioctl(FS_IOC_FIEMAP) [\"%s\"]: "
				"%s\n", progname, file->name, strerror(errno));
			free(fiemap);
			exitcode = 1;
			return 0;
		}

		/* No more extents to map, exit */
		if (!fiemap->fm_mapped_extents)
			break;

		for (i = 0; i < fiemap->fm_mapped_extents; i++) {
			struct fiemap_extent	*extent;

			extent = &fiemap->fm_extents[i];
			if (vflag) {
				if (cur_extent == 0) {
					calc_print_format(fiemap, blocksize,
							  &foff_w, &boff_w,
							  &tot_w, &flg_w);
				}
					
				print_verbose(extent, blocksize, foff_w,
					      boff_w, tot_w, flg_w,
					      max_extents, &cur_extent,
					      &last_logical);
			} else
				print_plain(extent, lflag, blocksize,
					    max_extents, &cur_extent,
					    &last_logical);

			if (extent->fe_flags & FIEMAP_EXTENT_LAST) {
				last = 1;
				break;
			}

			if ((cur_extent + 1) == max_extents)
				break;
		}
	}

	if ((cur_extent + 1) == max_extents)
		goto out;

	memset(&st, 0, sizeof(st));
	if (fstat(file->fd, &st)) {
		fprintf(stderr, "%s: fstat failed: %s\n", progname,
			strerror(errno));
		free(fiemap);
		exitcode = 1;
		return 0;
	}

	if (cur_extent && last_logical < st.st_size) {
		char	lbuf[32];

		snprintf(lbuf, sizeof(lbuf), "[%llu..%llu]:",
			 last_logical / blocksize, (st.st_size / blocksize) - 1);
		if (vflag) {
			printf("%4d: %-*s %-*s %*llu\n", cur_extent,
			       foff_w, lbuf, boff_w, _("hole"), tot_w,
			       (st.st_size - last_logical) / blocksize);
		} else {
			printf("\t%d: %s %s", cur_extent, lbuf,
			       _("hole"));
			if (lflag)
				printf(_(" %llu blocks\n"),
				       (st.st_size - last_logical) / blocksize);
			else
				printf("\n");
		}
	}

out:
	free(fiemap);
	return 0;
}