[Pvfs2-cvs] commit by sampson in pvfs2/src/client/windows/client-service: dokan-interface.c fs.c fs.h

CVS commit program cvs at parl.clemson.edu
Tue Dec 14 17:58:04 EST 2010


Update of /projects/cvsroot/pvfs2/src/client/windows/client-service
In directory parlweb1:/tmp/cvs-serv5956/src/client/windows/client-service

Modified Files:
      Tag: windows-client
	dokan-interface.c fs.c fs.h 
Log Message:
Coding Windows client


Index: dokan-interface.c
===================================================================
RCS file: /projects/cvsroot/pvfs2/src/client/windows/client-service/Attic/dokan-interface.c,v
diff -p -u -r1.1.2.5 -r1.1.2.6
--- dokan-interface.c	13 Dec 2010 22:31:33 -0000	1.1.2.5
+++ dokan-interface.c	14 Dec 2010 22:58:04 -0000	1.1.2.6
@@ -488,172 +488,192 @@ PVFS2_Dokan_read_file(
     LONGLONG         Offset,
     PDOKAN_FILE_INFO DokanFileInfo)
 {
-    PVFS_handle handle = DokanFileInfo->Context;
+    char *local_path, *fs_path;
+    int ret, err;
 
     DbgPrint("ReadFile: %S\n", FileName);
-    DbgPrint("   Context: %llx\n", handle);
+    DbgPrint("   Context: %llx\n", DokanFileInfo->Context);
 
+    /* convert from Unicode */
+    local_path = convert_string(FileName);
+    if (local_path == NULL)
+    {
+        return -ERROR_INVALID_DATA;
+    }
+
+    /* resolve the path */
+    fs_path = (char *) malloc(MAX_PATH);
+    MALLOC_CHECK(fs_path);
+    ret = fs_resolve_path(local_path, fs_path, MAX_PATH);
+    if (ret != 0)
+    {
+        free(local_path);
+        free(fs_path);
+        return -1;
+    }
     
+    /* perform the read operation */
+    ret = fs_read(fs_path, Buffer, BufferLength, Offset, (size_t *) ReadLength);
 
+    DbgPrint("   fs_read returns %d\n", ret);
 
+    switch (ret)
+    {
+    case 0: 
+        err = 0;
+        break;
+    default:
+        err = -1;
+    }
 
-    return 0;
+    return err;
 }
 
 
 static int
 PVFS2_Dokan_write_file(
-    LPCWSTR        FileName,
-    LPCVOID        Buffer,
-    DWORD        NumberOfBytesToWrite,
-    LPDWORD        NumberOfBytesWritten,
-    LONGLONG            Offset,
-    PDOKAN_FILE_INFO    DokanFileInfo)
+    LPCWSTR          FileName,
+    LPCVOID          Buffer,
+    DWORD            NumberOfBytesToWrite,
+    LPDWORD          NumberOfBytesWritten,
+    LONGLONG         Offset,
+    PDOKAN_FILE_INFO DokanFileInfo)
 {
-    char    filePath[MAX_PATH];
-    HANDLE    handle = (HANDLE)DokanFileInfo->Context;
-    ULONG    offset = (ULONG)Offset;
-    BOOL    opened = FALSE;
-
-    GetFilePath(filePath, FileName);
-
-    DbgPrint("WriteFile : %s, offset %I64d, length %d\n", filePath, Offset, NumberOfBytesToWrite);
-
-    // reopen the file
-    if (!handle || handle == INVALID_HANDLE_VALUE) {
-        DbgPrint("\tinvalid handle, cleanuped?\n");
-        handle = CreateFile(
-            filePath,
-            GENERIC_WRITE,
-            FILE_SHARE_WRITE,
-            NULL,
-            OPEN_EXISTING,
-            0,
-            NULL);
-        if (handle == INVALID_HANDLE_VALUE) {
-            DbgPrint("\tCreateFile error : %d\n\n", GetLastError());
-            return -1;
-        }
-        opened = TRUE;
-    }
-
-    if (DokanFileInfo->WriteToEndOfFile) {
-        if (SetFilePointer(handle, 0, NULL, FILE_END) == INVALID_SET_FILE_POINTER) {
-            DbgPrint("\tseek error, offset = EOF, error = %d\n", GetLastError());
-            return -1;
-        }
-    } else if (SetFilePointer(handle, offset, NULL, FILE_BEGIN) == INVALID_SET_FILE_POINTER) {
-        DbgPrint("\tseek error, offset = %d, error = %d\n", offset, GetLastError());
-        return -1;
-    }
+    char *local_path, *fs_path;
+    int ret, err;
 
-        
-    if (!WriteFile(handle, Buffer, NumberOfBytesToWrite, NumberOfBytesWritten, NULL)) {
-        DbgPrint("\twrite error = %u, buffer length = %d, write length = %d\n",
-            GetLastError(), NumberOfBytesToWrite, *NumberOfBytesWritten);
-        return -1;
+    DbgPrint("WriteFile: %S\n", FileName);
+    DbgPrint("   Context: %llx\n", DokanFileInfo->Context);
 
-    } else {
-        DbgPrint("\twrite %d, offset %d\n\n", *NumberOfBytesWritten, offset);
+    /* convert from Unicode */
+    local_path = convert_string(FileName);
+    if (local_path == NULL)
+    {
+        return -ERROR_INVALID_DATA;
+    }
+
+    /* resolve the path */
+    fs_path = (char *) malloc(MAX_PATH);
+    MALLOC_CHECK(fs_path);
+    ret = fs_resolve_path(local_path, fs_path, MAX_PATH);
+    if (ret != 0)
+    {
+        free(local_path);
+        free(fs_path);
+        return -1;
+    }
+    
+    /* perform the read operation */
+    ret = fs_write(fs_path, (void *) Buffer, NumberOfBytesToWrite, Offset, 
+                   (size_t *) NumberOfBytesWritten);
+
+    DbgPrint("   fs_write returns %d\n", ret);
+
+    switch (ret)
+    {
+    case 0: 
+        err = 0;
+        break;
+    default:
+        err = -1;
     }
 
-    // close the file when it is reopened
-    if (opened)
-        CloseHandle(handle);
-
-    return 0;
+    return err;
 }
 
 
 static int
 PVFS2_Dokan_flush_file_buffers(
-    LPCWSTR        FileName,
-    PDOKAN_FILE_INFO    DokanFileInfo)
+    LPCWSTR          FileName,
+    PDOKAN_FILE_INFO DokanFileInfo)
 {
-    char    filePath[MAX_PATH];
-    HANDLE    handle = (HANDLE)DokanFileInfo->Context;
+    char *local_path, *fs_path;
+    int ret, err;
 
-    GetFilePath(filePath, FileName);
+    DbgPrint("FlushFileBuffers : %S\n", FileName);
+    DbgPrint("   Context: %llx\n", DokanFileInfo->Context);
 
-    DbgPrint("FlushFileBuffers : %s\n", filePath);
-
-    if (!handle || handle == INVALID_HANDLE_VALUE) {
-        DbgPrint("\tinvalid handle\n\n");
-        return 0;
+    /* convert from Unicode */
+    local_path = convert_string(FileName);
+    if (local_path == NULL)
+    {
+        return -ERROR_INVALID_DATA;
+    }
+
+    /* resolve the path */
+    fs_path = (char *) malloc(MAX_PATH);
+    MALLOC_CHECK(fs_path);
+    ret = fs_resolve_path(local_path, fs_path, MAX_PATH);
+    if (ret != 0)
+    {
+        free(local_path);
+        free(fs_path);
+        return -1;
     }
 
-    if (FlushFileBuffers(handle)) {
-        return 0;
-    } else {
-        DbgPrint("\tflush error code = %d\n", GetLastError());
-        return -1;
+    /* flush the file */
+    ret = fs_flush(fs_path);
+
+    DbgPrint("   fs_flush returns %d\n", ret);
+
+    switch (ret)
+    {
+    case 0: 
+        err = 0;
+        break;
+    default:
+        err = -1;
     }
 
+    free(fs_path);
+    free(local_path);
+
+    return err;
 }
 
 
 static int
 PVFS2_Dokan_get_file_information(
-    LPCWSTR                            FileName,
-    LPBY_HANDLE_FILE_INFORMATION    HandleFileInformation,
-    PDOKAN_FILE_INFO                DokanFileInfo)
+    LPCWSTR                      FileName,
+    LPBY_HANDLE_FILE_INFORMATION HandleFileInformation,
+    PDOKAN_FILE_INFO             DokanFileInfo)
 {
-    char    filePath[MAX_PATH];
-    HANDLE    handle = (HANDLE)DokanFileInfo->Context;
-    BOOL    opened = FALSE;
-
-    GetFilePath(filePath, FileName);
-
-    DbgPrint("GetFileInfo : %s\n", filePath);
-
-    if (!handle || handle == INVALID_HANDLE_VALUE) {
-        DbgPrint("\tinvalid handle\n\n");
-
-        // If CreateDirectory returned FILE_ALREADY_EXISTS and 
-        // it is called with FILE_OPEN_IF, that handle must be opened.
-        handle = CreateFile(filePath, 0, FILE_SHARE_READ, NULL, OPEN_EXISTING,
-            FILE_FLAG_BACKUP_SEMANTICS, NULL);
-        if (handle == INVALID_HANDLE_VALUE)
-            return -1;
-        opened = TRUE;
-    }
-
-    if (!GetFileInformationByHandle(handle,HandleFileInformation)) {
-        DbgPrint("\terror code = %d\n", GetLastError());
-
-        // FileName is a root directory
-        // in this case, FindFirstFile can't get directory information
-        if (wcslen(FileName) == 1) {
-            DbgPrint("  root dir\n");
-            HandleFileInformation->dwFileAttributes = GetFileAttributes(filePath);
-
-        } else {
-            WIN32_FIND_DATAW find;
-            ZeroMemory(&find, sizeof(WIN32_FIND_DATAW));
-            handle = FindFirstFile(filePath, &find);
-            if (handle == INVALID_HANDLE_VALUE) {
-                DbgPrint("\tFindFirstFile error code = %d\n\n", GetLastError());
-                return -1;
-            }
-            HandleFileInformation->dwFileAttributes = find.dwFileAttributes;
-            HandleFileInformation->ftCreationTime = find.ftCreationTime;
-            HandleFileInformation->ftLastAccessTime = find.ftLastAccessTime;
-            HandleFileInformation->ftLastWriteTime = find.ftLastWriteTime;
-            HandleFileInformation->nFileSizeHigh = find.nFileSizeHigh;
-            HandleFileInformation->nFileSizeLow = find.nFileSizeLow;
-            DbgPrint("\tFindFiles OK, file size = %d\n", find.nFileSizeLow);
-            FindClose(handle);
-        }
-    } else {
-        DbgPrint("\tGetFileInformationByHandle success, file size = %d\n",
-            HandleFileInformation->nFileSizeLow);
+    char *local_path, *fs_path;
+    int ret, err;
+    PVFS_sys_attr attr;
+
+    DbgPrint("GetFileInfo : %S\n", FileName);
+    DbgPrint("   Context: %llx\n", DokanFileInfo->Context);
+
+    /* convert from Unicode */
+    local_path = convert_string(FileName);
+    if (local_path == NULL)
+    {
+        return -ERROR_INVALID_DATA;
+    }
+
+    /* resolve the path */
+    fs_path = (char *) malloc(MAX_PATH);
+    MALLOC_CHECK(fs_path);
+    ret = fs_resolve_path(local_path, fs_path, MAX_PATH);
+    if (ret != 0)
+    {
+        free(local_path);
+        free(fs_path);
+        return -1;
     }
 
+    ret = fs_getattr(fs_path, &attr);
+
+    HandleFileInformation->dwFileAttributes = find.dwFileAttributes;
+    HandleFileInformation->ftCreationTime = find.ftCreationTime;
+    HandleFileInformation->ftLastAccessTime = find.ftLastAccessTime;
+    HandleFileInformation->ftLastWriteTime = find.ftLastWriteTime;
+    HandleFileInformation->nFileSizeHigh = find.nFileSizeHigh;
+    HandleFileInformation->nFileSizeLow = find.nFileSizeLow;
+        
     DbgPrint("\n");
 
-    if (opened) {
-        CloseHandle(handle);
-    }
 
     return 0;
 }

Index: fs.c
===================================================================
RCS file: /projects/cvsroot/pvfs2/src/client/windows/client-service/Attic/fs.c,v
diff -p -u -r1.1.2.5 -r1.1.2.6
--- fs.c	13 Dec 2010 22:31:33 -0000	1.1.2.5
+++ fs.c	14 Dec 2010 22:58:04 -0000	1.1.2.6
@@ -376,6 +376,8 @@ int fs_io(PVFS_io_type io_type,
     PVFS_sys_mntent *mntent = fs_get_mntent(0);
     PVFS_sysresp_lookup resp_lookup;
     PVFS_object_ref object_ref;
+    PVFS_Request file_req, mem_req;
+    PVFS_sysresp_io resp_io;
     int ret;
 
     if (fs_path == NULL || strlen(fs_path) == 0 ||
@@ -392,18 +394,32 @@ int fs_io(PVFS_io_type io_type,
     object_ref.fs_id = resp_lookup.ref.fs_id;
     object_ref.handle = resp_lookup.ref.handle;
 
+    /* get memory buffer */
+    file_req = PVFS_BYTE;
+
+    ret = PVFS_Request_contiguous(buffer_len, PVFS_BYTE, &(mem_req));
+    if (ret != 0)
+        goto fs_io_exit;
 
+    /* perform io operation */
+    ret = PVFS_sys_io(object_ref, file_req, offset, buffer, mem_req,
+                      &credentials, &resp_io, io_type, NULL);
+    if (ret == 0 && op_len != NULL)
+    {
+        *op_len = resp_io.total_completed;
+    }
 
-fs_io_exit:
+    PVFS_Request_free(&mem_req);
 
+fs_io_exit:
 
-    return 0;
+    return ret;
 }
 
 int fs_read(char *fs_path, 
             void *buffer,
             size_t buffer_len,
-            uint64_t offset,
+            PVFS_offset offset,
             size_t *read_len)
 {
     return fs_io(PVFS_IO_READ, fs_path, buffer, buffer_len, offset, read_len);
@@ -412,10 +428,33 @@ int fs_read(char *fs_path, 
 int fs_write(char *fs_path,
              void *buffer,
              size_t buffer_len,
-             uint64_t offset,
+             PVFS_offset offset,
              size_t *write_len)
 {
     return fs_io(PVFS_IO_WRITE, fs_path, buffer, buffer_len, offset, write_len);
+}
+
+int fs_flush(char *fs_path)
+{
+    struct PVFS_sys_mntent *mntent = fs_get_mntent(0);
+    int ret;
+    PVFS_sysresp_lookup resp_lookup;
+
+    if (fs_path == NULL || strlen(fs_path) == 0)
+        return -PVFS_EINVAL;
+
+    /* lookup file */
+    ret = PVFS_sys_lookup(mntent->fs_id, fs_path, &credentials, &resp_lookup,
+                          TRUE, NULL);
+    if (ret != 0)
+        goto fs_flush_exit;
+
+    /* flush file */
+    ret = PVFS_sys_flush(resp_lookup.ref, &credentials, NULL);
+
+fs_flush_exit:
+
+    return ret;
 }
 
 int fs_finalize()

Index: fs.h
===================================================================
RCS file: /projects/cvsroot/pvfs2/src/client/windows/client-service/Attic/fs.h,v
diff -p -u -r1.1.2.2 -r1.1.2.3
--- fs.h	13 Dec 2010 22:31:33 -0000	1.1.2.2
+++ fs.h	14 Dec 2010 22:58:04 -0000	1.1.2.3
@@ -34,15 +34,17 @@ int fs_mkdir(char *fs_path,
 int fs_read(char *fs_path, 
             void *buffer,
             size_t buffer_len,
-            uint64_t offset,
+            PVFS_offset offset,
             size_t *read_len);
 
 int fs_write(char *fs_path,
              void *buffer,
              size_t buffer_len,
-             uint64_t offset,
+             PVFS_offset offset,
              size_t *write_len);
 
+int fs_flush(char *fs_path);
+             
 int fs_finalize();
 
 #endif



More information about the Pvfs2-cvs mailing list