help-smalltalk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-smalltalk] [PATCH] kernel: Add primitives for link, fsync, fdatasy


From: Holger Hans Peter Freyther
Subject: [Help-smalltalk] [PATCH] kernel: Add primitives for link, fsync, fdatasync and sync and expose them
Date: Fri, 9 Aug 2013 19:06:10 +0200

2013-08-09  Holger Hans Peter Freyther  <address@hidden>

        * kernel/FilePath.st: Add FilePath>>#linkAs: and FilePath>>#linkFrom:
        selectors.
        * kernel/File.st: Add File class>>#sync, File class>>#primFsync:,
        File class>>#primFdatasync, File class>>#link:as:, File 
class>>#link:from:,
        File>>#primLink:as:, File>>#linkFrom:, File>>#linkAs: selectors.
        * kernel/FileDescr.st: Add >>#fsync and >>#fdatasync selectors.
        * kernel/FileStream.st: Override >>#fsync and >>#fdatasync selectors.

2013-08-09  Holger Hans Peter Freyther  <address@hidden>

        * libgst/cint.c: Bind link, fsync, fdatasync and sync for
        additional C level access.
---
 ChangeLog            | 10 ++++++++++
 configure.ac         |  2 +-
 kernel/File.st       | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 kernel/FileDescr.st  | 11 +++++++++++
 kernel/FilePath.st   | 13 +++++++++++++
 kernel/FileStream.st | 12 ++++++++++++
 libgst/ChangeLog     |  5 +++++
 libgst/cint.c        |  8 ++++++++
 8 files changed, 112 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 3c2a4f5..8a52ed2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2013-08-09  Holger Hans Peter Freyther  <address@hidden>
+
+       * kernel/FilePath.st: Add FilePath>>#linkAs: and FilePath>>#linkFrom:
+       selectors.
+       * kernel/File.st: Add File class>>#sync, File class>>#primFsync:,
+       File class>>#primFdatasync, File class>>#link:as:, File 
class>>#link:from:,
+       File>>#primLink:as:, File>>#linkFrom:, File>>#linkAs: selectors.
+       * kernel/FileDescr.st: Add >>#fsync and >>#fdatasync selectors.
+       * kernel/FileStream.st: Override >>#fsync and >>#fdatasync selectors.
+
 2013-07-01  Gwenael Casaccio <address@hidden>
 
         * kernel/DirPackage.st: Return the loaded package.
diff --git a/configure.ac b/configure.ac
index 56c09cb..bb48016 100644
--- a/configure.ac
+++ b/configure.ac
@@ -359,7 +359,7 @@ AC_REPLACE_FUNCS(putenv strdup strerror strsignal mkstemp 
getpagesize \
         lrint trunc strsep strpbrk symlink mkdtemp)
 AC_CHECK_FUNCS_ONCE(gethostname memcpy memmove sighold uname usleep lstat \
        grantpt popen getrusage gettimeofday fork strchr utimes utime readlink \
-       sigsetmask alarm select mprotect madvise waitpid accept4 \
+       sigsetmask alarm select mprotect madvise waitpid accept4 fdatasync \
        setsid spawnl pread pwrite _NSGetExecutablePath _NSGetEnviron \
        chown getgrnam getpwnam endgrent endpwent setgroupent setpassent)
 
diff --git a/kernel/File.st b/kernel/File.st
index 426a415..fa34763 100644
--- a/kernel/File.st
+++ b/kernel/File.st
@@ -119,6 +119,20 @@ FilePath subclass: File [
        (self path: fileName) touch
     ]
 
