示例#1
0
文件: main.c 项目: draekko/exfat
static int dump_full(const char* spec, bool used_sectors)
{
	struct exfat ef;
	uint32_t free_clusters;
	uint64_t free_sectors;

	if (exfat_mount(&ef, spec, "ro") != 0)
		return 1;

	free_clusters = exfat_count_free_clusters(&ef);
	free_sectors = (uint64_t) free_clusters << ef.sb->spc_bits;

	printf("Volume label         %15s\n", exfat_get_label(&ef));
	print_generic_info(ef.sb);
	print_sector_info(ef.sb);
	printf("Free sectors              %10"PRIu64"\n", free_sectors);
	print_cluster_info(ef.sb);
	printf("Free clusters             %10u\n", free_clusters);
	print_other_info(ef.sb);
	if (used_sectors)
		dump_sectors(&ef);

	exfat_unmount(&ef);
	return 0;
}
int main(int argc, char* argv[])
{
	char** pp;
	struct exfat ef;
	int rc = 0;

	for (pp = argv + 1; *pp; pp++)
		if (strcmp(*pp, "-V") == 0)
		{
			printf("exfatlabel %u.%u.%u\n", EXFAT_VERSION_MAJOR,
					EXFAT_VERSION_MINOR, EXFAT_VERSION_PATCH);
			puts("Copyright (C) 2011-2013  Andrew Nayenko");
			return 0;
		}

	if (argc != 2 && argc != 3)
	{
		fprintf(stderr, "Usage: %s [-V] <device> [label]\n", argv[0]);
		return 1;
	}

	if (argv[2])
	{
		if (exfat_mount(&ef, argv[1], "") != 0)
			return 1;
		rc = (exfat_set_label(&ef, argv[2]) != 0);
	}
	else
	{
		if (exfat_mount(&ef, argv[1], "ro") != 0)
			return 1;
		puts(exfat_get_label(&ef));
	}

	exfat_unmount(&ef);
	return rc;
}
int main(int argc, char* argv[])
{
	int opt;
	const char* spec = NULL;
	struct exfat ef;

	printf("exfatfsck %u.%u.%u\n",
			EXFAT_VERSION_MAJOR, EXFAT_VERSION_MINOR, EXFAT_VERSION_PATCH);

	while ((opt = getopt(argc, argv, "V")) != -1)
	{
		switch (opt)
		{
		case 'V':
			puts("Copyright (C) 2011-2013  Andrew Nayenko");
			return 0;
		default:
			usage(argv[0]);
			break;
		}
	}
	if (argc - optind != 1)
		usage(argv[0]);
	spec = argv[optind];

	if (exfat_mount(&ef, spec, "ro") != 0)
		return 1;

	printf("Checking file system on %s.\n", spec);
	fsck(&ef);
	exfat_unmount(&ef);
	printf("Totally %"PRIu64" directories and %"PRIu64" files.\n",
			directories_count, files_count);

	fputs("File system checking finished. ", stdout);
	if (exfat_errors != 0)
	{
		printf("ERRORS FOUND: %d.\n", exfat_errors);
		return 1;
	}
	puts("No errors found.");
	return 0;
}
示例#4
0
文件: main.c 项目: salass00/exfat
static void* fuse_exfat_init(struct fuse_conn_info* fci)
{
	struct exfat_mount_data* md;
	int err;
	exfat_debug("[%s]", __func__);
	md = fuse_get_context()->private_data;
	err = exfat_mount(&ef, md->device, md->options);
	if (err) {
		if (err == -EIO && errno == ENODEV)
			return NULL;
		else
			return (void*)-1;
	}
	if (ef.label[0])
	{
		strlcpy(fci->volume_name, ef.label, CONN_VOLUME_NAME_BYTES);
	}
	else
	{
		// make something up
		snprintf(fci->volume_name, CONN_VOLUME_NAME_BYTES, "exFAT-%s", md->device);
	}
	return (void*)1;
}
示例#5
0
int exfatfsck_main(int argc, char* argv[])
{
	int opt;
	const char* spec = NULL;
	struct exfat ef;
	bool do_fix = false;

	printf("exfatfsck %u.%u.%u\n",
			EXFAT_VERSION_MAJOR, EXFAT_VERSION_MINOR, EXFAT_VERSION_PATCH);

	while ((opt = getopt(argc, argv, "Vf")) != -1)
	{
		switch (opt)
		{
		case 'V':
			puts("Copyright (C) 2011-2014  Andrew Nayenko");
			return 0;
		case 'f':
			do_fix = true;
			break;
		default:
			usage(argv[0]);
			break;
		}
	}
	if (argc - optind != 1)
		usage(argv[0]);
	spec = argv[optind];

	if (exfat_mount(&ef, spec, "ro") != 0)
		return 1;

	printf("Checking file system on %s.\n", spec);
	fsck(&ef);
	printf("Totally %"PRIu64" directories and %"PRIu64" files.\n",
			directories_count, files_count);

	puts("File system checking finished.");

	if ( do_fix && exfat_errors == 0 && (le16_to_cpu(ef.sb->volume_state) & EXFAT_STATE_MOUNTED) != 0 )
	{
		puts("Closing the volume...");
		exfat_unmount(&ef);
		if ( exfat_mount(&ef, spec, "rw") != 0 )
		{
			puts("Failed to mount for writing!");
			puts("No errors found.");
			return 0;
		}
		ef.was_dirty = false; // The following unmount will clear EXFAT_STATE_MOUNTED!
		puts("Done!");
	}

	exfat_unmount(&ef);
	if ( exfat_errors != 0 )
	{
		printf("ERRORS FOUND: %d.\n", exfat_errors);
		return 1;
	}

	puts("No errors found.");
	return 0;
}
示例#6
0
int main(int argc, char* argv[])
{
	struct fuse_args mount_args = FUSE_ARGS_INIT(0, NULL);
	struct fuse_args newfs_args = FUSE_ARGS_INIT(0, NULL);
	const char* spec = NULL;
	const char* mount_point = NULL;
	char* mount_options;
	int debug = 0;
	struct fuse_chan* fc = NULL;
	struct fuse* fh = NULL;
	int opt;

	printf("FUSE exfat %u.%u.%u\n",
			EXFAT_VERSION_MAJOR, EXFAT_VERSION_MINOR, EXFAT_VERSION_PATCH);

	mount_options = strdup(default_options);
	if (mount_options == NULL)
	{
		exfat_error("failed to allocate options string");
		return 1;
	}

	while ((opt = getopt(argc, argv, "dno:Vv")) != -1)
	{
		switch (opt)
		{
		case 'd':
			debug = 1;
			break;
		case 'n':
			break;
		case 'o':
			mount_options = add_option(mount_options, optarg, NULL);
			if (mount_options == NULL)
				return 1;
			break;
		case 'V':
			free(mount_options);
			puts("Copyright (C) 2010-2014  Andrew Nayenko");
			return 0;
		case 'v':
			break;
		default:
			free(mount_options);
			usage(argv[0]);
			break;
		}
	}
	if (argc - optind != 2)
	{
		free(mount_options);
		usage(argv[0]);
	}
	spec = argv[optind];
	mount_point = argv[optind + 1];

	if (exfat_mount(&ef, spec, mount_options) != 0)
	{
		free(mount_options);
		return 1;
	}

	if (ef.ro == -1) /* read-only fallback was used */
	{
		mount_options = add_option(mount_options, "ro", NULL);
		if (mount_options == NULL)
		{
			exfat_unmount(&ef);
			return 1;
		}
	}

	mount_options = add_fuse_options(mount_options, spec);
	if (mount_options == NULL)
	{
		exfat_unmount(&ef);
		return 1;
	}

	/* create arguments for fuse_mount() */
	if (fuse_opt_add_arg(&mount_args, "exfat") != 0 ||
		fuse_opt_add_arg(&mount_args, "-o") != 0 ||
		fuse_opt_add_arg(&mount_args, mount_options) != 0)
	{
		exfat_unmount(&ef);
		free(mount_options);
		return 1;
	}

	free(mount_options);

	/* create FUSE mount point */
	fc = fuse_mount(mount_point, &mount_args);
	fuse_opt_free_args(&mount_args);
	if (fc == NULL)
	{
		exfat_unmount(&ef);
		return 1;
	}

	/* create arguments for fuse_new() */
	if (fuse_opt_add_arg(&newfs_args, "") != 0 ||
		(debug && fuse_opt_add_arg(&newfs_args, "-d") != 0))
	{
		fuse_unmount(mount_point, fc);
		exfat_unmount(&ef);
		return 1;
	}

	/* create new FUSE file system */
	fh = fuse_new(fc, &newfs_args, &fuse_exfat_ops,
			sizeof(struct fuse_operations), NULL);
	fuse_opt_free_args(&newfs_args);
	if (fh == NULL)
	{
		fuse_unmount(mount_point, fc);
		exfat_unmount(&ef);
		return 1;
	}

	/* exit session on HUP, TERM and INT signals and ignore PIPE signal */
	if (fuse_set_signal_handlers(fuse_get_session(fh)) != 0)
	{
		fuse_unmount(mount_point, fc);
		fuse_destroy(fh);
		exfat_unmount(&ef);
		exfat_error("failed to set signal handlers");
		return 1;
	}

	/* go to background (unless "-d" option is passed) and run FUSE
	   main loop */
	if (fuse_daemonize(debug) == 0)
	{
		if (fuse_loop(fh) != 0)
			exfat_error("FUSE loop failure");
	}
	else
		exfat_error("failed to daemonize");

	fuse_remove_signal_handlers(fuse_get_session(fh));
	/* note that fuse_unmount() must be called BEFORE fuse_destroy() */
	fuse_unmount(mount_point, fc);
	fuse_destroy(fh);
	return 0;
}
示例#7
0
/// open device
static void fs_open(char* device) {
    log_mesg(2, 0, 0, fs_opt.debug, "%s: exfat_mount\n", __FILE__);
    if (exfat_mount(&ef, device, "ro") != 0)
        log_mesg(0, 1, 1, fs_opt.debug, "%s: File system exfat open fail\n", __FILE__);
    log_mesg(2, 0, 0, fs_opt.debug, "%s: exfat_mount done\n", __FILE__);
}