Make the smbd VFS typesafe
[samba.git] / source3 / locking / posix.c
index c036ee597c5f76403653b2bbc3401cdccdda8ec8..17945399c59ceff51b700c9f381453c48a92d51a 100644 (file)
@@ -177,6 +177,14 @@ static bool posix_lock_in_range(SMB_OFF_T *offset_out, SMB_OFF_T *count_out,
        return True;
 }
 
+bool smb_vfs_call_lock(struct vfs_handle_struct *handle,
+                      struct files_struct *fsp, int op, SMB_OFF_T offset,
+                      SMB_OFF_T count, int type)
+{
+       VFS_FIND(lock);
+       return handle->fns->lock(handle, fsp, op, offset, count, type);
+}
+
 /****************************************************************************
  Actual function that does POSIX locks. Copes with 64 -> 32 bit cruft and
  broken NFS implementations.
@@ -220,6 +228,14 @@ static bool posix_fcntl_lock(files_struct *fsp, int op, SMB_OFF_T offset, SMB_OF
        return ret;
 }
 
+bool smb_vfs_call_getlock(struct vfs_handle_struct *handle,
+                         struct files_struct *fsp, SMB_OFF_T *poffset,
+                         SMB_OFF_T *pcount, int *ptype, pid_t *ppid)
+{
+       VFS_FIND(getlock);
+       return handle->fns->getlock(handle, fsp, poffset, pcount, ptype, ppid);
+}
+
 /****************************************************************************
  Actual function that gets POSIX locks. Copes with 64 -> 32 bit cruft and
  broken NFS implementations.
@@ -280,8 +296,9 @@ bool is_posix_locked(files_struct *fsp,
        SMB_OFF_T count;
        int posix_lock_type = map_posix_lock_type(fsp,*plock_type);
 
-       DEBUG(10,("is_posix_locked: File %s, offset = %.0f, count = %.0f, type = %s\n",
-               fsp->fsp_name, (double)*pu_offset, (double)*pu_count, posix_lock_type_name(*plock_type) ));
+       DEBUG(10,("is_posix_locked: File %s, offset = %.0f, count = %.0f, "
+                 "type = %s\n", fsp_str_dbg(fsp), (double)*pu_offset,
+                 (double)*pu_count,  posix_lock_type_name(*plock_type)));
 
        /*
         * If the requested lock won't fit in the POSIX range, we will
@@ -424,7 +441,7 @@ static void increment_windows_lock_ref_count(files_struct *fsp)
        TALLOC_FREE(rec);
 
        DEBUG(10,("increment_windows_lock_ref_count for file now %s = %d\n",
-                 fsp->fsp_name, lock_ref_count ));
+                 fsp_str_dbg(fsp), lock_ref_count));
 }
 
 /****************************************************************************
@@ -460,7 +477,7 @@ void reduce_windows_lock_ref_count(files_struct *fsp, unsigned int dcount)
        TALLOC_FREE(rec);
 
        DEBUG(10,("reduce_windows_lock_ref_count for file now %s = %d\n",
-                 fsp->fsp_name, lock_ref_count ));
+                 fsp_str_dbg(fsp), lock_ref_count));
 }
 
 static void decrement_windows_lock_ref_count(files_struct *fsp)
@@ -492,7 +509,7 @@ static int get_windows_lock_ref_count(files_struct *fsp)
        }
 
        DEBUG(10,("get_windows_lock_count for file %s = %d\n",
-                 fsp->fsp_name, lock_ref_count ));
+                 fsp_str_dbg(fsp), lock_ref_count));
 
        return lock_ref_count;
 }
@@ -518,7 +535,7 @@ static void delete_windows_lock_ref_count(files_struct *fsp)
        TALLOC_FREE(rec);
 
        DEBUG(10,("delete_windows_lock_ref_count for file %s\n",
-                 fsp->fsp_name));
+                 fsp_str_dbg(fsp)));
 }
 
 /****************************************************************************
@@ -555,7 +572,7 @@ static void add_fd_to_close_entry(files_struct *fsp)
        TALLOC_FREE(rec);
 
        DEBUG(10,("add_fd_to_close_entry: added fd %d file %s\n",
-                 fsp->fh->fd, fsp->fsp_name ));
+                 fsp->fh->fd, fsp_str_dbg(fsp)));
 }
 
 /****************************************************************************
@@ -909,13 +926,12 @@ new: start=%.0f,size=%.0f\n", (double)l_curr->start, (double)l_curr->size,
                                 */
                                char *msg = NULL;
 
