+++ /dev/null
-;; lipe_scan3 common Scheme definitions
-(use-modules (rnrs bytevectors))
-(use-modules (ice-9 iconv)) ; bytevector->string
-;; (use-modules (ice-9 threads)) ; with-mutex
-
-(define S_IFMT #o0170000)
-(define S_IFDIR #o0040000)
-(define S_IFCHR #o0020000)
-(define S_IFBLK #o0060000)
-(define S_IFREG #o0100000)
-(define S_IFIFO #o0010000)
-(define S_IFLNK #o0120000)
-(define S_IFSOCK #o0140000)
-
-(define (perm)
- (logand (mode) #o07777))
-
-(define (type)
- (logand (mode) S_IFMT))
-
-(define (char->type c)
- (cond
- ((eq? c #\d) S_IFDIR)
- ((eq? c #\c) S_IFCHR)
- ((eq? c #\b) S_IFBLK)
- ((eq? c #\f) S_IFREG)
- ((eq? c #\p) S_IFIFO)
- ((eq? c #\l) S_IFLNK)
- ((eq? c #\s) S_IFSOCK)))
-
-(define (type->char t)
- (cond
- ((= t S_IFDIR) #\d)
- ((= t S_IFCHR) #\c)
- ((= t S_IFBLK) #\b)
- ((= t S_IFREG) #\f)
- ((= t S_IFIFO) #\p)
- ((= t S_IFLNK) #\l)
- ((= t S_IFSOCK) #\s)))
-
-;; fid
-;;
-;; Note: The struct type <fid>, constructor (make-fid), and slot accessors
-;; accessors (fid-{seq,oid,ver}), are defined in ls3_main.c.
-
-(set-struct-vtable-name! <fid> 'fid)
-
-;; (define-inlinable (%fid-printer x port)
-;; (format port "[0x~x:0x~x:0x~x]" (fid-seq x) (fid-oid x) (fid-ver x)))
-;;
-;; (struct-set! <fid> vtable-index-printer %fid-printer)
-
-(define-inlinable (%c-style-string->number s)
- (cond
- ((string-prefix? "0x" s)
- (string->number (substring s 2) 16))
- ((string-prefix? "0" s)
- (string->number s 8))
- (else
- (string->number s 10))))
-
-(define (fid? x)
- (and (struct? x)
- (eq? (struct-vtable x) <fid>)))
-
-(define (fid=? x1 x2)
- (and (= (fid-seq x1) (fid-seq x2))
- (= (fid-oid x1) (fid-oid x2))
- (= (fid-ver x1) (fid-ver x2))))
-
-(define (fid->string x)
- (%fid-printer x #f))
-
-(define (string->fid s)
- (apply make-fid
- (map %c-style-string->number
- (string-split (string-trim-right (string-trim s #\[)
- #\])
- #\:))))
-
-;; xattrs
-
-(define (xattr-ref-string name)
- (utf8->string (or (xattr-ref name) #vu8())))
#include "ls3_object_attrs.h"
#include "ls3_scan.h"
+#define LS3_MODULE_NAME "lipe"
#define LS3_SCAN "lipe-scan"
#define LS3_PRINT_FILE_FID "print-file-fid"
#define LS3_PRINT_SELF_FID "print-self-fid"
static bool print_null_delim;
static bool print_all_paths;
-#define X(s) SCM_GLOBAL_VARIABLE_INIT(ls3_ ## s, #s, scm_from_ulong(s))
+#define X(s) SCM_VARIABLE_INIT(ls3_ ## s, #s, scm_from_ulong(s))
X(LS3_OBJECT_ATTR_BASE);
X(LS3_OBJECT_ATTR_FILE_FID);
X(LS3_OBJECT_ATTR_FILTER_FID);
SCM_GLOBAL_SYMBOL(ls3_sym_scan_break, "*lipe-scan-break*");
SCM_GLOBAL_SYMBOL(ls3_sym_scan_continue, "*lipe-scan-continue*");
-SCM_GLOBAL_VARIABLE_INIT(ls3_scm_fid_vtable_var, "<fid>", ls3_scm_fid_vtable);
+SCM_VARIABLE_INIT(ls3_scm_fid_vtable_var, "<fid>", ls3_scm_fid_vtable);
#define LS3_SCM_FID(fid) \
((struct lu_fid *)SCM_STRUCT_DATA(fid))
return fid;
}
-#if 0
-static void ls3_scm_to_fid(SCM fid, struct lu_fid *c_fid)
-#define FUNC_NAME "ls3_scm_to_fid"
-{
- *c_fid = *LS3_SCM_UNPACK_FID(1, fid);
-}
-#undef FUNC_NAME
-#endif
-
static SCM ls3_scm_fid_printer(SCM x, SCM port)
#define FUNC_NAME "ls3_fid_printer"
{
}
#undef FUNC_NAME
-SCM_GLOBAL_VARIABLE_INIT(ls3_FNM_CASEFOLD, "FNM_CASEFOLD", scm_from_int(FNM_CASEFOLD));
+SCM_VARIABLE_INIT(ls3_FNM_CASEFOLD, "FNM_CASEFOLD", scm_from_int(FNM_CASEFOLD));
SCM_DEFINE(ls3_scm_fnmatch_p, "fnmatch?", 2, 1, 0,
(SCM pattern, SCM string, SCM flags), "match filename or pathname")
return SCM_UNSPECIFIED;
}
-#if 0
-SCM_GLOBAL_VARIABLE_INIT(ls3_scm_rmfid_max_fids, "%RMFID-MAX-FIDS",
- scm_from_ulong(OBD_MAX_FIDS_IN_ARRAY));
-
-SCM_DEFINE(ls3_scm_rmfid, "%rmfid", 1, 2, 0,
- (SCM vec, SCM start, SCM end), "remove a vector of FIDs")
-#define FUNC_NAME s_ls3_scm_rmfid
-{
- SCM res[2] = { SCM_UNDEFINED, SCM_UNDEFINED };
- SCM bv = SCM_UNDEFINED;
- struct fid_array *fa = NULL;
- size_t c_len;
- size_t c_start;
- size_t c_end;
- size_t c_count;
- size_t fa_size;
- size_t i;
- int rc;
-
- // Validate ls3_client_mount_fd
- SCM_VALIDATE_VECTOR(1, vec);
-
- c_len = scm_c_vector_length(vec);
-
- if (SCM_UNBNDP(start))
- c_start = 0;
- else
- c_start = scm_to_unsigned_integer(start, 0, c_len);
-
- if (SCM_UNBNDP(end))
- c_end = c_len;
- else
- c_end = scm_to_unsigned_integer(end, c_start, c_len);
-
- c_count = c_end - c_start;
-
- SCM_ASSERT_RANGE(1, scm_from_size_t(c_count), c_count <= OBD_MAX_FIDS_IN_ARRAY);
-
- fa_size = offsetof(struct fid_array, fa_fids[c_count]);
- LS3_DEBUG_U(c_len);
- LS3_DEBUG_U(c_start);
- LS3_DEBUG_U(c_end);
- LS3_DEBUG_U(c_count);
- LS3_DEBUG_U(fa_size);
-
- bv = scm_c_make_bytevector(fa_size);
- fa = (struct fid_array *)SCM_BYTEVECTOR_CONTENTS(bv);
- memset(fa, 0, fa_size);
-
- for (i = c_start; i < c_end; i++) {
- ls3_scm_to_fid(scm_c_vector_ref(vec, i),
- &fa->fa_fids[fa->fa_nr]);
- fa->fa_nr++;
- }
-
- assert(fa->fa_nr == c_count);
-
- rc = ioctl(ls3_client_mount_fd, LL_IOC_RMFID, fa);
- if (rc < 0) {
- res[0] = SCM_UNSPECIFIED;
- res[1] = scm_from_int(errno);
- return scm_c_values(res, ARRAY_SIZE(res));
- }
- LS3_DEBUG_D(rc);
-
- res[0] = scm_c_make_vector(fa->fa_nr, SCM_UNDEFINED);
- res[1] = scm_from_int(0);
-
- for (i = 0; i < fa->fa_nr; i++) {
- struct lu_fid *fid = &fa->fa_fids[i];
- __s32 rc2 = fid->f_ver;
-
- fid->f_ver = 0;
- SCM_SIMPLE_VECTOR_SET(res[0], i,
- scm_cons(ls3_scm_from_fid(fid),
- scm_from_int(-rc2)));
- }
-
- return scm_c_values(res, ARRAY_SIZE(res));
-}
-#undef FUNC_NAME
-#endif
-
SCM_DEFINE(ls3_scm_scan, LS3_SCAN, 5, 0, 0,
(SCM s_device_path,
SCM s_client_mount_path,
return scm_is_true(rc) ? EXIT_SUCCESS : EXIT_FAILURE;
}
-static void ls3_main_scm(void *data, int argc, char *argv[])
+static void ls3_scm_init(void *unused)
{
- bool interactive = false;
- const char *load_file;
- const char *script_file = NULL;
- const char *policy = NULL;
- char *end;
- int rc;
- int c;
-
- ls3_tid = syscall(SYS_gettid);
-
/* Need scm_c_eval_string("#t") here to prevent.
* Backtrace:
* In ice-9/boot-9.scm:
1, 0, 1,
&ls3_policy_exception_handler);
- /* Define our primitives before loading any files. */
#ifndef SCM_MAGIC_SNARFER
# include "ls3_main.x"
#endif
+ scm_c_export(
+ "FNM_CASEFOLD",
+ "fnmatch?",
+ "<fid>",
+ "fid-seq",
+ "fid-oid",
+ "fid-ver",
+ "make-fid",
+ "lipe-debug-enable",
+ "lipe-gettid",
+ "lipe-getopt-client-mount-path",
+ "lipe-getopt-device-path",
+ "lipe-getopt-required-attrs",
+ "lipe-getopt-thread-count",
+ "lipe-scan",
+ "lipe-scan-break",
+ "lipe-scan-client-mount-fd",
+ "lipe-scan-client-mount-path",
+ "lipe-scan-continue",
+ "lipe-scan-current-attrs",
+ "lipe-scan-device-name",
+ "lipe-scan-device-path",
+ "lipe-scan-fsname",
+ "lipe-scan-thread-count",
+ "lipe-scan-thread-index",
+ "atime",
+ "blocks",
+ "ctime",
+ "flags",
+ "gid",
+ "ino",
+ "mode",
+ "mtime",
+ "nlink",
+ "projid",
+ "size",
+ "uid",
+ "file-fid",
+ "self-fid",
+ "links",
+ "absolute-paths",
+ "relative-paths",
+ "xattrs",
+ "xattr-ref",
+ "pools",
+ "print-json",
+ "print-file-fid",
+ "print-self-fid",
+ "print-absolute-path",
+ "print-relative-path",
+ NULL);
+}
+
+static void ls3_main_scm(void *data, int argc, char *argv[])
+{
+ bool interactive = false;
+ const char *load_file;
+ const char *script_file = NULL;
+ const char *policy = NULL;
+ char *end;
+ int rc;
+ int c;
+
+ ls3_tid = syscall(SYS_gettid);
+
+ /* Define our primitives before loading any files. */
+ scm_c_define_module(LS3_MODULE_NAME, &ls3_scm_init, NULL);
+
while ((c = getopt_long(argc, argv, "hil:s:v", options, NULL)) != EOF) {
switch (c) {
case LS3_OPT_ALL_PATHS:
ls3_device_path = argv[i];
LS3_DEBUG_S(ls3_device_path);
-#define X(s) scm_variable_ref(scm_c_lookup(s))
+#define X(s) scm_c_public_ref(LS3_MODULE_NAME, s)
scan_rc = ls3_scm_scan(scm_call_0(X(LS3_GETOPT_DEVICE_PATH)),
scm_call_0(X(LS3_GETOPT_CLIENT_MOUNT_PATH)),
X(policy),
} else {
SCM script_rc;
+ scm_c_use_module(LS3_MODULE_NAME);
+
/* Forward positional parameters to script. */
scm_set_program_arguments(-1, argv + optind, (char *)script_file);
script_rc = scm_c_primitive_load(script_file);