[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
io-seek fixes.
From: |
Alfred M. Szmidt |
Subject: |
io-seek fixes. |
Date: |
Sun, 26 Sep 2004 04:16:54 +0200 |
[sorry for the long delay]
Here is Jeroen's patch that makes glibc's bug-fseek test case pass.
POSIX says that one should fail with EINVAL when the file posistion is
smaller than 0.
libdiskfs/ChangeLog
2004-05-08 Jeroen Dekkers <jeroen@dekkers.cx>
* libdiskfs/io-seek.c (diskfs_S_io_seek): Return EINVAL when
resulting file position is smaller than 0.
libnetfs/ChangeLog
2004-05-08 Jeroen Dekkers <jeroen@dekkers.cx>
* libnetfs/io-seek.c (netfs_S_io_seek): Return EINVAL when
resulting file position is smaller than 0.
storeio/ChangeLog
2004-05-08 Jeroen Dekkers <jeroen@dekkers.cx>
* storeio/open.c (open_seek): Return EINVAL when resulting file
position is smaller than 0.
trans/ChangeLog
2004-05-08 Jeroen Dekkers <jeroen@dekkers.cx>
* trans/hello-mt.c (trivfs_S_io_seek): Return EINVAL when
resulting file position is smaller than 0.
* trans/hello.c (trivfs_S_io_seek): Likewise.
Index: libdiskfs/io-seek.c
===================================================================
RCS file: /cvsroot/hurd/hurd/libdiskfs/io-seek.c,v
retrieving revision 1.7
diff -u -p -r1.7 io-seek.c
--- libdiskfs/io-seek.c 18 Jul 2000 21:33:33 -0000 1.7
+++ libdiskfs/io-seek.c 26 Sep 2004 01:57:34 -0000
@@ -1,5 +1,5 @@
/*
- Copyright (C) 1994, 1995, 1996, 2000 Free Software Foundation
+ Copyright (C) 1994, 1995, 1996, 2000, 2004 Free Software Foundation
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
@@ -28,7 +28,8 @@ diskfs_S_io_seek (struct protid *cred,
{
error_t err = 0;
struct node *np;
-
+ off_t pos;
+
if (!cred)
return EOPNOTSUPP;
@@ -40,19 +41,26 @@ diskfs_S_io_seek (struct protid *cred,
switch (whence)
{
case SEEK_SET:
- cred->po->filepointer = offset;
+ pos = offset;
break;
case SEEK_CUR:
- cred->po->filepointer += offset;
+ pos = cred->po->filepointer + offset;
break;
case SEEK_END:
- cred->po->filepointer = (np->dn_stat.st_size + offset);
+ pos = (np->dn_stat.st_size + offset);
break;
default:
err = EINVAL;
break;
}
- *newoffset = cred->po->filepointer;
+
+ if (!err)
+ {
+ if (pos < 0)
+ err = EINVAL;
+ else
+ *newoffset = cred->po->filepointer = pos;
+ }
mutex_unlock (&np->lock);
return err;
Index: libnetfs/io-seek.c
===================================================================
RCS file: /cvsroot/hurd/hurd/libnetfs/io-seek.c,v
retrieving revision 1.7
diff -u -p -r1.7 io-seek.c
--- libnetfs/io-seek.c 30 Dec 2000 18:22:28 -0000 1.7
+++ libnetfs/io-seek.c 26 Sep 2004 01:57:35 -0000
@@ -1,5 +1,5 @@
/*
- Copyright (C) 1995, 1996, 2000 Free Software Foundation, Inc.
+ Copyright (C) 1995, 1996, 2000, 2004 Free Software Foundation, Inc.
Written by Michael I. Bushnell, p/BSG.
This file is part of the GNU Hurd.
@@ -28,7 +28,8 @@ netfs_S_io_seek (struct protid *user,
int whence,
off_t *newoffset)
{
- error_t err;
+ error_t err = 0;
+ off_t pos;
if (!user)
return EOPNOTSUPP;
@@ -36,13 +37,11 @@ netfs_S_io_seek (struct protid *user,
switch (whence)
{
case SEEK_SET:
- err = 0;
- user->po->filepointer = offset;
+ pos = offset;
break;
case SEEK_CUR:
- err = 0;
- user->po->filepointer += offset;
+ pos = user->po->filepointer + offset;
break;
case SEEK_END:
@@ -54,7 +53,7 @@ netfs_S_io_seek (struct protid *user,
err = netfs_validate_stat (np, user->user);
if (!err)
- user->po->filepointer = np->nn_stat.st_size + offset;
+ pos = np->nn_stat.st_size + offset;
mutex_unlock (&np->lock);
@@ -66,7 +65,14 @@ netfs_S_io_seek (struct protid *user,
break;
}
- *newoffset = user->po->filepointer;
+ if (!err)
+ {
+ if (pos < 0)
+ err = EINVAL;
+ else
+ *newoffset = user->po->filepointer = pos;
+ }
+
return err;
}
Index: storeio/open.c
===================================================================
RCS file: /cvsroot/hurd/hurd/storeio/open.c,v
retrieving revision 1.2
diff -u -p -r1.2 open.c
--- storeio/open.c 23 Sep 1996 19:58:26 -0000 1.2
+++ storeio/open.c 26 Sep 2004 01:57:38 -0000
@@ -1,6 +1,6 @@
/* Per-open information for storeio
- Copyright (C) 1995, 1996 Free Software Foundation, Inc.
+ Copyright (C) 1995, 1996, 2004 Free Software Foundation, Inc.
Written by Miles Bader <miles@gnu.ai.mit.edu>
@@ -100,24 +100,30 @@ error_t
open_seek (struct open *open, off_t offs, int whence, off_t *new_offs)
{
error_t err = 0;
+ off_t pos;
mutex_lock (&open->lock);
switch (whence)
{
case SEEK_SET:
- open->offs = offs; break;
+ pos = offs; break;
case SEEK_CUR:
- open->offs += offs; break;
+ pos = open->offs + offs; break;
case SEEK_END:
- open->offs = open->dev->store->size - offs; break;
+ pos = open->dev->store->size + offs; break;
default:
err = EINVAL;
}
if (! err)
- *new_offs = open->offs;
-
+ {
+ if (pos < 0)
+ err = EINVAL;
+ else
+ *new_offs = open->offs = pos;
+ }
+
mutex_unlock (&open->lock);
return err;
Index: trans/hello-mt.c
===================================================================
RCS file: /cvsroot/hurd/hurd/trans/hello-mt.c,v
retrieving revision 1.4
diff -u -p -r1.4 hello-mt.c
--- trans/hello-mt.c 13 Jun 2002 21:26:39 -0000 1.4
+++ trans/hello-mt.c 26 Sep 2004 01:57:38 -0000
@@ -1,5 +1,5 @@
/* hello-mt.c - A trivial single-file translator, multithreaded version
- Copyright (C) 1998,99,2001,02 Free Software Foundation, Inc.
+ Copyright (C) 1998,99,2001,02,04 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
@@ -186,6 +186,7 @@ trivfs_S_io_seek (struct trivfs_protid *
{
struct open *op;
error_t err = 0;
+ off_t pos;
if (! cred)
return EOPNOTSUPP;
@@ -196,18 +197,23 @@ trivfs_S_io_seek (struct trivfs_protid *
switch (whence)
{
case SEEK_SET:
- op->offs = offs; break;
+ pos = offs; break;
case SEEK_CUR:
- op->offs += offs; break;
+ pos = op->offs + offs; break;
case SEEK_END:
- op->offs = contents_len - offs; break;
+ pos = contents_len + offs; break;
default:
err = EINVAL;
}
if (! err)
- *new_offs = op->offs;
-
+ {
+ if (pos < 0)
+ err = EINVAL;
+ else
+ *new_offs = op->offs = pos;
+ }
+
mutex_unlock (&op->lock);
return err;
Index: trans/hello.c
===================================================================
RCS file: /cvsroot/hurd/hurd/trans/hello.c,v
retrieving revision 1.5
diff -u -p -r1.5 hello.c
--- trans/hello.c 13 Jun 2002 21:26:39 -0000 1.5
+++ trans/hello.c 26 Sep 2004 01:57:38 -0000
@@ -1,5 +1,5 @@
/* hello.c - A trivial single-file translator
- Copyright (C) 1998, 1999,2001,02 Free Software Foundation, Inc.
+ Copyright (C) 1998, 1999,2001,02,04 Free Software Foundation, Inc.
Gordon Matzigkeit <gord@fig.org>, 1999
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
@@ -165,6 +165,7 @@ trivfs_S_io_seek (struct trivfs_protid *
{
struct open *op;
error_t err = 0;
+ off_t pos;
if (! cred)
return EOPNOTSUPP;
@@ -172,18 +173,23 @@ trivfs_S_io_seek (struct trivfs_protid *
switch (whence)
{
case SEEK_SET:
- op->offs = offs; break;
+ pos = offs; break;
case SEEK_CUR:
- op->offs += offs; break;
+ pos = op->offs + offs; break;
case SEEK_END:
- op->offs = contents_len - offs; break;
+ pos = contents_len + offs; break;
default:
err = EINVAL;
}
if (! err)
- *new_offs = op->offs;
-
+ {
+ if (pos < 0)
+ err = EINVAL;
+ else
+ *new_offs = op->offs = pos;
+ }
+
return err;
}
- io-seek fixes.,
Alfred M. Szmidt <=