[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    Re: Fwd: Re: 64 bit file support
From:       Waldo Bastian <bastian () kde ! org>
Date:       2001-08-11 4:54:29
[Download RAW message or body]

On Friday 10 August 2001 02:35 pm, Waldo Bastian wrote:
> On Friday 10 August 2001 11:53 am, Waldo Bastian wrote:
> > This solution won't work under Linux, though.  Linux headers define
> > "struct stat" based on the value of _FILE_OFFSET_BITS.  If you place the
> > line "#define _FILE_OFFSET_BITS 64" prior to any #include's in your
> > source, you get the 64 bit version, otherwise you get the 32 bit version.

[Snip]

> The solution to this seems to be to define _LARGEFILE_SOURCE and
> _LARGEFILE64_SOURCE and to leave _FILE_OFFSET_BITS undefined. You should
> then be able to use stat64() and other 64-bit versions of the stdio
> functions. The normal functions remain 32-bit then. That also means that
> you have to use "struct stat64" instead of "struct stat".

Which then leads to the following patch. largefile.h goes into kdelibs/kio. 
Note that the current file io-slave already does support 64-bit files on 
linux and 64-bit platforms. With this patch it should also do this on all 
other 32-bit platforms that support 64-bit files.

kio/largefile.h contains a bunch of defines that might be usefull in other 
places of KDE as well. We should probably move it to kdecore so that all of 
KDE can use it.

The API hasn't changed yet so although > 2GB files should now be reported, 
they will still have the wrong size.

Please test.

Cheers,
Waldo
-- 
KDE 2.2: We deliver.

["largefile.h" (text/x-c)]

#include <unistd.h>

#ifdef _LFS64_LARGEFILE
#define KIO_stat		::stat64
#define KIO_lstat		::lstat64
#define KIO_fstat		::fstat64
#define KIO_open		::open64
#define KIO_lseek		::lseek64
#define KIO_readdir		::readdir64
#define KIO_struct_stat 	struct stat64
#define KIO_struct_dirent	struct dirent64
#else
#define KIO_stat		::stat
#define KIO_lstat		::lstat
#define KIO_fstat		::fstat
#define KIO_open		::open
#define KIO_lseek		::lseek
#define KIO_readdir		::readdir
#define KIO_struct_stat 	struct stat
#define KIO_struct_dirent	struct dirent
#endif

#ifdef _LFS64_STDIO
#define KIO_fopen		fopen64
#else
#define KIO_fopen		fopen
#endif

["file.diff" (text/x-diff)]

Index: Makefile.am
===================================================================
RCS file: /home/kde/kdelibs/kio/file/Makefile.am,v
retrieving revision 1.20
diff -u -3 -d -p -r1.20 Makefile.am
--- Makefile.am	2001/05/14 11:59:12	1.20
+++ Makefile.am	2001/08/11 04:44:40
@@ -1,5 +1,7 @@
 ## Makefile.am of kdebase/kioslave/file
 
+AM_CPPFLAGS = -D_LARGEFILE64_SOURCE
+
 INCLUDES = -I$(srcdir)/.. -I$(srcdir)/../.. $(all_includes)
 
 ####### Files
Index: file.cc
===================================================================
RCS file: /home/kde/kdelibs/kio/file/file.cc,v
retrieving revision 1.110
diff -u -3 -d -p -r1.110 file.cc
--- file.cc	2001/07/18 21:32:51	1.110
+++ file.cc	2001/08/11 04:44:40
@@ -2,16 +2,6 @@
 
 #include <config.h>
 
-#ifdef __linux__
-#ifndef _GNU_SOURCE
-#define _GNU_SOURCE
-#endif
-#ifndef _FILE_OFFSET_BITS
-#define _FILE_OFFSET_BITS 64
-#endif
-#include <features.h>
-#endif
-
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <sys/stat.h>
@@ -55,6 +45,7 @@
 #endif
 
 #include <kio/ioslave_defaults.h>
+#include <kio/largefile.h>
 #include <kglobal.h>
 
 using namespace KIO;
@@ -105,8 +96,8 @@ void FileProtocol::chmod( const KURL& ur
 void FileProtocol::mkdir( const KURL& url, int permissions )
 {
     QCString _path( QFile::encodeName(url.path()));
-    struct stat buff;
-    if ( ::stat( _path.data(), &buff ) == -1 ) {
+    KIO_struct_stat buff;
+    if ( KIO_stat( _path.data(), &buff ) == -1 ) {
 	if ( ::mkdir( _path.data(), 0777 /*umask will be applied*/ ) != 0 ) {
 	    if ( errno == EACCES ) {
 		error( KIO::ERR_ACCESS_DENIED, url.path() );
@@ -136,8 +127,8 @@ void FileProtocol::mkdir( const KURL& ur
 void FileProtocol::get( const KURL& url )
 {
     QCString _path( QFile::encodeName(url.path()));
-    struct stat buff;
-    if ( ::stat( _path.data(), &buff ) == -1 ) {
+    KIO_struct_stat buff;
+    if ( KIO_stat( _path.data(), &buff ) == -1 ) {
         if ( errno == EACCES )
            error( KIO::ERR_ACCESS_DENIED, url.path() );
         else
@@ -154,7 +145,7 @@ void FileProtocol::get( const KURL& url 
 	return;
     }
 
-    int fd = open( _path.data(), O_RDONLY);
+    int fd = KIO_open( _path.data(), O_RDONLY);
     if ( fd < 0 ) {
 	error( KIO::ERR_CANNOT_OPEN_FOR_READING, url.path() );
 	return;
@@ -237,8 +228,8 @@ void FileProtocol::put( const KURL& url,
 
     bool bMarkPartial = config()->readBoolEntry("MarkPartial", true);
 
-    struct stat buff_orig;
-    bool orig_exists = ( ::stat( _dest_orig.data(), &buff_orig ) != -1 );
+    KIO_struct_stat buff_orig;
+    bool orig_exists = ( KIO_stat( _dest_orig.data(), &buff_orig ) != -1 );
     if ( orig_exists &&  !_overwrite && !_resume)
     {
         if (S_ISDIR(buff_orig.st_mode))
@@ -254,8 +245,8 @@ void FileProtocol::put( const KURL& url,
         kdDebug(7101) << "Appending .part extension to " << dest_orig << endl;
         dest = dest_part;
 
-        struct stat buff_part;
-        bool part_exists = ( ::stat( _dest_part.data(), &buff_part ) != -1 );
+        KIO_struct_stat buff_part;
+        bool part_exists = ( KIO_stat( _dest_part.data(), &buff_part ) != -1 );
         if ( part_exists && !_resume && buff_part.st_size > 0 )
         {
             kdDebug() << "FileProtocol::put : calling canResume with " << (unsigned \
long)buff_part.st_size << endl; @@ -293,8 +284,8 @@ void FileProtocol::put( const \
KURL& url,  int fd;
 
     if ( _resume ) {
-        fd = open( _dest.data(), O_RDWR );  // append if resuming
-        lseek(fd, 0, SEEK_END); // Seek to end
+        fd = KIO_open( _dest.data(), O_RDWR );  // append if resuming
+        KIO_lseek(fd, 0, SEEK_END); // Seek to end
     } else {
         // WABA: Make sure that we keep writing permissions ourselves,
         // otherwise we can be in for a surprise on NFS.
@@ -304,7 +295,7 @@ void FileProtocol::put( const KURL& url,
         else
            initialMode = 0666;
 
-        fd = open(_dest.data(), O_CREAT | O_TRUNC | O_WRONLY, initialMode);
+        fd = KIO_open(_dest.data(), O_CREAT | O_TRUNC | O_WRONLY, initialMode);
     }
 
     if ( fd < 0 ) {
@@ -354,8 +345,8 @@ void FileProtocol::put( const KURL& url,
 	   remove(_dest.data());
         } else if (bMarkPartial)
         {
-           struct stat buff;
-           if (( ::stat( _dest.data(), &buff ) == -1 ) ||
+           KIO_struct_stat buff;
+           if (( KIO_stat( _dest.data(), &buff ) == -1 ) ||
                ( buff.st_size < config()->readNumEntry("MinimumKeepSize", \
DEFAULT_MINIMUM_KEEP_SIZE) ))  {
 	       remove(_dest.data());
@@ -400,8 +391,8 @@ void FileProtocol::copy( const KURL &src
 {
     QCString _src( QFile::encodeName(src.path()));
     QCString _dest( QFile::encodeName(dest.path()));
-    struct stat buff_src;
-    if ( ::stat( _src.data(), &buff_src ) == -1 ) {
+    KIO_struct_stat buff_src;
+    if ( KIO_stat( _src.data(), &buff_src ) == -1 ) {
         if ( errno == EACCES )
            error( KIO::ERR_ACCESS_DENIED, src.path() );
         else
@@ -418,8 +409,8 @@ void FileProtocol::copy( const KURL &src
 	return;
     }
 
-    struct stat buff_dest;
-    bool dest_exists = ( ::stat( _dest.data(), &buff_dest ) != -1 );
+    KIO_struct_stat buff_dest;
+    bool dest_exists = ( KIO_stat( _dest.data(), &buff_dest ) != -1 );
     if ( dest_exists )
     {
         if (S_ISDIR(buff_dest.st_mode))
@@ -435,7 +426,7 @@ void FileProtocol::copy( const KURL &src
         }
     }
 
-    int src_fd = open( _src.data(), O_RDONLY);
+    int src_fd = KIO_open( _src.data(), O_RDONLY);
     if ( src_fd < 0 ) {
 	error( KIO::ERR_CANNOT_OPEN_FOR_READING, src.path() );
 	return;
@@ -449,7 +440,7 @@ void FileProtocol::copy( const KURL &src
     else
        initialMode = 0666;
 
-    int dest_fd = open(_dest.data(), O_CREAT | O_TRUNC | O_WRONLY, initialMode);
+    int dest_fd = KIO_open(_dest.data(), O_CREAT | O_TRUNC | O_WRONLY, initialMode);
     if ( dest_fd < 0 ) {
 	kdDebug(7101) << "###### COULD NOT WRITE " << dest.url() << endl;
         if ( errno == EACCES ) {
@@ -547,8 +538,8 @@ void FileProtocol::rename( const KURL &s
 {
     QCString _src( QFile::encodeName(src.path()));
     QCString _dest( QFile::encodeName(dest.path()));
-    struct stat buff_src;
-    if ( ::stat( _src.data(), &buff_src ) == -1 ) {
+    KIO_struct_stat buff_src;
+    if ( KIO_stat( _src.data(), &buff_src ) == -1 ) {
         if ( errno == EACCES )
            error( KIO::ERR_ACCESS_DENIED, src.path() );
         else
@@ -556,8 +547,8 @@ void FileProtocol::rename( const KURL &s
 	return;
     }
 
-    struct stat buff_dest;
-    bool dest_exists = ( ::stat( _dest.data(), &buff_dest ) != -1 );
+    KIO_struct_stat buff_dest;
+    bool dest_exists = ( KIO_stat( _dest.data(), &buff_dest ) != -1 );
     if ( dest_exists )
     {
         if (S_ISDIR(buff_dest.st_mode))
@@ -614,8 +605,8 @@ void FileProtocol::symlink( const QStrin
             }
             else
             {
-                struct stat buff_dest;
-                ::lstat( QFile::encodeName( dest.path() ), &buff_dest );
+                KIO_struct_stat buff_dest;
+                KIO_lstat( QFile::encodeName( dest.path() ), &buff_dest );
                 if (S_ISDIR(buff_dest.st_mode))
                     error( KIO::ERR_DIR_ALREADY_EXIST, dest.path() );
                 else
@@ -686,9 +677,9 @@ bool FileProtocol::createUDSEntry( const
 
     mode_t type;
     mode_t access;
-    struct stat buff;
+    KIO_struct_stat buff;
 
-	if ( lstat( path.data(), &buff ) == 0 )  {
+	if ( KIO_lstat( path.data(), &buff ) == 0 )  {
 
 	    if (S_ISLNK(buff.st_mode)) {
 
@@ -703,7 +694,7 @@ bool FileProtocol::createUDSEntry( const
 		entry.append( atom );
 
 		// A link poiting to nowhere ?
-		if ( ::stat( path.data(), &buff ) == -1 ) {
+		if ( KIO_stat( path.data(), &buff ) == -1 ) {
 		    // It is a link pointing to nowhere
 		    type = S_IFMT - 1;
 		    access = S_IRWXU | S_IRWXG | S_IRWXO;
@@ -803,8 +794,8 @@ void FileProtocol::stat( const KURL & ur
      * This is the reason for the -1
      */
     QCString _path( QFile::encodeName(url.path(-1)));
-    struct stat buff;
-    if ( ::lstat( _path.data(), &buff ) == -1 ) {
+    KIO_struct_stat buff;
+    if ( KIO_lstat( _path.data(), &buff ) == -1 ) {
 	error( KIO::ERR_DOES_NOT_EXIST, url.path(-1) );
 	return;
     }
@@ -860,8 +851,8 @@ void FileProtocol::listDir( const KURL& 
     QCString _path( QFile::encodeName(url.path()));
     kdDebug(7101) << "========= LIST " << url.url() << " =========" << endl;
 
-    struct stat buff;
-    if ( ::stat( _path.data(), &buff ) == -1 ) {
+    KIO_struct_stat buff;
+    if ( KIO_stat( _path.data(), &buff ) == -1 ) {
 	error( KIO::ERR_DOES_NOT_EXIST, url.path() );
 	return;
     }
@@ -872,7 +863,7 @@ void FileProtocol::listDir( const KURL& 
     }
 
     DIR *dp = 0L;
-    struct dirent *ep;
+    KIO_struct_dirent *ep;
 
     dp = opendir( _path.data() );
     if ( dp == 0 ) {
@@ -885,7 +876,7 @@ void FileProtocol::listDir( const KURL& 
     // files where QFile::encodeName(QFile::decodeName(a)) != a.
     QStrList entryNames;
 
-    while ( ( ep = readdir( dp ) ) != 0L )
+    while ( ( ep = KIO_readdir( dp ) ) != 0L )
 	entryNames.append( ep->d_name );
 
     closedir( dp );
@@ -927,8 +918,8 @@ void FileProtocol::listDir( const KURL& 
 void FileProtocol::testDir( const QString& path )
 {
     QCString _path( QFile::encodeName(path));
-    struct stat buff;
-    if ( ::stat( _path.data(), &buff ) == -1 ) {
+    KIO_struct_stat buff;
+    if ( KIO_stat( _path.data(), &buff ) == -1 ) {
 	error( KIO::ERR_DOES_NOT_EXIST, path );
 	return;
     }
@@ -1148,7 +1139,7 @@ void FileProtocol::unmount( const QStrin
 		kdDebug(7101) << "VOLMGT: looking for "
 			<< _point.local8Bit() << endl;
 
-		if( (mnttab = fopen( MNTTAB, "r" )) == NULL ) {
+		if( (mnttab = KIO_fopen( MNTTAB, "r" )) == NULL ) {
 			err = "couldn't open mnttab";
 			kdDebug(7101) << "VOLMGT: " << err << endl;
 			error( KIO::ERR_COULD_NOT_UNMOUNT, err );
@@ -1236,18 +1227,18 @@ void FileProtocol::unmount( const QStrin
 QString testLogFile( const char *_filename )
 {
     char buffer[ 1024 ];
-    struct stat buff;
+    KIO_struct_stat buff;
 
     QString result;
 
-    stat( _filename, &buff );
+    KIO_stat( _filename, &buff );
     int size = buff.st_size;
     if ( size == 0 ) {
 	unlink( _filename );
 	return result;
     }
 
-    FILE * f = fopen( _filename, "rb" );
+    FILE * f = KIO_fopen( _filename, "rb" );
     if ( f == 0L ) {
 	unlink( _filename );
 	result = i18n("Could not read %1").arg(QFile::decodeName(_filename));



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic