int jfs_getinfo(cdico *d, char *devname) { struct jfs_superblock sb; char uuid[512]; int ret=0; int fd; if ((fd=open64(devname, O_RDONLY|O_LARGEFILE))<0) { ret=-1; errprintf("cannot open(%s, O_RDONLY)\n", devname); goto jfs_getinfo_return; } if (lseek(fd, JFS_SUPER1_OFF, SEEK_SET)!=JFS_SUPER1_OFF) { ret=-2; errprintf("cannot lseek(fd, JFS_SUPER1_OFF, SEEK_SET) on %s\n", devname); goto jfs_getinfo_close; } if (read(fd, &sb, sizeof(sb))!=sizeof(sb)) { ret=-3; errprintf("cannot read the jfs superblock on [%s]\n", devname); goto jfs_getinfo_close; } if (strncmp(sb.s_magic, JFS_MAGIC, strlen(JFS_MAGIC)) != 0) { ret=-4; errprintf("magic different from expectations superblock on %s: magic=[%s], expected=[%s]\n", devname, sb.s_magic, JFS_MAGIC); goto jfs_getinfo_close; } msgprintf(MSG_DEBUG1, "jfs_magic=[%s]\n", sb.s_magic); // ---- label msgprintf(MSG_DEBUG1, "jfs_label=[%s]\n", sb.s_label); dico_add_string(d, 0, FSYSHEADKEY_FSLABEL, (char*)sb.s_label); // ---- uuid /*if ((str=e2p_uuid2str(sb.s_uuid))!=NULL) dico_add_string(d, 0, FSYSHEADKEY_FSUUID, str);*/ memset(uuid, 0, sizeof(uuid)); uuid_unparse_lower((u8*)sb.s_uuid, uuid); dico_add_string(d, 0, FSYSHEADKEY_FSUUID, uuid); msgprintf(MSG_DEBUG1, "jfs_uuid=[%s]\n", uuid); // ---- minimum fsarchiver version required to restore dico_add_u64(d, 0, FSYSHEADKEY_MINFSAVERSION, FSA_VERSION_BUILD(0, 6, 4, 0)); jfs_getinfo_close: close(fd); jfs_getinfo_return: return ret; }
int archwriter_write_volheader(carchwriter *ai) { struct s_writebuf *wb=NULL; cdico *voldico; assert(ai); if ((wb=writebuf_alloc())==NULL) { msgprintf(MSG_STACK, "writebuf_alloc() failed\n"); return -1; } if ((voldico=dico_alloc())==NULL) { msgprintf(MSG_STACK, "voldico=dico_alloc() failed\n"); return -1; } // prepare header dico_add_u32(voldico, 0, VOLUMEHEADKEY_VOLNUM, ai->curvol); dico_add_u32(voldico, 0, VOLUMEHEADKEY_ARCHID, ai->archid); dico_add_string(voldico, 0, VOLUMEHEADKEY_FILEFORMATVER, FSA_FILEFORMAT); dico_add_string(voldico, 0, VOLUMEHEADKEY_PROGVERCREAT, FSA_VERSION); // write header to buffer if (writebuf_add_header(wb, voldico, FSA_MAGIC_VOLH, ai->archid, FSA_FILESYSID_NULL)!=0) { errprintf("archio_write_header() failed\n"); return -1; } // write header to file if (archwriter_write_buffer(ai, wb)!=0) { errprintf("archwriter_write_buffer() failed\n"); return -1; } dico_destroy(voldico); writebuf_destroy(wb); return 0; }
int btrfs_getinfo(cdico *d, char *devname) { struct btrfs_super_block sb; char uuid[512]; u16 temp32; int ret=0; int fd; if ((fd=open64(devname, O_RDONLY|O_LARGEFILE))<0) { ret=-1; errprintf("cannot open(%s, O_RDONLY)\n", devname); goto btrfs_read_sb_return; } if (lseek(fd, BTRFS_SUPER_INFO_OFFSET, SEEK_SET)!=BTRFS_SUPER_INFO_OFFSET) { ret=-2; errprintf("cannot lseek(fd, BTRFS_SUPER_INFO_OFFSET, SEEK_SET) on %s\n", devname); goto btrfs_read_sb_close; } if (read(fd, &sb, sizeof(sb))!=sizeof(sb)) { ret=-3; errprintf("cannot read the btrfs superblock on device [%s]\n", devname); goto btrfs_read_sb_close; } if (strncmp((char*)&sb.magic, BTRFS_MAGIC, sizeof(sb.magic))!=0) { ret=-4; errprintf("magic different from expectations superblock on [%s]: magic=[%.8s], expected=[%.8s]\n", devname, (char*)&sb.magic, BTRFS_MAGIC); goto btrfs_read_sb_close; } // ---- label msgprintf(MSG_DEBUG1, "btrfs_label=[%s]\n", sb.label); dico_add_string(d, 0, FSYSHEADKEY_FSLABEL, (char*)sb.label); // ---- uuid /*if ((str=e2p_uuid2str(sb.dev_item.fsid))!=NULL) dico_add_string(d, 0, FSYSHEADKEY_FSUUID, str);*/ memset(uuid, 0, sizeof(uuid)); uuid_unparse_lower((u8*)sb.dev_item.fsid, uuid); dico_add_string(d, 0, FSYSHEADKEY_FSUUID, uuid); msgprintf(MSG_DEBUG1, "btrfs_uuid=[%s]\n", uuid); // ---- sector size temp32=le32_to_cpu(sb.sectorsize); dico_add_u64(d, 0, FSYSHEADKEY_FSBTRFSSECTORSIZE, temp32); msgprintf(MSG_DEBUG1, "btrfs_sectorsize=[%ld]\n", (long)temp32); // ---- filesystem features dico_add_u64(d, 0, FSYSHEADKEY_BTRFSFEATURECOMPAT, le64_to_cpu(sb.compat_flags)); dico_add_u64(d, 0, FSYSHEADKEY_BTRFSFEATUREINCOMPAT, le64_to_cpu(sb.incompat_flags)); dico_add_u64(d, 0, FSYSHEADKEY_BTRFSFEATUREROCOMPAT, le64_to_cpu(sb.compat_ro_flags)); if (btrfs_check_compatibility(le64_to_cpu(sb.compat_flags), le64_to_cpu(sb.incompat_flags), le64_to_cpu(sb.compat_ro_flags))!=0) { errprintf("this filesystem has features which are not supported by this fsarchiver version.\n"); return -1; } // ---- minimum fsarchiver version required to restore dico_add_u64(d, 0, FSYSHEADKEY_MINFSAVERSION, FSA_VERSION_BUILD(0, 6, 4, 0)); btrfs_read_sb_close: close(fd); btrfs_read_sb_return: return ret; }
int extfs_getinfo(cdico *d, char *devname) { struct fsa_ext2_sb *super; blk_t use_superblock=0; int use_blocksize=0; char uuid[512]; ext2_filsys fs; int origextfstype; char mntopt[1024]; char label[80]; u32 mask, m; int count; int i; // ---- open partition if (ext2fs_open(devname, EXT2_FLAG_JOURNAL_DEV_OK | EXT2_FLAG_SOFTSUPP_FEATURES, use_superblock, use_blocksize, unix_io_manager, &fs)!=0) { errprintf("ext2fs_open(%s) failed\n", devname); return -1; } super=(struct fsa_ext2_sb *)fs->super; // --- label memset(label, 0, sizeof(label)); if (super->s_volume_name[0]) { memset(label, 0, sizeof(label)); strncpy(label, super->s_volume_name, sizeof(super->s_volume_name)); } dico_add_string(d, 0, FSYSHEADKEY_FSLABEL, label); // ---- uuid /*if ((str=e2p_uuid2str(super->s_uuid))!=NULL) dico_add_string(d, 0, FSYSHEADKEY_FSUUID, str);*/ memset(uuid, 0, sizeof(uuid)); uuid_unparse_lower((u8*)super->s_uuid, uuid); dico_add_string(d, 0, FSYSHEADKEY_FSUUID, uuid); msgprintf(MSG_DEBUG1, "extfs_uuid=[%s]\n", uuid); // ---- block size dico_add_u64(d, 0, FSYSHEADKEY_FSEXTBLOCKSIZE, EXT2_BLOCK_SIZE(super)); // ---- filesystem revision (good-old-rev or dynamic) dico_add_u64(d, 0, FSYSHEADKEY_FSEXTREVISION, super->s_rev_level); // ---- inode size if (super->s_rev_level >= EXT2_DYNAMIC_REV) dico_add_u64(d, 0, FSYSHEADKEY_FSINODESIZE, super->s_inode_size); else dico_add_u64(d, 0, FSYSHEADKEY_FSINODESIZE, EXT2_GOOD_OLD_INODE_SIZE); // Good old rev // ---- extended options if (super->s_raid_stride > 0) { dico_add_u64(d, 0, FSYSHEADKEY_FSEXTEOPTRAIDSTRIDE, super->s_raid_stride); msgprintf(MSG_DEBUG1, "extfs_raid_stride: %u\n", super->s_raid_stride); } if (super->s_raid_stripe_width > 0) { dico_add_u64(d, 0, FSYSHEADKEY_FSEXTEOPTRAIDSTRIPEWIDTH, super->s_raid_stripe_width); msgprintf(MSG_DEBUG1, "extfs_raid_stripe_width: %u\n", super->s_raid_stripe_width); } // ---- fsck details: max_mount_count and check_interval dico_add_u64(d, 0, FSYSHEADKEY_FSEXTFSCKMAXMNTCOUNT, max(super->s_max_mnt_count,0)); dico_add_u64(d, 0, FSYSHEADKEY_FSEXTFSCKCHECKINTERVAL, super->s_checkinterval); msgprintf(MSG_DEBUG1, "extfs_max_mount_count: %ld\n", (long)max(super->s_max_mnt_count,0)); msgprintf(MSG_DEBUG1, "extfs_check_interval: %ld\n", (long)super->s_checkinterval); // ---- default mount options memset(mntopt, 0, sizeof(mntopt)); count=0; mask=super->s_default_mount_opts; if (mask & EXT3_DEFM_JMODE) { strlcatf(mntopt, sizeof(mntopt), "%s", e2p_mntopt2string(mask & EXT3_DEFM_JMODE)); count++; } for (i=0, m=1; i < 32; i++, m<<=1) { if (m & EXT3_DEFM_JMODE) continue; if (mask & m) { if (count++) strlcatf(mntopt, sizeof(mntopt), ","); strlcatf(mntopt, sizeof(mntopt), "%s", e2p_mntopt2string(m)); } } dico_add_string(d, 0, FSYSHEADKEY_FSEXTDEFMNTOPT, mntopt); msgprintf(MSG_DEBUG1, "default mount options: [%s]\n", mntopt); // ---- filesystem features dico_add_u64(d, 0, FSYSHEADKEY_FSEXTFEATURECOMPAT, (u64)super->s_feature_compat); dico_add_u64(d, 0, FSYSHEADKEY_FSEXTFEATUREINCOMPAT, (u64)super->s_feature_incompat); dico_add_u64(d, 0, FSYSHEADKEY_FSEXTFEATUREROCOMPAT, (u64)super->s_feature_ro_compat); origextfstype=extfs_get_fstype_from_compat_flags((u64)super->s_feature_compat, (u64)super->s_feature_incompat, (u64)super->s_feature_ro_compat); msgprintf(MSG_DEBUG1, "the filesystem type determined by the features is [%s]\n", format_fstype(origextfstype)); // ---- check that fsarchiver is aware of all the filesystem features used on that filesystem if (extfs_check_compatibility((u64)super->s_feature_compat, (u64)super->s_feature_incompat, (u64)super->s_feature_ro_compat)!=0) { errprintf("this filesystem has ext{2,3,4} features which are not supported by this fsarchiver version.\n"); return -1; } // ---- minimum fsarchiver version required to restore dico_add_u64(d, 0, FSYSHEADKEY_MINFSAVERSION, FSA_VERSION_BUILD(0, 6, 4, 0)); ext2fs_close(fs); return 0; }
int xfs_getinfo(cdico *d, char *devname) { struct xfs_sb sb; char uuid[512]; u64 xfsver; u32 temp32; int ret=0; int fd; int res; u64 sb_features_compat=0; u64 sb_features_ro_compat=0; u64 sb_features_incompat=0; u64 sb_features_log_incompat=0; if ((fd=open64(devname, O_RDONLY|O_LARGEFILE))<0) { ret=-1; goto xfs_read_sb_return; } res=read(fd, &sb, sizeof(sb)); if (res!=sizeof(sb)) { ret=-1; goto xfs_read_sb_close; } // ---- check it's an XFS file system if (be32_to_cpu(sb.sb_magicnum) != XFS_SB_MAGIC) { ret=-1; msgprintf(3, "sb.sb_magicnum!=XFS_SB_MAGIC\n"); goto xfs_read_sb_close; } // ---- check XFS filesystem version xfsver=be16_to_cpu(sb.sb_versionnum) & XFS_SB_VERSION_NUMBITS; switch (xfsver) { case XFS_SB_VERSION_4: case XFS_SB_VERSION_5: msgprintf(MSG_DEBUG1, "Detected XFS filesystem version %d\n", (int)xfsver); dico_add_u64(d, 0, FSYSHEADKEY_FSXFSVERSION, xfsver); break; default: ret=-1; msgprintf(MSG_STACK, "Invalid XFS filesystem version: version=[%d]\n", (int)xfsver); goto xfs_read_sb_close; break; } // ---- label msgprintf(MSG_DEBUG1, "xfs_label=[%s]\n", sb.sb_fname); dico_add_string(d, 0, FSYSHEADKEY_FSLABEL, (char*)sb.sb_fname); // ---- uuid /*if ((str=e2p_uuid2str(&sb.sb_uuid))!=NULL) dico_add_string(d, 0, FSYSHEADKEY_FSUUID, str);*/ memset(uuid, 0, sizeof(uuid)); uuid_unparse_lower((u8*)&sb.sb_uuid, uuid); dico_add_string(d, 0, FSYSHEADKEY_FSUUID, uuid); msgprintf(MSG_DEBUG1, "xfs_uuid=[%s]\n", uuid); // ---- block size temp32=be32_to_cpu(sb.sb_blocksize); if ((temp32%512!=0) || (temp32<512) || (temp32>65536)) { ret=-1; msgprintf(3, "xfs_blksize=[%ld] is an invalid xfs block size\n", (long)temp32); goto xfs_read_sb_close; } dico_add_u64(d, 0, FSYSHEADKEY_FSXFSBLOCKSIZE, temp32); msgprintf(MSG_DEBUG1, "xfs_blksize=[%ld]\n", (long)temp32); // ---- get filesystem features (will all be set to 0 if this is an XFSv4) if (xfsver == XFS_SB_VERSION_5) { sb_features_compat=be32_to_cpu(sb.sb_features_compat); sb_features_ro_compat=be32_to_cpu(sb.sb_features_ro_compat); sb_features_incompat=be32_to_cpu(sb.sb_features_incompat); sb_features_log_incompat=be32_to_cpu(sb.sb_features_log_incompat); } // ---- check fsarchiver is aware of all the filesystem features used on that filesystem if (xfs_check_compatibility(sb_features_compat, sb_features_ro_compat, sb_features_incompat, sb_features_log_incompat)!=0) return -1; // ---- store features in the archive metadata dico_add_u64(d, 0, FSYSHEADKEY_FSXFSFEATURECOMPAT, (u64)sb_features_compat); dico_add_u64(d, 0, FSYSHEADKEY_FSXFSFEATUREROCOMPAT, (u64)sb_features_ro_compat); dico_add_u64(d, 0, FSYSHEADKEY_FSXFSFEATUREINCOMPAT, (u64)sb_features_incompat); dico_add_u64(d, 0, FSYSHEADKEY_FSXFSFEATURELOGINCOMPAT, (u64)sb_features_log_incompat); // ---- minimum fsarchiver version required to restore dico_add_u64(d, 0, FSYSHEADKEY_MINFSAVERSION, FSA_VERSION_BUILD(0, 6, 20, 0)); xfs_read_sb_close: close(fd); xfs_read_sb_return: return ret; }