/// open device static void fs_open(char* device){ errcode_t retval; int use_superblock = 0; int use_blocksize = 0; int flags; flags = EXT2_FLAG_JOURNAL_DEV_OK | EXT2_FLAG_SOFTSUPP_FEATURES; if (use_superblock && !use_blocksize) { for (use_blocksize = EXT2_MIN_BLOCK_SIZE; use_blocksize <= EXT2_MAX_BLOCK_SIZE; use_blocksize *= 2) { retval = ext2fs_open (device, flags, use_superblock, use_blocksize, unix_io_manager, &fs); if (!retval) break; } } else retval = ext2fs_open (device, flags, use_superblock, use_blocksize, unix_io_manager, &fs); if (retval) log_mesg(0, 1, 1, fs_opt.debug, "%s: Couldn't find valid filesystem superblock.\n", __FILE__); ext2fs_mark_valid(fs); if(fs_opt.ignore_fschk){ log_mesg(1, 0, 0, fs_opt.debug, "%s: Ignore filesystem check\n", __FILE__); } else { if ((fs->super->s_state & EXT2_ERROR_FS) || !ext2fs_test_valid(fs)) log_mesg(0, 1, 1, fs_opt.debug, "%s: FS contains a file system with errors\n", __FILE__); else if ((fs->super->s_state & EXT2_VALID_FS) == 0) log_mesg(0, 1, 1, fs_opt.debug, "%s: FS was not cleanly unmounted\n", __FILE__); else if ((fs->super->s_max_mnt_count > 0) && (fs->super->s_mnt_count >= (unsigned) fs->super->s_max_mnt_count)) { log_mesg(0, 1, 1, fs_opt.debug, "%s: FS has been mounted %"PRIu16" times without being checked\n", __FILE__, fs->super->s_mnt_count); } } }
int main (int argc, char ** argv) { errcode_t retval; ext2_filsys fs; io_manager io_ptr; add_error_table(&et_ext2_error_table); blkid_get_cache(&cache, NULL); PRS(argc, argv); #ifdef CONFIG_TESTIO_DEBUG if (getenv("TEST_IO_FLAGS") || getenv("TEST_IO_BLOCK")) { io_ptr = test_io_manager; test_io_backing_manager = unix_io_manager; } else #endif io_ptr = unix_io_manager; retval = ext2fs_open (device_name, open_flag, 0, 0, io_ptr, &fs); if (retval) exit(1); if (root_type) get_root_type(fs); remove_error_table(&et_ext2_error_table); return (ext2fs_close (fs) ? 1 : 0); }
int extfs_mount(char *partition, char *mntbuf, char *fsbuf, int flags, char *mntinfo) { blk_t use_superblock=0; int use_blocksize=0; ext2_filsys fs; int origextfstype; char fsname[32]; msgprintf(MSG_DEBUG1, "extfs_mount(partition=[%s], mnt=[%s], fsbuf=[%s])\n", partition, mntbuf, fsbuf); if (ext2fs_open(partition, EXT2_FLAG_JOURNAL_DEV_OK | EXT2_FLAG_SOFTSUPP_FEATURES, use_superblock, use_blocksize, unix_io_manager, &fs)!=0) { msgprintf(MSG_DEBUG1, "ext2fs_open(%s) failed\n", partition); return -1; } origextfstype=extfs_get_fstype_from_compat_flags((u64)fs->super->s_feature_compat, (u64)fs->super->s_feature_incompat, (u64)fs->super->s_feature_ro_compat); snprintf(fsname, sizeof(fsname), "%s", format_fstype(origextfstype)); msgprintf(MSG_VERB2, "the filesystem of [%s] type determined by the features is [%s]\n", partition, fsname); ext2fs_close(fs); if (strcmp(fsname, fsbuf)!=0) { msgprintf(MSG_DEBUG1, "extfs_mount: the filesystem requested [%s] does not match the filesystem detected [%s]\n", fsbuf, fsname); return -1; } return generic_mount(partition, mntbuf, fsbuf, "user_xattr,acl", flags); }
main(int argc, char **argv) { errcode_t retval; char *device_name; ext2_filsys fs; if (argc < 2) { fprintf(stderr, "Usage: %s filesystem\n", argv[0]); exit(1); } device_name = argv[1]; retval = ext2fs_open (device_name, EXT2_FLAG_RW, 0, 0, unix_io_manager, &fs); if (retval) { com_err(argv[0], retval, "while opening %s", device_name); exit(1); } retval = ext2fs_add_journal_inode(fs, 1024, 0); if (retval) { com_err(argv[0], retval, "while adding journal to %s", device_name); exit(1); } retval = ext2fs_flush(fs); if (retval) { printf("Warning, had trouble writing out superblocks.\n"); } ext2fs_close(fs); exit(0); }
void * op_init (struct fuse_conn_info *conn) { errcode_t rc; struct fuse_context *cntx=fuse_get_context(); struct extfs_data *e2data=cntx->private_data; debugf("enter %s", e2data->device); rc = ext2fs_open(e2data->device, (e2data->readonly) ? 0 : EXT2_FLAG_RW, 0, 0, unix_io_manager, &e2data->e2fs); if (rc) { debugf("Error while trying to open %s", e2data->device); exit(1); } #if 1 if (e2data->readonly != 1) #endif rc = ext2fs_read_bitmaps(e2data->e2fs); if (rc) { debugf("Error while reading bitmaps"); ext2fs_close(e2data->e2fs); exit(1); } debugf("FileSystem %s", (e2data->e2fs->flags & EXT2_FLAG_RW) ? "Read&Write" : "ReadOnly"); debugf("leave"); return e2data; }
int main (int argc, char ** argv) { errcode_t retval; ext2_filsys fs; io_manager io_ptr; initialize_ext2_error_table(); blkid_get_cache(&cache, NULL); PRS(argc, argv); #ifdef CONFIG_TESTIO_DEBUG io_ptr = test_io_manager; test_io_backing_manager = unix_io_manager; #else io_ptr = unix_io_manager; #endif retval = ext2fs_open (device_name, open_flag, 0, 0, io_ptr, &fs); if (retval) exit(1); if (root_type) get_root_type(fs); return (ext2fs_close (fs) ? 1 : 0); }
int extfs_get_reqmntopt(char *partition, cstrlist *reqopt, cstrlist *badopt) { blk_t use_superblock=0; int use_blocksize=0; u32 defmntoptmask; ext2_filsys fs; if (!reqopt || !badopt) return -1; // check the "default mount options" if (ext2fs_open(partition, EXT2_FLAG_JOURNAL_DEV_OK | EXT2_FLAG_SOFTSUPP_FEATURES, use_superblock, use_blocksize, unix_io_manager, &fs)!=0) return -1; defmntoptmask=fs->super->s_default_mount_opts; if (!(defmntoptmask&EXT2_DEFM_XATTR_USER)) strlist_add(reqopt, "user_xattr"); if (!(defmntoptmask&EXT2_DEFM_ACL)) strlist_add(reqopt, "acl"); strlist_add(badopt, "nouser_xattr"); strlist_add(badopt, "noacl"); ext2fs_close(fs); return 0; }
int e2fsck_run_ext3_journal(e2fsck_t ctx) { io_manager io_ptr = ctx->fs->io->manager; int blocksize = ctx->fs->blocksize; errcode_t retval, recover_retval; io_stats stats = 0; unsigned long long kbytes_written = 0; printf(_("%s: recovering journal\n"), ctx->device_name); if (ctx->options & E2F_OPT_READONLY) { printf(_("%s: won't do journal recovery while read-only\n"), ctx->device_name); return EXT2_ET_FILE_RO; } if (ctx->fs->flags & EXT2_FLAG_DIRTY) ext2fs_flush(ctx->fs); /* Force out any modifications */ recover_retval = recover_ext3_journal(ctx); /* * Reload the filesystem context to get up-to-date data from disk * because journal recovery will change the filesystem under us. */ if (ctx->fs->super->s_kbytes_written && ctx->fs->io->manager->get_stats) ctx->fs->io->manager->get_stats(ctx->fs->io, &stats); if (stats && stats->bytes_written) kbytes_written = stats->bytes_written >> 10; ext2fs_mmp_stop(ctx->fs); ext2fs_free(ctx->fs); retval = ext2fs_open(ctx->filesystem_name, EXT2_FLAG_RW, ctx->superblock, blocksize, io_ptr, &ctx->fs); if (retval) { com_err(ctx->program_name, retval, _("while trying to re-open %s"), ctx->device_name); fatal_error(ctx, 0); } ctx->fs->priv_data = ctx; ctx->fs->now = ctx->now; ctx->fs->flags |= EXT2_FLAG_MASTER_SB_ONLY; ctx->fs->super->s_kbytes_written += kbytes_written; /* Set the superblock flags */ e2fsck_clear_recover(ctx, recover_retval); /* * Do one last sanity check, and propagate journal->s_errno to * the EXT2_ERROR_FS flag in the fs superblock if needed. */ retval = e2fsck_check_ext3_journal(ctx); return retval ? retval : recover_retval; }
errcode_t ext2fs_run_ext3_journal(ext2_filsys *fsp) { ext2_filsys fs = *fsp; io_manager io_ptr = fs->io->manager; errcode_t retval, recover_retval; io_stats stats = 0; unsigned long long kbytes_written = 0; char *fsname; int fsflags; int fsblocksize; if (!(fs->flags & EXT2_FLAG_RW)) return EXT2_ET_FILE_RO; if (fs->flags & EXT2_FLAG_DIRTY) ext2fs_flush(fs); /* Force out any modifications */ recover_retval = recover_ext3_journal(fs); /* * Reload the filesystem context to get up-to-date data from disk * because journal recovery will change the filesystem under us. */ if (fs->super->s_kbytes_written && fs->io->manager->get_stats) fs->io->manager->get_stats(fs->io, &stats); if (stats && stats->bytes_written) kbytes_written = stats->bytes_written >> 10; ext2fs_mmp_stop(fs); fsname = strdup(fs->device_name); fsflags = fs->flags; fsblocksize = fs->blocksize; ext2fs_free(fs); retval = ext2fs_open(fsname, fsflags, 0, fsblocksize, io_ptr, fsp); free(fsname); if (retval) return retval; fs = *fsp; fs->flags |= EXT2_FLAG_MASTER_SB_ONLY; fs->super->s_kbytes_written += kbytes_written; /* Set the superblock flags */ ext2fs_clear_recover(fs, recover_retval != 0); /* * Do one last sanity check, and propagate journal->s_errno to * the EXT2_ERROR_FS flag in the fs superblock if needed. */ retval = ext2fs_check_ext3_journal(fs); return retval ? retval : recover_retval; }
int main (int argc, char *argv[]) { errcode_t retval = 0; int exit_value = 0; int i; ext2_filsys fs; ext2_inode_scan scan; ext2_ino_t ino; struct ext2_inode inode; printf(_("size of inode=%d\n"), sizeof(inode)); device_name = "/dev/hda3"; init_resource_track(&global_rtrack); retval = ext2fs_open(device_name, 0, 0, 0, unix_io_manager, &fs); if (retval) { com_err(argv[0], retval, _("while trying to open %s"), device_name); exit(1); } retval = ext2fs_open_inode_scan(fs, 0, &scan); if (retval) { com_err(argv[0], retval, _("while opening inode scan")); exit(1); } retval = ext2fs_get_next_inode(scan, &ino, &inode); if (retval) { com_err(argv[0], retval, _("while starting inode scan")); exit(1); } while (ino) { if (!inode.i_links_count) goto next; printf("%lu\n", inode.i_blocks); next: retval = ext2fs_get_next_inode(scan, &ino, &inode); if (retval) { com_err(argv[0], retval, _("while doing inode scan")); exit(1); } } ext2fs_close(fs); print_resource_track(&global_rtrack); return exit_value; }
static int open_filesystem(char *device) { int retval; io_manager io_ptr = unix_io_manager; retval = ext2fs_open(device, 0, 0, 0, io_ptr, ¤t_fs); if (retval) { fprintf(stderr, "Error while opening filesystem: %d\n", retval); return retval; } return 0; }
int main (int argc, char *argv[]) { char* prgname = "iscan"; errcode_t retval = 0; int exit_value = FSCK_OK; ext2_filsys fs; ext2_ino_t ino; __u32 num_inodes = 0; struct ext2_inode inode; ext2_inode_scan scan; program_name = prgname; init_resource_track(&global_rtrack); PRS(argc, argv); retval = ext2fs_open(device_name, 0, 0, 0, unix_io_manager, &fs); if (retval) { com_err(program_name, retval, _("while trying to open %s"), device_name); exit(1); } ehandler_init(fs->io); retval = ext2fs_open_inode_scan(fs, inode_buffer_blocks, &scan); if (retval) { com_err(program_name, retval, _("while opening inode scan")); exit(1); } while (1) { retval = ext2fs_get_next_inode(scan, &ino, &inode); if (retval) { com_err(program_name, retval, _("while getting next inode")); exit(1); } if (ino == 0) break; num_inodes++; } print_resource_track(NULL, &global_rtrack); printf(_("%u inodes scanned.\n"), num_inodes); exit(0); }
const char *ext2_uuid(char *device) { errcode_t e2fserr; ext2_filsys fs; const char *uuid; e2fserr = ext2fs_open(device, 0, 0, 0, unix_io_manager, &fs); if (e2fserr) { uuid = "<none>"; } else { uuid = uuid2str(fs->super->s_uuid); e2fserr = ext2fs_close(fs); } return uuid; }
int main(int argc, char **argv) { ext2_filsys fs; ext2fs_generic_bitmap bitmap; size_t size; ext2fs_open(argv[1], 0, 0, 0, unix_io_manager, &fs); ext2fs_read_bitmaps(fs); ext2fs_get_mem(sizeof(struct ext2fs_struct_generic_bitmap), &bitmap); memcpy(bitmap, fs->block_map, sizeof(struct ext2fs_struct_generic_bitmap)); size = (size_t) (((bitmap->real_end - bitmap->start) / 8) + 1); printf("sBlock: %u\n", fs->blocksize); printf("sBitmap: %u\n", bitmap->real_end - bitmap->start + 1); printf("bitmap: "); fwrite(bitmap->bitmap, 1, size, stdout); ext2fs_close(fs); return 0; }
int extfs_test(char *partition, int extfstype) // returns true if it's that sort of filesystem { blk_t use_superblock=0; int use_blocksize=0; int extfstypedetected; ext2_filsys fs; if (ext2fs_open(partition, EXT2_FLAG_JOURNAL_DEV_OK | EXT2_FLAG_SOFTSUPP_FEATURES, use_superblock, use_blocksize, unix_io_manager, &fs)!=0) return false; extfstypedetected=extfs_get_fstype_from_compat_flags((u64)fs->super->s_feature_compat, (u64)fs->super->s_feature_incompat, (u64)fs->super->s_feature_ro_compat); msgprintf(MSG_DEBUG1, "the filesystem type determined by the extfs features is [%s]\n", format_fstype(extfstypedetected)); ext2fs_close(fs); // if detected is what is tested, say yes return (extfstypedetected==extfstype); }
int e2fsck_run_ext3_journal(e2fsck_t ctx) { io_manager io_ptr = ctx->fs->io->manager; int blocksize = ctx->fs->blocksize; errcode_t retval, recover_retval; printf(_("%s: recovering journal\n"), ctx->device_name); if (ctx->options & E2F_OPT_READONLY) { printf(_("%s: won't do journal recovery while read-only\n"), ctx->device_name); return EXT2_ET_FILE_RO; } if (ctx->fs->flags & EXT2_FLAG_DIRTY) ext2fs_flush(ctx->fs); /* Force out any modifications */ recover_retval = recover_ext3_journal(ctx); /* * Reload the filesystem context to get up-to-date data from disk * because journal recovery will change the filesystem under us. */ ext2fs_close(ctx->fs); retval = ext2fs_open(ctx->filesystem_name, EXT2_FLAG_RW, ctx->superblock, blocksize, io_ptr, &ctx->fs); if (retval) { com_err(ctx->program_name, retval, _("while trying to re-open %s"), ctx->device_name); fatal_error(ctx, 0); } ctx->fs->priv_data = ctx; ctx->fs->now = ctx->now; ctx->fs->flags |= EXT2_FLAG_MASTER_SB_ONLY; /* Set the superblock flags */ e2fsck_clear_recover(ctx, recover_retval); return recover_retval; }
/********************************************************************** Function :check_ext2_usb Descriptor : Input : part: partition Output : none return : 0: success 1: not ext2 2: ext2,but lost file Notice : **********************************************************************/ int check_ext2_usb(int part) { int nfile; char *filename_kernel = "vmlinux.ub"; int dev=0; block_dev_desc_t *dev_desc=NULL; int part_length; dev_desc = get_dev("usb",0); //first partition if (dev_desc == NULL) { printf ("[error]: Block dev not supported\n"); return(1); } part_length = ext2fs_set_blk_dev(dev_desc, part); if (part_length == 0) { ext2fs_close(); return(1); } if (!ext2fs_mount(part_length)) //if ext2 type { ext2fs_close(); return(1); } if (ext2fs_open(filename_kernel) < 0) { printf("[error]:Kernel not found %s ...\n", filename_kernel); ext2fs_close(); return(2); } ext2fs_close(); return(0); }
static BT_HANDLE ext2_open(BT_HANDLE hMount, const BT_i8 *szpPath, BT_u32 ulModeFlags, BT_ERROR *pError) { if(!hMount) { if(pError) *pError = BT_ERR_GENERIC; goto err_out; } BT_EXT2_FILE *pFile = (BT_EXT2_FILE *) BT_CreateHandle(&oFileHandleInterface, sizeof(BT_EXT2_FILE), pError); if(!pFile) { *pError = BT_ERR_NO_MEMORY; goto err_out; } pFile->pMount = (BT_EXT2_MOUNT *)hMount; if(ext2fs_open((char *)szpPath) < 0) { if(pError) *pError = BT_ERR_GENERIC; goto err_free_out; } return (BT_HANDLE) pFile; err_free_out: BT_DestroyHandle((BT_HANDLE)pFile); err_out: return NULL; }
/* function taken from anaconda/isys.c */ static PyObject * _sysutils_e2fslabel(PyObject * s, PyObject * args) { char * device; ext2_filsys fsys; char buf[50]; int rc; if (!PyArg_ParseTuple(args, "s", &device)) return NULL; rc = ext2fs_open(device, EXT2_FLAG_FORCE, 0, 0, unix_io_manager, &fsys); if (rc) { Py_INCREF(Py_None); return Py_None; } memset(buf, 0, sizeof(buf)); strncpy(buf, fsys->super->s_volume_name, sizeof(fsys->super->s_volume_name)); ext2fs_close(fsys); return Py_BuildValue("s", buf); }
dir_partition_t dir_partition_ext2_init(disk_t *disk_car, const partition_t *partition, dir_data_t *dir_data, const int verbose) { #if defined(HAVE_LIBEXT2FS) struct ext2_dir_struct *ls=(struct ext2_dir_struct *)MALLOC(sizeof(*ls)); io_channel ioch; my_data_t *my_data; ls->dir_list=NULL; /* ls->flags = DIRENT_FLAG_INCLUDE_EMPTY; */ ls->flags = DIRENT_FLAG_INCLUDE_REMOVED; ls->dir_data=dir_data; my_data=(my_data_t *)MALLOC(sizeof(*my_data)); my_data->partition=partition; my_data->disk_car=disk_car; ioch=alloc_io_channel(disk_car,my_data); shared_ioch=&ioch; /* An alternate superblock may be used if the calling function has set an IO redirection */ if(ext2fs_open ("/dev/testdisk", 0, 0, 0, &my_struct_manager, &ls->current_fs)!=0) { // free(my_data); free(ls); return DIR_PART_EIO; } strncpy(dir_data->current_directory,"/",sizeof(dir_data->current_directory)); dir_data->current_inode=EXT2_ROOT_INO; dir_data->param=FLAG_LIST_DELETED; dir_data->verbose=verbose; dir_data->capabilities=CAPA_LIST_DELETED; dir_data->get_dir=ext2_dir; dir_data->copy_file=ext2_copy; dir_data->close=&dir_partition_ext2_close; dir_data->local_dir=NULL; dir_data->private_dir_data=ls; return DIR_PART_OK; #else return DIR_PART_ENOSYS; #endif }
void make_journal_device(char *journal_device, ext2_filsys fs, int quiet, int force) { errcode_t retval; ext2_filsys jfs; io_manager io_ptr; check_plausibility(journal_device, force); check_mount(journal_device, force, "journal"); io_ptr = unix_io_manager; retval = ext2fs_open(journal_device, EXT2_FLAG_RW| EXT2_FLAG_JOURNAL_DEV_OK, 0, fs->blocksize, io_ptr, &jfs); if (retval) bb_error_msg_and_die("can't journal device %s", journal_device); if (!quiet) printf("Adding journal to device %s: ", journal_device); fflush(stdout); retval = ext2fs_add_journal_device(fs, jfs); if (retval) bb_error_msg_and_die("\nFailed to add journal to device %s", journal_device); if (!quiet) puts("done"); ext2fs_close(jfs); }
long open_filesystem(char *name, ext2_filsys *fs, ext2_ino_t *root, int rw_mode) { int retval; int closeval; if ((retval = ext2fs_open(name, (rw_mode) ? EXT2_FLAG_RW : 0, 0, 0, unix_io_manager, fs))) { fprintf(stderr, "%s\n", error_message(retval)); *fs = NULL; return retval; } if ((retval = ext2fs_read_inode_bitmap(*fs))) { fprintf(stderr, "%s\n", error_message(retval)); if ((closeval = ext2fs_close(*fs))) fputs(error_message(closeval), stderr); *fs = NULL; return retval; } if ((retval = ext2fs_read_block_bitmap(*fs))) { fprintf(stderr, "%s\n", error_message(retval)); if ((closeval = ext2fs_close(*fs))) fputs(error_message(closeval), stderr); *fs = NULL; return retval; } *root = EXT2_ROOT_INO; return(0); }
/* * Remove an external journal from the filesystem */ static void remove_journal_device(ext2_filsys fs) { char *journal_path; ext2_filsys jfs; char buf[1024]; journal_superblock_t *jsb; int i, nr_users; errcode_t retval; int commit_remove_journal = 0; if (f_flag) commit_remove_journal = 1; /* force removal even if error */ uuid_unparse(fs->super->s_journal_uuid, buf); journal_path = get_spec_by_uuid(buf); if (!journal_path) { journal_path = ext2fs_find_block_device(fs->super->s_journal_dev); if (!journal_path) return; } retval = ext2fs_open(journal_path, EXT2_FLAG_RW| EXT2_FLAG_JOURNAL_DEV_OK, 0, fs->blocksize, unix_io_manager, &jfs); if (retval) { com_err(program_name, retval, _("while trying to open external journal")); goto no_valid_journal; } if (!(jfs->super->s_feature_incompat & EXT3_FEATURE_INCOMPAT_JOURNAL_DEV)) { fprintf(stderr, _("%s is not a journal device.\n"), journal_path); goto no_valid_journal; } /* Get the journal superblock */ if ((retval = io_channel_read_blk(jfs->io, 1, -1024, buf))) { com_err(program_name, retval, _("while reading journal superblock")); goto no_valid_journal; } jsb = (journal_superblock_t *) buf; if ((jsb->s_header.h_magic != (unsigned) ntohl(JFS_MAGIC_NUMBER)) || (jsb->s_header.h_blocktype != (unsigned) ntohl(JFS_SUPERBLOCK_V2))) { fprintf(stderr, _("Journal superblock not found!\n")); goto no_valid_journal; } /* Find the filesystem UUID */ nr_users = ntohl(jsb->s_nr_users); for (i=0; i < nr_users; i++) { if (memcmp(fs->super->s_uuid, &jsb->s_users[i*16], 16) == 0) break; } if (i >= nr_users) { fprintf(stderr, _("Filesystem's UUID not found on journal device.\n")); commit_remove_journal = 1; goto no_valid_journal; } nr_users--; for (i=0; i < nr_users; i++) memcpy(&jsb->s_users[i*16], &jsb->s_users[(i+1)*16], 16); jsb->s_nr_users = htonl(nr_users); /* Write back the journal superblock */ if ((retval = io_channel_write_blk(jfs->io, 1, -1024, buf))) { com_err(program_name, retval, "while writing journal superblock."); goto no_valid_journal; } commit_remove_journal = 1; no_valid_journal: if (commit_remove_journal == 0) { fprintf(stderr, _("Journal NOT removed\n")); exit(1); } fs->super->s_journal_dev = 0; memset(fs->super->s_journal_uuid, 0, sizeof(fs->super->s_journal_uuid)); ext2fs_mark_super_dirty(fs); printf(_("Journal removed\n")); free(journal_path); }
int main (int argc, char ** argv) { errcode_t retval; ext2_filsys fs; int print_badblocks = 0; blk64_t use_superblock = 0; int use_blocksize = 0; int image_dump = 0; int force = 0; int flags; int header_only = 0; int c; #ifdef ENABLE_NLS setlocale(LC_MESSAGES, ""); setlocale(LC_CTYPE, ""); bindtextdomain(NLS_CAT_NAME, LOCALEDIR); textdomain(NLS_CAT_NAME); set_com_err_gettext(gettext); #endif add_error_table(&et_ext2_error_table); fprintf (stderr, "dumpe2fs %s (%s)\n", E2FSPROGS_VERSION, E2FSPROGS_DATE); if (argc && *argv) program_name = *argv; while ((c = getopt (argc, argv, "bfhixVo:")) != EOF) { switch (c) { case 'b': print_badblocks++; break; case 'f': force++; break; case 'h': header_only++; break; case 'i': image_dump++; break; case 'o': parse_extended_opts(optarg, &use_superblock, &use_blocksize); break; case 'V': /* Print version number and exit */ fprintf(stderr, _("\tUsing %s\n"), error_message(EXT2_ET_BASE)); exit(0); case 'x': hex_format++; break; default: usage(); } } if (optind > argc - 1) usage(); device_name = argv[optind++]; flags = EXT2_FLAG_JOURNAL_DEV_OK | EXT2_FLAG_SOFTSUPP_FEATURES | EXT2_FLAG_64BITS; if (force) flags |= EXT2_FLAG_FORCE; if (image_dump) flags |= EXT2_FLAG_IMAGE_FILE; if (use_superblock && !use_blocksize) { for (use_blocksize = EXT2_MIN_BLOCK_SIZE; use_blocksize <= EXT2_MAX_BLOCK_SIZE; use_blocksize *= 2) { retval = ext2fs_open (device_name, flags, use_superblock, use_blocksize, unix_io_manager, &fs); if (!retval) break; } } else retval = ext2fs_open (device_name, flags, use_superblock, use_blocksize, unix_io_manager, &fs); if (retval) { com_err (program_name, retval, _("while trying to open %s"), device_name); printf("%s", _("Couldn't find valid filesystem superblock.\n")); exit (1); } fs->default_bitmap_type = EXT2FS_BMAP64_RBTREE; if (fs->super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT) blocks64 = 1; if (print_badblocks) { list_bad_blocks(fs, 1); } else { list_super (fs->super); if (fs->super->s_feature_incompat & EXT3_FEATURE_INCOMPAT_JOURNAL_DEV) { print_journal_information(fs); ext2fs_close(fs); exit(0); } if ((fs->super->s_feature_compat & EXT3_FEATURE_COMPAT_HAS_JOURNAL) && (fs->super->s_journal_inum != 0)) print_inline_journal_information(fs); list_bad_blocks(fs, 0); if (header_only) { ext2fs_close (fs); exit (0); } retval = ext2fs_read_bitmaps (fs); list_desc (fs); if (retval) { printf(_("\n%s: %s: error reading bitmaps: %s\n"), program_name, device_name, error_message(retval)); } } ext2fs_close (fs); remove_error_table(&et_ext2_error_table); exit (0); }
static void PRS(int argc, char *argv[]) { int b, c; int size; char *tmp, *tmp2; int blocksize = 0; int inode_ratio = 0; int inode_size = 0; double reserved_ratio = 5.0; int sector_size = 0; int show_version_only = 0; ext2_ino_t num_inodes = 0; errcode_t retval; char * oldpath = getenv("PATH"); char * extended_opts = 0; const char * fs_type = 0; blk_t dev_size; #ifdef __linux__ struct utsname ut; #endif long sysval; int s_opt = -1, r_opt = -1; char *fs_features = 0; int use_bsize; /* Update our PATH to include /sbin */ if (oldpath) { char *newpath; newpath = malloc(sizeof (PATH_SET) + 1 + strlen (oldpath)); strcpy (newpath, PATH_SET); strcat (newpath, ":"); strcat (newpath, oldpath); putenv (newpath); } else putenv (PATH_SET); tmp = getenv("MKE2FS_SYNC"); if (tmp) sync_kludge = atoi(tmp); /* Determine the system page size if possible */ #ifdef HAVE_SYSCONF #if (!defined(_SC_PAGESIZE) && defined(_SC_PAGE_SIZE)) #define _SC_PAGESIZE _SC_PAGE_SIZE #endif #ifdef _SC_PAGESIZE sysval = sysconf(_SC_PAGESIZE); if (sysval > 0) sys_page_size = sysval; #endif /* _SC_PAGESIZE */ #endif /* HAVE_SYSCONF */ if ((tmp = getenv("MKE2FS_CONFIG")) != NULL) config_fn[0] = tmp; profile_set_syntax_err_cb(syntax_err_report); profile_init(config_fn, &profile); setbuf(stdout, NULL); setbuf(stderr, NULL); initialize_ext2_error_table(); memset(&fs_param, 0, sizeof(struct ext2_super_block)); fs_param.s_rev_level = 1; /* Create revision 1 filesystems now */ #ifdef __linux__ if (uname(&ut)) { perror("uname"); exit(1); } linux_version_code = parse_version_number(ut.release); if (linux_version_code && linux_version_code < (2*65536 + 2*256)) fs_param.s_rev_level = 0; #endif if (argc && *argv) { program_name = get_progname(*argv); /* If called as mkfs.ext3, create a journal inode */ if (!strcmp(program_name, "mkfs.ext3")) journal_size = -1; } while ((c = getopt (argc, argv, "b:cf:g:i:jl:m:no:qr:s:tvE:FI:J:L:M:N:O:R:ST:V")) != EOF) { switch (c) { case 'b': blocksize = strtol(optarg, &tmp, 0); b = (blocksize > 0) ? blocksize : -blocksize; if (b < EXT2_MIN_BLOCK_SIZE || b > EXT2_MAX_BLOCK_SIZE || *tmp) { com_err(program_name, 0, _("invalid block size - %s"), optarg); exit(1); } if (blocksize > 4096) fprintf(stderr, _("Warning: blocksize %d not " "usable on most systems.\n"), blocksize); if (blocksize > 0) fs_param.s_log_block_size = int_log2(blocksize >> EXT2_MIN_BLOCK_LOG_SIZE); break; case 'c': /* Check for bad blocks */ case 't': /* deprecated */ cflag++; break; case 'f': size = strtoul(optarg, &tmp, 0); if (size < EXT2_MIN_BLOCK_SIZE || size > EXT2_MAX_BLOCK_SIZE || *tmp) { com_err(program_name, 0, _("invalid fragment size - %s"), optarg); exit(1); } fs_param.s_log_frag_size = int_log2(size >> EXT2_MIN_BLOCK_LOG_SIZE); fprintf(stderr, _("Warning: fragments not supported. " "Ignoring -f option\n")); break; case 'g': fs_param.s_blocks_per_group = strtoul(optarg, &tmp, 0); if (*tmp) { com_err(program_name, 0, _("Illegal number for blocks per group")); exit(1); } if ((fs_param.s_blocks_per_group % 8) != 0) { com_err(program_name, 0, _("blocks per group must be multiple of 8")); exit(1); } break; case 'i': inode_ratio = strtoul(optarg, &tmp, 0); if (inode_ratio < EXT2_MIN_BLOCK_SIZE || inode_ratio > EXT2_MAX_BLOCK_SIZE * 1024 || *tmp) { com_err(program_name, 0, _("invalid inode ratio %s (min %d/max %d)"), optarg, EXT2_MIN_BLOCK_SIZE, EXT2_MAX_BLOCK_SIZE); exit(1); } break; case 'J': parse_journal_opts(optarg); break; case 'j': if (!journal_size) journal_size = -1; break; case 'l': bad_blocks_filename = malloc(strlen(optarg)+1); if (!bad_blocks_filename) { com_err(program_name, ENOMEM, _("in malloc for bad_blocks_filename")); exit(1); } strcpy(bad_blocks_filename, optarg); break; case 'm': reserved_ratio = strtod(optarg, &tmp); if (reserved_ratio > 50 || *tmp) { com_err(program_name, 0, _("invalid reserved blocks percent - %s"), optarg); exit(1); } break; case 'n': noaction++; break; case 'o': creator_os = optarg; break; case 'q': quiet = 1; break; case 'r': r_opt = strtoul(optarg, &tmp, 0); if (*tmp) { com_err(program_name, 0, _("bad revision level - %s"), optarg); exit(1); } fs_param.s_rev_level = r_opt; break; case 's': /* deprecated */ s_opt = atoi(optarg); break; #ifdef EXT2_DYNAMIC_REV case 'I': inode_size = strtoul(optarg, &tmp, 0); if (*tmp) { com_err(program_name, 0, _("invalid inode size - %s"), optarg); exit(1); } break; #endif case 'v': verbose = 1; break; case 'F': force = 1; break; case 'L': volume_label = optarg; break; case 'M': mount_dir = optarg; break; case 'N': num_inodes = strtoul(optarg, &tmp, 0); if (*tmp) { com_err(program_name, 0, _("bad num inodes - %s"), optarg); exit(1); } break; case 'O': fs_features = optarg; break; case 'E': case 'R': extended_opts = optarg; break; case 'S': super_only = 1; break; case 'T': fs_type = optarg; break; case 'V': /* Print version number and exit */ show_version_only++; break; default: usage(); } } if ((optind == argc) && !show_version_only) usage(); device_name = argv[optind++]; if (!quiet || show_version_only) fprintf (stderr, "mke2fs %s (%s)\n", E2FSPROGS_VERSION, E2FSPROGS_DATE); if (show_version_only) { fprintf(stderr, _("\tUsing %s\n"), error_message(EXT2_ET_BASE)); exit(0); } /* * If there's no blocksize specified and there is a journal * device, use it to figure out the blocksize */ if (blocksize <= 0 && journal_device) { ext2_filsys jfs; io_manager io_ptr; #ifdef CONFIG_TESTIO_DEBUG io_ptr = test_io_manager; test_io_backing_manager = unix_io_manager; #else io_ptr = unix_io_manager; #endif retval = ext2fs_open(journal_device, EXT2_FLAG_JOURNAL_DEV_OK, 0, 0, io_ptr, &jfs); if (retval) { com_err(program_name, retval, _("while trying to open journal device %s\n"), journal_device); exit(1); } if ((blocksize < 0) && (jfs->blocksize < (unsigned) (-blocksize))) { com_err(program_name, 0, _("Journal dev blocksize (%d) smaller than " "minimum blocksize %d\n"), jfs->blocksize, -blocksize); exit(1); } blocksize = jfs->blocksize; fs_param.s_log_block_size = int_log2(blocksize >> EXT2_MIN_BLOCK_LOG_SIZE); ext2fs_close(jfs); }
Ext3FS::Ext3FS(QString const &dev) { ext2fs_open(QFile::encodeName(dev), EXT2_FLAG_RW, 0, 0, unix_io_manager, &fs); sb=fs->super; fs->flags |= EXT2_FLAG_SUPER_ONLY; }
static void open_filesystem(char *device, int open_flags, blk_t superblock, blk_t blocksize, int catastrophic, char *data_filename) { int retval; io_channel data_io = 0; if (superblock != 0 && blocksize == 0) { com_err(device, 0, "if you specify the superblock, you must also specify the block size"); current_fs = NULL; return; } if (data_filename) { if ((open_flags & EXT2_FLAG_IMAGE_FILE) == 0) { com_err(device, 0, "The -d option is only valid when reading an e2image file"); current_fs = NULL; return; } retval = unix_io_manager->open(data_filename, 0, &data_io); if (retval) { com_err(data_filename, 0, "while opening data source"); current_fs = NULL; return; } } if (catastrophic && (open_flags & EXT2_FLAG_RW)) { com_err(device, 0, "opening read-only because of catastrophic mode"); open_flags &= ~EXT2_FLAG_RW; } retval = ext2fs_open(device, open_flags, superblock, blocksize, unix_io_manager, ¤t_fs); if (retval) { com_err(device, retval, "while opening filesystem"); current_fs = NULL; return; } if (catastrophic) com_err(device, 0, "catastrophic mode - not reading inode or group bitmaps"); else { retval = ext2fs_read_inode_bitmap(current_fs); if (retval) { com_err(device, retval, "while reading inode bitmap"); goto errout; } retval = ext2fs_read_block_bitmap(current_fs); if (retval) { com_err(device, retval, "while reading block bitmap"); goto errout; } } if (data_io) { retval = ext2fs_set_data_io(current_fs, data_io); if (retval) { com_err(device, retval, "while setting data source"); goto errout; } } root = cwd = EXT2_ROOT_INO; return; errout: retval = ext2fs_close(current_fs); if (retval) com_err(device, retval, "while trying to close filesystem"); current_fs = NULL; }
/** * \ingroup fslib * Tries to process data in a disk image at a given offset as a file system. * Returns a structure that can be used for analysis and reporting. * * @param a_img_info Disk image to analyze * @param a_offset Byte offset to start analyzing from * @param a_ftype Type of file system (or autodetect) * * @return NULL on error */ TSK_FS_INFO * tsk_fs_open_img(TSK_IMG_INFO * a_img_info, TSK_OFF_T a_offset, TSK_FS_TYPE_ENUM a_ftype) { if (a_img_info == NULL) { tsk_error_reset(); tsk_errno = TSK_ERR_FS_ARG; snprintf(tsk_errstr, TSK_ERRSTR_L, "tsk_fs_open_img: Null image handle"); return NULL; } /* We will try different file systems ... * We need to try all of them in case more than one matches */ if (a_ftype == TSK_FS_TYPE_DETECT) { TSK_FS_INFO *fs_info, *fs_set = NULL; char *set = NULL; if (tsk_verbose) tsk_fprintf(stderr, "fsopen: Auto detection mode at offset %" PRIuOFF "\n", a_offset); if ((fs_info = ntfs_open(a_img_info, a_offset, TSK_FS_TYPE_NTFS_DETECT, 1)) != NULL) { set = "NTFS"; fs_set = fs_info; } else { tsk_error_reset(); } if ((fs_info = fatfs_open(a_img_info, a_offset, TSK_FS_TYPE_FAT_DETECT, 1)) != NULL) { if (set == NULL) { set = "FAT"; fs_set = fs_info; } else { fs_set->close(fs_set); fs_info->close(fs_info); tsk_error_reset(); tsk_errno = TSK_ERR_FS_UNKTYPE; snprintf(tsk_errstr, TSK_ERRSTR_L, "FAT or %s", set); return NULL; } } else { tsk_error_reset(); } if ((fs_info = ext2fs_open(a_img_info, a_offset, TSK_FS_TYPE_EXT_DETECT, 1)) != NULL) { if (set == NULL) { set = "EXT2/3"; fs_set = fs_info; } else { fs_set->close(fs_set); fs_info->close(fs_info); tsk_error_reset(); tsk_errno = TSK_ERR_FS_UNKTYPE; snprintf(tsk_errstr, TSK_ERRSTR_L, "EXT2/3 or %s", set); return NULL; } } else { tsk_error_reset(); } if ((fs_info = ffs_open(a_img_info, a_offset, TSK_FS_TYPE_FFS_DETECT)) != NULL) { if (set == NULL) { set = "UFS"; fs_set = fs_info; } else { fs_set->close(fs_set); fs_info->close(fs_info); tsk_error_reset(); tsk_errno = TSK_ERR_FS_UNKTYPE; snprintf(tsk_errstr, TSK_ERRSTR_L, "UFS or %s", set); return NULL; } } else { tsk_error_reset(); } #if TSK_USE_HFS if ((fs_info = hfs_open(a_img_info, a_offset, TSK_FS_TYPE_HFS_DETECT, 1)) != NULL) { if (set == NULL) { set = "HFS"; fs_set = fs_info; } else { fs_set->close(fs_set); fs_info->close(fs_info); tsk_error_reset(); tsk_errno = TSK_ERR_FS_UNKTYPE; snprintf(tsk_errstr, TSK_ERRSTR_L, "HFS or %s", set); return NULL; } } else { tsk_error_reset(); } #endif if ((fs_info = iso9660_open(a_img_info, a_offset, TSK_FS_TYPE_ISO9660_DETECT, 1)) != NULL) { if (set != NULL) { fs_set->close(fs_set); fs_info->close(fs_info); tsk_error_reset(); tsk_errno = TSK_ERR_FS_UNKTYPE; snprintf(tsk_errstr, TSK_ERRSTR_L, "ISO9660 or %s", set); return NULL; } fs_set = fs_info; } else { tsk_error_reset(); } if (fs_set == NULL) { tsk_error_reset(); tsk_errno = TSK_ERR_FS_UNKTYPE; tsk_errstr[0] = '\0'; tsk_errstr2[0] = '\0'; return NULL; } return fs_set; } else { if (TSK_FS_TYPE_ISNTFS(a_ftype)) return ntfs_open(a_img_info, a_offset, a_ftype, 0); else if (TSK_FS_TYPE_ISFAT(a_ftype)) return fatfs_open(a_img_info, a_offset, a_ftype, 0); else if (TSK_FS_TYPE_ISFFS(a_ftype)) return ffs_open(a_img_info, a_offset, a_ftype); else if (TSK_FS_TYPE_ISEXT(a_ftype)) return ext2fs_open(a_img_info, a_offset, a_ftype, 0); else if (TSK_FS_TYPE_ISHFS(a_ftype)) return hfs_open(a_img_info, a_offset, a_ftype, 0); else if (TSK_FS_TYPE_ISISO9660(a_ftype)) return iso9660_open(a_img_info, a_offset, a_ftype, 0); else if (TSK_FS_TYPE_ISRAW(a_ftype)) return rawfs_open(a_img_info, a_offset); else if (TSK_FS_TYPE_ISSWAP(a_ftype)) return swapfs_open(a_img_info, a_offset); else { tsk_error_reset(); tsk_errno = TSK_ERR_FS_UNSUPTYPE; snprintf(tsk_errstr, TSK_ERRSTR_L, "%X", (int) a_ftype); return NULL; } } }
TSK_FS_INFO * tsk_fs_open(TSK_IMG_INFO * img_info, TSK_OFF_T offset, const TSK_TCHAR * type) { /* We will try different file systems ... * We need to try all of them in case more than one matches */ if (type == NULL) { TSK_FS_INFO *fs_info, *fs_set = NULL; char *set = NULL; if (tsk_verbose) tsk_fprintf(stderr, "fsopen: Auto detection mode at offset %" PRIuOFF "\n", offset); if ((fs_info = ntfs_open(img_info, offset, TSK_FS_INFO_TYPE_NTFS_AUTO, 1)) != NULL) { set = "NTFS"; fs_set = fs_info; } else { tsk_error_reset(); } if ((fs_info = fatfs_open(img_info, offset, TSK_FS_INFO_TYPE_FAT_AUTO, 1)) != NULL) { if (set == NULL) { set = "FAT"; fs_set = fs_info; } else { fs_set->close(fs_set); fs_info->close(fs_info); tsk_error_reset(); tsk_errno = TSK_ERR_FS_UNKTYPE; snprintf(tsk_errstr, TSK_ERRSTR_L, "FAT or %s", set); return NULL; } } else { tsk_error_reset(); } if ((fs_info = ext2fs_open(img_info, offset, TSK_FS_INFO_TYPE_EXT_AUTO, 1)) != NULL) { if (set == NULL) { set = "EXT2/3"; fs_set = fs_info; } else { fs_set->close(fs_set); fs_info->close(fs_info); tsk_error_reset(); tsk_errno = TSK_ERR_FS_UNKTYPE; snprintf(tsk_errstr, TSK_ERRSTR_L, "EXT2/3 or %s", set); return NULL; } } else { tsk_error_reset(); } if ((fs_info = ffs_open(img_info, offset, TSK_FS_INFO_TYPE_FFS_AUTO)) != NULL) { if (set == NULL) { set = "UFS"; fs_set = fs_info; } else { fs_set->close(fs_set); fs_info->close(fs_info); tsk_error_reset(); tsk_errno = TSK_ERR_FS_UNKTYPE; snprintf(tsk_errstr, TSK_ERRSTR_L, "UFS or %s", set); return NULL; } } else { tsk_error_reset(); } #if TSK_USE_HFS if ((fs_info = hfs_open(img_info, offset, TSK_FS_INFO_TYPE_HFS, 1)) != NULL) { if (set == NULL) { set = "HFS"; fs_set = fs_info; } else { fs_set->close(fs_set); fs_info->close(fs_info); tsk_error_reset(); tsk_errno = TSK_ERR_FS_UNKTYPE; snprintf(tsk_errstr, TSK_ERRSTR_L, "HFS or %s", set); return NULL; } } else { tsk_error_reset(); } #endif if ((fs_info = iso9660_open(img_info, offset, TSK_FS_INFO_TYPE_ISO9660, 1)) != NULL) { if (set != NULL) { fs_set->close(fs_set); fs_info->close(fs_info); tsk_error_reset(); tsk_errno = TSK_ERR_FS_UNKTYPE; snprintf(tsk_errstr, TSK_ERRSTR_L, "ISO9660 or %s", set); return NULL; } fs_set = fs_info; } else { tsk_error_reset(); } if (fs_set == NULL) { tsk_error_reset(); tsk_errno = TSK_ERR_FS_UNKTYPE; tsk_errstr[0] = '\0'; tsk_errstr2[0] = '\0'; return NULL; } return fs_set; } else { uint8_t ftype; ftype = tsk_fs_parse_type(type); switch (ftype & TSK_FS_INFO_TYPE_FS_MASK) { case TSK_FS_INFO_TYPE_FFS_TYPE: return ffs_open(img_info, offset, ftype); case TSK_FS_INFO_TYPE_EXT_TYPE: return ext2fs_open(img_info, offset, ftype, 0); case TSK_FS_INFO_TYPE_FAT_TYPE: return fatfs_open(img_info, offset, ftype, 0); case TSK_FS_INFO_TYPE_NTFS_TYPE: return ntfs_open(img_info, offset, ftype, 0); case TSK_FS_INFO_TYPE_ISO9660_TYPE: return iso9660_open(img_info, offset, ftype, 0); #if 0 case TSK_FS_INFO_TYPE_HFS_TYPE: return hfs_open(img_info, offset, ftype, 0); #endif case TSK_FS_INFO_TYPE_RAW_TYPE: return rawfs_open(img_info, offset); case TSK_FS_INFO_TYPE_SWAP_TYPE: return swapfs_open(img_info, offset); case TSK_FS_INFO_TYPE_UNSUPP: default: tsk_error_reset(); tsk_errno = TSK_ERR_FS_UNSUPTYPE; snprintf(tsk_errstr, TSK_ERRSTR_L, "%s", type); return NULL; } } }
/****************************************************************************** * Ext2fs boot command intepreter. Derived from diskboot */ int do_ext2load (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { char *filename = NULL; char *ep; int dev, part = 1; ulong addr = 0, part_length, filelen; disk_partition_t info; block_dev_desc_t *dev_desc = NULL; char buf [12]; unsigned long count; char *addr_str; switch (argc) { case 3: addr_str = getenv("loadaddr"); if (addr_str != NULL) { addr = simple_strtoul (addr_str, NULL, 16); } else { addr = CONFIG_SYS_LOAD_ADDR; } filename = getenv ("bootfile"); count = 0; break; case 4: addr = simple_strtoul (argv[3], NULL, 16); filename = getenv ("bootfile"); count = 0; break; case 5: addr = simple_strtoul (argv[3], NULL, 16); filename = argv[4]; count = 0; break; case 6: addr = simple_strtoul (argv[3], NULL, 16); filename = argv[4]; count = simple_strtoul (argv[5], NULL, 16); break; default: cmd_usage(cmdtp); return(1); } if (!filename) { puts ("\n** No boot file defined **\n"); return(1); } dev = (int)simple_strtoul (argv[2], &ep, 16); dev_desc = get_dev(argv[1],dev); if (dev_desc==NULL) { printf ("\n** Block device %s %d not supported\n", argv[1], dev); return(1); } if (*ep) { if (*ep != ':') { puts ("\n** Invalid boot device, use `dev[:part]' **\n"); return(1); } part = (int)simple_strtoul(++ep, NULL, 16); } PRINTF("Using device %s%d, partition %d\n", argv[1], dev, part); if (part != 0) { if (get_partition_info (dev_desc, part, &info)) { printf ("** Bad partition %d **\n", part); return(1); } if (strncmp((char *)info.type, BOOT_PART_TYPE, sizeof(info.type)) != 0) { printf ("\n** Invalid partition type \"%.32s\"" " (expect \"" BOOT_PART_TYPE "\")\n", info.type); return(1); } PRINTF ("\nLoading from block device %s device %d, partition %d: " "Name: %.32s Type: %.32s File:%s\n", argv[1], dev, part, info.name, info.type, filename); } else { PRINTF ("\nLoading from block device %s device %d, File:%s\n", argv[1], dev, filename); } if ((part_length = ext2fs_set_blk_dev(dev_desc, part)) == 0) { printf ("** Bad partition - %s %d:%d **\n", argv[1], dev, part); ext2fs_close(); return(1); } if (!ext2fs_mount(part_length)) { printf ("** Bad ext2 partition or disk - %s %d:%d **\n", argv[1], dev, part); ext2fs_close(); return(1); } filelen = ext2fs_open(filename); if (filelen < 0) { printf("** File not found %s\n", filename); ext2fs_close(); return(1); } if ((count < filelen) && (count != 0)) { filelen = count; } if (ext2fs_read((char *)addr, filelen) != filelen) { printf("\n** Unable to read \"%s\" from %s %d:%d **\n", filename, argv[1], dev, part); ext2fs_close(); return(1); } ext2fs_close(); /* Loading ok, update default load address */ load_addr = addr; printf ("\n%ld bytes read\n", filelen); sprintf(buf, "%lX", filelen); setenv("filesize", buf); return(filelen); }