summaryrefslogtreecommitdiff
path: root/source3/locking
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>1998-09-03 18:40:31 +0000
committerJeremy Allison <jra@samba.org>1998-09-03 18:40:31 +0000
commit7bb86c1b132bce31a006ea9768a54db7a45fe1a5 (patch)
tree1802e8e2741345e91187fc4b149016af75990971 /source3/locking
parent4acd373e5bbd615141ceb5fb3c4a588a5b4581d7 (diff)
downloadsamba-7bb86c1b132bce31a006ea9768a54db7a45fe1a5.tar.gz
samba-7bb86c1b132bce31a006ea9768a54db7a45fe1a5.tar.bz2
samba-7bb86c1b132bce31a006ea9768a54db7a45fe1a5.zip
Ok - this is the 64 bit widening check in. It changes the configure
to check for stat64 and friends, and then changes much of Samba to use the data type SMB_OFF_T for file size information. stat/fstat/lstat/lseek/ftruncate have now become sys_stat etc. to hide the 64 bit calls if needed. Note that this still does not expose 64 bit functionality to the client, as the changes to the reply_xxx smb's are not yet done. This code change should make these changes possible. Still to do before full 64 bit-ness to the client: fcntl lock code. statfs code widening of dev_t and ino_t (now possible due to SMB_DEV_T and SMB_OFF_T types being in place). Let me know if wierd things happen after this check-in and I'll fix them :-). Jeremy. (This used to be commit 14500936c321d15995c963766aac67bf1f4e3824)
Diffstat (limited to 'source3/locking')
-rw-r--r--source3/locking/locking_slow.c38
-rw-r--r--source3/locking/shmem.c93
2 files changed, 79 insertions, 52 deletions
diff --git a/source3/locking/locking_slow.c b/source3/locking/locking_slow.c
index 4c2ba43cd8..c242baec4a 100644
--- a/source3/locking/locking_slow.c
+++ b/source3/locking/locking_slow.c
@@ -188,7 +188,7 @@ static BOOL slow_lock_share_entry(connection_struct *conn,
* the open and the lock call. Back out and try again.
*/
- if(stat(fname, &dummy_stat)!=0)
+ if(sys_stat(fname, &dummy_stat)!=0)
{
DEBUG(2,("lock_share_entry: Re-issuing open on %s to fix race. Error was %s\n",
fname, strerror(errno)));
@@ -232,7 +232,7 @@ static BOOL slow_unlock_share_entry(connection_struct *conn,
share_name(conn, dev, inode, fname);
/* get the share mode file size */
- if(fstat((int)token, &sb) != 0)
+ if(sys_fstat((int)token, &sb) != 0)
{
DEBUG(0,("ERROR: unlock_share_entry: Failed to do stat on share file %s (%s)\n",
fname, strerror(errno)));
@@ -269,12 +269,12 @@ static int read_share_file(connection_struct *conn, int fd, char *fname, char **
{
SMB_STRUCT_STAT sb;
char *buf;
- int size;
+ SMB_OFF_T size;
*out = 0;
*p_new_file = False;
- if(fstat(fd, &sb) != 0)
+ if(sys_fstat(fd, &sb) != 0)
{
DEBUG(0,("ERROR: read_share_file: Failed to do stat on share file %s (%s)\n",
fname, strerror(errno)));
@@ -288,14 +288,14 @@ static int read_share_file(connection_struct *conn, int fd, char *fname, char **
}
/* Allocate space for the file */
- if((buf = (char *)malloc(sb.st_size)) == NULL)
+ if((buf = (char *)malloc((size_t)sb.st_size)) == NULL)
{
DEBUG(0,("read_share_file: malloc for file size %d fail !\n",
(int)sb.st_size));
return -1;
}
- if(lseek(fd, 0, SEEK_SET) != 0)
+ if(sys_lseek(fd, (SMB_OFF_T)0, SEEK_SET) != 0)
{
DEBUG(0,("ERROR: read_share_file: Failed to reset position to 0 \
for share file %s (%s)\n", fname, strerror(errno)));
@@ -304,7 +304,7 @@ for share file %s (%s)\n", fname, strerror(errno)));
return -1;
}
- if (read(fd,buf,sb.st_size) != sb.st_size)
+ if (read(fd,buf,(size_t)sb.st_size) != (size_t)sb.st_size)
{
DEBUG(0,("ERROR: read_share_file: Failed to read share file %s (%s)\n",
fname, strerror(errno)));
@@ -472,7 +472,7 @@ it left a share mode entry with mode 0x%X in share file %s\n",
if(num_entries_copied != num_entries)
{
- if(lseek(fd, 0, SEEK_SET) != 0)
+ if(sys_lseek(fd, (SMB_OFF_T)0, SEEK_SET) != 0)
{
DEBUG(0,("ERROR: get_share_modes: lseek failed to reset to \
position 0 for share mode file %s (%s)\n", fname, strerror(errno)));
@@ -510,7 +510,7 @@ mode file %s (%s)\n", fname, strerror(errno)));
return 0;
}
/* Now truncate the file at this point. */
- if(ftruncate(fd, newsize)!= 0)
+ if(sys_ftruncate(fd, (SMB_OFF_T)newsize)!= 0)
{
DEBUG(0,("ERROR: get_share_modes: failed to ftruncate share \
mode file %s to size %d (%s)\n", fname, newsize, strerror(errno)));
@@ -642,7 +642,7 @@ for share file %s\n", num_entries, fname));
}
/* Re-write the file - and truncate it at the correct point. */
- if(lseek(fd, 0, SEEK_SET) != 0)
+ if(sys_lseek(fd, (SMB_OFF_T)0, SEEK_SET) != 0)
{
DEBUG(0,("ERROR: del_share_mode: lseek failed to reset to \
position 0 for share mode file %s (%s)\n", fname, strerror(errno)));
@@ -662,7 +662,7 @@ mode file %s (%s)\n", fname, strerror(errno)));
}
/* Now truncate the file at this point. */
- if(ftruncate(fd, newsize) != 0)
+ if(sys_ftruncate(fd, (SMB_OFF_T)newsize) != 0)
{
DEBUG(0,("ERROR: del_share_mode: failed to ftruncate share \
mode file %s to size %d (%s)\n", fname, newsize, strerror(errno)));
@@ -689,7 +689,7 @@ static BOOL slow_set_share_mode(int token,files_struct *fsp, uint16 port, uint16
share_name(fsp->conn, fsp->fd_ptr->dev,
fsp->fd_ptr->inode, fname);
- if(fstat(fd, &sb) != 0)
+ if(sys_fstat(fd, &sb) != 0)
{
DEBUG(0,("ERROR: set_share_mode: Failed to do stat on share file %s\n",
fname));
@@ -699,17 +699,17 @@ static BOOL slow_set_share_mode(int token,files_struct *fsp, uint16 port, uint16
/* Sanity check for file contents (if it's not a new share file). */
if(sb.st_size != 0)
{
- int size = sb.st_size;
+ SMB_OFF_T size = sb.st_size;
/* Allocate space for the file plus one extra entry */
- if((buf = (char *)malloc(sb.st_size + SMF_ENTRY_LENGTH)) == NULL)
+ if((buf = (char *)malloc((size_t)(sb.st_size + SMF_ENTRY_LENGTH))) == NULL)
{
DEBUG(0,("set_share_mode: malloc for file size %d fail !\n",
(int)(sb.st_size + SMF_ENTRY_LENGTH)));
return False;
}
- if(lseek(fd, 0, SEEK_SET) != 0)
+ if(sys_lseek(fd, (SMB_OFF_T)0, SEEK_SET) != 0)
{
DEBUG(0,("ERROR: set_share_mode: Failed to reset position \
to 0 for share file %s (%s)\n", fname, strerror(errno)));
@@ -718,7 +718,7 @@ to 0 for share file %s (%s)\n", fname, strerror(errno)));
return False;
}
- if (read(fd,buf,sb.st_size) != sb.st_size)
+ if (read(fd,buf,(size_t)sb.st_size) != (size_t)sb.st_size)
{
DEBUG(0,("ERROR: set_share_mode: Failed to read share file %s (%s)\n",
fname, strerror(errno)));
@@ -781,7 +781,7 @@ deleting it.\n", fname));
SIVAL(buf,SMF_NUM_ENTRIES_OFFSET,num_entries);
- if(lseek(fd, 0, SEEK_SET) != 0)
+ if(sys_lseek(fd, (SMB_OFF_T)0, SEEK_SET) != 0)
{
DEBUG(0,("ERROR: set_share_mode: (1) Failed to reset position to \
0 for share file %s (%s)\n", fname, strerror(errno)));
@@ -803,7 +803,7 @@ deleting it (%s).\n",fname, strerror(errno)));
/* Now truncate the file at this point - just for safety. */
- if(ftruncate(fd, header_size + (SMF_ENTRY_LENGTH*num_entries))!= 0)
+ if(sys_ftruncate(fd, (SMB_OFF_T)(header_size + (SMF_ENTRY_LENGTH*num_entries)))!= 0)
{
DEBUG(0,("ERROR: set_share_mode: failed to ftruncate share \
mode file %s to size %d (%s)\n", fname, header_size + (SMF_ENTRY_LENGTH*num_entries),
@@ -916,7 +916,7 @@ from the share file %s\n", i, num_entries, fname));
}
/* Re-write the file - and truncate it at the correct point. */
- if(lseek(fd, 0, SEEK_SET) != 0)
+ if(sys_lseek(fd, (SMB_OFF_T)0, SEEK_SET) != 0)
{
DEBUG(0,("ERROR: remove_share_oplock: lseek failed to reset to \
position 0 for share mode file %s (%s)\n", fname, strerror(errno)));
diff --git a/source3/locking/shmem.c b/source3/locking/shmem.c
index 6015085fe4..8a81d0efff 100644
--- a/source3/locking/shmem.c
+++ b/source3/locking/shmem.c
@@ -314,9 +314,9 @@ static BOOL smb_shm_register_process(char *processreg_file, pid_t pid, BOOL *oth
int smb_shm_processes_fd = -1;
int nb_read;
pid_t other_pid;
- int seek_back = -((int)sizeof(other_pid));
- int free_slot = -1;
- int erased_slot;
+ SMB_OFF_T seek_back = -((SMB_OFF_T)sizeof(other_pid));
+ SMB_OFF_T free_slot = -1;
+ SMB_OFF_T erased_slot;
smb_shm_processes_fd = open(processreg_file,
read_only?O_RDONLY:(O_RDWR|O_CREAT),
@@ -339,10 +339,15 @@ static BOOL smb_shm_register_process(char *processreg_file, pid_t pid, BOOL *oth
else
{
/* erase old pid */
+#ifdef LARGE_SMB_OFF_T
+ DEBUG(5,("smb_shm_register_process : erasing stale record for pid %d (seek_back = %.0f)\n",
+ (int)other_pid, (double)seek_back));
+#else
DEBUG(5,("smb_shm_register_process : erasing stale record for pid %d (seek_back = %d)\n",
(int)other_pid, seek_back));
+#endif
other_pid = (pid_t)0;
- erased_slot = lseek(smb_shm_processes_fd, seek_back, SEEK_CUR);
+ erased_slot = sys_lseek(smb_shm_processes_fd, seek_back, SEEK_CUR);
write(smb_shm_processes_fd, &other_pid, sizeof(other_pid));
if(free_slot < 0)
free_slot = erased_slot;
@@ -350,7 +355,7 @@ static BOOL smb_shm_register_process(char *processreg_file, pid_t pid, BOOL *oth
}
else
if(free_slot < 0)
- free_slot = lseek(smb_shm_processes_fd, seek_back, SEEK_CUR);
+ free_slot = sys_lseek(smb_shm_processes_fd, seek_back, SEEK_CUR);
}
if (nb_read < 0)
{
@@ -360,11 +365,17 @@ static BOOL smb_shm_register_process(char *processreg_file, pid_t pid, BOOL *oth
}
if(free_slot < 0)
- free_slot = lseek(smb_shm_processes_fd, 0, SEEK_END);
+ free_slot = sys_lseek(smb_shm_processes_fd, 0, SEEK_END);
+#ifdef LARGE_SMB_OFF_T
+ DEBUG(5,("smb_shm_register_process : writing record for pid %d at offset %.0f\n",
+ (int)pid, (double)free_slot));
+#else /* LARGE_SMB_OFF_T */
DEBUG(5,("smb_shm_register_process : writing record for pid %d at offset %d\n",
(int)pid,free_slot));
- lseek(smb_shm_processes_fd, free_slot, SEEK_SET);
+#endif /* LARGE_SMB_OFF_T */
+
+ sys_lseek(smb_shm_processes_fd, free_slot, SEEK_SET);
if(write(smb_shm_processes_fd, &pid, sizeof(pid)) < 0)
{
DEBUG(0,("ERROR smb_shm_register_process : processreg_file write failed with code %s\n",strerror(errno)));
@@ -382,8 +393,8 @@ static BOOL smb_shm_unregister_process(char *processreg_file, pid_t pid)
int smb_shm_processes_fd = -1;
int nb_read;
pid_t other_pid;
- int seek_back = -((int)sizeof(other_pid));
- int erased_slot;
+ SMB_OFF_T seek_back = -((SMB_OFF_T)sizeof(other_pid));
+ SMB_OFF_T erased_slot;
BOOL found = False;
@@ -399,20 +410,25 @@ static BOOL smb_shm_unregister_process(char *processreg_file, pid_t pid)
DEBUG(5,("smb_shm_unregister_process : read record for pid %d\n",(int)other_pid));
if(other_pid == pid)
{
- /* erase pid */
- DEBUG(5,("smb_shm_unregister_process : erasing record for pid %d (seek_val = %d)\n",
+ /* erase pid */
+#ifdef LARGE_SMB_OFF_T
+ DEBUG(5,("smb_shm_unregister_process : erasing record for pid %d (seek_val = %.0f)\n",
+ (int)other_pid, (double)seek_back));
+#else /* LARGE_SMB_OFF_T */
+ DEBUG(5,("smb_shm_unregister_process : erasing record for pid %d (seek_val = %d)\n",
(int)other_pid, seek_back));
- other_pid = (pid_t)0;
- erased_slot = lseek(smb_shm_processes_fd, seek_back, SEEK_CUR);
- if(write(smb_shm_processes_fd, &other_pid, sizeof(other_pid)) < 0)
- {
- DEBUG(0,("ERROR smb_shm_unregister_process : processreg_file write failed with code %s\n",strerror(errno)));
- close(smb_shm_processes_fd);
- return False;
- }
+#endif /* LARGE_SMB_OFF_T */
+ other_pid = (pid_t)0;
+ erased_slot = sys_lseek(smb_shm_processes_fd, seek_back, SEEK_CUR);
+ if(write(smb_shm_processes_fd, &other_pid, sizeof(other_pid)) < 0)
+ {
+ DEBUG(0,("ERROR smb_shm_unregister_process : processreg_file write failed with code %s\n",strerror(errno)));
+ close(smb_shm_processes_fd);
+ return False;
+ }
- found = True;
- break;
+ found = True;
+ break;
}
}
if (nb_read < 0)
@@ -750,10 +766,10 @@ static struct shmem_ops shmops = {
struct shmem_ops *smb_shm_open(int ronly)
{
pstring file_name;
- int filesize;
+ SMB_OFF_T filesize;
BOOL created_new = False;
BOOL other_processes = True;
- int size = lp_shmem_size();
+ SMB_OFF_T size = (SMB_OFF_T)lp_shmem_size();
read_only = ronly;
@@ -766,7 +782,11 @@ struct shmem_ops *smb_shm_open(int ronly)
if (!*file_name) return(False);
pstrcat(file_name, "/SHARE_MEM_FILE");
+#ifdef LARGE_SMB_OFF_T
+ DEBUG(5,("smb_shm_open : using shmem file %s to be of size %.0f\n",file_name,(double)size));
+#else /* LARGE_SMB_OFF_T */
DEBUG(5,("smb_shm_open : using shmem file %s to be of size %d\n",file_name,size));
+#endif /* LARGE_SMB_OFF_T */
smb_shm_fd = open(file_name, read_only?O_RDONLY:(O_RDWR|O_CREAT),
SHM_FILE_MODE);
@@ -783,7 +803,7 @@ struct shmem_ops *smb_shm_open(int ronly)
return NULL;
}
- if( (filesize = lseek(smb_shm_fd, 0, SEEK_END)) < 0)
+ if( (filesize = sys_lseek(smb_shm_fd, 0, SEEK_END)) < 0)
{
DEBUG(0,("ERROR smb_shm_open : lseek failed with code %s\n",strerror(errno)));
smb_shm_global_unlock();
@@ -792,7 +812,7 @@ struct shmem_ops *smb_shm_open(int ronly)
}
/* return the file offset to 0 to save on later seeks */
- lseek(smb_shm_fd,0,SEEK_SET);
+ sys_lseek(smb_shm_fd,0,SEEK_SET);
if (filesize == 0)
{
@@ -819,17 +839,17 @@ struct shmem_ops *smb_shm_open(int ronly)
if (!read_only && (created_new || !other_processes))
{
/* we just created a new one, or are the first opener, lets set it size */
- if( ftruncate(smb_shm_fd, size) <0)
+ if( sys_ftruncate(smb_shm_fd, size) <0)
{
- DEBUG(0,("ERROR smb_shm_open : ftruncate failed with code %s\n",strerror(errno)));
- smb_shm_unregister_process(smb_shm_processreg_name, getpid());
- smb_shm_global_unlock();
- close(smb_shm_fd);
- return NULL;
+ DEBUG(0,("ERROR smb_shm_open : ftruncate failed with code %s\n",strerror(errno)));
+ smb_shm_unregister_process(smb_shm_processreg_name, getpid());
+ smb_shm_global_unlock();
+ close(smb_shm_fd);
+ return NULL;
}
/* paranoia */
- lseek(smb_shm_fd,0,SEEK_SET);
+ sys_lseek(smb_shm_fd,0,SEEK_SET);
filesize = size;
}
@@ -838,7 +858,14 @@ struct shmem_ops *smb_shm_open(int ronly)
{
/* the existing file has a different size and we are not the first opener.
Since another process is still using it, we will use the file size */
- DEBUG(0,("WARNING smb_shm_open : filesize (%d) != expected size (%d), using filesize\n",filesize,size));
+#ifdef LARGE_SMB_OFF_T
+ DEBUG(0,("WARNING smb_shm_open : filesize (%.0f) != expected size (%.0f), using filesize\n",
+ (double)filesize, (double)size));
+#else /* LARGE_SMB_OFF_T */
+ DEBUG(0,("WARNING smb_shm_open : filesize (%d) != expected size (%d), using filesize\n",
+ filesize,size));
+#endif /* LARGE_SMB_OFF_T */
+
size = filesize;
}