Re: CD writing in future Linux (stirring up a hornets' nest)

From: Kyle Moffett
Date: Sun Feb 05 2006 - 12:51:44 EST


On Feb 05, 2006, at 11:15, Phillip Susi wrote:
Jan Engelhardt wrote:
I would say we all forgot to RTFM. Because O_EXCL does nothing *unless* O_CREAT is specified, which probably *is not* specified in cdrecord or hal. There is no reason to have hal or cdrecord create a device node - which you can't do with open() anyway.

I think you are misinterpreting the man page, because it isn't worded very clearly. It should not even mention O_CREAT because it has nothing to do with O_EXCL; it is just repeating the semantics of O_CREAT ( if the file already exists, the call fails ) which would of course, apply if you do use O_CREAT in conjunction with any other flag including O_EXCL. It does not say that you must use O_EXCL with O_CREAT. The rest of the description talks about using lockfiles as an alternative to ensure exclusive access to the file on NFS where O_EXCL is broken. The intent of O_EXCL is clearly to provide the caller with exclusive access to the file.

You don't have this right either. The way open() works:

If you specify O_CREAT (and not O_EXCL), it will create the file if it does not exist, and open the existing file otherwise.

If you specify O_EXCL (and not O_CREAT), it is implementation defined what will happen (in the Linux case, this opens a block device for exclusive access).

If you specify O_CREAT|O_EXCL, it will atomically create the file if it does not exist, otherwise it will return the error -EEXIST.

Cheers,
Kyle Moffett

--
Q: Why do programmers confuse Halloween and Christmas?
A: Because OCT 31 == DEC 25.



-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/