|
From: Miklos S. <mi...@sz...> - 2006-01-15 20:10:00
|
> in my filesystem, I have to perform a particular action when a file is > created. Before version 2.5 it was straightforward: a file is only created > within an `mknod' call, `open' never creates a file. Note: you don't have to implement the 'create' call, it is completely optional. If you don't implement it, everything will work exactly the same way as before. For some filesystems it is useful to have an atomic create+open call (e.g. sshfs), but other filesystems may not need it. > In version 2.5 I find the `create' system call, which reads "If the file > does not exist, first create it with the specified mode, and then open it.". > > I have a few doubts: > 1. what does happen if the file exists? Is it truncated like in `creat'? > 2. Does this call ever get used when the file exists? I made a small program > where I only call a `creat', and I saw that: > - `create' is used when the file does not exists; Yes. > - `truncate' and `open' (why not `open' and `ftruncate'?) are used when the > file is already existing. The order should not matter, but this is the order that the Linux kernel does it. > May I assume that `create' always creates a file, and is never called on an > already existing file? Should this be true, I could perform my "new file" > action without having to `stat' the file before to check if the file is > existing... Yes. Miklos |