1    | /* mount_testkit.c
2    |    ---------------
3    |    $Id: mount_testkit.c,v 1.2 2003/09/22 09:03:26 stewart Exp $
4    | 
5    |    This is the code to mount a fcfs volume using the testkit stuff.
6    |    a bit icky, but it should work.
7    | 
8    |    (C)2003 Stewart Smith
9    |    Distributed under the GNU Public License
10   |  */
11   | 
12   | #include <stdio.h>
13   | #include <stdlib.h>
14   | #include <sys/stat.h>
15   | #include <unistd.h>
16   | #include <fcntl.h>
17   | #include <string.h>
18   | #include <time.h>
19   | 
20   | 
21   | #include "testkit/block_dev.h"
22   | #include "testkit/types.h"
23   | #include "testkit/bitops.h"
24   | #include "disk.h"
25   | 
26   | #include "super_block.h"
27   | #include "onode.h"
28   | #include "onode_index.h"
29   | #include "space_bitmap.h"
30   | 
31   | 
32   | struct fcfs_disk *fcfs_mount(char *name)
33   | {
34   |   struct block_device bdev,*bdevproper;
35   |   struct fcfs_disk *disk,*diskproper;
36   |   struct fcfs_disk_block *block;
37   |   u32 bsize;     // block size (bytes)
38   |   u64 blocksnr;  // number of blocks
39   | 
40   |   bdevproper = (struct block_device*)malloc(sizeof(struct block_device));
41   |   if(bdevproper==NULL)
42   |     {
43   |       fprintf(stderr,"No memory for bdevproper\n");
44   |       abort();
45   |     }
46   | 
47   |   block_dev_init();
48   |   block_dev_new(&bdev,name,4096,1);
49   |   disk = disk_new(&bdev);
50   | 
51   |   block = disk_getblock(disk,0);
52   |   disk->sb = (struct fcfs_sb*)block->data;
53   | 
54   |   bsize = disk->sb->bsize;
55   |   blocksnr = disk->sb->blocksnr;
56   | 
57   |   /* clean up after initial detection */
58   |   disk_freeblock(block);
59   |   disk_free(disk);
60   | 
61   |   /* Let's use our knowledge to make a proper disk */
62   |   block_dev_new(bdevproper,name,bsize,blocksnr);
63   |   diskproper = disk_new(bdevproper);
64   |   
65   |   /* Put proper superblock into disk */
66   |   block = disk_getblock(diskproper,0);
67   |   disk->sb_block = block;
68   |   disk->sb = (struct fcfs_sb*)block->data;
69   | 
70   |   fcfs_sb_mark_dirty(disk);
71   | 
72   |   return disk;
73   | }
74   | 
75   | int fcfs_umount(struct fcfs_disk *disk)
76   | {
77   |   fcfs_sb_mark_clean(disk);
78   |   disk_freeblock(disk->sb_block);
79   |   disk_free(disk);
80   |   return 0;
81   | }