Implemented the sync mount option

PERMISSION_HANDLING_BRANCH
Jean-Pierre André 2010-10-26 08:59:51 +02:00
parent ecbc2b9103
commit 1afaf16912
4 changed files with 26 additions and 0 deletions

View File

@ -41,6 +41,7 @@ typedef enum {
ND_ReadOnly, /* 1: Device is read-only. */
ND_Dirty, /* 1: Device is dirty, needs sync. */
ND_Block, /* 1: Device is a block device. */
ND_Sync, /* 1: Device is mounted with "-o sync" */
} ntfs_device_state_bits;
#define test_ndev_flag(nd, flag) test_bit(ND_##flag, (nd)->d_state)
@ -63,6 +64,10 @@ typedef enum {
#define NDevSetBlock(nd) set_ndev_flag(nd, Block)
#define NDevClearBlock(nd) clear_ndev_flag(nd, Block)
#define NDevSync(nd) test_ndev_flag(nd, Sync)
#define NDevSetSync(nd) set_ndev_flag(nd, Sync)
#define NDevClearSync(nd) clear_ndev_flag(nd, Sync)
/**
* struct ntfs_device -
*

View File

@ -280,6 +280,9 @@ s64 ntfs_pwrite(struct ntfs_device *dev, const s64 pos, s64 count,
total = written;
break;
}
if (NDevSync(dev) && total && dops->sync(dev)) {
total--; /* on sync error, return partially written */
}
ret = total;
out:
return ret;

View File

@ -217,6 +217,7 @@ typedef struct {
BOOL silent;
BOOL recover;
BOOL hiberfile;
BOOL sync;
BOOL debug;
BOOL no_detach;
BOOL blkdev;
@ -3671,6 +3672,8 @@ static int ntfs_open(const char *device)
ntfs_log_perror("Failed to mount '%s'", device);
goto err_out;
}
if (ctx->sync && ctx->vol->dev)
NDevSetSync(ctx->vol->dev);
if (ctx->compression)
NVolSetCompression(ctx->vol);
#ifdef HAVE_SETXATTR
@ -3893,6 +3896,12 @@ static char *parse_mount_options(const char *orig_opts)
if (bogus_option_value(val, "remove_hiberfile"))
goto err_exit;
ctx->hiberfile = TRUE;
} else if (!strcmp(opt, "sync")) {
if (bogus_option_value(val, "sync"))
goto err_exit;
ctx->sync = TRUE;
if (strappend(&ret, "sync,"))
goto err_exit;
} else if (!strcmp(opt, "locale")) {
if (missing_option_value(val, "locale"))
goto err_exit;

View File

@ -177,6 +177,7 @@ typedef struct {
BOOL silent;
BOOL recover;
BOOL hiberfile;
BOOL sync;
BOOL debug;
BOOL no_detach;
BOOL blkdev;
@ -3628,6 +3629,8 @@ static int ntfs_open(const char *device)
ntfs_log_perror("Failed to mount '%s'", device);
goto err_out;
}
if (ctx->sync && ctx->vol->dev)
NDevSetSync(ctx->vol->dev);
if (ctx->compression)
NVolSetCompression(ctx->vol);
#ifdef HAVE_SETXATTR
@ -3843,6 +3846,12 @@ static char *parse_mount_options(const char *orig_opts)
if (bogus_option_value(val, "remove_hiberfile"))
goto err_exit;
ctx->hiberfile = TRUE;
} else if (!strcmp(opt, "sync")) {
if (bogus_option_value(val, "sync"))
goto err_exit;
ctx->sync = TRUE;
if (strappend(&ret, "sync,"))
goto err_exit;
} else if (!strcmp(opt, "locale")) {
if (missing_option_value(val, "locale"))
goto err_exit;