VitaMTP icon indicating copy to clipboard operation
VitaMTP copied to clipboard

Add LARGEFILE support for 32bit builds

Open codestation opened this issue 12 years ago • 1 comments
trafficstars

The 32bit builds of opencma doesn't have LARGEFILE support so functions like statvfs gets the wrong values.

Here is a testcase using the getDiskSpace function defined in utilities.c. https://gist.github.com/codestation/6058882

Compile the testcase like this in a 64bit system:

gcc -m32 testcase.c -o testcase32 # for 32bit binary gcc testcase.c -o testcase # for 64bit binary

./testcase /path/to/file # gives correct values for total and free ./testcase32 /path/to/file # gives incorrect values for total and free space if the partition has over 2GiB of total/free space.

Compiling the testcase with gcc -m32 -D_FILE_OFFSET_BITS=64 testcase.c -o testcase32

Makes the testcase32 produce the same output as the 64bit binary.

Probably the correct fix is to add AC_SYS_LARGEFILE to the configure.ac file. Sadly i don't have a 32bit chroot right now to test the configure script. I will post again if i can find a 32bit system to make a full build to test that this fix is valid.

Note: probably this bug solves the issue #27

codestation avatar Jul 23 '13 00:07 codestation

Proposed patch to enable 64bit structures on 32bit systems and use fseeko instead of fseek (who doesn't support files greater than 2GiB on 32bit systems) https://gist.github.com/codestation/6081325

edit: i am gonna pospone this patch until i find a proper fix since i found some casting problems in the opencma code, like castings from uint64_t to size_t who are undefined in 32bit code.

edit2: patch updated: the OP of the issue #27 has confirmed me that the new patch solves his transfer problems under 32bit.

Let me explain the patch:

  • Add AC_SYS_LARGEFILE to configure.ac so the 64bit version of the fopen/fseeko/ftello are used under the hood.
  • Add config.h to database.c, opencma.c and utilities.c so the largefile flags gets passed to the opencma binary. The config.h should be referented by all the compilation units in a particular binary so the ABI is the same (else the binary will fail silenty at runtime with stack corruption).
  • Change writeFileFromBuffer and readFileToBuffer seek param to off_t so the values from vitamtp doesn't get truncated.
  • Replace ftell and fseek with ftello/fseeko. Those functions are 64bit aware, even on 32 bit systems.
  • Modified writeFileFromBuffer to reopen the file in RW mode when a seek value inside the file is detected, so the file pointer can be moved. The original function tried to move the file pointer while in append mode ("a+") but that isn't possible for writtes.

codestation avatar Jul 25 '13 16:07 codestation