1/*
2 * Copyright (c) 2007, 2008, 2009, 2011, ETH Zurich.
3 * All rights reserved.
4 *
5 * This file is distributed under the terms in the attached LICENSE file.
6 * If you do not find this file, copies can be found by writing to:
7 * ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group.
8 */
9
10#include <barrelfish/barrelfish.h>
11#include <vfs/vfs.h>
12#include <sys/stat.h>
13#include <unistd.h>
14#include "posixcompat.h"
15#include <vfs/fdtab.h>
16
17__weak_reference(fstat, _fstat);
18int fstat(int fd, struct stat *buf)
19{
20    struct fdtab_entry *e = fdtab_get(fd);
21    if (e->type != FDTAB_TYPE_FILE) {
22        return -1;
23    }
24
25    POSIXCOMPAT_DEBUG("fstat(%d)\n", fd);
26
27    struct vfs_fileinfo info;
28    errval_t err = vfs_stat((vfs_handle_t)e->handle, &info);
29    if (err_is_ok(err)) {
30        _posixcompat_vfs_info_to_stat(&info, buf);
31        return 0;
32    } else {
33        DEBUG_ERR(err, "fstat(%d) failed\n", fd);
34        return -1;
35    }
36}
37