40 #include <sys/types.h> 
   43 #include <sys/ioctl.h> 
   52 "Usage: cuse_client FIOC_FILE COMMAND\n" 
   55 "  s [SIZE]     : get size if SIZE is omitted, set size otherwise\n" 
   56 "  r SIZE [OFF] : read SIZE bytes @ OFF (dfl 0) and output to stdout\n" 
   57 "  w SIZE [OFF] : write SIZE bytes @ OFF (dfl 0) from stdin\n" 
   60 static int do_rw(
int fd, 
int is_read, 
size_t size, off_t offset,
 
   61                  size_t *prev_size, 
size_t *new_size)
 
   63         struct fioc_rw_arg arg = { .offset = offset };
 
   66         arg.buf = calloc(1, size);
 
   68                 fprintf(stderr, 
"failed to allocated %zu bytes\n", size);
 
   74                 ret = ioctl(fd, FIOC_READ, &arg);
 
   76                         fwrite(arg.buf, 1, ret, stdout);
 
   78                 arg.size = fread(arg.buf, 1, size, stdin);
 
   79                 fprintf(stderr, 
"Writing %zu bytes\n", arg.size);
 
   80                 ret = ioctl(fd, FIOC_WRITE, &arg);
 
   84                 *prev_size = arg.prev_size;
 
   85                 *new_size = arg.new_size;
 
   93 int main(
int argc, 
char **argv)
 
   95         size_t param[2] = { };
 
   96         size_t size, prev_size = 0, new_size = 0;
 
  103         fd = open(argv[1], O_RDWR);
 
  109         cmd = tolower(argv[2][0]);
 
  113         for (i = 0; i < argc; i++) {
 
  115                 param[i] = strtoul(argv[i], &endp, 0);
 
  116                 if (endp == argv[i] || *endp != 
'\0')
 
  123                         if (ioctl(fd, FIOC_GET_SIZE, &size)) {
 
  127                         printf(
"%zu\n", size);
 
  130                         if (ioctl(fd, FIOC_SET_SIZE, &size)) {
 
  140                 rc = do_rw(fd, cmd == 
'r', param[0], param[1],
 
  141                            &prev_size, &new_size);
 
  144                 fprintf(stderr, 
"transferred %d bytes (%zu -> %zu)\n",
 
  145                         rc, prev_size, new_size);
 
  151         fprintf(stderr, 
"%s", usage);