summaryrefslogtreecommitdiffstats
path: root/edd/pyedd.c
blob: 75aa988540d49920fe937f395d39bc9eb3ab450e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
 * pyedd.c - real mode bios library for discovering EDD capabilities of
 *           BIOS drives
 *
 * Matt Wilson <msw@redhat.com>
 *
 * Copyright 2000 Red Hat, Inc.
 *
 * This software may be freely redistributed under the terms of the GNU
 * library public license.
 *
 * You should have received a copy of the GNU Library Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 */

#include "edd.h"

#include <sys/wait.h>
#include <sys/resource.h>
#include <unistd.h>

#include <Python.h>

static PyObject * edd_py_detect (PyObject * s, PyObject * args);

static PyMethodDef edd_module_methods[] = {
  { "detect",  (PyCFunction) edd_py_detect, METH_VARARGS, NULL },
  { NULL }
};

static PyObject *
edd_py_detect (PyObject * s, PyObject * args) {
  EDDCapability *ec;
  int device = 0x80;
  pid_t childpid;
  int status;

  if (!PyArg_ParseTuple(args, "|i", &device))
    return NULL;

  /* Run this probe as a child as it sometimes segv's in the vm stuff. 
     The child returns 1 if edd works, and 0 if it doesn't. */

  if (!(childpid = fork())) {
      /* lets not drop core file if we do segv */
      struct rlimit lims;

      lims.rlim_cur = 0;
      setrlimit(RLIMIT_CORE, &lims);

      if ((ec = edd_supported(device))) {
	free (ec);
	_exit(1);
      }

      _exit(0);
  }

  waitpid(childpid, &status, 0);

  if (WIFEXITED(status) && WEXITSTATUS(status))
    return Py_BuildValue ("i", 1);

  return Py_BuildValue ("i", 0);
}

void initedd (void) {
    Py_InitModule("edd", edd_module_methods);
}