⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ffs.c

📁 linux下开发的针对所有磁盘的数据恢复的源码
💻 C
📖 第 1 页 / 共 5 页
字号:
            }            cache_len_f = frags;            cache_addr = addr;        }        // call the callback        tsk_fs_block_set(fs, fs_block, addr,            myflags | TSK_FS_BLOCK_FLAG_RAW,            &cache_blk_buf[(addr - cache_addr) * fs->block_size]);        retval = action(fs_block, ptr);        if (retval == TSK_WALK_STOP) {            break;        }        else if (retval == TSK_WALK_ERROR) {            tsk_fs_block_free(fs_block);            free(cache_blk_buf);            return 1;        }    }    /* Cleanup */    tsk_fs_block_free(fs_block);    free(cache_blk_buf);    return 0;}/* * return 1 on error and 0 on success */static uint8_tffs_fscheck(TSK_FS_INFO * fs, FILE * hFile){    tsk_error_reset();    tsk_errno = TSK_ERR_FS_UNSUPFUNC;    snprintf(tsk_errstr, TSK_ERRSTR_L,        "fscheck not implemented for ffs yet");    return 1;}/** * Print details about the file system to a file handle.  * * @param fs File system to print details on * @param hFile File handle to print text to *  * @returns 1 on error and 0 on success */static uint8_tffs_fsstat(TSK_FS_INFO * fs, FILE * hFile){    unsigned int i;    time_t tmptime;    ffs_csum1 *csum1 = NULL;    ffs_cgd *cgd = NULL;    FFS_INFO *ffs = (FFS_INFO *) fs;    ffs_sb1 *sb1 = ffs->fs.sb1;    ffs_sb2 *sb2 = ffs->fs.sb2;    int flags;    // clean up any error messages that are lying around    tsk_error_reset();    tsk_fprintf(hFile, "FILE SYSTEM INFORMATION\n");    tsk_fprintf(hFile, "--------------------------------------------\n");    if ((fs->ftype == TSK_FS_TYPE_FFS1)        || (fs->ftype == TSK_FS_TYPE_FFS1B)) {        tsk_fprintf(hFile, "File System Type: UFS 1\n");        tmptime = tsk_getu32(fs->endian, sb1->wtime);        tsk_fprintf(hFile, "Last Written: %s",            (tmptime > 0) ? asctime(localtime(&tmptime)) : "empty");        tsk_fprintf(hFile, "Last Mount Point: %s\n", sb1->last_mnt);        flags = sb1->fs_flags;    }    else {        tsk_fprintf(hFile, "File System Type: UFS 2\n");        tmptime = tsk_getu32(fs->endian, sb2->wtime);        tsk_fprintf(hFile, "Last Written: %s",            (tmptime > 0) ? asctime(localtime(&tmptime)) : "empty");        tsk_fprintf(hFile, "Last Mount Point: %s\n", sb2->last_mnt);        tsk_fprintf(hFile, "Volume Name: %s\n", sb2->volname);        tsk_fprintf(hFile, "System UID: %" PRIu64 "\n",            tsk_getu64(fs->endian, sb2->swuid));        flags = tsk_getu32(fs->endian, sb2->fs_flags);    }    if (flags) {        int cnt = 0;        tsk_fprintf(hFile, "Flags: ");        if (flags & FFS_SB_FLAG_UNCLEAN)            tsk_fprintf(hFile, "%s Unclean", (cnt++ == 0 ? "" : ","));        if (flags & FFS_SB_FLAG_SOFTDEP)            tsk_fprintf(hFile, "%s Soft Dependencies",                (cnt++ == 0 ? "" : ","));        if (flags & FFS_SB_FLAG_NEEDFSCK)            tsk_fprintf(hFile, "%s Needs fsck", (cnt++ == 0 ? "" : ","));        if (flags & FFS_SB_FLAG_INDEXDIR)            tsk_fprintf(hFile, "%s Index directories",                (cnt++ == 0 ? "" : ","));        if (flags & FFS_SB_FLAG_ACL)            tsk_fprintf(hFile, "%s ACLs", (cnt++ == 0 ? "" : ","));        if (flags & FFS_SB_FLAG_MULTILABEL)            tsk_fprintf(hFile, "%s TrustedBSD MAC Multi-label",                (cnt++ == 0 ? "" : ","));        if (flags & FFS_SB_FLAG_UPDATED)            tsk_fprintf(hFile, "%s Updated Flag Location",                (cnt++ == 0 ? "" : ","));        tsk_fprintf(hFile, "\n");    }    tsk_fprintf(hFile, "\nMETADATA INFORMATION\n");    tsk_fprintf(hFile, "--------------------------------------------\n");    tsk_fprintf(hFile, "Inode Range: %" PRIuINUM " - %" PRIuINUM "\n",        fs->first_inum, fs->last_inum);    tsk_fprintf(hFile, "Root Directory: %" PRIuINUM "\n", fs->root_inum);    if ((fs->ftype == TSK_FS_TYPE_FFS1)        || (fs->ftype == TSK_FS_TYPE_FFS1B)) {        tsk_fprintf(hFile, "Num of Avail Inodes: %" PRIu32 "\n",            tsk_getu32(fs->endian, sb1->cstotal.ino_free));        tsk_fprintf(hFile, "Num of Directories: %" PRIu32 "\n",            tsk_getu32(fs->endian, sb1->cstotal.dir_num));    }    else {        tsk_fprintf(hFile, "Num of Avail Inodes: %" PRIu64 "\n",            tsk_getu64(fs->endian, sb2->cstotal.ino_free));        tsk_fprintf(hFile, "Num of Directories: %" PRIu64 "\n",            tsk_getu64(fs->endian, sb2->cstotal.dir_num));    }    tsk_fprintf(hFile, "\nCONTENT INFORMATION\n");    tsk_fprintf(hFile, "--------------------------------------------\n");    tsk_fprintf(hFile, "Fragment Range: %" PRIuDADDR " - %" PRIuDADDR "\n",        fs->first_block, fs->last_block);    if (fs->last_block != fs->last_block_act)        tsk_fprintf(hFile,            "Total Range in Image: %" PRIuDADDR " - %" PRIuDADDR "\n",            fs->first_block, fs->last_block_act);    tsk_fprintf(hFile, "Block Size: %u\n", ffs->ffsbsize_b);    tsk_fprintf(hFile, "Fragment Size: %u\n", fs->block_size);    if ((fs->ftype == TSK_FS_TYPE_FFS1)        || (fs->ftype == TSK_FS_TYPE_FFS1B)) {        tsk_fprintf(hFile, "Num of Avail Full Blocks: %" PRIu32 "\n",            tsk_getu32(fs->endian, sb1->cstotal.blk_free));        tsk_fprintf(hFile, "Num of Avail Fragments: %" PRIu32 "\n",            tsk_getu32(fs->endian, sb1->cstotal.frag_free));    }    else {        tsk_fprintf(hFile, "Num of Avail Full Blocks: %" PRIu64 "\n",            tsk_getu64(fs->endian, sb2->cstotal.blk_free));        tsk_fprintf(hFile, "Num of Avail Fragments: %" PRIu64 "\n",            tsk_getu64(fs->endian, sb2->cstotal.frag_free));    }    tsk_fprintf(hFile, "\nCYLINDER GROUP INFORMATION\n");    tsk_fprintf(hFile, "--------------------------------------------\n");    tsk_fprintf(hFile, "Number of Cylinder Groups: %" PRIu32 "\n",        ffs->groups_count);    tsk_fprintf(hFile, "Inodes per group: %" PRId32 "\n",        tsk_gets32(fs->endian, sb1->cg_inode_num));    tsk_fprintf(hFile, "Fragments per group: %" PRId32 "\n",        tsk_gets32(fs->endian, sb1->cg_frag_num));    /* UFS 1 and 2 use the same ssize field  and use the same csum1 */    if (tsk_getu32(fs->endian, sb1->cg_ssize_b)) {        ssize_t cnt;        csum1 =            (ffs_csum1 *) tsk_malloc(tsk_getu32(fs->endian,                sb1->cg_ssize_b));        if (csum1 == NULL)            return 1;        if ((fs->ftype == TSK_FS_TYPE_FFS1)            || (fs->ftype == TSK_FS_TYPE_FFS1B)) {            cnt =                tsk_fs_read_block(fs, (TSK_DADDR_T) tsk_getu32(fs->endian,                    sb1->cg_saddr), (char *) csum1, tsk_getu32(fs->endian,                    sb1->cg_ssize_b));            if (cnt != tsk_getu32(fs->endian, sb1->cg_ssize_b)) {                if (cnt >= 0) {                    tsk_error_reset();                    tsk_errno = TSK_ERR_FS_READ;                }                snprintf(tsk_errstr2, TSK_ERRSTR_L,                    "ffs_fsstat: FFS1 group descriptor at %"                    PRIu32, tsk_getu32(fs->endian, sb1->cg_saddr));                return 1;            }        }        else {            cnt = tsk_fs_read_block                (fs, (TSK_DADDR_T) tsk_getu64(fs->endian,                    sb2->cg_saddr), (char *) csum1, tsk_getu32(fs->endian,                    sb2->cg_ssize_b));            if (cnt != tsk_getu32(fs->endian, sb2->cg_ssize_b)) {                if (cnt >= 0) {                    tsk_error_reset();                    tsk_errno = TSK_ERR_FS_READ;                }                snprintf(tsk_errstr2, TSK_ERRSTR_L,                    "ffs_fsstat: FFS2 group descriptor at %"                    PRIu64, tsk_getu64(fs->endian, sb2->cg_saddr));                return 1;            }        }    }    for (i = 0; i < ffs->groups_count; i++) {        if (ffs_group_load(ffs, i))            return 1;        cgd = (ffs_cgd *) ffs->grp_buf;        tsk_fprintf(hFile, "\nGroup %d:\n", i);        if (cgd) {            if ((fs->ftype == TSK_FS_TYPE_FFS1)                || (fs->ftype == TSK_FS_TYPE_FFS1B)) {                tmptime = tsk_getu32(fs->endian, cgd->wtime);            }            else {                ffs_cgd2 *cgd2 = (ffs_cgd2 *) cgd;                tmptime = (uint32_t) tsk_getu64(fs->endian, cgd2->wtime);            }            tsk_fprintf(hFile, "  Last Written: %s",                (tmptime > 0) ? asctime(localtime(&tmptime)) : "empty");        }        tsk_fprintf(hFile, "  Inode Range: %" PRIu32 " - %" PRIu32 "\n",            (tsk_gets32(fs->endian, sb1->cg_inode_num) * i),            ((uint32_t) ((tsk_gets32(fs->endian,                            sb1->cg_inode_num) * (i + 1)) - 1)                < fs->last_inum) ? (uint32_t) ((tsk_gets32(fs->endian,                        sb1->cg_inode_num) * (i + 1)) -                1) : (uint32_t) fs->last_inum);        tsk_fprintf(hFile,            "  Fragment Range: %" PRIuDADDR " - %" PRIuDADDR "\n",            cgbase_lcl(fs, sb1, i),            ((cgbase_lcl(fs, sb1, i + 1) - 1) <                fs->last_block) ? (cgbase_lcl(fs, sb1,                    i + 1) - 1) : fs->last_block);        /* The first group is special because the first 16 sectors are         * reserved for the boot block.           * the next contains the primary Super Block          */        if (!i) {            tsk_fprintf(hFile, "    Boot Block: 0 - %" PRIu32 "\n",                (uint32_t) (15 * 512 / fs->block_size));            tsk_fprintf(hFile,                "    Super Block: %" PRIu32 " - %" PRIu32 "\n",                (uint32_t) (16 * 512 / fs->block_size),                (uint32_t) ((16 * 512 / fs->block_size) + ffs->ffsbsize_f -                    1));        }        tsk_fprintf(hFile,            "    Super Block: %" PRIuDADDR " - %" PRIuDADDR "\n",            cgsblock_lcl(fs, sb1, i),            (cgsblock_lcl(fs, sb1, i) + ffs->ffsbsize_f - 1));        tsk_fprintf(hFile,            "    Group Desc: %" PRIuDADDR " - %" PRIuDADDR "\n",            cgtod_lcl(fs, sb1, i), (cgtod_lcl(fs, sb1,                    i) + ffs->ffsbsize_f - 1));        if (fs->ftype == TSK_FS_TYPE_FFS2) {            tsk_fprintf(hFile,                "    Inode Table: %" PRIuDADDR " - %" PRIuDADDR "\n",                cgimin_lcl(fs, sb1, i),                (cgimin_lcl(fs, sb1, i) +                    ((roundup                            (tsk_gets32(fs->endian,                                    sb1->cg_inode_num) *                                sizeof(ffs_inode2), fs->block_size)                            / fs->block_size) - 1)));        }        else {            tsk_fprintf(hFile,                "    Inode Table: %" PRIuDADDR " - %" PRIuDADDR "\n",                cgimin_lcl(fs, sb1, i),                (cgimin_lcl(fs, sb1, i) +                    ((roundup                            (tsk_gets32(fs->endian,                                    sb1->cg_inode_num) *                                sizeof(ffs_inode1), fs->block_size)                            / fs->block_size) - 1)));        }        tsk_fprintf(hFile, "    Data Fragments: ");        /* For all groups besides the first, the space before the         * super block is also used for data         */        if (i)            tsk_fprintf(hFile, "%" PRIuDADDR " - %" PRIuDADDR ", ",                cgbase_lcl(fs, sb1, i), cgsblock_lcl(fs, sb1, i) - 1);        tsk_fprintf(hFile, "%" PRIuDADDR " - %" PRIuDADDR "\n",            cgdmin_lcl(fs, sb1, i),            ((cgbase_lcl(fs, sb1, i + 1) - 1) < fs->last_block) ?            (cgbase_lcl(fs, sb1, i + 1) - 1) : fs->last_block);        if ((csum1)            && ((i + 1) * sizeof(ffs_csum1) < tsk_getu32(fs->endian,                    sb1->cg_ssize_b))) {            tsk_fprintf(hFile,                "  Global Summary (from the superblock summary area):\n");            tsk_fprintf(hFile, "    Num of Dirs: %" PRIu32 "\n",                tsk_getu32(fs->endian, &csum1[i].dir_num));            tsk_fprintf(hFile, "    Num of Avail Blocks: %" PRIu32 "\n",                tsk_getu32(fs->endian, &csum1[i].blk_free));            tsk_fprintf(hFile, "    Num of Avail Inodes: %" PRIu32 "\n",                tsk_getu32(fs->endian, &csum1[i].ino_free));            tsk_fprintf(hFile, "    Num of Avail Frags: %" PRIu32 "\n",                tsk_getu32(fs->endian, &csum1[i].frag_free));        }        if (cgd) {            tsk_fprintf(hFile,                "  Local Summary (from the group descriptor):\n");            tsk_fprintf(hFile, "    Num of Dirs: %" PRIu32 "\n",                tsk_getu32(fs->endian, &cgd->cs.dir_num));            tsk_fprintf(hFile, "    Num of Avail Blocks: %" PRIu32 "\n",                tsk_getu32(fs->endian, &cgd->cs.blk_free));            tsk_fprintf(hFile, "    Num of Avail Inodes: %" PRIu32 "\n",                tsk_getu32(fs->endian, &cgd->cs.ino_free));            tsk_fprintf(hFile, "    Num of Avail Frags: %" PRIu32 "\n",                tsk_getu32(fs->endian, &cgd->cs.frag_free));            tsk_fprintf(hFile,                "    Last Block Allocated: %" PRIuDADDR "\n",                tsk_getu32(fs->endian,                    &cgd->last_alloc_blk) + cgbase_lcl(fs, sb1, i));            tsk_fprintf(hFile,                "    Last Fragment Allocated: %" PRIuDADDR "\n",                tsk_getu32(fs->endian,                    &cgd->last_alloc_frag) + cgbase_lcl(fs, sb1, i));            tsk_fprintf(hFile, "    Last Inode Allocated: %" PRIu32 "\n",                tsk_getu32(fs->endian,                    &cgd->last_alloc_ino) + (tsk_gets32(fs->endian,                        sb1->cg_inode_num) * i));        }    }    return 0;}/************************* istat *******************************/typedef struct {    FILE *hFile;    int idx;} FFS_PRINT_ADDR;static TSK_WALK_RET_ENUMprint_addr_act(TSK_FS_FILE * fs_file, TSK_OFF_T a_off, TSK_DADDR_T addr,    char *buf, size_t size, TSK_FS_BLOCK_FLAG_ENUM a_flags, void *ptr){    TSK_FS_INFO *fs = fs_file->fs_info;    FFS_PRINT_ADDR *print = (FFS_PRINT_ADDR *) ptr;    if (a_flags & TSK_FS_BLOCK_FLAG_CONT) {        int i, s;        /* cycle through the fragments if they exist */        for (i = 0, s = (int) size; s > 0; s -= fs->block_size, i++) {            /* sparse file */            if (addr)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -