Esempio n. 1
0
/**
 * version - Print version information about the program
 *
 * Print a copyright statement and a brief description of the program.
 *
 * Return:  none
 */
static void version(void)
{
    ntfs_log_info("\n%s v%s (libntfs-3g) - Decrypt files and print on the "
                  "standard output.\n\n", EXEC_NAME, VERSION);
    ntfs_log_info("Copyright (c) 2005 Yuval Fledel\n");
    ntfs_log_info("Copyright (c) 2005 Anton Altaparmakov\n");
    ntfs_log_info("Copyright (c) 2014 Jean-Pierre Andre\n");
    ntfs_log_info("\n%s\n%s%s\n", ntfs_gpl, ntfs_bugs, ntfs_home);
}
Esempio n. 2
0
/**
 * version - Print version information about the program
 *
 * Print a copyright statement and a brief description of the program.
 *
 * Return:  none
 */
static void version(void)
{
	ntfs_log_info("\n%s v%s (libntfs-3g) - Find the owner of any given sector or "
			"cluster.\n\n", EXEC_NAME, VERSION);
	ntfs_log_info("Copyright (c) 2002-2003 Richard Russon\n");
	ntfs_log_info("Copyright (c) 2005 Anton Altaparmakov\n");
	ntfs_log_info("Copyright (c) 2005-2006 Szabolcs Szakacsits\n");
	ntfs_log_info("\n%s\n%s%s\n", ntfs_gpl, ntfs_bugs, ntfs_home);
}
Esempio n. 3
0
/**
 * usage - Print a list of the parameters to the program
 *
 * Print a list of the parameters and options for the program.
 *
 * Return:  none
 */
static void usage(void)
{
	ntfs_log_info("\nUsage: %s [options] device [label]\n"
	       "    -n, --no-action    Do not write to disk\n"
	       "    -f, --force        Use less caution\n"
	       "    -q, --quiet        Less output\n"
	       "    -v, --verbose      More output\n"
	       "    -V, --version      Display version information\n"
	       "    -h, --help         Display this help\n\n",
	       EXEC_NAME);
	ntfs_log_info("%s%s\n", ntfs_bugs, ntfs_home);
}
Esempio n. 4
0
/**
 * usage - Print a list of the parameters to the program
 *
 * Print a list of the parameters and options for the program.
 *
 * Return:  none
 */
static void usage(void)
{
    ntfs_log_info("\nUsage: %s [options] -k name.pfx device [file]\n\n"
                  "    -i, --inode num         Display this inode\n\n"
                  "    -k  --keyfile name.pfx  Use file name as the user's private key file.\n"
                  "    -f  --force             Use less caution\n"
                  "    -h  --help              Print this help\n"
                  "    -q  --quiet             Less output\n"
                  "    -V  --version           Version information\n"
                  "    -v  --verbose           More output\n\n",
                  EXEC_NAME);
    ntfs_log_info("%s%s\n", ntfs_bugs, ntfs_home);
}
Esempio n. 5
0
/**
 * usage - Print a list of the parameters to the program
 *
 * Print a list of the parameters and options for the program.
 *
 * Return:  none
 */
static void usage(void)
{
	ntfs_log_info("\nUsage: %s [options] device [file]\n\n"
		"    -a, --attribute TYPE       Display this attribute type\n"
		"    -n, --attribute-name NAME  Display this attribute name\n"
		"    -i, --inode NUM            Display this inode\n\n"
		"    -f, --force                Use less caution\n"
		"    -h, --help                 Print this help\n"
		"    -q, --quiet                Less output\n"
		"    -V, --version              Version information\n"
		"    -v, --verbose              More output\n\n",
// Does not work for compressed files at present so leave undocumented...
//		"    -r  --raw                  Display the raw data (e.g. for compressed or encrypted file)",
		EXEC_NAME);
	ntfs_log_info("%s%s\n", ntfs_bugs, ntfs_home);
}
Esempio n. 6
0
/**
 * print_label - display the current label of a mounted ntfs partition.
 * @dev:	device to read the label from
 * @mnt_flags:	mount flags of the device or 0 if not mounted
 * @mnt_point:	mount point of the device or NULL
 *
 * Print the label of the device @dev.
 */
