Skip to contentSkip to conversation

erofs-utils: fix `--blobdev=X`

PATCH In review Gao Xiang 2 participants 9 messages Apr 27, 2025 Library code

lore
Share & tools
lore

Gao Xiang

author
#0 lore raw

PATCH 1/1 erofs-utils: fix `--blobdev=X`

Create one if the file doesn't exist.

Fixes b6b741d8daaf ("erofs-utils: lib: get rid of tmpfile()")
---
 lib/blobchunk.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
lib/blobchunk.c +2 -1
index e6386d6..301f46a 100644
@@ -627,7 +627,8 @@ int erofs_blob_init(const char *blobfile_path, erofs_off_t chunksize)
 		blobfile = erofs_tmpfile();
 		multidev = false;
 	} else {
-		blobfile = open(blobfile_path, O_WRONLY | O_BINARY);
+		blobfile = open(blobfile_path, O_WRONLY | O_CREAT |
+						O_TRUNC | O_BINARY, 0666);
 		multidev = true;
 	}
 	if (blobfile < 0)
Signature · 1 line
2.43.5
#1 lore raw
Quoted 3 lines · Gao Xiang

Create one if the file doesn't exist.

Fixes b6b741d8daaf ("erofs-utils: lib: get rid of tmpfile()")

I think the real fixes should be Fixes: bbeec3c93076 ("erofs-utils: mkfs: add extra blob device support").

Quoted 10 lines
---
  lib/blobchunk.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
lib/blobchunk.c +0 -0
index e6386d6..301f46a 100644

lib/blobchunk.c int erofs_blob_init(const char *blobfile_path, erofs_off_t chunksize) · line 631

Quoted 6 lines
lib/blobchunk.c +2 -1
@@ -627,7 +627,8 @@ int erofs_blob_init(const char *blobfile_path, erofs_off_t chunksize)
  		blobfile = erofs_tmpfile();
  		multidev = false;
  	} else {
-		blobfile = open(blobfile_path, O_WRONLY | O_BINARY);
+		blobfile = open(blobfile_path, O_WRONLY | O_CREAT |
+						O_TRUNC | O_BINARY, 0666);

To maintain consistency, is it better to set the default permission to 0644?

Thanks,
Hongbo

Quoted 3 lines
lib/blobchunk.c +0 -0
  		multidev = true;
  	}
  	if (blobfile < 0)
author
#2 lore raw

Hi Hongbo,

Quoted 8 lines · Hongbo Li
Quoted 3 lines · Gao Xiang

Create one if the file doesn't exist.

Fixes b6b741d8daaf ("erofs-utils: lib: get rid of tmpfile()")

I think the real fixes should be Fixes: bbeec3c93076 ("erofs-utils: mkfs: add extra blob device support").

Prior to b6b741d8daaf, the functionality is ok since fopen(..,"wb") will create the file too.

Quoted 5 lines
Quoted 5 lines

---
  lib/blobchunk.c | 3 ++-

  1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 12 lines

lib/blobchunk.c int erofs_blob_init(const char *blobfile_path, erofs_off_t chunksize) · line 631

