File: create_devdir.c

package info (click to toggle)
oskit 0.97.20000202-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 58,008 kB
  • ctags: 172,612
  • sloc: ansic: 832,827; asm: 7,640; sh: 3,920; yacc: 3,664; perl: 1,457; lex: 427; makefile: 337; csh: 141; awk: 78
file content (785 lines) | stat: -rw-r--r-- 18,565 bytes parent folder | download
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
779
780
781
782
783
784
785
/*
 * Copyright (c) 1997-1999 University of Utah and the Flux Group.
 * All rights reserved.
 * 
 * This file is part of the Flux OSKit.  The OSKit is free software, also known
 * as "open source;" you can redistribute it and/or modify it under the terms
 * of the GNU General Public License (GPL), version 2, as published by the Free
 * Software Foundation (FSF).  To explore alternate licensing terms, contact
 * the University of Utah at csl-dist@cs.utah.edu or +1-801-585-3271.
 * 
 * The OSKit is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GPL for more details.  You should have
 * received a copy of the GPL along with the OSKit; see the file COPYING.  If
 * not, write to the FSF, 59 Temple Place #330, Boston, MA 02111-1307, USA.
 */

/*
 * Implement a virtual directory to be mounted under /dev, and which
 * converts opens into a call into the device code. We export an
 * absio interface which can then be converted into an openfile_t using
 * an soa adaptor. What the caller gets back then, is an openfile_t that
 * talks to a raw device and can be used to read/write into like a character
 * device.
 *
 * At the moment, we only deal with disk drivers, passing the open off into
 * the Linux device drivers. At some point this could be much smarter, by
 * looking at the registered devices and trying to match any arbitrary
 * device open request to an installed device. Someday ...
 */

#include <oskit/fs/dir.h>
#include <oskit/fs/openfile.h>
#include <oskit/fs/filesystem.h>
#include <oskit/io/absio.h>
#include <oskit/io/bufio.h>
#include <oskit/time.h>
#include <oskit/queue.h>
#include <oskit/dev/dev.h>
#include <oskit/dev/bus.h>
#include <oskit/dev/tty.h>
#include <oskit/dev/blk.h>
#include <oskit/dev/ethernet.h>
#include <oskit/startup.h>
#include <oskit/dev/linux.h>
#include <oskit/diskpart/diskpart.h>
#include <oskit/c/fs.h>

#include <sys/types.h>
#include <string.h>
#include <ctype.h>
#include <assert.h>
#include <errno.h>
#include <stdarg.h>
#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <stddef.h>
#include <sys/stat.h>

#ifndef VERBOSITY
#define VERBOSITY 	0
#endif

/*
 * structures to describe a native file or directory. Note how similar
 * they are. As it should (better) be.
 */
struct fs_file {
	oskit_file_t	filei;		/* COM file interface */
	oskit_absio_t	absioi;		/* COM absolute I/O interface */
	oskit_u32_t	count;		/* reference count */
	char		*component;	/* Component name */
	oskit_blkio_t   *bio;		/* Block I/O of open disk/part */
	oskit_u32_t	blksize;	/* For sanity check */
};

struct fs_dir {
	oskit_dir_t	diri;		/* COM directory interface */
	oskit_absio_t	absioi;		/* COM absolute I/O interface */
	oskit_u32_t	count;		/* reference count */
	char		*component;	/* Component name */
};

static struct oskit_file_ops		fs_file_ops;
static struct oskit_dir_ops		fs_dir_ops;
static struct oskit_absio_ops		fs_absio_ops;

/*
 * Create dir/file impls.
 */
static struct fs_file *
fs_file_allocate(const char *component)
{
        struct fs_file	*newfsf = malloc(sizeof(*newfsf));
	int		complen;

        if (newfsf == NULL)
                return 0;
	
        memset(newfsf, 0, sizeof(*newfsf));

	complen = strlen(component);
	
	if ((newfsf->component = malloc(complen + 1)) == NULL) {
		free(newfsf);
		return 0;
	}
	strcpy(newfsf->component, component);

        newfsf->count      = 1;
        newfsf->filei.ops  = &fs_file_ops;
        newfsf->absioi.ops = &fs_absio_ops;

	return newfsf;
}

static struct fs_dir *
fs_dir_allocate(const char *component)
{
        struct fs_dir	*newfsd = malloc(sizeof(*newfsd));
	int		complen;

        if (newfsd == NULL)
                return 0;
	
        memset(newfsd, 0, sizeof(*newfsd));

	complen = strlen(component);
	
	if ((newfsd->component = malloc(complen + 1)) == NULL) {
		free(newfsd);
		return 0;
	}
	strcpy(newfsd->component, component);

        newfsd->count      = 1;
        newfsd->diri.ops   = &fs_dir_ops;
        newfsd->absioi.ops = &fs_absio_ops;

	return newfsd;
}

/*
 * Methods.
 */
static OSKIT_COMDECL
fs_dir_query(oskit_dir_t *d, const oskit_iid_t *iid, void **out_ihandle)
{
	struct fs_dir *fsd = (struct fs_dir *) d;
	assert(fsd->count);

        if (memcmp(iid, &oskit_iunknown_iid, sizeof(*iid)) == 0 ||
            memcmp(iid, &oskit_posixio_iid, sizeof(*iid)) == 0 ||
            memcmp(iid, &oskit_file_iid, sizeof(*iid)) == 0 ||
            memcmp(iid, &oskit_dir_iid, sizeof(*iid)) == 0) {
                *out_ihandle = fsd;
                ++fsd->count;
                return 0;
        }

        *out_ihandle = NULL;
        return OSKIT_E_NOINTERFACE;
}

static OSKIT_COMDECL
fs_file_query(oskit_file_t *f, const oskit_iid_t *iid, void **out_ihandle)
{
        struct fs_file *fsf = (struct fs_file *) f;
	assert(fsf->count);

        if (memcmp(iid, &oskit_iunknown_iid, sizeof(*iid)) == 0 ||
            memcmp(iid, &oskit_posixio_iid, sizeof(*iid)) == 0 ||
            memcmp(iid, &oskit_file_iid, sizeof(*iid)) == 0) {
                *out_ihandle = fsf;
                ++fsf->count;
                return 0;
        }

	if (memcmp(iid, &oskit_absio_iid, sizeof(*iid)) == 0) {
		*out_ihandle = &fsf->absioi;
		++fsf->count;
		return 0;
	}

        *out_ihandle = NULL;
        return OSKIT_E_NOINTERFACE;
}

static OSKIT_COMDECL_U
fs_file_addref(oskit_file_t *f)
{
        struct fs_file *fsf = (struct fs_file *) f;
	
	assert(fsf->count);
	return ++fsf->count;
}

static OSKIT_COMDECL_U
fs_file_release(oskit_file_t *f)
{
        struct fs_file *fsf = (struct fs_file *) f;

	assert(fsf->count);

	if (--fsf->count)
		return fsf->count;

	if (fsf->bio)
		oskit_blkio_release(fsf->bio);
	
	free(fsf->component);
	free(fsf);
	return 0;
}

static OSKIT_COMDECL_U
fs_dir_release(oskit_dir_t *d)
{
        struct fs_dir *fsd = (struct fs_dir *) d;

	assert(fsd->count);

	if (--fsd->count)
		return fsd->count;

	free(fsd->component);
	free(fsd);
	return 0;
}

/*** Operations inherited from oskit_posixio_t ***/

static OSKIT_COMDECL
fs_file_stat(oskit_file_t *f, struct oskit_stat *out_stats)
{
#if VERBOSITY > 1
        struct fs_file *fsf = (struct fs_file *) f;

	printf(__FUNCTION__": asked to stat `%s'\n", fsf->component);
#endif

	/*
	 * Can stat anything we want. Just call it a character special
	 * file and give it a nice set of permissions. 
	 */
	memset(out_stats, 0, sizeof(*out_stats));
	out_stats->mode = OSKIT_S_IFCHR|OSKIT_S_IRUSR|OSKIT_S_IWUSR|
			  OSKIT_S_IRGRP|OSKIT_S_IWGRP|
			  OSKIT_S_IROTH|OSKIT_S_IWOTH;

	return 0;
}

static OSKIT_COMDECL
fs_file_setstat(oskit_file_t *f,
		oskit_u32_t mask, const struct oskit_stat *stats)
{
#if VERBOSITY > 1
        struct fs_file  *fsf = (struct fs_file *) f;

	printf(__FUNCTION__": asked to setstat `%s'\n", fsf->component);
#endif
	return OSKIT_E_NOTIMPL;
}

static OSKIT_COMDECL
fs_file_pathconf(oskit_file_t *f, oskit_s32_t option, oskit_s32_t *out_val)
{
	return OSKIT_E_NOTIMPL;
}

static OSKIT_COMDECL
fs_file_sync(oskit_file_t *f, oskit_bool_t wait)
{
#if VERBOSITY > 1
        struct fs_file  *fsf = (struct fs_file *) f;

	printf(__FUNCTION__": asked to sync on `%s'\n", fsf->component);
#endif

	return OSKIT_E_NOTIMPL;
}

static OSKIT_COMDECL
fs_file_access(oskit_file_t *f, oskit_amode_t mask)
{
#if VERBOSITY > 1
        struct fs_file  *fsf = (struct fs_file *) f;

	printf(__FUNCTION__": asked to access on `%s'\n", fsf->component);
#endif
	return 0;
}

static OSKIT_COMDECL
fs_file_readlink(oskit_file_t *f, char *buf, oskit_u32_t len,
		 oskit_u32_t *out_actual)
{
#if VERBOSITY > 1
        struct fs_file  *fsf = (struct fs_file *) f;

	printf(__FUNCTION__": asked to readlink on `%s'\n", fsf->component);
#endif
	*out_actual = 0;

	return OSKIT_EINVAL;
}

static OSKIT_COMDECL
fs_file_open(oskit_file_t *f, oskit_oflags_t iflags,
	     struct oskit_openfile **out_openfile)
{
        struct fs_file  *fsf = (struct fs_file *) f;
	char		*name, disk[8], part[8];
	oskit_blkio_t   *bio;

#if VERBOSITY > 1
	printf(__FUNCTION__": asked to open `%s'\n", fsf->component);
#endif
        memset(disk, 0, sizeof(disk));
        memset(part, 0, sizeof(part));

	/*
	 * Look at the component name and see if its recognizable as
	 * a linux device name. If it is, separate it from the partition
	 * and use start_disk to get it fired off.
	 */
	name = fsf->component;

	if (*name == 'r') {
		/* All we got is char devices, and linux does not like "r" */
		name++;
	}

	/*
	 * Look for sd, wd, or hd, followed by a single digit.
	 */
	if (strncmp("sd", name, 2) &&
	    strncmp("wd", name, 2) &&
	    strncmp("hd", name, 2))
		return OSKIT_EINVAL;

	if (!isdigit(name[2]))
		return OSKIT_EINVAL;

	/*
	 * Okay, got a valid disk name. Don't worry about what the partition
	 * looks like since it will be checked someplace else.
	 */
	strncpy(disk, name, 3);
	strncpy(part, &name[3], sizeof(part));

	/*
	 * Use the startup library. We get back a blkio.
	 */
	if (start_disk(disk, part,
		       (iflags & OSKIT_O_ACCMODE) == OSKIT_O_RDONLY, &bio)) {
		printf("devdir fs_file_open: "
		       "Could not start disk '%s'\n", name);
		return OSKIT_E_FAIL;
	}
	fsf->bio = bio;
	fsf->blksize = oskit_blkio_getblocksize(bio);

#if VERBOSITY > 1
	printf("devdir fs_file_open: "
	       "Opened `%s' - bio:%p blksize:%d\n", name, bio, fsf->blksize);
#endif
	/*
	 * Open succeeds, but we do not implement peropen state, so just
	 * return status. The absio interface will be used.
	 */
	*out_openfile = 0;
	return 0;
}

