1*9a267036Sbjh21 /* $NetBSD: devopen.c,v 1.3 2006/04/05 21:30:29 bjh21 Exp $ */
246dbb0f2Sreinoud
346dbb0f2Sreinoud /*-
4*9a267036Sbjh21 * Copyright (c) 2001, 2006 Ben Harris
546dbb0f2Sreinoud * All rights reserved.
646dbb0f2Sreinoud *
746dbb0f2Sreinoud * Redistribution and use in source and binary forms, with or without
846dbb0f2Sreinoud * modification, are permitted provided that the following conditions
946dbb0f2Sreinoud * are met:
1046dbb0f2Sreinoud * 1. Redistributions of source code must retain the above copyright
1146dbb0f2Sreinoud * notice, this list of conditions and the following disclaimer.
1246dbb0f2Sreinoud * 2. Redistributions in binary form must reproduce the above copyright
1346dbb0f2Sreinoud * notice, this list of conditions and the following disclaimer in the
1446dbb0f2Sreinoud * documentation and/or other materials provided with the distribution.
1546dbb0f2Sreinoud * 3. The name of the author may not be used to endorse or promote products
1646dbb0f2Sreinoud * derived from this software without specific prior written permission.
1746dbb0f2Sreinoud *
1846dbb0f2Sreinoud * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1946dbb0f2Sreinoud * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
2046dbb0f2Sreinoud * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2146dbb0f2Sreinoud * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2246dbb0f2Sreinoud * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2346dbb0f2Sreinoud * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2446dbb0f2Sreinoud * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2546dbb0f2Sreinoud * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2646dbb0f2Sreinoud * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2746dbb0f2Sreinoud * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2846dbb0f2Sreinoud */
2946dbb0f2Sreinoud
30bc24b5d8Sbjh21 #include <sys/disklabel.h>
31bc24b5d8Sbjh21 #include <lib/libkern/libkern.h>
3246dbb0f2Sreinoud #include <lib/libsa/stand.h>
33bc24b5d8Sbjh21 #include <riscosdisk.h>
3446dbb0f2Sreinoud
3546dbb0f2Sreinoud int
devopen(struct open_file * f,const char * fname,char ** file)3646dbb0f2Sreinoud devopen(struct open_file *f, const char *fname, char **file)
3746dbb0f2Sreinoud {
38bc24b5d8Sbjh21 #ifdef LIBSA_SINGLE_FILESYSTEM
3946dbb0f2Sreinoud
4046dbb0f2Sreinoud /* We don't support any devices yet. */
4146dbb0f2Sreinoud f->f_flags |= F_NODEV;
4246dbb0f2Sreinoud *file = (char *)fname;
4346dbb0f2Sreinoud return 0;
44bc24b5d8Sbjh21 #else
45bc24b5d8Sbjh21 char *p, *fsname;
46bc24b5d8Sbjh21 int part, drive, err, fslen;
47bc24b5d8Sbjh21
48bc24b5d8Sbjh21 p = strchr(fname, ':');
49bc24b5d8Sbjh21 if (p == NULL || p == fname) return ENOENT;
50bc24b5d8Sbjh21 *file = p + 1;
51bc24b5d8Sbjh21 p--;
52bc24b5d8Sbjh21 if (p == fname) return ENOENT;
53*9a267036Sbjh21 if (islower((unsigned char)*p))
54bc24b5d8Sbjh21 part = *p-- - 'a';
55bc24b5d8Sbjh21 else
56bc24b5d8Sbjh21 part = RAW_PART;
57bc24b5d8Sbjh21 if (p == fname) return ENOENT;
58bc24b5d8Sbjh21 drive = 0;
59*9a267036Sbjh21 while (isdigit((unsigned char)*p) && p >= fname)
60bc24b5d8Sbjh21 drive = drive * 10 + *p-- - '0';
61bc24b5d8Sbjh21 if (p <= fname) return ENOENT;
62bc24b5d8Sbjh21
63bc24b5d8Sbjh21 fslen = p + 1 - fname;
64bc24b5d8Sbjh21 fsname = alloc(fslen + 1);
65bc24b5d8Sbjh21 memcpy(fsname, fname, fslen);
66bc24b5d8Sbjh21 fsname[fslen] = 0;
67bc24b5d8Sbjh21 err = rodisk_open(f, fsname, drive, part);
68bc24b5d8Sbjh21 dealloc(fsname, fslen + 1);
69bc24b5d8Sbjh21 return err;
70bc24b5d8Sbjh21 #endif
7146dbb0f2Sreinoud }
72