Changeset 222e57c in mainline
- Timestamp:
- 2008-01-06T19:39:13Z (17 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 41a0d27
- Parents:
- 10d6b858
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/include/errno.h
r10d6b858 r222e57c 56 56 #define EINVAL -13 /* Invalid value */ 57 57 #define EBUSY -14 /* Resource is busy */ 58 #define EOVERFLOW -15 /* The result does not fit its size. */ 58 59 59 60 #endif -
uspace/lib/libc/generic/vfs.c
r10d6b858 r222e57c 1 1 /* 2 * Copyright (c) 200 7Jakub Jermar2 * Copyright (c) 2008 Jakub Jermar 3 3 * All rights reserved. 4 4 * … … 185 185 return (ssize_t) IPC_GET_ARG1(answer); 186 186 } 187 188 off_t lseek(int fildes, off_t offset, int whence) 189 { 190 int res; 191 ipcarg_t rc; 192 193 futex_down(&vfs_phone_futex); 194 async_serialize_start(); 195 if (vfs_phone < 0) { 196 res = vfs_connect(); 197 if (res < 0) { 198 async_serialize_end(); 199 futex_up(&vfs_phone_futex); 200 return res; 201 } 202 } 203 204 off_t newoffs; 205 rc = async_req_3_1(vfs_phone, VFS_SEEK, fildes, offset, whence, 206 &newoffs); 207 208 async_serialize_end(); 209 futex_up(&vfs_phone_futex); 210 211 if (rc != EOK) 212 return (off_t) -1; 213 214 return newoffs; 215 } 216 187 217 /** @} 188 218 */ -
uspace/lib/libc/include/unistd.h
r10d6b858 r222e57c 42 42 #define getpagesize() (PAGE_SIZE) 43 43 44 #define SEEK_SET 0 45 #define SEEK_CUR 1 46 #define SEEK_END 2 47 44 48 extern ssize_t write(int fd, const void * buf, size_t count); 45 49 extern ssize_t read(int fd, void * buf, size_t count); 50 extern off_t lseek(int, off_t, int); 51 46 52 extern void _exit(int status); 47 53 extern void *sbrk(ssize_t incr); -
uspace/srv/vfs/vfs.c
r10d6b858 r222e57c 100 100 vfs_write(callid, &call); 101 101 break; 102 case VFS_SEEK: 103 vfs_seek(callid, &call); 104 break; 102 105 case VFS_UNMOUNT: 103 106 case VFS_CREATE: 104 107 case VFS_CLOSE: 105 case VFS_SEEK:106 108 case VFS_UNLINK: 107 109 case VFS_RENAME: -
uspace/srv/vfs/vfs.h
r10d6b858 r222e57c 136 136 unsigned refcnt; /**< Usage counter. */ 137 137 link_t nh_link; /**< Node hash-table link. */ 138 size_t size; /**< Cached size of the file. */ 138 139 139 140 /** … … 211 212 extern void vfs_read(ipc_callid_t, ipc_call_t *); 212 213 extern void vfs_write(ipc_callid_t, ipc_call_t *); 214 extern void vfs_seek(ipc_callid_t, ipc_call_t *); 213 215 214 216 #endif -
uspace/srv/vfs/vfs_rdwr.c
r10d6b858 r222e57c 41 41 #include <errno.h> 42 42 #include <rwlock.h> 43 #include <unistd.h> 43 44 44 45 static void vfs_rdwr(ipc_callid_t rid, ipc_call_t *request, bool read) … … 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 * @}
Note:
See TracChangeset
for help on using the changeset viewer.