예제 #1
0
파일: oleg.c 프로젝트: carriercomm/OlegDB
struct tm *ol_sniff(ol_database *db, const char *key, size_t klen) {
    char _key[KEY_SIZE] = {'\0'};
    size_t _klen = 0;
    ol_bucket *bucket = ol_get_bucket(db, key, klen, &_key, &_klen);
    check_warn(_klen > 0, "Key length of zero not allowed.");

    if (bucket != NULL && bucket->expiration != NULL) {
        if (!_has_bucket_expired(bucket)) {
            return bucket->expiration;
        } else {
            /* It's dead, get rid of it. */
            check(ol_scoop(db, key, klen) == 0, "Could not delete a bucket!")
        }
    }

error:
    return NULL;
}
예제 #2
0
struct super_block *hpfs_read_super(struct super_block *s,
				    void *options, int silent)
{
	struct hpfs_boot_block *bootblock;
	struct hpfs_super_block *superblock;
	struct hpfs_spare_block *spareblock;
	struct hpfs_dirent *de;
	struct buffer_head *bh0, *bh1, *bh2;
	struct quad_buffer_head qbh;
	dnode_secno root_dno;
	dev_t dev;
	uid_t uid;
	gid_t gid;
	umode_t umask;
	int lowercase;
	int conv;
	int dubious;

	/*
	 * Get the mount options
	 */

	if (!parse_opts(options, &uid, &gid, &umask, &lowercase, &conv)) {
		printk("HPFS: syntax error in mount options.  Not mounted.\n");
		s->s_dev = 0;
		return 0;
	}

	/*
	 * Fill in the super block struct
	 */

	lock_super(s);
	dev = s->s_dev;
	set_blocksize(dev, 512);

	/*
	 * fetch sectors 0, 16, 17
	 */

	bootblock = map_sector(dev, 0, &bh0);
	if (!bootblock)
		goto bail;

	superblock = map_sector(dev, 16, &bh1);
	if (!superblock)
		goto bail0;

	spareblock = map_sector(dev, 17, &bh2);
	if (!spareblock)
		goto bail1;

	/*
	 * Check that this fs looks enough like a known one that we can find
	 * and read the root directory.
	 */

	if (bootblock->magic != 0xaa55
	    || superblock->magic != SB_MAGIC
	    || spareblock->magic != SP_MAGIC
	    || bootblock->sig_28h != 0x28
	    || memcmp(&bootblock->sig_hpfs, "HPFS    ", 8)
	    || little_ushort(bootblock->bytes_per_sector) != 512) {
		printk("HPFS: hpfs_read_super: Not HPFS\n");
		goto bail2;
	}

	/*
	 * Check for inconsistencies -- possibly wrong guesses here, possibly
	 * filesystem problems.
	 */

	dubious = 0;

	dubious |= check_warn(spareblock->dirty != 0,
		       "`Improperly stopped'", "flag is set", "run CHKDSK");
	dubious |= check_warn(spareblock->n_spares_used != 0,
			      "Spare blocks", "may be in use", "run CHKDSK");

	/*
	 * Above errors mean we could get wrong answers if we proceed,
	 * so don't
	 */

	if (dubious)
		goto bail2;

	dubious |= check_warn((spareblock->n_dnode_spares !=
			       spareblock->n_dnode_spares_free),
			      "Spare dnodes", "may be in use", "run CHKDSK");
	dubious |= check_warn(superblock->zero1 != 0,
			      "#1", "unknown word nonzero", "investigate");
	dubious |= check_warn(superblock->zero3 != 0,
			      "#3", "unknown word nonzero", "investigate");
	dubious |= check_warn(superblock->zero4 != 0,
			      "#4", "unknown word nonzero", "investigate");
	dubious |= check_warn(!zerop(superblock->zero5,
				     sizeof superblock->zero5),
			      "#5", "unknown word nonzero", "investigate");
	dubious |= check_warn(!zerop(superblock->zero6,
				     sizeof superblock->zero6),
			      "#6", "unknown word nonzero", "investigate");

	if (dubious)
		printk("HPFS: Proceeding, but operation may be unreliable\n");

	/*
	 * set fs read only
	 */

	s->s_flags |= MS_RDONLY;

	/*
	 * fill in standard stuff
	 */

	s->s_magic = HPFS_SUPER_MAGIC;
	s->s_blocksize = 512;
	s->s_blocksize_bits = 9;
	s->s_op = (struct super_operations *) &hpfs_sops;

	/*
	 * fill in hpfs stuff
	 */

	s->s_hpfs_root = dir_ino(superblock->root);
	s->s_hpfs_fs_size = superblock->n_sectors;
	s->s_hpfs_dirband_size = superblock->n_dir_band / 4;
	s->s_hpfs_dmap = superblock->dir_band_bitmap;
	s->s_hpfs_bitmaps = superblock->bitmaps;
	s->s_hpfs_uid = uid;
	s->s_hpfs_gid = gid;
	s->s_hpfs_mode = 0777 & ~umask;
	s->s_hpfs_n_free = -1;
	s->s_hpfs_n_free_dnodes = -1;
	s->s_hpfs_lowercase = lowercase;
	s->s_hpfs_conv = conv;

	/*
	 * done with the low blocks
	 */

	brelse(bh2);
	brelse(bh1);
	brelse(bh0);

	/*
	 * all set.  try it out.
	 */

	s->s_mounted = iget(s, s->s_hpfs_root);
	unlock_super(s);

	if (!s->s_mounted) {
		printk("HPFS: hpfs_read_super: inode get failed\n");
		s->s_dev = 0;
		return 0;
	}

	/*
	 * find the root directory's . pointer & finish filling in the inode
	 */

	root_dno = fnode_dno(dev, s->s_hpfs_root);
	if (root_dno)
		de = map_dirent(s->s_mounted, root_dno, "\001\001", 2, &qbh);
	if (!root_dno || !de) {
		printk("HPFS: "
		       "hpfs_read_super: root dir isn't in the root dir\n");
		s->s_dev = 0;
		return 0;
	}

	s->s_mounted->i_atime = local_to_gmt(de->read_date);
	s->s_mounted->i_mtime = local_to_gmt(de->write_date);
	s->s_mounted->i_ctime = local_to_gmt(de->creation_date);

	brelse4(&qbh);
	return s;

 bail2:
	brelse(bh2);
 bail1:
	brelse(bh1);
 bail0:
	brelse(bh0);
 bail:
	s->s_dev = 0;
	unlock_super(s);
	return 0;
}
예제 #3
0
/* ARGSUSED */
static int
checkfilesys(char *filesys)
{
    ufs2_daddr_t n_ffree, n_bfree;
    struct dups *dp;
    int cylno;
    intmax_t blks, files;

    check_filename = filesys;
    if (check_debug && check_clean)
        check_warn("starting\n");

    check_sblock_init();
    if (check_clean && check_skipclean) {
        /*
         * If file system is gjournaled, check it here.
         */
        if ((check_fsreadfd = open(filesys, O_RDONLY)) < 0 || check_readsb(0) == 0)
            exit(3);    /* Cannot read superblock */
        close(check_fsreadfd);
        if ((check_sblk.b_un.b_fs->fs_flags & FS_GJOURNAL) != 0) {
            //printf("GJournaled file system detected on %s.\n",
            //    filesys);
            if (check_sblk.b_un.b_fs->fs_clean == 1) {
                check_warn("FILE SYSTEM CLEAN; SKIPPING CHECKS\n");
                exit(0);
            }
            if ((check_sblk.b_un.b_fs->fs_flags & (FS_UNCLEAN | FS_NEEDSFSCK)) == 0) {
                check_gjournal(filesys);
                exit(0);
            } else {
                check_fatal(
                "UNEXPECTED INCONSISTENCY, CANNOT RUN FAST FSCK\n");
            }
        }
    }

    switch (check_setup(filesys, 0)) {
    case 0:
        if (check_preen)
            check_fatal("CAN'T CHECK FILE SYSTEM.");
        return (0);
    case -1:
        check_warn("clean, %ld free ", (long)(check_sblk.b_un.b_fs->fs_cstotal.cs_nffree +
            check_sblk.b_un.b_fs->fs_frag * check_sblk.b_un.b_fs->fs_cstotal.cs_nbfree));
        printf("(%jd frags, %jd blocks, %.1f%% fragmentation)\n",
            (intmax_t)check_sblk.b_un.b_fs->fs_cstotal.cs_nffree,
            (intmax_t)check_sblk.b_un.b_fs->fs_cstotal.cs_nbfree,
            check_sblk.b_un.b_fs->fs_cstotal.cs_nffree * 100.0 / check_sblk.b_un.b_fs->fs_dsize);
        return (0);
    }
    /*
     * Determine if we can and should do journal recovery.
     */
    if ((check_sblk.b_un.b_fs->fs_flags & FS_SUJ) == FS_SUJ) {
        if ((check_sblk.b_un.b_fs->fs_flags & FS_NEEDSFSCK) != FS_NEEDSFSCK && check_skipclean) {
            if (check_preen || check_reply("USE JOURNAL")) {
                if (check_suj(filesys) == 0) {
                    printf("\n***** FILE SYSTEM MARKED CLEAN *****\n");
                    exit(0);
                }
            }
            printf("** Skipping journal, falling through to full fsck\n\n");
        }
        /*
         * Write the superblock so we don't try to recover the
         * journal on another pass.
         */
        check_sblk.b_un.b_fs->fs_mtime = time(NULL);
        dirty(&check_sblk);
    }

    /*
     * Cleared if any questions answered no. Used to decide if
     * the superblock should be marked clean.
     */
    check_resolved = 1;
    /*
     * 1: scan inodes tallying blocks used
     */
    if (check_preen == 0) {
        printf("** Last Mounted on %s\n", check_sblk.b_un.b_fs->fs_fsmnt);
        printf("** Phase 1 - Check Blocks and Sizes\n");
    }
    check_pass1();

    /*
     * 1b: locate first references to duplicates, if any
     */
    if (check_duplist) {
        if (check_preen || check_usedsoftdep)
            check_fatal("INTERNAL ERROR: dups with %s%s%s",
                check_preen ? "-p" : "",
                (check_preen && check_usedsoftdep) ? " and " : "",
                check_usedsoftdep ? "softupdates" : "");
        printf("** Phase 1b - Rescan For More DUPS\n");
        check_pass1b();
    }

    /*
     * 2: traverse directories from root to mark all connected directories
     */
    if (check_preen == 0)
        printf("** Phase 2 - Check Pathnames\n");
    check_pass2();

    /*
     * 3: scan inodes looking for disconnected directories
     */
    if (check_preen == 0)
        printf("** Phase 3 - Check Connectivity\n");
    check_pass3();

    /*
     * 4: scan inodes looking for disconnected files; check reference counts
     */
    if (check_preen == 0)
        printf("** Phase 4 - Check Reference Counts\n");
    check_pass4();

    /*
     * 5: check and repair resource counts in cylinder groups
     */
    if (check_preen == 0)
        printf("** Phase 5 - Check Cyl groups\n");
    check_pass5();

    /*
     * print out summary statistics
     */
    n_ffree = check_sblk.b_un.b_fs->fs_cstotal.cs_nffree;
    n_bfree = check_sblk.b_un.b_fs->fs_cstotal.cs_nbfree;
    files = check_maxino - ROOTINO - check_sblk.b_un.b_fs->fs_cstotal.cs_nifree - check_n_files;
    blks = check_n_blks +
        check_sblk.b_un.b_fs->fs_ncg * (cgdmin(check_sblk.b_un.b_fs, 0) - cgsblock(check_sblk.b_un.b_fs, 0));
    blks += cgsblock(check_sblk.b_un.b_fs, 0) - cgbase(check_sblk.b_un.b_fs, 0);
    blks += howmany(check_sblk.b_un.b_fs->fs_cssize, check_sblk.b_un.b_fs->fs_fsize);
    blks = check_maxfsblock - (n_ffree + check_sblk.b_un.b_fs->fs_frag * n_bfree) - blks;
    check_warn("%ld files, %jd used, %ju free ",
        (long)check_n_files, (intmax_t)check_n_blks,
        (uintmax_t)(n_ffree + check_sblk.b_un.b_fs->fs_frag * n_bfree));
    printf("(%ju frags, %ju blocks, %.1f%% fragmentation)\n",
        (uintmax_t)n_ffree, (uintmax_t)n_bfree,
        n_ffree * 100.0 / check_sblk.b_un.b_fs->fs_dsize);
    if (check_debug) {
        if (files < 0)
            printf("%jd inodes missing\n", -files);
        if (blks < 0)
            printf("%jd blocks missing\n", -blks);
        if (check_duplist != NULL) {
            printf("The following duplicate blocks remain:");
            for (dp = check_duplist; dp; dp = dp->next)
                printf(" %jd,", (intmax_t)dp->dup);
            printf("\n");
        }
    }
    check_duplist = (struct dups *)0;
    check_muldup = (struct dups *)0;
    check_inocleanup();
    if (check_fsmodified) {
        check_sblk.b_un.b_fs->fs_time = time(NULL);
        dirty(&check_sblk);
    }
    if (check_cvtlevel && check_sblk.b_dirty) {
        /*
         * Write out the duplicate super blocks
         */
        for (cylno = 0; cylno < check_sblk.b_un.b_fs->fs_ncg; cylno++)
            check_blwrite(check_fswritefd, (char *)check_sblk.b_un.b_fs,
                fsbtodb(check_sblk.b_un.b_fs, cgsblock(check_sblk.b_un.b_fs, cylno)),
                SBLOCKSIZE);
    }
    if (check_rerun)
        check_resolved = 0;

    /*
     * Check to see if the file system is mounted read-write.
     */
    check_finish(check_resolved);

    for (cylno = 0; cylno < check_sblk.b_un.b_fs->fs_ncg; cylno++)
        if (check_inostathead[cylno].il_stat != NULL)
            free((char *)check_inostathead[cylno].il_stat);
    free((char *)check_inostathead);
    check_inostathead = NULL;
    if (check_fsmodified && !check_preen)
        printf("\n***** FILE SYSTEM WAS MODIFIED *****\n");
    if (check_rerun)
        printf("\n***** PLEASE RERUN FSCK *****\n");
    return (0);
}