summaryrefslogtreecommitdiff
path: root/libdiskfs
diff options
context:
space:
mode:
authorRoland McGrath <roland@gnu.org>2006-03-05 11:47:36 +0000
committerRoland McGrath <roland@gnu.org>2006-03-05 11:47:36 +0000
commitdd9469524f8de0c2ea06b390698a8b104090ade3 (patch)
treef1d48b4eef7d3c821c740a86434626f53f2dc56e /libdiskfs
parent61331860c768c1fcaeef786257e5ea6ea56317f7 (diff)
2006-03-05 Roland McGrath <roland@frob.com>
* io-seek.c (diskfs_S_io_seek): Return EINVAL if file pointer would become negative.
Diffstat (limited to 'libdiskfs')
-rw-r--r--libdiskfs/io-seek.c30
1 files changed, 16 insertions, 14 deletions
diff --git a/libdiskfs/io-seek.c b/libdiskfs/io-seek.c
index 6bdd4195..71179816 100644
--- a/libdiskfs/io-seek.c
+++ b/libdiskfs/io-seek.c
@@ -1,5 +1,5 @@
-/*
- Copyright (C) 1994, 1995, 1996, 2000 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
@@ -28,31 +28,33 @@ diskfs_S_io_seek (struct protid *cred,
{
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_SET:
- cred->po->filepointer = offset;
- break;
case SEEK_CUR:
- cred->po->filepointer += offset;
- break;
+ offset += cred->po->filepointer;
+ goto check;
case SEEK_END:
- cred->po->filepointer = (np->dn_stat.st_size + offset);
- break;
+ offset += np->dn_stat.st_size;
+ case SEEK_SET:
+ check:
+ if (offset >= 0)
+ {
+ *newoffset = cred->po->filepointer = offset;
+ break;
+ }
default:
err = EINVAL;
break;
}
- *newoffset = cred->po->filepointer;
mutex_unlock (&np->lock);
return err;