VM: make mapping types explicit
[minix.git] / servers / ext2 / misc.c
blobffc6341f71610c0513b9e34358b3f1a53b126cda
1 /* Created (MFS based):
2 * February 2010 (Evgeniy Ivanov)
3 */
5 #include "fs.h"
6 #include <assert.h>
7 #include <minix/vfsif.h>
8 #include <minix/bdev.h>
9 #include "inode.h"
10 #include "super.h"
12 /*===========================================================================*
13 * fs_sync *
14 *===========================================================================*/
15 int fs_sync()
17 /* Perform the sync() system call. Flush all the tables.
18 * The order in which the various tables are flushed is critical. The
19 * blocks must be flushed last, since rw_inode() leaves its results in
20 * the block cache.
22 struct inode *rip;
23 struct buf *bp;
25 assert(nr_bufs > 0);
26 assert(buf);
28 if (superblock->s_rd_only)
29 return(OK); /* nothing to sync */
31 /* Write all the dirty inodes to the disk. */
32 for(rip = &inode[0]; rip < &inode[NR_INODES]; rip++)
33 if(rip->i_count > 0 && rip->i_dirt == DIRTY) rw_inode(rip, WRITING);
35 /* Write all the dirty blocks to the disk, one drive at a time. */
36 for(bp = &buf[0]; bp < &buf[nr_bufs]; bp++)
37 if(bp->b_dev != NO_DEV && bp->b_dirt == DIRTY)
38 flushall(bp->b_dev);
40 if (superblock->s_dev != NO_DEV) {
41 superblock->s_wtime = clock_time();
42 write_super(superblock);
45 return(OK); /* sync() can't fail */
49 /*===========================================================================*
50 * fs_flush *
51 *===========================================================================*/
52 int fs_flush()
54 /* Flush the blocks of a device from the cache after writing any dirty blocks
55 * to disk.
57 dev_t dev = (dev_t) fs_m_in.REQ_DEV;
59 if(dev == fs_dev) return(EBUSY);
61 flushall(dev);
62 invalidate(dev);
64 return(OK);
67 /*===========================================================================*
68 * fs_new_driver *
69 *===========================================================================*/
70 int fs_new_driver(void)
72 /* Set a new driver endpoint for this device. */
73 dev_t dev;
74 cp_grant_id_t label_gid;
75 size_t label_len;
76 char label[sizeof(fs_dev_label)];
77 int r;
79 dev = (dev_t) fs_m_in.REQ_DEV;
80 label_gid = (cp_grant_id_t) fs_m_in.REQ_GRANT;
81 label_len = (size_t) fs_m_in.REQ_PATH_LEN;
83 if (label_len > sizeof(label))
84 return(EINVAL);
86 r = sys_safecopyfrom(fs_m_in.m_source, label_gid, (vir_bytes) 0,
87 (vir_bytes) label, label_len);
89 if (r != OK) {
90 printf("ext2: fs_new_driver safecopyfrom failed (%d)\n", r);
91 return(EINVAL);
94 bdev_driver(dev, label);
96 return(OK);