Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/share/examples/rump/sdread Use DIOCTUR to test if a newly co...
details: https://anonhg.NetBSD.org/src/rev/2266caee7fb9
branches: trunk
changeset: 753312:2266caee7fb9
user: pooka <pooka%NetBSD.org@localhost>
date: Mon Mar 22 20:37:26 2010 +0000
description:
Use DIOCTUR to test if a newly configured CD drive is ready instead
of playing a random waiting game.
diffstat:
share/examples/rump/sdread/sdread.c | 47 ++++++++++++++++++++++++++++++------
1 files changed, 39 insertions(+), 8 deletions(-)
diffs (75 lines):
diff -r abc8fecaea87 -r 2266caee7fb9 share/examples/rump/sdread/sdread.c
--- a/share/examples/rump/sdread/sdread.c Mon Mar 22 19:30:53 2010 +0000
+++ b/share/examples/rump/sdread/sdread.c Mon Mar 22 20:37:26 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sdread.c,v 1.4 2010/03/07 23:18:17 pooka Exp $ */
+/* $NetBSD: sdread.c,v 1.5 2010/03/22 20:37:26 pooka Exp $ */
/*
* Copyright (c) 2009 Antti Kantee. All Rights Reserved.
@@ -28,6 +28,7 @@
#include <sys/types.h>
#include <sys/dirent.h>
#include <sys/mount.h>
+#include <sys/dkio.h>
#include <ufs/ufs/ufsmount.h>
#include <msdosfs/msdosfsmount.h>
@@ -51,6 +52,38 @@
* rump kernel. Optionally copy a file out of the mounted file system.
*/
+/* recent -current, appease 5.0 etc. userland */
+#ifndef DIOCTUR
+#define DIOCTUR _IOR('d', 128, int)
+#endif
+
+static void
+waitcd(void)
+{
+ int fd, val = 0, rounds = 0;
+
+ fd = rump_sys_open("/dev/rcd0d", O_RDWR);
+ do {
+ if (rounds > 0) {
+ if (rounds == 1) {
+ printf("Waiting for CD device to settle ");
+ } else {
+ printf(".");
+ }
+ fflush(stdout);
+ sleep(1);
+ }
+ if (rump_sys_ioctl(fd, DIOCTUR, &val) == -1)
+ err(1, "DIOCTUR");
+ rounds++;
+ } while (val == 0 || rounds >= 30);
+
+ if (!val)
+ printf(" giving up\n");
+ else
+ printf(" done!\n");
+}
+
int
main(int argc, char *argv[])
{
@@ -96,13 +129,11 @@
&args, sizeof(args)) == -1) {
if (rump_sys_mount(MOUNT_FFS, "/mp", MNT_RDONLY,
&uargs, sizeof(uargs)) == -1) {
- printf("Trying CD. This might fail with "
- "\"media not present\".\n");
- printf("If that happens, wait a while without "
- "unplugging the device and re-run.\n");
- printf("Some devices apparently need a long time "
- "to settle after they are initialized.\n\n");
-
+ /*
+ * Wait for CD media to settle. In the end,
+ * just try to do it anyway and see if we fail.
+ */
+ waitcd();
if (rump_sys_mount(MOUNT_CD9660, "/mp", MNT_RDONLY,
&iargs, sizeof(iargs)) == -1) {
err(1, "mount");
Home |
Main Index |
Thread Index |
Old Index