data = (struct locking_data *)dbuf.dptr;
lck->delete_on_close = data->u.s.delete_on_close;
+ lck->old_write_time = data->u.s.old_write_time;
+ lck->changed_write_time = data->u.s.changed_write_time;
lck->num_share_modes = data->u.s.num_share_mode_entries;
- DEBUG(10, ("parse_share_modes: delete_on_close: %d, "
- "num_share_modes: %d\n",
- lck->delete_on_close,
- lck->num_share_modes));
+ DEBUG(10, ("parse_share_modes: delete_on_close: %d, owrt: %s, "
+ "cwrt: %s, tok: %u, num_share_modes: %d\n",
+ lck->delete_on_close,
+ timestring(debug_ctx(),
+ convert_timespec_to_time_t(lck->old_write_time)),
+ timestring(debug_ctx(),
+ convert_timespec_to_time_t(
+ lck->changed_write_time)),
+ (unsigned int)data->u.s.delete_token_size,
+ lck->num_share_modes));
if ((lck->num_share_modes < 0) || (lck->num_share_modes > 1000000)) {
DEBUG(0, ("invalid number of share modes: %d\n",
ZERO_STRUCTP(data);
data->u.s.num_share_mode_entries = lck->num_share_modes;
data->u.s.delete_on_close = lck->delete_on_close;
+ data->u.s.old_write_time = lck->old_write_time;
+ data->u.s.changed_write_time = lck->changed_write_time;
data->u.s.delete_token_size = delete_token_size;
- DEBUG(10, ("unparse_share_modes: del: %d, tok = %u, num: %d\n",
- data->u.s.delete_on_close,
- (unsigned int)data->u.s.delete_token_size,
- data->u.s.num_share_mode_entries));
+
+ DEBUG(10,("unparse_share_modes: del: %d, owrt: %s cwrt: %s, tok: %u, "
+ "num: %d\n", data->u.s.delete_on_close,
+ timestring(debug_ctx(),
+ convert_timespec_to_time_t(lck->old_write_time)),
+ timestring(debug_ctx(),
+ convert_timespec_to_time_t(
+ lck->changed_write_time)),
+ (unsigned int)data->u.s.delete_token_size,
+ data->u.s.num_share_mode_entries));
+
memcpy(result.dptr + sizeof(*data), lck->share_modes,
sizeof(struct share_mode_entry)*lck->num_share_modes);
offset = sizeof(*data) +
struct file_id id,
const char *servicepath,
const char *fname,
- TDB_DATA share_mode_data)
+ TDB_DATA share_mode_data,
+ const struct timespec *old_write_time)
{
/* Ensure we set every field here as the destructor must be
valid even if parse_share_modes fails. */
lck->share_modes = NULL;
lck->delete_token = NULL;
lck->delete_on_close = False;
+ ZERO_STRUCT(lck->old_write_time);
+ ZERO_STRUCT(lck->changed_write_time);
lck->fresh = False;
lck->modified = False;
lck->fresh = (share_mode_data.dptr == NULL);
if (lck->fresh) {
- if (fname == NULL || servicepath == NULL) {
+ if (fname == NULL || servicepath == NULL
+ || old_write_time == NULL) {
return False;
}
lck->filename = talloc_strdup(lck, fname);
DEBUG(0, ("talloc failed\n"));
return False;
}
+ lck->old_write_time = *old_write_time;
} else {
if (!parse_share_modes(share_mode_data, lck)) {
DEBUG(0, ("Could not parse share modes\n"));
struct share_mode_lock *get_share_mode_lock(TALLOC_CTX *mem_ctx,
const struct file_id id,
const char *servicepath,
- const char *fname)
+ const char *fname,
+ const struct timespec *old_write_time)
{
struct share_mode_lock *lck;
struct file_id tmp;
}
if (!fill_share_mode_lock(lck, id, servicepath, fname,
- lck->record->value)) {
+ lck->record->value, old_write_time)) {
DEBUG(3, ("fill_share_mode_lock failed\n"));
TALLOC_FREE(lck);
return NULL;
return NULL;
}
- if (!fill_share_mode_lock(lck, id, servicepath, fname, data)) {
+ if (!fill_share_mode_lock(lck, id, servicepath, fname, data, NULL)) {
DEBUG(3, ("fill_share_mode_lock failed\n"));
TALLOC_FREE(lck);
return NULL;
return True;
}
+struct timespec get_write_time(struct file_id id)
+{
+ struct timespec result;
+ struct share_mode_lock *lck;
+
+ ZERO_STRUCT(result);
+
+ if (!(lck = fetch_share_mode_unlocked(talloc_tos(), id, NULL, NULL))) {
+ return result;
+ }
+ result = lck->changed_write_time;
+
+ if (null_timespec(result)) {
+ result = lck->old_write_time;
+ }
+
+ TALLOC_FREE(lck);
+ return result;
+}
+
bool get_delete_on_close_flag(struct file_id id)
{
bool result;
return True;
}
- lck = get_share_mode_lock(talloc_tos(), fsp->file_id, NULL, NULL);
+ lck = get_share_mode_lock(talloc_tos(), fsp->file_id, NULL, NULL,
+ NULL);
if (lck == NULL) {
return False;
}
return True;
}
+bool set_write_time(struct file_id fileid, struct timespec write_time,
+ bool overwrite)
+{
+ struct share_mode_lock *lck;
+
+ DEBUG(5,("set_write_time: %s overwrite=%d id=%s\n",
+ timestring(debug_ctx(),
+ convert_timespec_to_time_t(write_time)),
+ overwrite, file_id_string_tos(&fileid)));
+
+ lck = get_share_mode_lock(NULL, fileid, NULL, NULL, NULL);
+ if (lck == NULL) {
+ return False;
+ }
+
+ if (overwrite || null_timespec(lck->changed_write_time)) {
+ lck->modified = True;
+ lck->changed_write_time = write_time;
+ }
+
+ TALLOC_FREE(lck);
+ return True;
+}
+
struct forall_state {
void (*fn)(const struct share_mode_entry *entry,
const char *sharepath,
request_time = pml->request_time;
/* Remove the deferred open entry under lock. */
- lck = get_share_mode_lock(talloc_tos(), state->id, NULL, NULL);
+ lck = get_share_mode_lock(talloc_tos(), state->id, NULL, NULL,
+ NULL);
if (lck == NULL) {
DEBUG(0, ("could not get share mode lock\n"));
} else {
}
if (file_existed) {
+ struct timespec old_write_time = get_mtimespec(psbuf);
id = vfs_file_id_from_sbuf(conn, psbuf);
lck = get_share_mode_lock(talloc_tos(), id,
conn->connectpath,
- fname);
+ fname, &old_write_time);
if (lck == NULL) {
file_free(fsp);
}
if (!file_existed) {
-
+ struct timespec old_write_time = get_mtimespec(psbuf);
/*
* Deal with the race condition where two smbd's detect the
* file doesn't exist and do the create at the same time. One
lck = get_share_mode_lock(talloc_tos(), id,
conn->connectpath,
- fname);
+ fname, &old_write_time);
if (lck == NULL) {
DEBUG(0, ("open_file_ntcreate: Could not get share "
bool dir_existed = VALID_STAT(*psbuf) ? True : False;
struct share_mode_lock *lck = NULL;
NTSTATUS status;
+ struct timespec mtimespec;
int info = 0;
DEBUG(5,("open_directory: opening directory %s, access_mask = 0x%x, "
string_set(&fsp->fsp_name,fname);
+ mtimespec = get_mtimespec(psbuf);
+
lck = get_share_mode_lock(talloc_tos(), fsp->file_id,
conn->connectpath,
- fname);
+ fname, &mtimespec);
if (lck == NULL) {
DEBUG(0, ("open_directory: Could not get share mode lock for %s\n", fname));
struct share_mode_lock *lck;
/* Remove the oplock flag from the sharemode. */
- lck = get_share_mode_lock(talloc_tos(), fsp->file_id, NULL, NULL);
+ lck = get_share_mode_lock(talloc_tos(), fsp->file_id, NULL, NULL,
+ NULL);
if (lck == NULL) {
DEBUG(0,("remove_oplock: failed to lock share entry for "
"file %s\n", fsp->fsp_name ));
bool ret;
struct share_mode_lock *lck;
- lck = get_share_mode_lock(talloc_tos(), fsp->file_id, NULL, NULL);
+ lck = get_share_mode_lock(talloc_tos(), fsp->file_id, NULL, NULL,
+ NULL);
if (lck == NULL) {
DEBUG(0,("downgrade_oplock: failed to lock share entry for "
"file %s\n", fsp->fsp_name ));
if (!LEVEL_II_OPLOCK_TYPE(fsp->oplock_type))
return;
- lck = get_share_mode_lock(talloc_tos(), fsp->file_id, NULL, NULL);
+ lck = get_share_mode_lock(talloc_tos(), fsp->file_id, NULL, NULL,
+ NULL);
if (lck == NULL) {
DEBUG(0,("release_level_2_oplocks_on_change: failed to lock "
"share mode entry for file %s.\n", fsp->fsp_name ));