please insert discthe c...

2072人阅读
Unix/Linux(98)
嵌入式系统(31)
CPlusPlus(158)
如果您的自制linux安装盘总是不能成功进行安装,阅读一下下面的c代码,相信肯定会成功,
&源码面前了无秘密&便是如此.此代码属于 Red Hat Linux anaconda 安装程序的关键代码.
//////////////////////////////////////////////////////////////////////////
* cdinstall.c - code to set up cdrom installs
* Erik Troan &&
* Matt Wilson &&
* Michael Fulbright &&
* Jeremy Katz &&
* Copyright 1997 - 2002 Red Hat, Inc.
* This software may be freely redistributed under the terms of the GNU
* General Public License.
* You should have received a copy of the GNU General Public License
* alo if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#include &ctype.h&
#include &dirent.h&
#include &errno.h&
#include &fcntl.h&
#include &newt.h&
#include &stdlib.h&
#include &string.h&
#include &sys/mount.h&
#include &sys/ioctl.h&
#include &unistd.h&
#include &asm/types.h&
#include &linux/cdrom.h&
#include &kickstart.h&
#include &loader.h&
#include &loadermisc.h&
#include &log.h&
#include &lang.h&
#include &modules.h&
#include &method.h&
#include &cdinstall.h&
#include &mediacheck.h&
#include &../isys/probe.h&
#include &../isys/imount.h&
#include &../isys/isys.h&
static int getISOStatusFromFD(int isofd, char *mediasum);
/* ejects the CD device the device node /tmp/cdrom points at */
void ejectCdrom(void) {
logMessage(&ejecting /tmp/cdrom...&);
if ((ejectfd = open(&/tmp/cdrom&, O_RDONLY | O_NONBLOCK, 0)) &= 0) {
if (ioctl(ejectfd, CDROMEJECT, 0))
logMessage(&eject failed %d &, errno);
close(ejectfd);
logMessage(&eject failed %d &, errno);
* Given cd device cddriver, this function will attempt to check its internal checksum.
* JKFIXME: this ignores &location&, which should be fixed */
static char * mediaCheckCdrom(char *cddriver) {
devMakeInode(cddriver, &/tmp/cdrom&);
first = 1;
/* init every pass */
ejectcd = 0;
descr = NULL;
/* if first time through, see if they want to eject the CD
/* currently in the drive (most likely the CD they booted from) */
/* and test a different disk.
Otherwise just test the disk in
/* the drive since it was inserted in the previous pass through */
/* this loop, so they want it tested.
if (first) {
first = 0;
rc = newtWinChoice(_(&Media Check&), _(&Test&), _(&Eject CD&),
_(&Choose /&%s/& to test the CD currently in &
&the drive, or /&%s/& to eject the CD and &
&insert another for testing.&), _(&Test&),
_(&Eject CD&));
if (rc == 2)
ejectcd = 1;
if (!ejectcd) {
/* XXX MSFFIXME: should check return code for error */
readStampFileFromIso(&/tmp/cdrom&, &tstamp, &descr);
mediaCheckFile(&/tmp/cdrom&, descr);
if (descr)
free(descr);
ejectCdrom();
rc = newtWinChoice(_(&Media Check&), _(&Test&), _(&Continue&),
_(&If you would like to test additional media, &
&insert the next CD and press /&%s/&. &
&You do not have to test all CDs, although &
&it is recommended you do so at least once./n/n&
&To begin the installation process &
&insert CD #1 into the drive &
&and press /&%s/&.&),
_(&Test&), _(&Continue&));
if (rc == 2) {
unlink(&/tmp/cdrom&);
return NULL;
} while (1);
return NULL;
/* output an error message when CD in drive is not the correct one */
/* Used by mountCdromStage2()
static void wrongCDMessage(void) {
char *buf = sdupprintf(_(&The %s CD was not found &
&in any of your CDROM drives. Please insert &
&the %s CD and press %s to retry.&), getProductName(),
getProductName(), _(&OK&));
newtWinMessage(_(&Error&), _(&OK&), buf, _(&OK&));
free(buf);
/* Attempts to get a proper CD #1 in the drive */
/* Is called after mediacheck is done so that we can proceed with the install */
/* During mediacheck we have to have CD umount'd so it can be ejected */
/* JKFIXME: Assumes CD is mounted as /mnt/source
static void mountCdromStage2(char *cddev) {
int gotcd1=0;
devMakeInode(cddev, &/tmp/cdrom&);
if (doPwMount(&/tmp/cdrom&, &/mnt/source&,
&iso9660&, 1, 0, NULL, NULL, 0)) {
ejectCdrom();
wrongCDMessage();
} while (1);
rc = mountStage2(&/mnt/source/RedHat/base/stage2.img&);
/* if we failed, umount /mnt/source and keep going */
umount(&/mnt/source&);
ejectCdrom();
wrongCDMessage();
gotcd1 = 1;
} while (!gotcd1);
/* reads iso status from device cddriver */
static int getISOStatusFromCDROM(char *cddriver, char *mediasum) {
devMakeInode(cddriver, &/tmp/cdrom&);
isofd = open(&/tmp/cdrom&, O_RDONLY);
if (isofd & 0) {
logMessage(&Could not check iso status: %s&, strerror(errno));
unlink(&/tmp/cdrom&);
isostatus = getISOStatusFromFD(isofd, mediasum);
close(isofd);
unlink(&/tmp/cdrom&);
/* get support status */
/* if returns 1 we found status, and mediasum will be checksum */
static int getISOStatusFromFD(int isofd, char *mediasum) {
unsigned char tmpsum[33];
int skipsectors,
long long isosize, pvd_
if (mediasum)
mediasum[0] = '/0';
if ((pvd_offset = parsepvd(isofd, tmpsum, &skipsectors, &isosize, &isostatus)) & 0) {
logMessage(&Could not parse pvd&);
if (mediasum)
strcpy(mediasum, tmpsum);
/* writes iso status info to file '/tmp/isoinfo' for later use */
static void writeISOStatus(int status, char *mediasum) {
if (!(f = fopen(&/tmp/isoinfo&, &w&)))
fprintf(f, &ISOSTATUS=%d/n&, status);
fprintf(f, &MEDIASUM=%s/n&, mediasum);
fclose(f);
/* ask about doing media check */
/* JKFIXME: Assumes CD is mounted as /mnt/source
static void queryCDMediaCheck(char *dev, int flags) {
char mediasum[33];
/* dont bother to test in automated installs */
if (FL_KICKSTART(flags))
/* see what status is */
isostatus = getISOStatusFromCDROM(dev, mediasum);
writeISOStatus(isostatus, mediasum);
/* see if we should check image(s) */
/* in rescue mode only test if they explicitly asked to */
if ((!isostatus && !FL_RESCUE(flags)) || FL_MEDIACHECK(flags)) {
startNewt(flags);
rc = newtWinChoice(_(&CD Found&), _(&OK&),
_(&Skip&),
_(&To begin testing the CD media before installation press %s./n/n&
&Choose %s to skip the media test and start the installation.&), _(&OK&), _(&Skip&));
if (rc != 2) {
/* unmount CD now we've identified */
/* a valid disc #1 is present */
umountStage2();
umount(&/mnt/source&);
/* test CD(s) */
mediaCheckCdrom(dev);
/* remount stage2 from CD #1 and proceed */
mountCdromStage2(dev);
/* set up a cdrom, nominally for installation
* location: where to mount the cdrom at JKFIXME: ignored
* flags: usual loader flags
* interactive: whether or not to prompt about questions/errors (1 is yes)
* loaderData is the kickstart info, can be NULL meaning no info
* side effect: found cdrom is mounted as /mnt/source.
stage2 mounted
* as /mnt/runtime.
char * setupCdrom(char * location,
struct knownDevices * kd,
struct loaderData_s * loaderData,
moduleInfoSet modInfo,
moduleList modLoaded,
moduleDeps modDeps,
int flags,
int interactive) {
int foundinvalid = 0;
if (FL_TESTING(flags) && interactive) {
for (i = 0; i & kd-&numK i++) {
if (kd-&known[i].class != CLASS_CDROM) continue;
buf = malloc(200);
sprintf(buf, &cdrom://%s:/mnt/source&, kd-&known[i].name);
/* JKFIXME: ASSERT -- we have a cdrom device when we get here */
for (i = 0; i & kd-&numK i++) {
if (kd-&known[i].class != CLASS_CDROM) continue;
logMessage(&trying to mount device %s&, kd-&known[i].name);
devMakeInode(kd-&known[i].name, &/tmp/cdrom&);
if (!doPwMount(&/tmp/cdrom&, &/mnt/source&, &iso9660&, 1, 0,
NULL, NULL, 0)) {
if (!access(&/mnt/source/RedHat/base/stage2.img&, R_OK) &&
(FL_RESCUE(flags) || !access(&/mnt/source/.discinfo&, R_OK))) {
rc = mountStage2(&/mnt/source/RedHat/base/stage2.img&);
/* if we failed, umount /mnt/source and keep going */
umount(&/mnt/source&);
if (rc == -1) foundinvalid = 1;
/* do the media check */
queryCDMediaCheck(kd-&known[i].name, flags);
buf = malloc(200);
sprintf(buf, &cdrom://%s:/mnt/source&, kd-&known[i].name);
/* this wasnt the CD we were looking for, clean up and */
/* try the next CD drive
umount(&/mnt/source&);
unlink(&/tmp/cdrom&);
if (interactive) {
if (foundinvalid)
buf = sdupprintf(_(&No %s CD was found which matches your &
&boot media.
Please insert the %s CD &
&and press %s to retry.&), getProductName(),
getProductName(), _(&OK&));
buf = sdupprintf(_(&The %s CD was not found in any of your &
&CDROM drives. Please insert the %s CD &
&and press %s to retry.&), getProductName(),
getProductName(), _(&OK&));
rc = newtWinChoice(_(&CD Not Found&),
_(&OK&), _(&Back&), buf, _(&OK&));
free(buf);
if (rc == 2) return NULL;
/* we can't ask them about it, so just return not found */
return NULL;
} while (1);
return NULL;
/* try to find a Red Hat CD non-interactively */
char * findRedHatCD(char * location,
struct knownDevices * kd,
moduleInfoSet modInfo,
moduleList modLoaded,
moduleDeps modDeps,
int flags) {
return setupCdrom(location, kd, NULL, modInfo, modLoaded, modDeps, flags, 0);
/* look for a Red Hat CD and mount it.
if we have problems, ask */
char * mountCdromImage(struct installMethod * method,
char * location, struct knownDevices * kd,
struct loaderData_s * loaderData,
moduleInfoSet modInfo, moduleList modLoaded,
moduleDeps * modDepsPtr, int flags) {
return setupCdrom(location, kd, loaderData, modInfo, modLoaded, *modDepsPtr, flags, 1);
void setKickstartCD(struct knownDevices * kd,
struct loaderData_s * loaderData, int argc,
char ** argv, int * flagsPtr) {
logMessage(&kickstartFromCD&);
loaderData-&method = strdup(&cdrom&);
#ifdef SDSC
kickstartFromCD(char *kssrc, struct knownDevices * kd, int flags)
char *p, *
logMessage(&kickstartFromCD:getting kickstart file from CDROM&);
* format is ks=cdrom:[/path/to/ks.cfg]
kspath = &&;
p = strchr(kssrc, ':');
kspath = p + 1;
if (!p || strlen(kspath) & 1) {
kspath = &/ks.cfg&;
for (i = 0; i & kd-&numK i++) {
if (kd-&known[i].class == CLASS_CDROM) {
logMessage(&kickstartFromCD:trying CD device (%s)&,
kd-&known[i].name);
if (getKickstartFromBlockDevice(kd-&known[i].name,
kspath) == 0) {
return(0);
* if made it here, then couldn't find the kickstart file on the CD
logMessage(&kickstartFromCD:Couldn't find kickstart file on CD&);
int kickstartFromCD(char *kssrc, struct knownDevices * kd, int flags) {
char *p, *
logMessage(&getting kickstart file from first CDROM&);
for (i = 0; i & kd-&numK i++)
if (kd-&known[i].class == CLASS_CDROM)
if (i &= kd-&numKnown) {
logMessage(&No CDROM devices found!&);
/* format is ks=cdrom:[/path/to/ks.cfg] */
kspath = &&;
p = strchr(kssrc, ':');
kspath = p + 1;
if (!p || strlen(kspath) & 1)
kspath = &/ks.cfg&;
if ((rc=getKickstartFromBlockDevice(kd-&known[i].name, kspath))) {
if (rc == 3) {
startNewt(flags);
newtWinMessage(_(&Error&), _(&OK&),
_(&Cannot find kickstart file on CDROM.&));
其他一些c源码下载
其他文章:
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:1133264次
积分:14421
积分:14421
排名:第566名
原创:116篇
转载:527篇
译文:50篇
评论:121条
(1)(1)(1)(3)(3)(3)(1)(2)(1)(1)(1)(1)(1)(4)(4)(1)(1)(1)(1)(1)(1)(2)(3)(29)(22)(9)(11)(1)(8)(35)(26)(1)(3)(1)(1)(2)(4)(1)(1)(1)(1)(1)(9)(24)(89)(86)(85)(68)(76)(34)(22)(4)c++ - There is no disk in the drive. Please insert a disk into drive E: - Super User
to customize your list.
Super User is a question and answer site for computer enthusiasts and power users. J it only takes a minute:
Here's how it works:
Anybody can ask a question
Anybody can answer
The best answers are voted up and rise to the top
I have an issue with this message that appears every time I try to compile any kind of Code in C++ language. I'm really tired trying to find a solution and its so annoying cause every time I want to test my code, this message (There is no disk in the drive. Please insert a disk into drive E:.) pop's up and need to click cancel/try again like 10 times in a row to remove it.
I found some relation about my issue and this thread:
But the thing is, I tried to follow each steps, but since the start I can't even do the first step (Insert a removable disk in the removable drive before you start the computer.), I do this, but my PC don't place the Removable Drive in the E: spot.
I click on preferences to check info about this E: Drive, but doesn't have space. Its like an imaginary drive (does nothing).
I can't figure out what's going on. Some Pics for help:
Any idea on how to remove this E: spot?
59.1k18120149
Reconfirming Doktoro Reichard's post, it's likely you're running into this known issue with hard-coded references to e: and i: in MinGW:
For example:
$ strings /c/mingw/bin/gcc.exe | grep '[a-z]:/[a-z]'
e:/p/giaw/mingw/lib/gcc/
e:/p/giaw/mingw/libexec/gcc/
e:/p/giaw/mingw/bin/
e:/p/giaw/mingw
e:/p/giaw/mingw/share/locale
i:/p/giaw/mingw/share/locale
i:/p/giaw/mingw/share/locale
The way I resolved this is to remove any/all E: or I: drives on my system.
By using Disk Management, I was able to rename a card reader from E: to not-E: and the error went away.
It seems that your C++ compiler/build environment is somewhere referring to a drive E: even though you don't have one.
You will have to get rid of this non-functional reference to stop this.
Maybe you've got E: mentioned somewhere as an INCLUDE of LIB path ?
Are you using a makefile or solution file made be someone else that has E: mentioned somewhere ?
Check the compile/build logfile for remarks like "can't open file E:\xxxxxxx". That might give a clue where the problem is exactly located.
10.3k12436
I also started having this issue just out of nowhere. Yesterday i was compiling and executing code without a hitch and today all of a sudden i get an error saying "There is no disk in the drive. Please insert a disk into drive E: ". . .
All that had changed between now and yesterday was that i had used my DVD drive, which is drive E, to install a program. So somehow it affected GCC. All I did was open my DVD Drive and close it again and all seems fine now.
I realise my answer is not nearly as technical as the others but sometimes the solution need not be technical or complicated. Sometimes a simple "open, close" will do wonders! ;) Just thought i would share how i solved the issue.
to answer this question.
Not the answer you're looking for?
Browse other questions tagged
Super User works best with JavaScript enabled刚安装好的泰坦之旅 不朽王座 运行出现Titan Quest PLEASE insert the original Titan Quest disc_百度知道

我要回帖

更多关于 please insert disc 的文章

 

随机推荐