Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/lib/libsa lfs code is built from ufs.c



details:   https://anonhg.NetBSD.org/src/rev/02fe60460f36
branches:  trunk
changeset: 545818:02fe60460f36
user:      dsl <dsl%NetBSD.org@localhost>
date:      Wed Apr 16 19:52:58 2003 +0000

description:
lfs code is built from ufs.c

diffstat:

 sys/lib/libsa/lfs.c |  839 ----------------------------------------------------
 1 files changed, 0 insertions(+), 839 deletions(-)

diffs (truncated from 843 to 300 lines):

diff -r 806ded3c7b55 -r 02fe60460f36 sys/lib/libsa/lfs.c
--- a/sys/lib/libsa/lfs.c       Wed Apr 16 19:20:33 2003 +0000
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,839 +0,0 @@
-/* $NetBSD: lfs.c,v 1.11 2003/04/02 10:39:33 fvdl Exp $ */
-
-/*-
- * Copyright (c) 1993
- *     The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * The Mach Operating System project at Carnegie-Mellon University.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by the University of
- *     California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *
- * Copyright (c) 1990, 1991 Carnegie Mellon University
- * All Rights Reserved.
- *
- * Author: David Golub
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
- * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
- * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- *
- * Carnegie Mellon requests users of this software to return to
- *
- *  Software Distribution Coordinator  or  Software.Distribution%CS.CMU.EDU@localhost
- *  School of Computer Science
- *  Carnegie Mellon University
- *  Pittsburgh PA 15213-3890
- *
- * any improvements or extensions that they make and grant Carnegie the
- * rights to redistribute these changes.
- */
-
-/*
- * XXX NOTE: ufs.c (FFS) and lfs.c (LFS) should eventually use much common
- * XXX code.  until then, the two files should be easily diffable.
- */
-
-/*
- *     Stand-alone file reading package.
- */
-
-#include <sys/param.h>
-#include <sys/time.h>
-#include <sys/mount.h>                 /* XXX for MNAMELEN */
-#include <ufs/ufs/dinode.h>
-#include <ufs/ufs/dir.h>
-#include <ufs/lfs/lfs.h>
-#ifdef _STANDALONE
-#include <lib/libkern/libkern.h>
-#else
-#include <string.h>
-#endif
-
-#include "stand.h"
-#include "lfs.h"
-
-#if defined(LIBSA_FS_SINGLECOMPONENT) && !defined(LIBSA_NO_FS_SYMLINK)
-#define LIBSA_NO_FS_SYMLINK
-#endif
-
-/*
- * In-core LFS superblock.  This exists only to placate the macros in lfs.h,
- * and to diff easily against the UFS code.
- */
-struct fs {
-       struct dlfs     lfs_dlfs;
-};
-#define        fs_magic        lfs_magic
-#define fs_maxsymlinklen lfs_maxsymlinklen
-
-#define        FS_MAGIC        LFS_MAGIC
-#define        SBSIZE          LFS_SBPAD
-#define        SBLOCK          (LFS_LABELPAD / DEV_BSIZE)
-
-
-#if defined(LIBSA_LFSv1)               /* XXX not tested */
-
-#undef fsbtodb
-#define        fsbtodb(fs, daddr)      (daddr)         /* LFSv1 uses sectors for addresses */
-#define        lfs_open                lfsv1_open
-#define        lfs_close               lfsv1_close
-#define        lfs_read                lfsv1_read
-#define        lfs_write               lfsv1_write
-#define        lfs_seek                lfsv1_seek
-#define        lfs_stat                lfsv1_stat
-
-#define        REQUIRED_LFS_VERSION    1
-#define        fs_bsize                lfs_ibsize
-#define        IFILE                   IFILE_V1
-
-#elif defined(LIBSA_LFSv2)
-
-#define        lfs_open                lfsv2_open
-#define        lfs_close               lfsv2_close
-#define        lfs_read                lfsv2_read
-#define        lfs_write               lfsv2_write
-#define        lfs_seek                lfsv2_seek
-#define        lfs_stat                lfsv2_stat
-
-#define        REQUIRED_LFS_VERSION    2
-#define        fs_bsize                lfs_bsize
-
-#ifdef LFS_IFILE_FRAG_ADDRESSING       /* XXX see sys/ufs/lfs/ -- not tested */
-#undef INOPB
-#define        INOPB INOPF
-#endif
-
-#else
-#error Must define one of LIBSA_LFSv1, LIBSA_LFSv2
-#endif
-
-
-/*
- * In-core open file.
- */
-struct file {
-       off_t           f_seekp;        /* seek pointer */
-       struct fs       *f_fs;          /* pointer to super-block */
-       struct ufs1_dinode      f_di;           /* copy of on-disk inode */
-       unsigned int    f_nindir[NIADDR];
-                                       /* number of blocks mapped by
-                                          indirect block at level i */
-       char            *f_blk[NIADDR]; /* buffer for indirect block at
-                                          level i */
-       size_t          f_blksize[NIADDR];
-                                       /* size of buffer */
-       daddr_t         f_blkno[NIADDR];/* disk address of block in buffer */
-       char            *f_buf;         /* buffer for data block */
-       size_t          f_buf_size;     /* size of data block */
-       daddr_t         f_buf_blkno;    /* block number of data block */
-};
-
-static int     find_inode_sector(ino_t inumber, struct open_file *f,
-                   daddr_t *ibp);
-static int     read_inode __P((ino_t, struct open_file *));
-static int     block_map __P((struct open_file *, daddr_t, daddr_t *));
-static int     buf_read_file __P((struct open_file *, char **, size_t *));
-static int     search_directory __P((char *, struct open_file *, ino_t *));
-
-/*
- * Find an inode's block.  Look it up in the ifile.  Whee!
- */
-static int
-find_inode_sector(ino_t inumber, struct open_file *f, daddr_t *isp)
-{
-       struct file *fp = (struct file *)f->f_fsdata;
-       struct fs *fs = fp->f_fs;
-       daddr_t ifileent_blkno;
-       char *ent_in_buf;
-       size_t buf_after_ent;
-       int rc;
-
-       rc = read_inode(fs->lfs_ifile, f);
-       if (rc)
-               return (rc);
-
-       ifileent_blkno =
-           (inumber / fs->lfs_ifpb) + fs->lfs_cleansz + fs->lfs_segtabsz;
-       fp->f_seekp = (off_t)ifileent_blkno * fs->fs_bsize +
-           (inumber % fs->lfs_ifpb) * sizeof (IFILE);
-       rc = buf_read_file(f, &ent_in_buf, &buf_after_ent);
-       if (rc)
-               return (rc);
-       /* make sure something's not badly wrong, but don't panic. */
-       if (buf_after_ent < sizeof (IFILE))
-               return (EINVAL);
-
-       *isp = fsbtodb(fs, ((IFILE *)ent_in_buf)->if_daddr);
-       if (*isp == LFS_UNUSED_DADDR)   /* again, something badly wrong */
-               return (EINVAL);
-       return (0);
-}
-
-/*
- * Read a new inode into a file structure.
- */
-static int
-read_inode(inumber, f)
-       ino_t inumber;
-       struct open_file *f;
-{
-       struct file *fp = (struct file *)f->f_fsdata;
-       struct fs *fs = fp->f_fs;
-       struct ufs1_dinode *dip;
-       daddr_t inode_sector;
-       size_t rsize;
-       char *buf;
-       int rc, cnt;
-
-       if (inumber == fs->lfs_ifile)
-               inode_sector = fsbtodb(fs, fs->lfs_idaddr);
-       else if ((rc = find_inode_sector(inumber, f, &inode_sector)) != 0)
-               return (rc);
-
-       /*
-        * Read inode and save it.
-        */
-       buf = alloc(fs->fs_bsize);
-#if !defined(LIBSA_NO_TWIDDLE)
-       twiddle();
-#endif
-       rc = DEV_STRATEGY(f->f_dev)(f->f_devdata, F_READ,
-               inode_sector, fs->fs_bsize,
-               buf, &rsize);
-       if (rc)
-               goto out;
-       if (rsize != fs->fs_bsize) {
-               rc = EIO;
-               goto out;
-       }
-
-       rc = EINVAL;
-       cnt = INOPB(fs);
-        for (dip = (struct ufs1_dinode *)buf + (cnt - 1); cnt--; --dip) {
-                if (dip->di_inumber == inumber) {
-                        rc = 0;
-                       break;
-               }
-       }
-       /* kernel code panics, but boot blocks which panic are Bad. */
-       if (rc)
-               goto out;
-       fp->f_di = *dip;
-
-       /*
-        * Clear out the old buffers
-        */
-       {
-               int level;
-
-               for (level = 0; level < NIADDR; level++)
-                       fp->f_blkno[level] = -1;
-               fp->f_buf_blkno = -1;
-       }
-out:
-       free(buf, fs->fs_bsize);
-       return (rc);
-}
-
-/*
- * Given an offset in a file, find the disk block number that
- * contains that block.
- */
-static int
-block_map(f, file_block, disk_block_p)
-       struct open_file *f;
-       daddr_t file_block;
-       daddr_t *disk_block_p;  /* out */
-{
-       struct file *fp = (struct file *)f->f_fsdata;
-       struct fs *fs = fp->f_fs;
-       int level;
-       int idx;
-       daddr_t ind_block_num;
-       /* XXX ondisk32 */
-       int32_t *ind_p;
-       int rc;
-
-       /*
-        * Index structure of an inode:
-        *
-        * di_db[0..NDADDR-1]   hold block numbers for blocks
-        *                      0..NDADDR-1
-        *



Home | Main Index | Thread Index | Old Index