1 /* Created (MFS based): 2 * February 2010 (Evgeniy Ivanov) 3 */ 4 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" 11 12 /*===========================================================================* 13 * fs_sync * 14 *===========================================================================*/ 15 int fs_sync() 16 { 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. 21 */ 22 struct inode *rip; 23 24 assert(lmfs_nr_bufs() > 0); 25 26 if (superblock->s_rd_only) 27 return(OK); /* nothing to sync */ 28 29 /* Write all the dirty inodes to the disk. */ 30 for(rip = &inode[0]; rip < &inode[NR_INODES]; rip++) 31 if(rip->i_count > 0 && rip->i_dirt == IN_DIRTY) rw_inode(rip, WRITING); 32 33 lmfs_flushall(); 34 35 if (superblock->s_dev != NO_DEV) { 36 superblock->s_wtime = clock_time(); 37 write_super(superblock); 38 } 39 40 return(OK); /* sync() can't fail */ 41 } 42 43 44 /*===========================================================================* 45 * fs_flush * 46 *===========================================================================*/ 47 int fs_flush() 48 { 49 /* Flush the blocks of a device from the cache after writing any dirty blocks 50 * to disk. 51 */ 52 dev_t dev = fs_m_in.m_vfs_fs_flush.device; 53 54 if(dev == fs_dev) return(EBUSY); 55 56 lmfs_flushall(); 57 lmfs_invalidate(dev); 58 59 return(OK); 60 } 61 62 /*===========================================================================* 63 * fs_new_driver * 64 *===========================================================================*/ 65 int fs_new_driver(void) 66 { 67 /* Set a new driver endpoint for this device. */ 68 dev_t dev; 69 cp_grant_id_t label_gid; 70 size_t label_len; 71 char label[sizeof(fs_dev_label)]; 72 int r; 73 74 dev = fs_m_in.m_vfs_fs_new_driver.device; 75 label_gid = fs_m_in.m_vfs_fs_new_driver.grant; 76 label_len = fs_m_in.m_vfs_fs_new_driver.path_len; 77 78 if (label_len > sizeof(label)) 79 return(EINVAL); 80 81 r = sys_safecopyfrom(fs_m_in.m_source, label_gid, (vir_bytes) 0, 82 (vir_bytes) label, label_len); 83 84 if (r != OK) { 85 printf("ext2: fs_new_driver safecopyfrom failed (%d)\n", r); 86 return(EINVAL); 87 } 88 89 bdev_driver(dev, label); 90 91 return(OK); 92 } 93 94 int fs_bpeek(void) 95 { 96 return lmfs_do_bpeek(&fs_m_in); 97 } 98 99