
    UFSlib

* What is this?

    Here you can find some source code to read UFS filesystems
    by accessing the raw device from SunOS and WinNT systems.

* What I get?

    You can compile a library you can link later against your
    own code; so your program will be able to read disks which
    use SunOS/Solaris Big-Endian UFS format.
    (Probably it would be easy to support Solaris x86 UFS filesystems,
    but I don't need it by now)

    BUT BE WARNED: libufs will silently fail for files which use level
    two indirection. You can use "ufs.c" (see below) for those.

    You will get also a small binary, named "ufssh" which should
    be considered more as an example of how to use the library
    than as a finished program; but you can find it useful "as is".

    "ufssh" will open a minimal shell rooted at the UFS of your
    choice, and from that shell you will be able to:

    - get the current path on the UFS ('pwd')

    - change the current path on the host system ('lcd')

    - change the current path on the UFS ('cd')

    - view files on the UFS by piping them to host pager ('more')
    (SunOS only; NT less is not too reliable)

    - copy files or directories from the UFS to the host filesystem ('cp')


    To try it on your you will have to do somethink like:
        Solaris 2.x -> ufssh -p0 /dev/rdsk/c0t0d0s2
        SunOS 4.x -> ufssh -p0 /dev/rsd0c
        WinNT -> ufssh -p0 \\.\PHYSICALDRIVE1

    And at last you will get also a simple "ufs.c" source code
    file which reads the UFS whitout using the library, so you
    can understand more easily how UFS works.


* How can I use the library?.

    Well, I'll try to sumarize here the usage (which is pretty simple)
    Anyway you should read ufssh.c (which, BTW, is a link to efssh.c)


    Your program should include "sun_ufs.h"
    The rest of the files are:

        sun_ufs.h       generic library include

        sun_io.h        implementation dependent
        ufs_db.c        debug
        ufs_db.h        debug headers
        ufs_file.c      file/dir reading
        ufs_fs.c        generic file system functions
        ufs_io.c        inode/block operations
        ufs_io.h        inode/block headers


    The generic operation goes like this:

    First you have to select a disk using
    * ufs_open_disk
        <- raw device name
        -> UFS_DISK *

        on error: NULL and sets ufs_errno or errno
        scan partitions using
            ufs_empty_partition( disk, partition )
            and
            ufs_partition_size( disk, partition )


        Then you mount a partition by:
        * ufs_mount
            <- disk
            <- partition
            <- flags
            -> UFS_FS *
                on error: NULL and sets ufs_errno or errno
                flags:
                    UFS_FMOUNTALL: allows mounting of swap/overlap
                    UFS_FMOUNTSTD: standard partitions only

            = sets default fs if there is none.

            *set_default_fs
                <- UFS_FS *
            *get_default_fs
                -> UFS_FS *

                default fs is used for all I/O operations.

            And the rest of the operations are POSIX-like:

            * ufs_getwd
                -> path (path can hold MAXPATHLEN chars)
                on error return NULL

            * ufs_chdir
                <- path
                on error return -1

            * ufs_stat
                <- path
                -> stat

                (note: you have a efs_istat, i-node based which can
                save you some cycles. See ufssh.c)

            * ufs_opendir
                * ufs_readdir
            * ufs_closedir

            * ufs_fopen
                rb, ignored
                * ufs_fread
                    buffered input
            * ufs_close
            * ufs_feof

        * ufs_umount
            <- *ufs

    * ufs_close_disk
        <- UFS_DISK *


* What I need?

    - SunOS 4.x using gcc 2.7.x
    Edit the Makefile so it uses gcc, ranlib and the -D_SUNOS_ line

    - Solaris 2.x using gcc/egcs
    Edit the Makefile so it uses gcc, : and the -D_SOLARIS_ line

    - Solaris 2.x using WorkShop 5.x cc
    Same as Solaris 2.x gcc, but set CC and LC to cc

    - WinNT 4.0 MSVC 6.0

    For compiling in WinNT you will need to create the appropiate sunos
    headers. See sunos/README


* Who can I blame if my NT crashes?

    I have no idea :-)

    All this code does is to open a raw device (this, usually requires
    root/administrator privs) and read it; so it hardly can panic your
    system or erase your data.

    (Well, the 'cp' code in "efssh.c" is somewhat quick and dirty; and
    it does modify the host filesystem. Use it at your own risk, and
    re-write it if you are planning to use it at any serious work)


    You can send fixes to spd@daphne.cps.unizar.es