static OSKIT_COMDECL
fs_dir_open(oskit_dir_t *d, oskit_oflags_t iflags,
	    struct oskit_openfile **out_opendir)
{
#if VERBOSITY > 1
        struct fs_dir  *fsd = (struct fs_dir *) d;

	printf(__FUNCTION__": asked to open `%s'\n", fsd->component);
#endif
	return OSKIT_E_NOTIMPL;
}

static OSKIT_COMDECL
fs_dir_lookup(oskit_dir_t *d, const char *name, oskit_file_t **out_file)
{
	struct fs_file  *fsf;

#if VERBOSITY > 1
        struct fs_dir	*fsd = (struct fs_dir *) d;

	printf(__FUNCTION__": asked to look up `%s' in `%s'\n",
	       name, fsd->component);
#endif

	/*
	 * Whatever it is, we got it. Its only when the device is opened
	 * that it matters.
	 *
	 * This directory contains only special files, so always create
	 * a file structure, not a directory structure. Maybe someday it
	 * will get more flexible.
	 */
	if ((fsf = fs_file_allocate(name)) == NULL)
		return OSKIT_ENOMEM;
	
	*out_file = &fsf->filei;
	return 0;
}

static OSKIT_COMDECL
fs_dir_create(oskit_dir_t *d, const char *name,
	       oskit_bool_t excl, oskit_mode_t mode,
	       oskit_file_t **out_file)
{
#if VERBOSITY > 1
        struct fs_dir	*fsd = (struct fs_dir *) d;

	printf(__FUNCTION__": asked to create `%s' in '%s'\n",
	       name, fsd->component);
#endif
	return OSKIT_E_NOTIMPL;
}

static OSKIT_COMDECL
fs_dir_link(oskit_dir_t *d, char *name, oskit_file_t *file)
{
	return OSKIT_E_NOTIMPL;
}

static OSKIT_COMDECL
fs_dir_unlink(oskit_dir_t *d, const char *name)
{
#if VERBOSITY > 1
	printf(__FUNCTION__": asked to unlink `%s'\n", name);
#endif
	return OSKIT_E_NOTIMPL;
}

static OSKIT_COMDECL
fs_dir_rename(oskit_dir_t *old_dir, char *old_name,
	      oskit_dir_t *new_dir, char *new_name)
{
#if VERBOSITY > 1
	printf(__FUNCTION__": asked to rename ...\n");
#endif
	return OSKIT_E_NOTIMPL;
}

static OSKIT_COMDECL
fs_dir_mkdir(oskit_dir_t *d, const char *name, oskit_mode_t mode)
{
	return OSKIT_E_NOTIMPL;
}

static OSKIT_COMDECL
fs_dir_rmdir(oskit_dir_t *d, const char *name)
{
#if VERBOSITY > 1
	printf(__FUNCTION__": asked to rmdir `%s'\n", name);
#endif
	return OSKIT_E_NOTIMPL;
}

/* oskit/fs/dir.h says:
 *
 * Read one or more entries in this directory.
 * The offset of the entry to be read is specified in 'inout_ofs';
 * the caller must initially supply zero as the offset,
 * and during each successful call the offset increases
 * by an unspecified amount dependent on the file system.
 * The file system will return at least 'nentries'
 * if there are at least this many remaining in the directory;
 * however, the file system may return more entries.
 *
 * The caller must free the dirents array and the names
 * using the task allocator when they are no longer needed.
 */
/*
 * Since nentries doesn't mean much, we'll just return everything
 * we have.
 */
static OSKIT_COMDECL
fs_dir_getdirentries(oskit_dir_t *d, oskit_u32_t *inout_ofs,
		     oskit_u32_t nentries,
		     struct oskit_dirents **out_dirents)
{
#if VERBOSITY > 1
        struct fs_dir		*fsd = (struct fs_dir *) d;

	printf(__FUNCTION__": asked to getdirentries `%s'\n", fsd->component);
#endif
	
	return OSKIT_E_NOTIMPL;
}

