OpenCores
URL https://opencores.org/ocsvn/c0or1k/c0or1k/trunk

Subversion Repositories c0or1k

[/] [c0or1k/] [trunk/] [conts/] [posix/] [libposix/] [stat.c] - Blame information for rev 7

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 drasko
/*
2
 * l4/posix glue for open()
3
 *
4
 * Copyright (C) 2007 Bahadir Balban
5
 */
6
#include <errno.h>
7
#include <stdio.h>
8
#include <stdarg.h>
9
#include <string.h>
10
#include <sys/shm.h>
11
#include <sys/types.h>
12
#include <sys/stat.h>
13
#include <l4lib/os/posix/kstat.h>
14
#include <l4lib/ipcdefs.h>
15
#include <l4lib/utcb.h>
16
#include <fcntl.h>
17
#include <l4/macros.h>
18
#include INC_GLUE(memory.h)
19
#include <shpage.h>
20
#include <libposix.h>
21
 
22
static inline int l4_fstat(int fd, void *buffer)
23
{
24
        int err;
25
 
26
        /* Pathname address on utcb page */
27
        write_mr(L4SYS_ARG0, fd);
28
        write_mr(L4SYS_ARG1, (unsigned long)buffer);
29
 
30
        /* Call pager with open() request. Check ipc error. */
31
        if ((err = l4_sendrecv_full(pagerid, pagerid, L4_IPC_TAG_FSTAT)) < 0) {
32
                print_err("%s: L4 IPC Error: %d.\n", __FUNCTION__, err);
33
                return err;
34
        }
35
        /* Check if syscall itself was successful */
36
        if ((err = l4_get_retval()) < 0) {
37
                print_err("%s: FSTAT Error: %d.\n", __FUNCTION__, err);
38
                return err;
39
        }
40
        return err;
41
}
42
 
43
int kstat_to_stat(struct kstat *ks, struct stat *s)
44
{
45
        s->st_dev = 0;
46
        s->st_ino = ks->vnum;
47
        s->st_mode = ks->mode;
48
        s->st_nlink = ks->links;
49
        s->st_uid = ks->uid;
50
        s->st_gid = ks->gid;
51
        s->st_rdev = 0;
52
        s->st_size = ks->size;
53
        s->st_blksize = ks->blksize;
54
        s->st_blocks = ks->size / ks->blksize;
55
        s->st_atime = ks->atime;
56
        s->st_mtime = ks->mtime;
57
        s->st_ctime = ks->ctime;
58
 
59
        return 0;
60
}
61
 
62
static inline int l4_stat(const char *pathname, void *buffer)
63
{
64
        int err;
65
        struct kstat ks;
66
 
67
        utcb_full_strcpy_from(pathname);
68
 
69
        /* Pathname address on utcb page */
70
        write_mr(L4SYS_ARG0, (unsigned long)utcb_full_buffer());
71
 
72
        /* Pass on buffer that should receive stat */
73
        write_mr(L4SYS_ARG1, (unsigned long)&ks);
74
 
75
        /* Call vfs with stat() request. Check ipc error. */
76
        if ((err = l4_sendrecv_full(pagerid, pagerid, L4_IPC_TAG_STAT)) < 0) {
77
                print_err("%s: L4 IPC Error: %d.\n", __FUNCTION__, err);
78
                return err;
79
        }
80
 
81
        /* Check if syscall itself was successful */
82
        if ((err = l4_get_retval()) < 0) {
83
                print_err("%s: STAT Error: %d.\n", __FUNCTION__, err);
84
                return err;
85
        }
86
 
87
        /* Convert c0-style stat structure to posix stat */
88
        kstat_to_stat(&ks, buffer);
89
 
90
        return err;
91
}
92
 
93
int fstat(int fd, struct stat *buffer)
94
{
95
        int ret;
96
 
97
        ret = l4_fstat(fd, buffer);
98
 
99
        /* If error, return positive error code */
100
        if (ret < 0) {
101
                errno = -ret;
102
                return -1;
103
        }
104
        /* else return value */
105
        return ret;
106
 
107
}
108
 
109
int stat(const char *pathname, struct stat *buffer)
110
{
111
        int ret;
112
 
113
        ret = l4_stat(pathname, buffer);
114
 
115
        /* If error, return positive error code */
116
        if (ret < 0) {
117
                errno = -ret;
118
                return -1;
119
        }
120
        /* else return value */
121
        return ret;
122
 
123
}
124
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.