[syslinux:master] libinstaller: introduce syslxrw library
syslinux-bot for Paulo Alcantara
pcacjr at zytor.com
Wed Nov 11 03:00:05 PST 2015
Commit-ID: 82aac76005b7b19f48b42cbcb192dab6d17b6b05
Gitweb: http://www.syslinux.org/commit/82aac76005b7b19f48b42cbcb192dab6d17b6b05
Author: Paulo Alcantara <pcacjr at zytor.com>
AuthorDate: Tue, 10 Nov 2015 22:14:30 -0200
Committer: Paulo Alcantara <pcacjr at zytor.com>
CommitDate: Tue, 10 Nov 2015 22:14:30 -0200
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 at zytor.com>
---
extlinux/Makefile | 1 +
extlinux/main.c | 1 +
libinstaller/advio.c | 1 +
libinstaller/syslxcom.c | 64 +----------------------
libinstaller/syslxcom.h | 2 -
libinstaller/syslxrw.c | 84 +++++++++++++++++++++++++++++++
extlinux/ntfs.h => libinstaller/syslxrw.h | 13 ++---
linux/Makefile | 1 +
linux/syslinux.c | 1 +
mtools/Makefile | 2 +-
mtools/syslinux.c | 3 +-
11 files changed, 100 insertions(+), 73 deletions(-)
diff --git a/extlinux/Makefile b/extlinux/Makefile
index 02d1db5..1721ee5 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 6ba16e1..6871fb1 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 66e477e..e282e11 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 57f13cd..efc6474 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 8b3b461..90d3966 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 0000000..86876e8
--- /dev/null
+++ b/libinstaller/syslxrw.c
@@ -0,0 +1,84 @@
+/* ----------------------------------------------------------------------- *
+ *
+ * Copyright 2010 Intel Corp. - All Rights Reserved
+ * Copyright 2015 Paulo Alcantara <pcacjr at 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/extlinux/ntfs.h b/libinstaller/syslxrw.h
similarity index 63%
copy from extlinux/ntfs.h
copy to libinstaller/syslxrw.h
index d907d45..d3ae3c2 100644
--- a/extlinux/ntfs.h
+++ b/libinstaller/syslxrw.h
@@ -1,6 +1,7 @@
/* ----------------------------------------------------------------------- *
*
- * Copyright 2011 Paulo Alcantara <pcacjr at gmail.com>
+ * Copyright 2010 Intel Corp. - All Rights Reserved
+ * Copyright 2015 Paulo Alcantara <pcacjr at 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
@@ -10,10 +11,10 @@
*
* ----------------------------------------------------------------------- */
-#ifndef _NTFS_H_
-#define _NTFS_H_
+#ifndef _H_SYSLXRW_
+#define _H_SYSLXRW_
-#define NTFS_SB_MAGIC 0x5346544E
-#define FUSE_SUPER_MAGIC 0x65735546
+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 /* _NTFS_H_ */
+#endif /* _H_SYSLXRW_ */
diff --git a/linux/Makefile b/linux/Makefile
index 11667e1..5a49d81 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 912de71..46d5624 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 c980420..632b185 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 3686be0..9d68882 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)
More information about the Syslinux-commits
mailing list