static OSKIT_COMDECL
fs_dir_mknod(oskit_dir_t *d, char *name,
	     oskit_mode_t mode, oskit_dev_t dev)
{
	return OSKIT_E_NOTIMPL;
}

static OSKIT_COMDECL
fs_dir_symlink(oskit_dir_t *d, char *link_name, char *dest_name)
{
#if VERBOSITY > 1
	printf(__FUNCTION__": asked to create symlink `%s' -> `%s'\n",
	       link_name, dest_name);
#endif

	return OSKIT_E_NOTIMPL;
}

static OSKIT_COMDECL
fs_dir_reparent(oskit_dir_t *d, oskit_dir_t *parent, oskit_dir_t **out_dir)
{
	return OSKIT_E_NOTIMPL;
}


static OSKIT_COMDECL
fs_file_getfs(oskit_file_t *f, struct oskit_filesystem **out_fs)
{
	return OSKIT_E_NOTIMPL;	/* XXX implement  */
}

static struct oskit_file_ops fs_file_ops = {
	fs_file_query,
	fs_file_addref,
	fs_file_release,
	fs_file_stat,
	fs_file_setstat,
	fs_file_pathconf,
	fs_file_sync,
	fs_file_sync,
	fs_file_access,
	fs_file_readlink,
	fs_file_open,
	fs_file_getfs
};

static struct oskit_dir_ops fs_dir_ops = {
	fs_dir_query,
	fs_file_addref,
	fs_dir_release,
	fs_file_stat,
	fs_file_setstat,
	fs_file_pathconf,
	fs_file_sync,
	fs_file_sync,
	fs_file_access,
	fs_file_readlink,
	fs_dir_open,
	fs_file_getfs,
	fs_dir_lookup,
	fs_dir_create,
	fs_dir_link,
	fs_dir_unlink,
	fs_dir_rename,
	fs_dir_mkdir,
	fs_dir_rmdir,
	fs_dir_getdirentries,
	fs_dir_mknod,
	fs_dir_symlink,
	fs_dir_reparent
};

/*
 * The absio interface, intended to allow an openfile to be created
 * using an soa.
 */
static OSKIT_COMDECL
fs_afile_query(oskit_absio_t *io,
	       const struct oskit_guid *iid, void **out_ihandle)
{
        struct fs_file  *fsf = (struct fs_file *) (io - 1);
	
	if (!fsf->count)
		return OSKIT_E_INVALIDARG;

	/* may be file_query or dir_query */
	return oskit_file_query(&fsf->filei, iid, out_ihandle);
}

static OSKIT_COMDECL_U
fs_afile_addref(oskit_absio_t *io)
{
        struct fs_file  *fsf = (struct fs_file *) (io - 1);

	return oskit_file_addref(&fsf->filei);
}

static OSKIT_COMDECL_U
fs_afile_release(oskit_absio_t *io)
{
        struct fs_file  *fsf = (struct fs_file *) (io - 1);

	return oskit_file_release(&fsf->filei);
}


static OSKIT_COMDECL
fs_afile_read(oskit_absio_t *io, void *buf,
	      oskit_off_t offset, oskit_size_t amount,
	      oskit_size_t *out_actual)
{
        struct fs_file  *fsf = (struct fs_file *) (io - 1);

	if (!fsf->count)
		return OSKIT_E_INVALIDARG;

	assert(fsf->bio);
	assert((offset & (fsf->blksize - 1)) == 0);
	assert((amount & (fsf->blksize - 1)) == 0);

	return oskit_blkio_read(fsf->bio, buf, offset, amount, out_actual);
}

static OSKIT_COMDECL
fs_afile_write(oskit_absio_t *io, const void *buf,
	       oskit_off_t offset, oskit_size_t amount,
	       oskit_size_t *out_actual)
{
        struct fs_file  *fsf = (struct fs_file *) (io - 1);

	if (!fsf->count)
		return OSKIT_E_INVALIDARG;

	assert(fsf->bio);
	assert((offset & (fsf->blksize - 1)) == 0);
	assert((amount & (fsf->blksize - 1)) == 0);

	return oskit_blkio_write(fsf->bio, buf, offset, amount, out_actual);
}

