|
|
Subscribe / Log in / New account

The shrinking role of ETXTBSY

The shrinking role of ETXTBSY

Posted Aug 19, 2021 23:15 UTC (Thu) by SLi (subscriber, #53131)
In reply to: The shrinking role of ETXTBSY by nybble41
Parent article: The shrinking role of ETXTBSY

Would it cause problems if such an operation by a user with write permission to the file but not the directory could patch the new node number to the directory entry?


to post comments

The shrinking role of ETXTBSY

Posted Aug 20, 2021 5:57 UTC (Fri) by nybble41 (subscriber, #55106) [Link] (2 responses)

Updating the directory entry would be a user-visible change since getdents(2), readdir(3), and stat(2) all report the inode number; more importantly it could result in breaking hardlinks (as the atomic rename approach would) which is something that normally requires write access to the containing directory. Beyond that I'm not sure how much trouble would result from allowing just the inode number to be updated in an otherwise read-only directory entry… it's not something that's seen much testing.

Atomically swapping the *content* of two files (one of which could be temporary/unlinked) could be a useful operation for some cases which currently rely on atomic rename, and wouldn't have any issue with read-only directories, but it wouldn't help in this particular situation since any existing open file descriptions or mapped memory would immediately see the new content just as if the file had been modified with ftruncate(2) and write(2).

The shrinking role of ETXTBSY

Posted Aug 20, 2021 17:47 UTC (Fri) by smurf (subscriber, #17840) [Link] (1 responses)

Yeah, but you could extend the atomic swap to *also* swap the file descriptor of A to point to B instead.

This will cause all kinds of interesting race conditions unless handled carefully … but it could work.

The shrinking role of ETXTBSY

Posted Aug 22, 2021 8:35 UTC (Sun) by NYKevin (subscriber, #129325) [Link]

Truncating a file already causes all kinds of interesting race conditions. But they're in userspace, so we all collectively pretend that they're not a problem.

(Because, well, what's the alternative? Any global mutable state will inevitably race, at some level of abstraction, and global mutable state is literally the whole point of a filesystem.)

The shrinking role of ETXTBSY

Posted Aug 20, 2021 6:42 UTC (Fri) by pbonzini (subscriber, #60935) [Link]

Yes, the operation would break hard links. Not having write permissions for the directory implies not being able to break hard links.


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds