summaryrefslogtreecommitdiffstats
path: root/floppy.py
blob: a1722f06513791e737317d45a9de2e95bdaadbc6 (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#
# floppy.py - floppy drive probe and bootdisk creation
#
# Erik Troan <ewt@redhat.com>
#
# Copyright 2001 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.
#

import isys
import errno
import iutil
import re
import os
import rpm
from constants import *
from log import log
from flags import flags
from translate import _

def probeFloppyDevice():
    fdDevice = "fd0"
    if iutil.getArch() == "sparc":
	try:
	    f = open(fdDevice, "r")
	except IOError, (errnum, msg):
	    if errno.errorcode[errnum] == 'ENXIO':
		fdDevice = "fd1"
	else:
	    f.close()
    elif iutil.getArch() == "alpha":
	pass
    elif iutil.getArch() == "i386" or iutil.getArch() == "ia64":
	# Look for the first IDE floppy device
	drives = isys.floppyDriveDict()
	if not drives:
	    log("no IDE floppy devices found")
	    return fdDevice

	floppyDrive = drives.keys()[0]
	# need to go through and find if there is an LS-120
	for dev in drives.keys():
	    if re.compile(".*[Ll][Ss]-120.*").search(drives[dev]):
		floppyDrive = dev

	# No IDE floppy's -- we're fine w/ /dev/fd0
	if not floppyDrive: return fdDevice

	if iutil.getArch() == "ia64":
	    fdDevice = floppyDrive
	    log("anaconda floppy device is %s", fdDevice)
	    return fdDevice

	# Look in syslog for a real fd0 (which would take precedence)
	try:
	    f = open("/tmp/syslog", "r")
	except IOError:
	    try: 
		f = open("/var/log/dmesg", "r")
	    except IOError:
		return fdDevice

	for line in f.readlines():
	    # chop off the loglevel (which init's syslog leaves behind)
	    line = line[3:]
	    match = "Floppy drive(s): "
	    if match == line[:len(match)]:
		# Good enough
		floppyDrive = "fd0"
		break

	fdDevice = floppyDrive
    else:
	raise SystemError, "cannot determine floppy device for this arch"

    log("anaconda floppy device is %s", fdDevice)

    return fdDevice

def makeBootdisk (intf, floppyDevice, hdList, instPath):
    if flags.test:
	return DISPATCH_NOOP

    # this is faster then waiting on mkbootdisk to fail
    device = floppyDevice
    file = "/tmp/floppy"
    isys.makeDevInode(device, file)
    try:
	fd = os.open(file, os.O_RDONLY)
    except:
	return DISPATCH_BACK
    os.close(fd)

    kernel = hdList['kernel']
    kernelTag = "-%s-%s" % (kernel[rpm.RPMTAG_VERSION],
			    kernel[rpm.RPMTAG_RELEASE])

    w = intf.waitWindow (_("Creating"), _("Creating boot disk..."))
    rc = iutil.execWithRedirect("/sbin/mkbootdisk",
				[ "/sbin/mkbootdisk",
				  "--noprompt",
				  "--device",
				  "/dev/" + floppyDevice,
				  kernelTag[1:] ],
				stdout = '/dev/tty5', stderr = '/dev/tty5',
				searchPath = 1, root = instPath)
    w.pop()

    if rc:
	return DISPATCH_BACK