summaryrefslogtreecommitdiff
path: root/usr/src/lib/libvolmgt/common/volname.c
blob: d04ffa22cf911a9f03744c11d61f02ae5730ec9b (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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright (c) 1996 by Sun Microsystems, Inc.
 * All rights reserved.
 */

/*LINTLIBRARY*/

#pragma ident	"%Z%%M%	%I%	%E% SMI"

#include	<stdio.h>
#include	<stdlib.h>
#include	<string.h>
#include	<dirent.h>
#include	<string.h>
#include	<errno.h>
#include	<limits.h>
#include	<unistd.h>
#include	<volmgt.h>
#include	<sys/types.h>
#include	<sys/stat.h>
#include	<sys/param.h>
#include	<sys/vol.h>

#include	"volmgt_private.h"



#define	ALIAS_DIR	"dev/aliases"
#define	HACKNAME_MAX	5		/* max aliases to try */
#define	NUMBUF_SZ	10		/* big enough for HACKNAME */


/* a shortcut for checkinf for absolute pathnames */
#define	IS_ABS_PATH(p)	(*(p) == '/')


/*
 * arc approved interface (pending)
 *	- can not be modified without approval from an arc
 *
 * committment level:
 *	public
 *
 * description:
 *	media_findname: try to come up with the character device when
 *	provided with a starting point.  This interface provides the
 *	application programmer to provide "user friendly" names and
 *	easily determine the "/vol" name.
 *
 * arguments:
 *	start - a string describing a device.  This string can be:
 *		- a full path name to a device (insures it's a
 *		  character device by using getfullrawname()).
 *		- a full path name to a volume management media name
 *		  with partitions (will return the lowest numbered
 *		  raw partition.
 *		- the name of a piece of media (e.g. "fred").
 *		- a symbolic device name (e.g. floppy0, cdrom0, etc)
 *		- a name like "floppy" or "cdrom".  Will pick the lowest
 *		  numbered device with media in it.
 *
 * return value(s):
 *	A pointer to a string that contains the character device
 *	most appropriate to the "start" argument.
 *
 *	NULL indicates that we were unable to find media based on "start".
 *
 *	The string must be free(3)'d.
 *
 * preconditions:
 *	none.
 */
char *
media_findname(char *start)
{
	static char 	*media_findname_work(char *);
	char		*s = NULL;


	/*
	 * This is just a wrapper to implement the volmgt_check nastyness.
	 */
#ifdef	DEBUG
	denter("media_findname(%s): entering\n", start ? start : "<null ptr>");
#endif

	if (start == NULL) {
		errno = EFAULT;
		goto dun;
	}

	/*
	 * If we don't get positive results, we kick volume management
	 * to ask it to look in the floppy drive.
	 *
	 * XXX: maybe this should be configurable ???
	 */
	if ((s = media_findname_work(start)) == NULL) {
#ifdef	DEBUG
		dprintf("media_findname: calling volcheck and trying again\n");
#endif
		(void) volmgt_check(NULL);
		s = media_findname_work(start);
	}

dun:
#ifdef	DEBUG
	dexit("media_findname: returning \"%s\"\n", s ? s : "<null ptr>");
#endif
	return (s);
}


/*
 * Return a raw name, given a starting point.
 *
 * Assume: input string ptr is not null
 */
static char *
media_findname_work(char *start)
{
	extern char		*vol_basename(char *);
	static void		volmgt_deref_link(char *, char *, char *);
	char			pathbuf[MAXPATHLEN+1];
	char			*rv;
	char			*s;
	char			linkbuf[MAXNAMELEN+1];
	char			*nameptr;
	struct stat64		sb;
	int			n;
	int			i;
	static const char	*vold_root = NULL;
	static char		vold_alias_dir[MAXPATHLEN+1];
	char			*res = NULL;
	DIR			*dirp = NULL;
	struct dirent64		*dp;



#ifdef	DEBUG
	denter("media_findname_work(%s): entering\n", start);
#endif

	if (vold_root == NULL) {
		vold_root = volmgt_root();
		(void) concat_paths(vold_alias_dir, (char *)vold_root,
		    (char *)ALIAS_DIR, NULL);
	}

	/*
	 * if this is an absolute path name then
	 *  if it's a symlink deref it
	 *  if it's a raw device then we're done
	 *  else if it's a directory then look for a dev under it
	 */
	if (IS_ABS_PATH(start)) {

		/* try to get data on name passed in */
		if (lstat64(start, &sb) < 0) {
#ifdef	DEBUG
			dprintf(
			"media_findname_work: lstat of \"%s\" (errno %d)\n",
			    start, errno);
#endif
			goto dun;		/* error exit */
		}

		/*
		 * if is this a link to something else (e.g. ".../floppy0")
		 * and it's in the volmgt namespace, then deref it
		 */
		if (S_ISLNK(sb.st_mode) && (strncmp(start, vold_alias_dir,
		    strlen(vold_alias_dir)) == 0)) {

			/* it's a symlink */
			if ((n = readlink(start, linkbuf, MAXNAMELEN)) <= 0) {
				/* we can't read the link */
#ifdef	DEBUG
				dprintf(
		"media_findname_work: readlink(\"%s\") failed (errno %d)\n",
				    start, errno);
#endif
				goto dun;	/* error exit */
			}
			linkbuf[n] = NULLC;

			/* dereference the link */
			volmgt_deref_link(pathbuf, start, linkbuf);

			/* stat where "start" pointed at */
			if (stat64(pathbuf, &sb) < 0) {
#ifdef	DEBUG
				dprintf(
		"media_findname_work: stat failed on \"%s\" (errno %d)\n",
				    pathbuf, errno);
#endif
				goto dun;	/* error exit */
			}
			nameptr = pathbuf;

		} else {
			nameptr = start;
		}

		/* do we already have a char-spcl device ?? */
		if (S_ISCHR(sb.st_mode)) {
			/*
			 * absoluate pathname of a char-spcl device passed in
			 */
			res = strdup(nameptr);
			goto dun;		/* success */
		}

		/* not a char-spcl device -- is it a dir ?? */
		if (S_ISDIR(sb.st_mode)) {
			/* open the dir and find first char-spcl device */
			if ((s = getrawpart0(nameptr)) != NULL) {
				/*
				 * absoluate pathname to a directory passed
				 * in, under which there is at least one
				 * char-spcl device
				 */
				free(s);
				res = strdup(nameptr);
				goto dun;	/* success */
			}
		}

		/*
		 * try to get the char-spcl name if this is a blk-spcl
		 *
		 * XXX: shouldn't we ensure this is a blk spcl device?
		 */
		rv = volmgt_getfullrawname(nameptr);
		if ((rv == NULL) || (*rv == NULLC)) {
			goto dun;		/* error exit */
		}

		/* stat the fullrawname device (to see if it's char-spcl) */
		if (stat64(rv, &sb) < 0) {
#ifdef	DEBUG
			dprintf(
			    "media_findname_work: stat of \"%s\" (errno %d)\n",
			    rv, errno);
#endif
			goto dun;		/* error exit */
		}

		/* have we found the char-spcl device ?? */
		if (S_ISCHR(sb.st_mode)) {
			/*
			 * absolute pathname to block device supplied and
			 * converted to an absoluate pathname to a char device
			 */
			res = rv;		/* already malloc'ed */
			goto dun;		/* success */
		}

		/*
		 * fullrawname not a char-spcl device -- is it a dir ??
		 *
		 * XXX: didn't we already check for a directory name
		 * being supplied above?
		 */
		if (S_ISDIR(sb.st_mode)) {
			/* open dir and find first char-spcl device */
			if ((s = getrawpart0(rv)) != NULL) {
				/*
				 * the absolute pathname of directory
				 * containing at least one char-spcl device
				 * was passed in
				 */
				free(s);
				res = strdup(rv);
				goto dun;	/* success */
			}
		}

		/* having a full pathname didn't help us */
		goto dun;	/* failure -- pathname not found */
	}

	/*
	 * Ok, now we check to see if it's an alias.
	 * Note here that in the case of an alias, we prefer
	 * to return what the alias (symbolic link) points
	 * at, rather than the symbolic link.  Makes for
	 * nicer printouts and such.
	 */
	(void) concat_paths(pathbuf, vold_alias_dir, start, NULL);

#ifdef	DEBUG
	dprintf("media_findname_work: looking for \"%s\"\n", pathbuf);
#endif

	if (stat64(pathbuf, &sb) == 0) {
#ifdef	DEBUG
		dprintf("media_findname_work: is \"%s\" a chr-spcl dev?\n",
		    pathbuf);
#endif
		/* is this a char-spcl device ?? */
		if (S_ISCHR(sb.st_mode)) {
			/* it's probably a link, so ... */
			if ((n = readlink(pathbuf,
			    linkbuf, MAXNAMELEN)) <= 0) {
				/*
				 * error (since we are in the symlink
				 * directory) not a link, but just punt
				 * anyway
				 */
				res = strdup(pathbuf);
			} else {
				/* it was a link */
				linkbuf[n] = NULLC;
				res = strdup(linkbuf);
			}
			goto dun;		/* success */
		}

#ifdef	DEBUG
		dprintf("media_findname_work: not chr-spcl -- is it a dir?\n");
#endif
		/* not a char-spcl device -- is it a dir ?? */
		if (S_ISDIR(sb.st_mode)) {
			/* it's probably a link, so ... */
			if ((n = readlink(pathbuf,
			    linkbuf, MAXNAMELEN)) <= 0) {
				/*
				 * error, but just punt anyway
				 */
				nameptr = pathbuf;
				s = getrawpart0(pathbuf);
			} else {
				/* it was a link */
				linkbuf[n] = NULLC;
				/* open dir, finding first char-spcl dev */
				nameptr = linkbuf;
				s = getrawpart0(linkbuf);
			}
			if (s != NULL) {
				free(s);
				res = strdup(nameptr);
				goto dun;
			}
		}
	}

	/*
	 * check all aliases in the alias dir, to see if any match
	 */
	if ((dirp = opendir(vold_alias_dir)) == NULL) {
		goto try_hack;
	}

	while (dp = readdir64(dirp)) {

		/* skip uninteresting entries */
		if (strcmp(dp->d_name, ".") == 0) {
			continue;
		}
		if (strcmp(dp->d_name, "..") == 0) {
			continue;
		}

#ifdef	DEBUG
		dprintf("media_findname_work: scanning alias \"%s\" ...\n",
		    dp->d_name);
#endif
		/*
		 * open the link and see if it points at our entry
		 */
		(void) concat_paths(pathbuf, vold_alias_dir, dp->d_name,
		    NULL);
		if ((n = readlink(pathbuf, linkbuf, MAXNAMELEN)) <= 0) {
#ifdef	DEBUG
				dprintf(
		"media_findname_work: readlink(\"%s\") failed (errno %d)\n",
				    pathbuf, errno);
#endif
			continue;
		}
		linkbuf[n] = NULLC;

#ifdef	DEBUG
		dprintf("media_findname_work: scanning link \"%s\" ...\n",
		    linkbuf);
#endif
		if (strcmp(vol_basename(linkbuf), start) == 0) {

			/* we *think* we've found a match */

			if (stat64(linkbuf, &sb) == 0) {

				if (S_ISCHR(sb.st_mode)) {
					res = strdup(linkbuf);
					goto dun;
				}

				if (S_ISDIR(sb.st_mode)) {
					res = getrawpart0(linkbuf);
					if (res != NULL) {
						free(res);
						res = strdup(linkbuf);
					}
					goto dun;
				}

			}

		}
	}

try_hack:

	/*
	 * Ok, well maybe that's not it.  Let's try the
	 * hackname alias.
	 */

	/*
	 * This creates the "hack" name.  The model
	 * is that xx# has the alias xx.  So, cdrom#
	 * and floppy# (the most frequent case) can
	 * be referred to as cdrom and floppy.
	 * We poke at what we consider to be a reasonable number of
	 * devices (currently 5) before giving up.
	 */

	for (i = 0; i < HACKNAME_MAX; i++) {
		char	num_buf[NUMBUF_SZ];


		(void) sprintf(num_buf, "%d", i);
		(void) concat_paths(pathbuf, vold_alias_dir, start, num_buf);

		if (stat64(pathbuf, &sb) == 0) {

			/* is it a char-spcl device ?? */
			if (S_ISCHR(sb.st_mode)) {
				/* it's probably a link, so... */
				if ((n = readlink(pathbuf,
				    linkbuf, MAXNAMELEN)) <= 0) {
					/* it wasn't a link */
					res = strdup(pathbuf);
				} else {
					/* it was a link */
					linkbuf[n] = NULLC;
					res = strdup(linkbuf);
				}
				goto dun;
			}

			/* not a char-spcl device -- is it a dir ?? */
			if (S_ISDIR(sb.st_mode)) {
				/* it's probably a link, so ... */
				if ((n = readlink(pathbuf,
				    linkbuf, MAXNAMELEN)) <= 0) {
					/* get fist char-spcl dev in dir */
					nameptr = pathbuf;
					s = getrawpart0(pathbuf);
				} else {
					/* it was a link */
					linkbuf[n] = NULLC;
					/* get fist char-spcl dev in dir */
					nameptr = linkbuf;
					s = getrawpart0(linkbuf);
				}
				if (s != NULL) {
					free(s);
					res = strdup(nameptr);
					goto dun;
				}
			}
		}
	}

#ifdef	DEBUG
	dprintf("media_findname_work: %s didn't match any test!\n", start);
#endif

dun:
	if (dirp != NULL) {
		(void) closedir(dirp);
	}

#ifdef	DEBUG
	dexit("media_findname_work: returning \"%s\"\n",
	    res ? res : "<null ptr>");
#endif
	return (res);
}


/*
 * deref the link (in link_buf) read from path_buf into res_buf
 *
 * if there's any problem then just return the contents of the link buffer
 */
static void
volmgt_deref_link(char *res_buf, char *path_buf, char *link_buf)
{
	static char	*vol_dirname(char *);
	char		buf[MAXPATHLEN+1];
	char		*path_dirname;


	if (IS_ABS_PATH(link_buf)) {

		/* degenerate case -- link is okay the way it is */
		(void) strncpy(res_buf, link_buf, MAXPATHLEN);

	} else {

		/* link pathname is relative */

		/* get a writable copy of the orig path */
		(void) strncpy(buf, path_buf, MAXPATHLEN);

		/* get the dir from the orig path */
		if ((path_dirname = vol_dirname(buf)) == NULL) {

			/* oh oh -- just use the link contents */
			(void) strncpy(res_buf, link_buf, MAXPATHLEN);

		} else {

			/* concat the orig dir with the link path (if room) */
			(void) concat_paths(res_buf, path_dirname, link_buf,
			    NULL);
		}
	}
}


/*
 * return the dirname part of a path (i.e. all but last component)
 *
 * NOTE: may destuctively change "path" (i.e. it may write a null over
 *	the last slash in the path to convert it into a dirname)
 */
static char *
vol_dirname(char *path)
{
	char	*cp;


	/* find the last seperator in the path */
	if ((cp = strrchr(path, '/')) == NULL) {
		/* must be just a local name -- use the local dir */
		return (".");
	}

	/* replace the last slash with a null */
	*cp = NULLC;

	/* return all but the last component */
	return (path);
}


/*
 * This function runs through the list of "old" aliases to
 * see if someone is calling a device by an old name before
 * the glory of volume management.
 */

struct alias {
	char	*alias;
	char	*name;
};

static struct alias volmgt_aliases[] = {
	{ "fd", "floppy0" },
	{ "fd0", "floppy0" },
	{ "fd1", "floppy1" },
	{ "diskette", "floppy0" },
	{ "diskette0", "floppy0" },
	{ "diskette1", "floppy1" },
	{ "rdiskette", "floppy0" },
	{ "rdiskette0", "floppy0" },
	{ "rdiskette1", "floppy1" },
	{ "cd", "cdrom0" },
	{ "cd0", "cdrom0" },
	{ "cd1", "cdrom1" },
	{ "sr", "cdrom0" },
	{ "sr0", "cdrom0" },
	{ "/dev/sr0", "cdrom0" },
	{ "/dev/rsr0", "cdrom0" },
	{ "", ""}
};


/*
 * "old" aliases -- XXX: only make sense if vold not running?
 */
static struct alias device_aliases[] = {
	{ "fd", "/dev/rdiskette" },
	{ "fd0", "/dev/rdiskette" },
	{ "fd1", "/dev/rdiskette1" },
	{ "diskette", "/dev/rdiskette" },
	{ "diskette0", "/dev/rdiskette0" },
	{ "diskette1", "/dev/rdiskette1" },
	{ "rdiskette", "/dev/rdiskette" },
	{ "rdiskette0", "/dev/rdiskette0" },
	{ "rdiskette1", "/dev/rdiskette1" },
	{ "floppy", "/dev/rdiskette" },
	{ "floppy0", "/dev/rdiskette0" },
	{ "floppy1", "/dev/rdiskette1" },
	{ "cd", "cdrom0" },
	{ "cd0", "cdrom0" },
	{ "cd1", "cdrom1" },
	{ "", ""}
};


/*
 * This is an ON Consolidation Private interface.
 */
char *
_media_oldaliases(char *start)
{
	struct alias	*s, *ns;
	char		*p;
	char		*res;



#ifdef	DEBUG
	denter("_media_oldaliases(%s): entering\n", start);
#endif

	for (s = device_aliases; *s->alias != NULLC; s++) {
		if (strcmp(start, s->alias) == 0) {
			break;
		}
	}

	/* we don't recognize that alias at all */
	if (*s->alias == NULLC) {
#ifdef	DEBUG
		dprintf("_media_oldaliases: failed\n");
#endif
		res = NULL;
		goto dun;
	}

	/* if volume management isn't running at all, give him back the name */
	if (!volmgt_running()) {
#ifdef	DEBUG
		dprintf("_media_oldaliases: no vold!\n");
#endif
		res = strdup(s->name);
		goto dun;
	}
	/*
	 * If volume management is managing that device, look up the
	 * volume management name.
	 */
	if (volmgt_inuse(s->name)) {
		for (s = volmgt_aliases; *s->alias != NULLC; s++) {
			if (strcmp(start, s->alias) == 0) {
				res = strdup(s->name);
				goto dun;
			}
		}
#ifdef	DEBUG
		dprintf("_media_oldaliases: failed\n");
#endif
		res = NULL;
		goto dun;
	}

	/*
	 * If volume management isn't managing the device, it's possible
	 * that he's given us an alias that we should recognize, but the
	 * default name is wrong.  For example a user might have his
	 * cdrom on controller 1, being managed by volume management,
	 * but we would think it isn't because volmgt_inuse just told
	 * us that c0t6d0s2 isn't being managed.  So, before we return
	 * the /dev name, we'll test the alias out using media_findname.
	 * If media_findname can't make sense out of the alias, it probably
	 * means that we really, really aren't managing the device and
	 * should just return the /dev name.  Whew.  Isn't this grody?
	 */

	for (ns = volmgt_aliases; *ns->alias != NULLC; ns++) {
		if (strcmp(start, ns->alias) == 0) {
			if ((p = media_findname_work(ns->name))) {
				res = p;
				goto dun;
			} else {
				break;
			}
		}
	}

	res = strdup(s->name);
dun:
#ifdef	DEBUG
	dexit("_media_oldaliases: returning %s\n", res ? res : "<null ptr>");
#endif
	return (res);
}


/*
 * This is an ON Consolidation Private interface.
 *
 * Print out the aliases available to the program user.  Changes
 * depending in whether volume management is running.
 */
void
_media_printaliases(void)
{
	struct alias		*s;
	DIR			*dirp;
	struct dirent64		*dp;
	char			pathbuf[MAXPATHLEN+1];
	char			*p;
	static const char	*vold_root = NULL;



	if (vold_root == NULL) {
		vold_root = volmgt_root();
	}

	if (!volmgt_running()) {
		/* no volume management */
		for (s = device_aliases; *s->alias != NULLC; s++) {
			(void) printf("\t%s -> %s\n", s->alias, s->name);
		}
		return;
	}

	for (s = volmgt_aliases; *s->alias != NULLC; s++) {
		(void) printf("\t%s -> %s\n", s->alias, s->name);
	}

	(void) concat_paths(pathbuf, (char *)vold_root, ALIAS_DIR, NULL);

	if ((dirp = opendir(pathbuf)) == NULL) {
		return;
	}
	while (dp = readdir64(dirp)) {
		if (strcmp(dp->d_name, ".") == 0) {
			continue;
		}
		if (strcmp(dp->d_name, "..") == 0) {
			continue;
		}
		if ((p = media_findname(dp->d_name)) != NULL) {
			(void) printf("\t%s -> %s\n", dp->d_name, p);
		}
	}
	(void) closedir(dirp);
}