Skip to contentSkip to conversation

mtd-utils: don't include features.h

PATCH In review Rosen Penev 2 participants 7 messages Oct 26, 2025 – Nov 28, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/5 mtd-utils: don't include features.h

This is an internal header that's already included with others.

---
 include/common.h | 1 -
 1 file changed, 1 deletion(-)
include/common.h +0 -1
index 303d30d..d443e17 100644
@@ -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>
Signature · 6 lines
2.51.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
#1 lore raw

PATCH 2/5 mtd-utils: rbtree: just include stddef.h

There's nothing specific in the linux headers that's needed.

---
 include/rbtree.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
include/rbtree.h +1 -2
index 89926e7..e4a215d 100644
@@ -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
 {
Signature · 6 lines
2.51.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
#2 lore raw

PATCH 3/5 mtd-utils: reduce linux/types.h usage

In reply to Rosen Penev

In the cases where it's needed, replace with asm variant. It's more portable.

---
 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(-)
nor-utils/rfddump.c +0 -1
index d6d7f68..2e9e275 100644
@@ -24,7 +24,6 @@
 #include <getopt.h>
 
 #include <mtd/mtd-user.h>
-#include <linux/types.h>
 #include <mtd_swab.h>
 
 #include "common.h"
nor-utils/rfdformat.c +0 -1
index 0a3d9fb..6a78122 100644
@@ -26,7 +26,6 @@
 #include <getopt.h>
 
 #include <mtd/mtd-user.h>
-#include <linux/types.h>
 
 #include "common.h"
 
ubifs-utils/common/compr.c +0 -1
index 6f90151..ef540ee 100644
@@ -27,7 +27,6 @@
 #ifdef WITH_LZO
 #include <lzo/lzo1x.h>
 #endif
-#include <linux/types.h>
 #ifdef WITH_ZSTD
 #include <zstd.h>
 #endif
ubifs-utils/common/linux_types.h +1 -1
index ebf9ecd..c172657 100644
@@ -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>
ubifs-utils/common/sign.c +0 -1
index 032a6ac..379d2e4 100644
@@ -28,7 +28,6 @@
 #include <openssl/conf.h>
 #include <err.h>
 
-#include "linux_types.h"
 #include "sign.h"
 #include "ubifs.h"
 #include "defs.h"
ubifs-utils/common/sort.c +1 -0
index d585836..a9cfa67 100644
@@ -12,6 +12,7 @@
 
 #include <stdio.h>
 #include <stdbool.h>
+
 #include <linux/types.h>
 
 #include "sort.h"
Signature · 6 lines
2.51.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
#3 lore raw

PATCH 4/5 mtd-utils: serve_image: fix _POSIX_C_SOURCE

In reply to Rosen Penev

200809 is needed for pread/pwrite

---
 misc-utils/serve_image.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
misc-utils/serve_image.c +1 -1
index 6c8c8fb..ec2090f 100644
@@ -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>
Signature · 6 lines
2.51.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
#4 lore raw

PATCH 5/5 mtd-utils: add GNU_SOURCE define to c files

In reply to Rosen Penev

Allows removing the global GNU_SOURCE define.

---
 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(-)
jffsX-utils/mkfs.jffs2.c +4 -0
index da07b69..b0e649c 100644
@@ -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>
lib/libmtd.c +5 -1
index f588e09..0489a15 100644
@@ -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>
lib/libmtd_legacy.c +4 -1
index e0ecf49..457f330 100644
@@ -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>
misc-utils/flash_erase.c +5 -1
index 36f8d57..98289f4 100644
@@ -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>
misc-utils/recv_image.c +4 -0
index eeaa2e2..157e240 100644
@@ -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>
nand-utils/nandtest.c +4 -0
index cac0dde..58542e5 100644
@@ -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>
Signature · 6 lines
2.51.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
#5 lore raw

Re: [PATCH 5/5] mtd-utils: add GNU_SOURCE define to c files

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/

#6 lore raw

Re: [PATCH 5/5] mtd-utils: add GNU_SOURCE define to c files

Quoted 8 lines · David Oberhollenzer

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.

Quoted 5 lines

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.

Quoted 5 lines

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.

Quoted 4 lines

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.

Quoted 4 lines

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.

Quoted 5 lines

Thanks,

David

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/