Search code examples
androidunixmkdirinodeterminal-emulator

Can 'touch' work and 'mkdir' fail?


Could there ever be a situation in which touch would work and mkdir would fail, within a directory.

I understand that both these calls involve writing to the inode of the parent directory. So if touch worked, doesn't it automatically mean that the inode is writable and hence, the mkdir couldn't possibly fail.

This was Android (I only heard a report, didn't actually see this case) and the commands were being run from the terminal emulator, in the /system directory (after requesting su), but that shouldn't make a difference IMO.


EDIT: mkdir failed with "permission denied"


Solution

  • There are a couple of ways I can think of by which this could happen:

    1) If you have reached the maximum number of sub-directories in a directory (typically around 32000), you will not be able to mkdir, but you will be able to touch a file.

    2) If you are very low on disk space, you will not be able to mkdir because it requires 4K, but you will be able to touch a file.