summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>1998-09-18 03:00:20 +0000
committerAndrew Tridgell <tridge@samba.org>1998-09-18 03:00:20 +0000
commitc7da9992cb39fc84a6a915dd2158beaf5e616617 (patch)
tree73f84eb8340e52b0362b3c7f84710062114194e4 /source3
parentfdc07d1417274d10038da83cee2ea718e6a7abec (diff)
downloadsamba-c7da9992cb39fc84a6a915dd2158beaf5e616617.tar.gz
samba-c7da9992cb39fc84a6a915dd2158beaf5e616617.tar.bz2
samba-c7da9992cb39fc84a6a915dd2158beaf5e616617.zip
gto ri of a bunch more #ifdef LARGE_SMB_OFF_T checks by introducing a
SOFF_T() macro for setting an SMB_OFF_T variable also limited mmap based reads to MAX_MMAP_SIZE. We really can't mmap 2^50 bytes due to virtual address space problems. (This used to be commit 4e784b18899eddd2399a51fa7d8c219560432922)
Diffstat (limited to 'source3')
-rw-r--r--source3/include/includes.h8
-rw-r--r--source3/include/local.h5
-rw-r--r--source3/smbd/fileio.c22
-rw-r--r--source3/smbd/negprot.c7
-rw-r--r--source3/smbd/nttrans.c30
-rw-r--r--source3/smbd/open.c16
-rw-r--r--source3/smbd/trans2.c45
7 files changed, 49 insertions, 84 deletions
diff --git a/source3/include/includes.h b/source3/include/includes.h
index 0f0bbdd89b..9b6e6266dc 100644
--- a/source3/include/includes.h
+++ b/source3/include/includes.h
@@ -353,6 +353,14 @@
#define SMB_OFF_T_BITS (sizeof(SMB_OFF_T)*8)
+
+#ifdef LARGE_SMB_OFF_T
+#define SOFF_T(p, ofs, v) (SIVAL(p,ofs,(v)&0xFFFFFFFF), SIVAL(p,(ofs)+4,(v)>>32))
+#else
+#define SOFF_T(p, ofs, v) SIVAL(p,ofs,v)
+#endif
+
+
/*
* Set the define that tells us if we can do 64 bit
* NT SMB calls.
diff --git a/source3/include/local.h b/source3/include/local.h
index ead97e565d..bf41af70d7 100644
--- a/source3/include/local.h
+++ b/source3/include/local.h
@@ -125,6 +125,11 @@
/* the size of the uid cache used to reduce valid user checks */
#define UID_CACHE_SIZE 4
+/* if mmap is enabled, then this is the maximum size of file to use
+ the mmap code on. We don't want to mmap huge files as virtual
+ address spaces are limited */
+#define MAX_MMAP_SIZE (100*0x100000)
+
/* the following control timings of various actions. Don't change
them unless you know what you are doing. These are all in seconds */
#define DEFAULT_SMBD_TIMEOUT (60*60*24*7)
diff --git a/source3/smbd/fileio.c b/source3/smbd/fileio.c
index d40c159798..5c4bf7dfc2 100644
--- a/source3/smbd/fileio.c
+++ b/source3/smbd/fileio.c
@@ -63,19 +63,15 @@ ssize_t read_file(files_struct *fsp,char *data,SMB_OFF_T pos,size_t n)
#if WITH_MMAP
if (fsp->mmap_ptr) {
- SMB_OFF_T num = (fsp->mmap_size > pos) ? (fsp->mmap_size - pos) : -1;
- num = MIN(n,num);
-#ifdef LARGE_SMB_OFF_T
- if ((num > 0) && (num < (1LL<<(sizeof(size_t)*8)))) {
-#else /* LARGE_SMB_OFF_T */
- if (num > 0) {
-#endif /* LARGE_SMB_OFF_T */
- memcpy(data,fsp->mmap_ptr+pos,num);
- data += num;
- pos += num;
- n -= num;
- ret += num;
- }
+ SMB_OFF_T num = (fsp->mmap_size > pos) ? (fsp->mmap_size - pos) : -1;
+ num = MIN(n,num);
+ if (num > 0) {
+ memcpy(data,fsp->mmap_ptr+pos,num);
+ data += num;
+ pos += num;
+ n -= num;
+ ret += num;
+ }
}
#endif
diff --git a/source3/smbd/negprot.c b/source3/smbd/negprot.c
index e79743cfd4..d4e6180261 100644
--- a/source3/smbd/negprot.c
+++ b/source3/smbd/negprot.c
@@ -161,11 +161,8 @@ static int reply_nt1(char *outbuf)
/* dual names + lock_and_read + nt SMBs + remote API calls */
int capabilities = CAP_NT_FIND|CAP_LOCK_AND_READ|
(lp_nt_smb_support() ? CAP_NT_SMBS | CAP_RPC_REMOTE_APIS : 0) |
-#ifdef LARGE_SMB_OFF_T
- (sizeof(SMB_OFF_T) == 8 ? CAP_LARGE_FILES : 0);
-#else
- 0;
-#endif
+ (SMB_OFF_T_BITS == 64 ? CAP_LARGE_FILES : 0);
+
/*
other valid capabilities which we may support at some time...
diff --git a/source3/smbd/nttrans.c b/source3/smbd/nttrans.c
index ee3385f152..2d991eef20 100644
--- a/source3/smbd/nttrans.c
+++ b/source3/smbd/nttrans.c
@@ -663,20 +663,10 @@ int reply_ntcreate_and_X(connection_struct *conn,
put_long_date(p,sbuf.st_mtime); /* change time */
p += 8;
SIVAL(p,0,fmode); /* File Attributes. */
- p += 4;
-#ifdef LARGE_SMB_OFF_T
- SIVAL(p,0, file_len);
- SIVAL(p,4, file_len >> 32);
-#else /* LARGE_SMB_OFF_T */
- SIVAL(p,0,file_len);
-#endif /* LARGE_SMB_OFF_T */
+ p += 4;
+ SOFF_T(p, 0, file_len);
p += 8;
-#ifdef LARGE_SMB_OFF_T
- SIVAL(p,0, file_len);
- SIVAL(p,4, file_len >> 32);
-#else /* LARGE_SMB_OFF_T */
- SIVAL(p,0,file_len);
-#endif /* LARGE_SMB_OFF_T */
+ SOFF_T(p,0,file_len);
p += 12;
SCVAL(p,0,fsp->is_directory ? 1 : 0);
@@ -900,19 +890,9 @@ static int call_nt_transact_create(connection_struct *conn,
p += 8;
SIVAL(p,0,fmode); /* File Attributes. */
p += 4;
-#ifdef LARGE_SMB_OFF_T
- SIVAL(p,0, file_len);
- SIVAL(p,4, (file_len >> 32));
-#else /* LARGE_SMB_OFF_T */
- SIVAL(p,0,file_len);
-#endif /* LARGE_SMB_OFF_T */
+ SOFF_T(p,0,file_len);
p += 8;
-#ifdef LARGE_SMB_OFF_T
- SIVAL(p,0, file_len);
- SIVAL(p,4, (file_len >> 32));
-#else /* LARGE_SMB_OFF_T */
- SIVAL(p,0,file_len);
-#endif /* LARGE_SMB_OFF_T */
+ SOFF_T(p,0,file_len);
}
/* Send the required number of replies */
diff --git a/source3/smbd/open.c b/source3/smbd/open.c
index a02fe91e68..394c7be3f8 100644
--- a/source3/smbd/open.c
+++ b/source3/smbd/open.c
@@ -541,13 +541,15 @@ static void open_file(files_struct *fsp,connection_struct *conn,
/* mmap it if read-only */
if (!fsp->can_write) {
fsp->mmap_size = file_size(fname);
- fsp->mmap_ptr = (char *)mmap(NULL,fsp->mmap_size,
- PROT_READ,MAP_SHARED,fsp->fd_ptr->fd,0);
-
- if (fsp->mmap_ptr == (char *)-1 || !fsp->mmap_ptr) {
- DEBUG(3,("Failed to mmap() %s - %s\n",
- fname,strerror(errno)));
- fsp->mmap_ptr = NULL;
+ if (fsp->mmap_size < MAX_MMAP_SIZE) {
+ fsp->mmap_ptr = (char *)mmap(NULL,fsp->mmap_size,
+ PROT_READ,MAP_SHARED,fsp->fd_ptr->fd,0);
+
+ if (fsp->mmap_ptr == (char *)-1 || !fsp->mmap_ptr) {
+ DEBUG(3,("Failed to mmap() %s - %s\n",
+ fname,strerror(errno)));
+ fsp->mmap_ptr = NULL;
+ }
}
}
#endif
diff --git a/source3/smbd/trans2.c b/source3/smbd/trans2.c
index 49687d4cca..fe2869db93 100644
--- a/source3/smbd/trans2.c
+++ b/source3/smbd/trans2.c
@@ -489,12 +489,8 @@ static int get_lanman2_dir_entry(connection_struct *conn,
put_long_date(p,adate); p += 8;
put_long_date(p,mdate); p += 8;
put_long_date(p,mdate); p += 8;
- SIVAL(p,0,size);
- SIVAL(p,8,size);
-#ifdef LARGE_SMB_OFF_T
- SIVAL(p,4,size >> 32);
- SIVAL(p,12,size >> 32);
-#endif /* LARGE_SMB_OFF_T */
+ SOFF_T(p,0,size);
+ SOFF_T(p,8,size);
p += 16;
SIVAL(p,0,nt_extmode); p += 4;
SIVAL(p,0,strlen(fname)); p += 4;
@@ -522,12 +518,8 @@ static int get_lanman2_dir_entry(connection_struct *conn,
put_long_date(p,adate); p += 8;
put_long_date(p,mdate); p += 8;
put_long_date(p,mdate); p += 8;
- SIVAL(p,0,size);
- SIVAL(p,8,size);
-#ifdef LARGE_SMB_OFF_T
- SIVAL(p,4,size >> 32);
- SIVAL(p,12,size >> 32);
-#endif /* LARGE_SMB_OFF_T */
+ SOFF_T(p,0,size);
+ SOFF_T(p,8,size);
p += 16;
SIVAL(p,0,nt_extmode); p += 4;
SIVAL(p,0,strlen(fname)); p += 4;
@@ -545,12 +537,8 @@ static int get_lanman2_dir_entry(connection_struct *conn,
put_long_date(p,adate); p += 8;
put_long_date(p,mdate); p += 8;
put_long_date(p,mdate); p += 8;
- SIVAL(p,0,size);
- SIVAL(p,8,size);
-#ifdef LARGE_SMB_OFF_T
- SIVAL(p,4,size >> 32);
- SIVAL(p,12,size >> 32);
-#endif /* LARGE_SMB_OFF_T */
+ SOFF_T(p,0,size);
+ SOFF_T(p,8,size);
p += 16;
SIVAL(p,0,nt_extmode); p += 4;
SIVAL(p,0,strlen(fname)); p += 4;
@@ -1349,12 +1337,8 @@ static int call_trans2qfilepathinfo(connection_struct *conn,
case SMB_QUERY_FILE_STANDARD_INFO:
data_size = 22;
- SIVAL(pdata,0,size);
- SIVAL(pdata,8,size);
-#ifdef LARGE_SMB_OFF_T
- SIVAL(pdata,4,size>>32);
- SIVAL(pdata,12,size>>32);
-#endif /* LARGE_SMB_OFF_T */
+ SOFF_T(pdata,0,size);
+ SOFF_T(pdata,8,size);
SIVAL(pdata,16,sbuf.st_nlink);
CVAL(pdata,20) = 0;
CVAL(pdata,21) = (mode&aDIR)?1:0;
@@ -1392,10 +1376,7 @@ static int call_trans2qfilepathinfo(connection_struct *conn,
case SMB_QUERY_FILE_ALLOCATION_INFO:
case SMB_QUERY_FILE_END_OF_FILEINFO:
data_size = 8;
- SIVAL(pdata,0,size);
-#ifdef LARGE_SMB_OFF_T
- SIVAL(pdata,4,size >> 32);
-#endif /* LARGE_SMB_OFF_T */
+ SOFF_T(pdata,0,size);
break;
case SMB_QUERY_FILE_ALL_INFO:
@@ -1405,12 +1386,8 @@ static int call_trans2qfilepathinfo(connection_struct *conn,
put_long_date(pdata+24,sbuf.st_mtime); /* change time */
SIVAL(pdata,32,mode);
pdata += 40;
- SIVAL(pdata,0,size);
- SIVAL(pdata,8,size);
-#ifdef LARGE_SMB_OFF_T
- SIVAL(pdata,4,size >> 32);
- SIVAL(pdata,12,size >> 32);
-#endif /* LARGE_SMB_OFF_T */
+ SOFF_T(pdata,0,size);
+ SOFF_T(pdata,8,size);
SIVAL(pdata,16,sbuf.st_nlink);
CVAL(pdata,20) = 0;
CVAL(pdata,21) = (mode&aDIR)?1:0;