Replace LFS64 interfaces off64_t and lseek64
PATCH 1/1 Replace LFS64 interfaces off64_t and lseek64
Musl does not define these interfaces unless -D_LARGEFILE64_SOURCE is defined and that too it is transitional until apps switch to using 64bit off_t. We pass -D_LARGEFILE64_SOURCE in makefiles already therefore original lseek and off_t are already 64bit
This fixes build with latest musl which has dropped LFS64 interfaces [1]
[1] https://git.musl-libc.org/cgit/musl/commit/?id=246f1c811448f37a44b41cd8df8d0ef9736d95f4i
--- .../include/private/trace-cmd-private.h | 12 +- lib/trace-cmd/include/trace-cmd-local.h | 4 +- lib/trace-cmd/trace-compress.c | 30 ++--- lib/trace-cmd/trace-input.c | 110 +++++++++--------- lib/trace-cmd/trace-msg.c | 20 ++-- lib/trace-cmd/trace-output.c | 64 +++++----- lib/trace-cmd/trace-recorder.c | 8 +- tracecmd/trace-dump.c | 34 +++--- tracecmd/trace-read.c | 2 +- 9 files changed, 142 insertions(+), 142 deletions(-)
lib/trace-cmd/include/private/trace-cmd-private.h +6 -6
@@ -106,7 +106,7 @@ const char *tracecmd_get_trace_clock(struct tracecmd_input *handle);const char *tracecmd_get_cpustats (struct tracecmd_input *handle);const char *tracecmd_get_uname (struct tracecmd_input *handle);const char *tracecmd_get_version (struct tracecmd_input *handle); -off64_t tracecmd_get_cpu_file_size (struct tracecmd_input *handle,int cpu); +off_t tracecmd_get_cpu_file_size (struct tracecmd_input *handle,int cpu);static inline int tracecmd_host_bigendian (void ) {
@@ -336,7 +336,7 @@ int tracecmd_write_buffer_info(struct tracecmd_output *handle);int tracecmd_write_cpus (struct tracecmd_output *handle,int cpus);int tracecmd_write_cmdlines (struct tracecmd_output *handle); -int tracecmd_prepare_options (struct tracecmd_output *handle,off64_t offset,int whence); +int tracecmd_prepare_options (struct tracecmd_output *handle,off_t offset,int whence);int tracecmd_write_options (struct tracecmd_output *handle);int tracecmd_write_meta_strings (struct tracecmd_output *handle);int tracecmd_append_options (struct tracecmd_output *handle);
@@ -393,7 +393,7 @@ struct tracecmd_msg_handle {short cpu_count;short version;/* Current protocol version */ unsigned long flags; -off64_t cache_start_offset; +off_t cache_start_offset;bool done;bool cache;int cfd;
@@ -542,8 +542,8 @@ int tracecmd_write_guest_time_shift(struct tracecmd_output *handle,struct tracecmd_compress_chunk {unsigned int size;unsigned int zsize; -off64_t zoffset; -off64_t offset; +off_t zoffset; +off_t offset; };struct tracecmd_compression ;struct tracecmd_compression_proto {
@@ -569,7 +569,7 @@ int tracecmd_compress_buffer_read(struct tracecmd_compression *handle, char *dstint tracecmd_compress_pread (struct tracecmd_compression *handle,char *dst,int len,off_t offset);int tracecmd_compress_buffer_write (struct tracecmd_compression *handle,const void *data,unsigned long long size); -off64_t tracecmd_compress_lseek (struct tracecmd_compression *handle,off64_t offset,int whence); +off_t tracecmd_compress_lseek (struct tracecmd_compression *handle,off_t offset,int whence);int tracecmd_compress_proto_get_name (struct tracecmd_compression *compress,const char **name,const char **version);bool tracecmd_compress_is_supported (const char *name,const char *version);
lib/trace-cmd/include/trace-cmd-local.h +2 -2
@@ -94,13 +94,13 @@ out_add_buffer_option(struct tracecmd_output *handle, const char *name,struct cpu_data_source {int fd;int size; -off64_t offset; +off_t offset; };int out_write_cpu_data (struct tracecmd_output *handle,int cpus,struct cpu_data_source *data,const char *buff_name);int out_write_emty_cpu_data (struct tracecmd_output *handle,int cpus); -off64_t msg_lseek (struct tracecmd_msg_handle *msg_handle,off64_t offset,int whence); +off_t msg_lseek (struct tracecmd_msg_handle *msg_handle,off_t offset,int whence);unsigned long long get_last_option_offset (struct tracecmd_input *handle);unsigned int get_meta_strings_size (struct tracecmd_input *handle);int trace_append_options (struct tracecmd_output *handle,void *buf,size_t len);
lib/trace-cmd/trace-compress.c +15 -15
@@ -117,12 +117,12 @@ static inline int buffer_extend(struct tracecmd_compression *handle, unsigned in* * Returns the new file pointer on success, or -1 in case of an error. */ -off64_t tracecmd_compress_lseek (struct tracecmd_compression *handle,off64_t offset,int whence) +off_t tracecmd_compress_lseek (struct tracecmd_compression *handle,off_t offset,int whence) {unsigned long p;if (!handle || !handle->buffer) -return (off64_t)-1 ; +return (off_t)-1 ;switch (whence) {case SEEK_CUR :
@@ -135,11 +135,11 @@ off64_t tracecmd_compress_lseek(struct tracecmd_compression *handle, off64_t off p = offset;break ;default : -return (off64_t)-1 ; +return (off_t)-1 ; }if (buffer_extend (handle, p)) -return (off64_t)-1 ; +return (off_t)-1 ; handle->pointer = p;
@@ -678,7 +678,7 @@ int tracecmd_compress_copy_from(struct tracecmd_compression *handle, int fd, intunsigned int size;unsigned int all;unsigned int r; -off64_t offset; +off_t offset;char *buf_from;char *buf_to;int endian4;
@@ -700,7 +700,7 @@ int tracecmd_compress_copy_from(struct tracecmd_compression *handle, int fd, intreturn -1 ;/* save the initial offset and write 0 as initial chunk count */ - offset =lseek64 (handle->fd,0 ,SEEK_CUR ); + offset =lseek (handle->fd,0 ,SEEK_CUR );write_fd (handle->fd, &chunks,4 ); do {
@@ -760,13 +760,13 @@ int tracecmd_compress_copy_from(struct tracecmd_compression *handle, int fd, intif (all)return -1 ; -if (lseek64 (handle->fd, offset,SEEK_SET ) == (off_t)-1 ) +if (lseek (handle->fd, offset,SEEK_SET ) == (off_t)-1 )return -1 ; endian4 =tep_read_number (handle->tep, &chunks,4 );/* write chunks count*/ write_fd (handle->fd, &chunks,4 ); -if (lseek64 (handle->fd,0 ,SEEK_END ) == (off_t)-1 ) +if (lseek (handle->fd,0 ,SEEK_END ) == (off_t)-1 )return -1 ;if (read_size)
@@ -796,7 +796,7 @@ int tracecmd_load_chunks_info(struct tracecmd_compression *handle,struct tracecmd_compress_chunk *chunks =NULL ;unsigned long long size =0 ;unsigned int count =0 ; -off64_t offset; +off_t offset;int ret =-1 ;char buf[4 ];int i;
@@ -804,8 +804,8 @@ int tracecmd_load_chunks_info(struct tracecmd_compression *handle,if (!handle)return -1 ; - offset =lseek64 (handle->fd,0 ,SEEK_CUR ); -if (offset == (off64_t)-1 ) + offset =lseek (handle->fd,0 ,SEEK_CUR ); +if (offset == (off_t)-1 )return -1 ;if (read (handle->fd, buf,4 ) !=4 )
@@ -822,7 +822,7 @@ int tracecmd_load_chunks_info(struct tracecmd_compression *handle, goto out;for (i =0 ; i < count; i++) { - chunks[i].zoffset =lseek64 (handle->fd,0 ,SEEK_CUR ); + chunks[i].zoffset =lseek (handle->fd,0 ,SEEK_CUR );if (chunks[i].zoffset == (off_t)-1 ) goto out;if (read (handle->fd, buf,4 ) !=4 )
@@ -833,13 +833,13 @@ int tracecmd_load_chunks_info(struct tracecmd_compression *handle, goto out; chunks[i].size =tep_read_number (handle->tep, buf,4 ); size += chunks[i].size; -if (lseek64 (handle->fd, chunks[i].zsize,SEEK_CUR ) == (off64_t)-1 ) +if (lseek (handle->fd, chunks[i].zsize,SEEK_CUR ) == (off_t)-1 ) goto out; } ret = count; out: -if (lseek64 (handle->fd, offset,SEEK_SET ) == (off64_t)-1 ) +if (lseek (handle->fd, offset,SEEK_SET ) == (off_t)-1 ) ret =-1 ;if (ret >0 && chunks_info)
@@ -872,7 +872,7 @@ int tracecmd_uncompress_chunk(struct tracecmd_compression *handle,if (!handle || !handle->proto || !handle->proto->uncompress_block || !chunk || !data)return -1 ; -if (lseek64 (handle->fd, chunk->zoffset +8 ,SEEK_SET ) == (off_t)-1 ) +if (lseek (handle->fd, chunk->zoffset +8 ,SEEK_SET ) == (off_t)-1 )return -1 ; bytes_in =malloc (chunk->zsize);
lib/trace-cmd/trace-input.c +55 -55
362 lines not on this page · raw message
lib/trace-cmd/trace-msg.c +10 -10
@@ -183,26 +183,26 @@ static int __msg_write(int fd, struct tracecmd_msg *msg, bool network)return __do_write_check (fd, msg->buf, data_size); } -__hidden off64_t msg_lseek(struct tracecmd_msg_handle *msg_handle, off64_t offset, int whence) +__hidden off_t msg_lseek(struct tracecmd_msg_handle *msg_handle, off_t offset, int whence) { -off64_t cache_offset = msg_handle->cache_start_offset; -off64_t ret; +off_t cache_offset = msg_handle->cache_start_offset; +off_t ret;/* * lseek works only if the handle is in cache mode, * cannot seek on a network socket */ if (!msg_handle->cache || msg_handle->cfd <0 ) -return (off64_t)-1 ; +return (off_t)-1 ;if (whence ==SEEK_SET ) {if (offset < cache_offset) -return (off64_t)-1 ; +return (off_t)-1 ; offset -= cache_offset; } - ret =lseek64 (msg_handle->cfd, offset, whence); -if (ret == (off64_t)-1 ) + ret =lseek (msg_handle->cfd, offset, whence); +if (ret == (off_t)-1 )return ret;return ret + cache_offset;
@@ -639,7 +639,7 @@ static int flush_cache(struct tracecmd_msg_handle *msg_handle)if (!msg_handle->cache || fd <0 )return 0 ; msg_handle->cache = false; -if (lseek64 (fd,0 ,SEEK_SET ) == (off64_t)-1 ) +if (lseek (fd,0 ,SEEK_SET ) == (off_t)-1 )return -1 ; do { ret = read(fd, buf, MSG_MAX_DATA_LEN);
@@ -650,8 +650,8 @@ static int flush_cache(struct tracecmd_msg_handle *msg_handle)break ; }while (ret >=0 ); - msg_handle->cache_start_offset =lseek64 (fd,0 ,SEEK_CUR ); -if (msg_handle->cache_start_offset == (off64_t)-1 ) + msg_handle->cache_start_offset =lseek (fd,0 ,SEEK_CUR ); +if (msg_handle->cache_start_offset == (off_t)-1 )return -1 ;close (fd);
lib/trace-cmd/trace-output.c +32 -32
239 lines not on this page · raw message
lib/trace-cmd/trace-recorder.c +4 -4
@@ -51,7 +51,7 @@ static int append_file(int size, int dst, int src)char buf[size];int r; -lseek64 (src,0 ,SEEK_SET ); +lseek (src,0 ,SEEK_SET );/* If there's an error, then we are pretty much screwed :-p */ do {
@@ -82,10 +82,10 @@ void tracecmd_free_recorder(struct tracecmd_recorder *recorder) recorder->fd2, recorder->fd1);/* Error on copying, then just keep fd1 */ if (ret) { -lseek64 (recorder->fd1,0 ,SEEK_END ); +lseek (recorder->fd1,0 ,SEEK_END ); goto close; } -lseek64 (recorder->fd1,0 ,SEEK_SET ); +lseek (recorder->fd1,0 ,SEEK_SET );ftruncate (recorder->fd1,0 ); }append_file (recorder->page_size, recorder->fd1, recorder->fd2);
@@ -305,7 +305,7 @@ static inline void update_fd(struct tracecmd_recorder *recorder, int size) fd = recorder->fd1;/* Zero out the new file we are writing to */ -lseek64 (fd,0 ,SEEK_SET ); +lseek (fd,0 ,SEEK_SET );ftruncate (fd,0 ); recorder->fd = fd;
tracecmd/trace-dump.c +17 -17
@@ -101,7 +101,7 @@ static int do_lseek(int fd, int offset, int whence)if (read_compress)return tracecmd_compress_lseek (compress, offset, whence); -return lseek64 (fd, offset, whence); +return lseek (fd, offset, whence); }static int read_file_string (int fd,char *dst,int len)
@@ -446,7 +446,7 @@ static void dump_section_header(int fd, enum dump_items v, unsigned short *flagsconst char *desc;int desc_id; - offset =lseek64 (fd,0 ,SEEK_CUR ); + offset =lseek (fd,0 ,SEEK_CUR );if (read_file_number (fd, &id,2 ))die ("cannot read the section id" );
@@ -500,13 +500,13 @@ static void dump_option_buffer(int fd, unsigned short option, int size)return ; } - current =lseek64 (fd,0 ,SEEK_CUR ); -if (lseek64 (fd, offset,SEEK_SET ) == (off_t)-1 ) + current =lseek (fd,0 ,SEEK_CUR ); +if (lseek (fd, offset,SEEK_SET ) == (off_t)-1 )die ("cannot goto buffer offset %lld" , offset);dump_section_header (fd,FLYRECORD , &flags); -if (lseek64 (fd, current,SEEK_SET ) == (off_t)-1 ) +if (lseek (fd, current,SEEK_SET ) == (off_t)-1 )die ("cannot go back to buffer option" );do_print (OPTIONS |FLYRECORD ,"\t\t[Option BUFFER, %d bytes]\n" , size);
@@ -773,7 +773,7 @@ static void dump_sections(int fd, int count)unsigned short flags;while (sec) { -if (lseek64 (fd, sec->offset,SEEK_SET ) == (off_t)-1 ) +if (lseek (fd, sec->offset,SEEK_SET ) == (off_t)-1 )die ("cannot goto option offset %lld" , sec->offset);dump_section_header (fd, sec->verbosity, &flags);
@@ -826,7 +826,7 @@ static int dump_option_done(int fd, int size)if (!offset)return 0 ; -if (lseek64 (fd, offset,SEEK_SET ) == (off_t)-1 ) +if (lseek (fd, offset,SEEK_SET ) == (off_t)-1 )die ("cannot goto next options offset %lld" , offset);do_print (OPTIONS ,"\n\n" );
@@ -1006,7 +1006,7 @@ static void dump_therest(int fd)else if (strncmp (str,HEAD_FLYRECORD ,10 ) ==0 )dump_flyrecord (fd);else { -lseek64 (fd,-10 ,SEEK_CUR ); +lseek (fd,-10 ,SEEK_CUR );break ; } }
@@ -1060,7 +1060,7 @@ static void get_meta_strings(int fd)unsigned short fl, id;int desc_id; - offset =lseek64 (fd,0 ,SEEK_CUR ); + offset =lseek (fd,0 ,SEEK_CUR ); do { if (read_file_number(fd, &id, 2)) break;
@@ -1074,7 +1074,7 @@ static void get_meta_strings(int fd)if ((fl &TRACECMD_SEC_FL_COMPRESS )) {read_file_number (fd, &csize,4 );read_file_number (fd, &rsize,4 ); -lseek64 (fd,-8 ,SEEK_CUR ); +lseek (fd,-8 ,SEEK_CUR );if (uncompress_block ())break ; }else {
@@ -1083,12 +1083,12 @@ static void get_meta_strings(int fd)read_metadata_strings (fd, rsize);uncompress_reset (); }else { -if (lseek64 (fd, size,SEEK_CUR ) == (off_t)-1 ) +if (lseek (fd, size,SEEK_CUR ) == (off_t)-1 )break ; } }while (1 ); -if (lseek64 (fd, offset,SEEK_SET ) == (off_t)-1 ) +if (lseek (fd, offset,SEEK_SET ) == (off_t)-1 )die ("cannot restore the original file location" ); }
@@ -1102,9 +1102,9 @@ static int walk_v7_sections(int fd)int desc_id;const char *desc; - offset =lseek64 (fd,0 ,SEEK_CUR ); + offset =lseek (fd,0 ,SEEK_CUR ); do { - soffset = lseek64(fd, 0, SEEK_CUR); + soffset = lseek(fd, 0, SEEK_CUR); if (read_file_number(fd, &id, 2)) break;
@@ -1149,11 +1149,11 @@ static int walk_v7_sections(int fd) id, soffset, desc, fl, size); } -if (lseek64 (fd, size,SEEK_CUR ) == (off_t)-1 ) +if (lseek (fd, size,SEEK_CUR ) == (off_t)-1 )break ; }while (1 ); -if (lseek64 (fd, offset,SEEK_SET ) == (off_t)-1 ) +if (lseek (fd, offset,SEEK_SET ) == (off_t)-1 )die ("cannot restore the original file location" );return count;
@@ -1170,7 +1170,7 @@ static void dump_v7_file(int fd)get_meta_strings (fd); sections =walk_v7_sections (fd); -if (lseek64 (fd, offset,SEEK_SET ) == (off_t)-1 ) +if (lseek (fd, offset,SEEK_SET ) == (off_t)-1 )die ("cannot goto options offset %lld" , offset);dump_options (fd);
tracecmd/trace-read.c +1 -1
@@ -195,7 +195,7 @@ static void print_event(struct trace_seq *s, struct tracecmd_input *handle,#define TEST_READ_AT 0#if TEST_READ_AT #define DO_TEST -static off64_t test_read_at_offset; +static off_t test_read_at_offset;static int test_read_at_copy =100 ;static int test_read_at_index;static void show_test (struct tracecmd_input *handle)
Signature · 1 line
2.39.0
Quoted 4 lines · On Fri, 6 Jan 2023 17:02:45 -0800 Khem Raj <[email protected]> wrote:
Musl does not define these interfaces unless -D_LARGEFILE64_SOURCE is defined and that too it is transitional until apps switch to using 64bit
off_t. We pass -D_LARGEFILE64_SOURCE in makefiles already therefore original lseek andoff_tare already 64bit
I just tested this, and that's not true.
static void pdie(const char *msg)
{
perror(msg);
exit(-1);
}int main (int argc, char **argv)
{
off_t off;
int fd;
argv0 = argv[0];
if (argc < 2)
usage();
printf("off size = %zd\n", sizeof(off));
fd = open(argv[1], O_RDONLY);
if (fd < 0)
pdie("open");
off = lseek(fd, 0, SEEK_END);
if (off < 0)
pdie("lseek");
printf("offset = %zd\n", off);
return 0;
}I compiled the above on a 32bit machine with:
$ gcc -D_LARGEFILE64_SOURCE -o lseek lseek.c $ ./lseek big-file
Where big-file was 6GBs, and I got this:
off size = 4
lseek: Value too large for defined data type
The _LARGEFILE64_SOURCE just makes the 64 bit versions available. It does not convert the original ones.
Quoted 7 lines
This fixes build with latest musl which has dropped LFS64 interfaces [1]
[1] https://git.musl-libc.org/cgit/musl/commit/?id=246f1c811448f37a44b41cd8df8d0ef9736d95f4i
Signed-off-by Khem Raj <[email protected]>---
What we could do is add something like:
#ifdef MUSL
# define off64_t off_t # define lseek64 lseek [..] #endif
in one of the headers to make it work with musl.
-- Steve
Quoted 6 lines · On Mon, 9 Jan 2023 13:05:39 -0500 Steven Rostedt <[email protected]> wrote:
Quoted 4 lines
Musl does not define these interfaces unless -D_LARGEFILE64_SOURCE is defined and that too it is transitional until apps switch to using 64bit
off_t. We pass -D_LARGEFILE64_SOURCE in makefiles already therefore original lseek andoff_tare already 64bitI just tested this, and that's not true.
I left out the headers:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
More than needed, but they are my default headers I cut and paste ;-)
-- Steve
Quoted 6 lines
static void
pdie(const char *msg){ perror(msg); exit(-1); }
Quoted 10 lines · Steven Rostedt
Quoted 4 lines · On Fri, 6 Jan 2023 17:02:45 -0800 Khem Raj <[email protected]> wrote:
Musl does not define these interfaces unless -D_LARGEFILE64_SOURCE is defined and that too it is transitional until apps switch to using 64bit
off_t. We pass -D_LARGEFILE64_SOURCE in makefiles already therefore original lseek andoff_tare already 64bitI just tested this, and that's not true.
Right, I should have said we are already using 64bit functions. I did not see it since in yocto
it was already being added by distro settings.
I think we need to add -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE and remove -D_LARGEFILE64_SOURCE, I can update this in v2.
Quoted 61 lines
static void
pdie(const char *msg){ perror(msg); exit(-1); }int main (int argc, char **argv)
{ off_t off; int fd; argv0 = argv[0]; if (argc < 2) usage(); printf("off size = %zd\n", sizeof(off)); fd = open(argv[1], O_RDONLY); if (fd < 0) pdie("open"); off = lseek(fd, 0, SEEK_END); if (off < 0) pdie("lseek"); printf("offset = %zd\n", off); return 0; }I compiled the above on a 32bit machine with:
$ gcc -D_LARGEFILE64_SOURCE -o lseek lseek.c $ ./lseek big-fileWhere big-file was 6GBs, and I got this:
off size = 4
lseek: Value too large for defined data typeThe
_LARGEFILE64_SOURCEjust makes the 64 bit versions available. It does not convert the original ones.Quoted 7 lines
This fixes build with latest musl which has dropped LFS64 interfaces [1]
[1] https://git.musl-libc.org/cgit/musl/commit/?id=246f1c811448f37a44b41cd8df8d0ef9736d95f4i
Signed-off-by Khem Raj <[email protected]>---
What we could do is add something like:
#ifdef MUSL
# define off64_t off_t # define lseek64 lseek [..] #endifin one of the headers to make it work with musl.
-- Steve
Quoted 5 lines · On Mon, 9 Jan 2023 11:42:13 -0800 Khem Raj <[email protected]> wrote:
Right, I should have said we are already using 64bit functions. I did not see it since in yocto
it was already being added by distro settings.
I think we need to add -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE and remove -D_LARGEFILE64_SOURCE, I can update this in v2.
OK, adding the -D_FILE_OFFSET_BITS=64 does appear to expand off_t.
-- Steve