Skip to content

Commit

Permalink
Merge pull request #109 from johnwcchau/master
Browse files Browse the repository at this point in the history
Add option to call fsync() before close() during mtp_op_SendObject()
  • Loading branch information
jfdelnero authored Oct 5, 2024
2 parents 1252d59 + 662de15 commit 3a85b68
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
8 changes: 8 additions & 0 deletions conf/umtprd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ usb_dev_version 0x3008

# no_inotify 0x1

# Sync when close
# Set this option to 0x1 to request all file data to be flushed from the RAM buffer to the
# internal storage after transfer is completed, this prevents data loss in the case where
# user un-plugged a non-battery-powered device too soon when there are still buffered data
# stayed in the RAM

# sync_when_close 0x0

#
# Internal buffers size
#
Expand Down
2 changes: 2 additions & 0 deletions inc/mtp.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ typedef struct mtp_ctx_

int no_inotify;

int sync_when_close;

int uid,euid;
int gid,egid;

Expand Down
12 changes: 11 additions & 1 deletion src/mtp_cfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ enum
DEFAULT_UID_CMD,
DEFAULT_GID_CMD,

NO_INOTIFY
NO_INOTIFY,

SYNC_WHEN_CLOSE

};

Expand Down Expand Up @@ -478,6 +480,9 @@ static int get_hex_param(mtp_ctx * context, char * line,int cmd)
context->no_inotify = param_value;
break;

case SYNC_WHEN_CLOSE:
context->sync_when_close = param_value;

}
}

Expand Down Expand Up @@ -617,6 +622,8 @@ kw_list kwlist[] =

{"no_inotify", get_hex_param, NO_INOTIFY},

{"sync_when_close", get_hex_param, SYNC_WHEN_CLOSE},

{ 0, 0, 0 }
};

Expand Down Expand Up @@ -702,6 +709,7 @@ int mtp_load_config_file(mtp_ctx * context, const char * conffile)
context->default_uid = -1;

context->no_inotify = 0;
context->sync_when_close = 0;

f = fopen(conffile, "r");
if(f)
Expand Down Expand Up @@ -787,5 +795,7 @@ int mtp_load_config_file(mtp_ctx * context, const char * conffile)

PRINT_MSG("inotify : %s",context->no_inotify?"no":"yes");

PRINT_MSG("Sync when close : %s",context->sync_when_close?"yes":"no");

return err;
}
1 change: 1 addition & 0 deletions src/mtp_operations/mtp_op_sendobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ uint32_t mtp_op_SendObject(mtp_ctx * ctx,MTP_PACKET_HEADER * mtp_packet_hdr, int

ctx->transferring_file_data = 0;

if (ctx->sync_when_close) fsync(file);
close(file);

if(ctx->usb_cfg.val_umask >= 0)
Expand Down

0 comments on commit 3a85b68

Please sign in to comment.