r8219: Merge the new open code from HEAD to 3.0. Haven't yet run the torture
[samba.git] / source3 / locking / posix.c
index 218c44102805429e4047cfc9e037e1d50f904715..c63992adc592a631e89ec665a3685a53e132aaf0 100644 (file)
@@ -114,7 +114,7 @@ static BOOL add_fd_to_close_entry(files_struct *fsp)
        } else
                dbuf.dptr = tp;
 
-       memcpy(dbuf.dptr + dbuf.dsize, &fsp->fd, sizeof(int));
+       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) {
@@ -209,8 +209,8 @@ int fd_close_posix(struct connection_struct *conn, files_struct *fsp)
                /*
                 * No POSIX to worry about, just close.
                 */
-               ret = SMB_VFS_CLOSE(fsp,fsp->fd);
-               fsp->fd = -1;
+               ret = SMB_VFS_CLOSE(fsp,fsp->fh->fd);
+               fsp->fh->fd = -1;
                return ret;
        }
 
@@ -227,7 +227,7 @@ int fd_close_posix(struct connection_struct *conn, files_struct *fsp)
         */
 
        for (i = 0; i < count; i++) {
-               if (entries[i].fd != fsp->fd) {
+               if (entries[i].fd != fsp->fh->fd) {
                        locks_on_other_fds = True;
                        break;
                }
@@ -237,7 +237,7 @@ int fd_close_posix(struct connection_struct *conn, files_struct *fsp)
 
                /*
                 * There are outstanding locks on this dev/inode pair on other fds.
-                * Add our fd to the pending close tdb and set fsp->fd to -1.
+                * Add our fd to the pending close tdb and set fsp->fh->fd to -1.
                 */
 
                if (!add_fd_to_close_entry(fsp)) {
@@ -246,7 +246,7 @@ int fd_close_posix(struct connection_struct *conn, files_struct *fsp)
                }
 
                SAFE_FREE(entries);
-               fsp->fd = -1;
+               fsp->fh->fd = -1;
                return 0;
        }
 
@@ -282,14 +282,14 @@ int fd_close_posix(struct connection_struct *conn, files_struct *fsp)
         * Finally close the fd associated with this fsp.
         */
 
-       ret = SMB_VFS_CLOSE(fsp,fsp->fd);
+       ret = SMB_VFS_CLOSE(fsp,fsp->fh->fd);
 
        if (saved_errno != 0) {
                errno = saved_errno;
                ret = -1;
        } 
 
-       fsp->fd = -1;
+       fsp->fh->fd = -1;
 
        return ret;
 }
@@ -371,7 +371,7 @@ static BOOL add_posix_lock_entry(files_struct *fsp, SMB_OFF_T start, SMB_OFF_T s
         * Add new record.
         */
 
-       pl.fd = fsp->fd;
+       pl.fd = fsp->fh->fd;
        pl.start = start;
        pl.size = size;
        pl.lock_type = lock_type;
@@ -455,7 +455,7 @@ static int delete_posix_lock_entry(files_struct *fsp, SMB_OFF_T start, SMB_OFF_T
        for (i=0; i<count; i++) { 
                struct posix_lock *entry = &locks[i];
 
-               if (entry->fd == fsp->fd &&
+               if (entry->fd == fsp->fh->fd &&
                        entry->start == start &&
                        entry->size == size) {
 
@@ -490,7 +490,7 @@ static int delete_posix_lock_entry(files_struct *fsp, SMB_OFF_T start, SMB_OFF_T
        for (i = 0; i < count; i++) {
                struct posix_lock *entry = &locks[i];
 
-               if (fsp->fd == entry->fd &&
+               if (fsp->fh->fd == entry->fd &&
                        does_lock_overlap( start, size, entry->start, entry->size))
                                num_overlapping_records++;
        }
@@ -524,13 +524,17 @@ static int map_posix_lock_type( files_struct *fsp, enum brl_type lock_type)
                 */
                DEBUG(10,("map_posix_lock_type: Downgrading write lock to read due to read-only file.\n"));
                return F_RDLCK;
-       } else if((lock_type == READ_LOCK) && !fsp->can_read) {
+       }
+#if 0
+       /* We no longer open files write-only. */
+        else if((lock_type == READ_LOCK) && !fsp->can_read) {
                /*
                 * Ditto for read locks on write only files.
                 */
                DEBUG(10,("map_posix_lock_type: Changing read lock to write due to write-only file.\n"));
                return F_WRLCK;
        }
+#endif
 
        /*
         * This return should be the most normal, as we attempt
@@ -652,9 +656,9 @@ static BOOL posix_fcntl_lock(files_struct *fsp, int op, SMB_OFF_T offset, SMB_OF
 {
        int ret;
 
-       DEBUG(8,("posix_fcntl_lock %d %d %.0f %.0f %d\n",fsp->fd,op,(double)offset,(double)count,type));
+       DEBUG(8,("posix_fcntl_lock %d %d %.0f %.0f %d\n",fsp->fh->fd,op,(double)offset,(double)count,type));
 
-       ret = SMB_VFS_LOCK(fsp,fsp->fd,op,offset,count,type);
+       ret = SMB_VFS_LOCK(fsp,fsp->fh->fd,op,offset,count,type);
 
        if (!ret && ((errno == EFBIG) || (errno == ENOLCK) || (errno ==  EINVAL))) {
 
@@ -678,7 +682,7 @@ static BOOL posix_fcntl_lock(files_struct *fsp, int op, SMB_OFF_T offset, SMB_OF
                        DEBUG(0,("Count greater than 31 bits - retrying with 31 bit truncated length.\n"));
                        errno = 0;
                        count &= 0x7fffffff;
-                       ret = SMB_VFS_LOCK(fsp,fsp->fd,op,offset,count,type);
+                       ret = SMB_VFS_LOCK(fsp,fsp->fh->fd,op,offset,count,type);
                }
        }
 
@@ -1247,7 +1251,7 @@ void posix_locking_close_file(files_struct *fsp)
        }
 
        for (i = 0; i < count; i++) {
-               if (entries[i].fd != fsp->fd )
+               if (entries[i].fd != fsp->fh->fd )
                        break;
 
                dump_entry(&entries[i]);
@@ -1269,7 +1273,7 @@ void posix_locking_close_file(files_struct *fsp)
 
        for (i = 0; i < count; i++) {
                struct posix_lock *pl = &entries[i];
-               if (pl->fd == fsp->fd)
+               if (pl->fd == fsp->fh->fd)
                        release_posix_lock(fsp, (SMB_BIG_UINT)pl->start, (SMB_BIG_UINT)pl->size );
        }
        SAFE_FREE(entries);