static int print_label(ntfs_volume *vol, unsigned long mnt_flags)
{
	int result = 0;
	//XXX significant?
	if ((mnt_flags & (NTFS_MF_MOUNTED | NTFS_MF_READONLY)) ==
			NTFS_MF_MOUNTED) {
		ntfs_log_error("%s is mounted read-write, results may be "
			"unreliable.\n", opts.device);
		result = 1;
	}

	if (opts.verbose)
		ntfs_log_info("Volume label :  %s\n", vol->vol_name);
	else
		ntfs_log_info("%s\n", vol->vol_name);
	return result;
}
Esempio n. 7
0
int ntfs_get_efs_info(const char *path,
			char *value, size_t size, ntfs_inode *ni)
{
	EFS_ATTR_HEADER *efs_info;
	s64 attr_size = 0;

	if (ni) {
		if (ni->flags & FILE_ATTR_ENCRYPTED) {
			efs_info = (EFS_ATTR_HEADER*)ntfs_attr_readall(ni,
				AT_LOGGED_UTILITY_STREAM,(ntfschar*)NULL, 0,
				&attr_size);
			if (efs_info
			    && (le32_to_cpu(efs_info->length) == attr_size)) {
				if (attr_size <= (s64)size) {
					if (value)
						memcpy(value,efs_info,attr_size);
					else {
						errno = EFAULT;
						attr_size = 0;
					}
				} else
					if (size) {
						errno = ERANGE;
						attr_size = 0;
					}
				free (efs_info);
			} else {
				if (efs_info) {
					free(efs_info);
					ntfs_log_info("Bad efs_info for file %s\n",path);
				} else {
					ntfs_log_info("Could not get efsinfo"
						" for file %s\n", path);
				}
				errno = EIO;
				attr_size = 0;
			}
		} else {
			errno = ENODATA;
			ntfs_log_info("File %s is not encrypted",path); 
		}
	}
	return (attr_size ? (int)attr_size : -errno);
}
Esempio n. 8
0
/**
 * usage - Print a list of the parameters to the program
 *
 * Print a list of the parameters and options for the program.
 *
 * Return:  none
 */
static void usage(void)
{
	ntfs_log_info("\nUsage: %s [options] device\n"
		"    -i, --info           Print information about the volume (default)\n"
		"\n"
		"    -c, --cluster RANGE  Look for objects in this range of clusters\n"
		"    -s, --sector RANGE   Look for objects in this range of sectors\n"
		"    -I, --inode NUM      Show information about this inode\n"
		"    -F, --filename NAME  Show information about this file\n"
	/*	"    -l, --last           Find the last file on the volume\n" */
		"\n"
		"    -f, --force          Use less caution\n"
		"    -q, --quiet          Less output\n"
		"    -v, --verbose        More output\n"
		"    -V, --version        Version information\n"
		"    -h, --help           Print this help\n\n",
		EXEC_NAME);
	ntfs_log_info("%s%s\n", ntfs_bugs, ntfs_home);
}
Esempio n. 9
0
static int print_serial(ntfs_volume *vol)
{
	NTFS_BOOT_SECTOR *bs; /* full boot sectors */
	int res;

	res = -1;
	bs = (NTFS_BOOT_SECTOR*)ntfs_malloc(vol->sector_size);
	if (bs
	    && (ntfs_pread(vol->dev, 0,
			vol->sector_size, bs) == vol->sector_size)) {
		ntfs_log_info("Serial number : %016llx\n",
			(long long)le64_to_cpu(bs->volume_serial_number));
		res = 0;
		free(bs);
	}
	if (res)
		ntfs_log_info("Error getting the serial number\n");
	return (res);
}
Esempio n. 10
0
static int set_new_serial(ntfs_volume *vol)
{
	NTFS_BOOT_SECTOR *bs; /* full boot sectors */
	NTFS_BOOT_SECTOR *oldbs; /* full original boot sector */
	le64 serial_number;
	u64 number_of_sectors;
	u64 sn;
	int res;

	res = -1;
	bs = (NTFS_BOOT_SECTOR*)ntfs_malloc(vol->sector_size);
	oldbs = (NTFS_BOOT_SECTOR*)ntfs_malloc(vol->sector_size);
	if (bs && oldbs) {
		if (opts.serial)
			serial_number = cpu_to_le64(opts.serial);
		else {
			/* different values for parallel processes */
			srandom(time((time_t*)NULL) ^ (getpid() << 16));
			sn = ((u64)random() << 32)
					| ((u64)random() & 0xffffffff);
			serial_number = cpu_to_le64(sn);
		}
		if (!change_serial(vol, 0, serial_number, bs, oldbs)) {
			number_of_sectors = le64_to_cpu(bs->number_of_sectors);
			if (!change_serial(vol, number_of_sectors,
						serial_number, bs, oldbs)) {
				ntfs_log_info("New serial number : %016llx\n",
					(long long)le64_to_cpu(
						bs->volume_serial_number));
				res = 0;
				}
		}
		free(bs);
		free(oldbs);
	}
	if (res)
		ntfs_log_info("Error setting a new serial number\n");
	return (res);
}
Esempio n. 11
0
/**
 * version - Print version information about the program
 *
 * Print a copyright statement and a brief description of the program.
 *
 * Return:  none
 */
