unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: KAction@gnu.org
To: guile-devel@gnu.org
Cc: Dmitry Bogatov <KAction@gnu.org>
Subject: [PATCH 25/25] ice9/attr: implement xattr-list procedure
Date: Mon, 18 Jul 2016 18:17:48 +0300	[thread overview]
Message-ID: <1468855068-7029-26-git-send-email-KAction@gnu.org> (raw)
In-Reply-To: <1468855068-7029-1-git-send-email-KAction@gnu.org>

From: Dmitry Bogatov <KAction@gnu.org>

---
 module/ice-9/xattr.scm | 43 ++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 42 insertions(+), 1 deletion(-)

diff --git a/module/ice-9/xattr.scm b/module/ice-9/xattr.scm
index 5374901..6773126 100644
--- a/module/ice-9/xattr.scm
+++ b/module/ice-9/xattr.scm
@@ -20,8 +20,13 @@
   #:use-module (system foreign)
   #:use-module (ice-9 iconv)
   #:use-module (ice-9 receive)
+  #:use-module (ice-9 q)
+  #:use-module (srfi srfi-1)
+  #:use-module (srfi srfi-26)
   #:export (xattr-set)
-  #:export (xattr-get))
+  #:export (xattr-get)
+  #:export (xattr-remove)
+  #:export (xattr-list))
 
 (define *libattr* (dynamic-link "libattr"))
 
@@ -120,3 +125,39 @@
             (unless (eqv? ENODATA (system-error-errno _args))
               (xattr-get/syserror))
             #f)))))
+
+(define-libattr-functions remove (string: attrname) (xattr-flags: flags))
+(define* (xattr-remove file attrname #:optional (flags '()))
+  (unless (zero? (libattr-remove file attrname flags))
+    (c-scm-syserror "xattr-remove")))
+
+(define-libattr-functions list
+  (*: buffer) (int: buffersize) (xattr-flags: flags) (*: cursor))
+
+(define (pointer-advance p bytes)
+  (make-pointer (+ (pointer-address p) bytes)))
+
+(define (int32-ref p offset)
+  (let* ((offset-bytes (* 4 offset))
+         (pointer      (pointer-advance p offset-bytes)))
+    (car (parse-c-struct pointer (list int32)))))
+
+(define* (xattr-list file #:optional (flags '()))
+  (define attr-queue (make-q))
+  (define buffer-size (* 64 1024 1024)) ; 64Kb, see list_attr(3)
+  ;; attr/attributes.h: struct attrlist_cursor { u_int32_t opaque[4]; }
+  (with-pointer ((cursor *--> 16)
+                 (buffer *--> buffer-size))
+      (let loop ()
+        (unless (zero? (libattr-list file buffer buffer-size flags cursor))
+          (c-scm-syserror "xattr-list"))
+        (let* ((count      (int32-ref buffer 0))
+               (more?      (not (zero? (int32-ref buffer 1))))
+               (offsets    (map (cut int32-ref buffer <>) (iota count 2)))
+               (offsets*   (map (cut + 4 <>) offsets)) ; skip attribute length
+               (pointers   (map (cut pointer-advance buffer <>) offsets*))
+               (attributes (map pointer->string pointers)))
+          (for-each (cut enq! attr-queue <>) attributes)
+          (when more?
+            (loop))))
+    (car attr-queue)))
-- 
I may be not subscribed. Please, keep me in carbon copy.




  parent reply	other threads:[~2016-07-18 15:17 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-18 15:17 Foreign-declarative module KAction
2016-07-18 15:17 ` [PATCH 01/25] New module: system/foreign/declarative.scm KAction
2016-07-18 15:17 ` [PATCH 02/25] Define <ffi-type> structure KAction
2016-07-18 17:41   ` Nala Ginrut
2016-07-18 17:59     ` Dmitry Bogatov
2017-03-10  4:46       ` Thien-Thi Nguyen
2017-03-12  6:00         ` Dmitry Bogatov
2016-07-18 15:17 ` [PATCH 03/25] Mirror types from system/foreign as <foreign-type> KAction
2016-07-18 15:17 ` [PATCH 04/25] Write boilerplate for primitive types KAction
2016-07-18 15:17 ` [PATCH 05/25] Fix bug in `default' macro KAction
2016-07-18 15:17 ` [PATCH 06/25] Basic implementation of `define-foreign-function' KAction
2016-07-18 15:17 ` [PATCH 07/25] Introduce foreign-type predicates KAction
2016-07-18 15:17 ` [PATCH 08/25] Add keywords for `define-foreign-function' macro KAction
2016-07-18 15:17 ` [PATCH 09/25] system/foreign/declarative: rename `predicate' to `validate' KAction
2016-07-18 15:17 ` [PATCH 10/25] Refactor type validation in `define-foreign-function' KAction
2016-07-18 15:17 ` [PATCH 11/25] system/foreign/declarative: new macro KAction
2016-07-18 15:17 ` [PATCH 12/25] Improve deriving c symbol name from scheme one KAction
2016-07-18 15:17 ` [PATCH 13/25] system/foreign/declarative.scm: export string foreign type KAction
2016-07-18 15:17 ` [PATCH 14/25] foreign/declarative: mirror more primitive types KAction
2016-07-18 15:17 ` [PATCH 15/25] New macro: with-pointer KAction
2016-07-18 15:17 ` [PATCH 16/25] Configure emacs file-local indention KAction
2016-07-18 15:17 ` [PATCH 17/25] system/foreign/declarative: unexport internal macro KAction
2016-07-18 15:17 ` [PATCH 18/25] write documentation for (system foreign declarative) KAction
2016-07-18 19:41   ` Amirouche Boubekki
2016-07-18 20:11     ` Dmitry Bogatov
2016-07-19 14:41       ` Taylan Ulrich Bayırlı/Kammer
2016-07-19 15:12         ` Dmitry Bogatov
2016-07-18 15:17 ` [PATCH 19/25] Document define-foreign-bitmask macro KAction
2016-07-18 15:17 ` [PATCH 20/25] Document with-pointer macro KAction
2016-07-18 15:17 ` [PATCH 21/25] new module: (ice-9 xattr) KAction
2016-07-18 15:17 ` [PATCH 22/25] ice-9/xattr: implement `xattr-get' function KAction
2016-07-18 15:17 ` [PATCH 23/25] Do not throw exception on missing xattr KAction
2016-07-18 15:17 ` [PATCH 24/25] Refactor defining foreign libattr function KAction
2016-07-18 15:17 ` KAction [this message]
2017-03-09 20:33   ` [PATCH 25/25] ice9/attr: implement xattr-list procedure Andy Wingo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1468855068-7029-26-git-send-email-KAction@gnu.org \
    --to=kaction@gnu.org \
    --cc=guile-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).