+    File class >> link: srcName as: destName [
+        "Create a hard link for the srcName file with the given path name"
+
+        <category: 'file operations'>
+        (self path: srcName) linkAs: destName
+    ]
+
+    File class >> link: destName from: srcName [
+        "Create a hard link named destName file from the given path"
+
+        <category: 'file operations'>
+        (self path: destName) linkFrom: srcName
+    ]
+
     File class >> symlink: srcName as: destName [
        "Create a symlink for the srcName file with the given path name"
 
@@ -197,6 +211,24 @@ FilePath subclass: File [
        ^self path: ImageFileName
     ]
 
+    File class >> primFsync: aFd [
+        <category: 'private-C call-outs'>
+        <cCall: 'fsync' returning: #int args: #(#int)>
+    ]
+
+    File class >> primFdatasync: aFd [
+        <category: 'private-C call-outs'>
+        "Depending on the version of the libc this might fail with a primitive
+        error. In that case primFsync should be called."
+        <cCall: 'fdatasync' returning: #int args: #(#int)>
+    ]
+
+    File class >> sync [
+        <category: 'C call-outs'>
+        "Blocking call to the kernel to sync all files to storage"
+        <cCall: 'sync' returning: #int args: #()>
+    ]
+
     = aFile [
        "Answer whether the receiver represents the same file as the receiver."
 
@@ -259,6 +291,11 @@ FilePath subclass: File [
        
     ]
 
+    primLink: srcName as: destName [
+        <category: 'private-C call-outs'>
+        <cCall: 'link' returning: #int args: #(#string #string)>
+    ]
+
     primSymlink: srcName as: destName [
        <category: 'private-C call-outs'>
        <cCall: 'symlink' returning: #int args: #(#string #string)>
@@ -526,6 +563,14 @@ FilePath subclass: File [
        result < 0 ifTrue: [ File checkError ]
     ]
 
+    linkFrom: srcName [
+        "Create the receiver as hard link from path destName"
+
+        <category: 'file operations'>
+        (self primLink: srcName as: self asString) < 0
+            ifTrue: [ File checkError ]
+    ]
+
     symlinkFrom: srcName [
        "Create the receiver as a symlink from path destName"
 
@@ -592,6 +637,13 @@ FilePath subclass: File [
        File checkError.
     ]
 
+    linkAs: destName [
+        "Create destName as a symbolic link of the receiver."
+
+        <category: 'file operations'>
+        (self class path: destName) linkFrom: self asString.
+    ]
+
     symlinkAs: destName [
        "Create destName as a symbolic link of the receiver.  The appropriate
         relative path is computed automatically."
diff --git a/kernel/FileDescr.st b/kernel/FileDescr.st
index 3dc8d01..2896d89 100644
--- a/kernel/FileDescr.st
+++ b/kernel/FileDescr.st
@@ -1104,5 +1104,16 @@ do arbitrary processing on the files.'>
        ^true
     ]
 
+    fsync [
+        <category: 'primitive'>
+        (File primFsync: fd) < 0
+            ifTrue: [self checkError]
+    ]
+
+    fdatasync [
+        <category: 'primitive'>
+        (File primFdatasync: fd) < 0
+            ifTrue: [self checkError]
+    ]
 ]
 
diff --git a/kernel/FilePath.st b/kernel/FilePath.st
index 8575c0b..84aae3e 100644
--- a/kernel/FilePath.st
+++ b/kernel/FilePath.st
@@ -688,6 +688,12 @@ size and timestamps.'>
        ^self open: FileStream write
     ]
 
+    linkAs: destName [
+        "Create destName as a hard link of the receiver."
+        <category: 'file operations'>
+        self subclassResponsibility
+    ]
+
     symlinkAs: destName [
        "Create destName as a symbolic link of the receiver.  The appropriate
         relative path is computed automatically."
@@ -703,6 +709,13 @@ size and timestamps.'>
        self subclassResponsibility
     ]
 
+    linkFrom: srcName [
+        "Create the receiver as a hard link from srcName."
+
+        <category: 'file operations'>
+        self subclassResponsibility
+    ]
+
     symlinkFrom: srcName [
        "Create the receiver as a symbolic link from srcName (relative to the
         path of the receiver)."
diff --git a/kernel/FileStream.st b/kernel/FileStream.st
index 1aa5635..780feff 100644
--- a/kernel/FileStream.st
+++ b/kernel/FileStream.st
@@ -659,6 +659,18 @@ file object, such as /dev/rmt0 on UNIX or MTA0: on VMS).'>
                            into: collection
                            startingAt: endPtr + 1)
     ]
+
+    fsync [
+        <category: 'primitive'>
+        self flush.
+        ^super fsync
+    ]
+
+    fdatasync [
+        <category: 'primitive'>
+        self flush.
+        ^super fdatasync
+    ]
 ]
 
 
diff --git a/libgst/ChangeLog b/libgst/ChangeLog
index 0fd6549..3392dd9 100644
--- a/libgst/ChangeLog
+++ b/libgst/ChangeLog
@@ -1,3 +1,8 @@
+2013-08-09  Holger Hans Peter Freyther  <address@hidden>
+
+       * libgst/cint.c: Bind link, fsync, fdatasync and sync for
+       additional C level access.
+
 2013-07-09  Gwenael Casaccio <address@hidden>
 
        * oop.c: Protect oop1 and oop2 in _gst_swap_objects.
diff --git a/libgst/cint.c b/libgst/cint.c
index 77c8f8c..9dd441e 100644
--- a/libgst/cint.c
+++ b/libgst/cint.c
@@ -641,6 +641,7 @@ _gst_init_cfuncs (void)
   _gst_define_cfunc ("rewinddir", rewinddir);
   _gst_define_cfunc ("extractDirentName", extract_dirent_name);
 
+  _gst_define_cfunc ("link", link);
   _gst_define_cfunc ("symlink", my_symlink);
   _gst_define_cfunc ("unlink", unlink);
   _gst_define_cfunc ("rename", rename);
@@ -649,6 +650,13 @@ _gst_init_cfuncs (void)
   _gst_define_cfunc ("mkdir", my_mkdir);
   _gst_define_cfunc ("mkdtemp", my_mkdtemp);
   _gst_define_cfunc ("getCurDirName", _gst_get_cur_dir_name);
+  _gst_define_cfunc ("fsync", fsync);
+#ifdef HAVE_FDATASYNC
+  _gst_define_cfunc ("fdatasync", fdatasync);
+#else
+  _gst_define_cfunc ("fdatasync", fsync);
+#endif
+  _gst_define_cfunc ("sync", sync);
 
   _gst_define_cfunc ("fileIsReadable", _gst_file_is_readable);
   _gst_define_cfunc ("fileIsWriteable", _gst_file_is_writeable);
-- 
1.8.3.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]