gto ri of a bunch more #ifdef LARGE_SMB_OFF_T checks by introducing a
authorAndrew Tridgell <tridge@samba.org>
Fri, 18 Sep 1998 03:00:20 +0000 (03:00 +0000)
committerAndrew Tridgell <tridge@samba.org>
Fri, 18 Sep 1998 03:00:20 +0000 (03:00 +0000)
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.

source/include/includes.h
source/include/local.h
source/smbd/fileio.c
source/smbd/negprot.c
source/smbd/nttrans.c
source/smbd/open.c
source/smbd/trans2.c

index 0f0bbdd89b99ae323920e515e6cdaba851511606..9b6e6266dc7dad3c06b364a6c60fa031856c5c1c 100644 (file)
 
 #define SMB_OFF_T_BITS (sizeof(SMB_OFF_T)*8)
 
 
 #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.
 /*
  * Set the define that tells us if we can do 64 bit
  * NT SMB calls.
index ead97e565d801e5f645012045804d0d4d2479c55..bf41af70d7a0b21b228eace114c0a00d33a4afd4 100644 (file)
 /* the size of the uid cache used to reduce valid user checks */
 #define UID_CACHE_SIZE 4
 
 /* 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)
 /* 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)
index d40c159798df42c6bbee102afe4a85befed714ff..5c4bf7dfc23083ab433779951d66d06bc9c209af 100644 (file)
@@ -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) {
 
 #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
 
   }
 #endif
 
index e79743cfd4b66e29b5ad1c686b9bc0e50a323535..d4e6180261bcb2598b8f8224b8c1a9aef3c1921d 100644 (file)
@@ -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) |
   /* 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...
 
 /*
   other valid capabilities which we may support at some time...
index ee3385f152fa86ac26f9bb8a46a041f91c169e39..2d991eef20f765efaf0e9c84931686d334db7708 100644 (file)
@@ -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. */
        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;
        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);
        
        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;
     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;
     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 */
   }
 
   /* Send the required number of replies */
index a02fe91e683c4f622bb462e679c9397815ea55b2..394c7be3f80eb683dab57604df2123d3899e008b 100644 (file)
@@ -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);
   /* 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
          }
   }
 #endif
index 49687d4cca0bfdf4d6810f6c9008a34e927c78f5..fe2869db937b08d13e837e732130b5aa8829ba19 100644 (file)
@@ -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;
       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;
       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;
       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;
       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;
       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;
       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;
 
     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;
       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;
     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:
       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;
       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;
       SIVAL(pdata,16,sbuf.st_nlink);
       CVAL(pdata,20) = 0;
       CVAL(pdata,21) = (mode&aDIR)?1:0;