"Fossies" - the Fresh Open Source Software Archive

Member "fuse-3.2.1/example/printcap.c" (14 Nov 2017, 3335 Bytes) of package /linux/misc/fuse-3.2.1.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /*
    2   FUSE: Filesystem in Userspace
    3   Copyright (C) 2017 Nikolaus Rath <Nikolaus@rath.org>
    4 
    5   This program can be distributed under the terms of the GNU GPL.
    6   See the file COPYING.
    7 */
    8 
    9 /** @file
   10  *
   11  * minimal example filesystem that prints out all capabilities
   12  * supported by the kernel and then exits.
   13  *
   14  * Compile with:
   15  *
   16  *     gcc -Wall protocol_info.c `pkg-config fuse3 --cflags --libs` -o protocol_info
   17  *
   18  * ## Source code ##
   19  * \include @file
   20  */
   21 
   22 #define FUSE_USE_VERSION 31
   23 
   24 #include <config.h>
   25 
   26 #include <fuse_lowlevel.h>
   27 #include <stdio.h>
   28 #include <unistd.h>
   29 #include <string.h>
   30 #include <stdlib.h>
   31 
   32 struct fuse_session *se;
   33 
   34 static void pc_init(void *userdata,
   35             struct fuse_conn_info *conn)
   36 {
   37     (void) userdata;
   38     
   39     printf("Protocol version: %d.%d\n", conn->proto_major,
   40            conn->proto_minor);
   41     printf("Capabilities:\n");
   42     if(conn->capable & FUSE_CAP_WRITEBACK_CACHE)
   43         printf("\tFUSE_CAP_WRITEBACK_CACHE\n");
   44     if(conn->capable & FUSE_CAP_ASYNC_READ)
   45             printf("\tFUSE_CAP_ASYNC_READ\n");
   46     if(conn->capable & FUSE_CAP_POSIX_LOCKS)
   47             printf("\tFUSE_CAP_POSIX_LOCKS\n");
   48     if(conn->capable & FUSE_CAP_ATOMIC_O_TRUNC)
   49             printf("\tFUSE_CAP_ATOMIC_O_TRUNC\n");
   50     if(conn->capable & FUSE_CAP_EXPORT_SUPPORT)
   51             printf("\tFUSE_CAP_EXPORT_SUPPORT\n");
   52     if(conn->capable & FUSE_CAP_DONT_MASK)
   53             printf("\tFUSE_CAP_DONT_MASK\n");
   54     if(conn->capable & FUSE_CAP_SPLICE_MOVE)
   55             printf("\tFUSE_CAP_SPLICE_MOVE\n");
   56     if(conn->capable & FUSE_CAP_SPLICE_READ)
   57             printf("\tFUSE_CAP_SPLICE_READ\n");
   58     if(conn->capable & FUSE_CAP_SPLICE_WRITE)
   59             printf("\tFUSE_CAP_SPLICE_WRITE\n");
   60     if(conn->capable & FUSE_CAP_FLOCK_LOCKS)
   61             printf("\tFUSE_CAP_FLOCK_LOCKS\n");
   62     if(conn->capable & FUSE_CAP_IOCTL_DIR)
   63             printf("\tFUSE_CAP_IOCTL_DIR\n");
   64     if(conn->capable & FUSE_CAP_AUTO_INVAL_DATA)
   65             printf("\tFUSE_CAP_AUTO_INVAL_DATA\n");
   66     if(conn->capable & FUSE_CAP_READDIRPLUS)
   67             printf("\tFUSE_CAP_READDIRPLUS\n");
   68     if(conn->capable & FUSE_CAP_READDIRPLUS_AUTO)
   69             printf("\tFUSE_CAP_READDIRPLUS_AUTO\n");
   70     if(conn->capable & FUSE_CAP_ASYNC_DIO)
   71             printf("\tFUSE_CAP_ASYNC_DIO\n");
   72     if(conn->capable & FUSE_CAP_WRITEBACK_CACHE)
   73             printf("\tFUSE_CAP_WRITEBACK_CACHE\n");
   74     if(conn->capable & FUSE_CAP_NO_OPEN_SUPPORT)
   75             printf("\tFUSE_CAP_NO_OPEN_SUPPORT\n");
   76     if(conn->capable & FUSE_CAP_PARALLEL_DIROPS)
   77             printf("\tFUSE_CAP_PARALLEL_DIROPS\n");
   78     if(conn->capable & FUSE_CAP_POSIX_ACL)
   79             printf("\tFUSE_CAP_POSIX_ACL\n");
   80     fuse_session_exit(se);
   81 }
   82 
   83 
   84 static struct fuse_lowlevel_ops pc_oper = {
   85     .init       = pc_init,
   86 };
   87 
   88 int main(int argc, char **argv)
   89 {
   90     struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
   91     char *mountpoint;
   92     int ret = -1;
   93 
   94     mountpoint = strdup("/tmp/fuse_printcap_XXXXXX");
   95     if(mkdtemp(mountpoint) == NULL) {
   96         perror("mkdtemp");
   97         return 1;
   98     }
   99     
  100     printf("FUSE library version %s\n", fuse_pkgversion());
  101     fuse_lowlevel_version();
  102 
  103     se = fuse_session_new(&args, &pc_oper,
  104                   sizeof(pc_oper), NULL);
  105     if (se == NULL)
  106         goto err_out1;
  107 
  108     if (fuse_set_signal_handlers(se) != 0)
  109         goto err_out2;
  110 
  111     if (fuse_session_mount(se, mountpoint) != 0)
  112         goto err_out3;
  113 
  114     ret = fuse_session_loop(se);
  115 
  116     fuse_session_unmount(se);
  117 err_out3:
  118     fuse_remove_signal_handlers(se);
  119 err_out2:
  120     fuse_session_destroy(se);
  121 err_out1:
  122     rmdir(mountpoint);
  123     free(mountpoint);
  124     fuse_opt_free_args(&args);
  125 
  126     return ret ? 1 : 0;
  127 }