Exemplo n.º 1
0
static int firefuse_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
                            off_t offset, struct fuse_file_info *fi)
{
    LOGTRACE1("firefuse_readdir(%s)", path);
    if (is_cv_path(path) ||
            is_cnc_path(path) ||
            0==strcmp(path, FIREREST_SYNC)) {
        return firerest_readdir(path, buf, filler, offset, fi);
    }

    (void) offset;
    (void) fi;

    LOGDEBUG1("firefuse_readdir(%s)", path);

    if (strcmp(path, "/") == 0) {
        filler(buf, ".", NULL, 0);
        filler(buf, "..", NULL, 0);
        filler(buf, STATUS_PATH + 1, NULL, 0);
        filler(buf, CONFIG_PATH + 1, NULL, 0);
        filler(buf, HOLES_PATH + 1, NULL, 0);
        filler(buf, FIRELOG_PATH + 1, NULL, 0);
        filler(buf, ECHO_PATH + 1, NULL, 0);
        filler(buf, FIRESTEP_PATH + 1, NULL, 0);
        filler(buf, FIREREST_CV + 1, NULL, 0);
        filler(buf, FIREREST_CNC + 1, NULL, 0);
        filler(buf, FIREREST_SYNC + 1, NULL, 0);
    } else {
        LOGERROR1("firefuse_readdir(%s) Unknown path", path);
        return -ENOENT;
    }

    return 0;
}
Exemplo n.º 2
0
int firefuse_write(const char *path, const char *buf, size_t bufsize, off_t offset, struct fuse_file_info *fi) {
  LOGTRACE1("firefuse_write(%s)", path);
  if (!buf) {
    LOGERROR1("firefuse_write %s -> null buffer", path);
    return EINVAL;
  }
  if (is_cv_path(path)) {
    return cve_write(path, buf, bufsize, offset, fi);
  } 
  if (offset) {
    LOGERROR2("firefuse_write %s -> non-zero offset:%ld", path, (long) offset);
    return EINVAL;
  } 
  if (is_cnc_path(path)) {
    return cnc_write(path, buf, bufsize, offset, fi);
  } 
  if (strcmp(path, ECHO_PATH) == 0) {
    if (bufsize > MAX_ECHO) {
      sprintf(echoBuf, "firefuse_write %s -> string too long (%ld > %d bytes)", path, bufsize, MAX_ECHO);
      LOGERROR1("%s", echoBuf);
      return EINVAL;
    }
    memcpy(echoBuf, buf, bufsize);
    echoBuf[bufsize] = 0;
    LOGINFO2("firefuse_write %s -> %s", path, echoBuf);
  } else if (strcmp(path, FIRELOG_PATH) == 0) {
    switch (buf[0]) {
      case 'E': 
      case 'e': 
      case '0': 
        firelog_level(FIRELOG_ERROR); 
	break;
      case 'W': 
      case 'w': 
      case '1': 
        firelog_level(FIRELOG_WARN); 
	break;
      case 'I': 
      case 'i': 
      case '2': 
        firelog_level(FIRELOG_INFO); 
        break;
      case 'D': 
      case 'd': 
      case '3': 
        firelog_level(FIRELOG_DEBUG); 
	break;
      case 'T': 
      case 't': 
      case '4': 
        firelog_level(FIRELOG_TRACE); 
	break;
    }
  } else if (strcmp(path, FIRESTEP_PATH) == 0) {
    firestep_write(buf, bufsize);
  }  

  return bufsize;
}
Exemplo n.º 3
0
int firefuse_read(const char *path, char *buf, size_t size, off_t offset, struct fuse_file_info *fi) {
    if (is_cv_path(path)) {
        int res = cve_read(path, buf, size, offset, fi);
        if (res > 0) {
            bytes_read += res;
        }
        return res;
    }
    if (is_cnc_path(path)) {
        int res = cnc_read(path, buf, size, offset, fi);
        if (res > 0) {
            bytes_read += res;
        }
        return res;
    }

    LOGTRACE1("firefuse_read(%s)", path);
    size_t sizeOut = size;
    size_t len;
    (void) fi;

    if (strcmp(path, STATUS_PATH) == 0) {
        const char *status_str = firepick_status();
        sizeOut = firefuse_readBuffer(buf, status_str, size, offset, strlen(status_str));
    } else if (strcmp(path, CONFIG_PATH) == 0) {
        sizeOut = firefuse_readBuffer(buf, pConfigJson, size, offset, strlen(pConfigJson));
    } else if (strcmp(path, HOLES_PATH) == 0) {
        const char *holes_str = "holes";
        sizeOut = firefuse_readBuffer(buf, holes_str, size, offset, strlen(holes_str));
    } else if (strcmp(path, ECHO_PATH) == 0) {
        sizeOut = firefuse_readBuffer(buf, echoBuf, size, offset, strlen(echoBuf));
    } else if (strcmp(path, FIRELOG_PATH) == 0) {
        char *str = "Actual log is " FIRELOG_FILE "\n";
        sizeOut = firefuse_readBuffer(buf, str, size, offset, strlen(str));
    } else if (strcmp(path, FIRESTEP_PATH) == 0) {
        const char *json = firestep_json();
        sizeOut = firefuse_readBuffer(buf, json, size, offset, strlen(json));
    } else {
        LOGERROR2("firefuse_read(%s, %ldB) ENOENT", path, size);
        return -ENOENT;
    }

    LOGTRACE3("firefuse_read(%s, %ldB) -> %ldB", path, size, sizeOut);
    bytes_read += sizeOut;
    return sizeOut;
}
Exemplo n.º 4
0
int firefuse_release(const char *path, struct fuse_file_info *fi) {
    if (is_cv_path(path)) {
        return cve_release(path, fi);
    }
    if (is_cnc_path(path)) {
        return cnc_release(path, fi);
    }

    LOGTRACE1("firefuse_release(%s)", path);
    if (strcmp(path, STATUS_PATH) == 0) {
        // NOP
    } else if (strcmp(path, CONFIG_PATH) == 0) {
        // NOP
    } else if (strcmp(path, HOLES_PATH) == 0) {
        firefuse_freeDataBuffer(path, fi);
    } else if (strcmp(path, ECHO_PATH) == 0) {
        // NOP
    } else if (strcmp(path, FIRELOG_PATH) == 0) {
        // NOP
    } else if (strcmp(path, FIRESTEP_PATH) == 0) {
        // NOP
    }
    return 0;
}