Subversion Repositories HelenOS

Rev

Rev 2683 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2683 Rev 2684
Line 38... Line 38...
38
#include "vfs.h"
38
#include "vfs.h"
39
#include <ipc/ipc.h>
39
#include <ipc/ipc.h>
40
#include <async.h>
40
#include <async.h>
41
#include <errno.h>
41
#include <errno.h>
42
#include <rwlock.h>
42
#include <rwlock.h>
-
 
43
#include <unistd.h>
43
 
44
 
44
static void vfs_rdwr(ipc_callid_t rid, ipc_call_t *request, bool read)
45
static void vfs_rdwr(ipc_callid_t rid, ipc_call_t *request, bool read)
45
{
46
{
46
 
47
 
47
    /*
48
    /*
Line 153... Line 154...
153
void vfs_write(ipc_callid_t rid, ipc_call_t *request)
154
void vfs_write(ipc_callid_t rid, ipc_call_t *request)
154
{
155
{
155
    vfs_rdwr(rid, request, false);
156
    vfs_rdwr(rid, request, false);
156
}
157
}
157
 
158
 
-
 
159
void vfs_seek(ipc_callid_t rid, ipc_call_t *request)
-
 
160
{
-
 
161
    int fd = (int) IPC_GET_ARG1(*request);
-
 
162
    off_t off = (off_t) IPC_GET_ARG2(*request);
-
 
163
    int whence = (int) IPC_GET_ARG3(*request);
-
 
164
 
-
 
165
 
-
 
166
    /*
-
 
167
     * Lookup the file structure corresponding to the file descriptor.
-
 
168
     */
-
 
169
    vfs_file_t *file = vfs_file_get(fd);
-
 
170
    if (!file) {
-
 
171
        ipc_answer_0(rid, ENOENT);
-
 
172
        return;
-
 
173
    }
-
 
174
 
-
 
175
    off_t newpos;
-
 
176
    futex_down(&file->lock);
-
 
177
    if (whence == SEEK_SET) {
-
 
178
        file->pos = off;
-
 
179
        futex_up(&file->lock);
-
 
180
        ipc_answer_1(rid, EOK, off);
-
 
181
        return;
-
 
182
    }
-
 
183
    if (whence == SEEK_CUR) {
-
 
184
        if (file->pos + off < file->pos) {
-
 
185
            futex_up(&file->lock);
-
 
186
            ipc_answer_0(rid, EOVERFLOW);
-
 
187
            return;
-
 
188
        }
-
 
189
        file->pos += off;
-
 
190
        newpos = file->pos;
-
 
191
        futex_up(&file->lock);
-
 
192
        ipc_answer_1(rid, EOK, newpos);
-
 
193
        return;
-
 
194
    }
-
 
195
    if (whence == SEEK_END) {
-
 
196
        rwlock_reader_lock(&file->node->contents_rwlock);
-
 
197
        size_t size = file->node->size;
-
 
198
        rwlock_reader_unlock(&file->node->contents_rwlock);
-
 
199
        if (size + off < size) {
-
 
200
            futex_up(&file->lock);
-
 
201
            ipc_answer_0(rid, EOVERFLOW);
-
 
202
            return;
-
 
203
        }
-
 
204
        newpos = size + off;
-
 
205
        futex_up(&file->lock);
-
 
206
        ipc_answer_1(rid, EOK, newpos);
-
 
207
        return;
-
 
208
    }
-
 
209
    futex_up(&file->lock);
-
 
210
    ipc_answer_0(rid, EINVAL);
-
 
211
}
-
 
212
 
158
/**
213
/**
159
 * @}
214
 * @}
160
 */
215
 */