* [PATCH 1/5] mtd-utils: don't include features.h
@ 2025-10-26 20:00 Rosen Penev
2025-10-26 20:00 ` [PATCH 2/5] mtd-utils: rbtree: just include stddef.h Rosen Penev
` (3 more replies)
0 siblings, 4 replies; 7+ messages in thread
From: Rosen Penev @ 2025-10-26 20:00 UTC (permalink / raw)
To: linux-mtd
This is an internal header that's already included with others.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
include/common.h | 1 -
1 file changed, 1 deletion(-)
diff --git a/include/common.h b/include/common.h
index 303d30d..d443e17 100644
--- a/include/common.h
+++ b/include/common.h
@@ -26,7 +26,6 @@
#include <string.h>
#include <fcntl.h>
#include <errno.h>
-#include <features.h>
#include <inttypes.h>
#include <unistd.h>
#include <sys/sysmacros.h>
--
2.51.1
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/5] mtd-utils: rbtree: just include stddef.h
2025-10-26 20:00 [PATCH 1/5] mtd-utils: don't include features.h Rosen Penev
@ 2025-10-26 20:00 ` Rosen Penev
2025-10-26 20:00 ` [PATCH 3/5] mtd-utils: reduce linux/types.h usage Rosen Penev
` (2 subsequent siblings)
3 siblings, 0 replies; 7+ messages in thread
From: Rosen Penev @ 2025-10-26 20:00 UTC (permalink / raw)
To: linux-mtd
There's nothing specific in the linux headers that's needed.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
include/rbtree.h | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/include/rbtree.h b/include/rbtree.h
index 89926e7..e4a215d 100644
--- a/include/rbtree.h
+++ b/include/rbtree.h
@@ -94,8 +94,7 @@ static inline struct page * rb_insert_page_cache(struct inode * inode,
#ifndef _LINUX_RBTREE_H
#define _LINUX_RBTREE_H
-#include <linux/kernel.h>
-#include <linux/stddef.h>
+#include <stddef.h>
struct rb_node
{
--
2.51.1
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 3/5] mtd-utils: reduce linux/types.h usage
2025-10-26 20:00 [PATCH 1/5] mtd-utils: don't include features.h Rosen Penev
2025-10-26 20:00 ` [PATCH 2/5] mtd-utils: rbtree: just include stddef.h Rosen Penev
@ 2025-10-26 20:00 ` Rosen Penev
2025-10-26 20:00 ` [PATCH 4/5] mtd-utils: serve_image: fix _POSIX_C_SOURCE Rosen Penev
2025-10-26 20:00 ` [PATCH 5/5] mtd-utils: add GNU_SOURCE define to c files Rosen Penev
3 siblings, 0 replies; 7+ messages in thread
From: Rosen Penev @ 2025-10-26 20:00 UTC (permalink / raw)
To: linux-mtd
In the cases where it's needed, replace with asm variant. It's more
portable.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
nor-utils/rfddump.c | 1 -
nor-utils/rfdformat.c | 1 -
ubifs-utils/common/compr.c | 1 -
ubifs-utils/common/linux_types.h | 2 +-
ubifs-utils/common/sign.c | 1 -
ubifs-utils/common/sort.c | 1 +
6 files changed, 2 insertions(+), 5 deletions(-)
diff --git a/nor-utils/rfddump.c b/nor-utils/rfddump.c
index d6d7f68..2e9e275 100644
--- a/nor-utils/rfddump.c
+++ b/nor-utils/rfddump.c
@@ -24,7 +24,6 @@
#include <getopt.h>
#include <mtd/mtd-user.h>
-#include <linux/types.h>
#include <mtd_swab.h>
#include "common.h"
diff --git a/nor-utils/rfdformat.c b/nor-utils/rfdformat.c
index 0a3d9fb..6a78122 100644
--- a/nor-utils/rfdformat.c
+++ b/nor-utils/rfdformat.c
@@ -26,7 +26,6 @@
#include <getopt.h>
#include <mtd/mtd-user.h>
-#include <linux/types.h>
#include "common.h"
diff --git a/ubifs-utils/common/compr.c b/ubifs-utils/common/compr.c
index 6f90151..ef540ee 100644
--- a/ubifs-utils/common/compr.c
+++ b/ubifs-utils/common/compr.c
@@ -27,7 +27,6 @@
#ifdef WITH_LZO
#include <lzo/lzo1x.h>
#endif
-#include <linux/types.h>
#ifdef WITH_ZSTD
#include <zstd.h>
#endif
diff --git a/ubifs-utils/common/linux_types.h b/ubifs-utils/common/linux_types.h
index ebf9ecd..c172657 100644
--- a/ubifs-utils/common/linux_types.h
+++ b/ubifs-utils/common/linux_types.h
@@ -1,7 +1,7 @@
#ifndef __LINUX_TYPES_H__
#define __LINUX_TYPES_H__
-#include <linux/types.h>
+#include <asm/types.h>
#include <sys/types.h>
#include <byteswap.h>
#include <stdint.h>
diff --git a/ubifs-utils/common/sign.c b/ubifs-utils/common/sign.c
index 032a6ac..379d2e4 100644
--- a/ubifs-utils/common/sign.c
+++ b/ubifs-utils/common/sign.c
@@ -28,7 +28,6 @@
#include <openssl/conf.h>
#include <err.h>
-#include "linux_types.h"
#include "sign.h"
#include "ubifs.h"
#include "defs.h"
diff --git a/ubifs-utils/common/sort.c b/ubifs-utils/common/sort.c
index d585836..a9cfa67 100644
--- a/ubifs-utils/common/sort.c
+++ b/ubifs-utils/common/sort.c
@@ -12,6 +12,7 @@
#include <stdio.h>
#include <stdbool.h>
+
#include <linux/types.h>
#include "sort.h"
--
2.51.1
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 4/5] mtd-utils: serve_image: fix _POSIX_C_SOURCE
2025-10-26 20:00 [PATCH 1/5] mtd-utils: don't include features.h Rosen Penev
2025-10-26 20:00 ` [PATCH 2/5] mtd-utils: rbtree: just include stddef.h Rosen Penev
2025-10-26 20:00 ` [PATCH 3/5] mtd-utils: reduce linux/types.h usage Rosen Penev
@ 2025-10-26 20:00 ` Rosen Penev
2025-10-26 20:00 ` [PATCH 5/5] mtd-utils: add GNU_SOURCE define to c files Rosen Penev
3 siblings, 0 replies; 7+ messages in thread
From: Rosen Penev @ 2025-10-26 20:00 UTC (permalink / raw)
To: linux-mtd
200809 is needed for pread/pwrite
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
misc-utils/serve_image.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/misc-utils/serve_image.c b/misc-utils/serve_image.c
index 6c8c8fb..ec2090f 100644
--- a/misc-utils/serve_image.c
+++ b/misc-utils/serve_image.c
@@ -1,5 +1,5 @@
#define PROGRAM_NAME "serve_image"
-#define _POSIX_C_SOURCE 200112L
+#define _POSIX_C_SOURCE 200809L
#include <time.h>
#include <errno.h>
--
2.51.1
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 5/5] mtd-utils: add GNU_SOURCE define to c files
2025-10-26 20:00 [PATCH 1/5] mtd-utils: don't include features.h Rosen Penev
` (2 preceding siblings ...)
2025-10-26 20:00 ` [PATCH 4/5] mtd-utils: serve_image: fix _POSIX_C_SOURCE Rosen Penev
@ 2025-10-26 20:00 ` Rosen Penev
2025-11-28 20:43 ` David Oberhollenzer
3 siblings, 1 reply; 7+ messages in thread
From: Rosen Penev @ 2025-10-26 20:00 UTC (permalink / raw)
To: linux-mtd
Allows removing the global GNU_SOURCE define.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
jffsX-utils/mkfs.jffs2.c | 4 ++++
lib/libmtd.c | 6 +++++-
lib/libmtd_legacy.c | 5 ++++-
misc-utils/flash_erase.c | 6 +++++-
misc-utils/recv_image.c | 4 ++++
nand-utils/nandtest.c | 4 ++++
6 files changed, 26 insertions(+), 3 deletions(-)
diff --git a/jffsX-utils/mkfs.jffs2.c b/jffsX-utils/mkfs.jffs2.c
index da07b69..b0e649c 100644
--- a/jffsX-utils/mkfs.jffs2.c
+++ b/jffsX-utils/mkfs.jffs2.c
@@ -49,6 +49,10 @@
#define PROGRAM_NAME "mkfs.jffs2"
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE // needed for asprintf
+#endif
+
#include <sys/types.h>
#include <stdio.h>
#include <sys/stat.h>
diff --git a/lib/libmtd.c b/lib/libmtd.c
index f588e09..0489a15 100644
--- a/lib/libmtd.c
+++ b/lib/libmtd.c
@@ -22,12 +22,16 @@
* MTD library.
*/
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE // needed for loff_t
+#endif
+
+#include <fcntl.h>
#include <limits.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
-#include <fcntl.h>
#include <dirent.h>
#include <sys/types.h>
#include <sys/stat.h>
diff --git a/lib/libmtd_legacy.c b/lib/libmtd_legacy.c
index e0ecf49..457f330 100644
--- a/lib/libmtd_legacy.c
+++ b/lib/libmtd_legacy.c
@@ -23,7 +23,10 @@
* not possible to get sub-page size.
*/
-#include <limits.h>
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE // needed for loff_t
+#endif
+
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
diff --git a/misc-utils/flash_erase.c b/misc-utils/flash_erase.c
index 36f8d57..98289f4 100644
--- a/misc-utils/flash_erase.c
+++ b/misc-utils/flash_erase.c
@@ -21,11 +21,15 @@
#define PROGRAM_NAME "flash_erase"
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE // needed for loff_t
+#endif
+
+#include <fcntl.h>
#include <inttypes.h>
#include <stdbool.h>
#include <stdio.h>
#include <unistd.h>
-#include <fcntl.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
diff --git a/misc-utils/recv_image.c b/misc-utils/recv_image.c
index eeaa2e2..157e240 100644
--- a/misc-utils/recv_image.c
+++ b/misc-utils/recv_image.c
@@ -4,6 +4,10 @@
#define _BSD_SOURCE /* struct ip_mreq */
#define _DEFAULT_SOURCE
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE // needed for loff_t
+#endif
+
#include <errno.h>
#include <stdio.h>
#include <netdb.h>
diff --git a/nand-utils/nandtest.c b/nand-utils/nandtest.c
index cac0dde..58542e5 100644
--- a/nand-utils/nandtest.c
+++ b/nand-utils/nandtest.c
@@ -1,5 +1,9 @@
#define PROGRAM_NAME "nandtest"
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE // needed for loff_t
+#endif
+
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
--
2.51.1
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 5/5] mtd-utils: add GNU_SOURCE define to c files
2025-10-26 20:00 ` [PATCH 5/5] mtd-utils: add GNU_SOURCE define to c files Rosen Penev
@ 2025-11-28 20:43 ` David Oberhollenzer
2025-11-28 20:50 ` Rosen Penev
0 siblings, 1 reply; 7+ messages in thread
From: David Oberhollenzer @ 2025-11-28 20:43 UTC (permalink / raw)
To: Rosen Penev, linux-mtd
Hi,
your _GNU_SOURCE commit breaks the build (you removed limits.h
from libmtd_legacy.c). Besides that, I'm reluctant to remove
the global _GNU_SOURCE define, we might have a number of implicit
users across the source and the extensions we use are generally
useful.
While I think it's a valuable goal to be compatible with non-GNU
libc implementations like Musl, or klibc. Libraries like Musl
implement a good chunk anyway and for stuff that's really missing,
we have a libmissing.a.
Regarding the Linux header inclusions across the code, those
parts (e.g. rb-tree) have probably been lifted directly from
the Linux kernel tree. I don't think we should try to intentionally
try to diverge from the upstream version.
Also, what would we gain from portability here? Portability to
non-Linux based, non-GNU, Unix-like systems? What use would those
have for mtd-utils?
Anyway, I cherry-picked and applied the _POSIX_C_SOURCE patch to
mtd-utils.git master.
Thanks,
David
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 5/5] mtd-utils: add GNU_SOURCE define to c files
2025-11-28 20:43 ` David Oberhollenzer
@ 2025-11-28 20:50 ` Rosen Penev
0 siblings, 0 replies; 7+ messages in thread
From: Rosen Penev @ 2025-11-28 20:50 UTC (permalink / raw)
To: David Oberhollenzer; +Cc: linux-mtd
On Fri, Nov 28, 2025 at 12:43 PM David Oberhollenzer
<david.oberhollenzer@sigma-star.at> wrote:
>
> Hi,
>
> your _GNU_SOURCE commit breaks the build (you removed limits.h
> from libmtd_legacy.c). Besides that, I'm reluctant to remove
> the global _GNU_SOURCE define, we might have a number of implicit
> users across the source and the extensions we use are generally
> useful.
Yeah this was not correct.
>
> While I think it's a valuable goal to be compatible with non-GNU
> libc implementations like Musl, or klibc. Libraries like Musl
> implement a good chunk anyway and for stuff that's really missing,
> we have a libmissing.a.
Some of these header removals are for compatibility with macOS, like
with features.h.
>
> Regarding the Linux header inclusions across the code, those
> parts (e.g. rb-tree) have probably been lifted directly from
> the Linux kernel tree. I don't think we should try to intentionally
> try to diverge from the upstream version.
It's a patch carried by OpenWrt to get compilation on macOS working.
I'll see what I can do about this.
>
> Also, what would we gain from portability here? Portability to
> non-Linux based, non-GNU, Unix-like systems? What use would those
> have for mtd-utils?
Some OpenWrt developers develop on macOS. That's about it.
>
>
> Anyway, I cherry-picked and applied the _POSIX_C_SOURCE patch to
> mtd-utils.git master.
Interestingly enough I found this issue while trying to remove
_GNU_SOURCE. Maybe there are some more.
>
> Thanks,
>
> David
>
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-11-28 20:50 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-26 20:00 [PATCH 1/5] mtd-utils: don't include features.h Rosen Penev
2025-10-26 20:00 ` [PATCH 2/5] mtd-utils: rbtree: just include stddef.h Rosen Penev
2025-10-26 20:00 ` [PATCH 3/5] mtd-utils: reduce linux/types.h usage Rosen Penev
2025-10-26 20:00 ` [PATCH 4/5] mtd-utils: serve_image: fix _POSIX_C_SOURCE Rosen Penev
2025-10-26 20:00 ` [PATCH 5/5] mtd-utils: add GNU_SOURCE define to c files Rosen Penev
2025-11-28 20:43 ` David Oberhollenzer
2025-11-28 20:50 ` Rosen Penev
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).