This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
+ the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
Revision History:
DEBUG(0,("posix_fcntl_lock: WARNING: lock request at offset %.0f, length %.0f returned\n",
(double)offset,(double)count));
- DEBUG(0,("an %s error. This can happen when using 64 bit lock offsets\n", strerror(errno)));
- DEBUG(0,("on 32 bit NFS mounted file systems.\n"));
+ DEBUGADD(0,("an %s error. This can happen when using 64 bit lock offsets\n", strerror(errno)));
+ DEBUGADD(0,("on 32 bit NFS mounted file systems.\n"));
/*
* If the offset is > 0x7FFFFFFF then this will cause problems on
DEBUG(0,("posix_fcntl_getlock: WARNING: lock request at offset %.0f, length %.0f returned\n",
(double)*poffset,(double)*pcount));
- DEBUG(0,("an %s error. This can happen when using 64 bit lock offsets\n", strerror(errno)));
- DEBUG(0,("on 32 bit NFS mounted file systems.\n"));
+ DEBUGADD(0,("an %s error. This can happen when using 64 bit lock offsets\n", strerror(errno)));
+ DEBUGADD(0,("on 32 bit NFS mounted file systems.\n"));
/*
* If the offset is > 0x7FFFFFFF then this will cause problems on
/* The key used in the in-memory POSIX databases. */
struct lock_ref_count_key {
- SMB_DEV_T device;
- SMB_INO_T inode;
+ struct file_id id;
char r;
};
-struct fd_key {
- SMB_DEV_T device;
- SMB_INO_T inode;
-};
-
/*******************************************************************
Form a static locking key for a dev/inode pair for the fd array.
******************************************************************/
-static TDB_DATA fd_array_key(SMB_DEV_T dev, SMB_INO_T inode)
+static TDB_DATA fd_array_key(struct file_id id)
{
- static struct fd_key key;
+ static struct file_id key;
TDB_DATA kbuf;
-
- memset(&key, '\0', sizeof(key));
- key.device = dev;
- key.inode = inode;
- kbuf.dptr = (char *)&key;
+ key = id;
+ kbuf.dptr = (uint8 *)&key;
kbuf.dsize = sizeof(key);
return kbuf;
}
Form a static locking key for a dev/inode pair for the lock ref count
******************************************************************/
-static TDB_DATA locking_ref_count_key(SMB_DEV_T dev, SMB_INO_T inode)
+static TDB_DATA locking_ref_count_key(struct file_id id)
{
static struct lock_ref_count_key key;
TDB_DATA kbuf;
memset(&key, '\0', sizeof(key));
- key.device = dev;
- key.inode = inode;
+ key.id = id;
key.r = 'r';
- kbuf.dptr = (char *)&key;
+ kbuf.dptr = (uint8 *)&key;
kbuf.dsize = sizeof(key);
return kbuf;
}
static TDB_DATA fd_array_key_fsp(files_struct *fsp)
{
- return fd_array_key(fsp->dev, fsp->inode);
+ return fd_array_key(fsp->file_id);
}
/*******************************************************************
static TDB_DATA locking_ref_count_key_fsp(files_struct *fsp)
{
- return locking_ref_count_key(fsp->dev, fsp->inode);
+ return locking_ref_count_key(fsp->file_id);
}
/*******************************************************************
dbuf = tdb_fetch(posix_pending_close_tdb, kbuf);
if (dbuf.dptr == NULL) {
- dbuf.dptr = (char *)SMB_MALLOC_P(int);
+ dbuf.dptr = (uint8 *)SMB_MALLOC_P(int);
if (!dbuf.dptr) {
- smb_panic("increment_windows_lock_ref_count: malloc fail.\n");
+ smb_panic("increment_windows_lock_ref_count: malloc fail");
}
memset(dbuf.dptr, '\0', sizeof(int));
dbuf.dsize = sizeof(int);
memcpy(dbuf.dptr, &lock_ref_count, sizeof(int));
if (tdb_store(posix_pending_close_tdb, kbuf, dbuf, TDB_REPLACE) == -1) {
- smb_panic("increment_windows_lock_ref_count: tdb_store_fail.\n");
+ smb_panic("increment_windows_lock_ref_count: tdb_store_fail");
}
SAFE_FREE(dbuf.dptr);
dbuf = tdb_fetch(posix_pending_close_tdb, kbuf);
if (!dbuf.dptr) {
- smb_panic("decrement_windows_lock_ref_count: logic error.\n");
+ smb_panic("decrement_windows_lock_ref_count: logic error");
}
memcpy(&lock_ref_count, dbuf.dptr, sizeof(int));
memcpy(dbuf.dptr, &lock_ref_count, sizeof(int));
if (lock_ref_count < 0) {
- smb_panic("decrement_windows_lock_ref_count: lock_count logic error.\n");
+ smb_panic("decrement_windows_lock_ref_count: lock_count logic error");
}
if (tdb_store(posix_pending_close_tdb, kbuf, dbuf, TDB_REPLACE) == -1) {
- smb_panic("decrement_windows_lock_ref_count: tdb_store_fail.\n");
+ smb_panic("decrement_windows_lock_ref_count: tdb_store_fail");
}
SAFE_FREE(dbuf.dptr);
lock_ref_count -= dcount;
if (lock_ref_count < 0) {
- smb_panic("reduce_windows_lock_ref_count: lock_count logic error.\n");
+ smb_panic("reduce_windows_lock_ref_count: lock_count logic error");
}
memcpy(dbuf.dptr, &lock_ref_count, sizeof(int));
if (tdb_store(posix_pending_close_tdb, kbuf, dbuf, TDB_REPLACE) == -1) {
- smb_panic("reduce_windows_lock_ref_count: tdb_store_fail.\n");
+ smb_panic("reduce_windows_lock_ref_count: tdb_store_fail");
}
SAFE_FREE(dbuf.dptr);
dbuf = tdb_fetch(posix_pending_close_tdb, kbuf);
- dbuf.dptr = (char *)SMB_REALLOC(dbuf.dptr, dbuf.dsize + sizeof(int));
+ dbuf.dptr = (uint8 *)SMB_REALLOC(dbuf.dptr, dbuf.dsize + sizeof(int));
if (!dbuf.dptr) {
- smb_panic("add_fd_to_close_entry: Realloc fail !\n");
+ smb_panic("add_fd_to_close_entry: SMB_REALLOC failed");
}
memcpy(dbuf.dptr + dbuf.dsize, &fsp->fh->fd, sizeof(int));
dbuf.dsize += sizeof(int);
if (tdb_store(posix_pending_close_tdb, kbuf, dbuf, TDB_REPLACE) == -1) {
- smb_panic("add_fd_to_close_entry: tdb_store_fail.\n");
+ smb_panic("add_fd_to_close_entry: tdb_store_fail");
}
DEBUG(10,("add_fd_to_close_entry: added fd %d file %s\n",
TDB_DATA kbuf = fd_array_key_fsp(fsp);
if (tdb_delete(posix_pending_close_tdb, kbuf) == -1) {
- smb_panic("delete_close_entries: tdb_delete fail !\n");
+ smb_panic("delete_close_entries: tdb_delete failed");
}
}
to delete all locks on this fsp before this function is called.
****************************************************************************/
-int fd_close_posix(struct connection_struct *conn, files_struct *fsp)
+NTSTATUS fd_close_posix(struct connection_struct *conn, files_struct *fsp)
{
int saved_errno = 0;
int ret;
*/
ret = SMB_VFS_CLOSE(fsp,fsp->fh->fd);
fsp->fh->fd = -1;
- return ret;
+ return map_nt_error_from_unix(errno);
}
if (get_windows_lock_ref_count(fsp)) {
add_fd_to_close_entry(fsp);
fsp->fh->fd = -1;
- return 0;
+ return NT_STATUS_OK;
}
/*
ret = SMB_VFS_CLOSE(fsp,fsp->fh->fd);
- if (saved_errno != 0) {
+ if (ret == 0 && saved_errno != 0) {
errno = saved_errno;
ret = -1;
}
fsp->fh->fd = -1;
- return ret;
+ if (ret == -1) {
+ return map_nt_error_from_unix(errno);
+ }
+
+ return NT_STATUS_OK;
}
/****************************************************************************
pstring msg;
slprintf(msg, sizeof(msg)-1, "logic flaw in cases: l_curr: start = %.0f, size = %.0f : \
-lock: start = %.0f, size = %.0f\n", (double)l_curr->start, (double)l_curr->size, (double)lock->start, (double)lock->size );
+lock: start = %.0f, size = %.0f", (double)l_curr->start, (double)l_curr->size, (double)lock->start, (double)lock->size );
smb_panic(msg);
}