示例#1
0
文件: fuse_lfs.c 项目: Theophilus/ffs
static void lfs_ll_getattr(fuse_req_t req, fuse_ino_t ino,
                             struct fuse_file_info *fi){
  struct stat stbuf;
  (void) fi;
  memset(&stbuf, 0, sizeof(stbuf));
  if (lfs_stat(ino, &stbuf) == -1)
    fuse_reply_err(req, ENOENT);
  else
    fuse_reply_attr(req, &stbuf, 1.0);
}
示例#2
0
static
int lfs_open(IsoFileSource *src)
{
    int err;
    struct stat info;
    _LocalFsFileSource *data;
    char *path;

    if (src == NULL) {
        return ISO_NULL_POINTER;
    }

    data = src->data;
    if (data->openned) {
        return ISO_FILE_ALREADY_OPENED;
    }

    /* is a file or a dir ? */
    err = lfs_stat(src, &info);
    if (err < 0) {
        return err;
    }

    path = lfs_get_path(src);
    if (S_ISDIR(info.st_mode)) {
        data->info.dir = opendir(path);
        data->openned = data->info.dir ? 2 : 0;
    } else {
        data->info.fd = open(path, O_RDONLY);
        data->openned = data->info.fd != -1 ? 1 : 0;
    }
    free(path);

    /*
     * check for possible errors, note that many of possible ones are
     * parsed in the lstat call above 
     */
    if (data->openned == 0) {
        switch (errno) {
        case EACCES:
            err = ISO_FILE_ACCESS_DENIED;
            break;
        case EFAULT:
        case ENOMEM:
            err = ISO_OUT_OF_MEM;
            break;
        default:
            err = ISO_FILE_ERROR;
            break;
        }
        return err;
    }

    return ISO_SUCCESS;
}
示例#3
0
int LittleFileSystem::stat(const char *name, struct stat *st)
{
    struct lfs_info info;
    _mutex.lock();
    LFS_INFO("stat(\"%s\", %p)", name, st);
    int err = lfs_stat(&_lfs, name, &info);
    LFS_INFO("stat -> %d", lfs_toerror(err));
    _mutex.unlock();
    st->st_size = info.size;
    st->st_mode = lfs_tomode(info.type);
    return lfs_toerror(err);
}
示例#4
0
文件: fuse_lfs.c 项目: Theophilus/ffs
static void lfs_ll_lookup(fuse_req_t req, fuse_ino_t parent, const char *name){
  struct fuse_entry_param e;
  if (parent != 1 || strcmp(name, hello_name) != 0)
    fuse_reply_err(req, ENOENT);
  else {
    memset(&e, 0, sizeof(e));
    e.ino = 2;
    e.attr_timeout = 1.0;
    e.entry_timeout = 1.0;
    lfs_stat(e.ino, &e.attr);
    fuse_reply_entry(req, &e);
  }
}
示例#5
0
    mutex_unlock(&fs->lock);

    return littlefs_err_to_errno(ret);
}

static int _stat(vfs_mount_t *mountp, const char *restrict path, struct stat *restrict buf)
{
    littlefs_desc_t *fs = mountp->private_data;

    mutex_lock(&fs->lock);

    DEBUG("littlefs: stat: mountp=%p, path=%s, buf=%p\n",
          (void *)mountp, path, (void *)buf);

    struct lfs_info info;
    int ret = lfs_stat(&fs->fs, path, &info);
    mutex_unlock(&fs->lock);
    /* info.name */
    buf->st_size = info.size;
    switch (info.type) {
    case LFS_TYPE_REG:
        buf->st_mode = S_IFREG;
        break;
    case LFS_TYPE_DIR:
        buf->st_mode = S_IFDIR;
        break;
    }

    return littlefs_err_to_errno(ret);
}