2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 1992-2000
5 Copyright (C) Jeremy Allison 1992-2000
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 12 aug 96: Erik.Devriendt@te6.siemens.be
24 added support for shared memory implementation of share mode locking
26 May 1997. Jeremy Allison (jallison@whistle.com). Modified share mode
27 locking to deal with multiple share modes per open file.
29 September 1997. Jeremy Allison (jallison@whistle.com). Added oplock
32 rewrtten completely to use new tdb code. Tridge, Dec '99
34 Added POSIX locking support. Jeremy Allison (jeremy@valinux.com), Apr. 2000.
40 /* the locking database handle */
41 static TDB_CONTEXT
*tdb
;
43 /****************************************************************************
45 ****************************************************************************/
47 static const char *lock_type_name(enum brl_type lock_type
)
49 return (lock_type
== READ_LOCK
) ? "READ" : "WRITE";
52 /****************************************************************************
53 Utility function called to see if a file region is locked.
54 If check_self is True, then checks on our own fd with the same locking context
55 are still made. If check_self is False, then checks are not made on our own fd
56 with the same locking context are not made.
57 ****************************************************************************/
59 BOOL
is_locked(files_struct
*fsp
,connection_struct
*conn
,
60 SMB_BIG_UINT count
,SMB_BIG_UINT offset
,
61 enum brl_type lock_type
, BOOL check_self
)
63 int snum
= SNUM(conn
);
69 if (!lp_locking(snum
) || !lp_strict_locking(snum
))
72 ret
= !brl_locktest(fsp
->dev
, fsp
->inode
, fsp
->fnum
,
73 global_smbpid
, sys_getpid(), conn
->cnum
,
74 offset
, count
, lock_type
, check_self
);
76 DEBUG(10,("is_locked: brl start=%.0f len=%.0f %s for file %s\n",
77 (double)offset
, (double)count
, ret
? "locked" : "unlocked",
81 * There is no lock held by an SMB daemon, check to
82 * see if there is a POSIX lock from a UNIX or NFS process.
85 if(!ret
&& lp_posix_locking(snum
)) {
86 ret
= is_posix_locked(fsp
, offset
, count
, lock_type
);
88 DEBUG(10,("is_locked: posix start=%.0f len=%.0f %s for file %s\n",
89 (double)offset
, (double)count
, ret
? "locked" : "unlocked",
96 /****************************************************************************
97 Utility function called by locking requests.
98 ****************************************************************************/
100 static NTSTATUS
do_lock(files_struct
*fsp
,connection_struct
*conn
, uint16 lock_pid
,
101 SMB_BIG_UINT count
,SMB_BIG_UINT offset
,enum brl_type lock_type
, BOOL
*my_lock_ctx
)
103 NTSTATUS status
= NT_STATUS_LOCK_NOT_GRANTED
;
105 if (!lp_locking(SNUM(conn
)))
108 /* NOTE! 0 byte long ranges ARE allowed and should be stored */
110 DEBUG(10,("do_lock: lock type %s start=%.0f len=%.0f requested for file %s\n",
111 lock_type_name(lock_type
), (double)offset
, (double)count
, fsp
->fsp_name
));
113 if (OPEN_FSP(fsp
) && fsp
->can_lock
&& (fsp
->conn
== conn
)) {
114 status
= brl_lock(fsp
->dev
, fsp
->inode
, fsp
->fnum
,
115 lock_pid
, sys_getpid(), conn
->cnum
,
117 lock_type
, my_lock_ctx
);
119 if (NT_STATUS_IS_OK(status
) && lp_posix_locking(SNUM(conn
))) {
122 * Try and get a POSIX lock on this range.
123 * Note that this is ok if it is a read lock
124 * overlapping on a different fd. JRA.
127 if (!set_posix_lock(fsp
, offset
, count
, lock_type
)) {
128 if (errno
== EACCES
|| errno
== EAGAIN
)
129 status
= NT_STATUS_FILE_LOCK_CONFLICT
;
131 status
= map_nt_error_from_unix(errno
);
134 * We failed to map - we must now remove the brl
137 (void)brl_unlock(fsp
->dev
, fsp
->inode
, fsp
->fnum
,
138 lock_pid
, sys_getpid(), conn
->cnum
,
139 offset
, count
, False
,
148 /****************************************************************************
149 Utility function called by locking requests. This is *DISGUSTING*. It also
150 appears to be "What Windows Does" (tm). Andrew, ever wonder why Windows 2000
151 is so slow on the locking tests...... ? This is the reason. Much though I hate
152 it, we need this. JRA.
153 ****************************************************************************/
155 NTSTATUS
do_lock_spin(files_struct
*fsp
,connection_struct
*conn
, uint16 lock_pid
,
156 SMB_BIG_UINT count
,SMB_BIG_UINT offset
,enum brl_type lock_type
, BOOL
*my_lock_ctx
)
158 int j
, maxj
= lp_lock_spin_count();
159 int sleeptime
= lp_lock_sleep_time();
160 NTSTATUS status
, ret
;
165 ret
= NT_STATUS_OK
; /* to keep dumb compilers happy */
167 for (j
= 0; j
< maxj
; j
++) {
168 status
= do_lock(fsp
, conn
, lock_pid
, count
, offset
, lock_type
, my_lock_ctx
);
169 if (!NT_STATUS_EQUAL(status
, NT_STATUS_LOCK_NOT_GRANTED
) &&
170 !NT_STATUS_EQUAL(status
, NT_STATUS_FILE_LOCK_CONFLICT
)) {
173 /* if we do fail then return the first error code we got */
176 /* Don't spin if we blocked ourselves. */
181 sys_usleep(sleeptime
);
186 /* Struct passed to brl_unlock. */
187 struct posix_unlock_data_struct
{
193 /****************************************************************************
194 Function passed to brl_unlock to allow POSIX unlock to be done first.
195 ****************************************************************************/
197 static void posix_unlock(void *pre_data
)
199 struct posix_unlock_data_struct
*pdata
= (struct posix_unlock_data_struct
*)pre_data
;
201 if (lp_posix_locking(SNUM(pdata
->fsp
->conn
)))
202 release_posix_lock(pdata
->fsp
, pdata
->offset
, pdata
->count
);
205 /****************************************************************************
206 Utility function called by unlocking requests.
207 ****************************************************************************/
209 NTSTATUS
do_unlock(files_struct
*fsp
,connection_struct
*conn
, uint16 lock_pid
,
210 SMB_BIG_UINT count
,SMB_BIG_UINT offset
)
213 struct posix_unlock_data_struct posix_data
;
215 if (!lp_locking(SNUM(conn
)))
218 if (!OPEN_FSP(fsp
) || !fsp
->can_lock
|| (fsp
->conn
!= conn
)) {
219 return NT_STATUS_INVALID_HANDLE
;
222 DEBUG(10,("do_unlock: unlock start=%.0f len=%.0f requested for file %s\n",
223 (double)offset
, (double)count
, fsp
->fsp_name
));
226 * Remove the existing lock record from the tdb lockdb
227 * before looking at POSIX locks. If this record doesn't
228 * match then don't bother looking to remove POSIX locks.
231 posix_data
.fsp
= fsp
;
232 posix_data
.offset
= offset
;
233 posix_data
.count
= count
;
235 ok
= brl_unlock(fsp
->dev
, fsp
->inode
, fsp
->fnum
,
236 lock_pid
, sys_getpid(), conn
->cnum
, offset
, count
,
237 False
, posix_unlock
, (void *)&posix_data
);
240 DEBUG(10,("do_unlock: returning ERRlock.\n" ));
241 return NT_STATUS_RANGE_NOT_LOCKED
;
246 /****************************************************************************
247 Remove any locks on this fd. Called from file_close().
248 ****************************************************************************/
250 void locking_close_file(files_struct
*fsp
)
252 pid_t pid
= sys_getpid();
254 if (!lp_locking(SNUM(fsp
->conn
)))
258 * Just release all the brl locks, no need to release individually.
261 brl_close(fsp
->dev
, fsp
->inode
, pid
, fsp
->conn
->cnum
, fsp
->fnum
);
263 if(lp_posix_locking(SNUM(fsp
->conn
))) {
266 * Release all the POSIX locks.
268 posix_locking_close_file(fsp
);
273 /****************************************************************************
274 Initialise the locking functions.
275 ****************************************************************************/
277 static int open_read_only
;
279 BOOL
locking_init(int read_only
)
286 tdb
= tdb_open_ex(lock_path("locking.tdb"),
287 0, TDB_DEFAULT
|(read_only
?0x0:TDB_CLEAR_IF_FIRST
),
288 read_only
?O_RDONLY
:O_RDWR
|O_CREAT
,
292 DEBUG(0,("ERROR: Failed to initialise locking database\n"));
296 if (!posix_locking_init(read_only
))
299 open_read_only
= read_only
;
304 /*******************************************************************
305 Deinitialize the share_mode management.
306 ******************************************************************/
308 BOOL
locking_end(void)
311 brl_shutdown(open_read_only
);
314 if (tdb_close(tdb
) != 0)
321 /*******************************************************************
322 Form a static locking key for a dev/inode pair.
323 ******************************************************************/
325 static TDB_DATA
locking_key(SMB_DEV_T dev
, SMB_INO_T inode
)
327 static struct locking_key key
;
330 memset(&key
, '\0', sizeof(key
));
333 kbuf
.dptr
= (char *)&key
;
334 kbuf
.dsize
= sizeof(key
);
338 static TDB_DATA
locking_key_fsp(files_struct
*fsp
)
340 return locking_key(fsp
->dev
, fsp
->inode
);
343 /*******************************************************************
344 Lock a hash bucket entry.
345 ******************************************************************/
347 BOOL
lock_share_entry(connection_struct
*conn
,
348 SMB_DEV_T dev
, SMB_INO_T inode
)
350 return tdb_chainlock(tdb
, locking_key(dev
, inode
)) == 0;
353 /*******************************************************************
354 Unlock a hash bucket entry.
355 ******************************************************************/
357 void unlock_share_entry(connection_struct
*conn
,
358 SMB_DEV_T dev
, SMB_INO_T inode
)
360 tdb_chainunlock(tdb
, locking_key(dev
, inode
));
363 /*******************************************************************
364 Lock a hash bucket entry. use a fsp for convenience
365 ******************************************************************/
367 BOOL
lock_share_entry_fsp(files_struct
*fsp
)
369 return tdb_chainlock(tdb
, locking_key(fsp
->dev
, fsp
->inode
)) == 0;
372 /*******************************************************************
373 Unlock a hash bucket entry.
374 ******************************************************************/
376 void unlock_share_entry_fsp(files_struct
*fsp
)
378 tdb_chainunlock(tdb
, locking_key(fsp
->dev
, fsp
->inode
));
381 /*******************************************************************
382 Print out a share mode.
383 ********************************************************************/
385 char *share_mode_str(int num
, share_mode_entry
*e
)
387 static pstring share_str
;
389 slprintf(share_str
, sizeof(share_str
)-1, "share_mode_entry[%d]: \
390 pid = %lu, share_mode = 0x%x, desired_access = 0x%x, port = 0x%x, type= 0x%x, file_id = %lu, dev = 0x%x, inode = %.0f",
391 num
, (unsigned long)e
->pid
, e
->share_mode
, (unsigned int)e
->desired_access
, e
->op_port
, e
->op_type
, e
->share_file_id
,
392 (unsigned int)e
->dev
, (double)e
->inode
);
397 /*******************************************************************
398 Print out a share mode table.
399 ********************************************************************/
401 static void print_share_mode_table(struct locking_data
*data
)
403 int num_share_modes
= data
->u
.num_share_mode_entries
;
404 share_mode_entry
*shares
= (share_mode_entry
*)(data
+ 1);
407 for (i
= 0; i
< num_share_modes
; i
++) {
408 share_mode_entry
*entry_p
= &shares
[i
];
409 DEBUG(10,("print_share_mode_table: %s\n", share_mode_str(i
, entry_p
) ));
413 /*******************************************************************
414 Get all share mode entries for a dev/inode pair.
415 ********************************************************************/
417 int get_share_modes(connection_struct
*conn
,
418 SMB_DEV_T dev
, SMB_INO_T inode
,
419 share_mode_entry
**pp_shares
)
422 struct locking_data
*data
;
424 share_mode_entry
*shares
= NULL
;
425 TDB_DATA key
= locking_key(dev
, inode
);
428 dbuf
= tdb_fetch(tdb
, key
);
432 data
= (struct locking_data
*)dbuf
.dptr
;
433 num_share_modes
= data
->u
.num_share_mode_entries
;
434 if(num_share_modes
) {
438 shares
= (share_mode_entry
*)memdup(dbuf
.dptr
+ sizeof(*data
),
439 num_share_modes
* sizeof(share_mode_entry
));
442 SAFE_FREE(dbuf
.dptr
);
447 * Ensure that each entry has a real process attached.
450 for (i
= 0; i
< num_share_modes
; ) {
451 share_mode_entry
*entry_p
= &shares
[i
];
452 if (process_exists(entry_p
->pid
)) {
453 DEBUG(10,("get_share_modes: %s\n", share_mode_str(i
, entry_p
) ));
456 DEBUG(10,("get_share_modes: deleted %s\n", share_mode_str(i
, entry_p
) ));
457 memcpy( &shares
[i
], &shares
[i
+1],
458 sizeof(share_mode_entry
) * (num_share_modes
- i
- 1));
464 /* Did we delete any ? If so, re-store in tdb. */
466 data
->u
.num_share_mode_entries
= num_share_modes
;
469 memcpy(dbuf
.dptr
+ sizeof(*data
), shares
,
470 num_share_modes
* sizeof(share_mode_entry
));
472 /* The record has shrunk a bit */
473 dbuf
.dsize
-= del_count
* sizeof(share_mode_entry
);
475 if (tdb_store(tdb
, key
, dbuf
, TDB_REPLACE
) == -1) {
477 SAFE_FREE(dbuf
.dptr
);
483 SAFE_FREE(dbuf
.dptr
);
485 return num_share_modes
;
488 /*******************************************************************
489 Fill a share mode entry.
490 ********************************************************************/
492 static void fill_share_mode(char *p
, files_struct
*fsp
, uint16 port
, uint16 op_type
)
494 share_mode_entry
*e
= (share_mode_entry
*)p
;
495 void *x
= &e
->time
; /* Needed to force alignment. p may not be aligned.... */
497 memset(e
, '\0', sizeof(share_mode_entry
));
498 e
->pid
= sys_getpid();
499 e
->share_mode
= fsp
->share_mode
;
500 e
->desired_access
= fsp
->desired_access
;
502 e
->op_type
= op_type
;
503 memcpy(x
, &fsp
->open_time
, sizeof(struct timeval
));
504 e
->share_file_id
= fsp
->file_id
;
506 e
->inode
= fsp
->inode
;
509 /*******************************************************************
510 Check if two share mode entries are identical, ignoring oplock
511 and port info and desired_access.
512 ********************************************************************/
514 BOOL
share_modes_identical( share_mode_entry
*e1
, share_mode_entry
*e2
)
516 #if 1 /* JRA PARANOIA TEST - REMOVE LATER */
517 if (e1
->pid
== e2
->pid
&&
518 e1
->share_file_id
== e2
->share_file_id
&&
519 e1
->dev
== e2
->dev
&&
520 e1
->inode
== e2
->inode
&&
521 (e1
->share_mode
& ~DELETE_ON_CLOSE_FLAG
) != (e2
->share_mode
& ~DELETE_ON_CLOSE_FLAG
)) {
522 DEBUG(0,("PANIC: share_modes_identical: share_mode missmatch (e1 = %u, e2 = %u). Logic error.\n",
523 (unsigned int)(e1
->share_mode
& ~DELETE_ON_CLOSE_FLAG
),
524 (unsigned int)(e2
->share_mode
& ~DELETE_ON_CLOSE_FLAG
) ));
525 smb_panic("PANIC: share_modes_identical logic error.\n");
529 return (e1
->pid
== e2
->pid
&&
530 (e1
->share_mode
& ~DELETE_ON_CLOSE_FLAG
) == (e2
->share_mode
& ~DELETE_ON_CLOSE_FLAG
) &&
531 e1
->dev
== e2
->dev
&&
532 e1
->inode
== e2
->inode
&&
533 e1
->share_file_id
== e2
->share_file_id
);
536 /*******************************************************************
537 Delete a specific share mode. Return the number
538 of entries left, and a memdup'ed copy of the entry deleted (if required).
539 Ignore if no entry deleted.
540 ********************************************************************/
542 ssize_t
del_share_entry( SMB_DEV_T dev
, SMB_INO_T inode
,
543 share_mode_entry
*entry
, share_mode_entry
**ppse
)
546 struct locking_data
*data
;
548 share_mode_entry
*shares
;
550 TDB_DATA key
= locking_key(dev
, inode
);
555 /* read in the existing share modes */
556 dbuf
= tdb_fetch(tdb
, key
);
560 data
= (struct locking_data
*)dbuf
.dptr
;
561 shares
= (share_mode_entry
*)(dbuf
.dptr
+ sizeof(*data
));
564 * Find any with this pid and delete it
565 * by overwriting with the rest of the data
569 DEBUG(10,("del_share_entry: num_share_modes = %d\n", data
->u
.num_share_mode_entries
));
571 for (i
=0;i
<data
->u
.num_share_mode_entries
;) {
572 if (share_modes_identical(&shares
[i
], entry
)) {
573 DEBUG(10,("del_share_entry: deleted %s\n",
574 share_mode_str(i
, &shares
[i
]) ));
576 *ppse
= memdup(&shares
[i
], sizeof(*shares
));
577 data
->u
.num_share_mode_entries
--;
578 memmove(&shares
[i
], &shares
[i
+1],
579 dbuf
.dsize
- (sizeof(*data
) + (i
+1)*sizeof(*shares
)));
582 DEBUG(10,("del_share_entry: deleting entry %d\n", i
));
590 /* the record may have shrunk a bit */
591 dbuf
.dsize
-= del_count
* sizeof(*shares
);
593 count
= (ssize_t
)data
->u
.num_share_mode_entries
;
595 /* store it back in the database */
596 if (data
->u
.num_share_mode_entries
== 0) {
597 if (tdb_delete(tdb
, key
) == -1)
600 if (tdb_store(tdb
, key
, dbuf
, TDB_REPLACE
) == -1)
604 DEBUG(10,("del_share_entry: Remaining table.\n"));
605 print_share_mode_table((struct locking_data
*)dbuf
.dptr
);
606 SAFE_FREE(dbuf
.dptr
);
610 /*******************************************************************
611 Del the share mode of a file for this process. Return the number
612 of entries left, and a memdup'ed copy of the entry deleted.
613 ********************************************************************/
615 ssize_t
del_share_mode(files_struct
*fsp
, share_mode_entry
**ppse
)
617 share_mode_entry entry
;
620 * Fake up a share_mode_entry for comparisons.
623 fill_share_mode((char *)&entry
, fsp
, 0, 0);
624 return del_share_entry(fsp
->dev
, fsp
->inode
, &entry
, ppse
);
627 /*******************************************************************
628 Set the share mode of a file. Return False on fail, True on success.
629 ********************************************************************/
631 BOOL
set_share_mode(files_struct
*fsp
, uint16 port
, uint16 op_type
)
634 struct locking_data
*data
;
637 TDB_DATA key
= locking_key_fsp(fsp
);
640 /* read in the existing share modes if any */
641 dbuf
= tdb_fetch(tdb
, key
);
644 /* we'll need to create a new record */
647 pstrcpy(fname
, fsp
->conn
->connectpath
);
649 pstrcat(fname
, fsp
->fsp_name
);
651 size
= sizeof(*data
) + sizeof(share_mode_entry
) + strlen(fname
) + 1;
652 p
= (char *)malloc(size
);
655 data
= (struct locking_data
*)p
;
656 data
->u
.num_share_mode_entries
= 1;
658 DEBUG(10,("set_share_mode: creating entry for file %s. num_share_modes = 1\n",
661 offset
= sizeof(*data
) + sizeof(share_mode_entry
);
662 safe_strcpy(p
+ offset
, fname
, size
- offset
- 1);
663 fill_share_mode(p
+ sizeof(*data
), fsp
, port
, op_type
);
666 if (tdb_store(tdb
, key
, dbuf
, TDB_REPLACE
) == -1)
669 print_share_mode_table((struct locking_data
*)p
);
675 /* we're adding to an existing entry - this is a bit fiddly */
676 data
= (struct locking_data
*)dbuf
.dptr
;
678 data
->u
.num_share_mode_entries
++;
680 DEBUG(10,("set_share_mode: adding entry for file %s. new num_share_modes = %d\n",
681 fsp
->fsp_name
, data
->u
.num_share_mode_entries
));
683 size
= dbuf
.dsize
+ sizeof(share_mode_entry
);
686 SAFE_FREE(dbuf
.dptr
);
689 memcpy(p
, dbuf
.dptr
, sizeof(*data
));
690 fill_share_mode(p
+ sizeof(*data
), fsp
, port
, op_type
);
691 memcpy(p
+ sizeof(*data
) + sizeof(share_mode_entry
), dbuf
.dptr
+ sizeof(*data
),
692 dbuf
.dsize
- sizeof(*data
));
693 SAFE_FREE(dbuf
.dptr
);
696 if (tdb_store(tdb
, key
, dbuf
, TDB_REPLACE
) == -1)
698 print_share_mode_table((struct locking_data
*)p
);
703 /*******************************************************************
704 A generic in-place modification call for share mode entries.
705 ********************************************************************/
707 static BOOL
mod_share_mode( SMB_DEV_T dev
, SMB_INO_T inode
, share_mode_entry
*entry
,
708 void (*mod_fn
)(share_mode_entry
*, SMB_DEV_T
, SMB_INO_T
, void *),
712 struct locking_data
*data
;
714 share_mode_entry
*shares
;
715 BOOL need_store
=False
;
717 TDB_DATA key
= locking_key(dev
, inode
);
719 /* read in the existing share modes */
720 dbuf
= tdb_fetch(tdb
, key
);
724 data
= (struct locking_data
*)dbuf
.dptr
;
725 shares
= (share_mode_entry
*)(dbuf
.dptr
+ sizeof(*data
));
727 /* find any with our pid and call the supplied function */
728 for (i
=0;i
<data
->u
.num_share_mode_entries
;i
++) {
729 if (share_modes_identical(entry
, &shares
[i
])) {
730 mod_fn(&shares
[i
], dev
, inode
, param
);
735 /* if the mod fn was called then store it back */
737 if (data
->u
.num_share_mode_entries
== 0) {
738 if (tdb_delete(tdb
, key
) == -1)
741 if (tdb_store(tdb
, key
, dbuf
, TDB_REPLACE
) == -1)
746 SAFE_FREE(dbuf
.dptr
);
750 /*******************************************************************
751 Static function that actually does the work for the generic function
753 ********************************************************************/
755 static void remove_share_oplock_fn(share_mode_entry
*entry
, SMB_DEV_T dev
, SMB_INO_T inode
,
758 DEBUG(10,("remove_share_oplock_fn: removing oplock info for entry dev=%x ino=%.0f\n",
759 (unsigned int)dev
, (double)inode
));
760 /* Delete the oplock info. */
762 entry
->op_type
= NO_OPLOCK
;
765 /*******************************************************************
766 Remove an oplock port and mode entry from a share mode.
767 ********************************************************************/
769 BOOL
remove_share_oplock(files_struct
*fsp
)
771 share_mode_entry entry
;
773 * Fake up an entry for comparisons...
775 fill_share_mode((char *)&entry
, fsp
, 0, 0);
776 return mod_share_mode(fsp
->dev
, fsp
->inode
, &entry
, remove_share_oplock_fn
, NULL
);
779 /*******************************************************************
780 Static function that actually does the work for the generic function
782 ********************************************************************/
784 static void downgrade_share_oplock_fn(share_mode_entry
*entry
, SMB_DEV_T dev
, SMB_INO_T inode
,
787 DEBUG(10,("downgrade_share_oplock_fn: downgrading oplock info for entry dev=%x ino=%.0f\n",
788 (unsigned int)dev
, (double)inode
));
789 entry
->op_type
= LEVEL_II_OPLOCK
;
792 /*******************************************************************
793 Downgrade a oplock type from exclusive to level II.
794 ********************************************************************/
796 BOOL
downgrade_share_oplock(files_struct
*fsp
)
798 share_mode_entry entry
;
800 * Fake up an entry for comparisons...
802 fill_share_mode((char *)&entry
, fsp
, 0, 0);
803 return mod_share_mode(fsp
->dev
, fsp
->inode
, &entry
, downgrade_share_oplock_fn
, NULL
);
806 /*******************************************************************
807 Get/Set the delete on close flag in a set of share modes.
808 Return False on fail, True on success.
809 ********************************************************************/
811 BOOL
modify_delete_flag( SMB_DEV_T dev
, SMB_INO_T inode
, BOOL delete_on_close
)
814 struct locking_data
*data
;
816 share_mode_entry
*shares
;
817 TDB_DATA key
= locking_key(dev
, inode
);
819 /* read in the existing share modes */
820 dbuf
= tdb_fetch(tdb
, key
);
824 data
= (struct locking_data
*)dbuf
.dptr
;
825 shares
= (share_mode_entry
*)(dbuf
.dptr
+ sizeof(*data
));
827 /* Set/Unset the delete on close element. */
828 for (i
=0;i
<data
->u
.num_share_mode_entries
;i
++,shares
++) {
829 shares
->share_mode
= (delete_on_close
?
830 (shares
->share_mode
| DELETE_ON_CLOSE_FLAG
) :
831 (shares
->share_mode
& ~DELETE_ON_CLOSE_FLAG
) );
835 if (data
->u
.num_share_mode_entries
) {
836 if (tdb_store(tdb
, key
, dbuf
, TDB_REPLACE
)==-1) {
837 SAFE_FREE(dbuf
.dptr
);
842 SAFE_FREE(dbuf
.dptr
);
846 /****************************************************************************
847 Traverse the whole database with this function, calling traverse_callback
849 ****************************************************************************/
851 static int traverse_fn(TDB_CONTEXT
*the_tdb
, TDB_DATA kbuf
, TDB_DATA dbuf
,
854 struct locking_data
*data
;
855 share_mode_entry
*shares
;
859 SHAREMODE_FN(traverse_callback
) = (SHAREMODE_FN_CAST())state
;
861 data
= (struct locking_data
*)dbuf
.dptr
;
862 shares
= (share_mode_entry
*)(dbuf
.dptr
+ sizeof(*data
));
863 name
= dbuf
.dptr
+ sizeof(*data
) + data
->u
.num_share_mode_entries
*sizeof(*shares
);
865 for (i
=0;i
<data
->u
.num_share_mode_entries
;i
++) {
866 traverse_callback(&shares
[i
], name
);
871 /*******************************************************************
872 Call the specified function on each entry under management by the
874 ********************************************************************/
876 int share_mode_forall(SHAREMODE_FN(fn
))
880 return tdb_traverse(tdb
, traverse_fn
, (void*)fn
);