util-linux: Fix llseek patch.

The old patch was not working, as sfdisk could not create partition
tables.
This commit is contained in:
Michael Tremer
2011-09-17 14:27:23 +02:00
parent 6bb612ca11
commit 371481f26c

View File

@@ -1,197 +1,272 @@
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=392236
Submitted By: Dan Nicholson <dbn_dot_lists_at_gmail_dot_com>
Date: 2006-07-08
Initial Package Version: 2.12r
Origin: Upstream
Upstream Status: Applied in util-linux-2.13-pre6.tar.bz2
Description: Replaces uses of *llseek with lseek. Fixes an issue
compiling util-linux with kernel headers from linux-2.6.18-rc1
headers_install.
diff -ru util-linux-2.12r/fdisk/llseek.c util-linux-2.12r-new/fdisk/llseek.c
--- util-linux-2.12r/fdisk/llseek.c 2003-07-14 07:13:33.000000000 +1000
+++ util-linux-2.12r-new/fdisk/llseek.c 2006-10-13 15:50:09.000000000 +1000
@@ -14,30 +14,23 @@
diff -pur -x '*.rej' util-linux-2.12r.orig/fdisk/Makefile util-linux-2.12r/fdisk/Makefile
--- util-linux-2.12r.orig/fdisk/Makefile 2004-09-06 20:28:58.000000000 +0000
+++ util-linux-2.12r/fdisk/Makefile 2006-07-08 15:40:57.140375072 +0000
@@ -39,7 +39,7 @@ else
endif
endif
#ifdef __linux__
-cfdisk: cfdisk.o llseek.o disksize.o i386_sys_types.o $(LIB)/xstrncpy.o
+cfdisk: cfdisk.o disksize.o i386_sys_types.o $(LIB)/xstrncpy.o
ifeq "$(HAVE_SLANG)" "yes"
$(CC) $(LDFLAGS) $^ -o $@ $(LIBSLANG)
else
@@ -55,7 +55,7 @@ activate: sfdisk
rm -f activate
ln -s sfdisk activate
-#ifdef HAVE_LLSEEK
-#include <syscall.h>
-
-#else /* HAVE_LLSEEK */
+#include <sys/syscall.h>
+#ifndef HAVE_LLSEEK
#if defined(__alpha__) || defined(__ia64__) || defined(__s390x__)
#define my_llseek lseek
#else
-#include <linux/unistd.h> /* for __NR__llseek */
-
-static int _llseek (unsigned int, unsigned long,
- unsigned long, long long *, unsigned int);
-#ifdef __NR__llseek
+#ifdef SYS__llseek
-static _syscall5(int,_llseek,unsigned int,fd,unsigned long,offset_high,
- unsigned long, offset_low,long long *,result,
- unsigned int, origin)
+#define _llseek(fd, offset_high, offset_low, result, origin) \
+ syscall(SYS__llseek, fd, offset_high, offset_low, result, origin)
#else
-/* no __NR__llseek on compilation machine - might give it explicitly */
+/* no SYS__llseek on compilation machine - might give it explicitly */
static int _llseek (unsigned int fd, unsigned long oh,
unsigned long ol, long long *result,
unsigned int origin) {
diff -ru util-linux-2.12r/fdisk/sfdisk.c util-linux-2.12r-new/fdisk/sfdisk.c
--- util-linux-2.12r/fdisk/sfdisk.c 2005-01-05 08:31:57.000000000 +1000
+++ util-linux-2.12r-new/fdisk/sfdisk.c 2006-10-13 15:48:42.000000000 +1000
@@ -48,7 +48,7 @@
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/utsname.h>
-#include <linux/unistd.h> /* _syscall */
+#include <sys/syscall.h>
#include "nls.h"
-fdisk: fdisk.o llseek.o disksize.o fdiskbsdlabel.o fdisksgilabel.o \
+fdisk: fdisk.o disksize.o fdiskbsdlabel.o fdisksgilabel.o \
fdisksunlabel.o fdiskaixlabel.o i386_sys_types.o partname.o
fdisk.o: fdisk.c fdisk.h
fdiskbsdlabel.o: fdiskbsdlabel.c fdisk.h fdiskbsdlabel.h
diff -pur -x '*.rej' util-linux-2.12r.orig/fdisk/cfdisk.c util-linux-2.12r/fdisk/cfdisk.c
--- util-linux-2.12r.orig/fdisk/cfdisk.c 2005-09-09 21:44:57.000000000 +0000
+++ util-linux-2.12r/fdisk/cfdisk.c 2006-07-08 15:40:23.458901045 +0000
@@ -84,9 +84,6 @@
#include "xstrncpy.h"
#include "common.h"
@@ -177,9 +177,8 @@
-extern long long ext2_llseek(unsigned int fd, long long offset,
- unsigned int origin);
-
#define VERSION UTIL_LINUX_VERSION
#define DEFAULT_DEVICE "/dev/hda"
@@ -552,7 +549,7 @@ die_x(int ret) {
static void
read_sector(char *buffer, long long sect_num) {
- if (ext2_llseek(fd, sect_num*SECTOR_SIZE, SEEK_SET) < 0)
+ if (lseek(fd, sect_num*SECTOR_SIZE, SEEK_SET) < 0)
fatal(_("Cannot seek on disk drive"), 2);
if (read(fd, buffer, SECTOR_SIZE) != SECTOR_SIZE)
fatal(_("Cannot read disk drive"), 2);
@@ -560,7 +557,7 @@ read_sector(char *buffer, long long sect
static void
write_sector(char *buffer, long long sect_num) {
- if (ext2_llseek(fd, sect_num*SECTOR_SIZE, SEEK_SET) < 0)
+ if (lseek(fd, sect_num*SECTOR_SIZE, SEEK_SET) < 0)
fatal(_("Cannot seek on disk drive"), 2);
if (write(fd, buffer, SECTOR_SIZE) != SECTOR_SIZE)
fatal(_("Cannot write disk drive"), 2);
@@ -587,7 +584,7 @@ get_dos_label(int i) {
long long offset;
offset = (p_info[i].first_sector + p_info[i].offset) * SECTOR_SIZE;
- if (ext2_llseek(fd, offset, SEEK_SET) == offset
+ if (lseek(fd, offset, SEEK_SET) == offset
&& read(fd, &sector, sizeof(sector)) == sizeof(sector)) {
dos_copy_to_info(p_info[i].ostype, OSTYPESZ,
sector+DOS_OSTYPE_OFFSET, DOS_OSTYPE_SZ);
@@ -672,7 +669,7 @@ get_linux_label(int i) {
offset = (p_info[i].first_sector + p_info[i].offset) * SECTOR_SIZE
+ 1024;
- if (ext2_llseek(fd, offset, SEEK_SET) == offset
+ if (lseek(fd, offset, SEEK_SET) == offset
&& read(fd, &e2fsb, sizeof(e2fsb)) == sizeof(e2fsb)
&& e2fsb.s_magic[0] + (e2fsb.s_magic[1]<<8) == EXT2_SUPER_MAGIC) {
label = e2fsb.s_volume_name;
@@ -688,7 +685,7 @@ get_linux_label(int i) {
}
offset = (p_info[i].first_sector + p_info[i].offset) * SECTOR_SIZE + 0;
- if (ext2_llseek(fd, offset, SEEK_SET) == offset
+ if (lseek(fd, offset, SEEK_SET) == offset
&& read(fd, &xfsb, sizeof(xfsb)) == sizeof(xfsb)
&& !strncmp(xfsb.s_magic, XFS_SUPER_MAGIC, 4)) {
label = xfsb.s_fname;
@@ -702,7 +699,7 @@ get_linux_label(int i) {
/* jfs? */
offset = (p_info[i].first_sector + p_info[i].offset) * SECTOR_SIZE
+ JFS_SUPER1_OFF;
- if (ext2_llseek(fd, offset, SEEK_SET) == offset
+ if (lseek(fd, offset, SEEK_SET) == offset
&& read(fd, &jfsb, sizeof(jfsb)) == sizeof(jfsb)
&& !strncmp(jfsb.s_magic, JFS_MAGIC, strlen(JFS_MAGIC))) {
label = jfsb.s_label;
@@ -716,7 +713,7 @@ get_linux_label(int i) {
/* reiserfs? */
offset = (p_info[i].first_sector + p_info[i].offset) * SECTOR_SIZE
+ REISERFS_DISK_OFFSET_IN_BYTES;
- if (ext2_llseek(fd, offset, SEEK_SET) == offset
+ if (lseek(fd, offset, SEEK_SET) == offset
&& read(fd, &reiserfsb, sizeof(reiserfsb)) == sizeof(reiserfsb)
&& has_reiserfs_magic_string(&reiserfsb, &reiserfs_is_3_6)) {
if (reiserfs_is_3_6) {
@@ -1860,7 +1857,7 @@ write_part_table(void) {
while (!done) {
mvaddstr(COMMAND_LINE_Y, COMMAND_LINE_X,
- _("Are you sure you want write the partition table "
+ _("Are you sure you want to write the partition table "
"to disk? (yes or no): "));
len = get_string(response, LINE_LENGTH, NULL);
clear_warning();
diff -pur -x '*.rej' util-linux-2.12r.orig/fdisk/fdisk.c util-linux-2.12r/fdisk/fdisk.c
--- util-linux-2.12r.orig/fdisk/fdisk.c 2004-12-18 02:00:31.000000000 +0000
+++ util-linux-2.12r/fdisk/fdisk.c 2006-07-08 15:40:23.461899841 +0000
@@ -239,8 +239,8 @@ void fatal(enum failure why) {
static void
seek_sector(int fd, unsigned int secno) {
- long long offset = (long long) secno * sector_size;
- if (ext2_llseek(fd, offset, SEEK_SET) == (long long) -1)
+ off_t offset = (off_t) secno * sector_size;
+ if (lseek(fd, offset, SEEK_SET) == (off_t) -1)
fatal(unable_to_seek);
}
diff -pur -x '*.rej' util-linux-2.12r.orig/fdisk/fdisk.h util-linux-2.12r/fdisk/fdisk.h
--- util-linux-2.12r.orig/fdisk/fdisk.h 2004-12-15 18:19:06.000000000 +0000
+++ util-linux-2.12r/fdisk/fdisk.h 2006-07-08 15:40:23.462899439 +0000
@@ -26,9 +26,6 @@
#define cround(n) (display_in_cyl_units ? ((n)/units_per_sector)+1 : (n))
#define scround(x) (((x)+units_per_sector-1)/units_per_sector)
-extern long long ext2_llseek(unsigned int fd, long long offset,
- unsigned int origin);
-
#if defined(__GNUC__) && (defined(__arm__) || defined(__alpha__))
# define PACKED __attribute__ ((packed))
#else
diff -pur -x '*.rej' util-linux-2.12r.orig/fdisk/fdiskbsdlabel.c util-linux-2.12r/fdisk/fdiskbsdlabel.c
--- util-linux-2.12r.orig/fdisk/fdiskbsdlabel.c 2003-07-13 21:12:47.000000000 +0000
+++ util-linux-2.12r/fdisk/fdiskbsdlabel.c 2006-07-08 15:40:23.463899038 +0000
@@ -566,7 +566,7 @@ xbsd_write_bootstrap (void)
sector = get_start_sect(xbsd_part);
#endif
#ifndef use_lseek
- if (ext2_llseek (fd, (long long) sector * SECTOR_SIZE, SEEK_SET) == -1)
+ if (lseek (fd, (off_t) sector * SECTOR_SIZE, SEEK_SET) == -1)
fatal (unable_to_seek);
if (BSD_BBSIZE != write (fd, disklabelbuffer, BSD_BBSIZE))
fatal (unable_to_write);
@@ -735,7 +735,7 @@ xbsd_readlabel (struct partition *p, str
sector = 0;
#endif
- if (ext2_llseek (fd, (long long) sector * SECTOR_SIZE, SEEK_SET) == -1)
+ if (lseek (fd, (off_t) sector * SECTOR_SIZE, SEEK_SET) == -1)
fatal (unable_to_seek);
if (BSD_BBSIZE != read (fd, disklabelbuffer, BSD_BBSIZE))
fatal (unable_to_read);
@@ -781,12 +781,12 @@ xbsd_writelabel (struct partition *p, st
#if defined (__alpha__) && BSD_LABELSECTOR == 0
alpha_bootblock_checksum (disklabelbuffer);
- if (ext2_llseek (fd, (long long) 0, SEEK_SET) == -1)
+ if (lseek (fd, (off_t) 0, SEEK_SET) == -1)
fatal (unable_to_seek);
if (BSD_BBSIZE != write (fd, disklabelbuffer, BSD_BBSIZE))
fatal (unable_to_write);
#else
- if (ext2_llseek (fd, (long long) sector * SECTOR_SIZE + BSD_LABELOFFSET,
+ if (lseek (fd, (off_t) sector * SECTOR_SIZE + BSD_LABELOFFSET,
SEEK_SET) == -1)
fatal (unable_to_seek);
if (sizeof (struct xbsd_disklabel) != write (fd, d, sizeof (struct xbsd_disklabel)))
diff -pur -x '*.rej' util-linux-2.12r.orig/fdisk/fdisksgilabel.c util-linux-2.12r/fdisk/fdisksgilabel.c
--- util-linux-2.12r.orig/fdisk/fdisksgilabel.c 2004-12-18 01:53:45.000000000 +0000
+++ util-linux-2.12r/fdisk/fdisksgilabel.c 2006-07-08 15:40:23.464898637 +0000
@@ -379,7 +379,7 @@ sgi_write_table(void) {
*/
sgiinfo *info = fill_sgiinfo();
int infostartblock = SSWAP32(sgilabel->directory[0].vol_file_start);
- if (ext2_llseek(fd, (long long)infostartblock*
+ if (lseek(fd, (off_t) infostartblock*
SECTOR_SIZE, SEEK_SET) < 0)
fatal(unable_to_seek);
if (write(fd, info, SECTOR_SIZE) != SECTOR_SIZE)
diff -pur -x '*.rej' util-linux-2.12r.orig/fdisk/sfdisk.c util-linux-2.12r/fdisk/sfdisk.c
--- util-linux-2.12r.orig/fdisk/sfdisk.c 2005-01-04 22:31:57.000000000 +0000
+++ util-linux-2.12r/fdisk/sfdisk.c 2006-07-08 15:40:23.467897432 +0000
@@ -164,36 +164,17 @@ fatal(char *s, ...) {
/*
* sseek: seek to specified sector - return 0 on failure
*
- * For >4GB disks lseek needs a > 32bit arg, and we have to use llseek.
- * On the other hand, a 32 bit sector number is OK until 2TB.
- * The routines _llseek and sseek below are the only ones that
- * know about the loff_t type.
- *
* Note: we use 512-byte sectors here, irrespective of the hardware ss.
*/
-#undef use_lseek
-#if defined (__alpha__) || defined (__ia64__) || defined (__x86_64__) || defined (__s390x__)
-#define use_lseek
-#endif
-
-#ifndef use_lseek
-static __attribute__used
-_syscall5(int, _llseek, unsigned int, fd, ulong, hi, ulong, lo,
- loff_t *, res, unsigned int, wh);
+#define _llseek(fd, hi, lo, res, wh) \
+ syscall(SYS__llseek, fd, hi, lo, res, wh)
#endif
-#endif
static int
diff -ru util-linux-2.12r/lib/my_reboot.c util-linux-2.12r-new/lib/my_reboot.c
--- util-linux-2.12r/lib/my_reboot.c 1999-07-09 12:56:36.000000000 +1000
+++ util-linux-2.12r-new/lib/my_reboot.c 2006-10-13 20:46:42.000000000 +1000
@@ -23,10 +23,11 @@
#else /* no USE_LIBC */
sseek(char *dev, unsigned int fd, unsigned long s) {
- loff_t in, out;
- in = ((loff_t) s << 9);
+ off_t in, out;
+ in = ((off_t) s << 9);
out = 1;
/* direct syscall version */
-#include <linux/unistd.h>
+#include <sys/syscall.h>
-#ifdef _syscall3
-_syscall3(int, reboot, int, magic, int, magic_too, int, cmd);
+#ifdef SYS_reboot
+#define reboot(magic, magic2, cmd) \
+ syscall(SYS_reboot, magic, magic2, cmd)
#else
/* Let us hope we have a 3-argument reboot here */
extern int reboot(int, int, int);
diff -ru util-linux-2.12r/misc-utils/setterm.c util-linux-2.12r-new/misc-utils/setterm.c
--- util-linux-2.12r/misc-utils/setterm.c 2003-10-18 02:17:51.000000000 +1000
+++ util-linux-2.12r-new/misc-utils/setterm.c 2006-10-13 20:54:06.000000000 +1000
@@ -119,14 +119,13 @@
#if __GNU_LIBRARY__ < 5
#ifndef __alpha__
-# include <linux/unistd.h>
-#define __NR_klogctl __NR_syslog
-_syscall3(int, klogctl, int, type, char*, buf, int, len);
+# include <sys/syscall.h>
+#define klogctl(type, buf, len) \
+ syscall(SYS_syslog, type, buf, len)
#else /* __alpha__ */
#define klogctl syslog
#endif
#endif
-extern int klogctl(int type, char *buf, int len);
/* Constants. */
diff -ru util-linux-2.12r/mount/swapon.c util-linux-2.12r-new/mount/swapon.c
--- util-linux-2.12r/mount/swapon.c 2004-12-22 19:50:19.000000000 +1000
+++ util-linux-2.12r-new/mount/swapon.c 2006-10-13 16:08:19.000000000 +1000
@@ -82,11 +82,11 @@
#else
/* We want a swapon with two args, but have an old libc.
Build the kernel call by hand. */
-#include <linux/unistd.h>
-static
-_syscall2(int, swapon, const char *, path, int, flags);
-static
-_syscall1(int, swapoff, const char *, path);
+#include <sys/syscall.h>
+#define swapon(path, flags) \
+ syscall(SYS_swapon, path, flags)
+#define swapoff(path) \
+ syscall(SYS_swapoff, path)
#endif
#else
/* just do as libc says */
diff -ru util-linux-2.12r/mount/umount.c util-linux-2.12r-new/mount/umount.c
--- util-linux-2.12r/mount/umount.c 2005-09-11 04:07:38.000000000 +1000
+++ util-linux-2.12r-new/mount/umount.c 2006-10-13 20:43:22.000000000 +1000
@@ -37,14 +37,13 @@
#else /* MNT_FORCE */
/* Does the present kernel source know about umount2? */
-#include <linux/unistd.h>
-#ifdef __NR_umount2
+#include <sys/syscall.h>
+#ifdef SYS_umount2
-static int umount2(const char *path, int flags);
+#define umount2(path, flags) \
+ syscall(SYS_umount2, path, flags)
-_syscall2(int, umount2, const char *, path, int, flags);
-
-#else /* __NR_umount2 */
+#else /* SYS_umount2 */
static int
umount2(const char *path, int flags) {
@@ -52,7 +51,7 @@
errno = ENOSYS;
return -1;
-#ifndef use_lseek
- if (_llseek (fd, in>>32, in & 0xffffffff, &out, SEEK_SET) != 0) {
-#else
if ((out = lseek(fd, in, SEEK_SET)) != in) {
-#endif
- perror("llseek");
+ perror("lseek");
error(_("seek error on %s - cannot seek to %lu\n"), dev, s);
return 0;
}
diff -pur -x '*.rej' util-linux-2.12r.orig/partx/partx.c util-linux-2.12r/partx/partx.c
--- util-linux-2.12r.orig/partx/partx.c 2004-08-23 20:13:27.000000000 +0000
+++ util-linux-2.12r/partx/partx.c 2006-07-08 15:40:23.469896630 +0000
@@ -330,34 +330,15 @@ xmalloc (size_t size) {
return t;
}
-#endif /* __NR_umount2 */
+#endif /* SYS_umount2 */
#if !defined(MNT_FORCE)
/* dare not try to include <linux/mount.h> -- lots of errors */
diff -ru util-linux-2.12r/partx/partx.c util-linux-2.12r-new/partx/partx.c
--- util-linux-2.12r/partx/partx.c 2004-08-24 06:13:27.000000000 +1000
+++ util-linux-2.12r-new/partx/partx.c 2006-10-13 21:01:34.000000000 +1000
@@ -338,10 +338,9 @@
#endif
#ifdef NEED__llseek
-/*
- * sseek: seek to specified sector
- */
-#if !defined (__alpha__) && !defined (__ia64__) && !defined (__s390x__) && !defined(__x86_64__)
-#define NEED__llseek
-#endif
-
-#ifdef NEED__llseek
-#include <linux/unistd.h> /* _syscall */
-static
-_syscall5(int, _llseek, uint, fd, ulong, hi, ulong, lo,
- long long *, res, uint, wh);
+#include <sys/syscall.h>
+#define _llseek(fd, hi, lo, res, wh) \
+ syscall(SYS__llseek, fd, hi, lo, res, wh)
#endif
-#endif
-
static int
diff -ru util-linux-2.12r/sys-utils/dmesg.c util-linux-2.12r-new/sys-utils/dmesg.c
--- util-linux-2.12r/sys-utils/dmesg.c 2004-05-05 02:38:12.000000000 +1000
+++ util-linux-2.12r-new/sys-utils/dmesg.c 2006-10-13 21:05:10.000000000 +1000
@@ -29,7 +29,7 @@
* Only function 3 is allowed to non-root processes.
*/
sseek(int fd, unsigned int secnr) {
long long in, out;
in = ((long long) secnr << 9);
out = 1;
-#include <linux/unistd.h>
+#include <sys/syscall.h>
#include <stdio.h>
#include <getopt.h>
#include <stdlib.h>
@@ -38,8 +38,8 @@
#if __GNU_LIBRARY__ < 5
#ifndef __alpha__
-# define __NR_klogctl __NR_syslog
- static inline _syscall3(int, klogctl, int, type, char *, b, int, len);
+# define klogctl(type, b, len) \
+ syscall(SYS_syslog, type, b, len)
#else /* __alpha__ */
#define klogctl syslog
#endif
-#ifdef NEED__llseek
- if (_llseek (fd, in>>32, in & 0xffffffff, &out, SEEK_SET) != 0
- || out != in)
-#else
if ((out = lseek(fd, in, SEEK_SET)) != in)
-#endif
{
- fprintf(stderr, "llseek error\n");
+ fprintf(stderr, "lseek error\n");
return -1;
}
return 0;