xref: /minix/minix/fs/mfs/misc.c (revision 7f5f010b)
1 #include "fs.h"
2 #include <assert.h>
3 #include <minix/vfsif.h>
4 #include <minix/bdev.h>
5 #include "inode.h"
6 #include "clean.h"
7 
8 /*===========================================================================*
9  *				fs_sync					     *
10  *===========================================================================*/
11 int fs_sync()
12 {
13 /* Perform the sync() system call.  Flush all the tables.
14  * The order in which the various tables are flushed is critical.  The
15  * blocks must be flushed last, since rw_inode() leaves its results in
16  * the block cache.
17  */
18   struct inode *rip;
19 
20   assert(lmfs_nr_bufs() > 0);
21 
22   /* Write all the dirty inodes to the disk. */
23   for(rip = &inode[0]; rip < &inode[NR_INODES]; rip++)
24 	  if(rip->i_count > 0 && IN_ISDIRTY(rip)) rw_inode(rip, WRITING);
25 
26   /* Write all the dirty blocks to the disk. */
27   lmfs_flushall();
28 
29   return(OK);		/* sync() can't fail */
30 }
31 
32 
33 /*===========================================================================*
34  *				fs_flush				     *
35  *===========================================================================*/
36 int fs_flush()
37 {
38 /* Flush the blocks of a device from the cache after writing any dirty blocks
39  * to disk.
40  */
41   dev_t dev = fs_m_in.m_vfs_fs_flush.device;
42   if(dev == fs_dev && lmfs_bufs_in_use() > 0) return(EBUSY);
43 
44   lmfs_flushall();
45   lmfs_invalidate(dev);
46 
47   return(OK);
48 }
49 
50 
51 /*===========================================================================*
52  *				fs_new_driver				     *
53  *===========================================================================*/
54 int fs_new_driver(void)
55 {
56 /* Set a new driver endpoint for this device. */
57   dev_t dev;
58   cp_grant_id_t label_gid;
59   size_t label_len;
60   char label[sizeof(fs_dev_label)];
61   int r;
62 
63   dev = fs_m_in.m_vfs_fs_new_driver.device;
64   label_gid = fs_m_in.m_vfs_fs_new_driver.grant;
65   label_len = fs_m_in.m_vfs_fs_new_driver.path_len;
66 
67   if (label_len > sizeof(label))
68 	return(EINVAL);
69 
70   r = sys_safecopyfrom(fs_m_in.m_source, label_gid, (vir_bytes) 0,
71 	(vir_bytes) label, label_len);
72 
73   if (r != OK) {
74 	printf("MFS: fs_new_driver safecopyfrom failed (%d)\n", r);
75 	return(EINVAL);
76   }
77 
78   bdev_driver(dev, label);
79 
80   return(OK);
81 }
82 
83 int fs_bpeek(void)
84 {
85 	return lmfs_do_bpeek(&fs_m_in);
86 }
87