Re: New Linux User needs some guidance
Hi,
after not finding in the man page a description of cp behavior with
existing target file, i looked up POSIX
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/cp.html
"3. If source_file is of type regular file, [...]
a. [...] if dest_file exists, the following steps shall be taken:
[...]
ii. A file descriptor for dest_file shall be obtained by performing
actions equivalent to the open() function defined in the System
Interfaces volume of POSIX.1-2017 called using dest_file as the
path argument, and the bitwise-inclusive OR of O_WRONLY and
O_TRUNC as the oflag argument.
"
open() is descibed by man 2 open:
"The argument flags must include one of the following access modes:
O_RDONLY, O_WRONLY, or O_RDWR. These request opening the file read-
only, write-only, or read/write, respectively.
[...]
O_TRUNC
If the file already exists and is a regular file and the access
mode allows writing (i.e., is O_RDWR or O_WRONLY) it will be
truncated to length 0. If the file is a FIFO or terminal device
file, the O_TRUNC flag is ignored. Otherwise, the effect of
O_TRUNC is unspecified.
"
So bitrot could indeed happen if open(2) decides to change its unspecified
behavior for block devices.
(I have difficulties to imagine what one must smoke in order to come to
the idea of unlinking the device file and creating a data file instead.)
Have a nice day :)
Thomas
Reply to: