Replace previous change by different test
[minix.git] / servers / mfs / misc.c
blob326e86f2823041ab1c6e31ce2bd38a2d9756c1b1
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"
8 /*===========================================================================*
9 * fs_sync *
10 *===========================================================================*/
11 int fs_sync()
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.
18 struct inode *rip;
20 assert(lmfs_nr_bufs() > 0);
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);
26 /* Write all the dirty blocks to the disk. */
27 lmfs_flushall();
29 return(OK); /* sync() can't fail */
33 /*===========================================================================*
34 * fs_flush *
35 *===========================================================================*/
36 int fs_flush()
38 /* Flush the blocks of a device from the cache after writing any dirty blocks
39 * to disk.
41 dev_t dev = (dev_t) fs_m_in.REQ_DEV;
42 if(dev == fs_dev) return(EBUSY);
44 lmfs_flushall();
45 lmfs_invalidate(dev);
47 return(OK);
51 /*===========================================================================*
52 * fs_new_driver *
53 *===========================================================================*/
54 int fs_new_driver(void)
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;
63 dev = (dev_t) fs_m_in.REQ_DEV;
64 label_gid = (cp_grant_id_t) fs_m_in.REQ_GRANT;
65 label_len = (size_t) fs_m_in.REQ_PATH_LEN;
67 if (label_len > sizeof(label))
68 return(EINVAL);
70 r = sys_safecopyfrom(fs_m_in.m_source, label_gid, (vir_bytes) 0,
71 (vir_bytes) label, label_len);
73 if (r != OK) {
74 printf("MFS: fs_new_driver safecopyfrom failed (%d)\n", r);
75 return(EINVAL);
78 bdev_driver(dev, label);
80 return(OK);