On Feb 11, 2012, at 12:31 AM, Mouse wrote: >>>> Why not use O_DIRECTORY (which is part of -current) and add that to >>>> flags? >>> Backporting that might be a better alternative. What are its >>> semantics? >> It means the open will only succeed is the file is a directory. > > Worth having, but not sufficient by itself, because it still requires > something in the low two bits, and without something like O_NOACCESS > there is nothing you can pass there that will let you open a directory > you have neither read nor write access to (even if you have search > access to it).
Right. You add O_DIRECTORY to that check. if ((flags & (FREAD|FWRITE)) == 0 && (flags & O_DIRECTORY) == 0) return EINVAL; if ((flags & O_DIRECTORY) != 0 && (flags & (FREAD|FWRITE)) != 0) return EINVAL;