static void version(void)
{
	ntfs_log_info("\n%s v%s (libntfs-3g) - Display, or set, the label for an "
			"NTFS Volume.\n\n", EXEC_NAME, VERSION);
	ntfs_log_info("Copyright (c)\n");
	ntfs_log_info("    2002      Matthew J. Fanto\n");
	ntfs_log_info("    2002-2005 Anton Altaparmakov\n");
	ntfs_log_info("    2002-2003 Richard Russon\n");
	ntfs_log_info("    2012      Jean-Pierre Andre\n");
	ntfs_log_info("\n%s\n%s%s\n", ntfs_gpl, ntfs_bugs, ntfs_home);
}
Esempio n. 12
0
/**
 * version - Print version information about the program
 *
 * Print a copyright statement and a brief description of the program.
 *
 * Return:  none
 */
static void version(void)
{
	ntfs_log_info("\n%s v%s (libntfs-3g) - Concatenate files and print "
			"on the standard output.\n\n", EXEC_NAME, VERSION);
	ntfs_log_info("Copyright (c) 2003-2005 Richard Russon\n");
	ntfs_log_info("Copyright (c) 2003-2005 Anton Altaparmakov\n");
	ntfs_log_info("Copyright (c) 2003-2005 Szabolcs Szakacsits\n");
	ntfs_log_info("Copyright (c) 2007      Yura Pakhuchiy\n");
	ntfs_log_info("\n%s\n%s%s\n", ntfs_gpl, ntfs_bugs, ntfs_home);
}
Esempio n. 13
0
static int change_serial(ntfs_volume *vol, u64 sector, le64 serial_number,
			NTFS_BOOT_SECTOR *bs, NTFS_BOOT_SECTOR *oldbs)
{
	int res;
	le64 mask;
	BOOL same;

	res = -1;
        if ((ntfs_pread(vol->dev, sector << vol->sector_size_bits,
			vol->sector_size, bs) == vol->sector_size)) {
		same = TRUE;
		if (!sector)
				/* save the real bootsector */
			memcpy(oldbs, bs, vol->sector_size);
		else
				/* backup bootsector must be similar */
			same = !memcmp(oldbs, bs, vol->sector_size);
		if (same) {
			if (opts.new_serial & 2)
				bs->volume_serial_number = serial_number;
			else {
				mask = const_cpu_to_le64(~0x0ffffffffULL);
				bs->volume_serial_number
				    = (serial_number & mask)
					| (bs->volume_serial_number & ~mask);
			}
			if (opts.noaction
			    || (ntfs_pwrite(vol->dev,
				sector << vol->sector_size_bits,
				vol->sector_size, bs) == vol->sector_size)) {
				res = 0;
			}
		} else {
			ntfs_log_info("* Warning : the backup boot sector"
				" does not match (leaving unchanged)\n");
			res = 0;
		}
	}
	return (res);
}
Esempio n. 14
0
/**
 * dump_file
 */
