Porting to OS/2: Case #14 open() and DASD access

On Unix-like systems, open() can open various devices including files, storages and so on. On OS/2 kLIBC as well, open() does like that. However, open() of kLIBC does not support DASD. If you open [x:] expecting to open a drive x: in DASD mode, your expectation will go wrong. Although open() for x: succeeds, it is not for DASD mode, but for a directory. The handle returned can be used with functions which do not alter a file position and contents. For examples, fchdir() and fstat().

Then what is how to open in DASD mode ? Use a wrapper function for DosOpen(). The following are the codes used by libdvdnav. 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#ifdef __OS2__
#define INCL_DOS
#include <os2safe.h>
#include <os2.h>
#include <io.h>     /* setmode() */
#include <fcntl.h>  /* O_BINARY  */
#endif

#ifdef __OS2__
#define open os2_open

static int os2_open(const char *name, int oflag)
{
  HFILE hfile;
  ULONG ulAction;
  ULONG rc;

  rc = DosOpenL(name, &hfile, &ulAction, 0, FILE_NORMAL,
                OPEN_ACTION_OPEN_IF_EXISTS | OPEN_ACTION_FAIL_IF_NEW,
                OPEN_ACCESS_READONLY | OPEN_SHARE_DENYNONE | OPEN_FLAGS_DASD,
                NULL);

  if(rc)
    return -1;

  setmode(hfile, O_BINARY);

  return (int)hfile;
}
#endif


Note that all open()s after the above codes try to open in DASD mode. If opening a normal file or a directory is necessary, undefine open.

댓글

이 블로그의 인기 게시물

토렌트: < 왕좌의 게임 > 시즌 1 ~ 시즌 8 완결편 마그넷

토렌트: NGC < 코스모스 > 우리말 더빙 전편(1편~13편) 마그넷

토렌트: < 스타워즈 > Ep.1 ~ Ep.6 마그넷