Lines Matching full:fs

19 # include <linux/fs.h>
96 errcode_t ext2fs_run_ext3_journal(ext2_filsys *fs);
147 * ext4 ACL structures, copied from fs/ext4/acl.h.
317 ext2_filsys fs; member
333 #define FUSE2FS_CHECK_MAGIC(fs, ptr, num) do {if ((ptr)->magic != (num)) \ argument
334 return translate_error((fs), 0, EXT2_ET_MAGIC_EXT2_FILE); \
341 static int __translate_error(ext2_filsys fs, errcode_t err, ext2_ino_t ino,
343 #define translate_error(fs, ino, err) __translate_error((fs), (err), (ino), \ argument
473 static int update_ctime(ext2_filsys fs, ext2_ino_t ino, in update_ctime() argument
491 err = ext2fs_read_inode_full(fs, ino, (struct ext2_inode *)&inode, in update_ctime()
494 return translate_error(fs, ino, err); in update_ctime()
499 err = ext2fs_write_inode_full(fs, ino, (struct ext2_inode *)&inode, in update_ctime()
502 return translate_error(fs, ino, err); in update_ctime()
507 static int update_atime(ext2_filsys fs, ext2_ino_t ino) in update_atime() argument
513 if (!(fs->flags & EXT2_FLAG_RW)) in update_atime()
516 err = ext2fs_read_inode_full(fs, ino, (struct ext2_inode *)&inode, in update_atime()
519 return translate_error(fs, ino, err); in update_atime()
533 err = ext2fs_write_inode_full(fs, ino, (struct ext2_inode *)&inode, in update_atime()
536 return translate_error(fs, ino, err); in update_atime()
541 static int update_mtime(ext2_filsys fs, ext2_ino_t ino, in update_mtime() argument
557 err = ext2fs_read_inode_full(fs, ino, (struct ext2_inode *)&inode, in update_mtime()
560 return translate_error(fs, ino, err); in update_mtime()
567 err = ext2fs_write_inode_full(fs, ino, (struct ext2_inode *)&inode, in update_mtime()
570 return translate_error(fs, ino, err); in update_mtime()
603 ext2_filsys fs = ff->fs; in fs_can_allocate() local
608 ext2fs_blocks_count(fs->super), in fs_can_allocate()
609 ext2fs_free_blocks_count(fs->super), in fs_can_allocate()
610 ext2fs_r_blocks_count(fs->super)); in fs_can_allocate()
611 if (num > ext2fs_blocks_count(fs->super)) in fs_can_allocate()
618 * Different meaning for r_blocks -- libext2fs has bugs where the FS in fs_can_allocate()
622 reserved = ext2fs_r_blocks_count(fs->super); in fs_can_allocate()
624 reserved = ext2fs_blocks_count(fs->super) / 10; in fs_can_allocate()
625 return ext2fs_free_blocks_count(fs->super) > reserved + num; in fs_can_allocate()
628 static int fs_writeable(ext2_filsys fs) in fs_writeable() argument
630 return (fs->flags & EXT2_FLAG_RW) && (fs->super->s_error_count == 0); in fs_writeable()
633 static int check_inum_access(ext2_filsys fs, ext2_ino_t ino, mode_t mask) in check_inum_access() argument
641 /* no writing to read-only or broken fs */ in check_inum_access()
642 if ((mask & W_OK) && !fs_writeable(fs)) in check_inum_access()
645 err = ext2fs_read_inode(fs, ino, &inode); in check_inum_access()
647 return translate_error(fs, ino, err); in check_inum_access()
707 ext2_filsys fs; in op_destroy() local
714 fs = ff->fs; in op_destroy()
715 dbg_printf("%s: dev=%s\n", __func__, fs->device_name); in op_destroy()
716 if (fs->flags & EXT2_FLAG_RW) { in op_destroy()
717 fs->super->s_state |= EXT2_VALID_FS; in op_destroy()
718 if (fs->super->s_error_count) in op_destroy()
719 fs->super->s_state |= EXT2_ERROR_FS; in op_destroy()
720 ext2fs_mark_super_dirty(fs); in op_destroy()
721 err = ext2fs_set_gdt_csum(fs); in op_destroy()
723 translate_error(fs, 0, err); in op_destroy()
725 err = ext2fs_flush2(fs, 0); in op_destroy()
727 translate_error(fs, 0, err); in op_destroy()
735 ext2_filsys fs; in op_init() local
742 fs = ff->fs; in op_init()
743 dbg_printf("%s: dev=%s\n", __func__, fs->device_name); in op_init()
747 if (fs->flags & EXT2_FLAG_RW) { in op_init()
748 fs->super->s_mnt_count++; in op_init()
749 fs->super->s_mtime = time(NULL); in op_init()
750 fs->super->s_state &= ~EXT2_VALID_FS; in op_init()
751 ext2fs_mark_super_dirty(fs); in op_init()
752 err = ext2fs_flush2(fs, 0); in op_init()
754 translate_error(fs, 0, err); in op_init()
759 static int stat_inode(ext2_filsys fs, ext2_ino_t ino, struct stat *statbuf) in stat_inode() argument
768 err = ext2fs_read_inode_full(fs, ino, (struct ext2_inode *)&inode, in stat_inode()
771 return translate_error(fs, ino, err); in stat_inode()
773 memcpy(&fakedev, fs->super->s_uuid, sizeof(fakedev)); in stat_inode()
781 statbuf->st_blksize = fs->blocksize; in stat_inode()
782 statbuf->st_blocks = ext2fs_get_stat_i_blocks(fs, in stat_inode()
805 ext2_filsys fs; in op_getattr() local
811 fs = ff->fs; in op_getattr()
814 err = ext2fs_namei(fs, EXT2_ROOT_INO, EXT2_ROOT_INO, path, &ino); in op_getattr()
816 ret = translate_error(fs, 0, err); in op_getattr()
819 ret = stat_inode(fs, ino, statbuf); in op_getattr()
829 ext2_filsys fs; in op_readlink() local
838 fs = ff->fs; in op_readlink()
841 err = ext2fs_namei(fs, EXT2_ROOT_INO, EXT2_ROOT_INO, path, &ino); in op_readlink()
843 ret = translate_error(fs, 0, err); in op_readlink()
847 err = ext2fs_read_inode(fs, ino, &inode); in op_readlink()
849 ret = translate_error(fs, ino, err); in op_readlink()
866 err = ext2fs_file_open(fs, ino, 0, &file); in op_readlink()
868 ret = translate_error(fs, ino, err); in op_readlink()
875 ret = translate_error(fs, ino, err); in op_readlink()
884 ret = translate_error(fs, ino, err); in op_readlink()
890 if (fs_writeable(fs)) { in op_readlink()
891 ret = update_atime(fs, ino); in op_readlink()
905 ext2_filsys fs; in op_mknod() local
915 fs = ff->fs; in op_mknod()
938 err = ext2fs_namei(fs, EXT2_ROOT_INO, EXT2_ROOT_INO, temp_path, in op_mknod()
941 ret = translate_error(fs, 0, err); in op_mknod()
945 ret = check_inum_access(fs, parent, W_OK); in op_mknod()
964 err = ext2fs_new_inode(fs, parent, mode, 0, &child); in op_mknod()
966 ret = translate_error(fs, 0, err); in op_mknod()
972 err = ext2fs_link(fs, parent, node_name, child, filetype); in op_mknod()
974 err = ext2fs_expand_dir(fs, parent); in op_mknod()
976 ret = translate_error(fs, parent, err); in op_mknod()
980 err = ext2fs_link(fs, parent, node_name, child, in op_mknod()
984 ret = translate_error(fs, parent, err); in op_mknod()
988 ret = update_mtime(fs, parent, NULL); in op_mknod()
1007 err = ext2fs_write_new_inode(fs, child, (struct ext2_inode *)&inode); in op_mknod()
1009 ret = translate_error(fs, child, err); in op_mknod()
1015 err = ext2fs_write_inode_full(fs, child, (struct ext2_inode *)&inode, in op_mknod()
1018 ret = translate_error(fs, child, err); in op_mknod()
1022 ext2fs_inode_alloc_stats2(fs, child, 1, 0); in op_mknod()
1035 ext2_filsys fs; in op_mkdir() local
1047 fs = ff->fs; in op_mkdir()
1069 err = ext2fs_namei(fs, EXT2_ROOT_INO, EXT2_ROOT_INO, temp_path, in op_mkdir()
1072 ret = translate_error(fs, 0, err); in op_mkdir()
1076 ret = check_inum_access(fs, parent, W_OK); in op_mkdir()
1081 err = ext2fs_read_inode_full(fs, parent, (struct ext2_inode *)&inode, in op_mkdir()
1084 ret = translate_error(fs, parent, err); in op_mkdir()
1091 err = ext2fs_mkdir(fs, parent, 0, node_name); in op_mkdir()
1093 err = ext2fs_expand_dir(fs, parent); in op_mkdir()
1095 ret = translate_error(fs, parent, err); in op_mkdir()
1099 err = ext2fs_mkdir(fs, parent, 0, node_name); in op_mkdir()
1102 ret = translate_error(fs, parent, err); in op_mkdir()
1106 ret = update_mtime(fs, parent, NULL); in op_mkdir()
1111 err = ext2fs_namei(fs, EXT2_ROOT_INO, EXT2_ROOT_INO, temp_path, in op_mkdir()
1114 ret = translate_error(fs, 0, err); in op_mkdir()
1121 err = ext2fs_read_inode_full(fs, child, (struct ext2_inode *)&inode, in op_mkdir()
1124 ret = translate_error(fs, child, err); in op_mkdir()
1132 inode.i_mode = LINUX_S_IFDIR | (mode & ~(S_ISUID | fs->umask)) | in op_mkdir()
1136 err = ext2fs_write_inode_full(fs, child, (struct ext2_inode *)&inode, in op_mkdir()
1139 ret = translate_error(fs, child, err); in op_mkdir()
1145 !ext2fs_has_feature_metadata_csum(fs->super)) in op_mkdir()
1147 err = ext2fs_new_dir_block(fs, child, parent, &block); in op_mkdir()
1149 ret = translate_error(fs, child, err); in op_mkdir()
1152 err = ext2fs_bmap2(fs, child, (struct ext2_inode *)&inode, NULL, 0, 0, in op_mkdir()
1155 ret = translate_error(fs, child, err); in op_mkdir()
1158 err = ext2fs_write_dir_block4(fs, blk, block, 0, child); in op_mkdir()
1160 ret = translate_error(fs, child, err); in op_mkdir()
1173 static int unlink_file_by_name(ext2_filsys fs, const char *path) in unlink_file_by_name() argument
1184 err = ext2fs_namei(fs, EXT2_ROOT_INO, EXT2_ROOT_INO, filename, in unlink_file_by_name()
1188 return translate_error(fs, 0, err); in unlink_file_by_name()
1195 ret = check_inum_access(fs, dir, W_OK); in unlink_file_by_name()
1203 err = ext2fs_unlink(fs, dir, base_name, 0, 0); in unlink_file_by_name()
1206 return translate_error(fs, dir, err); in unlink_file_by_name()
1208 return update_mtime(fs, dir, NULL); in unlink_file_by_name()
1213 ext2_filsys fs = ff->fs; in remove_inode() local
1219 err = ext2fs_read_inode_full(fs, ino, (struct ext2_inode *)&inode, in remove_inode()
1222 ret = translate_error(fs, ino, err); in remove_inode()
1233 inode.i_dtime = fs->now ? fs->now : time(0); in remove_inode()
1239 ret = update_ctime(fs, ino, &inode); in remove_inode()
1247 err = ext2fs_free_ext_attr(fs, ino, &inode); in remove_inode()
1251 if (ext2fs_inode_has_valid_blocks2(fs, (struct ext2_inode *)&inode)) { in remove_inode()
1252 err = ext2fs_punch(fs, ino, (struct ext2_inode *)&inode, NULL, in remove_inode()
1255 ret = translate_error(fs, ino, err); in remove_inode()
1260 ext2fs_inode_alloc_stats2(fs, ino, -1, in remove_inode()
1264 err = ext2fs_write_inode_full(fs, ino, (struct ext2_inode *)&inode, in remove_inode()
1267 ret = translate_error(fs, ino, err); in remove_inode()
1276 ext2_filsys fs = ff->fs; in __op_unlink() local
1281 err = ext2fs_namei(fs, EXT2_ROOT_INO, EXT2_ROOT_INO, path, &ino); in __op_unlink()
1283 ret = translate_error(fs, 0, err); in __op_unlink()
1287 ret = unlink_file_by_name(fs, path); in __op_unlink()
1341 ext2_filsys fs = ff->fs; in __op_rmdir() local
1348 err = ext2fs_namei(fs, EXT2_ROOT_INO, EXT2_ROOT_INO, path, &child); in __op_rmdir()
1350 ret = translate_error(fs, 0, err); in __op_rmdir()
1358 err = ext2fs_dir_iterate2(fs, child, 0, 0, rmdir_proc, &rds); in __op_rmdir()
1360 ret = translate_error(fs, child, err); in __op_rmdir()
1369 ret = unlink_file_by_name(fs, path); in __op_rmdir()
1383 err = ext2fs_read_inode_full(fs, rds.parent, in __op_rmdir()
1387 ret = translate_error(fs, rds.parent, err); in __op_rmdir()
1392 ret = update_mtime(fs, rds.parent, &inode); in __op_rmdir()
1395 err = ext2fs_write_inode_full(fs, rds.parent, in __op_rmdir()
1399 ret = translate_error(fs, rds.parent, err); in __op_rmdir()
1425 ext2_filsys fs; in op_symlink() local
1434 fs = ff->fs; in op_symlink()
1451 err = ext2fs_namei(fs, EXT2_ROOT_INO, EXT2_ROOT_INO, temp_path, in op_symlink()
1455 ret = translate_error(fs, 0, err); in op_symlink()
1459 ret = check_inum_access(fs, parent, W_OK); in op_symlink()
1465 err = ext2fs_symlink(fs, parent, 0, node_name, src); in op_symlink()
1467 err = ext2fs_expand_dir(fs, parent); in op_symlink()
1469 ret = translate_error(fs, parent, err); in op_symlink()
1473 err = ext2fs_symlink(fs, parent, 0, node_name, src); in op_symlink()
1476 ret = translate_error(fs, parent, err); in op_symlink()
1481 ret = update_mtime(fs, parent, NULL); in op_symlink()
1486 err = ext2fs_namei(fs, EXT2_ROOT_INO, EXT2_ROOT_INO, temp_path, in op_symlink()
1489 ret = translate_error(fs, 0, err); in op_symlink()
1496 err = ext2fs_read_inode_full(fs, child, (struct ext2_inode *)&inode, in op_symlink()
1499 ret = translate_error(fs, child, err); in op_symlink()
1509 err = ext2fs_write_inode_full(fs, child, (struct ext2_inode *)&inode, in op_symlink()
1512 ret = translate_error(fs, child, err); in op_symlink()
1549 ext2_filsys fs; in op_rename() local
1559 fs = ff->fs; in op_rename()
1567 err = ext2fs_namei(fs, EXT2_ROOT_INO, EXT2_ROOT_INO, from, &from_ino); in op_rename()
1569 ret = translate_error(fs, 0, err); in op_rename()
1573 err = ext2fs_namei(fs, EXT2_ROOT_INO, EXT2_ROOT_INO, to, &to_ino); in op_rename()
1575 ret = translate_error(fs, 0, err); in op_rename()
1609 err = ext2fs_namei(fs, EXT2_ROOT_INO, EXT2_ROOT_INO, temp_from, in op_rename()
1613 ret = translate_error(fs, 0, err); in op_rename()
1621 ret = check_inum_access(fs, from_dir_ino, W_OK); in op_rename()
1634 err = ext2fs_namei(fs, EXT2_ROOT_INO, EXT2_ROOT_INO, temp_to, in op_rename()
1638 ret = translate_error(fs, 0, err); in op_rename()
1646 ret = check_inum_access(fs, to_dir_ino, W_OK); in op_rename()
1652 err = ext2fs_read_inode(fs, to_ino, &inode); in op_rename()
1654 ret = translate_error(fs, to_ino, err); in op_rename()
1670 err = ext2fs_read_inode(fs, from_ino, &inode); in op_rename()
1672 ret = translate_error(fs, from_ino, err); in op_rename()
1679 err = ext2fs_link(fs, to_dir_ino, cp + 1, from_ino, in op_rename()
1682 err = ext2fs_expand_dir(fs, to_dir_ino); in op_rename()
1684 ret = translate_error(fs, to_dir_ino, err); in op_rename()
1688 err = ext2fs_link(fs, to_dir_ino, cp + 1, from_ino, in op_rename()
1692 ret = translate_error(fs, to_dir_ino, err); in op_rename()
1697 err = ext2fs_read_inode(fs, from_ino, &inode); in op_rename()
1699 ret = translate_error(fs, from_ino, err); in op_rename()
1707 err = ext2fs_dir_iterate2(fs, from_ino, 0, NULL, in op_rename()
1710 ret = translate_error(fs, from_ino, err); in op_rename()
1717 err = ext2fs_read_inode(fs, from_dir_ino, &inode); in op_rename()
1719 ret = translate_error(fs, from_dir_ino, err); in op_rename()
1723 err = ext2fs_write_inode(fs, from_dir_ino, &inode); in op_rename()
1725 ret = translate_error(fs, from_dir_ino, err); in op_rename()
1730 err = ext2fs_read_inode(fs, to_dir_ino, &inode); in op_rename()
1732 ret = translate_error(fs, to_dir_ino, err); in op_rename()
1736 err = ext2fs_write_inode(fs, to_dir_ino, &inode); in op_rename()
1738 ret = translate_error(fs, to_dir_ino, err); in op_rename()
1744 ret = update_ctime(fs, from_ino, NULL); in op_rename()
1748 ret = update_mtime(fs, to_dir_ino, NULL); in op_rename()
1753 ret = unlink_file_by_name(fs, from); in op_rename()
1758 err = ext2fs_flush2(fs, 0); in op_rename()
1760 ret = translate_error(fs, 0, err); in op_rename()
1774 ext2_filsys fs; in op_link() local
1783 fs = ff->fs; in op_link()
1805 err = ext2fs_namei(fs, EXT2_ROOT_INO, EXT2_ROOT_INO, temp_path, in op_link()
1813 ret = check_inum_access(fs, parent, W_OK); in op_link()
1818 err = ext2fs_namei(fs, EXT2_ROOT_INO, EXT2_ROOT_INO, src, &ino); in op_link()
1820 ret = translate_error(fs, 0, err); in op_link()
1825 err = ext2fs_read_inode_full(fs, ino, (struct ext2_inode *)&inode, in op_link()
1828 ret = translate_error(fs, ino, err); in op_link()
1833 ret = update_ctime(fs, ino, &inode); in op_link()
1837 err = ext2fs_write_inode_full(fs, ino, (struct ext2_inode *)&inode, in op_link()
1840 ret = translate_error(fs, ino, err); in op_link()
1846 err = ext2fs_link(fs, parent, node_name, ino, in op_link()
1849 err = ext2fs_expand_dir(fs, parent); in op_link()
1851 ret = translate_error(fs, parent, err); in op_link()
1855 err = ext2fs_link(fs, parent, node_name, ino, in op_link()
1859 ret = translate_error(fs, parent, err); in op_link()
1863 ret = update_mtime(fs, parent, NULL); in op_link()
1878 ext2_filsys fs; in op_chmod() local
1885 fs = ff->fs; in op_chmod()
1887 err = ext2fs_namei(fs, EXT2_ROOT_INO, EXT2_ROOT_INO, path, &ino); in op_chmod()
1889 ret = translate_error(fs, 0, err); in op_chmod()
1895 err = ext2fs_read_inode_full(fs, ino, (struct ext2_inode *)&inode, in op_chmod()
1898 ret = translate_error(fs, ino, err); in op_chmod()
1917 ret = update_ctime(fs, ino, &inode); in op_chmod()
1921 err = ext2fs_write_inode_full(fs, ino, (struct ext2_inode *)&inode, in op_chmod()
1924 ret = translate_error(fs, ino, err); in op_chmod()
1937 ext2_filsys fs; in op_chown() local
1944 fs = ff->fs; in op_chown()
1946 err = ext2fs_namei(fs, EXT2_ROOT_INO, EXT2_ROOT_INO, path, &ino); in op_chown()
1948 ret = translate_error(fs, 0, err); in op_chown()
1955 err = ext2fs_read_inode_full(fs, ino, (struct ext2_inode *)&inode, in op_chown()
1958 ret = translate_error(fs, ino, err); in op_chown()
1987 ret = update_ctime(fs, ino, &inode); in op_chown()
1991 err = ext2fs_write_inode_full(fs, ino, (struct ext2_inode *)&inode, in op_chown()
1994 ret = translate_error(fs, ino, err); in op_chown()
2007 ext2_filsys fs; in op_truncate() local
2014 fs = ff->fs; in op_truncate()
2016 err = ext2fs_namei(fs, EXT2_ROOT_INO, EXT2_ROOT_INO, path, &ino); in op_truncate()
2018 ret = translate_error(fs, 0, err); in op_truncate()
2023 ret = check_inum_access(fs, ino, W_OK); in op_truncate()
2027 err = ext2fs_file_open(fs, ino, EXT2_FILE_WRITE, &file); in op_truncate()
2029 ret = translate_error(fs, ino, err); in op_truncate()
2035 ret = translate_error(fs, ino, err); in op_truncate()
2044 ret = translate_error(fs, ino, err); in op_truncate()
2048 ret = update_mtime(fs, ino, NULL); in op_truncate()
2079 ext2_filsys fs = ff->fs; in __op_open() local
2087 return translate_error(fs, 0, err); in __op_open()
2110 err = ext2fs_namei(fs, EXT2_ROOT_INO, EXT2_ROOT_INO, path, &file->ino); in __op_open()
2112 ret = translate_error(fs, 0, err); in __op_open()
2117 ret = check_inum_access(fs, file->ino, check); in __op_open()
2120 * In a regular (Linux) fs driver, the kernel will open in __op_open()
2129 ret = check_inum_access(fs, file->ino, X_OK); in __op_open()
2164 ext2_filsys fs; in op_read() local
2171 fs = ff->fs; in op_read()
2172 FUSE2FS_CHECK_MAGIC(fs, fh, FUSE2FS_FILE_MAGIC); in op_read()
2176 err = ext2fs_file_open(fs, fh->ino, fh->open_flags, &efp); in op_read()
2178 ret = translate_error(fs, fh->ino, err); in op_read()
2184 ret = translate_error(fs, fh->ino, err); in op_read()
2190 ret = translate_error(fs, fh->ino, err); in op_read()
2199 ret = translate_error(fs, fh->ino, err); in op_read()
2203 if (fs_writeable(fs)) { in op_read()
2204 ret = update_atime(fs, fh->ino); in op_read()
2221 ext2_filsys fs; in op_write() local
2228 fs = ff->fs; in op_write()
2229 FUSE2FS_CHECK_MAGIC(fs, fh, FUSE2FS_FILE_MAGIC); in op_write()
2233 if (!fs_writeable(fs)) { in op_write()
2238 if (!fs_can_allocate(ff, len / fs->blocksize)) { in op_write()
2243 err = ext2fs_file_open(fs, fh->ino, fh->open_flags, &efp); in op_write()
2245 ret = translate_error(fs, fh->ino, err); in op_write()
2251 ret = translate_error(fs, fh->ino, err); in op_write()
2257 ret = translate_error(fs, fh->ino, err); in op_write()
2264 ret = translate_error(fs, fh->ino, err); in op_write()
2273 ret = translate_error(fs, fh->ino, err); in op_write()
2277 ret = update_mtime(fs, fh->ino, NULL); in op_write()
2293 ext2_filsys fs; in op_release() local
2298 fs = ff->fs; in op_release()
2299 FUSE2FS_CHECK_MAGIC(fs, fh, FUSE2FS_FILE_MAGIC); in op_release()
2302 if (fs_writeable(fs) && fh->open_flags & EXT2_FILE_WRITE) { in op_release()
2303 err = ext2fs_flush2(fs, EXT2_FLAG_FLUSH_NO_SYNC); in op_release()
2305 ret = translate_error(fs, fh->ino, err); in op_release()
2323 ext2_filsys fs; in op_fsync() local
2328 fs = ff->fs; in op_fsync()
2329 FUSE2FS_CHECK_MAGIC(fs, fh, FUSE2FS_FILE_MAGIC); in op_fsync()
2333 if (fs_writeable(fs) && fh->open_flags & EXT2_FILE_WRITE) { in op_fsync()
2334 err = ext2fs_flush2(fs, 0); in op_fsync()
2336 ret = translate_error(fs, fh->ino, err); in op_fsync()
2348 ext2_filsys fs; in op_statfs() local
2353 fs = ff->fs; in op_statfs()
2355 buf->f_bsize = fs->blocksize; in op_statfs()
2361 overhead = fs->desc_blocks + in op_statfs()
2362 (blk64_t)fs->group_desc_count * in op_statfs()
2363 (fs->inode_blocks_per_group + 2); in op_statfs()
2364 reserved = ext2fs_r_blocks_count(fs->super); in op_statfs()
2366 reserved = ext2fs_blocks_count(fs->super) / 10; in op_statfs()
2367 free = ext2fs_free_blocks_count(fs->super); in op_statfs()
2369 buf->f_blocks = ext2fs_blocks_count(fs->super) - overhead; in op_statfs()
2375 buf->f_files = fs->super->s_inodes_count; in op_statfs()
2376 buf->f_ffree = fs->super->s_free_inodes_count; in op_statfs()
2377 buf->f_favail = fs->super->s_free_inodes_count; in op_statfs()
2378 f = (uint64_t *)fs->super->s_uuid; in op_statfs()
2384 if (fs->flags & EXT2_FLAG_RW) in op_statfs()
2420 ext2_filsys fs; in op_getxattr() local
2430 fs = ff->fs; in op_getxattr()
2432 if (!ext2fs_has_feature_xattr(fs->super)) { in op_getxattr()
2437 err = ext2fs_namei(fs, EXT2_ROOT_INO, EXT2_ROOT_INO, path, &ino); in op_getxattr()
2439 ret = translate_error(fs, 0, err); in op_getxattr()
2444 ret = check_inum_access(fs, ino, R_OK); in op_getxattr()
2448 err = ext2fs_xattrs_open(fs, ino, &h); in op_getxattr()
2450 ret = translate_error(fs, ino, err); in op_getxattr()
2456 ret = translate_error(fs, ino, err); in op_getxattr()
2462 ret = translate_error(fs, ino, err); in op_getxattr()
2491 ret = translate_error(fs, ino, err); in op_getxattr()
2524 ext2_filsys fs; in op_listxattr() local
2532 fs = ff->fs; in op_listxattr()
2534 if (!ext2fs_has_feature_xattr(fs->super)) { in op_listxattr()
2539 err = ext2fs_namei(fs, EXT2_ROOT_INO, EXT2_ROOT_INO, path, &ino); in op_listxattr()
2541 ret = translate_error(fs, ino, err); in op_listxattr()
2546 ret = check_inum_access(fs, ino, R_OK); in op_listxattr()
2550 err = ext2fs_xattrs_open(fs, ino, &h); in op_listxattr()
2552 ret = translate_error(fs, ino, err); in op_listxattr()
2558 ret = translate_error(fs, ino, err); in op_listxattr()
2566 ret = translate_error(fs, ino, err); in op_listxattr()
2582 ret = translate_error(fs, ino, err); in op_listxattr()
2589 ret = translate_error(fs, ino, err); in op_listxattr()
2602 ext2_filsys fs; in op_setxattr() local
2612 fs = ff->fs; in op_setxattr()
2614 if (!ext2fs_has_feature_xattr(fs->super)) { in op_setxattr()
2619 err = ext2fs_namei(fs, EXT2_ROOT_INO, EXT2_ROOT_INO, path, &ino); in op_setxattr()
2621 ret = translate_error(fs, 0, err); in op_setxattr()
2626 ret = check_inum_access(fs, ino, W_OK); in op_setxattr()
2633 err = ext2fs_xattrs_open(fs, ino, &h); in op_setxattr()
2635 ret = translate_error(fs, ino, err); in op_setxattr()
2641 ret = translate_error(fs, ino, err); in op_setxattr()
2657 ret = translate_error(fs, ino, err); in op_setxattr()
2661 ret = update_ctime(fs, ino, NULL); in op_setxattr()
2668 ret = translate_error(fs, ino, err); in op_setxattr()
2679 ext2_filsys fs; in op_removexattr() local
2686 fs = ff->fs; in op_removexattr()
2688 if (!ext2fs_has_feature_xattr(fs->super)) { in op_removexattr()
2698 err = ext2fs_namei(fs, EXT2_ROOT_INO, EXT2_ROOT_INO, path, &ino); in op_removexattr()
2700 ret = translate_error(fs, 0, err); in op_removexattr()
2705 ret = check_inum_access(fs, ino, W_OK); in op_removexattr()
2709 err = ext2fs_xattrs_open(fs, ino, &h); in op_removexattr()
2711 ret = translate_error(fs, ino, err); in op_removexattr()
2717 ret = translate_error(fs, ino, err); in op_removexattr()
2723 ret = translate_error(fs, ino, err); in op_removexattr()
2727 ret = update_ctime(fs, ino, NULL); in op_removexattr()
2731 ret = translate_error(fs, ino, err); in op_removexattr()
2772 ext2_filsys fs; in op_readdir() local
2778 fs = ff->fs; in op_readdir()
2779 FUSE2FS_CHECK_MAGIC(fs, fh, FUSE2FS_FILE_MAGIC); in op_readdir()
2784 err = ext2fs_dir_iterate2(fs, fh->ino, 0, NULL, op_readdir_iter, &i); in op_readdir()
2786 ret = translate_error(fs, fh->ino, err); in op_readdir()
2790 if (fs_writeable(fs)) { in op_readdir()
2791 ret = update_atime(fs, fh->ino); in op_readdir()
2804 ext2_filsys fs; in op_access() local
2810 fs = ff->fs; in op_access()
2813 err = ext2fs_namei(fs, EXT2_ROOT_INO, EXT2_ROOT_INO, path, &ino); in op_access()
2815 ret = translate_error(fs, 0, err); in op_access()
2819 ret = check_inum_access(fs, ino, mask); in op_access()
2832 ext2_filsys fs; in op_create() local
2842 fs = ff->fs; in op_create()
2864 err = ext2fs_namei(fs, EXT2_ROOT_INO, EXT2_ROOT_INO, temp_path, in op_create()
2867 ret = translate_error(fs, 0, err); in op_create()
2871 ret = check_inum_access(fs, parent, W_OK); in op_create()
2879 err = ext2fs_new_inode(fs, parent, mode, 0, &child); in op_create()
2881 ret = translate_error(fs, parent, err); in op_create()
2887 err = ext2fs_link(fs, parent, node_name, child, filetype); in op_create()
2889 err = ext2fs_expand_dir(fs, parent); in op_create()
2891 ret = translate_error(fs, parent, err); in op_create()
2895 err = ext2fs_link(fs, parent, node_name, child, in op_create()
2899 ret = translate_error(fs, parent, err); in op_create()
2903 ret = update_mtime(fs, parent, NULL); in op_create()
2916 if (ext2fs_has_feature_extents(fs->super)) { in op_create()
2920 ret = ext2fs_extent_open2(fs, child, in op_create()
2927 err = ext2fs_write_new_inode(fs, child, (struct ext2_inode *)&inode); in op_create()
2929 ret = translate_error(fs, child, err); in op_create()
2935 err = ext2fs_write_inode_full(fs, child, (struct ext2_inode *)&inode, in op_create()
2938 ret = translate_error(fs, child, err); in op_create()
2942 ext2fs_inode_alloc_stats2(fs, child, 1, 0); in op_create()
2961 ext2_filsys fs; in op_ftruncate() local
2967 fs = ff->fs; in op_ftruncate()
2968 FUSE2FS_CHECK_MAGIC(fs, fh, FUSE2FS_FILE_MAGIC); in op_ftruncate()
2971 if (!fs_writeable(fs)) { in op_ftruncate()
2976 err = ext2fs_file_open(fs, fh->ino, fh->open_flags, &efp); in op_ftruncate()
2978 ret = translate_error(fs, fh->ino, err); in op_ftruncate()
2984 ret = translate_error(fs, fh->ino, err); in op_ftruncate()
2993 ret = translate_error(fs, fh->ino, err); in op_ftruncate()
2997 ret = update_mtime(fs, fh->ino, NULL); in op_ftruncate()
3012 ext2_filsys fs; in op_fgetattr() local
3018 fs = ff->fs; in op_fgetattr()
3019 FUSE2FS_CHECK_MAGIC(fs, fh, FUSE2FS_FILE_MAGIC); in op_fgetattr()
3022 ret = stat_inode(fs, fh->ino, statbuf); in op_fgetattr()
3033 ext2_filsys fs; in op_utimens() local
3040 fs = ff->fs; in op_utimens()
3042 err = ext2fs_namei(fs, EXT2_ROOT_INO, EXT2_ROOT_INO, path, &ino); in op_utimens()
3044 ret = translate_error(fs, 0, err); in op_utimens()
3049 ret = check_inum_access(fs, ino, W_OK); in op_utimens()
3054 err = ext2fs_read_inode_full(fs, ino, (struct ext2_inode *)&inode, in op_utimens()
3057 ret = translate_error(fs, ino, err); in op_utimens()
3075 ret = update_ctime(fs, ino, &inode); in op_utimens()
3079 err = ext2fs_write_inode_full(fs, ino, (struct ext2_inode *)&inode, in op_utimens()
3082 ret = translate_error(fs, ino, err); in op_utimens()
3092 static int ioctl_getflags(ext2_filsys fs, struct fuse2fs_file_handle *fh, in ioctl_getflags() argument
3098 FUSE2FS_CHECK_MAGIC(fs, fh, FUSE2FS_FILE_MAGIC); in ioctl_getflags()
3101 err = ext2fs_read_inode_full(fs, fh->ino, (struct ext2_inode *)&inode, in ioctl_getflags()
3104 return translate_error(fs, fh->ino, err); in ioctl_getflags()
3115 static int ioctl_setflags(ext2_filsys fs, struct fuse2fs_file_handle *fh, in ioctl_setflags() argument
3125 FUSE2FS_CHECK_MAGIC(fs, fh, FUSE2FS_FILE_MAGIC); in ioctl_setflags()
3128 err = ext2fs_read_inode_full(fs, fh->ino, (struct ext2_inode *)&inode, in ioctl_setflags()
3131 return translate_error(fs, fh->ino, err); in ioctl_setflags()
3142 ret = update_ctime(fs, fh->ino, &inode); in ioctl_setflags()
3146 err = ext2fs_write_inode_full(fs, fh->ino, (struct ext2_inode *)&inode, in ioctl_setflags()
3149 return translate_error(fs, fh->ino, err); in ioctl_setflags()
3154 static int ioctl_getversion(ext2_filsys fs, struct fuse2fs_file_handle *fh, in ioctl_getversion() argument
3160 FUSE2FS_CHECK_MAGIC(fs, fh, FUSE2FS_FILE_MAGIC); in ioctl_getversion()
3163 err = ext2fs_read_inode_full(fs, fh->ino, (struct ext2_inode *)&inode, in ioctl_getversion()
3166 return translate_error(fs, fh->ino, err); in ioctl_getversion()
3172 static int ioctl_setversion(ext2_filsys fs, struct fuse2fs_file_handle *fh, in ioctl_setversion() argument
3182 FUSE2FS_CHECK_MAGIC(fs, fh, FUSE2FS_FILE_MAGIC); in ioctl_setversion()
3185 err = ext2fs_read_inode_full(fs, fh->ino, (struct ext2_inode *)&inode, in ioctl_setversion()
3188 return translate_error(fs, fh->ino, err); in ioctl_setversion()
3195 ret = update_ctime(fs, fh->ino, &inode); in ioctl_setversion()
3199 err = ext2fs_write_inode_full(fs, fh->ino, (struct ext2_inode *)&inode, in ioctl_setversion()
3202 return translate_error(fs, fh->ino, err); in ioctl_setversion()
3209 static int ioctl_fitrim(ext2_filsys fs, struct fuse2fs_file_handle *fh, in ioctl_fitrim() argument
3216 start = fr->start / fs->blocksize; in ioctl_fitrim()
3217 end = (fr->start + fr->len - 1) / fs->blocksize; in ioctl_fitrim()
3220 if (start < fs->super->s_first_data_block) in ioctl_fitrim()
3221 start = fs->super->s_first_data_block; in ioctl_fitrim()
3222 if (start >= ext2fs_blocks_count(fs->super)) in ioctl_fitrim()
3223 start = ext2fs_blocks_count(fs->super) - 1; in ioctl_fitrim()
3225 if (end < fs->super->s_first_data_block) in ioctl_fitrim()
3226 end = fs->super->s_first_data_block; in ioctl_fitrim()
3227 if (end >= ext2fs_blocks_count(fs->super)) in ioctl_fitrim()
3228 end = ext2fs_blocks_count(fs->super) - 1; in ioctl_fitrim()
3231 max_blocks = 2048ULL * 1024 * 1024 / fs->blocksize; in ioctl_fitrim()
3235 err = ext2fs_find_first_zero_block_bitmap2(fs->block_map, in ioctl_fitrim()
3240 return translate_error(fs, fh->ino, err); in ioctl_fitrim()
3243 err = ext2fs_find_first_set_block_bitmap2(fs->block_map, in ioctl_fitrim()
3246 return translate_error(fs, fh->ino, err); in ioctl_fitrim()
3248 err = io_channel_discard(fs->io, start, b - start); in ioctl_fitrim()
3250 return translate_error(fs, fh->ino, err); in ioctl_fitrim()
3252 fr->len = cleared * fs->blocksize; in ioctl_fitrim()
3271 ext2_filsys fs; in op_ioctl() local
3275 fs = ff->fs; in op_ioctl()
3280 ret = ioctl_getflags(fs, fh, data); in op_ioctl()
3283 ret = ioctl_setflags(fs, fh, data); in op_ioctl()
3286 ret = ioctl_getversion(fs, fh, data); in op_ioctl()
3289 ret = ioctl_setversion(fs, fh, data); in op_ioctl()
3294 ret = ioctl_fitrim(fs, fh, data); in op_ioctl()
3312 ext2_filsys fs; in op_bmap() local
3318 fs = ff->fs; in op_bmap()
3320 err = ext2fs_namei(fs, EXT2_ROOT_INO, EXT2_ROOT_INO, path, &ino); in op_bmap()
3322 ret = translate_error(fs, 0, err); in op_bmap()
3327 err = ext2fs_bmap2(fs, ino, NULL, NULL, 0, *idx, 0, (blk64_t *)idx); in op_bmap()
3329 ret = translate_error(fs, ino, err); in op_bmap()
3347 ext2_filsys fs; in fallocate_helper() local
3355 fs = ff->fs; in fallocate_helper()
3356 FUSE2FS_CHECK_MAGIC(fs, fh, FUSE2FS_FILE_MAGIC); in fallocate_helper()
3357 start = offset / fs->blocksize; in fallocate_helper()
3358 end = (offset + len - 1) / fs->blocksize; in fallocate_helper()
3360 fh->ino, mode, offset / fs->blocksize, end); in fallocate_helper()
3361 if (!fs_can_allocate(ff, len / fs->blocksize)) in fallocate_helper()
3365 err = ext2fs_read_inode_full(fs, fh->ino, (struct ext2_inode *)&inode, in fallocate_helper()
3374 err = ext2fs_fallocate(fs, flags, fh->ino, in fallocate_helper()
3378 return translate_error(fs, fh->ino, err); in fallocate_helper()
3383 err = ext2fs_inode_size_set(fs, in fallocate_helper()
3387 return translate_error(fs, fh->ino, err); in fallocate_helper()
3391 err = update_mtime(fs, fh->ino, &inode); in fallocate_helper()
3395 err = ext2fs_write_inode_full(fs, fh->ino, (struct ext2_inode *)&inode, in fallocate_helper()
3398 return translate_error(fs, fh->ino, err); in fallocate_helper()
3403 static errcode_t clean_block_middle(ext2_filsys fs, ext2_ino_t ino, in clean_block_middle() argument
3412 residue = offset % fs->blocksize; in clean_block_middle()
3417 err = ext2fs_get_mem(fs->blocksize, buf); in clean_block_middle()
3422 err = ext2fs_bmap2(fs, ino, (struct ext2_inode *)inode, *buf, 0, in clean_block_middle()
3423 offset / fs->blocksize, &retflags, &blk); in clean_block_middle()
3429 err = io_channel_read_blk(fs->io, blk, 1, *buf); in clean_block_middle()
3435 return io_channel_write_blk(fs->io, blk, 1, *buf); in clean_block_middle()
3438 static errcode_t clean_block_edge(ext2_filsys fs, ext2_ino_t ino, in clean_block_edge() argument
3447 residue = offset % fs->blocksize; in clean_block_edge()
3452 err = ext2fs_get_mem(fs->blocksize, buf); in clean_block_edge()
3457 err = ext2fs_bmap2(fs, ino, (struct ext2_inode *)inode, *buf, 0, in clean_block_edge()
3458 offset / fs->blocksize, &retflags, &blk); in clean_block_edge()
3462 err = io_channel_read_blk(fs->io, blk, 1, *buf); in clean_block_edge()
3471 memset(*buf + residue, 0, fs->blocksize - residue); in clean_block_edge()
3473 return io_channel_write_blk(fs->io, blk, 1, *buf); in clean_block_edge()
3483 ext2_filsys fs; in punch_helper() local
3490 fs = ff->fs; in punch_helper()
3491 FUSE2FS_CHECK_MAGIC(fs, fh, FUSE2FS_FILE_MAGIC); in punch_helper()
3499 start = (offset + fs->blocksize - 1) / fs->blocksize; in punch_helper()
3500 end = (offset + len - fs->blocksize) / fs->blocksize; in punch_helper()
3505 err = ext2fs_read_inode_full(fs, fh->ino, (struct ext2_inode *)&inode, in punch_helper()
3508 return translate_error(fs, fh->ino, err); in punch_helper()
3511 if ((offset / fs->blocksize) == ((offset + len) / fs->blocksize)) in punch_helper()
3512 err = clean_block_middle(fs, fh->ino, &inode, offset, in punch_helper()
3515 err = clean_block_edge(fs, fh->ino, &inode, offset, 0, &buf); in punch_helper()
3517 err = clean_block_edge(fs, fh->ino, &inode, in punch_helper()
3523 return translate_error(fs, fh->ino, err); in punch_helper()
3527 err = ext2fs_punch(fs, fh->ino, (struct ext2_inode *)&inode, in punch_helper()
3530 return translate_error(fs, fh->ino, err); in punch_helper()
3533 err = update_mtime(fs, fh->ino, &inode); in punch_helper()
3537 err = ext2fs_write_inode_full(fs, fh->ino, (struct ext2_inode *)&inode, in punch_helper()
3540 return translate_error(fs, fh->ino, err); in punch_helper()
3551 ext2_filsys fs = ff->fs; in op_fallocate() local
3559 if (!fs_writeable(fs)) { in op_fallocate()
3779 /* Start up the fs (while we still can use stdout) */ in main()
3792 fctx.fs = global_fs; in main()
3838 printf("%s", _("Warning: Mounting unchecked fs, running e2fsck " in main()
3896 com_err(argv[0], err, "while closing fs"); in main()
3902 static int __translate_error(ext2_filsys fs, errcode_t err, ext2_ino_t ino, in __translate_error() argument
3907 struct fuse2fs *ff = fs->priv_data; in __translate_error()
3977 fs->device_name ? fs->device_name : "???", in __translate_error()
3981 fs->device_name ? fs->device_name : "???", in __translate_error()
3987 fs->super->s_last_error_time = now.tv_sec; in __translate_error()
3988 fs->super->s_last_error_ino = ino; in __translate_error()
3989 fs->super->s_last_error_line = line; in __translate_error()
3990 fs->super->s_last_error_block = err; /* Yeah... */ in __translate_error()
3991 strncpy((char *)fs->super->s_last_error_func, file, in __translate_error()
3992 sizeof(fs->super->s_last_error_func)); in __translate_error()
3993 if (fs->super->s_first_error_time == 0) { in __translate_error()
3994 fs->super->s_first_error_time = now.tv_sec; in __translate_error()
3995 fs->super->s_first_error_ino = ino; in __translate_error()
3996 fs->super->s_first_error_line = line; in __translate_error()
3997 fs->super->s_first_error_block = err; in __translate_error()
3998 strncpy((char *)fs->super->s_first_error_func, file, in __translate_error()
3999 sizeof(fs->super->s_first_error_func)); in __translate_error()
4002 fs->super->s_error_count++; in __translate_error()
4003 ext2fs_mark_super_dirty(fs); in __translate_error()
4004 ext2fs_flush(fs); in __translate_error()