open(): add O_DIRECTORY flag

This patch adds the O_DIRECTORY flag to sys_open(), which causes the open
to fail with ENOTDIR if the given file is any type of file but a directory.

We need this flag as part of a correct implementation of chdir() (which
should fail on a non-directory file), and it is also required for Linux
compatibility (the O_DIRECTORY flag exists since Linux 2.1.126).

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
chdir(): Fix error path, and add test

This patch fixes chdir() on a normal file, which used to succeed (!?),
but now will fail as it should, with ENOTDIR.

The patch also adds an exhaustive test for chdir's success and error cases.
Before the latest chdir() patches, most of these tests would fail, and now
all of them succeed.

This test is standard C++ & Posix code, so it can be run also on Linux.
This is important for verifing that whatever we expect from OSv, Linux
really does the same.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>