Author: tridge
Date: 2006-10-28 06:06:15 +0000 (Sat, 28 Oct 2006)
New Revision: 19504

WebSVN: 
http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=19504

Log:

- fixed a free error in file_lines_parse

- added a function to test for large file support

- enable CAP_LARGE_FILES only if the test passes

- don't test at large offsets if the server doesn't set
  CAP_LARGE_FILES

Modified:
   branches/SAMBA_4_0/source/lib/util/util_file.c
   branches/SAMBA_4_0/source/smb_server/smb/negprot.c
   branches/SAMBA_4_0/source/torture/raw/read.c
   branches/SAMBA_4_0/source/torture/raw/write.c


Changeset:
Modified: branches/SAMBA_4_0/source/lib/util/util_file.c
===================================================================
--- branches/SAMBA_4_0/source/lib/util/util_file.c      2006-10-28 05:21:11 UTC 
(rev 19503)
+++ branches/SAMBA_4_0/source/lib/util/util_file.c      2006-10-28 06:06:15 UTC 
(rev 19504)
@@ -241,6 +241,7 @@
 
 /**
 parse a buffer into lines
+'p' will be freed on error, and otherwise will be made a child of the returned 
array
 **/
 static char **file_lines_parse(char *p, size_t size, int *numlines, TALLOC_CTX 
*mem_ctx)
 {
@@ -259,7 +260,7 @@
                return NULL;
        }       
        
-       talloc_reference(ret, p);
+       talloc_steal(ret, p);
        
        memset(ret, 0, sizeof(ret[0])*(i+2));
        if (numlines) *numlines = i;
@@ -285,17 +286,12 @@
 _PUBLIC_ char **file_lines_load(const char *fname, int *numlines, TALLOC_CTX 
*mem_ctx)
 {
        char *p;
-       char **lines;
        size_t size;
 
        p = file_load(fname, &size, mem_ctx);
        if (!p) return NULL;
 
-       lines = file_lines_parse(p, size, numlines, mem_ctx);
-
-       talloc_free(p);
-
-       return lines;
+       return file_lines_parse(p, size, numlines, mem_ctx);
 }
 
 /**
@@ -306,17 +302,12 @@
 _PUBLIC_ char **fd_lines_load(int fd, int *numlines, TALLOC_CTX *mem_ctx)
 {
        char *p;
-       char **lines;
        size_t size;
 
        p = fd_load(fd, &size, mem_ctx);
        if (!p) return NULL;
 
-       lines = file_lines_parse(p, size, numlines, mem_ctx);
-
-       talloc_free(p);
-
-       return lines;
+       return file_lines_parse(p, size, numlines, mem_ctx);
 }
 
 
@@ -385,3 +376,24 @@
        va_end(ap);
        return ret;
 }
+
+
+/*
+  try to determine if the filesystem supports large files
+*/
+_PUBLIC_ bool large_file_support(const char *path)
+{
+       int fd;
+       ssize_t ret;
+       char c;
+
+       fd = open(path, O_RDWR|O_CREAT, 0600);
+       unlink(path);
+       if (fd == -1) {
+               /* have to assume large files are OK */
+               return true;
+       }
+       ret = pread(fd, &c, 1, ((uint64_t)1)<<32);
+       close(fd);
+       return ret == 0;
+}

Modified: branches/SAMBA_4_0/source/smb_server/smb/negprot.c
===================================================================
--- branches/SAMBA_4_0/source/smb_server/smb/negprot.c  2006-10-28 05:21:11 UTC 
(rev 19503)
+++ branches/SAMBA_4_0/source/smb_server/smb/negprot.c  2006-10-28 06:06:15 UTC 
(rev 19504)
@@ -250,6 +250,7 @@
        time_t t = req->request_time.tv_sec;
        NTTIME nttime;
        BOOL negotiate_spnego = False;
+       char *large_test_path;
 
        unix_to_nt_time(&nttime, t);
 
@@ -277,9 +278,12 @@
        if (lp_large_readwrite()) {
                capabilities |= CAP_LARGE_READX | CAP_LARGE_WRITEX | 
CAP_W2K_SMBS;
        }
-       
-       capabilities |= CAP_LARGE_FILES;
 
+       large_test_path = lock_path(req, "large_test.dat");
+       if (large_file_support(large_test_path)) {
+               capabilities |= CAP_LARGE_FILES;
+       }
+
        if (lp_readraw() && lp_writeraw()) {
                capabilities |= CAP_RAW_MODE;
        }

Modified: branches/SAMBA_4_0/source/torture/raw/read.c
===================================================================
--- branches/SAMBA_4_0/source/torture/raw/read.c        2006-10-28 05:21:11 UTC 
(rev 19503)
+++ branches/SAMBA_4_0/source/torture/raw/read.c        2006-10-28 06:06:15 UTC 
(rev 19504)
@@ -522,6 +522,11 @@
        status = smb_raw_read(cli->tree, &io);
        CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);     
 
+       if (!(cli->transport->negotiate.capabilities & CAP_LARGE_FILES)) {
+               printf("skipping large file tests - CAP_LARGE_FILES not set\n");
+               goto done;
+       }
+
        printf("Trying large offset read\n");
        io.readx.in.offset = ((uint64_t)0x2) << 32;
        io.readx.in.mincnt = 10;

Modified: branches/SAMBA_4_0/source/torture/raw/write.c
===================================================================
--- branches/SAMBA_4_0/source/torture/raw/write.c       2006-10-28 05:21:11 UTC 
(rev 19503)
+++ branches/SAMBA_4_0/source/torture/raw/write.c       2006-10-28 06:06:15 UTC 
(rev 19504)
@@ -182,6 +182,11 @@
        printf("Setting file as sparse\n");
        status = torture_set_sparse(cli->tree, fnum);
        CHECK_STATUS(status, NT_STATUS_OK);
+
+       if (!(cli->transport->negotiate.capabilities & CAP_LARGE_FILES)) {
+               printf("skipping large file tests - CAP_LARGE_FILES not set\n");
+               goto done;
+       }
        
        printf("Trying 2^32 offset\n");
        setup_buffer(buf, seed, maxsize);

Reply via email to