diff options
author | Paulo Alcantara <pcacjr@zytor.com> | 2015-11-10 22:14:30 -0200 |
---|---|---|
committer | Paulo Alcantara <pcacjr@zytor.com> | 2015-11-10 22:14:30 -0200 |
commit | 82aac76005b7b19f48b42cbcb192dab6d17b6b05 (patch) | |
tree | f2eaedc76b8587d30889b03b0f3a5d4d913b67e0 | |
parent | b8251024ac0635ec025886f71f3e065886c9cef4 (diff) | |
download | syslinux-82aac76005b7b19f48b42cbcb192dab6d17b6b05.tar.gz syslinux-82aac76005b7b19f48b42cbcb192dab6d17b6b05.tar.xz syslinux-82aac76005b7b19f48b42cbcb192dab6d17b6b05.zip |
libinstaller: introduce syslxrw library
Due to size constraints on DOS systems, do not include whole syslxcom
into DOS-based installer for using xpread() and xpwrite() functions,
instead make them part of another separate library and include it only.
Signed-off-by: Paulo Alcantara <pcacjr@zytor.com>
-rw-r--r-- | extlinux/Makefile | 1 | ||||
-rw-r--r-- | extlinux/main.c | 1 | ||||
-rw-r--r-- | libinstaller/advio.c | 1 | ||||
-rw-r--r-- | libinstaller/syslxcom.c | 64 | ||||
-rw-r--r-- | libinstaller/syslxcom.h | 2 | ||||
-rw-r--r-- | libinstaller/syslxrw.c | 84 | ||||
-rw-r--r-- | libinstaller/syslxrw.h | 20 | ||||
-rw-r--r-- | linux/Makefile | 1 | ||||
-rwxr-xr-x | linux/syslinux.c | 1 | ||||
-rwxr-xr-x | mtools/Makefile | 2 | ||||
-rwxr-xr-x | mtools/syslinux.c | 3 |
11 files changed, 113 insertions, 67 deletions
diff --git a/extlinux/Makefile b/extlinux/Makefile index 02d1db51..1721ee54 100644 --- a/extlinux/Makefile +++ b/extlinux/Makefile @@ -27,6 +27,7 @@ SRCS = main.c \ ../libinstaller/syslxmod.c \ ../libinstaller/syslxopt.c \ ../libinstaller/syslxcom.c \ + ../libinstaller/syslxrw.c \ ../libinstaller/setadv.c \ ../libinstaller/advio.c \ ../libinstaller/bootsect_bin.c \ diff --git a/extlinux/main.c b/extlinux/main.c index 6ba16e1e..6871fb15 100644 --- a/extlinux/main.c +++ b/extlinux/main.c @@ -56,6 +56,7 @@ #include "version.h" #include "syslxint.h" #include "syslxcom.h" /* common functions shared with extlinux and syslinux */ +#include "syslxrw.h" #include "syslxfs.h" #include "setadv.h" #include "syslxopt.h" /* unified options */ diff --git a/libinstaller/advio.c b/libinstaller/advio.c index 66e477ed..e282e11c 100644 --- a/libinstaller/advio.c +++ b/libinstaller/advio.c @@ -32,6 +32,7 @@ #include <sys/stat.h> #include <sys/types.h> #include "syslxint.h" +#include "syslxrw.h" #include "syslxcom.h" /* diff --git a/libinstaller/syslxcom.c b/libinstaller/syslxcom.c index 57f13cda..efc6474d 100644 --- a/libinstaller/syslxcom.c +++ b/libinstaller/syslxcom.c @@ -32,6 +32,7 @@ #include <sys/vfs.h> #include "linuxioctl.h" +#include "syslxrw.h" #include "syslxcom.h" #include "syslxfs.h" @@ -47,69 +48,6 @@ int fs_type; #define SECTOR_SHIFT 9 -static void die(const char *msg) -{ - fputs(msg, stderr); - exit(1); -} - -/* - * read/write wrapper functions - */ -ssize_t xpread(int fd, void *buf, size_t count, off_t offset) -{ - char *bufp = (char *)buf; - ssize_t rv; - ssize_t done = 0; - - while (count) { - rv = pread(fd, bufp, count, offset); - if (rv == 0) { - die("short read"); - } else if (rv == -1) { - if (errno == EINTR) { - continue; - } else { - die(strerror(errno)); - } - } else { - bufp += rv; - offset += rv; - done += rv; - count -= rv; - } - } - - return done; -} - -ssize_t xpwrite(int fd, const void *buf, size_t count, off_t offset) -{ - const char *bufp = (const char *)buf; - ssize_t rv; - ssize_t done = 0; - - while (count) { - rv = pwrite(fd, bufp, count, offset); - if (rv == 0) { - die("short write"); - } else if (rv == -1) { - if (errno == EINTR) { - continue; - } else { - die(strerror(errno)); - } - } else { - bufp += rv; - offset += rv; - done += rv; - count -= rv; - } - } - - return done; -} - /* * Set and clear file attributes */ diff --git a/libinstaller/syslxcom.h b/libinstaller/syslxcom.h index 8b3b4614..90d3966c 100644 --- a/libinstaller/syslxcom.h +++ b/libinstaller/syslxcom.h @@ -4,8 +4,6 @@ #include "syslinux.h" extern const char *program; -ssize_t xpread(int fd, void *buf, size_t count, off_t offset); -ssize_t xpwrite(int fd, const void *buf, size_t count, off_t offset); void clear_attributes(int fd); void set_attributes(int fd); int sectmap(int fd, sector_t *sectors, int nsectors); diff --git a/libinstaller/syslxrw.c b/libinstaller/syslxrw.c new file mode 100644 index 00000000..86876e8c --- /dev/null +++ b/libinstaller/syslxrw.c @@ -0,0 +1,84 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 2010 Intel Corp. - All Rights Reserved + * Copyright 2015 Paulo Alcantara <pcacjr@zytor.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, Inc., 53 Temple Place Ste 330, + * Boston MA 02111-1307, USA; either version 2 of the License, or + * (at your option) any later version; incorporated herein by reference. + * + * ----------------------------------------------------------------------- */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> +#include <fcntl.h> +#include <unistd.h> + +#include "syslxrw.h" + +static void die(const char *msg) +{ + fputs(msg, stderr); + exit(1); +} + +/* + * read/write wrapper functions + */ +ssize_t xpread(int fd, void *buf, size_t count, off_t offset) +{ + char *bufp = (char *)buf; + ssize_t rv; + ssize_t done = 0; + + while (count) { + rv = pread(fd, bufp, count, offset); + if (rv == 0) { + die("short read"); + } else if (rv == -1) { + if (errno == EINTR) { + continue; + } else { + die(strerror(errno)); + } + } else { + bufp += rv; + offset += rv; + done += rv; + count -= rv; + } + } + + return done; +} + +ssize_t xpwrite(int fd, const void *buf, size_t count, off_t offset) +{ + const char *bufp = (const char *)buf; + ssize_t rv; + ssize_t done = 0; + + while (count) { + rv = pwrite(fd, bufp, count, offset); + if (rv == 0) { + die("short write"); + } else if (rv == -1) { + if (errno == EINTR) { + continue; + } else { + die(strerror(errno)); + } + } else { + bufp += rv; + offset += rv; + done += rv; + count -= rv; + } + } + + return done; +} diff --git a/libinstaller/syslxrw.h b/libinstaller/syslxrw.h new file mode 100644 index 00000000..d3ae3c29 --- /dev/null +++ b/libinstaller/syslxrw.h @@ -0,0 +1,20 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 2010 Intel Corp. - All Rights Reserved + * Copyright 2015 Paulo Alcantara <pcacjr@zytor.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, Inc., 53 Temple Place Ste 330, + * Boston MA 02111-1307, USA; either version 2 of the License, or + * (at your option) any later version; incorporated herein by reference. + * + * ----------------------------------------------------------------------- */ + +#ifndef _H_SYSLXRW_ +#define _H_SYSLXRW_ + +ssize_t xpread(int fd, void *buf, size_t count, off_t offset); +ssize_t xpwrite(int fd, const void *buf, size_t count, off_t offset); + +#endif /* _H_SYSLXRW_ */ diff --git a/linux/Makefile b/linux/Makefile index 11667e1d..5a49d813 100644 --- a/linux/Makefile +++ b/linux/Makefile @@ -23,6 +23,7 @@ LDFLAGS = SRCS = syslinux.c \ ../libinstaller/syslxopt.c \ + ../libinstaller/syslxrw.c \ ../libinstaller/syslxcom.c \ ../libinstaller/setadv.c \ ../libinstaller/advio.c \ diff --git a/linux/syslinux.c b/linux/syslinux.c index 912de71f..46d5624c 100755 --- a/linux/syslinux.c +++ b/linux/syslinux.c @@ -68,6 +68,7 @@ #include <getopt.h> #include <sysexits.h> +#include "syslxrw.h" #include "syslxcom.h" #include "syslxfs.h" #include "setadv.h" diff --git a/mtools/Makefile b/mtools/Makefile index c9804209..632b185b 100755 --- a/mtools/Makefile +++ b/mtools/Makefile @@ -9,7 +9,7 @@ SRCS = syslinux.c \ ../libinstaller/fs.c \ ../libinstaller/syslxmod.c \ ../libinstaller/syslxopt.c \ - ../libinstaller/syslxcom.c \ + ../libinstaller/syslxrw.c \ ../libinstaller/setadv.c \ ../libinstaller/bootsect_bin.c \ ../libinstaller/ldlinux_bin.c \ diff --git a/mtools/syslinux.c b/mtools/syslinux.c index 3686be0a..9d68882f 100755 --- a/mtools/syslinux.c +++ b/mtools/syslinux.c @@ -42,8 +42,9 @@ #include "setadv.h" #include "syslxopt.h" #include "syslxfs.h" -#include "syslxcom.h" +#include "syslxrw.h" +const char *program; pid_t mypid; void __attribute__ ((noreturn)) die(const char *msg) |