aboutsummaryrefslogtreecommitdiff
path: root/libdiskfs/io-seek.c
diff options
context:
space:
mode:
Diffstat (limited to 'libdiskfs/io-seek.c')
-rw-r--r--libdiskfs/io-seek.c64
1 files changed, 34 insertions, 30 deletions
diff --git a/libdiskfs/io-seek.c b/libdiskfs/io-seek.c
index 33aa77d4..71179816 100644
--- a/libdiskfs/io-seek.c
+++ b/libdiskfs/io-seek.c
@@ -1,5 +1,5 @@
-/*
- Copyright (C) 1994, 1995, 1996 Free Software Foundation
+/*
+ Copyright (C) 1994,1995,1996,2000,2006 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
@@ -19,9 +19,6 @@
#include "io_S.h"
#include <unistd.h>
-#define diskfs_readonly 0
-#define diskfs_synchronous 0
-
/* Implement io_seek as described in <hurd/io.defs>. */
kern_return_t
diskfs_S_io_seek (struct protid *cred,
@@ -29,29 +26,36 @@ diskfs_S_io_seek (struct protid *cred,
int whence,
off_t *newoffset)
{
-
- CHANGE_NODE_FIELD (cred,
- ({
- iohelp_get_conch (&np->conch);
- switch (whence)
- {
- case SEEK_SET:
- err = 0;
- cred->po->filepointer = offset;
- break;
- case SEEK_CUR:
- err = 0;
- cred->po->filepointer += offset;
- break;
- case SEEK_END:
- err = 0;
- cred->po->filepointer = (np->dn_stat.st_size
- + offset);
- break;
- default:
- err = EINVAL;
- break;
- }
- *newoffset = cred->po->filepointer;
- }));
+ error_t err = 0;
+ struct node *np;
+
+ if (!cred)
+ return EOPNOTSUPP;
+
+ np = cred->po->np;
+
+ mutex_lock (&np->lock);
+
+ iohelp_get_conch (&np->conch);
+ switch (whence)
+ {
+ case SEEK_CUR:
+ offset += cred->po->filepointer;
+ goto check;
+ case SEEK_END:
+ offset += np->dn_stat.st_size;
+ case SEEK_SET:
+ check:
+ if (offset >= 0)
+ {
+ *newoffset = cred->po->filepointer = offset;
+ break;
+ }
+ default:
+ err = EINVAL;
+ break;
+ }
+
+ mutex_unlock (&np->lock);
+ return err;
}