mirror of
https://github.com/samba-team/samba.git
synced 2025-03-03 12:58:35 +03:00
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 commit is contained in:
parent
724b9508c2
commit
4e784b1889
@ -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.
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
||||
|
@ -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...
|
||||
|
@ -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 */
|
||||
|
@ -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_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;
|
||||
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
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user