diff options
author | Andrew Tridgell <tridge@samba.org> | 1998-09-18 03:00:20 +0000 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 1998-09-18 03:00:20 +0000 |
commit | 4e784b18899eddd2399a51fa7d8c219560432922 (patch) | |
tree | dbcf7f73a35659b8dfd4e2152ffe0eb53052f3ed /source | |
parent | 724b9508c2d15bafdad5912fce702108fdd4cac3 (diff) | |
download | samba-4e784b18899eddd2399a51fa7d8c219560432922.tar.gz samba-4e784b18899eddd2399a51fa7d8c219560432922.tar.xz samba-4e784b18899eddd2399a51fa7d8c219560432922.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.
Diffstat (limited to 'source')
-rw-r--r-- | source/include/includes.h | 8 | ||||
-rw-r--r-- | source/include/local.h | 5 | ||||
-rw-r--r-- | source/smbd/fileio.c | 22 | ||||
-rw-r--r-- | source/smbd/negprot.c | 7 | ||||
-rw-r--r-- | source/smbd/nttrans.c | 30 | ||||
-rw-r--r-- | source/smbd/open.c | 16 | ||||
-rw-r--r-- | source/smbd/trans2.c | 45 |
7 files changed, 49 insertions, 84 deletions
diff --git a/source/include/includes.h b/source/include/includes.h index 0f0bbdd89b9..9b6e6266dc7 100644 --- a/source/include/includes.h +++ b/source/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/source/include/local.h b/source/include/local.h index ead97e565d8..bf41af70d7a 100644 --- a/source/include/local.h +++ b/source/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/source/smbd/fileio.c b/source/smbd/fileio.c index d40c159798d..5c4bf7dfc23 100644 --- a/source/smbd/fileio.c +++ b/source/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/source/smbd/negprot.c b/source/smbd/negprot.c index e79743cfd4b..d4e6180261b 100644 --- a/source/smbd/negprot.c +++ b/source/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/source/smbd/nttrans.c b/source/smbd/nttrans.c index ee3385f152f..2d991eef20f 100644 --- a/source/smbd/nttrans.c +++ b/source/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/source/smbd/open.c b/source/smbd/open.c index a02fe91e683..394c7be3f80 100644 --- a/source/smbd/open.c +++ b/source/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/source/smbd/trans2.c b/source/smbd/trans2.c index 49687d4cca0..fe2869db937 100644 --- a/source/smbd/trans2.c +++ b/source/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; |