Author: jgg
Date: 1999-04-03 01:05:24 GMT
CDrom fixes
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: cdromutl.cc,v 1.2 1999/03/28 01:37:26 jgg Exp $
+// $Id: cdromutl.cc,v 1.3 1999/04/03 01:05:24 jgg Exp $
/* ######################################################################
CDROM Utilities - Some functions to manipulate CDROM mounts.
/* ######################################################################
CDROM Utilities - Some functions to manipulate CDROM mounts.
#include <apt-pkg/error.h>
#include <apt-pkg/md5.h>
#include <apt-pkg/fileutl.h>
#include <apt-pkg/error.h>
#include <apt-pkg/md5.h>
#include <apt-pkg/fileutl.h>
+#include <apt-pkg/configuration.h>
#include <sys/wait.h>
#include <sys/errno.h>
#include <sys/wait.h>
#include <sys/errno.h>
#include <stdio.h>
/*}}}*/
#include <stdio.h>
/*}}}*/
-// UnmountCdrom - Unmount a cdrom /*{{{*/
+// IsMounted - Returns true if the mount point is mounted /*{{{*/
// ---------------------------------------------------------------------
// ---------------------------------------------------------------------
-/* Forking umount works much better than the umount syscall which can
- leave /etc/mtab inconsitant. We drop all messages this produces. */
-bool UnmountCdrom(string Path)
+/* This is a simple algorithm that should always work, we stat the mount point
+ and the '..' file in the mount point and see if they are on the same device.
+ By definition if they are the same then it is not mounted. This should
+ account for symlinked mount points as well. */
+bool IsMounted(string &Path)
{
if (Path.empty() == true)
return false;
{
if (Path.empty() == true)
return false;
return _error->Errno("stat","Unable to stat the mount point %s",Path.c_str());
if (Buf.st_dev == Buf2.st_dev)
return _error->Errno("stat","Unable to stat the mount point %s",Path.c_str());
if (Buf.st_dev == Buf2.st_dev)
+ return false;
+ return true;
+}
+ /*}}}*/
+// UnmountCdrom - Unmount a cdrom /*{{{*/
+// ---------------------------------------------------------------------
+/* Forking umount works much better than the umount syscall which can
+ leave /etc/mtab inconsitant. We drop all messages this produces. */
+bool UnmountCdrom(string Path)
+{
+ if (IsMounted(Path) == false)
return true;
int Child = fork();
return true;
int Child = fork();
for (int I = 0; I != 3; I++)
dup2(open("/dev/null",O_RDWR),I);
for (int I = 0; I != 3; I++)
dup2(open("/dev/null",O_RDWR),I);
- const char *Args[10];
- Args[0] = "umount";
- Args[1] = Path.c_str();
- Args[2] = 0;
- execvp(Args[0],(char **)Args);
- exit(100);
+ if (_config->Exists("Acquire::cdrom::"+Path+"::UMount") == true)
+ {
+ if (system(_config->Find("Acquire::cdrom::"+Path+"::UMount").c_str()) != 0)
+ _exit(100);
+ _exit(0);
+ }
+ else
+ {
+ const char *Args[10];
+ Args[0] = "umount";
+ Args[1] = Path.c_str();
+ Args[2] = 0;
+ execvp(Args[0],(char **)Args);
+ _exit(100);
+ }
/* We fork mount and drop all messages */
bool MountCdrom(string Path)
{
/* We fork mount and drop all messages */
bool MountCdrom(string Path)
{
+ if (IsMounted(Path) == true)
+ return true;
+
int Child = fork();
if (Child < -1)
return _error->Errno("fork","Failed to fork");
int Child = fork();
if (Child < -1)
return _error->Errno("fork","Failed to fork");
for (int I = 0; I != 3; I++)
dup2(open("/dev/null",O_RDWR),I);
for (int I = 0; I != 3; I++)
dup2(open("/dev/null",O_RDWR),I);
- const char *Args[10];
- Args[0] = "mount";
- Args[1] = Path.c_str();
- Args[2] = 0;
- execvp(Args[0],(char **)Args);
- exit(100);
+ if (_config->Exists("Acquire::cdrom::"+Path+"::Mount") == true)
+ {
+ if (system(_config->Find("Acquire::cdrom::"+Path+"::Mount").c_str()) != 0)
+ _exit(100);
+ _exit(0);
+ }
+ else
+ {
+ const char *Args[10];
+ Args[0] = "mount";
+ Args[1] = Path.c_str();
+ Args[2] = 0;
+ execvp(Args[0],(char **)Args);
+ _exit(100);
+ }
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: apt-cdrom.cc,v 1.19 1999/03/29 19:28:52 jgg Exp $
+// $Id: apt-cdrom.cc,v 1.20 1999/04/03 01:05:25 jgg Exp $
/* ######################################################################
APT CDROM - Tool for handling APT's CDROM database.
/* ######################################################################
APT CDROM - Tool for handling APT's CDROM database.
UnmountCdrom(CDROM);
// Mount the new CDROM
UnmountCdrom(CDROM);
// Mount the new CDROM
- Prompt("Please insert a Disc in the drive and press any key");
+ Prompt("Please insert a Disc in the drive and press enter");
cout << "Mounting CD-ROM" << endl;
if (MountCdrom(CDROM) == false)
cout << "Mounting CD-ROM" << endl;
if (MountCdrom(CDROM) == false)
- {
- cout << "Failed to mount the cdrom." << endl;
- return false;
- }
+ return _error->Error("Failed to mount the cdrom.");
}
// Hash the CD to get an ID
}
// Hash the CD to get an ID
dit(bf(cdrom))
CDROM URIs; the only setting for CDROM URIs is the mount point, cdrom::Mount
which must be the mount point for the CDROM drive as specified in /etc/fstab.
dit(bf(cdrom))
CDROM URIs; the only setting for CDROM URIs is the mount point, cdrom::Mount
which must be the mount point for the CDROM drive as specified in /etc/fstab.
+It is possible to provide alternate mount and unmount commands if your
+mount point cannot be listed in the fstab (such as an SMB mount). The syntax
+is to put "/cdrom/"::Mount "foo"; within the cdrom block. It is important to
+have the trailing slash. Unmount commands can be specified using UMount.
bf(/usr/doc/apt/examples/apt.conf) contains a sample configuration file
showing the default values for all possible options.
bf(/usr/doc/apt/examples/apt.conf) contains a sample configuration file
showing the default values for all possible options.
/etc/apt/apt.conf
manpageseealso()
/etc/apt/apt.conf
manpageseealso()
-// $Id: apt.conf,v 1.28 1999/03/15 23:05:49 jgg Exp $
+// $Id: apt.conf,v 1.29 1999/04/03 01:05:25 jgg Exp $
/* This file is an index of all APT configuration directives. It should
NOT actually be used as a real config file, though it is a completely
valid file.
/* This file is an index of all APT configuration directives. It should
NOT actually be used as a real config file, though it is a completely
valid file.
+ Mount "/cdrom";
+
+ // You need the trailing slash!
+ "/cdrom/"
+ {
+ Mount "sleep 1000";
+ UMount "sleep 500";
+ }
pkgInitialize "false"; // This one will dump the configuration space
NoLocking "false";
Acquire::Ftp "false"; // Show ftp command traffic
pkgInitialize "false"; // This one will dump the configuration space
NoLocking "false";
Acquire::Ftp "false"; // Show ftp command traffic
+ aptcdrom "false"; // Show found package files