static int dump_file(ntfs_volume *vol, ntfs_inode *ino)
{
	char buffer[1024];
	ntfs_attr_search_ctx *ctx;
	ATTR_RECORD *rec;
	int i;
	runlist *runs;

	utils_inode_get_name(ino, buffer, sizeof(buffer));

	ntfs_log_info("Dump: %s\n", buffer);

	ctx = ntfs_attr_get_search_ctx(ino, NULL);

	while ((rec = find_attribute(AT_UNUSED, ctx))) {
		ntfs_log_info("    0x%02x - ", rec->type);
		if (rec->non_resident) {
			ntfs_log_info("non-resident\n");
			runs = ntfs_mapping_pairs_decompress(vol, rec, NULL);
			if (runs) {
				ntfs_log_info("             VCN     LCN     Length\n");
				for (i = 0; runs[i].length > 0; i++) {
					ntfs_log_info("        %8lld %8lld %8lld\n",
							(long long)runs[i].vcn,
							(long long)runs[i].lcn,
							(long long)
							runs[i].length);
				}
				free(runs);
			}
		} else {
			ntfs_log_info("resident\n");
		}
	}

	ntfs_attr_put_search_ctx(ctx);
	return 0;
}
Esempio n. 15
0
/**
 * parse_options - Read and validate the programs command line
 * Read the command line, verify the syntax and parse the options.
 *
 * Return:   0 success, -1 error.
 */
int ntfs_parse_options(struct ntfs_options *popts, void (*usage)(void),
			int argc, char *argv[])
{
	int c;

	static const char *sopt = "-o:hnvV";
	static const struct option lopt[] = {
		{ "options",	 required_argument,	NULL, 'o' },
		{ "help",	 no_argument,		NULL, 'h' },
		{ "no-mtab",	 no_argument,		NULL, 'n' },
		{ "verbose",	 no_argument,		NULL, 'v' },
		{ "version",	 no_argument,		NULL, 'V' },
		{ NULL,		 0,			NULL,  0  }
	};

	opterr = 0; /* We'll handle the errors, thank you. */

	while ((c = getopt_long(argc, argv, sopt, lopt, NULL)) != -1) {
		switch (c) {
		case 1:	/* A non-option argument */
			if (!popts->device) {
				popts->device = ntfs_malloc(PATH_MAX + 1);
				if (!popts->device)
					return -1;
				
				/* Canonicalize device name (mtab, etc) */
				popts->arg_device = optarg;
				if (!ntfs_realpath_canonicalize(optarg,
						popts->device)) {
					ntfs_log_perror("%s: Failed to access "
					     "volume '%s'", EXEC_NAME, optarg);
					free(popts->device);
					popts->device = NULL;
					return -1;
				}
			} else if (!popts->mnt_point) {
				popts->mnt_point = optarg;
			} else {
				ntfs_log_error("%s: You must specify exactly one "
						"device and exactly one mount "
						"point.\n", EXEC_NAME);
				return -1;
			}
			break;
		case 'o':
			if (popts->options)
				if (ntfs_strappend(&popts->options, ","))
					return -1;
			if (ntfs_strappend(&popts->options, optarg))
				return -1;
			break;
		case 'h':
			usage();
			exit(9);
		case 'n':
			/*
			 * no effect - automount passes it, meaning 'no-mtab'
			 */
			break;
		case 'v':
			/*
			 * We must handle the 'verbose' option even if
			 * we don't use it because mount(8) passes it.
			 */
			break;
		case 'V':
			ntfs_log_info("%s %s %s %d\n", EXEC_NAME, VERSION, 
				      FUSE_TYPE, fuse_version());
			exit(0);
		default:
			ntfs_log_error("%s: Unknown option '%s'.\n", EXEC_NAME,
				       argv[optind - 1]);
			return -1;
		}
	}

	if (!popts->device) {
		ntfs_log_error("%s: No device is specified.\n", EXEC_NAME);
		return -1;
	}
	if (!popts->mnt_point) {
		ntfs_log_error("%s: No mountpoint is specified.\n", EXEC_NAME);
		return -1;
	}

	return 0;
}
Esempio n. 16
0
char *parse_mount_options(ntfs_fuse_context_t *ctx,
			const struct ntfs_options *popts, BOOL low_fuse)
{
	char *options, *s, *opt, *val, *ret = NULL;
	const char *orig_opts = popts->options;
	BOOL no_def_opts = FALSE;
	int default_permissions = 0;
	int permissions = 0;
	int acl = 0;
	int want_permissions = 0;
	int intarg;
	const struct DEFOPTION *poptl;

	ctx->secure_flags = 0;
#ifdef HAVE_SETXATTR	/* extended attributes interface required */
	ctx->efs_raw = FALSE;
#endif /* HAVE_SETXATTR */
	ctx->compression = DEFAULT_COMPRESSION;
	options = strdup(orig_opts ? orig_opts : "");
	if (!options) {
		ntfs_log_perror("%s: strdup failed", EXEC_NAME);
		return NULL;
	}
	
	s = options;
	while (s && *s && (val = strsep(&s, ","))) {
		opt = strsep(&val, "=");
		poptl = optionlist;
		while (poptl->name && strcmp(poptl->name,opt))
			poptl++;
		if (poptl->name) {
			if ((poptl->flags & FLGOPT_BOGUS)
			    && bogus_option_value(val, opt))
				goto err_exit;
			if ((poptl->flags & FLGOPT_OCTAL)
			    && (!val
				|| !sscanf(val, "%o", &intarg))) {
				ntfs_log_error("'%s' option needs an octal value\n",
					opt);
				goto err_exit;
			}
			if (poptl->flags & FLGOPT_DECIMAL) {
				if ((poptl->flags & FLGOPT_OPTIONAL) && !val)
					intarg = 0;
				else
					if (!val
					    || !sscanf(val, "%i", &intarg)) {
						ntfs_log_error("'%s' option "
						     "needs a decimal value\n",
							opt);
						goto err_exit;
					}
			}
			if ((poptl->flags & FLGOPT_STRING)
			    && missing_option_value(val, opt))
				goto err_exit;

			switch (poptl->type) {
			case OPT_RO :
			case OPT_FAKE_RW :
				ctx->ro = TRUE;
				break;
			case OPT_NOATIME :
				ctx->atime = ATIME_DISABLED;
				break;
			case OPT_ATIME :
				ctx->atime = ATIME_ENABLED;
				break;
			case OPT_RELATIME :
				ctx->atime = ATIME_RELATIVE;
				break;
			case OPT_DMTIME :
				if (!intarg)
					intarg = DEFAULT_DMTIME;
				ctx->dmtime = intarg*10000000LL;
				break;
			case OPT_NO_DEF_OPTS :
				no_def_opts = TRUE; /* Don't add default options. */
				ctx->silent = FALSE; /* cancel default silent */
				break;
			case OPT_DEFAULT_PERMISSIONS :
				default_permissions = 1;
				break;
			case OPT_PERMISSIONS :
				permissions = 1;
				break;
#if POSIXACLS
			case OPT_ACL :
				acl = 1;
				break;
#endif
			case OPT_UMASK :
				ctx->dmask = ctx->fmask = intarg;
				want_permissions = 1;
				break;
			case OPT_FMASK :
				ctx->fmask = intarg;
			       	want_permissions = 1;
				break;
			case OPT_DMASK :
				ctx->dmask = intarg;
			       	want_permissions = 1;
				break;
			case OPT_UID :
				ctx->uid = intarg;
			       	want_permissions = 1;
				break;
			case OPT_GID :
				ctx->gid = intarg;
				want_permissions = 1;
				break;
			case OPT_SHOW_SYS_FILES :
				ctx->show_sys_files = TRUE;
				break;
			case OPT_HIDE_HID_FILES :
				ctx->hide_hid_files = TRUE;
				break;
			case OPT_HIDE_DOT_FILES :
				ctx->hide_dot_files = TRUE;
				break;
			case OPT_WINDOWS_NAMES :
				ctx->windows_names = TRUE;
				break;
			case OPT_IGNORE_CASE :
				if (low_fuse)
					ctx->ignore_case = TRUE;
				else {
					ntfs_log_error("'%s' is an unsupported option.\n",
						poptl->name);
					goto err_exit;
				}
				break;
			case OPT_COMPRESSION :
				ctx->compression = TRUE;
				break;
			case OPT_NOCOMPRESSION :
				ctx->compression = FALSE;
				break;
			case OPT_SILENT :
				ctx->silent = TRUE;
				break;
			case OPT_RECOVER :
				ctx->recover = TRUE;
				break;
			case OPT_NORECOVER :
				ctx->recover = FALSE;
				break;
			case OPT_REMOVE_HIBERFILE :
				ctx->hiberfile = TRUE;
				break;
			case OPT_SYNC :
				ctx->sync = TRUE;
				break;
#ifdef FUSE_CAP_BIG_WRITES
			case OPT_BIG_WRITES :
				ctx->big_writes = TRUE;
				break;
#endif
			case OPT_LOCALE :
				ntfs_set_char_encoding(val);
				break;
#if defined(__APPLE__) || defined(__DARWIN__)
#ifdef ENABLE_NFCONV
			case OPT_NFCONV :
				if (ntfs_macosx_normalize_filenames(1)) {
					ntfs_log_error("ntfs_macosx_normalize_filenames(1) failed!\n");
					goto err_exit;
				}
				break;
			case OPT_NONFCONV :
				if (ntfs_macosx_normalize_filenames(0)) {
					ntfs_log_error("ntfs_macosx_normalize_filenames(0) failed!\n");
					goto err_exit;
				}
				break;
#endif /* ENABLE_NFCONV */
#endif /* defined(__APPLE__) || defined(__DARWIN__) */
			case OPT_STREAMS_INTERFACE :
				if (!strcmp(val, "none"))
					ctx->streams = NF_STREAMS_INTERFACE_NONE;
				else if (!strcmp(val, "xattr"))
					ctx->streams = NF_STREAMS_INTERFACE_XATTR;
				else if (!strcmp(val, "openxattr"))
					ctx->streams = NF_STREAMS_INTERFACE_OPENXATTR;
				else if (!low_fuse && !strcmp(val, "windows"))
					ctx->streams = NF_STREAMS_INTERFACE_WINDOWS;
				else {
					ntfs_log_error("Invalid named data streams "
						"access interface.\n");
					goto err_exit;
				}
				break;
			case OPT_USER_XATTR :
				ctx->streams = NF_STREAMS_INTERFACE_XATTR;
				break;
			case OPT_NOAUTO :
				/* Don't pass noauto option to fuse. */
				break;
			case OPT_DEBUG :
				ctx->debug = TRUE;
				ntfs_log_set_levels(NTFS_LOG_LEVEL_DEBUG);
				ntfs_log_set_levels(NTFS_LOG_LEVEL_TRACE);
				break;
			case OPT_NO_DETACH :
				ctx->no_detach = TRUE;
				break;
			case OPT_REMOUNT :
				ntfs_log_error("Remounting is not supported at present."
					" You have to umount volume and then "
					"mount it once again.\n");
				goto err_exit;
			case OPT_BLKSIZE :
				ntfs_log_info("WARNING: blksize option is ignored "
				      "because ntfs-3g must calculate it.\n");
				break;
			case OPT_INHERIT :
				/*
				 * do not overwrite inherited permissions
				 * in create()
				 */
				ctx->inherit = TRUE;
				break;
			case OPT_ADDSECURIDS :
				/*
				 * create security ids for files being read
				 * with an individual security attribute
				 */
				ctx->secure_flags |= (1 << SECURITY_ADDSECURIDS);
				break;
			case OPT_STATICGRPS :
				/*
				 * use static definition of groups
				 * for file access control
				 */
				ctx->secure_flags |= (1 << SECURITY_STATICGRPS);
				break;
			case OPT_USERMAPPING :
				ctx->usermap_path = strdup(val);
				if (!ctx->usermap_path) {
					ntfs_log_error("no more memory to store "
						"'usermapping' option.\n");
					goto err_exit;
				}
				break;
#ifdef HAVE_SETXATTR	/* extended attributes interface required */
#ifdef XATTR_MAPPINGS
			case OPT_XATTRMAPPING :
				ctx->xattrmap_path = strdup(val);
				if (!ctx->xattrmap_path) {
					ntfs_log_error("no more memory to store "
						"'xattrmapping' option.\n");
					goto err_exit;
				}
				break;
#endif /* XATTR_MAPPINGS */
			case OPT_EFS_RAW :
				ctx->efs_raw = TRUE;
				break;
#endif /* HAVE_SETXATTR */
			case OPT_FSNAME : /* Filesystem name. */
			/*
			 * We need this to be able to check whether filesystem
			 * mounted or not.
			 *      (falling through to default)
			 */
			default :
				ntfs_log_error("'%s' is an unsupported option.\n",
					poptl->name);
				goto err_exit;
			}
			if ((poptl->flags & FLGOPT_APPEND)
			    && (ntfs_strappend(&ret, poptl->name)
				    || ntfs_strappend(&ret, ",")))
				goto err_exit;
		} else { /* Probably FUSE option. */
			if (ntfs_strappend(&ret, opt))
				goto err_exit;
			if (val) {
				if (ntfs_strappend(&ret, "="))
					goto err_exit;
				if (ntfs_strappend(&ret, val))
					goto err_exit;
			}
			if (ntfs_strappend(&ret, ","))
				goto err_exit;
		}
	}
	if (!no_def_opts && ntfs_strappend(&ret, def_opts))
		goto err_exit;
	if ((default_permissions || (permissions && !acl))
			&& ntfs_strappend(&ret, "default_permissions,"))
		goto err_exit;
			/* The atime options exclude each other */
	if (ctx->atime == ATIME_RELATIVE && ntfs_strappend(&ret, "relatime,"))
		goto err_exit;
	else if (ctx->atime == ATIME_ENABLED && ntfs_strappend(&ret, "atime,"))
		goto err_exit;
	else if (ctx->atime == ATIME_DISABLED && ntfs_strappend(&ret, "noatime,"))
		goto err_exit;
	
	if (ntfs_strappend(&ret, "fsname="))
		goto err_exit;
	if (ntfs_strappend(&ret, popts->device))
		goto err_exit;
	if (permissions && !acl)
		ctx->secure_flags |= (1 << SECURITY_DEFAULT);
	if (acl)
		ctx->secure_flags |= (1 << SECURITY_ACL);
	if (want_permissions)
		ctx->secure_flags |= (1 << SECURITY_WANTED);
	if (ctx->ro)
		ctx->secure_flags &= ~(1 << SECURITY_ADDSECURIDS);
exit:
	free(options);
	return ret;
err_exit:
	free(ret);
	ret = NULL;
	goto exit;
}
Esempio n. 17
0
/**
 * info
 */
