Changeset 222e57c in mainline for uspace/srv/vfs/vfs_rdwr.c
- 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
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.