[PATCH 5/6] commands: add new truncate command

Sascha Hauer s.hauer at pengutronix.de
Wed Nov 19 23:36:23 PST 2025


Hi Ahmad,

On Thu, Mar 20, 2025 at 06:20:18AM +0100, Ahmad Fatoum wrote:
> +		case 's':
> +			size_str = optarg;
> +			if (!size_str)
> +				return COMMAND_ERROR_USAGE;
> +			switch (*size_str) {
> +			case '+':
> +				modify = 1;
> +				size_str++;
> +				break;
> +			case '-':
> +				return COMMAND_ERROR_USAGE;
> +			}
> +			size = strtoull_suffix(size_str, NULL, 10);
> +			break;

...

> +		if (modify) {
> +			struct stat st;
> +
> +			if (fstat(fd, &st) == -1) {
> +				perror("fstat");
> +				ret = 1;
> +				goto close;
> +			}
> +
> +			size = st.st_size + modify * size;

You have taken 'modify' into account here, likely to be able to set it
to -1 in order to decrease the size. Any particular reason you haven't
implemented it?

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



More information about the barebox mailing list