00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "ad_ntfs.h"
00010
00011 void ADIOI_NTFS_Open(ADIO_File fd, int *error_code)
00012 {
00013 int err;
00014 int cmode, amode, attrib;
00015 static char myname[] = "ADIOI_NTFS_Open";
00016
00017 amode = 0;
00018 cmode = OPEN_EXISTING;
00019 #ifdef USE_WIN_THREADED_IO
00020 attrib = FILE_FLAG_OVERLAPPED;
00021 #else
00022 attrib = FILE_ATTRIBUTE_NORMAL;
00023 #endif
00024
00025 if (fd->access_mode & ADIO_CREATE)
00026 {
00027 cmode = OPEN_ALWAYS;
00028 }
00029 if (fd->access_mode & ADIO_EXCL)
00030 {
00031 cmode = CREATE_NEW;
00032 }
00033
00034 if (fd->access_mode & ADIO_RDONLY)
00035 {
00036 amode = GENERIC_READ;
00037 }
00038 if (fd->access_mode & ADIO_WRONLY)
00039 {
00040 amode = GENERIC_WRITE;
00041 }
00042 if (fd->access_mode & ADIO_RDWR)
00043 {
00044 amode = GENERIC_READ | GENERIC_WRITE;
00045 }
00046
00047 if (fd->access_mode & ADIO_DELETE_ON_CLOSE)
00048 {
00049 attrib = attrib | FILE_FLAG_DELETE_ON_CLOSE;
00050 }
00051 if (fd->access_mode & ADIO_SEQUENTIAL)
00052 {
00053 attrib = attrib | FILE_FLAG_SEQUENTIAL_SCAN;
00054 }
00055 else
00056 {
00057 attrib = attrib | FILE_FLAG_RANDOM_ACCESS;
00058 }
00059
00060 fd->fd_sys = CreateFile(fd->filename,
00061 amode,
00062 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
00063 NULL,
00064 cmode,
00065 attrib,
00066 NULL);
00067 fd->fd_direct = -1;
00068
00069 if ((fd->fd_sys != INVALID_HANDLE_VALUE) && (fd->access_mode & ADIO_APPEND))
00070 {
00071 fd->fp_ind = fd->fp_sys_posn = SetFilePointer(fd->fd_sys, 0, NULL, FILE_END);
00072 if (fd->fp_ind == INVALID_SET_FILE_POINTER)
00073 {
00074 char errMsg[ADIOI_NTFS_ERR_MSG_MAX];
00075 err = GetLastError();
00076 ADIOI_NTFS_Strerror(err, errMsg, ADIOI_NTFS_ERR_MSG_MAX);
00077 if (err != NO_ERROR)
00078 {
00079 *error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE,
00080 myname, __LINE__, MPI_ERR_IO,
00081 "**io", "**io %s", errMsg);
00082 return;
00083 }
00084 }
00085 }
00086
00087
00088 if (fd->fd_sys == INVALID_HANDLE_VALUE)
00089 {
00090 char errMsg[ADIOI_NTFS_ERR_MSG_MAX];
00091 err = GetLastError();
00092 ADIOI_NTFS_Strerror(err, errMsg, ADIOI_NTFS_ERR_MSG_MAX);
00093 *error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE,
00094 myname, __LINE__, MPI_ERR_IO,
00095 "**io",
00096 "**io %s", errMsg);
00097 return;
00098 }
00099
00100 *error_code = MPI_SUCCESS;
00101 }