static OSKIT_COMDECL
fs_afile_getsize(oskit_absio_t *io, oskit_off_t *out_size)
{
        struct fs_file  *fsf = (struct fs_file *) (io - 1);

	assert(fsf->bio);
	
	/*
	 * Ask the blockio device for its size.
	 */
	return oskit_blkio_getsize(fsf->bio, out_size);
}

static OSKIT_COMDECL
fs_afile_setsize(oskit_absio_t *io, oskit_off_t new_size)
{
#if VERBOSITY > 1
	printf(__FUNCTION__": asked to setsize\n");
#endif
	return OSKIT_E_NOTIMPL;
}

static struct oskit_absio_ops fs_absio_ops = {
	fs_afile_query,
	fs_afile_addref,
	fs_afile_release,
	(void *)0,			/* slot reserved for getblocksize */
	fs_afile_read,
	fs_afile_write,
	fs_afile_getsize,
	fs_afile_setsize
};

/*
 * Create a /dev directory in the bmod filesystem, and mount the virtual
 * directory on top of it.
 */
oskit_error_t
oskit_create_slashdev()
{
        struct fs_dir	*newfsd;
	int		rc;
	void		find_rootdisk();

	if (mkdir("/dev", 0666) < 0)
		if (errno != OSKIT_EEXIST)
			panic("oskit_create_slashdev: "
			      "Could not create /dev");

	/*
	 * Create the virtual top level directory, and mount it.
	 */
        if ((newfsd = fs_dir_allocate("/devices")) == NULL)
		panic("oskit_create_slashdev: Out of memory");		
	
	if ((rc = fs_mount("/dev", (oskit_file_t *) &newfsd->diri.ops)) != 0)
		panic("oskit_create_slashdev: fs_mount failed errno %d\n", rc);

	oskit_dir_release(&newfsd->diri);

	return 0;
}

#if 0
/*
 * Kinda silly. Look for a valid "a" partition on the first disk on
 * a bus. We call that the root partition.
 */
#define MAX_PARTS 30

void
checkforroot(oskit_blkdev_t *blk)
{
	oskit_blkio_t	*bio;
	int		numparts;
	diskpart_t	*dp, part_array[MAX_PARTS];

	if (oskit_blkdev_open(blk, OSKIT_DEV_OPEN_READ, &bio))
		return;

	/*
	 * Get the partition info.
	 */
	numparts = diskpart_blkio_get_partition(bio, part_array, MAX_PARTS);
	if (numparts == 0) {
		printf("checkforroot: No partitions found\n");
		oskit_blkio_release(bio);
		return;
	}

	diskpart_dump(part_array, 0, 'a');
}

static void
recurse_bus(oskit_bus_t *bus, char *busname, int seenroot)
{
	oskit_device_t		*dev;
	oskit_bus_t		*sub;
	oskit_devinfo_t		info;
	char			pos[OSKIT_BUS_POS_MAX+1];
	oskit_error_t		rc;
	unsigned int		i;

	for (i = 0; bus->ops->getchild(bus, i, &dev, pos) == 0; i++) {
		rc = oskit_device_getinfo(dev, &info);
		assert(rc == 0);

		rc = oskit_device_query(dev, &oskit_bus_iid, (void**)&sub);

		if (rc == 0) {
			char name[OSKIT_DEVNAME_MAX];
			
			/*
			 * This is a bus.
			 */
			strcpy(name, info.name);
			recurse_bus(sub, name, seenroot);
		} else {
			/*
			 * Just a single device.
			 */
			oskit_blkdev_t *blk;

			if (!oskit_device_query(dev, &oskit_blkdev_iid,
					(void **)&blk)) {
				checkforroot(blk);
				oskit_blkdev_release(blk);
			}
		}
		dev->ops->release(dev);
	}
}

void
find_rootdisk()
{
	char name[OSKIT_DEVNAME_MAX];

	memset(name, 0, sizeof(name));
	recurse_bus(osenv_rootbus_getbus(), name, 0);
}
#endif