Lennart Poettering <lennart@xxxxxxxxxxxxxx> writes: > Doing the locking on the fd you use for writing makes things a lot > easier, because as mentioned udev will automatically retrigger block > devices if an inotify event on it is seen that indicates > "close-after-write". If you deal with multiple fds you need to make That is exactly what I DON'T want to happen. If udev retriggers when the fd is closed, then that results in the partition being automatically mounted just because libparted read the partition table. > sure to close the fd used for writing *after* having released the > lock on the other one, because if you do it the other way round, udev > will retigger the device, but then not be able to lock device and not > actually do anything, and then no further inotify is seen and things > will remain out ofdate. That is what I WANT to happen. Well, at least I don't want a partition to be automatically mounted. It would be nice if udevdb could still be updated. >> Then again, this will also prevent the udevdb from being updated. Maybe >> that is a bigger hammer than you really want when the goal is just to >> stop auto mounting? > > If you change the superblock or part table of your disk, udev > shouldn't read half-written data, so yes, it's *good* it doesn't > update its udevdb. That's the whole point of the exercise! > > I am not sure I grok what the problem is supposed to be here... Right, you don't want it to read half updated data, but if I intentionally prevent udev from looking at the disk _at all_ ( so that partitions don't get auto mounted ), then it also means that it never looks at the finished updates either and updates udevdb. > parted should just open the main block device for writing, take an > exclusive BSD lock on it, then do its thing, and close the fd. It's > very easy, and will bock generation of udev's uevents on the thing, > will block udev from reading half-written data and everything else. Yes, but then it reads the disk and auto mounts a partition just because someone ran parted print. Printing the partition table should not trigger auto mount. Hrm... now that I think about it, why does a CHANGE event trigger auto mount? Shouldn't that only be done on ADD?