Rename legacy MS_* flags for ntfs_mount with NTFS_MNT_* flags.

The MS_* flags originated from system constants. However the flags
passed to ntfs_mount were really unrelated to the system constants and
many new MS_* flags had to be introduced as different features were
added to the library. Those flags had no counterparts in any system
APIs, so using the same naming scheme is inappropriate.

Instead, let's namespace these flags similarly to what has already been
done in ntfsprogs/libntfs earlier. This avoids any possible conflicts
with system constants.
The values of the flags themselves are kept the same as earlier, so
backward compatibility is retained.
edge.strict_endians
Erik Larsson 2012-11-07 16:29:48 +01:00
parent ebb38c4b1c
commit 7506d8b80b
26 changed files with 89 additions and 88 deletions

View File

@ -43,23 +43,6 @@
#include <mntent.h>
#endif
/*
* Under Cygwin, DJGPP and FreeBSD we do not have MS_RDONLY,
* so we define them ourselves.
*/
#ifndef MS_RDONLY
#define MS_RDONLY 1
#endif
#define MS_EXCLUSIVE 0x08000000
#ifndef MS_RECOVER
#define MS_RECOVER 0x10000000
#endif
#define MS_IGNORE_HIBERFILE 0x20000000
#define MS_FORENSIC 0x04000000 /* No modification during mount */
/* Forward declaration */
typedef struct _ntfs_volume ntfs_volume;
@ -74,13 +57,29 @@ typedef struct _ntfs_volume ntfs_volume;
/**
* enum ntfs_mount_flags -
*
* Flags for the ntfs_mount() function.
*/
enum {
NTFS_MNT_NONE = 0x00000000,
NTFS_MNT_RDONLY = 0x00000001,
NTFS_MNT_FORENSIC = 0x04000000, /* No modification during
* mount. */
NTFS_MNT_EXCLUSIVE = 0x08000000,
NTFS_MNT_RECOVER = 0x10000000,
NTFS_MNT_IGNORE_HIBERFILE = 0x20000000,
};
typedef unsigned long ntfs_mount_flags;
/**
* enum ntfs_mounted_flags -
*
* Flags returned by the ntfs_check_if_mounted() function.
*/
typedef enum {
NTFS_MF_MOUNTED = 1, /* Device is mounted. */
NTFS_MF_ISROOT = 2, /* Device is mounted as system root. */
NTFS_MF_READONLY = 4, /* Device is mounted read-only. */
} ntfs_mount_flags;
} ntfs_mounted_flags;
extern int ntfs_check_if_mounted(const char *file, unsigned long *mnt_flags);
@ -284,12 +283,12 @@ extern const char *ntfs_home;
extern ntfs_volume *ntfs_volume_alloc(void);
extern ntfs_volume *ntfs_volume_startup(struct ntfs_device *dev,
unsigned long flags);
ntfs_mount_flags flags);
extern ntfs_volume *ntfs_device_mount(struct ntfs_device *dev,
unsigned long flags);
ntfs_mount_flags flags);
extern ntfs_volume *ntfs_mount(const char *name, unsigned long flags);
extern ntfs_volume *ntfs_mount(const char *name, ntfs_mount_flags flags);
extern int ntfs_umount(ntfs_volume *vol, const BOOL force);
extern int ntfs_version_is_supported(ntfs_volume *vol);

View File

