[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
Wed Dec 15 17:54:49 EST 2010


Update of /projects/cvsroot/pvfs2/src/client/windows/client-service
In directory parlweb1:/tmp/cvs-serv6002/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.6 -r1.1.2.7
--- dokan-interface.c	14 Dec 2010 22:58:04 -0000	1.1.2.6
+++ dokan-interface.c	15 Dec 2010 22:54:49 -0000	1.1.2.7
@@ -7,6 +7,7 @@
 /* TODO: needed? #include <fileinfo.h> */
 
 #include "pvfs2.h"
+#include "str-utils.h"
 #include "fs.h"
 
 BOOL g_UseStdErr;
@@ -89,6 +90,17 @@ static char *convert_string(const wchar_
 
 }
 
+/* convert PVFS time to Windows FILETIME 
+   (from MSDN Knowledgebase) */
+void convert_time(time_t t, LPFILETIME pft)
+{
+    LONGLONG ll;
+
+    ll = Int32x32To64(t, 10000000) + 116444736000000000;
+    pft->dwLowDateTime = (DWORD) ll;
+    pft->dwHighDateTime = ll >> 32;
+}
+
 #define cleanup_string(str)    free(str)
 
 static int
@@ -638,9 +650,10 @@ PVFS2_Dokan_get_file_information(
     LPBY_HANDLE_FILE_INFORMATION HandleFileInformation,
     PDOKAN_FILE_INFO             DokanFileInfo)
 {
-    char *local_path, *fs_path;
+    char *local_path, *fs_path, *filename;
     int ret, err;
     PVFS_sys_attr attr;
+    bool attr_set = FALSE;    
 
     DbgPrint("GetFileInfo : %S\n", FileName);
     DbgPrint("   Context: %llx\n", DokanFileInfo->Context);
@@ -663,39 +676,98 @@ PVFS2_Dokan_get_file_information(
         return -1;
     }
 
+    /* get file attributes */
     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;
+    if (ret == 0)
+    {
+        /* convert to Windows attributes */
+        HandleFileInformation->dwFileAttributes = 0;
+        if (attr.objtype & PVFS_TYPE_DIRECTORY) 
+            HandleFileInformation->dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY;
+
+        /* check for hidden file */
+        filename = (char *) malloc(strlen(fs_path) + 1);
+        MALLOC_CHECK(filename);
+        ret = PINT_remove_base_dir(fs_path, filename, strlen(fs_path) + 1);
+        if (ret == 0 && filename[0] == '.')
+            HandleFileInformation->dwFileAttributes |= FILE_ATTRIBUTE_HIDDEN;
+        free(filename);
+        ret = 0;
         
-    DbgPrint("\n");
+        /* TODO
+           Check perms for READONLY */
+        
+        /* check for temporary file */
+        if (DokanFileInfo->DeleteOnClose)
+            HandleFileInformation->dwFileAttributes |= FILE_ATTRIBUTE_TEMPORARY;
+
+        /* normal file */
+        if (HandleFileInformation->dwFileAttributes == 0)
+            HandleFileInformation->dwFileAttributes = FILE_ATTRIBUTE_NORMAL;
+        
+        /* file times */
+        convert_time(attr.ctime, &HandleFileInformation->ftCreationTime);
+        convert_time(attr.atime, &HandleFileInformation->ftLastAccessTime);
+        convert_time(attr.mtime, &HandleFileInformation->ftLastWriteTime);
+
+        /* file size */
+        HandleFileInformation->nFileSizeHigh = (attr.size & 0x7FFFFFFF00000000LL) >> 32;
+        HandleFileInformation->nFileSizeLow = (attr.size & 0xFFFFFFFFLL);
+
+    }    
+    
+    switch (ret)
+    {
+    case 0: 
+        err = 0;
+        break;
+    default:
+        err = -1;
+    }
 
+    cleanup_string(local_path);
+    free(fs_path);
 
-    return 0;
+    DbgPrint("   fs_getattr returns %d\n", ret);
+
+    return err;
 }
 
 
 static int
 PVFS2_Dokan_find_files(
-    LPCWSTR                FileName,
-    PFillFindData        FillFindData, // function pointer
-    PDOKAN_FILE_INFO    DokanFileInfo)
-{
-    char                filePath[MAX_PATH];
-    HANDLE                hFind;
-    WIN32_FIND_DATAW    findData;
-    DWORD                error;
-    char                yenStar = "\\*";
-    int count = 0;
+    LPCWSTR          FileName,
+    PFillFindData    FillFindData, // function pointer
+    PDOKAN_FILE_INFO DokanFileInfo)
+{
+    char *local_path, *fs_path, *filename;
+    int ret, err;
+    PVFS_sys_attr attr;
+    bool attr_set = FALSE;    
+
+    DbgPrint("FindFiles : %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;
+    }
 
-    GetFilePath(filePath, FileName);
 
-    wcscat(filePath, yenStar);
-    DbgPrint("FindFiles :%s\n", filePath);
 
     hFind = FindFirstFile(filePath, &findData);
 

Index: fs.c
===================================================================
RCS file: /projects/cvsroot/pvfs2/src/client/windows/client-service/Attic/fs.c,v
diff -p -u -r1.1.2.6 -r1.1.2.7
--- fs.c	14 Dec 2010 22:58:04 -0000	1.1.2.6
+++ fs.c	15 Dec 2010 22:54:49 -0000	1.1.2.7
@@ -395,9 +395,9 @@ int fs_io(PVFS_io_type io_type,
     object_ref.handle = resp_lookup.ref.handle;
 
     /* get memory buffer */
-    file_req = PVFS_BYTE;
-
-    ret = PVFS_Request_contiguous(buffer_len, PVFS_BYTE, &(mem_req));
+    file_req = PVFS_BYTE;
+
+    ret = PVFS_Request_contiguous(buffer_len, PVFS_BYTE, &(mem_req));
     if (ret != 0)
         goto fs_io_exit;
 
@@ -416,23 +416,18 @@ fs_io_exit:
     return ret;
 }
 
-int fs_read(char *fs_path, 
-            void *buffer,
-            size_t buffer_len,
-            PVFS_offset offset,
-            size_t *read_len)
-{
-    return fs_io(PVFS_IO_READ, fs_path, buffer, buffer_len, offset, read_len);
-}
+#define fs_read(fs_path, \
+                buffer, \
+                buffer_len, \
+                offset, \
+                read_len)  fs_io(PVFS_IO_READ, fs_path, buffer, buffer_len, offset, read_len)
 
-int fs_write(char *fs_path,
-             void *buffer,
-             size_t buffer_len,
-             PVFS_offset offset,
-             size_t *write_len)
-{
-    return fs_io(PVFS_IO_WRITE, fs_path, buffer, buffer_len, offset, write_len);
-}
+
+#define fs_write(fs_path, \
+                 buffer, \
+                 buffer_len, \
+                 offset, \
+                 write_len)  fs_io(PVFS_IO_WRITE, fs_path, buffer, buffer_len, offset, write_len)
 
 int fs_flush(char *fs_path)
 {
@@ -453,6 +448,66 @@ int fs_flush(char *fs_path)
     ret = PVFS_sys_flush(resp_lookup.ref, &credentials, NULL);
 
 fs_flush_exit:
+
+    return ret;
+}
+
+int fs_read_first_file(char *fs_path,
+                       PVFS_ds_position *token,
+                       char *filename,
+                       size_t max_name_len)
+{
+    if (token == NULL)
+    {
+        return -PVFS_EINVAL;
+    }
+
+   *token = PVFS_READDIR_START;
+   return fs_read_next_file(fs_path, token, filename, max_name_len);
+}
+
+int fs_read_next_file(char *fs_path, 
+                      PVFS_ds_position *token,
+                      char *filename,
+                      size_t max_name_len)
+{
+    int ret;
+
+    struct PVFS_sys_mntent *mntent = fs_get_mntent(0);
+    int ret;
+    PVFS_sysresp_lookup resp_lookup;
+    PVFS_sysresp_readdir resp_readdir;
+
+    if (fs_path == NULL || strlen(fs_path) == 0 ||
+        token == NULL || filename == NULL || max_name_len == 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_readdir_exit;
+
+    /* read one entry, starting with token */
+    ret = PVFS_sys_readdir(resp_lookup.ref, *token, 1, &credentials, 
+                           &resp_readdir, NULL);
+    if (ret != 0)
+        goto fs_readdir_exit;
+
+    /* copy output results */
+    if (resp_readdir.pvfs_dirent_outcount != 0)
+    {
+        *token = resp_readdir.token;
+        
+        strncpy(filename, resp_readdir.dirent_array[0].d_name, max_name_len);
+    }
+    else
+    {
+        /* return empty string on end */
+        filename[0] = '\0';
+    }
+
+fs_readdir_exit:
 
     return ret;
 }

Index: fs.h
===================================================================
RCS file: /projects/cvsroot/pvfs2/src/client/windows/client-service/Attic/fs.h,v
diff -p -u -r1.1.2.3 -r1.1.2.4
--- fs.h	14 Dec 2010 22:58:04 -0000	1.1.2.3
+++ fs.h	15 Dec 2010 22:54:49 -0000	1.1.2.4
@@ -44,7 +44,17 @@ int fs_write(char *fs_path,
              size_t *write_len);
 
 int fs_flush(char *fs_path);
-             
+
+int fs_read_first_file(char *fs_path,
+                       PVFS_ds_position *token,
+                       char *filename,
+                       size_t max_name_len);
+
+int fs_read_next_file(char *fs_path, 
+                      PVFS_ds_position *token,
+                      char *filename,
+                      size_t max_name_len);
+
 int fs_finalize();
 
 #endif



More information about the Pvfs2-cvs mailing list