# Mender-flash: lseek64 doesn't work with musl

**URL:** <https://hub.mender.io/t/mender-flash-lseek64-doesnt-work-with-musl/7232>\
**Category:** General Discussions\
**Tags:** mender-flash, musl\
**Created:** [October 16, 2024, 12:12pm UTC](https://hub.mender.io/t/mender-flash-lseek64-doesnt-work-with-musl/7232 "2024-10-16T12:12:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![JohannesSchilling](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/johannesschilling/32/2316_2.png) [@JohannesSchilling](https://hub.mender.io/u/JohannesSchilling)\
**Post date:** [October 16, 2024, 12:12pm UTC](https://hub.mender.io/t/mender-flash-lseek64-doesnt-work-with-musl/7232/1 "2024-10-16T12:12:47Z")

</div>

in our environment, we use mender on a musl-based custom linux distro (yocto build). i’ve stumbled across an error when building `mender-flash`, which uses `lseek64` libc calls unavailable in musl. musl doesn’t have any of the foo64 functions, and instead just transitioned everything to be 64 bit (time\_t, off\_t, …) at some point.

so now i’ve replaced the `lseek64` calls in libflash/platformfs.cpp with `lseek`, and added that patch in a yocto .bbappend file as `SRC_URI:append:libc-musl = " file://lseek64.patch"`, so it’s applied when building for a musl-based system.

now my question is

- would patches for this be accepted upstream?
- would you prefer a patch on mender-flash to e.g. add a #define to map both lseek64 and lseek to the same thing, or a patch on the yocto layer like i described above?

---

<div class="post-metadata">

**Author:** ![TheYoctoJester](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/theyoctojester/32/1444_2.png) [@TheYoctoJester](https://hub.mender.io/u/TheYoctoJester)\
**Post date:** [October 17, 2024, 7:55am UTC](https://hub.mender.io/t/mender-flash-lseek64-doesnt-work-with-musl/7232/2 "2024-10-17T07:55:47Z")

</div>

Hi @JohannesSchilling,

Thanks for sharing this! Good question, any opinions here @lluiscampos @kacf?  
From my personal point of view, I’d love to see more streamlined `musl` support as I consider it relevant for a lot of use cases.

@JohannesSchilling, do you by any chance already have this in a Github fork so you can submit PRs for discussion? Not promising that they will be merged as-is, but it provides a much better code collaboration platform.

Greetz,  
Josef

---

<div class="post-metadata">

**Author:** ![kacf](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/kacf/32/146_2.png) [@kacf](https://hub.mender.io/u/kacf)\
**Post date:** [October 17, 2024, 8:57am UTC](https://hub.mender.io/t/mender-flash-lseek64-doesnt-work-with-musl/7232/3 "2024-10-17T08:57:43Z")

</div>

I did some research and I think we could actually switch to plain variants everywhere, as long as `-D _FILE_OFFSET_BITS=64` is defined by cmake. This causes `off_t` to become 64-bit everywhere, which is what those interfaces use. In addition to Linux, even QNX [supports this](https://www.qnx.com/developers/docs/7.0.0/index.html#com.qnx.doc.neutrino.lib_ref/topic/summary.html), which I don’t think is a deal breaker, since I believe it’s not going to be used there, but it’s nice to know in any case.

So my suggestion is:

- Add `target_compile_definitions(crossplatform_compiler_flags INTERFACE _FILE_OFFSET_BITS=64)` around [here](https://github.com/mendersoftware/mender-flash/blob/b10998f355af6def3126ae683e11dcc8003265a4/CMakeLists.txt#L34).
- Change `lseek64` calls (and any similar calls you find) into plain variants.

Thanks!

---

<div class="post-metadata">

**Author:** ![JohannesSchilling](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/johannesschilling/32/2316_2.png) [@JohannesSchilling](https://hub.mender.io/u/JohannesSchilling)\
**Post date:** [November 4, 2024, 3:03pm UTC](https://hub.mender.io/t/mender-flash-lseek64-doesnt-work-with-musl/7232/4 "2024-11-04T15:03:01Z")

</div>

@TheYoctoJester only as a patch file in our internal layer in the internal gitlab so far.

@kacf i made a merge request: [use 64bit filesystem offsets/sizes everywhere by JohannesSchilling · Pull Request #18 · mendersoftware/mender-flash · GitHub](https://github.com/mendersoftware/mender-flash/pull/18)
