1997-04-26 17:34:30 +04:00
|
|
|
/*
|
|
|
|
* llseek.c -- stub calling the llseek system call
|
|
|
|
*
|
ChangeLog, .del-io.h~72680822, irel_ma.c, llseek.c, rw_bitmaps.c:
io.h: Change the prototype of ext2fs_llseek() to use int's instead of
unsigned int's.
llseek.c: Change to allow PIC and !HAVE_LLSEEK. Add a prototype to
make life easer for GNU Libc 2.
rw_bitmaps.c: On the PowerPC, the big-endian variant of the ext2
filesystem has its bitmaps stored as 32-bit words with bit 0 as the
LSB of each word. Thus a bitmap with only bit 0 set would be, as a
string of bytes, 00 00 00 01 00 ... To cope with this, we
byte-reverse each word of a bitmap if we have a big-endian filesystem,
that is, if we are *not* byte-swapping other word-sized numbers.
ChangeLog, expect.1, image.gz:
f_badinode: Modify test to check for "bad" character and block devices
(i.e., ones which contain garbage block entries)
1997-08-14 21:20:42 +04:00
|
|
|
* Copyright (C) 1994, 1995, 1996, 1997 Theodore Ts'o.
|
1997-04-29 20:17:09 +04:00
|
|
|
*
|
|
|
|
* %Begin-Header%
|
2010-05-18 05:31:56 +04:00
|
|
|
* This file may be redistributed under the terms of the GNU Library
|
|
|
|
* General Public License, version 2.
|
1997-04-29 20:17:09 +04:00
|
|
|
* %End-Header%
|
1997-04-26 17:34:30 +04:00
|
|
|
*/
|
|
|
|
|
2000-05-26 03:31:54 +04:00
|
|
|
#define _LARGEFILE_SOURCE
|
|
|
|
#define _LARGEFILE64_SOURCE
|
|
|
|
|
2011-09-19 01:34:37 +04:00
|
|
|
#include "config.h"
|
1997-10-20 03:00:21 +04:00
|
|
|
#if HAVE_SYS_TYPES_H
|
1997-04-26 17:34:30 +04:00
|
|
|
#include <sys/types.h>
|
1997-10-20 03:00:21 +04:00
|
|
|
#endif
|
1997-04-26 17:34:30 +04:00
|
|
|
|
1997-10-25 08:16:53 +04:00
|
|
|
#if HAVE_ERRNO_H
|
1997-04-26 17:34:30 +04:00
|
|
|
#include <errno.h>
|
1997-10-25 08:16:53 +04:00
|
|
|
#endif
|
1997-08-11 03:07:40 +04:00
|
|
|
#if HAVE_UNISTD_H
|
1997-04-26 17:34:30 +04:00
|
|
|
#include <unistd.h>
|
1997-08-11 03:07:40 +04:00
|
|
|
#endif
|
Many files:
dosio.c: New file to do DOS/BIOS disk accesses.
namei.c (open_namei): Make pathlen be of type size_t.
llseek.c: Always #include stdlib.h since it's need to define
size_t.
io.h: Use errcode_t for magic numbers.
icount.c (get_icount_el), dupfs.c (ext2fs_dup_handle), dblist.c
(dir_block_cmp): Use size_t where appropriate.
read_bb.c (ext2fs_read_bb_inode), cmp_bitmaps.c
(ext2fs_compare_inode_bitmap): Use blk_t, ino_t and size_t
where appropriate.
closefs.c (ext2fs_flush): Use dgrp_t instead of int where
appropriate.
openfs.c (ext2fs_open), check_desc.c (ext2fs_check_desc): Use blk_t
instead of int where appropriate.
rw_bitmaps.c (read_bitmaps), irel_ma.c, inode.c (ext2fs_write_inode),
initialize.c (ext2fs_initialize): brel_ma.c: Fix to make be
16-bit safe.
link.c (ext2fs_link), unlink.c (ext2fs_unlink), lookup.c (lookup_proc),
ismounted.c (ext2fs_check_if_mounted), block.c (xlate_func):
Add #pragma argsused for Turbo C.
1997-08-12 00:29:22 +04:00
|
|
|
#ifdef __MSDOS__
|
|
|
|
#include <io.h>
|
|
|
|
#endif
|
1997-04-26 17:34:30 +04:00
|
|
|
#include "et/com_err.h"
|
1997-10-20 04:44:26 +04:00
|
|
|
#include "ext2fs/ext2_io.h"
|
1997-04-26 17:34:30 +04:00
|
|
|
|
|
|
|
#ifdef __linux__
|
|
|
|
|
2000-05-26 03:31:54 +04:00
|
|
|
#if defined(HAVE_LSEEK64) && defined(HAVE_LSEEK64_PROTOTYPE)
|
|
|
|
|
|
|
|
#define my_llseek lseek64
|
|
|
|
|
2003-07-06 08:36:48 +04:00
|
|
|
#else
|
|
|
|
#if defined(HAVE_LLSEEK)
|
1997-04-26 17:58:21 +04:00
|
|
|
#include <syscall.h>
|
|
|
|
|
1997-10-21 03:36:30 +04:00
|
|
|
#ifndef HAVE_LLSEEK_PROTOTYPE
|
|
|
|
extern long long llseek (int fd, long long offset, int origin);
|
ChangeLog, .del-io.h~72680822, irel_ma.c, llseek.c, rw_bitmaps.c:
io.h: Change the prototype of ext2fs_llseek() to use int's instead of
unsigned int's.
llseek.c: Change to allow PIC and !HAVE_LLSEEK. Add a prototype to
make life easer for GNU Libc 2.
rw_bitmaps.c: On the PowerPC, the big-endian variant of the ext2
filesystem has its bitmaps stored as 32-bit words with bit 0 as the
LSB of each word. Thus a bitmap with only bit 0 set would be, as a
string of bytes, 00 00 00 01 00 ... To cope with this, we
byte-reverse each word of a bitmap if we have a big-endian filesystem,
that is, if we are *not* byte-swapping other word-sized numbers.
ChangeLog, expect.1, image.gz:
f_badinode: Modify test to check for "bad" character and block devices
(i.e., ones which contain garbage block entries)
1997-08-14 21:20:42 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#define my_llseek llseek
|
|
|
|
|
2000-05-26 03:31:54 +04:00
|
|
|
#else /* ! HAVE_LLSEEK */
|
1997-04-26 17:58:21 +04:00
|
|
|
|
2008-01-27 08:35:32 +03:00
|
|
|
#if SIZEOF_LONG == SIZEOF_LONG_LONG
|
1997-04-26 17:58:21 +04:00
|
|
|
|
|
|
|
#define llseek lseek
|
|
|
|
|
2008-01-27 08:35:32 +03:00
|
|
|
#else /* SIZEOF_LONG != SIZEOF_LONG_LONG */
|
1997-04-26 17:58:21 +04:00
|
|
|
|
|
|
|
#include <linux/unistd.h>
|
|
|
|
|
1997-04-26 17:34:30 +04:00
|
|
|
#ifndef __NR__llseek
|
|
|
|
#define __NR__llseek 140
|
|
|
|
#endif
|
|
|
|
|
ChangeLog, .del-io.h~72680822, irel_ma.c, llseek.c, rw_bitmaps.c:
io.h: Change the prototype of ext2fs_llseek() to use int's instead of
unsigned int's.
llseek.c: Change to allow PIC and !HAVE_LLSEEK. Add a prototype to
make life easer for GNU Libc 2.
rw_bitmaps.c: On the PowerPC, the big-endian variant of the ext2
filesystem has its bitmaps stored as 32-bit words with bit 0 as the
LSB of each word. Thus a bitmap with only bit 0 set would be, as a
string of bytes, 00 00 00 01 00 ... To cope with this, we
byte-reverse each word of a bitmap if we have a big-endian filesystem,
that is, if we are *not* byte-swapping other word-sized numbers.
ChangeLog, expect.1, image.gz:
f_badinode: Modify test to check for "bad" character and block devices
(i.e., ones which contain garbage block entries)
1997-08-14 21:20:42 +04:00
|
|
|
#ifndef __i386__
|
1997-04-26 17:34:30 +04:00
|
|
|
static int _llseek (unsigned int, unsigned long,
|
|
|
|
unsigned long, ext2_loff_t *, unsigned int);
|
|
|
|
|
|
|
|
static _syscall5(int,_llseek,unsigned int,fd,unsigned long,offset_high,
|
|
|
|
unsigned long, offset_low,ext2_loff_t *,result,
|
|
|
|
unsigned int, origin)
|
ChangeLog, .del-io.h~72680822, irel_ma.c, llseek.c, rw_bitmaps.c:
io.h: Change the prototype of ext2fs_llseek() to use int's instead of
unsigned int's.
llseek.c: Change to allow PIC and !HAVE_LLSEEK. Add a prototype to
make life easer for GNU Libc 2.
rw_bitmaps.c: On the PowerPC, the big-endian variant of the ext2
filesystem has its bitmaps stored as 32-bit words with bit 0 as the
LSB of each word. Thus a bitmap with only bit 0 set would be, as a
string of bytes, 00 00 00 01 00 ... To cope with this, we
byte-reverse each word of a bitmap if we have a big-endian filesystem,
that is, if we are *not* byte-swapping other word-sized numbers.
ChangeLog, expect.1, image.gz:
f_badinode: Modify test to check for "bad" character and block devices
(i.e., ones which contain garbage block entries)
1997-08-14 21:20:42 +04:00
|
|
|
#endif
|
1997-04-26 17:34:30 +04:00
|
|
|
|
ChangeLog, .del-io.h~72680822, irel_ma.c, llseek.c, rw_bitmaps.c:
io.h: Change the prototype of ext2fs_llseek() to use int's instead of
unsigned int's.
llseek.c: Change to allow PIC and !HAVE_LLSEEK. Add a prototype to
make life easer for GNU Libc 2.
rw_bitmaps.c: On the PowerPC, the big-endian variant of the ext2
filesystem has its bitmaps stored as 32-bit words with bit 0 as the
LSB of each word. Thus a bitmap with only bit 0 set would be, as a
string of bytes, 00 00 00 01 00 ... To cope with this, we
byte-reverse each word of a bitmap if we have a big-endian filesystem,
that is, if we are *not* byte-swapping other word-sized numbers.
ChangeLog, expect.1, image.gz:
f_badinode: Modify test to check for "bad" character and block devices
(i.e., ones which contain garbage block entries)
1997-08-14 21:20:42 +04:00
|
|
|
static ext2_loff_t my_llseek (int fd, ext2_loff_t offset, int origin)
|
1997-04-26 17:58:21 +04:00
|
|
|
{
|
|
|
|
ext2_loff_t result;
|
|
|
|
int retval;
|
|
|
|
|
ChangeLog, .del-io.h~72680822, irel_ma.c, llseek.c, rw_bitmaps.c:
io.h: Change the prototype of ext2fs_llseek() to use int's instead of
unsigned int's.
llseek.c: Change to allow PIC and !HAVE_LLSEEK. Add a prototype to
make life easer for GNU Libc 2.
rw_bitmaps.c: On the PowerPC, the big-endian variant of the ext2
filesystem has its bitmaps stored as 32-bit words with bit 0 as the
LSB of each word. Thus a bitmap with only bit 0 set would be, as a
string of bytes, 00 00 00 01 00 ... To cope with this, we
byte-reverse each word of a bitmap if we have a big-endian filesystem,
that is, if we are *not* byte-swapping other word-sized numbers.
ChangeLog, expect.1, image.gz:
f_badinode: Modify test to check for "bad" character and block devices
(i.e., ones which contain garbage block entries)
1997-08-14 21:20:42 +04:00
|
|
|
#ifndef __i386__
|
|
|
|
retval = _llseek(fd, ((unsigned long long) offset) >> 32,
|
2008-08-28 07:07:54 +04:00
|
|
|
#else
|
ChangeLog, .del-io.h~72680822, irel_ma.c, llseek.c, rw_bitmaps.c:
io.h: Change the prototype of ext2fs_llseek() to use int's instead of
unsigned int's.
llseek.c: Change to allow PIC and !HAVE_LLSEEK. Add a prototype to
make life easer for GNU Libc 2.
rw_bitmaps.c: On the PowerPC, the big-endian variant of the ext2
filesystem has its bitmaps stored as 32-bit words with bit 0 as the
LSB of each word. Thus a bitmap with only bit 0 set would be, as a
string of bytes, 00 00 00 01 00 ... To cope with this, we
byte-reverse each word of a bitmap if we have a big-endian filesystem,
that is, if we are *not* byte-swapping other word-sized numbers.
ChangeLog, expect.1, image.gz:
f_badinode: Modify test to check for "bad" character and block devices
(i.e., ones which contain garbage block entries)
1997-08-14 21:20:42 +04:00
|
|
|
retval = syscall(__NR__llseek, fd, (unsigned long long) (offset >> 32),
|
|
|
|
#endif
|
|
|
|
((unsigned long long) offset) & 0xffffffff,
|
1997-04-26 17:58:21 +04:00
|
|
|
&result, origin);
|
|
|
|
return (retval == -1 ? (ext2_loff_t) retval : result);
|
|
|
|
}
|
|
|
|
|
2000-10-25 06:06:09 +04:00
|
|
|
#endif /* __alpha__ || __ia64__ */
|
1997-04-26 17:58:21 +04:00
|
|
|
|
2000-05-26 03:31:54 +04:00
|
|
|
#endif /* HAVE_LLSEEK */
|
2003-07-06 08:36:48 +04:00
|
|
|
#endif /* defined(HAVE_LSEEK64) && defined(HAVE_LSEEK64_PROTOTYPE) */
|
1997-04-26 17:58:21 +04:00
|
|
|
|
ChangeLog, .del-io.h~72680822, irel_ma.c, llseek.c, rw_bitmaps.c:
io.h: Change the prototype of ext2fs_llseek() to use int's instead of
unsigned int's.
llseek.c: Change to allow PIC and !HAVE_LLSEEK. Add a prototype to
make life easer for GNU Libc 2.
rw_bitmaps.c: On the PowerPC, the big-endian variant of the ext2
filesystem has its bitmaps stored as 32-bit words with bit 0 as the
LSB of each word. Thus a bitmap with only bit 0 set would be, as a
string of bytes, 00 00 00 01 00 ... To cope with this, we
byte-reverse each word of a bitmap if we have a big-endian filesystem,
that is, if we are *not* byte-swapping other word-sized numbers.
ChangeLog, expect.1, image.gz:
f_badinode: Modify test to check for "bad" character and block devices
(i.e., ones which contain garbage block entries)
1997-08-14 21:20:42 +04:00
|
|
|
ext2_loff_t ext2fs_llseek (int fd, ext2_loff_t offset, int origin)
|
1997-04-26 17:34:30 +04:00
|
|
|
{
|
|
|
|
ext2_loff_t result;
|
|
|
|
static int do_compat = 0;
|
|
|
|
|
1997-04-26 17:58:21 +04:00
|
|
|
if ((sizeof(off_t) >= sizeof(ext2_loff_t)) ||
|
|
|
|
(offset < ((ext2_loff_t) 1 << ((sizeof(off_t)*8) -1))))
|
|
|
|
return lseek(fd, (off_t) offset, origin);
|
|
|
|
|
1997-04-26 17:34:30 +04:00
|
|
|
if (do_compat) {
|
1997-04-26 17:58:21 +04:00
|
|
|
errno = EINVAL;
|
|
|
|
return -1;
|
1997-04-26 17:34:30 +04:00
|
|
|
}
|
2008-08-28 07:07:54 +04:00
|
|
|
|
ChangeLog, .del-io.h~72680822, irel_ma.c, llseek.c, rw_bitmaps.c:
io.h: Change the prototype of ext2fs_llseek() to use int's instead of
unsigned int's.
llseek.c: Change to allow PIC and !HAVE_LLSEEK. Add a prototype to
make life easer for GNU Libc 2.
rw_bitmaps.c: On the PowerPC, the big-endian variant of the ext2
filesystem has its bitmaps stored as 32-bit words with bit 0 as the
LSB of each word. Thus a bitmap with only bit 0 set would be, as a
string of bytes, 00 00 00 01 00 ... To cope with this, we
byte-reverse each word of a bitmap if we have a big-endian filesystem,
that is, if we are *not* byte-swapping other word-sized numbers.
ChangeLog, expect.1, image.gz:
f_badinode: Modify test to check for "bad" character and block devices
(i.e., ones which contain garbage block entries)
1997-08-14 21:20:42 +04:00
|
|
|
result = my_llseek (fd, offset, origin);
|
1997-04-26 17:58:21 +04:00
|
|
|
if (result == -1 && errno == ENOSYS) {
|
1997-04-26 17:34:30 +04:00
|
|
|
/*
|
|
|
|
* Just in case this code runs on top of an old kernel
|
|
|
|
* which does not support the llseek system call
|
|
|
|
*/
|
|
|
|
do_compat++;
|
1997-04-26 17:58:21 +04:00
|
|
|
errno = EINVAL;
|
1997-04-26 17:34:30 +04:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1997-04-26 17:58:21 +04:00
|
|
|
#else /* !linux */
|
1997-04-26 17:34:30 +04:00
|
|
|
|
1999-01-04 10:35:45 +03:00
|
|
|
#ifndef EINVAL
|
|
|
|
#define EINVAL EXT2_ET_INVALID_ARGUMENT
|
|
|
|
#endif
|
|
|
|
|
1997-10-03 21:42:28 +04:00
|
|
|
ext2_loff_t ext2fs_llseek (int fd, ext2_loff_t offset, int origin)
|
1997-04-26 17:34:30 +04:00
|
|
|
{
|
2004-09-18 01:47:12 +04:00
|
|
|
#if defined(HAVE_LSEEK64) && defined(HAVE_LSEEK64_PROTOTYPE)
|
|
|
|
return lseek64 (fd, offset, origin);
|
|
|
|
#else
|
1997-04-26 17:34:30 +04:00
|
|
|
if ((sizeof(off_t) < sizeof(ext2_loff_t)) &&
|
|
|
|
(offset >= ((ext2_loff_t) 1 << ((sizeof(off_t)*8) -1)))) {
|
1999-01-04 10:35:45 +03:00
|
|
|
errno = EINVAL;
|
1997-04-26 17:34:30 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return lseek (fd, (off_t) offset, origin);
|
2004-09-18 01:47:12 +04:00
|
|
|
#endif
|
1997-04-26 17:34:30 +04:00
|
|
|
}
|
|
|
|
|
1997-04-26 17:58:21 +04:00
|
|
|
#endif /* linux */
|
1997-04-26 17:34:30 +04:00
|
|
|
|
|
|
|
|