summaryrefslogtreecommitdiff
path: root/com32
diff options
context:
space:
mode:
authorMichal Soltys <soltys@ziu.info>2010-10-12 00:39:21 +0200
committerMichal Soltys <soltys@ziu.info>2010-10-12 00:39:21 +0200
commitdaa64db51f1dc7a19bfb915291348af79950c4ec (patch)
tree70d916be8b8942ac35305fbe4d9b756f5a4d53bc /com32
parent756c2e4179e70c92085207d1fe887fc9bff9fdeb (diff)
parentf5a591bf3b23f6f5fd25871f0f319b49c42e207e (diff)
downloadsyslinux-daa64db51f1dc7a19bfb915291348af79950c4ec.tar.gz
Merge branch 'disklibdev' into chaindev
Diffstat (limited to 'com32')
-rw-r--r--com32/lib/syslinux/disk.c62
-rw-r--r--com32/rosh/Makefile20
-rw-r--r--com32/rosh/rosh.c59
-rw-r--r--com32/rosh/rosh.h44
4 files changed, 123 insertions, 62 deletions
diff --git a/com32/lib/syslinux/disk.c b/com32/lib/syslinux/disk.c
index ddc3c5d4..3585da58 100644
--- a/com32/lib/syslinux/disk.c
+++ b/com32/lib/syslinux/disk.c
@@ -77,6 +77,7 @@ int disk_get_params(int disk, struct disk_info *const diskinfo)
memset(diskinfo, 0, sizeof *diskinfo);
diskinfo->disk = disk;
+ diskinfo->bps = SECTOR;
/* Get EBIOS support */
memset(&inreg, 0, sizeof inreg);
@@ -105,18 +106,15 @@ int disk_get_params(int disk, struct disk_info *const diskinfo)
__intcall(0x13, &inreg, &outreg);
- if (outreg.eflags.l & EFLAGS_CF)
- return -1; /* this really shouldn't happen if we have ebios */
-
- diskinfo->lbacnt = eparam->lbacnt;
- if (eparam->bps)
- diskinfo->bps = eparam->bps;
- else
- diskinfo->bps = SECTOR;
- /*
- * don't think about using geometry data returned by
- * 48h, as it can differ from 08h a lot ...
- */
+ if (!(outreg.eflags.l & EFLAGS_CF)) {
+ diskinfo->lbacnt = eparam->lbacnt;
+ if (eparam->bps)
+ diskinfo->bps = eparam->bps;
+ /*
+ * don't think about using geometry data returned by
+ * 48h, as it can differ from 08h a lot ...
+ */
+ }
}
/*
* Get disk parameters the old way - really only useful for hard
@@ -191,20 +189,14 @@ void *disk_read_sectors(const struct disk_info *const diskinfo, uint64_t lba,
unsigned int c, h, s, t;
/*
* if we passed lba + count check and we get here, that means that
- * lbacnt was calculated from chs geometry, thus 32bits are perfectly
- * enough and lbacnt corresponds to cylinder boundary
+ * lbacnt was calculated from chs geometry (or faked from 1/1/1), thus
+ * 32bits are perfectly enough and lbacnt corresponds to cylinder
+ * boundary
*/
- if (!diskinfo->cbios) {
- /* We failed to get the geometry */
- s = 1;
- h = 0;
- c = 0;
- } else {
- s = (lba % diskinfo->spt) + 1;
- t = lba / diskinfo->spt;
- h = t % diskinfo->head;
- c = t / diskinfo->head;
- }
+ s = (lba % diskinfo->spt) + 1;
+ t = lba / diskinfo->spt;
+ h = t % diskinfo->head;
+ c = t / diskinfo->head;
inreg.eax.b[0] = count;
inreg.eax.b[1] = 0x02; /* Read */
@@ -267,20 +259,14 @@ int disk_write_sectors(const struct disk_info *const diskinfo, uint64_t lba,
unsigned int c, h, s, t;
/*
* if we passed lba + count check and we get here, that means that
- * lbacnt was calculated from chs geometry, thus 32bits are perfectly
- * enough and lbacnt corresponds to cylinder boundary
+ * lbacnt was calculated from chs geometry (or faked from 1/1/1), thus
+ * 32bits are perfectly enough and lbacnt corresponds to cylinder
+ * boundary
*/
- if (!diskinfo->cbios) {
- /* We failed to get the geometry */
- s = 1;
- h = 0;
- c = 0;
- } else {
- s = (lba % diskinfo->spt) + 1;
- t = lba / diskinfo->spt;
- h = t % diskinfo->head;
- c = t / diskinfo->head;
- }
+ s = (lba % diskinfo->spt) + 1;
+ t = lba / diskinfo->spt;
+ h = t % diskinfo->head;
+ c = t / diskinfo->head;
inreg.eax.b[0] = count;
inreg.eax.b[1] = 0x03; /* Write */
diff --git a/com32/rosh/Makefile b/com32/rosh/Makefile
index 7bf5059c..f4b7d866 100644
--- a/com32/rosh/Makefile
+++ b/com32/rosh/Makefile
@@ -1,6 +1,8 @@
## -----------------------------------------------------------------------
##
## Copyright 2001-2008 H. Peter Anvin - All Rights Reserved
+## Copyright 2010 Intel Corporation; author: H. Peter Anvin
+## Copyright 2008-2010 Gene Cumm - All Rights Reserved
##
## 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
@@ -11,18 +13,34 @@
## -----------------------------------------------------------------------
##
-## samples for syslinux users
+## ROSH Read Only Shell
##
topdir = ../..
include MCONFIG
+# from com32/sysdump/Makefile
+# The DATE is set on the make command line when building binaries for
+# official release. Otherwise, substitute a hex string that is pretty much
+# guaranteed to be unique to be unique from build to build.
+ifndef HEXDATE
+HEXDATE := $(shell $(PERL) $(topdir)/now.pl $(SRCS) $(wildcard *.h))
+endif
+ifndef DATE
+DATE := $(shell sh $(topdir)/gen-id.sh $(VERSION) $(HEXDATE))
+endif
+
+CFLAGS += -DDATE='"$(DATE)"'
+LNXCFLAGS += -DDATE='"$(DATE)"'
+
rosh.o: rosh.h
rosh.lo: rosh.h
all: rosh.c32
+allgrc: rosh.c32 rosh.lnx
+
tidy dist:
rm -f *.o *.lo *.a *.lst *.elf .*.d *.tmp
diff --git a/com32/rosh/rosh.c b/com32/rosh/rosh.c
index bf1176fb..9efa35ef 100644
--- a/com32/rosh/rosh.c
+++ b/com32/rosh/rosh.c
@@ -32,17 +32,24 @@
* debugging enabled; Comment to remove.
*/
#include "rosh.h"
+#include "../../version.h"
#define APP_LONGNAME "Read-Only Shell"
#define APP_NAME "rosh"
#define APP_AUTHOR "Gene Cumm"
#define APP_YEAR "2010"
-#define APP_VER "beta-b062"
+#define APP_VER "beta-b068"
-void rosh_version(void)
+void rosh_version(int vtype)
{
- printf("%s v %s; (c) %s %s.\n", APP_LONGNAME, APP_VER, APP_YEAR,
- APP_AUTHOR);
+ char env[256];
+ env[0] = 0;
+ printf("%s v %s; (c) %s %s.\n\tFrom Syslinux %s, %s\n", APP_LONGNAME, APP_VER, APP_YEAR, APP_AUTHOR, VERSION_STR, DATE);
+ switch (vtype) {
+ case 1:
+ rosh_get_env_ver(env, 256);
+ printf("\tRunning on %s\n", env);
+ }
}
void print_beta(void)
@@ -124,7 +131,7 @@ void rosh_help(int type, const char *cmdstr)
case 2:
istr += rosh_search_nonsp(cmdstr, rosh_search_sp(cmdstr, 0));
if ((cmdstr == NULL) || (strcmp(istr, "") == 0)) {
- rosh_version();
+ rosh_version(0);
puts(rosh_help_str2);
} else {
switch (istr[0]) {
@@ -138,7 +145,7 @@ void rosh_help(int type, const char *cmdstr)
break;
case 1:
default:
- rosh_version();
+ rosh_version(0);
puts(rosh_help_str1);
}
}
@@ -775,15 +782,14 @@ void rosh_dir(const char *cmdstr)
/* Page through a buffer string
* buf Buffer to page through
*/
-//HERE: minor pagination issue; sometimes prints 1 less than rows
-void rosh_more_buf(char *buf, int buflen, int rows, int cols)
+void rosh_more_buf(char *buf, int buflen, int rows, int cols, char *scrbuf)
{
char *bufp, *bufeol, *bufeol2; /* Pointer to current and next
end-of-line position in buffer */
int bufpos, bufcnt; /* current position, count characters */
- char scrbuf[ROSH_SBUF_SZ];
int inc;
int i, numln; /* Index, Number of lines */
+ int elpl; /* Extra lines per line read */
(void)cols;
@@ -799,10 +805,19 @@ void rosh_more_buf(char *buf, int buflen, int rows, int cols)
bufeol = buf + buflen;
i = numln;
} else {
- i += ((bufeol2 - bufeol) / cols);
- bufeol = bufeol2 + 1;
+ elpl = ((bufeol2 - bufeol - 1) / cols);
+ if (elpl < 0)
+ elpl = 0;
+ i += elpl;
+ ROSH_DEBUG2(" %d/%d ", elpl, i+1);
+ /* If this will not push too much, use it */
+ /* but if it's the first line, use it */
+ /* //HERE: We should probably snip the line off */
+ if ((i < numln) || (i == elpl))
+ bufeol = bufeol2 + 1;
}
}
+ ROSH_DEBUG2("\n");
bufcnt = bufeol - bufp;
printf("--(%d/%d @%d)\n", bufcnt, buflen, bufpos);
memcpy(scrbuf, bufp, bufcnt);
@@ -829,7 +844,7 @@ void rosh_more_buf(char *buf, int buflen, int rows, int cols)
/* Page through a single file using the open file stream
* fd File Descriptor
*/
-void rosh_more_fd(int fd, int rows, int cols)
+void rosh_more_fd(int fd, int rows, int cols, char *scrbuf)
{
struct stat fdstat;
int status;
@@ -851,7 +866,7 @@ void rosh_more_fd(int fd, int rows, int cols)
((int)fdstat.st_size - bufpos), f);
}
fclose(f);
- rosh_more_buf(buf, bufpos, rows, cols);
+ rosh_more_buf(buf, bufpos, rows, cols, scrbuf);
}
} else {
}
@@ -868,13 +883,16 @@ void rosh_more(const char *cmdstr)
char filestr[ROSH_PATH_SZ];
int cmdpos;
int rows, cols;
+ char *scrbuf;
+ int ret;
ROSH_DEBUG("CMD: '%s'\n", cmdstr);
/* Initialization */
filestr[0] = 0;
cmdpos = 0;
- if (getscreensize(1, &rows, &cols)) {
- ROSH_DEBUG("getscreensize() fail; fall back\n");
+ ret = getscreensize(1, &rows, &cols);
+ if (ret) {
+ ROSH_DEBUG("getscreensize() fail(%d); fall back\n", ret);
ROSH_DEBUG("\tROWS='%d'\tCOLS='%d'\n", rows, cols);
/* If either fail, go under normal size, just in case */
if (!rows)
@@ -883,6 +901,10 @@ void rosh_more(const char *cmdstr)
cols = 75;
}
ROSH_DEBUG("\tUSE ROWS='%d'\tCOLS='%d'\n", rows, cols);
+ /* 32 bit align beginning of row and over allocate */
+ scrbuf = malloc(rows * ((cols+3)&(INT_MAX - 3)));
+ if (!scrbuf)
+ return;
/* skip the first word */
cmdpos = rosh_parse_sp_1(filestr, cmdstr, cmdpos);
@@ -895,7 +917,7 @@ void rosh_more(const char *cmdstr)
printf("--File = '%s'\n", filestr);
fd = open(filestr, O_RDONLY);
if (fd != -1) {
- rosh_more_fd(fd, rows, cols);
+ rosh_more_fd(fd, rows, cols, scrbuf);
close(fd);
} else {
rosh_error(errno, "more", filestr);
@@ -905,6 +927,7 @@ void rosh_more(const char *cmdstr)
}
rosh_console_std();
}
+ free(scrbuf);
} /* rosh_more */
/* Page a file with rewind
@@ -1109,7 +1132,7 @@ char rosh_command(const char *cmdstr, const char *ipwdstr)
case 'v':
case 'V':
if (strncasecmp("version", tstr, tlen) == 0)
- rosh_version();
+ rosh_version(1);
else
rosh_help(1, NULL);
break;
@@ -1168,7 +1191,7 @@ int main(int argc, char *argv[])
if (argc != 1) {
rv = rosh_argcat(cmdstr, argc, argv, 1);
} else {
- rosh_version();
+ rosh_version(0);
print_beta();
cmdstr[0] = '\0';
}
diff --git a/com32/rosh/rosh.h b/com32/rosh/rosh.h
index a8edda6a..b016e2f2 100644
--- a/com32/rosh/rosh.h
+++ b/com32/rosh/rosh.h
@@ -32,6 +32,7 @@
#include <stdbool.h> /* macro: true false */
#include <string.h> /* strcpy() strlen() memcpy() strchr() */
#include <sys/types.h>
+#include <limits.h>
#include <sys/stat.h> /* fstat() */
#include <fcntl.h> /* open(); open mode macros */
#include <dirent.h> /* fdopendir() opendir() readdir() closedir() DIR */
@@ -41,7 +42,7 @@
#include <ctype.h> /* isspace() */
#include <getkey.h>
-#include <consoles.h>
+#include <consoles.h> /* console_ansi_raw() console_ansi_std() */
#ifdef DO_DEBUG
# define ROSH_DEBUG printf
@@ -89,8 +90,17 @@ int stat(const char *pathname, struct stat *buf)
return ret;
}
+int rosh_get_env_ver(char *dest, size_t n)
+{
+ const struct syslinux_version *slv = syslinux_version();
+ strncpy(dest, slv->version_string, n);
+ return 0;
+}
+
#else
# include <termios.h>
+# include <sys/ioctl.h>
+# include <sys/utsname.h>
# define ROSH_IS_COM32 0
static inline char *syslinux_config_file(void)
@@ -98,19 +108,43 @@ static inline char *syslinux_config_file(void)
return "";
}
+int rosh_get_env_ver(char *dest, size_t n)
+{
+ int ret, len;
+ struct utsname env;
+ ret= uname(&env);
+ if (ret >= 0) {
+ strncpy(dest, env.sysname, n);
+ len = strlen(dest);
+ strncpy(dest + len, " ", (n - len));
+ len = strlen(dest);
+ strncpy(dest + len, env.release, (n - len));
+ }
+ return ret;
+}
+
static inline int getscreensize(int fd, int *rows, int *cols)
{
char *str;
int rv;
- *rows = 0;
- *cols = 0;
+ struct winsize ws;
+ if (rows)
+ *rows = 0;
+ if (cols)
+ *cols = 0;
+ str = NULL;
if (fd == 1) {
- if (rows) {
+ ioctl(0, TIOCGWINSZ, &ws);
+/* if (rows)
+ *rows = ws.ws_row;
+ if (cols)
+ *cols = ws.ws_col;*/
+ if (rows && !*rows) {
str = getenv("LINES");
if (str)
*rows = atoi(str);
}
- if (cols) {
+ if (cols && !*cols) {
str = getenv("COLUMNS");
if (str)
*cols = atoi(str);