@ -466,7 +466,8 @@ error_exit:
* Return the allocated volume structure on success and NULL on error with
* errno set to the error code.
*/
ntfs_volume *ntfs_volume_startup(struct ntfs_device *dev, unsigned long flags)
ntfs_volume *ntfs_volume_startup(struct ntfs_device *dev,
ntfs_mount_flags flags)
{
LCN mft_zone_size, mft_lcn;
s64 br;
@ -508,7 +509,7 @@ ntfs_volume *ntfs_volume_startup(struct ntfs_device *dev, unsigned long flags)
#else
NVolClearCompression(vol);
#endif
if (flags & MS_RDONLY)
if (flags & NTFS_MNT_RDONLY)
NVolSetReadOnly(vol);
/* ...->open needs bracketing to compile with glibc 2.7 */
@ -887,7 +888,7 @@ static int fix_txf_data(ntfs_volume *vol)
* @flags is an optional second parameter. The same flags are used as for
* the mount system call (man 2 mount). Currently only the following flag
* is implemented:
* MS_RDONLY - mount volume read-only
* NTFS_MNT_RDONLY - mount volume read-only
*
* The function opens the device @dev and verifies that it contains a valid
* bootsector. Then, it allocates an ntfs_volume structure and initializes
@ -898,7 +899,7 @@ static int fix_txf_data(ntfs_volume *vol)
* Return the allocated volume structure on success and NULL on error with
* errno set to the error code.
*/
ntfs_volume *ntfs_device_mount(struct ntfs_device *dev, unsigned long flags)
ntfs_volume *ntfs_device_mount(struct ntfs_device *dev, ntfs_mount_flags flags)
{
s64 l;
ntfs_volume *vol;
@ -1226,13 +1227,13 @@ ntfs_volume *ntfs_device_mount(struct ntfs_device *dev, unsigned long flags)
* Check for dirty logfile and hibernated Windows.
* We care only about read-write mounts.
*/
if (!(flags & (MS_RDONLY | MS_FORENSIC))) {
if (!(flags & MS_IGNORE_HIBERFILE) &&
if (!(flags & (NTFS_MNT_RDONLY | NTFS_MNT_FORENSIC))) {
if (!(flags & NTFS_MNT_IGNORE_HIBERFILE) &&
ntfs_volume_check_hiberfile(vol, 1) < 0)
goto error_exit;
if (ntfs_volume_check_logfile(vol) < 0) {
/* Always reject cached metadata for now */
if (!(flags & MS_RECOVER) || (errno == EPERM))
if (!(flags & NTFS_MNT_RECOVER) || (errno == EPERM))
goto error_exit;
ntfs_log_info("The file system wasn't safely "
"closed on Windows. Fixing.\n");
@ -1321,7 +1322,7 @@ int ntfs_set_ignore_case(ntfs_volume *vol)
* @flags is an optional second parameter. The same flags are used as for
* the mount system call (man 2 mount). Currently only the following flags
* is implemented:
* MS_RDONLY - mount volume read-only
* NTFS_MNT_RDONLY - mount volume read-only
*
* The function opens the device or file @name and verifies that it contains a
* valid bootsector. Then, it allocates an ntfs_volume structure and initializes
@ -1336,7 +1337,7 @@ int ntfs_set_ignore_case(ntfs_volume *vol)
* soon as the function returns.
*/
ntfs_volume *ntfs_mount(const char *name __attribute__((unused)),
unsigned long flags __attribute__((unused)))
ntfs_mount_flags flags __attribute__((unused)))
{
#ifndef NO_NTFS_DEVICE_DEFAULT_IO_OPS
struct ntfs_device *dev;

View File

@ -410,8 +410,8 @@ int main(int argc, char *argv[])
utils_set_locale();
vol = utils_mount_volume(opts.device, MS_RDONLY |
(opts.force ? MS_RECOVER : 0));
vol = utils_mount_volume(opts.device, NTFS_MNT_RDONLY |
(opts.force ? NTFS_MNT_RECOVER : 0));
if (!vol) {
ntfs_log_perror("ERROR: couldn't mount volume");
return 1;

View File

@ -850,7 +850,7 @@ int main(int argc, char **argv)
// at this point we know that the volume is valid enough for mounting.
/* Call ntfs_device_mount() to do the actual mount. */
vol = ntfs_device_mount(dev, MS_RDONLY);
vol = ntfs_device_mount(dev, NTFS_MNT_RDONLY);
if (!vol) {
ntfs_device_free(dev);
return 2;

View File

@ -2178,7 +2178,7 @@ static s64 open_volume(void)
{
s64 device_size;
mount_volume(MS_RDONLY);
mount_volume(NTFS_MNT_RDONLY);
device_size = ntfs_device_size_get(vol->dev, 1);
if (device_size <= 0)
@ -2448,7 +2448,7 @@ int main(int argc, char **argv)
FIXME: use mount flags to avoid potential side-effects in future */
opt.force++;
ntfs_umount(vol,FALSE);
mount_volume(0 /*MS_NOATIME*/);
mount_volume(0 /*NTFS_MNT_NOATIME*/);
}
free(lcn_bitmap.bm);

View File

@ -491,8 +491,8 @@ int main(int argc, char *argv[])
utils_set_locale();
vol = utils_mount_volume(opts.device, MS_RDONLY |
(opts.force ? MS_RECOVER : 0));
vol = utils_mount_volume(opts.device, NTFS_MNT_RDONLY |
(opts.force ? NTFS_MNT_RECOVER : 0));
if (!vol)
return 1;

View File

@ -969,7 +969,7 @@ static ntfs_volume *mount_volume(const char *volume)
"You must 'umount' it first.\n", volume);
}
vol = ntfs_mount(volume, MS_RDONLY);
vol = ntfs_mount(volume, NTFS_MNT_RDONLY);
if (vol == NULL) {
int err = errno;

View File

@ -346,9 +346,9 @@ int main(int argc, char *argv[])
}
if (opts.noaction)
flags = MS_RDONLY;
flags = NTFS_MNT_RDONLY;
if (opts.force)
flags |= MS_RECOVER;
flags |= NTFS_MNT_RECOVER;
vol = utils_mount_volume(opts.device, flags);
if (!vol) {

View File

@ -1451,8 +1451,8 @@ int main(int argc, char *argv[])
return 1;
}
/* Mount the ntfs volume. */
vol = utils_mount_volume(opts.device, MS_RDONLY |
(opts.force ? MS_RECOVER : 0));
vol = utils_mount_volume(opts.device, NTFS_MNT_RDONLY |
(opts.force ? NTFS_MNT_RECOVER : 0));
if (!vol) {
ntfs_log_error("Failed to mount ntfs volume. Aborting.\n");
ntfs_rsa_private_key_release(rsa_key);

View File

@ -200,7 +200,7 @@ static int logfile_open(BOOL is_volume, const char *filename,
/* Porting note: NTFS_MNT_FORENSIC is not needed when we mount
* the volume in read-only mode. No changes will be made to the
* logfile or anything else when we are in read only-mode. */
vol = ntfs_mount(filename, MS_RDONLY);
vol = ntfs_mount(filename, NTFS_MNT_RDONLY);
if (!vol)
log_err_exit(NULL, "Failed to mount %s: %s\n",
filename, strerror(errno));

View File

@ -1419,7 +1419,7 @@ static int fix_startup(struct ntfs_device *dev, unsigned long flags)
NVolSetShowSysFiles(vol);
NVolSetShowHidFiles(vol);
NVolClearHideDotFiles(vol);
if (flags & MS_RDONLY)
if (flags & NTFS_MNT_RDONLY)
NVolSetReadOnly(vol);
/* ...->open needs bracketing to compile with glibc 2.7 */
@ -1508,7 +1508,7 @@ static int fix_mount(void)
ntfs_log_perror("Failed to allocate device");
return -1;
}
flags = (opt.no_action ? MS_RDONLY : 0);
flags = (opt.no_action ? NTFS_MNT_RDONLY : 0);
vol = ntfs_volume_startup(dev, flags);
if (!vol) {
ntfs_log_info(FAILED);
@ -1573,7 +1573,7 @@ int main(int argc, char **argv)
ntfs_log_perror("Failed to determine whether %s is mounted",
opt.volume);
/* Attempt a full mount first. */
flags = (opt.no_action ? MS_RDONLY : 0);
flags = (opt.no_action ? NTFS_MNT_RDONLY : 0);
ntfs_log_info("Mounting volume... ");
vol = ntfs_mount(opt.volume, flags);
if (vol) {

View File

@ -2334,8 +2334,8 @@ int main(int argc, char **argv)
utils_set_locale();
vol = utils_mount_volume(opts.device, MS_RDONLY |
(opts.force ? MS_RECOVER : 0));
vol = utils_mount_volume(opts.device, NTFS_MNT_RDONLY |
(opts.force ? NTFS_MNT_RECOVER : 0));
if (!vol) {
printf("Failed to open '%s'.\n", opts.device);
exit(1);

View File

@ -432,8 +432,8 @@ int main(int argc, char **argv)
opts.noaction++;
vol = utils_mount_volume(opts.device,
(opts.noaction ? MS_RDONLY : 0) |
(opts.force ? MS_RECOVER : 0));
(opts.noaction ? NTFS_MNT_RDONLY : 0) |
(opts.force ? NTFS_MNT_RECOVER : 0));
if (!vol)
return 1;

View File

@ -650,8 +650,8 @@ int main(int argc, char **argv)
utils_set_locale();
vol = utils_mount_volume(opts.device, MS_RDONLY |
(opts.force ? MS_RECOVER : 0));
vol = utils_mount_volume(opts.device, NTFS_MNT_RDONLY |
(opts.force ? NTFS_MNT_RECOVER : 0));
if (!vol) {
// FIXME: Print error... (AIA)
return 2;

View File

@ -312,7 +312,7 @@ int main(int argc, char **argv)
/* Mount the device. */
if (opts.no_action) {
ntfs_log_quiet("Running in READ-ONLY mode!\n");
ul = MS_RDONLY;
ul = NTFS_MNT_RDONLY;
} else
ul = 0;
vol = ntfs_mount(dev_name, ul);

View File

@ -876,9 +876,9 @@ int main(int argc, char *argv[])
utils_set_locale();
if (opts.noaction)
flags |= MS_RDONLY;
flags |= NTFS_MNT_RDONLY;
if (opts.force)
flags |= MS_RECOVER;
flags |= NTFS_MNT_RECOVER;
vol = utils_mount_volume(opts.device, flags);
if (!vol) {

View File

@ -529,7 +529,7 @@ static int parse_options(int argc, char **argv)
opt.infombonly++;
break;
case 'n':
opt.ro_flag = MS_RDONLY;
opt.ro_flag = NTFS_MNT_RDONLY;
break;
case 'P':
opt.show_progress = 0;
@ -568,7 +568,7 @@ static int parse_options(int argc, char **argv)
err++;
}
if (opt.info || opt.infombonly) {
opt.ro_flag = MS_RDONLY;
opt.ro_flag = NTFS_MNT_RDONLY;
}
if (opt.bytes
&& (opt.expand || opt.info || opt.infombonly)) {
@ -2562,11 +2562,12 @@ static ntfs_volume *check_volume(void)
ntfs_volume *myvol = NULL;
/*
* Pass MS_FORENSIC so that the mount process does not modify the
* Pass NTFS_MNT_FORENSIC so that the mount process does not modify the
* volume at all. We will do the logfile emptying and dirty setting
* later if needed.
*/
if (!(myvol = ntfs_mount(opt.volume, opt.ro_flag | MS_FORENSIC))) {
if (!(myvol = ntfs_mount(opt.volume, opt.ro_flag | NTFS_MNT_FORENSIC)))
{
int err = errno;
perr_printf("Opening '%s' as NTFS failed", opt.volume);

View File

@ -737,7 +737,7 @@ int main(int argc, char **argv)
/* Mount the device. */
if (opts.no_action) {
ntfs_log_quiet("Running in READ-ONLY mode!\n");
ul = MS_RDONLY;
ul = NTFS_MNT_RDONLY;
} else
ul = 0;
vol = ntfs_mount(dev_name, ul);

View File

@ -2254,8 +2254,8 @@ int main(int argc, char *argv[])
utils_set_locale();
vol = utils_mount_volume(opts.device, MS_RDONLY |
(opts.force ? MS_RECOVER : 0));
vol = utils_mount_volume(opts.device, NTFS_MNT_RDONLY |
(opts.force ? NTFS_MNT_RECOVER : 0));
if (!vol)
return 1;

View File

@ -2009,9 +2009,9 @@ int main(int argc, char *argv[])
print_summary();
if (opts.info || opts.noaction)
flags = MS_RDONLY;
flags = NTFS_MNT_RDONLY;
if (opts.force)
flags |= MS_RECOVER;
flags |= NTFS_MNT_RECOVER;
vol = utils_mount_volume(opts.device, flags);
if (!vol)

View File

@ -273,11 +273,11 @@ ntfs_volume * utils_mount_volume(const char *device, unsigned long flags)
*
* libntfs-3g only has safety check number 2. The dirty flag is simply
* ignored because we are confident that we can handle a dirty volume.
* So we treat MS_RECOVER like NTFS_MNT_FORCE, knowing that the first
* check is always bypassed.
* So we treat NTFS_MNT_RECOVER like NTFS_MNT_FORCE, knowing that the
* first check is always bypassed.
*/
if (!utils_valid_device(device, flags & MS_RECOVER))
if (!utils_valid_device(device, flags & NTFS_MNT_RECOVER))
return NULL;
vol = ntfs_mount(device, flags);
@ -303,7 +303,7 @@ ntfs_volume * utils_mount_volume(const char *device, unsigned long flags)
* before mount, so we can only warn if the VOLUME_IS_DIRTY flag is set
* in VOLUME_INFORMATION. */
if (vol->flags & VOLUME_IS_DIRTY) {
if (!(flags & MS_RECOVER)) {
if (!(flags & NTFS_MNT_RECOVER)) {
ntfs_log_error("%s", dirty_volume_msg);
ntfs_umount(vol, FALSE);
return NULL;

View File

@ -3501,13 +3501,13 @@ static int ntfs_open(const char *device)
ntfs_volume *vol;
if (!ctx->blkdev)
flags |= MS_EXCLUSIVE;
flags |= NTFS_MNT_EXCLUSIVE;
if (ctx->ro)
flags |= MS_RDONLY;
flags |= NTFS_MNT_RDONLY;
if (ctx->recover)
flags |= MS_RECOVER;
flags |= NTFS_MNT_RECOVER;
if (ctx->hiberfile)
flags |= MS_IGNORE_HIBERFILE;
flags |= NTFS_MNT_IGNORE_HIBERFILE;
ctx->vol = vol = ntfs_mount(device, flags);
if (!vol) {

View File

@ -3392,13 +3392,13 @@ static int ntfs_open(const char *device)
unsigned long flags = 0;
if (!ctx->blkdev)
flags |= MS_EXCLUSIVE;
flags |= NTFS_MNT_EXCLUSIVE;
if (ctx->ro)
flags |= MS_RDONLY;
flags |= NTFS_MNT_RDONLY;
if (ctx->recover)
flags |= MS_RECOVER;
flags |= NTFS_MNT_RECOVER;
if (ctx->hiberfile)
flags |= MS_IGNORE_HIBERFILE;
flags |= NTFS_MNT_IGNORE_HIBERFILE;
ctx->vol = ntfs_mount(device, flags);
if (!ctx->vol) {

View File

@ -68,7 +68,7 @@ static int ntfs_open(const char *device)
int ret = NTFS_VOLUME_OK;
if (opts.probetype == PROBE_READONLY)
flags |= MS_RDONLY;
flags |= NTFS_MNT_RDONLY;
vol = ntfs_mount(device, flags);
if (!vol)

View File

@ -331,8 +331,8 @@
#endif /* STSC */
#define MS_NONE 0 /* no flag for mounting the device */
#define MS_RDONLY 1 /* flag for mounting the device read-only */
#define NTFS_MNT_NONE 0 /* no flag for mounting the device */
#define NTFS_MNT_RDONLY 1 /* flag for mounting the device read-only */
struct CALLBACK;
@ -2869,7 +2869,7 @@ BOOL dorestore(const char *volume, FILE *fd)
err = FALSE;
if (!getuid()) {
if (open_security_api()) {
if (open_volume(volume,MS_NONE)) {
if (open_volume(volume,NTFS_MNT_NONE)) {
if (restore(fd)) err = TRUE;
close_volume(volume);
} else {
@ -5735,7 +5735,7 @@ BOOL backup(const char *volume, const char *root)
now = time((time_t*)NULL);
txtime = ctime(&now);
if (!getuid() && open_security_api()) {
if (open_volume(volume,MS_RDONLY)) {
if (open_volume(volume,NTFS_MNT_RDONLY)) {
printf("#\n# Recursive ACL collection on %s#\n",txtime);
err = recurseshow(root);
count = 0;
@ -5796,7 +5796,7 @@ BOOL listfiles(const char *volume, const char *root)
int count;
if (!getuid() && open_security_api()) {
if (open_volume(volume,MS_RDONLY)) {
if (open_volume(volume,NTFS_MNT_RDONLY)) {
if (opt_r) {
printf("\nRecursive file check\n");
err = recurseshow(root);
@ -5840,7 +5840,7 @@ BOOL mapproposal(const char *volume, const char *name)
err = FALSE;
if (!getuid() && open_security_api()) {
if (open_volume(volume,MS_RDONLY)) {
if (open_volume(volume,NTFS_MNT_RDONLY)) {
attrsz = 0;
securindex = ntfs_get_file_security(ntfs_context,name,
@ -6567,7 +6567,7 @@ BOOL audit(const char *volume)
err = FALSE;
if (!getuid() && open_security_api()) {
if (open_volume(volume,MS_RDONLY)) {
if (open_volume(volume,NTFS_MNT_RDONLY)) {
if (audit_sds(FALSE)) err = TRUE;
if (audit_sds(TRUE)) err = TRUE;
if (audit_sii()) err = TRUE;
@ -7508,7 +7508,7 @@ int main(int argc, char *argv[])
pxdesc = encode_posix_acl(p);
if (pxdesc) {
if (!getuid() && open_security_api()) {
if (open_volume(argv[xarg],MS_NONE)) {
if (open_volume(argv[xarg],NTFS_MNT_NONE)) {
if (opt_r) {
for (i=0; i<(MAXSECURID + (1 << SECBLKSZ) - 1)/(1 << SECBLKSZ); i++)
securdata[i] = (struct SECURITY_DATA*)NULL;
@ -7541,7 +7541,7 @@ int main(int argc, char *argv[])
cmderr = TRUE;
} else
if (!getuid() && open_security_api()) {
if (open_volume(argv[xarg],MS_NONE)) {
if (open_volume(argv[xarg],NTFS_MNT_NONE)) {
if (opt_r) {
for (i=0; i<(MAXSECURID + (1 << SECBLKSZ) - 1)/(1 << SECBLKSZ); i++)
securdata[i] = (struct SECURITY_DATA*)NULL;

View File

@ -154,8 +154,8 @@ typedef int BOOL; /* Already defined in windows.h */
typedef u32 DWORD; /* must be 32 bits whatever the platform */
typedef DWORD *LPDWORD;
#define MS_NONE 0 /* no flag for mounting the device */
#define MS_RDONLY 1 /* flag for mounting the device read-only */
#define NTFS_MNT_NONE 0 /* no flag for mounting the device */
#define NTFS_MNT_RDONLY 1 /* flag for mounting the device read-only */
#endif /* WIN32 */