summaryrefslogtreecommitdiff
path: root/source3/lib/util.c
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/lib/util.c
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/lib/util.c')
-rw-r--r--source3/lib/util.c114
1 files changed, 59 insertions, 55 deletions
diff --git a/source3/lib/util.c b/source3/lib/util.c
index 8b10939a97..891b11facc 100644
--- a/source3/lib/util.c
+++ b/source3/lib/util.c
@@ -566,7 +566,7 @@ BOOL directory_exist(char *dname,SMB_STRUCT_STAT *st)
/*******************************************************************
returns the size in bytes of the named file
********************************************************************/
-uint32 file_size(char *file_name)
+SMB_OFF_T file_size(char *file_name)
{
SMB_STRUCT_STAT buf;
buf.st_size = 0;
@@ -1218,15 +1218,15 @@ struct
{
SMB_DEV_T dev; /* These *must* be compatible with the types returned in a stat() call. */
SMB_INO_T inode; /* These *must* be compatible with the types returned in a stat() call. */
- char *text;
+ char *text; /* The pathname in DOS format. */
BOOL valid;
} ino_list[MAX_GETWDCACHE];
BOOL use_getwd_cache=True;
/*******************************************************************
- return the absolute current directory path
- Note that this path is returned in UNIX format, not DOS
+ return the absolute current directory path - given a UNIX pathname.
+ Note that this path is returned in DOS format, not UNIX
format.
********************************************************************/
char *GetWd(char *str)
@@ -1239,7 +1239,7 @@ char *GetWd(char *str)
*s = 0;
if (!use_getwd_cache)
- return(sys_getwd(str));
+ return(dos_getwd(str));
/* init the cache */
if (!getwd_cache_init)
@@ -1255,10 +1255,10 @@ char *GetWd(char *str)
/* Get the inode of the current directory, if this doesn't work we're
in trouble :-) */
- if (stat(".",&st) == -1)
+ if (dos_stat(".",&st) == -1)
{
DEBUG(0,("Very strange, couldn't stat \".\"\n"));
- return(sys_getwd(str));
+ return(dos_getwd(str));
}
@@ -1275,7 +1275,7 @@ char *GetWd(char *str)
if (st.st_ino == ino_list[i].inode &&
st.st_dev == ino_list[i].dev)
{
- if (stat(ino_list[i].text,&st2) == 0)
+ if (dos_stat(ino_list[i].text,&st2) == 0)
{
if (st.st_ino == st2.st_ino &&
st.st_dev == st2.st_dev &&
@@ -1302,7 +1302,7 @@ char *GetWd(char *str)
The very slow getcwd, which spawns a process on some systems, or the
not quite so bad getwd. */
- if (!sys_getwd(s))
+ if (!dos_getwd(s))
{
DEBUG(0,("Getwd failed, errno %s\n",strerror(errno)));
return (NULL);
@@ -1692,7 +1692,7 @@ int count_chars(char *s,char c)
/****************************************************************************
make a dir struct
****************************************************************************/
-void make_dir_struct(char *buf,char *mask,char *fname,unsigned int size,int mode,time_t date)
+void make_dir_struct(char *buf,char *mask,char *fname,SMB_OFF_T size,int mode,time_t date)
{
char *p;
pstring mask2;
@@ -1717,7 +1717,7 @@ void make_dir_struct(char *buf,char *mask,char *fname,unsigned int size,int mode
CVAL(buf,21) = mode;
put_dos_date(buf,22,date);
SSVAL(buf,26,size & 0xFFFF);
- SSVAL(buf,28,size >> 16);
+ SSVAL(buf,28,(size >> 16)&0xFFFF);
StrnCpy(buf+30,fname,12);
if (!case_sensitive)
strupper(buf+30);
@@ -2054,14 +2054,18 @@ int write_data(int fd,char *buffer,int N)
/****************************************************************************
transfer some data between two fd's
****************************************************************************/
-int transfer_file(int infd,int outfd,int n,char *header,int headlen,int align)
+SMB_OFF_T transfer_file(int infd,int outfd,SMB_OFF_T n,char *header,int headlen,int align)
{
static char *buf=NULL;
static int size=0;
char *buf1,*abuf;
- int total = 0;
+ SMB_OFF_T total = 0;
- DEBUG(4,("transfer_file %d (head=%d) called\n",n,headlen));
+#ifdef LARGE_SMB_OFF_T
+ DEBUG(4,("transfer_file n=%.0f (head=%d) called\n",(double)n,headlen));
+#else /* LARGE_SMB_OFF_T */
+ DEBUG(4,("transfer_file n=%d (head=%d) called\n",n,headlen));
+#endif /* LARGE_SMB_OFF_T */
if (size == 0) {
size = lp_readsize();
@@ -2084,46 +2088,46 @@ int transfer_file(int infd,int outfd,int n,char *header,int headlen,int align)
n += headlen;
while (n > 0)
- {
- int s = MIN(n,size);
- int ret,ret2=0;
+ {
+ int s = (int)MIN(n,(SMB_OFF_T)size);
+ int ret,ret2=0;
- ret = 0;
+ ret = 0;
- if (header && (headlen >= MIN(s,1024))) {
- buf1 = header;
- s = headlen;
- ret = headlen;
- headlen = 0;
- header = NULL;
- } else {
- buf1 = abuf;
- }
+ if (header && (headlen >= MIN(s,1024))) {
+ buf1 = header;
+ s = headlen;
+ ret = headlen;
+ headlen = 0;
+ header = NULL;
+ } else {
+ buf1 = abuf;
+ }
- if (header && headlen > 0)
- {
- ret = MIN(headlen,size);
- memcpy(buf1,header,ret);
- headlen -= ret;
- header += ret;
- if (headlen <= 0) header = NULL;
- }
+ if (header && headlen > 0)
+ {
+ ret = MIN(headlen,size);
+ memcpy(buf1,header,ret);
+ headlen -= ret;
+ header += ret;
+ if (headlen <= 0) header = NULL;
+ }
- if (s > ret)
- ret += read(infd,buf1+ret,s-ret);
+ if (s > ret)
+ ret += read(infd,buf1+ret,s-ret);
- if (ret > 0)
- {
- ret2 = (outfd>=0?write_data(outfd,buf1,ret):ret);
- if (ret2 > 0) total += ret2;
- /* if we can't write then dump excess data */
- if (ret2 != ret)
- transfer_file(infd,-1,n-(ret+headlen),NULL,0,0);
- }
- if (ret <= 0 || ret2 != ret)
- return(total);
- n -= ret;
+ if (ret > 0)
+ {
+ ret2 = (outfd>=0?write_data(outfd,buf1,ret):ret);
+ if (ret2 > 0) total += ret2;
+ /* if we can't write then dump excess data */
+ if (ret2 != ret)
+ transfer_file(infd,-1,n-(ret+headlen),NULL,0,0);
}
+ if (ret <= 0 || ret2 != ret)
+ return(total);
+ n -= ret;
+ }
return(total);
}
@@ -3261,18 +3265,18 @@ char *fgets_slash(char *s2,int maxlen,FILE *f)
set the length of a file from a filedescriptor.
Returns 0 on success, -1 on failure.
****************************************************************************/
-int set_filelen(int fd, long len)
+int set_filelen(int fd, SMB_OFF_T len)
{
/* According to W. R. Stevens advanced UNIX prog. Pure 4.3 BSD cannot
extend a file with ftruncate. Provide alternate implementation
for this */
#ifdef HAVE_FTRUNCATE_EXTEND
- return ftruncate(fd, len);
+ return sys_ftruncate(fd, len);
#else
SMB_STRUCT_STAT st;
char c = 0;
- long currpos = lseek(fd, 0L, SEEK_CUR);
+ SMB_OFF_T currpos = sys_lseek(fd, (SMB_OFF_T)0, SEEK_CUR);
if(currpos < 0)
return -1;
@@ -3280,7 +3284,7 @@ int set_filelen(int fd, long len)
the requested size (call ftruncate),
or shorter, in which case seek to len - 1 and write 1
byte of zero */
- if(fstat(fd, &st)<0)
+ if(sys_fstat(fd, &st)<0)
return -1;
#ifdef S_ISFIFO
@@ -3290,14 +3294,14 @@ int set_filelen(int fd, long len)
if(st.st_size == len)
return 0;
if(st.st_size > len)
- return ftruncate(fd, len);
+ return sys_ftruncate(fd, len);
- if(lseek(fd, len-1, SEEK_SET) != len -1)
+ if(sys_lseek(fd, len-1, SEEK_SET) != len -1)
return -1;
if(write(fd, &c, 1)!=1)
return -1;
/* Seek to where we were */
- lseek(fd, currpos, SEEK_SET);
+ sys_lseek(fd, currpos, SEEK_SET);
return 0;
#endif
}