Is rename() atomic?

Yes and no. rename() is atomic assuming the OS does not crash. It cannot be split by any other filesystem op. If the system crashes you might see a ln() operation instead. Also note, when operating on a network filesystem, you might get ENOENT when the operation succeeded successfully. Local filesystem can’t do that to … Read more

Find size and free space of the filesystem containing a given file

This doesn’t give the name of the partition, but you can get the filesystem statistics directly using the statvfs Unix system call. To call it from Python, use os.statvfs(‘/home/foo/bar/baz’). The relevant fields in the result, according to POSIX: unsigned long f_frsize Fundamental file system block size. fsblkcnt_t f_blocks Total number of blocks on file system … Read more