summaryrefslogtreecommitdiffstats
path: root/isys
diff options
context:
space:
mode:
authorErik Troan <ewt@redhat.com>2000-11-17 17:37:11 +0000
committerErik Troan <ewt@redhat.com>2000-11-17 17:37:11 +0000
commitf942fb8a5541db5a2ae383fa4a5d7e5388cdf34e (patch)
treead78eda7b08cb7fb6cbb39f457caa619f8c5d879 /isys
parent514ad7cda7019e35fd9fe94f0cb28d8462715092 (diff)
downloadanaconda-f942fb8a5541db5a2ae383fa4a5d7e5388cdf34e.tar.gz
anaconda-f942fb8a5541db5a2ae383fa4a5d7e5388cdf34e.tar.xz
anaconda-f942fb8a5541db5a2ae383fa4a5d7e5388cdf34e.zip
added code to check to see if a file is an iso image
Diffstat (limited to 'isys')
-rw-r--r--isys/Makefile2
-rw-r--r--isys/isofs.c35
-rw-r--r--isys/isys.c15
-rw-r--r--isys/isys.h3
-rw-r--r--isys/isys.py2
5 files changed, 55 insertions, 2 deletions
diff --git a/isys/Makefile b/isys/Makefile
index 83b1a9db3..16ded0a16 100644
--- a/isys/Makefile
+++ b/isys/Makefile
@@ -5,7 +5,7 @@ ARCH := $(patsubst sparc%,sparc,$(ARCH))
CFLAGS = -I/usr/include/python1.5 -I.. -Wall -O2 -g -fPIC -DHAVE_NFS
OBJECTS = nfsmount.o dns.o nfsmount_clnt.o nfsmount_xdr.o imount.o \
smp.o moduleinfo.o devnodes.o cpio.o probe.o uncpio.o \
- lang.o
+ lang.o isofs.o
SOURCES = $(patsubst %.o,%.c,$(OBJECTS)) isys.c
STATICOBJS = otherinsmod.o
LOADLIBES = -lbz2 -lresolv -lz -lpci -lpopt -L../pump -lpump -lext2fs
diff --git a/isys/isofs.c b/isys/isofs.c
new file mode 100644
index 000000000..5ba255ff9
--- /dev/null
+++ b/isys/isofs.c
@@ -0,0 +1,35 @@
+#include <fcntl.h>
+#include <string.h>
+#include <unistd.h>
+
+#define BLOCK_SIZE 2048
+
+int fileIsIso(const char * file) {
+ int blkNum;
+ char magic[5];
+ int fd;
+
+ fd = open(file, O_RDONLY);
+ if (fd < 0)
+ return 1;
+
+ for (blkNum = 16; blkNum < 100; blkNum++) {
+ if (lseek(fd, blkNum * BLOCK_SIZE + 1, SEEK_SET) < 0) {
+ close(fd);
+ return 1;
+ }
+
+ if (read(fd, magic, sizeof(magic)) != sizeof(magic)) {
+ close(fd);
+ return 1;
+ }
+
+ if (!strncmp(magic, "CD001", 5)) {
+ close(fd);
+ return 0;
+ }
+ }
+
+ close(fd);
+ return 1;
+}
diff --git a/isys/isys.c b/isys/isys.c
index 723633f43..67ad778da 100644
--- a/isys/isys.c
+++ b/isys/isys.c
@@ -88,6 +88,7 @@ static PyObject * doEjectCdrom(PyObject * s, PyObject * args);
static PyObject * doVtActivate(PyObject * s, PyObject * args);
static PyObject * doisPsudoTTY(PyObject * s, PyObject * args);
static PyObject * doSync(PyObject * s, PyObject * args);
+static PyObject * doisIsoImage(PyObject * s, PyObject * args);
static PyMethodDef isysModuleMethods[] = {
{ "ejectcdrom", (PyCFunction) doEjectCdrom, METH_VARARGS, NULL },
@@ -135,6 +136,7 @@ static PyMethodDef isysModuleMethods[] = {
{ "vtActivate", (PyCFunction) doVtActivate, METH_VARARGS, NULL},
{ "isPsudoTTY", (PyCFunction) doisPsudoTTY, METH_VARARGS, NULL},
{ "sync", (PyCFunction) doSync, METH_VARARGS, NULL},
+ { "isisoimage", (PyCFunction) doisIsoImage, METH_VARARGS, NULL},
{ NULL }
} ;
@@ -1387,7 +1389,6 @@ static PyObject * doisPsudoTTY(PyObject * s, PyObject * args) {
static PyObject * doSync(PyObject * s, PyObject * args) {
int fd;
- struct stat sb;
if (!PyArg_ParseTuple(args, "", &fd)) return NULL;
sync();
@@ -1395,3 +1396,15 @@ static PyObject * doSync(PyObject * s, PyObject * args) {
Py_INCREF(Py_None);
return Py_None;
}
+
+static PyObject * doisIsoImage(PyObject * s, PyObject * args) {
+ char * fn;
+ int rc;
+
+ if (!PyArg_ParseTuple(args, "s", &fn)) return NULL;
+ /* ! returns proper true/false */
+ rc = !fileIsIso(fn);
+
+ return Py_BuildValue("i", rc);
+}
+int fileIsIso(const char * file);
diff --git a/isys/isys.h b/isys/isys.h
index f91ba47c2..82d1e2dea 100644
--- a/isys/isys.h
+++ b/isys/isys.h
@@ -47,4 +47,7 @@ int devMakeInode(char * devName, char * path);
int insmod(char * modName, char * path, char ** args);
int rmmod(char * modName);
+/* returns 0 for true, !0 for false */
+int fileIsIso(const char * file);
+
#endif
diff --git a/isys/isys.py b/isys/isys.py
index d5b0fba7d..1968a5824 100644
--- a/isys/isys.py
+++ b/isys/isys.py
@@ -356,3 +356,5 @@ def isPsudoTTY (fd):
def sync ():
return _isys.sync ()
+def isIsoImage(file):
+ return _isys.isisoimage(file)