Skip to content

Commit

Permalink
libinstaller: introduce syslxrw library
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Paulo Alcantara committed Nov 11, 2015
1 parent b825102 commit 82aac76
Show file tree
Hide file tree
Showing 11 changed files with 113 additions and 67 deletions.
1 change: 1 addition & 0 deletions extlinux/Makefile
Expand Up @@ -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 \
Expand Down
1 change: 1 addition & 0 deletions extlinux/main.c
Expand Up @@ -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 */
Expand Down
1 change: 1 addition & 0 deletions libinstaller/advio.c
Expand Up @@ -32,6 +32,7 @@
#include <sys/stat.h>
#include <sys/types.h>
#include "syslxint.h"
#include "syslxrw.h"
#include "syslxcom.h"

/*
Expand Down
64 changes: 1 addition & 63 deletions libinstaller/syslxcom.c
Expand Up @@ -32,6 +32,7 @@
#include <sys/vfs.h>

#include "linuxioctl.h"
#include "syslxrw.h"
#include "syslxcom.h"
#include "syslxfs.h"

Expand All @@ -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
*/
Expand Down
2 changes: 0 additions & 2 deletions libinstaller/syslxcom.h
Expand Up @@ -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);
Expand Down
84 changes: 84 additions & 0 deletions 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;
}
20 changes: 20 additions & 0 deletions 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_ */
1 change: 1 addition & 0 deletions linux/Makefile
Expand Up @@ -23,6 +23,7 @@ LDFLAGS =

SRCS = syslinux.c \
../libinstaller/syslxopt.c \
../libinstaller/syslxrw.c \
../libinstaller/syslxcom.c \
../libinstaller/setadv.c \
../libinstaller/advio.c \
Expand Down
1 change: 1 addition & 0 deletions linux/syslinux.c
Expand Up @@ -68,6 +68,7 @@

#include <getopt.h>
#include <sysexits.h>
#include "syslxrw.h"
#include "syslxcom.h"
#include "syslxfs.h"
#include "setadv.h"
Expand Down
2 changes: 1 addition & 1 deletion mtools/Makefile
Expand Up @@ -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 \
Expand Down
3 changes: 2 additions & 1 deletion mtools/syslinux.c
Expand Up @@ -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)
Expand Down

0 comments on commit 82aac76

Please sign in to comment.