static int info(ntfs_volume *vol)
{
	u64 a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u;
	int cb, sb, cps;
	u64 uc = 0, mc = 0, fc = 0;

	struct mft_search_ctx *m_ctx;
	ntfs_attr_search_ctx *a_ctx;
	runlist_element *rl;
	ATTR_RECORD *rec;
	int z;
	int inuse = 0;

	m_ctx = mft_get_search_ctx(vol);
	m_ctx->flags_search = FEMR_IN_USE | FEMR_METADATA | FEMR_BASE_RECORD | FEMR_NOT_BASE_RECORD;
	while (mft_next_record(m_ctx) == 0) {

		if (!(m_ctx->flags_match & FEMR_IN_USE))
			continue;

		inuse++;

		a_ctx = ntfs_attr_get_search_ctx(m_ctx->inode, NULL);

		while ((rec = find_attribute(AT_UNUSED, a_ctx))) {

			if (!rec->non_resident)
				continue;

			rl = ntfs_mapping_pairs_decompress(vol, rec, NULL);

			for (z = 0; rl[z].length > 0; z++)
			{
				if (rl[z].lcn >= 0) {
					if (m_ctx->flags_match & FEMR_METADATA)
						mc += rl[z].length;
					else
						uc += rl[z].length;
				}

			}

			free(rl);
		}

		ntfs_attr_put_search_ctx(a_ctx);
	}
	mft_put_search_ctx(m_ctx);

	cb  = vol->cluster_size_bits;
	sb  = vol->sector_size_bits;
	cps = cb - sb;

	fc  = vol->nr_clusters-mc-uc;
	fc  <<= cb;
	mc  <<= cb;
	uc  <<= cb;

	a = vol->sector_size;
	b = vol->cluster_size;
	c = 1 << cps;
	d = vol->nr_clusters << cb;
	e = vol->nr_clusters;
	f = vol->nr_clusters >> cps;
	g = vol->mft_na->initialized_size >> vol->mft_record_size_bits;
	h = inuse;
	i = h * 100 / g;
	j = fc;
	k = fc >> sb;
	l = fc >> cb;
	m = fc * 100 / b / e;
	n = uc;
	o = uc >> sb;
	p = uc >> cb;
	q = uc * 100 / b / e;
	r = mc;
	s = mc >> sb;
	t = mc >> cb;
	u = mc * 100 / b / e;

	ntfs_log_info("bytes per sector        : %llu\n", (unsigned long long)a);
	ntfs_log_info("bytes per cluster       : %llu\n", (unsigned long long)b);
	ntfs_log_info("sectors per cluster     : %llu\n", (unsigned long long)c);
	ntfs_log_info("bytes per volume        : %llu\n", (unsigned long long)d);
	ntfs_log_info("sectors per volume      : %llu\n", (unsigned long long)e);
	ntfs_log_info("clusters per volume     : %llu\n", (unsigned long long)f);
	ntfs_log_info("initialized mft records : %llu\n", (unsigned long long)g);
	ntfs_log_info("mft records in use      : %llu\n", (unsigned long long)h);
	ntfs_log_info("mft records percentage  : %llu\n", (unsigned long long)i);
	ntfs_log_info("bytes of free space     : %llu\n", (unsigned long long)j);
	ntfs_log_info("sectors of free space   : %llu\n", (unsigned long long)k);
	ntfs_log_info("clusters of free space  : %llu\n", (unsigned long long)l);
	ntfs_log_info("percentage free space   : %llu\n", (unsigned long long)m);
	ntfs_log_info("bytes of user data      : %llu\n", (unsigned long long)n);
	ntfs_log_info("sectors of user data    : %llu\n", (unsigned long long)o);
	ntfs_log_info("clusters of user data   : %llu\n", (unsigned long long)p);
	ntfs_log_info("percentage user data    : %llu\n", (unsigned long long)q);
	ntfs_log_info("bytes of metadata       : %llu\n", (unsigned long long)r);
	ntfs_log_info("sectors of metadata     : %llu\n", (unsigned long long)s);
	ntfs_log_info("clusters of metadata    : %llu\n", (unsigned long long)t);
	ntfs_log_info("percentage metadata     : %llu\n", (unsigned long long)u);

	return 0;
}
Esempio n. 18
0
static void usage(void)
{
	ntfs_log_info(usage_msg, EXEC_NAME, VERSION, EXEC_NAME, ntfs_home);
}