-                               /* Don't check if alloc succeeds here - we're
-                                * forcing a core dump anyway. */
-
-                               asprintf(&msg, "logic flaw in cases: l_curr: start = %.0f, size = %.0f : \
-lock: start = %.0f, size = %.0f", (double)l_curr->start, (double)l_curr->size, (double)lock->start, (double)lock->size );
-
-                               smb_panic(msg);
+                               if (asprintf(&msg, "logic flaw in cases: l_curr: start = %.0f, size = %.0f : \
+lock: start = %.0f, size = %.0f", (double)l_curr->start, (double)l_curr->size, (double)lock->start, (double)lock->size ) != -1) {
+                                       smb_panic(msg);
+                               } else {
+                                       smb_panic("posix_lock_list");
+                               }
                        }
                } /* end for ( l_curr = lhead; l_curr;) */
        } /* end for (i=0; i<num_locks && ul_head; i++) */
@@ -946,8 +962,10 @@ bool set_posix_lock_windows_flavour(files_struct *fsp,
        struct lock_list *llist = NULL;
        struct lock_list *ll = NULL;
 
-       DEBUG(5,("set_posix_lock_windows_flavour: File %s, offset = %.0f, count = %.0f, type = %s\n",
-                       fsp->fsp_name, (double)u_offset, (double)u_count, posix_lock_type_name(lock_type) ));
+       DEBUG(5,("set_posix_lock_windows_flavour: File %s, offset = %.0f, "
+                "count = %.0f, type = %s\n", fsp_str_dbg(fsp),
+                (double)u_offset, (double)u_count,
+                posix_lock_type_name(lock_type)));
 
        /*
         * If the requested lock won't fit in the POSIX range, we will
@@ -1080,8 +1098,9 @@ bool release_posix_lock_windows_flavour(files_struct *fsp,
        struct lock_list *ulist = NULL;
        struct lock_list *ul = NULL;
 
-       DEBUG(5,("release_posix_lock_windows_flavour: File %s, offset = %.0f, count = %.0f\n",
-               fsp->fsp_name, (double)u_offset, (double)u_count ));
+       DEBUG(5,("release_posix_lock_windows_flavour: File %s, offset = %.0f, "
+                "count = %.0f\n", fsp_str_dbg(fsp),
+                (double)u_offset, (double)u_count));
 
        /* Remember the number of Windows locks we have on this dev/ino pair. */
        decrement_windows_lock_ref_count(fsp);
@@ -1198,8 +1217,10 @@ bool set_posix_lock_posix_flavour(files_struct *fsp,
        SMB_OFF_T count;
        int posix_lock_type = map_posix_lock_type(fsp,lock_type);
 
-       DEBUG(5,("set_posix_lock_posix_flavour: File %s, offset = %.0f, count = %.0f, type = %s\n",
-                       fsp->fsp_name, (double)u_offset, (double)u_count, posix_lock_type_name(lock_type) ));
+       DEBUG(5,("set_posix_lock_posix_flavour: File %s, offset = %.0f, count "
+                "= %.0f, type = %s\n", fsp_str_dbg(fsp),
+                (double)u_offset, (double)u_count,
+                posix_lock_type_name(lock_type)));
 
        /*
         * If the requested lock won't fit in the POSIX range, we will
@@ -1242,8 +1263,9 @@ bool release_posix_lock_posix_flavour(files_struct *fsp,
        struct lock_list *ulist = NULL;
        struct lock_list *ul = NULL;
 
-       DEBUG(5,("release_posix_lock_posix_flavour: File %s, offset = %.0f, count = %.0f\n",
-               fsp->fsp_name, (double)u_offset, (double)u_count ));
+       DEBUG(5,("release_posix_lock_posix_flavour: File %s, offset = %.0f, "
+                "count = %.0f\n", fsp_str_dbg(fsp),
+                (double)u_offset, (double)u_count));
 
        /*
         * If the requested lock won't fit in the POSIX range, we will