Quoted 11 lines
lib/blobchunk.c +2 -1
index e6386d6..301f46a 100644
@@ -627,7 +627,8 @@ int erofs_blob_init(const char *blobfile_path, erofs_off_t chunksize)
           blobfile = erofs_tmpfile();
           multidev = false;
       } else {
-        blobfile = open(blobfile_path, O_WRONLY | O_BINARY);
+        blobfile = open(blobfile_path, O_WRONLY | O_CREAT |
+                        O_TRUNC | O_BINARY, 0666);

To maintain consistency, is it better to set the default permission to 0644?

I tend to switch all modes to 0666 around the codebase in the future, since umask(022) will mask them into 0644.

Thanks,
Gao Xiang

#3 lore raw
Quoted 6 lines · Gao Xiang

Hi Hongbo,

Quoted 3 lines · Hongbo Li

On 2025/4/27 10:15, Gao Xiang wrote:

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Create one if the file doesn't exist.

Fixes b6b741d8daaf ("erofs-utils: lib: get rid of tmpfile()")

I think the real fixes should be Fixes: bbeec3c93076 ("erofs-utils: mkfs: add extra blob device support").

Prior to b6b741d8daaf, the functionality is ok since fopen(..,"wb") will create the file too.

Sorry, you're right, I misread that.

Quoted 20 lines
Quoted 6 lines
Quoted 6 lines

---
  lib/blobchunk.c | 3 ++-

  1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 13 lines

lib/blobchunk.c int erofs_blob_init(const char *blobfile_path, · line 632

Quoted 12 lines
lib/blobchunk.c +2 -1
index e6386d6..301f46a 100644
@@ -627,7 +627,8 @@ int erofs_blob_init(const char *blobfile_path, 
 erofs_off_t chunksize)
           blobfile = erofs_tmpfile();
           multidev = false;
       } else {
-        blobfile = open(blobfile_path, O_WRONLY | O_BINARY);
+        blobfile = open(blobfile_path, O_WRONLY | O_CREAT |
+                        O_TRUNC | O_BINARY, 0666);

To maintain consistency, is it better to set the default permission to 0644?

Quoted 3 lines

I tend to switch all modes to 0666 around the codebase in the future, since umask(022) will mask them into 0644.

but 0644 can clearly show which permissions are set (the default umask 022 won't change anything). Or if we need to enforce a specific mode, can we umask to 0 at the beginning instead of relying on the default umask?

By the way, I have another doubt (just occurred to me when seeing O_TRUNC, though it might be unrelated to this change): the chunk-based format can't be used together with the "--increase" option. Should we add a warning for that?

Thanks,
Hongbo

Quoted 2 lines

Thanks,
Gao Xiang

author
#4 lore raw
Quoted 3 lines · Hongbo Li

On 2025/4/27 10:56, Gao Xiang wrote:

...

Quoted 13 lines
Quoted 13 lines
Quoted 12 lines

lib/blobchunk.c int erofs_blob_init(const char *blobfile_path, erofs_off_t chunksize) · line 631

Quoted 11 lines
lib/blobchunk.c +2 -1
index e6386d6..301f46a 100644
@@ -627,7 +627,8 @@ int erofs_blob_init(const char *blobfile_path, erofs_off_t chunksize)
           blobfile = erofs_tmpfile();
           multidev = false;
       } else {
-        blobfile = open(blobfile_path, O_WRONLY | O_BINARY);
+        blobfile = open(blobfile_path, O_WRONLY | O_CREAT |
+                        O_TRUNC | O_BINARY, 0666);

To maintain consistency, is it better to set the default permission to 0644?

Quoted 4 lines
Quoted 3 lines

I tend to switch all modes to 0666 around the codebase in the future, since umask(022) will mask them into 0644.

but 0644 can clearly show which permissions are set (the default umask 022 won't change anything). Or if we need to enforce a specific mode, can we umask to 0 at the beginning instead of relying on the default umask?

see fopen(3): https://man7.org/linux/man-pages/man3/fopen.3.html

In short, I'd like to change all 0644 to 0666 since there is no reason to mask off other permissions unless umask is also effective.

Or do you have other concerns?

Quoted 2 lines

By the way, I have another doubt (just occurred to me when seeing O_TRUNC, though it might be unrelated to this change): the chunk-based format can't be used together with the "--increase" option. Should we add a warning for that?

Why?

Thanks,
Gao Xiang

Quoted 6 lines

Thanks,
Hongbo

Quoted 2 lines

Thanks,
Gao Xiang

Reviewed-by
#5 lore raw
Quoted 28 lines · Gao Xiang
Quoted 3 lines · Hongbo Li

On 2025/4/27 10:56, Gao Xiang wrote:

...

Quoted 14 lines
Quoted 14 lines
Quoted 13 lines

lib/blobchunk.c int erofs_blob_init(const char *blobfile_path, · line 632

Quoted 12 lines
lib/blobchunk.c +2 -1
index e6386d6..301f46a 100644
@@ -627,7 +627,8 @@ int erofs_blob_init(const char *blobfile_path, 
 erofs_off_t chunksize)
           blobfile = erofs_tmpfile();
           multidev = false;
       } else {
-        blobfile = open(blobfile_path, O_WRONLY | O_BINARY);
+        blobfile = open(blobfile_path, O_WRONLY | O_CREAT |
+                        O_TRUNC | O_BINARY, 0666);

To maintain consistency, is it better to set the default permission to 0644?

Quoted 4 lines
Quoted 3 lines

I tend to switch all modes to 0666 around the codebase in the future, since umask(022) will mask them into 0644.

but 0644 can clearly show which permissions are set (the default umask 022 won't change anything). Or if we need to enforce a specific mode, can we umask to 0 at the beginning instead of relying on the default umask?

Quoted 7 lines

see fopen(3): https://man7.org/linux/man-pages/man3/fopen.3.html

In short, I'd like to change all 0644 to 0666 since there is no reason to mask off other permissions unless umask is also effective.

Or do you have other concerns?

ok, I have not other concerns.

Quoted 16 lines
Quoted 3 lines

By the way, I have another doubt (just occurred to me when seeing O_TRUNC, though it might be unrelated to this change): the chunk-based format can't be used together with the "--increase" option. Should we add a warning for that?

Why?

Thanks,
Gao Xiang

Quoted 6 lines

Thanks,
Hongbo

Quoted 2 lines

Thanks,
Gao Xiang

author
#6 lore raw
Quoted 36 lines · Hongbo Li
Quoted 33 lines · Gao Xiang
Quoted 3 lines · Hongbo Li

On 2025/4/27 10:56, Gao Xiang wrote:

...

Quoted 13 lines
Quoted 13 lines
Quoted 12 lines

lib/blobchunk.c int erofs_blob_init(const char *blobfile_path, erofs_off_t chunksize) · line 631

Quoted 11 lines
lib/blobchunk.c +2 -1
index e6386d6..301f46a 100644
@@ -627,7 +627,8 @@ int erofs_blob_init(const char *blobfile_path, erofs_off_t chunksize)
           blobfile = erofs_tmpfile();
           multidev = false;
       } else {
-        blobfile = open(blobfile_path, O_WRONLY | O_BINARY);
+        blobfile = open(blobfile_path, O_WRONLY | O_CREAT |
+                        O_TRUNC | O_BINARY, 0666);

To maintain consistency, is it better to set the default permission to 0644?

Quoted 4 lines
Quoted 3 lines

I tend to switch all modes to 0666 around the codebase in the future, since umask(022) will mask them into 0644.

but 0644 can clearly show which permissions are set (the default umask 022 won't change anything). Or if we need to enforce a specific mode, can we umask to 0 at the beginning instead of relying on the default umask?

see fopen(3): https://man7.org/linux/man-pages/man3/fopen.3.html

In short, I'd like to change all 0644 to 0666 since there is no reason to mask off other permissions unless umask is also effective.

Quoted 5 lines
Quoted 1 line

Or do you have other concerns?

ok, I have not other concerns.

Thanks for the review!

Thanks,
Gao Xiang

#7 lore raw
In reply to Gao Xiang
Quoted 34 lines · Gao Xiang
Quoted 3 lines · Hongbo Li

On 2025/4/27 10:56, Gao Xiang wrote:

...

Quoted 14 lines
Quoted 14 lines
Quoted 13 lines

lib/blobchunk.c int erofs_blob_init(const char *blobfile_path, · line 632

Quoted 12 lines
lib/blobchunk.c +2 -1
index e6386d6..301f46a 100644
@@ -627,7 +627,8 @@ int erofs_blob_init(const char *blobfile_path, 
 erofs_off_t chunksize)
           blobfile = erofs_tmpfile();
           multidev = false;
       } else {
-        blobfile = open(blobfile_path, O_WRONLY | O_BINARY);
+        blobfile = open(blobfile_path, O_WRONLY | O_CREAT |
+                        O_TRUNC | O_BINARY, 0666);

To maintain consistency, is it better to set the default permission to 0644?

Quoted 4 lines
Quoted 3 lines

I tend to switch all modes to 0666 around the codebase in the future, since umask(022) will mask them into 0644.

but 0644 can clearly show which permissions are set (the default umask 022 won't change anything). Or if we need to enforce a specific mode, can we umask to 0 at the beginning instead of relying on the default umask?

see fopen(3): https://man7.org/linux/man-pages/man3/fopen.3.html

In short, I'd like to change all 0644 to 0666 since there is no reason to mask off other permissions unless umask is also effective.

Quoted 7 lines

Or do you have other concerns?

Quoted 2 lines

By the way, I have another doubt (just occurred to me when seeing O_TRUNC, though it might be unrelated to this change): the chunk-based format can't be used together with the "--increase" option. Should we add a warning for that?

Why?

Because some formatting options cannot be used in combination (such as --blobdev --chunksize --incremental=xxx in non-tar mode). But this might be outside the scope of this patch.

Perhaps we can add the constraints or some explanation to avoid any misunderstanding later. What's about your opinion?

Thanks,
Hongbo

Quoted 10 lines

Thanks,
Gao Xiang

Quoted 6 lines

Thanks,
Hongbo

Quoted 2 lines

Thanks,
Gao Xiang

author
#8 lore raw
Quoted 2 lines · Hongbo Li

...

Quoted 4 lines
Quoted 1 line

Because some formatting options cannot be used in combination (such as --blobdev --chunksize --incremental=xxx in non-tar mode). But this might be outside the scope of this patch.

Perhaps we can add the constraints or some explanation to avoid any misunderstanding later. What's about your opinion?

Okay, I understand.

Yeah, I think they should be explicitly warned out, but they're just unimplemented due to lack of development resource...

Thanks,
Gao Xiang

Quoted 3 lines

Thanks,
Hongbo