From 412466ca43b6d8b45a2786d107396467aa15242d Mon Sep 17 00:00:00 2001 From: Marco Schuster Date: Sat, 16 Feb 2013 17:12:57 +0100 Subject: [PATCH 1/7] add sample1.php from tutorial original url: http://labs.gree.jp/Top/OpenSource/Fuse/Document/Tutorial.html --- examples/example_1.php | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 examples/example_1.php diff --git a/examples/example_1.php b/examples/example_1.php new file mode 100644 index 0000000..5b0ce18 --- /dev/null +++ b/examples/example_1.php @@ -0,0 +1,7 @@ +mount("/tmp/phpfusemount", "allow_other"); +?> From 5a9898c80a7d1f7bb40bbe495f7e1b4949389ef2 Mon Sep 17 00:00:00 2001 From: Marco Schuster Date: Sat, 16 Feb 2013 17:14:29 +0100 Subject: [PATCH 2/7] added second example from docs --- examples/example_2.php | 56 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 examples/example_2.php diff --git a/examples/example_2.php b/examples/example_2.php new file mode 100644 index 0000000..cdfef56 --- /dev/null +++ b/examples/example_2.php @@ -0,0 +1,56 @@ + FUSE_DT_DIR); + $retval[".."] = array('type' => FUSE_DT_DIR); + $retval["test.txt"] = array('type' => FUSE_DT_REG); + return 0; + } + + public function getattr($path, &$st) { + $st['dev'] = 0; + $st['ino'] = 0; + $st['mode'] = 0; + $st['nlink'] = 0; + $st['uid'] = 0; + $st['gid'] = 0; + $st['rdev'] = 0; + $st['size'] = 0; + $st['atime'] = 0; + $st['mtime'] = 0; + $st['ctime'] = 0; + $st['blksize'] = 0; + $st['blocks'] = 0; + + if ($path == "/") { + $st['mode'] = FUSE_S_IFDIR | 0775; + $st['nlink'] = 3; + $st['size'] = 0; + } else if ($path == "/test.txt") { + $st['mode'] = FUSE_S_IFREG | 0664; + $st['nlink'] = 1; + $st['size'] = 12; + } + + return 0; + } + public function open($path, $mode) { + return 1; + } + + public function read($path, $fh, $offset, $buf_len, &$buf) { + $buf = "hello world\n"; + return strlen($buf); + } + + public function release($path, $fh) { + return 0; + } +} + +$fuse = new Sample2Fuse(); +$fuse->mount("/tmp/phpfusemount", "allow_other"); +?> From 1e2bf11dc04495acb44c7d37939507d3e073726b Mon Sep 17 00:00:00 2001 From: Marco Schuster Date: Sat, 16 Feb 2013 18:33:50 +0100 Subject: [PATCH 3/7] test for multiple options --- examples/example_2.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/example_2.php b/examples/example_2.php index cdfef56..c657146 100644 --- a/examples/example_2.php +++ b/examples/example_2.php @@ -52,5 +52,5 @@ public function release($path, $fh) { } $fuse = new Sample2Fuse(); -$fuse->mount("/tmp/phpfusemount", "allow_other"); +$fuse->mount("/tmp/phpfusemount", array("allow_other","debug","uid"=>"20000")); ?> From aa0670ea04abbb4ec4409cd96712f1b93ea71926 Mon Sep 17 00:00:00 2001 From: Marco Schuster Date: Sat, 16 Feb 2013 18:34:32 +0100 Subject: [PATCH 4/7] Fuse->mount now has 2nd parameter as array, but only dumps it for now --- fuse.c | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/fuse.c b/fuse.c index 91fa53d..71f650b 100644 --- a/fuse.c +++ b/fuse.c @@ -1556,30 +1556,42 @@ static PHP_METHOD(Fuse, mount) { const char *path = NULL; int path_len = 0; - const char *option = NULL; - int option_len = 0; + zval* optarray; //array of Fuse options + HashTable* opthash; //HashTable of the array + HashPosition optptr; //Pointer to the position in the array + int optsize; //Size of the options array - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &path, &path_len, &option, &option_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|a", &path, &path_len, &optarray) == FAILURE) { return; } FUSEG(active_object) = object; - // currently no mount options are supported:( int argc = 2; - if (option && option_len > 0) { - argc += 2; - } + opthash=Z_ARRVAL_P(optarray); + optsize=zend_hash_num_elements(opthash); + php_printf("Options array size %d\n",optsize); + char **argv = emalloc(sizeof(char*)*argc); char *p = estrdup(path); - char *q = estrdup(option); int i = 0; *(argv + i++) = "php_fuse"; - if (option && option_len > 0) { - *(argv + i++) = "-o"; - *(argv + i++) = q; + + //Now join argv with the user-supplied arguments + int j=-1; + zval** data; + for(zend_hash_internal_pointer_reset_ex(opthash, &optptr); zend_hash_get_current_data_ex(opthash, (void**) &data, &optptr) == SUCCESS; zend_hash_move_forward_ex(opthash, &optptr)) { + j++; + if (Z_TYPE_PP(data) != IS_STRING) { + zend_error(E_WARNING,"Fuse.mount: Option %d is not a string, but %d!",j,Z_TYPE_PP(data)); + continue; + } + php_printf("Read argument %d: ",j); + php_write(Z_STRVAL_PP(data),Z_STRLEN_PP(data)); + php_printf("\n"); } + *(argv + i++) = p; struct fuse_operations op; @@ -1653,9 +1665,11 @@ static PHP_METHOD(Fuse, mount) { add_property_string(object, "_mount_point", p, 1); + for(i=0; i < argc; i++) + php_printf("php_fuse argc[%d/%d]: %s\n",i+1,argc,argv[i]); + fuse_main(argc, argv, &op); - efree(q); efree(p); efree(argv); From abcbf897903e610429449bc914abd7ef68563114 Mon Sep 17 00:00:00 2001 From: Marco Schuster Date: Sat, 16 Feb 2013 19:26:22 +0100 Subject: [PATCH 5/7] removed clutter and finished the stuff. --- fuse.c | 50 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 37 insertions(+), 13 deletions(-) diff --git a/fuse.c b/fuse.c index 71f650b..4e22e75 100644 --- a/fuse.c +++ b/fuse.c @@ -1567,12 +1567,12 @@ static PHP_METHOD(Fuse, mount) { FUSEG(active_object) = object; - int argc = 2; opthash=Z_ARRVAL_P(optarray); optsize=zend_hash_num_elements(opthash); - php_printf("Options array size %d\n",optsize); - - char **argv = emalloc(sizeof(char*)*argc); + + int argc = 2+(2*optsize); //2 fixed elements (php_fuse,mountpoint), and optsize additional args and a "-o" per arg + char **argv = safe_emalloc(sizeof(char*),argc,0); + char **elements=safe_emalloc(sizeof(char*),optsize,0); //to store the converted $options entries char *p = estrdup(path); int i = 0; @@ -1583,13 +1583,36 @@ static PHP_METHOD(Fuse, mount) { zval** data; for(zend_hash_internal_pointer_reset_ex(opthash, &optptr); zend_hash_get_current_data_ex(opthash, (void**) &data, &optptr) == SUCCESS; zend_hash_move_forward_ex(opthash, &optptr)) { j++; - if (Z_TYPE_PP(data) != IS_STRING) { - zend_error(E_WARNING,"Fuse.mount: Option %d is not a string, but %d!",j,Z_TYPE_PP(data)); - continue; + char* key; + int key_len; + long index; + + //resulting element + char* element; + int elsize; + + int valtype=Z_TYPE_PP(data); + + if (Z_TYPE_PP(data) != IS_STRING) { //element is not a string, convert instead + zend_error(E_WARNING,"Fuse.mount: Option %d is not a string, but type %d instead. Converting silently.",j,Z_TYPE_PP(data)); + convert_to_string_ex(data); + } + if (zend_hash_get_current_key_ex(opthash, &key, &key_len, &index, 0, &optptr) == HASH_KEY_IS_STRING) { //string=>string + //string key => the end value must be key=value + elsize=key_len+1+Z_STRLEN_PP(data); //key_len+'='+data_len, for unknown reasons one of them includes a nullbyte?! + element=safe_emalloc(elsize,sizeof(char),0); + memset(element,0,elsize); + strncat(element,key,key_len); + strncat(element,"=",1); + strncat(element,Z_STRVAL_PP(data),Z_STRLEN_PP(data)); + + } else { //int (or resource, or whatever)=>string, only use the value + elsize=Z_STRLEN_PP(data); + element=estrdup(Z_STRVAL_PP(data)); } - php_printf("Read argument %d: ",j); - php_write(Z_STRVAL_PP(data),Z_STRLEN_PP(data)); - php_printf("\n"); + *(argv + i++)="-o"; + *(argv + i++)=element; + *(elements + j)=element; } *(argv + i++) = p; @@ -1665,13 +1688,14 @@ static PHP_METHOD(Fuse, mount) { add_property_string(object, "_mount_point", p, 1); - for(i=0; i < argc; i++) - php_printf("php_fuse argc[%d/%d]: %s\n",i+1,argc,argv[i]); - fuse_main(argc, argv, &op); efree(p); efree(argv); + + for(i=0;i Date: Sat, 16 Feb 2013 21:41:21 +0100 Subject: [PATCH 6/7] added ENOSYS to indicate not implemented function --- examples/example_3.php | 12 ++++++++++++ fuse.c | 1 + 2 files changed, 13 insertions(+) create mode 100644 examples/example_3.php diff --git a/examples/example_3.php b/examples/example_3.php new file mode 100644 index 0000000..220088f --- /dev/null +++ b/examples/example_3.php @@ -0,0 +1,12 @@ +mount("/tmp/phpfusemount", "debug"); +?> diff --git a/fuse.c b/fuse.c index 4e22e75..2fe4c7b 100644 --- a/fuse.c +++ b/fuse.c @@ -1928,6 +1928,7 @@ PHP_MINIT_FUNCTION(fuse) { REGISTER_LONG_CONSTANT("FUSE_EPIPE", EPIPE, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("FUSE_EDOM", EDOM, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("FUSE_ERANGE", ERANGE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("FUSE_ENOSYS", ENOSYS, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("FUSE_DT_UKNOWN", DT_UNKNOWN, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("FUSE_DT_REG", DT_REG, CONST_CS | CONST_PERSISTENT); From a88d046c088a37ce0a65a54c89d9dc608acc35be Mon Sep 17 00:00:00 2001 From: Marco Schuster Date: Sat, 16 Feb 2013 21:41:50 +0100 Subject: [PATCH 7/7] added example3 including all currently available php-fuse hooks --- examples/example_3.php | 140 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 135 insertions(+), 5 deletions(-) diff --git a/examples/example_3.php b/examples/example_3.php index 220088f..8682355 100644 --- a/examples/example_3.php +++ b/examples/example_3.php @@ -1,12 +1,142 @@ mount("/tmp/phpfusemount", "debug"); +echo "mounting\n"; +$fuse->mount("/tmp/phpfusemount", array("debug")); +echo "done\n"; ?>