Conversation
|
Interesting. I'm a heavy user of the |
|
A form of Linux that's running on the QNAP NAS devices. I'm saying "a form of" because it has some limitations compared to distributions like Ubuntu, e.g. Regardless, I will need to run this tool on such QNAP devices and have already tested that this commit fixes |
|
Oh I wasn't trying to shoot down your contribution. It looks sane to me (without having tested it myself). |
|
No problem, I never took it like that :-) But I can confirm that using the stdout works as expected on a regular Ubuntu, without this commit being necessary. So it appears to be something more obscure, probably related to the version of Linux running on QNAP devices. I'm no expert in C, so if you think that there's some risk of this commit breaking things I'd completely understand if you feel like this is an edge case that's not worth solving. Applying it as a patch already solved the problem for me, so I'm fine either way. |
|
@mart-jansink could you try the exact same |
|
While doing this I found that it isn't actually the QNAP Linux version that's causing the problem. I didn't mention that I'm calling genext2fs from a node.js script that takes the stdout, instead of running something like The error is easily reproduced by running the following with node.js (at least the LTS one, v14.15.3): var child_process = require( "child_process" );
var fs = require( "fs" );
var child = child_process.spawn( "genext2fs-patched", [ "-N", 128, "-m", 0, "-b", ( 1024 * 1024 ), "-" ] )
.on( "error", console.error );
child.stderr
.on( "data", function( chunk ) { console.log( chunk.toString() ); } );
child.stdout
.pipe( fs.createWriteStream( "test.ext2" ) )
.on( "error", console.error );I can't tell if node.js is doing something special with the stdout of a spawned child process, nor could I find any issues like this for it. |
|
Please ignore the node.js part, its not necessarily relevant either. The problem appears to be piping the output to another program instead of redirecting it to a file. Under Ubuntu 20.04 |
|
How does |
bestouff
left a comment
There was a problem hiding this comment.
Anyway in this case the solution is probably just to unconditionally attempt an ftruncate(), without protesting if it fails. So revert your commit, and remove the if and the perror....
|
I just applied the same logic, for consistency, as it's done a few lines below: Line 2930 in 3b99f4a This is probably also the answer to your surprise, genext2fs doesn't try to seek() on a piped output because of this.
Do you still like me to make the change? |
While
-seems to be explicitly supported as the output option (becauseif(strcmp(fsout, "-") == 0)is checked), this doesn't work sinceftruncateis called on it anyway incopy_file. This commit adds a small check on the givendst, just like it does in the loop that actually writes the output.