Submitted By: DJ Lucas -- Date: 2004-02-03 Initial Package Version: 2.12 Origin: Relevant parts for 2.6 ripped from debian util-linux-2.12-6.patch Description: This patch allows util-linux to compile against raw or sanitized 2.6 kernel headers. Most changes taken directly from debian patch, but excluded were all pg/rd changes and termios changes in agetty. Also changed MCONFIG to be LFS specific while I was at it, so that a simple './configure && make && make install' will do the job. diff -Naur util-linux-2.12-orig/MCONFIG util-linux-2.12/MCONFIG --- util-linux-2.12-orig/MCONFIG 2002-11-25 04:29:48.000000000 -0600 +++ util-linux-2.12/MCONFIG 2004-02-03 00:04:35.037362320 -0600 @@ -73,7 +73,7 @@ # If HAVE_KILL is set to "yes", then kill will not be built or # installed from the misc-utils subdirectory. # (There is also a kill in the procps package.) -HAVE_KILL=no +HAVE_KILL=yes # If ALLOW_VCS_USE is set to "yes", then login will chown /dev/vcsN # to the current user, allowing her to make a screendump and do other @@ -88,7 +88,7 @@ # If HAVE_SLN is set to "yes", then sln won't be installed # (but the man page sln.8 will be installed anyway). # sln also comes with libc and glibc. -HAVE_SLN=no +HAVE_SLN=yes # If HAVE_FDUTILS is set to "yes", then setfdprm won't be installed. HAVE_FDUTILS=no diff -Naur util-linux-2.12-orig/disk-utils/Makefile util-linux-2.12/disk-utils/Makefile --- util-linux-2.12-orig/disk-utils/Makefile 2002-11-02 07:52:47.000000000 -0600 +++ util-linux-2.12/disk-utils/Makefile 2004-02-02 20:07:13.998329328 -0600 @@ -50,6 +50,8 @@ fsck.minix.o mkfs.minix.o: bitops.h minix.h +mkfs.minix mkfs.bfs mkswap: $(LIB)/get_blocks.o + install: all $(INSTALLDIR) $(SBINDIR) $(USRBINDIR) $(ETCDIR) $(INSTALLBIN) $(SBIN) $(SBINDIR) diff -Naur util-linux-2.12-orig/disk-utils/blockdev.c util-linux-2.12/disk-utils/blockdev.c --- util-linux-2.12-orig/disk-utils/blockdev.c 2002-03-08 16:57:02.000000000 -0600 +++ util-linux-2.12/disk-utils/blockdev.c 2004-02-02 20:08:26.759267984 -0600 @@ -24,8 +24,8 @@ #define BLKRASET _IO(0x12,98) #define BLKRAGET _IO(0x12,99) #define BLKSSZGET _IO(0x12,104) -#define BLKBSZGET _IOR(0x12,112,sizeof(int)) -#define BLKBSZSET _IOW(0x12,113,sizeof(int)) +#define BLKBSZGET _IOR(0x12,112,size_t) +#define BLKBSZSET _IOW(0x12,113,size_t) #endif /* Maybe could be included */ diff -Naur util-linux-2.12-orig/disk-utils/elvtune.c util-linux-2.12/disk-utils/elvtune.c --- util-linux-2.12-orig/disk-utils/elvtune.c 2002-03-08 16:57:49.000000000 -0600 +++ util-linux-2.12/disk-utils/elvtune.c 2004-02-02 20:09:25.383355768 -0600 @@ -37,8 +37,8 @@ int max_bomb_segments; } blkelv_ioctl_arg_t; -#define BLKELVGET _IOR(0x12,106,sizeof(blkelv_ioctl_arg_t)) -#define BLKELVSET _IOW(0x12,107,sizeof(blkelv_ioctl_arg_t)) +#define BLKELVGET _IOR(0x12,106,size_t) +#define BLKELVSET _IOW(0x12,107,size_t) static void usage(void) { diff -Naur util-linux-2.12-orig/disk-utils/mkfs.bfs.c util-linux-2.12/disk-utils/mkfs.bfs.c --- util-linux-2.12-orig/disk-utils/mkfs.bfs.c 2002-03-08 16:58:05.000000000 -0600 +++ util-linux-2.12/disk-utils/mkfs.bfs.c 2004-02-02 20:13:12.365849184 -0600 @@ -10,17 +10,12 @@ #include #include #include -#include #include #include #include #include #include "nls.h" - -/* cannot include */ -#ifndef BLKGETSIZE -#define BLKGETSIZE _IO(0x12,96) /* return device size */ -#endif +#include "get_blocks.h" #define BFS_ROOT_INO 2 #define BFS_NAMELEN 14 @@ -181,13 +176,9 @@ else if (optind != argc) usage(); - if (ioctl(fd, BLKGETSIZE, &total_blocks) == -1) { - if (!user_specified_total_blocks) { - perror("BLKGETSIZE"); - fatal(_("cannot get size of %s"), device); - } - total_blocks = user_specified_total_blocks; - } else if (user_specified_total_blocks) { + total_blocks = get_blocks(fd); + + if (user_specified_total_blocks) { if (user_specified_total_blocks > total_blocks) fatal(_("blocks argument too large, max is %lu"), total_blocks); diff -Naur util-linux-2.12-orig/disk-utils/mkfs.c util-linux-2.12/disk-utils/mkfs.c --- util-linux-2.12-orig/disk-utils/mkfs.c 2002-03-08 16:58:15.000000000 -0600 +++ util-linux-2.12/disk-utils/mkfs.c 2004-02-02 20:15:51.670631176 -0600 @@ -36,7 +36,7 @@ int main(int argc, char *argv[]) { - char progname[NAME_MAX]; + char progname; char *fstype = NULL; int i, more = 0, verbose = 0; char *oldpath, *newpath; @@ -92,7 +92,12 @@ } sprintf(newpath, "%s:%s\n", SEARCH_PATH, oldpath); putenv(newpath); - snprintf(progname, sizeof(progname), PROGNAME, fstype); + progname = (char *) malloc(sizeof(PROGNAME) + strlen(fstype) + 1); + if (!progname) { + fprintf(stderr, _("%s: Out of memory!\n"), "mkfs"); + exit(1); + } + sprintf(progname, PROGNAME, fstype); argv[--optind] = progname; if (verbose) { diff -Naur util-linux-2.12-orig/disk-utils/mkfs.minix.c util-linux-2.12/disk-utils/mkfs.minix.c --- util-linux-2.12-orig/disk-utils/mkfs.minix.c 2002-10-25 17:25:15.000000000 -0500 +++ util-linux-2.12/disk-utils/mkfs.minix.c 2004-02-02 20:22:07.737460328 -0600 @@ -68,16 +68,12 @@ #include #include #include -#include #include #include #include "minix.h" #include "nls.h" - -#ifndef BLKGETSIZE -#define BLKGETSIZE _IO(0x12,96) /* return device size */ -#endif +#include "get_blocks.h" #ifdef MINIX2_SUPER_MAGIC2 #define HAVE_MINIX2 1 @@ -200,37 +196,6 @@ } static long -valid_offset (int fd, int offset) { - char ch; - - if (lseek (fd, offset, 0) < 0) - return 0; - if (read (fd, &ch, 1) < 1) - return 0; - return 1; -} - -static int -count_blocks (int fd) { - int high, low; - - low = 0; - for (high = 1; valid_offset (fd, high); high *= 2) - low = high; - while (low < high - 1) - { - const int mid = (low + high) / 2; - - if (valid_offset (fd, mid)) - low = mid; - else - high = mid; - } - valid_offset (fd, 0); - return (low + 1); -} - -static int get_size(const char *file) { int fd; long size; @@ -240,12 +205,8 @@ perror(file); exit(1); } - if (ioctl(fd, BLKGETSIZE, &size) >= 0) { - close(fd); - return (size * 512); - } - - size = count_blocks(fd); + size = get_blocks(fd); + close(fd); return size; } @@ -695,8 +656,10 @@ } } - if (device_name && !BLOCKS) - BLOCKS = get_size (device_name) / 1024; + if (device_name && !BLOCKS) { + int sectors_per_block = 1024 / 512; + BLOCKS = get_size (device_name) / sectors_per_block; + } if (!device_name || BLOCKS<10) { usage(); } diff -Naur util-linux-2.12-orig/disk-utils/mkswap.c util-linux-2.12/disk-utils/mkswap.c --- util-linux-2.12-orig/disk-utils/mkswap.c 2002-10-31 19:52:29.000000000 -0600 +++ util-linux-2.12/disk-utils/mkswap.c 2004-02-02 20:29:58.877836104 -0600 @@ -36,10 +36,10 @@ #include #include #include -#include /* for _IO */ #include #include #include "nls.h" +#include "get_blocks.h" /* Try to get PAGE_SIZE from libc or kernel includes */ #ifdef HAVE_sys_user_h @@ -52,14 +52,6 @@ #endif #endif -#ifndef _IO -/* pre-1.3.45 */ -#define BLKGETSIZE 0x1260 -#else -/* same on i386, m68k, arm; different on alpha, mips, sparc, ppc */ -#define BLKGETSIZE _IO(0x12,96) -#endif - static char * program_name = "mkswap"; static char * device_name = NULL; static int DEV = -1; @@ -382,39 +374,11 @@ printf(_("%d bad pages\n"), badpages); } -static long -valid_offset (int fd, off_t offset) { - char ch; - - if (lseek (fd, offset, 0) < 0) - return 0; - if (read (fd, &ch, 1) < 1) - return 0; - return 1; -} - -static off_t -find_size (int fd) { - off_t high, low; - - low = 0; - for (high = 1; high > 0 && valid_offset (fd, high); high *= 2) - low = high; - while (low < high - 1) { - const off_t mid = (low + high) / 2; - - if (valid_offset (fd, mid)) - low = mid; - else - high = mid; - } - return (low + 1); -} - /* return size in pages, to avoid integer overflow */ static long get_size(const char *file) { int fd; + int sectors_per_page = pagesize / 512; long size; fd = open(file, O_RDONLY); @@ -422,14 +386,10 @@ perror(file); exit(1); } - if (ioctl(fd, BLKGETSIZE, &size) >= 0) { - int sectors_per_page = pagesize/512; - size /= sectors_per_page; - } else { - size = find_size(fd) / pagesize; - } + size = get_blocks(fd); + close(fd); - return size; + return (size / sectors_per_page); } static int @@ -553,8 +513,11 @@ maxpages = PAGES; else if (linux_version_code() >= MAKE_VERSION(2,2,1)) maxpages = V1_MAX_PAGES; - else + else { maxpages = V1_OLD_MAX_PAGES; + if (maxpages > V1_MAX_PAGES) + maxpages = V1_MAX_PAGES; + } if (PAGES > maxpages) { PAGES = maxpages; diff -Naur util-linux-2.12-orig/fdisk/Makefile util-linux-2.12/fdisk/Makefile --- util-linux-2.12-orig/fdisk/Makefile 2002-11-24 11:33:58.000000000 -0600 +++ util-linux-2.12/fdisk/Makefile 2004-02-02 20:31:45.965556296 -0600 @@ -39,7 +39,7 @@ endif endif -cfdisk: cfdisk.o llseek.o i386_sys_types.o $(LIB)/xstrncpy.o +cfdisk: cfdisk.o llseek.o i386_sys_types.o $(LIB)/xstrncpy.o $(LIB)/get_blocks.o ifeq "$(HAVE_SLANG)" "yes" $(CC) $(LDFLAGS) $^ -o $@ $(LIBSLANG) else @@ -56,14 +56,14 @@ ln -s sfdisk activate fdisk: fdisk.o llseek.o fdiskbsdlabel.o fdisksgilabel.o fdisksunlabel.o \ - fdiskaixlabel.o i386_sys_types.o partname.o + fdiskaixlabel.o i386_sys_types.o partname.o $(LIB)/get_blocks.o fdisk.o: fdisk.c fdisk.h fdiskbsdlabel.o: fdiskbsdlabel.c fdisk.h fdiskbsdlabel.h fdisksunlabel.o: fdisksunlabel.c fdisksunlabel.h fdisk.h fdiskaixlabel.o: fdiskaixlabel.c fdiskaixlabel.h fdisk.h fdisk.o cfdisk.o sfdisk.o fdiskbsdlabel.o fdisksunlabel.o \ fdisksgilabel.o fdiskaixlabel.o i386_sys_types.o partname.o: common.h -sfdisk: sfdisk.o i386_sys_types.o partname.o +sfdisk: sfdisk.o i386_sys_types.o partname.o $(LIB)/get_blocks.o install: all $(INSTALLDIR) $(SBINDIR) diff -Naur util-linux-2.12-orig/fdisk/cfdisk.c util-linux-2.12/fdisk/cfdisk.c --- util-linux-2.12-orig/fdisk/cfdisk.c 2003-07-13 09:08:59.000000000 -0500 +++ util-linux-2.12/fdisk/cfdisk.c 2004-02-02 20:38:31.535900232 -0600 @@ -80,6 +80,7 @@ #include "nls.h" #include "xstrncpy.h" +#include "get_blocks.h" #include "common.h" extern long long ext2_llseek(unsigned int fd, long long offset, @@ -87,8 +88,13 @@ #define VERSION UTIL_LINUX_VERSION -#define DEFAULT_DEVICE "/dev/hda" -#define ALTERNATE_DEVICE "/dev/sda" +#ifdef __GNU__ + #define DEFAULT_DEVICE "/dev/hd0" + #define ALTERNATE_DEVICE "/dev/sd0" +#else + #define DEFAULT_DEVICE "/dev/hda" + #define ALTERNATE_DEVICE "/dev/sda" +#endif /* With K=1024 we have `binary' megabytes, gigabytes, etc. Some misguided hackers like that. @@ -1601,7 +1607,6 @@ fill_p_info(void) { int pn, i; long long bs, bsz; - unsigned long long bytes; struct partition *p; partition_table buffer; partition_info tmp_ext = { 0, 0, 0, 0, FREE_SPACE, PRIMARY }; @@ -1630,15 +1635,7 @@ ioctl(fd, BLKFLSBUF); /* ignore errors */ /* e.g. Permission Denied */ - if (ioctl(fd, BLKGETSIZE64, &bytes) == 0) - actual_size = (bytes >> 9); - else { - unsigned long sz = 0; - - if (ioctl(fd, BLKGETSIZE, &sz)) - fatal(_("Cannot get disk size"), 3); - actual_size = sz; - } + actual_size = get_blocks(fd); read_sector(buffer.c.b, 0); diff -Naur util-linux-2.12-orig/fdisk/fdisk.c util-linux-2.12/fdisk/fdisk.c --- util-linux-2.12-orig/fdisk/fdisk.c 2003-07-13 13:23:32.000000000 -0500 +++ util-linux-2.12/fdisk/fdisk.c 2004-02-02 20:42:44.626424624 -0600 @@ -21,6 +21,7 @@ #include "nls.h" #include "common.h" +#include "get_blocks.h" #include "fdisk.h" #include "fdisksunlabel.h" @@ -737,7 +738,7 @@ static void get_sectorsize(int fd) { -#if defined(BLKSSZGET) +#if defined(BLKSSZGET) && defined(__linux__) if (!user_set_sector_size && linux_version_code() >= MAKE_VERSION(2,3,3)) { int arg; @@ -820,17 +821,8 @@ pt_sectors ? pt_sectors : kern_sectors ? kern_sectors : 63; - if (ioctl(fd, BLKGETSIZE64, &bytes) == 0) { - /* got bytes */ - } else { - unsigned long longsectors; - - if (ioctl(fd, BLKGETSIZE, &longsectors)) - longsectors = 0; - bytes = ((unsigned long long) longsectors) << 9; - } - - total_number_of_sectors = (bytes >> 9); + total_number_of_sectors = get_blocks(fd); + bytes = ((unsigned long long) total_number_of_sectors) << 9; sector_offset = 1; if (dos_compatible_flag) @@ -2519,8 +2511,7 @@ disk_device = argv[j]; if ((fd = open(disk_device, type_open)) < 0) fatal(unable_to_open); - if (ioctl(fd, BLKGETSIZE, &size)) - fatal(ioctl_error); + size = get_blocks(fd); close(fd); if (opts == 1) printf("%ld\n", size/2); diff -Naur util-linux-2.12-orig/fdisk/fdiskaixlabel.h util-linux-2.12/fdisk/fdiskaixlabel.h --- util-linux-2.12-orig/fdisk/fdiskaixlabel.h 2003-07-13 08:12:12.000000000 -0500 +++ util-linux-2.12/fdisk/fdiskaixlabel.h 2004-02-02 20:43:38.274268912 -0600 @@ -1,4 +1,3 @@ -#include /* for __u32 etc */ /* * Copyright (C) Andreas Neuper, Sep 1998. * This file may be redistributed under diff -Naur util-linux-2.12-orig/fdisk/fdiskbsdlabel.c util-linux-2.12/fdisk/fdiskbsdlabel.c --- util-linux-2.12-orig/fdisk/fdiskbsdlabel.c 2003-07-13 13:27:14.000000000 -0500 +++ util-linux-2.12/fdisk/fdiskbsdlabel.c 2004-02-02 20:50:17.087640064 -0600 @@ -52,7 +52,6 @@ #include #include "nls.h" -#include #include #include "common.h" @@ -515,7 +514,7 @@ xbsd_write_bootstrap (void) { char *bootdir = BSD_LINUX_BOOTDIR; - char path[MAXPATHLEN]; + char *path; char *dkbasename; struct xbsd_disklabel dl; char *d, *p, *e; @@ -532,9 +531,15 @@ line_ptr[strlen (line_ptr)-1] = '\0'; dkbasename = line_ptr; } - snprintf (path, sizeof(path), "%s/%sboot", bootdir, dkbasename); - if (!xbsd_get_bootstrap (path, disklabelbuffer, (int) xbsd_dlabel.d_secsize)) + path = (char *) malloc (sizeof("/boot") + 1 + strlen (bootdir) + + strlen (dkbasename)); + if (!path) + fatal (out_of_memory); + sprintf (path, "%s/%sboot", bootdir, dkbasename); + if (!xbsd_get_bootstrap (path, disklabelbuffer, (int) xbsd_dlabel.d_secsize)) { + free (path); return; + } /* We need a backup of the disklabel (xbsd_dlabel might have changed). */ d = &disklabelbuffer[BSD_LABELSECTOR * SECTOR_SIZE]; @@ -543,10 +548,13 @@ /* The disklabel will be overwritten by 0's from bootxx anyway */ bzero (d, sizeof (struct xbsd_disklabel)); + sprintf (path, "%s/boot%s", bootdir, dkbasename); snprintf (path, sizeof(path), "%s/boot%s", bootdir, dkbasename); if (!xbsd_get_bootstrap (path, &disklabelbuffer[xbsd_dlabel.d_secsize], - (int) xbsd_dlabel.d_bbsize - xbsd_dlabel.d_secsize)) + (int) xbsd_dlabel.d_bbsize - xbsd_dlabel.d_secsize)) { + free(path); return; + } e = d + sizeof (struct xbsd_disklabel); for (p=d; p < e; p++) @@ -579,6 +587,8 @@ #endif sync_disks (); + + free(path); } static void diff -Naur util-linux-2.12-orig/fdisk/fdiskbsdlabel.h util-linux-2.12/fdisk/fdiskbsdlabel.h --- util-linux-2.12-orig/fdisk/fdiskbsdlabel.h 2002-10-31 07:45:34.000000000 -0600 +++ util-linux-2.12/fdisk/fdiskbsdlabel.h 2004-02-02 21:02:27.263636440 -0600 @@ -31,10 +31,10 @@ * SUCH DAMAGE. */ -#include /* for __u32, __u16, __u8, __s16 */ +#include /* for uint32_t, uint16_t, uint8_t, int16_t */ #ifndef BSD_DISKMAGIC -#define BSD_DISKMAGIC ((__u32) 0x82564557) +#define BSD_DISKMAGIC ((uint32_t) 0x82564557) #endif #ifndef BSD_MAXPARTITIONS @@ -60,31 +60,30 @@ #define BSD_SBSIZE 8192 /* max size of fs superblock */ struct xbsd_disklabel { - __u32 d_magic; /* the magic number */ - __s16 d_type; /* drive type */ - __s16 d_subtype; /* controller/d_type specific */ - char d_typename[16]; /* type name, e.g. "eagle" */ - char d_packname[16]; /* pack identifier */ + uint32_t d_magic; /* the magic number */ + int16_t d_type; /* drive type */ + int16_t d_subtype; /* controller/d_type specific */ + char d_typename[16]; /* type name, e.g. "eagle" */ + char d_packname[16]; /* pack identifier */ /* disk geometry: */ - __u32 d_secsize; /* # of bytes per sector */ - __u32 d_nsectors; /* # of data sectors per track */ - __u32 d_ntracks; /* # of tracks per cylinder */ - __u32 d_ncylinders; /* # of data cylinders per unit */ - __u32 d_secpercyl; /* # of data sectors per cylinder */ - __u32 d_secperunit; /* # of data sectors per unit */ - /* + uint32_t d_secsize; /* # of bytes per sector */ + uint32_t d_nsectors; /* # of data sectors per track */ + uint32_t d_ntracks; /* # of tracks per cylinder */ + uint32_t d_ncylinders; /* # of data cylinders per unit */ + uint32_t d_secpercyl; /* # of data sectors per cylinder */ + uint32_t d_secperunit; /* # of data sectors per unit */ /* * Spares (bad sector replacements) below * are not counted in d_nsectors or d_secpercyl. * Spare sectors are assumed to be physical sectors * which occupy space at the end of each track and/or cylinder. */ - __u16 d_sparespertrack; /* # of spare sectors per track */ - __u16 d_sparespercyl; /* # of spare sectors per cylinder */ + uint16_t d_sparespertrack; /* # of spare sectors per track */ + uint16_t d_sparespercyl; /* # of spare sectors per cylinder */ /* * Alternate cylinders include maintenance, replacement, * configuration description areas, etc. */ - __u32 d_acylinders; /* # of alt. cylinders per unit */ + uint32_t d_acylinders; /* # of alt. cylinders per unit */ /* hardware characteristics: */ /* @@ -103,30 +102,30 @@ * Finally, d_cylskew is the offset of sector 0 on cylinder N * relative to sector 0 on cylinder N-1. */ - __u16 d_rpm; /* rotational speed */ - __u16 d_interleave; /* hardware sector interleave */ - __u16 d_trackskew; /* sector 0 skew, per track */ - __u16 d_cylskew; /* sector 0 skew, per cylinder */ - __u32 d_headswitch; /* head switch time, usec */ - __u32 d_trkseek; /* track-to-track seek, usec */ - __u32 d_flags; /* generic flags */ + uint16_t d_rpm; /* rotational speed */ + uint16_t d_interleave; /* hardware sector interleave */ + uint16_t d_trackskew; /* sector 0 skew, per track */ + uint16_t d_cylskew; /* sector 0 skew, per cylinder */ + uint32_t d_headswitch; /* head switch time, usec */ + uint32_t d_trkseek; /* track-to-track seek, usec */ + uint32_t d_flags; /* generic flags */ #define NDDATA 5 - __u32 d_drivedata[NDDATA]; /* drive-type specific information */ + uint32_t d_drivedata[NDDATA]; /* drive-type specific information */ #define NSPARE 5 - __u32 d_spare[NSPARE]; /* reserved for future use */ - __u32 d_magic2; /* the magic number (again) */ - __u16 d_checksum; /* xor of data incl. partitions */ + uint32_t d_spare[NSPARE]; /* reserved for future use */ + uint32_t d_magic2; /* the magic number (again) */ + uint16_t d_checksum; /* xor of data incl. partitions */ /* filesystem and partition information: */ - __u16 d_npartitions; /* number of partitions in following */ - __u32 d_bbsize; /* size of boot area at sn0, bytes */ - __u32 d_sbsize; /* max size of fs superblock, bytes */ + uint16_t d_npartitions; /* number of partitions in following */ + uint32_t d_bbsize; /* size of boot area at sn0, bytes */ + uint32_t d_sbsize; /* max size of fs superblock, bytes */ struct xbsd_partition { /* the partition table */ - __u32 p_size; /* number of sectors in partition */ - __u32 p_offset; /* starting sector */ - __u32 p_fsize; /* filesystem basic fragment size */ - __u8 p_fstype; /* filesystem type, see below */ - __u8 p_frag; /* filesystem fragments per block */ - __u16 p_cpg; /* filesystem cylinders per group */ + uint32_t p_size; /* number of sectors in partition */ + uint32_t p_offset; /* starting sector */ + uint32_t p_fsize; /* filesystem basic fragment size */ + uint8_t p_fstype; /* filesystem type, see below */ + uint8_t p_frag; /* filesystem fragments per block */ + uint16_t p_cpg; /* filesystem cylinders per group */ } d_partitions[BSD_MAXPARTITIONS]; /* actually may be more */ }; diff -Naur util-linux-2.12-orig/fdisk/fdisksgilabel.c util-linux-2.12/fdisk/fdisksgilabel.c --- util-linux-2.12-orig/fdisk/fdisksgilabel.c 2003-07-16 13:44:51.000000000 -0500 +++ util-linux-2.12/fdisk/fdisksgilabel.c 2004-02-02 21:42:20.151862136 -0600 @@ -16,13 +16,11 @@ #include /* exit */ #include /* strstr */ #include /* write */ -#include /* ioctl */ #include /* stat */ #include /* assert */ #include #include "nls.h" -#include /* FLOPPY_MAJOR */ #include "common.h" #include "fdisk.h" @@ -100,11 +98,11 @@ static inline unsigned short __swap16(unsigned short x) { - return (((__u16)(x) & 0xFF) << 8) | (((__u16)(x) & 0xFF00) >> 8); + return (((uint16_t)(x) & 0xFF) << 8) | (((uint16_t)(x) & 0xFF00) >> 8); } -static inline __u32 -__swap32(__u32 x) { +static inline uint32_t +__swap32(uint32_t x) { return (((x & 0xFF) << 24) | ((x & 0xFF00) << 8) | ((x & 0xFF0000) >> 8) | @@ -224,8 +222,8 @@ w + 2, _("Device")); for (i = 0 ; i < partitions; i++) { if (sgi_get_num_sectors(i) || debug) { - __u32 start = sgi_get_start_sector(i); - __u32 len = sgi_get_num_sectors(i); + uint32_t start = sgi_get_start_sector(i); + uint32_t len = sgi_get_num_sectors(i); kpi++; /* only count nonempty partitions */ printf( "%2d: %s %4s %9ld %9ld %9ld %2x %s\n", @@ -246,8 +244,8 @@ sgilabel->boot_file); for (i = 0 ; i < volumes; i++) { if (sgilabel->directory[i].vol_file_size) { - __u32 start = SSWAP32(sgilabel->directory[i].vol_file_start); - __u32 len = SSWAP32(sgilabel->directory[i].vol_file_size); + uint32_t start = SSWAP32(sgilabel->directory[i].vol_file_start); + uint32_t len = SSWAP32(sgilabel->directory[i].vol_file_size); char *name = sgilabel->directory[i].vol_file_name; printf(_("%2d: %-10s sector%5u size%8u\n"), i, name, (unsigned int) start, diff -Naur util-linux-2.12-orig/fdisk/fdisksgilabel.h util-linux-2.12/fdisk/fdisksgilabel.h --- util-linux-2.12-orig/fdisk/fdisksgilabel.h 2003-07-13 08:13:17.000000000 -0500 +++ util-linux-2.12/fdisk/fdisksgilabel.h 2004-02-02 21:44:15.131382592 -0600 @@ -1,4 +1,4 @@ -#include /* for __u32 etc */ +#include /* for uint32_t, uint16_t, uint8_t, int16_t */ /* * Copyright (C) Andreas Neuper, Sep 1998. * This file may be modified and redistributed under @@ -96,9 +96,9 @@ #define SGI_INFO_MAGIC 0x00072959 #define SGI_INFO_MAGIC_SWAPPED 0x59290700 #define SSWAP16(x) (other_endian ? __swap16(x) \ - : (__u16)(x)) + : (uint16_t)(x)) #define SSWAP32(x) (other_endian ? __swap32(x) \ - : (__u32)(x)) + : (uint32_t)(x)) /* fdisk.c */ #define sgilabel ((sgi_partition *)MBRbuffer) diff -Naur util-linux-2.12-orig/fdisk/fdisksunlabel.c util-linux-2.12/fdisk/fdisksunlabel.c --- util-linux-2.12-orig/fdisk/fdisksunlabel.c 2003-07-13 08:21:52.000000000 -0500 +++ util-linux-2.12/fdisk/fdisksunlabel.c 2004-02-02 21:48:35.693771088 -0600 @@ -60,10 +60,10 @@ }; static inline unsigned short __swap16(unsigned short x) { - return (((__u16)(x) & 0xFF) << 8) | (((__u16)(x) & 0xFF00) >> 8); + return (((uint16_t)(x) & 0xFF) << 8) | (((uint16_t)(x) & 0xFF00) >> 8); } -static inline __u32 __swap32(__u32 x) { - return (((__u32)(x) & 0xFF) << 24) | (((__u32)(x) & 0xFF00) << 8) | (((__u32)(x) & 0xFF0000) >> 8) | (((__u32)(x) & 0xFF000000) >> 24); +static inline uint32_t __swap32(uint32_t x) { + return (((uint32_t)(x) & 0xFF) << 24) | (((uint32_t)(x) & 0xFF00) << 8) | (((uint32_t)(x) & 0xFF0000) >> 8) | (((uint32_t)(x) & 0xFF000000) >> 24); } int @@ -249,7 +249,7 @@ void create_sunlabel(void) { - struct hd_geometry geometry; + struct geom geometry; unsigned int ndiv; int i; unsigned char c; @@ -674,8 +674,8 @@ w + 1, _("Device")); for (i = 0 ; i < partitions; i++) { if (sunlabel->partitions[i].num_sectors) { - __u32 start = SSWAP32(sunlabel->partitions[i].start_cylinder) * heads * sectors; - __u32 len = SSWAP32(sunlabel->partitions[i].num_sectors); + uint32_t start = SSWAP32(sunlabel->partitions[i].start_cylinder) * heads * sectors; + uint32_t len = SSWAP32(sunlabel->partitions[i].num_sectors); printf( "%s %c%c %9ld %9ld %9ld%c %2x %s\n", /* device */ partname(disk_device, i+1, w), diff -Naur util-linux-2.12-orig/fdisk/fdisksunlabel.h util-linux-2.12/fdisk/fdisksunlabel.h --- util-linux-2.12-orig/fdisk/fdisksunlabel.h 2003-07-13 08:17:02.000000000 -0500 +++ util-linux-2.12/fdisk/fdisksunlabel.h 2004-02-02 21:52:33.785575632 -0600 @@ -1,4 +1,4 @@ -#include /* for __u16, __u32 */ +#include /* for uint32_t, uint16_t, uint8_t, int16_t */ typedef struct { unsigned char info[128]; /* Informative text string */ @@ -21,8 +21,8 @@ unsigned short nsect; /* Sectors per track */ unsigned char spare3[4]; /* Even more magic... */ struct sun_partition { - __u32 start_cylinder; - __u32 num_sectors; + uint32_t start_cylinder; + uint32_t num_sectors; } partitions[8]; unsigned short magic; /* Magic number */ unsigned short csum; /* Label xor'd checksum */ @@ -32,9 +32,9 @@ #define SUN_LABEL_MAGIC_SWAPPED 0xBEDA #define sunlabel ((sun_partition *)MBRbuffer) #define SSWAP16(x) (other_endian ? __swap16(x) \ - : (__u16)(x)) + : (uint16_t)(x)) #define SSWAP32(x) (other_endian ? __swap32(x) \ - : (__u32)(x)) + : (uint32_t)(x)) /* fdisk.c */ extern char MBRbuffer[MAX_SECTOR_SIZE]; diff -Naur util-linux-2.12-orig/fdisk/sfdisk.c util-linux-2.12/fdisk/sfdisk.c --- util-linux-2.12-orig/fdisk/sfdisk.c 2003-07-13 08:19:24.000000000 -0500 +++ util-linux-2.12/fdisk/sfdisk.c 2004-02-02 22:02:51.521665472 -0600 @@ -49,6 +49,7 @@ #include /* _syscall */ #include "nls.h" #include "common.h" +#include "get_blocks.h" #define SIZE(a) (sizeof(a)/sizeof(a[0])) @@ -130,7 +131,7 @@ * * Note: we use 512-byte sectors here, irrespective of the hardware ss. */ -#if !defined (__alpha__) && !defined (__ia64__) && !defined (__x86_64__) && !defined (__s390x__) +#if defined(__linux__) && !defined (__alpha__) && !defined (__ia64__) && !defined (__x86_64__) && !defined (__s390x__) static _syscall5(int, _llseek, unsigned int, fd, ulong, hi, ulong, lo, loff_t *, res, unsigned int, wh); @@ -142,7 +143,7 @@ in = ((loff_t) s << 9); out = 1; -#if !defined (__alpha__) && !defined (__ia64__) && !defined (__x86_64__) && !defined (__s390x__) +#if defined(__linux__) && !defined (__alpha__) && !defined (__ia64__) && !defined (__x86_64__) && !defined (__s390x__) if (_llseek (fd, in>>32, in & 0xffffffff, &out, SEEK_SET) != 0) { #else if ((out = lseek(fd, in, SEEK_SET)) != in) { @@ -399,21 +400,23 @@ long size; struct geometry R; - if (ioctl(fd, BLKGETSIZE, &size)) { - size = 0; + size = get_blocks(fd); + if (!size) { if (!silent) printf(_("Disk %s: cannot get size\n"), dev); } - if (ioctl(fd, HDIO_GETGEO, &g)) { - g.heads = g.sectors = g.cylinders = g.start = 0; + if (ioctl(fd, HDIO_GETGEO, &g) >= 0) { + R.heads = g.heads; + R.sectors = g.sectors; + R.cylindersize = R.heads * R.sectors; + R.cylinders = (R.cylindersize ? size / R.cylindersize : 0); + R.start = g.start; + } else + { + R.heads = R.sectors = R.cylindersize = R.cylinders = R.start = 0; if (!silent) printf(_("Disk %s: cannot get geometry\n"), dev); } - R.heads = g.heads; - R.sectors = g.sectors; - R.cylindersize = R.heads * R.sectors; - R.cylinders = (R.cylindersize ? size / R.cylindersize : 0); - R.start = g.start; return R; } @@ -721,11 +724,10 @@ /* tell the kernel to reread the partition tables */ static int reread_ioctl(int fd) { - if(ioctl(fd, BLKRRPART)) { - perror("BLKRRPART"); - return -1; - } - return 0; + if(!ioctl(fd, BLKRRPART)) + return 0; + perror("BLKRRPART"); + return -1; } static int @@ -2670,10 +2672,11 @@ if (fd < 0) return; - if(ioctl(fd, BLKGETSIZE, &size)) { + size = get_blocks(fd); + if (!size) { if(!silent) { perror(dev); - fatal(_("BLKGETSIZE ioctl failed for %s\n"), dev); + fatal(_("Disk %s: cannot get size\n"), dev); } return; } diff -Naur util-linux-2.12-orig/hwclock/cmos.c util-linux-2.12/hwclock/cmos.c --- util-linux-2.12-orig/hwclock/cmos.c 2002-07-07 06:08:47.000000000 -0500 +++ util-linux-2.12/hwclock/cmos.c 2004-02-02 22:04:49.387747104 -0600 @@ -46,6 +46,7 @@ #include /* for geteuid() */ #include /* for O_RDWR */ +#include #include "nls.h" diff -Naur util-linux-2.12-orig/hwclock/kd.c util-linux-2.12/hwclock/kd.c --- util-linux-2.12-orig/hwclock/kd.c 2002-07-07 06:16:32.000000000 -0500 +++ util-linux-2.12/hwclock/kd.c 2004-02-02 22:05:08.721807880 -0600 @@ -3,6 +3,7 @@ #include /* for O_RDONLY */ #include #include +#include #include "../defines.h" /* for HAVE_nanosleep */ #include "clock.h" diff -Naur util-linux-2.12-orig/hwclock/rtc.c util-linux-2.12/hwclock/rtc.c --- util-linux-2.12-orig/hwclock/rtc.c 2003-07-05 15:13:27.000000000 -0500 +++ util-linux-2.12/hwclock/rtc.c 2004-02-02 22:05:34.024961216 -0600 @@ -3,6 +3,7 @@ #include /* for O_RDONLY */ #include #include +#include #include "clock.h" #include "nls.h" diff -Naur util-linux-2.12-orig/lib/Makefile util-linux-2.12/lib/Makefile --- util-linux-2.12-orig/lib/Makefile 2002-11-02 07:51:26.000000000 -0600 +++ util-linux-2.12/lib/Makefile 2004-02-02 22:07:43.681250464 -0600 @@ -1,7 +1,8 @@ include ../make_include include ../MCONFIG -all: err.o my_reboot.o setproctitle.o env.o carefulputc.o xstrncpy.o md5.o +all: err.o my_reboot.o setproctitle.o env.o carefulputc.o \ + xstrncpy.o md5.o get_blocks.o err.o: err.c @@ -17,6 +18,8 @@ md5.o: md5.c md5.h +get_blocks.o: get_blocks.h + .PHONY: clean clean: -rm -f *.o *~ core diff -Naur util-linux-2.12-orig/lib/get_blocks.c util-linux-2.12/lib/get_blocks.c --- util-linux-2.12-orig/lib/get_blocks.c 1969-12-31 18:00:00.000000000 -0600 +++ util-linux-2.12/lib/get_blocks.c 2004-02-02 22:11:08.965042584 -0600 @@ -0,0 +1,93 @@ +/* + * unsigned long get_blocks(int fd) + * + * returns the number of 512-byte blocks of fd + * + * Most code ripped from: + * + * mkswap.c + * mkfs.bfs.c + * mkfs.minix.c + * + * by Guillem Jover + * + */ + +#include "../defines.h" +#include "get_blocks.h" +#include +#include +#include +#include + +/* can't #include , because it uses u64... */ +#ifndef BLKGETSIZE +/* return device size */ +#ifndef _IO +/* pre-1.3.45 */ +#define BLKGETSIZE 0x1260 +#else +/* same on i386, m68k, arm; different on alpha, mips, sparc, ppc */ +#define BLKGETSIZE _IO(0x12,96) +#define BLKGETSIZE64 _IOR(0x12,114,long long) +#endif +#endif + +static int +valid_offset (int fd, off_t offset) +{ + char ch; + + if (lseek (fd, offset, 0) < 0) + return 0; + if (read (fd, &ch, 1) < 1) + return 0; + return 1; +} + +static off_t +count_blocks (int fd) +{ + off_t high, low, blocks; + + low = 0; + for (high = 1; high > 0 && valid_offset (fd, high); high *= 2) + low = high; + while (low < high - 1) + { + const off_t mid = (low + high) / 2; + + if (valid_offset (fd, mid)) + low = mid; + else + high = mid; + } + blocks = (low + 1) / 512; + return blocks; +} + +unsigned long +get_blocks (int fd) +{ + struct stat st; + + { + unsigned long blocks; + unsigned long long bytes; + if (ioctl(fd, BLKGETSIZE64, &bytes) == 0) { + blocks = (bytes >> 9); + return blocks; + } else { + blocks = 0; + + if (ioctl(fd, BLKGETSIZE, &blocks) >=0) + return blocks; + } + } + + if (fstat(fd, &st) == 0) + return st.st_size / 512; + + return count_blocks(fd); +} + diff -Naur util-linux-2.12-orig/lib/get_blocks.h util-linux-2.12/lib/get_blocks.h --- util-linux-2.12-orig/lib/get_blocks.h 1969-12-31 18:00:00.000000000 -0600 +++ util-linux-2.12/lib/get_blocks.h 2004-02-02 22:11:08.966042432 -0600 @@ -0,0 +1,7 @@ +#ifndef GET_BLOCKS_H +#define GET_BLOCKS_H + +extern unsigned long get_blocks (int fd); + +#endif + diff -Naur util-linux-2.12-orig/login-utils/last.c util-linux-2.12/login-utils/last.c --- util-linux-2.12-orig/login-utils/last.c 2002-03-08 16:59:41.000000000 -0600 +++ util-linux-2.12/login-utils/last.c 2004-02-02 22:47:36.202531944 -0600 @@ -430,19 +430,15 @@ hostconv(char *arg) { static int first = 1; static char *hostdot, - name[MAXHOSTNAMELEN]; + *name; char *argdot; if (!(argdot = strchr(arg, '.'))) return; if (first) { first = 0; - if (gethostname(name, sizeof(name))) { - perror(_("last: gethostname")); - exit(1); } hostdot = strchr(name, '.'); - } if (hostdot && !strcmp(hostdot, argdot)) *argdot = '\0'; } diff -Naur util-linux-2.12-orig/login-utils/login.c util-linux-2.12/login-utils/login.c --- util-linux-2.12-orig/login-utils/login.c 2003-07-13 13:11:31.000000000 -0500 +++ util-linux-2.12/login-utils/login.c 2004-02-02 23:02:34.439979096 -0600 @@ -202,10 +202,6 @@ #define TTYGRPNAME "tty" /* name of group to own ttys */ -#ifndef MAXPATHLEN -# define MAXPATHLEN 1024 -#endif - /* * This bounds the time given to login. Not a define so it can * be patched on machines where it's too small. @@ -213,7 +209,11 @@ #ifndef __linux__ int timeout = 300; #else -int timeout = 60; /* used in cryptocard.c */ +#if defined(__linux__) || defined(__GNU__) +int timeout = 60; /* used in cryptocard.c */ +#else +int timeout = 300; /* used in cryptocard.c */ +#endif #endif struct passwd *pwd; /* used in cryptocard.c */ @@ -223,7 +223,7 @@ char hostaddress[4]; /* used in checktty.c */ char *hostname; /* idem */ static char *username, *tty_name, *tty_number; -static char thishost[100]; +static char *thishost; static int failures = 1; static pid_t pid; @@ -288,6 +288,7 @@ } } +#ifdef CHOWNVCS /* true if the filedescriptor fd is a console tty, very Linux specific */ static int consoletty(int fd) { @@ -302,6 +303,7 @@ #endif return 0; } +#endif #if USE_PAM /* @@ -356,7 +358,7 @@ int ask, fflag, hflag, pflag, cnt, errsv; int quietlog, passwd_req; char *domain, *ttyn; - char tbuf[MAXPATHLEN + 2], tname[sizeof(_PATH_TTY) + 10]; + char tname[sizeof(_PATH_TTY) + 10]; char *termenv; char *childArgv[10]; char *buff; @@ -398,10 +400,8 @@ * -h is used by other servers to pass the name of the remote * host to login so that it may be placed in utmp and wtmp */ - gethostname(tbuf, sizeof(tbuf)); - xstrncpy(thishost, tbuf, sizeof(thishost)); - domain = index(tbuf, '.'); + domain = index(thishost, '.'); username = tty_name = hostname = NULL; fflag = hflag = pflag = 0; passwd_req = 1; @@ -861,23 +861,21 @@ having the BSD setreuid() */ { - char tmpstr[MAXPATHLEN]; + char *tmpstr; uid_t ruid = getuid(); gid_t egid = getegid(); /* avoid snprintf - old systems do not have it, or worse, have a libc in which snprintf is the same as sprintf */ - if (strlen(pwd->pw_dir) + sizeof(_PATH_HUSHLOGIN) + 2 > MAXPATHLEN) - quietlog = 0; - else { - sprintf(tmpstr, "%s/%s", pwd->pw_dir, _PATH_HUSHLOGIN); - setregid(-1, pwd->pw_gid); - setreuid(0, pwd->pw_uid); - quietlog = (access(tmpstr, R_OK) == 0); - setuid(0); /* setreuid doesn't do it alone! */ - setreuid(ruid, 0); - setregid(-1, egid); - } + tmpstr = malloc(strlen(pwd->pw_dir) + sizeof(_PATH_HUSHLOGIN) + 2); + sprintf(tmpstr, "%s/%s", pwd->pw_dir, _PATH_HUSHLOGIN); + setregid(-1, pwd->pw_gid); + setreuid(0, pwd->pw_uid); + quietlog = (access(tmpstr, R_OK) == 0); + setuid(0); /* setreuid doesn't do it alone! */ + setreuid(ruid, 0); + setregid(-1, egid); + free(tmpstr); } /* for linux, write entries in utmp and wtmp */ @@ -1029,12 +1027,13 @@ /* mailx will give a funny error msg if you forget this one */ { - char tmp[MAXPATHLEN]; + char *tmp; + /* avoid snprintf */ - if (sizeof(_PATH_MAILDIR) + strlen(pwd->pw_name) + 1 < MAXPATHLEN) { - sprintf(tmp, "%s/%s", _PATH_MAILDIR, pwd->pw_name); - setenv("MAIL",tmp,0); - } + tmp = malloc(sizeof(_PATH_MAILDIR) + strlen(pwd->pw_name) + 2); + sprintf(tmp, "%s/%s", _PATH_MAILDIR, pwd->pw_name); + setenv("MAIL", tmp, 0); + free(tmp); } /* LOGNAME is not documented in login(1) but @@ -1181,13 +1180,15 @@ childArgv[childArgc++] = "-c"; childArgv[childArgc++] = buff; } else { - tbuf[0] = '-'; - xstrncpy(tbuf + 1, ((p = rindex(pwd->pw_shell, '/')) ? - p + 1 : pwd->pw_shell), - sizeof(tbuf)-1); + char *tbuf, *shell_cmd; + + tbuf = ((p = rindex(pwd->pw_shell, '/')) ? p + 1 : pwd->pw_shell); + shell_cmd = malloc(strlen(tbuf)); + shell_cmd[0] = '-'; + xstrncpy(shell_cmd + 1, tbuf, strlen(tbuf)-1); childArgv[childArgc++] = pwd->pw_shell; - childArgv[childArgc++] = tbuf; + childArgv[childArgc++] = shell_cmd; } childArgv[childArgc++] = NULL; diff -Naur util-linux-2.12-orig/login-utils/simpleinit.c util-linux-2.12/login-utils/simpleinit.c --- util-linux-2.12-orig/login-utils/simpleinit.c 2002-11-24 16:31:53.000000000 -0600 +++ util-linux-2.12/login-utils/simpleinit.c 2004-02-02 23:03:43.440489424 -0600 @@ -22,7 +22,9 @@ #include #include #include +#include #include +#include #include #include #include diff -Naur util-linux-2.12-orig/login-utils/simpleinit.h util-linux-2.12/login-utils/simpleinit.h --- util-linux-2.12-orig/login-utils/simpleinit.h 2000-11-05 06:41:35.000000000 -0600 +++ util-linux-2.12/login-utils/simpleinit.h 2004-02-02 23:04:26.774901592 -0600 @@ -3,7 +3,7 @@ #define ERRSTRING strerror (errno) -#define COMMAND_SIZE (PIPE_BUF - 4) +#define COMMAND_SIZE (_POSIX_PIPE_BUF - 4) #define COMMAND_TEST 0 /* No wait, signal */ diff -Naur util-linux-2.12-orig/login-utils/wall.c util-linux-2.12/login-utils/wall.c --- util-linux-2.12-orig/login-utils/wall.c 2002-03-08 17:00:19.000000000 -0600 +++ util-linux-2.12/login-utils/wall.c 2004-02-02 23:10:16.875678184 -0600 @@ -150,8 +150,7 @@ time_t now; FILE *fp; int fd; - char *p, *whom, *where, hostname[MAXHOSTNAMELEN], - lbuf[MAXHOSTNAMELEN + 320], + char *p, *whom, *where, *hostname, lbuf[1024], tmpname[sizeof(_PATH_TMP) + 20]; (void)sprintf(tmpname, "%s/wall.XXXXXX", _PATH_TMP); @@ -162,6 +161,9 @@ (void)unlink(tmpname); if (!nobanner) { + char *mesg, *mesg_notice; + int mesg_size, size; + if (!(whom = getlogin()) || !*whom) whom = (pw = getpwuid(getuid())) ? pw->pw_name : "???"; if (!whom || strlen(whom) > 100) @@ -169,7 +171,6 @@ where = ttyname(2); if (!where || strlen(where) > 100) where = "somewhere"; - (void)gethostname(hostname, sizeof(hostname)); (void)time(&now); lt = localtime(&now); @@ -182,13 +183,35 @@ */ /* snprintf is not always available, but the sprintf's here will not overflow as long as %d takes at most 100 chars */ + + mesg_notice = _("Broadcast Message from %s@%s"); + mesg_size = strlen(whom) + strlen(hostname) + + strlen(mesg_notice); + if (!(mesg = malloc(mesg_size))) { + (void)fprintf(stderr, _("%s: Out of memory!\n"), + progname); + exit(1); + } + (void)fprintf(fp, "\r%79s\r\n", " "); - (void)sprintf(lbuf, _("Broadcast Message from %s@%s"), - whom, hostname); - (void)fprintf(fp, "%-79.79s\007\007\r\n", lbuf); - (void)sprintf(lbuf, " (%s) at %d:%02d ...", - where, lt->tm_hour, lt->tm_min); - (void)fprintf(fp, "%-79.79s\r\n", lbuf); + (void)sprintf(mesg, mesg_notice, whom, hostname); + (void)fprintf(fp, "%-79.79s\007\007\r\n", mesg); + + mesg_notice = " (%s) at %d:%02d ..."; + size = strlen(mesg_notice) + strlen(where); + if (mesg_size < size) { + if (!realloc(mesg, size)) { + (void)fprintf(stderr, _("%s: Out of memory!\n"), + progname); + exit(1); + } + } + + (void)sprintf(mesg, mesg_notice, where, + lt->tm_hour, lt->tm_min); + (void)fprintf(fp, "%-79.79s\r\n", mesg); + + free(mesg); } (void)fprintf(fp, "%79s\r\n", " "); diff -Naur util-linux-2.12-orig/misc-utils/cal.c util-linux-2.12/misc-utils/cal.c --- util-linux-2.12-orig/misc-utils/cal.c 2002-10-31 09:36:04.000000000 -0600 +++ util-linux-2.12/misc-utils/cal.c 2004-02-02 23:17:08.082165296 -0600 @@ -300,8 +300,9 @@ { int i, wd; #ifdef ENABLE_WIDECHAR + int j; wchar_t day_headings_wc[22],j_day_headings_wc[29]; - wchar_t wd_wc[10]; + wchar_t wd_wc[10], tmp_wd_wc[10]; #endif strcpy(day_headings,""); @@ -320,15 +321,32 @@ for(i = 0 ; i < 7 ; i++ ) { wd = (i + week1stday) % 7; #ifdef ENABLE_WIDECHAR - mbstowcs(wd_wc,weekday(wd),10); - if (wcswidth(wd_wc,10) < 3) - wcscat(j_day_headings_wc,L" "); - if (wcswidth(wd_wc,10) < 2) { - wcscat(day_headings_wc, L" "); - wcscat(j_day_headings_wc, L" "); + mbstowcs(tmp_wd_wc,weekday(wd),10); + + wmemset(wd_wc, L'\0', 10); + for (j = 0; j < wcslen(tmp_wd_wc); j++) { + wd_wc[j] = tmp_wd_wc[j]; + if (wcswidth(wd_wc,10) > 2) { + wd_wc[j] = L'\0'; + break; + } + } + for (j = wcswidth(wd_wc,10); j < 2; j++) + wcscat(day_headings_wc,L" "); + wcscat(day_headings_wc,wd_wc); + + wmemset(wd_wc, L'\0', 10); + for (j = 0; j < wcslen(tmp_wd_wc); j++) { + wd_wc[j] = tmp_wd_wc[j]; + if (wcswidth(wd_wc,10) > 3) { + wd_wc[j] = L'\0'; + break; + } } - wcsncat(day_headings_wc,wd_wc,2); - wcsncat(j_day_headings_wc,wd_wc,3); + for (j = wcswidth(wd_wc,10); j < 3; j++) + wcscat(j_day_headings_wc,L" "); + wcscat(j_day_headings_wc,wd_wc); + wcscat(day_headings_wc, L" "); wcscat(j_day_headings_wc, L" "); #else @@ -362,6 +380,7 @@ char *p, lineout[300]; #ifdef ENABLE_WIDECHAR wchar_t lineout_wc[300]; + size_t wcs_len; #endif day_array(month, year, days); @@ -372,8 +391,9 @@ */ len = sprintf(lineout, _("%s %d"), full_month[month - 1], year); #ifdef ENABLE_WIDECHAR - if (mbstowcs(lineout_wc,lineout,len) > 0) { - len = wcswidth(lineout_wc,len); + wcs_len = mbstowcs(lineout_wc,lineout,len); + if (wcs_len != (size_t)-1 && wcs_len != 0) { + len = wcswidth(lineout_wc,wcs_len); } else { len = strlen(lineout); } @@ -653,10 +673,11 @@ { #ifdef ENABLE_WIDECHAR wchar_t str_wc[300]; - int str_len; + size_t str_len, wcs_len; - if (mbstowcs(str_wc,str,300) > 0) { - str_len = wcswidth(str_wc,300); + wcs_len = mbstowcs (str_wc,str,300); + if (wcs_len != (size_t)-1 && wcs_len != 0) { + str_len = wcswidth(str_wc,wcs_len); } else { str_len = strlen(str); } diff -Naur util-linux-2.12-orig/misc-utils/mcookie.c util-linux-2.12/misc-utils/mcookie.c --- util-linux-2.12-orig/misc-utils/mcookie.c 2002-03-08 17:00:52.000000000 -0600 +++ util-linux-2.12/misc-utils/mcookie.c 2004-02-02 23:22:08.337519544 -0600 @@ -30,8 +30,9 @@ #include "md5.h" #if HAVE_GETTIMEOFDAY #include -#include #endif +#include +#include #include "nls.h" #define BUFFERSIZE 4096 diff -Naur util-linux-2.12-orig/misc-utils/namei.c util-linux-2.12/misc-utils/namei.c --- util-linux-2.12-orig/misc-utils/namei.c 2002-03-08 17:00:59.000000000 -0600 +++ util-linux-2.12/misc-utils/namei.c 2004-02-02 23:25:16.415927280 -0600 @@ -72,7 +72,8 @@ main(int argc, char **argv) { extern int optind; int c; - char curdir[MAXPATHLEN]; + int curdir_size; + char *curdir; setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); @@ -97,14 +98,28 @@ } } - if(getcwd(curdir, sizeof(curdir)) == NULL){ - (void)fprintf(stderr, - _("namei: unable to get current directory - %s\n"), - curdir); + curdir_size = 1024; + curdir = malloc(curdir_size); + if (curdir==NULL){ + (void)fprintf(stderr, _("namei: out of memory\n")); exit(1); } - + while (getcwd(curdir, curdir_size) == NULL){ + if (errno!=ERANGE){ + (void)fprintf(stderr, + _("namei: unable to get current directory - %s\n"), + curdir); + exit(1); + } + curdir_size *= 2; + realloc(curdir, curdir_size); + if (curdir==NULL){ + (void)fprintf(stderr, _("namei: out of memory\n")); + exit(1); + } + } + for(; optind < argc; optind++){ (void)printf("f: %s\n", argv[optind]); symcount = 1; diff -Naur util-linux-2.12-orig/misc-utils/setterm.c util-linux-2.12/misc-utils/setterm.c --- util-linux-2.12-orig/misc-utils/setterm.c 2002-11-26 11:07:38.000000000 -0600 +++ util-linux-2.12/misc-utils/setterm.c 2004-02-02 23:30:12.816867488 -0600 @@ -112,11 +112,6 @@ #include #include "nls.h" -#ifndef TCGETS -/* TCGETS is either defined in termios.h, or here: */ -#include -#endif - #if __GNU_LIBRARY__ < 5 #ifndef __alpha__ # include @@ -165,19 +160,22 @@ int opt_term, opt_reset, opt_initialize, opt_cursor; int opt_linewrap, opt_snow, opt_softscroll, opt_default, opt_foreground; int opt_background, opt_bold, opt_blink, opt_reverse, opt_underline; -int opt_store, opt_clear, opt_blank, opt_snap, opt_snapfile, opt_standout; -int opt_append, opt_ulcolor, opt_hbcolor, opt_halfbright, opt_repeat; +int opt_store, opt_clear, opt_blank, opt_standout; +int opt_ulcolor, opt_hbcolor, opt_halfbright, opt_repeat; int opt_tabs, opt_clrtabs, opt_regtabs, opt_appcursorkeys, opt_inversescreen; -int opt_msg, opt_msglevel, opt_powersave, opt_powerdown; +int opt_powerdown; int opt_blength, opt_bfreq; +int opt_append, opt_snap, opt_snapfile; +int opt_powersave; +int opt_msg, opt_msglevel; /* Option controls. The variable names have been contracted to ensure * uniqueness. */ char *opt_te_terminal_name; /* Terminal name. */ -int opt_cu_on, opt_li_on, opt_sn_on, opt_so_on, opt_bo_on, opt_hb_on, opt_bl_on; -int opt_re_on, opt_un_on, opt_rep_on, opt_appck_on, opt_invsc_on; -int opt_msg_on; /* Boolean switches. */ +int opt_cu_on, opt_li_on, opt_sn_on, opt_so_on, opt_bo_on, opt_hb_on; +int opt_bl_on, opt_re_on, opt_un_on, opt_rep_on, opt_appck_on; +int opt_invsc_on; /* Boolean switches. */ int opt_ke_type; /* Keyboard type. */ int opt_fo_color, opt_ba_color; /* Colors. */ int opt_ul_color, opt_hb_color; @@ -185,13 +183,15 @@ int opt_bl_min; /* Blank screen. */ int opt_blength_l; int opt_bfreq_f; -int opt_sn_num; /* Snap screen. */ int opt_st_attr; int opt_rt_len; /* regular tab length */ int opt_tb_array[161]; /* Array for tab list */ -int opt_msglevel_num; int opt_ps_mode, opt_pd_min; /* powersave mode/powerdown time */ +int opt_msg_on; +int opt_msglevel_num; + +int opt_sn_num; /* Snap screen. */ char opt_sn_name[200] = "screen.dump"; static void screendump(int vcnum, FILE *F); diff -Naur util-linux-2.12-orig/misc-utils/write.c util-linux-2.12/misc-utils/write.c --- util-linux-2.12-orig/misc-utils/write.c 2001-03-15 04:09:58.000000000 -0600 +++ util-linux-2.12/misc-utils/write.c 2004-02-02 23:40:50.318952440 -0600 @@ -66,7 +66,7 @@ #include "carefulputc.h" #include "nls.h" -void search_utmp(char *, char *, char *, uid_t); +void search_utmp(char *, char **, char *, uid_t); void do_write(char *, char *, uid_t); void wr_fputs(char *); static void done(int); @@ -78,7 +78,7 @@ time_t atime; uid_t myuid; int msgsok, myttyfd; - char tty[MAXPATHLEN], *mytty; + char *tty, *mytty; setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); @@ -120,7 +120,7 @@ /* check args */ switch (argc) { case 2: - search_utmp(argv[1], tty, mytty, myuid); + search_utmp(argv[1], &tty, mytty, myuid); do_write(tty, mytty, myuid); break; case 3: @@ -190,7 +190,7 @@ * Special case for writing to yourself - ignore the terminal you're * writing from, unless that's the only terminal with messages enabled. */ -void search_utmp(char *user, char *tty, char *mytty, uid_t myuid) +void search_utmp(char *user, char **tty, char *mytty, uid_t myuid) { struct utmp u; @@ -224,7 +224,11 @@ ++nttys; if (atime > bestatime) { bestatime = atime; - (void)strcpy(tty, atty); + if ((*tty = strdup(atty)) == NULL) { + (void)fprintf(stderr, + _("write: out of memory\n")); + exit(1); + } } } } @@ -236,7 +240,12 @@ } if (nttys == 0) { if (user_is_me) { /* ok, so write to yourself! */ - (void)strcpy(tty, mytty); + if ((*tty = strdup(mytty)) == NULL) { + (void)fprintf(stderr, + _("write: out of memory\n")); + exit(1); + } + return; } (void)fprintf(stderr, @@ -245,7 +254,7 @@ } else if (nttys > 1) { (void)fprintf(stderr, _("write: %s is logged in more than once; writing to %s\n"), - user, tty); + user, *tty); } } @@ -257,19 +266,23 @@ { struct stat s; - char path[MAXPATHLEN]; + char *path; - if (strlen(tty) + 6 > sizeof(path)) - return(1); + if ((path = malloc(strlen(tty) + sizeof("/dev/") + 1)) == NULL){ + (void)fprintf(stderr,_("write: out of memory\n")); + exit(1); + } (void)sprintf(path, "/dev/%s", tty); if (stat(path, &s) < 0) { if (showerror) (void)fprintf(stderr, "write: %s: %s\n", path, strerror(errno)); + free(path); return(1); } *msgsokP = (s.st_mode & (S_IWRITE >> 3)) != 0; /* group write bit */ *atimeP = s.st_atime; + free(path); return(0); } @@ -280,7 +293,7 @@ char *login, *pwuid, *nows; struct passwd *pwd; time_t now; - char path[MAXPATHLEN], host[MAXHOSTNAMELEN], line[512]; + char *path, *host, *host_tmp, line[512]; /* Determine our login name(s) before the we reopen() stdout */ if ((pwd = getpwuid(myuid)) != NULL) @@ -290,8 +303,10 @@ if ((login = getlogin()) == NULL) login = pwuid; - if (strlen(tty) + 6 > sizeof(path)) + if ((path = malloc(strlen(tty) + sizeof("/dev/") + 1)) == NULL) { + (void)fprintf(stderr, _("write: out of memory\n")); exit(1); + } (void)sprintf(path, "/dev/%s", tty); if ((freopen(path, "w", stdout)) == NULL) { (void)fprintf(stderr, "write: %s: %s\n", @@ -299,12 +314,13 @@ exit(1); } + free(path); + (void)signal(SIGINT, done); (void)signal(SIGHUP, done); /* print greeting */ - if (gethostname(host, sizeof(host)) < 0) - (void)strcpy(host, "???"); + host = "???"; now = time((time_t *)NULL); nows = ctime(&now); nows[16] = '\0'; @@ -317,6 +333,8 @@ login, host, mytty, nows + 11); printf("\r\n"); + free(host_tmp); + while (fgets(line, sizeof(line), stdin) != NULL) wr_fputs(line); } diff -Naur util-linux-2.12-orig/mount/fstab.c util-linux-2.12/mount/fstab.c --- util-linux-2.12-orig/mount/fstab.c 2003-07-15 16:14:41.000000000 -0500 +++ util-linux-2.12/mount/fstab.c 2004-02-02 23:49:27.809281952 -0600 @@ -437,7 +437,7 @@ struct flock flock; int errsv, fd, i, j; - i = open (linktargetfile, O_WRONLY|O_CREAT, 0); + i = open (linktargetfile, O_WRONLY|O_CREAT, 0600); if (i < 0) { int errsv = errno; /* linktargetfile does not exist (as a file) diff -Naur util-linux-2.12-orig/mount/my_dev_t.h util-linux-2.12/mount/my_dev_t.h --- util-linux-2.12-orig/mount/my_dev_t.h 2003-07-16 15:05:50.000000000 -0500 +++ util-linux-2.12/mount/my_dev_t.h 2004-02-02 20:02:00.355010360 -0600 @@ -4,4 +4,4 @@ /* for ancient systems use "unsigned short" */ #include -#define my_dev_t __kernel_dev_t +#define my_dev_t __kernel_old_dev_t diff -Naur util-linux-2.12-orig/sys-utils/ipcrm.c util-linux-2.12/sys-utils/ipcrm.c --- util-linux-2.12-orig/sys-utils/ipcrm.c 2002-04-24 09:42:54.000000000 -0500 +++ util-linux-2.12/sys-utils/ipcrm.c 2004-02-02 23:56:00.032654936 -0600 @@ -26,7 +26,7 @@ /* for tolower and isupper */ #include -#if defined (__GNU_LIBRARY__) && !defined(_SEM_SEMUN_UNDEFINED) +#if defined (__GLIBC__) && !defined(_SEM_SEMUN_UNDEFINED) /* union semun is defined by including */ #else /* according to X/OPEN we have to define it ourselves */ diff -Naur util-linux-2.12-orig/sys-utils/ipcs.c util-linux-2.12/sys-utils/ipcs.c --- util-linux-2.12-orig/sys-utils/ipcs.c 2002-11-24 16:21:44.000000000 -0600 +++ util-linux-2.12/sys-utils/ipcs.c 2004-02-02 23:57:43.787881744 -0600 @@ -78,7 +78,7 @@ /* The last arg of semctl is a union semun, but where is it defined? X/OPEN tells us to define it ourselves, but until recently Linux include files would also define it. */ -#if defined (__GNU_LIBRARY__) && !defined(_SEM_SEMUN_UNDEFINED) +#if defined (__GLIBC__) && !defined(_SEM_SEMUN_UNDEFINED) /* union semun is defined by including */ #else /* according to X/OPEN we have to define it ourselves */ @@ -95,7 +95,7 @@ , which defines a struct ipc_perm with such fields. glibc-1.09 has no support for sysv ipc. glibc 2 uses __key, __seq */ -#if defined (__GNU_LIBRARY__) && __GNU_LIBRARY__ > 1 +#if defined (__GLIBC__) && __GLIBC__ > 1 #define KEY __key #else #define KEY key diff -Naur util-linux-2.12-orig/sys-utils/readprofile.c util-linux-2.12/sys-utils/readprofile.c --- util-linux-2.12-orig/sys-utils/readprofile.c 2003-07-13 09:23:54.000000000 -0500 +++ util-linux-2.12/sys-utils/readprofile.c 2004-02-02 23:58:33.619306216 -0600 @@ -102,7 +102,7 @@ if (uname(&uname_info)) return ""; - len = strlen(BOOT_SYSTEM_MAP) + strlen(uname_info.release) + 1; + len = strlen(BOOT_SYSTEM_MAP) + strlen(uname_info.release) + 2; s = xmalloc(len); strcpy(s, BOOT_SYSTEM_MAP); strcat(s, uname_info.release);