summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.cvsignore1
-rw-r--r--README.CVS29
-rw-r--r--bsdfsck/Makefile31
-rw-r--r--bsdfsck/dir.c690
-rw-r--r--bsdfsck/fsck.h303
-rw-r--r--bsdfsck/inode.c562
-rw-r--r--bsdfsck/main.c333
-rw-r--r--bsdfsck/pass1.c331
-rw-r--r--bsdfsck/pass1b.c100
-rw-r--r--bsdfsck/pass2.c441
-rw-r--r--bsdfsck/pass3.c72
-rw-r--r--bsdfsck/pass4.c134
-rw-r--r--bsdfsck/pass5.c358
-rw-r--r--bsdfsck/preen.c355
-rw-r--r--bsdfsck/setup.c480
-rw-r--r--bsdfsck/utilities.c567
-rwxr-xr-xconfigure5868
-rw-r--r--configure.in258
-rw-r--r--libpthread/ChangeLog6
-rw-r--r--libpthread/Makefile249
-rw-r--r--libpthread/Makefile.am168
-rw-r--r--libpthread/TODO177
-rw-r--r--libpthread/headers.m445
-rw-r--r--libpthread/include/libc-symbols.h395
-rw-r--r--libpthread/include/pthread.h7
-rw-r--r--libpthread/include/pthread/pthread.h755
-rw-r--r--libpthread/include/pthread/pthreadtypes.h125
-rw-r--r--libpthread/include/semaphore.h69
-rw-r--r--libpthread/include/set-hooks.h72
-rw-r--r--libpthread/libpthread.a20
-rw-r--r--libpthread/libpthread_pic.a20
-rw-r--r--libpthread/lockfile.c65
-rw-r--r--libpthread/not-in-libc.h11
-rw-r--r--libpthread/pt-yield.c26
-rw-r--r--libpthread/pthread/Versions15
-rw-r--r--libpthread/pthread/cthreads-compat.c107
-rw-r--r--libpthread/pthread/pt-alloc.c215
-rw-r--r--libpthread/pthread/pt-cancel.c40
-rw-r--r--libpthread/pthread/pt-cleanup.c28
-rw-r--r--libpthread/pthread/pt-create.c217
-rw-r--r--libpthread/pthread/pt-dealloc.c64
-rw-r--r--libpthread/pthread/pt-detach.c92
-rw-r--r--libpthread/pthread/pt-exit.c122
-rw-r--r--libpthread/pthread/pt-getattr.c49
-rw-r--r--libpthread/pthread/pt-initialize.c33
-rw-r--r--libpthread/pthread/pt-internal.h317
-rw-r--r--libpthread/pthread/pt-join.c88
-rw-r--r--libpthread/pthread/pt-self.c32
-rw-r--r--libpthread/pthread/pt-setcancelstate.c43
-rw-r--r--libpthread/pthread/pt-setcanceltype.c43
-rw-r--r--libpthread/pthread/pt-sigmask.c33
-rw-r--r--libpthread/pthread/pt-spin-inlines.c34
-rw-r--r--libpthread/pthread/pt-testcancel.c31
-rw-r--r--libpthread/signal/README4
-rw-r--r--libpthread/signal/TODO29
-rw-r--r--libpthread/signal/kill.c70
-rw-r--r--libpthread/signal/pt-kill-siginfo-np.c88
-rw-r--r--libpthread/signal/sig-internal.c26
-rw-r--r--libpthread/signal/sig-internal.h177
-rw-r--r--libpthread/signal/sigaction.c72
-rw-r--r--libpthread/signal/sigaltstack.c69
-rw-r--r--libpthread/signal/signal-dispatch.c117
-rw-r--r--libpthread/signal/signal.h275
-rw-r--r--libpthread/signal/sigpending.c38
-rw-r--r--libpthread/signal/sigsuspend.c29
-rw-r--r--libpthread/signal/sigtimedwait.c30
-rw-r--r--libpthread/signal/sigwaiter.c91
-rw-r--r--libpthread/signal/sigwaitinfo.c74
-rw-r--r--libpthread/sysdeps/generic/bits/barrier-attr.h32
-rw-r--r--libpthread/sysdeps/generic/bits/barrier.h39
-rw-r--r--libpthread/sysdeps/generic/bits/cancelation.h51
-rw-r--r--libpthread/sysdeps/generic/bits/condition-attr.h34
-rw-r--r--libpthread/sysdeps/generic/bits/condition.h39
-rw-r--r--libpthread/sysdeps/generic/bits/mutex-attr.h41
-rw-r--r--libpthread/sysdeps/generic/bits/mutex.h75
-rw-r--r--libpthread/sysdeps/generic/bits/once.h34
-rw-r--r--libpthread/sysdeps/generic/bits/pthread-np.h27
-rw-r--r--libpthread/sysdeps/generic/bits/pthread.h38
-rw-r--r--libpthread/sysdeps/generic/bits/pthreadtypes.h29
-rw-r--r--libpthread/sysdeps/generic/bits/rwlock-attr.h32
-rw-r--r--libpthread/sysdeps/generic/bits/rwlock.h46
-rw-r--r--libpthread/sysdeps/generic/bits/semaphore.h43
-rw-r--r--libpthread/sysdeps/generic/bits/thread-attr.h44
-rw-r--r--libpthread/sysdeps/generic/bits/thread-specific.h25
-rw-r--r--libpthread/sysdeps/generic/killpg.c27
-rw-r--r--libpthread/sysdeps/generic/pt-atfork.c29
-rw-r--r--libpthread/sysdeps/generic/pt-attr-destroy.c27
-rw-r--r--libpthread/sysdeps/generic/pt-attr-getdetachstate.c29
-rw-r--r--libpthread/sysdeps/generic/pt-attr-getguardsize.c29
-rw-r--r--libpthread/sysdeps/generic/pt-attr-getinheritsched.c29
-rw-r--r--libpthread/sysdeps/generic/pt-attr-getschedparam.c32
-rw-r--r--libpthread/sysdeps/generic/pt-attr-getschedpolicy.c29
-rw-r--r--libpthread/sysdeps/generic/pt-attr-getscope.c29
-rw-r--r--libpthread/sysdeps/generic/pt-attr-getstack.c31
-rw-r--r--libpthread/sysdeps/generic/pt-attr-getstackaddr.c29
-rw-r--r--libpthread/sysdeps/generic/pt-attr-getstacksize.c29
-rw-r--r--libpthread/sysdeps/generic/pt-attr-init.c28
-rw-r--r--libpthread/sysdeps/generic/pt-attr-setdetachstate.c38
-rw-r--r--libpthread/sysdeps/generic/pt-attr-setguardsize.c29
-rw-r--r--libpthread/sysdeps/generic/pt-attr-setinheritsched.c38
-rw-r--r--libpthread/sysdeps/generic/pt-attr-setschedparam.c38
-rw-r--r--libpthread/sysdeps/generic/pt-attr-setschedpolicy.c42
-rw-r--r--libpthread/sysdeps/generic/pt-attr-setscope.c41
-rw-r--r--libpthread/sysdeps/generic/pt-attr-setstack.c51
-rw-r--r--libpthread/sysdeps/generic/pt-attr-setstackaddr.c29
-rw-r--r--libpthread/sysdeps/generic/pt-attr-setstacksize.c41
-rw-r--r--libpthread/sysdeps/generic/pt-attr.c41
-rw-r--r--libpthread/sysdeps/generic/pt-barrier-destroy.c27
-rw-r--r--libpthread/sysdeps/generic/pt-barrier-init.c53
-rw-r--r--libpthread/sysdeps/generic/pt-barrier-wait.c61
-rw-r--r--libpthread/sysdeps/generic/pt-barrier.c26
-rw-r--r--libpthread/sysdeps/generic/pt-barrierattr-destroy.c27
-rw-r--r--libpthread/sysdeps/generic/pt-barrierattr-getpshared.c29
-rw-r--r--libpthread/sysdeps/generic/pt-barrierattr-init.c28
-rw-r--r--libpthread/sysdeps/generic/pt-barrierattr-setpshared.c39
-rw-r--r--libpthread/sysdeps/generic/pt-cond-brdcast.c42
-rw-r--r--libpthread/sysdeps/generic/pt-cond-destroy.c27
-rw-r--r--libpthread/sysdeps/generic/pt-cond-init.c45
-rw-r--r--libpthread/sysdeps/generic/pt-cond-signal.c54
-rw-r--r--libpthread/sysdeps/generic/pt-cond-timedwait.c106
-rw-r--r--libpthread/sysdeps/generic/pt-cond-wait.c37
-rw-r--r--libpthread/sysdeps/generic/pt-cond.c29
-rw-r--r--libpthread/sysdeps/generic/pt-condattr-destroy.c27
-rw-r--r--libpthread/sysdeps/generic/pt-condattr-getclock.c31
-rw-r--r--libpthread/sysdeps/generic/pt-condattr-getpshared.c29
-rw-r--r--libpthread/sysdeps/generic/pt-condattr-init.c28
-rw-r--r--libpthread/sysdeps/generic/pt-condattr-setclock.c33
-rw-r--r--libpthread/sysdeps/generic/pt-condattr-setpshared.c39
-rw-r--r--libpthread/sysdeps/generic/pt-destroy-specific.c28
-rw-r--r--libpthread/sysdeps/generic/pt-equal.c29
-rw-r--r--libpthread/sysdeps/generic/pt-getconcurrency.c27
-rw-r--r--libpthread/sysdeps/generic/pt-getcpuclockid.c34
-rw-r--r--libpthread/sysdeps/generic/pt-getschedparam.c28
-rw-r--r--libpthread/sysdeps/generic/pt-getspecific.c27
-rw-r--r--libpthread/sysdeps/generic/pt-init-specific.c27
-rw-r--r--libpthread/sysdeps/generic/pt-key-create.c27
-rw-r--r--libpthread/sysdeps/generic/pt-key-delete.c27
-rw-r--r--libpthread/sysdeps/generic/pt-key.h22
-rw-r--r--libpthread/sysdeps/generic/pt-kill.c32
-rw-r--r--libpthread/sysdeps/generic/pt-mutex-destroy.c39
-rw-r--r--libpthread/sysdeps/generic/pt-mutex-getprioceiling.c28
-rw-r--r--libpthread/sysdeps/generic/pt-mutex-init.c50
-rw-r--r--libpthread/sysdeps/generic/pt-mutex-lock.c37
-rw-r--r--libpthread/sysdeps/generic/pt-mutex-setprioceiling.c28
-rw-r--r--libpthread/sysdeps/generic/pt-mutex-timedlock.c187
-rw-r--r--libpthread/sysdeps/generic/pt-mutex-transfer-np.c66
-rw-r--r--libpthread/sysdeps/generic/pt-mutex-trylock.c112
-rw-r--r--libpthread/sysdeps/generic/pt-mutex-unlock.c108
-rw-r--r--libpthread/sysdeps/generic/pt-mutexattr-destroy.c27
-rw-r--r--libpthread/sysdeps/generic/pt-mutexattr-getprioceiling.c28
-rw-r--r--libpthread/sysdeps/generic/pt-mutexattr-getprotocol.c29
-rw-r--r--libpthread/sysdeps/generic/pt-mutexattr-getpshared.c29
-rw-r--r--libpthread/sysdeps/generic/pt-mutexattr-gettype.c28
-rw-r--r--libpthread/sysdeps/generic/pt-mutexattr-init.c28
-rw-r--r--libpthread/sysdeps/generic/pt-mutexattr-setprioceiling.c28
-rw-r--r--libpthread/sysdeps/generic/pt-mutexattr-setprotocol.c42
-rw-r--r--libpthread/sysdeps/generic/pt-mutexattr-setpshared.c39
-rw-r--r--libpthread/sysdeps/generic/pt-mutexattr-settype.c37
-rw-r--r--libpthread/sysdeps/generic/pt-mutexattr.c45
-rw-r--r--libpthread/sysdeps/generic/pt-once.c43
-rw-r--r--libpthread/sysdeps/generic/pt-rwlock-attr.c26
-rw-r--r--libpthread/sysdeps/generic/pt-rwlock-destroy.c29
-rw-r--r--libpthread/sysdeps/generic/pt-rwlock-init.c45
-rw-r--r--libpthread/sysdeps/generic/pt-rwlock-rdlock.c32
-rw-r--r--libpthread/sysdeps/generic/pt-rwlock-timedrdlock.c113
-rw-r--r--libpthread/sysdeps/generic/pt-rwlock-timedwrlock.c95
-rw-r--r--libpthread/sysdeps/generic/pt-rwlock-tryrdlock.c56
-rw-r--r--libpthread/sysdeps/generic/pt-rwlock-trywrlock.c46
-rw-r--r--libpthread/sysdeps/generic/pt-rwlock-unlock.c90
-rw-r--r--libpthread/sysdeps/generic/pt-rwlock-wrlock.c34
-rw-r--r--libpthread/sysdeps/generic/pt-rwlockattr-destroy.c27
-rw-r--r--libpthread/sysdeps/generic/pt-rwlockattr-getpshared.c29
-rw-r--r--libpthread/sysdeps/generic/pt-rwlockattr-init.c28
-rw-r--r--libpthread/sysdeps/generic/pt-rwlockattr-setpshared.c39
-rw-r--r--libpthread/sysdeps/generic/pt-setconcurrency.c34
-rw-r--r--libpthread/sysdeps/generic/pt-setschedparam.c28
-rw-r--r--libpthread/sysdeps/generic/pt-setschedprio.c27
-rw-r--r--libpthread/sysdeps/generic/pt-setspecific.c27
-rw-r--r--libpthread/sysdeps/generic/pt-startup.c25
-rw-r--r--libpthread/sysdeps/generic/raise.c41
-rw-r--r--libpthread/sysdeps/generic/sem-close.c32
-rw-r--r--libpthread/sysdeps/generic/sem-destroy.c38
-rw-r--r--libpthread/sysdeps/generic/sem-getvalue.c33
-rw-r--r--libpthread/sysdeps/generic/sem-init.c46
-rw-r--r--libpthread/sysdeps/generic/sem-open.c32
-rw-r--r--libpthread/sysdeps/generic/sem-post.c62
-rw-r--r--libpthread/sysdeps/generic/sem-timedwait.c91
-rw-r--r--libpthread/sysdeps/generic/sem-trywait.c42
-rw-r--r--libpthread/sysdeps/generic/sem-unlink.c32
-rw-r--r--libpthread/sysdeps/generic/sem-wait.c32
-rw-r--r--libpthread/sysdeps/generic/sigaddset.c35
-rw-r--r--libpthread/sysdeps/generic/sigdelset.c35
-rw-r--r--libpthread/sysdeps/generic/sigemptyset.c29
-rw-r--r--libpthread/sysdeps/generic/sigfillset.c29
-rw-r--r--libpthread/sysdeps/generic/siginterrupt.c36
-rw-r--r--libpthread/sysdeps/generic/sigismember.c36
-rw-r--r--libpthread/sysdeps/generic/signal.c44
-rw-r--r--libpthread/sysdeps/generic/sigwait.c34
-rw-r--r--libpthread/sysdeps/hurd/pt-destroy-specific.c79
-rw-r--r--libpthread/sysdeps/hurd/pt-getspecific.c39
-rw-r--r--libpthread/sysdeps/hurd/pt-init-specific.c30
-rw-r--r--libpthread/sysdeps/hurd/pt-key-create.c109
-rw-r--r--libpthread/sysdeps/hurd/pt-key-delete.c64
-rw-r--r--libpthread/sysdeps/hurd/pt-key.h76
-rw-r--r--libpthread/sysdeps/hurd/pt-kill.c52
-rw-r--r--libpthread/sysdeps/hurd/pt-setspecific.c47
-rw-r--r--libpthread/sysdeps/ia32/bits/atomic.h66
-rw-r--r--libpthread/sysdeps/ia32/bits/memory.h40
-rw-r--r--libpthread/sysdeps/ia32/bits/spin-lock-inline.h98
-rw-r--r--libpthread/sysdeps/ia32/bits/spin-lock.h39
-rw-r--r--libpthread/sysdeps/ia32/machine-sp.h30
-rw-r--r--libpthread/sysdeps/ia32/pt-machdep.h29
-rw-r--r--libpthread/sysdeps/l4/bits/pthread-np.h35
-rw-r--r--libpthread/sysdeps/l4/hurd/bits/pthread-np.h31
-rw-r--r--libpthread/sysdeps/l4/hurd/ia32/pt-machdep.c20
-rw-r--r--libpthread/sysdeps/l4/hurd/ia32/pt-setup.c117
-rw-r--r--libpthread/sysdeps/l4/hurd/ia32/signal-dispatch-lowlevel.c213
-rw-r--r--libpthread/sysdeps/l4/hurd/powerpc/pt-machdep.c20
-rw-r--r--libpthread/sysdeps/l4/hurd/powerpc/pt-setup.c93
-rw-r--r--libpthread/sysdeps/l4/hurd/pt-block.c30
-rw-r--r--libpthread/sysdeps/l4/hurd/pt-kill.c3
-rw-r--r--libpthread/sysdeps/l4/hurd/pt-setactivity-np.c39
-rw-r--r--libpthread/sysdeps/l4/hurd/pt-sigstate-destroy.c28
-rw-r--r--libpthread/sysdeps/l4/hurd/pt-sigstate-init.c44
-rw-r--r--libpthread/sysdeps/l4/hurd/pt-sigstate.c81
-rw-r--r--libpthread/sysdeps/l4/hurd/pt-startup.c30
-rw-r--r--libpthread/sysdeps/l4/hurd/pt-sysdep.c61
-rw-r--r--libpthread/sysdeps/l4/hurd/pt-sysdep.h61
-rw-r--r--libpthread/sysdeps/l4/hurd/pt-thread-alloc.c95
-rw-r--r--libpthread/sysdeps/l4/hurd/pt-thread-halt.c104
-rw-r--r--libpthread/sysdeps/l4/hurd/pt-thread-start.c70
-rw-r--r--libpthread/sysdeps/l4/hurd/pt-wakeup.c46
-rw-r--r--libpthread/sysdeps/l4/hurd/sig-sysdep.h69
-rw-r--r--libpthread/sysdeps/l4/hurd/sigprocmask.c41
-rw-r--r--libpthread/sysdeps/l4/pt-block.c47
-rw-r--r--libpthread/sysdeps/l4/pt-docancel.c42
-rw-r--r--libpthread/sysdeps/l4/pt-pool-np.c54
-rw-r--r--libpthread/sysdeps/l4/pt-spin.c63
-rw-r--r--libpthread/sysdeps/l4/pt-stack-alloc.c43
-rw-r--r--libpthread/sysdeps/l4/pt-thread-alloc.c43
-rw-r--r--libpthread/sysdeps/l4/pt-thread-dealloc.c32
-rw-r--r--libpthread/sysdeps/l4/pt-thread-halt.c45
-rw-r--r--libpthread/sysdeps/l4/pt-thread-start.c40
-rw-r--r--libpthread/sysdeps/l4/pt-timedblock.c35
-rw-r--r--libpthread/sysdeps/l4/pt-wakeup.c54
-rw-r--r--libpthread/sysdeps/mach/bits/spin-lock-inline.h90
-rw-r--r--libpthread/sysdeps/mach/bits/spin-lock.h38
-rw-r--r--libpthread/sysdeps/mach/hurd/ia32/pt-machdep.c83
-rw-r--r--libpthread/sysdeps/mach/hurd/ia32/pt-setup.c108
-rw-r--r--libpthread/sysdeps/mach/hurd/pt-attr-setstackaddr.c35
-rw-r--r--libpthread/sysdeps/mach/hurd/pt-attr-setstacksize.c35
-rw-r--r--libpthread/sysdeps/mach/hurd/pt-docancel.c64
-rw-r--r--libpthread/sysdeps/mach/hurd/pt-sigstate-destroy.c28
-rw-r--r--libpthread/sysdeps/mach/hurd/pt-sigstate-init.c37
-rw-r--r--libpthread/sysdeps/mach/hurd/pt-sigstate.c69
-rw-r--r--libpthread/sysdeps/mach/hurd/pt-sysdep.c72
-rw-r--r--libpthread/sysdeps/mach/hurd/pt-sysdep.h72
-rw-r--r--libpthread/sysdeps/mach/pt-block.c39
-rw-r--r--libpthread/sysdeps/mach/pt-spin.c36
-rw-r--r--libpthread/sysdeps/mach/pt-stack-alloc.c74
-rw-r--r--libpthread/sysdeps/mach/pt-thread-alloc.c106
-rw-r--r--libpthread/sysdeps/mach/pt-thread-dealloc.c41
-rw-r--r--libpthread/sysdeps/mach/pt-thread-halt.c37
-rw-r--r--libpthread/sysdeps/mach/pt-thread-start.c49
-rw-r--r--libpthread/sysdeps/mach/pt-timedblock.c68
-rw-r--r--libpthread/sysdeps/mach/pt-wakeup.c38
-rw-r--r--libpthread/sysdeps/posix/pt-spin.c54
-rw-r--r--libpthread/sysdeps/powerpc/bits/machine-lock.h78
-rw-r--r--libpthread/sysdeps/powerpc/bits/memory.h36
-rw-r--r--libpthread/sysdeps/powerpc/bits/spin-lock.h108
-rw-r--r--libpthread/sysdeps/powerpc/machine-sp.h31
-rw-r--r--libpthread/sysdeps/powerpc/pt-machdep.h29
-rw-r--r--libpthread/tests/.cvsignore1
-rw-r--r--libpthread/tests/Makefile29
-rw-r--r--libpthread/tests/test-1.c50
-rw-r--r--libpthread/tests/test-10.c46
-rw-r--r--libpthread/tests/test-11.c143
-rw-r--r--libpthread/tests/test-12.c29
-rw-r--r--libpthread/tests/test-13.c66
-rw-r--r--libpthread/tests/test-14.c44
-rw-r--r--libpthread/tests/test-15.c87
-rw-r--r--libpthread/tests/test-16.c71
-rw-r--r--libpthread/tests/test-2.c39
-rw-r--r--libpthread/tests/test-3.c55
-rw-r--r--libpthread/tests/test-4.c86
-rw-r--r--libpthread/tests/test-5.c75
-rw-r--r--libpthread/tests/test-6.c96
-rw-r--r--libpthread/tests/test-7.c70
-rw-r--r--libpthread/tests/test-8.c60
-rw-r--r--libpthread/tests/test-9.c88
-rw-r--r--procfs/Makefile26
-rw-r--r--procfs/TODO24
-rw-r--r--procfs/dircat.c128
-rw-r--r--procfs/dircat.h29
-rw-r--r--procfs/main.c190
-rw-r--r--procfs/main.h25
-rw-r--r--procfs/netfs.c445
-rw-r--r--procfs/process.c393
-rw-r--r--procfs/process.h27
-rw-r--r--procfs/procfs.c203
-rw-r--r--procfs/procfs.h93
-rw-r--r--procfs/procfs_dir.c134
-rw-r--r--procfs/procfs_dir.h63
-rw-r--r--procfs/proclist.c94
-rw-r--r--procfs/proclist.h23
-rw-r--r--procfs/rootdir.c506
-rw-r--r--procfs/rootdir.h23
-rw-r--r--random/Makefile29
-rw-r--r--random/TODO11
-rw-r--r--random/gnupg-bithelp.h41
-rw-r--r--random/gnupg-glue.h40
-rw-r--r--random/gnupg-random.c810
-rw-r--r--random/gnupg-random.h47
-rw-r--r--random/gnupg-rmd.h38
-rw-r--r--random/gnupg-rmd160.c656
-rw-r--r--random/random.c624
-rw-r--r--random/random.h32
-rw-r--r--tests/test-17.c57
-rw-r--r--tests/test-__pthread_destroy_specific-skip.c83
-rw-r--r--ufs-fsck/Makefile35
-rw-r--r--ufs-fsck/dir.c567
-rw-r--r--ufs-fsck/fsck.h183
-rw-r--r--ufs-fsck/inode.c203
-rw-r--r--ufs-fsck/main.c170
-rw-r--r--ufs-fsck/pass1.c437
-rw-r--r--ufs-fsck/pass1b.c90
-rw-r--r--ufs-fsck/pass2.c400
-rw-r--r--ufs-fsck/pass3.c71
-rw-r--r--ufs-fsck/pass4.c94
-rw-r--r--ufs-fsck/pass5.c450
-rw-r--r--ufs-fsck/setup.c191
-rw-r--r--ufs-fsck/utilities.c455
-rw-r--r--ufs-utils/Makefile38
-rw-r--r--ufs-utils/clri.c168
-rw-r--r--ufs-utils/dlabel.c91
-rw-r--r--ufs-utils/mkfs.c1406
-rw-r--r--ufs-utils/newfs.c705
-rw-r--r--ufs-utils/stati.c260
-rw-r--r--ufs/Makefile32
-rw-r--r--ufs/alloc.c1703
-rw-r--r--ufs/bmap.c120
-rw-r--r--ufs/consts.c33
-rw-r--r--ufs/dinode.h137
-rw-r--r--ufs/dir.c988
-rw-r--r--ufs/dir.h163
-rw-r--r--ufs/fs.h509
-rw-r--r--ufs/hyper.c414
-rw-r--r--ufs/inode.c703
-rw-r--r--ufs/main.c210
-rw-r--r--ufs/pager.c806
-rw-r--r--ufs/pokeloc.c85
-rw-r--r--ufs/sizes.c719
-rw-r--r--ufs/subr.c264
-rw-r--r--ufs/tables.c138
-rw-r--r--ufs/ufs.h289
355 files changed, 44619 insertions, 0 deletions
diff --git a/.cvsignore b/.cvsignore
new file mode 100644
index 00000000..70845e08
--- /dev/null
+++ b/.cvsignore
@@ -0,0 +1 @@
+Makefile.in
diff --git a/README.CVS b/README.CVS
new file mode 100644
index 00000000..92a2392d
--- /dev/null
+++ b/README.CVS
@@ -0,0 +1,29 @@
+-*- Text -*-
+GNU Hurd CVS version.
+
+
+This is the Hurd. Welcome.
+
+For installation instructions, you might try your luck with the files
+README, INSTALL, and INSTALL-cross. However, they have not been
+updated for a long time.
+
+For now, this file documents the version requirements for the CVS
+version of the Hurd. Other combinations might work, but the stated
+minimum requirements are best tested by the developers.
+
+GNU MiG at least 1.3
+GNU Mach at least 1.3
+GNU C library CVS from 2004-03-09 or later
+GNU C compiler at least 3.3.2
+
+Optionally, a Sun RPC implementation is needed to build the NFS
+translator and daemon:
+
+GNU C library at most 2.13
+TI-RPC (currently fails to build on GNU, see
+ <http://lists.debian.org/debian-hurd/2010/12/msg00007.html>.)
+
+Obviously, you also need somewhat recent versions of binutils, make,
+bash and some other tools. No hard requirements are currently known
+for these, though.
diff --git a/bsdfsck/Makefile b/bsdfsck/Makefile
new file mode 100644
index 00000000..b5dcfbf2
--- /dev/null
+++ b/bsdfsck/Makefile
@@ -0,0 +1,31 @@
+#
+# Copyright (C) 1994, 1995 Free Software Foundation
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2, or (at
+# your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+dir := bsdfsck
+makemode := utility
+
+SRCS = dir.c inode.c main.c pass1.c pass1b.c pass2.c pass3.c pass4.c \
+ pass5.c setup.c utilities.c # preen.c
+OBJS = dir.o inode.o main.o pass1.o pass1b.o pass2.o pass3.o pass4.o \
+ pass5.o setup.o utilities.o tables.o # preen.o
+LCLHDRS = fsck.h
+target = bsdfsck
+
+vpath tables.c ../ufs
+
+include ../Makeconf
+
diff --git a/bsdfsck/dir.c b/bsdfsck/dir.c
new file mode 100644
index 00000000..e63473ae
--- /dev/null
+++ b/bsdfsck/dir.c
@@ -0,0 +1,690 @@
+/*
+ * Copyright (c) 1980, 1986, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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.
+ */
+
+#ifndef lint
+/*static char sccsid[] = "from: @(#)dir.c 8.1 (Berkeley) 6/5/93";*/
+static char *rcsid = "$Id: dir.c,v 1.5 1994/11/04 21:54:56 mib Exp $";
+#endif /* not lint */
+
+#include <sys/param.h>
+#include <sys/time.h>
+#include "../ufs/dinode.h"
+#include "../ufs/dir.h"
+#include "../ufs/fs.h"
+#include <stdlib.h>
+#include <string.h>
+#include "fsck.h"
+
+char *lfname = "lost+found";
+int lfmode = 01777;
+struct dirtemplate emptydir = { 0, DIRBLKSIZ };
+struct dirtemplate dirhead = {
+ 0, 12, DT_DIR, 1, ".",
+ 0, DIRBLKSIZ - 12, DT_DIR, 2, ".."
+};
+struct odirtemplate odirhead = {
+ 0, 12, 1, ".",
+ 0, DIRBLKSIZ - 12, 2, ".."
+};
+
+struct direct *fsck_readdir();
+struct bufarea *getdirblk();
+
+/*
+ * Propagate connected state through the tree.
+ */
+propagate()
+{
+ register struct inoinfo **inpp, *inp;
+ struct inoinfo **inpend;
+ long change;
+
+ inpend = &inpsort[inplast];
+ do {
+ change = 0;
+ for (inpp = inpsort; inpp < inpend; inpp++) {
+ inp = *inpp;
+ if (inp->i_parent == 0)
+ continue;
+ if (statemap[inp->i_parent] == DFOUND &&
+ statemap[inp->i_number] == DSTATE) {
+ statemap[inp->i_number] = DFOUND;
+ change++;
+ }
+ }
+ } while (change > 0);
+}
+
+/*
+ * Scan each entry in a directory block.
+ */
+dirscan(idesc)
+ register struct inodesc *idesc;
+{
+ register struct direct *dp;
+ register struct bufarea *bp;
+ int dsize, n;
+ long blksiz;
+ char dbuf[DIRBLKSIZ];
+
+ if (idesc->id_type != DATA)
+ errexit("wrong type to dirscan %d\n", idesc->id_type);
+ if (idesc->id_entryno == 0 &&
+ (idesc->id_filesize & (DIRBLKSIZ - 1)) != 0)
+ idesc->id_filesize = roundup(idesc->id_filesize, DIRBLKSIZ);
+ blksiz = idesc->id_numfrags * sblock.fs_fsize;
+ if (chkrange(idesc->id_blkno, idesc->id_numfrags)) {
+ idesc->id_filesize -= blksiz;
+ return (SKIP);
+ }
+ idesc->id_loc = 0;
+ for (dp = fsck_readdir(idesc); dp != NULL; dp = fsck_readdir(idesc)) {
+ dsize = dp->d_reclen;
+ bcopy((char *)dp, dbuf, (size_t)dsize);
+# if (BYTE_ORDER == LITTLE_ENDIAN)
+ if (!newinofmt) {
+ struct direct *tdp = (struct direct *)dbuf;
+ u_char tmp;
+
+ tmp = tdp->d_namlen;
+ tdp->d_namlen = tdp->d_type;
+ tdp->d_type = tmp;
+ }
+# endif
+ idesc->id_dirp = (struct direct *)dbuf;
+ if ((n = (*idesc->id_func)(idesc)) & ALTERED) {
+# if (BYTE_ORDER == LITTLE_ENDIAN)
+ if (!newinofmt && !doinglevel2) {
+ struct direct *tdp;
+ u_char tmp;
+
+ tdp = (struct direct *)dbuf;
+ tmp = tdp->d_namlen;
+ tdp->d_namlen = tdp->d_type;
+ tdp->d_type = tmp;
+ }
+# endif
+ bp = getdirblk(idesc->id_blkno, blksiz);
+ bcopy(dbuf, bp->b_un.b_buf + idesc->id_loc - dsize,
+ (size_t)dsize);
+ dirty(bp);
+ sbdirty();
+ }
+ if (n & STOP)
+ return (n);
+ }
+ return (idesc->id_filesize > 0 ? KEEPON : STOP);
+}
+
+/*
+ * get next entry in a directory.
+ */
+struct direct *
+fsck_readdir(idesc)
+ register struct inodesc *idesc;
+{
+ register struct direct *dp, *ndp;
+ register struct bufarea *bp;
+ long size, blksiz, fix, dploc;
+
+ blksiz = idesc->id_numfrags * sblock.fs_fsize;
+ bp = getdirblk(idesc->id_blkno, blksiz);
+ if (idesc->id_loc % DIRBLKSIZ == 0 && idesc->id_filesize > 0 &&
+ idesc->id_loc < blksiz) {
+ dp = (struct direct *)(bp->b_un.b_buf + idesc->id_loc);
+ if (dircheck(idesc, dp))
+ goto dpok;
+ fix = dofix(idesc, "DIRECTORY CORRUPTED");
+ bp = getdirblk(idesc->id_blkno, blksiz);
+ dp = (struct direct *)(bp->b_un.b_buf + idesc->id_loc);
+ dp->d_reclen = DIRBLKSIZ;
+ dp->d_ino = 0;
+ dp->d_type = 0;
+ dp->d_namlen = 0;
+ dp->d_name[0] = '\0';
+ if (fix)
+ dirty(bp);
+ idesc->id_loc += DIRBLKSIZ;
+ idesc->id_filesize -= DIRBLKSIZ;
+ return (dp);
+ }
+dpok:
+ if (idesc->id_filesize <= 0 || idesc->id_loc >= blksiz)
+ return NULL;
+ dploc = idesc->id_loc;
+ dp = (struct direct *)(bp->b_un.b_buf + dploc);
+ idesc->id_loc += dp->d_reclen;
+ idesc->id_filesize -= dp->d_reclen;
+ if ((idesc->id_loc % DIRBLKSIZ) == 0)
+ return (dp);
+ ndp = (struct direct *)(bp->b_un.b_buf + idesc->id_loc);
+ if (idesc->id_loc < blksiz && idesc->id_filesize > 0 &&
+ dircheck(idesc, ndp) == 0) {
+ size = DIRBLKSIZ - (idesc->id_loc % DIRBLKSIZ);
+ idesc->id_loc += size;
+ idesc->id_filesize -= size;
+ fix = dofix(idesc, "DIRECTORY CORRUPTED");
+ bp = getdirblk(idesc->id_blkno, blksiz);
+ dp = (struct direct *)(bp->b_un.b_buf + dploc);
+ dp->d_reclen += size;
+ if (fix)
+ dirty(bp);
+ }
+ return (dp);
+}
+
+/*
+ * Verify that a directory entry is valid.
+ * This is a superset of the checks made in the kernel.
+ */
+dircheck(idesc, dp)
+ struct inodesc *idesc;
+ register struct direct *dp;
+{
+ register int size;
+ register char *cp;
+ u_char namlen, type;
+ int spaceleft;
+ spaceleft = DIRBLKSIZ - (idesc->id_loc % DIRBLKSIZ);
+
+ if (dp->d_ino >= maxino ||
+ dp->d_reclen == 0 ||
+ dp->d_reclen > spaceleft ||
+ (dp->d_reclen & 0x3) != 0)
+ return (0);
+ if (dp->d_ino == 0)
+ return (1);
+ size = DIRSIZ(!newinofmt, dp);
+# if (BYTE_ORDER == LITTLE_ENDIAN)
+ if (!newinofmt) {
+ type = dp->d_namlen;
+ namlen = dp->d_type;
+ } else {
+ namlen = dp->d_namlen;
+ type = dp->d_type;
+ }
+# else
+ namlen = dp->d_namlen;
+ type = dp->d_type;
+# endif
+ if (dp->d_reclen < size ||
+ idesc->id_filesize < size ||
+ namlen > MAXNAMLEN ||
+ type > 15)
+ return (0);
+ for (cp = dp->d_name, size = 0; size < namlen; size++)
+ if (*cp == '\0' || (*cp++ == '/'))
+ return (0);
+ if (*cp != '\0')
+ return (0);
+ return (1);
+}
+
+direrror(ino, errmesg)
+ ino_t ino;
+ char *errmesg;
+{
+
+ fileerror(ino, ino, errmesg);
+}
+
+fileerror(cwd, ino, errmesg)
+ ino_t cwd, ino;
+ char *errmesg;
+{
+ register struct dinode *dp;
+ char pathbuf[MAXPATHLEN + 1];
+
+ pwarn("%s ", errmesg);
+ pinode(ino);
+ printf("\n");
+ getpathname(pathbuf, cwd, ino);
+ if (ino < ROOTINO || ino > maxino) {
+ pfatal("NAME=%s\n", pathbuf);
+ return;
+ }
+ dp = ginode(ino);
+ if (ftypeok(dp))
+ pfatal("%s=%s\n",
+ (DI_MODE(dp) & IFMT) == IFDIR ? "DIR" : "FILE", pathbuf);
+ else
+ pfatal("NAME=%s\n", pathbuf);
+}
+
+adjust(idesc, lcnt)
+ register struct inodesc *idesc;
+ short lcnt;
+{
+ register struct dinode *dp;
+
+ dp = ginode(idesc->id_number);
+ if (dp->di_nlink == lcnt) {
+ if (linkup(idesc->id_number, (ino_t)0) == 0)
+ clri(idesc, "UNREF", 0);
+ } else {
+ pwarn("LINK COUNT %s", (lfdir == idesc->id_number) ? lfname :
+ ((DI_MODE(dp) & IFMT) == IFDIR ? "DIR" : "FILE"));
+ pinode(idesc->id_number);
+ printf(" COUNT %d SHOULD BE %d",
+ dp->di_nlink, dp->di_nlink - lcnt);
+ if (preen) {
+ if (lcnt < 0) {
+ printf("\n");
+ pfatal("LINK COUNT INCREASING");
+ }
+ printf(" (ADJUSTED)\n");
+ }
+ if (preen || reply("ADJUST") == 1) {
+ dp->di_nlink -= lcnt;
+ inodirty();
+ }
+ }
+}
+
+mkentry(idesc)
+ struct inodesc *idesc;
+{
+ register struct direct *dirp = idesc->id_dirp;
+ struct direct newent;
+ int newlen, oldlen;
+
+ newent.d_namlen = strlen(idesc->id_name);
+ newlen = DIRSIZ(0, &newent);
+ if (dirp->d_ino != 0)
+ oldlen = DIRSIZ(0, dirp);
+ else
+ oldlen = 0;
+ if (dirp->d_reclen - oldlen < newlen)
+ return (KEEPON);
+ newent.d_reclen = dirp->d_reclen - oldlen;
+ dirp->d_reclen = oldlen;
+ dirp = (struct direct *)(((char *)dirp) + oldlen);
+ dirp->d_ino = idesc->id_parent; /* ino to be entered is in id_parent */
+ if (newinofmt) {
+ dirp->d_type = typemap[idesc->id_parent];
+ dirp->d_namlen = newent.d_namlen;
+ } else {
+# if (BYTE_ORDER == LITTLE_ENDIAN)
+ dirp->d_type = newent.d_namlen;
+ dirp->d_namlen = 0;
+# else
+ dirp->d_type = 0;
+ dirp->d_namlen = newent.d_namlen;
+# endif
+ }
+ dirp->d_reclen = newent.d_reclen;
+ bcopy(idesc->id_name, dirp->d_name, (size_t)newent.d_namlen + 1);
+ return (ALTERED|STOP);
+}
+
+chgino(idesc)
+ struct inodesc *idesc;
+{
+ register struct direct *dirp = idesc->id_dirp;
+
+ if (bcmp(dirp->d_name, idesc->id_name, (int)dirp->d_namlen + 1))
+ return (KEEPON);
+ dirp->d_ino = idesc->id_parent;
+ if (newinofmt)
+ dirp->d_type = typemap[idesc->id_parent];
+ else
+ dirp->d_type = 0;
+ return (ALTERED|STOP);
+}
+
+linkup(orphan, parentdir)
+ ino_t orphan;
+ ino_t parentdir;
+{
+ register struct dinode *dp;
+ int lostdir;
+ ino_t oldlfdir;
+ struct inodesc idesc;
+ char tempname[BUFSIZ];
+ extern int pass4check();
+
+ bzero((char *)&idesc, sizeof(struct inodesc));
+ dp = ginode(orphan);
+ lostdir = (DI_MODE(dp) & IFMT) == IFDIR;
+ pwarn("UNREF %s ", lostdir ? "DIR" : "FILE");
+ pinode(orphan);
+ if (preen && dp->di_size == 0)
+ return (0);
+ if (preen)
+ printf(" (RECONNECTED)\n");
+ else
+ if (reply("RECONNECT") == 0)
+ return (0);
+ if (lfdir == 0) {
+ dp = ginode(ROOTINO);
+ idesc.id_name = lfname;
+ idesc.id_type = DATA;
+ idesc.id_func = findino;
+ idesc.id_number = ROOTINO;
+ if ((ckinode(dp, &idesc) & FOUND) != 0) {
+ lfdir = idesc.id_parent;
+ } else {
+ pwarn("NO lost+found DIRECTORY");
+ if (preen || reply("CREATE")) {
+ lfdir = allocdir(ROOTINO, (ino_t)0, lfmode);
+ if (lfdir != 0) {
+ if (makeentry(ROOTINO, lfdir, lfname) != 0) {
+ if (preen)
+ printf(" (CREATED)\n");
+ } else {
+ freedir(lfdir, ROOTINO);
+ lfdir = 0;
+ if (preen)
+ printf("\n");
+ }
+ }
+ }
+ }
+ if (lfdir == 0) {
+ pfatal("SORRY. CANNOT CREATE lost+found DIRECTORY");
+ printf("\n\n");
+ return (0);
+ }
+ }
+ dp = ginode(lfdir);
+ if ((DI_MODE(dp) & IFMT) != IFDIR) {
+ pfatal("lost+found IS NOT A DIRECTORY");
+ if (reply("REALLOCATE") == 0)
+ return (0);
+ oldlfdir = lfdir;
+ if ((lfdir = allocdir(ROOTINO, (ino_t)0, lfmode)) == 0) {
+ pfatal("SORRY. CANNOT CREATE lost+found DIRECTORY\n\n");
+ return (0);
+ }
+ if ((changeino(ROOTINO, lfname, lfdir) & ALTERED) == 0) {
+ pfatal("SORRY. CANNOT CREATE lost+found DIRECTORY\n\n");
+ return (0);
+ }
+ inodirty();
+ idesc.id_type = ADDR;
+ idesc.id_func = pass4check;
+ idesc.id_number = oldlfdir;
+ adjust(&idesc, lncntp[oldlfdir] + 1);
+ lncntp[oldlfdir] = 0;
+ dp = ginode(lfdir);
+ }
+ if (statemap[lfdir] != DFOUND) {
+ pfatal("SORRY. NO lost+found DIRECTORY\n\n");
+ return (0);
+ }
+ (void)lftempname(tempname, orphan);
+ if (makeentry(lfdir, orphan, tempname) == 0) {
+ pfatal("SORRY. NO SPACE IN lost+found DIRECTORY");
+ printf("\n\n");
+ return (0);
+ }
+ lncntp[orphan]--;
+ if (lostdir) {
+ if ((changeino(orphan, "..", lfdir) & ALTERED) == 0 &&
+ parentdir != (ino_t)-1)
+ (void)makeentry(orphan, lfdir, "..");
+ dp = ginode(lfdir);
+ dp->di_nlink++;
+ inodirty();
+ lncntp[lfdir]++;
+ pwarn("DIR I=%lu CONNECTED. ", orphan);
+ if (parentdir != (ino_t)-1)
+ printf("PARENT WAS I=%lu\n", parentdir);
+ if (preen == 0)
+ printf("\n");
+ }
+ return (1);
+}
+
+/*
+ * fix an entry in a directory.
+ */
+changeino(dir, name, newnum)
+ ino_t dir;
+ char *name;
+ ino_t newnum;
+{
+ struct inodesc idesc;
+
+ bzero((char *)&idesc, sizeof(struct inodesc));
+ idesc.id_type = DATA;
+ idesc.id_func = chgino;
+ idesc.id_number = dir;
+ idesc.id_fix = DONTKNOW;
+ idesc.id_name = name;
+ idesc.id_parent = newnum; /* new value for name */
+ return (ckinode(ginode(dir), &idesc));
+}
+
+/*
+ * make an entry in a directory
+ */
+makeentry(parent, ino, name)
+ ino_t parent, ino;
+ char *name;
+{
+ struct dinode *dp;
+ struct inodesc idesc;
+ char pathbuf[MAXPATHLEN + 1];
+
+ if (parent < ROOTINO || parent >= maxino ||
+ ino < ROOTINO || ino >= maxino)
+ return (0);
+ bzero((char *)&idesc, sizeof(struct inodesc));
+ idesc.id_type = DATA;
+ idesc.id_func = mkentry;
+ idesc.id_number = parent;
+ idesc.id_parent = ino; /* this is the inode to enter */
+ idesc.id_fix = DONTKNOW;
+ idesc.id_name = name;
+ dp = ginode(parent);
+ if (dp->di_size % DIRBLKSIZ) {
+ dp->di_size = roundup(dp->di_size, DIRBLKSIZ);
+ inodirty();
+ }
+ if ((ckinode(dp, &idesc) & ALTERED) != 0)
+ return (1);
+ getpathname(pathbuf, parent, parent);
+ dp = ginode(parent);
+ if (expanddir(dp, pathbuf) == 0)
+ return (0);
+ return (ckinode(dp, &idesc) & ALTERED);
+}
+
+/*
+ * Attempt to expand the size of a directory
+ */
+expanddir(dp, name)
+ register struct dinode *dp;
+ char *name;
+{
+ daddr_t lastbn, newblk;
+ register struct bufarea *bp;
+ char *cp, firstblk[DIRBLKSIZ];
+
+ lastbn = lblkno(&sblock, dp->di_size);
+ if (lastbn >= NDADDR - 1 || dp->di_db[lastbn] == 0 || dp->di_size == 0)
+ return (0);
+ if ((newblk = allocblk(sblock.fs_frag)) == 0)
+ return (0);
+ dp->di_db[lastbn + 1] = dp->di_db[lastbn];
+ dp->di_db[lastbn] = newblk;
+ dp->di_size += sblock.fs_bsize;
+ dp->di_blocks += btodb(sblock.fs_bsize);
+ bp = getdirblk(dp->di_db[lastbn + 1],
+ (long)dblksize(&sblock, dp, lastbn + 1));
+ if (bp->b_errs)
+ goto bad;
+ bcopy(bp->b_un.b_buf, firstblk, DIRBLKSIZ);
+ bp = getdirblk(newblk, sblock.fs_bsize);
+ if (bp->b_errs)
+ goto bad;
+ bcopy(firstblk, bp->b_un.b_buf, DIRBLKSIZ);
+ for (cp = &bp->b_un.b_buf[DIRBLKSIZ];
+ cp < &bp->b_un.b_buf[sblock.fs_bsize];
+ cp += DIRBLKSIZ)
+ bcopy((char *)&emptydir, cp, sizeof emptydir);
+ dirty(bp);
+ bp = getdirblk(dp->di_db[lastbn + 1],
+ (long)dblksize(&sblock, dp, lastbn + 1));
+ if (bp->b_errs)
+ goto bad;
+ bcopy((char *)&emptydir, bp->b_un.b_buf, sizeof emptydir);
+ pwarn("NO SPACE LEFT IN %s", name);
+ if (preen)
+ printf(" (EXPANDED)\n");
+ else if (reply("EXPAND") == 0)
+ goto bad;
+ dirty(bp);
+ inodirty();
+ return (1);
+bad:
+ dp->di_db[lastbn] = dp->di_db[lastbn + 1];
+ dp->di_db[lastbn + 1] = 0;
+ dp->di_size -= sblock.fs_bsize;
+ dp->di_blocks -= btodb(sblock.fs_bsize);
+ freeblk(newblk, sblock.fs_frag);
+ return (0);
+}
+
+/*
+ * allocate a new directory
+ */
+allocdir(parent, request, mode)
+ ino_t parent, request;
+ int mode;
+{
+ ino_t ino;
+ char *cp;
+ struct dinode *dp;
+ register struct bufarea *bp;
+ struct dirtemplate *dirp;
+
+ ino = allocino(request, IFDIR|mode);
+ if (newinofmt)
+ dirp = &dirhead;
+ else
+ dirp = (struct dirtemplate *)&odirhead;
+ dirp->dot_ino = ino;
+ dirp->dotdot_ino = parent;
+ dp = ginode(ino);
+ bp = getdirblk(dp->di_db[0], sblock.fs_fsize);
+ if (bp->b_errs) {
+ freeino(ino);
+ return (0);
+ }
+ bcopy((char *)dirp, bp->b_un.b_buf, sizeof(struct dirtemplate));
+ for (cp = &bp->b_un.b_buf[DIRBLKSIZ];
+ cp < &bp->b_un.b_buf[sblock.fs_fsize];
+ cp += DIRBLKSIZ)
+ bcopy((char *)&emptydir, cp, sizeof emptydir);
+ dirty(bp);
+ dp->di_nlink = 2;
+ inodirty();
+ if (ino == ROOTINO) {
+ lncntp[ino] = dp->di_nlink;
+ cacheino(dp, ino);
+ return(ino);
+ }
+ if (statemap[parent] != DSTATE && statemap[parent] != DFOUND) {
+ freeino(ino);
+ return (0);
+ }
+ cacheino(dp, ino);
+ statemap[ino] = statemap[parent];
+ if (statemap[ino] == DSTATE) {
+ lncntp[ino] = dp->di_nlink;
+ lncntp[parent]++;
+ }
+ dp = ginode(parent);
+ dp->di_nlink++;
+ inodirty();
+ return (ino);
+}
+
+/*
+ * free a directory inode
+ */
+freedir(ino, parent)
+ ino_t ino, parent;
+{
+ struct dinode *dp;
+
+ if (ino != parent) {
+ dp = ginode(parent);
+ dp->di_nlink--;
+ inodirty();
+ }
+ freeino(ino);
+}
+
+/*
+ * generate a temporary name for the lost+found directory.
+ */
+lftempname(bufp, ino)
+ char *bufp;
+ ino_t ino;
+{
+ register ino_t in;
+ register char *cp;
+ int namlen;
+
+ cp = bufp + 2;
+ for (in = maxino; in > 0; in /= 10)
+ cp++;
+ *--cp = 0;
+ namlen = cp - bufp;
+ in = ino;
+ while (cp > bufp) {
+ *--cp = (in % 10) + '0';
+ in /= 10;
+ }
+ *cp = '#';
+ return (namlen);
+}
+
+/*
+ * Get a directory block.
+ * Insure that it is held until another is requested.
+ */
+struct bufarea *
+getdirblk(blkno, size)
+ daddr_t blkno;
+ long size;
+{
+
+ if (pdirbp != 0)
+ pdirbp->b_flags &= ~B_INUSE;
+ pdirbp = getdatablk(blkno, size);
+ return (pdirbp);
+}
diff --git a/bsdfsck/fsck.h b/bsdfsck/fsck.h
new file mode 100644
index 00000000..04bb7698
--- /dev/null
+++ b/bsdfsck/fsck.h
@@ -0,0 +1,303 @@
+/*
+ * Copyright (c) 1980, 1986, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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.
+ *
+ * from: @(#)fsck.h 8.1 (Berkeley) 6/5/93
+ * $Id: fsck.h,v 1.10 1994/10/05 17:09:06 mib Exp $
+ */
+
+/* Begin GNU Hurd */
+
+/* GNU ufs doesn't define struct direct, but fsck needs it. */
+#define direct directory_entry
+
+/* For GNU Hurd: the ufs DIRSIZ macro is different than the BSD
+ 4.4 version that fsck expects. So we provide here the BSD version. */
+#undef DIRSIZ
+#if (BYTE_ORDER == LITTLE_ENDIAN)
+#define DIRSIZ(oldfmt, dp) \
+ ((oldfmt) ? \
+ ((sizeof (struct direct) - (MAXNAMLEN+1)) + (((dp)->d_type+1 + 3) &~ 3)) : \
+ ((sizeof (struct direct) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3)))
+#else
+#define DIRSIZ(oldfmt, dp) \
+ ((sizeof (struct direct) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3))
+#endif
+
+/* GNU ufs has no need of struct dirtemplate; so provide the
+ BSD version here. */
+/*
+ * Template for manipulating directories.
+ * Should use struct direct's, but the name field
+ * is MAXNAMLEN - 1, and this just won't do.
+ */
+struct dirtemplate {
+ u_long dot_ino;
+ short dot_reclen;
+ u_char dot_type;
+ u_char dot_namlen;
+ char dot_name[4]; /* must be multiple of 4 */
+ u_long dotdot_ino;
+ short dotdot_reclen;
+ u_char dotdot_type;
+ u_char dotdot_namlen;
+ char dotdot_name[4]; /* ditto */
+};
+/*
+ * This is the old format of directories, sanz type element.
+ */
+struct odirtemplate {
+ u_long dot_ino;
+ short dot_reclen;
+ u_short dot_namlen;
+ char dot_name[4]; /* must be multiple of 4 */
+ u_long dotdot_ino;
+ short dotdot_reclen;
+ u_short dotdot_namlen;
+ char dotdot_name[4]; /* ditto */
+};
+
+/* These shouldn't be used by anyone, but fsck seems to need it */
+#define DEV_BSIZE 512
+#define MAXPATHLEN 1024
+
+/* Provide mode from struct dinode * */
+#define DI_MODE(dp) (((dp)->di_modeh << 16) | (dp)->di_model)
+
+#define NBBY 8
+
+#define MAXPHYS (64 * 1024)
+
+/* The fsck code in setup.c sets the fs_csp table which ufs doesn't want.
+ So here is the fs_cs macro from ufs for use when that table is real. */
+#undef fs_cs
+#define fs_cs(fs, indx) \
+ fs_csp[(indx) >> (fs)->fs_csshift][(indx) & ~(fs)->fs_csmask]
+
+#define dblksize(fs, dip, lbn) \
+ (((lbn) >= NDADDR || (dip)->di_size >= ((lbn) + 1) << (fs)->fs_bshift) \
+ ? (fs)->fs_bsize \
+ : (fragroundup(fs, blkoff(fs, (dip)->di_size))))
+
+/* Don't include dirent.h lest we get confused, but we still want this. */
+#define IFTODT(mode) (((mode) & 0170000) >> 12)
+#define DT_DIR IFTODT (IFDIR)
+
+/* missing macros */
+
+/* Convert bytes to disk blocks */
+#define btodb(bytes) ((bytes) / DEV_BSIZE)
+
+
+
+/* End GNU Hurd additions */
+
+
+#define MAXDUP 10 /* limit on dup blks (per inode) */
+#define MAXBAD 10 /* limit on bad blks (per inode) */
+#define MAXBUFSPACE 40*1024 /* maximum space to allocate to buffers */
+#define INOBUFSIZE 56*1024 /* size of buffer to read inodes in pass1 */
+
+#ifndef BUFSIZ
+#define BUFSIZ 1024
+#endif
+
+#define USTATE 01 /* inode not allocated */
+#define FSTATE 02 /* inode is file */
+#define DSTATE 03 /* inode is directory */
+#define DFOUND 04 /* directory found during descent */
+#define DCLEAR 05 /* directory is to be cleared */
+#define FCLEAR 06 /* file is to be cleared */
+
+/*
+ * buffer cache structure.
+ */
+struct bufarea {
+ struct bufarea *b_next; /* free list queue */
+ struct bufarea *b_prev; /* free list queue */
+ daddr_t b_bno;
+ int b_size;
+ int b_errs;
+ int b_flags;
+ union {
+ char *b_buf; /* buffer space */
+ daddr_t *b_indir; /* indirect block */
+ struct fs *b_fs; /* super block */
+ struct cg *b_cg; /* cylinder group */
+ struct dinode *b_dinode; /* inode block */
+ } b_un;
+ char b_dirty;
+};
+
+#define B_INUSE 1
+
+#define MINBUFS 5 /* minimum number of buffers required */
+struct bufarea bufhead; /* head of list of other blks in filesys */
+struct bufarea sblk; /* file system superblock */
+struct bufarea cgblk; /* cylinder group blocks */
+struct bufarea *pdirbp; /* current directory contents */
+struct bufarea *pbp; /* current inode block */
+struct bufarea *getdatablk();
+
+#define dirty(bp) (bp)->b_dirty = 1
+#define initbarea(bp) \
+ (bp)->b_dirty = 0; \
+ (bp)->b_bno = (daddr_t)-1; \
+ (bp)->b_flags = 0;
+
+#define sbdirty() sblk.b_dirty = 1
+#define cgdirty() cgblk.b_dirty = 1
+#define sblock (*sblk.b_un.b_fs)
+#define cgrp (*cgblk.b_un.b_cg)
+
+enum fixstate {DONTKNOW, NOFIX, FIX, IGNORE};
+
+struct inodesc {
+ enum fixstate id_fix; /* policy on fixing errors */
+ int (*id_func)(); /* function to be applied to blocks of inode */
+ ino_t id_number; /* inode number described */
+ ino_t id_parent; /* for DATA nodes, their parent */
+ daddr_t id_blkno; /* current block number being examined */
+ int id_numfrags; /* number of frags contained in block */
+ quad_t id_filesize; /* for DATA nodes, the size of the directory */
+ int id_loc; /* for DATA nodes, current location in dir */
+ int id_entryno; /* for DATA nodes, current entry number */
+ struct direct *id_dirp; /* for DATA nodes, ptr to current entry */
+ char *id_name; /* for DATA nodes, name to find or enter */
+ char id_type; /* type of descriptor, DATA or ADDR */
+};
+/* file types */
+#define DATA 1
+#define ADDR 2
+
+/*
+ * Linked list of duplicate blocks.
+ *
+ * The list is composed of two parts. The first part of the
+ * list (from duplist through the node pointed to by muldup)
+ * contains a single copy of each duplicate block that has been
+ * found. The second part of the list (from muldup to the end)
+ * contains duplicate blocks that have been found more than once.
+ * To check if a block has been found as a duplicate it is only
+ * necessary to search from duplist through muldup. To find the
+ * total number of times that a block has been found as a duplicate
+ * the entire list must be searched for occurrences of the block
+ * in question. The following diagram shows a sample list where
+ * w (found twice), x (found once), y (found three times), and z
+ * (found once) are duplicate block numbers:
+ *
+ * w -> y -> x -> z -> y -> w -> y
+ * ^ ^
+ * | |
+ * duplist muldup
+ */
+struct dups {
+ struct dups *next;
+ daddr_t dup;
+};
+struct dups *duplist; /* head of dup list */
+struct dups *muldup; /* end of unique duplicate dup block numbers */
+
+/*
+ * Linked list of inodes with zero link counts.
+ */
+struct zlncnt {
+ struct zlncnt *next;
+ ino_t zlncnt;
+};
+struct zlncnt *zlnhead; /* head of zero link count list */
+
+/*
+ * Inode cache data structures.
+ */
+struct inoinfo {
+ struct inoinfo *i_nexthash; /* next entry in hash chain */
+ ino_t i_number; /* inode number of this entry */
+ ino_t i_parent; /* inode number of parent */
+ ino_t i_dotdot; /* inode number of `..' */
+ size_t i_isize; /* size of inode */
+ u_int i_numblks; /* size of block array in bytes */
+ daddr_t i_blks[1]; /* actually longer */
+} **inphead, **inpsort;
+long numdirs, listmax, inplast;
+
+char *cdevname; /* name of device being checked */
+long dev_bsize; /* computed value of DEV_BSIZE */
+long secsize; /* actual disk sector size */
+char nflag; /* assume a no response */
+char yflag; /* assume a yes response */
+int bflag; /* location of alternate super block */
+int debug; /* output debugging info */
+int cvtlevel; /* convert to newer file system format */
+int doinglevel1; /* converting to new cylinder group format */
+int doinglevel2; /* converting to new inode format */
+int newinofmt; /* filesystem has new inode format */
+char preen; /* just fix normal inconsistencies */
+char hotroot; /* checking root device */
+char havesb; /* superblock has been read */
+int fsmodified; /* 1 => write done to file system */
+int fsreadfd; /* file descriptor for reading file system */
+int fswritefd; /* file descriptor for writing file system */
+
+daddr_t maxfsblock; /* number of blocks in the file system */
+char *blockmap; /* ptr to primary blk allocation map */
+ino_t maxino; /* number of inodes in file system */
+ino_t lastino; /* last inode in use */
+char *statemap; /* ptr to inode state table */
+char *typemap; /* ptr to inode type table */
+short *lncntp; /* ptr to link count table */
+
+ino_t lfdir; /* lost & found directory inode number */
+char *lfname; /* lost & found directory name */
+int lfmode; /* lost & found directory creation mode */
+
+daddr_t n_blks; /* number of blocks in use */
+daddr_t n_files; /* number of files in use */
+
+#define clearinode(dp) (*(dp) = zino)
+struct dinode zino;
+
+#define setbmap(blkno) setbit(blockmap, blkno)
+#define testbmap(blkno) isset(blockmap, blkno)
+#define clrbmap(blkno) clrbit(blockmap, blkno)
+
+#define STOP 0x01
+#define SKIP 0x02
+#define KEEPON 0x04
+#define ALTERED 0x08
+#define FOUND 0x10
+
+time_t time();
+struct dinode *ginode();
+struct inoinfo *getinoinfo();
+void getblk();
+ino_t allocino();
+int findino();
diff --git a/bsdfsck/inode.c b/bsdfsck/inode.c
new file mode 100644
index 00000000..7b48aef6
--- /dev/null
+++ b/bsdfsck/inode.c
@@ -0,0 +1,562 @@
+/*
+ * Copyright (c) 1980, 1986, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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.
+ */
+
+#ifndef lint
+/*static char sccsid[] = "from: @(#)inode.c 8.4 (Berkeley) 4/18/94";*/
+static char *rcsid = "$Id: inode.c,v 1.6 1994/10/05 17:05:30 mib Exp $";
+#endif /* not lint */
+
+#include <sys/param.h>
+#include <sys/time.h>
+#include "../ufs/dinode.h"
+#include "../ufs/dir.h"
+#include "../ufs/fs.h"
+#ifndef SMALL
+#include <pwd.h>
+#endif
+#include <stdlib.h>
+#include <string.h>
+#include "fsck.h"
+
+static ino_t startinum;
+
+ckinode(dp, idesc)
+ struct dinode *dp;
+ register struct inodesc *idesc;
+{
+ register daddr_t *ap;
+ long ret, n, ndb, offset;
+ struct dinode dino;
+ quad_t remsize, sizepb;
+ mode_t mode;
+
+ if (idesc->id_fix != IGNORE)
+ idesc->id_fix = DONTKNOW;
+ idesc->id_entryno = 0;
+ idesc->id_filesize = dp->di_size;
+ mode = DI_MODE(dp) & IFMT;
+ if (mode == IFBLK || mode == IFCHR
+ || (mode == IFLNK && sblock.fs_maxsymlinklen != -1 &&
+ (dp->di_size < sblock.fs_maxsymlinklen
+ || (sblock.fs_maxsymlinklen == 0 && dp->di_blocks == 0))))
+ return (KEEPON);
+ dino = *dp;
+ ndb = howmany(dino.di_size, sblock.fs_bsize);
+ for (ap = &dino.di_db[0]; ap < &dino.di_db[NDADDR]; ap++) {
+ if (--ndb == 0 && (offset = blkoff(&sblock, dino.di_size)) != 0)
+ idesc->id_numfrags =
+ numfrags(&sblock, fragroundup(&sblock, offset));
+ else
+ idesc->id_numfrags = sblock.fs_frag;
+ if (*ap == 0)
+ continue;
+ idesc->id_blkno = *ap;
+ if (idesc->id_type == ADDR)
+ ret = (*idesc->id_func)(idesc);
+ else
+ ret = dirscan(idesc);
+ if (ret & STOP)
+ return (ret);
+ }
+ idesc->id_numfrags = sblock.fs_frag;
+ remsize = dino.di_size - sblock.fs_bsize * NDADDR;
+ sizepb = sblock.fs_bsize;
+ for (ap = &dino.di_ib[0], n = 1; n <= NIADDR; ap++, n++) {
+ if (*ap) {
+ idesc->id_blkno = *ap;
+ ret = iblock(idesc, n, remsize);
+ if (ret & STOP)
+ return (ret);
+ }
+ sizepb *= NINDIR(&sblock);
+ remsize -= sizepb;
+ }
+ /* GNU Hurd extension. */
+ if (dino.di_trans && idesc->id_type == ADDR)
+ {
+ idesc->id_blkno = dino.di_trans;
+ idesc->id_numfrags = sblock.fs_frag;
+ return (*idesc->id_func)(idesc);
+ }
+ return (KEEPON);
+}
+
+iblock(idesc, ilevel, isize)
+ struct inodesc *idesc;
+ long ilevel;
+ quad_t isize;
+{
+ register daddr_t *ap;
+ register daddr_t *aplim;
+ register struct bufarea *bp;
+ int i, n, (*func)(), nif;
+ quad_t sizepb;
+ char buf[BUFSIZ];
+ extern int dirscan(), pass1check();
+
+ if (idesc->id_type == ADDR) {
+ func = idesc->id_func;
+ if (((n = (*func)(idesc)) & KEEPON) == 0)
+ return (n);
+ } else
+ func = dirscan;
+ if (chkrange(idesc->id_blkno, idesc->id_numfrags))
+ return (SKIP);
+ bp = getdatablk(idesc->id_blkno, sblock.fs_bsize);
+ ilevel--;
+ for (sizepb = sblock.fs_bsize, i = 0; i < ilevel; i++)
+ sizepb *= NINDIR(&sblock);
+ nif = howmany(isize , sizepb);
+ if (nif > NINDIR(&sblock))
+ nif = NINDIR(&sblock);
+ if (idesc->id_func == pass1check && nif < NINDIR(&sblock)) {
+ aplim = &bp->b_un.b_indir[NINDIR(&sblock)];
+ for (ap = &bp->b_un.b_indir[nif]; ap < aplim; ap++) {
+ if (*ap == 0)
+ continue;
+ (void)sprintf(buf, "PARTIALLY TRUNCATED INODE I=%lu",
+ idesc->id_number);
+ if (dofix(idesc, buf)) {
+ *ap = 0;
+ dirty(bp);
+ }
+ }
+ flush(fswritefd, bp);
+ }
+ aplim = &bp->b_un.b_indir[nif];
+ for (ap = bp->b_un.b_indir; ap < aplim; ap++) {
+ if (*ap) {
+ idesc->id_blkno = *ap;
+ if (ilevel == 0)
+ n = (*func)(idesc);
+ else
+ n = iblock(idesc, ilevel, isize);
+ if (n & STOP) {
+ bp->b_flags &= ~B_INUSE;
+ return (n);
+ }
+ }
+ isize -= sizepb;
+ }
+ bp->b_flags &= ~B_INUSE;
+ return (KEEPON);
+}
+
+/*
+ * Check that a block in a legal block number.
+ * Return 0 if in range, 1 if out of range.
+ */
+chkrange(blk, cnt)
+ daddr_t blk;
+ int cnt;
+{
+ register int c;
+
+ if ((unsigned)(blk + cnt) > maxfsblock)
+ return (1);
+ c = dtog(&sblock, blk);
+ if (blk < cgdmin(&sblock, c)) {
+ if ((blk + cnt) > cgsblock(&sblock, c)) {
+ if (debug) {
+ printf("blk %ld < cgdmin %ld;",
+ blk, cgdmin(&sblock, c));
+ printf(" blk + cnt %ld > cgsbase %ld\n",
+ blk + cnt, cgsblock(&sblock, c));
+ }
+ return (1);
+ }
+ } else {
+ if ((blk + cnt) > cgbase(&sblock, c+1)) {
+ if (debug) {
+ printf("blk %ld >= cgdmin %ld;",
+ blk, cgdmin(&sblock, c));
+ printf(" blk + cnt %ld > sblock.fs_fpg %ld\n",
+ blk+cnt, sblock.fs_fpg);
+ }
+ return (1);
+ }
+ }
+ return (0);
+}
+
+/*
+ * General purpose interface for reading inodes.
+ */
+struct dinode *
+ginode(inumber)
+ ino_t inumber;
+{
+ daddr_t iblk;
+
+ if (inumber < ROOTINO || inumber > maxino)
+ errexit("bad inode number %d to ginode\n", inumber);
+ if (startinum == 0 ||
+ inumber < startinum || inumber >= startinum + INOPB(&sblock)) {
+ iblk = ino_to_fsba(&sblock, inumber);
+ if (pbp != 0)
+ pbp->b_flags &= ~B_INUSE;
+ pbp = getdatablk(iblk, sblock.fs_bsize);
+ startinum = (inumber / INOPB(&sblock)) * INOPB(&sblock);
+ }
+ return (&pbp->b_un.b_dinode[inumber % INOPB(&sblock)]);
+}
+
+/*
+ * Special purpose version of ginode used to optimize first pass
+ * over all the inodes in numerical order.
+ */
+ino_t nextino, lastinum;
+long readcnt, readpercg, fullcnt, inobufsize, partialcnt, partialsize;
+struct dinode *inodebuf;
+
+struct dinode *
+getnextinode(inumber)
+ ino_t inumber;
+{
+ long size;
+ daddr_t dblk;
+ static struct dinode *dp;
+
+ if (inumber != nextino++ || inumber > maxino)
+ errexit("bad inode number %d to nextinode\n", inumber);
+ if (inumber >= lastinum) {
+ readcnt++;
+ dblk = fsbtodb(&sblock, ino_to_fsba(&sblock, lastinum));
+ if (readcnt % readpercg == 0) {
+ size = partialsize;
+ lastinum += partialcnt;
+ } else {
+ size = inobufsize;
+ lastinum += fullcnt;
+ }
+ (void)bread(fsreadfd, (char *)inodebuf, dblk, size); /* ??? */
+ dp = inodebuf;
+ }
+ return (dp++);
+}
+
+resetinodebuf()
+{
+
+ startinum = 0;
+ nextino = 0;
+ lastinum = 0;
+ readcnt = 0;
+ inobufsize = blkroundup(&sblock, INOBUFSIZE);
+ fullcnt = inobufsize / sizeof(struct dinode);
+ readpercg = sblock.fs_ipg / fullcnt;
+ partialcnt = sblock.fs_ipg % fullcnt;
+ partialsize = partialcnt * sizeof(struct dinode);
+ if (partialcnt != 0) {
+ readpercg++;
+ } else {
+ partialcnt = fullcnt;
+ partialsize = inobufsize;
+ }
+ if (inodebuf == NULL &&
+ (inodebuf = (struct dinode *)malloc((unsigned)inobufsize)) == NULL)
+ errexit("Cannot allocate space for inode buffer\n");
+ while (nextino < ROOTINO)
+ (void)getnextinode(nextino);
+}
+
+freeinodebuf()
+{
+
+ if (inodebuf != NULL)
+ free((char *)inodebuf);
+ inodebuf = NULL;
+}
+
+/*
+ * Routines to maintain information about directory inodes.
+ * This is built during the first pass and used during the
+ * second and third passes.
+ *
+ * Enter inodes into the cache.
+ */
+cacheino(dp, inumber)
+ register struct dinode *dp;
+ ino_t inumber;
+{
+ register struct inoinfo *inp;
+ struct inoinfo **inpp;
+ unsigned int blks;
+
+ blks = howmany(dp->di_size, sblock.fs_bsize);
+ if (blks > NDADDR)
+ blks = NDADDR + NIADDR;
+ inp = (struct inoinfo *)
+ malloc(sizeof(*inp) + (blks - 1) * sizeof(daddr_t));
+ if (inp == NULL)
+ return;
+ inpp = &inphead[inumber % numdirs];
+ inp->i_nexthash = *inpp;
+ *inpp = inp;
+ inp->i_parent = (ino_t)0;
+ inp->i_dotdot = (ino_t)0;
+ inp->i_number = inumber;
+ inp->i_isize = dp->di_size;
+ inp->i_numblks = blks * sizeof(daddr_t);
+ bcopy((char *)&dp->di_db[0], (char *)&inp->i_blks[0],
+ (size_t)inp->i_numblks);
+ if (inplast == listmax) {
+ listmax += 100;
+ inpsort = (struct inoinfo **)realloc((char *)inpsort,
+ (unsigned)listmax * sizeof(struct inoinfo *));
+ if (inpsort == NULL)
+ errexit("cannot increase directory list");
+ }
+ inpsort[inplast++] = inp;
+}
+
+/*
+ * Look up an inode cache structure.
+ */
+struct inoinfo *
+getinoinfo(inumber)
+ ino_t inumber;
+{
+ register struct inoinfo *inp;
+
+ for (inp = inphead[inumber % numdirs]; inp; inp = inp->i_nexthash) {
+ if (inp->i_number != inumber)
+ continue;
+ return (inp);
+ }
+ errexit("cannot find inode %d\n", inumber);
+ return ((struct inoinfo *)0);
+}
+
+/*
+ * Clean up all the inode cache structure.
+ */
+inocleanup()
+{
+ register struct inoinfo **inpp;
+
+ if (inphead == NULL)
+ return;
+ for (inpp = &inpsort[inplast - 1]; inpp >= inpsort; inpp--)
+ free((char *)(*inpp));
+ free((char *)inphead);
+ free((char *)inpsort);
+ inphead = inpsort = NULL;
+}
+
+inodirty()
+{
+
+ dirty(pbp);
+}
+
+clri(idesc, type, flag)
+ register struct inodesc *idesc;
+ char *type;
+ int flag;
+{
+ register struct dinode *dp;
+
+ dp = ginode(idesc->id_number);
+ if (flag == 1) {
+ pwarn("%s %s", type,
+ (DI_MODE(dp) & IFMT) == IFDIR ? "DIR" : "FILE");
+ pinode(idesc->id_number);
+ }
+ if (preen || reply("CLEAR") == 1) {
+ if (preen)
+ printf(" (CLEARED)\n");
+ n_files--;
+ (void)ckinode(dp, idesc);
+ clearinode(dp);
+ statemap[idesc->id_number] = USTATE;
+ inodirty();
+ }
+}
+
+findname(idesc)
+ struct inodesc *idesc;
+{
+ register struct direct *dirp = idesc->id_dirp;
+
+ if (dirp->d_ino != idesc->id_parent)
+ return (KEEPON);
+ bcopy(dirp->d_name, idesc->id_name, (size_t)dirp->d_namlen + 1);
+ return (STOP|FOUND);
+}
+
+findino(idesc)
+ struct inodesc *idesc;
+{
+ register struct direct *dirp = idesc->id_dirp;
+
+ if (dirp->d_ino == 0)
+ return (KEEPON);
+ if (strcmp(dirp->d_name, idesc->id_name) == 0 &&
+ dirp->d_ino >= ROOTINO && dirp->d_ino <= maxino) {
+ idesc->id_parent = dirp->d_ino;
+ return (STOP|FOUND);
+ }
+ return (KEEPON);
+}
+
+pinode(ino)
+ ino_t ino;
+{
+ register struct dinode *dp;
+ register char *p;
+ struct passwd *pw;
+ char *ctime();
+
+ printf(" I=%lu ", ino);
+ if (ino < ROOTINO || ino > maxino)
+ return;
+ dp = ginode(ino);
+ printf(" OWNER=");
+#ifndef SMALL
+ if ((pw = getpwuid((int)dp->di_uid)) != 0)
+ printf("%s ", pw->pw_name);
+ else
+#endif
+ printf("%u ", (unsigned)dp->di_uid);
+ printf("MODE=%o\n", DI_MODE(dp));
+ if (preen)
+ printf("%s: ", cdevname);
+ printf("SIZE=%qu ", dp->di_size);
+ p = ctime(&dp->di_mtime.ts_sec);
+ printf("MTIME=%12.12s %4.4s ", &p[4], &p[20]);
+}
+
+blkerror(ino, type, blk)
+ ino_t ino;
+ char *type;
+ daddr_t blk;
+{
+
+ pfatal("%ld %s I=%lu", blk, type, ino);
+ printf("\n");
+ switch (statemap[ino]) {
+
+ case FSTATE:
+ statemap[ino] = FCLEAR;
+ return;
+
+ case DSTATE:
+ statemap[ino] = DCLEAR;
+ return;
+
+ case FCLEAR:
+ case DCLEAR:
+ return;
+
+ default:
+ errexit("BAD STATE %d TO BLKERR", statemap[ino]);
+ /* NOTREACHED */
+ }
+}
+
+/*
+ * allocate an unused inode
+ */
+ino_t
+allocino(request, type)
+ ino_t request;
+ int type;
+{
+ register ino_t ino;
+ register struct dinode *dp;
+
+ if (request == 0)
+ request = ROOTINO;
+ else if (statemap[request] != USTATE)
+ return (0);
+ for (ino = request; ino < maxino; ino++)
+ if (statemap[ino] == USTATE)
+ break;
+ if (ino == maxino)
+ return (0);
+ switch (type & IFMT) {
+ case IFDIR:
+ statemap[ino] = DSTATE;
+ break;
+ case IFREG:
+ case IFLNK:
+ statemap[ino] = FSTATE;
+ break;
+ default:
+ return (0);
+ }
+ dp = ginode(ino);
+ dp->di_db[0] = allocblk((long)1);
+ if (dp->di_db[0] == 0) {
+ statemap[ino] = USTATE;
+ return (0);
+ }
+#if 0
+ dp->di_mode = type;
+#else
+ dp->di_modeh = (type & 0xffff0000) >> 16;
+ dp->di_model = (type & 0x0000ffff);
+#endif
+ (void)time(&dp->di_atime.ts_sec);
+ dp->di_mtime = dp->di_ctime = dp->di_atime;
+ dp->di_size = sblock.fs_fsize;
+ dp->di_blocks = btodb(sblock.fs_fsize);
+ n_files++;
+ inodirty();
+ if (newinofmt)
+ typemap[ino] = IFTODT(type);
+ return (ino);
+}
+
+/*
+ * deallocate an inode
+ */
+freeino(ino)
+ ino_t ino;
+{
+ struct inodesc idesc;
+ extern int pass4check();
+ struct dinode *dp;
+
+ bzero((char *)&idesc, sizeof(struct inodesc));
+ idesc.id_type = ADDR;
+ idesc.id_func = pass4check;
+ idesc.id_number = ino;
+ dp = ginode(ino);
+ (void)ckinode(dp, &idesc);
+ clearinode(dp);
+ inodirty();
+ statemap[ino] = USTATE;
+ n_files--;
+}
diff --git a/bsdfsck/main.c b/bsdfsck/main.c
new file mode 100644
index 00000000..adf84f74
--- /dev/null
+++ b/bsdfsck/main.c
@@ -0,0 +1,333 @@
+/*
+ * Copyright (c) 1980, 1986, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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.
+ */
+
+#ifndef lint
+static char copyright[] =
+"@(#) Copyright (c) 1980, 1986, 1993\n\
+ The Regents of the University of California. All rights reserved.\n";
+#endif /* not lint */
+
+#ifndef lint
+/*static char sccsid[] = "from: @(#)main.c 8.2 (Berkeley) 1/23/94";*/
+static char *rcsid = "$Id: main.c,v 1.4 1994/08/26 18:06:30 mib Exp $";
+#endif /* not lint */
+
+#include <sys/param.h>
+#include <sys/time.h>
+/*#include <sys/mount.h> */
+#include "../ufs/dinode.h"
+#include "../ufs/fs.h"
+/* #include <fstab.h> */
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <stdio.h>
+#include "fsck.h"
+
+void catch(), catchquit(), voidquit();
+int returntosingle;
+
+/* GNU Hurd patch */
+#define blockcheck(a) (a)
+
+main(argc, argv)
+ int argc;
+ char *argv[];
+{
+ int ch;
+ int ret, maxrun = 0;
+ extern int docheck(), checkfilesys();
+ extern char *optarg;
+/* extern char *blockcheck(); */
+ extern int optind;
+
+ sync();
+ while ((ch = getopt(argc, argv, "dpnNyYb:c:l:m:")) != EOF) {
+ switch (ch) {
+ case 'p':
+ preen++;
+ break;
+
+ case 'b':
+ bflag = argtoi('b', "number", optarg, 10);
+ printf("Alternate super block location: %d\n", bflag);
+ break;
+
+ case 'c':
+ cvtlevel = argtoi('c', "conversion level", optarg, 10);
+ break;
+
+ case 'd':
+ debug++;
+ break;
+
+ case 'l':
+ maxrun = argtoi('l', "number", optarg, 10);
+ break;
+
+ case 'm':
+ lfmode = argtoi('m', "mode", optarg, 8);
+ if (lfmode &~ 07777)
+ errexit("bad mode to -m: %o\n", lfmode);
+ printf("** lost+found creation mode %o\n", lfmode);
+ break;
+
+ case 'n':
+ case 'N':
+ nflag++;
+ yflag = 0;
+ break;
+
+ case 'y':
+ case 'Y':
+ yflag++;
+ nflag = 0;
+ break;
+
+ default:
+ errexit("%c option?\n", ch);
+ }
+ }
+ argc -= optind;
+ argv += optind;
+ if (signal(SIGINT, SIG_IGN) != SIG_IGN)
+ (void)signal(SIGINT, catch);
+ if (preen)
+ (void)signal(SIGQUIT, catchquit);
+ if (argc) {
+ while (argc-- > 0)
+ (void)checkfilesys(blockcheck(*argv++), 0, 0L, 0);
+ exit(0);
+ }
+ fprintf (stderr, "You must explicitly name the filesystem to check\n");
+ exit (1);
+#if 0
+ ret = checkfstab(preen, maxrun, docheck, checkfilesys);
+ if (returntosingle)
+ exit(2);
+ exit(ret);
+#endif
+}
+
+argtoi(flag, req, str, base)
+ int flag;
+ char *req, *str;
+ int base;
+{
+ char *cp;
+ int ret;
+
+ ret = (int)strtol(str, &cp, base);
+ if (cp == str || *cp)
+ errexit("-%c flag requires a %s\n", flag, req);
+ return (ret);
+}
+
+#if 0
+/*
+ * Determine whether a filesystem should be checked.
+ */
+docheck(fsp)
+ register struct fstab *fsp;
+{
+
+ if (strcmp(fsp->fs_vfstype, "ufs") ||
+ (strcmp(fsp->fs_type, FSTAB_RW) &&
+ strcmp(fsp->fs_type, FSTAB_RO)) ||
+ fsp->fs_passno == 0)
+ return (0);
+ return (1);
+}
+#endif
+
+/*
+ * Check the specified filesystem.
+ */
+/* ARGSUSED */
+checkfilesys(filesys, mntpt, auxdata, child)
+ char *filesys, *mntpt;
+ long auxdata;
+{
+ daddr_t n_ffree, n_bfree;
+ struct dups *dp;
+ struct zlncnt *zlnp;
+ int cylno;
+
+ if (preen && child)
+ (void)signal(SIGQUIT, voidquit);
+ cdevname = filesys;
+ if (debug && preen)
+ pwarn("starting\n");
+ if (setup(filesys) == 0) {
+ if (preen)
+ pfatal("CAN'T CHECK FILE SYSTEM.");
+ return (0);
+ }
+ /*
+ * 1: scan inodes tallying blocks used
+ */
+ if (preen == 0) {
+ printf("** Last Mounted on %s\n", sblock.fs_fsmnt);
+#if 0
+ if (hotroot)
+ printf("** Root file system\n");
+#endif
+ printf("** Phase 1 - Check Blocks and Sizes\n");
+ }
+ pass1();
+
+ /*
+ * 1b: locate first references to duplicates, if any
+ */
+ if (duplist) {
+ if (preen)
+ pfatal("INTERNAL ERROR: dups with -p");
+ printf("** Phase 1b - Rescan For More DUPS\n");
+ pass1b();
+ }
+
+ /*
+ * 2: traverse directories from root to mark all connected directories
+ */
+ if (preen == 0)
+ printf("** Phase 2 - Check Pathnames\n");
+ pass2();
+
+ /*
+ * 3: scan inodes looking for disconnected directories
+ */
+ if (preen == 0)
+ printf("** Phase 3 - Check Connectivity\n");
+ pass3();
+
+ /*
+ * 4: scan inodes looking for disconnected files; check reference counts
+ */
+ if (preen == 0)
+ printf("** Phase 4 - Check Reference Counts\n");
+ pass4();
+
+ /*
+ * 5: check and repair resource counts in cylinder groups
+ */
+ if (preen == 0)
+ printf("** Phase 5 - Check Cyl groups\n");
+ pass5();
+
+ /*
+ * print out summary statistics
+ */
+ n_ffree = sblock.fs_cstotal.cs_nffree;
+ n_bfree = sblock.fs_cstotal.cs_nbfree;
+ pwarn("%ld files, %ld used, %ld free ",
+ n_files, n_blks, n_ffree + sblock.fs_frag * n_bfree);
+ printf("(%ld frags, %ld blocks, %d.%d%% fragmentation)\n",
+ n_ffree, n_bfree, (n_ffree * 100) / sblock.fs_dsize,
+ ((n_ffree * 1000 + sblock.fs_dsize / 2) / sblock.fs_dsize) % 10);
+ if (debug &&
+ (n_files -= maxino - ROOTINO - sblock.fs_cstotal.cs_nifree))
+ printf("%ld files missing\n", n_files);
+ if (debug) {
+ n_blks += sblock.fs_ncg *
+ (cgdmin(&sblock, 0) - cgsblock(&sblock, 0));
+ n_blks += cgsblock(&sblock, 0) - cgbase(&sblock, 0);
+ n_blks += howmany(sblock.fs_cssize, sblock.fs_fsize);
+ if (n_blks -= maxfsblock - (n_ffree + sblock.fs_frag * n_bfree))
+ printf("%ld blocks missing\n", n_blks);
+ if (duplist != NULL) {
+ printf("The following duplicate blocks remain:");
+ for (dp = duplist; dp; dp = dp->next)
+ printf(" %ld,", dp->dup);
+ printf("\n");
+ }
+ if (zlnhead != NULL) {
+ printf("The following zero link count inodes remain:");
+ for (zlnp = zlnhead; zlnp; zlnp = zlnp->next)
+ printf(" %lu,", zlnp->zlncnt);
+ printf("\n");
+ }
+ }
+ zlnhead = (struct zlncnt *)0;
+ duplist = (struct dups *)0;
+ muldup = (struct dups *)0;
+ inocleanup();
+ if (fsmodified) {
+ (void)time(&sblock.fs_time);
+ sbdirty();
+ }
+ if (cvtlevel && sblk.b_dirty) {
+ /*
+ * Write out the duplicate super blocks
+ */
+ for (cylno = 0; cylno < sblock.fs_ncg; cylno++)
+ bwrite(fswritefd, (char *)&sblock,
+ fsbtodb(&sblock, cgsblock(&sblock, cylno)), SBSIZE);
+ }
+ ckfini();
+ free(blockmap);
+ free(statemap);
+ free((char *)lncntp);
+ if (!fsmodified)
+ return (0);
+ if (!preen)
+ printf("\n***** FILE SYSTEM WAS MODIFIED *****\n");
+#if 0
+ if (hotroot) {
+ struct statfs stfs_buf;
+ /*
+ * We modified the root. Do a mount update on
+ * it, unless it is read-write, so we can continue.
+ */
+ if (statfs("/", &stfs_buf) == 0) {
+ long flags = stfs_buf.f_flags;
+ struct ufs_args args;
+ int ret;
+
+ if (flags & MNT_RDONLY) {
+ args.fspec = 0;
+ args.export.ex_flags = 0;
+ args.export.ex_root = 0;
+ flags |= MNT_UPDATE | MNT_RELOAD;
+ ret = mount(MOUNT_UFS, "/", flags, &args);
+ if (ret == 0)
+ return(0);
+ }
+ }
+ if (!preen)
+ printf("\n***** REBOOT NOW *****\n");
+ sync();
+ return (4);
+ }
+#endif
+ return (0);
+}
diff --git a/bsdfsck/pass1.c b/bsdfsck/pass1.c
new file mode 100644
index 00000000..46b0e109
--- /dev/null
+++ b/bsdfsck/pass1.c
@@ -0,0 +1,331 @@
+/*
+ * Copyright (c) 1980, 1986, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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.
+ */
+
+#ifndef lint
+/*static char sccsid[] = "from: @(#)pass1.c 8.1 (Berkeley) 6/5/93";*/
+static char *rcsid = "$Id: pass1.c,v 1.4 1994/10/05 16:53:12 mib Exp $";
+#endif /* not lint */
+
+#include <sys/param.h>
+#include <sys/time.h>
+#include "../ufs/dinode.h"
+#include "../ufs/dir.h"
+#include "../ufs/fs.h"
+#include <stdlib.h>
+#include <string.h>
+#include "fsck.h"
+
+static daddr_t badblk;
+static daddr_t dupblk;
+int pass1check();
+struct dinode *getnextinode();
+
+pass1()
+{
+ ino_t inumber;
+ int c, i, cgd;
+ struct inodesc idesc;
+
+ /*
+ * Set file system reserved blocks in used block map.
+ */
+ for (c = 0; c < sblock.fs_ncg; c++) {
+ cgd = cgdmin(&sblock, c);
+ if (c == 0) {
+ i = cgbase(&sblock, c);
+ cgd += howmany(sblock.fs_cssize, sblock.fs_fsize);
+ } else
+ i = cgsblock(&sblock, c);
+ for (; i < cgd; i++)
+ setbmap(i);
+ }
+ /*
+ * Find all allocated blocks.
+ */
+ bzero((char *)&idesc, sizeof(struct inodesc));
+ idesc.id_type = ADDR;
+ idesc.id_func = pass1check;
+ inumber = 0;
+ n_files = n_blks = 0;
+ resetinodebuf();
+ for (c = 0; c < sblock.fs_ncg; c++) {
+ for (i = 0; i < sblock.fs_ipg; i++, inumber++) {
+ if (inumber < ROOTINO)
+ continue;
+ checkinode(inumber, &idesc);
+ }
+ }
+ freeinodebuf();
+}
+
+checkinode(inumber, idesc)
+ ino_t inumber;
+ register struct inodesc *idesc;
+{
+ register struct dinode *dp;
+ struct zlncnt *zlnp;
+ int ndb, j;
+ mode_t mode;
+ char *symbuf;
+
+ dp = getnextinode(inumber);
+ mode = DI_MODE(dp) & IFMT;
+ if (mode == 0) {
+ /* Check for DI_TRANS here is a GNU Hurd addition. */
+ if (bcmp((char *)dp->di_db, (char *)zino.di_db,
+ NDADDR * sizeof(daddr_t)) ||
+ bcmp((char *)dp->di_ib, (char *)zino.di_ib,
+ NIADDR * sizeof(daddr_t)) ||
+ DI_MODE(dp) || dp->di_size || dp->di_trans) {
+ pfatal("PARTIALLY ALLOCATED INODE I=%lu", inumber);
+ if (reply("CLEAR") == 1) {
+ dp = ginode(inumber);
+ clearinode(dp);
+ inodirty();
+ }
+ }
+ statemap[inumber] = USTATE;
+ return;
+ }
+ lastino = inumber;
+ if (/* dp->di_size < 0 || */
+ dp->di_size + sblock.fs_bsize - 1 < dp->di_size) {
+ if (debug)
+ printf("bad size %qu:", dp->di_size);
+ goto unknown;
+ }
+ if (!preen && mode == IFMT && reply("HOLD BAD BLOCK") == 1) {
+ dp = ginode(inumber);
+ dp->di_size = sblock.fs_fsize;
+#if 0
+ dp->di_mode = IFREG|0600;
+#else
+ dp->di_modeh = 0;
+ dp->di_model = IFREG|0600;
+#endif
+ inodirty();
+ }
+ ndb = howmany(dp->di_size, sblock.fs_bsize);
+ if (ndb < 0) {
+ if (debug)
+ printf("bad size %qu ndb %d:",
+ dp->di_size, ndb);
+ goto unknown;
+ }
+ if (mode == IFBLK || mode == IFCHR)
+ ndb++;
+ if (mode == IFLNK) {
+ /*
+ * Note that the old fastlink format always had di_blocks set
+ * to 0. Other than that we no longer use the `spare' field
+ * (which is now the extended uid) for sanity checking, the
+ * new format is the same as the old. We simply ignore the
+ * conversion altogether. - mycroft, 19MAY1994
+ */
+ if (doinglevel2 &&
+ dp->di_size > 0 && dp->di_size < MAXSYMLINKLEN &&
+ dp->di_blocks != 0) {
+ symbuf = alloca(secsize);
+ if (bread(fsreadfd, symbuf,
+ fsbtodb(&sblock, dp->di_db[0]),
+ (long)secsize) != 0)
+ errexit("cannot read symlink");
+ if (debug) {
+ symbuf[dp->di_size] = 0;
+ printf("convert symlink %d(%s) of size %d\n",
+ inumber, symbuf, (long)dp->di_size);
+ }
+ dp = ginode(inumber);
+ bcopy(symbuf, (caddr_t)dp->di_shortlink,
+ (long)dp->di_size);
+ dp->di_blocks = 0;
+ inodirty();
+ }
+ /*
+ * Fake ndb value so direct/indirect block checks below
+ * will detect any garbage after symlink string.
+ */
+ if (sblock.fs_maxsymlinklen != -1 &&
+ (dp->di_size < sblock.fs_maxsymlinklen ||
+ (sblock.fs_maxsymlinklen == 0 && dp->di_blocks == 0))) {
+ ndb = howmany(dp->di_size, sizeof(daddr_t));
+ if (ndb > NDADDR) {
+ j = ndb - NDADDR;
+ for (ndb = 1; j > 1; j--)
+ ndb *= NINDIR(&sblock);
+ ndb += NDADDR;
+ }
+ }
+ }
+ for (j = ndb; j < NDADDR; j++)
+ if (dp->di_db[j] != 0) {
+ if (debug)
+ printf("bad direct addr: %ld\n", dp->di_db[j]);
+ goto unknown;
+ }
+ for (j = 0, ndb -= NDADDR; ndb > 0; j++)
+ ndb /= NINDIR(&sblock);
+ for (; j < NIADDR; j++)
+ if (dp->di_ib[j] != 0) {
+ if (debug)
+ printf("bad indirect addr: %ld\n",
+ dp->di_ib[j]);
+ goto unknown;
+ }
+ if (ftypeok(dp) == 0)
+ goto unknown;
+ n_files++;
+ lncntp[inumber] = dp->di_nlink;
+ if (dp->di_nlink <= 0) {
+ zlnp = (struct zlncnt *)malloc(sizeof *zlnp);
+ if (zlnp == NULL) {
+ pfatal("LINK COUNT TABLE OVERFLOW");
+ if (reply("CONTINUE") == 0)
+ errexit("");
+ } else {
+ zlnp->zlncnt = inumber;
+ zlnp->next = zlnhead;
+ zlnhead = zlnp;
+ }
+ }
+ if (mode == IFDIR) {
+ if (dp->di_size == 0)
+ statemap[inumber] = DCLEAR;
+ else
+ statemap[inumber] = DSTATE;
+ cacheino(dp, inumber);
+ } else
+ statemap[inumber] = FSTATE;
+ typemap[inumber] = IFTODT(mode);
+ if (doinglevel2 &&
+ (dp->di_ouid != (u_short)-1 || dp->di_ogid != (u_short)-1)) {
+ dp = ginode(inumber);
+ dp->di_uid = dp->di_ouid;
+ dp->di_ouid = -1;
+ dp->di_gid = dp->di_ogid;
+ dp->di_ogid = -1;
+ inodirty();
+ }
+ badblk = dupblk = 0;
+ idesc->id_number = inumber;
+ (void)ckinode(dp, idesc);
+ idesc->id_entryno *= btodb(sblock.fs_fsize);
+ if (dp->di_blocks != idesc->id_entryno) {
+ pwarn("INCORRECT BLOCK COUNT I=%lu (%ld should be %ld)",
+ inumber, dp->di_blocks, idesc->id_entryno);
+ if (preen)
+ printf(" (CORRECTED)\n");
+ else if (reply("CORRECT") == 0)
+ return;
+ dp = ginode(inumber);
+ dp->di_blocks = idesc->id_entryno;
+ inodirty();
+ }
+ return;
+unknown:
+ pfatal("UNKNOWN FILE TYPE I=%lu", inumber);
+ statemap[inumber] = FCLEAR;
+ if (reply("CLEAR") == 1) {
+ statemap[inumber] = USTATE;
+ dp = ginode(inumber);
+ clearinode(dp);
+ inodirty();
+ }
+}
+
+pass1check(idesc)
+ register struct inodesc *idesc;
+{
+ int res = KEEPON;
+ int anyout, nfrags;
+ daddr_t blkno = idesc->id_blkno;
+ register struct dups *dlp;
+ struct dups *new;
+
+ if ((anyout = chkrange(blkno, idesc->id_numfrags)) != 0) {
+ blkerror(idesc->id_number, "BAD", blkno);
+ if (badblk++ >= MAXBAD) {
+ pwarn("EXCESSIVE BAD BLKS I=%lu",
+ idesc->id_number);
+ if (preen)
+ printf(" (SKIPPING)\n");
+ else if (reply("CONTINUE") == 0)
+ errexit("");
+ return (STOP);
+ }
+ }
+ for (nfrags = idesc->id_numfrags; nfrags > 0; blkno++, nfrags--) {
+ if (anyout && chkrange(blkno, 1)) {
+ res = SKIP;
+ } else if (!testbmap(blkno)) {
+ n_blks++;
+ setbmap(blkno);
+ } else {
+ blkerror(idesc->id_number, "DUP", blkno);
+ if (dupblk++ >= MAXDUP) {
+ pwarn("EXCESSIVE DUP BLKS I=%lu",
+ idesc->id_number);
+ if (preen)
+ printf(" (SKIPPING)\n");
+ else if (reply("CONTINUE") == 0)
+ errexit("");
+ return (STOP);
+ }
+ new = (struct dups *)malloc(sizeof(struct dups));
+ if (new == NULL) {
+ pfatal("DUP TABLE OVERFLOW.");
+ if (reply("CONTINUE") == 0)
+ errexit("");
+ return (STOP);
+ }
+ new->dup = blkno;
+ if (muldup == 0) {
+ duplist = muldup = new;
+ new->next = 0;
+ } else {
+ new->next = muldup->next;
+ muldup->next = new;
+ }
+ for (dlp = duplist; dlp != muldup; dlp = dlp->next)
+ if (dlp->dup == blkno)
+ break;
+ if (dlp == muldup && dlp->dup != blkno)
+ muldup = new;
+ }
+ /*
+ * count the number of blocks found in id_entryno
+ */
+ idesc->id_entryno++;
+ }
+ return (res);
+}
diff --git a/bsdfsck/pass1b.c b/bsdfsck/pass1b.c
new file mode 100644
index 00000000..f5aadc06
--- /dev/null
+++ b/bsdfsck/pass1b.c
@@ -0,0 +1,100 @@
+/*
+ * Copyright (c) 1980, 1986, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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.
+ */
+
+#ifndef lint
+/*static char sccsid[] = "from: @(#)pass1b.c 8.1 (Berkeley) 6/5/93";*/
+static char *rcsid = "$Id: pass1b.c,v 1.2 1994/08/23 20:01:24 mib Exp $";
+#endif /* not lint */
+
+#include <sys/param.h>
+#include <sys/time.h>
+#include "../ufs/dinode.h"
+#include "../ufs/fs.h"
+#include <string.h>
+#include "fsck.h"
+
+int pass1bcheck();
+static struct dups *duphead;
+
+pass1b()
+{
+ register int c, i;
+ register struct dinode *dp;
+ struct inodesc idesc;
+ ino_t inumber;
+
+ bzero((char *)&idesc, sizeof(struct inodesc));
+ idesc.id_type = ADDR;
+ idesc.id_func = pass1bcheck;
+ duphead = duplist;
+ inumber = 0;
+ for (c = 0; c < sblock.fs_ncg; c++) {
+ for (i = 0; i < sblock.fs_ipg; i++, inumber++) {
+ if (inumber < ROOTINO)
+ continue;
+ dp = ginode(inumber);
+ if (dp == NULL)
+ continue;
+ idesc.id_number = inumber;
+ if (statemap[inumber] != USTATE &&
+ (ckinode(dp, &idesc) & STOP))
+ return;
+ }
+ }
+}
+
+pass1bcheck(idesc)
+ register struct inodesc *idesc;
+{
+ register struct dups *dlp;
+ int nfrags, res = KEEPON;
+ daddr_t blkno = idesc->id_blkno;
+
+ for (nfrags = idesc->id_numfrags; nfrags > 0; blkno++, nfrags--) {
+ if (chkrange(blkno, 1))
+ res = SKIP;
+ for (dlp = duphead; dlp; dlp = dlp->next) {
+ if (dlp->dup == blkno) {
+ blkerror(idesc->id_number, "DUP", blkno);
+ dlp->dup = duphead->dup;
+ duphead->dup = blkno;
+ duphead = duphead->next;
+ }
+ if (dlp == muldup)
+ break;
+ }
+ if (muldup == 0 || duphead == muldup->next)
+ return (STOP);
+ }
+ return (res);
+}
diff --git a/bsdfsck/pass2.c b/bsdfsck/pass2.c
new file mode 100644
index 00000000..184106c1
--- /dev/null
+++ b/bsdfsck/pass2.c
@@ -0,0 +1,441 @@
+/*
+ * Copyright (c) 1980, 1986, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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.
+ */
+
+#ifndef lint
+/*static char sccsid[] = "from: @(#)pass2.c 8.2 (Berkeley) 2/27/94";*/
+static char *rcsid = "$Id: pass2.c,v 1.3 1994/08/24 15:11:56 mib Exp $";
+#endif /* not lint */
+
+#include <sys/param.h>
+#include <sys/time.h>
+#include "../ufs/dinode.h"
+#include "../ufs/dir.h"
+#include "../ufs/fs.h"
+#include <stdlib.h>
+#include <string.h>
+#include "fsck.h"
+
+#define MINDIRSIZE (sizeof (struct dirtemplate))
+
+int pass2check(), blksort();
+
+pass2()
+{
+ register struct dinode *dp;
+ register struct inoinfo **inpp, *inp;
+ struct inoinfo **inpend;
+ struct inodesc curino;
+ struct dinode dino;
+ char pathbuf[MAXPATHLEN + 1];
+
+ switch (statemap[ROOTINO]) {
+
+ case USTATE:
+ pfatal("ROOT INODE UNALLOCATED");
+ if (reply("ALLOCATE") == 0)
+ errexit("");
+ if (allocdir(ROOTINO, ROOTINO, 0755) != ROOTINO)
+ errexit("CANNOT ALLOCATE ROOT INODE\n");
+ break;
+
+ case DCLEAR:
+ pfatal("DUPS/BAD IN ROOT INODE");
+ if (reply("REALLOCATE")) {
+ freeino(ROOTINO);
+ if (allocdir(ROOTINO, ROOTINO, 0755) != ROOTINO)
+ errexit("CANNOT ALLOCATE ROOT INODE\n");
+ break;
+ }
+ if (reply("CONTINUE") == 0)
+ errexit("");
+ break;
+
+ case FSTATE:
+ case FCLEAR:
+ pfatal("ROOT INODE NOT DIRECTORY");
+ if (reply("REALLOCATE")) {
+ freeino(ROOTINO);
+ if (allocdir(ROOTINO, ROOTINO, 0755) != ROOTINO)
+ errexit("CANNOT ALLOCATE ROOT INODE\n");
+ break;
+ }
+ if (reply("FIX") == 0)
+ errexit("");
+ dp = ginode(ROOTINO);
+#if 0
+ dp->di_mode &= ~IFMT;
+ dp->di_mode |= IFDIR;
+#else
+ dp->di_model &= ~IFMT;
+ dp->di_model |= IFDIR;
+#endif
+ inodirty();
+ break;
+
+ case DSTATE:
+ break;
+
+ default:
+ errexit("BAD STATE %d FOR ROOT INODE", statemap[ROOTINO]);
+ }
+ statemap[ROOTINO] = DFOUND;
+ /*
+ * Sort the directory list into disk block order.
+ */
+ qsort((char *)inpsort, (size_t)inplast, sizeof *inpsort, blksort);
+ /*
+ * Check the integrity of each directory.
+ */
+ bzero((char *)&curino, sizeof(struct inodesc));
+ curino.id_type = DATA;
+ curino.id_func = pass2check;
+ dp = &dino;
+ inpend = &inpsort[inplast];
+ for (inpp = inpsort; inpp < inpend; inpp++) {
+ inp = *inpp;
+ if (inp->i_isize == 0)
+ continue;
+ if (inp->i_isize < MINDIRSIZE) {
+ direrror(inp->i_number, "DIRECTORY TOO SHORT");
+ inp->i_isize = roundup(MINDIRSIZE, DIRBLKSIZ);
+ if (reply("FIX") == 1) {
+ dp = ginode(inp->i_number);
+ dp->di_size = inp->i_isize;
+ inodirty();
+ dp = &dino;
+ }
+ } else if ((inp->i_isize & (DIRBLKSIZ - 1)) != 0) {
+ getpathname(pathbuf, inp->i_number, inp->i_number);
+ pwarn("DIRECTORY %s: LENGTH %d NOT MULTIPLE OF %d",
+ pathbuf, inp->i_isize, DIRBLKSIZ);
+ if (preen)
+ printf(" (ADJUSTED)\n");
+ inp->i_isize = roundup(inp->i_isize, DIRBLKSIZ);
+ if (preen || reply("ADJUST") == 1) {
+ dp = ginode(inp->i_number);
+ dp->di_size = roundup(inp->i_isize, DIRBLKSIZ);
+ inodirty();
+ dp = &dino;
+ }
+ }
+ bzero((char *)&dino, sizeof(struct dinode));
+#if 0
+ dino.di_mode = IFDIR;
+#else
+ dino.di_modeh = 0;
+ dino.di_model = IFDIR;
+#endif
+ dp->di_size = inp->i_isize;
+ bcopy((char *)&inp->i_blks[0], (char *)&dp->di_db[0],
+ (size_t)inp->i_numblks);
+ curino.id_number = inp->i_number;
+ curino.id_parent = inp->i_parent;
+ (void)ckinode(dp, &curino);
+ }
+ /*
+ * Now that the parents of all directories have been found,
+ * make another pass to verify the value of `..'
+ */
+ for (inpp = inpsort; inpp < inpend; inpp++) {
+ inp = *inpp;
+ if (inp->i_parent == 0 || inp->i_isize == 0)
+ continue;
+ if (statemap[inp->i_parent] == DFOUND &&
+ statemap[inp->i_number] == DSTATE)
+ statemap[inp->i_number] = DFOUND;
+ if (inp->i_dotdot == inp->i_parent ||
+ inp->i_dotdot == (ino_t)-1)
+ continue;
+ if (inp->i_dotdot == 0) {
+ inp->i_dotdot = inp->i_parent;
+ fileerror(inp->i_parent, inp->i_number, "MISSING '..'");
+ if (reply("FIX") == 0)
+ continue;
+ (void)makeentry(inp->i_number, inp->i_parent, "..");
+ lncntp[inp->i_parent]--;
+ continue;
+ }
+ fileerror(inp->i_parent, inp->i_number,
+ "BAD INODE NUMBER FOR '..'");
+ if (reply("FIX") == 0)
+ continue;
+ lncntp[inp->i_dotdot]++;
+ lncntp[inp->i_parent]--;
+ inp->i_dotdot = inp->i_parent;
+ (void)changeino(inp->i_number, "..", inp->i_parent);
+ }
+ /*
+ * Mark all the directories that can be found from the root.
+ */
+ propagate();
+}
+
+pass2check(idesc)
+ struct inodesc *idesc;
+{
+ register struct direct *dirp = idesc->id_dirp;
+ register struct inoinfo *inp;
+ int n, entrysize, ret = 0;
+ struct dinode *dp;
+ char *errmsg;
+ struct direct proto;
+ char namebuf[MAXPATHLEN + 1];
+ char pathbuf[MAXPATHLEN + 1];
+
+ /*
+ * If converting, set directory entry type.
+ */
+ if (doinglevel2 && dirp->d_ino > 0 && dirp->d_ino < maxino) {
+ dirp->d_type = typemap[dirp->d_ino];
+ ret |= ALTERED;
+ }
+ /*
+ * check for "."
+ */
+ if (idesc->id_entryno != 0)
+ goto chk1;
+ if (dirp->d_ino != 0 && strcmp(dirp->d_name, ".") == 0) {
+ if (dirp->d_ino != idesc->id_number) {
+ direrror(idesc->id_number, "BAD INODE NUMBER FOR '.'");
+ dirp->d_ino = idesc->id_number;
+ if (reply("FIX") == 1)
+ ret |= ALTERED;
+ }
+ if (newinofmt && dirp->d_type != DT_DIR) {
+ direrror(idesc->id_number, "BAD TYPE VALUE FOR '.'");
+ dirp->d_type = DT_DIR;
+ if (reply("FIX") == 1)
+ ret |= ALTERED;
+ }
+ goto chk1;
+ }
+ direrror(idesc->id_number, "MISSING '.'");
+ proto.d_ino = idesc->id_number;
+ if (newinofmt)
+ proto.d_type = DT_DIR;
+ else
+ proto.d_type = 0;
+ proto.d_namlen = 1;
+ (void)strcpy(proto.d_name, ".");
+ entrysize = DIRSIZ(0, &proto);
+ if (dirp->d_ino != 0 && strcmp(dirp->d_name, "..") != 0) {
+ pfatal("CANNOT FIX, FIRST ENTRY IN DIRECTORY CONTAINS %s\n",
+ dirp->d_name);
+ } else if (dirp->d_reclen < entrysize) {
+ pfatal("CANNOT FIX, INSUFFICIENT SPACE TO ADD '.'\n");
+ } else if (dirp->d_reclen < 2 * entrysize) {
+ proto.d_reclen = dirp->d_reclen;
+ bcopy((char *)&proto, (char *)dirp, (size_t)entrysize);
+ if (reply("FIX") == 1)
+ ret |= ALTERED;
+ } else {
+ n = dirp->d_reclen - entrysize;
+ proto.d_reclen = entrysize;
+ bcopy((char *)&proto, (char *)dirp, (size_t)entrysize);
+ idesc->id_entryno++;
+ lncntp[dirp->d_ino]--;
+ dirp = (struct direct *)((char *)(dirp) + entrysize);
+ bzero((char *)dirp, (size_t)n);
+ dirp->d_reclen = n;
+ if (reply("FIX") == 1)
+ ret |= ALTERED;
+ }
+chk1:
+ if (idesc->id_entryno > 1)
+ goto chk2;
+ inp = getinoinfo(idesc->id_number);
+ proto.d_ino = inp->i_parent;
+ if (newinofmt)
+ proto.d_type = DT_DIR;
+ else
+ proto.d_type = 0;
+ proto.d_namlen = 2;
+ (void)strcpy(proto.d_name, "..");
+ entrysize = DIRSIZ(0, &proto);
+ if (idesc->id_entryno == 0) {
+ n = DIRSIZ(0, dirp);
+ if (dirp->d_reclen < n + entrysize)
+ goto chk2;
+ proto.d_reclen = dirp->d_reclen - n;
+ dirp->d_reclen = n;
+ idesc->id_entryno++;
+ lncntp[dirp->d_ino]--;
+ dirp = (struct direct *)((char *)(dirp) + n);
+ bzero((char *)dirp, (size_t)proto.d_reclen);
+ dirp->d_reclen = proto.d_reclen;
+ }
+ if (dirp->d_ino != 0 && strcmp(dirp->d_name, "..") == 0) {
+ inp->i_dotdot = dirp->d_ino;
+ if (newinofmt && dirp->d_type != DT_DIR) {
+ direrror(idesc->id_number, "BAD TYPE VALUE FOR '..'");
+ dirp->d_type = DT_DIR;
+ if (reply("FIX") == 1)
+ ret |= ALTERED;
+ }
+ goto chk2;
+ }
+ if (dirp->d_ino != 0 && strcmp(dirp->d_name, ".") != 0) {
+ fileerror(inp->i_parent, idesc->id_number, "MISSING '..'");
+ pfatal("CANNOT FIX, SECOND ENTRY IN DIRECTORY CONTAINS %s\n",
+ dirp->d_name);
+ inp->i_dotdot = (ino_t)-1;
+ } else if (dirp->d_reclen < entrysize) {
+ fileerror(inp->i_parent, idesc->id_number, "MISSING '..'");
+ pfatal("CANNOT FIX, INSUFFICIENT SPACE TO ADD '..'\n");
+ inp->i_dotdot = (ino_t)-1;
+ } else if (inp->i_parent != 0) {
+ /*
+ * We know the parent, so fix now.
+ */
+ inp->i_dotdot = inp->i_parent;
+ fileerror(inp->i_parent, idesc->id_number, "MISSING '..'");
+ proto.d_reclen = dirp->d_reclen;
+ bcopy((char *)&proto, (char *)dirp, (size_t)entrysize);
+ if (reply("FIX") == 1)
+ ret |= ALTERED;
+ }
+ idesc->id_entryno++;
+ if (dirp->d_ino != 0)
+ lncntp[dirp->d_ino]--;
+ return (ret|KEEPON);
+chk2:
+ if (dirp->d_ino == 0)
+ return (ret|KEEPON);
+ if (dirp->d_namlen <= 2 &&
+ dirp->d_name[0] == '.' &&
+ idesc->id_entryno >= 2) {
+ if (dirp->d_namlen == 1) {
+ direrror(idesc->id_number, "EXTRA '.' ENTRY");
+ dirp->d_ino = 0;
+ if (reply("FIX") == 1)
+ ret |= ALTERED;
+ return (KEEPON | ret);
+ }
+ if (dirp->d_name[1] == '.') {
+ direrror(idesc->id_number, "EXTRA '..' ENTRY");
+ dirp->d_ino = 0;
+ if (reply("FIX") == 1)
+ ret |= ALTERED;
+ return (KEEPON | ret);
+ }
+ }
+ idesc->id_entryno++;
+ n = 0;
+ if (dirp->d_ino > maxino) {
+ fileerror(idesc->id_number, dirp->d_ino, "I OUT OF RANGE");
+ n = reply("REMOVE");
+ } else {
+again:
+ switch (statemap[dirp->d_ino]) {
+ case USTATE:
+ if (idesc->id_entryno <= 2)
+ break;
+ fileerror(idesc->id_number, dirp->d_ino, "UNALLOCATED");
+ n = reply("REMOVE");
+ break;
+
+ case DCLEAR:
+ case FCLEAR:
+ if (idesc->id_entryno <= 2)
+ break;
+ if (statemap[dirp->d_ino] == FCLEAR)
+ errmsg = "DUP/BAD";
+ else if (!preen)
+ errmsg = "ZERO LENGTH DIRECTORY";
+ else {
+ n = 1;
+ break;
+ }
+ fileerror(idesc->id_number, dirp->d_ino, errmsg);
+ if ((n = reply("REMOVE")) == 1)
+ break;
+ dp = ginode(dirp->d_ino);
+ statemap[dirp->d_ino] =
+ (DI_MODE(dp) & IFMT) == IFDIR ? DSTATE : FSTATE;
+ lncntp[dirp->d_ino] = dp->di_nlink;
+ goto again;
+
+ case DSTATE:
+ if (statemap[idesc->id_number] == DFOUND)
+ statemap[dirp->d_ino] = DFOUND;
+ /* fall through */
+
+ case DFOUND:
+ inp = getinoinfo(dirp->d_ino);
+ if (inp->i_parent != 0 && idesc->id_entryno > 2) {
+ getpathname(pathbuf, idesc->id_number,
+ idesc->id_number);
+ getpathname(namebuf, dirp->d_ino, dirp->d_ino);
+ pwarn("%s %s %s\n", pathbuf,
+ "IS AN EXTRANEOUS HARD LINK TO DIRECTORY",
+ namebuf);
+ if (preen)
+ printf(" (IGNORED)\n");
+ else if ((n = reply("REMOVE")) == 1)
+ break;
+ }
+ if (idesc->id_entryno > 2)
+ inp->i_parent = idesc->id_number;
+ /* fall through */
+
+ case FSTATE:
+ if (newinofmt && dirp->d_type != typemap[dirp->d_ino]) {
+ fileerror(idesc->id_number, dirp->d_ino,
+ "BAD TYPE VALUE");
+ dirp->d_type = typemap[dirp->d_ino];
+ if (reply("FIX") == 1)
+ ret |= ALTERED;
+ }
+ lncntp[dirp->d_ino]--;
+ break;
+
+ default:
+ errexit("BAD STATE %d FOR INODE I=%d",
+ statemap[dirp->d_ino], dirp->d_ino);
+ }
+ }
+ if (n == 0)
+ return (ret|KEEPON);
+ dirp->d_ino = 0;
+ return (ret|KEEPON|ALTERED);
+}
+
+/*
+ * Routine to sort disk blocks.
+ */
+blksort(inpp1, inpp2)
+ struct inoinfo **inpp1, **inpp2;
+{
+
+ return ((*inpp1)->i_blks[0] - (*inpp2)->i_blks[0]);
+}
diff --git a/bsdfsck/pass3.c b/bsdfsck/pass3.c
new file mode 100644
index 00000000..78fb6a96
--- /dev/null
+++ b/bsdfsck/pass3.c
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 1980, 1986, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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.
+ */
+
+#ifndef lint
+/*static char sccsid[] = "from: @(#)pass3.c 8.1 (Berkeley) 6/5/93";*/
+static char *rcsid = "$Id: pass3.c,v 1.2 1994/08/23 20:02:13 mib Exp $";
+#endif /* not lint */
+
+#include <sys/param.h>
+#include <sys/time.h>
+#include "../ufs/dinode.h"
+#include "../ufs/fs.h"
+#include "fsck.h"
+
+pass3()
+{
+ register struct inoinfo **inpp, *inp;
+ ino_t orphan;
+ int loopcnt;
+
+ for (inpp = &inpsort[inplast - 1]; inpp >= inpsort; inpp--) {
+ inp = *inpp;
+ if (inp->i_number == ROOTINO ||
+ !(inp->i_parent == 0 || statemap[inp->i_number] == DSTATE))
+ continue;
+ if (statemap[inp->i_number] == DCLEAR)
+ continue;
+ for (loopcnt = 0; ; loopcnt++) {
+ orphan = inp->i_number;
+ if (inp->i_parent == 0 ||
+ statemap[inp->i_parent] != DSTATE ||
+ loopcnt > numdirs)
+ break;
+ inp = getinoinfo(inp->i_parent);
+ }
+ (void)linkup(orphan, inp->i_dotdot);
+ inp->i_parent = inp->i_dotdot = lfdir;
+ lncntp[lfdir]--;
+ statemap[orphan] = DFOUND;
+ propagate();
+ }
+}
diff --git a/bsdfsck/pass4.c b/bsdfsck/pass4.c
new file mode 100644
index 00000000..449c96ab
--- /dev/null
+++ b/bsdfsck/pass4.c
@@ -0,0 +1,134 @@
+/*
+ * Copyright (c) 1980, 1986, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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.
+ */
+
+#ifndef lint
+/*static char sccsid[] = "from: @(#)pass4.c 8.1 (Berkeley) 6/5/93";*/
+static char *rcsid = "$Id: pass4.c,v 1.2 1994/08/23 20:02:28 mib Exp $";
+#endif /* not lint */
+
+#include <sys/param.h>
+#include <sys/time.h>
+#include "../ufs/dinode.h"
+#include "../ufs/fs.h"
+#include <stdlib.h>
+#include <string.h>
+#include "fsck.h"
+
+int pass4check();
+
+pass4()
+{
+ register ino_t inumber;
+ register struct zlncnt *zlnp;
+ struct dinode *dp;
+ struct inodesc idesc;
+ int n;
+
+ bzero((char *)&idesc, sizeof(struct inodesc));
+ idesc.id_type = ADDR;
+ idesc.id_func = pass4check;
+ for (inumber = ROOTINO; inumber <= lastino; inumber++) {
+ idesc.id_number = inumber;
+ switch (statemap[inumber]) {
+
+ case FSTATE:
+ case DFOUND:
+ n = lncntp[inumber];
+ if (n)
+ adjust(&idesc, (short)n);
+ else {
+ for (zlnp = zlnhead; zlnp; zlnp = zlnp->next)
+ if (zlnp->zlncnt == inumber) {
+ zlnp->zlncnt = zlnhead->zlncnt;
+ zlnp = zlnhead;
+ zlnhead = zlnhead->next;
+ free((char *)zlnp);
+ clri(&idesc, "UNREF", 1);
+ break;
+ }
+ }
+ break;
+
+ case DSTATE:
+ clri(&idesc, "UNREF", 1);
+ break;
+
+ case DCLEAR:
+ dp = ginode(inumber);
+ if (dp->di_size == 0) {
+ clri(&idesc, "ZERO LENGTH", 1);
+ break;
+ }
+ /* fall through */
+ case FCLEAR:
+ clri(&idesc, "BAD/DUP", 1);
+ break;
+
+ case USTATE:
+ break;
+
+ default:
+ errexit("BAD STATE %d FOR INODE I=%d",
+ statemap[inumber], inumber);
+ }
+ }
+}
+
+pass4check(idesc)
+ register struct inodesc *idesc;
+{
+ register struct dups *dlp;
+ int nfrags, res = KEEPON;
+ daddr_t blkno = idesc->id_blkno;
+
+ for (nfrags = idesc->id_numfrags; nfrags > 0; blkno++, nfrags--) {
+ if (chkrange(blkno, 1)) {
+ res = SKIP;
+ } else if (testbmap(blkno)) {
+ for (dlp = duplist; dlp; dlp = dlp->next) {
+ if (dlp->dup != blkno)
+ continue;
+ dlp->dup = duplist->dup;
+ dlp = duplist;
+ duplist = duplist->next;
+ free((char *)dlp);
+ break;
+ }
+ if (dlp == 0) {
+ clrbmap(blkno);
+ n_blks--;
+ }
+ }
+ }
+ return (res);
+}
diff --git a/bsdfsck/pass5.c b/bsdfsck/pass5.c
new file mode 100644
index 00000000..11877f9d
--- /dev/null
+++ b/bsdfsck/pass5.c
@@ -0,0 +1,358 @@
+/*
+ * Copyright (c) 1980, 1986, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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.
+ */
+
+#ifndef lint
+/*static char sccsid[] = "from: @(#)pass5.c 8.2 (Berkeley) 2/2/94";*/
+static char *rcsid = "$Id: pass5.c,v 1.3 1994/08/26 18:03:07 mib Exp $";
+#endif /* not lint */
+
+#include <sys/param.h>
+#include <sys/time.h>
+#include "../ufs/dinode.h"
+#include "../ufs/fs.h"
+#include <string.h>
+#include "fsck.h"
+
+/* From ../ufs/subr.c: */
+
+/*
+ * Update the frsum fields to reflect addition or deletion
+ * of some frags.
+ */
+void
+ffs_fragacct(fs, fragmap, fraglist, cnt)
+ struct fs *fs;
+ int fragmap;
+ long fraglist[];
+ int cnt;
+{
+ int inblk;
+ register int field, subfield;
+ register int siz, pos;
+
+ inblk = (int)(fragtbl[fs->fs_frag][fragmap]) << 1;
+ fragmap <<= 1;
+ for (siz = 1; siz < fs->fs_frag; siz++) {
+ if ((inblk & (1 << (siz + (fs->fs_frag % NBBY)))) == 0)
+ continue;
+ field = around[siz];
+ subfield = inside[siz];
+ for (pos = siz; pos <= fs->fs_frag; pos++) {
+ if ((fragmap & field) == subfield) {
+ fraglist[siz] += cnt;
+ pos += siz;
+ field <<= siz;
+ subfield <<= siz;
+ }
+ field <<= 1;
+ subfield <<= 1;
+ }
+ }
+}
+
+
+pass5()
+{
+ int c, blk, frags, basesize, sumsize, mapsize, savednrpos;
+ register struct fs *fs = &sblock;
+ register struct cg *cg = &cgrp;
+ daddr_t dbase, dmax;
+ register daddr_t d;
+ register long i, j;
+ struct csum *cs;
+ struct csum cstotal;
+ struct inodesc idesc[3];
+ char buf[MAXBSIZE];
+ register struct cg *newcg = (struct cg *)buf;
+ struct ocg *ocg = (struct ocg *)buf;
+
+ bzero((char *)newcg, (size_t)fs->fs_cgsize);
+ newcg->cg_niblk = fs->fs_ipg;
+ if (cvtlevel > 3) {
+ if (fs->fs_maxcontig < 2 && fs->fs_contigsumsize > 0) {
+ if (preen)
+ pwarn("DELETING CLUSTERING MAPS\n");
+ if (preen || reply("DELETE CLUSTERING MAPS")) {
+ fs->fs_contigsumsize = 0;
+ doinglevel1 = 1;
+ sbdirty();
+ }
+ }
+ if (fs->fs_maxcontig > 1) {
+ char *doit = 0;
+
+ if (fs->fs_contigsumsize < 1) {
+ doit = "CREAT";
+ } else if (fs->fs_contigsumsize < fs->fs_maxcontig &&
+ fs->fs_contigsumsize < FS_MAXCONTIG) {
+ doit = "EXPAND";
+ }
+ if (doit) {
+ i = fs->fs_contigsumsize;
+ fs->fs_contigsumsize =
+ MIN(fs->fs_maxcontig, FS_MAXCONTIG);
+ if (CGSIZE(fs) > fs->fs_bsize) {
+ pwarn("CANNOT %s CLUSTER MAPS\n", doit);
+ fs->fs_contigsumsize = i;
+ } else if (preen ||
+ reply("CREATE CLUSTER MAPS")) {
+ if (preen)
+ pwarn("%sING CLUSTER MAPS\n",
+ doit);
+ fs->fs_cgsize =
+ fragroundup(fs, CGSIZE(fs));
+ doinglevel1 = 1;
+ sbdirty();
+ }
+ }
+ }
+ }
+ switch ((int)fs->fs_postblformat) {
+
+ case FS_42POSTBLFMT:
+ basesize = (char *)(&ocg->cg_btot[0]) - (char *)(&ocg->cg_link);
+ sumsize = &ocg->cg_iused[0] - (char *)(&ocg->cg_btot[0]);
+ mapsize = &ocg->cg_free[howmany(fs->fs_fpg, NBBY)] -
+ (u_char *)&ocg->cg_iused[0];
+ ocg->cg_magic = CG_MAGIC;
+ savednrpos = fs->fs_nrpos;
+ fs->fs_nrpos = 8;
+ break;
+
+ case FS_DYNAMICPOSTBLFMT:
+ newcg->cg_btotoff =
+ &newcg->cg_space[0] - (u_char *)(&newcg->cg_link);
+ newcg->cg_boff =
+ newcg->cg_btotoff + fs->fs_cpg * sizeof(long);
+ newcg->cg_iusedoff = newcg->cg_boff +
+ fs->fs_cpg * fs->fs_nrpos * sizeof(short);
+ newcg->cg_freeoff =
+ newcg->cg_iusedoff + howmany(fs->fs_ipg, NBBY);
+ if (fs->fs_contigsumsize <= 0) {
+ newcg->cg_nextfreeoff = newcg->cg_freeoff +
+ howmany(fs->fs_cpg * fs->fs_spc / NSPF(fs), NBBY);
+ } else {
+ newcg->cg_clustersumoff = newcg->cg_freeoff +
+ howmany(fs->fs_cpg * fs->fs_spc / NSPF(fs), NBBY) -
+ sizeof(long);
+ newcg->cg_clustersumoff =
+ roundup(newcg->cg_clustersumoff, sizeof(long));
+ newcg->cg_clusteroff = newcg->cg_clustersumoff +
+ (fs->fs_contigsumsize + 1) * sizeof(long);
+ newcg->cg_nextfreeoff = newcg->cg_clusteroff +
+ howmany(fs->fs_cpg * fs->fs_spc / NSPB(fs), NBBY);
+ }
+ newcg->cg_magic = CG_MAGIC;
+ basesize = &newcg->cg_space[0] - (u_char *)(&newcg->cg_link);
+ sumsize = newcg->cg_iusedoff - newcg->cg_btotoff;
+ mapsize = newcg->cg_nextfreeoff - newcg->cg_iusedoff;
+ break;
+
+ default:
+ errexit("UNKNOWN ROTATIONAL TABLE FORMAT %d\n",
+ fs->fs_postblformat);
+ }
+ bzero((char *)&idesc[0], sizeof idesc);
+ for (i = 0; i < 3; i++) {
+ idesc[i].id_type = ADDR;
+ if (doinglevel2)
+ idesc[i].id_fix = FIX;
+ }
+ bzero((char *)&cstotal, sizeof(struct csum));
+ j = blknum(fs, fs->fs_size + fs->fs_frag - 1);
+ for (i = fs->fs_size; i < j; i++)
+ setbmap(i);
+ for (c = 0; c < fs->fs_ncg; c++) {
+ getblk(&cgblk, cgtod(fs, c), fs->fs_cgsize);
+ if (!cg_chkmagic(cg))
+ pfatal("CG %d: BAD MAGIC NUMBER\n", c);
+ dbase = cgbase(fs, c);
+ dmax = dbase + fs->fs_fpg;
+ if (dmax > fs->fs_size)
+ dmax = fs->fs_size;
+ newcg->cg_time = cg->cg_time;
+ newcg->cg_cgx = c;
+ if (c == fs->fs_ncg - 1)
+ newcg->cg_ncyl = fs->fs_ncyl % fs->fs_cpg;
+ else
+ newcg->cg_ncyl = fs->fs_cpg;
+ newcg->cg_ndblk = dmax - dbase;
+ if (fs->fs_contigsumsize > 0)
+ newcg->cg_nclusterblks = newcg->cg_ndblk / fs->fs_frag;
+ newcg->cg_cs.cs_ndir = 0;
+ newcg->cg_cs.cs_nffree = 0;
+ newcg->cg_cs.cs_nbfree = 0;
+ newcg->cg_cs.cs_nifree = fs->fs_ipg;
+ if (cg->cg_rotor < newcg->cg_ndblk)
+ newcg->cg_rotor = cg->cg_rotor;
+ else
+ newcg->cg_rotor = 0;
+ if (cg->cg_frotor < newcg->cg_ndblk)
+ newcg->cg_frotor = cg->cg_frotor;
+ else
+ newcg->cg_frotor = 0;
+ if (cg->cg_irotor < newcg->cg_niblk)
+ newcg->cg_irotor = cg->cg_irotor;
+ else
+ newcg->cg_irotor = 0;
+ bzero((char *)&newcg->cg_frsum[0], sizeof newcg->cg_frsum);
+ bzero((char *)&cg_blktot(newcg)[0],
+ (size_t)(sumsize + mapsize));
+ if (fs->fs_postblformat == FS_42POSTBLFMT)
+ ocg->cg_magic = CG_MAGIC;
+ j = fs->fs_ipg * c;
+ for (i = 0; i < fs->fs_ipg; j++, i++) {
+ switch (statemap[j]) {
+
+ case USTATE:
+ break;
+
+ case DSTATE:
+ case DCLEAR:
+ case DFOUND:
+ newcg->cg_cs.cs_ndir++;
+ /* fall through */
+
+ case FSTATE:
+ case FCLEAR:
+ newcg->cg_cs.cs_nifree--;
+ setbit(cg_inosused(newcg), i);
+ break;
+
+ default:
+ if (j < ROOTINO)
+ break;
+ errexit("BAD STATE %d FOR INODE I=%d",
+ statemap[j], j);
+ }
+ }
+ if (c == 0)
+ for (i = 0; i < ROOTINO; i++) {
+ setbit(cg_inosused(newcg), i);
+ newcg->cg_cs.cs_nifree--;
+ }
+ for (i = 0, d = dbase;
+ d < dmax;
+ d += fs->fs_frag, i += fs->fs_frag) {
+ frags = 0;
+ for (j = 0; j < fs->fs_frag; j++) {
+ if (testbmap(d + j))
+ continue;
+ setbit(cg_blksfree(newcg), i + j);
+ frags++;
+ }
+ if (frags == fs->fs_frag) {
+ newcg->cg_cs.cs_nbfree++;
+ j = cbtocylno(fs, i);
+ cg_blktot(newcg)[j]++;
+ cg_blks(fs, newcg, j)[cbtorpos(fs, i)]++;
+ if (fs->fs_contigsumsize > 0)
+ setbit(cg_clustersfree(newcg),
+ i / fs->fs_frag);
+ } else if (frags > 0) {
+ newcg->cg_cs.cs_nffree += frags;
+ blk = blkmap(fs, cg_blksfree(newcg), i);
+ ffs_fragacct(fs, blk, newcg->cg_frsum, 1);
+ }
+ }
+ if (fs->fs_contigsumsize > 0) {
+ long *sump = cg_clustersum(newcg);
+ u_char *mapp = cg_clustersfree(newcg);
+ int map = *mapp++;
+ int bit = 1;
+ int run = 0;
+
+ for (i = 0; i < newcg->cg_nclusterblks; i++) {
+ if ((map & bit) != 0) {
+ run++;
+ } else if (run != 0) {
+ if (run > fs->fs_contigsumsize)
+ run = fs->fs_contigsumsize;
+ sump[run]++;
+ run = 0;
+ }
+ if ((i & (NBBY - 1)) != (NBBY - 1)) {
+ bit <<= 1;
+ } else {
+ map = *mapp++;
+ bit = 1;
+ }
+ }
+ if (run != 0) {
+ if (run > fs->fs_contigsumsize)
+ run = fs->fs_contigsumsize;
+ sump[run]++;
+ }
+ }
+ cstotal.cs_nffree += newcg->cg_cs.cs_nffree;
+ cstotal.cs_nbfree += newcg->cg_cs.cs_nbfree;
+ cstotal.cs_nifree += newcg->cg_cs.cs_nifree;
+ cstotal.cs_ndir += newcg->cg_cs.cs_ndir;
+ cs = &fs->fs_cs(fs, c);
+ if (bcmp((char *)&newcg->cg_cs, (char *)cs, sizeof *cs) != 0 &&
+ dofix(&idesc[0], "FREE BLK COUNT(S) WRONG IN SUPERBLK")) {
+ bcopy((char *)&newcg->cg_cs, (char *)cs, sizeof *cs);
+ sbdirty();
+ }
+ if (doinglevel1) {
+ bcopy((char *)newcg, (char *)cg, (size_t)fs->fs_cgsize);
+ cgdirty();
+ continue;
+ }
+ if (bcmp(cg_inosused(newcg),
+ cg_inosused(cg), mapsize) != 0 &&
+ dofix(&idesc[1], "BLK(S) MISSING IN BIT MAPS")) {
+ bcopy(cg_inosused(newcg), cg_inosused(cg),
+ (size_t)mapsize);
+ cgdirty();
+ }
+ if ((bcmp((char *)newcg, (char *)cg, basesize) != 0 ||
+ bcmp((char *)&cg_blktot(newcg)[0],
+ (char *)&cg_blktot(cg)[0], sumsize) != 0) &&
+ dofix(&idesc[2], "SUMMARY INFORMATION BAD")) {
+ bcopy((char *)newcg, (char *)cg, (size_t)basesize);
+ bcopy((char *)&cg_blktot(newcg)[0],
+ (char *)&cg_blktot(cg)[0], (size_t)sumsize);
+ cgdirty();
+ }
+ }
+ if (fs->fs_postblformat == FS_42POSTBLFMT)
+ fs->fs_nrpos = savednrpos;
+ if (bcmp((char *)&cstotal, (char *)&fs->fs_cstotal, sizeof *cs) != 0
+ && dofix(&idesc[0], "FREE BLK COUNT(S) WRONG IN SUPERBLK")) {
+ bcopy((char *)&cstotal, (char *)&fs->fs_cstotal, sizeof *cs);
+ fs->fs_ronly = 0;
+ fs->fs_fmod = 0;
+ sbdirty();
+ }
+}
diff --git a/bsdfsck/preen.c b/bsdfsck/preen.c
new file mode 100644
index 00000000..5650f900
--- /dev/null
+++ b/bsdfsck/preen.c
@@ -0,0 +1,355 @@
+/*
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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.
+ */
+
+#ifndef lint
+/*static char sccsid[] = "from: @(#)preen.c 8.1 (Berkeley) 6/5/93";*/
+static char *rcsid = "$Id: preen.c,v 1.1 1994/08/23 19:29:25 mib Exp $";
+#endif /* not lint */
+
+#include <sys/param.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+#include <fstab.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h>
+
+char *rawname(), *unrawname(), *blockcheck();
+
+struct part {
+ struct part *next; /* forward link of partitions on disk */
+ char *name; /* device name */
+ char *fsname; /* mounted filesystem name */
+ long auxdata; /* auxiliary data for application */
+} *badlist, **badnext = &badlist;
+
+struct disk {
+ char *name; /* disk base name */
+ struct disk *next; /* forward link for list of disks */
+ struct part *part; /* head of list of partitions on disk */
+ int pid; /* If != 0, pid of proc working on */
+} *disks;
+
+int nrun, ndisks;
+char hotroot;
+
+checkfstab(preen, maxrun, docheck, chkit)
+ int preen, maxrun;
+ int (*docheck)(), (*chkit)();
+{
+ register struct fstab *fsp;
+ register struct disk *dk, *nextdisk;
+ register struct part *pt;
+ int ret, pid, retcode, passno, sumstatus, status;
+ long auxdata;
+ char *name;
+
+ sumstatus = 0;
+ for (passno = 1; passno <= 2; passno++) {
+ if (setfsent() == 0) {
+ fprintf(stderr, "Can't open checklist file: %s\n",
+ _PATH_FSTAB);
+ return (8);
+ }
+ while ((fsp = getfsent()) != 0) {
+ if ((auxdata = (*docheck)(fsp)) == 0)
+ continue;
+ if (preen == 0 || passno == 1 && fsp->fs_passno == 1) {
+ if (name = blockcheck(fsp->fs_spec)) {
+ if (sumstatus = (*chkit)(name,
+ fsp->fs_file, auxdata, 0))
+ return (sumstatus);
+ } else if (preen)
+ return (8);
+ } else if (passno == 2 && fsp->fs_passno > 1) {
+ if ((name = blockcheck(fsp->fs_spec)) == NULL) {
+ fprintf(stderr, "BAD DISK NAME %s\n",
+ fsp->fs_spec);
+ sumstatus |= 8;
+ continue;
+ }
+ addpart(name, fsp->fs_file, auxdata);
+ }
+ }
+ if (preen == 0)
+ return (0);
+ }
+ if (preen) {
+ if (maxrun == 0)
+ maxrun = ndisks;
+ if (maxrun > ndisks)
+ maxrun = ndisks;
+ nextdisk = disks;
+ for (passno = 0; passno < maxrun; ++passno) {
+ while (ret = startdisk(nextdisk, chkit) && nrun > 0)
+ sleep(10);
+ if (ret)
+ return (ret);
+ nextdisk = nextdisk->next;
+ }
+ while ((pid = wait(&status)) != -1) {
+ for (dk = disks; dk; dk = dk->next)
+ if (dk->pid == pid)
+ break;
+ if (dk == 0) {
+ printf("Unknown pid %d\n", pid);
+ continue;
+ }
+ if (WIFEXITED(status))
+ retcode = WEXITSTATUS(status);
+ else
+ retcode = 0;
+ if (WIFSIGNALED(status)) {
+ printf("%s (%s): EXITED WITH SIGNAL %d\n",
+ dk->part->name, dk->part->fsname,
+ WTERMSIG(status));
+ retcode = 8;
+ }
+ if (retcode != 0) {
+ sumstatus |= retcode;
+ *badnext = dk->part;
+ badnext = &dk->part->next;
+ dk->part = dk->part->next;
+ *badnext = NULL;
+ } else
+ dk->part = dk->part->next;
+ dk->pid = 0;
+ nrun--;
+ if (dk->part == NULL)
+ ndisks--;
+
+ if (nextdisk == NULL) {
+ if (dk->part) {
+ while (ret = startdisk(dk, chkit) &&
+ nrun > 0)
+ sleep(10);
+ if (ret)
+ return (ret);
+ }
+ } else if (nrun < maxrun && nrun < ndisks) {
+ for ( ;; ) {
+ if ((nextdisk = nextdisk->next) == NULL)
+ nextdisk = disks;
+ if (nextdisk->part != NULL &&
+ nextdisk->pid == 0)
+ break;
+ }
+ while (ret = startdisk(nextdisk, chkit) &&
+ nrun > 0)
+ sleep(10);
+ if (ret)
+ return (ret);
+ }
+ }
+ }
+ if (sumstatus) {
+ if (badlist == 0)
+ return (sumstatus);
+ fprintf(stderr, "THE FOLLOWING FILE SYSTEM%s HAD AN %s\n\t",
+ badlist->next ? "S" : "", "UNEXPECTED INCONSISTENCY:");
+ for (pt = badlist; pt; pt = pt->next)
+ fprintf(stderr, "%s (%s)%s", pt->name, pt->fsname,
+ pt->next ? ", " : "\n");
+ return (sumstatus);
+ }
+ (void)endfsent();
+ return (0);
+}
+
+struct disk *
+finddisk(name)
+ char *name;
+{
+ register struct disk *dk, **dkp;
+ register char *p;
+ size_t len;
+
+ for (p = name + strlen(name) - 1; p >= name; --p)
+ if (isdigit(*p)) {
+ len = p - name + 1;
+ break;
+ }
+ if (p < name)
+ len = strlen(name);
+
+ for (dk = disks, dkp = &disks; dk; dkp = &dk->next, dk = dk->next) {
+ if (strncmp(dk->name, name, len) == 0 &&
+ dk->name[len] == 0)
+ return (dk);
+ }
+ if ((*dkp = (struct disk *)malloc(sizeof(struct disk))) == NULL) {
+ fprintf(stderr, "out of memory");
+ exit (8);
+ }
+ dk = *dkp;
+ if ((dk->name = malloc(len + 1)) == NULL) {
+ fprintf(stderr, "out of memory");
+ exit (8);
+ }
+ (void)strncpy(dk->name, name, len);
+ dk->name[len] = '\0';
+ dk->part = NULL;
+ dk->next = NULL;
+ dk->pid = 0;
+ ndisks++;
+ return (dk);
+}
+
+addpart(name, fsname, auxdata)
+ char *name, *fsname;
+ long auxdata;
+{
+ struct disk *dk = finddisk(name);
+ register struct part *pt, **ppt = &dk->part;
+
+ for (pt = dk->part; pt; ppt = &pt->next, pt = pt->next)
+ if (strcmp(pt->name, name) == 0) {
+ printf("%s in fstab more than once!\n", name);
+ return;
+ }
+ if ((*ppt = (struct part *)malloc(sizeof(struct part))) == NULL) {
+ fprintf(stderr, "out of memory");
+ exit (8);
+ }
+ pt = *ppt;
+ if ((pt->name = malloc(strlen(name) + 1)) == NULL) {
+ fprintf(stderr, "out of memory");
+ exit (8);
+ }
+ (void)strcpy(pt->name, name);
+ if ((pt->fsname = malloc(strlen(fsname) + 1)) == NULL) {
+ fprintf(stderr, "out of memory");
+ exit (8);
+ }
+ (void)strcpy(pt->fsname, fsname);
+ pt->next = NULL;
+ pt->auxdata = auxdata;
+}
+
+startdisk(dk, checkit)
+ register struct disk *dk;
+ int (*checkit)();
+{
+ register struct part *pt = dk->part;
+
+ dk->pid = fork();
+ if (dk->pid < 0) {
+ perror("fork");
+ return (8);
+ }
+ if (dk->pid == 0)
+ exit((*checkit)(pt->name, pt->fsname, pt->auxdata, 1));
+ nrun++;
+ return (0);
+}
+
+char *
+blockcheck(name)
+ char *name;
+{
+ struct stat stslash, stblock, stchar;
+ char *raw;
+ int retried = 0;
+
+ hotroot = 0;
+ if (stat("/", &stslash) < 0) {
+ perror("/");
+ printf("Can't stat root\n");
+ return (0);
+ }
+retry:
+ if (stat(name, &stblock) < 0) {
+ perror(name);
+ printf("Can't stat %s\n", name);
+ return (0);
+ }
+ if ((stblock.st_mode & S_IFMT) == S_IFBLK) {
+ if (stslash.st_dev == stblock.st_rdev)
+ hotroot++;
+ raw = rawname(name);
+ if (stat(raw, &stchar) < 0) {
+ perror(raw);
+ printf("Can't stat %s\n", raw);
+ return (name);
+ }
+ if ((stchar.st_mode & S_IFMT) == S_IFCHR) {
+ return (raw);
+ } else {
+ printf("%s is not a character device\n", raw);
+ return (name);
+ }
+ } else if ((stblock.st_mode & S_IFMT) == S_IFCHR && !retried) {
+ name = unrawname(name);
+ retried++;
+ goto retry;
+ }
+ printf("Can't make sense out of name %s\n", name);
+ return (0);
+}
+
+char *
+unrawname(name)
+ char *name;
+{
+ char *dp;
+ struct stat stb;
+
+ if ((dp = rindex(name, '/')) == 0)
+ return (name);
+ if (stat(name, &stb) < 0)
+ return (name);
+ if ((stb.st_mode & S_IFMT) != S_IFCHR)
+ return (name);
+ if (dp[1] != 'r')
+ return (name);
+ (void)strcpy(&dp[1], &dp[2]);
+ return (name);
+}
+
+char *
+rawname(name)
+ char *name;
+{
+ static char rawbuf[32];
+ char *dp;
+
+ if ((dp = rindex(name, '/')) == 0)
+ return (0);
+ *dp = 0;
+ (void)strcpy(rawbuf, name);
+ *dp = '/';
+ (void)strcat(rawbuf, "/r");
+ (void)strcat(rawbuf, &dp[1]);
+ return (rawbuf);
+}
diff --git a/bsdfsck/setup.c b/bsdfsck/setup.c
new file mode 100644
index 00000000..f65ade47
--- /dev/null
+++ b/bsdfsck/setup.c
@@ -0,0 +1,480 @@
+/*
+ * Copyright (c) 1980, 1986, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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.
+ */
+
+#ifndef lint
+/*static char sccsid[] = "from: @(#)setup.c 8.2 (Berkeley) 2/21/94";*/
+static char *rcsid = "$Id: setup.c,v 1.3 1994/08/25 15:22:35 mib Exp $";
+#endif /* not lint */
+
+#define DKTYPENAMES
+#include <sys/param.h>
+#include <sys/time.h>
+#include "../ufs/dinode.h"
+#include "../ufs/fs.h"
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+/* #include <sys/disklabel.h> */
+#include <sys/file.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include "fsck.h"
+
+struct bufarea asblk;
+#define altsblock (*asblk.b_un.b_fs)
+#define POWEROF2(num) (((num) & ((num) - 1)) == 0)
+
+struct disklabel *getdisklabel();
+
+setup(dev)
+ char *dev;
+{
+ long cg, size, asked, i, j;
+ long bmapsize;
+/* struct disklabel *lp; */
+ off_t sizepb;
+ struct stat statb;
+ struct fs proto;
+
+ havesb = 0;
+ fswritefd = -1;
+ if (stat(dev, &statb) < 0) {
+ printf("Can't stat %s: %s\n", dev, strerror(errno));
+ return (0);
+ }
+ if ((statb.st_mode & S_IFMT) != S_IFCHR) {
+ pfatal("%s is not a character device", dev);
+ if (reply("CONTINUE") == 0)
+ return (0);
+ }
+ if ((fsreadfd = open(dev, O_RDONLY)) < 0) {
+ printf("Can't open %s: %s\n", dev, strerror(errno));
+ return (0);
+ }
+ if (preen == 0)
+ printf("** %s", dev);
+ if (nflag || (fswritefd = open(dev, O_WRONLY)) < 0) {
+ fswritefd = -1;
+ if (preen)
+ pfatal("NO WRITE ACCESS");
+ printf(" (NO WRITE)");
+ }
+ if (preen == 0)
+ printf("\n");
+ fsmodified = 0;
+ lfdir = 0;
+ initbarea(&sblk);
+ initbarea(&asblk);
+ sblk.b_un.b_buf = malloc(SBSIZE);
+ asblk.b_un.b_buf = malloc(SBSIZE);
+ if (sblk.b_un.b_buf == NULL || asblk.b_un.b_buf == NULL)
+ errexit("cannot allocate space for superblock\n");
+#if 0
+ if (lp = getdisklabel((char *)NULL, fsreadfd))
+ dev_bsize = secsize = lp->d_secsize;
+ else
+#endif
+ dev_bsize = secsize = DEV_BSIZE;
+ /*
+ * Read in the superblock, looking for alternates if necessary
+ */
+ if (readsb(1) == 0) {
+ if (bflag || preen || calcsb(dev, fsreadfd, &proto) == 0)
+ return(0);
+ if (reply("LOOK FOR ALTERNATE SUPERBLOCKS") == 0)
+ return (0);
+ for (cg = 0; cg < proto.fs_ncg; cg++) {
+ bflag = fsbtodb(&proto, cgsblock(&proto, cg));
+ if (readsb(0) != 0)
+ break;
+ }
+ if (cg >= proto.fs_ncg) {
+ printf("%s %s\n%s %s\n%s %s\n",
+ "SEARCH FOR ALTERNATE SUPER-BLOCK",
+ "FAILED. YOU MUST USE THE",
+ "-b OPTION TO FSCK TO SPECIFY THE",
+ "LOCATION OF AN ALTERNATE",
+ "SUPER-BLOCK TO SUPPLY NEEDED",
+ "INFORMATION; SEE fsck(8).");
+ return(0);
+ }
+ pwarn("USING ALTERNATE SUPERBLOCK AT %d\n", bflag);
+ }
+ maxfsblock = sblock.fs_size;
+ maxino = sblock.fs_ncg * sblock.fs_ipg;
+ /*
+ * Check and potentially fix certain fields in the super block.
+ */
+ if (sblock.fs_optim != FS_OPTTIME && sblock.fs_optim != FS_OPTSPACE) {
+ pfatal("UNDEFINED OPTIMIZATION IN SUPERBLOCK");
+ if (reply("SET TO DEFAULT") == 1) {
+ sblock.fs_optim = FS_OPTTIME;
+ sbdirty();
+ }
+ }
+ if ((sblock.fs_minfree < 0 || sblock.fs_minfree > 99)) {
+ pfatal("IMPOSSIBLE MINFREE=%d IN SUPERBLOCK",
+ sblock.fs_minfree);
+ if (reply("SET TO DEFAULT") == 1) {
+ sblock.fs_minfree = 10;
+ sbdirty();
+ }
+ }
+ if (sblock.fs_interleave < 1 ||
+ sblock.fs_interleave > sblock.fs_nsect) {
+ pwarn("IMPOSSIBLE INTERLEAVE=%d IN SUPERBLOCK",
+ sblock.fs_interleave);
+ sblock.fs_interleave = 1;
+ if (preen)
+ printf(" (FIXED)\n");
+ if (preen || reply("SET TO DEFAULT") == 1) {
+ sbdirty();
+ dirty(&asblk);
+ }
+ }
+ if (sblock.fs_npsect < sblock.fs_nsect ||
+ sblock.fs_npsect > sblock.fs_nsect*2) {
+ pwarn("IMPOSSIBLE NPSECT=%d IN SUPERBLOCK",
+ sblock.fs_npsect);
+ sblock.fs_npsect = sblock.fs_nsect;
+ if (preen)
+ printf(" (FIXED)\n");
+ if (preen || reply("SET TO DEFAULT") == 1) {
+ sbdirty();
+ dirty(&asblk);
+ }
+ }
+ if (sblock.fs_inodefmt >= FS_44INODEFMT) {
+ newinofmt = 1;
+ } else {
+ sblock.fs_qbmask = ~sblock.fs_bmask;
+ sblock.fs_qfmask = ~sblock.fs_fmask;
+ newinofmt = 0;
+ }
+ /*
+ * Convert to new inode format.
+ */
+ if (cvtlevel >= 2 && sblock.fs_inodefmt < FS_44INODEFMT) {
+ if (preen)
+ pwarn("CONVERTING TO NEW INODE FORMAT\n");
+ else if (!reply("CONVERT TO NEW INODE FORMAT"))
+ return(0);
+ doinglevel2++;
+ sblock.fs_inodefmt = FS_44INODEFMT;
+ sizepb = sblock.fs_bsize;
+ sblock.fs_maxfilesize = sblock.fs_bsize * NDADDR - 1;
+ for (i = 0; i < NIADDR; i++) {
+ sizepb *= NINDIR(&sblock);
+ sblock.fs_maxfilesize += sizepb;
+ }
+ sblock.fs_maxsymlinklen = MAXSYMLINKLEN;
+ sblock.fs_qbmask = ~sblock.fs_bmask;
+ sblock.fs_qfmask = ~sblock.fs_fmask;
+ sbdirty();
+ dirty(&asblk);
+ }
+ /*
+ * Convert to new cylinder group format.
+ */
+ if (cvtlevel >= 1 && sblock.fs_postblformat == FS_42POSTBLFMT) {
+ if (preen)
+ pwarn("CONVERTING TO NEW CYLINDER GROUP FORMAT\n");
+ else if (!reply("CONVERT TO NEW CYLINDER GROUP FORMAT"))
+ return(0);
+ doinglevel1++;
+ sblock.fs_postblformat = FS_DYNAMICPOSTBLFMT;
+ sblock.fs_nrpos = 8;
+ sblock.fs_postbloff =
+ (char *)(&sblock.fs_opostbl[0][0]) -
+ (char *)(&sblock.fs_link);
+ sblock.fs_rotbloff = &sblock.fs_space[0] -
+ (u_char *)(&sblock.fs_link);
+ sblock.fs_cgsize =
+ fragroundup(&sblock, CGSIZE(&sblock));
+ sbdirty();
+ dirty(&asblk);
+ }
+ if (asblk.b_dirty && !bflag) {
+ bcopy((char *)&sblock, (char *)&altsblock,
+ (size_t)sblock.fs_sbsize);
+ flush(fswritefd, &asblk);
+ }
+ /*
+ * read in the summary info.
+ */
+ asked = 0;
+ for (i = 0, j = 0; i < sblock.fs_cssize; i += sblock.fs_bsize, j++) {
+ size = sblock.fs_cssize - i < sblock.fs_bsize ?
+ sblock.fs_cssize - i : sblock.fs_bsize;
+ sblock.fs_csp[j] = (struct csum *)calloc(1, (unsigned)size);
+ if (bread(fsreadfd, (char *)sblock.fs_csp[j],
+ fsbtodb(&sblock, sblock.fs_csaddr + j * sblock.fs_frag),
+ size) != 0 && !asked) {
+ pfatal("BAD SUMMARY INFORMATION");
+ if (reply("CONTINUE") == 0)
+ errexit("");
+ asked++;
+ }
+ }
+ /*
+ * allocate and initialize the necessary maps
+ */
+ bmapsize = roundup(howmany(maxfsblock, NBBY), sizeof(short));
+ blockmap = calloc((unsigned)bmapsize, sizeof (char));
+ if (blockmap == NULL) {
+ printf("cannot alloc %u bytes for blockmap\n",
+ (unsigned)bmapsize);
+ goto badsb;
+ }
+ statemap = calloc((unsigned)(maxino + 1), sizeof(char));
+ if (statemap == NULL) {
+ printf("cannot alloc %u bytes for statemap\n",
+ (unsigned)(maxino + 1));
+ goto badsb;
+ }
+ typemap = calloc((unsigned)(maxino + 1), sizeof(char));
+ if (typemap == NULL) {
+ printf("cannot alloc %u bytes for typemap\n",
+ (unsigned)(maxino + 1));
+ goto badsb;
+ }
+ lncntp = (short *)calloc((unsigned)(maxino + 1), sizeof(short));
+ if (lncntp == NULL) {
+ printf("cannot alloc %u bytes for lncntp\n",
+ (unsigned)(maxino + 1) * sizeof(short));
+ goto badsb;
+ }
+ numdirs = sblock.fs_cstotal.cs_ndir;
+ inplast = 0;
+ listmax = numdirs + 10;
+ inpsort = (struct inoinfo **)calloc((unsigned)listmax,
+ sizeof(struct inoinfo *));
+ inphead = (struct inoinfo **)calloc((unsigned)numdirs,
+ sizeof(struct inoinfo *));
+ if (inpsort == NULL || inphead == NULL) {
+ printf("cannot alloc %u bytes for inphead\n",
+ (unsigned)numdirs * sizeof(struct inoinfo *));
+ goto badsb;
+ }
+ bufinit();
+ return (1);
+
+badsb:
+ ckfini();
+ return (0);
+}
+
+/*
+ * Read in the super block and its summary info.
+ */
+readsb(listerr)
+ int listerr;
+{
+ daddr_t super = bflag ? bflag : SBOFF / dev_bsize;
+
+ if (bread(fsreadfd, (char *)&sblock, super, (long)SBSIZE) != 0)
+ return (0);
+ sblk.b_bno = super;
+ sblk.b_size = SBSIZE;
+ /*
+ * run a few consistency checks of the super block
+ */
+ if (sblock.fs_magic != FS_MAGIC)
+ { badsb(listerr, "MAGIC NUMBER WRONG"); return (0); }
+ if (sblock.fs_ncg < 1)
+ { badsb(listerr, "NCG OUT OF RANGE"); return (0); }
+ if (sblock.fs_cpg < 1)
+ { badsb(listerr, "CPG OUT OF RANGE"); return (0); }
+ if (sblock.fs_ncg * sblock.fs_cpg < sblock.fs_ncyl ||
+ (sblock.fs_ncg - 1) * sblock.fs_cpg >= sblock.fs_ncyl)
+ { badsb(listerr, "NCYL LESS THAN NCG*CPG"); return (0); }
+ if (sblock.fs_sbsize > SBSIZE)
+ { badsb(listerr, "SIZE PREPOSTEROUSLY LARGE"); return (0); }
+ /*
+ * Compute block size that the filesystem is based on,
+ * according to fsbtodb, and adjust superblock block number
+ * so we can tell if this is an alternate later.
+ */
+ super *= dev_bsize;
+ dev_bsize = sblock.fs_fsize / fsbtodb(&sblock, 1);
+ sblk.b_bno = super / dev_bsize;
+ if (bflag) {
+ havesb = 1;
+ return (1);
+ }
+ /*
+ * Set all possible fields that could differ, then do check
+ * of whole super block against an alternate super block.
+ * When an alternate super-block is specified this check is skipped.
+ */
+ getblk(&asblk, cgsblock(&sblock, sblock.fs_ncg - 1), sblock.fs_sbsize);
+ if (asblk.b_errs)
+ return (0);
+ altsblock.fs_link = sblock.fs_link;
+ altsblock.fs_rlink = sblock.fs_rlink;
+ altsblock.fs_time = sblock.fs_time;
+ altsblock.fs_cstotal = sblock.fs_cstotal;
+ altsblock.fs_cgrotor = sblock.fs_cgrotor;
+ altsblock.fs_fmod = sblock.fs_fmod;
+ altsblock.fs_clean = sblock.fs_clean;
+ altsblock.fs_ronly = sblock.fs_ronly;
+ altsblock.fs_flags = sblock.fs_flags;
+ altsblock.fs_maxcontig = sblock.fs_maxcontig;
+ altsblock.fs_minfree = sblock.fs_minfree;
+ altsblock.fs_optim = sblock.fs_optim;
+ altsblock.fs_rotdelay = sblock.fs_rotdelay;
+ altsblock.fs_maxbpg = sblock.fs_maxbpg;
+ bcopy((char *)sblock.fs_csp, (char *)altsblock.fs_csp,
+ sizeof sblock.fs_csp);
+ bcopy((char *)sblock.fs_fsmnt, (char *)altsblock.fs_fsmnt,
+ sizeof sblock.fs_fsmnt);
+ bcopy((char *)sblock.fs_sparecon, (char *)altsblock.fs_sparecon,
+ sizeof sblock.fs_sparecon);
+ /*
+ * The following should not have to be copied.
+ */
+ altsblock.fs_fsbtodb = sblock.fs_fsbtodb;
+ altsblock.fs_interleave = sblock.fs_interleave;
+ altsblock.fs_npsect = sblock.fs_npsect;
+ altsblock.fs_nrpos = sblock.fs_nrpos;
+ altsblock.fs_qbmask = sblock.fs_qbmask;
+ altsblock.fs_qfmask = sblock.fs_qfmask;
+ altsblock.fs_state = sblock.fs_state;
+ altsblock.fs_maxfilesize = sblock.fs_maxfilesize;
+ if (bcmp((char *)&sblock, (char *)&altsblock, (int)sblock.fs_sbsize)) {
+ badsb(listerr,
+ "VALUES IN SUPER BLOCK DISAGREE WITH THOSE IN FIRST ALTERNATE");
+ return (0);
+ }
+ havesb = 1;
+ return (1);
+}
+
+badsb(listerr, s)
+ int listerr;
+ char *s;
+{
+
+ if (!listerr)
+ return;
+ if (preen)
+ printf("%s: ", cdevname);
+ pfatal("BAD SUPER BLOCK: %s\n", s);
+}
+
+/* XXX */
+calcsb (dev, devfd, fs)
+ char *dev;
+ int devfd;
+ struct fs *fs;
+{
+ return 0;
+}
+
+#if 0
+/*
+ * Calculate a prototype superblock based on information in the disk label.
+ * When done the cgsblock macro can be calculated and the fs_ncg field
+ * can be used. Do NOT attempt to use other macros without verifying that
+ * their needed information is available!
+ */
+calcsb(dev, devfd, fs)
+ char *dev;
+ int devfd;
+ register struct fs *fs;
+{
+ register struct disklabel *lp;
+ register struct partition *pp;
+ register char *cp;
+ int i;
+
+ cp = index(dev, '\0') - 1;
+ if (cp == (char *)-1 || (*cp < 'a' || *cp > 'h') && !isdigit(*cp)) {
+ pfatal("%s: CANNOT FIGURE OUT FILE SYSTEM PARTITION\n", dev);
+ return (0);
+ }
+ lp = getdisklabel(dev, devfd);
+ if (isdigit(*cp))
+ pp = &lp->d_partitions[0];
+ else
+ pp = &lp->d_partitions[*cp - 'a'];
+ if (pp->p_fstype != FS_BSDFFS) {
+ pfatal("%s: NOT LABELED AS A BSD FILE SYSTEM (%s)\n",
+ dev, pp->p_fstype < FSMAXTYPES ?
+ fstypenames[pp->p_fstype] : "unknown");
+ return (0);
+ }
+ bzero((char *)fs, sizeof(struct fs));
+ fs->fs_fsize = pp->p_fsize;
+ fs->fs_frag = pp->p_frag;
+ fs->fs_cpg = pp->p_cpg;
+ fs->fs_size = pp->p_size;
+ fs->fs_ntrak = lp->d_ntracks;
+ fs->fs_nsect = lp->d_nsectors;
+ fs->fs_spc = lp->d_secpercyl;
+ fs->fs_nspf = fs->fs_fsize / lp->d_secsize;
+ fs->fs_sblkno = roundup(
+ howmany(lp->d_bbsize + lp->d_sbsize, fs->fs_fsize),
+ fs->fs_frag);
+ fs->fs_cgmask = 0xffffffff;
+ for (i = fs->fs_ntrak; i > 1; i >>= 1)
+ fs->fs_cgmask <<= 1;
+ if (!POWEROF2(fs->fs_ntrak))
+ fs->fs_cgmask <<= 1;
+ fs->fs_cgoffset = roundup(
+ howmany(fs->fs_nsect, NSPF(fs)), fs->fs_frag);
+ fs->fs_fpg = (fs->fs_cpg * fs->fs_spc) / NSPF(fs);
+ fs->fs_ncg = howmany(fs->fs_size / fs->fs_spc, fs->fs_cpg);
+ for (fs->fs_fsbtodb = 0, i = NSPF(fs); i > 1; i >>= 1)
+ fs->fs_fsbtodb++;
+ dev_bsize = lp->d_secsize;
+ return (1);
+}
+
+struct disklabel *
+getdisklabel(s, fd)
+ char *s;
+ int fd;
+{
+ static struct disklabel lab;
+
+ if (ioctl(fd, DIOCGDINFO, (char *)&lab) < 0) {
+ if (s == NULL)
+ return ((struct disklabel *)NULL);
+ pwarn("ioctl (GCINFO): %s\n", strerror(errno));
+ errexit("%s: can't read disk label\n", s);
+ }
+ return (&lab);
+}
+#endif
diff --git a/bsdfsck/utilities.c b/bsdfsck/utilities.c
new file mode 100644
index 00000000..1c281b1b
--- /dev/null
+++ b/bsdfsck/utilities.c
@@ -0,0 +1,567 @@
+/*
+ * Copyright (c) 1980, 1986, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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.
+ */
+
+#ifndef lint
+/*static char sccsid[] = "from: @(#)utilities.c 8.1 (Berkeley) 6/5/93";*/
+static char *rcsid = "$Id: utilities.c,v 1.2 1994/08/23 20:18:15 mib Exp $";
+#endif /* not lint */
+
+#include <sys/param.h>
+#include <sys/time.h>
+#include "../ufs/dinode.h"
+#include "../ufs/dir.h"
+#include "../ufs/fs.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include "fsck.h"
+
+long diskreads, totalreads; /* Disk cache statistics */
+
+ftypeok(dp)
+ struct dinode *dp;
+{
+ switch (DI_MODE(dp) & IFMT) {
+
+ case IFDIR:
+ case IFREG:
+ case IFBLK:
+ case IFCHR:
+ case IFLNK:
+ case IFSOCK:
+ case IFIFO:
+ return (1);
+
+ default:
+ if (debug)
+ printf("bad file type 0%o\n", DI_MODE(dp));
+ return (0);
+ }
+}
+
+reply(question)
+ char *question;
+{
+ int persevere;
+ char c;
+
+ if (preen)
+ pfatal("INTERNAL ERROR: GOT TO reply()");
+ persevere = !strcmp(question, "CONTINUE");
+ printf("\n");
+ if (!persevere && (nflag || fswritefd < 0)) {
+ printf("%s? no\n\n", question);
+ return (0);
+ }
+ if (yflag || (persevere && nflag)) {
+ printf("%s? yes\n\n", question);
+ return (1);
+ }
+ do {
+ printf("%s? [yn] ", question);
+ (void) fflush(stdout);
+ c = getc(stdin);
+ while (c != '\n' && getc(stdin) != '\n')
+ if (feof(stdin))
+ return (0);
+ } while (c != 'y' && c != 'Y' && c != 'n' && c != 'N');
+ printf("\n");
+ if (c == 'y' || c == 'Y')
+ return (1);
+ return (0);
+}
+
+/*
+ * Malloc buffers and set up cache.
+ */
+bufinit()
+{
+ register struct bufarea *bp;
+ long bufcnt, i;
+ char *bufp;
+
+ pbp = pdirbp = (struct bufarea *)0;
+ bufp = malloc((unsigned int)sblock.fs_bsize);
+ if (bufp == 0)
+ errexit("cannot allocate buffer pool\n");
+ cgblk.b_un.b_buf = bufp;
+ initbarea(&cgblk);
+ bufhead.b_next = bufhead.b_prev = &bufhead;
+ bufcnt = MAXBUFSPACE / sblock.fs_bsize;
+ if (bufcnt < MINBUFS)
+ bufcnt = MINBUFS;
+ for (i = 0; i < bufcnt; i++) {
+ bp = (struct bufarea *)malloc(sizeof(struct bufarea));
+ bufp = malloc((unsigned int)sblock.fs_bsize);
+ if (bp == NULL || bufp == NULL) {
+ if (i >= MINBUFS)
+ break;
+ errexit("cannot allocate buffer pool\n");
+ }
+ bp->b_un.b_buf = bufp;
+ bp->b_prev = &bufhead;
+ bp->b_next = bufhead.b_next;
+ bufhead.b_next->b_prev = bp;
+ bufhead.b_next = bp;
+ initbarea(bp);
+ }
+ bufhead.b_size = i; /* save number of buffers */
+}
+
+/*
+ * Manage a cache of directory blocks.
+ */
+struct bufarea *
+getdatablk(blkno, size)
+ daddr_t blkno;
+ long size;
+{
+ register struct bufarea *bp;
+
+ for (bp = bufhead.b_next; bp != &bufhead; bp = bp->b_next)
+ if (bp->b_bno == fsbtodb(&sblock, blkno))
+ goto foundit;
+ for (bp = bufhead.b_prev; bp != &bufhead; bp = bp->b_prev)
+ if ((bp->b_flags & B_INUSE) == 0)
+ break;
+ if (bp == &bufhead)
+ errexit("deadlocked buffer pool\n");
+ getblk(bp, blkno, size);
+ /* fall through */
+foundit:
+ totalreads++;
+ bp->b_prev->b_next = bp->b_next;
+ bp->b_next->b_prev = bp->b_prev;
+ bp->b_prev = &bufhead;
+ bp->b_next = bufhead.b_next;
+ bufhead.b_next->b_prev = bp;
+ bufhead.b_next = bp;
+ bp->b_flags |= B_INUSE;
+ return (bp);
+}
+
+void
+getblk(bp, blk, size)
+ register struct bufarea *bp;
+ daddr_t blk;
+ long size;
+{
+ daddr_t dblk;
+
+ dblk = fsbtodb(&sblock, blk);
+ if (bp->b_bno != dblk) {
+ flush(fswritefd, bp);
+ diskreads++;
+ bp->b_errs = bread(fsreadfd, bp->b_un.b_buf, dblk, size);
+ bp->b_bno = dblk;
+ bp->b_size = size;
+ }
+}
+
+flush(fd, bp)
+ int fd;
+ register struct bufarea *bp;
+{
+ register int i, j;
+
+ if (!bp->b_dirty)
+ return;
+ if (bp->b_errs != 0)
+ pfatal("WRITING %sZERO'ED BLOCK %d TO DISK\n",
+ (bp->b_errs == bp->b_size / dev_bsize) ? "" : "PARTIALLY ",
+ bp->b_bno);
+ bp->b_dirty = 0;
+ bp->b_errs = 0;
+ bwrite(fd, bp->b_un.b_buf, bp->b_bno, (long)bp->b_size);
+ if (bp != &sblk)
+ return;
+ for (i = 0, j = 0; i < sblock.fs_cssize; i += sblock.fs_bsize, j++) {
+ bwrite(fswritefd, (char *)sblock.fs_csp[j],
+ fsbtodb(&sblock, sblock.fs_csaddr + j * sblock.fs_frag),
+ sblock.fs_cssize - i < sblock.fs_bsize ?
+ sblock.fs_cssize - i : sblock.fs_bsize);
+ }
+}
+
+rwerror(mesg, blk)
+ char *mesg;
+ daddr_t blk;
+{
+
+ if (preen == 0)
+ printf("\n");
+ pfatal("CANNOT %s: BLK %ld", mesg, blk);
+ if (reply("CONTINUE") == 0)
+ errexit("Program terminated\n");
+}
+
+ckfini()
+{
+ register struct bufarea *bp, *nbp;
+ int cnt = 0;
+
+ if (fswritefd < 0) {
+ (void)close(fsreadfd);
+ return;
+ }
+ flush(fswritefd, &sblk);
+ if (havesb && sblk.b_bno != SBOFF / dev_bsize &&
+ !preen && reply("UPDATE STANDARD SUPERBLOCK")) {
+ sblk.b_bno = SBOFF / dev_bsize;
+ sbdirty();
+ flush(fswritefd, &sblk);
+ }
+ flush(fswritefd, &cgblk);
+ free(cgblk.b_un.b_buf);
+ for (bp = bufhead.b_prev; bp && bp != &bufhead; bp = nbp) {
+ cnt++;
+ flush(fswritefd, bp);
+ nbp = bp->b_prev;
+ free(bp->b_un.b_buf);
+ free((char *)bp);
+ }
+ if (bufhead.b_size != cnt)
+ errexit("Panic: lost %d buffers\n", bufhead.b_size - cnt);
+ pbp = pdirbp = (struct bufarea *)0;
+ if (debug)
+ printf("cache missed %ld of %ld (%d%%)\n", diskreads,
+ totalreads, (int)(diskreads * 100 / totalreads));
+ (void)close(fsreadfd);
+ (void)close(fswritefd);
+}
+
+bread(fd, buf, blk, size)
+ int fd;
+ char *buf;
+ daddr_t blk;
+ long size;
+{
+ char *cp;
+ int i, errs;
+ off_t offset;
+
+ offset = blk;
+ offset *= dev_bsize;
+ if (lseek(fd, offset, 0) < 0)
+ rwerror("SEEK", blk);
+ else if (read(fd, buf, (int)size) == size)
+ return (0);
+ rwerror("READ", blk);
+ if (lseek(fd, offset, 0) < 0)
+ rwerror("SEEK", blk);
+ errs = 0;
+ bzero(buf, (size_t)size);
+ printf("THE FOLLOWING DISK SECTORS COULD NOT BE READ:");
+ for (cp = buf, i = 0; i < size; i += secsize, cp += secsize) {
+ if (read(fd, cp, (int)secsize) != secsize) {
+ (void)lseek(fd, offset + i + secsize, 0);
+ if (secsize != dev_bsize && dev_bsize != 1)
+ printf(" %ld (%ld),",
+ (blk * dev_bsize + i) / secsize,
+ blk + i / dev_bsize);
+ else
+ printf(" %ld,", blk + i / dev_bsize);
+ errs++;
+ }
+ }
+ printf("\n");
+ return (errs);
+}
+
+bwrite(fd, buf, blk, size)
+ int fd;
+ char *buf;
+ daddr_t blk;
+ long size;
+{
+ int i;
+ char *cp;
+ off_t offset;
+
+ if (fd < 0)
+ return;
+ offset = blk;
+ offset *= dev_bsize;
+ if (lseek(fd, offset, 0) < 0)
+ rwerror("SEEK", blk);
+ else if (write(fd, buf, (int)size) == size) {
+ fsmodified = 1;
+ return;
+ }
+ rwerror("WRITE", blk);
+ if (lseek(fd, offset, 0) < 0)
+ rwerror("SEEK", blk);
+ printf("THE FOLLOWING SECTORS COULD NOT BE WRITTEN:");
+ for (cp = buf, i = 0; i < size; i += dev_bsize, cp += dev_bsize)
+ if (write(fd, cp, (int)dev_bsize) != dev_bsize) {
+ (void)lseek(fd, offset + i + dev_bsize, 0);
+ printf(" %ld,", blk + i / dev_bsize);
+ }
+ printf("\n");
+ return;
+}
+
+/*
+ * allocate a data block with the specified number of fragments
+ */
+allocblk(frags)
+ long frags;
+{
+ register int i, j, k;
+
+ if (frags <= 0 || frags > sblock.fs_frag)
+ return (0);
+ for (i = 0; i < maxfsblock - sblock.fs_frag; i += sblock.fs_frag) {
+ for (j = 0; j <= sblock.fs_frag - frags; j++) {
+ if (testbmap(i + j))
+ continue;
+ for (k = 1; k < frags; k++)
+ if (testbmap(i + j + k))
+ break;
+ if (k < frags) {
+ j += k;
+ continue;
+ }
+ for (k = 0; k < frags; k++)
+ setbmap(i + j + k);
+ n_blks += frags;
+ return (i + j);
+ }
+ }
+ return (0);
+}
+
+/*
+ * Free a previously allocated block
+ */
+freeblk(blkno, frags)
+ daddr_t blkno;
+ long frags;
+{
+ struct inodesc idesc;
+
+ idesc.id_blkno = blkno;
+ idesc.id_numfrags = frags;
+ (void)pass4check(&idesc);
+}
+
+/*
+ * Find a pathname
+ */
+getpathname(namebuf, curdir, ino)
+ char *namebuf;
+ ino_t curdir, ino;
+{
+ int len;
+ register char *cp;
+ struct inodesc idesc;
+ static int busy = 0;
+ extern int findname();
+
+ if (curdir == ino && ino == ROOTINO) {
+ (void)strcpy(namebuf, "/");
+ return;
+ }
+ if (busy ||
+ (statemap[curdir] != DSTATE && statemap[curdir] != DFOUND)) {
+ (void)strcpy(namebuf, "?");
+ return;
+ }
+ busy = 1;
+ bzero((char *)&idesc, sizeof(struct inodesc));
+ idesc.id_type = DATA;
+ idesc.id_fix = IGNORE;
+ cp = &namebuf[MAXPATHLEN - 1];
+ *cp = '\0';
+ if (curdir != ino) {
+ idesc.id_parent = curdir;
+ goto namelookup;
+ }
+ while (ino != ROOTINO) {
+ idesc.id_number = ino;
+ idesc.id_func = findino;
+ idesc.id_name = "..";
+ if ((ckinode(ginode(ino), &idesc) & FOUND) == 0)
+ break;
+ namelookup:
+ idesc.id_number = idesc.id_parent;
+ idesc.id_parent = ino;
+ idesc.id_func = findname;
+ idesc.id_name = namebuf;
+ if ((ckinode(ginode(idesc.id_number), &idesc)&FOUND) == 0)
+ break;
+ len = strlen(namebuf);
+ cp -= len;
+ bcopy(namebuf, cp, (size_t)len);
+ *--cp = '/';
+ if (cp < &namebuf[MAXNAMLEN])
+ break;
+ ino = idesc.id_number;
+ }
+ busy = 0;
+ if (ino != ROOTINO)
+ *--cp = '?';
+ bcopy(cp, namebuf, (size_t)(&namebuf[MAXPATHLEN] - cp));
+}
+
+void
+catch()
+{
+ if (!doinglevel2)
+ ckfini();
+ exit(12);
+}
+
+/*
+ * When preening, allow a single quit to signal
+ * a special exit after filesystem checks complete
+ * so that reboot sequence may be interrupted.
+ */
+void
+catchquit()
+{
+ extern returntosingle;
+
+ printf("returning to single-user after filesystem check\n");
+ returntosingle = 1;
+ (void)signal(SIGQUIT, SIG_DFL);
+}
+
+/*
+ * Ignore a single quit signal; wait and flush just in case.
+ * Used by child processes in preen.
+ */
+void
+voidquit()
+{
+
+ sleep(1);
+ (void)signal(SIGQUIT, SIG_IGN);
+ (void)signal(SIGQUIT, SIG_DFL);
+}
+
+/*
+ * determine whether an inode should be fixed.
+ */
+dofix(idesc, msg)
+ register struct inodesc *idesc;
+ char *msg;
+{
+
+ switch (idesc->id_fix) {
+
+ case DONTKNOW:
+ if (idesc->id_type == DATA)
+ direrror(idesc->id_number, msg);
+ else
+ pwarn(msg);
+ if (preen) {
+ printf(" (SALVAGED)\n");
+ idesc->id_fix = FIX;
+ return (ALTERED);
+ }
+ if (reply("SALVAGE") == 0) {
+ idesc->id_fix = NOFIX;
+ return (0);
+ }
+ idesc->id_fix = FIX;
+ return (ALTERED);
+
+ case FIX:
+ return (ALTERED);
+
+ case NOFIX:
+ case IGNORE:
+ return (0);
+
+ default:
+ errexit("UNKNOWN INODESC FIX MODE %d\n", idesc->id_fix);
+ }
+ /* NOTREACHED */
+}
+
+/* VARARGS1 */
+errexit(s1, s2, s3, s4)
+ char *s1;
+{
+ printf(s1, s2, s3, s4);
+ exit(8);
+}
+
+/*
+ * An unexpected inconsistency occurred.
+ * Die if preening, otherwise just print message and continue.
+ */
+/* VARARGS1 */
+pfatal(s, a1, a2, a3)
+ char *s;
+{
+
+ if (preen) {
+ printf("%s: ", cdevname);
+ printf(s, a1, a2, a3);
+ printf("\n");
+ printf("%s: UNEXPECTED INCONSISTENCY; RUN fsck MANUALLY.\n",
+ cdevname);
+ exit(8);
+ }
+ printf(s, a1, a2, a3);
+}
+
+/*
+ * Pwarn just prints a message when not preening,
+ * or a warning (preceded by filename) when preening.
+ */
+/* VARARGS1 */
+pwarn(s, a1, a2, a3, a4, a5, a6)
+ char *s;
+{
+
+ if (preen)
+ printf("%s: ", cdevname);
+ printf(s, a1, a2, a3, a4, a5, a6);
+}
+
+#ifndef lint
+/*
+ * Stub for routines from kernel.
+ */
+panic(s)
+ char *s;
+{
+
+ pfatal("INTERNAL INCONSISTENCY:");
+ errexit(s);
+}
+#endif
diff --git a/configure b/configure
new file mode 100755
index 00000000..1fab7980
--- /dev/null
+++ b/configure
@@ -0,0 +1,5868 @@
+#! /bin/sh
+# From configure.in Id: configure.in,v 1.38 2008/11/17 11:34:18 tschwinge Exp .
+# Guess values for system-dependent variables and create Makefiles.
+# Generated by GNU Autoconf 2.67 for GNU Hurd 0.3.
+#
+# Report bugs to <bug-hurd@gnu.org>.
+#
+#
+# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
+# 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software
+# Foundation, Inc.
+#
+#
+# This configure script is free software; the Free Software Foundation
+# gives unlimited permission to copy, distribute and modify it.
+## -------------------- ##
+## M4sh Initialization. ##
+## -------------------- ##
+
+# Be more Bourne compatible
+DUALCASE=1; export DUALCASE # for MKS sh
+if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
+ emulate sh
+ NULLCMD=:
+ # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
+ # is contrary to our usage. Disable this feature.
+ alias -g '${1+"$@"}'='"$@"'
+ setopt NO_GLOB_SUBST
+else
+ case `(set -o) 2>/dev/null` in #(
+ *posix*) :
+ set -o posix ;; #(
+ *) :
+ ;;
+esac
+fi
+
+
+as_nl='
+'
+export as_nl
+# Printing a long string crashes Solaris 7 /usr/bin/printf.
+as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'
+as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo
+as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo
+# Prefer a ksh shell builtin over an external printf program on Solaris,
+# but without wasting forks for bash or zsh.
+if test -z "$BASH_VERSION$ZSH_VERSION" \
+ && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then
+ as_echo='print -r --'
+ as_echo_n='print -rn --'
+elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then
+ as_echo='printf %s\n'
+ as_echo_n='printf %s'
+else
+ if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then
+ as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"'
+ as_echo_n='/usr/ucb/echo -n'
+ else
+ as_echo_body='eval expr "X$1" : "X\\(.*\\)"'
+ as_echo_n_body='eval
+ arg=$1;
+ case $arg in #(
+ *"$as_nl"*)
+ expr "X$arg" : "X\\(.*\\)$as_nl";
+ arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;;
+ esac;
+ expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl"
+ '
+ export as_echo_n_body
+ as_echo_n='sh -c $as_echo_n_body as_echo'
+ fi
+ export as_echo_body
+ as_echo='sh -c $as_echo_body as_echo'
+fi
+
+# The user is always right.
+if test "${PATH_SEPARATOR+set}" != set; then
+ PATH_SEPARATOR=:
+ (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {
+ (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||
+ PATH_SEPARATOR=';'
+ }
+fi
+
+
+# IFS
+# We need space, tab and new line, in precisely that order. Quoting is
+# there to prevent editors from complaining about space-tab.
+# (If _AS_PATH_WALK were called with IFS unset, it would disable word
+# splitting by setting IFS to empty value.)
+IFS=" "" $as_nl"
+
+# Find who we are. Look in the path if we contain no directory separator.
+case $0 in #((
+ *[\\/]* ) as_myself=$0 ;;
+ *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break
+ done
+IFS=$as_save_IFS
+
+ ;;
+esac
+# We did not find ourselves, most probably we were run as `sh COMMAND'
+# in which case we are not to be found in the path.
+if test "x$as_myself" = x; then
+ as_myself=$0
+fi
+if test ! -f "$as_myself"; then
+ $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2
+ exit 1
+fi
+
+# Unset variables that we do not need and which cause bugs (e.g. in
+# pre-3.0 UWIN ksh). But do not cause bugs in bash 2.01; the "|| exit 1"
+# suppresses any "Segmentation fault" message there. '((' could
+# trigger a bug in pdksh 5.2.14.
+for as_var in BASH_ENV ENV MAIL MAILPATH
+do eval test x\${$as_var+set} = xset \
+ && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || :
+done
+PS1='$ '
+PS2='> '
+PS4='+ '
+
+# NLS nuisances.
+LC_ALL=C
+export LC_ALL
+LANGUAGE=C
+export LANGUAGE
+
+# CDPATH.
+(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
+
+if test "x$CONFIG_SHELL" = x; then
+ as_bourne_compatible="if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then :
+ emulate sh
+ NULLCMD=:
+ # Pre-4.2 versions of Zsh do word splitting on \${1+\"\$@\"}, which
+ # is contrary to our usage. Disable this feature.
+ alias -g '\${1+\"\$@\"}'='\"\$@\"'
+ setopt NO_GLOB_SUBST
+else
+ case \`(set -o) 2>/dev/null\` in #(
+ *posix*) :
+ set -o posix ;; #(
+ *) :
+ ;;
+esac
+fi
+"
+ as_required="as_fn_return () { (exit \$1); }
+as_fn_success () { as_fn_return 0; }
+as_fn_failure () { as_fn_return 1; }
+as_fn_ret_success () { return 0; }
+as_fn_ret_failure () { return 1; }
+
+exitcode=0
+as_fn_success || { exitcode=1; echo as_fn_success failed.; }
+as_fn_failure && { exitcode=1; echo as_fn_failure succeeded.; }
+as_fn_ret_success || { exitcode=1; echo as_fn_ret_success failed.; }
+as_fn_ret_failure && { exitcode=1; echo as_fn_ret_failure succeeded.; }
+if ( set x; as_fn_ret_success y && test x = \"\$1\" ); then :
+
+else
+ exitcode=1; echo positional parameters were not saved.
+fi
+test x\$exitcode = x0 || exit 1"
+ as_suggested=" as_lineno_1=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_1a=\$LINENO
+ as_lineno_2=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_2a=\$LINENO
+ eval 'test \"x\$as_lineno_1'\$as_run'\" != \"x\$as_lineno_2'\$as_run'\" &&
+ test \"x\`expr \$as_lineno_1'\$as_run' + 1\`\" = \"x\$as_lineno_2'\$as_run'\"' || exit 1
+test \$(( 1 + 1 )) = 2 || exit 1"
+ if (eval "$as_required") 2>/dev/null; then :
+ as_have_required=yes
+else
+ as_have_required=no
+fi
+ if test x$as_have_required = xyes && (eval "$as_suggested") 2>/dev/null; then :
+
+else
+ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+as_found=false
+for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ as_found=:
+ case $as_dir in #(
+ /*)
+ for as_base in sh bash ksh sh5; do
+ # Try only shells that exist, to save several forks.
+ as_shell=$as_dir/$as_base
+ if { test -f "$as_shell" || test -f "$as_shell.exe"; } &&
+ { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$as_shell"; } 2>/dev/null; then :
+ CONFIG_SHELL=$as_shell as_have_required=yes
+ if { $as_echo "$as_bourne_compatible""$as_suggested" | as_run=a "$as_shell"; } 2>/dev/null; then :
+ break 2
+fi
+fi
+ done;;
+ esac
+ as_found=false
+done
+$as_found || { if { test -f "$SHELL" || test -f "$SHELL.exe"; } &&
+ { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$SHELL"; } 2>/dev/null; then :
+ CONFIG_SHELL=$SHELL as_have_required=yes
+fi; }
+IFS=$as_save_IFS
+
+
+ if test "x$CONFIG_SHELL" != x; then :
+ # We cannot yet assume a decent shell, so we have to provide a
+ # neutralization value for shells without unset; and this also
+ # works around shells that cannot unset nonexistent variables.
+ BASH_ENV=/dev/null
+ ENV=/dev/null
+ (unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV
+ export CONFIG_SHELL
+ exec "$CONFIG_SHELL" "$as_myself" ${1+"$@"}
+fi
+
+ if test x$as_have_required = xno; then :
+ $as_echo "$0: This script requires a shell more modern than all"
+ $as_echo "$0: the shells that I found on your system."
+ if test x${ZSH_VERSION+set} = xset ; then
+ $as_echo "$0: In particular, zsh $ZSH_VERSION has bugs and should"
+ $as_echo "$0: be upgraded to zsh 4.3.4 or later."
+ else
+ $as_echo "$0: Please tell bug-autoconf@gnu.org and bug-hurd@gnu.org
+$0: about your system, including any error possibly output
+$0: before this message. Then install a modern shell, or
+$0: manually run the script under such a shell if you do
+$0: have one."
+ fi
+ exit 1
+fi
+fi
+fi
+SHELL=${CONFIG_SHELL-/bin/sh}
+export SHELL
+# Unset more variables known to interfere with behavior of common tools.
+CLICOLOR_FORCE= GREP_OPTIONS=
+unset CLICOLOR_FORCE GREP_OPTIONS
+
+## --------------------- ##
+## M4sh Shell Functions. ##
+## --------------------- ##
+# as_fn_unset VAR
+# ---------------
+# Portably unset VAR.
+as_fn_unset ()
+{
+ { eval $1=; unset $1;}
+}
+as_unset=as_fn_unset
+
+# as_fn_set_status STATUS
+# -----------------------
+# Set $? to STATUS, without forking.
+as_fn_set_status ()
+{
+ return $1
+} # as_fn_set_status
+
+# as_fn_exit STATUS
+# -----------------
+# Exit the shell with STATUS, even in a "trap 0" or "set -e" context.
+as_fn_exit ()
+{
+ set +e
+ as_fn_set_status $1
+ exit $1
+} # as_fn_exit
+
+# as_fn_mkdir_p
+# -------------
+# Create "$as_dir" as a directory, including parents if necessary.
+as_fn_mkdir_p ()
+{
+
+ case $as_dir in #(
+ -*) as_dir=./$as_dir;;
+ esac
+ test -d "$as_dir" || eval $as_mkdir_p || {
+ as_dirs=
+ while :; do
+ case $as_dir in #(
+ *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'(
+ *) as_qdir=$as_dir;;
+ esac
+ as_dirs="'$as_qdir' $as_dirs"
+ as_dir=`$as_dirname -- "$as_dir" ||
+$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+ X"$as_dir" : 'X\(//\)[^/]' \| \
+ X"$as_dir" : 'X\(//\)$' \| \
+ X"$as_dir" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X"$as_dir" |
+ sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+ s//\1/
+ q
+ }
+ /^X\(\/\/\)[^/].*/{
+ s//\1/
+ q
+ }
+ /^X\(\/\/\)$/{
+ s//\1/
+ q
+ }
+ /^X\(\/\).*/{
+ s//\1/
+ q
+ }
+ s/.*/./; q'`
+ test -d "$as_dir" && break
+ done
+ test -z "$as_dirs" || eval "mkdir $as_dirs"
+ } || test -d "$as_dir" || as_fn_error $? "cannot create directory $as_dir"
+
+
+} # as_fn_mkdir_p
+# as_fn_append VAR VALUE
+# ----------------------
+# Append the text in VALUE to the end of the definition contained in VAR. Take
+# advantage of any shell optimizations that allow amortized linear growth over
+# repeated appends, instead of the typical quadratic growth present in naive
+# implementations.
+if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then :
+ eval 'as_fn_append ()
+ {
+ eval $1+=\$2
+ }'
+else
+ as_fn_append ()
+ {
+ eval $1=\$$1\$2
+ }
+fi # as_fn_append
+
+# as_fn_arith ARG...
+# ------------------
+# Perform arithmetic evaluation on the ARGs, and store the result in the
+# global $as_val. Take advantage of shells that can avoid forks. The arguments
+# must be portable across $(()) and expr.
+if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then :
+ eval 'as_fn_arith ()
+ {
+ as_val=$(( $* ))
+ }'
+else
+ as_fn_arith ()
+ {
+ as_val=`expr "$@" || test $? -eq 1`
+ }
+fi # as_fn_arith
+
+
+# as_fn_error STATUS ERROR [LINENO LOG_FD]
+# ----------------------------------------
+# Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are
+# provided, also output the error to LOG_FD, referencing LINENO. Then exit the
+# script with STATUS, using 1 if that was 0.
+as_fn_error ()
+{
+ as_status=$1; test $as_status -eq 0 && as_status=1
+ if test "$4"; then
+ as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+ $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4
+ fi
+ $as_echo "$as_me: error: $2" >&2
+ as_fn_exit $as_status
+} # as_fn_error
+
+if expr a : '\(a\)' >/dev/null 2>&1 &&
+ test "X`expr 00001 : '.*\(...\)'`" = X001; then
+ as_expr=expr
+else
+ as_expr=false
+fi
+
+if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then
+ as_basename=basename
+else
+ as_basename=false
+fi
+
+if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then
+ as_dirname=dirname
+else
+ as_dirname=false
+fi
+
+as_me=`$as_basename -- "$0" ||
+$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \
+ X"$0" : 'X\(//\)$' \| \
+ X"$0" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X/"$0" |
+ sed '/^.*\/\([^/][^/]*\)\/*$/{
+ s//\1/
+ q
+ }
+ /^X\/\(\/\/\)$/{
+ s//\1/
+ q
+ }
+ /^X\/\(\/\).*/{
+ s//\1/
+ q
+ }
+ s/.*/./; q'`
+
+# Avoid depending upon Character Ranges.
+as_cr_letters='abcdefghijklmnopqrstuvwxyz'
+as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
+as_cr_Letters=$as_cr_letters$as_cr_LETTERS
+as_cr_digits='0123456789'
+as_cr_alnum=$as_cr_Letters$as_cr_digits
+
+
+ as_lineno_1=$LINENO as_lineno_1a=$LINENO
+ as_lineno_2=$LINENO as_lineno_2a=$LINENO
+ eval 'test "x$as_lineno_1'$as_run'" != "x$as_lineno_2'$as_run'" &&
+ test "x`expr $as_lineno_1'$as_run' + 1`" = "x$as_lineno_2'$as_run'"' || {
+ # Blame Lee E. McMahon (1931-1989) for sed's syntax. :-)
+ sed -n '
+ p
+ /[$]LINENO/=
+ ' <$as_myself |
+ sed '
+ s/[$]LINENO.*/&-/
+ t lineno
+ b
+ :lineno
+ N
+ :loop
+ s/[$]LINENO\([^'$as_cr_alnum'_].*\n\)\(.*\)/\2\1\2/
+ t loop
+ s/-\n.*//
+ ' >$as_me.lineno &&
+ chmod +x "$as_me.lineno" ||
+ { $as_echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2; as_fn_exit 1; }
+
+ # Don't try to exec as it changes $[0], causing all sort of problems
+ # (the dirname of $[0] is not the place where we might find the
+ # original and so on. Autoconf is especially sensitive to this).
+ . "./$as_me.lineno"
+ # Exit status is that of the last command.
+ exit
+}
+
+ECHO_C= ECHO_N= ECHO_T=
+case `echo -n x` in #(((((
+-n*)
+ case `echo 'xy\c'` in
+ *c*) ECHO_T=' ';; # ECHO_T is single tab character.
+ xy) ECHO_C='\c';;
+ *) echo `echo ksh88 bug on AIX 6.1` > /dev/null
+ ECHO_T=' ';;
+ esac;;
+*)
+ ECHO_N='-n';;
+esac
+
+rm -f conf$$ conf$$.exe conf$$.file
+if test -d conf$$.dir; then
+ rm -f conf$$.dir/conf$$.file
+else
+ rm -f conf$$.dir
+ mkdir conf$$.dir 2>/dev/null
+fi
+if (echo >conf$$.file) 2>/dev/null; then
+ if ln -s conf$$.file conf$$ 2>/dev/null; then
+ as_ln_s='ln -s'
+ # ... but there are two gotchas:
+ # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail.
+ # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable.
+ # In both cases, we have to default to `cp -p'.
+ ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe ||
+ as_ln_s='cp -p'
+ elif ln conf$$.file conf$$ 2>/dev/null; then
+ as_ln_s=ln
+ else
+ as_ln_s='cp -p'
+ fi
+else
+ as_ln_s='cp -p'
+fi
+rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file
+rmdir conf$$.dir 2>/dev/null
+
+if mkdir -p . 2>/dev/null; then
+ as_mkdir_p='mkdir -p "$as_dir"'
+else
+ test -d ./-p && rmdir ./-p
+ as_mkdir_p=false
+fi
+
+if test -x / >/dev/null 2>&1; then
+ as_test_x='test -x'
+else
+ if ls -dL / >/dev/null 2>&1; then
+ as_ls_L_option=L
+ else
+ as_ls_L_option=
+ fi
+ as_test_x='
+ eval sh -c '\''
+ if test -d "$1"; then
+ test -d "$1/.";
+ else
+ case $1 in #(
+ -*)set "./$1";;
+ esac;
+ case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in #((
+ ???[sx]*):;;*)false;;esac;fi
+ '\'' sh
+ '
+fi
+as_executable_p=$as_test_x
+
+# Sed expression to map a string onto a valid CPP name.
+as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'"
+
+# Sed expression to map a string onto a valid variable name.
+as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'"
+
+
+test -n "$DJDIR" || exec 7<&0 </dev/null
+exec 6>&1
+
+# Name of the host.
+# hostname on some systems (SVR3.2, old GNU/Linux) returns a bogus exit status,
+# so uname gets run too.
+ac_hostname=`(hostname || uname -n) 2>/dev/null | sed 1q`
+
+#
+# Initializations.
+#
+ac_default_prefix=/usr/local
+ac_clean_files=
+ac_config_libobj_dir=.
+LIBOBJS=
+cross_compiling=no
+subdirs=
+MFLAGS=
+MAKEFLAGS=
+
+# Identity of this package.
+PACKAGE_NAME='GNU Hurd'
+PACKAGE_TARNAME='hurd'
+PACKAGE_VERSION='0.3'
+PACKAGE_STRING='GNU Hurd 0.3'
+PACKAGE_BUGREPORT='bug-hurd@gnu.org'
+PACKAGE_URL='http://www.gnu.org/software/hurd/'
+
+ac_unique_file="hurd/hurd_types.h"
+ac_default_prefix=
+# Factoring default headers for most tests.
+ac_includes_default="\
+#include <stdio.h>
+#ifdef HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_STAT_H
+# include <sys/stat.h>
+#endif
+#ifdef STDC_HEADERS
+# include <stdlib.h>
+# include <stddef.h>
+#else
+# ifdef HAVE_STDLIB_H
+# include <stdlib.h>
+# endif
+#endif
+#ifdef HAVE_STRING_H
+# if !defined STDC_HEADERS && defined HAVE_MEMORY_H
+# include <memory.h>
+# endif
+# include <string.h>
+#endif
+#ifdef HAVE_STRINGS_H
+# include <strings.h>
+#endif
+#ifdef HAVE_INTTYPES_H
+# include <inttypes.h>
+#endif
+#ifdef HAVE_STDINT_H
+# include <stdint.h>
+#endif
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif"
+
+ac_subst_vars='LTLIBOBJS
+LIBOBJS
+HAVE_SUN_RPC
+LIBNCURSESW
+NCURSESW_INCLUDE
+boot_store_types
+PARTED_LIBS
+EGREP
+GREP
+CPP
+libc_cv_gnu89_inline
+VERSIONING
+LIBCRYPT
+MIG
+RANLIB
+AR
+OBJCOPY
+LD
+OBJEXT
+EXEEXT
+ac_ct_CC
+CPPFLAGS
+LDFLAGS
+CFLAGS
+CC
+AWK
+INSTALL_DATA
+INSTALL_SCRIPT
+INSTALL_PROGRAM
+enable_static_progs
+enable_profile
+asm_syntax
+host_os
+host_vendor
+host_cpu
+host
+build_os
+build_vendor
+build_cpu
+build
+target_alias
+host_alias
+build_alias
+LIBS
+ECHO_T
+ECHO_N
+ECHO_C
+DEFS
+mandir
+localedir
+libdir
+psdir
+pdfdir
+dvidir
+htmldir
+infodir
+docdir
+oldincludedir
+includedir
+localstatedir
+sharedstatedir
+sysconfdir
+datadir
+datarootdir
+libexecdir
+sbindir
+bindir
+program_transform_name
+prefix
+exec_prefix
+PACKAGE_URL
+PACKAGE_BUGREPORT
+PACKAGE_STRING
+PACKAGE_VERSION
+PACKAGE_TARNAME
+PACKAGE_NAME
+PATH_SEPARATOR
+SHELL'
+ac_subst_files=''
+ac_user_opts='
+enable_option_checking
+enable_profile
+enable_static_progs
+with_parted
+enable_boot_store_types
+enable_ncursesw
+with_ncursesw_include_dir
+'
+ ac_precious_vars='build_alias
+host_alias
+target_alias
+CC
+CFLAGS
+LDFLAGS
+LIBS
+CPPFLAGS
+CPP'
+
+
+# Initialize some variables set by options.
+ac_init_help=
+ac_init_version=false
+ac_unrecognized_opts=
+ac_unrecognized_sep=
+# The variables have the same names as the options, with
+# dashes changed to underlines.
+cache_file=/dev/null
+exec_prefix=NONE
+no_create=
+no_recursion=
+prefix=NONE
+program_prefix=NONE
+program_suffix=NONE
+program_transform_name=s,x,x,
+silent=
+site=
+srcdir=
+verbose=
+x_includes=NONE
+x_libraries=NONE
+
+# Installation directory options.
+# These are left unexpanded so users can "make install exec_prefix=/foo"
+# and all the variables that are supposed to be based on exec_prefix
+# by default will actually change.
+# Use braces instead of parens because sh, perl, etc. also accept them.
+# (The list follows the same order as the GNU Coding Standards.)
+bindir='${exec_prefix}/bin'
+sbindir='${exec_prefix}/sbin'
+libexecdir='${exec_prefix}/libexec'
+datarootdir='${prefix}/share'
+datadir='${datarootdir}'
+sysconfdir='${prefix}/etc'
+sharedstatedir='${prefix}/com'
+localstatedir='${prefix}/var'
+includedir='${prefix}/include'
+oldincludedir='/usr/include'
+docdir='${datarootdir}/doc/${PACKAGE_TARNAME}'
+infodir='${datarootdir}/info'
+htmldir='${docdir}'
+dvidir='${docdir}'
+pdfdir='${docdir}'
+psdir='${docdir}'
+libdir='${exec_prefix}/lib'
+localedir='${datarootdir}/locale'
+mandir='${datarootdir}/man'
+
+ac_prev=
+ac_dashdash=
+for ac_option
+do
+ # If the previous option needs an argument, assign it.
+ if test -n "$ac_prev"; then
+ eval $ac_prev=\$ac_option
+ ac_prev=
+ continue
+ fi
+
+ case $ac_option in
+ *=?*) ac_optarg=`expr "X$ac_option" : '[^=]*=\(.*\)'` ;;
+ *=) ac_optarg= ;;
+ *) ac_optarg=yes ;;
+ esac
+
+ # Accept the important Cygnus configure options, so we can diagnose typos.
+
+ case $ac_dashdash$ac_option in
+ --)
+ ac_dashdash=yes ;;
+
+ -bindir | --bindir | --bindi | --bind | --bin | --bi)
+ ac_prev=bindir ;;
+ -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*)
+ bindir=$ac_optarg ;;
+
+ -build | --build | --buil | --bui | --bu)
+ ac_prev=build_alias ;;
+ -build=* | --build=* | --buil=* | --bui=* | --bu=*)
+ build_alias=$ac_optarg ;;
+
+ -cache-file | --cache-file | --cache-fil | --cache-fi \
+ | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c)
+ ac_prev=cache_file ;;
+ -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \
+ | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*)
+ cache_file=$ac_optarg ;;
+
+ --config-cache | -C)
+ cache_file=config.cache ;;
+
+ -datadir | --datadir | --datadi | --datad)
+ ac_prev=datadir ;;
+ -datadir=* | --datadir=* | --datadi=* | --datad=*)
+ datadir=$ac_optarg ;;
+
+ -datarootdir | --datarootdir | --datarootdi | --datarootd | --dataroot \
+ | --dataroo | --dataro | --datar)
+ ac_prev=datarootdir ;;
+ -datarootdir=* | --datarootdir=* | --datarootdi=* | --datarootd=* \
+ | --dataroot=* | --dataroo=* | --dataro=* | --datar=*)
+ datarootdir=$ac_optarg ;;
+
+ -disable-* | --disable-*)
+ ac_useropt=`expr "x$ac_option" : 'x-*disable-\(.*\)'`
+ # Reject names that are not valid shell variable names.
+ expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null &&
+ as_fn_error $? "invalid feature name: $ac_useropt"
+ ac_useropt_orig=$ac_useropt
+ ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
+ case $ac_user_opts in
+ *"
+"enable_$ac_useropt"
+"*) ;;
+ *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--disable-$ac_useropt_orig"
+ ac_unrecognized_sep=', ';;
+ esac
+ eval enable_$ac_useropt=no ;;
+
+ -docdir | --docdir | --docdi | --doc | --do)
+ ac_prev=docdir ;;
+ -docdir=* | --docdir=* | --docdi=* | --doc=* | --do=*)
+ docdir=$ac_optarg ;;
+
+ -dvidir | --dvidir | --dvidi | --dvid | --dvi | --dv)
+ ac_prev=dvidir ;;
+ -dvidir=* | --dvidir=* | --dvidi=* | --dvid=* | --dvi=* | --dv=*)
+ dvidir=$ac_optarg ;;
+
+ -enable-* | --enable-*)
+ ac_useropt=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'`
+ # Reject names that are not valid shell variable names.
+ expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null &&
+ as_fn_error $? "invalid feature name: $ac_useropt"
+ ac_useropt_orig=$ac_useropt
+ ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
+ case $ac_user_opts in
+ *"
+"enable_$ac_useropt"
+"*) ;;
+ *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--enable-$ac_useropt_orig"
+ ac_unrecognized_sep=', ';;
+ esac
+ eval enable_$ac_useropt=\$ac_optarg ;;
+
+ -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \
+ | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \
+ | --exec | --exe | --ex)
+ ac_prev=exec_prefix ;;
+ -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \
+ | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \
+ | --exec=* | --exe=* | --ex=*)
+ exec_prefix=$ac_optarg ;;
+
+ -gas | --gas | --ga | --g)
+ # Obsolete; use --with-gas.
+ with_gas=yes ;;
+
+ -help | --help | --hel | --he | -h)
+ ac_init_help=long ;;
+ -help=r* | --help=r* | --hel=r* | --he=r* | -hr*)
+ ac_init_help=recursive ;;
+ -help=s* | --help=s* | --hel=s* | --he=s* | -hs*)
+ ac_init_help=short ;;
+
+ -host | --host | --hos | --ho)
+ ac_prev=host_alias ;;
+ -host=* | --host=* | --hos=* | --ho=*)
+ host_alias=$ac_optarg ;;
+
+ -htmldir | --htmldir | --htmldi | --htmld | --html | --htm | --ht)
+ ac_prev=htmldir ;;
+ -htmldir=* | --htmldir=* | --htmldi=* | --htmld=* | --html=* | --htm=* \
+ | --ht=*)
+ htmldir=$ac_optarg ;;
+
+ -includedir | --includedir | --includedi | --included | --include \
+ | --includ | --inclu | --incl | --inc)
+ ac_prev=includedir ;;
+ -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \
+ | --includ=* | --inclu=* | --incl=* | --inc=*)
+ includedir=$ac_optarg ;;
+
+ -infodir | --infodir | --infodi | --infod | --info | --inf)
+ ac_prev=infodir ;;
+ -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*)
+ infodir=$ac_optarg ;;
+
+ -libdir | --libdir | --libdi | --libd)
+ ac_prev=libdir ;;
+ -libdir=* | --libdir=* | --libdi=* | --libd=*)
+ libdir=$ac_optarg ;;
+
+ -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \
+ | --libexe | --libex | --libe)
+ ac_prev=libexecdir ;;
+ -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \
+ | --libexe=* | --libex=* | --libe=*)
+ libexecdir=$ac_optarg ;;
+
+ -localedir | --localedir | --localedi | --localed | --locale)
+ ac_prev=localedir ;;
+ -localedir=* | --localedir=* | --localedi=* | --localed=* | --locale=*)
+ localedir=$ac_optarg ;;
+
+ -localstatedir | --localstatedir | --localstatedi | --localstated \
+ | --localstate | --localstat | --localsta | --localst | --locals)
+ ac_prev=localstatedir ;;
+ -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \
+ | --localstate=* | --localstat=* | --localsta=* | --localst=* | --locals=*)
+ localstatedir=$ac_optarg ;;
+
+ -mandir | --mandir | --mandi | --mand | --man | --ma | --m)
+ ac_prev=mandir ;;
+ -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*)
+ mandir=$ac_optarg ;;
+
+ -nfp | --nfp | --nf)
+ # Obsolete; use --without-fp.
+ with_fp=no ;;
+
+ -no-create | --no-create | --no-creat | --no-crea | --no-cre \
+ | --no-cr | --no-c | -n)
+ no_create=yes ;;
+
+ -no-recursion | --no-recursion | --no-recursio | --no-recursi \
+ | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r)
+ no_recursion=yes ;;
+
+ -oldincludedir | --oldincludedir | --oldincludedi | --oldincluded \
+ | --oldinclude | --oldinclud | --oldinclu | --oldincl | --oldinc \
+ | --oldin | --oldi | --old | --ol | --o)
+ ac_prev=oldincludedir ;;
+ -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \
+ | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \
+ | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*)
+ oldincludedir=$ac_optarg ;;
+
+ -prefix | --prefix | --prefi | --pref | --pre | --pr | --p)
+ ac_prev=prefix ;;
+ -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*)
+ prefix=$ac_optarg ;;
+
+ -program-prefix | --program-prefix | --program-prefi | --program-pref \
+ | --program-pre | --program-pr | --program-p)
+ ac_prev=program_prefix ;;
+ -program-prefix=* | --program-prefix=* | --program-prefi=* \
+ | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*)
+ program_prefix=$ac_optarg ;;
+
+ -program-suffix | --program-suffix | --program-suffi | --program-suff \
+ | --program-suf | --program-su | --program-s)
+ ac_prev=program_suffix ;;
+ -program-suffix=* | --program-suffix=* | --program-suffi=* \
+ | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*)
+ program_suffix=$ac_optarg ;;
+
+ -program-transform-name | --program-transform-name \
+ | --program-transform-nam | --program-transform-na \
+ | --program-transform-n | --program-transform- \
+ | --program-transform | --program-transfor \
+ | --program-transfo | --program-transf \
+ | --program-trans | --program-tran \
+ | --progr-tra | --program-tr | --program-t)
+ ac_prev=program_transform_name ;;
+ -program-transform-name=* | --program-transform-name=* \
+ | --program-transform-nam=* | --program-transform-na=* \
+ | --program-transform-n=* | --program-transform-=* \
+ | --program-transform=* | --program-transfor=* \
+ | --program-transfo=* | --program-transf=* \
+ | --program-trans=* | --program-tran=* \
+ | --progr-tra=* | --program-tr=* | --program-t=*)
+ program_transform_name=$ac_optarg ;;
+
+ -pdfdir | --pdfdir | --pdfdi | --pdfd | --pdf | --pd)
+ ac_prev=pdfdir ;;
+ -pdfdir=* | --pdfdir=* | --pdfdi=* | --pdfd=* | --pdf=* | --pd=*)
+ pdfdir=$ac_optarg ;;
+
+ -psdir | --psdir | --psdi | --psd | --ps)
+ ac_prev=psdir ;;
+ -psdir=* | --psdir=* | --psdi=* | --psd=* | --ps=*)
+ psdir=$ac_optarg ;;
+
+ -q | -quiet | --quiet | --quie | --qui | --qu | --q \
+ | -silent | --silent | --silen | --sile | --sil)
+ silent=yes ;;
+
+ -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
+ ac_prev=sbindir ;;
+ -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
+ | --sbi=* | --sb=*)
+ sbindir=$ac_optarg ;;
+
+ -sharedstatedir | --sharedstatedir | --sharedstatedi \
+ | --sharedstated | --sharedstate | --sharedstat | --sharedsta \
+ | --sharedst | --shareds | --shared | --share | --shar \
+ | --sha | --sh)
+ ac_prev=sharedstatedir ;;
+ -sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \
+ | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \
+ | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \
+ | --sha=* | --sh=*)
+ sharedstatedir=$ac_optarg ;;
+
+ -site | --site | --sit)
+ ac_prev=site ;;
+ -site=* | --site=* | --sit=*)
+ site=$ac_optarg ;;
+
+ -srcdir | --srcdir | --srcdi | --srcd | --src | --sr)
+ ac_prev=srcdir ;;
+ -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*)
+ srcdir=$ac_optarg ;;
+
+ -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \
+ | --syscon | --sysco | --sysc | --sys | --sy)
+ ac_prev=sysconfdir ;;
+ -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \
+ | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*)
+ sysconfdir=$ac_optarg ;;
+
+ -target | --target | --targe | --targ | --tar | --ta | --t)
+ ac_prev=target_alias ;;
+ -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*)
+ target_alias=$ac_optarg ;;
+
+ -v | -verbose | --verbose | --verbos | --verbo | --verb)
+ verbose=yes ;;
+
+ -version | --version | --versio | --versi | --vers | -V)
+ ac_init_version=: ;;
+
+ -with-* | --with-*)
+ ac_useropt=`expr "x$ac_option" : 'x-*with-\([^=]*\)'`
+ # Reject names that are not valid shell variable names.
+ expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null &&
+ as_fn_error $? "invalid package name: $ac_useropt"
+ ac_useropt_orig=$ac_useropt
+ ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
+ case $ac_user_opts in
+ *"
+"with_$ac_useropt"
+"*) ;;
+ *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--with-$ac_useropt_orig"
+ ac_unrecognized_sep=', ';;
+ esac
+ eval with_$ac_useropt=\$ac_optarg ;;
+
+ -without-* | --without-*)
+ ac_useropt=`expr "x$ac_option" : 'x-*without-\(.*\)'`
+ # Reject names that are not valid shell variable names.
+ expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null &&
+ as_fn_error $? "invalid package name: $ac_useropt"
+ ac_useropt_orig=$ac_useropt
+ ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
+ case $ac_user_opts in
+ *"
+"with_$ac_useropt"
+"*) ;;
+ *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--without-$ac_useropt_orig"
+ ac_unrecognized_sep=', ';;
+ esac
+ eval with_$ac_useropt=no ;;
+
+ --x)
+ # Obsolete; use --with-x.
+ with_x=yes ;;
+
+ -x-includes | --x-includes | --x-include | --x-includ | --x-inclu \
+ | --x-incl | --x-inc | --x-in | --x-i)
+ ac_prev=x_includes ;;
+ -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \
+ | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*)
+ x_includes=$ac_optarg ;;
+
+ -x-libraries | --x-libraries | --x-librarie | --x-librari \
+ | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l)
+ ac_prev=x_libraries ;;
+ -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \
+ | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*)
+ x_libraries=$ac_optarg ;;
+
+ -*) as_fn_error $? "unrecognized option: \`$ac_option'
+Try \`$0 --help' for more information"
+ ;;
+
+ *=*)
+ ac_envvar=`expr "x$ac_option" : 'x\([^=]*\)='`
+ # Reject names that are not valid shell variable names.
+ case $ac_envvar in #(
+ '' | [0-9]* | *[!_$as_cr_alnum]* )
+ as_fn_error $? "invalid variable name: \`$ac_envvar'" ;;
+ esac
+ eval $ac_envvar=\$ac_optarg
+ export $ac_envvar ;;
+
+ *)
+ # FIXME: should be removed in autoconf 3.0.
+ $as_echo "$as_me: WARNING: you should use --build, --host, --target" >&2
+ expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null &&
+ $as_echo "$as_me: WARNING: invalid host type: $ac_option" >&2
+ : ${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option}
+ ;;
+
+ esac
+done
+
+if test -n "$ac_prev"; then
+ ac_option=--`echo $ac_prev | sed 's/_/-/g'`
+ as_fn_error $? "missing argument to $ac_option"
+fi
+
+if test -n "$ac_unrecognized_opts"; then
+ case $enable_option_checking in
+ no) ;;
+ fatal) as_fn_error $? "unrecognized options: $ac_unrecognized_opts" ;;
+ *) $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2 ;;
+ esac
+fi
+
+# Check all directory arguments for consistency.
+for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \
+ datadir sysconfdir sharedstatedir localstatedir includedir \
+ oldincludedir docdir infodir htmldir dvidir pdfdir psdir \
+ libdir localedir mandir
+do
+ eval ac_val=\$$ac_var
+ # Remove trailing slashes.
+ case $ac_val in
+ */ )
+ ac_val=`expr "X$ac_val" : 'X\(.*[^/]\)' \| "X$ac_val" : 'X\(.*\)'`
+ eval $ac_var=\$ac_val;;
+ esac
+ # Be sure to have absolute directory names.
+ case $ac_val in
+ [\\/$]* | ?:[\\/]* ) continue;;
+ NONE | '' ) case $ac_var in *prefix ) continue;; esac;;
+ esac
+ as_fn_error $? "expected an absolute directory name for --$ac_var: $ac_val"
+done
+
+# There might be people who depend on the old broken behavior: `$host'
+# used to hold the argument of --host etc.
+# FIXME: To remove some day.
+build=$build_alias
+host=$host_alias
+target=$target_alias
+
+# FIXME: To remove some day.
+if test "x$host_alias" != x; then
+ if test "x$build_alias" = x; then
+ cross_compiling=maybe
+ $as_echo "$as_me: WARNING: if you wanted to set the --build type, don't use --host.
+ If a cross compiler is detected then cross compile mode will be used" >&2
+ elif test "x$build_alias" != "x$host_alias"; then
+ cross_compiling=yes
+ fi
+fi
+
+ac_tool_prefix=
+test -n "$host_alias" && ac_tool_prefix=$host_alias-
+
+test "$silent" = yes && exec 6>/dev/null
+
+
+ac_pwd=`pwd` && test -n "$ac_pwd" &&
+ac_ls_di=`ls -di .` &&
+ac_pwd_ls_di=`cd "$ac_pwd" && ls -di .` ||
+ as_fn_error $? "working directory cannot be determined"
+test "X$ac_ls_di" = "X$ac_pwd_ls_di" ||
+ as_fn_error $? "pwd does not report name of working directory"
+
+
+# Find the source files, if location was not specified.
+if test -z "$srcdir"; then
+ ac_srcdir_defaulted=yes
+ # Try the directory containing this script, then the parent directory.
+ ac_confdir=`$as_dirname -- "$as_myself" ||
+$as_expr X"$as_myself" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+ X"$as_myself" : 'X\(//\)[^/]' \| \
+ X"$as_myself" : 'X\(//\)$' \| \
+ X"$as_myself" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X"$as_myself" |
+ sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+ s//\1/
+ q
+ }
+ /^X\(\/\/\)[^/].*/{
+ s//\1/
+ q
+ }
+ /^X\(\/\/\)$/{
+ s//\1/
+ q
+ }
+ /^X\(\/\).*/{
+ s//\1/
+ q
+ }
+ s/.*/./; q'`
+ srcdir=$ac_confdir
+ if test ! -r "$srcdir/$ac_unique_file"; then
+ srcdir=..
+ fi
+else
+ ac_srcdir_defaulted=no
+fi
+if test ! -r "$srcdir/$ac_unique_file"; then
+ test "$ac_srcdir_defaulted" = yes && srcdir="$ac_confdir or .."
+ as_fn_error $? "cannot find sources ($ac_unique_file) in $srcdir"
+fi
+ac_msg="sources are in $srcdir, but \`cd $srcdir' does not work"
+ac_abs_confdir=`(
+ cd "$srcdir" && test -r "./$ac_unique_file" || as_fn_error $? "$ac_msg"
+ pwd)`
+# When building in place, set srcdir=.
+if test "$ac_abs_confdir" = "$ac_pwd"; then
+ srcdir=.
+fi
+# Remove unnecessary trailing slashes from srcdir.
+# Double slashes in file names in object file debugging info
+# mess up M-x gdb in Emacs.
+case $srcdir in
+*/) srcdir=`expr "X$srcdir" : 'X\(.*[^/]\)' \| "X$srcdir" : 'X\(.*\)'`;;
+esac
+for ac_var in $ac_precious_vars; do
+ eval ac_env_${ac_var}_set=\${${ac_var}+set}
+ eval ac_env_${ac_var}_value=\$${ac_var}
+ eval ac_cv_env_${ac_var}_set=\${${ac_var}+set}
+ eval ac_cv_env_${ac_var}_value=\$${ac_var}
+done
+
+#
+# Report the --help message.
+#
+if test "$ac_init_help" = "long"; then
+ # Omit some internal or obsolete options to make the list less imposing.
+ # This message is too long to be a string in the A/UX 3.1 sh.
+ cat <<_ACEOF
+\`configure' configures GNU Hurd 0.3 to adapt to many kinds of systems.
+
+Usage: $0 [OPTION]... [VAR=VALUE]...
+
+To assign environment variables (e.g., CC, CFLAGS...), specify them as
+VAR=VALUE. See below for descriptions of some of the useful variables.
+
+Defaults for the options are specified in brackets.
+
+Configuration:
+ -h, --help display this help and exit
+ --help=short display options specific to this package
+ --help=recursive display the short help of all the included packages
+ -V, --version display version information and exit
+ -q, --quiet, --silent do not print \`checking ...' messages
+ --cache-file=FILE cache test results in FILE [disabled]
+ -C, --config-cache alias for \`--cache-file=config.cache'
+ -n, --no-create do not create output files
+ --srcdir=DIR find the sources in DIR [configure dir or \`..']
+
+Installation directories:
+ --prefix=PREFIX install architecture-independent files in PREFIX
+ [$ac_default_prefix]
+ --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
+ [PREFIX]
+
+By default, \`make install' will install all the files in
+\`$ac_default_prefix/bin', \`$ac_default_prefix/lib' etc. You can specify
+an installation prefix other than \`$ac_default_prefix' using \`--prefix',
+for instance \`--prefix=\$HOME'.
+
+For better control, use the options below.
+
+Fine tuning of the installation directories:
+ --bindir=DIR user executables [EPREFIX/bin]
+ --sbindir=DIR system admin executables [EPREFIX/sbin]
+ --libexecdir=DIR program executables [EPREFIX/libexec]
+ --sysconfdir=DIR read-only single-machine data [PREFIX/etc]
+ --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
+ --localstatedir=DIR modifiable single-machine data [PREFIX/var]
+ --libdir=DIR object code libraries [EPREFIX/lib]
+ --includedir=DIR C header files [PREFIX/include]
+ --oldincludedir=DIR C header files for non-gcc [/usr/include]
+ --datarootdir=DIR read-only arch.-independent data root [PREFIX/share]
+ --datadir=DIR read-only architecture-independent data [DATAROOTDIR]
+ --infodir=DIR info documentation [DATAROOTDIR/info]
+ --localedir=DIR locale-dependent data [DATAROOTDIR/locale]
+ --mandir=DIR man documentation [DATAROOTDIR/man]
+ --docdir=DIR documentation root [DATAROOTDIR/doc/hurd]
+ --htmldir=DIR html documentation [DOCDIR]
+ --dvidir=DIR dvi documentation [DOCDIR]
+ --pdfdir=DIR pdf documentation [DOCDIR]
+ --psdir=DIR ps documentation [DOCDIR]
+_ACEOF
+
+ cat <<\_ACEOF
+
+System types:
+ --build=BUILD configure for building on BUILD [guessed]
+ --host=HOST cross-compile to build programs to run on HOST [BUILD]
+_ACEOF
+fi
+
+if test -n "$ac_init_help"; then
+ case $ac_init_help in
+ short | recursive ) echo "Configuration of GNU Hurd 0.3:";;
+ esac
+ cat <<\_ACEOF
+
+Optional Features:
+ --disable-option-checking ignore unrecognized --enable/--with options
+ --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no)
+ --enable-FEATURE[=ARG] include FEATURE [ARG=yes]
+ --disable-profile do not build profiled libraries and programs
+ --enable-static-progs=PROGRAMS...
+ build statically-linked PROGRAM.static versions
+ of (only) the listed programs ext2fs,ufs
+ --enable-boot-store-types=TYPES...
+ list of store types included in statically
+ linked filesystems used for booting
+ --disable-ncursesw Do not use ncursesw
+
+Optional Packages:
+ --with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
+ --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no)
+ --without-parted disable user-space partition stores
+ --with-ncursesw-include-dir=DIR
+ Set directory containing the include files for
+ use with -lncursesw, when it isn't installed as
+ the default curses library. If DIR is "none",
+ then no special ncursesw include files are used.
+ --without-ncursesw-include-dir
+ Equivalent to --with-ncursesw-include-dir=none
+
+Some influential environment variables:
+ CC C compiler command
+ CFLAGS C compiler flags
+ LDFLAGS linker flags, e.g. -L<lib dir> if you have libraries in a
+ nonstandard directory <lib dir>
+ LIBS libraries to pass to the linker, e.g. -l<library>
+ CPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if
+ you have headers in a nonstandard directory <include dir>
+ CPP C preprocessor
+
+Use these variables to override the choices made by `configure' or to help
+it to find libraries and programs with nonstandard names/locations.
+
+Report bugs to <bug-hurd@gnu.org>.
+GNU Hurd home page: <http://www.gnu.org/software/hurd/>.
+General help using GNU software: <http://www.gnu.org/gethelp/>.
+_ACEOF
+ac_status=$?
+fi
+
+if test "$ac_init_help" = "recursive"; then
+ # If there are subdirs, report their specific --help.
+ for ac_dir in : $ac_subdirs_all; do test "x$ac_dir" = x: && continue
+ test -d "$ac_dir" ||
+ { cd "$srcdir" && ac_pwd=`pwd` && srcdir=. && test -d "$ac_dir"; } ||
+ continue
+ ac_builddir=.
+
+case "$ac_dir" in
+.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;;
+*)
+ ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'`
+ # A ".." for each directory in $ac_dir_suffix.
+ ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'`
+ case $ac_top_builddir_sub in
+ "") ac_top_builddir_sub=. ac_top_build_prefix= ;;
+ *) ac_top_build_prefix=$ac_top_builddir_sub/ ;;
+ esac ;;
+esac
+ac_abs_top_builddir=$ac_pwd
+ac_abs_builddir=$ac_pwd$ac_dir_suffix
+# for backward compatibility:
+ac_top_builddir=$ac_top_build_prefix
+
+case $srcdir in
+ .) # We are building in place.
+ ac_srcdir=.
+ ac_top_srcdir=$ac_top_builddir_sub
+ ac_abs_top_srcdir=$ac_pwd ;;
+ [\\/]* | ?:[\\/]* ) # Absolute name.
+ ac_srcdir=$srcdir$ac_dir_suffix;
+ ac_top_srcdir=$srcdir
+ ac_abs_top_srcdir=$srcdir ;;
+ *) # Relative name.
+ ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix
+ ac_top_srcdir=$ac_top_build_prefix$srcdir
+ ac_abs_top_srcdir=$ac_pwd/$srcdir ;;
+esac
+ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix
+
+ cd "$ac_dir" || { ac_status=$?; continue; }
+ # Check for guested configure.
+ if test -f "$ac_srcdir/configure.gnu"; then
+ echo &&
+ $SHELL "$ac_srcdir/configure.gnu" --help=recursive
+ elif test -f "$ac_srcdir/configure"; then
+ echo &&
+ $SHELL "$ac_srcdir/configure" --help=recursive
+ else
+ $as_echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2
+ fi || ac_status=$?
+ cd "$ac_pwd" || { ac_status=$?; break; }
+ done
+fi
+
+test -n "$ac_init_help" && exit $ac_status
+if $ac_init_version; then
+ cat <<\_ACEOF
+GNU Hurd configure 0.3
+generated by GNU Autoconf 2.67
+
+Copyright (C) 2010 Free Software Foundation, Inc.
+This configure script is free software; the Free Software Foundation
+gives unlimited permission to copy, distribute and modify it.
+_ACEOF
+ exit
+fi
+
+## ------------------------ ##
+## Autoconf initialization. ##
+## ------------------------ ##
+
+# ac_fn_c_try_compile LINENO
+# --------------------------
+# Try to compile conftest.$ac_ext, and return whether this succeeded.
+ac_fn_c_try_compile ()
+{
+ as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+ rm -f conftest.$ac_objext
+ if { { ac_try="$ac_compile"
+case "(($ac_try" in
+ *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+ *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+ (eval "$ac_compile") 2>conftest.err
+ ac_status=$?
+ if test -s conftest.err; then
+ grep -v '^ *+' conftest.err >conftest.er1
+ cat conftest.er1 >&5
+ mv -f conftest.er1 conftest.err
+ fi
+ $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+ test $ac_status = 0; } && {
+ test -z "$ac_c_werror_flag" ||
+ test ! -s conftest.err
+ } && test -s conftest.$ac_objext; then :
+ ac_retval=0
+else
+ $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ ac_retval=1
+fi
+ eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
+ as_fn_set_status $ac_retval
+
+} # ac_fn_c_try_compile
+
+# ac_fn_c_try_link LINENO
+# -----------------------
+# Try to link conftest.$ac_ext, and return whether this succeeded.
+ac_fn_c_try_link ()
+{
+ as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+ rm -f conftest.$ac_objext conftest$ac_exeext
+ if { { ac_try="$ac_link"
+case "(($ac_try" in
+ *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+ *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+ (eval "$ac_link") 2>conftest.err
+ ac_status=$?
+ if test -s conftest.err; then
+ grep -v '^ *+' conftest.err >conftest.er1
+ cat conftest.er1 >&5
+ mv -f conftest.er1 conftest.err
+ fi
+ $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+ test $ac_status = 0; } && {
+ test -z "$ac_c_werror_flag" ||
+ test ! -s conftest.err
+ } && test -s conftest$ac_exeext && {
+ test "$cross_compiling" = yes ||
+ $as_test_x conftest$ac_exeext
+ }; then :
+ ac_retval=0
+else
+ $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ ac_retval=1
+fi
+ # Delete the IPA/IPO (Inter Procedural Analysis/Optimization) information
+ # created by the PGI compiler (conftest_ipa8_conftest.oo), as it would
+ # interfere with the next link command; also delete a directory that is
+ # left behind by Apple's compiler. We do this before executing the actions.
+ rm -rf conftest.dSYM conftest_ipa8_conftest.oo
+ eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
+ as_fn_set_status $ac_retval
+
+} # ac_fn_c_try_link
+
+# ac_fn_c_check_func LINENO FUNC VAR
+# ----------------------------------
+# Tests whether FUNC exists, setting the cache variable VAR accordingly
+ac_fn_c_check_func ()
+{
+ as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
+$as_echo_n "checking for $2... " >&6; }
+if eval "test \"\${$3+set}\"" = set; then :
+ $as_echo_n "(cached) " >&6
+else
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+/* Define $2 to an innocuous variant, in case <limits.h> declares $2.
+ For example, HP-UX 11i <limits.h> declares gettimeofday. */
+#define $2 innocuous_$2
+
+/* System header to define __stub macros and hopefully few prototypes,
+ which can conflict with char $2 (); below.
+ Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+ <limits.h> exists even on freestanding compilers. */
+
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+
+#undef $2
+
+/* Override any GCC internal prototype to avoid an error.
+ Use char because int might match the return type of a GCC
+ builtin and then its argument prototype would still apply. */
+#ifdef __cplusplus
+extern "C"
+#endif
+char $2 ();
+/* The GNU C library defines this for functions which it implements
+ to always fail with ENOSYS. Some functions are actually named
+ something starting with __ and the normal name is an alias. */
+#if defined __stub_$2 || defined __stub___$2
+choke me
+#endif
+
+int
+main ()
+{
+return $2 ();
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+ eval "$3=yes"
+else
+ eval "$3=no"
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+fi
+eval ac_res=\$$3
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+ eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
+
+} # ac_fn_c_check_func
+
+# ac_fn_c_try_cpp LINENO
+# ----------------------
+# Try to preprocess conftest.$ac_ext, and return whether this succeeded.
+ac_fn_c_try_cpp ()
+{
+ as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+ if { { ac_try="$ac_cpp conftest.$ac_ext"
+case "(($ac_try" in
+ *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+ *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+ (eval "$ac_cpp conftest.$ac_ext") 2>conftest.err
+ ac_status=$?
+ if test -s conftest.err; then
+ grep -v '^ *+' conftest.err >conftest.er1
+ cat conftest.er1 >&5
+ mv -f conftest.er1 conftest.err
+ fi
+ $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+ test $ac_status = 0; } > conftest.i && {
+ test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
+ test ! -s conftest.err
+ }; then :
+ ac_retval=0
+else
+ $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ ac_retval=1
+fi
+ eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
+ as_fn_set_status $ac_retval
+
+} # ac_fn_c_try_cpp
+
+# ac_fn_c_check_header_mongrel LINENO HEADER VAR INCLUDES
+# -------------------------------------------------------
+# Tests whether HEADER exists, giving a warning if it cannot be compiled using
+# the include files in INCLUDES and setting the cache variable VAR
+# accordingly.
+ac_fn_c_check_header_mongrel ()
+{
+ as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+ if eval "test \"\${$3+set}\"" = set; then :
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
+$as_echo_n "checking for $2... " >&6; }
+if eval "test \"\${$3+set}\"" = set; then :
+ $as_echo_n "(cached) " >&6
+fi
+eval ac_res=\$$3
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+else
+ # Is the header compilable?
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 usability" >&5
+$as_echo_n "checking $2 usability... " >&6; }
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+$4
+#include <$2>
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+ ac_header_compiler=yes
+else
+ ac_header_compiler=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_compiler" >&5
+$as_echo "$ac_header_compiler" >&6; }
+
+# Is the header present?
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 presence" >&5
+$as_echo_n "checking $2 presence... " >&6; }
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#include <$2>
+_ACEOF
+if ac_fn_c_try_cpp "$LINENO"; then :
+ ac_header_preproc=yes
+else
+ ac_header_preproc=no
+fi
+rm -f conftest.err conftest.i conftest.$ac_ext
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_preproc" >&5
+$as_echo "$ac_header_preproc" >&6; }
+
+# So? What about this header?
+case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in #((
+ yes:no: )
+ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&5
+$as_echo "$as_me: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&2;}
+ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5
+$as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;}
+ ;;
+ no:yes:* )
+ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: present but cannot be compiled" >&5
+$as_echo "$as_me: WARNING: $2: present but cannot be compiled" >&2;}
+ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: check for missing prerequisite headers?" >&5
+$as_echo "$as_me: WARNING: $2: check for missing prerequisite headers?" >&2;}
+ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: see the Autoconf documentation" >&5
+$as_echo "$as_me: WARNING: $2: see the Autoconf documentation" >&2;}
+ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: section \"Present But Cannot Be Compiled\"" >&5
+$as_echo "$as_me: WARNING: $2: section \"Present But Cannot Be Compiled\"" >&2;}
+ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5
+$as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;}
+( $as_echo "## ------------------------------- ##
+## Report this to bug-hurd@gnu.org ##
+## ------------------------------- ##"
+ ) | sed "s/^/$as_me: WARNING: /" >&2
+ ;;
+esac
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
+$as_echo_n "checking for $2... " >&6; }
+if eval "test \"\${$3+set}\"" = set; then :
+ $as_echo_n "(cached) " >&6
+else
+ eval "$3=\$ac_header_compiler"
+fi
+eval ac_res=\$$3
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+fi
+ eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
+
+} # ac_fn_c_check_header_mongrel
+
+# ac_fn_c_try_run LINENO
+# ----------------------
+# Try to link conftest.$ac_ext, and return whether this succeeded. Assumes
+# that executables *can* be run.
+ac_fn_c_try_run ()
+{
+ as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+ if { { ac_try="$ac_link"
+case "(($ac_try" in
+ *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+ *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+ (eval "$ac_link") 2>&5
+ ac_status=$?
+ $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+ test $ac_status = 0; } && { ac_try='./conftest$ac_exeext'
+ { { case "(($ac_try" in
+ *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+ *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+ (eval "$ac_try") 2>&5
+ ac_status=$?
+ $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+ test $ac_status = 0; }; }; then :
+ ac_retval=0
+else
+ $as_echo "$as_me: program exited with status $ac_status" >&5
+ $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ ac_retval=$ac_status
+fi
+ rm -rf conftest.dSYM conftest_ipa8_conftest.oo
+ eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
+ as_fn_set_status $ac_retval
+
+} # ac_fn_c_try_run
+
+# ac_fn_c_check_header_compile LINENO HEADER VAR INCLUDES
+# -------------------------------------------------------
+# Tests whether HEADER exists and can be compiled using the include files in
+# INCLUDES, setting the cache variable VAR accordingly.
+ac_fn_c_check_header_compile ()
+{
+ as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
+$as_echo_n "checking for $2... " >&6; }
+if eval "test \"\${$3+set}\"" = set; then :
+ $as_echo_n "(cached) " >&6
+else
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+$4
+#include <$2>
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+ eval "$3=yes"
+else
+ eval "$3=no"
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+eval ac_res=\$$3
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+ eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
+
+} # ac_fn_c_check_header_compile
+cat >config.log <<_ACEOF
+This file contains any messages produced by compilers while
+running configure, to aid debugging if configure makes a mistake.
+
+It was created by GNU Hurd $as_me 0.3, which was
+generated by GNU Autoconf 2.67. Invocation command line was
+
+ $ $0 $@
+
+_ACEOF
+exec 5>>config.log
+{
+cat <<_ASUNAME
+## --------- ##
+## Platform. ##
+## --------- ##
+
+hostname = `(hostname || uname -n) 2>/dev/null | sed 1q`
+uname -m = `(uname -m) 2>/dev/null || echo unknown`
+uname -r = `(uname -r) 2>/dev/null || echo unknown`
+uname -s = `(uname -s) 2>/dev/null || echo unknown`
+uname -v = `(uname -v) 2>/dev/null || echo unknown`
+
+/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null || echo unknown`
+/bin/uname -X = `(/bin/uname -X) 2>/dev/null || echo unknown`
+
+/bin/arch = `(/bin/arch) 2>/dev/null || echo unknown`
+/usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null || echo unknown`
+/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null || echo unknown`
+/usr/bin/hostinfo = `(/usr/bin/hostinfo) 2>/dev/null || echo unknown`
+/bin/machine = `(/bin/machine) 2>/dev/null || echo unknown`
+/usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null || echo unknown`
+/bin/universe = `(/bin/universe) 2>/dev/null || echo unknown`
+
+_ASUNAME
+
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ $as_echo "PATH: $as_dir"
+ done
+IFS=$as_save_IFS
+
+} >&5
+
+cat >&5 <<_ACEOF
+
+
+## ----------- ##
+## Core tests. ##
+## ----------- ##
+
+_ACEOF
+
+
+# Keep a trace of the command line.
+# Strip out --no-create and --no-recursion so they do not pile up.
+# Strip out --silent because we don't want to record it for future runs.
+# Also quote any args containing shell meta-characters.
+# Make two passes to allow for proper duplicate-argument suppression.
+ac_configure_args=
+ac_configure_args0=
+ac_configure_args1=
+ac_must_keep_next=false
+for ac_pass in 1 2
+do
+ for ac_arg
+ do
+ case $ac_arg in
+ -no-create | --no-c* | -n | -no-recursion | --no-r*) continue ;;
+ -q | -quiet | --quiet | --quie | --qui | --qu | --q \
+ | -silent | --silent | --silen | --sile | --sil)
+ continue ;;
+ *\'*)
+ ac_arg=`$as_echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;;
+ esac
+ case $ac_pass in
+ 1) as_fn_append ac_configure_args0 " '$ac_arg'" ;;
+ 2)
+ as_fn_append ac_configure_args1 " '$ac_arg'"
+ if test $ac_must_keep_next = true; then
+ ac_must_keep_next=false # Got value, back to normal.
+ else
+ case $ac_arg in
+ *=* | --config-cache | -C | -disable-* | --disable-* \
+ | -enable-* | --enable-* | -gas | --g* | -nfp | --nf* \
+ | -q | -quiet | --q* | -silent | --sil* | -v | -verb* \
+ | -with-* | --with-* | -without-* | --without-* | --x)
+ case "$ac_configure_args0 " in
+ "$ac_configure_args1"*" '$ac_arg' "* ) continue ;;
+ esac
+ ;;
+ -* ) ac_must_keep_next=true ;;
+ esac
+ fi
+ as_fn_append ac_configure_args " '$ac_arg'"
+ ;;
+ esac
+ done
+done
+{ ac_configure_args0=; unset ac_configure_args0;}
+{ ac_configure_args1=; unset ac_configure_args1;}
+
+# When interrupted or exit'd, cleanup temporary files, and complete
+# config.log. We remove comments because anyway the quotes in there
+# would cause problems or look ugly.
+# WARNING: Use '\'' to represent an apostrophe within the trap.
+# WARNING: Do not start the trap code with a newline, due to a FreeBSD 4.0 bug.
+trap 'exit_status=$?
+ # Save into config.log some information that might help in debugging.
+ {
+ echo
+
+ $as_echo "## ---------------- ##
+## Cache variables. ##
+## ---------------- ##"
+ echo
+ # The following way of writing the cache mishandles newlines in values,
+(
+ for ac_var in `(set) 2>&1 | sed -n '\''s/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'\''`; do
+ eval ac_val=\$$ac_var
+ case $ac_val in #(
+ *${as_nl}*)
+ case $ac_var in #(
+ *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5
+$as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;;
+ esac
+ case $ac_var in #(
+ _ | IFS | as_nl) ;; #(
+ BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #(
+ *) { eval $ac_var=; unset $ac_var;} ;;
+ esac ;;
+ esac
+ done
+ (set) 2>&1 |
+ case $as_nl`(ac_space='\'' '\''; set) 2>&1` in #(
+ *${as_nl}ac_space=\ *)
+ sed -n \
+ "s/'\''/'\''\\\\'\'''\''/g;
+ s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\''\\2'\''/p"
+ ;; #(
+ *)
+ sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p"
+ ;;
+ esac |
+ sort
+)
+ echo
+
+ $as_echo "## ----------------- ##
+## Output variables. ##
+## ----------------- ##"
+ echo
+ for ac_var in $ac_subst_vars
+ do
+ eval ac_val=\$$ac_var
+ case $ac_val in
+ *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;;
+ esac
+ $as_echo "$ac_var='\''$ac_val'\''"
+ done | sort
+ echo
+
+ if test -n "$ac_subst_files"; then
+ $as_echo "## ------------------- ##
+## File substitutions. ##
+## ------------------- ##"
+ echo
+ for ac_var in $ac_subst_files
+ do
+ eval ac_val=\$$ac_var
+ case $ac_val in
+ *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;;
+ esac
+ $as_echo "$ac_var='\''$ac_val'\''"
+ done | sort
+ echo
+ fi
+
+ if test -s confdefs.h; then
+ $as_echo "## ----------- ##
+## confdefs.h. ##
+## ----------- ##"
+ echo
+ cat confdefs.h
+ echo
+ fi
+ test "$ac_signal" != 0 &&
+ $as_echo "$as_me: caught signal $ac_signal"
+ $as_echo "$as_me: exit $exit_status"
+ } >&5
+ rm -f core *.core core.conftest.* &&
+ rm -f -r conftest* confdefs* conf$$* $ac_clean_files &&
+ exit $exit_status
+' 0
+for ac_signal in 1 2 13 15; do
+ trap 'ac_signal='$ac_signal'; as_fn_exit 1' $ac_signal
+done
+ac_signal=0
+
+# confdefs.h avoids OS command line length limits that DEFS can exceed.
+rm -f -r conftest* confdefs.h
+
+$as_echo "/* confdefs.h */" > confdefs.h
+
+# Predefined preprocessor variables.
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_NAME "$PACKAGE_NAME"
+_ACEOF
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_TARNAME "$PACKAGE_TARNAME"
+_ACEOF
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_VERSION "$PACKAGE_VERSION"
+_ACEOF
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_STRING "$PACKAGE_STRING"
+_ACEOF
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_BUGREPORT "$PACKAGE_BUGREPORT"
+_ACEOF
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_URL "$PACKAGE_URL"
+_ACEOF
+
+
+# Let the site file select an alternate cache file if it wants to.
+# Prefer an explicitly selected file to automatically selected ones.
+ac_site_file1=NONE
+ac_site_file2=NONE
+if test -n "$CONFIG_SITE"; then
+ # We do not want a PATH search for config.site.
+ case $CONFIG_SITE in #((
+ -*) ac_site_file1=./$CONFIG_SITE;;
+ */*) ac_site_file1=$CONFIG_SITE;;
+ *) ac_site_file1=./$CONFIG_SITE;;
+ esac
+elif test "x$prefix" != xNONE; then
+ ac_site_file1=$prefix/share/config.site
+ ac_site_file2=$prefix/etc/config.site
+else
+ ac_site_file1=$ac_default_prefix/share/config.site
+ ac_site_file2=$ac_default_prefix/etc/config.site
+fi
+for ac_site_file in "$ac_site_file1" "$ac_site_file2"
+do
+ test "x$ac_site_file" = xNONE && continue
+ if test /dev/null != "$ac_site_file" && test -r "$ac_site_file"; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: loading site script $ac_site_file" >&5
+$as_echo "$as_me: loading site script $ac_site_file" >&6;}
+ sed 's/^/| /' "$ac_site_file" >&5
+ . "$ac_site_file" \
+ || { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "failed to load site script $ac_site_file
+See \`config.log' for more details" "$LINENO" 5; }
+ fi
+done
+
+if test -r "$cache_file"; then
+ # Some versions of bash will fail to source /dev/null (special files
+ # actually), so we avoid doing that. DJGPP emulates it as a regular file.
+ if test /dev/null != "$cache_file" && test -f "$cache_file"; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: loading cache $cache_file" >&5
+$as_echo "$as_me: loading cache $cache_file" >&6;}
+ case $cache_file in
+ [\\/]* | ?:[\\/]* ) . "$cache_file";;
+ *) . "./$cache_file";;
+ esac
+ fi
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: creating cache $cache_file" >&5
+$as_echo "$as_me: creating cache $cache_file" >&6;}
+ >$cache_file
+fi
+
+# Check that the precious variables saved in the cache have kept the same
+# value.
+ac_cache_corrupted=false
+for ac_var in $ac_precious_vars; do
+ eval ac_old_set=\$ac_cv_env_${ac_var}_set
+ eval ac_new_set=\$ac_env_${ac_var}_set
+ eval ac_old_val=\$ac_cv_env_${ac_var}_value
+ eval ac_new_val=\$ac_env_${ac_var}_value
+ case $ac_old_set,$ac_new_set in
+ set,)
+ { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5
+$as_echo "$as_me: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;}
+ ac_cache_corrupted=: ;;
+ ,set)
+ { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was not set in the previous run" >&5
+$as_echo "$as_me: error: \`$ac_var' was not set in the previous run" >&2;}
+ ac_cache_corrupted=: ;;
+ ,);;
+ *)
+ if test "x$ac_old_val" != "x$ac_new_val"; then
+ # differences in whitespace do not lead to failure.
+ ac_old_val_w=`echo x $ac_old_val`
+ ac_new_val_w=`echo x $ac_new_val`
+ if test "$ac_old_val_w" != "$ac_new_val_w"; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' has changed since the previous run:" >&5
+$as_echo "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;}
+ ac_cache_corrupted=:
+ else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&5
+$as_echo "$as_me: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&2;}
+ eval $ac_var=\$ac_old_val
+ fi
+ { $as_echo "$as_me:${as_lineno-$LINENO}: former value: \`$ac_old_val'" >&5
+$as_echo "$as_me: former value: \`$ac_old_val'" >&2;}
+ { $as_echo "$as_me:${as_lineno-$LINENO}: current value: \`$ac_new_val'" >&5
+$as_echo "$as_me: current value: \`$ac_new_val'" >&2;}
+ fi;;
+ esac
+ # Pass precious variables to config.status.
+ if test "$ac_new_set" = set; then
+ case $ac_new_val in
+ *\'*) ac_arg=$ac_var=`$as_echo "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;;
+ *) ac_arg=$ac_var=$ac_new_val ;;
+ esac
+ case " $ac_configure_args " in
+ *" '$ac_arg' "*) ;; # Avoid dups. Use of quotes ensures accuracy.
+ *) as_fn_append ac_configure_args " '$ac_arg'" ;;
+ esac
+ fi
+done
+if $ac_cache_corrupted; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+ { $as_echo "$as_me:${as_lineno-$LINENO}: error: changes in the environment can compromise the build" >&5
+$as_echo "$as_me: error: changes in the environment can compromise the build" >&2;}
+ as_fn_error $? "run \`make distclean' and/or \`rm $cache_file' and start over" "$LINENO" 5
+fi
+## -------------------- ##
+## Main body of script. ##
+## -------------------- ##
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+
+
+ac_aux_dir=
+for ac_dir in "$srcdir" "$srcdir/.." "$srcdir/../.."; do
+ if test -f "$ac_dir/install-sh"; then
+ ac_aux_dir=$ac_dir
+ ac_install_sh="$ac_aux_dir/install-sh -c"
+ break
+ elif test -f "$ac_dir/install.sh"; then
+ ac_aux_dir=$ac_dir
+ ac_install_sh="$ac_aux_dir/install.sh -c"
+ break
+ elif test -f "$ac_dir/shtool"; then
+ ac_aux_dir=$ac_dir
+ ac_install_sh="$ac_aux_dir/shtool install -c"
+ break
+ fi
+done
+if test -z "$ac_aux_dir"; then
+ as_fn_error $? "cannot find install-sh, install.sh, or shtool in \"$srcdir\" \"$srcdir/..\" \"$srcdir/../..\"" "$LINENO" 5
+fi
+
+# These three variables are undocumented and unsupported,
+# and are intended to be withdrawn in a future Autoconf release.
+# They can cause serious problems if a builder's source tree is in a directory
+# whose full name contains unusual characters.
+ac_config_guess="$SHELL $ac_aux_dir/config.guess" # Please don't use this var.
+ac_config_sub="$SHELL $ac_aux_dir/config.sub" # Please don't use this var.
+ac_configure="$SHELL $ac_aux_dir/configure" # Please don't use this var.
+
+
+# Make sure we can run config.sub.
+$SHELL "$ac_aux_dir/config.sub" sun4 >/dev/null 2>&1 ||
+ as_fn_error $? "cannot run $SHELL $ac_aux_dir/config.sub" "$LINENO" 5
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking build system type" >&5
+$as_echo_n "checking build system type... " >&6; }
+if test "${ac_cv_build+set}" = set; then :
+ $as_echo_n "(cached) " >&6
+else
+ ac_build_alias=$build_alias
+test "x$ac_build_alias" = x &&
+ ac_build_alias=`$SHELL "$ac_aux_dir/config.guess"`
+test "x$ac_build_alias" = x &&
+ as_fn_error $? "cannot guess build type; you must specify one" "$LINENO" 5
+ac_cv_build=`$SHELL "$ac_aux_dir/config.sub" $ac_build_alias` ||
+ as_fn_error $? "$SHELL $ac_aux_dir/config.sub $ac_build_alias failed" "$LINENO" 5
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_build" >&5
+$as_echo "$ac_cv_build" >&6; }
+case $ac_cv_build in
+*-*-*) ;;
+*) as_fn_error $? "invalid value of canonical build" "$LINENO" 5;;
+esac
+build=$ac_cv_build
+ac_save_IFS=$IFS; IFS='-'
+set x $ac_cv_build
+shift
+build_cpu=$1
+build_vendor=$2
+shift; shift
+# Remember, the first character of IFS is used to create $*,
+# except with old shells:
+build_os=$*
+IFS=$ac_save_IFS
+case $build_os in *\ *) build_os=`echo "$build_os" | sed 's/ /-/g'`;; esac
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking host system type" >&5
+$as_echo_n "checking host system type... " >&6; }
+if test "${ac_cv_host+set}" = set; then :
+ $as_echo_n "(cached) " >&6
+else
+ if test "x$host_alias" = x; then
+ ac_cv_host=$ac_cv_build
+else
+ ac_cv_host=`$SHELL "$ac_aux_dir/config.sub" $host_alias` ||
+ as_fn_error $? "$SHELL $ac_aux_dir/config.sub $host_alias failed" "$LINENO" 5
+fi
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_host" >&5
+$as_echo "$ac_cv_host" >&6; }
+case $ac_cv_host in
+*-*-*) ;;
+*) as_fn_error $? "invalid value of canonical host" "$LINENO" 5;;
+esac
+host=$ac_cv_host
+ac_save_IFS=$IFS; IFS='-'
+set x $ac_cv_host
+shift
+host_cpu=$1
+host_vendor=$2
+shift; shift
+# Remember, the first character of IFS is used to create $*,
+# except with old shells:
+host_os=$*
+IFS=$ac_save_IFS
+case $host_os in *\ *) host_os=`echo "$host_os" | sed 's/ /-/g'`;; esac
+
+
+case "$host_os" in
+gnu*) ;;
+none) as_fn_error $? "
+*** You must specify a host of $host_cpu-gnu or $host_cpu-$host_vendor-gnu
+*** to configure; you will need to use the same host specification
+*** to configure other packages for the GNU/Hurd system." "$LINENO" 5 ;;
+*) as_fn_error $? "this is the gnu os, host cannot be $host_os
+*** Host configuration must be \`MACHINE-gnu' or \`MACHINE-VENDOR-gnu'.
+*** To cross-compile, you must specify both --host and --build;
+*** for example \`--build=$host --host=$host_cpu-gnu'.
+*** Run $0 --help for more information." "$LINENO" 5 ;;
+esac
+
+case "$host_cpu" in
+alpha*)
+ asm_syntax=alpha
+ ;;
+arm*)
+ asm_syntax=arm
+ ;;
+m68k | m680?0)
+ asm_syntax=m68k
+ ;;
+mips*)
+ asm_syntax=mips
+ ;;
+i?86)
+ asm_syntax=i386
+ ;;
+powerpc*)
+ asm_syntax=ppc
+ ;;
+sparc64* | ultrasparc*)
+ asm_syntax=sparc64
+ ;;
+sparc*)
+ asm_syntax=sparc
+ ;;
+*)
+ asm_syntax="$host_cpu"
+ ;;
+esac
+
+
+test -r "$srcdir/libthreads/$asm_syntax/cthreads.h" || {
+ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: unsupported CPU type $host_cpu" >&5
+$as_echo "$as_me: WARNING: unsupported CPU type $host_cpu" >&2;}
+}
+
+# Check whether --enable-profile was given.
+if test "${enable_profile+set}" = set; then :
+ enableval=$enable_profile;
+fi
+
+
+
+# Check whether --enable-static-progs was given.
+if test "${enable_static_progs+set}" = set; then :
+ enableval=$enable_static_progs;
+fi
+
+case "$enable_static_progs" in
+'no') enable_static_progs= ;; # we got --disable-static
+'') enable_static_progs='ext2fs,ufs' ;;
+esac
+# Convert comma/space-separated list into space-separated list.
+enable_static_progs=`echo "$enable_static_progs" | sed 's/[, ][, ]*/ /g'`
+
+
+# Don't needlessly overwrite files that whose contents haven't changed. This
+# helps for avoinding unneccessary recompilation cycles when keeping
+# cross-compilation toolchains up-to-date. Thus, unconditionally use the
+# supplied `install-sh', as the GNU Coreutils one doesn't provide this
+# functionality yet (TODO: change that). TODO: $ac_abs_top_builddir et al. are
+# not yet available here, that's why we use `readlink' (but only if available).
+INSTALL="$SHELL $(readlink -f "$ac_install_sh")"\ -C || unset INSTALL
+# Find a good install program. We prefer a C program (faster),
+# so one script is as good as another. But avoid the broken or
+# incompatible versions:
+# SysV /etc/install, /usr/sbin/install
+# SunOS /usr/etc/install
+# IRIX /sbin/install
+# AIX /bin/install
+# AmigaOS /C/install, which installs bootblocks on floppy discs
+# AIX 4 /usr/bin/installbsd, which doesn't work without a -g flag
+# AFS /usr/afsws/bin/install, which mishandles nonexistent args
+# SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff"
+# OS/2's system install, which has a completely different semantic
+# ./install, which can be erroneously created by make from ./install.sh.
+# Reject install programs that cannot install multiple files.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for a BSD-compatible install" >&5
+$as_echo_n "checking for a BSD-compatible install... " >&6; }
+if test -z "$INSTALL"; then
+if test "${ac_cv_path_install+set}" = set; then :
+ $as_echo_n "(cached) " >&6
+else
+ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ # Account for people who put trailing slashes in PATH elements.
+case $as_dir/ in #((
+ ./ | .// | /[cC]/* | \
+ /etc/* | /usr/sbin/* | /usr/etc/* | /sbin/* | /usr/afsws/bin/* | \
+ ?:[\\/]os2[\\/]install[\\/]* | ?:[\\/]OS2[\\/]INSTALL[\\/]* | \
+ /usr/ucb/* ) ;;
+ *)
+ # OSF1 and SCO ODT 3.0 have their own names for install.
+ # Don't use installbsd from OSF since it installs stuff as root
+ # by default.
+ for ac_prog in ginstall scoinst install; do
+ for ac_exec_ext in '' $ac_executable_extensions; do
+ if { test -f "$as_dir/$ac_prog$ac_exec_ext" && $as_test_x "$as_dir/$ac_prog$ac_exec_ext"; }; then
+ if test $ac_prog = install &&
+ grep dspmsg "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then
+ # AIX install. It has an incompatible calling convention.
+ :
+ elif test $ac_prog = install &&
+ grep pwplus "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then
+ # program-specific install script used by HP pwplus--don't use.
+ :
+ else
+ rm -rf conftest.one conftest.two conftest.dir
+ echo one > conftest.one
+ echo two > conftest.two
+ mkdir conftest.dir
+ if "$as_dir/$ac_prog$ac_exec_ext" -c conftest.one conftest.two "`pwd`/conftest.dir" &&
+ test -s conftest.one && test -s conftest.two &&
+ test -s conftest.dir/conftest.one &&
+ test -s conftest.dir/conftest.two
+ then
+ ac_cv_path_install="$as_dir/$ac_prog$ac_exec_ext -c"
+ break 3
+ fi
+ fi
+ fi
+ done
+ done
+ ;;
+esac
+
+ done
+IFS=$as_save_IFS
+
+rm -rf conftest.one conftest.two conftest.dir
+
+fi
+ if test "${ac_cv_path_install+set}" = set; then
+ INSTALL=$ac_cv_path_install
+ else
+ # As a last resort, use the slow shell script. Don't cache a
+ # value for INSTALL within a source directory, because that will
+ # break other packages using the cache if that directory is
+ # removed, or if the value is a relative name.
+ INSTALL=$ac_install_sh
+ fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $INSTALL" >&5
+$as_echo "$INSTALL" >&6; }
+
+# Use test -z because SunOS4 sh mishandles braces in ${var-val}.
+# It thinks the first close brace ends the variable substitution.
+test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}'
+
+test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL}'
+
+test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644'
+
+for ac_prog in gawk mawk nawk awk
+do
+ # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_AWK+set}" = set; then :
+ $as_echo_n "(cached) " >&6
+else
+ if test -n "$AWK"; then
+ ac_cv_prog_AWK="$AWK" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ for ac_exec_ext in '' $ac_executable_extensions; do
+ if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+ ac_cv_prog_AWK="$ac_prog"
+ $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+ break 2
+ fi
+done
+ done
+IFS=$as_save_IFS
+
+fi
+fi
+AWK=$ac_cv_prog_AWK
+if test -n "$AWK"; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $AWK" >&5
+$as_echo "$AWK" >&6; }
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+ test -n "$AWK" && break
+done
+
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+if test -n "$ac_tool_prefix"; then
+ # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args.
+set dummy ${ac_tool_prefix}gcc; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_CC+set}" = set; then :
+ $as_echo_n "(cached) " >&6
+else
+ if test -n "$CC"; then
+ ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ for ac_exec_ext in '' $ac_executable_extensions; do
+ if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+ ac_cv_prog_CC="${ac_tool_prefix}gcc"
+ $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+ break 2
+ fi
+done
+ done
+IFS=$as_save_IFS
+
+fi
+fi
+CC=$ac_cv_prog_CC
+if test -n "$CC"; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
+$as_echo "$CC" >&6; }
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_CC"; then
+ ac_ct_CC=$CC
+ # Extract the first word of "gcc", so it can be a program name with args.
+set dummy gcc; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_ac_ct_CC+set}" = set; then :
+ $as_echo_n "(cached) " >&6
+else
+ if test -n "$ac_ct_CC"; then
+ ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ for ac_exec_ext in '' $ac_executable_extensions; do
+ if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+ ac_cv_prog_ac_ct_CC="gcc"
+ $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+ break 2
+ fi
+done
+ done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_CC=$ac_cv_prog_ac_ct_CC
+if test -n "$ac_ct_CC"; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5
+$as_echo "$ac_ct_CC" >&6; }
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+ if test "x$ac_ct_CC" = x; then
+ CC=""
+ else
+ case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+ CC=$ac_ct_CC
+ fi
+else
+ CC="$ac_cv_prog_CC"
+fi
+
+if test -z "$CC"; then
+ if test -n "$ac_tool_prefix"; then
+ # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args.
+set dummy ${ac_tool_prefix}cc; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_CC+set}" = set; then :
+ $as_echo_n "(cached) " >&6
+else
+ if test -n "$CC"; then
+ ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ for ac_exec_ext in '' $ac_executable_extensions; do
+ if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+ ac_cv_prog_CC="${ac_tool_prefix}cc"
+ $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+ break 2
+ fi
+done
+ done
+IFS=$as_save_IFS
+
+fi
+fi
+CC=$ac_cv_prog_CC
+if test -n "$CC"; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
+$as_echo "$CC" >&6; }
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+ fi
+fi
+if test -z "$CC"; then
+ # Extract the first word of "cc", so it can be a program name with args.
+set dummy cc; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_CC+set}" = set; then :
+ $as_echo_n "(cached) " >&6
+else
+ if test -n "$CC"; then
+ ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+ ac_prog_rejected=no
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ for ac_exec_ext in '' $ac_executable_extensions; do
+ if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+ if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then
+ ac_prog_rejected=yes
+ continue
+ fi
+ ac_cv_prog_CC="cc"
+ $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+ break 2
+ fi
+done
+ done
+IFS=$as_save_IFS
+
+if test $ac_prog_rejected = yes; then
+ # We found a bogon in the path, so make sure we never use it.
+ set dummy $ac_cv_prog_CC
+ shift
+ if test $# != 0; then
+ # We chose a different compiler from the bogus one.
+ # However, it has the same basename, so the bogon will be chosen
+ # first if we set CC to just the basename; use the full file name.
+ shift
+ ac_cv_prog_CC="$as_dir/$ac_word${1+' '}$@"
+ fi
+fi
+fi
+fi
+CC=$ac_cv_prog_CC
+if test -n "$CC"; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
+$as_echo "$CC" >&6; }
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$CC"; then
+ if test -n "$ac_tool_prefix"; then
+ for ac_prog in cl.exe
+ do
+ # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args.
+set dummy $ac_tool_prefix$ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_CC+set}" = set; then :
+ $as_echo_n "(cached) " >&6
+else
+ if test -n "$CC"; then
+ ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ for ac_exec_ext in '' $ac_executable_extensions; do
+ if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+ ac_cv_prog_CC="$ac_tool_prefix$ac_prog"
+ $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+ break 2
+ fi
+done
+ done
+IFS=$as_save_IFS
+
+fi
+fi
+CC=$ac_cv_prog_CC
+if test -n "$CC"; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
+$as_echo "$CC" >&6; }
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+ test -n "$CC" && break
+ done
+fi
+if test -z "$CC"; then
+ ac_ct_CC=$CC
+ for ac_prog in cl.exe
+do
+ # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_ac_ct_CC+set}" = set; then :
+ $as_echo_n "(cached) " >&6
+else
+ if test -n "$ac_ct_CC"; then
+ ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ for ac_exec_ext in '' $ac_executable_extensions; do
+ if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+ ac_cv_prog_ac_ct_CC="$ac_prog"
+ $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+ break 2
+ fi
+done
+ done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_CC=$ac_cv_prog_ac_ct_CC
+if test -n "$ac_ct_CC"; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5
+$as_echo "$ac_ct_CC" >&6; }
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+ test -n "$ac_ct_CC" && break
+done
+
+ if test "x$ac_ct_CC" = x; then
+ CC=""
+ else
+ case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+ CC=$ac_ct_CC
+ fi
+fi
+
+fi
+
+
+test -z "$CC" && { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "no acceptable C compiler found in \$PATH
+See \`config.log' for more details" "$LINENO" 5; }
+
+# Provide some information about the compiler.
+$as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler version" >&5
+set X $ac_compile
+ac_compiler=$2
+for ac_option in --version -v -V -qversion; do
+ { { ac_try="$ac_compiler $ac_option >&5"
+case "(($ac_try" in
+ *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+ *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+ (eval "$ac_compiler $ac_option >&5") 2>conftest.err
+ ac_status=$?
+ if test -s conftest.err; then
+ sed '10a\
+... rest of stderr output deleted ...
+ 10q' conftest.err >conftest.er1
+ cat conftest.er1 >&5
+ fi
+ rm -f conftest.er1 conftest.err
+ $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+ test $ac_status = 0; }
+done
+
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+int
+main ()
+{
+
+ ;
+ return 0;
+}
+_ACEOF
+ac_clean_files_save=$ac_clean_files
+ac_clean_files="$ac_clean_files a.out a.out.dSYM a.exe b.out"
+# Try to create an executable without -o first, disregard a.out.
+# It will help us diagnose broken compilers, and finding out an intuition
+# of exeext.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the C compiler works" >&5
+$as_echo_n "checking whether the C compiler works... " >&6; }
+ac_link_default=`$as_echo "$ac_link" | sed 's/ -o *conftest[^ ]*//'`
+
+# The possible output files:
+ac_files="a.out conftest.exe conftest a.exe a_out.exe b.out conftest.*"
+
+ac_rmfiles=
+for ac_file in $ac_files
+do
+ case $ac_file in
+ *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;;
+ * ) ac_rmfiles="$ac_rmfiles $ac_file";;
+ esac
+done
+rm -f $ac_rmfiles
+
+if { { ac_try="$ac_link_default"
+case "(($ac_try" in
+ *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+ *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+ (eval "$ac_link_default") 2>&5
+ ac_status=$?
+ $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+ test $ac_status = 0; }; then :
+ # Autoconf-2.13 could set the ac_cv_exeext variable to `no'.
+# So ignore a value of `no', otherwise this would lead to `EXEEXT = no'
+# in a Makefile. We should not override ac_cv_exeext if it was cached,
+# so that the user can short-circuit this test for compilers unknown to
+# Autoconf.
+for ac_file in $ac_files ''
+do
+ test -f "$ac_file" || continue
+ case $ac_file in
+ *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj )
+ ;;
+ [ab].out )
+ # We found the default executable, but exeext='' is most
+ # certainly right.
+ break;;
+ *.* )
+ if test "${ac_cv_exeext+set}" = set && test "$ac_cv_exeext" != no;
+ then :; else
+ ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'`
+ fi
+ # We set ac_cv_exeext here because the later test for it is not
+ # safe: cross compilers may not add the suffix if given an `-o'
+ # argument, so we may need to know it at that point already.
+ # Even if this section looks crufty: it has the advantage of
+ # actually working.
+ break;;
+ * )
+ break;;
+ esac
+done
+test "$ac_cv_exeext" = no && ac_cv_exeext=
+
+else
+ ac_file=''
+fi
+if test -z "$ac_file"; then :
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+$as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error 77 "C compiler cannot create executables
+See \`config.log' for more details" "$LINENO" 5; }
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler default output file name" >&5
+$as_echo_n "checking for C compiler default output file name... " >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_file" >&5
+$as_echo "$ac_file" >&6; }
+ac_exeext=$ac_cv_exeext
+
+rm -f -r a.out a.out.dSYM a.exe conftest$ac_cv_exeext b.out
+ac_clean_files=$ac_clean_files_save
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of executables" >&5
+$as_echo_n "checking for suffix of executables... " >&6; }
+if { { ac_try="$ac_link"
+case "(($ac_try" in
+ *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+ *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+ (eval "$ac_link") 2>&5
+ ac_status=$?
+ $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+ test $ac_status = 0; }; then :
+ # If both `conftest.exe' and `conftest' are `present' (well, observable)
+# catch `conftest.exe'. For instance with Cygwin, `ls conftest' will
+# work properly (i.e., refer to `conftest.exe'), while it won't with
+# `rm'.
+for ac_file in conftest.exe conftest conftest.*; do
+ test -f "$ac_file" || continue
+ case $ac_file in
+ *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;;
+ *.* ) ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'`
+ break;;
+ * ) break;;
+ esac
+done
+else
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "cannot compute suffix of executables: cannot compile and link
+See \`config.log' for more details" "$LINENO" 5; }
+fi
+rm -f conftest conftest$ac_cv_exeext
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_exeext" >&5
+$as_echo "$ac_cv_exeext" >&6; }
+
+rm -f conftest.$ac_ext
+EXEEXT=$ac_cv_exeext
+ac_exeext=$EXEEXT
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#include <stdio.h>
+int
+main ()
+{
+FILE *f = fopen ("conftest.out", "w");
+ return ferror (f) || fclose (f) != 0;
+
+ ;
+ return 0;
+}
+_ACEOF
+ac_clean_files="$ac_clean_files conftest.out"
+# Check that the compiler produces executables we can run. If not, either
+# the compiler is broken, or we cross compile.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are cross compiling" >&5
+$as_echo_n "checking whether we are cross compiling... " >&6; }
+if test "$cross_compiling" != yes; then
+ { { ac_try="$ac_link"
+case "(($ac_try" in
+ *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+ *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+ (eval "$ac_link") 2>&5
+ ac_status=$?
+ $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+ test $ac_status = 0; }
+ if { ac_try='./conftest$ac_cv_exeext'
+ { { case "(($ac_try" in
+ *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+ *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+ (eval "$ac_try") 2>&5
+ ac_status=$?
+ $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+ test $ac_status = 0; }; }; then
+ cross_compiling=no
+ else
+ if test "$cross_compiling" = maybe; then
+ cross_compiling=yes
+ else
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "cannot run C compiled programs.
+If you meant to cross compile, use \`--host'.
+See \`config.log' for more details" "$LINENO" 5; }
+ fi
+ fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $cross_compiling" >&5
+$as_echo "$cross_compiling" >&6; }
+
+rm -f conftest.$ac_ext conftest$ac_cv_exeext conftest.out
+ac_clean_files=$ac_clean_files_save
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of object files" >&5
+$as_echo_n "checking for suffix of object files... " >&6; }
+if test "${ac_cv_objext+set}" = set; then :
+ $as_echo_n "(cached) " >&6
+else
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+int
+main ()
+{
+
+ ;
+ return 0;
+}
+_ACEOF
+rm -f conftest.o conftest.obj
+if { { ac_try="$ac_compile"
+case "(($ac_try" in
+ *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+ *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+ (eval "$ac_compile") 2>&5
+ ac_status=$?
+ $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+ test $ac_status = 0; }; then :
+ for ac_file in conftest.o conftest.obj conftest.*; do
+ test -f "$ac_file" || continue;
+ case $ac_file in
+ *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM ) ;;
+ *) ac_cv_objext=`expr "$ac_file" : '.*\.\(.*\)'`
+ break;;
+ esac
+done
+else
+ $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "cannot compute suffix of object files: cannot compile
+See \`config.log' for more details" "$LINENO" 5; }
+fi
+rm -f conftest.$ac_cv_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_objext" >&5
+$as_echo "$ac_cv_objext" >&6; }
+OBJEXT=$ac_cv_objext
+ac_objext=$OBJEXT
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C compiler" >&5
+$as_echo_n "checking whether we are using the GNU C compiler... " >&6; }
+if test "${ac_cv_c_compiler_gnu+set}" = set; then :
+ $as_echo_n "(cached) " >&6
+else
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+int
+main ()
+{
+#ifndef __GNUC__
+ choke me
+#endif
+
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+ ac_compiler_gnu=yes
+else
+ ac_compiler_gnu=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+ac_cv_c_compiler_gnu=$ac_compiler_gnu
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_compiler_gnu" >&5
+$as_echo "$ac_cv_c_compiler_gnu" >&6; }
+if test $ac_compiler_gnu = yes; then
+ GCC=yes
+else
+ GCC=
+fi
+ac_test_CFLAGS=${CFLAGS+set}
+ac_save_CFLAGS=$CFLAGS
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -g" >&5
+$as_echo_n "checking whether $CC accepts -g... " >&6; }
+if test "${ac_cv_prog_cc_g+set}" = set; then :
+ $as_echo_n "(cached) " >&6
+else
+ ac_save_c_werror_flag=$ac_c_werror_flag
+ ac_c_werror_flag=yes
+ ac_cv_prog_cc_g=no
+ CFLAGS="-g"
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+int
+main ()
+{
+
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+ ac_cv_prog_cc_g=yes
+else
+ CFLAGS=""
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+int
+main ()
+{
+
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+
+else
+ ac_c_werror_flag=$ac_save_c_werror_flag
+ CFLAGS="-g"
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+int
+main ()
+{
+
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+ ac_cv_prog_cc_g=yes
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+ ac_c_werror_flag=$ac_save_c_werror_flag
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_g" >&5
+$as_echo "$ac_cv_prog_cc_g" >&6; }
+if test "$ac_test_CFLAGS" = set; then
+ CFLAGS=$ac_save_CFLAGS
+elif test $ac_cv_prog_cc_g = yes; then
+ if test "$GCC" = yes; then
+ CFLAGS="-g -O2"
+ else
+ CFLAGS="-g"
+ fi
+else
+ if test "$GCC" = yes; then
+ CFLAGS="-O2"
+ else
+ CFLAGS=
+ fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $CC option to accept ISO C89" >&5
+$as_echo_n "checking for $CC option to accept ISO C89... " >&6; }
+if test "${ac_cv_prog_cc_c89+set}" = set; then :
+ $as_echo_n "(cached) " >&6
+else
+ ac_cv_prog_cc_c89=no
+ac_save_CC=$CC
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#include <stdarg.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+/* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */
+struct buf { int x; };
+FILE * (*rcsopen) (struct buf *, struct stat *, int);
+static char *e (p, i)
+ char **p;
+ int i;
+{
+ return p[i];
+}
+static char *f (char * (*g) (char **, int), char **p, ...)
+{
+ char *s;
+ va_list v;
+ va_start (v,p);
+ s = g (p, va_arg (v,int));
+ va_end (v);
+ return s;
+}
+
+/* OSF 4.0 Compaq cc is some sort of almost-ANSI by default. It has
+ function prototypes and stuff, but not '\xHH' hex character constants.
+ These don't provoke an error unfortunately, instead are silently treated
+ as 'x'. The following induces an error, until -std is added to get
+ proper ANSI mode. Curiously '\x00'!='x' always comes out true, for an
+ array size at least. It's necessary to write '\x00'==0 to get something
+ that's true only with -std. */
+int osf4_cc_array ['\x00' == 0 ? 1 : -1];
+
+/* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters
+ inside strings and character constants. */
+#define FOO(x) 'x'
+int xlc6_cc_array[FOO(a) == 'x' ? 1 : -1];
+
+int test (int i, double x);
+struct s1 {int (*f) (int a);};
+struct s2 {int (*f) (double a);};
+int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int);
+int argc;
+char **argv;
+int
+main ()
+{
+return f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1];
+ ;
+ return 0;
+}
+_ACEOF
+for ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std \
+ -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__"
+do
+ CC="$ac_save_CC $ac_arg"
+ if ac_fn_c_try_compile "$LINENO"; then :
+ ac_cv_prog_cc_c89=$ac_arg
+fi
+rm -f core conftest.err conftest.$ac_objext
+ test "x$ac_cv_prog_cc_c89" != "xno" && break
+done
+rm -f conftest.$ac_ext
+CC=$ac_save_CC
+
+fi
+# AC_CACHE_VAL
+case "x$ac_cv_prog_cc_c89" in
+ x)
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: none needed" >&5
+$as_echo "none needed" >&6; } ;;
+ xno)
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5
+$as_echo "unsupported" >&6; } ;;
+ *)
+ CC="$CC $ac_cv_prog_cc_c89"
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c89" >&5
+$as_echo "$ac_cv_prog_cc_c89" >&6; } ;;
+esac
+if test "x$ac_cv_prog_cc_c89" != xno; then :
+
+fi
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+# Require GCC.
+if test x$GCC != xyes; then
+ as_fn_error $? "this code uses GNU C extensions, you must compile with GCC" "$LINENO" 5
+fi
+
+if test -n "$ac_tool_prefix"; then
+ # Extract the first word of "${ac_tool_prefix}ld", so it can be a program name with args.
+set dummy ${ac_tool_prefix}ld; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_LD+set}" = set; then :
+ $as_echo_n "(cached) " >&6
+else
+ if test -n "$LD"; then
+ ac_cv_prog_LD="$LD" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ for ac_exec_ext in '' $ac_executable_extensions; do
+ if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+ ac_cv_prog_LD="${ac_tool_prefix}ld"
+ $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+ break 2
+ fi
+done
+ done
+IFS=$as_save_IFS
+
+fi
+fi
+LD=$ac_cv_prog_LD
+if test -n "$LD"; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LD" >&5
+$as_echo "$LD" >&6; }
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_LD"; then
+ ac_ct_LD=$LD
+ # Extract the first word of "ld", so it can be a program name with args.
+set dummy ld; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_ac_ct_LD+set}" = set; then :
+ $as_echo_n "(cached) " >&6
+else
+ if test -n "$ac_ct_LD"; then
+ ac_cv_prog_ac_ct_LD="$ac_ct_LD" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ for ac_exec_ext in '' $ac_executable_extensions; do
+ if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+ ac_cv_prog_ac_ct_LD="ld"
+ $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+ break 2
+ fi
+done
+ done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_LD=$ac_cv_prog_ac_ct_LD
+if test -n "$ac_ct_LD"; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_LD" >&5
+$as_echo "$ac_ct_LD" >&6; }
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+ if test "x$ac_ct_LD" = x; then
+ LD=""
+ else
+ case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+ LD=$ac_ct_LD
+ fi
+else
+ LD="$ac_cv_prog_LD"
+fi
+
+if test -n "$ac_tool_prefix"; then
+ # Extract the first word of "${ac_tool_prefix}objcopy", so it can be a program name with args.
+set dummy ${ac_tool_prefix}objcopy; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_OBJCOPY+set}" = set; then :
+ $as_echo_n "(cached) " >&6
+else
+ if test -n "$OBJCOPY"; then
+ ac_cv_prog_OBJCOPY="$OBJCOPY" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ for ac_exec_ext in '' $ac_executable_extensions; do
+ if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+ ac_cv_prog_OBJCOPY="${ac_tool_prefix}objcopy"
+ $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+ break 2
+ fi
+done
+ done
+IFS=$as_save_IFS
+
+fi
+fi
+OBJCOPY=$ac_cv_prog_OBJCOPY
+if test -n "$OBJCOPY"; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $OBJCOPY" >&5
+$as_echo "$OBJCOPY" >&6; }
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_OBJCOPY"; then
+ ac_ct_OBJCOPY=$OBJCOPY
+ # Extract the first word of "objcopy", so it can be a program name with args.
+set dummy objcopy; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_ac_ct_OBJCOPY+set}" = set; then :
+ $as_echo_n "(cached) " >&6
+else
+ if test -n "$ac_ct_OBJCOPY"; then
+ ac_cv_prog_ac_ct_OBJCOPY="$ac_ct_OBJCOPY" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ for ac_exec_ext in '' $ac_executable_extensions; do
+ if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+ ac_cv_prog_ac_ct_OBJCOPY="objcopy"
+ $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+ break 2
+ fi
+done
+ done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_OBJCOPY=$ac_cv_prog_ac_ct_OBJCOPY
+if test -n "$ac_ct_OBJCOPY"; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OBJCOPY" >&5
+$as_echo "$ac_ct_OBJCOPY" >&6; }
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+ if test "x$ac_ct_OBJCOPY" = x; then
+ OBJCOPY=""
+ else
+ case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+ OBJCOPY=$ac_ct_OBJCOPY
+ fi
+else
+ OBJCOPY="$ac_cv_prog_OBJCOPY"
+fi
+
+if test -n "$ac_tool_prefix"; then
+ # Extract the first word of "${ac_tool_prefix}ar", so it can be a program name with args.
+set dummy ${ac_tool_prefix}ar; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_AR+set}" = set; then :
+ $as_echo_n "(cached) " >&6
+else
+ if test -n "$AR"; then
+ ac_cv_prog_AR="$AR" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ for ac_exec_ext in '' $ac_executable_extensions; do
+ if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+ ac_cv_prog_AR="${ac_tool_prefix}ar"
+ $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+ break 2
+ fi
+done
+ done
+IFS=$as_save_IFS
+
+fi
+fi
+AR=$ac_cv_prog_AR
+if test -n "$AR"; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $AR" >&5
+$as_echo "$AR" >&6; }
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_AR"; then
+ ac_ct_AR=$AR
+ # Extract the first word of "ar", so it can be a program name with args.
+set dummy ar; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_ac_ct_AR+set}" = set; then :
+ $as_echo_n "(cached) " >&6
+else
+ if test -n "$ac_ct_AR"; then
+ ac_cv_prog_ac_ct_AR="$ac_ct_AR" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ for ac_exec_ext in '' $ac_executable_extensions; do
+ if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+ ac_cv_prog_ac_ct_AR="ar"
+ $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+ break 2
+ fi
+done
+ done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_AR=$ac_cv_prog_ac_ct_AR
+if test -n "$ac_ct_AR"; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_AR" >&5
+$as_echo "$ac_ct_AR" >&6; }
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+ if test "x$ac_ct_AR" = x; then
+ AR=""
+ else
+ case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+ AR=$ac_ct_AR
+ fi
+else
+ AR="$ac_cv_prog_AR"
+fi
+
+if test -n "$ac_tool_prefix"; then
+ # Extract the first word of "${ac_tool_prefix}ranlib", so it can be a program name with args.
+set dummy ${ac_tool_prefix}ranlib; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_RANLIB+set}" = set; then :
+ $as_echo_n "(cached) " >&6
+else
+ if test -n "$RANLIB"; then
+ ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ for ac_exec_ext in '' $ac_executable_extensions; do
+ if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+ ac_cv_prog_RANLIB="${ac_tool_prefix}ranlib"
+ $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+ break 2
+ fi
+done
+ done
+IFS=$as_save_IFS
+
+fi
+fi
+RANLIB=$ac_cv_prog_RANLIB
+if test -n "$RANLIB"; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $RANLIB" >&5
+$as_echo "$RANLIB" >&6; }
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_RANLIB"; then
+ ac_ct_RANLIB=$RANLIB
+ # Extract the first word of "ranlib", so it can be a program name with args.
+set dummy ranlib; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_ac_ct_RANLIB+set}" = set; then :
+ $as_echo_n "(cached) " >&6
+else
+ if test -n "$ac_ct_RANLIB"; then
+ ac_cv_prog_ac_ct_RANLIB="$ac_ct_RANLIB" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ for ac_exec_ext in '' $ac_executable_extensions; do
+ if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+ ac_cv_prog_ac_ct_RANLIB="ranlib"
+ $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+ break 2
+ fi
+done
+ done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_RANLIB=$ac_cv_prog_ac_ct_RANLIB
+if test -n "$ac_ct_RANLIB"; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_RANLIB" >&5
+$as_echo "$ac_ct_RANLIB" >&6; }
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+ if test "x$ac_ct_RANLIB" = x; then
+ RANLIB=""
+ else
+ case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+ RANLIB=$ac_ct_RANLIB
+ fi
+else
+ RANLIB="$ac_cv_prog_RANLIB"
+fi
+
+if test -n "$ac_tool_prefix"; then
+ # Extract the first word of "${ac_tool_prefix}mig", so it can be a program name with args.
+set dummy ${ac_tool_prefix}mig; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_MIG+set}" = set; then :
+ $as_echo_n "(cached) " >&6
+else
+ if test -n "$MIG"; then
+ ac_cv_prog_MIG="$MIG" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ for ac_exec_ext in '' $ac_executable_extensions; do
+ if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+ ac_cv_prog_MIG="${ac_tool_prefix}mig"
+ $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+ break 2
+ fi
+done
+ done
+IFS=$as_save_IFS
+
+fi
+fi
+MIG=$ac_cv_prog_MIG
+if test -n "$MIG"; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $MIG" >&5
+$as_echo "$MIG" >&6; }
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_MIG"; then
+ ac_ct_MIG=$MIG
+ # Extract the first word of "mig", so it can be a program name with args.
+set dummy mig; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_ac_ct_MIG+set}" = set; then :
+ $as_echo_n "(cached) " >&6
+else
+ if test -n "$ac_ct_MIG"; then
+ ac_cv_prog_ac_ct_MIG="$ac_ct_MIG" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ for ac_exec_ext in '' $ac_executable_extensions; do
+ if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+ ac_cv_prog_ac_ct_MIG="mig"
+ $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+ break 2
+ fi
+done
+ done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_MIG=$ac_cv_prog_ac_ct_MIG
+if test -n "$ac_ct_MIG"; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_MIG" >&5
+$as_echo "$ac_ct_MIG" >&6; }
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+ if test "x$ac_ct_MIG" = x; then
+ MIG=""
+ else
+ case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+ MIG=$ac_ct_MIG
+ fi
+else
+ MIG="$ac_cv_prog_MIG"
+fi
+
+# Require MiG.
+if test x${MIG} = x; then
+ as_fn_error $? "
+*** You need GNU MiG to compile the GNU Hurd, please see
+*** http://www.gnu.org/software/hurd/mig.html for further details, or
+*** download it directly from the main GNU server (ftp.gnu.org) or any
+*** GNU mirror." "$LINENO" 5
+fi
+
+
+
+# See if there's a separate libcrypt (many systems put crypt there).
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for crypt in -lcrypt" >&5
+$as_echo_n "checking for crypt in -lcrypt... " >&6; }
+if test "${ac_cv_lib_crypt_crypt+set}" = set; then :
+ $as_echo_n "(cached) " >&6
+else
+ ac_check_lib_save_LIBS=$LIBS
+LIBS="-lcrypt $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+/* Override any GCC internal prototype to avoid an error.
+ Use char because int might match the return type of a GCC
+ builtin and then its argument prototype would still apply. */
+#ifdef __cplusplus
+extern "C"
+#endif
+char crypt ();
+int
+main ()
+{
+return crypt ();
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+ ac_cv_lib_crypt_crypt=yes
+else
+ ac_cv_lib_crypt_crypt=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_crypt_crypt" >&5
+$as_echo "$ac_cv_lib_crypt_crypt" >&6; }
+if test "x$ac_cv_lib_crypt_crypt" = x""yes; then :
+ LIBCRYPT=-lcrypt
+fi
+
+
+
+# See if mig groks `retcode'.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $MIG supports the retcode keyword" >&5
+$as_echo_n "checking whether $MIG supports the retcode keyword... " >&6; }
+if test "${hurd_cv_mig_retcode+set}" = set; then :
+ $as_echo_n "(cached) " >&6
+else
+ cat > conftest.defs <<\EOF
+#include <mach/std_types.defs>
+#include <mach/mach_types.defs>
+subsystem foobar 1000;
+type reply_port_t = polymorphic | MACH_MSG_TYPE_PORT_SEND_ONCE
+ ctype: mach_port_t;
+simpleroutine foobar_reply (
+ reply_port: reply_port_t;
+ err: kern_return_t, RetCode);
+EOF
+if { ac_try='CC="${CC}" ${MIG-false} -n conftest.defs 1>&5'
+ { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+ test $ac_status = 0; }; }; then
+ hurd_cv_mig_retcode=yes
+else
+ hurd_cv_mig_retcode=no
+fi
+rm -f conftest*
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $hurd_cv_mig_retcode" >&5
+$as_echo "$hurd_cv_mig_retcode" >&6; }
+if test $hurd_cv_mig_retcode = yes; then
+ $as_echo "#define HAVE_MIG_RETCODE 1" >>confdefs.h
+
+fi
+
+# See if --version-script is available.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ld --version-script" >&5
+$as_echo_n "checking for ld --version-script... " >&6; }
+if test "${hurd_cv_ld_version_script_option+set}" = set; then :
+ $as_echo_n "(cached) " >&6
+else
+ cat > conftest.c <<\EOF
+void foobar() {}
+EOF
+cat > conftest.map <<\EOF
+VERS_1 {
+ global: sym;
+};
+
+VERS_2 {
+ global: sym;
+} VERS_1;
+EOF
+
+if { ac_try='eval $ac_compile 1>&5'
+ { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+ test $ac_status = 0; }; } &&
+ { ac_try='${CC-cc} $CFLAGS -shared -o conftest.so conftest.o
+ -nostartfiles -nostdlib
+ -Wl,--version-script,conftest.map
+ 1>&5'
+ { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+ test $ac_status = 0; }; }; then
+ hurd_cv_ld_version_script_option=yes
+else
+ hurd_cv_ld_version_script_option=no
+fi
+rm -f conftest*
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $hurd_cv_ld_version_script_option" >&5
+$as_echo "$hurd_cv_ld_version_script_option" >&6; }
+
+# See if libc was built with --enable-libio.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for libio" >&5
+$as_echo_n "checking for libio... " >&6; }
+if test "${hurd_cv_libio+set}" = set; then :
+ $as_echo_n "(cached) " >&6
+else
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#include <stdio.h>
+#ifndef _STDIO_USES_IOSTREAM
+# error No libio found.
+#endif
+int
+main ()
+{
+
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+ hurd_cv_libio=yes
+else
+ hurd_cv_libio=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $hurd_cv_libio" >&5
+$as_echo "$hurd_cv_libio" >&6; }
+
+# The versions of the symbols in libthreads have to match those in
+# libc.so. Since the symbols in a libc that includes libio will be
+# versioned differently from the ones in a libc that uses stdio, this
+# isn't easy to accomplish. Instead we leave things unversioned if
+# libio isn't found.
+if test $hurd_cv_libio = yes; then
+ VERSIONING=$hurd_cv_ld_version_script_option
+else
+ VERSIONING=no
+fi
+
+
+# Check if libc contains getgrouplist and/or uselocale.
+for ac_func in getgrouplist uselocale
+do :
+ as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
+ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
+if eval test \"x\$"$as_ac_var"\" = x"yes"; then :
+ cat >>confdefs.h <<_ACEOF
+#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1
+_ACEOF
+
+fi
+done
+
+
+
+# From glibc HEAD, 2007-11-07.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for -fgnu89-inline" >&5
+$as_echo_n "checking for -fgnu89-inline... " >&6; }
+if test "${libc_cv_gnu89_inline+set}" = set; then :
+ $as_echo_n "(cached) " >&6
+else
+ cat > conftest.c <<EOF
+int foo;
+#ifdef __GNUC_GNU_INLINE__
+main () { return 0;}
+#else
+#error
+#endif
+EOF
+if { ac_try='${CC-cc} $CFLAGS $CPPFLAGS -S -std=gnu99 -fgnu89-inline
+ -o conftest.s conftest.c 1>&5'
+ { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+ test $ac_status = 0; }; }
+then
+ libc_cv_gnu89_inline=yes
+else
+ libc_cv_gnu89_inline=no
+fi
+rm -f conftest*
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_gnu89_inline" >&5
+$as_echo "$libc_cv_gnu89_inline" >&6; }
+if test $libc_cv_gnu89_inline = yes; then
+ libc_cv_gnu89_inline=-fgnu89-inline
+else
+ libc_cv_gnu89_inline=
+fi
+
+
+
+# Insist on libparted unless the user declines explicitely
+
+# Check whether --with-parted was given.
+if test "${with_parted+set}" = set; then :
+ withval=$with_parted;
+else
+ with_parted=yes
+fi
+
+
+PARTED_LIBS=
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to run the C preprocessor" >&5
+$as_echo_n "checking how to run the C preprocessor... " >&6; }
+# On Suns, sometimes $CPP names a directory.
+if test -n "$CPP" && test -d "$CPP"; then
+ CPP=
+fi
+if test -z "$CPP"; then
+ if test "${ac_cv_prog_CPP+set}" = set; then :
+ $as_echo_n "(cached) " >&6
+else
+ # Double quotes because CPP needs to be expanded
+ for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp"
+ do
+ ac_preproc_ok=false
+for ac_c_preproc_warn_flag in '' yes
+do
+ # Use a header file that comes with gcc, so configuring glibc
+ # with a fresh cross-compiler works.
+ # Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+ # <limits.h> exists even on freestanding compilers.
+ # On the NeXT, cc -E runs the code through the compiler's parser,
+ # not just through cpp. "Syntax error" is here to catch this case.
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+ Syntax error
+_ACEOF
+if ac_fn_c_try_cpp "$LINENO"; then :
+
+else
+ # Broken: fails on valid input.
+continue
+fi
+rm -f conftest.err conftest.i conftest.$ac_ext
+
+ # OK, works on sane cases. Now check whether nonexistent headers
+ # can be detected and how.
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#include <ac_nonexistent.h>
+_ACEOF
+if ac_fn_c_try_cpp "$LINENO"; then :
+ # Broken: success on invalid input.
+continue
+else
+ # Passes both tests.
+ac_preproc_ok=:
+break
+fi
+rm -f conftest.err conftest.i conftest.$ac_ext
+
+done
+# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped.
+rm -f conftest.i conftest.err conftest.$ac_ext
+if $ac_preproc_ok; then :
+ break
+fi
+
+ done
+ ac_cv_prog_CPP=$CPP
+
+fi
+ CPP=$ac_cv_prog_CPP
+else
+ ac_cv_prog_CPP=$CPP
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $CPP" >&5
+$as_echo "$CPP" >&6; }
+ac_preproc_ok=false
+for ac_c_preproc_warn_flag in '' yes
+do
+ # Use a header file that comes with gcc, so configuring glibc
+ # with a fresh cross-compiler works.
+ # Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+ # <limits.h> exists even on freestanding compilers.
+ # On the NeXT, cc -E runs the code through the compiler's parser,
+ # not just through cpp. "Syntax error" is here to catch this case.
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+ Syntax error
+_ACEOF
+if ac_fn_c_try_cpp "$LINENO"; then :
+
+else
+ # Broken: fails on valid input.
+continue
+fi
+rm -f conftest.err conftest.i conftest.$ac_ext
+
+ # OK, works on sane cases. Now check whether nonexistent headers
+ # can be detected and how.
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#include <ac_nonexistent.h>
+_ACEOF
+if ac_fn_c_try_cpp "$LINENO"; then :
+ # Broken: success on invalid input.
+continue
+else
+ # Passes both tests.
+ac_preproc_ok=:
+break
+fi
+rm -f conftest.err conftest.i conftest.$ac_ext
+
+done
+# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped.
+rm -f conftest.i conftest.err conftest.$ac_ext
+if $ac_preproc_ok; then :
+
+else
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "C preprocessor \"$CPP\" fails sanity check
+See \`config.log' for more details" "$LINENO" 5; }
+fi
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for grep that handles long lines and -e" >&5
+$as_echo_n "checking for grep that handles long lines and -e... " >&6; }
+if test "${ac_cv_path_GREP+set}" = set; then :
+ $as_echo_n "(cached) " >&6
+else
+ if test -z "$GREP"; then
+ ac_path_GREP_found=false
+ # Loop through the user's path and test for each of PROGNAME-LIST
+ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ for ac_prog in grep ggrep; do
+ for ac_exec_ext in '' $ac_executable_extensions; do
+ ac_path_GREP="$as_dir/$ac_prog$ac_exec_ext"
+ { test -f "$ac_path_GREP" && $as_test_x "$ac_path_GREP"; } || continue
+# Check for GNU ac_path_GREP and select it if it is found.
+ # Check for GNU $ac_path_GREP
+case `"$ac_path_GREP" --version 2>&1` in
+*GNU*)
+ ac_cv_path_GREP="$ac_path_GREP" ac_path_GREP_found=:;;
+*)
+ ac_count=0
+ $as_echo_n 0123456789 >"conftest.in"
+ while :
+ do
+ cat "conftest.in" "conftest.in" >"conftest.tmp"
+ mv "conftest.tmp" "conftest.in"
+ cp "conftest.in" "conftest.nl"
+ $as_echo 'GREP' >> "conftest.nl"
+ "$ac_path_GREP" -e 'GREP$' -e '-(cannot match)-' < "conftest.nl" >"conftest.out" 2>/dev/null || break
+ diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break
+ as_fn_arith $ac_count + 1 && ac_count=$as_val
+ if test $ac_count -gt ${ac_path_GREP_max-0}; then
+ # Best one so far, save it but keep looking for a better one
+ ac_cv_path_GREP="$ac_path_GREP"
+ ac_path_GREP_max=$ac_count
+ fi
+ # 10*(2^10) chars as input seems more than enough
+ test $ac_count -gt 10 && break
+ done
+ rm -f conftest.in conftest.tmp conftest.nl conftest.out;;
+esac
+
+ $ac_path_GREP_found && break 3
+ done
+ done
+ done
+IFS=$as_save_IFS
+ if test -z "$ac_cv_path_GREP"; then
+ as_fn_error $? "no acceptable grep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5
+ fi
+else
+ ac_cv_path_GREP=$GREP
+fi
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_GREP" >&5
+$as_echo "$ac_cv_path_GREP" >&6; }
+ GREP="$ac_cv_path_GREP"
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for egrep" >&5
+$as_echo_n "checking for egrep... " >&6; }
+if test "${ac_cv_path_EGREP+set}" = set; then :
+ $as_echo_n "(cached) " >&6
+else
+ if echo a | $GREP -E '(a|b)' >/dev/null 2>&1
+ then ac_cv_path_EGREP="$GREP -E"
+ else
+ if test -z "$EGREP"; then
+ ac_path_EGREP_found=false
+ # Loop through the user's path and test for each of PROGNAME-LIST
+ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ for ac_prog in egrep; do
+ for ac_exec_ext in '' $ac_executable_extensions; do
+ ac_path_EGREP="$as_dir/$ac_prog$ac_exec_ext"
+ { test -f "$ac_path_EGREP" && $as_test_x "$ac_path_EGREP"; } || continue
+# Check for GNU ac_path_EGREP and select it if it is found.
+ # Check for GNU $ac_path_EGREP
+case `"$ac_path_EGREP" --version 2>&1` in
+*GNU*)
+ ac_cv_path_EGREP="$ac_path_EGREP" ac_path_EGREP_found=:;;
+*)
+ ac_count=0
+ $as_echo_n 0123456789 >"conftest.in"
+ while :
+ do
+ cat "conftest.in" "conftest.in" >"conftest.tmp"
+ mv "conftest.tmp" "conftest.in"
+ cp "conftest.in" "conftest.nl"
+ $as_echo 'EGREP' >> "conftest.nl"
+ "$ac_path_EGREP" 'EGREP$' < "conftest.nl" >"conftest.out" 2>/dev/null || break
+ diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break
+ as_fn_arith $ac_count + 1 && ac_count=$as_val
+ if test $ac_count -gt ${ac_path_EGREP_max-0}; then
+ # Best one so far, save it but keep looking for a better one
+ ac_cv_path_EGREP="$ac_path_EGREP"
+ ac_path_EGREP_max=$ac_count
+ fi
+ # 10*(2^10) chars as input seems more than enough
+ test $ac_count -gt 10 && break
+ done
+ rm -f conftest.in conftest.tmp conftest.nl conftest.out;;
+esac
+
+ $ac_path_EGREP_found && break 3
+ done
+ done
+ done
+IFS=$as_save_IFS
+ if test -z "$ac_cv_path_EGREP"; then
+ as_fn_error $? "no acceptable egrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5
+ fi
+else
+ ac_cv_path_EGREP=$EGREP
+fi
+
+ fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_EGREP" >&5
+$as_echo "$ac_cv_path_EGREP" >&6; }
+ EGREP="$ac_cv_path_EGREP"
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ANSI C header files" >&5
+$as_echo_n "checking for ANSI C header files... " >&6; }
+if test "${ac_cv_header_stdc+set}" = set; then :
+ $as_echo_n "(cached) " >&6
+else
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#include <float.h>
+
+int
+main ()
+{
+
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+ ac_cv_header_stdc=yes
+else
+ ac_cv_header_stdc=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
+if test $ac_cv_header_stdc = yes; then
+ # SunOS 4.x string.h does not declare mem*, contrary to ANSI.
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#include <string.h>
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+ $EGREP "memchr" >/dev/null 2>&1; then :
+
+else
+ ac_cv_header_stdc=no
+fi
+rm -f conftest*
+
+fi
+
+if test $ac_cv_header_stdc = yes; then
+ # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI.
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#include <stdlib.h>
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+ $EGREP "free" >/dev/null 2>&1; then :
+
+else
+ ac_cv_header_stdc=no
+fi
+rm -f conftest*
+
+fi
+
+if test $ac_cv_header_stdc = yes; then
+ # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi.
+ if test "$cross_compiling" = yes; then :
+ :
+else
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#include <ctype.h>
+#include <stdlib.h>
+#if ((' ' & 0x0FF) == 0x020)
+# define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
+# define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c))
+#else
+# define ISLOWER(c) \
+ (('a' <= (c) && (c) <= 'i') \
+ || ('j' <= (c) && (c) <= 'r') \
+ || ('s' <= (c) && (c) <= 'z'))
+# define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c))
+#endif
+
+#define XOR(e, f) (((e) && !(f)) || (!(e) && (f)))
+int
+main ()
+{
+ int i;
+ for (i = 0; i < 256; i++)
+ if (XOR (islower (i), ISLOWER (i))
+ || toupper (i) != TOUPPER (i))
+ return 2;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_run "$LINENO"; then :
+
+else
+ ac_cv_header_stdc=no
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+ conftest.$ac_objext conftest.beam conftest.$ac_ext
+fi
+
+fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_stdc" >&5
+$as_echo "$ac_cv_header_stdc" >&6; }
+if test $ac_cv_header_stdc = yes; then
+
+$as_echo "#define STDC_HEADERS 1" >>confdefs.h
+
+fi
+
+# On IRIX 5.3, sys/types and inttypes.h are conflicting.
+for ac_header in sys/types.h sys/stat.h stdlib.h string.h memory.h strings.h \
+ inttypes.h stdint.h unistd.h
+do :
+ as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
+ac_fn_c_check_header_compile "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default
+"
+if eval test \"x\$"$as_ac_Header"\" = x"yes"; then :
+ cat >>confdefs.h <<_ACEOF
+#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1
+_ACEOF
+
+fi
+
+done
+
+
+if test "x$with_parted" != xno; then :
+
+ ac_fn_c_check_header_mongrel "$LINENO" "parted/parted.h" "ac_cv_header_parted_parted_h" "$ac_includes_default"
+if test "x$ac_cv_header_parted_parted_h" = x""yes; then :
+ $as_echo "#define HAVE_PARTED_PARTED_H 1" >>confdefs.h
+
+else
+
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "Please install required libraries or use --without-parted.
+See \`config.log' for more details" "$LINENO" 5; }
+
+fi
+
+
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ped_device_read in -lparted" >&5
+$as_echo_n "checking for ped_device_read in -lparted... " >&6; }
+if test "${ac_cv_lib_parted_ped_device_read+set}" = set; then :
+ $as_echo_n "(cached) " >&6
+else
+ ac_check_lib_save_LIBS=$LIBS
+LIBS="-lparted $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+/* Override any GCC internal prototype to avoid an error.
+ Use char because int might match the return type of a GCC
+ builtin and then its argument prototype would still apply. */
+#ifdef __cplusplus
+extern "C"
+#endif
+char ped_device_read ();
+int
+main ()
+{
+return ped_device_read ();
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+ ac_cv_lib_parted_ped_device_read=yes
+else
+ ac_cv_lib_parted_ped_device_read=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_parted_ped_device_read" >&5
+$as_echo "$ac_cv_lib_parted_ped_device_read" >&6; }
+if test "x$ac_cv_lib_parted_ped_device_read" = x""yes; then :
+ cat >>confdefs.h <<_ACEOF
+#define HAVE_LIBPARTED 1
+_ACEOF
+
+ LIBS="-lparted $LIBS"
+
+else
+
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "Please install required libraries or use --without-parted.
+See \`config.log' for more details" "$LINENO" 5; }
+
+fi
+
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for uuid_generate in -luuid" >&5
+$as_echo_n "checking for uuid_generate in -luuid... " >&6; }
+if test "${ac_cv_lib_uuid_uuid_generate+set}" = set; then :
+ $as_echo_n "(cached) " >&6
+else
+ ac_check_lib_save_LIBS=$LIBS
+LIBS="-luuid $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+/* Override any GCC internal prototype to avoid an error.
+ Use char because int might match the return type of a GCC
+ builtin and then its argument prototype would still apply. */
+#ifdef __cplusplus
+extern "C"
+#endif
+char uuid_generate ();
+int
+main ()
+{
+return uuid_generate ();
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+ ac_cv_lib_uuid_uuid_generate=yes
+else
+ ac_cv_lib_uuid_uuid_generate=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_uuid_uuid_generate" >&5
+$as_echo "$ac_cv_lib_uuid_uuid_generate" >&6; }
+if test "x$ac_cv_lib_uuid_uuid_generate" = x""yes; then :
+ cat >>confdefs.h <<_ACEOF
+#define HAVE_LIBUUID 1
+_ACEOF
+
+ LIBS="-luuid $LIBS"
+
+else
+
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "Please install required libraries or use --without-parted.
+See \`config.log' for more details" "$LINENO" 5; }
+
+fi
+
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dlopen in -ldl" >&5
+$as_echo_n "checking for dlopen in -ldl... " >&6; }
+if test "${ac_cv_lib_dl_dlopen+set}" = set; then :
+ $as_echo_n "(cached) " >&6
+else
+ ac_check_lib_save_LIBS=$LIBS
+LIBS="-ldl $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+/* Override any GCC internal prototype to avoid an error.
+ Use char because int might match the return type of a GCC
+ builtin and then its argument prototype would still apply. */
+#ifdef __cplusplus
+extern "C"
+#endif
+char dlopen ();
+int
+main ()
+{
+return dlopen ();
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+ ac_cv_lib_dl_dlopen=yes
+else
+ ac_cv_lib_dl_dlopen=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dl_dlopen" >&5
+$as_echo "$ac_cv_lib_dl_dlopen" >&6; }
+if test "x$ac_cv_lib_dl_dlopen" = x""yes; then :
+ cat >>confdefs.h <<_ACEOF
+#define HAVE_LIBDL 1
+_ACEOF
+
+ LIBS="-ldl $LIBS"
+
+else
+
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "Please install required libraries or use --without-parted.
+See \`config.log' for more details" "$LINENO" 5; }
+
+fi
+
+ PARTED_LIBS="-lparted -luuid -ldl"
+
+fi
+
+
+# Check whether --enable-boot-store-types was given.
+if test "${enable_boot_store_types+set}" = set; then :
+ enableval=$enable_boot_store_types;
+fi
+if test -z "$enable_boot_store_types"; then
+ boot_store_types='device remap gunzip bunzip2'
+ test -z "$PARTED_LIBS" || boot_store_types="$boot_store_types part"
+elif test "x$enable_boot_store_types" = xno; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: you probably wanted --disable-static-progs" >&5
+$as_echo "$as_me: WARNING: you probably wanted --disable-static-progs" >&2;}
+else
+ boot_store_types="$enable_boot_store_types"
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking boot store types" >&5
+$as_echo_n "checking boot store types... " >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $boot_store_types" >&5
+$as_echo "$boot_store_types" >&6; }
+
+# Check for ncursesw, which is needed for the console-curses client.
+
+ # Check whether --enable-ncursesw was given.
+if test "${enable_ncursesw+set}" = set; then :
+ enableval=$enable_ncursesw;
+else
+ enable_ncursesw=yes
+fi
+
+ if test "$enable_ncursesw" = yes; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for initscr in -lncursesw" >&5
+$as_echo_n "checking for initscr in -lncursesw... " >&6; }
+if test "${ac_cv_lib_ncursesw_initscr+set}" = set; then :
+ $as_echo_n "(cached) " >&6
+else
+ ac_check_lib_save_LIBS=$LIBS
+LIBS="-lncursesw $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+/* Override any GCC internal prototype to avoid an error.
+ Use char because int might match the return type of a GCC
+ builtin and then its argument prototype would still apply. */
+#ifdef __cplusplus
+extern "C"
+#endif
+char initscr ();
+int
+main ()
+{
+return initscr ();
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+ ac_cv_lib_ncursesw_initscr=yes
+else
+ ac_cv_lib_ncursesw_initscr=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_ncursesw_initscr" >&5
+$as_echo "$ac_cv_lib_ncursesw_initscr" >&6; }
+if test "x$ac_cv_lib_ncursesw_initscr" = x""yes; then :
+ LIBNCURSESW="-lncursesw"
+fi
+
+ if test "$LIBNCURSESW"; then
+
+# Check whether --with-ncursesw-include-dir was given.
+if test "${with_ncursesw_include_dir+set}" = set; then :
+ withval=$with_ncursesw_include_dir;
+fi
+ if test "${with_ncursesw_include_dir+set}" = set; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ncursesw include dir" >&5
+$as_echo_n "checking for ncursesw include dir... " >&6; }
+ case "$with_ncursesw_include_dir" in
+ no|none)
+ hurd_cv_includedir_ncursesw=none;;
+ *)
+ hurd_cv_includedir_ncursesw="$with_ncursesw_include_dir";;
+ esac
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $hurd_cv_includedir_ncursesw" >&5
+$as_echo "$hurd_cv_includedir_ncursesw" >&6; }
+ else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ncursesw include dir" >&5
+$as_echo_n "checking for ncursesw include dir... " >&6; }
+if test "${hurd_cv_includedir_ncursesw+set}" = set; then :
+ $as_echo_n "(cached) " >&6
+else
+ for D in $includedir $prefix/include /local/include /usr/local/include /include /usr/include; do
+ if test -d $D/ncursesw; then
+ hurd_cv_includedir_ncursesw="$D/ncursesw"
+ break
+ fi
+ test "$hurd_cv_includedir_ncursesw" \
+ || hurd_cv_includedir_ncursesw=none
+ done
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $hurd_cv_includedir_ncursesw" >&5
+$as_echo "$hurd_cv_includedir_ncursesw" >&6; }
+ fi
+ if test "$hurd_cv_includedir_ncursesw" = none; then
+ NCURSESW_INCLUDE=""
+ else
+ NCURSESW_INCLUDE="-I$hurd_cv_includedir_ncursesw"
+ fi
+ fi
+ fi
+
+
+
+# Check for Sun RPC headers and library.
+ac_fn_c_check_header_mongrel "$LINENO" "rpc/types.h" "ac_cv_header_rpc_types_h" "$ac_includes_default"
+if test "x$ac_cv_header_rpc_types_h" = x""yes; then :
+ HAVE_SUN_RPC=yes
+else
+ HAVE_SUN_RPC=no
+fi
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing clnt_create" >&5
+$as_echo_n "checking for library containing clnt_create... " >&6; }
+if test "${ac_cv_search_clnt_create+set}" = set; then :
+ $as_echo_n "(cached) " >&6
+else
+ ac_func_search_save_LIBS=$LIBS
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+/* Override any GCC internal prototype to avoid an error.
+ Use char because int might match the return type of a GCC
+ builtin and then its argument prototype would still apply. */
+#ifdef __cplusplus
+extern "C"
+#endif
+char clnt_create ();
+int
+main ()
+{
+return clnt_create ();
+ ;
+ return 0;
+}
+_ACEOF
+for ac_lib in '' ; do
+ if test -z "$ac_lib"; then
+ ac_res="none required"
+ else
+ ac_res=-l$ac_lib
+ LIBS="-l$ac_lib $ac_func_search_save_LIBS"
+ fi
+ if ac_fn_c_try_link "$LINENO"; then :
+ ac_cv_search_clnt_create=$ac_res
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext
+ if test "${ac_cv_search_clnt_create+set}" = set; then :
+ break
+fi
+done
+if test "${ac_cv_search_clnt_create+set}" = set; then :
+
+else
+ ac_cv_search_clnt_create=no
+fi
+rm conftest.$ac_ext
+LIBS=$ac_func_search_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_clnt_create" >&5
+$as_echo "$ac_cv_search_clnt_create" >&6; }
+ac_res=$ac_cv_search_clnt_create
+if test "$ac_res" != no; then :
+ test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
+ :
+else
+ HAVE_SUN_RPC=no
+fi
+
+
+
+if test -f ./$ac_unique_file; then
+ # Configuring in source directory; don't create any Makefiles.
+ makefiles=
+else
+ # We are configuring in a separate build tree.
+ # Create a Makefile in the top-level build directory and
+ # one for each subdirectory Makefile in the source.
+ makefiles="Makeconf:build.mkcf.in \
+ `cd $srcdir; for file in Makefile */Makefile; do \
+ echo ${file}:build.mk.in; done`"
+fi
+
+ac_config_files="$ac_config_files config.make ${makefiles}"
+
+cat >confcache <<\_ACEOF
+# This file is a shell script that caches the results of configure
+# tests run on this system so they can be shared between configure
+# scripts and configure runs, see configure's option --config-cache.
+# It is not useful on other systems. If it contains results you don't
+# want to keep, you may remove or edit it.
+#
+# config.status only pays attention to the cache file if you give it
+# the --recheck option to rerun configure.
+#
+# `ac_cv_env_foo' variables (set or unset) will be overridden when
+# loading this file, other *unset* `ac_cv_foo' will be assigned the
+# following values.
+
+_ACEOF
+
+# The following way of writing the cache mishandles newlines in values,
+# but we know of no workaround that is simple, portable, and efficient.
+# So, we kill variables containing newlines.
+# Ultrix sh set writes to stderr and can't be redirected directly,
+# and sets the high bit in the cache file unless we assign to the vars.
+(
+ for ac_var in `(set) 2>&1 | sed -n 's/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'`; do
+ eval ac_val=\$$ac_var
+ case $ac_val in #(
+ *${as_nl}*)
+ case $ac_var in #(
+ *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5
+$as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;;
+ esac
+ case $ac_var in #(
+ _ | IFS | as_nl) ;; #(
+ BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #(
+ *) { eval $ac_var=; unset $ac_var;} ;;
+ esac ;;
+ esac
+ done
+
+ (set) 2>&1 |
+ case $as_nl`(ac_space=' '; set) 2>&1` in #(
+ *${as_nl}ac_space=\ *)
+ # `set' does not quote correctly, so add quotes: double-quote
+ # substitution turns \\\\ into \\, and sed turns \\ into \.
+ sed -n \
+ "s/'/'\\\\''/g;
+ s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\\2'/p"
+ ;; #(
+ *)
+ # `set' quotes correctly as required by POSIX, so do not add quotes.
+ sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p"
+ ;;
+ esac |
+ sort
+) |
+ sed '
+ /^ac_cv_env_/b end
+ t clear
+ :clear
+ s/^\([^=]*\)=\(.*[{}].*\)$/test "${\1+set}" = set || &/
+ t end
+ s/^\([^=]*\)=\(.*\)$/\1=${\1=\2}/
+ :end' >>confcache
+if diff "$cache_file" confcache >/dev/null 2>&1; then :; else
+ if test -w "$cache_file"; then
+ test "x$cache_file" != "x/dev/null" &&
+ { $as_echo "$as_me:${as_lineno-$LINENO}: updating cache $cache_file" >&5
+$as_echo "$as_me: updating cache $cache_file" >&6;}
+ cat confcache >$cache_file
+ else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: not updating unwritable cache $cache_file" >&5
+$as_echo "$as_me: not updating unwritable cache $cache_file" >&6;}
+ fi
+fi
+rm -f confcache
+
+test "x$prefix" = xNONE && prefix=$ac_default_prefix
+# Let make expand exec_prefix.
+test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
+
+# Transform confdefs.h into DEFS.
+# Protect against shell expansion while executing Makefile rules.
+# Protect against Makefile macro expansion.
+#
+# If the first sed substitution is executed (which looks for macros that
+# take arguments), then branch to the quote section. Otherwise,
+# look for a macro that doesn't take arguments.
+ac_script='
+:mline
+/\\$/{
+ N
+ s,\\\n,,
+ b mline
+}
+t clear
+:clear
+s/^[ ]*#[ ]*define[ ][ ]*\([^ (][^ (]*([^)]*)\)[ ]*\(.*\)/-D\1=\2/g
+t quote
+s/^[ ]*#[ ]*define[ ][ ]*\([^ ][^ ]*\)[ ]*\(.*\)/-D\1=\2/g
+t quote
+b any
+:quote
+s/[ `~#$^&*(){}\\|;'\''"<>?]/\\&/g
+s/\[/\\&/g
+s/\]/\\&/g
+s/\$/$$/g
+H
+:any
+${
+ g
+ s/^\n//
+ s/\n/ /g
+ p
+}
+'
+DEFS=`sed -n "$ac_script" confdefs.h`
+
+
+ac_libobjs=
+ac_ltlibobjs=
+U=
+for ac_i in : $LIBOBJS; do test "x$ac_i" = x: && continue
+ # 1. Remove the extension, and $U if already installed.
+ ac_script='s/\$U\././;s/\.o$//;s/\.obj$//'
+ ac_i=`$as_echo "$ac_i" | sed "$ac_script"`
+ # 2. Prepend LIBOBJDIR. When used with automake>=1.10 LIBOBJDIR
+ # will be set to the directory where LIBOBJS objects are built.
+ as_fn_append ac_libobjs " \${LIBOBJDIR}$ac_i\$U.$ac_objext"
+ as_fn_append ac_ltlibobjs " \${LIBOBJDIR}$ac_i"'$U.lo'
+done
+LIBOBJS=$ac_libobjs
+
+LTLIBOBJS=$ac_ltlibobjs
+
+
+
+: ${CONFIG_STATUS=./config.status}
+ac_write_fail=0
+ac_clean_files_save=$ac_clean_files
+ac_clean_files="$ac_clean_files $CONFIG_STATUS"
+{ $as_echo "$as_me:${as_lineno-$LINENO}: creating $CONFIG_STATUS" >&5
+$as_echo "$as_me: creating $CONFIG_STATUS" >&6;}
+as_write_fail=0
+cat >$CONFIG_STATUS <<_ASEOF || as_write_fail=1
+#! $SHELL
+# Generated by $as_me.
+# Run this file to recreate the current configuration.
+# Compiler output produced by configure, useful for debugging
+# configure, is in config.log if it exists.
+
+debug=false
+ac_cs_recheck=false
+ac_cs_silent=false
+
+SHELL=\${CONFIG_SHELL-$SHELL}
+export SHELL
+_ASEOF
+cat >>$CONFIG_STATUS <<\_ASEOF || as_write_fail=1
+## -------------------- ##
+## M4sh Initialization. ##
+## -------------------- ##
+
+# Be more Bourne compatible
+DUALCASE=1; export DUALCASE # for MKS sh
+if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
+ emulate sh
+ NULLCMD=:
+ # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
+ # is contrary to our usage. Disable this feature.
+ alias -g '${1+"$@"}'='"$@"'
+ setopt NO_GLOB_SUBST
+else
+ case `(set -o) 2>/dev/null` in #(
+ *posix*) :
+ set -o posix ;; #(
+ *) :
+ ;;
+esac
+fi
+
+
+as_nl='
+'
+export as_nl
+# Printing a long string crashes Solaris 7 /usr/bin/printf.
+as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'
+as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo
+as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo
+# Prefer a ksh shell builtin over an external printf program on Solaris,
+# but without wasting forks for bash or zsh.
+if test -z "$BASH_VERSION$ZSH_VERSION" \
+ && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then
+ as_echo='print -r --'
+ as_echo_n='print -rn --'
+elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then
+ as_echo='printf %s\n'
+ as_echo_n='printf %s'
+else
+ if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then
+ as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"'
+ as_echo_n='/usr/ucb/echo -n'
+ else
+ as_echo_body='eval expr "X$1" : "X\\(.*\\)"'
+ as_echo_n_body='eval
+ arg=$1;
+ case $arg in #(
+ *"$as_nl"*)
+ expr "X$arg" : "X\\(.*\\)$as_nl";
+ arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;;
+ esac;
+ expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl"
+ '
+ export as_echo_n_body
+ as_echo_n='sh -c $as_echo_n_body as_echo'
+ fi
+ export as_echo_body
+ as_echo='sh -c $as_echo_body as_echo'
+fi
+
+# The user is always right.
+if test "${PATH_SEPARATOR+set}" != set; then
+ PATH_SEPARATOR=:
+ (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {
+ (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||
+ PATH_SEPARATOR=';'
+ }
+fi
+
+
+# IFS
+# We need space, tab and new line, in precisely that order. Quoting is
+# there to prevent editors from complaining about space-tab.
+# (If _AS_PATH_WALK were called with IFS unset, it would disable word
+# splitting by setting IFS to empty value.)
+IFS=" "" $as_nl"
+
+# Find who we are. Look in the path if we contain no directory separator.
+case $0 in #((
+ *[\\/]* ) as_myself=$0 ;;
+ *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break
+ done
+IFS=$as_save_IFS
+
+ ;;
+esac
+# We did not find ourselves, most probably we were run as `sh COMMAND'
+# in which case we are not to be found in the path.
+if test "x$as_myself" = x; then
+ as_myself=$0
+fi
+if test ! -f "$as_myself"; then
+ $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2
+ exit 1
+fi
+
+# Unset variables that we do not need and which cause bugs (e.g. in
+# pre-3.0 UWIN ksh). But do not cause bugs in bash 2.01; the "|| exit 1"
+# suppresses any "Segmentation fault" message there. '((' could
+# trigger a bug in pdksh 5.2.14.
+for as_var in BASH_ENV ENV MAIL MAILPATH
+do eval test x\${$as_var+set} = xset \
+ && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || :
+done
+PS1='$ '
+PS2='> '
+PS4='+ '
+
+# NLS nuisances.
+LC_ALL=C
+export LC_ALL
+LANGUAGE=C
+export LANGUAGE
+
+# CDPATH.
+(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
+
+
+# as_fn_error STATUS ERROR [LINENO LOG_FD]
+# ----------------------------------------
+# Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are
+# provided, also output the error to LOG_FD, referencing LINENO. Then exit the
+# script with STATUS, using 1 if that was 0.
+as_fn_error ()
+{
+ as_status=$1; test $as_status -eq 0 && as_status=1
+ if test "$4"; then
+ as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+ $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4
+ fi
+ $as_echo "$as_me: error: $2" >&2
+ as_fn_exit $as_status
+} # as_fn_error
+
+
+# as_fn_set_status STATUS
+# -----------------------
+# Set $? to STATUS, without forking.
+as_fn_set_status ()
+{
+ return $1
+} # as_fn_set_status
+
+# as_fn_exit STATUS
+# -----------------
+# Exit the shell with STATUS, even in a "trap 0" or "set -e" context.
+as_fn_exit ()
+{
+ set +e
+ as_fn_set_status $1
+ exit $1
+} # as_fn_exit
+
+# as_fn_unset VAR
+# ---------------
+# Portably unset VAR.
+as_fn_unset ()
+{
+ { eval $1=; unset $1;}
+}
+as_unset=as_fn_unset
+# as_fn_append VAR VALUE
+# ----------------------
+# Append the text in VALUE to the end of the definition contained in VAR. Take
+# advantage of any shell optimizations that allow amortized linear growth over
+# repeated appends, instead of the typical quadratic growth present in naive
+# implementations.
+if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then :
+ eval 'as_fn_append ()
+ {
+ eval $1+=\$2
+ }'
+else
+ as_fn_append ()
+ {
+ eval $1=\$$1\$2
+ }
+fi # as_fn_append
+
+# as_fn_arith ARG...
+# ------------------
+# Perform arithmetic evaluation on the ARGs, and store the result in the
+# global $as_val. Take advantage of shells that can avoid forks. The arguments
+# must be portable across $(()) and expr.
+if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then :
+ eval 'as_fn_arith ()
+ {
+ as_val=$(( $* ))
+ }'
+else
+ as_fn_arith ()
+ {
+ as_val=`expr "$@" || test $? -eq 1`
+ }
+fi # as_fn_arith
+
+
+if expr a : '\(a\)' >/dev/null 2>&1 &&
+ test "X`expr 00001 : '.*\(...\)'`" = X001; then
+ as_expr=expr
+else
+ as_expr=false
+fi
+
+if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then
+ as_basename=basename
+else
+ as_basename=false
+fi
+
+if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then
+ as_dirname=dirname
+else
+ as_dirname=false
+fi
+
+as_me=`$as_basename -- "$0" ||
+$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \
+ X"$0" : 'X\(//\)$' \| \
+ X"$0" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X/"$0" |
+ sed '/^.*\/\([^/][^/]*\)\/*$/{
+ s//\1/
+ q
+ }
+ /^X\/\(\/\/\)$/{
+ s//\1/
+ q
+ }
+ /^X\/\(\/\).*/{
+ s//\1/
+ q
+ }
+ s/.*/./; q'`
+
+# Avoid depending upon Character Ranges.
+as_cr_letters='abcdefghijklmnopqrstuvwxyz'
+as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
+as_cr_Letters=$as_cr_letters$as_cr_LETTERS
+as_cr_digits='0123456789'
+as_cr_alnum=$as_cr_Letters$as_cr_digits
+
+ECHO_C= ECHO_N= ECHO_T=
+case `echo -n x` in #(((((
+-n*)
+ case `echo 'xy\c'` in
+ *c*) ECHO_T=' ';; # ECHO_T is single tab character.
+ xy) ECHO_C='\c';;
+ *) echo `echo ksh88 bug on AIX 6.1` > /dev/null
+ ECHO_T=' ';;
+ esac;;
+*)
+ ECHO_N='-n';;
+esac
+
+rm -f conf$$ conf$$.exe conf$$.file
+if test -d conf$$.dir; then
+ rm -f conf$$.dir/conf$$.file
+else
+ rm -f conf$$.dir
+ mkdir conf$$.dir 2>/dev/null
+fi
+if (echo >conf$$.file) 2>/dev/null; then
+ if ln -s conf$$.file conf$$ 2>/dev/null; then
+ as_ln_s='ln -s'
+ # ... but there are two gotchas:
+ # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail.
+ # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable.
+ # In both cases, we have to default to `cp -p'.
+ ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe ||
+ as_ln_s='cp -p'
+ elif ln conf$$.file conf$$ 2>/dev/null; then
+ as_ln_s=ln
+ else
+ as_ln_s='cp -p'
+ fi
+else
+ as_ln_s='cp -p'
+fi
+rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file
+rmdir conf$$.dir 2>/dev/null
+
+
+# as_fn_mkdir_p
+# -------------
+# Create "$as_dir" as a directory, including parents if necessary.
+as_fn_mkdir_p ()
+{
+
+ case $as_dir in #(
+ -*) as_dir=./$as_dir;;
+ esac
+ test -d "$as_dir" || eval $as_mkdir_p || {
+ as_dirs=
+ while :; do
+ case $as_dir in #(
+ *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'(
+ *) as_qdir=$as_dir;;
+ esac
+ as_dirs="'$as_qdir' $as_dirs"
+ as_dir=`$as_dirname -- "$as_dir" ||
+$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+ X"$as_dir" : 'X\(//\)[^/]' \| \
+ X"$as_dir" : 'X\(//\)$' \| \
+ X"$as_dir" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X"$as_dir" |
+ sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+ s//\1/
+ q
+ }
+ /^X\(\/\/\)[^/].*/{
+ s//\1/
+ q
+ }
+ /^X\(\/\/\)$/{
+ s//\1/
+ q
+ }
+ /^X\(\/\).*/{
+ s//\1/
+ q
+ }
+ s/.*/./; q'`
+ test -d "$as_dir" && break
+ done
+ test -z "$as_dirs" || eval "mkdir $as_dirs"
+ } || test -d "$as_dir" || as_fn_error $? "cannot create directory $as_dir"
+
+
+} # as_fn_mkdir_p
+if mkdir -p . 2>/dev/null; then
+ as_mkdir_p='mkdir -p "$as_dir"'
+else
+ test -d ./-p && rmdir ./-p
+ as_mkdir_p=false
+fi
+
+if test -x / >/dev/null 2>&1; then
+ as_test_x='test -x'
+else
+ if ls -dL / >/dev/null 2>&1; then
+ as_ls_L_option=L
+ else
+ as_ls_L_option=
+ fi
+ as_test_x='
+ eval sh -c '\''
+ if test -d "$1"; then
+ test -d "$1/.";
+ else
+ case $1 in #(
+ -*)set "./$1";;
+ esac;
+ case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in #((
+ ???[sx]*):;;*)false;;esac;fi
+ '\'' sh
+ '
+fi
+as_executable_p=$as_test_x
+
+# Sed expression to map a string onto a valid CPP name.
+as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'"
+
+# Sed expression to map a string onto a valid variable name.
+as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'"
+
+
+exec 6>&1
+## ----------------------------------- ##
+## Main body of $CONFIG_STATUS script. ##
+## ----------------------------------- ##
+_ASEOF
+test $as_write_fail = 0 && chmod +x $CONFIG_STATUS || ac_write_fail=1
+
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+# Save the log message, to keep $0 and so on meaningful, and to
+# report actual input values of CONFIG_FILES etc. instead of their
+# values after options handling.
+ac_log="
+This file was extended by GNU Hurd $as_me 0.3, which was
+generated by GNU Autoconf 2.67. Invocation command line was
+
+ CONFIG_FILES = $CONFIG_FILES
+ CONFIG_HEADERS = $CONFIG_HEADERS
+ CONFIG_LINKS = $CONFIG_LINKS
+ CONFIG_COMMANDS = $CONFIG_COMMANDS
+ $ $0 $@
+
+on `(hostname || uname -n) 2>/dev/null | sed 1q`
+"
+
+_ACEOF
+
+case $ac_config_files in *"
+"*) set x $ac_config_files; shift; ac_config_files=$*;;
+esac
+
+
+
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+# Files that config.status was made for.
+config_files="$ac_config_files"
+
+_ACEOF
+
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+ac_cs_usage="\
+\`$as_me' instantiates files and other configuration actions
+from templates according to the current configuration. Unless the files
+and actions are specified as TAGs, all are instantiated by default.
+
+Usage: $0 [OPTION]... [TAG]...
+
+ -h, --help print this help, then exit
+ -V, --version print version number and configuration settings, then exit
+ --config print configuration, then exit
+ -q, --quiet, --silent
+ do not print progress messages
+ -d, --debug don't remove temporary files
+ --recheck update $as_me by reconfiguring in the same conditions
+ --file=FILE[:TEMPLATE]
+ instantiate the configuration file FILE
+
+Configuration files:
+$config_files
+
+Report bugs to <bug-hurd@gnu.org>.
+GNU Hurd home page: <http://www.gnu.org/software/hurd/>.
+General help using GNU software: <http://www.gnu.org/gethelp/>."
+
+_ACEOF
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
+ac_cs_version="\\
+GNU Hurd config.status 0.3
+configured by $0, generated by GNU Autoconf 2.67,
+ with options \\"\$ac_cs_config\\"
+
+Copyright (C) 2010 Free Software Foundation, Inc.
+This config.status script is free software; the Free Software Foundation
+gives unlimited permission to copy, distribute and modify it."
+
+ac_pwd='$ac_pwd'
+srcdir='$srcdir'
+INSTALL='$INSTALL'
+AWK='$AWK'
+test -n "\$AWK" || AWK=awk
+_ACEOF
+
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+# The default lists apply if the user does not specify any file.
+ac_need_defaults=:
+while test $# != 0
+do
+ case $1 in
+ --*=?*)
+ ac_option=`expr "X$1" : 'X\([^=]*\)='`
+ ac_optarg=`expr "X$1" : 'X[^=]*=\(.*\)'`
+ ac_shift=:
+ ;;
+ --*=)
+ ac_option=`expr "X$1" : 'X\([^=]*\)='`
+ ac_optarg=
+ ac_shift=:
+ ;;
+ *)
+ ac_option=$1
+ ac_optarg=$2
+ ac_shift=shift
+ ;;
+ esac
+
+ case $ac_option in
+ # Handling of the options.
+ -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r)
+ ac_cs_recheck=: ;;
+ --version | --versio | --versi | --vers | --ver | --ve | --v | -V )
+ $as_echo "$ac_cs_version"; exit ;;
+ --config | --confi | --conf | --con | --co | --c )
+ $as_echo "$ac_cs_config"; exit ;;
+ --debug | --debu | --deb | --de | --d | -d )
+ debug=: ;;
+ --file | --fil | --fi | --f )
+ $ac_shift
+ case $ac_optarg in
+ *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;;
+ '') as_fn_error $? "missing file argument" ;;
+ esac
+ as_fn_append CONFIG_FILES " '$ac_optarg'"
+ ac_need_defaults=false;;
+ --he | --h | --help | --hel | -h )
+ $as_echo "$ac_cs_usage"; exit ;;
+ -q | -quiet | --quiet | --quie | --qui | --qu | --q \
+ | -silent | --silent | --silen | --sile | --sil | --si | --s)
+ ac_cs_silent=: ;;
+
+ # This is an error.
+ -*) as_fn_error $? "unrecognized option: \`$1'
+Try \`$0 --help' for more information." ;;
+
+ *) as_fn_append ac_config_targets " $1"
+ ac_need_defaults=false ;;
+
+ esac
+ shift
+done
+
+ac_configure_extra_args=
+
+if $ac_cs_silent; then
+ exec 6>/dev/null
+ ac_configure_extra_args="$ac_configure_extra_args --silent"
+fi
+
+_ACEOF
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+if \$ac_cs_recheck; then
+ set X '$SHELL' '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion
+ shift
+ \$as_echo "running CONFIG_SHELL=$SHELL \$*" >&6
+ CONFIG_SHELL='$SHELL'
+ export CONFIG_SHELL
+ exec "\$@"
+fi
+
+_ACEOF
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+exec 5>>config.log
+{
+ echo
+ sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX
+## Running $as_me. ##
+_ASBOX
+ $as_echo "$ac_log"
+} >&5
+
+_ACEOF
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+_ACEOF
+
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+
+# Handling of arguments.
+for ac_config_target in $ac_config_targets
+do
+ case $ac_config_target in
+ "config.make") CONFIG_FILES="$CONFIG_FILES config.make" ;;
+ "${makefiles}") CONFIG_FILES="$CONFIG_FILES ${makefiles}" ;;
+
+ *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;;
+ esac
+done
+
+
+# If the user did not use the arguments to specify the items to instantiate,
+# then the envvar interface is used. Set only those that are not.
+# We use the long form for the default assignment because of an extremely
+# bizarre bug on SunOS 4.1.3.
+if $ac_need_defaults; then
+ test "${CONFIG_FILES+set}" = set || CONFIG_FILES=$config_files
+fi
+
+# Have a temporary directory for convenience. Make it in the build tree
+# simply because there is no reason against having it here, and in addition,
+# creating and moving files from /tmp can sometimes cause problems.
+# Hook for its removal unless debugging.
+# Note that there is a small window in which the directory will not be cleaned:
+# after its creation but before its name has been assigned to `$tmp'.
+$debug ||
+{
+ tmp=
+ trap 'exit_status=$?
+ { test -z "$tmp" || test ! -d "$tmp" || rm -fr "$tmp"; } && exit $exit_status
+' 0
+ trap 'as_fn_exit 1' 1 2 13 15
+}
+# Create a (secure) tmp directory for tmp files.
+
+{
+ tmp=`(umask 077 && mktemp -d "./confXXXXXX") 2>/dev/null` &&
+ test -n "$tmp" && test -d "$tmp"
+} ||
+{
+ tmp=./conf$$-$RANDOM
+ (umask 077 && mkdir "$tmp")
+} || as_fn_error $? "cannot create a temporary directory in ." "$LINENO" 5
+
+# Set up the scripts for CONFIG_FILES section.
+# No need to generate them if there are no CONFIG_FILES.
+# This happens for instance with `./config.status config.h'.
+if test -n "$CONFIG_FILES"; then
+
+
+ac_cr=`echo X | tr X '\015'`
+# On cygwin, bash can eat \r inside `` if the user requested igncr.
+# But we know of no other shell where ac_cr would be empty at this
+# point, so we can use a bashism as a fallback.
+if test "x$ac_cr" = x; then
+ eval ac_cr=\$\'\\r\'
+fi
+ac_cs_awk_cr=`$AWK 'BEGIN { print "a\rb" }' </dev/null 2>/dev/null`
+if test "$ac_cs_awk_cr" = "a${ac_cr}b"; then
+ ac_cs_awk_cr='\\r'
+else
+ ac_cs_awk_cr=$ac_cr
+fi
+
+echo 'BEGIN {' >"$tmp/subs1.awk" &&
+_ACEOF
+
+
+{
+ echo "cat >conf$$subs.awk <<_ACEOF" &&
+ echo "$ac_subst_vars" | sed 's/.*/&!$&$ac_delim/' &&
+ echo "_ACEOF"
+} >conf$$subs.sh ||
+ as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5
+ac_delim_num=`echo "$ac_subst_vars" | grep -c '^'`
+ac_delim='%!_!# '
+for ac_last_try in false false false false false :; do
+ . ./conf$$subs.sh ||
+ as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5
+
+ ac_delim_n=`sed -n "s/.*$ac_delim\$/X/p" conf$$subs.awk | grep -c X`
+ if test $ac_delim_n = $ac_delim_num; then
+ break
+ elif $ac_last_try; then
+ as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5
+ else
+ ac_delim="$ac_delim!$ac_delim _$ac_delim!! "
+ fi
+done
+rm -f conf$$subs.sh
+
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+cat >>"\$tmp/subs1.awk" <<\\_ACAWK &&
+_ACEOF
+sed -n '
+h
+s/^/S["/; s/!.*/"]=/
+p
+g
+s/^[^!]*!//
+:repl
+t repl
+s/'"$ac_delim"'$//
+t delim
+:nl
+h
+s/\(.\{148\}\)..*/\1/
+t more1
+s/["\\]/\\&/g; s/^/"/; s/$/\\n"\\/
+p
+n
+b repl
+:more1
+s/["\\]/\\&/g; s/^/"/; s/$/"\\/
+p
+g
+s/.\{148\}//
+t nl
+:delim
+h
+s/\(.\{148\}\)..*/\1/
+t more2
+s/["\\]/\\&/g; s/^/"/; s/$/"/
+p
+b
+:more2
+s/["\\]/\\&/g; s/^/"/; s/$/"\\/
+p
+g
+s/.\{148\}//
+t delim
+' <conf$$subs.awk | sed '
+/^[^""]/{
+ N
+ s/\n//
+}
+' >>$CONFIG_STATUS || ac_write_fail=1
+rm -f conf$$subs.awk
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+_ACAWK
+cat >>"\$tmp/subs1.awk" <<_ACAWK &&
+ for (key in S) S_is_set[key] = 1
+ FS = ""
+
+}
+{
+ line = $ 0
+ nfields = split(line, field, "@")
+ substed = 0
+ len = length(field[1])
+ for (i = 2; i < nfields; i++) {
+ key = field[i]
+ keylen = length(key)
+ if (S_is_set[key]) {
+ value = S[key]
+ line = substr(line, 1, len) "" value "" substr(line, len + keylen + 3)
+ len += length(value) + length(field[++i])
+ substed = 1
+ } else
+ len += 1 + keylen
+ }
+
+ print line
+}
+
+_ACAWK
+_ACEOF
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+if sed "s/$ac_cr//" < /dev/null > /dev/null 2>&1; then
+ sed "s/$ac_cr\$//; s/$ac_cr/$ac_cs_awk_cr/g"
+else
+ cat
+fi < "$tmp/subs1.awk" > "$tmp/subs.awk" \
+ || as_fn_error $? "could not setup config files machinery" "$LINENO" 5
+_ACEOF
+
+# VPATH may cause trouble with some makes, so we remove sole $(srcdir),
+# ${srcdir} and @srcdir@ entries from VPATH if srcdir is ".", strip leading and
+# trailing colons and then remove the whole line if VPATH becomes empty
+# (actually we leave an empty line to preserve line numbers).
+if test "x$srcdir" = x.; then
+ ac_vpsub='/^[ ]*VPATH[ ]*=[ ]*/{
+h
+s///
+s/^/:/
+s/[ ]*$/:/
+s/:\$(srcdir):/:/g
+s/:\${srcdir}:/:/g
+s/:@srcdir@:/:/g
+s/^:*//
+s/:*$//
+x
+s/\(=[ ]*\).*/\1/
+G
+s/\n//
+s/^[^=]*=[ ]*$//
+}'
+fi
+
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+fi # test -n "$CONFIG_FILES"
+
+
+eval set X " :F $CONFIG_FILES "
+shift
+for ac_tag
+do
+ case $ac_tag in
+ :[FHLC]) ac_mode=$ac_tag; continue;;
+ esac
+ case $ac_mode$ac_tag in
+ :[FHL]*:*);;
+ :L* | :C*:*) as_fn_error $? "invalid tag \`$ac_tag'" "$LINENO" 5;;
+ :[FH]-) ac_tag=-:-;;
+ :[FH]*) ac_tag=$ac_tag:$ac_tag.in;;
+ esac
+ ac_save_IFS=$IFS
+ IFS=:
+ set x $ac_tag
+ IFS=$ac_save_IFS
+ shift
+ ac_file=$1
+ shift
+
+ case $ac_mode in
+ :L) ac_source=$1;;
+ :[FH])
+ ac_file_inputs=
+ for ac_f
+ do
+ case $ac_f in
+ -) ac_f="$tmp/stdin";;
+ *) # Look for the file first in the build tree, then in the source tree
+ # (if the path is not absolute). The absolute path cannot be DOS-style,
+ # because $ac_f cannot contain `:'.
+ test -f "$ac_f" ||
+ case $ac_f in
+ [\\/$]*) false;;
+ *) test -f "$srcdir/$ac_f" && ac_f="$srcdir/$ac_f";;
+ esac ||
+ as_fn_error 1 "cannot find input file: \`$ac_f'" "$LINENO" 5;;
+ esac
+ case $ac_f in *\'*) ac_f=`$as_echo "$ac_f" | sed "s/'/'\\\\\\\\''/g"`;; esac
+ as_fn_append ac_file_inputs " '$ac_f'"
+ done
+
+ # Let's still pretend it is `configure' which instantiates (i.e., don't
+ # use $as_me), people would be surprised to read:
+ # /* config.h. Generated by config.status. */
+ configure_input='Generated from '`
+ $as_echo "$*" | sed 's|^[^:]*/||;s|:[^:]*/|, |g'
+ `' by configure.'
+ if test x"$ac_file" != x-; then
+ configure_input="$ac_file. $configure_input"
+ { $as_echo "$as_me:${as_lineno-$LINENO}: creating $ac_file" >&5
+$as_echo "$as_me: creating $ac_file" >&6;}
+ fi
+ # Neutralize special characters interpreted by sed in replacement strings.
+ case $configure_input in #(
+ *\&* | *\|* | *\\* )
+ ac_sed_conf_input=`$as_echo "$configure_input" |
+ sed 's/[\\\\&|]/\\\\&/g'`;; #(
+ *) ac_sed_conf_input=$configure_input;;
+ esac
+
+ case $ac_tag in
+ *:-:* | *:-) cat >"$tmp/stdin" \
+ || as_fn_error $? "could not create $ac_file" "$LINENO" 5 ;;
+ esac
+ ;;
+ esac
+
+ ac_dir=`$as_dirname -- "$ac_file" ||
+$as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+ X"$ac_file" : 'X\(//\)[^/]' \| \
+ X"$ac_file" : 'X\(//\)$' \| \
+ X"$ac_file" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X"$ac_file" |
+ sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+ s//\1/
+ q
+ }
+ /^X\(\/\/\)[^/].*/{
+ s//\1/
+ q
+ }
+ /^X\(\/\/\)$/{
+ s//\1/
+ q
+ }
+ /^X\(\/\).*/{
+ s//\1/
+ q
+ }
+ s/.*/./; q'`
+ as_dir="$ac_dir"; as_fn_mkdir_p
+ ac_builddir=.
+
+case "$ac_dir" in
+.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;;
+*)
+ ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'`
+ # A ".." for each directory in $ac_dir_suffix.
+ ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'`
+ case $ac_top_builddir_sub in
+ "") ac_top_builddir_sub=. ac_top_build_prefix= ;;
+ *) ac_top_build_prefix=$ac_top_builddir_sub/ ;;
+ esac ;;
+esac
+ac_abs_top_builddir=$ac_pwd
+ac_abs_builddir=$ac_pwd$ac_dir_suffix
+# for backward compatibility:
+ac_top_builddir=$ac_top_build_prefix
+
+case $srcdir in
+ .) # We are building in place.
+ ac_srcdir=.
+ ac_top_srcdir=$ac_top_builddir_sub
+ ac_abs_top_srcdir=$ac_pwd ;;
+ [\\/]* | ?:[\\/]* ) # Absolute name.
+ ac_srcdir=$srcdir$ac_dir_suffix;
+ ac_top_srcdir=$srcdir
+ ac_abs_top_srcdir=$srcdir ;;
+ *) # Relative name.
+ ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix
+ ac_top_srcdir=$ac_top_build_prefix$srcdir
+ ac_abs_top_srcdir=$ac_pwd/$srcdir ;;
+esac
+ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix
+
+
+ case $ac_mode in
+ :F)
+ #
+ # CONFIG_FILE
+ #
+
+ case $INSTALL in
+ [\\/$]* | ?:[\\/]* ) ac_INSTALL=$INSTALL ;;
+ *) ac_INSTALL=$ac_top_build_prefix$INSTALL ;;
+ esac
+_ACEOF
+
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+# If the template does not know about datarootdir, expand it.
+# FIXME: This hack should be removed a few years after 2.60.
+ac_datarootdir_hack=; ac_datarootdir_seen=
+ac_sed_dataroot='
+/datarootdir/ {
+ p
+ q
+}
+/@datadir@/p
+/@docdir@/p
+/@infodir@/p
+/@localedir@/p
+/@mandir@/p'
+case `eval "sed -n \"\$ac_sed_dataroot\" $ac_file_inputs"` in
+*datarootdir*) ac_datarootdir_seen=yes;;
+*@datadir@*|*@docdir@*|*@infodir@*|*@localedir@*|*@mandir@*)
+ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&5
+$as_echo "$as_me: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&2;}
+_ACEOF
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+ ac_datarootdir_hack='
+ s&@datadir@&$datadir&g
+ s&@docdir@&$docdir&g
+ s&@infodir@&$infodir&g
+ s&@localedir@&$localedir&g
+ s&@mandir@&$mandir&g
+ s&\\\${datarootdir}&$datarootdir&g' ;;
+esac
+_ACEOF
+
+# Neutralize VPATH when `$srcdir' = `.'.
+# Shell code in configure.ac might set extrasub.
+# FIXME: do we really want to maintain this feature?
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+ac_sed_extra="$ac_vpsub
+$extrasub
+_ACEOF
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+:t
+/@[a-zA-Z_][a-zA-Z_0-9]*@/!b
+s|@configure_input@|$ac_sed_conf_input|;t t
+s&@top_builddir@&$ac_top_builddir_sub&;t t
+s&@top_build_prefix@&$ac_top_build_prefix&;t t
+s&@srcdir@&$ac_srcdir&;t t
+s&@abs_srcdir@&$ac_abs_srcdir&;t t
+s&@top_srcdir@&$ac_top_srcdir&;t t
+s&@abs_top_srcdir@&$ac_abs_top_srcdir&;t t
+s&@builddir@&$ac_builddir&;t t
+s&@abs_builddir@&$ac_abs_builddir&;t t
+s&@abs_top_builddir@&$ac_abs_top_builddir&;t t
+s&@INSTALL@&$ac_INSTALL&;t t
+$ac_datarootdir_hack
+"
+eval sed \"\$ac_sed_extra\" "$ac_file_inputs" | $AWK -f "$tmp/subs.awk" >$tmp/out \
+ || as_fn_error $? "could not create $ac_file" "$LINENO" 5
+
+test -z "$ac_datarootdir_hack$ac_datarootdir_seen" &&
+ { ac_out=`sed -n '/\${datarootdir}/p' "$tmp/out"`; test -n "$ac_out"; } &&
+ { ac_out=`sed -n '/^[ ]*datarootdir[ ]*:*=/p' "$tmp/out"`; test -z "$ac_out"; } &&
+ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file contains a reference to the variable \`datarootdir'
+which seems to be undefined. Please make sure it is defined" >&5
+$as_echo "$as_me: WARNING: $ac_file contains a reference to the variable \`datarootdir'
+which seems to be undefined. Please make sure it is defined" >&2;}
+
+ rm -f "$tmp/stdin"
+ case $ac_file in
+ -) cat "$tmp/out" && rm -f "$tmp/out";;
+ *) rm -f "$ac_file" && mv "$tmp/out" "$ac_file";;
+ esac \
+ || as_fn_error $? "could not create $ac_file" "$LINENO" 5
+ ;;
+
+
+
+ esac
+
+done # for ac_tag
+
+
+as_fn_exit 0
+_ACEOF
+ac_clean_files=$ac_clean_files_save
+
+test $ac_write_fail = 0 ||
+ as_fn_error $? "write failure creating $CONFIG_STATUS" "$LINENO" 5
+
+
+# configure is writing to config.log, and then calls config.status.
+# config.status does its own redirection, appending to config.log.
+# Unfortunately, on DOS this fails, as config.log is still kept open
+# by configure, so config.status won't be able to write to it; its
+# output is simply discarded. So we exec the FD to /dev/null,
+# effectively closing config.log, so it can be properly (re)opened and
+# appended to by config.status. When coming back to configure, we
+# need to make the FD available again.
+if test "$no_create" != yes; then
+ ac_cs_success=:
+ ac_config_status_args=
+ test "$silent" = yes &&
+ ac_config_status_args="$ac_config_status_args --quiet"
+ exec 5>/dev/null
+ $SHELL $CONFIG_STATUS $ac_config_status_args || ac_cs_success=false
+ exec 5>>config.log
+ # Use ||, not &&, to avoid exiting from the if with $? = 1, which
+ # would make configure fail if this is the last instruction.
+ $ac_cs_success || as_fn_exit 1
+fi
+if test -n "$ac_unrecognized_opts" && test "$enable_option_checking" != no; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: unrecognized options: $ac_unrecognized_opts" >&5
+$as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;}
+fi
+
+
diff --git a/configure.in b/configure.in
new file mode 100644
index 00000000..05b959b0
--- /dev/null
+++ b/configure.in
@@ -0,0 +1,258 @@
+dnl Process this file with autoconf to produce a configure script.
+AC_REVISION([$Id: configure.in,v 1.38 2008/11/17 11:34:18 tschwinge Exp $])
+AC_PREREQ(2.54) dnl Minimum Autoconf version required.
+AC_INIT([GNU Hurd], [0.3], [bug-hurd@gnu.org])
+AC_CONFIG_SRCDIR([hurd/hurd_types.h]) dnl File to look for in srcdir.
+
+AC_PREFIX_DEFAULT() dnl Default to empty prefix, not /usr/local.
+
+AC_CANONICAL_HOST
+case "$host_os" in
+gnu*) ;;
+none) AC_MSG_ERROR([
+*** You must specify a host of $host_cpu-gnu or $host_cpu-$host_vendor-gnu
+*** to configure; you will need to use the same host specification
+*** to configure other packages for the GNU/Hurd system.]) ;;
+*) AC_MSG_ERROR([this is the gnu os, host cannot be $host_os
+*** Host configuration must be \`MACHINE-gnu' or \`MACHINE-VENDOR-gnu'.
+*** To cross-compile, you must specify both --host and --build;
+*** for example \`--build=$host --host=$host_cpu-gnu'.
+*** Run $0 --help for more information.]) ;;
+esac
+
+case "$host_cpu" in
+alpha*)
+ asm_syntax=alpha
+ ;;
+arm*)
+ asm_syntax=arm
+ ;;
+m68k | m680?0)
+ asm_syntax=m68k
+ ;;
+mips*)
+ asm_syntax=mips
+ ;;
+i?86)
+ asm_syntax=i386
+ ;;
+powerpc*)
+ asm_syntax=ppc
+ ;;
+sparc64* | ultrasparc*)
+ asm_syntax=sparc64
+ ;;
+sparc*)
+ asm_syntax=sparc
+ ;;
+*)
+ asm_syntax="$host_cpu"
+ ;;
+esac
+AC_SUBST(asm_syntax)
+
+test -r "$srcdir/libthreads/$asm_syntax/cthreads.h" || {
+ AC_MSG_WARN([unsupported CPU type $host_cpu])
+}
+
+AC_ARG_ENABLE(profile,
+[ --disable-profile do not build profiled libraries and programs])
+AC_SUBST(enable_profile)
+
+define([default_static],['ext2fs,ufs'])dnl
+AC_ARG_ENABLE(static-progs,
+[ --enable-static-progs=PROGRAMS...
+ build statically-linked PROGRAM.static versions
+ of (only) the listed programs ]dnl
+changequote(',')[default_static]changequote([,]))
+case "$enable_static_progs" in
+'no') enable_static_progs= ;; # we got --disable-static
+'') enable_static_progs=default_static ;;
+esac
+# Convert comma/space-separated list into space-separated list.
+enable_static_progs=`echo "$enable_static_progs" | sed 's/[[, ]][[, ]]*/ /g'`
+AC_SUBST(enable_static_progs)
+
+[# Don't needlessly overwrite files that whose contents haven't changed. This
+# helps for avoinding unneccessary recompilation cycles when keeping
+# cross-compilation toolchains up-to-date. Thus, unconditionally use the
+# supplied `install-sh', as the GNU Coreutils one doesn't provide this
+# functionality yet (TODO: change that). TODO: $ac_abs_top_builddir et al. are
+# not yet available here, that's why we use `readlink' (but only if available).
+INSTALL="$SHELL $(readlink -f "$ac_install_sh")"\ -C || unset INSTALL]
+AC_PROG_INSTALL
+AC_PROG_AWK
+
+AC_PROG_CC
+# Require GCC.
+if test x$GCC != xyes; then
+ AC_MSG_ERROR([this code uses GNU C extensions, you must compile with GCC])
+fi
+
+AC_CHECK_TOOL(LD, ld)
+AC_CHECK_TOOL(OBJCOPY, objcopy)
+AC_CHECK_TOOL(AR, ar)
+AC_CHECK_TOOL(RANLIB, ranlib)
+AC_CHECK_TOOL(MIG, mig)
+# Require MiG.
+if test x${MIG} = x; then
+ AC_MSG_ERROR([
+*** You need GNU MiG to compile the GNU Hurd, please see
+*** http://www.gnu.org/software/hurd/mig.html for further details, or
+*** download it directly from the main GNU server (ftp.gnu.org) or any
+*** GNU mirror.])
+fi
+
+dnl Let these propagate from the environment.
+AC_SUBST(CFLAGS) AC_SUBST(CPPFLAGS) AC_SUBST(LDFLAGS)
+
+# See if there's a separate libcrypt (many systems put crypt there).
+AC_CHECK_LIB(crypt, crypt, LIBCRYPT=-lcrypt)
+AC_SUBST(LIBCRYPT)
+
+hurd_MIG_RETCODE
+
+# See if --version-script is available.
+AC_CACHE_CHECK(for ld --version-script, hurd_cv_ld_version_script_option, [dnl
+cat > conftest.c <<\EOF
+void foobar() {}
+EOF
+cat > conftest.map <<\EOF
+VERS_1 {
+ global: sym;
+};
+
+VERS_2 {
+ global: sym;
+} VERS_1;
+EOF
+
+if AC_TRY_COMMAND([eval $ac_compile 1>&AS_MESSAGE_LOG_FD()]) &&
+ AC_TRY_COMMAND([${CC-cc} $CFLAGS -shared -o conftest.so conftest.o
+ -nostartfiles -nostdlib
+ -Wl,--version-script,conftest.map
+ 1>&AS_MESSAGE_LOG_FD()]); then
+ hurd_cv_ld_version_script_option=yes
+else
+ hurd_cv_ld_version_script_option=no
+fi
+rm -f conftest*])
+
+# See if libc was built with --enable-libio.
+AC_CACHE_CHECK([for libio],
+ hurd_cv_libio,
+ AC_TRY_COMPILE([#include <stdio.h>
+#ifndef _STDIO_USES_IOSTREAM
+# error No libio found.
+#endif],,
+ hurd_cv_libio=yes,
+ hurd_cv_libio=no))
+
+# The versions of the symbols in libthreads have to match those in
+# libc.so. Since the symbols in a libc that includes libio will be
+# versioned differently from the ones in a libc that uses stdio, this
+# isn't easy to accomplish. Instead we leave things unversioned if
+# libio isn't found.
+if test $hurd_cv_libio = yes; then
+ VERSIONING=$hurd_cv_ld_version_script_option
+else
+ VERSIONING=no
+fi
+AC_SUBST(VERSIONING)
+
+# Check if libc contains getgrouplist and/or uselocale.
+AC_CHECK_FUNCS(getgrouplist uselocale)
+
+
+# From glibc HEAD, 2007-11-07.
+AC_CACHE_CHECK(for -fgnu89-inline, libc_cv_gnu89_inline, [dnl
+cat > conftest.c <<EOF
+int foo;
+#ifdef __GNUC_GNU_INLINE__
+main () { return 0;}
+#else
+#error
+#endif
+EOF
+if AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS -S -std=gnu99 -fgnu89-inline
+ -o conftest.s conftest.c 1>&AS_MESSAGE_LOG_FD])
+then
+ libc_cv_gnu89_inline=yes
+else
+ libc_cv_gnu89_inline=no
+fi
+rm -f conftest*])
+if test $libc_cv_gnu89_inline = yes; then
+ libc_cv_gnu89_inline=-fgnu89-inline
+else
+ libc_cv_gnu89_inline=
+fi
+AC_SUBST(libc_cv_gnu89_inline)
+
+
+# Insist on libparted unless the user declines explicitely
+AC_ARG_WITH([parted],
+ [AS_HELP_STRING([--without-parted], [disable user-space partition stores])],
+ [],
+ [with_parted=yes])
+
+PARTED_LIBS=
+AC_DEFUN([PARTED_FAIL], [
+ AC_MSG_FAILURE([Please install required libraries or use --without-parted.])
+])
+AS_IF([test "x$with_parted" != xno], [
+ AC_CHECK_HEADER([parted/parted.h],
+ [AC_DEFINE(HAVE_PARTED_PARTED_H)],
+ [PARTED_FAIL])
+ AC_CHECK_LIB([parted], [ped_device_read], [], [PARTED_FAIL])
+ AC_CHECK_LIB([uuid], [uuid_generate], [], [PARTED_FAIL])
+ AC_CHECK_LIB([dl], [dlopen], [], [PARTED_FAIL])
+ PARTED_LIBS="-lparted -luuid -ldl"
+])
+AC_SUBST([PARTED_LIBS])
+
+AC_ARG_ENABLE(boot-store-types,
+[ --enable-boot-store-types=TYPES...
+ list of store types included in statically
+ linked filesystems used for booting])dnl
+if test -z "$enable_boot_store_types"; then
+ boot_store_types='device remap gunzip bunzip2'
+ test -z "$PARTED_LIBS" || boot_store_types="$boot_store_types part"
+elif test "x$enable_boot_store_types" = xno; then
+ AC_MSG_WARN([you probably wanted --disable-static-progs])
+else
+ boot_store_types="$enable_boot_store_types"
+fi
+AC_SUBST(boot_store_types)dnl
+AC_MSG_CHECKING(boot store types)
+AC_MSG_RESULT($boot_store_types)
+
+# Check for ncursesw, which is needed for the console-curses client.
+hurd_LIB_NCURSESW
+
+# Check for Sun RPC headers and library.
+AC_CHECK_HEADER([rpc/types.h], [HAVE_SUN_RPC=yes], [HAVE_SUN_RPC=no])
+AC_SEARCH_LIBS([clnt_create], [], [:], [HAVE_SUN_RPC=no])
+AC_SUBST([HAVE_SUN_RPC])
+
+if test -f ./$ac_unique_file; then
+ # Configuring in source directory; don't create any Makefiles.
+ makefiles=
+else
+ # We are configuring in a separate build tree.
+ # Create a Makefile in the top-level build directory and
+ # one for each subdirectory Makefile in the source.
+ makefiles="Makeconf:build.mkcf.in \
+ `cd $srcdir; for file in Makefile */Makefile; do \
+ echo ${file}:build.mk.in; done`"
+fi
+
+AC_CONFIG_FILES([config.make ${makefiles}])
+AC_OUTPUT
+
+dnl Local Variables:
+dnl comment-start: "dnl "
+dnl comment-end: ""
+dnl comment-start-skip: "\\bdnl\\b\\s *"
+dnl compile-command: "autoconf"
+dnl End:
diff --git a/libpthread/ChangeLog b/libpthread/ChangeLog
new file mode 100644
index 00000000..e991eac7
--- /dev/null
+++ b/libpthread/ChangeLog
@@ -0,0 +1,6 @@
+51839d398b0f9885a17ab5c0768b8dec4dd9eb79 is the last commit imported from CVS.
+All commits after that one have valid author and committer information.
+
+Use this to examine the change log for earlier changes:
+
+ $ git show 51839d398b0f9885a17ab5c0768b8dec4dd9eb79:ChangeLog
diff --git a/libpthread/Makefile b/libpthread/Makefile
new file mode 100644
index 00000000..a1801f5c
--- /dev/null
+++ b/libpthread/Makefile
@@ -0,0 +1,249 @@
+#
+# Copyright (C) 1994, 1995, 1996, 1997, 2000, 2002, 2004, 2005, 2006, 2007,
+# 2008, 2011 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2, or (at
+# your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+dir := libpthread
+makemode := library
+
+MICROKERNEL := mach
+SYSDEPS := lockfile.c
+
+LCLHDRS :=
+
+SRCS := pt-attr.c pt-attr-destroy.c pt-attr-getdetachstate.c \
+ pt-attr-getguardsize.c pt-attr-getinheritsched.c \
+ pt-attr-getschedparam.c pt-attr-getschedpolicy.c pt-attr-getscope.c \
+ pt-attr-getstack.c pt-attr-getstackaddr.c pt-attr-getstacksize.c \
+ pt-attr-init.c pt-attr-setdetachstate.c pt-attr-setguardsize.c \
+ pt-attr-setinheritsched.c pt-attr-setschedparam.c \
+ pt-attr-setschedpolicy.c pt-attr-setscope.c pt-attr-setstack.c \
+ pt-attr-setstackaddr.c pt-attr-setstacksize.c \
+ \
+ pt-barrier-destroy.c pt-barrier-init.c pt-barrier-wait.c \
+ pt-barrier.c pt-barrierattr-destroy.c pt-barrierattr-init.c \
+ pt-barrierattr-getpshared.c pt-barrierattr-setpshared.c \
+ \
+ pt-destroy-specific.c pt-init-specific.c \
+ pt-key-create.c pt-key-delete.c \
+ pt-getspecific.c pt-setspecific.c \
+ \
+ pt-once.c \
+ \
+ pt-alloc.c \
+ pt-create.c \
+ pt-getattr.c \
+ pt-equal.c \
+ pt-dealloc.c \
+ pt-detach.c \
+ pt-exit.c \
+ pt-initialize.c \
+ pt-join.c \
+ pt-self.c \
+ pt-sigmask.c \
+ pt-spin-inlines.c \
+ pt-cleanup.c \
+ pt-setcancelstate.c \
+ pt-setcanceltype.c \
+ pt-testcancel.c \
+ pt-cancel.c \
+ \
+ pt-mutexattr.c \
+ pt-mutexattr-destroy.c pt-mutexattr-init.c \
+ pt-mutexattr-getprioceiling.c pt-mutexattr-getprotocol.c \
+ pt-mutexattr-getpshared.c pt-mutexattr-gettype.c \
+ pt-mutexattr-setprioceiling.c pt-mutexattr-setprotocol.c \
+ pt-mutexattr-setpshared.c pt-mutexattr-settype.c \
+ \
+ pt-mutex-init.c pt-mutex-destroy.c \
+ pt-mutex-lock.c pt-mutex-trylock.c pt-mutex-timedlock.c \
+ pt-mutex-unlock.c \
+ pt-mutex-transfer-np.c \
+ pt-mutex-getprioceiling.c pt-mutex-setprioceiling.c \
+ \
+ pt-rwlock-attr.c \
+ pt-rwlockattr-init.c pt-rwlockattr-destroy.c \
+ pt-rwlockattr-getpshared.c pt-rwlockattr-setpshared.c \
+ \
+ pt-rwlock-init.c pt-rwlock-destroy.c \
+ pt-rwlock-rdlock.c pt-rwlock-tryrdlock.c \
+ pt-rwlock-trywrlock.c pt-rwlock-wrlock.c \
+ pt-rwlock-timedrdlock.c pt-rwlock-timedwrlock.c \
+ pt-rwlock-unlock.c \
+ \
+ pt-cond.c \
+ pt-condattr-init.c pt-condattr-destroy.c \
+ pt-condattr-getclock.c pt-condattr-getpshared.c \
+ pt-condattr-setclock.c pt-condattr-setpshared.c \
+ \
+ pt-cond-destroy.c pt-cond-init.c \
+ pt-cond-brdcast.c \
+ pt-cond-signal.c \
+ pt-cond-wait.c \
+ pt-cond-timedwait.c \
+ \
+ pt-stack-alloc.c \
+ pt-thread-alloc.c \
+ pt-thread-dealloc.c \
+ pt-thread-start.c \
+ pt-thread-halt.c \
+ pt-startup.c \
+ \
+ pt-getconcurrency.c pt-setconcurrency.c \
+ \
+ pt-block.c \
+ pt-timedblock.c \
+ pt-wakeup.c \
+ pt-docancel.c \
+ pt-sysdep.c \
+ pt-setup.c \
+ pt-machdep.c \
+ pt-spin.c \
+ \
+ pt-sigstate-init.c \
+ pt-sigstate-destroy.c \
+ pt-sigstate.c \
+ \
+ pt-atfork.c \
+ pt-kill.c \
+ pt-getcpuclockid.c \
+ \
+ pt-getschedparam.c pt-setschedparam.c pt-setschedprio.c \
+ pt-yield.c \
+ \
+ sem-close.c sem-destroy.c sem-getvalue.c sem-init.c sem-open.c \
+ sem-post.c sem-timedwait.c sem-trywait.c sem-unlink.c \
+ sem-wait.c \
+ \
+ cthreads-compat.c \
+ $(SYSDEPS)
+
+OBJS = $(addsuffix .o,$(basename $(notdir $(SRCS))))
+
+OTHERTAGS =
+
+libname = libpthread
+
+sysdeps_headers = \
+ pthread.h \
+ pthread/pthread.h \
+ pthread/pthreadtypes.h \
+ semaphore.h \
+ \
+ bits/pthread.h \
+ bits/pthread-np.h \
+ bits/mutex.h \
+ bits/condition.h \
+ bits/condition-attr.h \
+ bits/spin-lock.h \
+ bits/spin-lock-inline.h \
+ bits/cancelation.h \
+ bits/thread-attr.h \
+ bits/barrier-attr.h \
+ bits/barrier.h \
+ bits/thread-specific.h \
+ bits/once.h \
+ bits/mutex-attr.h \
+ bits/rwlock.h \
+ bits/rwlock-attr.h \
+ bits/semaphore.h
+
+SYSDEP_PATH = $(srcdir)/sysdeps/$(MICROKERNEL)/hurd/ia32 \
+ $(srcdir)/sysdeps/$(MICROKERNEL)/ia32 \
+ $(srcdir)/sysdeps/ia32 \
+ $(srcdir)/sysdeps/$(MICROKERNEL)/hurd \
+ $(srcdir)/sysdeps/$(MICROKERNEL) \
+ $(srcdir)/sysdeps/hurd \
+ $(srcdir)/sysdeps/generic \
+ $(srcdir)/sysdeps/posix \
+ $(srcdir)/pthread \
+ $(srcdir)/include
+
+VPATH += $(SYSDEP_PATH)
+
+HURDLIBS = ihash
+
+installhdrs :=
+installhdrsubdir := .
+
+include ../Makeconf
+
+CPPFLAGS += \
+ -DENABLE_TLS \
+ $(addprefix -I, $(SYSDEP_PATH)) \
+ -imacros $(srcdir)/include/libc-symbols.h \
+ -imacros $(srcdir)/not-in-libc.h
+
+
+install: install-headers $(libdir)/libpthread2.a $(libdir)/libpthread2_pic.a
+install-headers: $(addprefix $(includedir)/, $(sysdeps_headers))
+
+# XXX: If $(libdir)/libpthread2.a is installed and
+# $(libdir)/libpthread is not, we can have some issues.
+.PHONY: $(libdir)/libpthread.a $(libdir)/libpthread_pic.a
+
+# XXX: These rules are a hack. But it is better than messing with
+# ../Makeconf at the moment. Note that the linker scripts
+# $(srcdir)/libpthread.a and $(srcdir)/libpthread_pic.a get overwritten
+# when building in $(srcdir) and not a seperate build directory.
+$(libdir)/libpthread2.a: $(libdir)/libpthread.a
+ mv $< $@
+ $(INSTALL_DATA) $(srcdir)/libpthread.a $<
+
+$(libdir)/libpthread2_pic.a: $(libdir)/libpthread_pic.a
+ mv $< $@
+ $(INSTALL_DATA) $(srcdir)/libpthread_pic.a $<
+
+.PHONY: $(addprefix $(includedir)/, $(sysdeps_headers))
+
+$(addprefix $(includedir)/, $(sysdeps_headers)):
+ @set -e; \
+ t="$@"; \
+ t=$${t#$(includedir)/}; \
+ header_ok=0; \
+ for dir in $(SYSDEP_PATH); \
+ do \
+ if test -e "$$dir/$$t"; \
+ then \
+ tdir=`dirname "$@"`; \
+ if test ! -e $$tdir; \
+ then \
+ mkdir $$tdir; \
+ fi; \
+ echo $(INSTALL_DATA) "$$dir/$$t" "$@"; \
+ $(INSTALL_DATA) "$$dir/$$t" "$@"; \
+ header_ok=1; \
+ break; \
+ fi; \
+ done; \
+ if test "$${header_ok}" -ne 1; \
+ then \
+ echo; \
+ echo '*** 'The header file \`$@\' is required, but not \
+provided, by; \
+ echo '*** 'this configuration. Please report this to the \
+maintainer.; \
+ echo; \
+ false; \
+ fi
+
+# ifeq ($(VERSIONING),yes)
+#
+# # Adding this dependency gets it included in the command line,
+# # where ld will read it as a linker script.
+# $(libname).so.$(hurd-version): $(srcdir)/$(libname).map
+#
+# endif
diff --git a/libpthread/Makefile.am b/libpthread/Makefile.am
new file mode 100644
index 00000000..e1c062c1
--- /dev/null
+++ b/libpthread/Makefile.am
@@ -0,0 +1,168 @@
+# Makefile.am - Makefile template for libpthread.
+# Copyright (C) 2003, 2008 Free Software Foundation, Inc.
+#
+# This file is part of the GNU Hurd.
+#
+# The GNU Hurd is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# The GNU Hurd is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+
+if ARCH_IA32
+ arch=ia32
+endif
+if ARCH_POWERPC
+ arch=powerpc
+endif
+
+# The source files are scattered over several directories. Add
+# all these directories to the vpath.
+SYSDEP_PATH = $(srcdir)/sysdeps/l4/hurd/${arch} \
+ $(srcdir)/sysdeps/l4/${arch} \
+ $(srcdir)/sysdeps/${arch} \
+ $(srcdir)/sysdeps/l4/hurd \
+ $(srcdir)/sysdeps/l4 \
+ $(srcdir)/sysdeps/hurd \
+ $(srcdir)/sysdeps/generic \
+ $(srcdir)/sysdeps/posix \
+ $(srcdir)/pthread \
+ $(srcdir)/signal \
+ $(srcdir)/include
+vpath %.c $(SYSDEP_PATH)
+
+AM_CPPFLAGS = $(USER_CPPFLAGS) -I$(srcdir)/pthread \
+ $(addprefix -I, $(SYSDEP_PATH)) -imacros $(srcdir)/include/libc-symbols.h
+AM_CFLAGS = $(USER_CFLAGS)
+
+# Sources.
+SYSDEPS := lockfile.c
+
+if ! ENABLE_TESTS
+noinst_LIBRARIES = libpthread.a
+endif
+
+libpthread_a_SOURCES = pt-attr.c pt-attr-destroy.c pt-attr-getdetachstate.c \
+ pt-attr-getguardsize.c pt-attr-getinheritsched.c \
+ pt-attr-getschedparam.c pt-attr-getschedpolicy.c pt-attr-getscope.c \
+ pt-attr-getstack.c pt-attr-getstackaddr.c pt-attr-getstacksize.c \
+ pt-attr-init.c pt-attr-setdetachstate.c pt-attr-setguardsize.c \
+ pt-attr-setinheritsched.c pt-attr-setschedparam.c \
+ pt-attr-setschedpolicy.c pt-attr-setscope.c pt-attr-setstack.c \
+ pt-attr-setstackaddr.c pt-attr-setstacksize.c pt-attr.c \
+ pt-barrier-destroy.c pt-barrier-init.c pt-barrier-wait.c \
+ pt-barrier.c pt-barrierattr-destroy.c pt-barrierattr-init.c \
+ pt-barrierattr-getpshared.c pt-barrierattr-setpshared.c \
+ pt-destroy-specific.c pt-init-specific.c \
+ pt-key-create.c pt-key-delete.c \
+ pt-getspecific.c pt-setspecific.c \
+ pt-once.c \
+ pt-alloc.c \
+ pt-create.c \
+ pt-getattr.c \
+ pt-pool-np.c \
+ pt-equal.c \
+ pt-dealloc.c \
+ pt-detach.c \
+ pt-exit.c \
+ pt-initialize.c \
+ pt-join.c \
+ pt-self.c \
+ pt-sigmask.c \
+ pt-spin-inlines.c \
+ pt-cleanup.c \
+ pt-setcancelstate.c \
+ pt-setcanceltype.c \
+ pt-testcancel.c \
+ pt-cancel.c \
+ pt-mutexattr.c \
+ pt-mutexattr-destroy.c pt-mutexattr-init.c \
+ pt-mutexattr-getprioceiling.c pt-mutexattr-getprotocol.c \
+ pt-mutexattr-getpshared.c pt-mutexattr-gettype.c \
+ pt-mutexattr-setprioceiling.c pt-mutexattr-setprotocol.c \
+ pt-mutexattr-setpshared.c pt-mutexattr-settype.c \
+ pt-mutex-init.c pt-mutex-destroy.c \
+ pt-mutex-lock.c pt-mutex-trylock.c pt-mutex-timedlock.c \
+ pt-mutex-unlock.c \
+ pt-mutex-transfer-np.c \
+ pt-mutex-getprioceiling.c pt-mutex-setprioceiling.c \
+ pt-rwlock-attr.c \
+ pt-rwlockattr-init.c pt-rwlockattr-destroy.c \
+ pt-rwlockattr-getpshared.c pt-rwlockattr-setpshared.c \
+ pt-rwlock-init.c pt-rwlock-destroy.c \
+ pt-rwlock-rdlock.c pt-rwlock-tryrdlock.c \
+ pt-rwlock-trywrlock.c pt-rwlock-wrlock.c \
+ pt-rwlock-timedrdlock.c pt-rwlock-timedwrlock.c \
+ pt-rwlock-unlock.c \
+ pt-cond.c \
+ pt-condattr-init.c pt-condattr-destroy.c \
+ pt-condattr-getclock.c pt-condattr-getpshared.c \
+ pt-condattr-setclock.c pt-condattr-setpshared.c \
+ pt-cond-destroy.c pt-cond-init.c \
+ pt-cond-brdcast.c \
+ pt-cond-signal.c \
+ pt-cond-wait.c \
+ pt-cond-timedwait.c \
+ pt-stack-alloc.c \
+ pt-thread-alloc.c \
+ pt-thread-dealloc.c \
+ pt-thread-start.c \
+ pt-thread-halt.c \
+ pt-startup.c \
+ pt-getconcurrency.c pt-setconcurrency.c \
+ pt-block.c \
+ pt-timedblock.c \
+ pt-wakeup.c \
+ pt-docancel.c \
+ pt-sysdep.c \
+ pt-setup.c \
+ pt-machdep.c \
+ pt-spin.c \
+ pt-sigstate-init.c \
+ pt-sigstate-destroy.c \
+ pt-sigstate.c \
+ pt-atfork.c \
+ pt-kill.c \
+ pt-getcpuclockid.c \
+ pt-getschedparam.c pt-setschedparam.c pt-setschedprio.c \
+ pt-yield.c \
+ sem-close.c sem-init.c sem-timedwait.c sem-wait.c \
+ sem-destroy.c sem-open.c sem-trywait.c sem-getvalue.c \
+ sem-post.c sem-unlink.c \
+ \
+ pt-setactivity-np.c \
+ \
+ kill.c \
+ killpg.c \
+ pt-kill-siginfo-np.c \
+ raise.c \
+ sigaction.c \
+ sigaddset.c \
+ sigaltstack.c \
+ sigdelset.c \
+ sigemptyset.c \
+ sigfillset.c \
+ sig-internal.c \
+ sig-internal.h \
+ siginterrupt.c \
+ sigismember.c \
+ signal.c \
+ signal-dispatch.c \
+ signal.h \
+ sigpending.c \
+ sigprocmask.c \
+ sigsuspend.c \
+ sigtimedwait.c \
+ sigwait.c \
+ sigwaiter.c \
+ sigwaitinfo.c \
+ signal-dispatch-lowlevel.c \
+ sigprocmask.c
diff --git a/libpthread/TODO b/libpthread/TODO
new file mode 100644
index 00000000..d7e54da6
--- /dev/null
+++ b/libpthread/TODO
@@ -0,0 +1,177 @@
+-*- Mode: outline -*-
+
+* Interfaces
+** All interfaces specified by IEEE Std 1003.1-2001 are present, however,
+ pthread_kill and pthread_sigmask are defined in <pthread.h> and not
+ <signal.h> as they should be. Once we are compiled with glibc,
+ this should be eaiser.
+
+* Test cases. Can never have enough.
+
+* Ports
+ Port to other kernels (e.g. Linux and FreeBSD) and test on other
+ platforms.
+
+* Implementation details
+** pthread_atfork
+ This cannot be implemented without either changing glibc to export
+ some hooks (c.f. libc/sysdeps/mach/hurd/fork.c) or by providing a
+ custom fork implementation that wraps the origial using dlopen et
+ al.
+
+** Scheduling and priorities
+
+ We do not support scheduling right now in any way what so ever.
+
+ This affects:
+ pthread_attr_getinheritsched
+ pthread_attr_setinheritsched
+ pthread_attr_getschedparam
+ pthread_attr_setschedparam
+ pthread_attr_getschedpolicy
+ pthread_attr_setschedpolicy
+ pthread_attr_getscope
+ pthread_attr_setscope
+
+ pthread_mutexattr_getprioceiling
+ pthread_mutexattr_setprioceiling
+ pthread_mutexattr_getprotocol
+ pthread_mutexattr_setprotocol
+ pthread_mutex_getprioceiling
+ pthread_mutex_setprioceiling
+
+ pthread_setschedprio
+ pthread_getschedparam
+ pthread_setschedparam
+
+** Alternate stacks
+
+ Supporting alternate stacks (via pthread_attr_getstackaddr,
+ pthread_attr_setstackaddr, pthread_attr_getstack,
+ pthread_attr_setstack, pthread_attr_getstacksize and
+ pthread_attr_setstacksize) is no problem as long as they are of the
+ correct size and have the correct alignment. This is due to
+ limitations in the Hurd TSD implementation
+ (c.f. <hurd/threadvar.h>).
+
+** Cancelation
+*** Cancelation points
+ The only cancelation points are pthread_join, pthread_cond_wait,
+ pthead_cond_timedwait and pthread_testcancel. Need to explore if
+ the hurd_sigstate->cancel_hook (c.f. <hurd/signal.h>) provides the
+ desired semantics. If not, must either wrap the some functions
+ using dlsym or wait until integration with glibc.
+*** Async cancelation
+ We inject a new IP into the cancelled (running) thread and then
+ run the cancelation handlers
+ (c.f. sysdeps/mach/hurd/pt-docancel.c). The handlers need to have
+ access to the stack as they may use local variables. I think that
+ this method may leave the frame pointer in a corrupted state if
+ the thread was in, for instance, the middle of a function call.
+ The robustness needs to be confirmed.
+
+** Process Shared Attribute
+
+ Currently, there is no real support for the process shared
+ attribute. spinlocks work because we just use a test and set loop,
+ however, barriers, conditions mutexes and rwlocks, however, signal
+ wakeups via ports of which the names are process local.
+
+ We could have some process local data that is hashed to via the
+ address of the data structure. Then the first thread that blocks
+ per process would spin on the shared memory area and all others
+ would then block as normal. When the resource became available,
+ the first thread would signal the other local threads as necessary.
+ Alternatively, there could be some server, however, this opens a
+ new question: what can we use as an authentication agent.
+
+** Locking algorithm
+
+ When a thread blocks, it puts itself on a queue and then waits for
+ a message on a thread local port. The thread which eventually does
+ the wakeup sends a message to the waiter thereby waking it up. If
+ the wakeup is a broadcast wakeup (e.g. pthread_cond_broadcast,
+ pthread_barrier_wait and pthread_rdlock_unlock), the thread must
+ send O(N) messages where N is the number of waiting threads. If
+ all the threads instead received on a lock local (rather than
+ thread local) port then the thread which eventually does the wake
+ need just do one operation, mach_port_destroy and all of the
+ waiting threads would wakeup and get MACH_RCV_PORT_DIED back from
+ mach_msg. Note that the trade off is that the port must be
+ recreated. This needs to be benchmarked.
+
+ A possible problem with this is scheduling priorities. There may
+ be a preference for certain threads to wakeup before others
+ (especially if we are not doing a broadcast, for instance,
+ pthread_mutex_unlock and pthread_cond_signal). If we take this
+ approach, the kernel chooses which threads are awakened. If we
+ find that the kernel makes the wrong choices, we can still overcome
+ this by merging the two algorithms: have a list of ports sorted in
+ priority order and the waker does a mach_port_destroy on each as
+ appropriate.
+
+** Barriers
+
+ Barriers can be very slow and the contention can be very high. The
+ above algorithm is very appealing, however, this may be augmented
+ with an initial number of spins and yields. It is expected that
+ all of the threads reach the barrier within close succession, thus
+ queuing a message may be more expensive. This needs to be
+ benchmarked.
+
+** Clocks
+*** pthread_condattr_setclock allows a process to specify a clock for
+ use with pthread_cond_timedwaits. What is the correct default for
+ this, right now, we use CLOCK_REALTIME, however, we are really
+ using the system clock which, if I understand correctly, is
+ completely different.
+*** Could we even use other clocks? mach_msg uses a relative time against
+ the system clock.
+*** pthread_getcpuclockid just returns CLOCK_THREAD_CPUTIME_ID if defined.
+ Is this the correct behavior?
+
+** Timed Blocking
+*** pthread_cond_timedwait, pthead_mutex_timedlock, pthread_rwlock_timedrdlock
+ and pthread_rwlock_timedwrlock all take absolute times. We need
+ to convert them to relative times for mach_msg. Is there a way
+ around this? How will clock skew affect us?
+
+** weak aliases
+ Use them consistently and correctly and start by reading
+ http://sources.redhat.com/ml/libc-alpha/2002-08/msg00278.html.
+
+** TLS
+ Support for TLS is only implemented for Mach/Hurd (x86).
+
+* L4 Specific Issues
+** Stack
+*** Size
+ The stack size is defined to be a single page in
+ sysdeps/l4/hurd/pt-sysdep.h. Once we are able to setup regions,
+ this can be expanded to two megs as suggested by the Mach version.
+ Until then, however, we need to allocate too much physical memory.
+*** Deallocation
+ __thread_stack_dealloc currently does not deallocate the stack.
+ For a proper implementation, we need a working memory manager.
+
+** Scheduling
+*** yield
+ [L4] We cannot use yield for spin locks as L4 only yields to threads of
+ priority which are greater than or equal to the yielding thread.
+ If there are threads of lower priority, they are not considered;
+ the yielding thread is just placed back on the processor. This
+ introduces priority inversion quite quickly. L4 will not add a
+ priority suppression function call. As such, we need to do
+ an ipc with a small time out and then use exponential back off to
+ do the actual waiting. This sucks.
+
+** Stub code
+ [L4] We include <task_client.h> in pt-start.c, however, we need a library
+ so we do not have to play with the corba stuff.
+
+** Root server and Task server
+*** Getting the tids.
+ pt-start.c has a wonderfully evil hack that will never work well.
+
+** Paging
+ We set the pager to the root server. Evil. Fix this in pt-start.c.
diff --git a/libpthread/headers.m4 b/libpthread/headers.m4
new file mode 100644
index 00000000..5a58b9bf
--- /dev/null
+++ b/libpthread/headers.m4
@@ -0,0 +1,45 @@
+# headers.m4 - Autoconf snippets to install links for header files.
+# Copyright 2003, 2008 Free Software Foundation, Inc.
+# Written by Marcus Brinkmann <marcus@gnu.org>.
+#
+# This file is free software; as a special exception the author gives
+# unlimited permission to copy and/or distribute it, with or without
+# modifications, as long as this notice is preserved.
+#
+# This file is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+AC_CONFIG_LINKS([
+ sysroot/include/pthread.h:libpthread/include/pthread.h
+ sysroot/include/pthread/pthread.h:libpthread/include/pthread/pthread.h
+ sysroot/include/pthread/pthreadtypes.h:libpthread/include/pthread/pthreadtypes.h
+ sysroot/include/bits/memory.h:libpthread/sysdeps/${arch}/bits/memory.h
+ sysroot/include/bits/spin-lock.h:libpthread/sysdeps/${arch}/bits/spin-lock.h
+ sysroot/include/bits/spin-lock-inline.h:libpthread/sysdeps/${arch}/bits/spin-lock-inline.h
+ sysroot/include/bits/pthreadtypes.h:libpthread/sysdeps/generic/bits/pthreadtypes.h
+ sysroot/include/bits/barrier-attr.h:libpthread/sysdeps/generic/bits/barrier-attr.h
+ sysroot/include/bits/barrier.h:libpthread/sysdeps/generic/bits/barrier.h
+ sysroot/include/bits/cancelation.h:libpthread/sysdeps/generic/bits/cancelation.h
+ sysroot/include/bits/condition-attr.h:libpthread/sysdeps/generic/bits/condition-attr.h
+ sysroot/include/bits/condition.h:libpthread/sysdeps/generic/bits/condition.h
+ sysroot/include/bits/mutex-attr.h:libpthread/sysdeps/generic/bits/mutex-attr.h
+ sysroot/include/bits/mutex.h:libpthread/sysdeps/generic/bits/mutex.h
+ sysroot/include/bits/once.h:libpthread/sysdeps/generic/bits/once.h
+ sysroot/include/bits/pthread.h:libpthread/sysdeps/generic/bits/pthread.h
+ sysroot/include/bits/rwlock-attr.h:libpthread/sysdeps/generic/bits/rwlock-attr.h
+ sysroot/include/bits/rwlock.h:libpthread/sysdeps/generic/bits/rwlock.h
+ sysroot/include/bits/thread-attr.h:libpthread/sysdeps/generic/bits/thread-attr.h
+ sysroot/include/bits/thread-barrier.h:libpthread/sysdeps/generic/bits/thread-barrier.h
+ sysroot/include/bits/thread-specific.h:libpthread/sysdeps/generic/bits/thread-specific.h
+ sysroot/include/bits/pthread-np.h:libpthread/sysdeps/l4/hurd/bits/pthread-np.h
+ sysroot/include/semaphore.h:libpthread/include/semaphore.h
+ sysroot/include/bits/semaphore.h:libpthread/sysdeps/generic/bits/semaphore.h
+ sysroot/include/signal.h:libpthread/signal/signal.h
+])
+
+AC_CONFIG_COMMANDS_POST([
+ mkdir -p sysroot/lib libpthread &&
+ ln -sf ../../libpthread/libpthread.a sysroot/lib/ &&
+ touch libpthread/libpthread.a
+])
diff --git a/libpthread/include/libc-symbols.h b/libpthread/include/libc-symbols.h
new file mode 100644
index 00000000..54dd6e26
--- /dev/null
+++ b/libpthread/include/libc-symbols.h
@@ -0,0 +1,395 @@
+/* Support macros for making weak and strong aliases for symbols,
+ and for using symbol sets and linker warnings with GNU ld.
+ Copyright (C) 1995, 1996, 1997, 1998, 2000, 2001, 2002, 2008
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _LIBC_SYMBOLS_H
+#define _LIBC_SYMBOLS_H 1
+
+/* This file's macros are included implicitly in the compilation of every
+ file in the C library by -imacros.
+
+ We include config.h which is generated by configure.
+ It should define for us the following symbols:
+
+ * HAVE_ASM_SET_DIRECTIVE if we have `.set B, A' instead of `A = B'.
+ * ASM_GLOBAL_DIRECTIVE with `.globl' or `.global'.
+ * HAVE_GNU_LD if using GNU ld, with support for weak symbols in a.out,
+ and for symbol set and warning messages extensions in a.out and ELF.
+ * HAVE_ELF if using ELF, which supports weak symbols using `.weak'.
+ * HAVE_ASM_WEAK_DIRECTIVE if we have weak symbols using `.weak'.
+ * HAVE_ASM_WEAKEXT_DIRECTIVE if we have weak symbols using `.weakext'.
+
+ */
+
+/* This is defined for the compilation of all C library code. features.h
+ tests this to avoid inclusion of stubs.h while compiling the library,
+ before stubs.h has been generated. Some library code that is shared
+ with other packages also tests this symbol to see if it is being
+ compiled as part of the C library. We must define this before including
+ config.h, because it makes some definitions conditional on whether libc
+ itself is being compiled, or just some generator program. */
+// #define _LIBC 1
+
+/* Enable declarations of GNU extensions, since we are compiling them. */
+#define _GNU_SOURCE 1
+/* And we also need the data for the reentrant functions. */
+#define _REENTRANT 1
+
+// #include <config.h>
+#define HAVE_ASM_WEAK_DIRECTIVE
+#define HAVE_WEAK_SYMBOLS
+#define HAVE_ASM_SET_DIRECTIVE
+#define HAVE_BUILTIN_EXPECT
+#define HAVE_GNU_LD
+#define HAVE_ELF
+#define HAVE_SECTION_QUOTES
+#define HAVE_VISIBILITY_ATTRIBUTE
+#define HAVE_ASM_PREVIOUS_DIRECTIVE
+// #define SHARED
+
+/* The symbols in all the user (non-_) macros are C symbols.
+ HAVE_GNU_LD without HAVE_ELF implies a.out. */
+
+#if defined HAVE_ASM_WEAK_DIRECTIVE || defined HAVE_ASM_WEAKEXT_DIRECTIVE
+# define HAVE_WEAK_SYMBOLS
+#endif
+
+#ifndef __SYMBOL_PREFIX
+# ifdef NO_UNDERSCORES
+# define __SYMBOL_PREFIX
+# else
+# define __SYMBOL_PREFIX "_"
+# endif
+#endif
+
+#ifndef C_SYMBOL_NAME
+# ifdef NO_UNDERSCORES
+# define C_SYMBOL_NAME(name) name
+# else
+# define C_SYMBOL_NAME(name) _##name
+# endif
+#endif
+
+#ifndef ASM_LINE_SEP
+# define ASM_LINE_SEP ;
+#endif
+
+#ifndef C_SYMBOL_DOT_NAME
+# define C_SYMBOL_DOT_NAME(name) .##name
+#endif
+
+#ifndef __ASSEMBLER__
+/* GCC understands weak symbols and aliases; use its interface where
+ possible, instead of embedded assembly language. */
+
+/* Define ALIASNAME as a strong alias for NAME. */
+# define strong_alias(name, aliasname) _strong_alias(name, aliasname)
+# define _strong_alias(name, aliasname) \
+ extern __typeof (name) aliasname __attribute__ ((alias (#name)));
+
+/* This comes between the return type and function name in
+ a function definition to make that definition weak. */
+# define weak_function __attribute__ ((weak))
+# define weak_const_function __attribute__ ((weak, __const__))
+
+# ifdef HAVE_WEAK_SYMBOLS
+
+/* Define ALIASNAME as a weak alias for NAME.
+ If weak aliases are not available, this defines a strong alias. */
+# define weak_alias(name, aliasname) _weak_alias (name, aliasname)
+# define _weak_alias(name, aliasname) \
+ extern __typeof (name) aliasname __attribute__ ((weak, alias (#name)));
+
+/* Declare SYMBOL as weak undefined symbol (resolved to 0 if not defined). */
+# define weak_extern(symbol) _weak_extern (symbol)
+# ifdef HAVE_ASM_WEAKEXT_DIRECTIVE
+# define _weak_extern(symbol) asm (".weakext " __SYMBOL_PREFIX #symbol);
+# else
+# define _weak_extern(symbol) asm (".weak " __SYMBOL_PREFIX #symbol);
+# endif
+
+# else
+
+# define weak_alias(name, aliasname) strong_alias(name, aliasname)
+# define weak_extern(symbol) /* Nothing. */
+
+# endif
+
+#else /* __ASSEMBLER__ */
+
+# ifdef HAVE_ASM_SET_DIRECTIVE
+# define strong_alias(original, alias) \
+ ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME (alias) ASM_LINE_SEP \
+ .set C_SYMBOL_NAME (alias),C_SYMBOL_NAME (original)
+# else
+# ifdef HAVE_ASM_GLOBAL_DOT_NAME
+# define strong_alias(original, alias) \
+ ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME (alias) ASM_LINE_SEP \
+ C_SYMBOL_NAME (alias) = C_SYMBOL_NAME (original) ASM_LINE_SEP \
+ ASM_GLOBAL_DIRECTIVE C_SYMBOL_DOT_NAME (alias) ASM_LINE_SEP \
+ C_SYMBOL_DOT_NAME (alias) = C_SYMBOL_DOT_NAME (original)
+# else
+# define strong_alias(original, alias) \
+ ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME (alias) ASM_LINE_SEP \
+ C_SYMBOL_NAME (alias) = C_SYMBOL_NAME (original)
+# endif
+# endif
+
+# ifdef HAVE_WEAK_SYMBOLS
+# ifdef HAVE_ASM_WEAKEXT_DIRECTIVE
+# define weak_alias(original, alias) \
+ .weakext C_SYMBOL_NAME (alias), C_SYMBOL_NAME (original)
+# define weak_extern(symbol) \
+ .weakext C_SYMBOL_NAME (symbol)
+
+# else /* ! HAVE_ASM_WEAKEXT_DIRECTIVE */
+
+# ifdef HAVE_ASM_GLOBAL_DOT_NAME
+# define weak_alias(original, alias) \
+ .weak C_SYMBOL_NAME (alias) ASM_LINE_SEP \
+ C_SYMBOL_NAME (alias) = C_SYMBOL_NAME (original) ASM_LINE_SEP \
+ ASM_GLOBAL_DIRECTIVE C_SYMBOL_DOT_NAME (alias) ASM_LINE_SEP \
+ C_SYMBOL_DOT_NAME (alias) = C_SYMBOL_DOT_NAME (original)
+# else
+# define weak_alias(original, alias) \
+ .weak C_SYMBOL_NAME (alias) ASM_LINE_SEP \
+ C_SYMBOL_NAME (alias) = C_SYMBOL_NAME (original)
+# endif
+
+# define weak_extern(symbol) \
+ .weak C_SYMBOL_NAME (symbol)
+
+# endif /* ! HAVE_ASM_WEAKEXT_DIRECTIVE */
+
+# else /* ! HAVE_WEAK_SYMBOLS */
+
+# define weak_alias(original, alias) strong_alias(original, alias)
+# define weak_extern(symbol) /* Nothing */
+# endif /* ! HAVE_WEAK_SYMBOLS */
+
+#endif /* __ASSEMBLER__ */
+
+/* On some platforms we can make internal function calls (i.e., calls of
+ functions not exported) a bit faster by using a different calling
+ convention. */
+#ifndef internal_function
+# define internal_function /* empty */
+#endif
+
+/* Prepare for the case that `__builtin_expect' is not available. */
+#ifndef HAVE_BUILTIN_EXPECT
+# define __builtin_expect(expr, val) (expr)
+#endif
+
+/* Determine the return address. */
+#define RETURN_ADDRESS(nr) \
+ __builtin_extract_return_addr (__builtin_return_address (nr))
+
+/* When a reference to SYMBOL is encountered, the linker will emit a
+ warning message MSG. */
+#ifdef HAVE_GNU_LD
+# ifdef HAVE_ELF
+
+/* We want the .gnu.warning.SYMBOL section to be unallocated. */
+# ifdef HAVE_ASM_PREVIOUS_DIRECTIVE
+# define __make_section_unallocated(section_string) \
+ asm (".section " section_string "\n\t.previous");
+# elif defined HAVE_ASM_POPSECTION_DIRECTIVE
+# define __make_section_unallocated(section_string) \
+ asm (".pushsection " section_string "\n\t.popsection");
+# else
+# define __make_section_unallocated(section_string)
+# endif
+
+/* Tacking on "\n\t#" to the section name makes gcc put it's bogus
+ section attributes on what looks like a comment to the assembler. */
+# ifdef HAVE_SECTION_QUOTES
+# define link_warning(symbol, msg) \
+ __make_section_unallocated (".gnu.warning." #symbol) \
+ static const char __evoke_link_warning_##symbol[] \
+ __attribute__ ((unused, section (".gnu.warning." #symbol "\"\n\t#\""))) \
+ = msg;
+# else
+# define link_warning(symbol, msg) \
+ __make_section_unallocated (".gnu.warning." #symbol) \
+ static const char __evoke_link_warning_##symbol[] \
+ __attribute__ ((unused, section (".gnu.warning." #symbol "\n\t#"))) = msg;
+# endif
+# else /* Not ELF: a.out */
+# ifdef HAVE_XCOFF
+/* XCOFF does not support .stabs.
+ The native aix linker will remove the .stab and .stabstr sections
+ The gnu linker will have a fatal error if there is a relocation for
+ symbol in the .stab section. Silently disable this macro. */
+# define link_warning(symbol, msg)
+# else
+# define link_warning(symbol, msg) \
+ asm (".stabs \"" msg "\",30,0,0,0\n\t" \
+ ".stabs \"" __SYMBOL_PREFIX #symbol "\",1,0,0,0\n");
+# endif /* XCOFF */
+# endif
+#else
+/* We will never be heard; they will all die horribly. */
+# define link_warning(symbol, msg)
+#endif
+
+/* A canned warning for sysdeps/stub functions. */
+#define stub_warning(name) \
+ link_warning (name, \
+ "warning: " #name " is not implemented and will always fail")
+
+/*
+
+*/
+
+#ifdef HAVE_GNU_LD
+
+/* Symbol set support macros. */
+
+# ifdef HAVE_ELF
+
+/* Make SYMBOL, which is in the text segment, an element of SET. */
+# define text_set_element(set, symbol) _elf_set_element(set, symbol)
+/* Make SYMBOL, which is in the data segment, an element of SET. */
+# define data_set_element(set, symbol) _elf_set_element(set, symbol)
+/* Make SYMBOL, which is in the bss segment, an element of SET. */
+# define bss_set_element(set, symbol) _elf_set_element(set, symbol)
+
+/* These are all done the same way in ELF.
+ There is a new section created for each set. */
+# ifdef SHARED
+/* When building a shared library, make the set section writable,
+ because it will need to be relocated at run time anyway. */
+# define _elf_set_element(set, symbol) \
+ static const void *__elf_set_##set##_element_##symbol##__ \
+ __attribute__ ((unused, section (#set))) = &(symbol)
+# else
+# define _elf_set_element(set, symbol) \
+ static const void *const __elf_set_##set##_element_##symbol##__ \
+ __attribute__ ((unused, section (#set))) = &(symbol)
+# endif
+
+/* Define SET as a symbol set. This may be required (it is in a.out) to
+ be able to use the set's contents. */
+# define symbol_set_define(set) symbol_set_declare(set)
+
+/* Declare SET for use in this module, if defined in another module. */
+# define symbol_set_declare(set) \
+ extern void *const __start_##set __attribute__ ((__weak__)); \
+ extern void *const __stop_##set __attribute__ ((__weak__)); \
+ weak_extern (__start_##set) weak_extern (__stop_##set)
+
+/* Return a pointer (void *const *) to the first element of SET. */
+# define symbol_set_first_element(set) (&__start_##set)
+
+/* Return true iff PTR (a void *const *) has been incremented
+ past the last element in SET. */
+# define symbol_set_end_p(set, ptr) ((ptr) >= &__stop_##set)
+
+# else /* Not ELF: a.out. */
+
+# ifdef HAVE_XCOFF
+/* XCOFF does not support .stabs.
+ The native aix linker will remove the .stab and .stabstr sections
+ The gnu linker will have a fatal error if there is a relocation for
+ symbol in the .stab section. Silently disable these macros. */
+# define text_set_element(set, symbol)
+# define data_set_element(set, symbol)
+# define bss_set_element(set, symbol)
+# else
+# define text_set_element(set, symbol) \
+ asm (".stabs \"" __SYMBOL_PREFIX #set "\",23,0,0," __SYMBOL_PREFIX #symbol)
+# define data_set_element(set, symbol) \
+ asm (".stabs \"" __SYMBOL_PREFIX #set "\",25,0,0," __SYMBOL_PREFIX #symbol)
+# define bss_set_element(set, symbol) ?error Must use initialized data.
+# endif /* XCOFF */
+# define symbol_set_define(set) void *const (set)[1];
+# define symbol_set_declare(set) extern void *const (set)[1];
+
+# define symbol_set_first_element(set) &(set)[1]
+# define symbol_set_end_p(set, ptr) (*(ptr) == 0)
+
+# endif /* ELF. */
+#else
+/* We cannot do anything in generial. */
+# define text_set_element(set, symbol) asm ("")
+# define data_set_element(set, symbol) asm ("")
+# define bss_set_element(set, symbol) asm ("")
+# define symbol_set_define(set) void *const (set)[1];
+# define symbol_set_declare(set) extern void *const (set)[1];
+
+# define symbol_set_first_element(set) &(set)[1]
+# define symbol_set_end_p(set, ptr) (*(ptr) == 0)
+#endif /* Have GNU ld. */
+
+#if DO_VERSIONING
+# define symbol_version(real, name, version) \
+ _symbol_version(real, name, version)
+# define default_symbol_version(real, name, version) \
+ _default_symbol_version(real, name, version)
+# ifdef __ASSEMBLER__
+# define _symbol_version(real, name, version) \
+ .symver real, name##@##version
+# define _default_symbol_version(real, name, version) \
+ .symver real, name##@##@##version
+# else
+# define _symbol_version(real, name, version) \
+ __asm__ (".symver " #real "," #name "@" #version)
+# define _default_symbol_version(real, name, version) \
+ __asm__ (".symver " #real "," #name "@@" #version)
+# endif
+#else
+# define symbol_version(real, name, version)
+# define default_symbol_version(real, name, version) \
+ strong_alias(real, name)
+#endif
+
+#if defined HAVE_VISIBILITY_ATTRIBUTE && defined SHARED
+# define attribute_hidden __attribute__ ((visibility ("hidden")))
+#else
+# define attribute_hidden
+#endif
+
+/* Handling on non-exported internal names. We have to do this only
+ for shared code. */
+#ifdef SHARED
+# define INTUSE(name) name##_internal
+# define INTDEF(name) strong_alias (name, name##_internal)
+# define INTVARDEF(name) \
+ _INTVARDEF (name, name##_internal)
+# if defined HAVE_VISIBILITY_ATTRIBUTE
+# define _INTVARDEF(name, aliasname) \
+ extern __typeof (name) aliasname __attribute__ ((alias (#name), \
+ visibility ("hidden")));
+# else
+# define _INTVARDEF(name, aliasname) \
+ extern __typeof (name) aliasname __attribute__ ((alias (#name)));
+# endif
+# define INTDEF2(name, newname) strong_alias (name, newname##_internal)
+# define INTVARDEF2(name, newname) _INTVARDEF (name, newname##_internal)
+#else
+# define INTUSE(name) name
+# define INTDEF(name)
+# define INTVARDEF(name)
+# define INTDEF2(name, newname)
+# define INTVARDEF2(name, newname)
+#endif
+
+#endif /* libc-symbols.h */
diff --git a/libpthread/include/pthread.h b/libpthread/include/pthread.h
new file mode 100644
index 00000000..1d4d3c7b
--- /dev/null
+++ b/libpthread/include/pthread.h
@@ -0,0 +1,7 @@
+#ifndef _PTHREAD_H
+#include <pthread/pthread.h>
+
+extern int __pthread_mutex_lock (pthread_mutex_t *__mutex);
+extern int __pthread_mutex_unlock (pthread_mutex_t *__mutex);
+
+#endif
diff --git a/libpthread/include/pthread/pthread.h b/libpthread/include/pthread/pthread.h
new file mode 100644
index 00000000..cd32fb22
--- /dev/null
+++ b/libpthread/include/pthread/pthread.h
@@ -0,0 +1,755 @@
+/* Copyright (C) 2000, 2002, 2005, 2006, 2007, 2008, 2009, 2010
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+/*
+ * POSIX Threads Extension: ??? <pthread.h>
+ */
+
+#ifndef _PTHREAD_H
+#define _PTHREAD_H 1
+
+#include <features.h>
+
+#include <sys/cdefs.h>
+#ifndef __extern_inline
+/* GCC 4.3 and above with -std=c99 or -std=gnu99 implements ISO C99
+ inline semantics, unless -fgnu89-inline is used. */
+# if !defined __cplusplus || __GNUC_PREREQ (4,3)
+# if defined __GNUC_STDC_INLINE__ || defined __cplusplus
+# define __extern_inline extern __inline __attribute__ ((__gnu_inline__))
+# if __GNUC_PREREQ (4,3)
+# define __extern_always_inline \
+ extern __always_inline __attribute__ ((__gnu_inline__, __artificial__))
+# else
+# define __extern_always_inline \
+ extern __always_inline __attribute__ ((__gnu_inline__))
+# endif
+# else
+# define __extern_inline extern __inline
+# define __extern_always_inline extern __always_inline
+# endif
+# endif
+#endif
+
+#include <sched.h>
+#include <time.h>
+
+__BEGIN_DECLS
+
+#include <pthread/pthreadtypes.h>
+
+#include <bits/pthread.h>
+
+/* Possible values for the process shared attribute. */
+#define PTHREAD_PROCESS_PRIVATE __PTHREAD_PROCESS_PRIVATE
+#define PTHREAD_PROCESS_SHARED __PTHREAD_PROCESS_SHARED
+
+
+/* Thread attributes. */
+
+/* Possible values for the inheritsched attribute. */
+#define PTHREAD_EXPLICIT_SCHED __PTHREAD_EXPLICIT_SCHED
+#define PTHREAD_INHERIT_SCHED __PTHREAD_INHERIT_SCHED
+
+/* Possible values for the `contentionscope' attribute. */
+#define PTHREAD_SCOPE_SYSTEM __PTHREAD_SCOPE_SYSTEM
+#define PTHREAD_SCOPE_PROCESS __PTHREAD_SCOPE_PROCESS
+
+/* Possible values for the `detachstate' attribute. */
+#define PTHREAD_CREATE_JOINABLE __PTHREAD_CREATE_JOINABLE
+#define PTHREAD_CREATE_DETACHED __PTHREAD_CREATE_DETACHED
+
+#include <bits/thread-attr.h>
+
+/* Initialize the thread attribute object in *ATTR to the default
+ values. */
+extern int pthread_attr_init (pthread_attr_t *attr);
+
+/* Destroy the thread attribute object in *ATTR. */
+extern int pthread_attr_destroy (pthread_attr_t *attr);
+
+
+/* Return the value of the inheritsched attribute in *ATTR in
+ *INHERITSCHED. */
+extern int pthread_attr_getinheritsched (const pthread_attr_t *__restrict attr,
+ int *__restrict inheritsched);
+
+/* Set the value of the inheritsched attribute in *ATTR to
+ INHERITSCHED. */
+extern int pthread_attr_setinheritsched (pthread_attr_t *attr,
+ int inheritsched);
+
+
+/* Return the value of the schedparam attribute in *ATTR in *PARAM. */
+extern int pthread_attr_getschedparam (const pthread_attr_t *__restrict attr,
+ struct sched_param *__restrict param);
+
+/* Set the value of the schedparam attribute in *ATTR to PARAM. */
+extern int pthread_attr_setschedparam (pthread_attr_t *__restrict attr,
+ const struct sched_param *__restrict param);
+
+
+/* Return the value of the schedpolicy attribute in *ATTR to *POLICY. */
+extern int pthread_attr_getschedpolicy (const pthread_attr_t *__restrict attr,
+ int *__restrict policy);
+
+/* Set the value of the schedpolicy attribute in *ATTR to POLICY. */
+extern int pthread_attr_setschedpolicy (pthread_attr_t *attr,
+ int policy);
+
+
+/* Return the value of the contentionscope attribute in *ATTR in
+ *CONTENTIONSCOPE. */
+extern int pthread_attr_getscope (const pthread_attr_t *__restrict attr,
+ int *__restrict contentionscope);
+
+/* Set the value of the contentionscope attribute in *ATTR to
+ CONTENTIONSCOPE. */
+extern int pthread_attr_setscope (pthread_attr_t *attr,
+ int contentionscope);
+
+
+/* Return the value of the stackaddr attribute in *ATTR in
+ *STACKADDR. */
+extern int pthread_attr_getstackaddr (const pthread_attr_t *__restrict attr,
+ void **__restrict stackaddr);
+
+/* Set the value of the stackaddr attribute in *ATTR to STACKADDR. */
+extern int pthread_attr_setstackaddr (pthread_attr_t *attr,
+ void *stackaddr);
+
+
+#ifdef __USE_XOPEN2K
+/* Return the value of the stackaddr and stacksize attributes in *ATTR
+ in *STACKADDR and *STACKSIZE respectively. */
+extern int pthread_attr_getstack (const pthread_attr_t *__restrict attr,
+ void **__restrict stackaddr,
+ size_t *__restrict stacksize);
+
+/* Set the value of the stackaddr and stacksize attributes in *ATTR to
+ STACKADDR and STACKSIZE respectively. */
+extern int pthread_attr_setstack (pthread_attr_t *attr,
+ void *stackaddr,
+ size_t stacksize);
+#endif
+
+
+/* Return the value of the detachstate attribute in *ATTR in
+ *DETACHSTATE. */
+extern int pthread_attr_getdetachstate (const pthread_attr_t *attr,
+ int *detachstate);
+
+/* Set the value of the detachstate attribute in *ATTR to
+ DETACHSTATE. */
+extern int pthread_attr_setdetachstate (pthread_attr_t *attr,
+ int detachstate);
+
+
+/* Return the value of the guardsize attribute in *ATTR in
+ *GUARDSIZE. */
+extern int pthread_attr_getguardsize (const pthread_attr_t *__restrict attr,
+ size_t *__restrict guardsize);
+
+/* Set the value of the guardsize attribute in *ATTR to GUARDSIZE. */
+extern int pthread_attr_setguardsize (pthread_attr_t *attr,
+ size_t guardsize);
+
+
+/* Return the value of the stacksize attribute in *ATTR in
+ *STACKSIZE. */
+extern int pthread_attr_getstacksize (const pthread_attr_t *__restrict attr,
+ size_t *__restrict stacksize);
+
+/* Set the value of the stacksize attribute in *ATTR to STACKSIZE. */
+extern int pthread_attr_setstacksize (pthread_attr_t *attr,
+ size_t stacksize);
+
+#ifdef __USE_GNU
+/* Initialize thread attribute *ATTR with attributes corresponding to the
+ already running thread THREAD. It shall be called on an uninitialized ATTR
+ and destroyed with pthread_attr_destroy when no longer needed. */
+extern int pthread_getattr_np (pthread_t thread, pthread_attr_t *attr);
+#endif
+
+
+/* Create a thread with attributes given by ATTR, executing
+ START_ROUTINE with argument ARG. */
+extern int pthread_create (pthread_t *__restrict __threadp,
+ __const pthread_attr_t *__restrict __attr,
+ void *(*__start_routine)(void *),
+ void *__restrict __arg);
+
+/* Terminate the current thread and make STATUS available to any
+ thread that might join us. */
+extern void pthread_exit (void *__status) __attribute__ ((noreturn));
+
+/* Make calling thread wait for termination of thread THREAD. Return
+ the exit status of the thread in *STATUS. */
+extern int pthread_join (pthread_t __threadp, void **__status);
+
+/* Indicate that the storage for THREAD can be reclaimed when it
+ terminates. */
+extern int pthread_detach (pthread_t __threadp);
+
+/* Compare thread IDs T1 and T2. Return nonzero if they are equal, 0
+ if they are not. */
+extern int pthread_equal (pthread_t __t1, pthread_t __t2);
+
+# ifdef __USE_EXTERN_INLINES
+
+__extern_inline int
+pthread_equal (pthread_t __t1, pthread_t __t2)
+{
+ return __pthread_equal (__t1, __t2);
+}
+
+# endif /* Use extern inlines. */
+
+
+/* Return the thread ID of the calling thread. */
+extern pthread_t pthread_self (void);
+
+
+/* Mutex attributes. */
+
+#define PTHREAD_PRIO_NONE_NP __PTHREAD_PRIO_NONE
+#define PTHREAD_PRIO_INHERIT_NP __PTHREAD_PRIO_INHERIT
+#define PTHREAD_PRIO_PROTECT_NP __PTHREAD_PRIO_PROTECT
+#ifdef __USE_UNIX98
+#define PTHREAD_PRIO_NONE PTHREAD_PRIO_NONE_NP
+#define PTHREAD_PRIO_INHERIT PTHREAD_PRIO_INHERIT_NP
+#define PTHREAD_PRIO_PROTECT PTHREAD_PRIO_PROTECT_NP
+#endif
+
+#define PTHREAD_MUTEX_TIMED_NP __PTHREAD_MUTEX_TIMED
+#define PTHREAD_MUTEX_ERRORCHECK_NP __PTHREAD_MUTEX_ERRORCHECK
+#define PTHREAD_MUTEX_RECURSIVE_NP __PTHREAD_MUTEX_RECURSIVE
+#if defined __USE_UNIX98 || defined __USE_XOPEN2K8
+#define PTHREAD_MUTEX_NORMAL PTHREAD_MUTEX_TIMED_NP
+#define PTHREAD_MUTEX_ERRORCHECK PTHREAD_MUTEX_ERRORCHECK_NP
+#define PTHREAD_MUTEX_RECURSIVE PTHREAD_MUTEX_RECURSIVE_NP
+#define PTHREAD_MUTEX_DEFAULT PTHREAD_MUTEX_NORMAL
+#endif
+#ifdef __USE_GNU
+/* For compatibility. */
+#define PTHREAD_MUTEX_FAST_NP PTHREAD_MUTEX_TIMED_NP
+#endif
+
+#include <bits/mutex-attr.h>
+
+/* Initialize the mutex attribute object in *ATTR to the default
+ values. */
+extern int pthread_mutexattr_init(pthread_mutexattr_t *attr);
+
+/* Destroy the mutex attribute structure in *ATTR. */
+extern int pthread_mutexattr_destroy(pthread_mutexattr_t *attr);
+
+
+#ifdef __USE_UNIX98
+/* Return the value of the prioceiling attribute in *ATTR in
+ *PRIOCEILING. */
+extern int pthread_mutexattr_getprioceiling(const pthread_mutexattr_t *__restrict attr,
+ int *__restrict prioceiling);
+
+/* Set the value of the prioceiling attribute in *ATTR to
+ PRIOCEILING. */
+extern int pthread_mutexattr_setprioceiling(pthread_mutexattr_t *attr,
+ int prioceiling);
+
+
+/* Return the value of the protocol attribute in *ATTR in
+ *PROTOCOL. */
+extern int pthread_mutexattr_getprotocol(const pthread_mutexattr_t *__restrict attr,
+ int *__restrict protocol);
+
+/* Set the value of the protocol attribute in *ATTR to PROTOCOL. */
+extern int pthread_mutexattr_setprotocol(pthread_mutexattr_t *attr,
+ int protocol);
+#endif
+
+
+/* Return the value of the process shared attribute in *ATTR in
+ *PSHARED. */
+extern int pthread_mutexattr_getpshared(const pthread_mutexattr_t *__restrict attr,
+ int *__restrict pshared);
+
+/* Set the value of the process shared attribute in *ATTR to
+ PSHARED. */
+extern int pthread_mutexattr_setpshared(pthread_mutexattr_t *attr,
+ int pshared);
+
+
+#if defined __USE_UNIX98 || defined __USE_XOPEN2K8
+/* Return the value of the type attribute in *ATTR in *TYPE. */
+extern int pthread_mutexattr_gettype(const pthread_mutexattr_t *__restrict attr,
+ int *__restrict type);
+
+/* Set the value of the type attribute in *ATTR to TYPE. */
+extern int pthread_mutexattr_settype(pthread_mutexattr_t *attr,
+ int type);
+#endif
+
+
+/* Mutexes. */
+
+#include <bits/mutex.h>
+
+#define PTHREAD_MUTEX_INITIALIZER __PTHREAD_MUTEX_INITIALIZER
+/* Static initializer for recursive mutexes. */
+
+#ifdef __USE_GNU
+# define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP \
+ __PTHREAD_ERRORCHECK_MUTEX_INITIALIZER
+# define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP \
+ __PTHREAD_RECURSIVE_MUTEX_INITIALIZER
+#endif
+
+/* Create a mutex with attributes given by ATTR and store it in
+ *__MUTEX. */
+extern int pthread_mutex_init (struct __pthread_mutex *__restrict __mutex,
+ const pthread_mutexattr_t *__restrict attr);
+
+/* Destroy the mutex __MUTEX. */
+extern int pthread_mutex_destroy (struct __pthread_mutex *__mutex);
+
+/* Wait until lock for MUTEX becomes available and lock it. */
+extern int pthread_mutex_lock (pthread_mutex_t *__mutex);
+
+/* Try to lock MUTEX. */
+extern int pthread_mutex_trylock (pthread_mutex_t *__mutex);
+
+#ifdef __USE_XOPEN2K
+/* Try to lock MUTEX, block until *ABSTIME if it is already held. */
+extern int pthread_mutex_timedlock (struct __pthread_mutex *__restrict mutex,
+ const struct timespec *__restrict abstime);
+#endif
+
+/* Unlock MUTEX. */
+extern int pthread_mutex_unlock (pthread_mutex_t *__mutex);
+
+/* Transfer ownership of the mutex MUTEX to the thread TID. The
+ caller must own the lock. */
+extern int __pthread_mutex_transfer_np (struct __pthread_mutex *mutex,
+ pthread_t tid);
+
+
+#ifdef __USE_UNIX98
+/* Return the priority ceiling of mutex *MUTEX in *PRIOCEILING. */
+extern int pthread_mutex_getprioceiling (const pthread_mutex_t *__restrict mutex,
+ int *__restrict prioceiling);
+
+/* After acquiring the mutex *MUTEX, set its priority ceiling to PRIO
+ and return the old priority ceiling in *OLDPRIO. Before returning,
+ release the mutex. */
+extern int pthread_mutex_setprioceiling (pthread_mutex_t *__restrict mutex,
+ int prio, int *__restrict oldprio);
+#endif
+
+
+
+/* Condition attributes. */
+
+#include <bits/condition-attr.h>
+
+/* Initialize the condition attribute in *ATTR to the default
+ values. */
+extern int pthread_condattr_init (pthread_condattr_t *attr);
+
+/* Destroy the condition attribute structure in *ATTR. */
+extern int pthread_condattr_destroy (pthread_condattr_t *attr);
+
+
+#ifdef __USE_XOPEN2K
+/* Return the value of the clock attribute in *ATTR in *CLOCK_ID. */
+extern int pthread_condattr_getclock (const pthread_condattr_t *__restrict attr,
+ __clockid_t *__restrict clock_id);
+
+/* Set the value of the clock attribute in *ATTR to CLOCK_ID. */
+extern int pthread_condattr_setclock (pthread_condattr_t *attr,
+ __clockid_t clock_id);
+#endif
+
+
+/* Return the value of the process shared attribute in *ATTR in
+ *PSHARED. */
+extern int pthread_condattr_getpshared (const pthread_condattr_t *__restrict attr,
+ int *__restrict pshared);
+
+/* Set the value of the process shared attribute in *ATTR to
+ PSHARED. */
+extern int pthread_condattr_setpshared (pthread_condattr_t *attr,
+ int pshared);
+
+
+/* Condition variables. */
+
+#include <bits/condition.h>
+
+#define PTHREAD_COND_INITIALIZER __PTHREAD_COND_INITIALIZER
+
+extern int pthread_cond_init (pthread_cond_t *__restrict cond,
+ const pthread_condattr_t *__restrict attr);
+
+extern int pthread_cond_destroy (pthread_cond_t *cond);
+
+/* Unblock at least one of the threads that are blocked on condition
+ variable COND. */
+extern int pthread_cond_signal (pthread_cond_t *__cond);
+
+/* Unblock all threads that are blocked on condition variable COND. */
+extern int pthread_cond_broadcast (pthread_cond_t *__cond);
+
+/* Block on condition variable COND. MUTEX should be held by the
+ calling thread. On success, MUTEX will be held by the calling
+ thread. */
+extern int pthread_cond_wait (pthread_cond_t *__restrict __cond,
+ pthread_mutex_t *__restrict __mutex);
+
+/* Block on condition variable COND. MUTEX should be held by the
+ calling thread. On success, MUTEX will be held by the calling
+ thread. If the time specified by ABSTIME passes, ETIMEDOUT is
+ returned, and MUTEX will nevertheless be held. */
+extern int pthread_cond_timedwait (pthread_cond_t *__restrict __cond,
+ pthread_mutex_t *__restrict __mutex,
+ __const struct timespec *__restrict __abstime);
+
+
+/* Spin locks. */
+
+#ifdef __USE_XOPEN2K
+
+# include <bits/spin-lock.h>
+
+#define PTHREAD_SPINLOCK_INITIALIZER __PTHREAD_SPIN_LOCK_INITIALIZER
+
+/* Destroy the spin lock object LOCK. */
+extern int pthread_spin_destroy (pthread_spinlock_t *__lock);
+
+/* Initialize the spin lock object LOCK. PSHARED determines whether
+ the spin lock can be operated upon by multiple processes. */
+extern int pthread_spin_init (pthread_spinlock_t *__lock, int __pshared);
+
+/* Lock the spin lock object LOCK. If the lock is held by another
+ thread spin until it becomes available. */
+extern int pthread_spin_lock (pthread_spinlock_t *__lock);
+
+/* Lock the spin lock object LOCK. Fail if the lock is held by
+ another thread. */
+extern int pthread_spin_trylock (pthread_spinlock_t *__lock);
+
+/* Unlock the spin lock object LOCK. */
+extern int pthread_spin_unlock (pthread_spinlock_t *__lock);
+
+# ifdef __USE_EXTERN_INLINES
+
+# include <bits/spin-lock-inline.h>
+
+__extern_inline int
+pthread_spin_destroy (pthread_spinlock_t *__lock)
+{
+ return __pthread_spin_destroy (__lock);
+}
+
+__extern_inline int
+pthread_spin_init (pthread_spinlock_t *__lock, int __pshared)
+{
+ return __pthread_spin_init (__lock, __pshared);
+}
+
+__extern_inline int
+pthread_spin_lock (pthread_spinlock_t *__lock)
+{
+ return __pthread_spin_lock (__lock);
+}
+
+__extern_inline int
+pthread_spin_trylock (pthread_spinlock_t *__lock)
+{
+ return __pthread_spin_trylock (__lock);
+}
+
+__extern_inline int
+pthread_spin_unlock (pthread_spinlock_t *__lock)
+{
+ return __pthread_spin_unlock (__lock);
+}
+
+# endif /* Use extern inlines. */
+
+#endif /* XPG6. */
+
+
+/* rwlock attributes. */
+
+#if defined __USE_UNIX98 || defined __USE_XOPEN2K
+
+#include <bits/rwlock-attr.h>
+
+/* Initialize rwlock attribute object in *ATTR to the default
+ values. */
+extern int pthread_rwlockattr_init (pthread_rwlockattr_t *attr);
+
+/* Destroy the rwlock attribute object in *ATTR. */
+extern int pthread_rwlockattr_destroy (pthread_rwlockattr_t *attr);
+
+
+/* Return the value of the process shared attribute in *ATTR in
+ *PSHARED. */
+extern int pthread_rwlockattr_getpshared (const pthread_rwlockattr_t *__restrict attr,
+ int *__restrict pshared);
+
+/* Set the value of the process shared atrribute in *ATTR to
+ PSHARED. */
+extern int pthread_rwlockattr_setpshared (pthread_rwlockattr_t *attr,
+ int pshared);
+
+
+/* rwlocks. */
+
+#include <bits/rwlock.h>
+
+#define PTHREAD_RWLOCK_INITIALIZER __PTHREAD_RWLOCK_INITIALIZER
+/* Create a rwlock object with attributes given by ATTR and strore the
+ result in *RWLOCK. */
+extern int pthread_rwlock_init (pthread_rwlock_t *__restrict rwlock,
+ const pthread_rwlockattr_t *__restrict attr);
+
+/* Destroy the rwlock *RWLOCK. */
+extern int pthread_rwlock_destroy (pthread_rwlock_t *rwlock);
+
+/* Acquire the rwlock *RWLOCK for reading. */
+extern int pthread_rwlock_rdlock (pthread_rwlock_t *rwlock);
+
+/* Acquire the rwlock *RWLOCK for reading. */
+extern int pthread_rwlock_tryrdlock (pthread_rwlock_t *rwlock);
+
+# ifdef __USE_XOPEN2K
+/* Acquire the rwlock *RWLOCK for reading blocking until *ABSTIME if
+ it is already held. */
+extern int pthread_rwlock_timedrdlock (struct __pthread_rwlock *__restrict rwlock,
+ const struct timespec *__restrict abstime);
+# endif
+
+/* Acquire the rwlock *RWLOCK for writing. */
+extern int pthread_rwlock_wrlock (pthread_rwlock_t *rwlock);
+
+/* Try to acquire the rwlock *RWLOCK for writing. */
+extern int pthread_rwlock_trywrlock (pthread_rwlock_t *rwlock);
+
+# ifdef __USE_XOPEN2K
+/* Acquire the rwlock *RWLOCK for writing blocking until *ABSTIME if
+ it is already held. */
+extern int pthread_rwlock_timedwrlock (struct __pthread_rwlock *__restrict rwlock,
+ const struct timespec *__restrict abstime);
+# endif
+
+/* Release the lock held by the current thread on *RWLOCK. */
+extern int pthread_rwlock_unlock (pthread_rwlock_t *rwlock);
+
+#endif /* __USE_UNIX98 || __USE_XOPEN2K */
+
+
+
+/* Cancelation. */
+
+/* Register a cleanup handler. */
+extern void pthread_cleanup_push (void (*routine) (void *), void *arg);
+
+/* Unregister a cleanup handler. */
+extern void pthread_cleanup_pop (int execute);
+
+#include <bits/cancelation.h>
+
+#define pthread_cleanup_push(rt, rtarg) __pthread_cleanup_push(rt, rtarg)
+#define pthread_cleanup_pop(execute) __pthread_cleanup_pop(execute)
+
+#define PTHREAD_CANCEL_DISABLE 0
+#define PTHREAD_CANCEL_ENABLE 1
+
+/* Return the calling thread's cancelation state in *OLDSTATE and set
+ its state to STATE. */
+extern int pthread_setcancelstate (int state, int *oldstate);
+
+#define PTHREAD_CANCEL_DEFERRED 0
+#define PTHREAD_CANCEL_ASYNCHRONOUS 1
+
+/* Return the calling thread's cancelation type in *OLDTYPE and set
+ its type to TYPE. */
+extern int pthread_setcanceltype (int type, int *oldtype);
+
+/* Value returned by pthread_join if the target thread was
+ canceled. */
+#define PTHREAD_CANCELED ((void *) -1)
+
+/* Cancel THEAD. */
+extern int pthread_cancel (pthread_t thread);
+
+/* Add an explicit cancelation point. */
+extern void pthread_testcancel (void);
+
+
+/* Barriers attributes. */
+
+#ifdef __USE_XOPEN2K
+
+#include <bits/barrier-attr.h>
+
+/* Initialize barrier attribute object in *ATTR to the default
+ values. */
+extern int pthread_barrierattr_init (pthread_barrierattr_t *attr);
+
+/* Destroy the barrier attribute object in *ATTR. */
+extern int pthread_barrierattr_destroy (pthread_barrierattr_t *attr);
+
+
+/* Return the value of the process shared attribute in *ATTR in
+ *PSHARED. */
+extern int pthread_barrierattr_getpshared (const pthread_barrierattr_t *__restrict attr,
+ int *__restrict pshared);
+
+/* Set the value of the process shared atrribute in *ATTR to
+ PSHARED. */
+extern int pthread_barrierattr_setpshared (pthread_barrierattr_t *attr,
+ int pshared);
+
+
+/* Barriers. */
+
+#include <bits/barrier.h>
+
+/* Returned by pthread_barrier_wait to exactly one thread each time a
+ barrier is passed. */
+#define PTHREAD_BARRIER_SERIAL_THREAD -1
+
+/* Initialize barrier BARRIER. */
+extern int pthread_barrier_init (pthread_barrier_t *__restrict barrier,
+ const pthread_barrierattr_t *__restrict attr,
+ unsigned count);
+
+/* Destroy barrier BARRIER. */
+extern int pthread_barrier_destroy (pthread_barrier_t *barrier);
+
+/* Wait on barrier BARRIER. */
+extern int pthread_barrier_wait (pthread_barrier_t *barrier);
+
+#endif /* __USE_XOPEN2K */
+
+
+
+/* Thread specific data. */
+
+#include <bits/thread-specific.h>
+
+/* Create a thread specific data key in KEY visible to all threads.
+ On thread destruction, DESTRUCTOR shall be called with the thread
+ specific data associate with KEY if it is not NULL. */
+extern int pthread_key_create (pthread_key_t *key,
+ void (*destructor) (void *));
+
+/* Delete the thread specific data key KEY. The associated destructor
+ function is not called. */
+extern int pthread_key_delete (pthread_key_t key);
+
+/* Return the caller thread's thread specific value of KEY. */
+extern void *pthread_getspecific (pthread_key_t key);
+
+/* Set the caller thread's thread specific value of KEY to VALUE. */
+extern int pthread_setspecific (pthread_key_t key, const void *value);
+
+
+/* Dynamic package initialization. */
+
+#include <bits/once.h>
+
+#define PTHREAD_ONCE_INIT __PTHREAD_ONCE_INIT
+
+/* Call INIT_ROUTINE if this function has never been called with
+ *ONCE_CONTROL, otherwise do nothing. */
+extern int pthread_once (pthread_once_t *once_control,
+ void (*init_routine) (void));
+
+
+/* Concurrency. */
+
+#ifdef __USE_UNIX98
+/* Set the desired concurrency level to NEW_LEVEL. */
+extern int pthread_setconcurrency (int new_level);
+
+/* Get the current concurrency level. */
+extern int pthread_getconcurrency (void);
+#endif
+
+
+/* Forking. */
+
+/* Register the function PREPARE to be run before the process forks,
+ the function PARENT to be run after a fork in the parent and the
+ function CHILD to be run in the child after the fork. If no
+ handling is desired then any of PREPARE, PARENT and CHILD may be
+ NULL. The prepare handles will be called in the reverse order
+ which they were registered and the parent and child handlers in the
+ order in which they were registered. */
+extern int pthread_atfork (void (*prepare) (void), void (*parent) (void),
+ void (*child) (void));
+
+
+/* Signals (should be in <signal.h>). */
+
+/* Send signal SIGNO to thread THREAD. */
+extern int pthread_kill (pthread_t thread, int signo);
+
+
+/* Time. */
+
+#ifdef __USE_XOPEN2K
+/* Return the thread cpu clock. */
+extern int pthread_getcpuclockid (pthread_t thread, __clockid_t *clock);
+#endif
+
+
+/* Scheduling. */
+
+/* Return thread THREAD's scheduling paramters. */
+extern int pthread_getschedparam (pthread_t thread, int *__restrict policy,
+ struct sched_param *__restrict param);
+
+/* Set thread THREAD's scheduling paramters. */
+extern int pthread_setschedparam (pthread_t thread, int policy,
+ const struct sched_param *param);
+
+/* Set thread THREAD's scheduling priority. */
+extern int pthread_setschedprio (pthread_t thread, int prio);
+
+#ifdef __USE_GNU
+/* Yield the processor to another thread or process.
+ This function is similar to the POSIX `sched_yield' function but
+ might be differently implemented in the case of a m-on-n thread
+ implementation. */
+extern int pthread_yield (void);
+#endif
+
+
+/* Kernel-specific interfaces. */
+
+#include <bits/pthread-np.h>
+
+
+__END_DECLS
+
+#endif /* pthread.h */
diff --git a/libpthread/include/pthread/pthreadtypes.h b/libpthread/include/pthread/pthreadtypes.h
new file mode 100644
index 00000000..33bd0099
--- /dev/null
+++ b/libpthread/include/pthread/pthreadtypes.h
@@ -0,0 +1,125 @@
+/* Copyright (C) 2000, 2002, 2005, 2008 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+/*
+ * POSIX Threads Extension: ??? <pthreadtypes.h>
+ */
+
+#ifndef _PTHREADTYPES_H
+#define _PTHREADTYPES_H 1
+
+#include <features.h>
+
+#include <bits/types.h>
+
+__BEGIN_DECLS
+
+#include <bits/pthread.h>
+typedef __pthread_t pthread_t;
+
+/* Possible values for the process shared attribute. */
+enum __pthread_process_shared
+ {
+ __PTHREAD_PROCESS_PRIVATE = 0,
+ __PTHREAD_PROCESS_SHARED
+ };
+
+/* Possible values for the inheritsched attribute. */
+enum __pthread_inheritsched
+ {
+ __PTHREAD_EXPLICIT_SCHED = 0,
+ __PTHREAD_INHERIT_SCHED
+ };
+
+/* Possible values for the `contentionscope' attribute. */
+enum __pthread_contentionscope
+ {
+ __PTHREAD_SCOPE_SYSTEM = 0,
+ __PTHREAD_SCOPE_PROCESS
+ };
+
+/* Possible values for the `detachstate' attribute. */
+enum __pthread_detachstate
+ {
+ __PTHREAD_CREATE_JOINABLE = 0,
+ __PTHREAD_CREATE_DETACHED
+ };
+
+#include <bits/thread-attr.h>
+typedef struct __pthread_attr pthread_attr_t;
+
+enum __pthread_mutex_protocol
+ {
+ __PTHREAD_PRIO_NONE= 0,
+ __PTHREAD_PRIO_INHERIT,
+ __PTHREAD_PRIO_PROTECT
+ };
+
+enum __pthread_mutex_type
+ {
+ __PTHREAD_MUTEX_TIMED,
+ __PTHREAD_MUTEX_ERRORCHECK,
+ __PTHREAD_MUTEX_RECURSIVE
+ };
+
+#include <bits/mutex-attr.h>
+typedef struct __pthread_mutexattr pthread_mutexattr_t;
+
+#include <bits/mutex.h>
+typedef struct __pthread_mutex pthread_mutex_t;
+
+#include <bits/condition-attr.h>
+typedef struct __pthread_condattr pthread_condattr_t;
+
+#include <bits/condition.h>
+typedef struct __pthread_cond pthread_cond_t;
+
+#ifdef __USE_XOPEN2K
+# include <bits/spin-lock.h>
+typedef __pthread_spinlock_t pthread_spinlock_t;
+#endif /* XPG6. */
+
+#if defined __USE_UNIX98 || defined __USE_XOPEN2K
+
+#include <bits/rwlock-attr.h>
+typedef struct __pthread_rwlockattr pthread_rwlockattr_t;
+
+#include <bits/rwlock.h>
+typedef struct __pthread_rwlock pthread_rwlock_t;
+
+#endif /* __USE_UNIX98 || __USE_XOPEN2K */
+
+#ifdef __USE_XOPEN2K
+
+#include <bits/barrier-attr.h>
+typedef struct __pthread_barrierattr pthread_barrierattr_t;
+
+#include <bits/barrier.h>
+typedef struct __pthread_barrier pthread_barrier_t;
+
+#endif /* __USE_XOPEN2K */
+
+#include <bits/thread-specific.h>
+typedef __pthread_key pthread_key_t;
+
+#include <bits/once.h>
+typedef struct __pthread_once pthread_once_t;
+
+__END_DECLS
+
+#endif /* pthreadtypes.h */
diff --git a/libpthread/include/semaphore.h b/libpthread/include/semaphore.h
new file mode 100644
index 00000000..657e796e
--- /dev/null
+++ b/libpthread/include/semaphore.h
@@ -0,0 +1,69 @@
+/* Copyright (C) 2005, 2007 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#ifndef _SEMAPHORE_H
+#define _SEMAPHORE_H 1
+
+#include <features.h>
+
+__BEGIN_DECLS
+
+#include <bits/semaphore.h>
+
+#define SEM_FAILED ((void *) 0)
+
+typedef struct __semaphore sem_t;
+
+/* Initialize semaphore *SEM with value VALUE. */
+extern int sem_init (sem_t *sem, int pshared, unsigned value);
+
+/* Destroy semaphore *SEM created with sem_init. */
+extern int sem_destroy (sem_t *sem);
+
+/* Store the value of semaphore *SEM in *VALUE. */
+extern int sem_getvalue (sem_t *__restrict sem, int *__restrict value);
+
+/* Perform a down operation on semaphore *SEM. */
+extern int sem_wait (sem_t *sem);
+
+/* Perform a down operation on semaphore *SEM if it can be done so
+ without blocking. */
+extern int sem_trywait (sem_t *sem);
+
+#ifdef __USE_XOPEN2K
+/* Perform a down operation on semaphore *SEM but don't wait longer
+ than TIMEOUT. */
+extern int sem_timedwait (sem_t *__restrict sem,
+ const struct timespec *__restrict timeout);
+#endif
+
+/* Perform an up operation on semaphore *SEM. */
+extern int sem_post (sem_t *sem);
+
+/* Open a named semaphore. */
+extern sem_t *sem_open (const char *name, int open_flags, ...);
+
+/* Close a semaphore returned by sem_open. */
+extern int sem_close (sem_t *sem);
+
+/* Unlink a named semaphore. */
+extern int sem_unlink (const char *name);
+
+__END_DECLS
+
+#endif /* semaphore.h */
diff --git a/libpthread/include/set-hooks.h b/libpthread/include/set-hooks.h
new file mode 100644
index 00000000..9ed71b32
--- /dev/null
+++ b/libpthread/include/set-hooks.h
@@ -0,0 +1,72 @@
+/* Macros for using symbol sets for running lists of functions.
+ Copyright (C) 1994, 1995, 1997, 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SET_HOOKS_H
+#define _SET_HOOKS_H 1
+
+#define __need_size_t
+#include <stddef.h>
+// #include <sys/cdefs.h>
+#define __unbounded
+
+#ifdef symbol_set_define
+/* Define a hook variable called NAME. Functions put on this hook take
+ arguments described by PROTO. Use `text_set_element (NAME, FUNCTION)'
+ from gnu-stabs.h to add a function to the hook. */
+
+# define DEFINE_HOOK(NAME, PROTO) \
+ typedef void __##NAME##_hook_function_t PROTO; \
+ symbol_set_define (NAME)
+
+# define DECLARE_HOOK(NAME, PROTO) \
+ typedef void __##NAME##_hook_function_t PROTO;\
+ symbol_set_declare (NAME)
+
+/* Run all the functions hooked on the set called NAME.
+ Each function is called like this: `function ARGS'. */
+
+# define RUN_HOOK(NAME, ARGS) \
+do { \
+ void *const *__unbounded ptr; \
+ for (ptr = symbol_set_first_element (NAME); \
+ ! symbol_set_end_p (NAME, ptr); ++ptr) \
+ (*(__##NAME##_hook_function_t *) *ptr) ARGS; \
+} while (0)
+
+/* Define a hook variable with NAME and PROTO, and a function called RUNNER
+ which calls each function on the hook in turn, with ARGS. */
+
+# define DEFINE_HOOK_RUNNER(name, runner, proto, args) \
+DEFINE_HOOK (name, proto); \
+extern void runner proto; void runner proto { RUN_HOOK (name, args); }
+
+#else
+
+/* The system does not provide necessary support for this. */
+# define DEFINE_HOOK(NAME, PROTO)
+
+# define DECLARE_HOOK(NAME, PROTO)
+
+# define RUN_HOOK(NAME, ARGS)
+
+# define DEFINE_HOOK_RUNNER(name, runner, proto, args)
+
+#endif
+
+#endif /* set-hooks.h */
diff --git a/libpthread/libpthread.a b/libpthread/libpthread.a
new file mode 100644
index 00000000..d0e689e9
--- /dev/null
+++ b/libpthread/libpthread.a
@@ -0,0 +1,20 @@
+/* pthread initializer is weak in glibc. It must be included if glibc
+ is to start threading. */
+EXTERN(_cthread_init_routine)
+
+/* Weak references in glibc that must be filled if glibc is to be
+ thread safe. */
+EXTERN(cthread_detach)
+EXTERN(cthread_fork)
+EXTERN(cthread_keycreate)
+EXTERN(cthread_getspecific)
+EXTERN(__libc_getspecific)
+EXTERN(cthread_setspecific)
+EXTERN(__mutex_lock_solid)
+EXTERN(__mutex_unlock_solid)
+/* For libio stream locking. */
+EXTERN(_cthreads_flockfile)
+EXTERN(_cthreads_funlockfile)
+EXTERN(_cthreads_ftrylockfile)
+
+GROUP(-lpthread2 -lihash)
diff --git a/libpthread/libpthread_pic.a b/libpthread/libpthread_pic.a
new file mode 100644
index 00000000..5673b4e7
--- /dev/null
+++ b/libpthread/libpthread_pic.a
@@ -0,0 +1,20 @@
+/* pthread initializer is weak in glibc. It must be included if glibc
+ is to start threading. */
+EXTERN(_cthread_init_routine)
+
+/* Weak references in glibc that must be filled if glibc is to be
+ thread safe. */
+EXTERN(cthread_detach)
+EXTERN(cthread_fork)
+EXTERN(cthread_keycreate)
+EXTERN(cthread_getspecific)
+EXTERN(__libc_getspecific)
+EXTERN(cthread_setspecific)
+EXTERN(__mutex_lock_solid)
+EXTERN(__mutex_unlock_solid)
+/* For libio stream locking. */
+EXTERN(_cthreads_flockfile)
+EXTERN(_cthreads_funlockfile)
+EXTERN(_cthreads_ftrylockfile)
+
+GROUP(-lpthread2_pic -lihash_pic)
diff --git a/libpthread/lockfile.c b/libpthread/lockfile.c
new file mode 100644
index 00000000..040cbfb4
--- /dev/null
+++ b/libpthread/lockfile.c
@@ -0,0 +1,65 @@
+/* lockfile - Handle locking and unlocking of streams. Hurd cthreads version.
+ Copyright (C) 2000,01,02 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <cthreads.h>
+#include <pthread.h> /* Must come before <stdio.h>! */
+#include <stdio.h>
+
+#ifdef _STDIO_USES_IOSTREAM
+
+void
+_cthreads_flockfile (_IO_FILE *fp)
+{
+ _IO_lock_lock (*fp->_lock);
+}
+
+void
+_cthreads_funlockfile (_IO_FILE *fp)
+{
+ _IO_lock_unlock (*fp->_lock);
+}
+
+int
+_cthreads_ftrylockfile (_IO_FILE *fp)
+{
+ return __libc_lock_trylock_recursive (*fp->_lock);
+}
+
+# undef _IO_flockfile
+# undef _IO_funlockfile
+# undef _IO_ftrylockfile
+# undef flockfile
+# undef funlockfile
+# undef ftrylockfile
+
+void _IO_flockfile (_IO_FILE *)
+ __attribute__ ((alias ("_cthreads_flockfile")));
+void _IO_funlockfile (_IO_FILE *)
+ __attribute__ ((alias ("_cthreads_funlockfile")));
+int _IO_ftrylockfile (_IO_FILE *)
+ __attribute__ ((alias ("_cthreads_ftrylockfile")));
+
+void flockfile (_IO_FILE *)
+ __attribute__ ((alias ("_cthreads_flockfile")));
+void funlockfile (_IO_FILE *)
+ __attribute__ ((alias ("_cthreads_funlockfile")));
+int ftrylockfile (_IO_FILE *)
+ __attribute__ ((alias ("_cthreads_ftrylockfile")));
+
+#endif /* _STDIO_USES_IOSTREAM */
diff --git a/libpthread/not-in-libc.h b/libpthread/not-in-libc.h
new file mode 100644
index 00000000..516d4d13
--- /dev/null
+++ b/libpthread/not-in-libc.h
@@ -0,0 +1,11 @@
+#define __mach_port_insert_right mach_port_insert_right
+#define __mach_port_allocate mach_port_allocate
+#define __mig_init mig_init
+#define __thread_create thread_create
+#define __thread_get_state thread_get_state
+#define __thread_resume thread_resume
+#define __thread_set_state thread_set_state
+#define __thread_terminate thread_terminate
+#define __vm_allocate vm_allocate
+#define __vm_deallocate vm_deallocate
+#define __sched_yield sched_yield
diff --git a/libpthread/pt-yield.c b/libpthread/pt-yield.c
new file mode 100644
index 00000000..27848bb7
--- /dev/null
+++ b/libpthread/pt-yield.c
@@ -0,0 +1,26 @@
+/* Yield the processor to another thread or process.
+ Copyright (C) 2010 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <sched.h>
+
+int pthread_yield(void)
+{
+ return sched_yield ();
+}
diff --git a/libpthread/pthread/Versions b/libpthread/pthread/Versions
new file mode 100644
index 00000000..e4b4e8bf
--- /dev/null
+++ b/libpthread/pthread/Versions
@@ -0,0 +1,15 @@
+libc {
+ GLIBC_2.2 {
+ # XXX
+ __vm_deallocate; __mach_port_insert_right; __mach_reply_port;
+ __mig_init; __vm_allocate;
+
+ # functions used in inline functions or macros
+ __pthread_spin_destroy; __pthread_spin_init; __pthread_spin_lock;
+ _pthread_spin_lock; __pthread_spin_trylock; __pthread_spin_unlock;
+
+ # p*
+ pthread_spin_destroy; pthread_spin_init; pthread_spin_lock;
+ pthread_spin_trylock; pthread_spin_unlock;
+ }
+}
diff --git a/libpthread/pthread/cthreads-compat.c b/libpthread/pthread/cthreads-compat.c
new file mode 100644
index 00000000..cbe8170e
--- /dev/null
+++ b/libpthread/pthread/cthreads-compat.c
@@ -0,0 +1,107 @@
+/* Compatibility routines for cthreads.
+ Copyright (C) 2000, 2002, 2008 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <assert.h>
+#include <pthread.h>
+
+typedef void *cthread_t;
+typedef void *(*cthread_fn_t) (void *arg);
+typedef int cthread_key_t;
+
+#define CTHREAD_KEY_INVALID (cthread_key_t) -1
+
+void
+cthread_detach (cthread_t thread)
+{
+ int err;
+
+ err = pthread_detach ((pthread_t) thread);
+ assert_perror (err);
+}
+
+cthread_t
+cthread_fork (cthread_fn_t func, void *arg)
+{
+ pthread_t thread;
+ int err;
+
+ err = pthread_create (&thread, NULL, func, arg);
+ assert_perror (err);
+
+ return (cthread_t) thread;
+}
+
+int
+cthread_keycreate (cthread_key_t *key)
+{
+ error_t err;
+
+ err = pthread_key_create (key, 0);
+ if (err)
+ {
+ errno = err;
+ *key = CTHREAD_KEY_INVALID;
+ err = -1;
+ }
+
+ return err;
+}
+
+int
+cthread_getspecific (cthread_key_t key, void **val)
+{
+ *val = pthread_getspecific (key);
+ return 0;
+}
+
+void *
+__libc_getspecific (cthread_key_t key)
+{
+ return pthread_getspecific (key);
+}
+
+int
+cthread_setspecific (cthread_key_t key, void *val)
+{
+ error_t err;
+
+ err = pthread_setspecific (key, (const void *) val);
+ if (err)
+ {
+ errno = err;
+ err = -1;
+ }
+
+ return err;
+}
+
+void
+__mutex_lock_solid (void *lock)
+{
+ __pthread_mutex_lock (lock);
+}
+
+void
+__mutex_unlock_solid (void *lock)
+{
+ if (__pthread_spin_trylock (lock) != 0)
+ /* Somebody already got the lock, that one will manage waking up others */
+ return;
+ __pthread_mutex_unlock (lock);
+}
diff --git a/libpthread/pthread/pt-alloc.c b/libpthread/pthread/pt-alloc.c
new file mode 100644
index 00000000..6af2da92
--- /dev/null
+++ b/libpthread/pthread/pt-alloc.c
@@ -0,0 +1,215 @@
+/* Allocate a new thread structure.
+ Copyright (C) 2000, 2002, 2005, 2007, 2008 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <assert.h>
+#include <errno.h>
+#include <pthread.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <pt-internal.h>
+
+/* This braindamage is necessary because the standard says that some
+ of the threads functions "shall fail" if "No thread could be found
+ corresponding to that specified by the given thread ID." */
+
+/* Thread ID lookup table. */
+struct __pthread **__pthread_threads;
+
+/* The size of the thread ID lookup table. */
+int __pthread_max_threads;
+
+/* The total number of thread IDs currently in use, or on the list of
+ available thread IDs. */
+int __pthread_num_threads;
+
+/* A lock for the table, and the other variables above. */
+pthread_rwlock_t __pthread_threads_lock;
+
+/* List of thread structures corresponding to free thread IDs. */
+struct __pthread *__pthread_free_threads;
+pthread_mutex_t __pthread_free_threads_lock;
+
+static inline error_t
+initialize_pthread (struct __pthread *new, int recycling)
+{
+ error_t err;
+
+ err = __pthread_init_specific (new);
+ if (err)
+ return err;
+
+ new->cancel_state = PTHREAD_CANCEL_ENABLE;
+ new->cancel_type = PTHREAD_CANCEL_DEFERRED;
+ new->cancel_pending = 0;
+
+ if (recycling)
+ /* Since we are recycling PTHREAD, we can assume certains things
+ about PTHREAD's current state and save some cycles by not
+ rewriting the memory. */
+ return 0;
+
+ new->stack = 0;
+
+ new->state_lock = (pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER;
+ new->state_cond = (pthread_cond_t) PTHREAD_COND_INITIALIZER;
+
+ new->cancelation_handlers = 0;
+
+ new->next = 0;
+ new->prevp = 0;
+
+ return 0;
+}
+
+
+/* Allocate a new thread structure and its pthread thread ID (but not
+ a kernel thread). */
+int
+__pthread_alloc (struct __pthread **pthread)
+{
+ error_t err;
+
+ struct __pthread *new;
+ struct __pthread **threads;
+ struct __pthread **old_threads;
+ int max_threads;
+ int new_max_threads;
+
+ pthread_mutex_lock (&__pthread_free_threads_lock);
+ for (new = __pthread_free_threads; new; new = new->next)
+ {
+ /* There is no need to take NEW->STATE_LOCK: if NEW is on this
+ list, then it is protected by __PTHREAD_FREE_THREADS_LOCK
+ except in __pthread_dealloc where after it is added to the
+ list (with the lock held), it drops the lock and then sets
+ NEW->STATE and immediately stops using NEW. */
+ if (new->state == PTHREAD_TERMINATED)
+ {
+ __pthread_dequeue (new);
+ break;
+ }
+ }
+ pthread_mutex_unlock (&__pthread_free_threads_lock);
+
+ if (new)
+ {
+ /* The thread may still be running. Make sure it is stopped.
+ If this is the case, then the thread is either at the end of
+ __pthread_dealloc or in __pthread_thread_halt. In both
+ cases, we are interrupt it. */
+ __pthread_thread_halt (new);
+
+ err = initialize_pthread (new, 1);
+ if (! err)
+ *pthread = new;
+ return err;
+ }
+
+ /* Allocate a new thread structure. */
+ new = malloc (sizeof (struct __pthread));
+ if (new == NULL)
+ return ENOMEM;
+
+ err = initialize_pthread (new, 0);
+ if (err)
+ {
+ free (new);
+ return err;
+ }
+
+ retry:
+ pthread_rwlock_wrlock (&__pthread_threads_lock);
+
+ if (__pthread_num_threads < __pthread_max_threads)
+ {
+ /* We have a free slot. Use the slot number plus one as the
+ thread ID for the new thread. */
+ new->thread = 1 + __pthread_num_threads++;
+ __pthread_threads[new->thread - 1] = NULL;
+
+ pthread_rwlock_unlock (&__pthread_threads_lock);
+
+ *pthread = new;
+ return 0;
+ }
+#ifdef PTHREAD_THREADS_MAX
+ else if (__pthread_num_threads >= PTHREAD_THREADS_MAX)
+ {
+ /* We have reached the limit on the number of threads per process. */
+ pthread_rwlock_unlock (&__pthread_threads_lock);
+
+ free (new);
+ return EAGAIN;
+ }
+#endif
+
+ /* We are going to enlarge the threads table. Save its current
+ size. We're going to release the lock before doing the necessary
+ memory allocation, since that's a potentially blocking operation. */
+ max_threads = __pthread_max_threads;
+
+ pthread_rwlock_unlock (&__pthread_threads_lock);
+
+ /* Allocate a new lookup table that's twice as large. */
+ new_max_threads
+ = max_threads > 0 ? max_threads * 2 : _POSIX_THREAD_THREADS_MAX;
+ threads = malloc (new_max_threads * sizeof (struct __pthread *));
+ if (threads == NULL)
+ {
+ free (new);
+ return ENOMEM;
+ }
+
+ pthread_rwlock_wrlock (&__pthread_threads_lock);
+
+ /* Check if nobody else has already enlarged the table. */
+ if (max_threads != __pthread_max_threads)
+ {
+ /* Yep, they did. */
+ pthread_rwlock_unlock (&__pthread_threads_lock);
+
+ /* Free the newly allocated table and try again to allocate a slot. */
+ free (threads);
+ goto retry;
+ }
+
+ /* Copy over the contents of the old table. */
+ memcpy (threads, __pthread_threads,
+ __pthread_max_threads * sizeof (struct __pthread *));
+
+ /* Save the location of the old table. We want to deallocate its
+ storage after we released the lock. */
+ old_threads = __pthread_threads;
+
+ /* Replace the table with the new one. */
+ __pthread_max_threads = new_max_threads;
+ __pthread_threads = threads;
+
+ /* And allocate ourselves one of the newly created slots. */
+ new->thread = 1 + __pthread_num_threads++;
+ __pthread_threads[new->thread - 1] = NULL;
+
+ pthread_rwlock_unlock (&__pthread_threads_lock);
+
+ free (old_threads);
+
+ *pthread = new;
+ return 0;
+}
diff --git a/libpthread/pthread/pt-cancel.c b/libpthread/pthread/pt-cancel.c
new file mode 100644
index 00000000..d19c557d
--- /dev/null
+++ b/libpthread/pthread/pt-cancel.c
@@ -0,0 +1,40 @@
+/* Cancel a thread.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+
+#include <pt-internal.h>
+
+int
+pthread_cancel (pthread_t t)
+{
+ int err = 0;
+ struct __pthread *p;
+
+ p = __pthread_getid (t);
+ if (! p)
+ return ESRCH;
+
+ p->cancel_pending = 1;
+ if (p->cancel_state == PTHREAD_CANCEL_ENABLE
+ && p->cancel_type == PTHREAD_CANCEL_ASYNCHRONOUS)
+ err = __pthread_do_cancel (p);
+
+ return err;
+}
diff --git a/libpthread/pthread/pt-cleanup.c b/libpthread/pthread/pt-cleanup.c
new file mode 100644
index 00000000..58865aa4
--- /dev/null
+++ b/libpthread/pthread/pt-cleanup.c
@@ -0,0 +1,28 @@
+/* Add a cancelation handler to the stack.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+
+#include <pt-internal.h>
+
+struct __pthread_cancelation_handler **
+__pthread_get_cleanup_stack (void)
+{
+ return &_pthread_self ()->cancelation_handlers;
+}
diff --git a/libpthread/pthread/pt-create.c b/libpthread/pthread/pt-create.c
new file mode 100644
index 00000000..346c6979
--- /dev/null
+++ b/libpthread/pthread/pt-create.c
@@ -0,0 +1,217 @@
+/* Thread creation.
+ Copyright (C) 2000, 2002, 2005, 2007 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <assert.h>
+#include <errno.h>
+#include <pthread.h>
+#include <signal.h>
+
+#include <bits/atomic.h>
+
+#include <pt-internal.h>
+
+#ifdef HAVE_USELOCALE
+# include <locale.h>
+#endif
+
+/* The total number of pthreads currently active. This is defined
+ here since it would be really stupid to have a threads-using
+ program that doesn't call `pthread_create'. */
+__atomic_t __pthread_total;
+
+
+/* The entry-point for new threads. */
+static void
+entry_point (void *(*start_routine)(void *), void *arg)
+{
+#ifdef HAVE_USELOCALE
+ /* A fresh thread needs to be bound to the global locale. */
+ uselocale (LC_GLOBAL_LOCALE);
+#endif
+
+ __pthread_startup ();
+
+ pthread_exit (start_routine (arg));
+}
+
+/* Create a thread with attributes given by ATTR, executing
+ START_ROUTINE with argument ARG. */
+int
+pthread_create (pthread_t *thread, const pthread_attr_t *attr,
+ void *(*start_routine)(void *), void *arg)
+{
+ int err;
+ struct __pthread *pthread;
+
+ err = __pthread_create_internal (&pthread, attr, start_routine, arg);
+ if (! err)
+ *thread = pthread->thread;
+
+ return err;
+}
+
+/* Internal version of pthread_create. See comment in
+ pt-internal.h. */
+int
+__pthread_create_internal (struct __pthread **thread,
+ const pthread_attr_t *attr,
+ void *(*start_routine)(void *), void *arg)
+{
+ int err;
+ struct __pthread *pthread;
+ const struct __pthread_attr *setup;
+ sigset_t sigset;
+
+ /* Allocate a new thread structure. */
+ err = __pthread_alloc (&pthread);
+ if (err)
+ goto failed;
+
+ /* Use the default attributes if ATTR is NULL. */
+ setup = attr ? attr : &__pthread_default_attr;
+
+ /* Initialize the thread state. */
+ pthread->state = (setup->detachstate == PTHREAD_CREATE_DETACHED
+ ? PTHREAD_DETACHED : PTHREAD_JOINABLE);
+
+ /* If the user supplied a stack, it is not our responsibility to
+ setup a stack guard. */
+ if (setup->stackaddr)
+ pthread->guardsize = 0;
+ else
+ pthread->guardsize = (setup->guardsize <= setup->stacksize
+ ? setup->guardsize : setup->stacksize);
+
+ /* Find a stack. There are several scenarios: if a detached thread
+ kills itself, it has no way to deallocate its stack, thus it
+ leaves PTHREAD->stack set to true. We try to reuse it here,
+ however, if the user supplied a stack, we cannot use the old one.
+ Right now, we simply deallocate it. */
+ if (pthread->stack)
+ {
+ if (setup->stackaddr != __pthread_default_attr.stackaddr)
+ {
+ __pthread_stack_dealloc (pthread->stackaddr,
+ pthread->stacksize);
+ pthread->stackaddr = setup->stackaddr;
+ pthread->stacksize = setup->stacksize;
+ }
+ }
+ else
+ {
+ err = __pthread_stack_alloc (&pthread->stackaddr,
+ setup->stacksize);
+ if (err)
+ goto failed_stack_alloc;
+
+ pthread->stacksize = setup->stacksize;
+ pthread->stack = 1;
+ }
+
+ /* Allocate the kernel thread and other required resources. */
+ err = __pthread_thread_alloc (pthread);
+ if (err)
+ goto failed_thread_alloc;
+
+#ifdef ENABLE_TLS
+ pthread->tcb = _dl_allocate_tls (NULL);
+ if (!pthread->tcb)
+ goto failed_thread_tls_alloc;
+ pthread->tcb->tcb = pthread->tcb;
+#endif /* ENABLE_TLS */
+
+ /* And initialize the rest of the machine context. This may include
+ additional machine- and system-specific initializations that
+ prove convenient. */
+ err = __pthread_setup (pthread, entry_point, start_routine, arg);
+ if (err)
+ goto failed_setup;
+
+ /* Initialize the system-specific signal state for the new
+ thread. */
+ err = __pthread_sigstate_init (pthread);
+ if (err)
+ goto failed_sigstate;
+
+ /* Set the new thread's signal mask and set the pending signals to
+ empty. POSIX says: "The signal mask shall be inherited from the
+ creating thread. The set of signals pending for the new thread
+ shall be empty." If the currnet thread is not a pthread then we
+ just inherit the process' sigmask. */
+ if (__pthread_num_threads == 1)
+ err = sigprocmask (0, 0, &sigset);
+ else
+ err = __pthread_sigstate (_pthread_self (), 0, 0, &sigset, 0);
+ assert_perror (err);
+
+ err = __pthread_sigstate (pthread, SIG_SETMASK, &sigset, 0, 1);
+ assert_perror (err);
+
+ /* Increase the total number of threads. We do this before actually
+ starting the new thread, since the new thread might immediately
+ call `pthread_exit' which decreases the number of threads and
+ calls `exit' if the number of threads reaches zero. Increasing
+ the number of threads from within the new thread isn't an option
+ since this thread might return and call `pthread_exit' before the
+ new thread runs. */
+ __atomic_inc (&__pthread_total);
+
+ /* Store a pointer to this thread in the thread ID lookup table. We
+ could use __thread_setid, however, we only lock for reading as no
+ other thread should be using this entry (we also assume that the
+ store is atomic). */
+ pthread_rwlock_rdlock (&__pthread_threads_lock);
+ __pthread_threads[pthread->thread - 1] = pthread;
+ pthread_rwlock_unlock (&__pthread_threads_lock);
+
+ /* At this point it is possible to guess our pthread ID. We have to
+ make sure that all functions taking a pthread_t argument can
+ handle the fact that this thread isn't really running yet. */
+
+ /* Schedule the new thread. */
+ err = __pthread_thread_start (pthread);
+ if (err)
+ goto failed_starting;
+
+ /* At this point the new thread is up and running. */
+
+ *thread = pthread;
+
+ return 0;
+
+ failed_starting:
+ __pthread_setid (pthread->thread, NULL);
+ __atomic_dec (&__pthread_total);
+ failed_sigstate:
+ __pthread_sigstate_destroy (pthread);
+ failed_setup:
+#ifdef ENABLE_TLS
+ _dl_deallocate_tls (pthread->tcb, 1);
+ failed_thread_tls_alloc:
+#endif /* ENABLE_TLS */
+ __pthread_thread_dealloc (pthread);
+ __pthread_thread_halt (pthread);
+ failed_thread_alloc:
+ __pthread_stack_dealloc (pthread->stackaddr, pthread->stacksize);
+ pthread->stack = 0;
+ failed_stack_alloc:
+ __pthread_dealloc (pthread);
+ failed:
+ return err;
+}
diff --git a/libpthread/pthread/pt-dealloc.c b/libpthread/pthread/pt-dealloc.c
new file mode 100644
index 00000000..92fe1fda
--- /dev/null
+++ b/libpthread/pthread/pt-dealloc.c
@@ -0,0 +1,64 @@
+/* Deallocate a thread structure.
+ Copyright (C) 2000, 2008 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <assert.h>
+#include <pthread.h>
+#include <stdlib.h>
+
+#include <pt-internal.h>
+
+/* List of thread structures corresponding to free thread IDs. */
+extern struct __pthread *__pthread_free_threads;
+extern pthread_mutex_t __pthread_free_threads_lock;
+
+
+/* Deallocate the thread structure for PTHREAD. */
+void
+__pthread_dealloc (struct __pthread *pthread)
+{
+ assert (pthread->state != PTHREAD_TERMINATED);
+
+ /* Withdraw this thread from the thread ID lookup table. */
+ __pthread_setid (pthread->thread, NULL);
+
+ /* Mark the thread as terminated. We broadcast the condition
+ here to prevent pthread_join from waiting for this thread to
+ exit where it was never really started. Such a call to
+ pthread_join is completely bogus, but unfortunately allowed
+ by the standards. */
+ __pthread_mutex_lock (&pthread->state_lock);
+ if (pthread->state != PTHREAD_EXITED)
+ pthread_cond_broadcast (&pthread->state_cond);
+ __pthread_mutex_unlock (&pthread->state_lock);
+
+ /* We do not actually deallocate the thread structure, but add it to
+ a list of re-usable thread structures. */
+ pthread_mutex_lock (&__pthread_free_threads_lock);
+ __pthread_enqueue (&__pthread_free_threads, pthread);
+ pthread_mutex_unlock (&__pthread_free_threads_lock);
+
+ /* Setting PTHREAD->STATE to PTHREAD_TERMINATED makes this TCB
+ available for reuse. After that point, we can no longer assume
+ that PTHREAD is valid.
+
+ Note that it is safe to not lock this update to PTHREAD->STATE:
+ the only way that it can now be accessed is in __pthread_alloc,
+ which reads this variable. */
+ pthread->state = PTHREAD_TERMINATED;
+}
diff --git a/libpthread/pthread/pt-detach.c b/libpthread/pthread/pt-detach.c
new file mode 100644
index 00000000..1e42c452
--- /dev/null
+++ b/libpthread/pthread/pt-detach.c
@@ -0,0 +1,92 @@
+/* Detach a thread.
+ Copyright (C) 2000, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <errno.h>
+#include <pthread.h>
+#include <stddef.h>
+
+#include <pt-internal.h>
+
+/* Indicate that the storage for THREAD can be reclaimed when it
+ terminates. */
+int
+pthread_detach (pthread_t thread)
+{
+ struct __pthread *pthread;
+ int err = 0;
+
+ /* Lookup the thread structure for THREAD. */
+ pthread = __pthread_getid (thread);
+ if (pthread == NULL)
+ return ESRCH;
+
+ __pthread_mutex_lock (&pthread->state_lock);
+
+ switch (pthread->state)
+ {
+ case PTHREAD_JOINABLE:
+ /* THREAD still running. Mark it as detached such that its
+ resources can be reclaimed as soon as the thread exits. */
+ pthread->state = PTHREAD_DETACHED;
+
+ /* Broadcast the condition. This will make threads that are
+ waiting to join THREAD continue with hopefully disastrous
+ consequences instead of blocking indefinitely. */
+ pthread_cond_broadcast (&pthread->state_cond);
+ __pthread_mutex_unlock (&pthread->state_lock);
+ break;
+
+ case PTHREAD_EXITED:
+ /* THREAD has already exited. Make sure that nobody can
+ reference it anymore, and mark it as terminated. */
+
+ __pthread_mutex_unlock (&pthread->state_lock);
+
+ /* Make sure the thread is not running before we remove its
+ stack. (The only possibility is that it is in a call to
+ __pthread_thread_halt itself, but that is enough to cause a
+ sigsegv.) */
+ __pthread_thread_halt (pthread);
+
+ /* Destroy the stack, the kernel resources and the control
+ block. */
+ assert (pthread->stack);
+ __pthread_stack_dealloc (pthread->stackaddr, pthread->stacksize);
+ pthread->stack = 0;
+
+ __pthread_thread_dealloc (pthread);
+
+ __pthread_dealloc (pthread);
+ break;
+
+ case PTHREAD_TERMINATED:
+ /* Pretend THREAD wasn't there in the first place. */
+ __pthread_mutex_unlock (&pthread->state_lock);
+ err = ESRCH;
+ break;
+
+ default:
+ /* Thou shalt not detach non-joinable threads! */
+ __pthread_mutex_unlock (&pthread->state_lock);
+ err = EINVAL;
+ break;
+ }
+
+ return err;
+}
diff --git a/libpthread/pthread/pt-exit.c b/libpthread/pthread/pt-exit.c
new file mode 100644
index 00000000..c01efda0
--- /dev/null
+++ b/libpthread/pthread/pt-exit.c
@@ -0,0 +1,122 @@
+/* Thread termination.
+ Copyright (C) 2000, 2002, 2005, 2007, 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <assert.h>
+#include <errno.h>
+#include <pthread.h>
+#include <stdlib.h>
+
+#include <pt-internal.h>
+
+#include <bits/atomic.h>
+
+
+/* Terminate the current thread and make STATUS available to any
+ thread that might join it. */
+void
+pthread_exit (void *status)
+{
+ struct __pthread *self = _pthread_self ();
+ struct __pthread_cancelation_handler **handlers;
+ int oldstate;
+
+ /* Run any cancelation handlers. According to POSIX, the
+ cancellation cleanup handlers should be called with cancellation
+ disabled. */
+ pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, &oldstate);
+
+ for (handlers = __pthread_get_cleanup_stack ();
+ *handlers;
+ *handlers = (*handlers)->next)
+ (*handlers)->handler ((*handlers)->arg);
+
+ pthread_setcancelstate (oldstate, &oldstate);
+
+ /* Destory any thread specific data. */
+ __pthread_destroy_specific (self);
+
+ /* Destroy any signal state. */
+ __pthread_sigstate_destroy (self);
+
+ /* Decrease the number of threads. We use an atomic operation to
+ make sure that only the last thread calls `exit'. */
+ if (__atomic_dec_and_test (&__pthread_total))
+ /* We are the last thread. */
+ exit (0);
+
+ /* Note that after this point the process can be terminated at any
+ point if another thread calls `pthread_exit' and happens to be
+ the last thread. */
+
+ __pthread_mutex_lock (&self->state_lock);
+
+ if (self->cancel_state == PTHREAD_CANCEL_ENABLE && self->cancel_pending)
+ status = PTHREAD_CANCELED;
+
+#ifdef ENABLE_TLS
+ if (self->tcb)
+ _dl_deallocate_tls (self->tcb, 1);
+#endif /* ENABLE_TLS */
+
+ switch (self->state)
+ {
+ default:
+ assert (! "Consistency error: unexpected self->state");
+ abort ();
+ break;
+
+ case PTHREAD_DETACHED:
+ /* Make sure that nobody can reference this thread anymore, and
+ mark it as terminated. Our thread ID will immediately become
+ available for re-use. For obvious reasons, we cannot
+ deallocate our own stack. However, it will eventually be
+ reused when this thread structure is recycled. */
+ __pthread_mutex_unlock (&self->state_lock);
+
+ __pthread_dealloc (self);
+
+ break;
+
+ case PTHREAD_JOINABLE:
+ /* We need to stay around for a while since another thread
+ might want to join us. */
+ self->state = PTHREAD_EXITED;
+
+ /* We need to remember the exit status. A thread joining us
+ might ask for it. */
+ self->status = status;
+
+ /* Broadcast the condition. This will wake up threads that are
+ waiting to join us. */
+ pthread_cond_broadcast (&self->state_cond);
+ __pthread_mutex_unlock (&self->state_lock);
+
+ break;
+ }
+
+ /* Note that after this point the resources used by this thread can
+ be freed at any moment if another thread joins or detaches us.
+ This means that before freeing any resources, such a thread
+ should make sure that this thread is really halted. */
+
+ __pthread_thread_halt (self);
+
+ /* NOTREACHED */
+ abort ();
+}
diff --git a/libpthread/pthread/pt-getattr.c b/libpthread/pthread/pt-getattr.c
new file mode 100644
index 00000000..24599c6e
--- /dev/null
+++ b/libpthread/pthread/pt-getattr.c
@@ -0,0 +1,49 @@
+/* Thread attributes retrieval.
+ Copyright (C) 2008 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <assert.h>
+#include <errno.h>
+#include <pthread.h>
+
+#include <pt-internal.h>
+
+/* Initialize thread attribute *ATTR with attributes corresponding to the
+ already running thread THREAD. It shall be called on an uninitialized ATTR
+ and destroyed with pthread_attr_destroy when no longer needed. */
+int
+pthread_getattr_np (pthread_t thread, pthread_attr_t *attr)
+{
+ struct __pthread *pthread;
+
+ pthread = __pthread_getid(thread);
+ if (pthread == NULL)
+ return ESRCH;
+
+ /* Some attributes (schedparam, inheritsched, contentionscope and schedpolicy)
+ are not supported yet, so fill them with our default values. */
+ *attr = __pthread_default_attr;
+
+ attr->stackaddr = pthread->stackaddr;
+ attr->stacksize = pthread->stacksize;
+ attr->guardsize = pthread->guardsize;
+ attr->detachstate = (pthread->state == PTHREAD_DETACHED
+ ? PTHREAD_CREATE_DETACHED : PTHREAD_CREATE_JOINABLE);
+
+ return 0;
+}
diff --git a/libpthread/pthread/pt-initialize.c b/libpthread/pthread/pt-initialize.c
new file mode 100644
index 00000000..cf32b8b5
--- /dev/null
+++ b/libpthread/pthread/pt-initialize.c
@@ -0,0 +1,33 @@
+/* Initialize pthreads library.
+ Copyright (C) 2000,02 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <assert.h>
+#include <string.h>
+
+#include <pt-internal.h>
+#include <set-hooks.h>
+
+DEFINE_HOOK (__pthread_init, (void));
+
+/* Initialize the pthreads library. */
+void
+__pthread_initialize (void)
+{
+ RUN_HOOK (__pthread_init, ());
+}
diff --git a/libpthread/pthread/pt-internal.h b/libpthread/pthread/pt-internal.h
new file mode 100644
index 00000000..3f69d2dd
--- /dev/null
+++ b/libpthread/pthread/pt-internal.h
@@ -0,0 +1,317 @@
+/* Internal defenitions for pthreads library.
+ Copyright (C) 2000, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#ifndef _PT_INTERNAL_H
+#define _PT_INTERNAL_H 1
+
+#include <pthread.h>
+#include <stddef.h>
+#include <sched.h>
+#include <signal.h>
+#include <assert.h>
+
+#include <bits/atomic.h>
+
+#include <pt-key.h>
+
+#include <pt-sysdep.h>
+#include <pt-machdep.h>
+
+/* Thread state. */
+enum pthread_state
+{
+ /* The thread is running and joinable. */
+ PTHREAD_JOINABLE = 0,
+ /* The thread is running and detached. */
+ PTHREAD_DETACHED,
+ /* A joinable thread exited and its return code is available. */
+ PTHREAD_EXITED,
+ /* The thread structure is unallocated and available for reuse. */
+ PTHREAD_TERMINATED
+};
+
+#ifndef PTHREAD_KEY_MEMBERS
+# define PTHREAD_KEY_MEMBERS
+#endif
+
+#ifndef PTHREAD_SYSDEP_MEMBERS
+# define PTHREAD_SYSDEP_MEMBERS
+#endif
+
+#ifdef ENABLE_TLS
+/* Type of the TCB. */
+typedef struct
+{
+ void *tcb; /* Points to this structure. */
+ void *dtv; /* Vector of pointers to TLS data. */
+ thread_t self; /* This thread's control port. */
+} tcbhead_t;
+#endif /* ENABLE_TLS */
+
+/* This structure describes a POSIX thread. */
+struct __pthread
+{
+ /* Thread ID. */
+ pthread_t thread;
+
+ /* Cancellation. */
+ int cancel_state;
+ int cancel_type;
+ int cancel_pending;
+ struct __pthread_cancelation_handler *cancelation_handlers;
+
+ /* Thread stack. */
+ void *stackaddr;
+ size_t stacksize;
+ size_t guardsize; /* Included in STACKSIZE (i.e. total
+ stack memory is STACKSIZE, not
+ STACKSIZE + GUARDSIZE). */
+ int stack; /* Nonzero if the stack was allocated. */
+
+ /* Exit status. */
+ void *status;
+
+ /* Thread state. */
+ enum pthread_state state;
+ pthread_mutex_t state_lock; /* Locks the state. */
+ pthread_cond_t state_cond; /* Signalled when the state changes. */
+
+ /* Thread context. */
+ struct pthread_mcontext mcontext;
+
+ PTHREAD_KEY_MEMBERS
+
+ PTHREAD_SYSDEP_MEMBERS
+
+#ifdef ENABLE_TLS
+ tcbhead_t *tcb;
+#endif /* ENABLE_TLS */
+
+ struct __pthread *next, **prevp;
+};
+
+/* Enqueue an element THREAD on the queue *HEAD. */
+static inline void
+__pthread_enqueue (struct __pthread **head, struct __pthread *thread)
+{
+ assert (thread->prevp == 0);
+
+ thread->next = *head;
+ thread->prevp = head;
+ if (*head)
+ (*head)->prevp = &thread->next;
+ *head = thread;
+}
+
+/* Dequeue the element THREAD from the queue it is connected to. */
+static inline void
+__pthread_dequeue (struct __pthread *thread)
+{
+ assert (thread);
+
+ if (thread->next)
+ thread->next->prevp = thread->prevp;
+ *thread->prevp = thread->next;
+ thread->prevp = 0;
+}
+
+/* Iterate over QUEUE storing each element in ELEMENT. */
+#define __pthread_queue_iterate(queue, element) \
+ for (struct __pthread *__pdi_next = (queue); \
+ ((element) = __pdi_next) \
+ && ((__pdi_next = __pdi_next->next), \
+ 1); \
+ )
+
+/* Iterate over QUEUE dequeuing each element, storing it in
+ ELEMENT. */
+#define __pthread_dequeuing_iterate(queue, element) \
+ for (struct __pthread *__pdi_next = (queue); \
+ ((element) = __pdi_next) \
+ && ((__pdi_next = __pdi_next->next), \
+ ((element)->prevp = 0), \
+ 1); \
+ )
+
+/* The total number of threads currently active. */
+extern __atomic_t __pthread_total;
+
+/* The total number of thread IDs currently in use, or on the list of
+ available thread IDs. */
+extern int __pthread_num_threads;
+
+/* Concurrency hint. */
+extern int __pthread_concurrency;
+
+/* Array of __pthread structures and its lock. Indexed by the pthread
+ id minus one. (Why not just use the pthread id? Because some
+ brain-dead users of the pthread interface incorrectly assume that 0
+ is an invalid pthread id.) */
+extern struct __pthread **__pthread_threads;
+extern pthread_rwlock_t __pthread_threads_lock;
+
+#define __pthread_getid(thread) \
+ ({ struct __pthread *__t; \
+ pthread_rwlock_rdlock (&__pthread_threads_lock); \
+ __t = __pthread_threads[thread - 1]; \
+ pthread_rwlock_unlock (&__pthread_threads_lock); \
+ __t; })
+
+#define __pthread_setid(thread, pthread) \
+ pthread_rwlock_wrlock (&__pthread_threads_lock); \
+ __pthread_threads[thread - 1] = pthread; \
+ pthread_rwlock_unlock (&__pthread_threads_lock);
+
+/* Similar to pthread_self, but returns the thread descriptor instead
+ of the thread ID. */
+#ifndef _pthread_self
+extern struct __pthread *_pthread_self (void);
+#endif
+
+
+/* Initialize the pthreads library. */
+extern void __pthread_initialize (void);
+
+/* Internal version of pthread_create. Rather than return the new
+ tid, we return the whole __pthread structure in *PTHREAD. */
+extern int __pthread_create_internal (struct __pthread **__restrict pthread,
+ const pthread_attr_t *__restrict attr,
+ void *(*start_routine)(void *),
+ void *__restrict arg);
+
+/* Allocate a new thread structure and a pthread thread ID (but not a
+ kernel thread or a stack). */
+extern int __pthread_alloc (struct __pthread **thread);
+
+/* Deallocate the thread structure. This is the dual of
+ __pthread_alloc (N.B. it does not call __pthread_stack_alloc nor
+ __pthread_thread_halt). */
+extern void __pthread_dealloc (struct __pthread *thread);
+
+
+/* Allocate a stack of size STACKSIZE. The stack base shall be
+ returned in *STACKADDR. */
+extern int __pthread_stack_alloc (void **stackaddr, size_t stacksize);
+
+/* Deallocate the stack STACKADDR of size STACKSIZE. */
+extern void __pthread_stack_dealloc (void *stackaddr, size_t stacksize);
+
+
+/* Setup thread THREAD's context. */
+extern int __pthread_setup (struct __pthread *__restrict thread,
+ void (*entry_point)(void *(*)(void *),
+ void *),
+ void *(*start_routine)(void *),
+ void *__restrict arg);
+
+
+/* Allocate a kernel thread (and any miscellaneous system dependent
+ resources) for THREAD; it must not be placed on the run queue. */
+extern int __pthread_thread_alloc (struct __pthread *thread);
+
+/* Deallocate any kernel resources associated with THREAD. The thread
+ must not be running (that is, if __pthread_thread_start was called,
+ __pthread_thread_halt must first be called). This function will
+ never be called by a thread on itself. In the case that a thread
+ exits, its thread structure will be cached and cleaned up
+ later. */
+extern void __pthread_thread_dealloc (struct __pthread *thread);
+
+/* Start THREAD making it eligible to run. */
+extern int __pthread_thread_start (struct __pthread *thread);
+
+/* Stop the kernel thread associated with THREAD. This function may
+ be called by two threads in parallel. In particular, by the thread
+ itself and another thread trying to join it. This function must be
+ implemented such that this is safe. */
+extern void __pthread_thread_halt (struct __pthread *thread);
+
+
+/* Called by a thread just before it calls the provided start
+ routine. */
+extern void __pthread_startup (void);
+
+/* Block THREAD. */
+extern void __pthread_block (struct __pthread *thread);
+
+/* Block THREAD until *ABSTIME is reached. */
+extern error_t __pthread_timedblock (struct __pthread *__restrict thread,
+ const struct timespec *__restrict abstime);
+
+/* Wakeup THREAD. */
+extern void __pthread_wakeup (struct __pthread *thread);
+
+
+/* Perform a cancelation. */
+extern int __pthread_do_cancel (struct __pthread *thread);
+
+
+/* Initialize the thread specific data structures. THREAD must be the
+ calling thread. */
+extern error_t __pthread_init_specific (struct __pthread *thread);
+
+/* Call the destructors on all of the thread specific data in THREAD.
+ THREAD must be the calling thread. */
+extern void __pthread_destroy_specific (struct __pthread *thread);
+
+
+/* Initialize newly create thread *THREAD's signal state data
+ structures. */
+extern error_t __pthread_sigstate_init (struct __pthread *thread);
+
+/* Destroy the signal state data structures associcated with thread
+ *THREAD. */
+extern void __pthread_sigstate_destroy (struct __pthread *thread);
+
+/* Modify thread *THREAD's signal state. */
+extern error_t __pthread_sigstate (struct __pthread *__restrict thread, int how,
+ const sigset_t *__restrict set,
+ sigset_t *__restrict oset,
+ int clear_pending);
+
+
+/* Default thread attributes. */
+extern const struct __pthread_attr __pthread_default_attr;
+
+/* Default barrier attributes. */
+extern const struct __pthread_barrierattr __pthread_default_barrierattr;
+
+/* Default mutex attributes. */
+extern const struct __pthread_mutexattr __pthread_default_mutexattr;
+
+/* Default rdlock attributes. */
+const struct __pthread_rwlockattr __pthread_default_rwlockattr;
+
+/* Default condition attributes. */
+const struct __pthread_condattr __pthread_default_condattr;
+
+
+#ifdef ENABLE_TLS
+
+/* From glibc. */
+
+/* Dynamic linker TLS allocation. */
+extern void *_dl_allocate_tls(void *);
+
+/* Dynamic linker TLS deallocation. */
+extern void _dl_deallocate_tls(void *, int);
+
+#endif /* ENABLE_TLS */
+
+#endif /* pt-internal.h */
diff --git a/libpthread/pthread/pt-join.c b/libpthread/pthread/pt-join.c
new file mode 100644
index 00000000..153058b5
--- /dev/null
+++ b/libpthread/pthread/pt-join.c
@@ -0,0 +1,88 @@
+/* Wait for thread termination.
+ Copyright (C) 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <errno.h>
+#include <pthread.h>
+#include <stddef.h>
+
+#include <pt-internal.h>
+
+/* Make calling thread wait for termination of thread THREAD. Return
+ the exit status of the thread in *STATUS. */
+int
+pthread_join (pthread_t thread, void **status)
+{
+ struct __pthread *pthread;
+ int err = 0;
+
+ /* Lookup the thread structure for THREAD. */
+ pthread = __pthread_getid (thread);
+ if (pthread == NULL)
+ return ESRCH;
+
+ __pthread_mutex_lock (&pthread->state_lock);
+ pthread_cleanup_push ((void (*)(void *)) __pthread_mutex_unlock,
+ &pthread->state_lock);
+
+ while (pthread->state == PTHREAD_JOINABLE)
+ pthread_cond_wait (&pthread->state_cond, &pthread->state_lock);
+
+ pthread_cleanup_pop (0);
+
+ switch (pthread->state)
+ {
+ case PTHREAD_EXITED:
+ __pthread_mutex_unlock (&pthread->state_lock);
+
+ /* THREAD has already exited. Salvage its exit status. */
+ if (status)
+ *status = pthread->status;
+
+ /* Make sure the thread is not running before we remove its
+ stack. (The only possibility is that it is in a call to
+ __pthread_thread_halt itself, but that is enough to cause a
+ sigsegv.) */
+ __pthread_thread_halt (pthread);
+
+ /* Destroy the stack, the kernel resources and the control
+ block. */
+ assert (pthread->stack);
+ __pthread_stack_dealloc (pthread->stackaddr, pthread->stacksize);
+ pthread->stack = 0;
+
+ __pthread_thread_dealloc (pthread);
+
+ __pthread_dealloc (pthread);
+ break;
+
+ case PTHREAD_TERMINATED:
+ /* Pretend THREAD wasn't there in the first place. */
+ __pthread_mutex_unlock (&pthread->state_lock);
+ err = ESRCH;
+ break;
+
+ default:
+ /* Thou shalt not join non-joinable threads! */
+ __pthread_mutex_unlock (&pthread->state_lock);
+ err = EINVAL;
+ break;
+ }
+
+ return err;
+}
diff --git a/libpthread/pthread/pt-self.c b/libpthread/pthread/pt-self.c
new file mode 100644
index 00000000..49768643
--- /dev/null
+++ b/libpthread/pthread/pt-self.c
@@ -0,0 +1,32 @@
+/* Get calling thread's ID.
+ Copyright (C) 2000, 2008 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+
+#include <pt-internal.h>
+
+/* Return the thread ID of the calling thread. */
+pthread_t
+pthread_self (void)
+{
+ struct __pthread *self = _pthread_self ();
+ assert (self);
+
+ return self->thread;
+}
diff --git a/libpthread/pthread/pt-setcancelstate.c b/libpthread/pthread/pt-setcancelstate.c
new file mode 100644
index 00000000..e2d81833
--- /dev/null
+++ b/libpthread/pthread/pt-setcancelstate.c
@@ -0,0 +1,43 @@
+/* Set the cancel state for the calling thread.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+
+#include <pt-internal.h>
+
+int
+pthread_setcancelstate (int state, int *oldstate)
+{
+ struct __pthread *p = _pthread_self ();
+
+ switch (state)
+ {
+ default:
+ return EINVAL;
+ case PTHREAD_CANCEL_ENABLE:
+ case PTHREAD_CANCEL_DISABLE:
+ break;
+ }
+
+ if (oldstate)
+ *oldstate = p->cancel_state;
+ p->cancel_state = state;
+
+ return 0;
+}
diff --git a/libpthread/pthread/pt-setcanceltype.c b/libpthread/pthread/pt-setcanceltype.c
new file mode 100644
index 00000000..3ce4259c
--- /dev/null
+++ b/libpthread/pthread/pt-setcanceltype.c
@@ -0,0 +1,43 @@
+/* Set the cancel type for the calling thread.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+
+#include <pt-internal.h>
+
+int
+pthread_setcanceltype (int type, int *oldtype)
+{
+ struct __pthread *p = _pthread_self ();
+
+ switch (type)
+ {
+ default:
+ return EINVAL;
+ case PTHREAD_CANCEL_DEFERRED:
+ case PTHREAD_CANCEL_ASYNCHRONOUS:
+ break;
+ }
+
+ if (oldtype)
+ *oldtype = p->cancel_type;
+ p->cancel_type = type;
+
+ return 0;
+}
diff --git a/libpthread/pthread/pt-sigmask.c b/libpthread/pthread/pt-sigmask.c
new file mode 100644
index 00000000..1b53873e
--- /dev/null
+++ b/libpthread/pthread/pt-sigmask.c
@@ -0,0 +1,33 @@
+/* Get or set a thread's signal mask.
+ Copyright (C) 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <signal.h>
+
+#include <pt-internal.h>
+
+int
+pthread_sigmask (int how, const sigset_t *set,
+ sigset_t *oset)
+{
+ struct __pthread *self = _pthread_self ();
+
+ /* Do not clear SELF's pending signals. */
+ return __pthread_sigstate (self, how, set, oset, 0);
+}
diff --git a/libpthread/pthread/pt-spin-inlines.c b/libpthread/pthread/pt-spin-inlines.c
new file mode 100644
index 00000000..cfb21dd3
--- /dev/null
+++ b/libpthread/pthread/pt-spin-inlines.c
@@ -0,0 +1,34 @@
+/* Copyright (C) 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+/* <bits/spin-lock.h> declares some extern inline functions. These
+ functions are declared additionally here for use when inlining is
+ not possible. */
+
+#define _FORCE_INLINES
+#define __PT_SPIN_INLINE /* empty */
+
+#include <pthread.h>
+
+/* Weak aliases for the spin lock functions. Note that
+ pthread_spin_lock is left out deliberately. We already provide an
+ implementation for it in pt-spin.c. */
+weak_alias (__pthread_spin_destroy, pthread_spin_destroy);
+weak_alias (__pthread_spin_init, pthread_spin_init);
+weak_alias (__pthread_spin_trylock, pthread_spin_trylock);
+weak_alias (__pthread_spin_unlock, pthread_spin_unlock);
diff --git a/libpthread/pthread/pt-testcancel.c b/libpthread/pthread/pt-testcancel.c
new file mode 100644
index 00000000..01f1ac9c
--- /dev/null
+++ b/libpthread/pthread/pt-testcancel.c
@@ -0,0 +1,31 @@
+/* Add an explicit cancelation point.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+
+#include <pt-internal.h>
+
+void
+pthread_testcancel (void)
+{
+ struct __pthread *p = _pthread_self ();
+
+ if (p->cancel_state == PTHREAD_CANCEL_ENABLE && p->cancel_pending)
+ pthread_exit (PTHREAD_CANCELED);
+}
diff --git a/libpthread/signal/README b/libpthread/signal/README
new file mode 100644
index 00000000..5487e2e3
--- /dev/null
+++ b/libpthread/signal/README
@@ -0,0 +1,4 @@
+This directory provides a signal implementation, which is appropriate
+for operating systems where signals are managed at user-level. It is
+up to the run-time to catch the signals and forward them to the
+implementation via, e.g., the pthread_kill_info_np call.
diff --git a/libpthread/signal/TODO b/libpthread/signal/TODO
new file mode 100644
index 00000000..1148abb3
--- /dev/null
+++ b/libpthread/signal/TODO
@@ -0,0 +1,29 @@
+Unimplemented Functionality
+---------------------------
+
+We don't support interruptible functions. That is, if a signal is
+delivered when a thread is in e.g. the write system call, then the
+write function should be interrupted and return EINTR when the signal
+handler is finished. To realize this behavior, we could have a thread
+local interruptible flag and a setjmp buffer. A function that is
+interruptible would fill the jump buffer and set the interruptible
+flag. If a signal comes in and the interruptible flag is set, rather
+than resuming the thread, we longjmp to the buffer.
+
+If a signal action has set the SA_SIGINFO, the third argument must be
+a pointer to a ucontext describing the thread's interrupted state;
+this implementation passes NULL. This isn't as bad as it sounds as
+the the ucontext family of functions are marked obsolete in SUSv3 with
+the advisory that any use of them should be replaced by the use of
+pthread functionality (cf. makecontext rationale).
+
+stop and continue signals are not implemented (as we need to stop all
+threads, this requires being in bed with libpthread).
+
+Implementation is not yet cancellation-safe.
+
+There are not even stubs for sighold, sigingore, sigpause, sigrelse,
+however, according to posix: "Use of any of these functions is
+unspecified in a multi-threaded process."
+
+Implement sigtimedwait, sigqueue. \ No newline at end of file
diff --git a/libpthread/signal/kill.c b/libpthread/signal/kill.c
new file mode 100644
index 00000000..27c9c32a
--- /dev/null
+++ b/libpthread/signal/kill.c
@@ -0,0 +1,70 @@
+/* kill.c - Generic kill implementation.
+ Copyright (C) 2008 Free Software Foundation, Inc.
+ Written by Neal H. Walfield <neal@gnu.org>.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public License
+ as published by the Free Software Foundation; either version 3 of
+ the License, or (at your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this program. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include "sig-internal.h"
+
+int
+kill (pid_t pid, int signo)
+{
+ if (pid != getpid ())
+ {
+ errno = EOPNOTSUPP;
+ return -1;
+ }
+
+ /* "Signals generated for the process shall be delivered to exactly
+ one of those threads within the process which is in a call to a
+ sigwait() function selecting that signal or has not blocked
+ delivery of the signal. If there are no threads in a call to a
+ sigwait() function selecting that signal, and if all threads
+ within the process block delivery of the signal, the signal shall
+ remaing pending on the process" (2.4.1). */
+
+ /* First, see if there is a waiter, which is interested in this
+ signal. */
+ pthread_mutex_lock (&sig_lock);
+
+ struct sigwaiter *waiter;
+ for (waiter = sigwaiters; waiter; waiter = waiter->next)
+ if ((waiter->signals & sigmask (signo)))
+ /* Got a winner. */
+ {
+ sigdelset (&process_pending, signo);
+
+ pthread_mutex_lock (&waiter->ss->lock);
+ sigdelset (&waiter->ss->pending, signo);
+
+ memset (&waiter->info, 0, sizeof (waiter->info));
+ waiter->info.si_signo = signo;
+
+ sigwaiter_unblock (waiter);
+
+ return 0;
+ }
+
+ pthread_mutex_unlock (&sig_lock);
+
+ /* XXX: We just generate the signal for the current thread. If the
+ current thread has blocked the signal, the correct thing to do is
+ to iterate over all the other threads and find on that hasn't
+ blocked it. */
+ return pthread_kill (pthread_self (), signo);
+}
+
diff --git a/libpthread/signal/pt-kill-siginfo-np.c b/libpthread/signal/pt-kill-siginfo-np.c
new file mode 100644
index 00000000..9bdf6cc4
--- /dev/null
+++ b/libpthread/signal/pt-kill-siginfo-np.c
@@ -0,0 +1,88 @@
+/* pthread-kill-siginfo-np.c - Generic pthread_kill_siginfo_np implementation.
+ Copyright (C) 2008 Free Software Foundation, Inc.
+ Written by Neal H. Walfield <neal@gnu.org>.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public License
+ as published by the Free Software Foundation; either version 3 of
+ the License, or (at your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this program. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include "pt-internal.h"
+#include "sig-internal.h"
+
+int
+pthread_kill_siginfo_np (pthread_t tid, siginfo_t si)
+{
+ int sig = si.si_signo;
+
+ if (sig < 0 || sig >= NSIG)
+ return EINVAL;
+
+ if (sig == 0)
+ return 0;
+
+ struct signal_state *ss = &__pthread_getid (tid)->ss;
+
+ pthread_mutex_lock (&sig_lock);
+ pthread_mutex_lock (&ss->lock);
+
+ if (ss->sigwaiter && (ss->sigwaiter->signals & sigmask (si.si_signo)))
+ /* The thread is in a call to sigwait. */
+ {
+ ss->sigwaiter->info = si;
+ sigwaiter_unblock (ss->sigwaiter);
+ return 0;
+ }
+
+ pthread_mutex_unlock (&sig_lock);
+
+ if (ss->actions[sig - 1].sa_handler == (void *) SIG_IGN
+ || (ss->actions[sig - 1].sa_handler == (void *) SIG_DFL
+ && default_action (sig) == sig_ignore))
+ /* It is unclear (to me) what is supposed to happen when a signal
+ is generated for a thread, which is blocking that signal and
+ ignoring it. POSIX does say that when the action associated
+ with a pending, blocked signal is set to SIG_IGN, the pending
+ signal is to be cleared. Thus, it makes sense that any signal
+ set to ignore is discarded at generation. */
+ {
+ pthread_mutex_unlock (&ss->lock);
+ return 0;
+ }
+
+
+ if ((sigmask (sig) & ss->blocked))
+ /* The signal is blocked. Mark it pending. */
+ {
+ ss->pending |= sigmask (sig);
+ pthread_mutex_unlock (&ss->lock);
+ return 0;
+ }
+
+ if (pthread_self () == tid
+ && (! (ss->actions[si.si_signo - 1].sa_flags & SA_ONSTACK)
+ || (ss->stack.ss_flags & SS_DISABLE)
+ || (ss->stack.ss_flags & SS_ONSTACK)))
+ /* We are sending a signal to ourself and we don't use an
+ alternate stack. */
+ signal_dispatch (ss, &si);
+ else
+ signal_dispatch_lowlevel (ss, tid, si);
+
+ /* Don't unlock ss: signal_dispatch and signal_dispatch_lowlevel
+ assume ownership of the lock. */
+
+ return 0;
+}
+
diff --git a/libpthread/signal/sig-internal.c b/libpthread/signal/sig-internal.c
new file mode 100644
index 00000000..f73f38b4
--- /dev/null
+++ b/libpthread/signal/sig-internal.c
@@ -0,0 +1,26 @@
+/* sig-internal.c - Signal state functions.
+ Copyright (C) 2008 Free Software Foundation, Inc.
+ Written by Neal H. Walfield <neal@gnu.org>.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public License
+ as published by the Free Software Foundation; either version 3 of
+ the License, or (at your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this program. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include "sig-internal.h"
+
+pthread_mutex_t sig_lock = PTHREAD_MUTEX_INITIALIZER;
+
+sigset_t process_pending;
+siginfo_t process_pending_info[NSIG];
diff --git a/libpthread/signal/sig-internal.h b/libpthread/signal/sig-internal.h
new file mode 100644
index 00000000..6c86c796
--- /dev/null
+++ b/libpthread/signal/sig-internal.h
@@ -0,0 +1,177 @@
+/* sig-internal.h - Internal signal handling interface.
+ Copyright (C) 2008 Free Software Foundation, Inc.
+ Written by Neal H. Walfield <neal@gnu.org>.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public License
+ as published by the Free Software Foundation; either version 3 of
+ the License, or (at your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this program. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#ifndef SIG_INTERNAL_H
+#define SIG_INTERNAL_H
+
+#include <signal.h>
+
+#include <sig-sysdep.h>
+
+#define sigmask(sig) (1ULL << (sig - 1))
+#define STOPSIGS (sigmask (SIGTTIN) | sigmask (SIGTTOU) | \
+ sigmask (SIGSTOP) | sigmask (SIGTSTP))
+
+/* General lock. Protects PROCESS_PENDING, PROCESS_PENDING_INFO,
+ SIGWAITERS. */
+extern pthread_mutex_t sig_lock;
+
+/* "Signals generated for the process shall be delivered to exactly
+ one of those threads within the process which is in a call to a
+ sigwait() function selecting that signal or has not blocked
+ delivery of the signal. If there are no threads in a call to a
+ sigwait() function selecting that signal, and if all threads within
+ the process block delivery of the signal, the signal shall remaing
+ pending on the process" (2.4.1).
+
+ This variable is protected by SIG_LOCK. */
+extern sigset_t process_pending;
+extern siginfo_t process_pending_info[NSIG];
+
+struct sigwaiter;
+
+/* The per-thread signal state. */
+struct signal_state
+{
+ /* Protects the following fields. STACK.SA_FLAGS may be accessed
+ using atomic operations. */
+ pthread_mutex_t lock;
+
+ /* Pending signals. */
+ sigset_t pending;
+
+ /* Blocked signals (i.e., the signal mask). */
+ sigset_t blocked;
+
+ stack_t stack;
+ struct sigaction actions[NSIG];
+ siginfo_t info[NSIG];
+
+ /* If the thread is blocked in a call to sigwait. */
+ struct sigwaiter *sigwaiter;
+};
+
+#define PTHREAD_SIGNAL_MEMBERS struct signal_state ss;
+
+/* Arranges for thread TID to call signal_dispatch. Must not be
+ called if TID is the caller and an alternate stack is not required.
+ In this case, the caller should call signal_dispatch directly. */
+extern void signal_dispatch_lowlevel (struct signal_state *ss,
+ pthread_t tid, siginfo_t si);
+
+/* This is the signal handler entry point. A thread is forced into
+ this state when it receives a signal. We need to save the thread's
+ state and then invoke the high-level signal dispatcher. SS->LOCK
+ is locked by the caller. */
+extern void signal_dispatch (struct signal_state *ss, siginfo_t *si);
+
+#ifndef SIGNAL_DISPATCH_ENTRY
+#define SIGNAL_DISPATCH_ENTRY
+#endif
+
+#ifndef SIGNAL_DISPATCH_EXIT
+#define SIGNAL_DISPATCH_EXIT
+#endif
+
+/* When a thread calls sigwait and a requested signal is not pending,
+ it allocates the following structure, fills it in, adds it to
+ sigwaiters and sleeps. */
+struct sigwaiter
+{
+ struct sigwaiter *next;
+ struct sigwaiter *prev;
+
+ /* Thread's signal state. */
+ struct signal_state *ss;
+
+ /* Signals this thread is waiting for. */
+ sigset_t signals;
+
+ /* The selected signal is returned here. The waiter also
+ futex_waits on this info.si_signo. */
+ siginfo_t info;
+};
+
+/* This variable is protected by SIG_LOCK. */
+extern struct sigwaiter *sigwaiters;
+
+/* Block the caller waiting for a signal in set SET. SIG_LOCK and
+ SS->LOCK must be held and will be unlocked by this function before
+ blocking. */
+extern siginfo_t sigwaiter_block (struct signal_state *ss,
+ const sigset_t *restrict set);
+
+/* Unblock the waiter WAITER. SIG_LOCK and WAITER->SS->LOCK must be
+ held. Both will be dropped on return. */
+extern void sigwaiter_unblock (struct sigwaiter *waiter);
+
+enum sig_action { sig_core, sig_terminate, sig_ignore, sig_cont, sig_stop };
+
+static inline enum sig_action
+default_action (int signo)
+{
+ switch (signo)
+ {
+ case SIGABRT:
+ case SIGBUS:
+ case SIGFPE:
+ case SIGILL:
+ case SIGQUIT:
+ case SIGSEGV:
+ case SIGSTKFLT:
+ case SIGSYS:
+ case SIGTRAP:
+ case SIGXCPU:
+ case SIGXFSZ:
+ return sig_core;
+
+ case SIGALRM:
+ case SIGHUP:
+ case SIGINT:
+ case SIGIO: /* Perhaps ignore? */
+ case SIGKILL:
+ case SIGPIPE:
+ case SIGPROF:
+ case SIGTERM:
+ case SIGUSR1:
+ case SIGUSR2:
+ case SIGVTALRM:
+ return sig_terminate;
+
+ case SIGCHLD:
+ case SIGPWR:
+ case SIGURG:
+ case SIGWINCH:
+ return sig_ignore;
+
+ case SIGCONT:
+ return sig_cont;
+
+ case SIGSTOP:
+ case SIGTSTP:
+ case SIGTTIN:
+ case SIGTTOU:
+ return sig_stop;
+ }
+
+ panic ("Unknown signal number: %d", signo);
+}
+
+#endif
diff --git a/libpthread/signal/sigaction.c b/libpthread/signal/sigaction.c
new file mode 100644
index 00000000..0126c99d
--- /dev/null
+++ b/libpthread/signal/sigaction.c
@@ -0,0 +1,72 @@
+/* sigaction.c - Generic sigaction implementation.
+ Copyright (C) 2008 Free Software Foundation, Inc.
+ Written by Neal H. Walfield <neal@gnu.org>.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public License
+ as published by the Free Software Foundation; either version 3 of
+ the License, or (at your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this program. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include "sig-internal.h"
+#include "pt-internal.h"
+
+int
+sigaction (int sig, const struct sigaction *restrict sa,
+ struct sigaction *restrict osa)
+{
+ if (sig <= 0 || sig >= NSIG)
+ {
+ errno = EINVAL;
+ return -1;
+ }
+
+ struct signal_state *ss = &_pthread_self ()->ss;
+
+ pthread_mutex_lock (&ss->lock);
+
+ if (osa)
+ *osa = ss->actions[sig - 1];
+
+ if (sa)
+ {
+ ss->actions[sig - 1] = *sa;
+
+ /* "The SIGKILL and SIGSTOP signals shall not be added to the
+ signal mask using this mechanism; this restriction shall be
+ enforced by the system without causing an error to be
+ indicated" (sigaction). */
+ sigdelset (&ss->blocked, SIGKILL);
+ sigdelset (&ss->blocked, SIGSTOP);
+
+ /* A "signal shall remain pending on the process until it is
+ unblocked, it is accepted when ..., or the action associated
+ with it is set to ignore the signal" (2.4.1).
+
+ "Setting a signal action to SIG_DFL for a signal that is
+ pending, and whose default action is to ignore the signal,
+ ..., shall cause the pending signal to be discarded, whether
+ or not it is blocked" (2.4.3). */
+ if (sa->sa_handler == SIG_IGN
+ || (sa->sa_handler == SIG_DFL && default_action (sig) == sig_ignore))
+ {
+ sigdelset (&ss->pending, sig);
+ sigdelset (&process_pending, sig);
+ }
+ }
+
+ pthread_mutex_unlock (&ss->lock);
+
+ return 0;
+}
+
diff --git a/libpthread/signal/sigaltstack.c b/libpthread/signal/sigaltstack.c
new file mode 100644
index 00000000..8334811a
--- /dev/null
+++ b/libpthread/signal/sigaltstack.c
@@ -0,0 +1,69 @@
+/* sigaltstack.c - Generic sigaltstack implementation.
+ Copyright (C) 2008 Free Software Foundation, Inc.
+ Written by Neal H. Walfield <neal@gnu.org>.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public License
+ as published by the Free Software Foundation; either version 3 of
+ the License, or (at your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this program. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include "sig-internal.h"
+#include "pt-internal.h"
+
+int
+sigaltstack (const stack_t *restrict stack, stack_t *restrict old)
+{
+ int err = 0;
+ struct signal_state *ss = &_pthread_self ()->ss;
+
+ pthread_mutex_lock (&ss->lock);
+
+ if (old)
+ *old = ss->stack;
+
+ if (stack)
+ {
+ if (stack->ss_size < MINSIGSTKSZ)
+ {
+ err = ENOMEM;
+ goto out;
+ }
+
+ if ((stack->ss_flags & ~(SS_DISABLE)))
+ /* Flags contains a value other than SS_DISABLE. */
+ {
+ err = EINVAL;
+ goto out;
+ }
+
+ if ((ss->stack.ss_flags & SS_ONSTACK))
+ /* Stack in use. */
+ {
+ err = EPERM;
+ goto out;
+ }
+
+ ss->stack = *stack;
+ }
+
+ out:
+ pthread_mutex_unlock (&ss->lock);
+
+ if (err)
+ {
+ errno = err;
+ return -1;
+ }
+ return 0;
+}
diff --git a/libpthread/signal/signal-dispatch.c b/libpthread/signal/signal-dispatch.c
new file mode 100644
index 00000000..40440b70
--- /dev/null
+++ b/libpthread/signal/signal-dispatch.c
@@ -0,0 +1,117 @@
+/* signal-dispatch.c - Signal dispatcher.
+ Copyright (C) 2008 Free Software Foundation, Inc.
+ Written by Neal H. Walfield <neal@gnu.org>.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public License
+ as published by the Free Software Foundation; either version 3 of
+ the License, or (at your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this program. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include "sig-internal.h"
+
+/* This is the signal handler entry point. A thread is forced into
+ this state when it receives a signal. We need to save the thread's
+ state and then invoke the high-level signal dispatcher. SS->LOCK
+ is locked by the caller. */
+void
+signal_dispatch (struct signal_state *ss, siginfo_t *si)
+{
+ SIGNAL_DISPATCH_ENTRY;
+
+ int signo = si->si_signo;
+
+ assert (signo > 0 && signo < NSIG);
+ assert (pthread_mutex_trylock (&ss->lock) == EBUSY);
+
+ do
+ {
+ if ((sigmask (signo) & STOPSIGS))
+ /* Stop signals clear a pending SIGCONT even if they
+ are handled or ignored (but not if preempted). */
+ {
+ sigdelset (&ss->pending, SIGCONT);
+ sigdelset (&process_pending, SIGCONT);
+ }
+ else if ((signo == SIGCONT))
+ /* Even if handled or ignored (but not preempted), SIGCONT
+ clears stop signals and resumes the process. */
+ {
+ ss->pending &= ~STOPSIGS;
+ process_pending &= ~STOPSIGS;
+ }
+
+ void (*handler)(int, siginfo_t *, void *)
+ = ss->actions[signo - 1].sa_sigaction;
+
+ /* Reset to SIG_DFL if requested. SIGILL and SIGTRAP cannot
+ be automatically reset when delivered; the system silently
+ enforces this restriction (sigaction). */
+ if (ss->actions[signo - 1].sa_flags & SA_RESETHAND
+ && signo != SIGILL && signo != SIGTRAP)
+ ss->actions[signo - 1].sa_handler = SIG_DFL;
+
+ sigset_t orig_blocked = ss->blocked;
+ /* Block requested signals while running the handler. */
+ ss->blocked |= ss->actions[signo - 1].sa_mask;
+
+ /* Block SIGNO unless we're asked not to. */
+ if (! (ss->actions[signo - 1].sa_flags & (SA_RESETHAND | SA_NODEFER)))
+ sigaddset (&ss->blocked, signo);
+
+ sigdelset (&ss->pending, signo);
+ pthread_mutex_unlock (&ss->lock);
+
+ pthread_mutex_lock (&sig_lock);
+ sigdelset (&process_pending, signo);
+ pthread_mutex_unlock (&sig_lock);
+
+ if (handler == (void *) SIG_DFL)
+ {
+ enum sig_action action = default_action (signo);
+
+ if (action == sig_terminate || action == sig_core)
+ _exit (128 + signo);
+
+ if (action == sig_stop)
+ /* XXX: Implement me. */
+ panic ("Stopping process unimplemented.");
+
+ if (action == sig_cont)
+ /* XXX: Implement me. */;
+ panic ("Continuing process unimplemented.");
+ }
+ else if (handler == (void *) SIG_IGN)
+ ;
+ else
+ handler (signo, si, NULL);
+
+ pthread_mutex_lock (&ss->lock);
+
+ /* "When a thread's signal mask is changed in a signal-catching
+ function that is installed by sigaction(), the restoration of
+ the signal mask on return from the signal-catching function
+ overrides that change (see sigaction())" (sigprocmask). */
+ ss->blocked = orig_blocked;
+
+ sigset_t pending = ~ss->blocked & ss->pending;
+ if (! pending)
+ pending = ~ss->blocked & process_pending;
+ signo = l4_lsb64 (pending);
+ }
+ while (signo);
+
+ pthread_mutex_unlock (&ss->lock);
+
+ SIGNAL_DISPATCH_EXIT;
+}
diff --git a/libpthread/signal/signal.h b/libpthread/signal/signal.h
new file mode 100644
index 00000000..a33d995c
--- /dev/null
+++ b/libpthread/signal/signal.h
@@ -0,0 +1,275 @@
+/* signal.h - Signal handling interface.
+ Copyright (C) 2008 Free Software Foundation, Inc.
+ Written by Neal H. Walfield <neal@gnu.org>.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public License
+ as published by the Free Software Foundation; either version 3 of
+ the License, or (at your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this program. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#ifndef _SIGNAL_H
+#define _SIGNAL_H 1
+
+#include <stdint.h>
+#include <sys/types.h>
+
+typedef volatile int sig_atomic_t;
+
+typedef uint64_t sigset_t;
+
+int sigaddset (sigset_t *, int);
+int sigdelset (sigset_t *, int);
+int sigemptyset (sigset_t *);
+int sigfillset (sigset_t *);
+int sigismember (const sigset_t *, int);
+
+/* These values are consistent with Linux. */
+#define SIGRTMIN 34
+#define SIGRTMAX 64
+
+enum
+ {
+ SIGHUP = 1,
+#define SIGHUP SIGHUP
+ SIGINT,
+#define SIGINT SIGINT
+ SIGQUIT,
+#define SIGQUIT SIGQUIT
+ SIGILL,
+#define SIGILL SIGILL
+ SIGTRAP,
+#define SIGTRAP SIGTRAP
+ SIGABRT,
+#define SIGABRT SIGABRT
+ SIGBUS,
+#define SIGBUS SIGBUS
+ SIGFPE,
+#define SIGFPE SIGFPE
+ SIGKILL,
+#define SIGKILL SIGKILL
+ SIGUSR1,
+#define SIGUSR1 SIGUSR1
+ SIGSEGV,
+#define SIGSEGV SIGSEGV
+ SIGUSR2,
+#define SIGUSR2 SIGUSR2
+ SIGPIPE,
+#define SIGPIPE SIGPIPE
+ SIGALRM,
+#define SIGALRM SIGALRM
+ SIGTERM,
+#define SIGTERM SIGTERM
+ SIGSTKFLT,
+#define SIGSTKFLT SIGSTKFLT
+ SIGCHLD,
+#define SIGCHLD SIGCHLD
+ SIGCONT,
+#define SIGCONT SIGCONT
+ SIGSTOP,
+#define SIGSTOP SIGSTOP
+ SIGTSTP,
+#define SIGTSTP SIGTSTP
+ SIGTTIN,
+#define SIGTTIN SIGTTIN
+ SIGTTOU,
+#define SIGTTOU SIGTTOU
+ SIGURG,
+#define SIGURG SIGURG
+ SIGXCPU,
+#define SIGXCPU SIGXCPU
+ SIGXFSZ,
+#define SIGXFSZ SIGXFSZ
+ SIGVTALRM,
+#define SIGVTALRM SIGVTALRM
+ SIGPROF,
+#define SIGPROF SIGPROF
+ SIGWINCH,
+#define SIGWINCH SIGWINCH
+ SIGIO,
+#define SIGIO SIGIO
+ SIGPWR,
+#define SIGPWR SIGPWR
+ SIGSYS,
+#define SIGSYS SIGSYS
+ NSIG
+ };
+
+/* The resulting set is the union of the current set and the signal
+ set pointed to by the argument set. */
+#define SIG_BLOCK 1
+/* The resulting set is the intersection of the current set and the
+ complement of the signal set pointed to by the argument set. */
+#define SIG_UNBLOCK 2
+/* The resulting set is the signal set pointed to by the argument
+ set. */
+#define SIG_SETMASK 3
+
+int pthread_sigmask (int how, const sigset_t *mask, sigset_t *old);
+int sigprocmask (int how, const sigset_t *restrict mask,
+ sigset_t *restrict old);
+
+/* Return set of pending signals. */
+int sigpending(sigset_t *set);
+
+union sigval
+{
+ int sival_int;
+ void *sival_ptr;
+};
+
+#define SIG_DFL ((void (*)(int)) (0))
+#define SIG_ERR ((void (*)(int)) (-1))
+#define SIG_IGN ((void (*)(int)) (1))
+
+/* Causes signal delivery to occur on an alternate stack. */
+#define SA_ONSTACK (1 << 0)
+/* Do not generate SIGCHLD when children stop or stopped children
+ continue. */
+#define SA_NOCLDSTOP (1 << 1)
+/* Causes signal dispositions to be set to SIG_DFL on entry to signal
+ handlers. */
+#define SA_RESETHAND (1 << 2)
+/* Causes certain functions to become restartable. */
+#define SA_RESTART (1 << 3)
+/* Causes extra information to be passed to signal handlers at the
+ time of receipt of a signal. */
+#define SA_SIGINFO (1 << 4)
+/* Causes implementations not to create zombie processes on child
+ death. */
+#define SA_NOCLDWAIT (1 << 5)
+/* Causes signal not to be automatically blocked on entry to
+ signal handler. */
+#define SA_NODEFER (1 << 6)
+
+typedef struct
+{
+ int si_signo;
+ int si_code;
+ int si_errno;
+ pid_t si_pid;
+ uid_t si_uid;
+ void *si_addr;
+ int si_status;
+ long si_band;
+ union sigval si_value;
+} siginfo_t;
+
+struct sigaction
+{
+ union
+ {
+ /* Pointer to a signal-catching function or one of the macros
+ SIG_IGN or SIG_DFL. */
+ void (*sa_handler)(int);
+
+ /* Pointer to a signal-catching function. */
+ void (*sa_sigaction)(int, siginfo_t *, void *);
+ };
+
+ /* Set of signals to be blocked during execution of the signal
+ handling function. */
+ sigset_t sa_mask;
+
+ /* Special flags. */
+ int sa_flags;
+};
+
+int sigaction (int signo, const struct sigaction *restrict newaction,
+ struct sigaction *restrict oldaction);
+
+void (*signal (int signo, void (*handler)(int)))(int);
+void (*bsd_signal (int signo, void (*handler)(int)))(int);
+
+/* Process is executing on an alternate signal stack. */
+#define SS_ONSTACK (1 << 0)
+/* Alternate signal stack is disabled. */
+#define SS_DISABLE (1 << 1)
+
+/* Minimum stack size for a signal handler. */
+#define MINSIGSTKSZ PAGESIZE
+/* Default size in bytes for the alternate signal stack. */
+#define SIGSTKSZ (16 * PAGESIZE)
+
+typedef struct
+{
+ void *ss_sp;
+ size_t ss_size;
+ int ss_flags;
+} stack_t;
+
+int sigaltstack(const stack_t *restrict stack, stack_t *restrict old);
+
+#include <pthread.h>
+
+/* Send SIGNO to the process PID. */
+int kill(pid_t pid, int signo);
+
+/* Send SIGNO to the process group PG. */
+int killpg(pid_t pg, int signo);
+
+/* Send SIGNO to thread TID. */
+int pthread_kill(pthread_t tid, int signo);
+
+/* Send a signal to thread TID using SIGINFO. */
+int pthread_kill_siginfo_np (pthread_t tid, siginfo_t siginfo);
+
+/* Send SIGNO to the calling thread. */
+int raise(int signo);
+
+typedef struct sigevent
+{
+ /* Notification type. */
+ int sigev_notify;
+
+ /* Signal number. */
+ int sigev_signo;
+
+ /* Signal value. */
+ union sigval sigev_value;
+
+ /* Notification function. */
+ void (*sigev_notify_function) (union sigval);
+
+ /* Notification attributes. */
+ pthread_attr_t *sigev_notify_attributes;
+} sigevent_t;
+
+enum
+ {
+ SIGEV_NONE = 0,
+#define SIGEV_NONE SIGEV_NONE
+ SIGEV_SIGNAL,
+#define SIGEV_SIGNAL SIGEV_SIGNAL
+ SIGEV_THREAD
+#define SIGEV_THREAD SIGEV_THREAD
+ };
+
+#define SIG_HOLD
+
+int sighold (int);
+int sigignore (int);
+int siginterrupt (int, int);
+int sigpause (int);
+int sigqueue (pid_t, int, const union sigval);
+int sigrelse (int);
+void (*sigset (int, void (*)(int)))(int);
+int sigsuspend (const sigset_t *);
+
+/* Wait for a signal. */
+int sigwait (const sigset_t *restrict set, int *restrict signo);
+int sigwaitinfo (const sigset_t *restrict set, siginfo_t *restrict info);
+int sigtimedwait (const sigset_t *restrict set, siginfo_t *restrict info,
+ const struct timespec *restrict timespec);
+
+#endif
diff --git a/libpthread/signal/sigpending.c b/libpthread/signal/sigpending.c
new file mode 100644
index 00000000..609b55d6
--- /dev/null
+++ b/libpthread/signal/sigpending.c
@@ -0,0 +1,38 @@
+/* sigpending.c - Generic sigpending implementation.
+ Copyright (C) 2008 Free Software Foundation, Inc.
+ Written by Neal H. Walfield <neal@gnu.org>.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public License
+ as published by the Free Software Foundation; either version 3 of
+ the License, or (at your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this program. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <sig-internal.h>
+#include <pt-internal.h>
+
+int
+sigpending (sigset_t *set)
+{
+ struct signal_state *ss = &_pthread_self ()->ss;
+
+ pthread_mutex_lock (&ss->lock);
+
+ /* There is no need to lock SIG_LOCK for process_pending since we
+ just read it, which is atomic. */
+ *set = (ss->pending | process_pending) & ss->blocked;
+
+ pthread_mutex_unlock (&ss->lock);
+
+ return 0;
+}
diff --git a/libpthread/signal/sigsuspend.c b/libpthread/signal/sigsuspend.c
new file mode 100644
index 00000000..73cf12a1
--- /dev/null
+++ b/libpthread/signal/sigsuspend.c
@@ -0,0 +1,29 @@
+/* sigsuspend.c - Generic sigsuspend implementation.
+ Copyright (C) 2008 Free Software Foundation, Inc.
+ Written by Neal H. Walfield <neal@gnu.org>.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public License
+ as published by the Free Software Foundation; either version 3 of
+ the License, or (at your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this program. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include "sig-internal.h"
+
+int
+sigsuspend (const sigset_t *set)
+{
+ /* XXX: Implement me. */
+ errno = EOPNOTSUPP;
+ return -1;
+}
diff --git a/libpthread/signal/sigtimedwait.c b/libpthread/signal/sigtimedwait.c
new file mode 100644
index 00000000..52cd0176
--- /dev/null
+++ b/libpthread/signal/sigtimedwait.c
@@ -0,0 +1,30 @@
+/* sigtimedwait.c - Generic sigtimedwait implementation.
+ Copyright (C) 2008 Free Software Foundation, Inc.
+ Written by Neal H. Walfield <neal@gnu.org>.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public License
+ as published by the Free Software Foundation; either version 3 of
+ the License, or (at your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this program. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include "sig-internal.h"
+
+int
+sigtimedwait (const sigset_t *restrict set, siginfo_t *restrict info,
+ const struct timespec *restrict timeout)
+{
+ errno = EOPNOTSUPP;
+ return -1;
+}
+
diff --git a/libpthread/signal/sigwaiter.c b/libpthread/signal/sigwaiter.c
new file mode 100644
index 00000000..8d041ac1
--- /dev/null
+++ b/libpthread/signal/sigwaiter.c
@@ -0,0 +1,91 @@
+/* sigwaiter.c - Signal handling functions.
+ Copyright (C) 2008 Free Software Foundation, Inc.
+ Written by Neal H. Walfield <neal@gnu.org>.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public License
+ as published by the Free Software Foundation; either version 3 of
+ the License, or (at your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this program. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include "sig-internal.h"
+
+#include <hurd/futex.h>
+
+struct sigwaiter *sigwaiters;
+
+siginfo_t
+sigwaiter_block (struct signal_state *ss, const sigset_t *restrict set)
+{
+ assert (pthread_mutex_trylock (&sig_lock) == EBUSY);
+ assert (pthread_mutex_trylock (&ss->lock) == EBUSY);
+
+ assert (! ss->sigwaiter);
+
+ struct sigwaiter waiter;
+
+ waiter.next = sigwaiters;
+ if (waiter.next)
+ {
+ assert (! waiter.next->prev);
+ waiter.next->prev = &waiter;
+ }
+ waiter.prev = 0;
+ sigwaiters = &waiter;
+
+ waiter.ss = ss;
+ waiter.info.si_signo = 0;
+ waiter.signals = *set;
+
+ ss->sigwaiter = &waiter;
+
+ pthread_mutex_unlock (&ss->lock);
+ pthread_mutex_unlock (&sig_lock);
+
+ futex_wait (&waiter.info.si_signo, 0);
+
+#ifndef NDEBUG
+ pthread_mutex_lock (&ss->lock);
+ ss->sigwaiter = 0;
+ pthread_mutex_unlock (&ss->lock);
+#endif
+
+ assert (waiter.info.si_signo);
+ return waiter.info;
+}
+
+void
+sigwaiter_unblock (struct sigwaiter *waiter)
+{
+ assert (pthread_mutex_trylock (&sig_lock) == EBUSY);
+ assert (pthread_mutex_trylock (&waiter->ss->lock) == EBUSY);
+
+ struct sigwaiter *prev = waiter->prev;
+ struct sigwaiter *next = waiter->next;
+
+ if (next)
+ next->prev = prev;
+
+ if (prev)
+ prev->next = next;
+ else
+ sigwaiters = next;
+
+ sigdelset (&process_pending, waiter->info.si_signo);
+ sigdelset (&waiter->ss->pending, waiter->info.si_signo);
+
+ pthread_mutex_unlock (&waiter->ss->lock);
+ pthread_mutex_unlock (&sig_lock);
+
+ futex_wake (&waiter->info.si_signo, 1);
+}
diff --git a/libpthread/signal/sigwaitinfo.c b/libpthread/signal/sigwaitinfo.c
new file mode 100644
index 00000000..1b47079e
--- /dev/null
+++ b/libpthread/signal/sigwaitinfo.c
@@ -0,0 +1,74 @@
+/* sigwaitinfo.c - Generic sigwaitinfo implementation.
+ Copyright (C) 2008 Free Software Foundation, Inc.
+ Written by Neal H. Walfield <neal@gnu.org>.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public License
+ as published by the Free Software Foundation; either version 3 of
+ the License, or (at your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this program. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <sig-internal.h>
+#include <pt-internal.h>
+
+int
+sigwaitinfo (const sigset_t *restrict set, siginfo_t *restrict info)
+{
+ pthread_mutex_lock (&sig_lock);
+
+ struct signal_state *ss = &_pthread_self ()->ss;
+
+ pthread_mutex_lock (&ss->lock);
+
+ if ((process_pending & *set) || (ss->pending & *set))
+ /* There is at least one signal pending. */
+ {
+ bool local = true;
+ sigset_t extant = process_pending & *set;
+ if (! extant)
+ {
+ local = false;
+ extant = ss->pending & *set;
+ }
+
+ assert (extant);
+
+ int signo = l4_msb64 (extant);
+
+ if (info)
+ {
+ if (local)
+ *info = ss->info[signo - 1];
+ else
+ *info = process_pending_info[signo - 1];
+ info->si_signo = signo;
+ }
+
+ sigdelset (&process_pending, signo);
+ sigdelset (&ss->pending, signo);
+
+ pthread_mutex_unlock (&ss->lock);
+ pthread_mutex_unlock (&sig_lock);
+ return 0;
+ }
+
+ siginfo_t i = sigwaiter_block (ss, set);
+ assert (i.si_signo);
+ assert ((sigmask (i.si_signo) & *set));
+
+ if (info)
+ *info = i;
+
+ return 0;
+}
+
diff --git a/libpthread/sysdeps/generic/bits/barrier-attr.h b/libpthread/sysdeps/generic/bits/barrier-attr.h
new file mode 100644
index 00000000..a9900b71
--- /dev/null
+++ b/libpthread/sysdeps/generic/bits/barrier-attr.h
@@ -0,0 +1,32 @@
+/* Thread barrier attribute type. Generic version.
+ Copyright (C) 2002, 2008 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#ifndef _BITS_BARRIER_ATTR_H
+#define _BITS_BARRIER_ATTR_H 1
+
+enum __pthread_process_shared;
+
+/* This structure describes the attributes of a POSIX thread barrier.
+ Note that not all of them are supported on all systems. */
+struct __pthread_barrierattr
+{
+ enum __pthread_process_shared pshared;
+};
+
+#endif /* bits/barrier-attr.h */
diff --git a/libpthread/sysdeps/generic/bits/barrier.h b/libpthread/sysdeps/generic/bits/barrier.h
new file mode 100644
index 00000000..5e559312
--- /dev/null
+++ b/libpthread/sysdeps/generic/bits/barrier.h
@@ -0,0 +1,39 @@
+/* Thread barrier attribute type. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#ifndef _BITS_BARRIER_H
+#define _BITS_BARRIER_H 1
+
+#include <bits/spin-lock.h>
+
+/* This structure describes the attributes of a POSIX barrier. */
+struct __pthread_barrier
+{
+ __pthread_spinlock_t lock;
+ struct __pthread *queue; /* List of waiters. */
+ unsigned pending; /* Number of that still need to wait on
+ barrier. */
+ unsigned count; /* Number of threads that must wait before
+ barrier is passed. */
+ struct __pthread_barrierattr *attr;
+ void *data;
+};
+
+
+#endif /* bits/barrier.h */
diff --git a/libpthread/sysdeps/generic/bits/cancelation.h b/libpthread/sysdeps/generic/bits/cancelation.h
new file mode 100644
index 00000000..46486f5e
--- /dev/null
+++ b/libpthread/sysdeps/generic/bits/cancelation.h
@@ -0,0 +1,51 @@
+/* Cancelation. Generic version.
+ Copyright (C) 2002, 2008 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#ifndef _BITS_CANCELATION_H
+#define _BITS_CANCELATION_H 1
+
+struct __pthread_cancelation_handler
+{
+ void (*handler)(void *);
+ void *arg;
+ struct __pthread_cancelation_handler *next;
+};
+
+/* Returns the thread local location of the cleanup handler stack. */
+struct __pthread_cancelation_handler **__pthread_get_cleanup_stack (void);
+
+#define __pthread_cleanup_push(rt, rtarg) \
+ { \
+ struct __pthread_cancelation_handler **__handlers \
+ = __pthread_get_cleanup_stack (); \
+ struct __pthread_cancelation_handler __handler = \
+ { \
+ (rt), \
+ (rtarg), \
+ *__handlers \
+ }; \
+ *__handlers = &__handler;
+
+#define __pthread_cleanup_pop(execute) \
+ if (execute) \
+ __handler.handler (__handler.arg); \
+ *__handlers = __handler.next; \
+ }
+
+#endif /* _BITS_CANCELATION_H */
diff --git a/libpthread/sysdeps/generic/bits/condition-attr.h b/libpthread/sysdeps/generic/bits/condition-attr.h
new file mode 100644
index 00000000..4cd4e8c4
--- /dev/null
+++ b/libpthread/sysdeps/generic/bits/condition-attr.h
@@ -0,0 +1,34 @@
+/* Condition attribute type. Generic version.
+ Copyright (C) 2002, 2008 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#ifndef _BITS_CONDITION_ATTR_H
+#define _BITS_CONDITION_ATTR_H 1
+
+#include <bits/types.h>
+
+enum __pthread_process_shared;
+
+/* User visible part of a condition attribute variable. */
+struct __pthread_condattr
+ {
+ enum __pthread_process_shared pshared;
+ __clockid_t clock;
+ };
+
+#endif /* bits/condition.h */
diff --git a/libpthread/sysdeps/generic/bits/condition.h b/libpthread/sysdeps/generic/bits/condition.h
new file mode 100644
index 00000000..bf13adab
--- /dev/null
+++ b/libpthread/sysdeps/generic/bits/condition.h
@@ -0,0 +1,39 @@
+/* Condition type. Generic version.
+ Copyright (C) 2000, 2005, 2009 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#ifndef _BITS_CONDITION_H
+#define _BITS_CONDITION_H 1
+
+#include <bits/spin-lock.h>
+
+/* User visible part of a condition variable. */
+struct __pthread_cond
+ {
+ __pthread_spinlock_t __lock;
+ struct __pthread *__queue;
+ struct __pthread_condattr *__attr;
+ struct __pthread_condimpl *__impl;
+ void *__data;
+ };
+
+/* Initializer for a condition variable. */
+#define __PTHREAD_COND_INITIALIZER \
+ { __PTHREAD_SPIN_LOCK_INITIALIZER, NULL, NULL, NULL, NULL }
+
+#endif /* bits/condition.h */
diff --git a/libpthread/sysdeps/generic/bits/mutex-attr.h b/libpthread/sysdeps/generic/bits/mutex-attr.h
new file mode 100644
index 00000000..8514ebe8
--- /dev/null
+++ b/libpthread/sysdeps/generic/bits/mutex-attr.h
@@ -0,0 +1,41 @@
+/* Mutex attribute type. Generic version.
+ Copyright (C) 2002, 2008 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#ifndef _BITS_MUTEX_ATTR_H
+#define _BITS_MUTEX_ATTR_H 1
+
+enum __pthread_mutex_protocol;
+enum __pthread_process_shared;
+enum __pthread_mutex_type;
+
+/* This structure describes the attributes of a POSIX mutex
+ attribute. */
+struct __pthread_mutexattr
+{
+ int prioceiling;
+ enum __pthread_mutex_protocol protocol;
+ enum __pthread_process_shared pshared;
+ enum __pthread_mutex_type mutex_type;
+};
+
+/* Attributes for a recursive mutex. */
+extern const struct __pthread_mutexattr __pthread_errorcheck_mutexattr;
+extern const struct __pthread_mutexattr __pthread_recursive_mutexattr;
+
+#endif /* bits/mutex-attr.h */
diff --git a/libpthread/sysdeps/generic/bits/mutex.h b/libpthread/sysdeps/generic/bits/mutex.h
new file mode 100644
index 00000000..c734c393
--- /dev/null
+++ b/libpthread/sysdeps/generic/bits/mutex.h
@@ -0,0 +1,75 @@
+/* Mutex type. Generic version.
+
+ Copyright (C) 2000, 2002, 2005, 2006, 2007, 2008, 2009
+ Free Software Foundation, Inc.
+
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#ifndef _BITS_MUTEX_H
+
+#ifndef __need_pthread_mutex
+# define _BITS_MUTEX_H 1
+#endif
+
+#ifndef __pthread_mutex_defined
+# if defined __need_pthread_mutex || defined _BITS_MUTEX_H
+# undef __need_pthread_mutex
+# define __pthread_mutex_defined
+
+# include <bits/spin-lock.h>
+# include <bits/mutex-attr.h>
+
+/* User visible part of a mutex. */
+struct __pthread_mutex
+ {
+ __pthread_spinlock_t __held;
+ __pthread_spinlock_t __lock;
+ /* In cthreads, mutex_init does not initialized thre third
+ pointer, as such, we cannot rely on its value for anything. */
+ char *cthreadscompat1;
+ struct __pthread *__queue;
+ struct __pthread_mutexattr *attr;
+ void *data;
+ /* Up to this point, we are completely compatible with cthreads
+ and what libc expects. */
+ void *owner;
+ unsigned locks;
+ /* If NULL then the default attributes apply. */
+ };
+
+/* Initializer for a mutex. N.B. this also happens to be compatible
+ with the cthread mutex initializer. */
+# define __PTHREAD_MUTEX_INITIALIZER \
+ { __PTHREAD_SPIN_LOCK_INITIALIZER, __PTHREAD_SPIN_LOCK_INITIALIZER, 0, 0, 0, 0, 0, 0 }
+
+# define __PTHREAD_ERRORCHECK_MUTEXATTR ((struct __pthread_mutexattr *) ((unsigned long) __PTHREAD_MUTEX_ERRORCHECK + 1))
+
+# define __PTHREAD_ERRORCHECK_MUTEX_INITIALIZER \
+ { __PTHREAD_SPIN_LOCK_INITIALIZER, __PTHREAD_SPIN_LOCK_INITIALIZER, 0, 0, \
+ __PTHREAD_ERRORCHECK_MUTEXATTR, 0, 0, 0 }
+
+# define __PTHREAD_RECURSIVE_MUTEXATTR ((struct __pthread_mutexattr *) ((unsigned long) __PTHREAD_MUTEX_RECURSIVE + 1))
+
+# define __PTHREAD_RECURSIVE_MUTEX_INITIALIZER \
+ { __PTHREAD_SPIN_LOCK_INITIALIZER, __PTHREAD_SPIN_LOCK_INITIALIZER, 0, 0, \
+ __PTHREAD_RECURSIVE_MUTEXATTR, 0, 0, 0 }
+
+# endif
+#endif /* Not __pthread_mutex_defined. */
+
+#endif /* bits/mutex.h */
diff --git a/libpthread/sysdeps/generic/bits/once.h b/libpthread/sysdeps/generic/bits/once.h
new file mode 100644
index 00000000..f4985d6f
--- /dev/null
+++ b/libpthread/sysdeps/generic/bits/once.h
@@ -0,0 +1,34 @@
+/* Dynamic package initialization data structures. Generic version.
+ Copyright (C) 2002, 2009 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#ifndef _BITS_ONCE_H
+#define _BITS_ONCE_H 1
+
+#include <bits/spin-lock.h>
+
+struct __pthread_once
+{
+ int run;
+ __pthread_spinlock_t lock;
+};
+
+#define __PTHREAD_ONCE_INIT \
+ { 0, __PTHREAD_SPIN_LOCK_INITIALIZER }
+
+#endif /* bits/once.h */
diff --git a/libpthread/sysdeps/generic/bits/pthread-np.h b/libpthread/sysdeps/generic/bits/pthread-np.h
new file mode 100644
index 00000000..d5ddbb05
--- /dev/null
+++ b/libpthread/sysdeps/generic/bits/pthread-np.h
@@ -0,0 +1,27 @@
+/* Non-portable functions. Generic version.
+ Copyright (C) 2008 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+/*
+ * Never include this file directly; use <pthread.h> or <cthreads.h> instead.
+ */
+
+#ifndef _BITS_PTHREAD_NP_H
+#define _BITS_PTHREAD_NP_H 1
+
+#endif /* bits/pthread-np.h */
diff --git a/libpthread/sysdeps/generic/bits/pthread.h b/libpthread/sysdeps/generic/bits/pthread.h
new file mode 100644
index 00000000..80e6b096
--- /dev/null
+++ b/libpthread/sysdeps/generic/bits/pthread.h
@@ -0,0 +1,38 @@
+/* Pthread data structures. Generic version.
+ Copyright (C) 2002, 2008 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#ifndef _BITS_PTHREAD_H
+#define _BITS_PTHREAD_H 1
+
+typedef int __pthread_t;
+
+/* Return true if __T1 and __T2 both name the same thread. Otherwise,
+ false. */
+extern int
+__pthread_equal (__pthread_t __t1, __pthread_t __t2);
+
+#ifdef __USE_EXTERN_INLINES
+__extern_inline int
+__pthread_equal (__pthread_t __t1, __pthread_t __t2)
+{
+ return __t1 == __t2;
+}
+#endif
+
+#endif /* bits/pthread.h */
diff --git a/libpthread/sysdeps/generic/bits/pthreadtypes.h b/libpthread/sysdeps/generic/bits/pthreadtypes.h
new file mode 100644
index 00000000..e5cbfd2a
--- /dev/null
+++ b/libpthread/sysdeps/generic/bits/pthreadtypes.h
@@ -0,0 +1,29 @@
+/*
+ Copyright (C) 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#if !defined _BITS_TYPES_H && !defined _PTHREAD_H
+# error "Never include <bits/pthreadtypes.h> directly; use <sys/types.h> instead."
+#endif
+
+#ifndef _BITS_PTHREADTYPES_H
+#define _BITS_PTHREADTYPES_H 1
+
+#include <pthread.h>
+
+#endif /* bits/pthreadtypes.h */
diff --git a/libpthread/sysdeps/generic/bits/rwlock-attr.h b/libpthread/sysdeps/generic/bits/rwlock-attr.h
new file mode 100644
index 00000000..dba99f1d
--- /dev/null
+++ b/libpthread/sysdeps/generic/bits/rwlock-attr.h
@@ -0,0 +1,32 @@
+/* Thread rwlock attribute type. Generic version.
+ Copyright (C) 2002, 2008 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#ifndef _BITS_RWLOCK_ATTR_H
+#define _BITS_RWLOCK_ATTR_H 1
+
+enum __pthread_process_shared;
+
+/* This structure describes the attributes of a POSIX thread rwlock.
+ Note that not all of them are supported on all systems. */
+struct __pthread_rwlockattr
+{
+ enum __pthread_process_shared pshared;
+};
+
+#endif /* bits/rwlock-attr.h */
diff --git a/libpthread/sysdeps/generic/bits/rwlock.h b/libpthread/sysdeps/generic/bits/rwlock.h
new file mode 100644
index 00000000..af6b1c86
--- /dev/null
+++ b/libpthread/sysdeps/generic/bits/rwlock.h
@@ -0,0 +1,46 @@
+/* rwlock type. Generic version.
+ Copyright (C) 2002, 2005, 2006, 2007, 2009 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#ifndef _BITS_RWLOCK_H
+#define _BITS_RWLOCK_H
+
+#include <bits/spin-lock.h>
+
+/* User visible part of a rwlock. If __held is not held and readers
+ is 0, then the lock is unlocked. If __held is held and readers is
+ 0, then the lock is held by a writer. If __held is held and
+ readers is greater than 0, then the lock is held by READERS
+ readers. */
+struct __pthread_rwlock
+ {
+ __pthread_spinlock_t __held;
+ __pthread_spinlock_t __lock;
+ int readers;
+ struct __pthread *readerqueue;
+ struct __pthread *writerqueue;
+ struct __pthread_rwlockattr *__attr;
+ void *__data;
+ };
+
+/* Initializer for a rwlock. */
+#define __PTHREAD_RWLOCK_INITIALIZER \
+ { __PTHREAD_SPIN_LOCK_INITIALIZER, __PTHREAD_SPIN_LOCK_INITIALIZER, 0, 0, 0, 0, 0 }
+
+
+#endif /* bits/rwlock.h */
diff --git a/libpthread/sysdeps/generic/bits/semaphore.h b/libpthread/sysdeps/generic/bits/semaphore.h
new file mode 100644
index 00000000..5e987c15
--- /dev/null
+++ b/libpthread/sysdeps/generic/bits/semaphore.h
@@ -0,0 +1,43 @@
+/* Semaphore type. Generic version.
+ Copyright (C) 2005, 2009 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#ifndef _BITS_SEMAPHORE_H
+#define _BITS_SEMAPHORE_H 1
+
+#ifndef _SEMAPHORE_H
+#error Never include <bits/semaphore.h> directly.
+#endif
+
+#include <pthread.h>
+
+/* User visible part of a semaphore. */
+struct __semaphore
+ {
+ __pthread_spinlock_t __lock;
+ struct __pthread *__queue;
+ int __pshared;
+ int __value;
+ void *__data;
+ };
+
+/* Initializer for a semaphore. */
+#define __SEMAPHORE_INITIALIZER(pshared, value) \
+ { __PTHREAD_SPIN_LOCK_INITIALIZER, NULL, (pshared), (value), NULL }
+
+#endif /* bits/mutex.h */
diff --git a/libpthread/sysdeps/generic/bits/thread-attr.h b/libpthread/sysdeps/generic/bits/thread-attr.h
new file mode 100644
index 00000000..f2e55f2b
--- /dev/null
+++ b/libpthread/sysdeps/generic/bits/thread-attr.h
@@ -0,0 +1,44 @@
+/* Thread attribute type. Generic version.
+ Copyright (C) 2000, 2002, 2008 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#ifndef _BITS_THREAD_ATTR_H
+#define _BITS_THREAD_ATTR_H 1
+
+#define __need_schedparam
+#include <bits/sched.h>
+
+enum __pthread_detachstate;
+enum __pthread_inheritsched;
+enum __pthread_contentionscope;
+
+/* This structure describes the attributes of a POSIX thread. Note
+ that not all of them are supported on all systems. */
+struct __pthread_attr
+{
+ struct __sched_param schedparam;
+ void *stackaddr;
+ size_t stacksize;
+ size_t guardsize;
+ enum __pthread_detachstate detachstate;
+ enum __pthread_inheritsched inheritsched;
+ enum __pthread_contentionscope contentionscope;
+ int schedpolicy;
+};
+
+#endif /* bits/thread-attr.h */
diff --git a/libpthread/sysdeps/generic/bits/thread-specific.h b/libpthread/sysdeps/generic/bits/thread-specific.h
new file mode 100644
index 00000000..b42d99e7
--- /dev/null
+++ b/libpthread/sysdeps/generic/bits/thread-specific.h
@@ -0,0 +1,25 @@
+/* Thread specific data. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#ifndef _BITS_THREAD_SPECIFIC_H
+#define _BITS_THREAD_SPECIFIC_H 1
+
+typedef int __pthread_key;
+
+#endif /* bits/thread-specific.h */
diff --git a/libpthread/sysdeps/generic/killpg.c b/libpthread/sysdeps/generic/killpg.c
new file mode 100644
index 00000000..7f7ed87d
--- /dev/null
+++ b/libpthread/sysdeps/generic/killpg.c
@@ -0,0 +1,27 @@
+/* killpg.c - Generic killpg implementation.
+ Copyright (C) 2008 Free Software Foundation, Inc.
+ Written by Neal H. Walfield <neal@gnu.org>.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public License
+ as published by the Free Software Foundation; either version 3 of
+ the License, or (at your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this program. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include "sig-internal.h"
+
+int
+killpg (pid_t pid, int sig)
+{
+ return kill (-pid, sig);
+}
diff --git a/libpthread/sysdeps/generic/pt-atfork.c b/libpthread/sysdeps/generic/pt-atfork.c
new file mode 100644
index 00000000..32e1e78c
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-atfork.c
@@ -0,0 +1,29 @@
+/* Register fork handlers. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_atfork (void (*prepare) (void),
+ void (*parent) (void),
+ void (*child) (void))
+{
+ return ENOSYS;
+}
diff --git a/libpthread/sysdeps/generic/pt-attr-destroy.c b/libpthread/sysdeps/generic/pt-attr-destroy.c
new file mode 100644
index 00000000..c4b9aa54
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-attr-destroy.c
@@ -0,0 +1,27 @@
+/* pthread_attr_destroy. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_attr_destroy (pthread_attr_t *attr)
+{
+ return 0;
+}
diff --git a/libpthread/sysdeps/generic/pt-attr-getdetachstate.c b/libpthread/sysdeps/generic/pt-attr-getdetachstate.c
new file mode 100644
index 00000000..be406f1d
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-attr-getdetachstate.c
@@ -0,0 +1,29 @@
+/* pthread_attr_getdetachstate. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_attr_getdetachstate (const pthread_attr_t *attr,
+ int *detachstate)
+{
+ *detachstate = attr->detachstate;
+ return 0;
+}
diff --git a/libpthread/sysdeps/generic/pt-attr-getguardsize.c b/libpthread/sysdeps/generic/pt-attr-getguardsize.c
new file mode 100644
index 00000000..c1d9f13e
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-attr-getguardsize.c
@@ -0,0 +1,29 @@
+/* pthread_attr_getguardsize. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_attr_getguardsize (const pthread_attr_t *attr,
+ size_t *guardsize)
+{
+ *guardsize = attr->guardsize;
+ return 0;
+}
diff --git a/libpthread/sysdeps/generic/pt-attr-getinheritsched.c b/libpthread/sysdeps/generic/pt-attr-getinheritsched.c
new file mode 100644
index 00000000..cca4e3d7
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-attr-getinheritsched.c
@@ -0,0 +1,29 @@
+/* pthread_attr_getinheritsched. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_attr_getinheritsched (const pthread_attr_t *attr,
+ int *inheritsched)
+{
+ *inheritsched = attr->inheritsched;
+ return 0;
+}
diff --git a/libpthread/sysdeps/generic/pt-attr-getschedparam.c b/libpthread/sysdeps/generic/pt-attr-getschedparam.c
new file mode 100644
index 00000000..190cf9d0
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-attr-getschedparam.c
@@ -0,0 +1,32 @@
+/* pthread_attr_getschedparam. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <sched.h>
+#include <string.h>
+
+#include <pt-internal.h>
+
+int
+pthread_attr_getschedparam (const pthread_attr_t *attr,
+ struct sched_param *param)
+{
+ memcpy (param, &attr->schedparam, sizeof *param);
+ return 0;
+}
diff --git a/libpthread/sysdeps/generic/pt-attr-getschedpolicy.c b/libpthread/sysdeps/generic/pt-attr-getschedpolicy.c
new file mode 100644
index 00000000..4349a238
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-attr-getschedpolicy.c
@@ -0,0 +1,29 @@
+/* pthread_attr_getschedpolicy. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_attr_getschedpolicy (const pthread_attr_t *attr,
+ int *policy)
+{
+ *policy = attr->schedpolicy;
+ return 0;
+}
diff --git a/libpthread/sysdeps/generic/pt-attr-getscope.c b/libpthread/sysdeps/generic/pt-attr-getscope.c
new file mode 100644
index 00000000..97198fa5
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-attr-getscope.c
@@ -0,0 +1,29 @@
+/* pthread_attr_getscope. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_attr_getscope (const pthread_attr_t *attr,
+ int *contentionscope)
+{
+ *contentionscope = attr->contentionscope;
+ return 0;
+}
diff --git a/libpthread/sysdeps/generic/pt-attr-getstack.c b/libpthread/sysdeps/generic/pt-attr-getstack.c
new file mode 100644
index 00000000..7beb79f0
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-attr-getstack.c
@@ -0,0 +1,31 @@
+/* pthread_attr_getstack. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_attr_getstack (const pthread_attr_t *attr,
+ void **stackaddr,
+ size_t *stacksize)
+{
+ pthread_attr_getstackaddr (attr, stackaddr);
+ pthread_attr_getstacksize (attr, stacksize);
+ return 0;
+}
diff --git a/libpthread/sysdeps/generic/pt-attr-getstackaddr.c b/libpthread/sysdeps/generic/pt-attr-getstackaddr.c
new file mode 100644
index 00000000..d43eeff7
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-attr-getstackaddr.c
@@ -0,0 +1,29 @@
+/* pthread_attr_getstackaddr. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_attr_getstackaddr (const pthread_attr_t *attr,
+ void **stackaddr)
+{
+ *stackaddr = attr->stackaddr;
+ return 0;
+}
diff --git a/libpthread/sysdeps/generic/pt-attr-getstacksize.c b/libpthread/sysdeps/generic/pt-attr-getstacksize.c
new file mode 100644
index 00000000..c1bc6617
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-attr-getstacksize.c
@@ -0,0 +1,29 @@
+/* pthread_attr_getstacksize. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_attr_getstacksize (const pthread_attr_t *attr,
+ size_t *stacksize)
+{
+ *stacksize = attr->stacksize;
+ return 0;
+}
diff --git a/libpthread/sysdeps/generic/pt-attr-init.c b/libpthread/sysdeps/generic/pt-attr-init.c
new file mode 100644
index 00000000..6a930e30
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-attr-init.c
@@ -0,0 +1,28 @@
+/* pthread_attr_init. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_attr_init (pthread_attr_t *attr)
+{
+ *attr = __pthread_default_attr;
+ return 0;
+}
diff --git a/libpthread/sysdeps/generic/pt-attr-setdetachstate.c b/libpthread/sysdeps/generic/pt-attr-setdetachstate.c
new file mode 100644
index 00000000..688ba5d6
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-attr-setdetachstate.c
@@ -0,0 +1,38 @@
+/* pthread_attr_setdetachstate. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_attr_setdetachstate (pthread_attr_t *attr,
+ int detachstate)
+{
+ switch (detachstate)
+ {
+ case PTHREAD_CREATE_DETACHED:
+ case PTHREAD_CREATE_JOINABLE:
+ attr->detachstate = detachstate;
+ break;
+ default:
+ return EINVAL;
+ }
+
+ return 0;
+}
diff --git a/libpthread/sysdeps/generic/pt-attr-setguardsize.c b/libpthread/sysdeps/generic/pt-attr-setguardsize.c
new file mode 100644
index 00000000..b2ba0f0f
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-attr-setguardsize.c
@@ -0,0 +1,29 @@
+/* pthread_attr_setguardsize. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_attr_setguardsize (pthread_attr_t *attr,
+ size_t guardsize)
+{
+ attr->guardsize = guardsize;
+ return 0;
+}
diff --git a/libpthread/sysdeps/generic/pt-attr-setinheritsched.c b/libpthread/sysdeps/generic/pt-attr-setinheritsched.c
new file mode 100644
index 00000000..e9012c58
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-attr-setinheritsched.c
@@ -0,0 +1,38 @@
+/* pthread_attr_setinheritsched. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_attr_setinheritsched (pthread_attr_t *attr,
+ int inheritsched)
+{
+ switch (inheritsched)
+ {
+ case PTHREAD_INHERIT_SCHED:
+ case PTHREAD_EXPLICIT_SCHED:
+ attr->inheritsched = inheritsched;
+ break;
+ default:
+ return EINVAL;
+ }
+
+ return 0;
+}
diff --git a/libpthread/sysdeps/generic/pt-attr-setschedparam.c b/libpthread/sysdeps/generic/pt-attr-setschedparam.c
new file mode 100644
index 00000000..5459f108
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-attr-setschedparam.c
@@ -0,0 +1,38 @@
+/* pthread_attr_getschedparam. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <sched.h>
+#include <string.h>
+
+#include <pt-internal.h>
+
+int
+pthread_attr_setschedparam (pthread_attr_t *attr,
+ const struct sched_param *param)
+{
+ if (memcmp (param, &__pthread_default_attr.schedparam,
+ sizeof *param) == 0)
+ {
+ memcpy (&attr->schedparam, param, sizeof *param);
+ return 0;
+ }
+
+ return ENOTSUP;
+}
diff --git a/libpthread/sysdeps/generic/pt-attr-setschedpolicy.c b/libpthread/sysdeps/generic/pt-attr-setschedpolicy.c
new file mode 100644
index 00000000..e481d04c
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-attr-setschedpolicy.c
@@ -0,0 +1,42 @@
+/* pthread_attr_getschedpolicy. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_attr_setschedpolicy (pthread_attr_t *attr,
+ int policy)
+{
+ switch (policy)
+ {
+ case SCHED_OTHER:
+ attr->schedpolicy = policy;
+ break;
+
+ case SCHED_FIFO:
+ case SCHED_RR:
+ return ENOTSUP;
+
+ default:
+ return EINVAL;
+ }
+
+ return 0;
+}
diff --git a/libpthread/sysdeps/generic/pt-attr-setscope.c b/libpthread/sysdeps/generic/pt-attr-setscope.c
new file mode 100644
index 00000000..c74a4f67
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-attr-setscope.c
@@ -0,0 +1,41 @@
+/* pthread_attr_setscope. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_attr_setscope (pthread_attr_t *attr,
+ int contentionscope)
+{
+ if (contentionscope == __pthread_default_attr.contentionscope)
+ {
+ attr->contentionscope = contentionscope;
+ return 0;
+ }
+
+ switch (contentionscope)
+ {
+ case PTHREAD_SCOPE_PROCESS:
+ case PTHREAD_SCOPE_SYSTEM:
+ return ENOTSUP;
+ default:
+ return EINVAL;
+ }
+}
diff --git a/libpthread/sysdeps/generic/pt-attr-setstack.c b/libpthread/sysdeps/generic/pt-attr-setstack.c
new file mode 100644
index 00000000..360d27a3
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-attr-setstack.c
@@ -0,0 +1,51 @@
+/* pthread_attr_setstack. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <assert.h>
+
+#include <pt-internal.h>
+
+int
+pthread_attr_setstack (pthread_attr_t *attr,
+ void *stackaddr,
+ size_t stacksize)
+{
+ int err;
+ size_t s;
+
+ /* pthread_attr_setstack should always succeed, thus we set the size
+ first as it is more discriminating. */
+ pthread_attr_getstacksize (attr, &s);
+
+ err = pthread_attr_setstacksize (attr, stacksize);
+ if (err)
+ return err;
+
+ err = pthread_attr_setstackaddr (attr, stackaddr);
+ if (err)
+ {
+ int e = pthread_attr_setstacksize (attr, s);
+ assert_perror (e);
+
+ return err;
+ }
+
+ return 0;
+}
diff --git a/libpthread/sysdeps/generic/pt-attr-setstackaddr.c b/libpthread/sysdeps/generic/pt-attr-setstackaddr.c
new file mode 100644
index 00000000..431f2d0c
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-attr-setstackaddr.c
@@ -0,0 +1,29 @@
+/* pthread_attr_setstackaddr. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_attr_setstackaddr (pthread_attr_t *attr,
+ void *stackaddr)
+{
+ attr->stackaddr = stackaddr;
+ return 0;
+}
diff --git a/libpthread/sysdeps/generic/pt-attr-setstacksize.c b/libpthread/sysdeps/generic/pt-attr-setstacksize.c
new file mode 100644
index 00000000..d0e51022
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-attr-setstacksize.c
@@ -0,0 +1,41 @@
+/* pthread_attr_setstacksize. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_attr_setstacksize (pthread_attr_t *attr,
+ size_t stacksize)
+{
+ if (stacksize == __pthread_default_attr.stacksize)
+ {
+ attr->stacksize = stacksize;
+
+ /* The guard size cannot be larger than the stack itself, as
+ such, if the new stack size is smaller than the guard size,
+ we squash the guard size. */
+ if (attr->guardsize > attr->stacksize)
+ attr->guardsize = attr->stacksize;
+
+ return 0;
+ }
+
+ return ENOTSUP;
+}
diff --git a/libpthread/sysdeps/generic/pt-attr.c b/libpthread/sysdeps/generic/pt-attr.c
new file mode 100644
index 00000000..769f292a
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-attr.c
@@ -0,0 +1,41 @@
+/* Default attributes. Generic version.
+ Copyright (C) 2000,02 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <sched.h>
+#include <stddef.h>
+#include <limits.h>
+
+#include <pt-internal.h>
+
+const struct __pthread_attr __pthread_default_attr =
+{
+ schedparam: { sched_priority: 0 },
+ stacksize: PTHREAD_STACK_DEFAULT,
+ stackaddr: NULL,
+#ifdef PAGESIZE
+ guardsize: PAGESIZE,
+#else
+ guardsize: 0,
+#endif /* PAGESIZE */
+ detachstate: PTHREAD_CREATE_JOINABLE,
+ inheritsched: PTHREAD_EXPLICIT_SCHED,
+ contentionscope: PTHREAD_SCOPE_SYSTEM,
+ schedpolicy: SCHED_OTHER
+};
diff --git a/libpthread/sysdeps/generic/pt-barrier-destroy.c b/libpthread/sysdeps/generic/pt-barrier-destroy.c
new file mode 100644
index 00000000..01b938b4
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-barrier-destroy.c
@@ -0,0 +1,27 @@
+/* pthread_barrier_destroy. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_barrier_destroy (pthread_barrier_t *barrier)
+{
+ return 0;
+}
diff --git a/libpthread/sysdeps/generic/pt-barrier-init.c b/libpthread/sysdeps/generic/pt-barrier-init.c
new file mode 100644
index 00000000..c42b3bb6
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-barrier-init.c
@@ -0,0 +1,53 @@
+/* pthread_barrier_init. Generic version.
+ Copyright (C) 2002, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <string.h>
+#include <assert.h>
+
+#include <pt-internal.h>
+
+int
+pthread_barrier_init (pthread_barrier_t *barrier,
+ const pthread_barrierattr_t *attr,
+ unsigned count)
+{
+ if (count == 0)
+ return EINVAL;
+
+ memset (barrier, 0, sizeof *barrier);
+
+ barrier->lock = PTHREAD_SPINLOCK_INITIALIZER;
+ barrier->pending = count;
+ barrier->count = count;
+
+ if (! attr
+ || memcmp (attr, &__pthread_default_barrierattr, sizeof (*attr) == 0))
+ /* Use the default attributes. */
+ return 0;
+
+ /* Non-default attributes. */
+
+ barrier->attr = malloc (sizeof *attr);
+ if (! barrier->attr)
+ return ENOMEM;
+
+ *barrier->attr = *attr;
+ return 0;
+}
diff --git a/libpthread/sysdeps/generic/pt-barrier-wait.c b/libpthread/sysdeps/generic/pt-barrier-wait.c
new file mode 100644
index 00000000..f1de250a
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-barrier-wait.c
@@ -0,0 +1,61 @@
+/* pthread_barrier_wait. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <assert.h>
+
+#include <pt-internal.h>
+
+int
+pthread_barrier_wait (pthread_barrier_t *barrier)
+{
+ __pthread_spin_lock (&barrier->lock);
+ if (-- barrier->pending == 0)
+ {
+ barrier->pending = barrier->count;
+
+ if (barrier->count > 1)
+ {
+ struct __pthread *wakeup;
+
+ wakeup = barrier->queue;
+ barrier->queue = NULL;
+ __pthread_spin_unlock (&barrier->lock);
+
+ /* We can safely walk the list of waiting threads without
+ holding the lock since it is decoupled from the barrier
+ variable now. */
+ __pthread_dequeuing_iterate (wakeup, wakeup)
+ __pthread_wakeup (wakeup);
+ }
+
+ return PTHREAD_BARRIER_SERIAL_THREAD;
+ }
+ else
+ {
+ struct __pthread *self = _pthread_self ();
+
+ /* Add ourselves to the list of waiters. */
+ __pthread_enqueue (&barrier->queue, self);
+ __pthread_spin_unlock (&barrier->lock);
+
+ __pthread_block (self);
+ return 0;
+ }
+}
diff --git a/libpthread/sysdeps/generic/pt-barrier.c b/libpthread/sysdeps/generic/pt-barrier.c
new file mode 100644
index 00000000..d772719f
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-barrier.c
@@ -0,0 +1,26 @@
+/* Default barrier attributes. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+const struct __pthread_barrierattr __pthread_default_barrierattr =
+{
+ pshared: PTHREAD_PROCESS_PRIVATE
+};
diff --git a/libpthread/sysdeps/generic/pt-barrierattr-destroy.c b/libpthread/sysdeps/generic/pt-barrierattr-destroy.c
new file mode 100644
index 00000000..eb396347
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-barrierattr-destroy.c
@@ -0,0 +1,27 @@
+/* pthread_barrierattr_destroy. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_barrierattr_destroy (pthread_barrierattr_t *attr)
+{
+ return 0;
+}
diff --git a/libpthread/sysdeps/generic/pt-barrierattr-getpshared.c b/libpthread/sysdeps/generic/pt-barrierattr-getpshared.c
new file mode 100644
index 00000000..ed2cdd24
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-barrierattr-getpshared.c
@@ -0,0 +1,29 @@
+/* pthread_barrierattr_getpshared. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_barrierattr_getpshared (const pthread_barrierattr_t *attr,
+ int *pshared)
+{
+ *pshared = attr->pshared;
+ return 0;
+}
diff --git a/libpthread/sysdeps/generic/pt-barrierattr-init.c b/libpthread/sysdeps/generic/pt-barrierattr-init.c
new file mode 100644
index 00000000..45f16cc8
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-barrierattr-init.c
@@ -0,0 +1,28 @@
+/* pthread_barrierattr_init. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_barrierattr_init (pthread_barrierattr_t *attr)
+{
+ *attr = __pthread_default_barrierattr;
+ return 0;
+}
diff --git a/libpthread/sysdeps/generic/pt-barrierattr-setpshared.c b/libpthread/sysdeps/generic/pt-barrierattr-setpshared.c
new file mode 100644
index 00000000..84ef2df8
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-barrierattr-setpshared.c
@@ -0,0 +1,39 @@
+/* pthread_barrierattr_setpshared. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_barrierattr_setpshared (pthread_barrierattr_t *attr,
+ int pshared)
+{
+ switch (pshared)
+ {
+ case PTHREAD_PROCESS_PRIVATE:
+ attr->pshared = pshared;
+ return 0;
+
+ case PTHREAD_PROCESS_SHARED:
+ return ENOTSUP;
+
+ default:
+ return EINVAL;
+ }
+}
diff --git a/libpthread/sysdeps/generic/pt-cond-brdcast.c b/libpthread/sysdeps/generic/pt-cond-brdcast.c
new file mode 100644
index 00000000..3f55e33e
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-cond-brdcast.c
@@ -0,0 +1,42 @@
+/* Broadcast a condition. Generic version.
+ Copyright (C) 2000, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+
+#include <pt-internal.h>
+
+/* Unblock all threads that are blocked on condition variable COND. */
+int
+pthread_cond_broadcast (pthread_cond_t *cond)
+{
+ struct __pthread *wakeup;
+
+ __pthread_spin_lock (&cond->__lock);
+
+ wakeup = cond->__queue;
+ cond->__queue = NULL;
+ __pthread_spin_unlock (&cond->__lock);
+
+ /* We can safely walk the list of waiting threads without holding
+ the lock since it is now decoupled from the condition. */
+ __pthread_dequeuing_iterate (wakeup, wakeup)
+ __pthread_wakeup (wakeup);
+
+ return 0;
+}
diff --git a/libpthread/sysdeps/generic/pt-cond-destroy.c b/libpthread/sysdeps/generic/pt-cond-destroy.c
new file mode 100644
index 00000000..eba47784
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-cond-destroy.c
@@ -0,0 +1,27 @@
+/* pthread_cond_destroy. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_cond_destroy (pthread_cond_t *cond)
+{
+ return 0;
+}
diff --git a/libpthread/sysdeps/generic/pt-cond-init.c b/libpthread/sysdeps/generic/pt-cond-init.c
new file mode 100644
index 00000000..b9e9fb7a
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-cond-init.c
@@ -0,0 +1,45 @@
+/* pthread_cond_init. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <assert.h>
+#include <string.h>
+
+#include <pt-internal.h>
+
+int
+pthread_cond_init (pthread_cond_t *cond,
+ const pthread_condattr_t *attr)
+{
+ *cond = (pthread_cond_t) __PTHREAD_COND_INITIALIZER;
+
+ if (! attr
+ || memcmp (attr, &__pthread_default_condattr, sizeof (*attr) == 0))
+ /* Use the default attributes. */
+ return 0;
+
+ /* Non-default attributes. */
+
+ cond->__attr = malloc (sizeof *attr);
+ if (! cond->__attr)
+ return ENOMEM;
+
+ *cond->__attr = *attr;
+ return 0;
+}
diff --git a/libpthread/sysdeps/generic/pt-cond-signal.c b/libpthread/sysdeps/generic/pt-cond-signal.c
new file mode 100644
index 00000000..c5e1bc1d
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-cond-signal.c
@@ -0,0 +1,54 @@
+/* Signal a condition. Generic version.
+ Copyright (C) 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+
+#include <pt-internal.h>
+
+static int
+cond_signal (struct __pthread_cond *cond, int *unblocked)
+{
+ struct __pthread *wakeup;
+
+ __pthread_spin_lock (&cond->__lock);
+ wakeup = cond->__queue;
+ if (wakeup)
+ __pthread_dequeue (wakeup);
+ __pthread_spin_unlock (&cond->__lock);
+
+ if (wakeup)
+ {
+ /* We found a thread waiting for the condition to be signalled.
+ Wake it up! */
+ __pthread_wakeup (wakeup);
+ *unblocked = 1;
+ }
+
+ return 0;
+}
+
+/* Unblock at least one of the threads that are blocked on condition
+ variable COND. */
+int
+pthread_cond_signal (pthread_cond_t *cond)
+{
+ int unblocked = 0;
+
+ return cond_signal (cond, &unblocked);
+}
diff --git a/libpthread/sysdeps/generic/pt-cond-timedwait.c b/libpthread/sysdeps/generic/pt-cond-timedwait.c
new file mode 100644
index 00000000..c10bdb30
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-cond-timedwait.c
@@ -0,0 +1,106 @@
+/* Wait on a condition. Generic version.
+ Copyright (C) 2000, 2002, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+
+#include <pt-internal.h>
+
+extern int __pthread_cond_timedwait_internal (pthread_cond_t *cond,
+ pthread_mutex_t *mutex,
+ const struct timespec *abstime);
+
+int
+pthread_cond_timedwait (pthread_cond_t *cond,
+ pthread_mutex_t *mutex,
+ const struct timespec *abstime)
+{
+ return __pthread_cond_timedwait_internal (cond, mutex, abstime);
+}
+
+/* Block on condition variable COND until ABSTIME. As a GNU
+ extension, if ABSTIME is NULL, then wait forever. MUTEX should be
+ held by the calling thread. On return, MUTEX will be held by the
+ calling thread. */
+int
+__pthread_cond_timedwait_internal (pthread_cond_t *cond,
+ pthread_mutex_t *mutex,
+ const struct timespec *abstime)
+{
+ error_t err;
+ int canceltype;
+
+ void cleanup (void *arg)
+ {
+ struct __pthread *self = _pthread_self ();
+
+ __pthread_spin_lock (&cond->__lock);
+ if (self->prevp)
+ __pthread_dequeue (self);
+ __pthread_spin_unlock (&cond->__lock);
+
+ pthread_setcanceltype (canceltype, &canceltype);
+ __pthread_mutex_lock (mutex);
+ }
+
+ if (abstime && (abstime->tv_nsec < 0 || abstime->tv_nsec >= 1000000000))
+ return EINVAL;
+
+ struct __pthread *self = _pthread_self ();
+
+ /* Add ourselves to the list of waiters. */
+ __pthread_spin_lock (&cond->__lock);
+ __pthread_enqueue (&cond->__queue, self);
+ __pthread_spin_unlock (&cond->__lock);
+
+ __pthread_mutex_unlock (mutex);
+
+ /* Enter async cancelation mode. If cancelation is disabled, then
+ this does not change anything which is exactly what we want. */
+ pthread_cleanup_push (cleanup, 0);
+ pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, &canceltype);
+
+ if (abstime)
+ {
+ err = __pthread_timedblock (self, abstime);
+ if (err)
+ /* We timed out. We may need to disconnect ourself from the
+ waiter queue.
+
+ FIXME: What do we do if we get a wakeup message before we
+ disconnect ourself? It may remain until the next time we
+ block. */
+ {
+ assert (err == ETIMEDOUT);
+
+ __pthread_spin_lock (&mutex->__lock);
+ if (self->prevp)
+ __pthread_dequeue (self);
+ __pthread_spin_unlock (&mutex->__lock);
+ }
+ }
+ else
+ {
+ err = 0;
+ __pthread_block (self);
+ }
+
+ pthread_cleanup_pop (1);
+
+ return err;
+}
diff --git a/libpthread/sysdeps/generic/pt-cond-wait.c b/libpthread/sysdeps/generic/pt-cond-wait.c
new file mode 100644
index 00000000..a03476df
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-cond-wait.c
@@ -0,0 +1,37 @@
+/* Wait on a condition. Generic version.
+ Copyright (C) 2000,02 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+
+#include <pt-internal.h>
+
+/* Implemented in pt-cond-timedwait.c. */
+extern int __pthread_cond_timedwait_internal (pthread_cond_t *cond,
+ pthread_mutex_t *mutex,
+ const struct timespec *abstime);
+
+
+/* Block on condition variable COND. MUTEX should be held by the
+ calling thread. On return, MUTEX will be held by the calling
+ thread. */
+int
+pthread_cond_wait (pthread_cond_t *cond, pthread_mutex_t *mutex)
+{
+ return __pthread_cond_timedwait_internal (cond, mutex, 0);
+}
diff --git a/libpthread/sysdeps/generic/pt-cond.c b/libpthread/sysdeps/generic/pt-cond.c
new file mode 100644
index 00000000..033e767f
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-cond.c
@@ -0,0 +1,29 @@
+/* Default condition attributes. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <time.h>
+
+#include <pt-internal.h>
+
+const struct __pthread_condattr __pthread_default_condattr =
+{
+ pshared: PTHREAD_PROCESS_PRIVATE,
+ clock: CLOCK_REALTIME
+};
diff --git a/libpthread/sysdeps/generic/pt-condattr-destroy.c b/libpthread/sysdeps/generic/pt-condattr-destroy.c
new file mode 100644
index 00000000..c8fd71b9
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-condattr-destroy.c
@@ -0,0 +1,27 @@
+/* pthread_condattr_destroy. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_condattr_destroy (pthread_condattr_t *cond)
+{
+ return 0;
+}
diff --git a/libpthread/sysdeps/generic/pt-condattr-getclock.c b/libpthread/sysdeps/generic/pt-condattr-getclock.c
new file mode 100644
index 00000000..5b9f8893
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-condattr-getclock.c
@@ -0,0 +1,31 @@
+/* pthread_condattr_getclock. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <time.h>
+
+#include <pt-internal.h>
+
+int
+pthread_condattr_getclock (const pthread_condattr_t *attr,
+ clockid_t *clock)
+{
+ *clock = attr->clock;
+ return 0;
+}
diff --git a/libpthread/sysdeps/generic/pt-condattr-getpshared.c b/libpthread/sysdeps/generic/pt-condattr-getpshared.c
new file mode 100644
index 00000000..c072a507
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-condattr-getpshared.c
@@ -0,0 +1,29 @@
+/* pthread_condattr_getpshared. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_condattr_getpshared (const pthread_condattr_t *attr,
+ int *pshared)
+{
+ *pshared = attr->pshared;
+ return 0;
+}
diff --git a/libpthread/sysdeps/generic/pt-condattr-init.c b/libpthread/sysdeps/generic/pt-condattr-init.c
new file mode 100644
index 00000000..cf9e1989
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-condattr-init.c
@@ -0,0 +1,28 @@
+/* pthread_condattr_init. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_condattr_init (pthread_condattr_t *attr)
+{
+ *attr = __pthread_default_condattr;
+ return 0;
+}
diff --git a/libpthread/sysdeps/generic/pt-condattr-setclock.c b/libpthread/sysdeps/generic/pt-condattr-setclock.c
new file mode 100644
index 00000000..984c17e2
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-condattr-setclock.c
@@ -0,0 +1,33 @@
+/* pthread_condattr_setclock. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_condattr_setclock (pthread_condattr_t *attr, clockid_t clock)
+{
+ if (__pthread_default_condattr.clock == clock)
+ {
+ attr->clock = clock;
+ return 0;
+ }
+
+ return EINVAL;
+}
diff --git a/libpthread/sysdeps/generic/pt-condattr-setpshared.c b/libpthread/sysdeps/generic/pt-condattr-setpshared.c
new file mode 100644
index 00000000..b9f0af83
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-condattr-setpshared.c
@@ -0,0 +1,39 @@
+/* pthread_condattr_setpshared. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_condattr_setpshared (pthread_condattr_t *attr,
+ int pshared)
+{
+ switch (pshared)
+ {
+ case PTHREAD_PROCESS_PRIVATE:
+ attr->pshared = pshared;
+ return 0;
+
+ case PTHREAD_PROCESS_SHARED:
+ return ENOTSUP;
+
+ default:
+ return EINVAL;
+ }
+}
diff --git a/libpthread/sysdeps/generic/pt-destroy-specific.c b/libpthread/sysdeps/generic/pt-destroy-specific.c
new file mode 100644
index 00000000..b627f872
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-destroy-specific.c
@@ -0,0 +1,28 @@
+/* __pthread_destory_specific. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+void
+__pthread_destory_specifc (struct __pthread *thread)
+{
+ /* Not support, thus there cannot be any. */
+ return;
+}
diff --git a/libpthread/sysdeps/generic/pt-equal.c b/libpthread/sysdeps/generic/pt-equal.c
new file mode 100644
index 00000000..8fbc519c
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-equal.c
@@ -0,0 +1,29 @@
+/* Default attributes. Generic version.
+ Copyright (C) 2000,02 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+/* Return true if __T1 and __T2 both name the same thread. Otherwise,
+ false. */
+int
+pthread_equal (pthread_t __t1, pthread_t __t2)
+{
+ return __t1 == __t2;
+}
diff --git a/libpthread/sysdeps/generic/pt-getconcurrency.c b/libpthread/sysdeps/generic/pt-getconcurrency.c
new file mode 100644
index 00000000..b55c8eef
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-getconcurrency.c
@@ -0,0 +1,27 @@
+/* Get the current level of desired concurrency. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_getconcurrency (void)
+{
+ return __pthread_concurrency;
+}
diff --git a/libpthread/sysdeps/generic/pt-getcpuclockid.c b/libpthread/sysdeps/generic/pt-getcpuclockid.c
new file mode 100644
index 00000000..81f6aabd
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-getcpuclockid.c
@@ -0,0 +1,34 @@
+/* Return a thread's cpu clockid. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <time.h>
+
+#include <pt-internal.h>
+
+int
+pthread_getcpuclockid (pthread_t thread, clockid_t *clock)
+{
+#ifdef CLOCK_THREAD_CPUTIME_ID
+ *clock = CLOCK_THREAD_CPUTIME_ID;
+ return 0;
+#else
+ return ENOSYS;
+#endif
+}
diff --git a/libpthread/sysdeps/generic/pt-getschedparam.c b/libpthread/sysdeps/generic/pt-getschedparam.c
new file mode 100644
index 00000000..c128d02e
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-getschedparam.c
@@ -0,0 +1,28 @@
+/* Get the scheduling parameters for a thread. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_getschedparam (pthread_t thread, int *policy,
+ struct sched_param *param)
+{
+ return ENOSYS;
+}
diff --git a/libpthread/sysdeps/generic/pt-getspecific.c b/libpthread/sysdeps/generic/pt-getspecific.c
new file mode 100644
index 00000000..2a7c4a9e
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-getspecific.c
@@ -0,0 +1,27 @@
+/* pthread_getspecific. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_getspecific (pthread_key_t key)
+{
+ return EINVAL;
+}
diff --git a/libpthread/sysdeps/generic/pt-init-specific.c b/libpthread/sysdeps/generic/pt-init-specific.c
new file mode 100644
index 00000000..00744fb6
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-init-specific.c
@@ -0,0 +1,27 @@
+/* __pthread_init_specific. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+error_t
+__pthread_init_specific (struct __pthread *thread)
+{
+ return 0;
+}
diff --git a/libpthread/sysdeps/generic/pt-key-create.c b/libpthread/sysdeps/generic/pt-key-create.c
new file mode 100644
index 00000000..7ef4b991
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-key-create.c
@@ -0,0 +1,27 @@
+/* pthread_key_create. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_key_create (pthread_key_t *key, void (*destructor) (void *))
+{
+ return ENOSYS;
+}
diff --git a/libpthread/sysdeps/generic/pt-key-delete.c b/libpthread/sysdeps/generic/pt-key-delete.c
new file mode 100644
index 00000000..6c86f8e2
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-key-delete.c
@@ -0,0 +1,27 @@
+/* pthread_key_delete. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_key_delete (pthread_key_t key)
+{
+ return ENOSYS;
+}
diff --git a/libpthread/sysdeps/generic/pt-key.h b/libpthread/sysdeps/generic/pt-key.h
new file mode 100644
index 00000000..544eb20f
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-key.h
@@ -0,0 +1,22 @@
+/* pthread_key internal declatations. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+
+#define PTHREAD_KEY_MEMBERS
diff --git a/libpthread/sysdeps/generic/pt-kill.c b/libpthread/sysdeps/generic/pt-kill.c
new file mode 100644
index 00000000..0dfac344
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-kill.c
@@ -0,0 +1,32 @@
+/* pthread-kill.c - Generic pthread-kill implementation.
+ Copyright (C) 2008 Free Software Foundation, Inc.
+ Written by Neal H. Walfield <neal@gnu.org>.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public License
+ as published by the Free Software Foundation; either version 3 of
+ the License, or (at your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this program. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include "sig-internal.h"
+
+int
+pthread_kill (pthread_t tid, int signo)
+{
+ siginfo_t si;
+ memset (&si, 0, sizeof (si));
+ si.si_signo = signo;
+
+ return pthread_kill_siginfo_np (tid, si);
+}
+
diff --git a/libpthread/sysdeps/generic/pt-mutex-destroy.c b/libpthread/sysdeps/generic/pt-mutex-destroy.c
new file mode 100644
index 00000000..3bbc73fe
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-mutex-destroy.c
@@ -0,0 +1,39 @@
+/* Destroy a mutex. Generic version.
+ Copyright (C) 2000, 2002, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <stdlib.h>
+#include <assert.h>
+
+#include <pt-internal.h>
+
+int
+_pthread_mutex_destroy (pthread_mutex_t *mutex)
+{
+ if (mutex->attr == __PTHREAD_ERRORCHECK_MUTEXATTR
+ || mutex->attr == __PTHREAD_RECURSIVE_MUTEXATTR)
+ /* Static attributes. */
+ ;
+ else
+ free (mutex->attr);
+
+ return 0;
+}
+
+strong_alias (_pthread_mutex_destroy, pthread_mutex_destroy);
diff --git a/libpthread/sysdeps/generic/pt-mutex-getprioceiling.c b/libpthread/sysdeps/generic/pt-mutex-getprioceiling.c
new file mode 100644
index 00000000..eb51639b
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-mutex-getprioceiling.c
@@ -0,0 +1,28 @@
+/* Get a mutex' priority ceiling. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_mutex_getprioceiling (const pthread_mutex_t *mutex,
+ int *prioceiling)
+{
+ return ENOSYS;
+}
diff --git a/libpthread/sysdeps/generic/pt-mutex-init.c b/libpthread/sysdeps/generic/pt-mutex-init.c
new file mode 100644
index 00000000..2f960286
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-mutex-init.c
@@ -0,0 +1,50 @@
+/* Initialize a mutex. Generic version.
+ Copyright (C) 2000, 2002, 2005, 2006, 2008 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <string.h>
+#include <stdlib.h>
+#include <assert.h>
+
+#include <pt-internal.h>
+
+int
+_pthread_mutex_init (pthread_mutex_t *mutex,
+ const pthread_mutexattr_t *attr)
+{
+ *mutex = (pthread_mutex_t) __PTHREAD_MUTEX_INITIALIZER;
+
+ if (! attr
+ || memcmp (attr, &__pthread_default_mutexattr, sizeof (*attr) == 0))
+ /* The default attributes. */
+ return 0;
+
+ if (! mutex->attr
+ || mutex->attr == __PTHREAD_ERRORCHECK_MUTEXATTR
+ || mutex->attr == __PTHREAD_RECURSIVE_MUTEXATTR)
+ mutex->attr = malloc (sizeof *attr);
+
+ if (! mutex->attr)
+ return ENOMEM;
+
+ *mutex->attr = *attr;
+ return 0;
+}
+
+strong_alias (_pthread_mutex_init, pthread_mutex_init);
diff --git a/libpthread/sysdeps/generic/pt-mutex-lock.c b/libpthread/sysdeps/generic/pt-mutex-lock.c
new file mode 100644
index 00000000..528e593f
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-mutex-lock.c
@@ -0,0 +1,37 @@
+/* Lock a mutex. Generic version.
+ Copyright (C) 2000, 2002, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <assert.h>
+
+#include <pt-internal.h>
+
+/* Implemented in pt-mutex-timedlock.c. */
+extern int __pthread_mutex_timedlock_internal (struct __pthread_mutex *mutex,
+ const struct timespec *abstime);
+
+/* Lock MUTEX, block if we can't get it. */
+int
+__pthread_mutex_lock (struct __pthread_mutex *mutex)
+{
+ return __pthread_mutex_timedlock_internal (mutex, 0);
+}
+
+strong_alias (__pthread_mutex_lock, _pthread_mutex_lock);
+strong_alias (__pthread_mutex_lock, pthread_mutex_lock);
diff --git a/libpthread/sysdeps/generic/pt-mutex-setprioceiling.c b/libpthread/sysdeps/generic/pt-mutex-setprioceiling.c
new file mode 100644
index 00000000..9fa8e50d
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-mutex-setprioceiling.c
@@ -0,0 +1,28 @@
+/* Set a mutex' priority ceiling. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_mutex_setprioceiling (pthread_mutex_t *mutex, int prio,
+ int *oldprio)
+{
+ return ENOSYS;
+}
diff --git a/libpthread/sysdeps/generic/pt-mutex-timedlock.c b/libpthread/sysdeps/generic/pt-mutex-timedlock.c
new file mode 100644
index 00000000..883e50af
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-mutex-timedlock.c
@@ -0,0 +1,187 @@
+/* Lock a mutex with a timeout. Generic version.
+ Copyright (C) 2000, 2002, 2005, 2008 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <assert.h>
+
+#include <pt-internal.h>
+
+#define LOSE do { * (int *) 0 = 0; } while (1)
+
+/* Try to lock MUTEX, block until *ABSTIME if it is already held. As
+ a GNU extension, if TIMESPEC is NULL then wait forever. */
+int
+__pthread_mutex_timedlock_internal (struct __pthread_mutex *mutex,
+ const struct timespec *abstime)
+{
+ struct __pthread *self;
+ const struct __pthread_mutexattr *attr = mutex->attr;
+
+ if (attr == __PTHREAD_ERRORCHECK_MUTEXATTR)
+ attr = &__pthread_errorcheck_mutexattr;
+ if (attr == __PTHREAD_RECURSIVE_MUTEXATTR)
+ attr = &__pthread_recursive_mutexattr;
+
+ __pthread_spin_lock (&mutex->__lock);
+ if (__pthread_spin_trylock (&mutex->__held) == 0)
+ /* Successfully acquired the lock. */
+ {
+#ifdef ALWAYS_TRACK_MUTEX_OWNER
+#ifndef NDEBUG
+ self = _pthread_self ();
+ if (self)
+ /* The main thread may take a lock before the library is fully
+ initialized, in particular, before the main thread has a
+ TCB. */
+ {
+ assert (! mutex->owner);
+ mutex->owner = _pthread_self ();
+ }
+#endif
+#endif
+
+ if (attr)
+ switch (attr->mutex_type)
+ {
+ case PTHREAD_MUTEX_NORMAL:
+ break;
+
+ case PTHREAD_MUTEX_RECURSIVE:
+ mutex->locks = 1;
+ case PTHREAD_MUTEX_ERRORCHECK:
+ mutex->owner = _pthread_self ();
+ break;
+
+ default:
+ LOSE;
+ }
+
+ __pthread_spin_unlock (&mutex->__lock);
+ return 0;
+ }
+
+ /* The lock is busy. */
+
+ self = _pthread_self ();
+ assert (self);
+
+ if (! attr || attr->mutex_type == PTHREAD_MUTEX_NORMAL)
+ {
+#if defined(ALWAYS_TRACK_MUTEX_OWNER)
+ assert (mutex->owner != self);
+#endif
+ }
+ else
+ {
+ switch (attr->mutex_type)
+ {
+ case PTHREAD_MUTEX_ERRORCHECK:
+ if (mutex->owner == self)
+ {
+ __pthread_spin_unlock (&mutex->__lock);
+ return EDEADLK;
+ }
+ break;
+
+ case PTHREAD_MUTEX_RECURSIVE:
+ if (mutex->owner == self)
+ {
+ mutex->locks ++;
+ __pthread_spin_unlock (&mutex->__lock);
+ return 0;
+ }
+ break;
+
+ default:
+ LOSE;
+ }
+ }
+
+#if !defined(ALWAYS_TRACK_MUTEX_OWNER)
+ if (attr && attr->mutex_type != PTHREAD_MUTEX_NORMAL)
+#endif
+ assert (mutex->owner);
+
+ if (abstime && (abstime->tv_nsec < 0 || abstime->tv_nsec >= 1000000000))
+ return EINVAL;
+
+ /* Add ourselves to the queue. */
+ __pthread_enqueue (&mutex->__queue, self);
+ __pthread_spin_unlock (&mutex->__lock);
+
+ /* Block the thread. */
+ if (abstime)
+ {
+ error_t err;
+
+ err = __pthread_timedblock (self, abstime);
+ if (err)
+ /* We timed out. We may need to disconnect ourself from the
+ waiter queue.
+
+ FIXME: What do we do if we get a wakeup message before we
+ disconnect ourself? It may remain until the next time we
+ block. */
+ {
+ assert (err == ETIMEDOUT);
+
+ __pthread_spin_lock (&mutex->__lock);
+ if (self->prevp)
+ __pthread_dequeue (self);
+ __pthread_spin_unlock (&mutex->__lock);
+
+ return err;
+ }
+ }
+ else
+ __pthread_block (self);
+
+#if !defined(ALWAYS_TRACK_MUTEX_OWNER)
+ if (attr && attr->mutex_type != PTHREAD_MUTEX_NORMAL)
+#endif
+ {
+ assert (mutex->owner == self);
+ }
+
+ if (attr)
+ switch (attr->mutex_type)
+ {
+ case PTHREAD_MUTEX_NORMAL:
+ break;
+
+ case PTHREAD_MUTEX_RECURSIVE:
+ assert (mutex->locks == 0);
+ mutex->locks = 1;
+ case PTHREAD_MUTEX_ERRORCHECK:
+ mutex->owner = self;
+ break;
+
+ default:
+ LOSE;
+ }
+
+ return 0;
+}
+
+int
+pthread_mutex_timedlock (struct __pthread_mutex *mutex,
+ const struct timespec *abstime)
+{
+ return __pthread_mutex_timedlock_internal (mutex, abstime);
+}
diff --git a/libpthread/sysdeps/generic/pt-mutex-transfer-np.c b/libpthread/sysdeps/generic/pt-mutex-transfer-np.c
new file mode 100644
index 00000000..967f1c7c
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-mutex-transfer-np.c
@@ -0,0 +1,66 @@
+/* Transfer ownership of a mutex. Generic version.
+ Copyright (C) 2008 Free Software Foundation, Inc.
+ Written by Neal H. Walfield <neal@gnu.org>.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public License
+ as published by the Free Software Foundation; either version 3 of
+ the License, or (at your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this program. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <pthread.h>
+#include <assert.h>
+
+#include <pt-internal.h>
+
+int
+__pthread_mutex_transfer_np (struct __pthread_mutex *mutex, pthread_t tid)
+{
+ assert (mutex->owner == _pthread_self ());
+
+ struct __pthread *thread = __pthread_getid (tid);
+ const struct __pthread_mutexattr *attr = mutex->attr;
+
+ if (! thread)
+ return ESRCH;
+
+ if (thread == _pthread_self ())
+ return 0;
+
+ if (attr == __PTHREAD_ERRORCHECK_MUTEXATTR)
+ attr = &__pthread_errorcheck_mutexattr;
+ if (attr == __PTHREAD_RECURSIVE_MUTEXATTR)
+ attr = &__pthread_recursive_mutexattr;
+
+ if (attr && attr->mutex_type == PTHREAD_MUTEX_ERRORCHECK)
+ {
+
+ if (mutex->owner != _pthread_self ())
+ return EPERM;
+
+ mutex->owner = thread;
+ }
+
+#ifndef NDEBUG
+# if !defined(ALWAYS_TRACK_MUTEX_OWNER)
+ if (attr && attr->mutex_type != PTHREAD_MUTEX_NORMAL)
+# endif
+ {
+ mutex->owner = thread;
+ }
+#endif
+
+ return 0;
+}
+
+strong_alias (__pthread_mutex_transfer_np, pthread_mutex_transfer_np)
diff --git a/libpthread/sysdeps/generic/pt-mutex-trylock.c b/libpthread/sysdeps/generic/pt-mutex-trylock.c
new file mode 100644
index 00000000..7a54cc9a
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-mutex-trylock.c
@@ -0,0 +1,112 @@
+/* Try to Lock a mutex. Generic version.
+ Copyright (C) 2002, 2005, 2008 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+
+#include <pt-internal.h>
+
+#define LOSE do { * (int *) 0 = 0; } while (1)
+
+/* Lock MUTEX, return EBUSY if we can't get it. */
+int
+__pthread_mutex_trylock (struct __pthread_mutex *mutex)
+{
+ int err;
+ struct __pthread *self;
+ const struct __pthread_mutexattr *attr = mutex->attr;
+
+ if (attr == __PTHREAD_ERRORCHECK_MUTEXATTR)
+ attr = &__pthread_errorcheck_mutexattr;
+ if (attr == __PTHREAD_RECURSIVE_MUTEXATTR)
+ attr = &__pthread_recursive_mutexattr;
+
+ __pthread_spin_lock (&mutex->__lock);
+ if (__pthread_spin_trylock (&mutex->__held) == 0)
+ /* Acquired the lock. */
+ {
+#if defined(ALWAYS_TRACK_MUTEX_OWNER)
+#ifndef NDEBUG
+ self = _pthread_self ();
+ if (self)
+ /* The main thread may take a lock before the library is fully
+ initialized, in particular, before the main thread has a
+ TCB. */
+ {
+ assert (! mutex->owner);
+ mutex->owner = _pthread_self ();
+ }
+#endif
+#endif
+
+ if (attr)
+ switch (attr->mutex_type)
+ {
+ case PTHREAD_MUTEX_NORMAL:
+ break;
+
+ case PTHREAD_MUTEX_RECURSIVE:
+ mutex->locks = 1;
+ case PTHREAD_MUTEX_ERRORCHECK:
+ mutex->owner = _pthread_self ();
+ break;
+
+ default:
+ LOSE;
+ }
+
+ __pthread_spin_unlock (&mutex->__lock);
+ return 0;
+ }
+
+ err = EBUSY;
+
+ if (attr)
+ {
+ self = _pthread_self ();
+ switch (attr->mutex_type)
+ {
+ case PTHREAD_MUTEX_NORMAL:
+ break;
+
+ case PTHREAD_MUTEX_ERRORCHECK:
+ /* We could check if MUTEX->OWNER is SELF, however, POSIX
+ does not permit pthread_mutex_trylock to return EDEADLK
+ instead of EBUSY, only pthread_mutex_lock. */
+ break;
+
+ case PTHREAD_MUTEX_RECURSIVE:
+ if (mutex->owner == self)
+ {
+ mutex->locks ++;
+ err = 0;
+ }
+ break;
+
+ default:
+ LOSE;
+ }
+ }
+
+ __pthread_spin_unlock (&mutex->__lock);
+
+ return err;
+}
+
+strong_alias (__pthread_mutex_trylock, _pthread_mutex_trylock);
+strong_alias (__pthread_mutex_trylock, pthread_mutex_trylock);
diff --git a/libpthread/sysdeps/generic/pt-mutex-unlock.c b/libpthread/sysdeps/generic/pt-mutex-unlock.c
new file mode 100644
index 00000000..09d70f8f
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-mutex-unlock.c
@@ -0,0 +1,108 @@
+/* Unlock a mutex. Generic version.
+ Copyright (C) 2000, 2002, 2008 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+
+#include <pt-internal.h>
+
+#define LOSE do { * (int *) 0 = 0; } while (1)
+
+/* Unlock MUTEX, rescheduling a waiting thread. */
+int
+__pthread_mutex_unlock (pthread_mutex_t *mutex)
+{
+ struct __pthread *wakeup;
+ const struct __pthread_mutexattr *attr = mutex->attr;
+
+ if (attr == __PTHREAD_ERRORCHECK_MUTEXATTR)
+ attr = &__pthread_errorcheck_mutexattr;
+ if (attr == __PTHREAD_RECURSIVE_MUTEXATTR)
+ attr = &__pthread_recursive_mutexattr;
+
+ __pthread_spin_lock (&mutex->__lock);
+
+ if (! attr || attr->mutex_type == PTHREAD_MUTEX_NORMAL)
+ {
+#if defined(ALWAYS_TRACK_MUTEX_OWNER)
+# ifndef NDEBUG
+ if (_pthread_self ())
+ {
+ assert (mutex->owner);
+ assert (mutex->owner == _pthread_self ());
+ mutex->owner = NULL;
+ }
+# endif
+#endif
+ }
+ else
+ switch (attr->mutex_type)
+ {
+ case PTHREAD_MUTEX_ERRORCHECK:
+ case PTHREAD_MUTEX_RECURSIVE:
+ if (mutex->owner != _pthread_self ())
+ {
+ __pthread_spin_unlock (&mutex->__lock);
+ return EPERM;
+ }
+
+ if (attr->mutex_type == PTHREAD_MUTEX_RECURSIVE)
+ if (--mutex->locks > 0)
+ {
+ __pthread_spin_unlock (&mutex->__lock);
+ return 0;
+ }
+
+ mutex->owner = 0;
+ break;
+
+ default:
+ LOSE;
+ }
+
+
+ if (mutex->__queue == NULL)
+ {
+ __pthread_spin_unlock (&mutex->__held);
+ __pthread_spin_unlock (&mutex->__lock);
+ return 0;
+ }
+
+ wakeup = mutex->__queue;
+ __pthread_dequeue (wakeup);
+
+#ifndef NDEBUG
+# if !defined (ALWAYS_TRACK_MUTEX_OWNER)
+ if (attr && attr->mutex_type != PTHREAD_MUTEX_NORMAL)
+# endif
+ {
+ mutex->owner = wakeup;
+ }
+#endif
+
+ /* We do not unlock MUTEX->held: we are transferring the ownership
+ to the thread that we are waking up. */
+
+ __pthread_spin_unlock (&mutex->__lock);
+ __pthread_wakeup (wakeup);
+
+ return 0;
+}
+
+strong_alias (__pthread_mutex_unlock, _pthread_mutex_unlock);
+strong_alias (__pthread_mutex_unlock, pthread_mutex_unlock);
diff --git a/libpthread/sysdeps/generic/pt-mutexattr-destroy.c b/libpthread/sysdeps/generic/pt-mutexattr-destroy.c
new file mode 100644
index 00000000..fe7e95d2
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-mutexattr-destroy.c
@@ -0,0 +1,27 @@
+/* pthread_mutexattr_destroy. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_mutexattr_destroy (pthread_mutexattr_t *attr)
+{
+ return 0;
+}
diff --git a/libpthread/sysdeps/generic/pt-mutexattr-getprioceiling.c b/libpthread/sysdeps/generic/pt-mutexattr-getprioceiling.c
new file mode 100644
index 00000000..d03d7192
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-mutexattr-getprioceiling.c
@@ -0,0 +1,28 @@
+/* pthread_mutexattr_getprioceiling. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_mutexattr_getprioceiling (const pthread_mutexattr_t *attr,
+ int *prioceiling)
+{
+ return ENOSYS;
+}
diff --git a/libpthread/sysdeps/generic/pt-mutexattr-getprotocol.c b/libpthread/sysdeps/generic/pt-mutexattr-getprotocol.c
new file mode 100644
index 00000000..d75021a3
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-mutexattr-getprotocol.c
@@ -0,0 +1,29 @@
+/* pthread_mutexattr_getprotocol. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_mutexattr_getprotocol (const pthread_mutexattr_t *attr,
+ int *protocol)
+{
+ *protocol = attr->protocol;
+ return 0;
+}
diff --git a/libpthread/sysdeps/generic/pt-mutexattr-getpshared.c b/libpthread/sysdeps/generic/pt-mutexattr-getpshared.c
new file mode 100644
index 00000000..0dad13b8
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-mutexattr-getpshared.c
@@ -0,0 +1,29 @@
+/* pthread_mutexattr_getpshared. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_mutexattr_getpshared (const pthread_mutexattr_t *attr,
+ int *pshared)
+{
+ *pshared = attr->pshared;
+ return 0;
+}
diff --git a/libpthread/sysdeps/generic/pt-mutexattr-gettype.c b/libpthread/sysdeps/generic/pt-mutexattr-gettype.c
new file mode 100644
index 00000000..ff2caea4
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-mutexattr-gettype.c
@@ -0,0 +1,28 @@
+/* pthread_mutexattr_gettype. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_mutexattr_gettype (const pthread_mutexattr_t *attr, int *type)
+{
+ *type = attr->mutex_type;
+ return 0;
+}
diff --git a/libpthread/sysdeps/generic/pt-mutexattr-init.c b/libpthread/sysdeps/generic/pt-mutexattr-init.c
new file mode 100644
index 00000000..2f23673c
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-mutexattr-init.c
@@ -0,0 +1,28 @@
+/* pthread_mutexattr_init. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_mutexattr_init (pthread_mutexattr_t *attr)
+{
+ *attr = __pthread_default_mutexattr;
+ return 0;
+}
diff --git a/libpthread/sysdeps/generic/pt-mutexattr-setprioceiling.c b/libpthread/sysdeps/generic/pt-mutexattr-setprioceiling.c
new file mode 100644
index 00000000..a9bbd327
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-mutexattr-setprioceiling.c
@@ -0,0 +1,28 @@
+/* pthread_mutexattr_setprioceiling. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_mutexattr_setprioceiling (pthread_mutexattr_t *attr,
+ int prioceiling)
+{
+ return ENOSYS;
+}
diff --git a/libpthread/sysdeps/generic/pt-mutexattr-setprotocol.c b/libpthread/sysdeps/generic/pt-mutexattr-setprotocol.c
new file mode 100644
index 00000000..9a0d1b1f
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-mutexattr-setprotocol.c
@@ -0,0 +1,42 @@
+/* pthread_mutexattr_setprotocol. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_mutexattr_setprotocol (pthread_mutexattr_t *attr,
+ int protocol)
+{
+ if (protocol == __pthread_default_mutexattr.protocol)
+ {
+ attr->protocol = protocol;
+ return 0;
+ }
+
+ switch (protocol)
+ {
+ case PTHREAD_PRIO_NONE:
+ case PTHREAD_PRIO_INHERIT:
+ case PTHREAD_PRIO_PROTECT:
+ return ENOTSUP;
+ default:
+ return EINVAL;
+ }
+}
diff --git a/libpthread/sysdeps/generic/pt-mutexattr-setpshared.c b/libpthread/sysdeps/generic/pt-mutexattr-setpshared.c
new file mode 100644
index 00000000..bcbc4d91
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-mutexattr-setpshared.c
@@ -0,0 +1,39 @@
+/* pthread_mutexattr_setpshared. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_mutexattr_setpshared (pthread_mutexattr_t *attr,
+ int pshared)
+{
+ switch (pshared)
+ {
+ case PTHREAD_PROCESS_PRIVATE:
+ attr->pshared = pshared;
+ return 0;
+
+ case PTHREAD_PROCESS_SHARED:
+ return ENOTSUP;
+
+ default:
+ return EINVAL;
+ }
+}
diff --git a/libpthread/sysdeps/generic/pt-mutexattr-settype.c b/libpthread/sysdeps/generic/pt-mutexattr-settype.c
new file mode 100644
index 00000000..e7ae213a
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-mutexattr-settype.c
@@ -0,0 +1,37 @@
+/* pthread_mutexattr_settype. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_mutexattr_settype (pthread_mutexattr_t *attr, int type)
+{
+ switch (type)
+ {
+ case PTHREAD_MUTEX_NORMAL:
+ case PTHREAD_MUTEX_ERRORCHECK:
+ case PTHREAD_MUTEX_RECURSIVE:
+ attr->mutex_type = type;
+ return 0;
+
+ default:
+ return EINVAL;
+ }
+}
diff --git a/libpthread/sysdeps/generic/pt-mutexattr.c b/libpthread/sysdeps/generic/pt-mutexattr.c
new file mode 100644
index 00000000..5ebde6ea
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-mutexattr.c
@@ -0,0 +1,45 @@
+/* Default mutex attributes. Generic version.
+ Copyright (C) 2000, 2002, 2008 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+const struct __pthread_mutexattr __pthread_default_mutexattr =
+{
+ prioceiling: 0,
+ protocol: PTHREAD_PRIO_NONE,
+ pshared: PTHREAD_PROCESS_PRIVATE,
+ mutex_type: PTHREAD_MUTEX_DEFAULT
+};
+
+const struct __pthread_mutexattr __pthread_errorcheck_mutexattr =
+{
+ prioceiling: 0,
+ protocol: PTHREAD_PRIO_NONE,
+ pshared: PTHREAD_PROCESS_PRIVATE,
+ mutex_type: PTHREAD_MUTEX_ERRORCHECK
+};
+
+const struct __pthread_mutexattr __pthread_recursive_mutexattr =
+{
+ prioceiling: 0,
+ protocol: PTHREAD_PRIO_NONE,
+ pshared: PTHREAD_PROCESS_PRIVATE,
+ mutex_type: PTHREAD_MUTEX_RECURSIVE
+};
diff --git a/libpthread/sysdeps/generic/pt-once.c b/libpthread/sysdeps/generic/pt-once.c
new file mode 100644
index 00000000..5be5e484
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-once.c
@@ -0,0 +1,43 @@
+/* pthread_once. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <bits/memory.h>
+
+#include <pt-internal.h>
+
+int
+pthread_once (pthread_once_t *once_control, void (*init_routine) (void))
+{
+ if (once_control->run == 0)
+ {
+ __pthread_spin_lock (&once_control->lock);
+
+ if (once_control->run == 0)
+ {
+ init_routine ();
+ __memory_barrier ();
+ once_control->run = 1;
+ }
+
+ __pthread_spin_unlock (&once_control->lock);
+ }
+
+ return 0;
+}
diff --git a/libpthread/sysdeps/generic/pt-rwlock-attr.c b/libpthread/sysdeps/generic/pt-rwlock-attr.c
new file mode 100644
index 00000000..1587feef
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-rwlock-attr.c
@@ -0,0 +1,26 @@
+/* Default rwlock attributes. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+const struct __pthread_rwlockattr __pthread_default_rwlockattr =
+{
+ pshared: PTHREAD_PROCESS_PRIVATE
+};
diff --git a/libpthread/sysdeps/generic/pt-rwlock-destroy.c b/libpthread/sysdeps/generic/pt-rwlock-destroy.c
new file mode 100644
index 00000000..045eebd8
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-rwlock-destroy.c
@@ -0,0 +1,29 @@
+/* Destroy a rwlock. Generic version.
+ Copyright (C) 2002, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+_pthread_rwlock_destroy (pthread_rwlock_t *rwlock)
+{
+ return 0;
+}
+
+strong_alias (_pthread_rwlock_destroy, pthread_rwlock_destroy);
diff --git a/libpthread/sysdeps/generic/pt-rwlock-init.c b/libpthread/sysdeps/generic/pt-rwlock-init.c
new file mode 100644
index 00000000..c9ff9b28
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-rwlock-init.c
@@ -0,0 +1,45 @@
+/* Initialize a rwlock. Generic version.
+ Copyright (C) 2002, 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <string.h>
+#include <pt-internal.h>
+
+int
+_pthread_rwlock_init (pthread_rwlock_t *rwlock,
+ const pthread_rwlockattr_t *attr)
+{
+ *rwlock = (pthread_rwlock_t) __PTHREAD_RWLOCK_INITIALIZER;
+
+ if (! attr
+ || memcmp (attr, &__pthread_default_rwlockattr, sizeof (*attr) == 0))
+ /* Use the default attributes. */
+ return 0;
+
+ /* Non-default attributes. */
+
+ rwlock->__attr = malloc (sizeof *attr);
+ if (! rwlock->__attr)
+ return ENOMEM;
+
+ *rwlock->__attr = *attr;
+ return 0;
+}
+
+strong_alias (_pthread_rwlock_init, pthread_rwlock_init);
diff --git a/libpthread/sysdeps/generic/pt-rwlock-rdlock.c b/libpthread/sysdeps/generic/pt-rwlock-rdlock.c
new file mode 100644
index 00000000..480cf489
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-rwlock-rdlock.c
@@ -0,0 +1,32 @@
+/* Acquire a rwlock for reading. Generic version.
+ Copyright (C) 2002, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+/* Implemented in pt-rwlock-timedrdlock.c. */
+extern int __pthread_rwlock_timedrdlock_internal (struct __pthread_rwlock *rwlock,
+ const struct timespec *abstime);
+
+/* Acquire RWLOCK for reading, block if we can't get it. */
+int
+pthread_rwlock_rdlock (struct __pthread_rwlock *rwlock)
+{
+ return __pthread_rwlock_timedrdlock_internal (rwlock, 0);
+}
diff --git a/libpthread/sysdeps/generic/pt-rwlock-timedrdlock.c b/libpthread/sysdeps/generic/pt-rwlock-timedrdlock.c
new file mode 100644
index 00000000..ba610fa5
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-rwlock-timedrdlock.c
@@ -0,0 +1,113 @@
+/* Acquire a rwlock for reading. Generic version.
+ Copyright (C) 2002, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <assert.h>
+
+#include <pt-internal.h>
+
+/* Acquire the rwlock *RWLOCK for reading blocking until *ABSTIME if
+ it is already held. As a GNU extension, if TIMESPEC is NULL then
+ wait forever. */
+int
+__pthread_rwlock_timedrdlock_internal (struct __pthread_rwlock *rwlock,
+ const struct timespec *abstime)
+{
+ struct __pthread *self;
+
+ __pthread_spin_lock (&rwlock->__lock);
+ if (__pthread_spin_trylock (&rwlock->__held) == 0)
+ /* Successfully acquired the lock. */
+ {
+ assert (rwlock->readerqueue == 0);
+ assert (rwlock->writerqueue == 0);
+ assert (rwlock->readers == 0);
+
+ rwlock->readers = 1;
+ __pthread_spin_unlock (&rwlock->__lock);
+ return 0;
+ }
+ else
+ /* Lock is held, but is held by a reader? */
+ if (rwlock->readers > 0)
+ /* Just add ourself to number of readers. */
+ {
+ assert (rwlock->readerqueue == 0);
+ rwlock->readers ++;
+ __pthread_spin_unlock (&rwlock->__lock);
+ return 0;
+ }
+
+ /* The lock is busy. */
+
+ /* Better be blocked by a writer. */
+ assert (rwlock->readers == 0);
+
+ if (abstime && (abstime->tv_nsec < 0 || abstime->tv_nsec >= 1000000000))
+ return EINVAL;
+
+ self = _pthread_self ();
+
+ /* Add ourself to the queue. */
+ __pthread_enqueue (&rwlock->readerqueue, self);
+ __pthread_spin_unlock (&rwlock->__lock);
+
+ /* Block the thread. */
+ if (abstime)
+ {
+ error_t err;
+
+ err = __pthread_timedblock (self, abstime);
+ if (err)
+ /* We timed out. We may need to disconnect ourself from the
+ waiter queue.
+
+ FIXME: What do we do if we get a wakeup message before we
+ disconnect ourself? It may remain until the next time we
+ block. */
+ {
+ assert (err == ETIMEDOUT);
+
+ __pthread_spin_lock (&rwlock->__lock);
+ if (self->prevp)
+ /* Disconnect ourself. */
+ __pthread_dequeue (self);
+ __pthread_spin_unlock (&rwlock->__lock);
+
+ return err;
+ }
+ }
+ else
+ __pthread_block (self);
+
+
+ /* The reader count has already been increment by whoever woke us
+ up. */
+
+ assert (rwlock->readers > 0);
+
+ return 0;
+}
+
+int
+pthread_rwlock_timedrdlock (struct __pthread_rwlock *rwlock,
+ const struct timespec *abstime)
+{
+ return __pthread_rwlock_timedrdlock_internal (rwlock, abstime);
+}
diff --git a/libpthread/sysdeps/generic/pt-rwlock-timedwrlock.c b/libpthread/sysdeps/generic/pt-rwlock-timedwrlock.c
new file mode 100644
index 00000000..04eab51f
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-rwlock-timedwrlock.c
@@ -0,0 +1,95 @@
+/* Acquire a rwlock for writing. Generic version.
+ Copyright (C) 2002, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <assert.h>
+
+#include <pt-internal.h>
+
+/* Acquire RWLOCK for writing blocking until *ABSTIME if we cannot get
+ it. As a special GNU extension, if ABSTIME is NULL then the wait
+ shall not time out. */
+int
+__pthread_rwlock_timedwrlock_internal (struct __pthread_rwlock *rwlock,
+ const struct timespec *abstime)
+{
+ struct __pthread *self;
+
+ __pthread_spin_lock (&rwlock->__lock);
+ if (__pthread_spin_trylock (&rwlock->__held) == 0)
+ /* Successfully acquired the lock. */
+ {
+ assert (rwlock->readerqueue == 0);
+ assert (rwlock->writerqueue == 0);
+ assert (rwlock->readers == 0);
+
+ __pthread_spin_unlock (&rwlock->__lock);
+ return 0;
+ }
+
+ /* The lock is busy. */
+
+ if (abstime && (abstime->tv_nsec < 0 || abstime->tv_nsec >= 1000000000))
+ return EINVAL;
+
+ self = _pthread_self ();
+
+ /* Add ourselves to the queue. */
+ __pthread_enqueue (&rwlock->writerqueue, self);
+ __pthread_spin_unlock (&rwlock->__lock);
+
+ /* Block the thread. */
+ if (abstime)
+ {
+ error_t err;
+
+ err = __pthread_timedblock (self, abstime);
+ if (err)
+ /* We timed out. We may need to disconnect ourself from the
+ waiter queue.
+
+ FIXME: What do we do if we get a wakeup message before we
+ disconnect ourself? It may remain until the next time we
+ block. */
+ {
+ assert (err == ETIMEDOUT);
+
+ __pthread_spin_lock (&rwlock->__lock);
+ if (self->prevp)
+ /* Disconnect ourself. */
+ __pthread_dequeue (self);
+ __pthread_spin_unlock (&rwlock->__lock);
+
+ return err;
+ }
+ }
+ else
+ __pthread_block (self);
+
+ assert (rwlock->readers == 0);
+
+ return 0;
+}
+
+int
+pthread_rwlock_timedwrlock (struct __pthread_rwlock *rwlock,
+ const struct timespec *abstime)
+{
+ return __pthread_rwlock_timedwrlock_internal (rwlock, abstime);
+}
diff --git a/libpthread/sysdeps/generic/pt-rwlock-tryrdlock.c b/libpthread/sysdeps/generic/pt-rwlock-tryrdlock.c
new file mode 100644
index 00000000..2419efb1
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-rwlock-tryrdlock.c
@@ -0,0 +1,56 @@
+/* Try to acquire a rwlock for reading. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <assert.h>
+
+#include <pt-internal.h>
+
+/* Try to acquire RWLOCK. */
+int
+pthread_rwlock_tryrdlock (struct __pthread_rwlock *rwlock)
+{
+ __pthread_spin_lock (&rwlock->__lock);
+ if (__pthread_spin_trylock (&rwlock->__held) == 0)
+ /* Successfully acquired the lock. */
+ {
+ assert (rwlock->readerqueue == 0);
+ assert (rwlock->writerqueue == 0);
+ assert (rwlock->readers == 0);
+
+ rwlock->readers = 1;
+ __pthread_spin_unlock (&rwlock->__lock);
+ return 0;
+ }
+ else
+ /* Lock is held, but is held by a reader? */
+ if (rwlock->readers > 0)
+ {
+ assert (rwlock->readerqueue == 0);
+ rwlock->readers ++;
+ __pthread_spin_unlock (&rwlock->__lock);
+ return 0;
+ }
+
+ /* The lock is busy. */
+
+ __pthread_spin_unlock (&rwlock->__lock);
+
+ return EBUSY;
+}
diff --git a/libpthread/sysdeps/generic/pt-rwlock-trywrlock.c b/libpthread/sysdeps/generic/pt-rwlock-trywrlock.c
new file mode 100644
index 00000000..6b9c5b56
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-rwlock-trywrlock.c
@@ -0,0 +1,46 @@
+/* Try to acquire a rwlock for writing. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <assert.h>
+
+#include <pt-internal.h>
+
+/* Try to acquire RWLOCK for writing. */
+int
+pthread_rwlock_trywrlock (struct __pthread_rwlock *rwlock)
+{
+ __pthread_spin_lock (&rwlock->__lock);
+ if (__pthread_spin_trylock (&rwlock->__held) == 0)
+ /* Successfully acquired the lock. */
+ {
+ assert (rwlock->readerqueue == 0);
+ assert (rwlock->writerqueue == 0);
+ assert (rwlock->readers == 0);
+
+ __pthread_spin_unlock (&rwlock->__lock);
+ return 0;
+ }
+
+ /* The lock is busy. */
+
+ __pthread_spin_unlock (&rwlock->__lock);
+
+ return EBUSY;
+}
diff --git a/libpthread/sysdeps/generic/pt-rwlock-unlock.c b/libpthread/sysdeps/generic/pt-rwlock-unlock.c
new file mode 100644
index 00000000..fb23a0b9
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-rwlock-unlock.c
@@ -0,0 +1,90 @@
+/* Unlock a rwlock. Generic version.
+ Copyright (C) 2000,02 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+
+#include <pt-internal.h>
+
+/* Unlock *RWLOCK, rescheduling a waiting writer thread or, if there
+ are no threads waiting for a write lock, rescheduling the reader
+ threads. */
+int
+pthread_rwlock_unlock (pthread_rwlock_t *rwlock)
+{
+ struct __pthread *wakeup;
+
+ __pthread_spin_lock (&rwlock->__lock);
+
+ assert (__pthread_spin_trylock (&rwlock->__held) == EBUSY);
+
+ if (rwlock->readers > 1)
+ /* There are other readers. */
+ {
+ rwlock->readers --;
+ __pthread_spin_unlock (&rwlock->__lock);
+ return 0;
+ }
+
+ if (rwlock->readers == 1)
+ /* Last reader. */
+ rwlock->readers = 0;
+
+
+ /* Wake someone else up. Try the writer queue first, then the
+ reader queue if that is empty. */
+
+ if (rwlock->writerqueue)
+ {
+ wakeup = rwlock->writerqueue;
+ __pthread_dequeue (wakeup);
+
+ /* We do not unlock RWLOCK->held: we are transferring the ownership
+ to the thread that we are waking up. */
+
+ __pthread_spin_unlock (&rwlock->__lock);
+ __pthread_wakeup (wakeup);
+
+ return 0;
+ }
+
+ if (rwlock->readerqueue)
+ {
+ __pthread_queue_iterate (rwlock->readerqueue, wakeup)
+ rwlock->readers ++;
+
+ wakeup = rwlock->readerqueue;
+ rwlock->readerqueue = 0;
+
+ __pthread_spin_unlock (&rwlock->__lock);
+
+ /* We can safely walk the list of waiting threads without holding
+ the lock since it is now decoupled from the rwlock. */
+ __pthread_dequeuing_iterate (wakeup, wakeup)
+ __pthread_wakeup (wakeup);
+
+ return 0;
+ }
+
+
+ /* Noone is waiting. Just unlock it. */
+
+ __pthread_spin_unlock (&rwlock->__held);
+ __pthread_spin_unlock (&rwlock->__lock);
+ return 0;
+}
diff --git a/libpthread/sysdeps/generic/pt-rwlock-wrlock.c b/libpthread/sysdeps/generic/pt-rwlock-wrlock.c
new file mode 100644
index 00000000..be85b906
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-rwlock-wrlock.c
@@ -0,0 +1,34 @@
+/* Acquire a rwlock for writing. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <assert.h>
+
+#include <pt-internal.h>
+
+/* Implemented in pt-rwlock-timedwrlock.c. */
+extern int __pthread_rwlock_timedwrlock_internal (struct __pthread_rwlock *rwlock,
+ const struct timespec *abstime);
+
+/* Acquire RWLOCK for writing. */
+int
+pthread_rwlock_wrlock (struct __pthread_rwlock *rwlock)
+{
+ return __pthread_rwlock_timedwrlock_internal (rwlock, 0);
+}
diff --git a/libpthread/sysdeps/generic/pt-rwlockattr-destroy.c b/libpthread/sysdeps/generic/pt-rwlockattr-destroy.c
new file mode 100644
index 00000000..eabfcbe8
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-rwlockattr-destroy.c
@@ -0,0 +1,27 @@
+/* pthread_rwlockattr_destroy. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_rwlockattr_destroy (pthread_rwlockattr_t *attr)
+{
+ return 0;
+}
diff --git a/libpthread/sysdeps/generic/pt-rwlockattr-getpshared.c b/libpthread/sysdeps/generic/pt-rwlockattr-getpshared.c
new file mode 100644
index 00000000..e8752c0c
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-rwlockattr-getpshared.c
@@ -0,0 +1,29 @@
+/* pthread_rwlockattr_getpshared. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_rwlockattr_getpshared (const pthread_rwlockattr_t *attr,
+ int *pshared)
+{
+ *pshared = attr->pshared;
+ return 0;
+}
diff --git a/libpthread/sysdeps/generic/pt-rwlockattr-init.c b/libpthread/sysdeps/generic/pt-rwlockattr-init.c
new file mode 100644
index 00000000..34da6bf0
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-rwlockattr-init.c
@@ -0,0 +1,28 @@
+/* pthread_rwlockattr_init. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_rwlockattr_init (pthread_rwlockattr_t *attr)
+{
+ *attr = __pthread_default_rwlockattr;
+ return 0;
+}
diff --git a/libpthread/sysdeps/generic/pt-rwlockattr-setpshared.c b/libpthread/sysdeps/generic/pt-rwlockattr-setpshared.c
new file mode 100644
index 00000000..a861d034
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-rwlockattr-setpshared.c
@@ -0,0 +1,39 @@
+/* pthread_rwlockattr_setpshared. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_rwlockattr_setpshared (pthread_rwlockattr_t *attr,
+ int pshared)
+{
+ switch (pshared)
+ {
+ case PTHREAD_PROCESS_PRIVATE:
+ attr->pshared = pshared;
+ return 0;
+
+ case PTHREAD_PROCESS_SHARED:
+ return ENOTSUP;
+
+ default:
+ return EINVAL;
+ }
+}
diff --git a/libpthread/sysdeps/generic/pt-setconcurrency.c b/libpthread/sysdeps/generic/pt-setconcurrency.c
new file mode 100644
index 00000000..cd55b1ba
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-setconcurrency.c
@@ -0,0 +1,34 @@
+/* Set the desired level of concurrency. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int __pthread_concurrency;
+
+int
+pthread_setconcurrency (int new_level)
+{
+ if (new_level < 0)
+ return EINVAL;
+
+ __pthread_concurrency = new_level;
+
+ return 0;
+}
diff --git a/libpthread/sysdeps/generic/pt-setschedparam.c b/libpthread/sysdeps/generic/pt-setschedparam.c
new file mode 100644
index 00000000..a70b0796
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-setschedparam.c
@@ -0,0 +1,28 @@
+/* Set the scheduling parameters for a thread. Generic version.
+ Copyright (C) 2002, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_setschedparam (pthread_t thread, int policy,
+ const struct sched_param *param)
+{
+ return ENOSYS;
+}
diff --git a/libpthread/sysdeps/generic/pt-setschedprio.c b/libpthread/sysdeps/generic/pt-setschedprio.c
new file mode 100644
index 00000000..60668eb1
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-setschedprio.c
@@ -0,0 +1,27 @@
+/* Set the scheduling priority of a thread. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_setschedprio (pthread_t thread, int prio)
+{
+ return ENOSYS;
+}
diff --git a/libpthread/sysdeps/generic/pt-setspecific.c b/libpthread/sysdeps/generic/pt-setspecific.c
new file mode 100644
index 00000000..d520c5df
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-setspecific.c
@@ -0,0 +1,27 @@
+/* pthread_setspecific. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_setspecific (pthread_key_t key, const void *value)
+{
+ return EINVAL;
+}
diff --git a/libpthread/sysdeps/generic/pt-startup.c b/libpthread/sysdeps/generic/pt-startup.c
new file mode 100644
index 00000000..c21a1819
--- /dev/null
+++ b/libpthread/sysdeps/generic/pt-startup.c
@@ -0,0 +1,25 @@
+/* Thread initialization. Generic version.
+ Copyright (C) 2008 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pt-internal.h>
+
+void
+__pthread_startup (void)
+{
+}
diff --git a/libpthread/sysdeps/generic/raise.c b/libpthread/sysdeps/generic/raise.c
new file mode 100644
index 00000000..410f557d
--- /dev/null
+++ b/libpthread/sysdeps/generic/raise.c
@@ -0,0 +1,41 @@
+/* raise.c - Generic raise implementation.
+ Copyright (C) 2008 Free Software Foundation, Inc.
+ Written by Neal H. Walfield <neal@gnu.org>.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public License
+ as published by the Free Software Foundation; either version 3 of
+ the License, or (at your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this program. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include "sig-internal.h"
+
+int
+raise (int signo)
+{
+ /* According to POSIX, if we implement threads (and we do), then
+ "the effect of the raise() function shall be equivalent to
+ calling: pthread_kill(pthread_self(), sig);" */
+
+debug (0, "");
+ int err = pthread_kill (pthread_self (), signo);
+debug (0, "");
+ if (err)
+ {
+ errno = err;
+ return -1;
+ }
+
+ return 0;
+}
+
diff --git a/libpthread/sysdeps/generic/sem-close.c b/libpthread/sysdeps/generic/sem-close.c
new file mode 100644
index 00000000..9f48032f
--- /dev/null
+++ b/libpthread/sysdeps/generic/sem-close.c
@@ -0,0 +1,32 @@
+/* Close a named semaphore. Generic version.
+ Copyright (C) 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <semaphore.h>
+#include <errno.h>
+
+#include <pt-internal.h>
+
+int
+__sem_close (sem_t *sem)
+{
+ errno = EOPNOTSUPP;
+ return -1;
+}
+
+strong_alias (__sem_close, sem_close);
diff --git a/libpthread/sysdeps/generic/sem-destroy.c b/libpthread/sysdeps/generic/sem-destroy.c
new file mode 100644
index 00000000..6486599c
--- /dev/null
+++ b/libpthread/sysdeps/generic/sem-destroy.c
@@ -0,0 +1,38 @@
+/* Destroy a semaphore. Generic version.
+ Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <semaphore.h>
+#include <errno.h>
+
+#include <pt-internal.h>
+
+int
+__sem_destroy (sem_t *sem)
+{
+ if (sem->__queue)
+ /* There are threads waiting on *SEM. */
+ {
+ errno = EBUSY;
+ return -1;
+ }
+
+ return 0;
+}
+
+strong_alias (__sem_destroy, sem_destroy);
diff --git a/libpthread/sysdeps/generic/sem-getvalue.c b/libpthread/sysdeps/generic/sem-getvalue.c
new file mode 100644
index 00000000..7762089b
--- /dev/null
+++ b/libpthread/sysdeps/generic/sem-getvalue.c
@@ -0,0 +1,33 @@
+/* Get the value of a semaphore. Generic version.
+ Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <semaphore.h>
+#include <pt-internal.h>
+
+int
+__sem_getvalue (sem_t *restrict sem, int *restrict value)
+{
+ __pthread_spin_lock (&sem->__lock);
+ *value = sem->__value;
+ __pthread_spin_unlock (&sem->__lock);
+
+ return 0;
+}
+
+strong_alias (__sem_getvalue, sem_getvalue);
diff --git a/libpthread/sysdeps/generic/sem-init.c b/libpthread/sysdeps/generic/sem-init.c
new file mode 100644
index 00000000..d2414f5d
--- /dev/null
+++ b/libpthread/sysdeps/generic/sem-init.c
@@ -0,0 +1,46 @@
+/* Initialize a semaphore. Generic version.
+ Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <semaphore.h>
+#include <errno.h>
+
+#include <pt-internal.h>
+
+int
+__sem_init (sem_t *sem, int pshared, unsigned value)
+{
+ if (pshared != 0)
+ {
+ errno = EOPNOTSUPP;
+ return -1;
+ }
+
+#ifdef SEM_VALUE_MAX
+ if (value > SEM_VALUE_MAX)
+ {
+ errno = EINVAL;
+ return -1;
+ }
+#endif
+
+ *sem = (sem_t) __SEMAPHORE_INITIALIZER (pshared, value);
+ return 0;
+}
+
+strong_alias (__sem_init, sem_init);
diff --git a/libpthread/sysdeps/generic/sem-open.c b/libpthread/sysdeps/generic/sem-open.c
new file mode 100644
index 00000000..bae87ed0
--- /dev/null
+++ b/libpthread/sysdeps/generic/sem-open.c
@@ -0,0 +1,32 @@
+/* Open a named semaphore. Generic version.
+ Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <semaphore.h>
+#include <errno.h>
+
+#include <pt-internal.h>
+
+sem_t *
+__sem_open (const char *name, int open_flags, ...)
+{
+ errno = EOPNOTSUPP;
+ return SEM_FAILED;
+}
+
+strong_alias (__sem_open, sem_open);
diff --git a/libpthread/sysdeps/generic/sem-post.c b/libpthread/sysdeps/generic/sem-post.c
new file mode 100644
index 00000000..6d438bf2
--- /dev/null
+++ b/libpthread/sysdeps/generic/sem-post.c
@@ -0,0 +1,62 @@
+/* Post a semaphore. Generic version.
+ Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <semaphore.h>
+#include <assert.h>
+
+#include <pt-internal.h>
+
+int
+__sem_post (sem_t *sem)
+{
+ struct __pthread *wakeup;
+
+ __pthread_spin_lock (&sem->__lock);
+ if (sem->__value > 0)
+ /* Do a quick up. */
+ {
+ assert (! sem->__queue);
+ sem->__value ++;
+ __pthread_spin_unlock (&sem->__lock);
+ return 0;
+ }
+
+ if (! sem->__queue)
+ /* No one waiting. */
+ {
+ sem->__value = 1;
+ __pthread_spin_unlock (&sem->__lock);
+ return 0;
+ }
+
+ /* Wake someone up. */
+
+ /* First dequeue someone. */
+ wakeup = sem->__queue;
+ __pthread_dequeue (wakeup);
+
+ /* Then drop the lock and transfer control. */
+ __pthread_spin_unlock (&sem->__lock);
+
+ __pthread_wakeup (wakeup);
+
+ return 0;
+}
+
+strong_alias (__sem_post, sem_post);
diff --git a/libpthread/sysdeps/generic/sem-timedwait.c b/libpthread/sysdeps/generic/sem-timedwait.c
new file mode 100644
index 00000000..e34539a9
--- /dev/null
+++ b/libpthread/sysdeps/generic/sem-timedwait.c
@@ -0,0 +1,91 @@
+/* Wait on a semaphore with a timeout. Generic version.
+ Copyright (C) 2005, 2006, 2008 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <semaphore.h>
+#include <errno.h>
+#include <assert.h>
+
+#include <pt-internal.h>
+
+int
+__sem_timedwait_internal (sem_t *restrict sem,
+ const struct timespec *restrict timeout)
+{
+ struct __pthread *self;
+
+ __pthread_spin_lock (&sem->__lock);
+ if (sem->__value > 0)
+ /* Successful down. */
+ {
+ sem->__value --;
+ __pthread_spin_unlock (&sem->__lock);
+ return 0;
+ }
+
+ if (timeout && (timeout->tv_nsec < 0 || timeout->tv_nsec >= 1000000000))
+ {
+ errno = EINVAL;
+ return -1;
+ }
+
+ /* Add ourselves to the queue. */
+ self = _pthread_self ();
+
+ __pthread_enqueue (&sem->__queue, self);
+ __pthread_spin_unlock (&sem->__lock);
+
+ /* Block the thread. */
+ if (timeout)
+ {
+ error_t err;
+
+ err = __pthread_timedblock (self, timeout);
+ if (err)
+ /* We timed out. We may need to disconnect ourself from the
+ waiter queue.
+
+ FIXME: What do we do if we get a wakeup message before we
+ disconnect ourself? It may remain until the next time we
+ block. */
+ {
+ assert (err == ETIMEDOUT);
+
+ __pthread_spin_lock (&sem->__lock);
+ if (self->prevp)
+ __pthread_dequeue (self);
+ __pthread_spin_unlock (&sem->__lock);
+
+ errno = err;
+ return -1;
+ }
+ }
+ else
+ __pthread_block (self);
+
+ return 0;
+}
+
+int
+__sem_timedwait (sem_t *restrict sem,
+ const struct timespec *restrict timeout)
+{
+ return __sem_timedwait_internal (sem, timeout);
+}
+
+strong_alias (__sem_timedwait, sem_timedwait);
diff --git a/libpthread/sysdeps/generic/sem-trywait.c b/libpthread/sysdeps/generic/sem-trywait.c
new file mode 100644
index 00000000..437e2822
--- /dev/null
+++ b/libpthread/sysdeps/generic/sem-trywait.c
@@ -0,0 +1,42 @@
+/* Lock a semaphore if it does not require blocking. Generic version.
+ Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <semaphore.h>
+#include <errno.h>
+
+#include <pt-internal.h>
+
+int
+__sem_trywait (sem_t *sem)
+{
+ __pthread_spin_lock (&sem->__lock);
+ if (sem->__value > 0)
+ /* Successful down. */
+ {
+ sem->__value --;
+ __pthread_spin_unlock (&sem->__lock);
+ return 0;
+ }
+ __pthread_spin_unlock (&sem->__lock);
+
+ errno = EAGAIN;
+ return -1;
+}
+
+strong_alias (__sem_trywait, sem_trywait);
diff --git a/libpthread/sysdeps/generic/sem-unlink.c b/libpthread/sysdeps/generic/sem-unlink.c
new file mode 100644
index 00000000..570ed614
--- /dev/null
+++ b/libpthread/sysdeps/generic/sem-unlink.c
@@ -0,0 +1,32 @@
+/* Unlink a named semaphore. Generic version.
+ Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <semaphore.h>
+#include <errno.h>
+
+#include <pt-internal.h>
+
+int
+__sem_unlink (const char *name)
+{
+ errno = EOPNOTSUPP;
+ return -1;
+}
+
+strong_alias (__sem_unlink, sem_unlink);
diff --git a/libpthread/sysdeps/generic/sem-wait.c b/libpthread/sysdeps/generic/sem-wait.c
new file mode 100644
index 00000000..8347480c
--- /dev/null
+++ b/libpthread/sysdeps/generic/sem-wait.c
@@ -0,0 +1,32 @@
+/* Wait on a semaphore. Generic version.
+ Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <semaphore.h>
+#include <pt-internal.h>
+
+extern int __sem_timedwait_internal (sem_t *restrict sem,
+ const struct timespec *restrict timeout);
+
+int
+__sem_wait (sem_t *sem)
+{
+ return __sem_timedwait_internal (sem, 0);
+}
+
+strong_alias (__sem_wait, sem_wait);
diff --git a/libpthread/sysdeps/generic/sigaddset.c b/libpthread/sysdeps/generic/sigaddset.c
new file mode 100644
index 00000000..14edb71c
--- /dev/null
+++ b/libpthread/sysdeps/generic/sigaddset.c
@@ -0,0 +1,35 @@
+/* sigaddset.c - Generic sigaddset implementation.
+ Copyright (C) 2008 Free Software Foundation, Inc.
+ Written by Neal H. Walfield <neal@gnu.org>.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public License
+ as published by the Free Software Foundation; either version 3 of
+ the License, or (at your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this program. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include "sig-internal.h"
+
+int
+sigaddset (sigset_t *sigset, int signo)
+{
+ if (signo <= 0 || signo >= NSIG)
+ {
+ errno = EINVAL;
+ return -1;
+ }
+
+ *sigset |= sigmask (signo);
+ return 0;
+}
+
diff --git a/libpthread/sysdeps/generic/sigdelset.c b/libpthread/sysdeps/generic/sigdelset.c
new file mode 100644
index 00000000..5456467f
--- /dev/null
+++ b/libpthread/sysdeps/generic/sigdelset.c
@@ -0,0 +1,35 @@
+/* sigdelset.c - Generic sigdelset implementation.
+ Copyright (C) 2008 Free Software Foundation, Inc.
+ Written by Neal H. Walfield <neal@gnu.org>.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public License
+ as published by the Free Software Foundation; either version 3 of
+ the License, or (at your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this program. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include "sig-internal.h"
+
+int
+sigdelset (sigset_t *sigset, int signo)
+{
+ if (signo <= 0 || signo >= NSIG)
+ {
+ errno = EINVAL;
+ return -1;
+ }
+
+ *sigset &= ~sigmask (signo);
+ return 0;
+}
+
diff --git a/libpthread/sysdeps/generic/sigemptyset.c b/libpthread/sysdeps/generic/sigemptyset.c
new file mode 100644
index 00000000..690c15b6
--- /dev/null
+++ b/libpthread/sysdeps/generic/sigemptyset.c
@@ -0,0 +1,29 @@
+/* sigemptyset.c - Generic sigemptyset implementation.
+ Copyright (C) 2008 Free Software Foundation, Inc.
+ Written by Neal H. Walfield <neal@gnu.org>.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public License
+ as published by the Free Software Foundation; either version 3 of
+ the License, or (at your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this program. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <signal.h>
+
+int
+sigemptyset (sigset_t *sigset)
+{
+ *sigset = 0;
+ return 0;
+}
+
diff --git a/libpthread/sysdeps/generic/sigfillset.c b/libpthread/sysdeps/generic/sigfillset.c
new file mode 100644
index 00000000..f0ac0781
--- /dev/null
+++ b/libpthread/sysdeps/generic/sigfillset.c
@@ -0,0 +1,29 @@
+/* sigfillset.c - Generic sigfillset implementation.
+ Copyright (C) 2008 Free Software Foundation, Inc.
+ Written by Neal H. Walfield <neal@gnu.org>.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public License
+ as published by the Free Software Foundation; either version 3 of
+ the License, or (at your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this program. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <signal.h>
+
+int
+sigfillset (sigset_t *sigset)
+{
+ *sigset = (1ULL << (NSIG - 1)) - 1;
+ return 0;
+}
+
diff --git a/libpthread/sysdeps/generic/siginterrupt.c b/libpthread/sysdeps/generic/siginterrupt.c
new file mode 100644
index 00000000..0899efbb
--- /dev/null
+++ b/libpthread/sysdeps/generic/siginterrupt.c
@@ -0,0 +1,36 @@
+/* siginterrupt.c - Generic siginterrupt implementation.
+ Copyright (C) 2008 Free Software Foundation, Inc.
+ Written by Neal H. Walfield <neal@gnu.org>.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public License
+ as published by the Free Software Foundation; either version 3 of
+ the License, or (at your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this program. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include "sig-internal.h"
+
+int
+siginterrupt (int sig, int flag)
+{
+ int ret;
+ struct sigaction act;
+
+ sigaction (sig, NULL, &act);
+ if (flag)
+ act.sa_flags &= ~SA_RESTART;
+ else
+ act.sa_flags |= SA_RESTART;
+ ret = sigaction(sig, &act, NULL);
+ return ret;
+}
diff --git a/libpthread/sysdeps/generic/sigismember.c b/libpthread/sysdeps/generic/sigismember.c
new file mode 100644
index 00000000..b3d65c97
--- /dev/null
+++ b/libpthread/sysdeps/generic/sigismember.c
@@ -0,0 +1,36 @@
+/* sigismember.c - Generic sigismember implementation.
+ Copyright (C) 2008 Free Software Foundation, Inc.
+ Written by Neal H. Walfield <neal@gnu.org>.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public License
+ as published by the Free Software Foundation; either version 3 of
+ the License, or (at your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this program. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include "sig-internal.h"
+
+int
+sigismember (const sigset_t *sigset, int signo)
+{
+ if (signo <= 0 || signo >= NSIG)
+ {
+ errno = EINVAL;
+ return -1;
+ }
+
+ if (*sigset & sigmask (signo))
+ return 1;
+ else
+ return 0;
+}
diff --git a/libpthread/sysdeps/generic/signal.c b/libpthread/sysdeps/generic/signal.c
new file mode 100644
index 00000000..7555d0a1
--- /dev/null
+++ b/libpthread/sysdeps/generic/signal.c
@@ -0,0 +1,44 @@
+/* signal.c - Generic signal implementation.
+ Copyright (C) 2008 Free Software Foundation, Inc.
+ Written by Neal H. Walfield <neal@gnu.org>.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public License
+ as published by the Free Software Foundation; either version 3 of
+ the License, or (at your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this program. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include "sig-internal.h"
+
+void (*signal (int sig, void (*handler)(int)))(int)
+{
+ struct sigaction sa;
+
+ sa.sa_handler = handler;
+ sa.sa_flags = SA_RESTART;
+
+ if (sigemptyset (&sa.sa_mask) < 0
+ || sigaddset (&sa.sa_mask, sig) < 0)
+ return SIG_ERR;
+
+ struct sigaction osa;
+ if (sigaction (sig, &sa, &osa) < 0)
+ return SIG_ERR;
+
+ return osa.sa_handler;
+}
+
+void (*bsd_signal (int sig, void (*func)(int)))(int)
+{
+ return signal (sig, func);
+}
diff --git a/libpthread/sysdeps/generic/sigwait.c b/libpthread/sysdeps/generic/sigwait.c
new file mode 100644
index 00000000..7d10bf8b
--- /dev/null
+++ b/libpthread/sysdeps/generic/sigwait.c
@@ -0,0 +1,34 @@
+/* sigwait.c - Generic sigwait implementation.
+ Copyright (C) 2008 Free Software Foundation, Inc.
+ Written by Neal H. Walfield <neal@gnu.org>.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public License
+ as published by the Free Software Foundation; either version 3 of
+ the License, or (at your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this program. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include "sig-internal.h"
+
+int
+sigwait (const sigset_t *restrict set, int *restrict signo)
+{
+ siginfo_t info;
+
+ if (sigwaitinfo (set, &info) < 0)
+ return -1;
+
+ *signo = info.si_signo;
+ return 0;
+}
+
diff --git a/libpthread/sysdeps/hurd/pt-destroy-specific.c b/libpthread/sysdeps/hurd/pt-destroy-specific.c
new file mode 100644
index 00000000..f7896e5e
--- /dev/null
+++ b/libpthread/sysdeps/hurd/pt-destroy-specific.c
@@ -0,0 +1,79 @@
+/* __pthread_destory_specific. Hurd version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <stdlib.h>
+#include <hurd/ihash.h>
+
+#include <pt-internal.h>
+
+void
+__pthread_destroy_specific (struct __pthread *thread)
+{
+ error_t err;
+ int i;
+ int seen_one;
+
+ /* Check if there is any thread specific data. */
+ if (! thread->thread_specifics)
+ return;
+
+ __pthread_key_lock_ready ();
+
+ /* Iterate and call the destructors on any thread specific data. */
+ for (;;)
+ {
+ seen_one = 0;
+
+ __pthread_mutex_lock (&__pthread_key_lock);
+
+ for (i = 0; i < __pthread_key_count; i ++)
+ {
+ void *value;
+
+ if (__pthread_key_destructors[i] == PTHREAD_KEY_INVALID)
+ continue;
+
+ value = hurd_ihash_find (thread->thread_specifics, i);
+ if (value)
+ {
+ err = hurd_ihash_remove (thread->thread_specifics, i);
+ assert (err == 1);
+
+ if (__pthread_key_destructors[i])
+ {
+ seen_one = 1;
+ __pthread_key_destructors[i] (value);
+ }
+ }
+ }
+
+ __pthread_mutex_unlock (&__pthread_key_lock);
+
+ if (! seen_one)
+ break;
+
+ /* This may take a very long time. Let those blocking on
+ pthread_key_create or pthread_key_delete make progress. */
+ sched_yield ();
+ }
+
+ hurd_ihash_free (thread->thread_specifics);
+ thread->thread_specifics = 0;
+}
diff --git a/libpthread/sysdeps/hurd/pt-getspecific.c b/libpthread/sysdeps/hurd/pt-getspecific.c
new file mode 100644
index 00000000..71ec63c6
--- /dev/null
+++ b/libpthread/sysdeps/hurd/pt-getspecific.c
@@ -0,0 +1,39 @@
+/* pthread_getspecific. Hurd version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <hurd/ihash.h>
+
+#include <pt-internal.h>
+
+void *
+pthread_getspecific (pthread_key_t key)
+{
+ struct __pthread *self;
+
+ if (key < 0 || key >= __pthread_key_count
+ || __pthread_key_destructors[key] == PTHREAD_KEY_INVALID)
+ return NULL;
+
+ self = _pthread_self ();
+ if (! self->thread_specifics)
+ return 0;
+
+ return hurd_ihash_find (self->thread_specifics, key);
+}
diff --git a/libpthread/sysdeps/hurd/pt-init-specific.c b/libpthread/sysdeps/hurd/pt-init-specific.c
new file mode 100644
index 00000000..c1bacbcb
--- /dev/null
+++ b/libpthread/sysdeps/hurd/pt-init-specific.c
@@ -0,0 +1,30 @@
+/* __pthread_init_specific. Hurd version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <stdlib.h>
+
+#include <pt-internal.h>
+
+error_t
+__pthread_init_specific (struct __pthread *thread)
+{
+ thread->thread_specifics = 0;
+ return 0;
+}
diff --git a/libpthread/sysdeps/hurd/pt-key-create.c b/libpthread/sysdeps/hurd/pt-key-create.c
new file mode 100644
index 00000000..b3e01412
--- /dev/null
+++ b/libpthread/sysdeps/hurd/pt-key-create.c
@@ -0,0 +1,109 @@
+/* pthread_key_create. Hurd version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <stdlib.h>
+#include <assert.h>
+
+#include <pt-internal.h>
+
+pthread_mutex_t __pthread_key_lock;
+
+void (**__pthread_key_destructors) (void *arg);
+int __pthread_key_size;
+int __pthread_key_count;
+int __pthread_key_invalid_count;
+
+int
+pthread_key_create (pthread_key_t *key, void (*destructor) (void *))
+{
+ /* Where to look for the next key slot. */
+ static int index;
+
+ __pthread_key_lock_ready ();
+
+ __pthread_mutex_lock (&__pthread_key_lock);
+
+ do_search:
+ /* Use the search hint and try to find a free slot. */
+ for (; index < __pthread_key_count
+ && __pthread_key_destructors[index] != PTHREAD_KEY_INVALID;
+ index ++)
+ ;
+
+ /* See if we actually found a free element. */
+ if (index < __pthread_key_count)
+ {
+ assert (__pthread_key_destructors[index] == PTHREAD_KEY_INVALID);
+ assert (__pthread_key_invalid_count > 0);
+
+ __pthread_key_invalid_count --;
+ __pthread_key_destructors[index] = destructor;
+ *key = index ++;
+
+ __pthread_mutex_unlock (&__pthread_key_lock);
+ return 0;
+ }
+
+ assert (index == __pthread_key_count);
+
+ /* No space at the end. */
+ if (__pthread_key_size == __pthread_key_count)
+ {
+ /* See if it is worth looking for a free element. */
+ if (__pthread_key_invalid_count > 4
+ && __pthread_key_invalid_count > __pthread_key_size / 8)
+ {
+ index = 0;
+ goto do_search;
+ }
+
+
+ /* Resize the array. */
+ {
+ void *t;
+ int newsize;
+
+ if (__pthread_key_size == 0)
+ newsize = 8;
+ else
+ newsize = __pthread_key_size * 2;
+
+ t = realloc (__pthread_key_destructors,
+ newsize * sizeof (*__pthread_key_destructors));
+ if (! t)
+ {
+ __pthread_mutex_unlock (&__pthread_key_lock);
+ return ENOMEM;
+ }
+
+ __pthread_key_size = newsize;
+ __pthread_key_destructors = t;
+ }
+ }
+
+ __pthread_key_destructors[index] = destructor;
+ *key = index;
+
+ index ++;
+ __pthread_key_count ++;
+
+ __pthread_mutex_unlock (&__pthread_key_lock);
+ return 0;
+}
diff --git a/libpthread/sysdeps/hurd/pt-key-delete.c b/libpthread/sysdeps/hurd/pt-key-delete.c
new file mode 100644
index 00000000..9d88647e
--- /dev/null
+++ b/libpthread/sysdeps/hurd/pt-key-delete.c
@@ -0,0 +1,64 @@
+/* pthread_key_delete. Hurd version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+
+#include <pt-internal.h>
+
+int
+pthread_key_delete (pthread_key_t key)
+{
+ error_t err = 0;
+
+ __pthread_key_lock_ready ();
+
+ __pthread_mutex_lock (&__pthread_key_lock);
+
+ if (key < 0 || key >= __pthread_key_count
+ || __pthread_key_destructors[key] == PTHREAD_KEY_INVALID)
+ err = EINVAL;
+ else
+ {
+ int i;
+
+ __pthread_key_destructors[key] = PTHREAD_KEY_INVALID;
+ __pthread_key_invalid_count ++;
+
+ pthread_rwlock_rdlock (&__pthread_threads_lock);
+ for (i = 0; i < __pthread_num_threads; ++i)
+ {
+ struct __pthread *t;
+
+ t = __pthread_threads[i];
+
+ if (t == NULL)
+ continue;
+
+ /* Just remove the key, no need to care whether it was
+ already there. */
+ if (t->thread_specifics)
+ hurd_ihash_remove (t->thread_specifics, key);
+ }
+ pthread_rwlock_unlock (&__pthread_threads_lock);
+ }
+
+ __pthread_mutex_unlock (&__pthread_key_lock);
+
+ return err;
+}
diff --git a/libpthread/sysdeps/hurd/pt-key.h b/libpthread/sysdeps/hurd/pt-key.h
new file mode 100644
index 00000000..494e01d7
--- /dev/null
+++ b/libpthread/sysdeps/hurd/pt-key.h
@@ -0,0 +1,76 @@
+/* pthread_key internal declatations for the Hurd version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <hurd/ihash.h>
+
+#define PTHREAD_KEY_MEMBERS \
+ hurd_ihash_t thread_specifics;
+
+#define PTHREAD_KEY_INVALID (void *) (-1)
+
+
+/* __PTHREAD_KEY_DESTRUCTORS is an array of destructors with
+ __PTHREAD_KEY_SIZE elements. If an element with index less than
+ __PTHREAD_KEY_COUNT is invalid, it shall contain the value
+ PTHREAD_KEY_INVALID which shall be distinct from NULL.
+
+ Normally, we just add new keys to the end of the array and realloc
+ it as necessary. The pthread_key_create routine may decide to
+ rescan the array if __PTHREAD_KEY_FREE is large. */
+extern void (**__pthread_key_destructors) (void *arg);
+extern int __pthread_key_size;
+extern int __pthread_key_count;
+/* Number of invalid elements in the array. Does not include elements
+ for which memory has been allocated but which have not yet been
+ used (i.e. those elements with indexes greater than
+ __PTHREAD_KEY_COUNT). */
+extern int __pthread_key_invalid_count;
+
+/* Protects the above variables. This must be a recursive lock: the
+ destructors may call pthread_key_delete. */
+extern pthread_mutex_t __pthread_key_lock;
+
+#include <assert.h>
+
+static inline void
+__pthread_key_lock_ready (void)
+{
+ static pthread_once_t o = PTHREAD_ONCE_INIT;
+
+ void do_init (void)
+ {
+ int err;
+ pthread_mutexattr_t attr;
+
+ err = pthread_mutexattr_init (&attr);
+ assert_perror (err);
+
+ err = pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE);
+ assert_perror (err);
+
+ err = pthread_mutex_init (&__pthread_key_lock, &attr);
+ assert_perror (err);
+
+ err = pthread_mutexattr_destroy (&attr);
+ assert_perror (err);
+ }
+
+ pthread_once (&o, do_init);
+}
diff --git a/libpthread/sysdeps/hurd/pt-kill.c b/libpthread/sysdeps/hurd/pt-kill.c
new file mode 100644
index 00000000..d204e3f6
--- /dev/null
+++ b/libpthread/sysdeps/hurd/pt-kill.c
@@ -0,0 +1,52 @@
+/* pthread_kill. Hurd version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <assert.h>
+#include <signal.h>
+#include <hurd/signal.h>
+
+#include <pt-internal.h>
+
+int
+pthread_kill (pthread_t thread, int sig)
+{
+ struct __pthread *pthread;
+ struct hurd_signal_detail detail;
+ struct hurd_sigstate *ss;
+
+ /* Lookup the thread structure for THREAD. */
+ pthread = __pthread_getid (thread);
+ if (pthread == NULL)
+ return ESRCH;
+
+ ss = _hurd_thread_sigstate (pthread->kernel_thread);
+ assert (ss);
+
+ if (!sig)
+ return 0;
+
+ detail.exc = 0;
+ detail.code = sig;
+ detail.error = 0;
+
+ _hurd_raise_signal (ss, sig, &detail);
+
+ return 0;
+}
diff --git a/libpthread/sysdeps/hurd/pt-setspecific.c b/libpthread/sysdeps/hurd/pt-setspecific.c
new file mode 100644
index 00000000..d0b7302f
--- /dev/null
+++ b/libpthread/sysdeps/hurd/pt-setspecific.c
@@ -0,0 +1,47 @@
+/* pthread_setspecific. Generic version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <hurd/ihash.h>
+
+#include <pt-internal.h>
+
+int
+pthread_setspecific (pthread_key_t key, const void *value)
+{
+ error_t err;
+ struct __pthread *self = _pthread_self ();
+
+ if (key < 0 || key >= __pthread_key_count
+ || __pthread_key_destructors[key] == PTHREAD_KEY_INVALID)
+ return EINVAL;
+
+ if (! self->thread_specifics)
+ {
+ err = hurd_ihash_create (&self->thread_specifics, HURD_IHASH_NO_LOCP);
+ if (err)
+ return ENOMEM;
+ }
+
+ err = hurd_ihash_add (self->thread_specifics, key, (void *) value);
+ if (err)
+ return ENOMEM;
+
+ return 0;
+}
diff --git a/libpthread/sysdeps/ia32/bits/atomic.h b/libpthread/sysdeps/ia32/bits/atomic.h
new file mode 100644
index 00000000..0dfc1f60
--- /dev/null
+++ b/libpthread/sysdeps/ia32/bits/atomic.h
@@ -0,0 +1,66 @@
+/* Atomic operations. i386 version.
+ Copyright (C) 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#ifndef _BITS_ATOMIC_H
+#define _BITS_ATOMIC_H 1
+
+typedef __volatile int __atomic_t;
+
+static inline void
+__atomic_inc (__atomic_t *__var)
+{
+ __asm__ __volatile ("lock; incl %0" : "=m" (*__var) : "m" (*__var));
+}
+
+static inline void
+__atomic_dec (__atomic_t *__var)
+{
+ __asm__ __volatile ("lock; decl %0" : "=m" (*__var) : "m" (*__var));
+}
+
+static inline int
+__atomic_dec_and_test (__atomic_t *__var)
+{
+ unsigned char __ret;
+
+ __asm__ __volatile ("lock; decl %0; sete %1"
+ : "=m" (*__var), "=qm" (__ret) : "m" (*__var));
+ return __ret != 0;
+}
+
+/* We assume that an __atomicptr_t is only used for pointers to
+ word-aligned objects, and use the lowest bit for a simple lock. */
+typedef __volatile int * __atomicptr_t;
+
+/* Actually we don't implement that yet, and assume that we run on
+ something that has the i486 instruction set. */
+static inline int
+__atomicptr_compare_and_swap (__atomicptr_t *__ptr, void *__oldval,
+ void * __newval)
+{
+ char __ret;
+ int __dummy;
+
+ __asm__ __volatile ("lock; cmpxchgl %3, %1; sete %0"
+ : "=q" (__ret), "=m" (*__ptr), "=a" (__dummy)
+ : "r" (__newval), "m" (*__ptr), "a" (__oldval));
+ return __ret;
+}
+
+#endif
diff --git a/libpthread/sysdeps/ia32/bits/memory.h b/libpthread/sysdeps/ia32/bits/memory.h
new file mode 100644
index 00000000..932c4086
--- /dev/null
+++ b/libpthread/sysdeps/ia32/bits/memory.h
@@ -0,0 +1,40 @@
+/* Memory barrier operations. i386 version.
+ Copyright (C) 2002, 2008 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#ifndef _BITS_MEMORY_H
+#define _BITS_MEMORY_H 1
+
+/* Prevent read and write reordering across this function. */
+static inline void
+__memory_barrier (void)
+{
+ int i;
+
+ /* Any lock'ed instruction will do. We just do a simple
+ increment. */
+ __asm__ __volatile ("lock; incl %0" : "=m" (i) : "m" (i) : "memory");
+}
+
+/* Prevent read reordering across this function. */
+#define __memory_read_barrier __memory_barrier
+
+/* Prevent write reordering across this function. */
+#define __memory_write_barrier __memory_barrier
+
+#endif
diff --git a/libpthread/sysdeps/ia32/bits/spin-lock-inline.h b/libpthread/sysdeps/ia32/bits/spin-lock-inline.h
new file mode 100644
index 00000000..e5ed3def
--- /dev/null
+++ b/libpthread/sysdeps/ia32/bits/spin-lock-inline.h
@@ -0,0 +1,98 @@
+/* Machine-specific definitions for spin locks. i386 version.
+ Copyright (C) 2000, 2005, 2008, 2009 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+/*
+ * Never include this file directly; use <pthread.h> or <cthreads.h> instead.
+ */
+
+#ifndef _BITS_SPIN_LOCK_INLINE_H
+#define _BITS_SPIN_LOCK_INLINE_H 1
+
+#include <features.h>
+#include <bits/spin-lock.h>
+
+__BEGIN_DECLS
+
+#if defined __USE_EXTERN_INLINES || defined _FORCE_INLINES
+
+# ifndef __EBUSY
+# include <errno.h>
+# define __EBUSY EBUSY
+# endif
+
+# ifndef __PT_SPIN_INLINE
+# define __PT_SPIN_INLINE __extern_inline
+# endif
+
+__PT_SPIN_INLINE int __pthread_spin_destroy (__pthread_spinlock_t *__lock);
+
+__PT_SPIN_INLINE int
+__pthread_spin_destroy (__pthread_spinlock_t *__lock)
+{
+ return 0;
+}
+
+__PT_SPIN_INLINE int __pthread_spin_init (__pthread_spinlock_t *__lock,
+ int __pshared);
+
+__PT_SPIN_INLINE int
+__pthread_spin_init (__pthread_spinlock_t *__lock, int __pshared)
+{
+ *__lock = __PTHREAD_SPIN_LOCK_INITIALIZER;
+ return 0;
+}
+
+__PT_SPIN_INLINE int __pthread_spin_trylock (__pthread_spinlock_t *__lock);
+
+__PT_SPIN_INLINE int
+__pthread_spin_trylock (__pthread_spinlock_t *__lock)
+{
+ int __locked;
+ __asm__ __volatile ("xchgl %0, %1"
+ : "=&r" (__locked), "=m" (*__lock) : "0" (1) : "memory");
+ return __locked ? __EBUSY : 0;
+}
+
+__extern_inline int __pthread_spin_lock (__pthread_spinlock_t *__lock);
+extern int _pthread_spin_lock (__pthread_spinlock_t *__lock);
+
+__extern_inline int
+__pthread_spin_lock (__pthread_spinlock_t *__lock)
+{
+ if (__pthread_spin_trylock (__lock))
+ return _pthread_spin_lock (__lock);
+ return 0;
+}
+
+__PT_SPIN_INLINE int __pthread_spin_unlock (__pthread_spinlock_t *__lock);
+
+__PT_SPIN_INLINE int
+__pthread_spin_unlock (__pthread_spinlock_t *__lock)
+{
+ int __unlocked;
+ __asm__ __volatile ("xchgl %0, %1"
+ : "=&r" (__unlocked), "=m" (*__lock) : "0" (0) : "memory");
+ return 0;
+}
+
+#endif /* Use extern inlines or force inlines. */
+
+__END_DECLS
+
+#endif /* bits/spin-lock.h */
diff --git a/libpthread/sysdeps/ia32/bits/spin-lock.h b/libpthread/sysdeps/ia32/bits/spin-lock.h
new file mode 100644
index 00000000..5ae81e18
--- /dev/null
+++ b/libpthread/sysdeps/ia32/bits/spin-lock.h
@@ -0,0 +1,39 @@
+/* Machine-specific definitions for spin locks. i386 version.
+ Copyright (C) 2000, 2005, 2008, 2009 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+/*
+ * Never include this file directly; use <pthread.h> or <cthreads.h> instead.
+ */
+
+#ifndef _BITS_SPIN_LOCK_H
+#define _BITS_SPIN_LOCK_H 1
+
+#include <features.h>
+
+__BEGIN_DECLS
+
+/* The type of a spin lock object. */
+typedef __volatile int __pthread_spinlock_t;
+
+/* Initializer for a spin lock object. */
+# define __PTHREAD_SPIN_LOCK_INITIALIZER ((__pthread_spinlock_t) 0)
+
+__END_DECLS
+
+#endif /* bits/spin-lock.h */
diff --git a/libpthread/sysdeps/ia32/machine-sp.h b/libpthread/sysdeps/ia32/machine-sp.h
new file mode 100644
index 00000000..cef6ab72
--- /dev/null
+++ b/libpthread/sysdeps/ia32/machine-sp.h
@@ -0,0 +1,30 @@
+/* Machine-specific function to return the stack pointer. i386 version.
+ Copyright (C) 1994, 1997, 2001, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _MACHINE_SP_H
+#define _MACHINE_SP_H
+
+/* Return the current stack pointer. */
+
+#define __thread_stack_pointer() ({ \
+ register void *__sp__ asm("esp"); \
+ __sp__; \
+})
+
+#endif /* machine-sp.h */
diff --git a/libpthread/sysdeps/ia32/pt-machdep.h b/libpthread/sysdeps/ia32/pt-machdep.h
new file mode 100644
index 00000000..6d456367
--- /dev/null
+++ b/libpthread/sysdeps/ia32/pt-machdep.h
@@ -0,0 +1,29 @@
+/* Machine dependent pthreads internal defenitions. i386 version.
+ Copyright (C) 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#ifndef _PT_MACHDEP_H
+#define _PT_MACHDEP_H 1
+
+struct pthread_mcontext
+{
+ void *pc;
+ void *sp;
+};
+
+#endif /* pt-machdep.h */
diff --git a/libpthread/sysdeps/l4/bits/pthread-np.h b/libpthread/sysdeps/l4/bits/pthread-np.h
new file mode 100644
index 00000000..6a02bdc0
--- /dev/null
+++ b/libpthread/sysdeps/l4/bits/pthread-np.h
@@ -0,0 +1,35 @@
+/* Non-portable functions. L4 version.
+ Copyright (C) 2003, 2007 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+/*
+ * Never include this file directly; use <pthread.h> or <cthreads.h> instead.
+ */
+
+#ifndef _BITS_PTHREAD_NP_H
+#define _BITS_PTHREAD_NP_H 1
+
+#include <l4.h>
+
+/* Add the thread TID to the internal kernel thread pool. */
+extern int pthread_pool_add_np (l4_thread_id_t tid);
+
+/* Get the first thread from the pool. */
+extern l4_thread_id_t pthread_pool_get_np (void);
+
+#endif /* bits/pthread-np.h */
diff --git a/libpthread/sysdeps/l4/hurd/bits/pthread-np.h b/libpthread/sysdeps/l4/hurd/bits/pthread-np.h
new file mode 100644
index 00000000..a90793df
--- /dev/null
+++ b/libpthread/sysdeps/l4/hurd/bits/pthread-np.h
@@ -0,0 +1,31 @@
+/* Non-portable functions. Viengoos version.
+ Copyright (C) 2008 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+/*
+ * Never include this file directly; use <pthread.h> or <cthreads.h> instead.
+ */
+
+#ifndef _BITS_PTHREAD_NP_H
+#define _BITS_PTHREAD_NP_H 1
+
+#include <hurd/addr.h>
+
+int pthread_setactivity_np (addr_t activity);
+
+#endif /* bits/pthread-np.h */
diff --git a/libpthread/sysdeps/l4/hurd/ia32/pt-machdep.c b/libpthread/sysdeps/l4/hurd/ia32/pt-machdep.c
new file mode 100644
index 00000000..dbf5cd7e
--- /dev/null
+++ b/libpthread/sysdeps/l4/hurd/ia32/pt-machdep.c
@@ -0,0 +1,20 @@
+/* Machine dependent pthreads code. Hurd/i386 version.
+ Copyright (C) 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+/* Nothing to do. */
diff --git a/libpthread/sysdeps/l4/hurd/ia32/pt-setup.c b/libpthread/sysdeps/l4/hurd/ia32/pt-setup.c
new file mode 100644
index 00000000..579905c9
--- /dev/null
+++ b/libpthread/sysdeps/l4/hurd/ia32/pt-setup.c
@@ -0,0 +1,117 @@
+/* Setup thread stack. Viengoos/i386 version.
+ Copyright (C) 2000, 2002, 2008 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <l4.h>
+
+#include <pt-internal.h>
+#include <hurd/thread.h>
+#include <hurd/exceptions.h>
+
+/* The stack layout used on the i386 is:
+
+ -----------------
+ | ARG |
+ -----------------
+ | START_ROUTINE |
+ -----------------
+ | Return address |
+ ----------------- <- %ebp
+ | Frame pointer |
+ -----------------
+
+ We do the following: setup the stack to return to the entry routine.
+
+
+*/
+
+/* The stack contains:
+
+ arg
+ start_routine
+ 0 <- fake return address
+ C entry_point
+*/
+extern uintptr_t _pthread_entry_point;
+__asm__ ("\n\
+ .globl _pthread_entry_point, __pthread_entry_point\n\
+_pthread_entry_point:\n\
+__pthread_entry_point:\n\
+ pushl $0\n\
+ popf\n\
+\n\
+ xor %ebp, %ebp\n\
+ ret\n");
+
+/* Set up the stack for THREAD, such that it appears as if
+ START_ROUTINE and ARG were passed to the new thread's entry-point.
+ Return the stack pointer for the new thread. We also take the
+ opportunity to install THREAD in our utcb. */
+static void *
+stack_setup (struct __pthread *thread,
+ void *(*start_routine)(void *), void *arg,
+ void (*entry_point)(void *(*)(void *), void *))
+{
+ uintptr_t *top;
+
+ /* Calculate top of the new stack. */
+ top = (uintptr_t *) ((uintptr_t) thread->stackaddr + thread->stacksize);
+
+ /* Align on 0x10 for MMX operations. */
+ top = (uintptr_t) top & ~0xf;
+
+ if (start_routine)
+ {
+ /* Set up call frame. */
+ *--top = (uintptr_t) arg; /* Argument to START_ROUTINE. */
+ *--top = (uintptr_t) start_routine;
+ *--top = 0; /* Fake return address. */
+ *--top = (uintptr_t) entry_point;
+ }
+
+ return top;
+}
+
+int
+__pthread_setup (struct __pthread *thread,
+ void (*entry_point)(void *(*)(void *), void *),
+ void *(*start_routine)(void *), void *arg)
+{
+ thread->mcontext.pc = (void *) &_pthread_entry_point;
+ thread->mcontext.sp = (void *) stack_setup (thread, start_routine, arg,
+ entry_point);
+
+ if (__pthread_num_threads == 1)
+ return 0;
+
+ assert (! ADDR_IS_VOID (thread->exception_area[0]));
+
+ struct exception_page *exception_page = thread->exception_area_va;
+
+ /* SP is set to the end of the exception area minus one word, which
+ is the location of the exception page. */
+ exception_page->exception_handler_sp
+ = (uintptr_t) thread->exception_area_va + EXCEPTION_AREA_SIZE;
+ exception_page->exception_handler_sp -= sizeof (void *);
+ * (void **) exception_page->exception_handler_sp = thread->exception_area_va;
+
+ exception_page->exception_handler_ip = (uintptr_t) &exception_handler_entry;
+ exception_page->exception_handler_end = (uintptr_t) &exception_handler_end;
+
+ return 0;
+}
diff --git a/libpthread/sysdeps/l4/hurd/ia32/signal-dispatch-lowlevel.c b/libpthread/sysdeps/l4/hurd/ia32/signal-dispatch-lowlevel.c
new file mode 100644
index 00000000..37ef8215
--- /dev/null
+++ b/libpthread/sysdeps/l4/hurd/ia32/signal-dispatch-lowlevel.c
@@ -0,0 +1,213 @@
+/* signal-dispatch-lowlevel.c - ia32 specific signal handling functions.
+ Copyright (C) 2008 Free Software Foundation, Inc.
+ Written by Neal H. Walfield <neal@gnu.org>.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public License
+ as published by the Free Software Foundation; either version 3 of
+ the License, or (at your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this program. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <pt-internal.h>
+#include <sig-internal.h>
+
+#include <hurd/thread.h>
+#include <pthread.h>
+#include <stdint.h>
+#include <atomic.h>
+
+extern char _signal_dispatch_entry;
+/* - 0(%esp) a pointer to the thread's struct signal_state.
+ - 4(%esp) a pointer to a siginfo_t.
+ - 8(%esp) is a pointer to the ss_flags field (or NULL).
+ - 12(%esp)+4 is the value of the sp when the thread was interrupted (intr_sp)
+ - 0(intr_sp) is the value of the ip when the thread was interrupted.
+ - 16(%esp) - 16 byte register save area
+*/
+__asm__ ("\n\
+ .globl _signal_dispatch_entry\n\
+_signal_dispatch_entry:\n\
+ /* Save caller saved registers (16 bytes). */\n\
+ mov %eax, 16(%esp)\n\
+ mov %ecx, 16+4(%esp)\n\
+ mov %edx, 16+8(%esp)\n\
+ pushf\n\
+ popl %eax\n\
+ mov %eax, 16+12(%esp)\n\
+\n\
+ /* Reset EFLAGS. */\n\
+ cld\n\
+ call signal_dispatch\n\
+\n\
+ /* Get the original stack and begin restoration. */\n\
+ mov 12(%esp), %edx\n\
+\n\
+ /* Move the saved registers to the user stack. */\n\
+ sub $16, %edx\n\
+ /* eax. */\n\
+ mov 16+0(%esp), %ecx\n\
+ mov %ecx, 0(%edx)\n\
+ /* ecx. */\n\
+ mov 16+4(%esp), %ecx\n\
+ mov %ecx, 4(%edx)\n\
+ /* edx. */\n\
+ mov 16+8(%esp), %ecx\n\
+ mov %ecx, 8(%edx)\n\
+ /* eflags. */\n\
+ mov 16+12(%esp), %ecx\n\
+ mov %ecx, 12(%edx)\n\
+\n\
+ /* Get the pointer to the sigaltstack flags. */\n\
+ mov 8(%esp), %ecx\n\
+\n\
+ /* Restore the user stack. */\n\
+ mov %edx, %esp\n\
+\n\
+ /* Clear the SA_ONSTACK flag. */\n\
+ and %ecx, %ecx\n\
+ jz after_clear\n\
+ lock; and $~1, 0(%ecx)\n\
+after_clear:\n\
+\n\
+ /* Restore eflags, the scratch regs and the original sp and ip. */\n\
+ popl %eax\n\
+ popl %ecx\n\
+ popl %edx\n\
+ popf\n\
+ ret\n");
+
+extern char _signal_dispatch_entry_self;
+/* - 0(%esp) is the return address (we ignore it)
+ - 4(%esp) is the sp to load
+
+ Since we are returning to signal_dispatch_lowlevel's caller, we
+ also need to restore its frame pointer. */
+__asm__ ("\n\
+ .globl _signal_dispatch_entry_self\n\
+_signal_dispatch_entry_self:\n\
+ mov 0(%ebp), %ebp\n\
+ mov 4(%esp), %esp\n\
+ jmp _signal_dispatch_entry\n");
+
+void
+signal_dispatch_lowlevel (struct signal_state *ss, pthread_t tid,
+ siginfo_t si)
+{
+ assert (pthread_mutex_trylock (&ss->lock) == EBUSY);
+
+ struct __pthread *thread = __pthread_getid (tid);
+
+ bool self = tid == pthread_self ();
+
+ uintptr_t intr_sp;
+
+ if (self)
+ {
+ /* The return address is just before the first argument. */
+ intr_sp = (uintptr_t) &ss - 4;
+ assert (* (void **) intr_sp == __builtin_return_address (0));
+ }
+ else
+ {
+ struct hurd_thread_exregs_in in;
+ memset (&in, 0, sizeof (in));
+ struct hurd_thread_exregs_out out;
+
+ error_t err;
+ err = rm_thread_exregs (ADDR_VOID, thread->object,
+ HURD_EXREGS_STOP | HURD_EXREGS_ABORT_IPC
+ | HURD_EXREGS_GET_REGS,
+ in, &out);
+ if (err)
+ panic ("Failed to modify thread " ADDR_FMT,
+ ADDR_PRINTF (thread->object));
+
+ intr_sp = out.sp;
+
+ /* Push the ip on the user stack. */
+ intr_sp -= 4;
+ * (uintptr_t *) intr_sp = out.ip;
+ }
+
+ bool altstack = false;
+ uintptr_t sp;
+ if (! (ss->actions[si.si_signo - 1].sa_flags & SA_ONSTACK)
+ || (ss->stack.ss_flags & SS_DISABLE)
+ || (ss->stack.ss_flags & SS_ONSTACK))
+ {
+ assert (! self);
+ sp = intr_sp;
+ }
+ else
+ {
+ /* The stack grows down. */
+ sp = (uintptr_t) ss->stack.ss_sp + ss->stack.ss_size;
+
+ /* We know intimately that SS_ONSTACK is the least significant
+ bit. */
+ assert (SS_ONSTACK == 1);
+ atomic_bit_set (&ss->stack.ss_flags, 0);
+
+ altstack = true;
+ }
+
+ /* Set up the call frame for a call to signal_dispatch_entry. */
+
+ /* Allocate a siginfo structure on the stack. */
+ sp = sp - sizeof (siginfo_t);
+ siginfo_t *sip = (void *) sp;
+ /* Copy the user supplied values. */
+ *sip = si;
+
+ /* Add space for the 4 caller saved registers. */
+ sp -= 4 * sizeof (uintptr_t);
+
+ /* Save the interrupted sp. */
+ sp -= 4;
+ * (uintptr_t *) sp = intr_sp;
+
+ /* Address of the ss_flags. */
+ sp -= 4;
+ if (altstack)
+ * (uintptr_t *) sp = (uintptr_t) &ss->stack.ss_flags;
+ else
+ * (uintptr_t *) sp = 0;
+
+ /* Push the parameters to signal_dispatch. */
+
+ /* signal info structure. */
+ sp -= 4;
+ * (uintptr_t *) sp = (uintptr_t) sip;
+
+ /* The ss. */
+ sp -= 4;
+ * (uintptr_t *) sp = (uintptr_t) ss;
+
+ pthread_mutex_transfer_np (&ss->lock, tid);
+
+ if (self)
+ ((void (*) (uintptr_t)) &_signal_dispatch_entry_self) ((uintptr_t) sp);
+ else
+ {
+ struct hurd_thread_exregs_in in;
+ struct hurd_thread_exregs_out out;
+
+ in.sp = sp;
+ in.ip = (uintptr_t) &_signal_dispatch_entry;
+
+ rm_thread_exregs (ADDR_VOID, thread->object,
+ HURD_EXREGS_SET_SP_IP
+ | HURD_EXREGS_START | HURD_EXREGS_ABORT_IPC,
+ in, &out);
+ }
+}
diff --git a/libpthread/sysdeps/l4/hurd/powerpc/pt-machdep.c b/libpthread/sysdeps/l4/hurd/powerpc/pt-machdep.c
new file mode 100644
index 00000000..754d203e
--- /dev/null
+++ b/libpthread/sysdeps/l4/hurd/powerpc/pt-machdep.c
@@ -0,0 +1,20 @@
+/* Machine dependent pthreads code. Hurd/PowerPC version.
+ Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+/* Nothing to do. */
diff --git a/libpthread/sysdeps/l4/hurd/powerpc/pt-setup.c b/libpthread/sysdeps/l4/hurd/powerpc/pt-setup.c
new file mode 100644
index 00000000..d3cf4ec3
--- /dev/null
+++ b/libpthread/sysdeps/l4/hurd/powerpc/pt-setup.c
@@ -0,0 +1,93 @@
+/* Setup thread stack. Hurd/PowerPC version.
+ Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <l4.h>
+
+#include <pt-internal.h>
+
+/* Arguments is passed in registers on the PowerPC. But the
+ exchange registers syscall only allows us to set the PC and the
+ stack pointer so we put the entry point and start function on
+ the stack. */
+struct start_info
+{
+ void (*entry_point) (void *(*)(void *), void *);
+ void *(*start_routine) (void *);
+ void *arg;
+};
+
+void first_entry_1 (void);
+
+/* Stage 1 entry function. The start_info structure is inlined on the
+ stack. Put values into registers and call entry function. */
+asm (" ;\
+first_entry_1: ;\
+ lwz 0, 0(1) ;\
+ lwz 3, 4(1) ;\
+ lwz 4, 8(1) ;\
+ mtctr 0 ;\
+ bctrl ;\
+");
+
+/* Set up the stack for THREAD, such that it appears as if
+ START_ROUTINE and ARG were passed to the new thread's entry-point.
+ Return the stack pointer for the new thread. We also take the
+ opportunity to install THREAD in our utcb. */
+static void *
+stack_setup (struct __pthread *thread,
+ void (*entry_point)(void *(*)(void *), void *),
+ void *(*start_routine)(void *), void *arg)
+{
+ l4_word_t *top;
+
+ /* Calculate top of the new stack. */
+ top = (l4_word_t *) ((l4_word_t) thread->stackaddr + thread->stacksize);
+
+ /* Initial stack frame. */
+ top[-4] = 0;
+ top = top - 4;
+
+ if (start_routine)
+ {
+ struct start_info *info = ((struct start_info *) top) - 1;
+
+ info->entry_point = entry_point;
+ info->start_routine = start_routine;
+ info->arg = arg;
+ return (void *) info;
+ }
+ return top;
+}
+
+int
+__pthread_setup (struct __pthread *thread,
+ void (*entry_point)(void *(*)(void *), void *),
+ void *(*start_routine)(void *), void *arg)
+{
+ thread->mcontext.pc = first_entry_1;
+ thread->mcontext.sp = stack_setup (thread, entry_point,
+ start_routine, arg);
+
+ if (l4_same_threads (thread->threadid, l4_myself ()))
+ l4_set_user_defined_handle ((l4_word_t) thread);
+ else
+ l4_set_user_defined_handle_of (thread->threadid,
+ (l4_word_t) thread);
+ return 0;
+}
diff --git a/libpthread/sysdeps/l4/hurd/pt-block.c b/libpthread/sysdeps/l4/hurd/pt-block.c
new file mode 100644
index 00000000..2315b1c4
--- /dev/null
+++ b/libpthread/sysdeps/l4/hurd/pt-block.c
@@ -0,0 +1,30 @@
+/* Block a thread. Viengoos version.
+ Copyright (C) 2008 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pt-internal.h>
+
+#include <hurd/stddef.h>
+#include <hurd/futex.h>
+
+/* Block THREAD. */
+void
+__pthread_block (struct __pthread *thread)
+{
+ futex_wait (&thread->threadid, thread->threadid);
+}
diff --git a/libpthread/sysdeps/l4/hurd/pt-kill.c b/libpthread/sysdeps/l4/hurd/pt-kill.c
new file mode 100644
index 00000000..c72e82f4
--- /dev/null
+++ b/libpthread/sysdeps/l4/hurd/pt-kill.c
@@ -0,0 +1,3 @@
+/* The generic version is good enough for us, however, the generic
+ Hurd on Mach version supplies a specialized version */
+#include "../generic/pt-kill.c"
diff --git a/libpthread/sysdeps/l4/hurd/pt-setactivity-np.c b/libpthread/sysdeps/l4/hurd/pt-setactivity-np.c
new file mode 100644
index 00000000..f2f07233
--- /dev/null
+++ b/libpthread/sysdeps/l4/hurd/pt-setactivity-np.c
@@ -0,0 +1,39 @@
+/* Set a thread's activity activity. Viengoos version.
+ Copyright (C) 2008 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pt-internal.h>
+
+#include <hurd/addr.h>
+#include <hurd/thread.h>
+
+int
+pthread_setactivity_np (addr_t activity)
+{
+ struct __pthread *self = _pthread_self ();
+
+ struct hurd_thread_exregs_in in;
+ in.activity = activity;
+
+ struct hurd_thread_exregs_out out;
+ int err = rm_thread_exregs (ADDR_VOID, self->object,
+ HURD_EXREGS_SET_ACTIVITY,
+ in, &out);
+
+ return err;
+}
diff --git a/libpthread/sysdeps/l4/hurd/pt-sigstate-destroy.c b/libpthread/sysdeps/l4/hurd/pt-sigstate-destroy.c
new file mode 100644
index 00000000..997a0369
--- /dev/null
+++ b/libpthread/sysdeps/l4/hurd/pt-sigstate-destroy.c
@@ -0,0 +1,28 @@
+/* Destroy the signal state. Hurd on L4 version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+
+#include <pt-internal.h>
+
+void
+__pthread_sigstate_destroy (struct __pthread *thread)
+{
+ /* Nothing to do. */
+}
diff --git a/libpthread/sysdeps/l4/hurd/pt-sigstate-init.c b/libpthread/sysdeps/l4/hurd/pt-sigstate-init.c
new file mode 100644
index 00000000..4c40fdb3
--- /dev/null
+++ b/libpthread/sysdeps/l4/hurd/pt-sigstate-init.c
@@ -0,0 +1,44 @@
+/* Initialize the signal state. Hurd on L4 version.
+ Copyright (C) 2003, 2008 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+
+#include <pt-internal.h>
+#include <sig-internal.h>
+
+error_t
+__pthread_sigstate_init (struct __pthread *thread)
+{
+ struct signal_state *ss = &thread->ss;
+
+ memset (ss, 0, sizeof (*ss));
+
+ ss->stack.ss_flags = SS_DISABLE;
+
+ int signo;
+ for (signo = 1; signo < NSIG; ++signo)
+ {
+ sigemptyset (&ss->actions[signo - 1].sa_mask);
+ ss->actions[signo - 1].sa_flags = SA_RESTART;
+ ss->actions[signo - 1].sa_handler = SIG_DFL;
+ ss->lock = (pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER;
+ }
+
+ return 0;
+}
diff --git a/libpthread/sysdeps/l4/hurd/pt-sigstate.c b/libpthread/sysdeps/l4/hurd/pt-sigstate.c
new file mode 100644
index 00000000..66dd08cf
--- /dev/null
+++ b/libpthread/sysdeps/l4/hurd/pt-sigstate.c
@@ -0,0 +1,81 @@
+/* Set a thread's signal state. Hurd on L4 version.
+ Copyright (C) 2002, 2005, 2008 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <assert.h>
+#include <signal.h>
+
+#include <pt-internal.h>
+
+error_t
+__pthread_sigstate (struct __pthread *thread, int how,
+ const sigset_t *set, sigset_t *oset,
+ int clear_pending)
+{
+ struct signal_state *ss = &thread->ss;
+ pthread_mutex_lock (&ss->lock);
+
+ if (oset)
+ *oset = ss->blocked;
+
+ if (set)
+ {
+ /* Mask out SIGKILL and SIGSTOP. */
+ sigset_t s = *set;
+ sigdelset (&s, SIGKILL);
+ sigdelset (&s, SIGSTOP);
+
+ switch (how)
+ {
+ case SIG_BLOCK:
+ ss->blocked |= s;
+ break;
+ case SIG_UNBLOCK:
+ ss->blocked &= ~s;
+ break;
+ case SIG_SETMASK:
+ ss->blocked = s;
+ break;
+ default:
+ errno = EINVAL;
+ pthread_mutex_unlock (&ss->lock);
+ return -1;
+ }
+ }
+
+ if (clear_pending)
+ sigemptyset (&ss->pending);
+
+ /* A "signal shall remain pending until it is unblocked" (2.4.1).
+
+ "If there are any pending unblocked signals after the call to
+ sigprocmask(), at least one of those signals shall be delivered
+ before the call to sigprocmask() returns."
+ (pthread_sigmask). */
+ sigset_t extant = ~ss->blocked & ss->pending;
+ if (! extant)
+ extant = ~ss->blocked & process_pending;
+
+ pthread_mutex_unlock (&ss->lock);
+
+ if (extant)
+ raise (l4_lsb64 (extant));
+
+ return 0;
+}
diff --git a/libpthread/sysdeps/l4/hurd/pt-startup.c b/libpthread/sysdeps/l4/hurd/pt-startup.c
new file mode 100644
index 00000000..b6461de7
--- /dev/null
+++ b/libpthread/sysdeps/l4/hurd/pt-startup.c
@@ -0,0 +1,30 @@
+/* Thread initialization. Hurd/L4 version.
+ Copyright (C) 2007 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <l4.h>
+#include <pt-internal.h>
+
+#include <hurd/exceptions.h>
+
+void
+__pthread_startup (void)
+{
+ struct __pthread *pthread = _pthread_self ();
+ pthread->threadid = l4_myself ();
+}
diff --git a/libpthread/sysdeps/l4/hurd/pt-sysdep.c b/libpthread/sysdeps/l4/hurd/pt-sysdep.c
new file mode 100644
index 00000000..c23364c7
--- /dev/null
+++ b/libpthread/sysdeps/l4/hurd/pt-sysdep.c
@@ -0,0 +1,61 @@
+/* System dependent pthreads code. Hurd version.
+ Copyright (C) 2000, 2008 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <assert.h>
+#include <stddef.h>
+#include <stdint.h>
+
+#include <pt-internal.h>
+
+int
+sched_yield (void)
+{
+ l4_yield ();
+ return 0;
+}
+
+/* Forward. */
+static void init_routine (void (*) (void *), void *)
+ __attribute__ ((noreturn));
+
+/* OK, the name of this variable isn't really appropriate, but I don't
+ want to change it yet. */
+void (*_pthread_init_routine)(void (*) (void *), void *) = &init_routine;
+
+/* This function is called from the Hurd-specific startup code. It
+ should return a new stack pointer for the main thread. The caller
+ will switch to this new stack before doing anything serious. */
+static void
+init_routine (void (*entry) (void *), void *arg)
+{
+ /* Initialize the library. */
+ __pthread_initialize ();
+
+ struct __pthread *thread;
+ int err;
+
+ /* Create the pthread structure for the main thread (i.e. us). */
+ err = __pthread_create_internal (&thread, 0,
+ (void *(*)(void *)) entry, arg);
+ assert_perror (err);
+
+ /* Switch stacks. */
+ l4_start_sp_ip (l4_myself (), thread->mcontext.sp,
+ thread->mcontext.pc);
+}
diff --git a/libpthread/sysdeps/l4/hurd/pt-sysdep.h b/libpthread/sysdeps/l4/hurd/pt-sysdep.h
new file mode 100644
index 00000000..08bcd143
--- /dev/null
+++ b/libpthread/sysdeps/l4/hurd/pt-sysdep.h
@@ -0,0 +1,61 @@
+/* Internal definitions for pthreads library.
+ Copyright (C) 2000, 2002, 2005, 2007, 2008 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#ifndef _PT_SYSDEP_H
+#define _PT_SYSDEP_H 1
+
+#include <l4.h>
+#include <hurd/storage.h>
+#include <sys/mman.h>
+
+/* XXX */
+#define _POSIX_THREAD_THREADS_MAX 64
+
+/* The default stack size: 2MB. */
+#define PTHREAD_STACK_DEFAULT (2 * 1024 * 1024)
+
+#include <hurd/exceptions.h>
+
+#define EXCEPTION_AREA_SIZE EXCEPTION_STACK_SIZE
+#define EXCEPTION_AREA_SIZE_LOG2 EXCEPTION_STACK_SIZE_LOG2
+/* The exception page is the first object. */
+#define EXCEPTION_PAGE 0
+
+#define PTHREAD_SYSDEP_MEMBERS \
+ addr_t object; \
+ l4_thread_id_t threadid; \
+ addr_t exception_area[EXCEPTION_AREA_SIZE / PAGESIZE]; \
+ void *exception_area_va; \
+ l4_word_t my_errno;
+
+extern inline struct __pthread *
+__attribute__((__always_inline__))
+_pthread_self (void)
+{
+ return (struct __pthread *) l4_user_defined_handle ();
+}
+
+extern inline void
+__attribute__((__always_inline__))
+__pthread_stack_dealloc (void *stackaddr, size_t stacksize)
+{
+ munmap (stackaddr, stacksize);
+}
+
+#endif /* pt-sysdep.h */
diff --git a/libpthread/sysdeps/l4/hurd/pt-thread-alloc.c b/libpthread/sysdeps/l4/hurd/pt-thread-alloc.c
new file mode 100644
index 00000000..ada7b3b8
--- /dev/null
+++ b/libpthread/sysdeps/l4/hurd/pt-thread-alloc.c
@@ -0,0 +1,95 @@
+/* Allocate kernel thread. Viengoos version.
+ Copyright (C) 2007, 2008 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <assert.h>
+#include <errno.h>
+#include <string.h>
+
+#include <hurd/startup.h>
+#include <hurd/storage.h>
+#include <hurd/as.h>
+#include <hurd/addr.h>
+
+#include <pt-internal.h>
+
+extern struct hurd_startup_data *__hurd_startup_data;
+
+extern addr_t meta_data_activity;
+
+int
+__pthread_thread_alloc (struct __pthread *thread)
+{
+ /* The main thread is already running of course. */
+ if (__pthread_num_threads == 1)
+ {
+ thread->object = __hurd_startup_data->thread;
+ thread->threadid = l4_myself ();
+ return 0;
+ }
+ else
+ {
+ addr_t exception_area = as_alloc (EXCEPTION_AREA_SIZE_LOG2, 1, true);
+
+ thread->exception_area_va
+ = ADDR_TO_PTR (addr_extend (exception_area,
+ 0, EXCEPTION_AREA_SIZE_LOG2));
+
+ int i;
+ for (i = 0; i < EXCEPTION_AREA_SIZE / PAGESIZE; i ++)
+ {
+ addr_t slot = addr_chop (PTR_TO_ADDR (thread->exception_area_va
+ + i * PAGESIZE),
+ PAGESIZE_LOG2);
+ as_ensure (slot);
+
+ struct storage storage = storage_alloc (ADDR_VOID, cap_page,
+ STORAGE_LONG_LIVED,
+ OBJECT_POLICY_DEFAULT,
+ slot);
+ if (ADDR_IS_VOID (storage.addr))
+ {
+ int j;
+ for (j = 0; j < i; j ++)
+ storage_free (thread->exception_area[j], false);
+ as_free (exception_area, false);
+ return EAGAIN;
+ }
+
+ thread->exception_area[i] = storage.addr;
+ }
+
+ struct storage storage;
+ storage = storage_alloc (meta_data_activity, cap_thread,
+ /* Threads are rarely shortly lived. */
+ STORAGE_MEDIUM_LIVED, OBJECT_POLICY_DEFAULT,
+ ADDR_VOID);
+ if (ADDR_IS_VOID (storage.addr))
+ {
+ int j;
+ for (j = 0; j < EXCEPTION_AREA_SIZE / PAGESIZE; j ++)
+ storage_free (thread->exception_area[j], false);
+ as_free (exception_area, false);
+ return EAGAIN;
+ }
+
+ thread->object = storage.addr;
+ }
+
+ return 0;
+}
diff --git a/libpthread/sysdeps/l4/hurd/pt-thread-halt.c b/libpthread/sysdeps/l4/hurd/pt-thread-halt.c
new file mode 100644
index 00000000..98fefaab
--- /dev/null
+++ b/libpthread/sysdeps/l4/hurd/pt-thread-halt.c
@@ -0,0 +1,104 @@
+/* Deallocate the kernel thread resources. Viengoos version.
+ Copyright (C) 2007, 2008 Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <assert.h>
+#include <errno.h>
+
+#include <pt-internal.h>
+
+#include <hurd/exceptions.h>
+#include <hurd/mutex.h>
+#include <hurd/as.h>
+#include <hurd/addr.h>
+
+/* If we try to deallocate our self, we will end up causing a
+ deadlock. Thus, when a thread tries to free itself, we add it
+ here. The next thread to free a thread will free it. */
+ss_mutex_t saved_object_lock;
+static addr_t saved_object;
+
+void
+__pthread_thread_halt (struct __pthread *thread, int need_dealloc)
+{
+ /* We may deallocate THREAD. First save any data we need. */
+
+ addr_t exception_area[EXCEPTION_AREA_SIZE / PAGESIZE];
+ memcpy (exception_area, thread->exception_area,
+ sizeof (thread->exception_area));
+ memset (thread->exception_area, 0, sizeof (thread->exception_area));
+
+ void *va = thread->exception_area_va;
+
+ addr_t object = thread->object;
+ l4_thread_id_t tid = thread->threadid;
+
+ if (need_dealloc)
+ __pthread_dealloc (thread);
+
+ /* The THREAD data structure is no longer valid. */
+ thread = NULL;
+
+ /* Deallocate any saved object. */
+ ss_mutex_lock (&saved_object_lock);
+ if (! ADDR_IS_VOID (saved_object))
+ {
+ storage_free (saved_object, false);
+ saved_object = ADDR_VOID;
+ }
+ ss_mutex_unlock (&saved_object_lock);
+
+ /* Free the exception area. */
+
+ /* Clean up the exception page. */
+ exception_page_cleanup
+ (ADDR_TO_PTR (addr_extend (exception_area[EXCEPTION_PAGE],
+ 0, PAGESIZE_LOG2)));
+
+ /* Free the storage. */
+ int i;
+ for (i = 0; i < EXCEPTION_AREA_SIZE / PAGESIZE; i ++)
+ {
+ assert (! ADDR_IS_VOID (exception_area[i]));
+ storage_free (exception_area[i], false);
+ }
+
+ /* And the address space. */
+ as_free (addr_chop (PTR_TO_ADDR (va), EXCEPTION_AREA_SIZE_LOG2), false);
+
+ if (tid == l4_myself ())
+ /* If we try to storage_free (storage.addr), we will freeze in the
+ middle. That's no good. We set SAVED_OBJECT to our thread
+ object and the next thread in will free us. */
+ {
+ ss_mutex_lock (&saved_object_lock);
+ saved_object = object;
+ ss_mutex_unlock (&saved_object_lock);
+ }
+ else
+ storage_free (object, false);
+
+ if (tid == l4_myself ())
+ {
+ l4_send_timeout (l4_myself (), L4_NEVER);
+ panic ("Failed to stop thread %x.%x!",
+ l4_thread_no (l4_myself ()), l4_version (l4_myself ()));
+ }
+ else
+ thread_stop (object);
+}
diff --git a/libpthread/sysdeps/l4/hurd/pt-thread-start.c b/libpthread/sysdeps/l4/hurd/pt-thread-start.c
new file mode 100644
index 00000000..9db399ce
--- /dev/null
+++ b/libpthread/sysdeps/l4/hurd/pt-thread-start.c
@@ -0,0 +1,70 @@
+/* Start thread. L4 version.
+ Copyright (C) 2007 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <assert.h>
+#include <errno.h>
+#include <string.h>
+#include <hurd/thread.h>
+#include <hurd/exceptions.h>
+
+#include <pt-internal.h>
+
+int
+__pthread_thread_start (struct __pthread *thread)
+{
+ error_t err;
+
+ if (__pthread_num_threads == 1)
+ /* The main thread is already running of course. */
+ {
+ assert (__pthread_total == 1);
+ assert (l4_is_thread_equal (l4_myself (), thread->threadid));
+ l4_set_user_defined_handle ((l4_word_t) thread);
+ }
+ else
+ {
+ struct hurd_thread_exregs_in in;
+ struct hurd_thread_exregs_out out;
+
+ in.aspace = ADDR (0, 0);
+ in.aspace_cap_properties = CAP_PROPERTIES_VOID;
+ in.aspace_cap_properties_flags = CAP_COPY_COPY_SOURCE_GUARD;
+
+ in.activity = ADDR_VOID;
+
+ in.exception_page = addr_chop (PTR_TO_ADDR (thread->exception_area_va),
+ PAGESIZE_LOG2);
+
+ in.sp = (l4_word_t) thread->mcontext.sp;
+ in.ip = (l4_word_t) thread->mcontext.pc;
+
+ in.user_handle = (l4_word_t) thread;
+ err = rm_thread_exregs (ADDR_VOID, thread->object,
+ HURD_EXREGS_SET_ASPACE
+ | HURD_EXREGS_SET_ACTIVITY
+ | HURD_EXREGS_SET_EXCEPTION_PAGE
+ | HURD_EXREGS_SET_SP_IP
+ | HURD_EXREGS_SET_USER_HANDLE
+ | HURD_EXREGS_START
+ | HURD_EXREGS_ABORT_IPC,
+ in, &out);
+ assert (err == 0);
+ }
+ return 0;
+}
diff --git a/libpthread/sysdeps/l4/hurd/pt-wakeup.c b/libpthread/sysdeps/l4/hurd/pt-wakeup.c
new file mode 100644
index 00000000..e568a6f9
--- /dev/null
+++ b/libpthread/sysdeps/l4/hurd/pt-wakeup.c
@@ -0,0 +1,46 @@
+/* Wakeup a thread. Viengoos version.
+ Copyright (C) 2008 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pt-internal.h>
+
+#include <hurd/stddef.h>
+#include <hurd/futex.h>
+#include <stdint.h>
+
+/* Wakeup THREAD. */
+void
+__pthread_wakeup (struct __pthread *thread)
+{
+ /* We need to loop here as the blocked thread may not yet be
+ blocked! Here's what happens when a thread blocks: it registers
+ itself as blocked, drops the relevant lock and then actually
+ blocks (via __pthread_block). This means that after dropping the
+ lock and before blocking, it may be interrupted and another
+ thread may try to wake it. */
+ long ret;
+ do
+ {
+ ret = futex_wake (&thread->threadid, INT_MAX);
+ assertx (ret <= 1, "tid: %x, ret: %d", thread->threadid, ret);
+
+ if (ret == 0)
+ l4_thread_switch (thread->threadid);
+ }
+ while (ret == 0);
+}
diff --git a/libpthread/sysdeps/l4/hurd/sig-sysdep.h b/libpthread/sysdeps/l4/hurd/sig-sysdep.h
new file mode 100644
index 00000000..33e13857
--- /dev/null
+++ b/libpthread/sysdeps/l4/hurd/sig-sysdep.h
@@ -0,0 +1,69 @@
+/* sig-sysdep.h - Hurd system specific header file.
+ Copyright (C) 2008 Free Software Foundation, Inc.
+ Written by Neal H. Walfield <neal@gnu.org>.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public License
+ as published by the Free Software Foundation; either version 3 of
+ the License, or (at your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this program. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <l4.h>
+#include <string.h>
+
+struct utcb
+{
+ l4_word_t saved_sender;
+ l4_word_t saved_receiver;
+ l4_word_t saved_timeout;
+ l4_word_t saved_error_code;
+ l4_word_t saved_flags;
+ l4_word_t saved_br0;
+ l4_msg_t saved_message;
+};
+
+static inline void
+utcb_state_save (struct utcb *buffer)
+{
+ l4_word_t *utcb = _L4_utcb ();
+
+ buffer->saved_sender = utcb[_L4_UTCB_SENDER];
+ buffer->saved_receiver = utcb[_L4_UTCB_RECEIVER];
+ buffer->saved_timeout = utcb[_L4_UTCB_TIMEOUT];
+ buffer->saved_error_code = utcb[_L4_UTCB_ERROR_CODE];
+ buffer->saved_flags = utcb[_L4_UTCB_FLAGS];
+ buffer->saved_br0 = utcb[_L4_UTCB_BR0];
+ memcpy (&buffer->saved_message,
+ utcb, L4_NUM_MRS * sizeof (l4_word_t));
+}
+
+static inline void
+utcb_state_restore (struct utcb *buffer)
+{
+ l4_word_t *utcb = _L4_utcb ();
+
+ utcb[_L4_UTCB_SENDER] = buffer->saved_sender;
+ utcb[_L4_UTCB_RECEIVER] = buffer->saved_receiver;
+ utcb[_L4_UTCB_TIMEOUT] = buffer->saved_timeout;
+ utcb[_L4_UTCB_ERROR_CODE] = buffer->saved_error_code;
+ utcb[_L4_UTCB_FLAGS] = buffer->saved_flags;
+ utcb[_L4_UTCB_BR0] = buffer->saved_br0;
+ memcpy (utcb, &buffer->saved_message,
+ L4_NUM_MRS * sizeof (l4_word_t));
+}
+
+#define SIGNAL_DISPATCH_ENTRY \
+ struct utcb buffer; utcb_state_save (&buffer);
+
+#define SIGNAL_DISPATCH_EXIT \
+ utcb_state_restore (&buffer);
diff --git a/libpthread/sysdeps/l4/hurd/sigprocmask.c b/libpthread/sysdeps/l4/hurd/sigprocmask.c
new file mode 100644
index 00000000..a38b3795
--- /dev/null
+++ b/libpthread/sysdeps/l4/hurd/sigprocmask.c
@@ -0,0 +1,41 @@
+/* sigprocmask.c - Generic sigprocmask implementation.
+ Copyright (C) 2008 Free Software Foundation, Inc.
+ Written by Neal H. Walfield <neal@gnu.org>.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public License
+ as published by the Free Software Foundation; either version 3 of
+ the License, or (at your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this program. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <pt-internal.h>
+#include <sig-internal.h>
+
+int
+sigprocmask (int how, const sigset_t *restrict set, sigset_t *restrict old)
+{
+ struct __pthread *thread = _pthread_self ();
+ if (! thread)
+ /* Library is initializing. */
+ {
+ assert (__pthread_num_threads == 1);
+
+ /* We should get the default mask from the startup data structure. */
+ if (old)
+ *old = 0;
+
+ return 0;
+ }
+
+ return pthread_sigmask (how, set, old);
+}
diff --git a/libpthread/sysdeps/l4/pt-block.c b/libpthread/sysdeps/l4/pt-block.c
new file mode 100644
index 00000000..69e1d358
--- /dev/null
+++ b/libpthread/sysdeps/l4/pt-block.c
@@ -0,0 +1,47 @@
+/* Block a thread. L4 version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <l4.h>
+
+#include <pt-internal.h>
+
+#include <hurd/stddef.h>
+
+/* Block THREAD. */
+void
+__pthread_block (struct __pthread *thread)
+{
+ debug (5, "%x.%x/%x blocking",
+ l4_thread_no (thread->threadid), l4_version (thread->threadid),
+ thread->threadid);
+
+ l4_accept (L4_UNTYPED_WORDS_ACCEPTOR);
+ l4_msg_tag_t tag = l4_receive (l4_anythread);
+ if (l4_ipc_failed (tag))
+ {
+ debug (1, "%x.%x failed to block: %d, offset: %x",
+ l4_thread_no (l4_myself ()), l4_version (l4_myself ()),
+ (l4_error_code () >> 1) & 0x7,
+ l4_error_code () >> 4);
+ assert (! l4_ipc_failed (tag));
+ }
+ else
+ debug (5, "%x.%x unblocked",
+ l4_thread_no (thread->threadid), l4_version (thread->threadid));
+}
diff --git a/libpthread/sysdeps/l4/pt-docancel.c b/libpthread/sysdeps/l4/pt-docancel.c
new file mode 100644
index 00000000..a3965d0d
--- /dev/null
+++ b/libpthread/sysdeps/l4/pt-docancel.c
@@ -0,0 +1,42 @@
+/* Cancel a thread.
+ Copyright (C) 2002, 2007 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+
+#include <pt-internal.h>
+
+static void
+call_exit (void)
+{
+ pthread_exit (0);
+}
+
+int
+__pthread_do_cancel (struct __pthread *p)
+{
+ assert (p->cancel_pending == 1);
+ assert (p->cancel_state == PTHREAD_CANCEL_ENABLE);
+
+ if (l4_is_thread_equal (l4_myself (), p->threadid))
+ call_exit ();
+ else
+ l4_start_sp_ip (p->threadid, (l4_word_t) p->mcontext.sp,
+ (l4_word_t) call_exit);
+ return 0;
+}
diff --git a/libpthread/sysdeps/l4/pt-pool-np.c b/libpthread/sysdeps/l4/pt-pool-np.c
new file mode 100644
index 00000000..e83022ba
--- /dev/null
+++ b/libpthread/sysdeps/l4/pt-pool-np.c
@@ -0,0 +1,54 @@
+/* Thread pool for L4 threads.
+ Copyright (C) 2004, 2007 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pt-internal.h>
+#include <l4/thread.h>
+
+static pthread_mutex_t pool_lock = PTHREAD_MUTEX_INITIALIZER;
+
+_L4_thread_id_t pool_list = l4_nilthread;
+
+/* Add the thread TID to the pthread kernel thread pool. */
+int
+pthread_pool_add_np (l4_thread_id_t tid)
+{
+ __pthread_mutex_lock (&pool_lock);
+ /* FIXME: Do error checking. */
+ l4_set_user_defined_handle_of (tid, pool_list);
+ pool_list = tid;
+ __pthread_mutex_unlock (&pool_lock);
+
+ return 0;
+}
+
+
+/* Get the first thread from the pool. */
+l4_thread_id_t
+pthread_pool_get_np (void)
+{
+ _L4_thread_id_t tid;
+
+ __pthread_mutex_lock (&pool_lock);
+ /* FIXME: Do error checking. */
+ tid = pool_list;
+ if (tid != l4_nilthread)
+ pool_list = l4_user_defined_handle_of (tid);
+ __pthread_mutex_unlock (&pool_lock);
+ return tid;
+}
diff --git a/libpthread/sysdeps/l4/pt-spin.c b/libpthread/sysdeps/l4/pt-spin.c
new file mode 100644
index 00000000..b6978b0c
--- /dev/null
+++ b/libpthread/sysdeps/l4/pt-spin.c
@@ -0,0 +1,63 @@
+/* Spin locks. L4 version.
+ Copyright (C) 2000, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <l4.h>
+
+#include <pthread.h>
+#include <sched.h>
+
+/* The default for single processor machines; don't spin, it's
+ pointless. */
+#ifndef __PTHREAD_SPIN_COUNT
+# define __PTHREAD_SPIN_COUNT 1
+#endif
+
+/* The number of times to spin while trying to lock a spin lock object
+ before yielding the processor. */
+int __pthread_spin_count = __PTHREAD_SPIN_COUNT;
+
+
+/* Lock the spin lock object LOCK. If the lock is held by another
+ thread spin until it becomes available. */
+int
+_pthread_spin_lock (__pthread_spinlock_t *lock)
+{
+ l4_time_t timeout;
+ int i;
+
+ /* Start with a small timeout of 2 microseconds, then back off
+ exponentially. */
+ timeout = l4_time_period (2);
+
+ while (1)
+ {
+ for (i = 0; i < __pthread_spin_count; i++)
+ {
+ if (__pthread_spin_trylock (lock) == 0)
+ return 0;
+ }
+ l4_sleep (timeout);
+
+ timeout = l4_time_mul2 (timeout);
+ if (timeout == L4_NEVER)
+ timeout = L4_TIME_PERIOD_MAX;
+ }
+}
+
+weak_alias (_pthread_spin_lock, pthread_spin_lock);
diff --git a/libpthread/sysdeps/l4/pt-stack-alloc.c b/libpthread/sysdeps/l4/pt-stack-alloc.c
new file mode 100644
index 00000000..b7ec12b4
--- /dev/null
+++ b/libpthread/sysdeps/l4/pt-stack-alloc.c
@@ -0,0 +1,43 @@
+/* Allocate a new stack. L4 Hurd version.
+ Copyright (C) 2000, 2007 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <l4.h>
+#include <errno.h>
+
+#include <pt-internal.h>
+
+#include <sys/mman.h>
+
+/* Allocate a new stack of size STACKSIZE. If successful, store the
+ address of the newly allocated stack in *STACKADDR and return 0.
+ Otherwise return an error code (EINVAL for an invalid stack size,
+ EAGAIN if the system lacked the necessary resources to allocate a
+ new stack). */
+int
+__pthread_stack_alloc (void **stackaddr, size_t stacksize)
+{
+ void *buffer = mmap (0, stacksize, PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+ if (buffer == MAP_FAILED)
+ return EAGAIN;
+
+ *stackaddr = buffer;
+
+ return 0;
+}
diff --git a/libpthread/sysdeps/l4/pt-thread-alloc.c b/libpthread/sysdeps/l4/pt-thread-alloc.c
new file mode 100644
index 00000000..ec69afb5
--- /dev/null
+++ b/libpthread/sysdeps/l4/pt-thread-alloc.c
@@ -0,0 +1,43 @@
+/* Allocate kernel thread. L4 version.
+ Copyright (C) 2003, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <assert.h>
+#include <errno.h>
+#include <string.h>
+
+#include <pt-internal.h>
+
+int
+__pthread_thread_alloc (struct __pthread *thread)
+{
+ error_t err;
+
+ /* The main thread is already running of course. */
+ if (__pthread_num_threads == 1)
+ thread->threadid = l4_myself ();
+ else
+ {
+ thread->threadid = pthread_pool_get_np ();
+ if (thread->threadid != l4_nilthread)
+ return 0;
+
+ return EAGAIN;
+ }
+ return 0;
+}
diff --git a/libpthread/sysdeps/l4/pt-thread-dealloc.c b/libpthread/sysdeps/l4/pt-thread-dealloc.c
new file mode 100644
index 00000000..c09e4860
--- /dev/null
+++ b/libpthread/sysdeps/l4/pt-thread-dealloc.c
@@ -0,0 +1,32 @@
+/* Deallocate the kernel thread resources. L4 version.
+ Copyright (C) 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <assert.h>
+#include <errno.h>
+#include <l4.h>
+
+#include <pt-internal.h>
+
+/* Deallocate any kernel resources associated with THREAD except don't
+ halt the thread itself. On return, the thread will be marked as
+ dead and __pthread_halt will be called. */
+void
+__pthread_thread_dealloc (struct __pthread *thread)
+{
+}
diff --git a/libpthread/sysdeps/l4/pt-thread-halt.c b/libpthread/sysdeps/l4/pt-thread-halt.c
new file mode 100644
index 00000000..aa2bf43d
--- /dev/null
+++ b/libpthread/sysdeps/l4/pt-thread-halt.c
@@ -0,0 +1,45 @@
+/* Deallocate the kernel thread resources. L4version.
+ Copyright (C) 2000, 2002, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <assert.h>
+#include <errno.h>
+
+#include <pt-internal.h>
+
+/* Deallocate the kernel thread resources associated with THREAD. */
+void
+__pthread_thread_halt (struct __pthread *thread, int need_dealloc)
+{
+ l4_thread_id_t tid = thread->threadid;
+
+ if (need_dealloc)
+ __pthread_dealloc (thread);
+
+ /* There is potential race here: once if TID is the current thread,
+ then once we add TID to the pool, someone can reallocate it
+ before we call stop. However, to start the thread, the caller
+ atomically starts and sets the sp and ip, thus, if the stop has
+ not yet executed at that point, it won't. */
+
+ if (tid != l4_myself ())
+ l4_stop (tid);
+ pthread_pool_add_np (tid);
+ if (tid == l4_myself ())
+ l4_stop (tid);
+}
diff --git a/libpthread/sysdeps/l4/pt-thread-start.c b/libpthread/sysdeps/l4/pt-thread-start.c
new file mode 100644
index 00000000..144c58bb
--- /dev/null
+++ b/libpthread/sysdeps/l4/pt-thread-start.c
@@ -0,0 +1,40 @@
+/* Start thread. L4 version.
+ Copyright (C) 2003, 2004, 2007 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <assert.h>
+#include <errno.h>
+#include <string.h>
+
+#include <pt-internal.h>
+
+/* Start THREAD. Get the kernel thread scheduled and running. */
+int
+__pthread_thread_start (struct __pthread *thread)
+{
+ if (__pthread_num_threads == 1)
+ /* The main thread is already running of course. */
+ {
+ assert (__pthread_total == 1);
+ assert (l4_is_thread_equal (l4_myself (), thread->threadid));
+ }
+ else
+ l4_start_sp_ip (thread->threadid, (l4_word_t) thread->mcontext.sp,
+ (l4_word_t) thread->mcontext.pc);
+ return 0;
+}
diff --git a/libpthread/sysdeps/l4/pt-timedblock.c b/libpthread/sysdeps/l4/pt-timedblock.c
new file mode 100644
index 00000000..ce7972bd
--- /dev/null
+++ b/libpthread/sysdeps/l4/pt-timedblock.c
@@ -0,0 +1,35 @@
+/* Block a thread with a timeout. L4 version.
+ Copyright (C) 2000,02 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <assert.h>
+#include <errno.h>
+#include <time.h>
+#include <sys/time.h>
+
+#include <pt-internal.h>
+
+/* Block THREAD. */
+error_t
+__pthread_timedblock (struct __pthread *thread,
+ const struct timespec *abstime)
+{
+#warning Need gettimeofday to implement properly.
+ __pthread_block (thread);
+ return 0;
+}
diff --git a/libpthread/sysdeps/l4/pt-wakeup.c b/libpthread/sysdeps/l4/pt-wakeup.c
new file mode 100644
index 00000000..de378465
--- /dev/null
+++ b/libpthread/sysdeps/l4/pt-wakeup.c
@@ -0,0 +1,54 @@
+/* Wakeup a thread. L4 version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <l4.h>
+
+#include <pt-internal.h>
+
+#include <hurd/stddef.h>
+
+/* Wakeup THREAD. */
+void
+__pthread_wakeup (struct __pthread *thread)
+{
+ debug (5, "%x.%x/%x waking %x.%x/%x",
+ l4_thread_no (l4_myself ()), l4_version (l4_myself ()), l4_myself (),
+ l4_thread_no (thread->threadid), l4_version (thread->threadid),
+ thread->threadid);
+
+ /* Signal the waiter. */
+ l4_msg_t msg;
+ l4_msg_clear (msg);
+ l4_msg_set_untyped_words (msg, 0);
+ l4_msg_load (msg);
+
+ l4_msg_tag_t tag = l4_send (thread->threadid);
+ if (l4_ipc_failed (tag))
+ {
+ int err = l4_error_code ();
+ debug (1, "%x.%x failed to wake %x.%x: %s (%d)",
+ l4_thread_no (l4_myself ()), l4_version (l4_myself ()),
+ l4_thread_no (thread->threadid), l4_version (thread->threadid),
+ l4_strerror (err), err);
+ }
+ else
+ debug (5, "%x.%x woke %x.%x",
+ l4_thread_no (l4_myself ()), l4_version (l4_myself ()),
+ l4_thread_no (thread->threadid), l4_version (thread->threadid));
+}
diff --git a/libpthread/sysdeps/mach/bits/spin-lock-inline.h b/libpthread/sysdeps/mach/bits/spin-lock-inline.h
new file mode 100644
index 00000000..f9f7c299
--- /dev/null
+++ b/libpthread/sysdeps/mach/bits/spin-lock-inline.h
@@ -0,0 +1,90 @@
+/* Definitions of user-visible names for spin locks.
+ Copyright (C) 1994, 1997, 2002, 2008, 2009 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _BITS_SPIN_LOCK_INLINE_H
+#define _BITS_SPIN_LOCK_INLINE_H 1
+
+#include <features.h>
+#include <bits/spin-lock.h>
+#include <machine-lock.h> /* This does all the work. */
+
+__BEGIN_DECLS
+
+#if defined __USE_EXTERN_INLINES || defined _FORCE_INLINES
+
+# ifndef __EBUSY
+# include <errno.h>
+# define __EBUSY EBUSY
+# endif
+
+# ifndef __PT_SPIN_INLINE
+# define __PT_SPIN_INLINE __extern_inline
+# endif
+
+__PT_SPIN_INLINE int __pthread_spin_destroy (__pthread_spinlock_t *__lock);
+
+__PT_SPIN_INLINE int
+__pthread_spin_destroy (__pthread_spinlock_t *__lock)
+{
+ return 0;
+}
+
+__PT_SPIN_INLINE int __pthread_spin_init (__pthread_spinlock_t *__lock,
+ int __pshared);
+
+__PT_SPIN_INLINE int
+__pthread_spin_init (__pthread_spinlock_t *__lock, int __pshared)
+{
+ *__lock = __PTHREAD_SPIN_LOCK_INITIALIZER;
+ return 0;
+}
+
+__PT_SPIN_INLINE int __pthread_spin_trylock (__pthread_spinlock_t *__lock);
+
+__PT_SPIN_INLINE int
+__pthread_spin_trylock (__pthread_spinlock_t *__lock)
+{
+ return __spin_try_lock (__lock) ? 0 : __EBUSY;
+}
+
+__extern_inline int __pthread_spin_lock (__pthread_spinlock_t *__lock);
+extern int _pthread_spin_lock (__pthread_spinlock_t *__lock);
+
+__extern_inline int
+__pthread_spin_lock (__pthread_spinlock_t *__lock)
+{
+ if (__pthread_spin_trylock (__lock))
+ return _pthread_spin_lock (__lock);
+ return 0;
+}
+
+__PT_SPIN_INLINE int __pthread_spin_unlock (__pthread_spinlock_t *__lock);
+
+__PT_SPIN_INLINE int
+__pthread_spin_unlock (__pthread_spinlock_t *__lock)
+{
+ __spin_unlock (__lock);
+ return 0;
+}
+
+#endif /* Use extern inlines or force inlines. */
+
+__END_DECLS
+
+#endif /* bits/spin-lock.h */
diff --git a/libpthread/sysdeps/mach/bits/spin-lock.h b/libpthread/sysdeps/mach/bits/spin-lock.h
new file mode 100644
index 00000000..537dac9d
--- /dev/null
+++ b/libpthread/sysdeps/mach/bits/spin-lock.h
@@ -0,0 +1,38 @@
+/* Definitions of user-visible names for spin locks.
+ Copyright (C) 1994, 1997, 2002, 2008, 2009 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _BITS_SPIN_LOCK_H
+#define _BITS_SPIN_LOCK_H 1
+
+#include <features.h>
+#include <machine-lock.h> /* This does all the work. */
+
+__BEGIN_DECLS
+
+/* The type of a spin lock object. */
+typedef __spin_lock_t __pthread_spinlock_t;
+
+/* Initializer for a spin lock object. */
+#ifndef __PTHREAD_SPIN_LOCK_INITIALIZER
+#error __PTHREAD_SPIN_LOCK_INITIALIZER undefined: should be defined by <lock-intern.h>.
+#endif
+
+__END_DECLS
+
+#endif /* bits/spin-lock.h */
diff --git a/libpthread/sysdeps/mach/hurd/ia32/pt-machdep.c b/libpthread/sysdeps/mach/hurd/ia32/pt-machdep.c
new file mode 100644
index 00000000..f3c8cf50
--- /dev/null
+++ b/libpthread/sysdeps/mach/hurd/ia32/pt-machdep.c
@@ -0,0 +1,83 @@
+/* Machine dependent pthreads code. Hurd/i386 version.
+ Copyright (C) 2000, 2002, 2007 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <errno.h>
+
+#include <mach.h>
+#include <mach/i386/thread_status.h>
+#include <mach/i386/mach_i386.h>
+#include <mach/mig_errors.h>
+#include <mach/thread_status.h>
+
+#define HURD_TLS_DESC_DECL(desc, tcb) \
+ struct descriptor desc = \
+ { /* low word: */ \
+ 0xffff /* limit 0..15 */ \
+ | (((unsigned int) (tcb)) << 16) /* base 0..15 */ \
+ , /* high word: */ \
+ ((((unsigned int) (tcb)) >> 16) & 0xff) /* base 16..23 */ \
+ | ((0x12 | 0x60 | 0x80) << 8) /* access = ACC_DATA_W|ACC_PL_U|ACC_P */ \
+ | (0xf << 16) /* limit 16..19 */ \
+ | ((4 | 8) << 20) /* granularity = SZ_32|SZ_G */ \
+ | (((unsigned int) (tcb)) & 0xff000000) /* base 24..31 */ \
+ }
+
+int
+__thread_set_pcsptp (thread_t thread,
+ int set_ip, void *ip,
+ int set_sp, void *sp,
+ int set_tp, void *tp)
+{
+ error_t err;
+ struct i386_thread_state state;
+ mach_msg_type_number_t state_count;
+
+ state_count = i386_THREAD_STATE_COUNT;
+
+ err = __thread_get_state (thread, i386_REGS_SEGS_STATE,
+ (thread_state_t) &state, &state_count);
+ if (err)
+ return err;
+
+ if (set_sp)
+ state.uesp = (unsigned int) sp;
+ if (set_ip)
+ state.eip = (unsigned int) ip;
+ if (set_tp) {
+ HURD_TLS_DESC_DECL(desc, tp);
+ int sel;
+
+ asm ("mov %%gs, %w0" : "=q" (sel) : "0" (0));
+ if (__builtin_expect (sel, 0x48) & 4) /* LDT selector */
+ err = __i386_set_ldt (thread, sel, &desc, 1);
+ else
+ err = __i386_set_gdt (thread, &sel, desc);
+ if (err)
+ return err;
+ state.gs = sel;
+ }
+
+ err = __thread_set_state (thread, i386_REGS_SEGS_STATE,
+ (thread_state_t) &state,
+ i386_THREAD_STATE_COUNT);
+ if (err)
+ return err;
+
+ return 0;
+}
diff --git a/libpthread/sysdeps/mach/hurd/ia32/pt-setup.c b/libpthread/sysdeps/mach/hurd/ia32/pt-setup.c
new file mode 100644
index 00000000..5420dc8e
--- /dev/null
+++ b/libpthread/sysdeps/mach/hurd/ia32/pt-setup.c
@@ -0,0 +1,108 @@
+/* Setup thread stack. Hurd/i386 version.
+ Copyright (C) 2000, 2002, 2005, 2007, 2008 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <stdint.h>
+#include <assert.h>
+#include <mach.h>
+
+#include <pt-internal.h>
+
+/* The stack layout used on the i386 is:
+
+ -----------------
+ | ARG |
+ -----------------
+ | START_ROUTINE |
+ -----------------
+ | 0 |
+ -----------------
+ | |
+ | Fast TSD |
+ | |
+ -----------------
+
+ We need to reserve __hurd_threadvar_max `unsigned long int's' of
+ (fast) thread-specific data (TSD) for the Hurd. */
+
+/* Set up the stack for THREAD, such that it appears as if
+ START_ROUTINE and ARG were passed to the new thread's entry-point.
+ Return the stack pointer for the new thread. */
+static void *
+stack_setup (struct __pthread *thread,
+ void *(*start_routine)(void *), void *arg)
+{
+ error_t err;
+ uintptr_t *bottom, *top;
+
+ /* Calculate the top of the new stack. */
+ bottom = thread->stackaddr;
+ top = (uintptr_t *) ((uintptr_t) bottom + thread->stacksize);
+
+ /* Next, make room for the TSDs. */
+ top -= __hurd_threadvar_max;
+
+ /* Save the self pointer. */
+ top[_HURD_THREADVAR_THREAD] = (uintptr_t) thread;
+
+ if (start_routine)
+ {
+ /* And then the call frame. */
+ top -= 2;
+ top = (uintptr_t *) ((uintptr_t) top & ~0xf);
+ top[1] = (uintptr_t) arg; /* Argument to START_ROUTINE. */
+ top[0] = (uintptr_t) start_routine;
+ *--top = 0; /* Fake return address. */
+ }
+
+ if (thread->guardsize)
+ {
+ err = __vm_protect (__mach_task_self (), (vm_address_t) bottom,
+ thread->guardsize, 0, 0);
+ assert_perror (err);
+ }
+
+ return top;
+}
+
+int
+__pthread_setup (struct __pthread *thread,
+ void (*entry_point)(void *(*)(void *), void *),
+ void *(*start_routine)(void *), void *arg)
+{
+ error_t err;
+ mach_port_t ktid;
+
+ thread->mcontext.pc = entry_point;
+ thread->mcontext.sp = stack_setup (thread, start_routine, arg);
+
+ thread->tcb->self = thread->kernel_thread;
+
+ ktid = __mach_thread_self ();
+ if (thread->kernel_thread != ktid)
+ {
+ err = __thread_set_pcsptp (thread->kernel_thread,
+ 1, thread->mcontext.pc,
+ 1, thread->mcontext.sp,
+ 1, thread->tcb);
+ assert_perror (err);
+ }
+ __mach_port_deallocate (__mach_task_self (), ktid);
+
+ return 0;
+}
diff --git a/libpthread/sysdeps/mach/hurd/pt-attr-setstackaddr.c b/libpthread/sysdeps/mach/hurd/pt-attr-setstackaddr.c
new file mode 100644
index 00000000..1225ed5b
--- /dev/null
+++ b/libpthread/sysdeps/mach/hurd/pt-attr-setstackaddr.c
@@ -0,0 +1,35 @@
+/* pthread_attr_setstackaddr. Hurd on Mach version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+/* We use fixed sized stacks which require proper alignment. */
+#define __pthread_stacksize __pthread_default_attr.stacksize
+
+int
+pthread_attr_setstackaddr (pthread_attr_t *attr,
+ void *stackaddr)
+{
+ if ((long) stackaddr & (__pthread_stacksize - 1))
+ return EINVAL;
+
+ attr->stackaddr = stackaddr;
+ return 0;
+}
diff --git a/libpthread/sysdeps/mach/hurd/pt-attr-setstacksize.c b/libpthread/sysdeps/mach/hurd/pt-attr-setstacksize.c
new file mode 100644
index 00000000..6471c0a3
--- /dev/null
+++ b/libpthread/sysdeps/mach/hurd/pt-attr-setstacksize.c
@@ -0,0 +1,35 @@
+/* pthread_attr_setstacksize. Hurd on Mach version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+/* We use fixed sized stacks which require proper alignment. */
+#define __pthread_stacksize __pthread_default_attr.stacksize
+
+int
+pthread_attr_setstacksize (pthread_attr_t *attr,
+ size_t stacksize)
+{
+ if (stacksize != __pthread_stacksize)
+ return EINVAL;
+
+ attr->stacksize = stacksize;
+ return 0;
+}
diff --git a/libpthread/sysdeps/mach/hurd/pt-docancel.c b/libpthread/sysdeps/mach/hurd/pt-docancel.c
new file mode 100644
index 00000000..105c6fda
--- /dev/null
+++ b/libpthread/sysdeps/mach/hurd/pt-docancel.c
@@ -0,0 +1,64 @@
+/* Cancel a thread.
+ Copyright (C) 2002, 2007, 2008 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+
+#include <pt-internal.h>
+
+static void
+call_exit (void)
+{
+ pthread_exit (0);
+}
+
+int
+__pthread_do_cancel (struct __pthread *p)
+{
+ mach_port_t ktid;
+ int me;
+
+ assert (p->cancel_pending == 1);
+ assert (p->cancel_state == PTHREAD_CANCEL_ENABLE);
+
+ ktid = __mach_thread_self ();
+ me = p->kernel_thread == ktid;
+ __mach_port_deallocate (__mach_task_self (), ktid);
+
+ if (me)
+ call_exit ();
+ else
+ {
+ error_t err;
+
+ err = __thread_suspend (p->kernel_thread);
+ assert_perror (err);
+
+ err = __thread_abort (p->kernel_thread);
+ assert_perror (err);
+
+ err = __thread_set_pcsptp (p->kernel_thread,
+ 1, (void *) call_exit, 0, 0, 0, 0);
+ assert_perror (err);
+
+ err = __thread_resume (p->kernel_thread);
+ assert_perror (err);
+ }
+
+ return 0;
+}
diff --git a/libpthread/sysdeps/mach/hurd/pt-sigstate-destroy.c b/libpthread/sysdeps/mach/hurd/pt-sigstate-destroy.c
new file mode 100644
index 00000000..8e56c5cf
--- /dev/null
+++ b/libpthread/sysdeps/mach/hurd/pt-sigstate-destroy.c
@@ -0,0 +1,28 @@
+/* Destroy the signal state. Hurd on Mach version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+
+#include <pt-internal.h>
+
+void
+__pthread_sigstate_destroy (struct __pthread *thread)
+{
+ /* Nothing to do. */
+}
diff --git a/libpthread/sysdeps/mach/hurd/pt-sigstate-init.c b/libpthread/sysdeps/mach/hurd/pt-sigstate-init.c
new file mode 100644
index 00000000..da5a9455
--- /dev/null
+++ b/libpthread/sysdeps/mach/hurd/pt-sigstate-init.c
@@ -0,0 +1,37 @@
+/* Initialize the signal state. Hurd on Mach version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <hurd/threadvar.h>
+
+#include <pt-internal.h>
+
+error_t
+__pthread_sigstate_init (struct __pthread *thread)
+{
+ void **location =
+ (void *) __hurd_threadvar_location_from_sp (_HURD_THREADVAR_SIGSTATE,
+ thread->stackaddr);
+
+ /* The real initialization happens internally in glibc the first
+ time that _hurd_thead_sigstate is called. */
+ *location = 0;
+
+ return 0;
+}
diff --git a/libpthread/sysdeps/mach/hurd/pt-sigstate.c b/libpthread/sysdeps/mach/hurd/pt-sigstate.c
new file mode 100644
index 00000000..68c79c5b
--- /dev/null
+++ b/libpthread/sysdeps/mach/hurd/pt-sigstate.c
@@ -0,0 +1,69 @@
+/* Set a thread's signal state. Hurd on Mach version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <assert.h>
+#include <signal.h>
+#include <hurd/signal.h>
+
+#include <pt-internal.h>
+
+error_t
+__pthread_sigstate (struct __pthread *thread, int how,
+ const sigset_t *set, sigset_t *oset,
+ int clear_pending)
+{
+ error_t err = 0;
+ struct hurd_sigstate *ss;
+
+ ss = _hurd_thread_sigstate (thread->kernel_thread);
+ assert (ss);
+
+ __pthread_spin_lock (&ss->lock);
+
+ if (oset)
+ *oset = ss->blocked;
+
+ if (set)
+ switch (how)
+ {
+ case SIG_BLOCK:
+ ss->blocked |= *set;
+ break;
+
+ case SIG_SETMASK:
+ ss->blocked = *set;
+ break;
+
+ case SIG_UNBLOCK:
+ ss->blocked &= ~*set;
+ break;
+
+ default:
+ err = EINVAL;
+ break;
+ }
+
+ if (! err && clear_pending)
+ __sigemptyset (&ss->pending);
+
+ __pthread_spin_unlock (&ss->lock);
+
+ return err;
+}
diff --git a/libpthread/sysdeps/mach/hurd/pt-sysdep.c b/libpthread/sysdeps/mach/hurd/pt-sysdep.c
new file mode 100644
index 00000000..5e070067
--- /dev/null
+++ b/libpthread/sysdeps/mach/hurd/pt-sysdep.c
@@ -0,0 +1,72 @@
+/* System dependent pthreads code. Hurd version.
+ Copyright (C) 2000, 2002, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <assert.h>
+#include <stddef.h>
+#include <stdint.h>
+
+#include <mach.h>
+#include <mach/mig_support.h>
+
+#include <hurd/threadvar.h>
+
+#include <pt-internal.h>
+
+/* Forward. */
+static void *init_routine (void);
+
+/* OK, the name of this variable isn't really appropriate, but I don't
+ want to change it yet. */
+void *(*_cthread_init_routine)(void) = &init_routine;
+
+/* This function is called from the Hurd-specific startup code. It
+ should return a new stack pointer for the main thread. The caller
+ will switch to this new stack before doing anything serious. */
+static void *
+init_routine (void)
+{
+ struct __pthread *thread;
+ int err;
+
+ /* Initialize the library. */
+ __pthread_initialize ();
+
+ /* Create the pthread structure for the main thread (i.e. us). */
+ err = __pthread_create_internal (&thread, 0, 0, 0);
+ assert_perror (err);
+
+ ((void **) (__hurd_threadvar_stack_offset))[_HURD_THREADVAR_THREAD]
+ = thread;
+
+ /* Decrease the number of threads, to take into account that the
+ signal thread (which will be created by the glibc startup code
+ when we return from here) shouldn't be seen as a user thread. */
+ __pthread_total--;
+
+ /* Make MiG code thread aware. */
+ __mig_init (thread->stackaddr);
+
+ /* Make sure we can find the per-thread variables. */
+ __hurd_threadvar_stack_mask = ~(__pthread_default_attr.stacksize - 1);
+ __hurd_threadvar_stack_offset
+ = (__pthread_default_attr.stacksize
+ - __hurd_threadvar_max * sizeof (uintptr_t));
+
+ return thread->mcontext.sp;
+}
diff --git a/libpthread/sysdeps/mach/hurd/pt-sysdep.h b/libpthread/sysdeps/mach/hurd/pt-sysdep.h
new file mode 100644
index 00000000..13e235d9
--- /dev/null
+++ b/libpthread/sysdeps/mach/hurd/pt-sysdep.h
@@ -0,0 +1,72 @@
+/* Internal defenitions for pthreads library.
+ Copyright (C) 2000, 2002, 2007, 2008 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#ifndef _PT_SYSDEP_H
+#define _PT_SYSDEP_H 1
+
+#include <mach.h>
+
+#include <hurd/threadvar.h>
+
+/* XXX */
+#define _POSIX_THREAD_THREADS_MAX 64
+
+/* The default stack size. */
+#define PTHREAD_STACK_DEFAULT (2 * 1024 * 1024)
+
+#define PTHREAD_SYSDEP_MEMBERS \
+ thread_t kernel_thread; \
+ mach_msg_header_t wakeupmsg; \
+ int have_kernel_resources;
+
+#define _HURD_THREADVAR_THREAD _HURD_THREADVAR_DYNAMIC_USER
+
+#define _pthread_self() \
+ ({ \
+ struct __pthread *thread; \
+ \
+ assert (__pthread_threads); \
+ thread = *(struct __pthread **) \
+ __hurd_threadvar_location (_HURD_THREADVAR_THREAD); \
+ \
+ assert (thread); \
+ assert (({ mach_port_t ktid = __mach_thread_self (); \
+ int ok = thread->kernel_thread == ktid; \
+ __mach_port_deallocate (__mach_task_self (), ktid);\
+ ok; })); \
+ thread; \
+ })
+
+extern inline void
+__attribute__((__always_inline__))
+__pthread_stack_dealloc (void *stackaddr, size_t stacksize)
+{
+ __vm_deallocate (__mach_task_self (), (vm_offset_t) stackaddr, stacksize);
+}
+
+/* Change thread THREAD's program counter to PC if SET_PC is true,
+ its stack pointer to SP if SET_IP is true, and its thread pointer
+ to TP if SET_TP is true. */
+extern int __thread_set_pcsptp (thread_t thread,
+ int set_pc, void *pc,
+ int set_sp, void *sp,
+ int set_tp, void *tp);
+
+
+#endif /* pt-sysdep.h */
diff --git a/libpthread/sysdeps/mach/pt-block.c b/libpthread/sysdeps/mach/pt-block.c
new file mode 100644
index 00000000..a947b27c
--- /dev/null
+++ b/libpthread/sysdeps/mach/pt-block.c
@@ -0,0 +1,39 @@
+/* Block a thread. Mach version.
+ Copyright (C) 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <assert.h>
+#include <errno.h>
+
+#include <mach.h>
+#include <mach/message.h>
+
+#include <pt-internal.h>
+
+/* Block THREAD. */
+void
+__pthread_block (struct __pthread *thread)
+{
+ mach_msg_header_t msg;
+ error_t err;
+
+ err = __mach_msg (&msg, MACH_RCV_MSG, 0, sizeof msg,
+ thread->wakeupmsg.msgh_remote_port,
+ MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL);
+ assert_perror (err);
+}
diff --git a/libpthread/sysdeps/mach/pt-spin.c b/libpthread/sysdeps/mach/pt-spin.c
new file mode 100644
index 00000000..d9a2a32a
--- /dev/null
+++ b/libpthread/sysdeps/mach/pt-spin.c
@@ -0,0 +1,36 @@
+/* Spin locks. Mach version.
+ Copyright (C) 2002, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <machine-lock.h>
+
+/* In glibc. */
+extern void __spin_lock_solid (__pthread_spinlock_t *lock);
+
+/* Lock the spin lock object LOCK. If the lock is held by another
+ thread spin until it becomes available. */
+int
+_pthread_spin_lock (__pthread_spinlock_t *lock)
+{
+ __spin_lock_solid (lock);
+ return 0;
+}
+
+weak_alias (_pthread_spin_lock, pthread_spin_lock);
+weak_alias (_pthread_spin_lock, __pthread_spin_lock);
diff --git a/libpthread/sysdeps/mach/pt-stack-alloc.c b/libpthread/sysdeps/mach/pt-stack-alloc.c
new file mode 100644
index 00000000..0956fc7d
--- /dev/null
+++ b/libpthread/sysdeps/mach/pt-stack-alloc.c
@@ -0,0 +1,74 @@
+/* Allocate a new stack. Mach version.
+ Copyright (C) 2000,02 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <errno.h>
+
+#include <mach.h>
+#include <mach/machine/vm_param.h>
+
+#include <pt-internal.h>
+
+#define __pthread_stacksize __pthread_default_attr.stacksize
+
+/* The next address to use for stack allocation. */
+static vm_address_t next_stack_base = VM_MIN_ADDRESS;
+
+
+/* Allocate a new stack of size STACKSIZE. If successful, store the
+ address of the newly allocated stack in *STACKADDR and return 0.
+ Otherwise return an error code (EINVAL for an invalid stack size,
+ EAGAIN if the system lacked the necessary resources to allocate a
+ new stack). */
+int
+__pthread_stack_alloc (void **stackaddr, size_t stacksize)
+{
+ vm_offset_t base;
+ int i = 0;
+
+ if (stacksize != __pthread_stacksize)
+ return EINVAL;
+
+ get_stack:
+ i ++;
+ for (base = next_stack_base;
+ base < VM_MAX_ADDRESS
+ && __vm_allocate (__mach_task_self (), &base,
+ __pthread_stacksize, FALSE) != KERN_SUCCESS;
+ base += __pthread_stacksize)
+ ;
+
+ if (base >= VM_MAX_ADDRESS)
+ {
+ if (i == 1)
+ {
+ next_stack_base = VM_MIN_ADDRESS;
+ goto get_stack;
+ }
+ else
+ return EAGAIN;
+ }
+
+ if (base >= VM_MAX_ADDRESS)
+ return EAGAIN;
+
+ next_stack_base = base + __pthread_stacksize;
+
+ (*stackaddr) = (void *) base;
+ return 0;
+}
diff --git a/libpthread/sysdeps/mach/pt-thread-alloc.c b/libpthread/sysdeps/mach/pt-thread-alloc.c
new file mode 100644
index 00000000..3d7c0465
--- /dev/null
+++ b/libpthread/sysdeps/mach/pt-thread-alloc.c
@@ -0,0 +1,106 @@
+/* Start thread. Mach version.
+ Copyright (C) 2000, 2002, 2005, 2008 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <assert.h>
+#include <errno.h>
+#include <string.h>
+
+#include <mach.h>
+
+#include <pt-internal.h>
+
+/* Prepare a wakeup message. */
+static error_t
+create_wakeupmsg (struct __pthread *thread)
+{
+ kern_return_t err;
+
+ /* Build wakeup message. */
+ thread->wakeupmsg.msgh_bits = MACH_MSGH_BITS (MACH_MSG_TYPE_COPY_SEND, 0);
+ thread->wakeupmsg.msgh_size = 0;
+
+ err = __mach_port_allocate (__mach_task_self (), MACH_PORT_RIGHT_RECEIVE,
+ &thread->wakeupmsg.msgh_remote_port);
+ if (err)
+ return EAGAIN;
+
+ thread->wakeupmsg.msgh_local_port = MACH_PORT_NULL;
+ thread->wakeupmsg.msgh_seqno = 0;
+ thread->wakeupmsg.msgh_id = 0;
+
+ err = __mach_port_insert_right (__mach_task_self (),
+ thread->wakeupmsg.msgh_remote_port,
+ thread->wakeupmsg.msgh_remote_port,
+ MACH_MSG_TYPE_MAKE_SEND);
+ if (err)
+ {
+ __mach_port_destroy (__mach_task_self (),
+ thread->wakeupmsg.msgh_remote_port);
+ return EAGAIN;
+ }
+
+ return 0;
+}
+
+/* Allocate any resouces for THREAD. The new kernel thread should not
+ be eligible to be scheduled. */
+int
+__pthread_thread_alloc (struct __pthread *thread)
+{
+ if (thread->have_kernel_resources)
+ return 0;
+
+ error_t err;
+
+ err = create_wakeupmsg (thread);
+ if (err)
+ return err;
+
+ /* If there are no pthreads in the system then the pthread library
+ is bootstrapping and the main thread must create initialize
+ itself. The thread itself is already running, it just has not
+ pthread context. We want to reuse what it already has (including
+ the kernel thread), however, we must determine which thread is
+ the main thread.
+
+ We cannot test if __pthread_total is one as we later decrement
+ before creating the signal thread. Currently, we check if
+ __pthread_num_threads--the number of allocated thread
+ structures--is one. __pthread_alloc has already been called in
+ __pthread_create_internal for us. This predicate could be improved,
+ however, it is sufficient for now. */
+ if (__pthread_num_threads == 1)
+ {
+ assert (__pthread_total == 0);
+ thread->kernel_thread = __mach_thread_self ();
+ /* We implicitly hold a reference drop the one that we just
+ acquired. */
+ __mach_port_deallocate (__mach_task_self (), thread->kernel_thread);
+ }
+ else
+ {
+ err = __thread_create (__mach_task_self (), &thread->kernel_thread);
+ if (err)
+ return EAGAIN;
+ }
+
+ thread->have_kernel_resources = 1;
+
+ return 0;
+}
diff --git a/libpthread/sysdeps/mach/pt-thread-dealloc.c b/libpthread/sysdeps/mach/pt-thread-dealloc.c
new file mode 100644
index 00000000..55d8c4d5
--- /dev/null
+++ b/libpthread/sysdeps/mach/pt-thread-dealloc.c
@@ -0,0 +1,41 @@
+/* Deallocate the kernel thread resources. Mach version.
+ Copyright (C) 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <assert.h>
+#include <errno.h>
+#include <mach.h>
+
+#include <pt-internal.h>
+
+/* Deallocate any kernel resources associated with THREAD except don't
+ halt the thread itself. On return, the thread will be marked as
+ dead and __pthread_halt will be called. */
+void
+__pthread_thread_dealloc (struct __pthread *thread)
+{
+ /* Why no assert? Easy. When Mach kills a task, it starts by
+ invalidating the task port and then terminating the threads one
+ by one. But while it is terminating them, they are still
+ eligible to be scheduled. Imagine we have two threads, one calls
+ exit, one calls pthread_exit. The second one may run this after
+ the mask port can been destroyed thus gratuitously triggering the
+ assert. */
+ __mach_port_destroy (__mach_task_self (),
+ thread->wakeupmsg.msgh_remote_port);
+}
diff --git a/libpthread/sysdeps/mach/pt-thread-halt.c b/libpthread/sysdeps/mach/pt-thread-halt.c
new file mode 100644
index 00000000..973cde1e
--- /dev/null
+++ b/libpthread/sysdeps/mach/pt-thread-halt.c
@@ -0,0 +1,37 @@
+/* Deallocate the kernel thread resources. Mach version.
+ Copyright (C) 2000, 2002, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <assert.h>
+#include <errno.h>
+#include <mach.h>
+
+#include <pt-internal.h>
+
+/* Stop the kernel thread associated with THREAD. If NEED_DEALLOC is
+ true, the function must call __pthread_dealloc on THREAD.
+
+ NB: The thread executing this function may be the thread which is
+ being halted, thus the last action should be halting the thread
+ itself. */
+void
+__pthread_thread_halt (struct __pthread *thread)
+{
+ error_t err = __thread_terminate (thread->kernel_thread);
+ assert_perror (err);
+}
diff --git a/libpthread/sysdeps/mach/pt-thread-start.c b/libpthread/sysdeps/mach/pt-thread-start.c
new file mode 100644
index 00000000..11b017ff
--- /dev/null
+++ b/libpthread/sysdeps/mach/pt-thread-start.c
@@ -0,0 +1,49 @@
+/* Start thread. Mach version.
+ Copyright (C) 2000,02 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <assert.h>
+#include <errno.h>
+#include <mach.h>
+
+#include <pt-internal.h>
+
+/* Start THREAD. Get the kernel thread scheduled and running. */
+int
+__pthread_thread_start (struct __pthread *thread)
+{
+ error_t err;
+
+ if (__pthread_num_threads == 1)
+ {
+ /* The main thread is already running: do nothing. */
+ assert (__pthread_total == 1);
+ assert (({ mach_port_t ktid = __mach_thread_self ();
+ int ok = thread->kernel_thread == ktid;
+ __mach_port_deallocate (__mach_task_self (),
+ thread->kernel_thread);
+ ok; }));
+ }
+ else
+ {
+ err = __thread_resume (thread->kernel_thread);
+ assert_perror (err);
+ }
+
+ return 0;
+}
diff --git a/libpthread/sysdeps/mach/pt-timedblock.c b/libpthread/sysdeps/mach/pt-timedblock.c
new file mode 100644
index 00000000..6f547265
--- /dev/null
+++ b/libpthread/sysdeps/mach/pt-timedblock.c
@@ -0,0 +1,68 @@
+/* Block a thread with a timeout. Mach version.
+ Copyright (C) 2000, 2002, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <assert.h>
+#include <errno.h>
+#include <time.h>
+#include <sys/time.h>
+
+#include <mach.h>
+#include <mach/message.h>
+
+#include <pt-internal.h>
+
+/* Block THREAD. */
+error_t
+__pthread_timedblock (struct __pthread *thread,
+ const struct timespec *abstime)
+{
+ error_t err;
+ mach_msg_header_t msg;
+ mach_msg_timeout_t timeout;
+ struct timeval now;
+
+ /* We have an absolute time and now we have to convert it to a
+ relative time. Arg. */
+
+ err = gettimeofday(&now, NULL);
+ assert (! err);
+
+ if (now.tv_sec > abstime->tv_sec
+ || (now.tv_sec == abstime->tv_sec
+ && now.tv_usec > ((abstime->tv_nsec + 999) / 1000)))
+ return ETIMEDOUT;
+
+ timeout = (abstime->tv_sec - now.tv_sec) * 1000;
+
+ if (((abstime->tv_nsec + 999) / 1000) >= now.tv_usec)
+ timeout += (((abstime->tv_nsec + 999) / 1000) - now.tv_usec + 999) / 1000;
+ else
+ /* Need to do a carry. */
+ timeout -= (now.tv_usec + 999) / 1000 -
+ ((abstime->tv_nsec + 999999) / 1000000);
+
+ err = __mach_msg (&msg, MACH_RCV_MSG | MACH_RCV_TIMEOUT, 0,
+ sizeof msg, thread->wakeupmsg.msgh_remote_port,
+ timeout, MACH_PORT_NULL);
+ if (err == EMACH_RCV_TIMED_OUT)
+ return ETIMEDOUT;
+
+ assert_perror (err);
+ return 0;
+}
diff --git a/libpthread/sysdeps/mach/pt-wakeup.c b/libpthread/sysdeps/mach/pt-wakeup.c
new file mode 100644
index 00000000..4920d102
--- /dev/null
+++ b/libpthread/sysdeps/mach/pt-wakeup.c
@@ -0,0 +1,38 @@
+/* Wakeup a thread. Mach version.
+ Copyright (C) 2000, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <assert.h>
+#include <errno.h>
+
+#include <mach.h>
+#include <mach/message.h>
+
+#include <pt-internal.h>
+
+/* Wakeup THREAD. */
+void
+__pthread_wakeup (struct __pthread *thread)
+{
+ error_t err;
+
+ err = __mach_msg (&thread->wakeupmsg, MACH_SEND_MSG,
+ sizeof (thread->wakeupmsg), 0, MACH_PORT_NULL,
+ MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL);
+ assert_perror (err);
+}
diff --git a/libpthread/sysdeps/posix/pt-spin.c b/libpthread/sysdeps/posix/pt-spin.c
new file mode 100644
index 00000000..cb809c64
--- /dev/null
+++ b/libpthread/sysdeps/posix/pt-spin.c
@@ -0,0 +1,54 @@
+/* Spin locks.
+ Copyright (C) 2000, 2004, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <sched.h>
+
+/* The default for single processor machines; don't spin, it's
+ pointless. */
+#ifndef __PTHREAD_SPIN_COUNT
+# define __PTHREAD_SPIN_COUNT 1
+#endif
+
+/* The number of times to spin while trying to lock a spin lock object
+ before yielding the processor. */
+int __pthread_spin_count = __PTHREAD_SPIN_COUNT;
+
+
+/* Lock the spin lock object LOCK. If the lock is held by another
+ thread spin until it becomes available. */
+int
+_pthread_spin_lock (__pthread_spinlock_t *lock)
+{
+ int i;
+
+ while (1)
+ {
+ for (i = 0; i < __pthread_spin_count; i++)
+ {
+ if (__pthread_spin_trylock (lock) == 0)
+ return 0;
+ }
+
+ __sched_yield ();
+ }
+}
+
+weak_alias (_pthread_spin_lock, pthread_spin_lock);
+weak_alias (_pthread_spin_lock, __pthread_spin_lock);
diff --git a/libpthread/sysdeps/powerpc/bits/machine-lock.h b/libpthread/sysdeps/powerpc/bits/machine-lock.h
new file mode 100644
index 00000000..cba6b0a6
--- /dev/null
+++ b/libpthread/sysdeps/powerpc/bits/machine-lock.h
@@ -0,0 +1,78 @@
+/* Machine-specific definition for spin locks. PowerPC version.
+ Copyright (C) 1994,97,2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _MACHINE_LOCK_H
+#define _MACHINE_LOCK_H
+
+/* The type of a spin lock variable. */
+
+typedef __volatile long int __spin_lock_t;
+
+/* Value to initialize `__spin_lock_t' variables to. */
+
+#define __SPIN_LOCK_INITIALIZER 0L
+
+
+#ifndef _EXTERN_INLINE
+#define _EXTERN_INLINE extern __inline
+#endif
+
+/* Unlock LOCK. */
+
+_EXTERN_INLINE void
+__spin_unlock (__spin_lock_t *__lock)
+{
+ long int __locked;
+ __asm__ __volatile__ ("\
+0: lwarx %0,0,%1\n\
+ stwcx. %2,0,%1\n\
+ bne- 0b\n\
+" : "=&r" (__locked) : "r" (__lock), "r" (0) : "cr0");
+}
+
+/* Try to lock LOCK; return nonzero if we locked it, zero if another has. */
+
+_EXTERN_INLINE int
+__spin_try_lock (register __spin_lock_t *__lock)
+{
+ long int __rtn;
+ __asm__ __volatile__ ("\
+0: lwarx %0,0,%1\n\
+ stwcx. %2,0,%1\n\
+ bne- 0b\n\
+" : "=&r" (__rtn) : "r" (__lock), "r" (1) : "cr0");
+ return !__rtn;
+}
+
+/* Return nonzero if LOCK is locked. */
+
+_EXTERN_INLINE int
+__spin_lock_locked (__spin_lock_t *__lock)
+{
+ long int __rtn;
+ __asm__ __volatile__ ("\
+0: lwarx %0,0,%1\n\
+ stwcx. %0,0,%1\n\
+ bne- 0b\n\
+" : "=&r" (__rtn) : "r" (__lock) : "cr0");
+ return __rtn;
+}
+
+
+#endif /* machine-lock.h */
diff --git a/libpthread/sysdeps/powerpc/bits/memory.h b/libpthread/sysdeps/powerpc/bits/memory.h
new file mode 100644
index 00000000..96624c3e
--- /dev/null
+++ b/libpthread/sysdeps/powerpc/bits/memory.h
@@ -0,0 +1,36 @@
+/* Memory barrier operations. PowerPC version.
+ Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#ifndef _BITS_MEMORY_H
+#define _BITS_MEMORY_H 1
+
+/* Prevent read and write reordering across this function. */
+inline void
+__memory_barrier (void)
+{
+ asm ("sync" ::: "memory");
+}
+
+/* Prevent read reordering across this function. */
+#define __memory_read_barrier __memory_barrier
+
+/* Prevent write reordering across this function. */
+#define __memory_write_barrier __memory_barrier
+
+#endif
diff --git a/libpthread/sysdeps/powerpc/bits/spin-lock.h b/libpthread/sysdeps/powerpc/bits/spin-lock.h
new file mode 100644
index 00000000..1dc25710
--- /dev/null
+++ b/libpthread/sysdeps/powerpc/bits/spin-lock.h
@@ -0,0 +1,108 @@
+/* Machine-specific definitions for spin locks. PowerPC version.
+ Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+/*
+ * Never include this file directly; use <pthread.h> or <cthreads.h> instead.
+ */
+
+#ifndef _BITS_SPIN_LOCK_H
+#define _BITS_SPIN_LOCK_H 1
+
+#include <features.h>
+
+__BEGIN_DECLS
+
+/* The type of a spin lock object. */
+typedef __volatile int __pthread_spinlock_t;
+
+/* Initializer for a spin lock object. */
+# define __SPIN_LOCK_INITIALIZER ((__pthread_spinlock_t) 0)
+
+#if defined __USE_EXTERN_INLINES || defined _FORCE_INLINES
+
+# ifndef __EBUSY
+# include <errno.h>
+# define __EBUSY EBUSY
+# endif
+
+# ifndef __PT_SPIN_INLINE
+# define __PT_SPIN_INLINE extern __inline
+# endif
+
+__PT_SPIN_INLINE int __pthread_spin_destroy (__pthread_spinlock_t *__lock);
+
+__PT_SPIN_INLINE int
+__pthread_spin_destroy (__pthread_spinlock_t *__lock)
+{
+ return 0;
+}
+
+__PT_SPIN_INLINE int __pthread_spin_init (__pthread_spinlock_t *__lock,
+ int __pshared);
+
+__PT_SPIN_INLINE int
+__pthread_spin_init (__pthread_spinlock_t *__lock, int __pshared)
+{
+ *__lock = __SPIN_LOCK_INITIALIZER;
+ return 0;
+}
+
+__PT_SPIN_INLINE int __pthread_spin_trylock (__pthread_spinlock_t *__lock);
+
+__PT_SPIN_INLINE int
+__pthread_spin_trylock (__pthread_spinlock_t *__lock)
+{
+ long int __rtn;
+ __asm__ __volatile__ ("\
+0: lwarx %0,0,%1\n\
+ stwcx. %2,0,%1\n\
+ bne- 0b\n\
+" : "=&r" (__rtn) : "r" (__lock), "r" (1) : "cr0");
+ return __rtn ? __EBUSY : 0;
+}
+
+extern inline int __pthread_spin_lock (__pthread_spinlock_t *__lock);
+extern int _pthread_spin_lock (__pthread_spinlock_t *__lock);
+
+extern inline int
+__pthread_spin_lock (__pthread_spinlock_t *__lock)
+{
+ if (__pthread_spin_trylock (__lock))
+ return _pthread_spin_lock (__lock);
+ return 0;
+}
+
+__PT_SPIN_INLINE int __pthread_spin_unlock (__pthread_spinlock_t *__lock);
+
+__PT_SPIN_INLINE int
+__pthread_spin_unlock (__pthread_spinlock_t *__lock)
+{
+ long int __locked;
+ __asm__ __volatile__ ("\
+0: lwarx %0,0,%1\n\
+ stwcx. %2,0,%1\n\
+ bne- 0b\n\
+" : "=&r" (__locked) : "r" (__lock), "r" (0) : "cr0");
+}
+
+#endif /* Use extern inlines or force inlines. */
+
+__END_DECLS
+
+#endif /* bits/spin-lock.h */
diff --git a/libpthread/sysdeps/powerpc/machine-sp.h b/libpthread/sysdeps/powerpc/machine-sp.h
new file mode 100644
index 00000000..aa787c59
--- /dev/null
+++ b/libpthread/sysdeps/powerpc/machine-sp.h
@@ -0,0 +1,31 @@
+/* Machine-specific function to return the stack pointer. i386 version.
+ Copyright (C) 1994,97,2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _MACHINE_SP_H
+#define _MACHINE_SP_H
+
+/* Return the current stack pointer. */
+
+#define __thread_stack_pointer() ({ \
+ void *__sp__; \
+ __asm__ ("mr %0, 1" : "=r" (__sp__)); \
+ __sp__; \
+})
+
+#endif /* machine-sp.h */
diff --git a/libpthread/sysdeps/powerpc/pt-machdep.h b/libpthread/sysdeps/powerpc/pt-machdep.h
new file mode 100644
index 00000000..6d456367
--- /dev/null
+++ b/libpthread/sysdeps/powerpc/pt-machdep.h
@@ -0,0 +1,29 @@
+/* Machine dependent pthreads internal defenitions. i386 version.
+ Copyright (C) 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#ifndef _PT_MACHDEP_H
+#define _PT_MACHDEP_H 1
+
+struct pthread_mcontext
+{
+ void *pc;
+ void *sp;
+};
+
+#endif /* pt-machdep.h */
diff --git a/libpthread/tests/.cvsignore b/libpthread/tests/.cvsignore
new file mode 100644
index 00000000..70845e08
--- /dev/null
+++ b/libpthread/tests/.cvsignore
@@ -0,0 +1 @@
+Makefile.in
diff --git a/libpthread/tests/Makefile b/libpthread/tests/Makefile
new file mode 100644
index 00000000..5ebc01d3
--- /dev/null
+++ b/libpthread/tests/Makefile
@@ -0,0 +1,29 @@
+CFLAGS=-Wall -g
+
+LDLIBS = -lpthread
+
+CHECK_SRC := test-1.c test-2.c test-3.c test-6.c test-7.c test-8.c \
+ test-9.c test-10.c test-11.c test-12.c test-13.c test-14.c \
+ test-15.c test-16.c test-17.c test-__pthread_destroy_specific-skip.c
+
+CHECK_OBJS := $(addsuffix .o,$(basename $(notdir $(CHECK_SRC))))
+CHECK_PROGS := $(basename $(notdir $(CHECK_SRC))) \
+ $(addsuffix -static, $(basename $(CHECK_SRC)))
+
+%-static: %.o
+ $(CC) -static $(CFLAGS) $(LDFLAGS) $< -o $@ $(LDLIBS)
+
+check: $(CHECK_OBJS) $(CHECK_PROGS)
+ for i in $(CHECK_PROGS); do \
+ echo -n Running $$i...\ ; \
+ if ./$$i 2>&1 > $$i.out; \
+ then \
+ echo Success.; \
+ else \
+ echo Failure.; \
+ fi \
+ done
+
+clean:
+ rm -f $(CHECK_OBJS) $(CHECK_PROGS) \
+ $(addsuffix .out,$(basename $(notdir $(CHECK_PROGS)))) \ No newline at end of file
diff --git a/libpthread/tests/test-1.c b/libpthread/tests/test-1.c
new file mode 100644
index 00000000..6ec1afb3
--- /dev/null
+++ b/libpthread/tests/test-1.c
@@ -0,0 +1,50 @@
+#define _GNU_SOURCE
+
+#include <pthread.h>
+#include <assert.h>
+#include <unistd.h>
+#include <error.h>
+#include <errno.h>
+#include <stdio.h>
+
+#define THREADS 500
+
+void *
+foo (void *arg)
+{
+ pthread_mutex_t *mutex = arg;
+ pthread_mutex_lock (mutex);
+ pthread_mutex_unlock (mutex);
+ return mutex;
+}
+
+int
+main (int argc, char **argv)
+{
+ int i;
+ error_t err;
+ pthread_t tid[THREADS];
+ pthread_mutex_t mutex[THREADS];
+
+ for (i = 0; i < THREADS; i ++)
+ {
+ pthread_mutex_init (&mutex[i], 0);
+ pthread_mutex_lock (&mutex[i]);
+ err = pthread_create (&tid[i], 0, foo, &mutex[i]);
+ if (err)
+ error (1, err, "pthread_create");
+ sched_yield ();
+ }
+
+ for (i = THREADS - 1; i >= 0; i --)
+ {
+ void *ret;
+ pthread_mutex_unlock (&mutex[i]);
+ err = pthread_join (tid[i], &ret);
+ if (err)
+ error (1, err, "pthread_join");
+ assert (ret == &mutex[i]);
+ }
+
+ return 0;
+}
diff --git a/libpthread/tests/test-10.c b/libpthread/tests/test-10.c
new file mode 100644
index 00000000..bec05c14
--- /dev/null
+++ b/libpthread/tests/test-10.c
@@ -0,0 +1,46 @@
+/* Test error checking mutexes. */
+
+#define _GNU_SOURCE
+
+#include <pthread.h>
+#include <assert.h>
+#include <error.h>
+#include <errno.h>
+
+int
+main (int argc, char **argv)
+{
+ error_t err;
+ pthread_mutexattr_t mattr;
+ pthread_mutex_t mutex;
+
+ err = pthread_mutexattr_init (&mattr);
+ if (err)
+ error (1, err, "pthread_mutexattr_init");
+
+ err = pthread_mutexattr_settype (&mattr, PTHREAD_MUTEX_ERRORCHECK);
+ if (err)
+ error (1, err, "pthread_mutexattr_settype");
+
+ err = pthread_mutex_init (&mutex, &mattr);
+ if (err)
+ error (1, err, "pthread_mutex_init");
+
+ err = pthread_mutexattr_destroy (&mattr);
+ if (err)
+ error (1, err, "pthread_mutexattr_destroy");
+
+ err = pthread_mutex_lock (&mutex);
+ assert (err == 0);
+
+ err = pthread_mutex_lock (&mutex);
+ assert (err == EDEADLK);
+
+ err = pthread_mutex_unlock (&mutex);
+ assert (err == 0);
+
+ err = pthread_mutex_unlock (&mutex);
+ assert (err == EPERM);
+
+ return 0;
+}
diff --git a/libpthread/tests/test-11.c b/libpthread/tests/test-11.c
new file mode 100644
index 00000000..de779a40
--- /dev/null
+++ b/libpthread/tests/test-11.c
@@ -0,0 +1,143 @@
+/* Test rwlocks. */
+
+#define _GNU_SOURCE
+
+#include <pthread.h>
+#include <assert.h>
+#include <error.h>
+#include <errno.h>
+
+#define THREADS 1
+
+int a;
+int b;
+
+/* Get a read lock and assert that a == b. */
+void *
+test1 (void *arg)
+{
+ error_t err;
+ pthread_rwlock_t *lock = arg;
+ int i;
+
+ for (i = 0; i < 200; i ++)
+ {
+ err = pthread_rwlock_rdlock (lock);
+ assert (err == 0);
+
+ assert (a == b);
+
+ sched_yield ();
+
+ assert (a == b);
+
+ err = pthread_rwlock_unlock (lock);
+ assert (err == 0);
+ }
+
+ return 0;
+}
+
+int
+main (int argc, char **argv)
+{
+ error_t err;
+ pthread_rwlockattr_t attr;
+ pthread_rwlock_t lock;
+ int pshared;
+
+ int i;
+ pthread_t tid[THREADS];
+ void *ret;
+
+ err = pthread_rwlockattr_init (&attr);
+ if (err)
+ error (1, err, "pthread_rwlockattr_init");
+
+ err = pthread_rwlockattr_getpshared (&attr, &pshared);
+ if (err)
+ error (1, err, "pthread_rwlockattr_getpshared");
+
+ /* Assert the default state as mandated by POSIX. */
+ assert (pshared == PTHREAD_PROCESS_PRIVATE);
+
+ err = pthread_rwlockattr_setpshared (&attr, pshared);
+ if (err)
+ error (1, err, "pthread_rwlockattr_setpshared");
+
+ err = pthread_rwlock_init (&lock, &attr);
+ if (err)
+ error (1, err, "pthread_rwlock_init");
+
+ err = pthread_rwlockattr_destroy (&attr);
+ if (err)
+ error (1, err, "pthread_rwlockattr_destroy");
+
+ /* Now test the lock. */
+
+ for (i = 0; i < THREADS; i ++)
+ {
+ err = pthread_create (&tid[i], 0, test1, &lock);
+ if (err)
+ error (1, err, "pthread_create");
+ }
+
+ for (i = 0; i < 10; i ++)
+ {
+ sched_yield ();
+
+ /* Get a write lock. */
+ pthread_rwlock_wrlock (&lock);
+ /* Increment a and b giving other threads a chance to run in
+ between. */
+ sched_yield ();
+ a ++;
+ sched_yield ();
+ b ++;
+ sched_yield ();
+ /* Unlock. */
+ pthread_rwlock_unlock (&lock);
+ }
+
+ for (i = 0; i < THREADS; i ++)
+ {
+ err = pthread_join (tid[i], &ret);
+ if (err)
+ error (1, err, "pthread_join");
+ }
+
+ /* Read lock it. */
+ err = pthread_rwlock_tryrdlock (&lock);
+ assert (err == 0);
+
+ /* Try to write lock it. It should fail with EBUSY. */
+ err = pthread_rwlock_trywrlock (&lock);
+ assert (err == EBUSY);
+
+ /* Drop the read lock. */
+ err = pthread_rwlock_unlock (&lock);
+ assert (err == 0);
+
+ /* Get a write lock. */
+ err = pthread_rwlock_trywrlock (&lock);
+ assert (err == 0);
+
+ /* Fail trying to acquire another write lock. */
+ err = pthread_rwlock_trywrlock (&lock);
+ assert (err == EBUSY);
+
+ /* Try to get a read lock which should also fail. */
+ err = pthread_rwlock_tryrdlock (&lock);
+ assert (err == EBUSY);
+
+ /* Unlock it. */
+ err = pthread_rwlock_unlock (&lock);
+ assert (err == 0);
+
+
+ err = pthread_rwlock_destroy (&lock);
+ if (err)
+ error (1, err, "pthread_rwlock_destroy");
+
+ return 0;
+}
diff --git a/libpthread/tests/test-12.c b/libpthread/tests/test-12.c
new file mode 100644
index 00000000..2b784908
--- /dev/null
+++ b/libpthread/tests/test-12.c
@@ -0,0 +1,29 @@
+/* Test concurrency level. */
+
+#define _GNU_SOURCE
+
+#include <pthread.h>
+#include <assert.h>
+#include <error.h>
+#include <errno.h>
+
+int
+main (int argc, char **argv)
+{
+ int i;
+ int err;
+
+ i = pthread_getconcurrency ();
+ assert (i == 0);
+
+ err = pthread_setconcurrency (-1);
+ assert (err == EINVAL);
+
+ err = pthread_setconcurrency (4);
+ assert (err == 0);
+
+ i = pthread_getconcurrency ();
+ assert (i == 4);
+
+ return 0;
+}
diff --git a/libpthread/tests/test-13.c b/libpthread/tests/test-13.c
new file mode 100644
index 00000000..13b09051
--- /dev/null
+++ b/libpthread/tests/test-13.c
@@ -0,0 +1,66 @@
+/* Test condition attributes and pthread_cond_timedwait. */
+
+#define _GNU_SOURCE
+
+#include <pthread.h>
+#include <stdio.h>
+#include <assert.h>
+#include <error.h>
+#include <errno.h>
+#include <sys/time.h>
+
+int
+main (int argc, char **argv)
+{
+ error_t err;
+ int i;
+ pthread_condattr_t attr;
+ pthread_cond_t cond;
+ struct timespec ts;
+ pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
+ struct timeval before, after;
+ int diff;
+
+ err = pthread_condattr_init (&attr);
+ if (err)
+ error (1, err, "pthread_condattr_init");
+
+ err = pthread_condattr_getpshared (&attr, &i);
+ if (err)
+ error (1, err, "pthread_condattr_getpshared");
+ assert (i == PTHREAD_PROCESS_PRIVATE);
+
+ err = pthread_condattr_setpshared (&attr, PTHREAD_PROCESS_PRIVATE);
+ assert (err == 0);
+
+ err = pthread_cond_init (&cond, &attr);
+ if (err)
+ error (1, err, "pthread_cond_init");
+
+ err = pthread_condattr_destroy (&attr);
+ if (err)
+ error (1, err, "pthread_condattr_destroy");
+
+ gettimeofday (&before, 0);
+ ts.tv_sec = before.tv_sec + 1;
+ ts.tv_nsec = before.tv_usec * 1000;
+
+ printf ("Starting wait @ %d\n", (int) before.tv_sec);
+
+ pthread_mutex_lock (&m);
+ err = pthread_cond_timedwait (&cond, &m, &ts);
+
+ gettimeofday (&after, 0);
+
+ printf ("End wait @ %d (err = %d)\n", (int) after.tv_sec, err);
+
+ assert (err == ETIMEDOUT);
+
+ diff = after.tv_sec * 1000000 + after.tv_usec
+ - before.tv_sec * 1000000 - before.tv_usec;
+
+ if (diff < 900000 || diff > 1100000)
+ error (1, EGRATUITOUS, "pthread_cond_timedwait waited %d us", diff);
+
+ return 0;
+}
diff --git a/libpthread/tests/test-14.c b/libpthread/tests/test-14.c
new file mode 100644
index 00000000..b1dbfa66
--- /dev/null
+++ b/libpthread/tests/test-14.c
@@ -0,0 +1,44 @@
+/* Test pthread_mutex_timedlock. */
+
+#define _GNU_SOURCE
+
+#include <pthread.h>
+#include <stdio.h>
+#include <assert.h>
+#include <error.h>
+#include <errno.h>
+#include <sys/time.h>
+
+int
+main (int argc, char **argv)
+{
+ error_t err;
+ struct timespec ts;
+ pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
+ struct timeval before, after;
+ int diff;
+
+ gettimeofday (&before, 0);
+ ts.tv_sec = before.tv_sec + 1;
+ ts.tv_nsec = before.tv_usec * 1000;
+
+ printf ("Starting wait @ %d\n", (int) before.tv_sec);
+
+ pthread_mutex_lock (&m);
+ /* A default mutex shall dead lock if locked twice. As such we do
+ not need spawn a second thread. */
+ err = pthread_mutex_timedlock (&m, &ts);
+ assert (err == ETIMEDOUT);
+
+ gettimeofday (&after, 0);
+
+ printf ("End wait @ %d\n", (int) after.tv_sec);
+
+ diff = after.tv_sec * 1000000 + after.tv_usec
+ - before.tv_sec * 1000000 - before.tv_usec;
+
+ if (diff < 900000 || diff > 1100000)
+ error (1, EGRATUITOUS, "pthread_mutex_timedlock waited %d us", diff);
+
+ return 0;
+}
diff --git a/libpthread/tests/test-15.c b/libpthread/tests/test-15.c
new file mode 100644
index 00000000..173f8b6b
--- /dev/null
+++ b/libpthread/tests/test-15.c
@@ -0,0 +1,87 @@
+/* Test pthread_rwlock_timedrdlock and pthread_rwlock_timedwrlock. */
+
+#define _GNU_SOURCE
+
+#include <pthread.h>
+#include <stdio.h>
+#include <assert.h>
+#include <error.h>
+#include <errno.h>
+#include <sys/time.h>
+
+#define THREADS 10
+
+pthread_rwlock_t rwlock;
+
+void *
+test (void *arg)
+{
+ error_t err;
+ int foo = (int) arg;
+ struct timespec ts;
+ struct timeval before, after;
+ int diff;
+
+ gettimeofday (&before, 0);
+ ts.tv_sec = before.tv_sec + 1;
+ ts.tv_nsec = before.tv_usec * 1000;
+
+ printf ("Thread %d starting wait @ %d\n", pthread_self (),
+ (int) before.tv_sec);
+
+ if (foo % 2 == 0)
+ err = pthread_rwlock_timedrdlock (&rwlock, &ts);
+ else
+ err = pthread_rwlock_timedwrlock (&rwlock, &ts);
+
+ assert (err == ETIMEDOUT);
+
+ gettimeofday (&after, 0);
+
+ printf ("Thread %d ending wait @ %d\n", pthread_self (),
+ (int) after.tv_sec);
+
+ diff = after.tv_sec * 1000000 + after.tv_usec
+ - before.tv_sec * 1000000 - before.tv_usec;
+
+ if (diff < 900000 || diff > 1100000)
+ error (1, EGRATUITOUS, "pthread_mutex_timedlock waited %d us", diff);
+
+ return 0;
+}
+
+int
+main (int argc, char **argv)
+{
+ error_t err;
+ int i;
+ pthread_t tid[THREADS];
+
+ err = pthread_rwlock_init (&rwlock, 0);
+ if (err)
+ error (1, err, "pthread_rwlock_init");
+
+ /* Lock it so all the threads will block. */
+ err = pthread_rwlock_wrlock (&rwlock);
+ assert (err == 0);
+
+ for (i = 0; i < THREADS; i ++)
+ {
+ err = pthread_create (&tid[i], 0, test, (void *) i);
+ if (err)
+ error (1, err, "pthread_create");
+ }
+
+ for (i = 0; i < THREADS; i ++)
+ {
+ void *ret;
+
+ err = pthread_join (tid[i], &ret);
+ if (err)
+ error (1, err, "pthread_join");
+
+ assert (ret == 0);
+ }
+
+ return 0;
+}
diff --git a/libpthread/tests/test-16.c b/libpthread/tests/test-16.c
new file mode 100644
index 00000000..3660f5f7
--- /dev/null
+++ b/libpthread/tests/test-16.c
@@ -0,0 +1,71 @@
+/* Test pthread_kill.c. */
+
+#define _GNU_SOURCE
+
+#include <pthread.h>
+#include <signal.h>
+#include <stdio.h>
+#include <assert.h>
+#include <error.h>
+#include <errno.h>
+#include <hurd/signal.h>
+
+pthread_t testthread;
+
+int i;
+
+void *
+test (void *arg)
+{
+ error_t err;
+
+ printf ("test: %d\n", pthread_self ());
+
+ err = pthread_kill (pthread_self (), SIGINFO);
+ if (err)
+ error (1, err, "pthread_kill");
+
+ /* To avoid using condition variables in a signal handler. */
+ while (i == 0)
+ sched_yield ();
+
+ return 0;
+}
+
+static void
+handler (int sig)
+{
+ assert (pthread_equal (pthread_self (), testthread));
+ printf ("handler: %d\n", pthread_self ());
+ i = 1;
+}
+
+int
+main (int argc, char **argv)
+{
+ error_t err;
+ struct sigaction sa;
+ void *ret;
+
+ printf ("main: %d\n", pthread_self ());
+
+ sa.sa_handler = handler;
+ sa.sa_mask = 0;
+ sa.sa_flags = 0;
+
+ err = sigaction (SIGINFO, &sa, 0);
+ if (err)
+ error (1, err, "sigaction");
+
+ err = pthread_create (&testthread, 0, test, 0);
+ if (err)
+ error (1, err, "pthread_create");
+
+ err = pthread_join (testthread, &ret);
+ if (err)
+ error (1, err, "pthread_join");
+
+ assert (ret == 0);
+
+ return 0;
+}
diff --git a/libpthread/tests/test-2.c b/libpthread/tests/test-2.c
new file mode 100644
index 00000000..701462e8
--- /dev/null
+++ b/libpthread/tests/test-2.c
@@ -0,0 +1,39 @@
+/* Test detachability. */
+#define _GNU_SOURCE
+
+#include <pthread.h>
+#include <assert.h>
+#include <error.h>
+#include <errno.h>
+#include <unistd.h>
+
+void *
+thread (void *arg)
+{
+ while (1)
+ sched_yield ();
+}
+
+int
+main (int argc, char **argv)
+{
+ int err;
+ pthread_t tid;
+ void *ret;
+
+ err = pthread_create (&tid, 0, thread, 0);
+ if (err)
+ error (1, err, "pthread_create");
+
+ err = pthread_detach (tid);
+ if (err)
+ error (1, err, "pthread_detach");
+
+ err = pthread_detach (tid);
+ assert (err == EINVAL);
+
+ err = pthread_join (tid, &ret);
+ assert (err == EINVAL);
+
+ return 0;
+}
diff --git a/libpthread/tests/test-3.c b/libpthread/tests/test-3.c
new file mode 100644
index 00000000..7db2e43f
--- /dev/null
+++ b/libpthread/tests/test-3.c
@@ -0,0 +1,55 @@
+/* Test the thread attribute get and set methods. */
+
+#define _GNU_SOURCE
+
+#include <pthread.h>
+#include <sched.h>
+#include <assert.h>
+#include <errno.h>
+
+int
+main (int argc, char *argv[])
+{
+ error_t err;
+ pthread_attr_t attr;
+
+ int i;
+ struct sched_param sp;
+ void *p;
+ size_t sz;
+
+ err = pthread_attr_init (&attr);
+ assert_perror (err);
+
+ err = pthread_attr_destroy (&attr);
+ assert_perror (err);
+
+ err = pthread_attr_init (&attr);
+ assert_perror (err);
+
+#define TEST1(foo, rv, v) \
+ err = pthread_attr_get##foo (&attr, rv); \
+ assert_perror (err); \
+ \
+ err = pthread_attr_set##foo (&attr, v); \
+ assert_perror (err);
+
+#define TEST(foo, rv, v) TEST1(foo, rv, v)
+
+ TEST(inheritsched, &i, i);
+ TEST(schedparam, &sp, &sp);
+ TEST(schedpolicy, &i, i);
+ TEST(scope, &i, i);
+ TEST(stackaddr, &p, p);
+ TEST(detachstate, &i, i);
+ TEST(guardsize, &sz, sz);
+ TEST(stacksize, &sz, sz);
+
+ err = pthread_attr_getstack (&attr, &p, &sz);
+ assert_perror (err);
+
+ err = pthread_attr_setstack (&attr, p, sz);
+ assert_perror (err);
+
+ return 0;
+}
diff --git a/libpthread/tests/test-4.c b/libpthread/tests/test-4.c
new file mode 100644
index 00000000..de9c8fe4
--- /dev/null
+++ b/libpthread/tests/test-4.c
@@ -0,0 +1,86 @@
+/* Test the stack guard. */
+
+#define _GNU_SOURCE
+
+#include <pthread.h>
+#include <assert.h>
+#include <unistd.h>
+#include <errno.h>
+#include <string.h>
+#include <stdio.h>
+
+size_t stacksize;
+
+void *
+thr (void *arg)
+{
+ int i;
+ char *foo;
+
+ foo = alloca (3 * stacksize / 4);
+ for (i = 0; i < sizeof foo; i ++)
+ foo[i] = -1;
+
+ return (void *) 1;
+}
+
+int
+main (int argc, char *argv[])
+{
+ error_t err;
+ pid_t child;
+
+ child = fork ();
+ switch (child)
+ {
+ case -1:
+ error (1, errno, "fork");
+ break;
+
+ case 0:
+ {
+ pthread_attr_t attr;
+ pthread_t tid;
+ void *ret;
+
+ err = pthread_attr_init (&attr);
+ assert_perror (err);
+
+ err = pthread_attr_getstacksize (&attr, &stacksize);
+ assert_perror (err);
+
+ err = pthread_attr_setguardsize (&attr, stacksize / 2);
+ if (err == ENOTSUP)
+ {
+ printf ("Stack guard attribute not supported.\n");
+ return 1;
+ }
+ assert_perror (err);
+
+ err = pthread_create (&tid, &attr, thr, 0);
+ assert_perror (err);
+
+ err = pthread_attr_destroy (&attr);
+ assert_perror (err);
+
+ err = pthread_join (tid, &ret);
+ /* Should never be successful. */
+ printf ("Thread did not segfault!?!\n");
+ assert_perror (err);
+ return 0;
+ }
+
+ default:
+ {
+ pid_t pid;
+ int status;
+
+ pid = waitpid (child, &status, 0);
+ printf ("pid = %d; child = %d; status = %d\n", pid, child, status);
+ assert (pid == child);
+ assert (status != 0);
+ }
+ }
+
+ return 0;
+}
diff --git a/libpthread/tests/test-5.c b/libpthread/tests/test-5.c
new file mode 100644
index 00000000..0f5000b2
--- /dev/null
+++ b/libpthread/tests/test-5.c
@@ -0,0 +1,75 @@
+/* Test signals. */
+
+#define _GNU_SOURCE
+
+#include <pthread.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <errno.h>
+#include <error.h>
+#include <assert.h>
+#include <sys/resource.h>
+#include <sys/wait.h>
+
+void *
+thr (void *arg)
+{
+ * (int *)0 = 0;
+ return 0;
+}
+
+int foobar;
+
+int
+main (int argc, char *argv[])
+{
+ error_t err;
+ pid_t child;
+
+ struct rlimit limit;
+
+ limit.rlim_cur = 0;
+ limit.rlim_max = 0;
+
+ err = setrlimit (RLIMIT_CORE, &limit);
+ if (err)
+ error (1, err, "setrlimit");
+
+ child = fork ();
+ switch (child)
+ {
+ case -1:
+ error (1, errno, "fork");
+ break;
+
+ case 0:
+ {
+ pthread_t tid;
+ void *ret;
+
+ err = pthread_create (&tid, 0, thr, 0);
+ if (err)
+ error (1, err, "pthread_create");
+
+ err = pthread_join (tid, &ret);
+ assert_perror (err);
+
+ /* Should have never returned. Our parent expects us to fail
+ thus we succeed and indicate the error. */
+ return 0;
+ }
+
+ default:
+ {
+ pid_t pid;
+ int status;
+
+ pid = waitpid (child, &status, 0);
+ printf ("pid = %d; child = %d; status = %d\n", pid, child, status);
+ assert (pid == child);
+ assert (status != 0);
+ }
+ }
+
+ return 0;
+}
diff --git a/libpthread/tests/test-6.c b/libpthread/tests/test-6.c
new file mode 100644
index 00000000..edf2919e
--- /dev/null
+++ b/libpthread/tests/test-6.c
@@ -0,0 +1,96 @@
+#define _GNU_SOURCE
+
+#include <pthread.h>
+#include <stdio.h>
+#include <error.h>
+#include <assert.h>
+#include <errno.h>
+
+#define THREADS 500
+#define WAITS 3
+
+void *
+dowait (void *arg)
+{
+ pthread_barrier_t *barrier = arg;
+ int ret;
+
+ ret = pthread_barrier_wait (barrier);
+ printf ("%d ", pthread_self ());
+ return (void *) ret;
+}
+
+int
+main (int argc, char **argv)
+{
+ pthread_barrierattr_t attr;
+ pthread_barrier_t barrier;
+
+ int i, j;
+ error_t err;
+ pthread_t tid[THREADS];
+
+ int havesyncs;
+
+ err = pthread_barrierattr_init (&attr);
+ if (err)
+ error (1, err, "pthread_barrierattr_init");
+
+ err = pthread_barrierattr_getpshared (&attr, &i);
+ if (err)
+ error (1, err, "pthread_barrierattr_getpshared");
+ assert (i == PTHREAD_PROCESS_PRIVATE || i == PTHREAD_PROCESS_SHARED);
+
+ err = pthread_barrierattr_setpshared (&attr, PTHREAD_PROCESS_PRIVATE);
+ if (err)
+ error (1, err, "pthread_barrierattr_setpshared");
+
+ err = pthread_barrier_init (&barrier, &attr, THREADS + 1);
+ if (err)
+ error (1, err, "pthread_barrier_init");
+
+ for (j = 0; j < WAITS; j ++)
+ {
+
+ for (i = 0; i < THREADS; i ++)
+ {
+ err = pthread_create (&tid[i], 0, dowait, &barrier);
+ if (err)
+ error (1, err, "pthread_create (%d)", i);
+ }
+
+ printf ("Manager will now call pthread_barrier_wait.\n");
+
+ havesyncs
+ = pthread_barrier_wait (&barrier) == PTHREAD_BARRIER_SERIAL_THREAD
+ ? 1 : 0;
+
+ for (i = THREADS - 1; i >= 0; i --)
+ {
+ void *ret;
+ err = pthread_join (tid[i], &ret);
+ if (err)
+ error (1, err, "pthread_join");
+
+ switch ((int) ret)
+ {
+ case 0:
+ break;
+
+ case PTHREAD_BARRIER_SERIAL_THREAD:
+ havesyncs ++;
+ break;
+
+ default:
+ assert (! "Unknown value returned from pthread_barrier_wait.");
+ break;
+ }
+ }
+
+ printf ("\n");
+
+ assert (havesyncs == 1);
+ }
+
+ return 0;
+}
diff --git a/libpthread/tests/test-7.c b/libpthread/tests/test-7.c
new file mode 100644
index 00000000..22fb1caa
--- /dev/null
+++ b/libpthread/tests/test-7.c
@@ -0,0 +1,70 @@
+#define _GNU_SOURCE
+
+#include <pthread.h>
+#include <assert.h>
+#include <stdio.h>
+#include <error.h>
+#include <errno.h>
+
+#define THREADS 10
+#define KEYS 400
+
+pthread_key_t key[KEYS];
+
+void *
+thr (void *arg)
+{
+ error_t err;
+ int i;
+
+ for (i = 0; i < KEYS; i ++)
+ {
+ printf ("pthread_getspecific(%d).\n", key[i]);
+ assert (pthread_getspecific (key[i]) == NULL);
+ printf ("pthread_setspecific(%d, %d).\n", key[i], pthread_self ());
+ err = pthread_setspecific (key[i], (void *) pthread_self ());
+ printf ("pthread_setspecific(%d, %d) => %d.\n", key[i], pthread_self (), err);
+ assert_perror (err);
+ }
+
+ return 0;
+}
+
+int
+main (int argc, char **argv)
+{
+ error_t err;
+ int i;
+ pthread_t tid[THREADS];
+
+ void des (void *val)
+ {
+ assert ((pthread_t) val == pthread_self ());
+ }
+
+ assert (pthread_getspecific ((pthread_key_t) 0) == NULL);
+ assert (pthread_setspecific ((pthread_key_t) 0, (void *) 0x1) == EINVAL);
+
+ for (i = 0; i < KEYS; i ++)
+ err = pthread_key_create (&key[i], des);
+
+ for (i = 0; i < THREADS; i ++)
+ {
+ err = pthread_create (&tid[i], 0, thr, 0);
+ if (err)
+ error (1, err, "pthread_create (%d)", i);
+ }
+
+ for (i = 0; i < THREADS; i ++)
+ {
+ void *ret;
+
+ err = pthread_join (tid[i], &ret);
+ if (err)
+ error (1, err, "pthread_join");
+
+ assert (ret == 0);
+ }
+
+ return 0;
+}
diff --git a/libpthread/tests/test-8.c b/libpthread/tests/test-8.c
new file mode 100644
index 00000000..85a7f8f6
--- /dev/null
+++ b/libpthread/tests/test-8.c
@@ -0,0 +1,60 @@
+#define _GNU_SOURCE
+
+#include <pthread.h>
+#include <assert.h>
+#include <error.h>
+#include <errno.h>
+
+#define THREADS 10
+
+pthread_once_t inc_var_once = PTHREAD_ONCE_INIT;
+int var;
+
+void
+inc_var (void)
+{
+ var ++;
+}
+
+void *
+thr (void *arg)
+{
+ int i;
+
+ for (i = 0; i < 500; i ++)
+ pthread_once (&inc_var_once, inc_var);
+
+ return 0;
+}
+
+int
+main (int argc, char **argv)
+{
+ error_t err;
+ int i;
+ pthread_t tid[THREADS];
+
+ for (i = 0; i < THREADS; i ++)
+ {
+ err = pthread_create (&tid[i], 0, thr, 0);
+ if (err)
+ error (1, err, "pthread_create (%d)", i);
+ }
+
+ assert (thr (0) == 0);
+
+ for (i = 0; i < THREADS; i ++)
+ {
+ void *ret;
+
+ err = pthread_join (tid[i], &ret);
+ if (err)
+ error (1, err, "pthread_join");
+
+ assert (ret == 0);
+ }
+
+ assert (var == 1);
+
+ return 0;
+}
diff --git a/libpthread/tests/test-9.c b/libpthread/tests/test-9.c
new file mode 100644
index 00000000..82051570
--- /dev/null
+++ b/libpthread/tests/test-9.c
@@ -0,0 +1,88 @@
+/* Test recursive mutexes. */
+
+#define _GNU_SOURCE
+
+#include <pthread.h>
+#include <assert.h>
+#include <error.h>
+#include <errno.h>
+
+#define THREADS 10
+
+int foo;
+
+void *
+thr (void *arg)
+{
+ int i;
+
+ pthread_mutex_lock (arg);
+
+ foo = pthread_self ();
+
+ for (i = 0; i < 500; i ++)
+ pthread_mutex_lock (arg);
+ for (i = 0; i < 500; i ++)
+ pthread_mutex_unlock (arg);
+
+ assert (foo == pthread_self ());
+
+ pthread_mutex_unlock (arg);
+
+ return 0;
+}
+
+int
+main (int argc, char **argv)
+{
+ error_t err;
+ int i;
+ pthread_t tid[THREADS];
+ pthread_mutexattr_t mattr;
+ pthread_mutex_t mutex;
+
+ err = pthread_mutexattr_init (&mattr);
+ if (err)
+ error (1, err, "pthread_mutexattr_init");
+
+ err = pthread_mutexattr_settype (&mattr, PTHREAD_MUTEX_RECURSIVE);
+ if (err)
+ error (1, err, "pthread_mutexattr_settype");
+
+ err = pthread_mutex_init (&mutex, &mattr);
+ if (err)
+ error (1, err, "pthread_mutex_init");
+
+ err = pthread_mutexattr_destroy (&mattr);
+ if (err)
+ error (1, err, "pthread_mutexattr_destroy");
+
+ pthread_mutex_lock (&mutex);
+ pthread_mutex_lock (&mutex);
+ pthread_mutex_unlock (&mutex);
+ pthread_mutex_unlock (&mutex);
+
+ for (i = 0; i < THREADS; i ++)
+ {
+ err = pthread_create (&tid[i], 0, thr, &mutex);
+ if (err)
+ error (1, err, "pthread_create (%d)", i);
+ }
+
+ for (i = 0; i < THREADS; i ++)
+ {
+ void *ret;
+
+ err = pthread_join (tid[i], &ret);
+ if (err)
+ error (1, err, "pthread_join");
+
+ assert (ret == 0);
+ }
+
+ err = pthread_mutex_destroy (&mutex);
+ if (err)
+ error (1, err, "pthread_mutex_destroy");
+
+ return 0;
+}
diff --git a/procfs/Makefile b/procfs/Makefile
new file mode 100644
index 00000000..a397522f
--- /dev/null
+++ b/procfs/Makefile
@@ -0,0 +1,26 @@
+TARGET = procfs
+OBJS = procfs.o netfs.o procfs_dir.o \
+ process.o proclist.o rootdir.o dircat.o main.o
+LIBS = -lnetfs -lps
+
+CC = gcc
+CFLAGS = -Wall -g
+CPPFLAGS =
+LDFLAGS =
+
+ifdef PROFILE
+CFLAGS= -g -pg
+CPPFLAGS= -DPROFILE
+LDFLAGS= -static
+LIBS= -lnetfs -lfshelp -liohelp -lps -lports -lthreads -lihash -lshouldbeinlibc
+endif
+
+CPPFLAGS += -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64
+
+all: $(TARGET)
+
+$(TARGET): $(OBJS)
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
+
+clean:
+ $(RM) $(TARGET) $(OBJS)
diff --git a/procfs/TODO b/procfs/TODO
new file mode 100644
index 00000000..952d67bc
--- /dev/null
+++ b/procfs/TODO
@@ -0,0 +1,24 @@
+Known bugs to be fixed
+----------------------
+
+* The non-owned processes sometimes show up with INT_MAX as their owner,
+ instead of opt_anon_uid. This is likely to be a libps problem.
+
+Improvements and new features
+-----------------------------
+
+* There is a lot of dynamic memory allocation going on and it comes with a
+ cost in performance. We could try to limit such allocation, as long as it
+ keeps the inner interface simple and preserves the read/readdir semantics
+ (performance is probably not critical for a proc filesystem.)
+ One way would be to add an (optional) "needed_length" field to
+ procfs_node_ops, and arrange to pass a sufficent buffer in (*contents,
+ *contents_len) when get_contents is called. Then the user-provided buffer
+ might be used directly under some circumstances.
+
+* Add thread directories as [pid]/task/[n]. This shouldn't be too hard if we
+ use "process" nodes for threads, and provide an "exists" hook for the "task"
+ entry itself so that it's disabled in thread nodes. It might prove necessary
+ to have "optional" libps flags for some content generators, though, since
+ some of them might be missing for threads.
+
diff --git a/procfs/dircat.c b/procfs/dircat.c
new file mode 100644
index 00000000..5a60899a
--- /dev/null
+++ b/procfs/dircat.c
@@ -0,0 +1,128 @@
+/* Hurd /proc filesystem, concatenation of two directories.
+ Copyright (C) 2010 Free Software Foundation, Inc.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#include <stdlib.h>
+#include <string.h>
+#include "procfs.h"
+
+struct dircat_node
+{
+ int num_dirs;
+ struct node *dirs[0];
+};
+
+static error_t
+dircat_get_contents (void *hook, char **contents, ssize_t *contents_len)
+{
+ struct dircat_node *dcn = hook;
+ int i, sz, pos;
+ error_t err;
+
+ pos = 0;
+ *contents = malloc (sz = 512);
+
+ for (i=0; i < dcn->num_dirs; i++)
+ {
+ char *subcon;
+ ssize_t sublen;
+
+ /* Make sure we're not getting some old stuff. */
+ procfs_refresh (dcn->dirs[i]);
+
+ err = procfs_get_contents (dcn->dirs[i], &subcon, &sublen);
+ if (err)
+ {
+ free (*contents);
+ *contents = NULL;
+ return err;
+ }
+
+ while (pos + sublen > sz)
+ *contents = realloc (*contents, sz *= 2);
+
+ memcpy (*contents + pos, subcon, sublen);
+ pos += sublen;
+ }
+
+ *contents_len = pos;
+ return 0;
+}
+
+static error_t
+dircat_lookup (void *hook, const char *name, struct node **np)
+{
+ struct dircat_node *dcn = hook;
+ error_t err;
+ int i;
+
+ err = ENOENT;
+ for (i=0; err && i < dcn->num_dirs; i++)
+ err = procfs_lookup (dcn->dirs[i], name, np);
+
+ return err;
+}
+
+static void
+dircat_release_dirs (struct node *const *dirs, int num_dirs)
+{
+ int i;
+
+ for (i=0; i < num_dirs; i++)
+ if (dirs[i])
+ netfs_nrele (dirs[i]);
+}
+
+static void
+dircat_cleanup (void *hook)
+{
+ struct dircat_node *dcn = hook;
+
+ dircat_release_dirs (dcn->dirs, dcn->num_dirs);
+ free (dcn);
+}
+
+struct node *
+dircat_make_node (struct node *const *dirs, int num_dirs)
+{
+ static struct procfs_node_ops ops = {
+ .get_contents = dircat_get_contents,
+ .cleanup_contents = procfs_cleanup_contents_with_free,
+ .lookup = dircat_lookup,
+ .cleanup = dircat_cleanup,
+ };
+ struct dircat_node *dcn;
+ int i;
+
+ for (i=0; i < num_dirs; i++)
+ if (! dirs[i])
+ goto fail;
+
+ dcn = malloc (sizeof *dcn + num_dirs * sizeof dcn->dirs[0]);
+ if (! dcn)
+ goto fail;
+
+ dcn->num_dirs = num_dirs;
+ memcpy (dcn->dirs, dirs, num_dirs * sizeof dcn->dirs[0]);
+ return procfs_make_node (&ops, dcn);
+
+fail:
+ dircat_release_dirs (dirs, num_dirs);
+ return NULL;
+}
+
diff --git a/procfs/dircat.h b/procfs/dircat.h
new file mode 100644
index 00000000..4177b384
--- /dev/null
+++ b/procfs/dircat.h
@@ -0,0 +1,29 @@
+/* Hurd /proc filesystem, concatenation of two directories.
+ Copyright (C) 2010 Free Software Foundation, Inc.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+/* Append the contents of NUM_DIRS directories. DIRS is an array of
+ directory nodes. One reference is consumed for each of them. If a
+ memory allocation error occurs, or if one of the directories is a
+ NULL pointer, the references are dropped immediately and NULL is
+ returned. The given DIRS array is duplicated and can therefore be
+ allocated on the caller's stack. Strange things will happen if some
+ elements of DIRS have entries with the same name or if one of them is
+ not a directory. */
+struct node *
+dircat_make_node (struct node *const *dirs, int num_dirs);
diff --git a/procfs/main.c b/procfs/main.c
new file mode 100644
index 00000000..3a976ccc
--- /dev/null
+++ b/procfs/main.c
@@ -0,0 +1,190 @@
+/* Hurd /proc filesystem, main program.
+ Copyright (C) 2010 Free Software Foundation, Inc.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#include <mach.h>
+#include <hurd.h>
+#include <unistd.h>
+#include <error.h>
+#include <argp.h>
+#include <hurd/netfs.h>
+#include <ps.h>
+#include "procfs.h"
+#include "proclist.h"
+#include "rootdir.h"
+#include "dircat.h"
+#include "main.h"
+
+/* Command-line options */
+int opt_clk_tck;
+mode_t opt_stat_mode;
+pid_t opt_fake_self;
+pid_t opt_kernel_pid;
+uid_t opt_anon_owner;
+
+static error_t
+argp_parser (int key, char *arg, struct argp_state *state)
+{
+ struct passwd *pw;
+ char *endp;
+
+ switch (key)
+ {
+ case 'h':
+ opt_clk_tck = strtol (arg, &endp, 0);
+ if (*endp || ! *arg || opt_clk_tck <= 0)
+ error (1, 0, "--clk-tck: HZ should be a positive integer");
+ break;
+
+ case 's':
+ opt_stat_mode = strtol (arg, &endp, 8);
+ if (*endp || ! *arg || opt_stat_mode & ~07777)
+ error (1, 0, "--stat-mode: MODE should be an octal mode");
+ break;
+
+ case 'S':
+ if (arg)
+ {
+ opt_fake_self = strtol (arg, &endp, 0);
+ if (*endp || ! *arg)
+ error (1, 0, "--fake-self: PID must be an integer");
+ }
+ else
+ opt_fake_self = 1;
+ break;
+
+ case 'k':
+ opt_kernel_pid = strtol (arg, &endp, 0);
+ if (*endp || ! *arg || (signed) opt_kernel_pid < 0)
+ error (1, 0, "--kernel-process: PID must be a positive integer");
+ break;
+
+ case 'c':
+ opt_clk_tck = 100;
+ opt_stat_mode = 0444;
+ opt_fake_self = 1;
+ break;
+
+ case 'a':
+ pw = getpwnam (arg);
+ if (pw)
+ {
+ opt_anon_owner = pw->pw_uid;
+ break;
+ }
+
+ opt_anon_owner = strtol (arg, &endp, 0);
+ if (*endp || ! *arg || (signed) opt_anon_owner < 0)
+ error(1, 0, "--anonymous-owner: USER should be the a user name "
+ "or a numeric UID.");
+ break;
+ }
+
+ return 0;
+}
+
+struct argp argp = {
+ .options = (struct argp_option []) {
+ { "clk-tck", 'h', "HZ", 0,
+ "Unit used for the values expressed in system clock ticks "
+ "(default: sysconf(_SC_CLK_TCK))" },
+ { "stat-mode", 's', "MODE", 0,
+ "The [pid]/stat file publishes information which on Hurd is only "
+ "available to the process owner. "
+ "You can use this option to override its mode to be more permissive "
+ "for compatibility purposes. "
+ "(default: 0400)" },
+ { "fake-self", 'S', "PID", OPTION_ARG_OPTIONAL,
+ "Provide a fake \"self\" symlink to the given PID, for compatibility "
+ "purposes. If PID is omitted, \"self\" will point to init. "
+ "(default: no self link)" },
+ { "kernel-process", 'k', "PID", 0,
+ "Process identifier for the kernel, used to retreive its command "
+ "line, as well as the global up and idle times. "
+ "(default: 2)" },
+ { "compatible", 'c', NULL, 0,
+ "Try to be compatible with the Linux procps utilities. "
+ "Currently equivalent to -h 100 -s 0444 -S 1." },
+ { "anonymous-owner", 'a', "USER", 0,
+ "Make USER the owner of files related to processes without one. "
+ "Be aware that USER will be granted access to the environment and "
+ "other sensitive information about the processes in question. "
+ "(default: use uid 0)" },
+ {}
+ },
+ .parser = argp_parser,
+ .doc = "A virtual filesystem emulating the Linux procfs.",
+ .children = (struct argp_child []) {
+ { &netfs_std_startup_argp, },
+ {}
+ },
+};
+
+error_t
+root_make_node (struct ps_context *pc, struct node **np)
+{
+ struct node *root_dirs[] = {
+ proclist_make_node (pc),
+ rootdir_make_node (pc),
+ };
+
+ *np = dircat_make_node (root_dirs, sizeof root_dirs / sizeof root_dirs[0]);
+ if (! *np)
+ return ENOMEM;
+
+ /* Since this one is not created through proc_lookup(), we have to affect an
+ inode number to it. */
+ (*np)->nn_stat.st_ino = * (uint32_t *) "PROC";
+
+ return 0;
+}
+
+int main (int argc, char **argv)
+{
+ struct ps_context *pc;
+ mach_port_t bootstrap;
+ error_t err;
+
+ opt_clk_tck = sysconf(_SC_CLK_TCK);
+ opt_stat_mode = 0400;
+ opt_fake_self = -1;
+ opt_kernel_pid = 2;
+ opt_anon_owner = 0;
+ err = argp_parse (&argp, argc, argv, 0, 0, 0);
+ if (err)
+ error (1, err, "Could not parse command line");
+
+ err = ps_context_create (getproc (), &pc);
+ if (err)
+ error (1, err, "Could not create libps context");
+
+ task_get_bootstrap_port (mach_task_self (), &bootstrap);
+ if (bootstrap == MACH_PORT_NULL)
+ error (1, 0, "Must be started as a translator");
+
+ netfs_init ();
+ err = root_make_node (pc, &netfs_root_node);
+ if (err)
+ error (1, err, "Could not create the root node");
+
+ netfs_startup (bootstrap, 0);
+ netfs_server_loop ();
+
+ assert (0 /* netfs_server_loop returned after all */);
+}
+
diff --git a/procfs/main.h b/procfs/main.h
new file mode 100644
index 00000000..4e28b7eb
--- /dev/null
+++ b/procfs/main.h
@@ -0,0 +1,25 @@
+/* Hurd /proc filesystem, command-line options set by main.c.
+ Copyright (C) 2010 Free Software Foundation, Inc.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+/* Startup options */
+extern int opt_clk_tck;
+extern mode_t opt_stat_mode;
+extern pid_t opt_fake_self;
+extern pid_t opt_kernel_pid;
+extern uid_t opt_anon_owner;
diff --git a/procfs/netfs.c b/procfs/netfs.c
new file mode 100644
index 00000000..24a6603f
--- /dev/null
+++ b/procfs/netfs.c
@@ -0,0 +1,445 @@
+/* Hurd /proc filesystem, interface with libnetfs.
+ Copyright (C) 2010 Free Software Foundation, Inc.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#include <hurd/netfs.h>
+#include <hurd/fshelp.h>
+#include <sys/mman.h>
+#include <mach/vm_param.h>
+#include <dirent.h>
+#include <fcntl.h>
+#include "procfs.h"
+
+#define PROCFS_SERVER_NAME "procfs"
+#define PROCFS_SERVER_VERSION "0.1.0"
+#define PROCFS_MAXSYMLINKS 16
+
+
+/* Interesting libnetfs callback functions. */
+
+/* The user must define this variable. Set this to the name of the
+ filesystem server. */
+char *netfs_server_name = PROCFS_SERVER_NAME;
+
+/* The user must define this variables. Set this to be the server
+ version number. */
+char *netfs_server_version = PROCFS_SERVER_VERSION;
+
+/* Maximum number of symlinks to follow before returning ELOOP. */
+int netfs_maxsymlinks = PROCFS_MAXSYMLINKS;
+
+/* The user must define this function. Make sure that NP->nn_stat is
+ filled with the most current information. CRED identifies the user
+ responsible for the operation. NP is locked. */
+error_t netfs_validate_stat (struct node *np, struct iouser *cred)
+{
+ char *contents;
+ ssize_t contents_len;
+ error_t err;
+
+ /* Only symlinks need to have their size filled, before a read is
+ attempted. */
+ if (! S_ISLNK (np->nn_stat.st_mode))
+ return 0;
+
+ err = procfs_get_contents (np, &contents, &contents_len);
+ if (err)
+ return err;
+
+ np->nn_stat.st_size = contents_len;
+ return 0;
+}
+
+/* The user must define this function. Read from the locked file NP
+ for user CRED starting at OFFSET and continuing for up to *LEN
+ bytes. Put the data at DATA. Set *LEN to the amount successfully
+ read upon return. */
+error_t netfs_attempt_read (struct iouser *cred, struct node *np,
+ loff_t offset, size_t *len, void *data)
+{
+ char *contents;
+ ssize_t contents_len;
+ error_t err;
+
+ if (offset == 0)
+ procfs_refresh (np);
+
+ err = procfs_get_contents (np, &contents, &contents_len);
+ if (err)
+ return err;
+
+ contents += offset;
+ contents_len -= offset;
+
+ if (*len > contents_len)
+ *len = contents_len;
+ if (*len < 0)
+ *len = 0;
+
+ memcpy (data, contents, *len);
+ return 0;
+}
+
+/* The user must define this function. Read the contents of locked
+ node NP (a symlink), for USER, into BUF. */
+error_t netfs_attempt_readlink (struct iouser *user, struct node *np,
+ char *buf)
+{
+ char *contents;
+ ssize_t contents_len;
+ error_t err;
+
+ err = procfs_get_contents (np, &contents, &contents_len);
+ if (err)
+ return err;
+
+ assert (contents_len == np->nn_stat.st_size);
+ memcpy (buf, contents, contents_len);
+ return 0;
+}
+
+/* Helper function for netfs_get_dirents() below. CONTENTS is an argz
+ vector of directory entry names, as returned by procfs_get_contents().
+ Convert at most NENTRIES of them to dirent structures, put them in
+ DATA (if not NULL), write the number of entries processed in *AMT and
+ return the required/used space in DATACNT. */
+static int putentries (char *contents, size_t contents_len, int nentries,
+ char *data, mach_msg_type_number_t *datacnt)
+{
+ int i;
+
+ *datacnt = 0;
+ for (i = 0; contents_len && (nentries < 0 || i < nentries); i++)
+ {
+ int namlen = strlen (contents);
+ int reclen = sizeof (struct dirent) + namlen;
+
+ if (data)
+ {
+ struct dirent *d = (struct dirent *) (data + *datacnt);
+ d->d_fileno = 42; /* XXX */
+ d->d_namlen = namlen;
+ d->d_reclen = reclen;
+ d->d_type = DT_UNKNOWN;
+ strcpy (d->d_name, contents);
+ }
+
+ *datacnt += reclen;
+ contents += namlen + 1;
+ contents_len -= namlen + 1;
+ }
+
+ return i;
+}
+
+/* The user must define this function. Fill the array *DATA of size
+ BUFSIZE with up to NENTRIES dirents from DIR (which is locked)
+ starting with entry ENTRY for user CRED. The number of entries in
+ the array is stored in *AMT and the number of bytes in *DATACNT.
+ If the supplied buffer is not large enough to hold the data, it
+ should be grown. */
+error_t netfs_get_dirents (struct iouser *cred, struct node *dir,
+ int entry, int nentries, char **data,
+ mach_msg_type_number_t *datacnt,
+ vm_size_t bufsize, int *amt)
+{
+ char *contents;
+ ssize_t contents_len;
+ error_t err;
+
+ if (entry == 0)
+ procfs_refresh (dir);
+
+ err = procfs_get_contents (dir, &contents, &contents_len);
+ if (err)
+ return err;
+
+ /* We depend on the fact that CONTENTS is terminated. */
+ assert (contents_len == 0 || contents[contents_len - 1] == '\0');
+
+ /* Skip to the first requested entry. */
+ while (contents_len && entry--)
+ {
+ int ofs = strlen (contents) + 1;
+ contents += ofs;
+ contents_len -= ofs;
+ }
+
+ /* Allocate a buffer if necessary. */
+ putentries (contents, contents_len, nentries, NULL, datacnt);
+ if (bufsize < *datacnt)
+ {
+ char *n = mmap (0, *datacnt, PROT_READ | PROT_WRITE, MAP_ANONYMOUS, 0, 0);
+ if (n == MAP_FAILED)
+ return ENOMEM;
+
+ *data = n;
+ }
+
+ /* Do the actual conversion. */
+ *amt = putentries (contents, contents_len, nentries, *data, datacnt);
+
+ return 0;
+}
+
+/* The user must define this function. Lookup NAME in DIR (which is
+ locked) for USER; set *NP to the found name upon return. If the
+ name was not found, then return ENOENT. On any error, clear *NP.
+ (*NP, if found, should be locked and a reference to it generated.
+ This call should unlock DIR no matter what.) */
+error_t netfs_attempt_lookup (struct iouser *user, struct node *dir,
+ char *name, struct node **np)
+{
+ error_t err;
+
+ err = procfs_lookup (dir, name, np);
+ mutex_unlock (&dir->lock);
+
+ if (! err)
+ mutex_lock (&(*np)->lock);
+
+ return err;
+}
+
+/* The user must define this function. Node NP has no more references;
+ free all its associated storage. */
+void netfs_node_norefs (struct node *np)
+{
+ spin_unlock (&netfs_node_refcnt_lock);
+
+ procfs_cleanup (np);
+ free (np);
+
+ spin_lock (&netfs_node_refcnt_lock);
+}
+
+
+/* Libnetfs callbacks managed with libfshelp. */
+
+/* The user must define this function. Locked node NP is being opened
+ by USER, with FLAGS. NEWNODE is nonzero if we just created this
+ node. Return an error if we should not permit the open to complete
+ because of a permission restriction. */
+error_t netfs_check_open_permissions (struct iouser *user, struct node *np,
+ int flags, int newnode)
+{
+ error_t err = 0;
+ if (!err && (flags & O_READ))
+ err = fshelp_access (&np->nn_stat, S_IREAD, user);
+ if (!err && (flags & O_WRITE))
+ err = fshelp_access (&np->nn_stat, S_IWRITE, user);
+ if (!err && (flags & O_EXEC))
+ err = fshelp_access (&np->nn_stat, S_IEXEC, user);
+ return err;
+}
+
+/* The user must define this function. Return the valid access
+ types (bitwise OR of O_READ, O_WRITE, and O_EXEC) in *TYPES for
+ locked file NP and user CRED. */
+error_t netfs_report_access (struct iouser *cred, struct node *np,
+ int *types)
+{
+ *types = 0;
+ if (fshelp_access (&np->nn_stat, S_IREAD, cred) == 0)
+ *types |= O_READ;
+ if (fshelp_access (&np->nn_stat, S_IWRITE, cred) == 0)
+ *types |= O_WRITE;
+ if (fshelp_access (&np->nn_stat, S_IEXEC, cred) == 0)
+ *types |= O_EXEC;
+ return 0;
+}
+
+
+/* Trivial or unsupported libnetfs callbacks. */
+
+/* The user must define this function. This should attempt a chmod
+ call for the user specified by CRED on locked node NP, to change
+ the owner to UID and the group to GID. */
+error_t netfs_attempt_chown (struct iouser *cred, struct node *np,
+ uid_t uid, uid_t gid)
+{
+ return EROFS;
+}
+
+/* The user must define this function. This should attempt a chauthor
+ call for the user specified by CRED on locked node NP, thereby
+ changing the author to AUTHOR. */
+error_t netfs_attempt_chauthor (struct iouser *cred, struct node *np,
+ uid_t author)
+{
+ return EROFS;
+}
+
+/* The user must define this function. This should attempt a chmod
+ call for the user specified by CRED on locked node NODE, to change
+ the mode to MODE. Unlike the normal Unix and Hurd meaning of
+ chmod, this function is also used to attempt to change files into
+ other types. If such a transition is attempted which is
+ impossible, then return EOPNOTSUPP. */
+error_t netfs_attempt_chmod (struct iouser *cred, struct node *np,
+ mode_t mode)
+{
+ return EROFS;
+}
+
+/* The user must define this function. Attempt to turn locked node NP
+ (user CRED) into a symlink with target NAME. */
+error_t netfs_attempt_mksymlink (struct iouser *cred, struct node *np,
+ char *name)
+{
+ return EROFS;
+}
+
+/* The user must define this function. Attempt to turn NODE (user
+ CRED) into a device. TYPE is either S_IFBLK or S_IFCHR. NP is
+ locked. */
+error_t netfs_attempt_mkdev (struct iouser *cred, struct node *np,
+ mode_t type, dev_t indexes)
+{
+ return EROFS;
+}
+
+/* The user must define this function. This should attempt a chflags
+ call for the user specified by CRED on locked node NP, to change
+ the flags to FLAGS. */
+error_t netfs_attempt_chflags (struct iouser *cred, struct node *np,
+ int flags)
+{
+ return EROFS;
+}
+
+/* The user must define this function. This should attempt a utimes
+ call for the user specified by CRED on locked node NP, to change
+ the atime to ATIME and the mtime to MTIME. If ATIME or MTIME is
+ null, then set to the current time. */
+error_t netfs_attempt_utimes (struct iouser *cred, struct node *np,
+ struct timespec *atime, struct timespec *mtime)
+{
+ return EROFS;
+}
+
+/* The user must define this function. This should attempt to set the
+ size of the locked file NP (for user CRED) to SIZE bytes long. */
+error_t netfs_attempt_set_size (struct iouser *cred, struct node *np,
+ loff_t size)
+{
+ return EROFS;
+}
+
+/* The user must define this function. This should attempt to fetch
+ filesystem status information for the remote filesystem, for the
+ user CRED. NP is locked. */
+error_t netfs_attempt_statfs (struct iouser *cred, struct node *np,
+ fsys_statfsbuf_t *st)
+{
+ return ENOSYS;
+}
+
+/* The user must define this function. This should sync the locked
+ file NP completely to disk, for the user CRED. If WAIT is set,
+ return only after the sync is completely finished. */
+error_t netfs_attempt_sync (struct iouser *cred, struct node *np,
+ int wait)
+{
+ return 0;
+}
+
+/* The user must define this function. This should sync the entire
+ remote filesystem. If WAIT is set, return only after the sync is
+ completely finished. */
+error_t netfs_attempt_syncfs (struct iouser *cred, int wait)
+{
+ return 0;
+}
+
+/* The user must define this function. Delete NAME in DIR (which is
+ locked) for USER. */
+error_t netfs_attempt_unlink (struct iouser *user, struct node *dir,
+ char *name)
+{
+ return EROFS;
+}
+
+/* The user must define this function. Attempt to rename the
+ directory FROMDIR to TODIR. Note that neither of the specific nodes
+ are locked. */
+error_t netfs_attempt_rename (struct iouser *user, struct node *fromdir,
+ char *fromname, struct node *todir,
+ char *toname, int excl)
+{
+ return EROFS;
+}
+
+/* The user must define this function. Attempt to create a new
+ directory named NAME in DIR (which is locked) for USER with mode
+ MODE. */
+error_t netfs_attempt_mkdir (struct iouser *user, struct node *dir,
+ char *name, mode_t mode)
+{
+ return EROFS;
+}
+
+/* The user must define this function. Attempt to remove directory
+ named NAME in DIR (which is locked) for USER. */
+error_t netfs_attempt_rmdir (struct iouser *user,
+ struct node *dir, char *name)
+{
+ return EROFS;
+}
+
+
+/* The user must define this function. Create a link in DIR with name
+ NAME to FILE for USER. Note that neither DIR nor FILE are
+ locked. If EXCL is set, do not delete the target. Return EEXIST if
+ NAME is already found in DIR. */
+error_t netfs_attempt_link (struct iouser *user, struct node *dir,
+ struct node *file, char *name, int excl)
+{
+ return EROFS;
+}
+
+/* The user must define this function. Attempt to create an anonymous
+ file related to DIR (which is locked) for USER with MODE. Set *NP
+ to the returned file upon success. No matter what, unlock DIR. */
+error_t netfs_attempt_mkfile (struct iouser *user, struct node *dir,
+ mode_t mode, struct node **np)
+{
+ return EROFS;
+}
+
+/* The user must define this function. Attempt to create a file named
+ NAME in DIR (which is locked) for USER with MODE. Set *NP to the
+ new node upon return. On any error, clear *NP. *NP should be
+ locked on success; no matter what, unlock DIR before returning. */
+error_t netfs_attempt_create_file (struct iouser *user, struct node *dir,
+ char *name, mode_t mode, struct node **np)
+{
+ return EROFS;
+}
+
+/* The user must define this function. Write to the locked file NP
+ for user CRED starting at OFSET and continuing for up to *LEN bytes
+ from DATA. Set *LEN to the amount successfully written upon
+ return. */
+error_t netfs_attempt_write (struct iouser *cred, struct node *np,
+ loff_t offset, size_t *len, void *data)
+{
+ return EROFS;
+}
+
+
diff --git a/procfs/process.c b/procfs/process.c
new file mode 100644
index 00000000..17a38ea8
--- /dev/null
+++ b/procfs/process.c
@@ -0,0 +1,393 @@
+/* Hurd /proc filesystem, implementation of process directories.
+ Copyright (C) 2010 Free Software Foundation, Inc.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <hurd/process.h>
+#include <hurd/resource.h>
+#include <mach/vm_param.h>
+#include <ps.h>
+#include "procfs.h"
+#include "procfs_dir.h"
+#include "process.h"
+#include "main.h"
+
+/* This module implements the process directories and the files they
+ contain. A libps proc_stat structure is created for each process
+ node, and is used by the individual file content generators as a
+ source of information. Each possible file (cmdline, environ, ...) is
+ decribed in a process_file_desc structure, which specifies which bits
+ of information (ie. libps flags) it needs, and what function should
+ be used to generate the file's contents.
+
+ The content generators are defined first, followed by glue logic and
+ entry table. */
+
+
+/* Helper functions */
+
+static char state_char (struct proc_stat *ps)
+{
+ int i;
+
+ for (i = 0; (1 << i) & (PSTAT_STATE_P_STATES | PSTAT_STATE_T_STATES); i++)
+ if (proc_stat_state (ps) & (1 << i))
+ return proc_stat_state_tags[i];
+
+ return '?';
+}
+
+static const char *state_string (struct proc_stat *ps)
+{
+ static const char *const state_strings[] = {
+ "T (stopped)",
+ "Z (zombie)",
+ "R (running)",
+ "H (halted)",
+ "D (disk sleep)",
+ "S (sleeping)",
+ "I (idle)",
+ NULL
+ };
+ int i;
+
+ for (i = 0; state_strings[i]; i++)
+ if (proc_stat_state (ps) & (1 << i))
+ return state_strings[i];
+
+ return "? (unknown)";
+}
+
+static long long int timeval_jiffies (time_value_t tv)
+{
+ double secs = tv.seconds * 1000000. + tv.microseconds;
+ return secs * opt_clk_tck / 1000000.;
+}
+
+static const char *args_filename (const char *name)
+{
+ char *sp = strrchr (name, '/');
+ return sp != NULL && *(sp + 1) != '\0' ? sp + 1 : name;
+}
+
+/* Actual content generators */
+
+static ssize_t
+process_file_gc_cmdline (struct proc_stat *ps, char **contents)
+{
+ *contents = proc_stat_args(ps);
+ return proc_stat_args_len(ps);
+}
+
+static ssize_t
+process_file_gc_environ (struct proc_stat *ps, char **contents)
+{
+ *contents = proc_stat_env(ps);
+ return proc_stat_env_len(ps);
+}
+
+static ssize_t
+process_file_gc_stat (struct proc_stat *ps, char **contents)
+{
+ struct procinfo *pi = proc_stat_proc_info (ps);
+ task_basic_info_t tbi = proc_stat_task_basic_info (ps);
+ thread_basic_info_t thbi = proc_stat_thread_basic_info (ps);
+
+ /* See proc(5) for more information about the contents of each field for the
+ Linux procfs. */
+ return asprintf (contents,
+ "%d (%s) %c " /* pid, command, state */
+ "%d %d %d " /* ppid, pgid, session */
+ "%d %d " /* controling tty stuff */
+ "%u " /* flags, as defined by <linux/sched.h> */
+ "%lu %lu %lu %lu " /* page fault counts */
+ "%lu %lu %ld %ld " /* user/sys times, in sysconf(_SC_CLK_TCK) */
+ "%d %d " /* scheduler params (priority, nice) */
+ "%d %ld " /* number of threads, [obsolete] */
+ "%llu " /* start time since boot (jiffies) */
+ "%lu %ld %lu " /* virtual size (bytes), rss (pages), rss lim */
+ "%lu %lu %lu %lu %lu " /* some vm addresses (code, stack, sp, pc) */
+ "%lu %lu %lu %lu " /* pending, blocked, ignored and caught sigs */
+ "%lu " /* wait channel */
+ "%lu %lu " /* swap usage (not maintained in Linux) */
+ "%d " /* exit signal, to be sent to the parent */
+ "%d " /* last processor used */
+ "%u %u " /* RT priority and policy */
+ "%llu " /* aggregated block I/O delay */
+ "\n",
+ proc_stat_pid (ps), args_filename (proc_stat_args (ps)), state_char (ps),
+ pi->ppid, pi->pgrp, pi->session,
+ 0, 0, /* no such thing as a major:minor for ctty */
+ 0, /* no such thing as CLONE_* flags on Hurd */
+ 0L, 0L, 0L, 0L, /* TASK_EVENTS_INFO is unavailable on GNU Mach */
+ (long unsigned) timeval_jiffies (thbi->user_time),
+ (long unsigned) timeval_jiffies (thbi->system_time),
+ 0L, 0L, /* cumulative time for children */
+ MACH_PRIORITY_TO_NICE(thbi->base_priority) + 20,
+ MACH_PRIORITY_TO_NICE(thbi->base_priority),
+ pi->nthreads, 0L,
+ timeval_jiffies (thbi->creation_time), /* FIXME: ... since boot */
+ (long unsigned) tbi->virtual_size,
+ (long unsigned) tbi->resident_size / PAGE_SIZE, 0L,
+ 0L, 0L, 0L, 0L, 0L,
+ 0L, 0L, 0L, 0L,
+ (long unsigned) proc_stat_thread_rpc (ps), /* close enough */
+ 0L, 0L,
+ 0,
+ 0,
+ 0, 0,
+ 0LL);
+}
+
+static ssize_t
+process_file_gc_statm (struct proc_stat *ps, char **contents)
+{
+ task_basic_info_t tbi = proc_stat_task_basic_info (ps);
+
+ return asprintf (contents,
+ "%lu %lu 0 0 0 0 0\n",
+ tbi->virtual_size / sysconf(_SC_PAGE_SIZE),
+ tbi->resident_size / sysconf(_SC_PAGE_SIZE));
+}
+
+static ssize_t
+process_file_gc_status (struct proc_stat *ps, char **contents)
+{
+ task_basic_info_t tbi = proc_stat_task_basic_info (ps);
+
+ return asprintf (contents,
+ "Name:\t%s\n"
+ "State:\t%s\n"
+ "Tgid:\t%u\n"
+ "Pid:\t%u\n"
+ "PPid:\t%u\n"
+ "Uid:\t%u\t%u\t%u\t%u\n"
+ "VmSize:\t%8u kB\n"
+ "VmPeak:\t%8u kB\n"
+ "VmRSS:\t%8u kB\n"
+ "VmHWM:\t%8u kB\n" /* ie. resident peak */
+ "Threads:\t%u\n",
+ args_filename (proc_stat_args (ps)),
+ state_string (ps),
+ proc_stat_pid (ps), /* XXX will need more work for threads */
+ proc_stat_pid (ps),
+ proc_stat_proc_info (ps)->ppid,
+ proc_stat_owner_uid (ps),
+ proc_stat_owner_uid (ps),
+ proc_stat_owner_uid (ps),
+ proc_stat_owner_uid (ps),
+ tbi->virtual_size / 1024,
+ tbi->virtual_size / 1024,
+ tbi->resident_size / 1024,
+ tbi->resident_size / 1024,
+ proc_stat_num_threads (ps));
+}
+
+
+/* Implementation of the file nodes. */
+
+/* Describes a file in the process directories. This structure is
+ filled in as an "entry hook" in our procfs_dir entry table and is
+ passed to the process_file_make_node function defined below. */
+struct process_file_desc
+{
+ /* The proc_stat information required to get the contents of this file. */
+ ps_flags_t needs;
+
+ /* Content generator to use for this file. Once we have acquired the
+ necessary information, there can be only memory allocation errors,
+ hence this simplified signature. */
+ ssize_t (*get_contents) (struct proc_stat *ps, char **contents);
+
+ /* The cmdline and environ contents don't need any cleaning since they
+ point directly into the proc_stat structure. */
+ int no_cleanup;
+
+ /* If specified, the file mode to be set with procfs_node_chmod(). */
+ mode_t mode;
+};
+
+struct process_file_node
+{
+ const struct process_file_desc *desc;
+ struct proc_stat *ps;
+};
+
+/* FIXME: lock the parent! */
+static error_t
+process_file_get_contents (void *hook, char **contents, ssize_t *contents_len)
+{
+ struct process_file_node *file = hook;
+ error_t err;
+
+ /* Fetch the required information. */
+ err = proc_stat_set_flags (file->ps, file->desc->needs);
+ if (err)
+ return EIO;
+ if ((proc_stat_flags (file->ps) & file->desc->needs) != file->desc->needs)
+ return EIO;
+
+ /* Call the actual content generator (see the definitions below). */
+ *contents_len = file->desc->get_contents (file->ps, contents);
+ return 0;
+}
+
+static void
+process_file_cleanup_contents (void *hook, char *contents, ssize_t len)
+{
+ struct process_file_node *file = hook;
+
+ if (! file->desc->no_cleanup)
+ free (contents);
+}
+
+static struct node *
+process_file_make_node (void *dir_hook, const void *entry_hook)
+{
+ static const struct procfs_node_ops ops = {
+ .get_contents = process_file_get_contents,
+ .cleanup_contents = process_file_cleanup_contents,
+ .cleanup = free,
+ };
+ struct process_file_node *f;
+ struct node *np;
+
+ f = malloc (sizeof *f);
+ if (! f)
+ return NULL;
+
+ f->desc = entry_hook;
+ f->ps = dir_hook;
+
+ np = procfs_make_node (&ops, f);
+ if (! np)
+ return NULL;
+
+ procfs_node_chown (np, proc_stat_owner_uid (f->ps));
+ if (f->desc->mode)
+ procfs_node_chmod (np, f->desc->mode);
+
+ return np;
+}
+
+/* Stat needs its own constructor in oreder to set its mode according to
+ the --stat-mode command-line option. */
+static struct node *
+process_stat_make_node (void *dir_hook, const void *entry_hook)
+{
+ struct node *np = process_file_make_node (dir_hook, entry_hook);
+ if (np) procfs_node_chmod (np, opt_stat_mode);
+ return np;
+}
+
+
+/* Implementation of the process directory per se. */
+
+static struct procfs_dir_entry entries[] = {
+ {
+ .name = "cmdline",
+ .hook = & (struct process_file_desc) {
+ .get_contents = process_file_gc_cmdline,
+ .needs = PSTAT_ARGS,
+ .no_cleanup = 1,
+ },
+ },
+ {
+ .name = "environ",
+ .hook = & (struct process_file_desc) {
+ .get_contents = process_file_gc_environ,
+ .needs = PSTAT_ENV,
+ .no_cleanup = 1,
+ .mode = 0400,
+ },
+ },
+ {
+ .name = "stat",
+ .hook = & (struct process_file_desc) {
+ .get_contents = process_file_gc_stat,
+ .needs = PSTAT_PID | PSTAT_ARGS | PSTAT_STATE | PSTAT_PROC_INFO
+ | PSTAT_TASK | PSTAT_TASK_BASIC | PSTAT_THREAD_BASIC
+ | PSTAT_THREAD_WAIT,
+ },
+ .ops = {
+ .make_node = process_stat_make_node,
+ }
+ },
+ {
+ .name = "statm",
+ .hook = & (struct process_file_desc) {
+ .get_contents = process_file_gc_statm,
+ .needs = PSTAT_TASK_BASIC,
+ },
+ },
+ {
+ .name = "status",
+ .hook = & (struct process_file_desc) {
+ .get_contents = process_file_gc_status,
+ .needs = PSTAT_PID | PSTAT_ARGS | PSTAT_STATE | PSTAT_PROC_INFO
+ | PSTAT_TASK_BASIC | PSTAT_OWNER_UID | PSTAT_NUM_THREADS,
+ },
+ },
+ {}
+};
+
+error_t
+process_lookup_pid (struct ps_context *pc, pid_t pid, struct node **np)
+{
+ static const struct procfs_dir_ops dir_ops = {
+ .entries = entries,
+ .cleanup = (void (*)(void *)) _proc_stat_free,
+ .entry_ops = {
+ .make_node = process_file_make_node,
+ },
+ };
+ struct proc_stat *ps;
+ int owner;
+ error_t err;
+
+ err = _proc_stat_create (pid, pc, &ps);
+ if (err == ESRCH)
+ return ENOENT;
+ if (err)
+ return EIO;
+
+ err = proc_stat_set_flags (ps, PSTAT_OWNER_UID);
+ if (err || ! (proc_stat_flags (ps) & PSTAT_OWNER_UID))
+ {
+ _proc_stat_free (ps);
+ return EIO;
+ }
+
+ /* FIXME: have a separate proc_desc structure for each file, so this can be
+ accessed in a more robust and straightforward way. */
+ ((struct process_file_desc *) entries[2].hook)->mode = opt_stat_mode;
+
+ /* FIXME: have a separate proc_desc structure for each file, so this can be
+ accessed in a more robust and straightforward way. */
+ ((struct process_file_desc *) entries[2].hook)->mode = opt_stat_mode;
+
+ *np = procfs_dir_make_node (&dir_ops, ps);
+ if (! *np)
+ return ENOMEM;
+
+ owner = proc_stat_owner_uid (ps);
+ procfs_node_chown (*np, owner >= 0 ? owner : opt_anon_owner);
+ return 0;
+}
diff --git a/procfs/process.h b/procfs/process.h
new file mode 100644
index 00000000..b230a281
--- /dev/null
+++ b/procfs/process.h
@@ -0,0 +1,27 @@
+/* Hurd /proc filesystem, implementation of process directories.
+ Copyright (C) 2010 Free Software Foundation, Inc.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#include <ps.h>
+
+/* Create a node for a directory representing the given PID, as published by
+ the proc server refrenced by the libps context PC. On success, returns the
+ newly created node in *NP. */
+error_t
+process_lookup_pid (struct ps_context *pc, pid_t pid, struct node **np);
+
diff --git a/procfs/procfs.c b/procfs/procfs.c
new file mode 100644
index 00000000..ae5a6769
--- /dev/null
+++ b/procfs/procfs.c
@@ -0,0 +1,203 @@
+/* Hurd /proc filesystem, basic infrastructure.
+ Copyright (C) 2010 Free Software Foundation, Inc.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
+#include <mach.h>
+#include <hurd/netfs.h>
+#include <hurd/fshelp.h>
+#include "procfs.h"
+
+struct netnode
+{
+ const struct procfs_node_ops *ops;
+ void *hook;
+
+ /* (cached) contents of the node */
+ char *contents;
+ ssize_t contents_len;
+
+ /* parent directory, if applicable */
+ struct node *parent;
+};
+
+void
+procfs_cleanup_contents_with_free (void *hook, char *cont, ssize_t len)
+{
+ free (cont);
+}
+
+void
+procfs_cleanup_contents_with_vm_deallocate (void *hook, char *cont, ssize_t len)
+{
+ vm_deallocate (mach_task_self (), (vm_address_t) cont, (vm_size_t) len);
+}
+
+struct node *procfs_make_node (const struct procfs_node_ops *ops, void *hook)
+{
+ struct netnode *nn;
+ struct node *np;
+
+ nn = malloc (sizeof *nn);
+ if (! nn)
+ goto fail;
+
+ memset (nn, 0, sizeof *nn);
+ nn->ops = ops;
+ nn->hook = hook;
+
+ np = netfs_make_node (nn);
+ if (! np)
+ goto fail;
+
+ np->nn = nn;
+ memset (&np->nn_stat, 0, sizeof np->nn_stat);
+ np->nn_translated = 0;
+
+ if (np->nn->ops->lookup)
+ np->nn_stat.st_mode = S_IFDIR | 0555;
+ else
+ np->nn_stat.st_mode = S_IFREG | 0444;
+
+ return np;
+
+fail:
+ if (ops->cleanup)
+ ops->cleanup (hook);
+
+ free (nn);
+ return NULL;
+}
+
+void procfs_node_chown (struct node *np, uid_t owner)
+{
+ np->nn_stat.st_uid = owner;
+}
+
+void procfs_node_chmod (struct node *np, mode_t mode)
+{
+ np->nn_stat.st_mode = (np->nn_stat.st_mode & S_IFMT) | mode;
+ np->nn_translated = np->nn_stat.st_mode;
+}
+
+void procfs_node_chtype (struct node *np, mode_t type)
+{
+ np->nn_stat.st_mode = (np->nn_stat.st_mode & ~S_IFMT) | type;
+ np->nn_translated = np->nn_stat.st_mode;
+ if (type == S_IFLNK)
+ procfs_node_chmod (np, 0777);
+}
+
+/* FIXME: possibly not the fastest hash function... */
+ino64_t
+procfs_make_ino (struct node *np, const char *filename)
+{
+ unsigned short x[3];
+
+ if (! strcmp (filename, "."))
+ return np->nn_stat.st_ino;
+ if (! strcmp (filename, ".."))
+ return np->nn->parent ? np->nn->parent->nn_stat.st_ino : /* FIXME: */ 2;
+
+ assert (sizeof np->nn_stat.st_ino > sizeof x);
+ memcpy (x, &np->nn_stat.st_ino, sizeof x);
+
+ while (*filename)
+ {
+ x[0] ^= *(filename++);
+ jrand48 (x);
+ }
+
+ return (unsigned long) jrand48 (x);
+}
+
+error_t procfs_get_contents (struct node *np, char **data, ssize_t *data_len)
+{
+ if (! np->nn->contents && np->nn->ops->get_contents)
+ {
+ char *contents;
+ ssize_t contents_len;
+ error_t err;
+
+ contents_len = -1;
+ err = np->nn->ops->get_contents (np->nn->hook, &contents, &contents_len);
+ if (err)
+ return err;
+ if (contents_len < 0)
+ return ENOMEM;
+
+ np->nn->contents = contents;
+ np->nn->contents_len = contents_len;
+ }
+
+ *data = np->nn->contents;
+ *data_len = np->nn->contents_len;
+ return 0;
+}
+
+void procfs_refresh (struct node *np)
+{
+ if (np->nn->contents && np->nn->ops->cleanup_contents)
+ np->nn->ops->cleanup_contents (np->nn->hook, np->nn->contents, np->nn->contents_len);
+
+ np->nn->contents = NULL;
+}
+
+error_t procfs_lookup (struct node *np, const char *name, struct node **npp)
+{
+ error_t err = ENOENT;
+
+ if (err && ! strcmp (name, "."))
+ {
+ netfs_nref(*npp = np);
+ err = 0;
+ }
+
+ if (err && np->nn->parent && ! strcmp (name, ".."))
+ {
+ netfs_nref(*npp = np->nn->parent);
+ err = 0;
+ }
+
+ if (err && np->nn->ops->lookup)
+ {
+ err = np->nn->ops->lookup (np->nn->hook, name, npp);
+ if (! err)
+ {
+ (*npp)->nn_stat.st_ino = procfs_make_ino (np, name);
+ netfs_nref ((*npp)->nn->parent = np);
+ }
+ }
+
+ return err;
+}
+
+void procfs_cleanup (struct node *np)
+{
+ procfs_refresh (np);
+
+ if (np->nn->ops->cleanup)
+ np->nn->ops->cleanup (np->nn->hook);
+
+ if (np->nn->parent)
+ netfs_nrele (np->nn->parent);
+
+ free (np->nn);
+}
diff --git a/procfs/procfs.h b/procfs/procfs.h
new file mode 100644
index 00000000..64782ec4
--- /dev/null
+++ b/procfs/procfs.h
@@ -0,0 +1,93 @@
+/* Hurd /proc filesystem, basic infrastructure.
+ Copyright (C) 2010 Free Software Foundation, Inc.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#include <hurd/hurd_types.h>
+#include <hurd/netfs.h>
+
+
+/* Interface for the procfs side. */
+
+/* Any of these callback functions can be omitted, in which case
+ reasonable defaults will be used. The initial file mode and type
+ depend on whether a lookup function is provided, but can be
+ overridden in update_stat(). */
+struct procfs_node_ops
+{
+ /* Fetch the contents of a node. A pointer to the contents should be
+ returned in *CONTENTS and their length in *CONTENTS_LEN. The exact
+ nature of these data depends on whether the node is a regular file,
+ symlink or directory, as determined by the file mode in
+ netnode->nn_stat. For regular files and symlinks, they are what
+ you would expect; for directories, they are an argz vector of the
+ names of the entries. If upon return, *CONTENTS_LEN is negative or
+ unchanged, the call is considered to have failed because of a memory
+ allocation error. */
+ error_t (*get_contents) (void *hook, char **contents, ssize_t *contents_len);
+ void (*cleanup_contents) (void *hook, char *contents, ssize_t contents_len);
+
+ /* Lookup NAME in this directory, and store the result in *np. The
+ returned node should be created by lookup() using procfs_make_node()
+ or a derived function. Note that the parent will be kept alive as
+ long as the child exists, so you can safely reference the parent's
+ data from the child. You may want to consider locking if there's
+ any mutation going on, though. */
+ error_t (*lookup) (void *hook, const char *name, struct node **np);
+
+ /* Destroy this node. */
+ void (*cleanup) (void *hook);
+};
+
+/* These helper functions can be used as procfs_node_ops.cleanup_contents. */
+void procfs_cleanup_contents_with_free (void *, char *, ssize_t);
+void procfs_cleanup_contents_with_vm_deallocate (void *, char *, ssize_t);
+
+/* Create a new node and return it. Returns NULL if it fails to allocate
+ enough memory. In this case, ops->cleanup will be invoked. */
+struct node *procfs_make_node (const struct procfs_node_ops *ops, void *hook);
+
+/* Set the owner of the node NP. Must be called right after the node
+ has been created. */
+void procfs_node_chown (struct node *np, uid_t owner);
+
+/* Set the permission bits of the node NP. Must be called right after
+ the node has been created. */
+void procfs_node_chmod (struct node *np, mode_t mode);
+
+/* Set the type of the node NP. If type is S_IFLNK, appropriate
+ permission bits will be set as well. Must be called right after the
+ node has been created. */
+void procfs_node_chtype (struct node *np, mode_t type);
+
+
+/* Interface for the libnetfs side. */
+
+/* Get the inode number which will be given to a child of NP named FILENAME.
+ This allows us to retreive them for readdir() without creating the
+ corresponding child nodes. */
+ino64_t procfs_make_ino (struct node *np, const char *filename);
+
+/* Forget the current cached contents for the node. This is done before reads
+ from offset 0, to ensure that the data are recent even for utilities such as
+ top which keep some nodes open. */
+void procfs_refresh (struct node *np);
+
+error_t procfs_get_contents (struct node *np, char **data, ssize_t *data_len);
+error_t procfs_lookup (struct node *np, const char *name, struct node **npp);
+void procfs_cleanup (struct node *np);
+
diff --git a/procfs/procfs_dir.c b/procfs/procfs_dir.c
new file mode 100644
index 00000000..c250aa48
--- /dev/null
+++ b/procfs/procfs_dir.c
@@ -0,0 +1,134 @@
+/* Hurd /proc filesystem, infrastructure for directories.
+ Copyright (C) 2010 Free Software Foundation, Inc.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#include <stdlib.h>
+#include <string.h>
+#include "procfs.h"
+#include "procfs_dir.h"
+
+struct procfs_dir_node
+{
+ const struct procfs_dir_ops *ops;
+ void *hook;
+};
+
+static int
+entry_exists (struct procfs_dir_node *dir, const struct procfs_dir_entry *ent)
+{
+ if (ent->ops.exists)
+ return ent->ops.exists (dir->hook, ent->hook);
+ if (dir->ops->entry_ops.exists)
+ return dir->ops->entry_ops.exists (dir->hook, ent->hook);
+
+ return 1;
+}
+
+static error_t
+procfs_dir_get_contents (void *hook, char **contents, ssize_t *contents_len)
+{
+ static const char dot_dotdot[] = ".\0..";
+ struct procfs_dir_node *dir = hook;
+ const struct procfs_dir_entry *ent;
+ int pos;
+
+ /* Evaluate how much space is needed. Note that we include the hidden
+ entries, just in case their status changes between now and then. */
+ pos = sizeof dot_dotdot;
+ for (ent = dir->ops->entries; ent->name; ent++)
+ pos += strlen (ent->name) + 1;
+
+ *contents = malloc (pos);
+ if (! *contents)
+ return ENOMEM;
+
+ memcpy (*contents, dot_dotdot, sizeof dot_dotdot);
+ pos = sizeof dot_dotdot;
+ for (ent = dir->ops->entries; ent->name; ent++)
+ {
+ if (! entry_exists (dir, ent))
+ continue;
+
+ strcpy (*contents + pos, ent->name);
+ pos += strlen (ent->name) + 1;
+ }
+
+ *contents_len = pos;
+ return 0;
+}
+
+static error_t
+procfs_dir_lookup (void *hook, const char *name, struct node **np)
+{
+ struct procfs_dir_node *dir = hook;
+ const struct procfs_dir_entry *ent;
+
+ for (ent = dir->ops->entries; ent->name && strcmp (name, ent->name); ent++);
+ if (! ent->name)
+ return ENOENT;
+
+ if (ent->ops.make_node)
+ *np = ent->ops.make_node (dir->hook, ent->hook);
+ else if (dir->ops->entry_ops.make_node)
+ *np = dir->ops->entry_ops.make_node (dir->hook, ent->hook);
+ else
+ return EGRATUITOUS;
+
+ if (! *np)
+ return ENOMEM;
+
+ return 0;
+}
+
+static void
+procfs_dir_cleanup (void *hook)
+{
+ struct procfs_dir_node *dir = hook;
+
+ if (dir->ops->cleanup)
+ dir->ops->cleanup (dir->hook);
+
+ free (dir);
+}
+
+struct node *
+procfs_dir_make_node (const struct procfs_dir_ops *dir_ops, void *dir_hook)
+{
+ static const struct procfs_node_ops ops = {
+ .get_contents = procfs_dir_get_contents,
+ .lookup = procfs_dir_lookup,
+ .cleanup_contents = procfs_cleanup_contents_with_free,
+ .cleanup = procfs_dir_cleanup,
+ };
+ struct procfs_dir_node *dir;
+
+ dir = malloc (sizeof *dir);
+ if (! dir)
+ {
+ if (dir_ops->cleanup)
+ dir_ops->cleanup (dir_hook);
+
+ return NULL;
+ }
+
+ dir->ops = dir_ops;
+ dir->hook = dir_hook;
+
+ return procfs_make_node (&ops, dir);
+}
+
diff --git a/procfs/procfs_dir.h b/procfs/procfs_dir.h
new file mode 100644
index 00000000..94c5b019
--- /dev/null
+++ b/procfs/procfs_dir.h
@@ -0,0 +1,63 @@
+/* Hurd /proc filesystem, infrastructure for directories.
+ Copyright (C) 2010 Free Software Foundation, Inc.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+/* This module provides an abstraction layer for implementing simple
+ directories with (mostly) static contents. The user defines the
+ contents of the directory by providing a table of entries and various
+ optional callback functions. */
+
+/* These operations define how a given entry will behave. Either can be
+ omitted, both from the entry-specific operations and from the
+ directory-wide defaults. */
+struct procfs_dir_entry_ops
+{
+ /* Called when this entry is looked up to create a corresponding node. */
+ struct node *(*make_node)(void *dir_hook, const void *entry_hook);
+ /* If this is provided and returns 0, this entry will be hidden. */
+ int (*exists)(void *dir_hook, const void *entry_hook);
+};
+
+/* Describes an individual directory entry, associating a NAME with
+ * arbitrary HOOK data and node-specific OPS. */
+struct procfs_dir_entry
+{
+ const char *name;
+ const void *hook;
+ struct procfs_dir_entry_ops ops;
+};
+
+/* Describes a complete directory. ENTRIES is a table terminated by a
+ null NAME field. ENTRY_OPS provides default operations for the
+ entries which don't specify them. The optional CLEANUP function
+ should release all the resources associated with the directory hook. */
+struct procfs_dir_ops
+{
+ const struct procfs_dir_entry *entries;
+ void (*cleanup)(void *dir_hook);
+ struct procfs_dir_entry_ops entry_ops;
+};
+
+/* Create and return a new node for the directory described in OPS.
+ The DIR_HOOK is passed the MAKE_NODE callback function of looked up
+ entries, as well as to the CLEANUP callback when the node is
+ destroyed. If not enough memory can be allocated, OPS->CLEANUP is
+ invoked immediately and NULL is returned. */
+struct node *
+procfs_dir_make_node (const struct procfs_dir_ops *ops, void *dir_hook);
+
diff --git a/procfs/proclist.c b/procfs/proclist.c
new file mode 100644
index 00000000..58b942dc
--- /dev/null
+++ b/procfs/proclist.c
@@ -0,0 +1,94 @@
+/* Hurd /proc filesystem, list of processes as a directory.
+ Copyright (C) 2010 Free Software Foundation, Inc.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <mach.h>
+#include <hurd/process.h>
+#include <ps.h>
+#include "procfs.h"
+#include "process.h"
+
+#define PID_STR_SIZE (3 * sizeof (pid_t) + 1)
+
+static error_t
+proclist_get_contents (void *hook, char **contents, ssize_t *contents_len)
+{
+ struct ps_context *pc = hook;
+ pidarray_t pids;
+ mach_msg_type_number_t num_pids;
+ error_t err;
+ int i;
+
+ num_pids = 0;
+ err = proc_getallpids (pc->server, &pids, &num_pids);
+ if (err)
+ return EIO;
+
+ *contents = malloc (num_pids * PID_STR_SIZE);
+ if (*contents)
+ {
+ *contents_len = 0;
+ for (i=0; i < num_pids; i++)
+ {
+ int n = sprintf (*contents + *contents_len, "%d", pids[i]);
+ assert (n >= 0);
+ *contents_len += (n + 1);
+ }
+ }
+ else
+ err = ENOMEM;
+
+ vm_deallocate (mach_task_self (), (vm_address_t) pids, num_pids * sizeof pids[0]);
+ return err;
+}
+
+static error_t
+proclist_lookup (void *hook, const char *name, struct node **np)
+{
+ struct ps_context *pc = hook;
+ char *endp;
+ pid_t pid;
+
+ /* Self-lookups should not end up here. */
+ assert (name[0]);
+
+ /* No leading zeros allowed */
+ if (name[0] == '0' && name[1])
+ return ENOENT;
+
+ pid = strtol (name, &endp, 10);
+ if (*endp)
+ return ENOENT;
+
+ return process_lookup_pid (pc, pid, np);
+}
+
+struct node *
+proclist_make_node (struct ps_context *pc)
+{
+ static const struct procfs_node_ops ops = {
+ .get_contents = proclist_get_contents,
+ .lookup = proclist_lookup,
+ .cleanup_contents = procfs_cleanup_contents_with_free,
+ };
+ return procfs_make_node (&ops, pc);
+}
+
diff --git a/procfs/proclist.h b/procfs/proclist.h
new file mode 100644
index 00000000..bfe95b3d
--- /dev/null
+++ b/procfs/proclist.h
@@ -0,0 +1,23 @@
+/* Hurd /proc filesystem, list of processes as a directory.
+ Copyright (C) 2010 Free Software Foundation, Inc.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#include <ps.h>
+
+struct node *
+proclist_make_node (struct ps_context *pc);
diff --git a/procfs/rootdir.c b/procfs/rootdir.c
new file mode 100644
index 00000000..1fa71b03
--- /dev/null
+++ b/procfs/rootdir.c
@@ -0,0 +1,506 @@
+/* Hurd /proc filesystem, permanent files of the root directory.
+ Copyright (C) 2010 Free Software Foundation, Inc.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#include <mach/vm_param.h>
+#include <mach/vm_statistics.h>
+#include <mach/default_pager.h>
+#include <hurd/paths.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/time.h>
+#include <sys/utsname.h>
+#include <sys/stat.h>
+#include <argz.h>
+#include <ps.h>
+#include "procfs.h"
+#include "procfs_dir.h"
+#include "main.h"
+
+/* This implements a directory node with the static files in /proc.
+ NB: the libps functions for host information return static storage;
+ using them would require locking and as a consequence it would be
+ more complicated, not simpler. */
+
+
+/* Helper functions */
+
+/* We get the boot time by using that of the kernel process. */
+static error_t
+get_boottime (struct ps_context *pc, struct timeval *tv)
+{
+ struct proc_stat *ps;
+ error_t err;
+
+ err = _proc_stat_create (opt_kernel_pid, pc, &ps);
+ if (err)
+ return err;
+
+ err = proc_stat_set_flags (ps, PSTAT_TASK_BASIC);
+ if (err || !(proc_stat_flags (ps) & PSTAT_TASK_BASIC))
+ err = EIO;
+
+ if (! err)
+ {
+ task_basic_info_t tbi = proc_stat_task_basic_info (ps);
+ tv->tv_sec = tbi->creation_time.seconds;
+ tv->tv_usec = tbi->creation_time.microseconds;
+ }
+
+ _proc_stat_free (ps);
+ return err;
+}
+
+/* We get the idle time by querying the kernel's idle thread. */
+static error_t
+get_idletime (struct ps_context *pc, struct timeval *tv)
+{
+ struct proc_stat *ps, *pst;
+ thread_basic_info_t tbi;
+ error_t err;
+ int i;
+
+ err = _proc_stat_create (opt_kernel_pid, pc, &ps);
+ if (err)
+ return err;
+
+ pst = NULL, tbi = NULL;
+
+ err = proc_stat_set_flags (ps, PSTAT_NUM_THREADS);
+ if (err || !(proc_stat_flags (ps) & PSTAT_NUM_THREADS))
+ {
+ err = EIO;
+ goto out;
+ }
+
+ /* Look for the idle thread */
+ for (i=0; !tbi || !(tbi->flags & TH_FLAGS_IDLE); i++)
+ {
+ if (pst)
+ _proc_stat_free (pst);
+
+ pst = NULL, tbi = NULL;
+ if (i >= proc_stat_num_threads (ps))
+ {
+ err = ESRCH;
+ goto out;
+ }
+
+ err = proc_stat_thread_create (ps, i, &pst);
+ if (err)
+ continue;
+
+ err = proc_stat_set_flags (pst, PSTAT_THREAD_BASIC);
+ if (err || ! (proc_stat_flags (pst) & PSTAT_THREAD_BASIC))
+ continue;
+
+ tbi = proc_stat_thread_basic_info (pst);
+ }
+
+ /* We found it! */
+ tv->tv_sec = tbi->system_time.seconds;
+ tv->tv_usec = tbi->system_time.microseconds;
+ err = 0;
+
+out:
+ if (pst) _proc_stat_free (pst);
+ _proc_stat_free (ps);
+ return err;
+}
+
+static error_t
+get_swapinfo (default_pager_info_t *info)
+{
+ mach_port_t defpager;
+ error_t err;
+
+ defpager = file_name_lookup (_SERVERS_DEFPAGER, O_READ, 0);
+ if (defpager == MACH_PORT_NULL)
+ return errno;
+
+ err = default_pager_info (defpager, info);
+ mach_port_deallocate (mach_task_self (), defpager);
+
+ return err;
+}
+
+
+/* Content generators */
+
+static error_t
+rootdir_gc_version (void *hook, char **contents, ssize_t *contents_len)
+{
+ struct utsname uts;
+ int r;
+
+ r = uname (&uts);
+ if (r < 0)
+ return errno;
+
+ *contents_len = asprintf (contents,
+ "Linux version 2.6.1 (%s %s %s %s)\n",
+ uts.sysname, uts.release, uts.version, uts.machine);
+
+ return 0;
+}
+
+static error_t
+rootdir_gc_uptime (void *hook, char **contents, ssize_t *contents_len)
+{
+ struct timeval time, boottime, idletime;
+ double up_secs, idle_secs;
+ error_t err;
+
+ err = gettimeofday (&time, NULL);
+ if (err < 0)
+ return errno;
+
+ err = get_boottime (hook, &boottime);
+ if (err)
+ return err;
+
+ err = get_idletime (hook, &idletime);
+ if (err)
+ return err;
+
+ timersub (&time, &boottime, &time);
+ up_secs = (time.tv_sec * 1000000. + time.tv_usec) / 1000000.;
+ idle_secs = (idletime.tv_sec * 1000000. + idletime.tv_usec) / 1000000.;
+
+ /* The second field is the total idle time. As far as I know we don't
+ keep track of it. However, procps uses it to compute "USER_HZ", and
+ proc(5) specifies that it should be equal to USER_HZ times the idle value
+ in ticks from /proc/stat. So we assume a completely idle system both here
+ and there to make that work. */
+ *contents_len = asprintf (contents, "%.2lf %.2lf\n", up_secs, idle_secs);
+
+ return 0;
+}
+
+static error_t
+rootdir_gc_stat (void *hook, char **contents, ssize_t *contents_len)
+{
+ struct timeval boottime, time, idletime;
+ struct vm_statistics vmstats;
+ unsigned long up_ticks, idle_ticks;
+ error_t err;
+
+ err = gettimeofday (&time, NULL);
+ if (err < 0)
+ return errno;
+
+ err = get_boottime (hook, &boottime);
+ if (err)
+ return err;
+
+ err = get_idletime (hook, &idletime);
+ if (err)
+ return err;
+
+ err = vm_statistics (mach_task_self (), &vmstats);
+ if (err)
+ return EIO;
+
+ timersub (&time, &boottime, &time);
+ up_ticks = opt_clk_tck * (time.tv_sec * 1000000. + time.tv_usec) / 1000000.;
+ idle_ticks = opt_clk_tck * (idletime.tv_sec * 1000000. + idletime.tv_usec) / 1000000.;
+
+ *contents_len = asprintf (contents,
+ "cpu %lu 0 0 %lu 0 0 0 0 0\n"
+ "cpu0 %lu 0 0 %lu 0 0 0 0 0\n"
+ "intr 0\n"
+ "page %d %d\n"
+ "btime %lu\n",
+ up_ticks - idle_ticks, idle_ticks,
+ up_ticks - idle_ticks, idle_ticks,
+ vmstats.pageins, vmstats.pageouts,
+ boottime.tv_sec);
+
+ return 0;
+}
+
+static error_t
+rootdir_gc_loadavg (void *hook, char **contents, ssize_t *contents_len)
+{
+ host_load_info_data_t hli;
+ mach_msg_type_number_t cnt;
+ error_t err;
+
+ cnt = HOST_LOAD_INFO_COUNT;
+ err = host_info (mach_host_self (), HOST_LOAD_INFO, (host_info_t) &hli, &cnt);
+ if (err)
+ return err;
+
+ assert (cnt == HOST_LOAD_INFO_COUNT);
+ *contents_len = asprintf (contents,
+ "%.2f %.2f %.2f 1/0 0\n",
+ hli.avenrun[0] / (double) LOAD_SCALE,
+ hli.avenrun[1] / (double) LOAD_SCALE,
+ hli.avenrun[2] / (double) LOAD_SCALE);
+
+ return 0;
+}
+
+static error_t
+rootdir_gc_meminfo (void *hook, char **contents, ssize_t *contents_len)
+{
+ host_basic_info_data_t hbi;
+ mach_msg_type_number_t cnt;
+ struct vm_statistics vmstats;
+ default_pager_info_t swap;
+ error_t err;
+
+ err = vm_statistics (mach_task_self (), &vmstats);
+ if (err)
+ return EIO;
+
+ cnt = HOST_BASIC_INFO_COUNT;
+ err = host_info (mach_host_self (), HOST_BASIC_INFO, (host_info_t) &hbi, &cnt);
+ if (err)
+ return err;
+
+ err = get_swapinfo (&swap);
+ if (err)
+ return err;
+
+ assert (cnt == HOST_BASIC_INFO_COUNT);
+ *contents_len = asprintf (contents,
+ "MemTotal: %14lu kB\n"
+ "MemFree: %14lu kB\n"
+ "Buffers: %14lu kB\n"
+ "Cached: %14lu kB\n"
+ "Active: %14lu kB\n"
+ "Inactive: %14lu kB\n"
+ "Mlocked: %14lu kB\n"
+ "SwapTotal:%14lu kB\n"
+ "SwapFree: %14lu kB\n"
+ ,
+ (long unsigned) hbi.memory_size / 1024,
+ (long unsigned) vmstats.free_count * PAGE_SIZE / 1024,
+ 0,
+ 0,
+ (long unsigned) vmstats.active_count * PAGE_SIZE / 1024,
+ (long unsigned) vmstats.inactive_count * PAGE_SIZE / 1024,
+ (long unsigned) vmstats.wire_count * PAGE_SIZE / 1024,
+ (long unsigned) swap.dpi_total_space / 1024,
+ (long unsigned) swap.dpi_free_space / 1024);
+
+ return 0;
+}
+
+static error_t
+rootdir_gc_vmstat (void *hook, char **contents, ssize_t *contents_len)
+{
+ host_basic_info_data_t hbi;
+ mach_msg_type_number_t cnt;
+ struct vm_statistics vmstats;
+ error_t err;
+
+ err = vm_statistics (mach_task_self (), &vmstats);
+ if (err)
+ return EIO;
+
+ cnt = HOST_BASIC_INFO_COUNT;
+ err = host_info (mach_host_self (), HOST_BASIC_INFO, (host_info_t) &hbi, &cnt);
+ if (err)
+ return err;
+
+ assert (cnt == HOST_BASIC_INFO_COUNT);
+ *contents_len = asprintf (contents,
+ "nr_free_pages %lu\n"
+ "nr_inactive_anon %lu\n"
+ "nr_active_anon %lu\n"
+ "nr_inactive_file %lu\n"
+ "nr_active_file %lu\n"
+ "nr_unevictable %lu\n"
+ "nr_mlock %lu\n"
+ "pgpgin %lu\n"
+ "pgpgout %lu\n"
+ "pgfault %lu\n",
+ (long unsigned) vmstats.free_count,
+ /* FIXME: how can we distinguish the anon/file pages? Maybe we can
+ ask the default pager how many it manages? */
+ (long unsigned) vmstats.inactive_count,
+ (long unsigned) vmstats.active_count,
+ (long unsigned) 0,
+ (long unsigned) 0,
+ (long unsigned) vmstats.wire_count,
+ (long unsigned) vmstats.wire_count,
+ (long unsigned) vmstats.pageins,
+ (long unsigned) vmstats.pageouts,
+ (long unsigned) vmstats.faults);
+
+ return 0;
+}
+
+static error_t
+rootdir_gc_cmdline (void *hook, char **contents, ssize_t *contents_len)
+{
+ struct ps_context *pc = hook;
+ struct proc_stat *ps;
+ error_t err;
+
+ err = _proc_stat_create (opt_kernel_pid, pc, &ps);
+ if (err)
+ return EIO;
+
+ err = proc_stat_set_flags (ps, PSTAT_ARGS);
+ if (err || ! (proc_stat_flags (ps) & PSTAT_ARGS))
+ {
+ err = EIO;
+ goto out;
+ }
+
+ *contents_len = proc_stat_args_len (ps);
+ *contents = malloc (*contents_len);
+ if (! *contents)
+ {
+ err = ENOMEM;
+ goto out;
+ }
+
+ memcpy (*contents, proc_stat_args (ps), *contents_len);
+ argz_stringify (*contents, *contents_len, ' ');
+ (*contents)[*contents_len - 1] = '\n';
+
+out:
+ _proc_stat_free (ps);
+ return err;
+}
+
+static int
+rootdir_fakeself_exists ()
+{
+ return opt_fake_self >= 0;
+}
+
+static error_t
+rootdir_gc_fakeself (void *hook, char **contents, ssize_t *contents_len)
+{
+ *contents_len = asprintf (contents, "%d", opt_fake_self);
+ return 0;
+}
+
+
+/* Glue logic and entries table */
+
+static struct node *
+rootdir_file_make_node (void *dir_hook, const void *entry_hook)
+{
+ /* The entry hook we use is actually a procfs_node_ops for the file to be
+ created. The hook associated to these newly created files (and passed
+ to the generators above as a consequence) is always the same global
+ ps_context, which we get from rootdir_make_node as the directory hook. */
+ return procfs_make_node (entry_hook, dir_hook);
+}
+
+static struct node *
+rootdir_symlink_make_node (void *dir_hook, const void *entry_hook)
+{
+ struct node *np = procfs_make_node (entry_hook, dir_hook);
+ if (np)
+ procfs_node_chtype (np, S_IFLNK);
+ return np;
+}
+
+static const struct procfs_dir_entry rootdir_entries[] = {
+ {
+ .name = "self",
+ .hook = & (struct procfs_node_ops) {
+ .get_contents = rootdir_gc_fakeself,
+ .cleanup_contents = procfs_cleanup_contents_with_free,
+ },
+ .ops = {
+ .make_node = rootdir_symlink_make_node,
+ .exists = rootdir_fakeself_exists,
+ }
+ },
+ {
+ .name = "version",
+ .hook = & (struct procfs_node_ops) {
+ .get_contents = rootdir_gc_version,
+ .cleanup_contents = procfs_cleanup_contents_with_free,
+ },
+ },
+ {
+ .name = "uptime",
+ .hook = & (struct procfs_node_ops) {
+ .get_contents = rootdir_gc_uptime,
+ .cleanup_contents = procfs_cleanup_contents_with_free,
+ },
+ },
+ {
+ .name = "stat",
+ .hook = & (struct procfs_node_ops) {
+ .get_contents = rootdir_gc_stat,
+ .cleanup_contents = procfs_cleanup_contents_with_free,
+ },
+ },
+ {
+ .name = "loadavg",
+ .hook = & (struct procfs_node_ops) {
+ .get_contents = rootdir_gc_loadavg,
+ .cleanup_contents = procfs_cleanup_contents_with_free,
+ },
+ },
+ {
+ .name = "meminfo",
+ .hook = & (struct procfs_node_ops) {
+ .get_contents = rootdir_gc_meminfo,
+ .cleanup_contents = procfs_cleanup_contents_with_free,
+ },
+ },
+ {
+ .name = "vmstat",
+ .hook = & (struct procfs_node_ops) {
+ .get_contents = rootdir_gc_vmstat,
+ .cleanup_contents = procfs_cleanup_contents_with_free,
+ },
+ },
+ {
+ .name = "cmdline",
+ .hook = & (struct procfs_node_ops) {
+ .get_contents = rootdir_gc_cmdline,
+ .cleanup_contents = procfs_cleanup_contents_with_free,
+ },
+ },
+#ifdef PROFILE
+ /* In order to get a usable gmon.out file, we must apparently use exit(). */
+ {
+ .name = "exit",
+ .ops = {
+ .make_node = exit,
+ },
+ },
+#endif
+ {}
+};
+
+struct node
+*rootdir_make_node (struct ps_context *pc)
+{
+ static const struct procfs_dir_ops ops = {
+ .entries = rootdir_entries,
+ .entry_ops = {
+ .make_node = rootdir_file_make_node,
+ },
+ };
+ return procfs_dir_make_node (&ops, pc);
+}
+
diff --git a/procfs/rootdir.h b/procfs/rootdir.h
new file mode 100644
index 00000000..6980da8f
--- /dev/null
+++ b/procfs/rootdir.h
@@ -0,0 +1,23 @@
+/* Hurd /proc filesystem, permanent files of the root directory.
+ Copyright (C) 2010 Free Software Foundation, Inc.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#include <ps.h>
+
+struct node *
+rootdir_make_node (struct ps_context *pc);
diff --git a/random/Makefile b/random/Makefile
new file mode 100644
index 00000000..9b3a95dd
--- /dev/null
+++ b/random/Makefile
@@ -0,0 +1,29 @@
+#
+# Copyright (C) 1994,95,96,97,99,2000,2001 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2, or (at
+# your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+dir := random
+makemode := server
+
+CFLAGS += -D__HURD__
+
+target = random
+SRCS = random.c gnupg-random.c gnupg-rmd160.c
+OBJS = $(SRCS:.c=.o) startup_notifyServer.o
+LCLHDRS = gnupg-random.h gnupg-rmd.h gnupg-bithelp.h random.h
+HURDLIBS = trivfs threads ports fshelp ihash shouldbeinlibc
+
+include ../Makeconf
diff --git a/random/TODO b/random/TODO
new file mode 100644
index 00000000..9cc57ab9
--- /dev/null
+++ b/random/TODO
@@ -0,0 +1,11 @@
+* read_poll uses random_poll until the pool is filled. This is ian
+ issue at first initialization, as this requries POOLSIZE good random (level 1 from
+ gather_random) even in level 0 and 1.
+ For now, the code is only applied to level 2. Eventually, readable_pool
+ should be fixed to return 0 if initialization is not done yet and not enough bytes
+ are available. Otherwise it enters an infinite loop.
+
+* Permissions?
+
+* Off by one error in gather_random/io_write? I can only get GATHERBUFSIZE - 1
+ bytes from it.
diff --git a/random/gnupg-bithelp.h b/random/gnupg-bithelp.h
new file mode 100644
index 00000000..188db168
--- /dev/null
+++ b/random/gnupg-bithelp.h
@@ -0,0 +1,41 @@
+/* bithelp.h - Some bit manipulation helpers
+ * Copyright (C) 1999 Free Software Foundation, Inc.
+ *
+ * This file is part of GnuPG.
+ *
+ * GnuPG is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * GnuPG is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+#ifndef G10_BITHELP_H
+#define G10_BITHELP_H
+
+
+/****************
+ * Rotate a 32 bit integer by n bytes
+ */
+#if defined(__GNUC__) && defined(__i386__)
+static inline u32
+rol( u32 x, int n)
+{
+ __asm__("roll %%cl,%0"
+ :"=r" (x)
+ :"0" (x),"c" (n));
+ return x;
+}
+#else
+ #define rol(x,n) ( ((x) << (n)) | ((x) >> (32-(n))) )
+#endif
+
+
+#endif /*G10_BITHELP_H*/
diff --git a/random/gnupg-glue.h b/random/gnupg-glue.h
new file mode 100644
index 00000000..cbf0a103
--- /dev/null
+++ b/random/gnupg-glue.h
@@ -0,0 +1,40 @@
+#ifndef __GNUPG_GLUE_H__
+#define __GNUPG_GLUE_H__
+
+#include <sys/types.h>
+#include <random.h>
+
+#define SIZEOF_UNSIGNED_LONG 4
+typedef unsigned int u32;
+typedef unsigned char byte;
+
+/* GnuPG's config.h */
+#define HAVE_GETTIMEOFDAY 1
+#define HAVE_GETRUSAGE 1
+#define HAVE_RAND 1
+
+/* GnuPG's memory.h */
+#define m_alloc malloc
+#define m_alloc_secure malloc
+#define m_alloc_clear(x) calloc(x, 1)
+#define m_alloc_secure_clear(x) calloc(x, 1)
+#define m_free free
+#define m_strdup strdup
+
+/* GnuPG's dynaload.h */
+#define dynload_getfnc_fast_random_poll() (0)
+#define dynload_getfnc_gather_random() &gather_random
+int
+gather_random( void (*add)(const void*, size_t, int), int requester,
+ size_t length, int level );
+
+/* GnuPG's miscellaneous stuff. */
+#define BUG() assert(0)
+#define _(x) x
+#define make_timestamp() time(0)
+#define tty_printf printf
+#define log_info(format, args...) printf(format , ## args)
+#define log_fatal(format, args...) { printf(format , ## args) ; exit(2); }
+#define DIM(v) (sizeof(v)/sizeof((v)[0]))
+
+#endif /* __GNUPG_GLUE_H__ */
diff --git a/random/gnupg-random.c b/random/gnupg-random.c
new file mode 100644
index 00000000..8f308621
--- /dev/null
+++ b/random/gnupg-random.c
@@ -0,0 +1,810 @@
+/* random.c - random number generator
+ * Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
+ *
+ * This file is part of GnuPG.
+ *
+ * GnuPG is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * GnuPG is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+
+/****************
+ * This random number generator is modelled after the one described
+ * in Peter Gutmann's Paper: "Software Generation of Practically
+ * Strong Random Numbers".
+ */
+
+#ifndef __HURD__
+#include <config.h>
+#else
+#include "gnupg-glue.h"
+#endif
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <errno.h>
+#include <string.h>
+#include <time.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <fcntl.h>
+#ifdef HAVE_GETHRTIME
+ #include <sys/times.h>
+#endif
+#ifdef HAVE_GETTIMEOFDAY
+ #include <sys/times.h>
+#endif
+#ifdef HAVE_GETRUSAGE
+ #include <sys/resource.h>
+#endif
+#ifdef __MINGW32__
+ #include <process.h>
+#endif
+#ifndef __HURD__
+#include "util.h"
+#endif
+#ifndef __HURD__
+#include "rmd.h"
+#include "ttyio.h"
+#include "i18n.h"
+#include "random.h"
+#include "rand-internal.h"
+#include "dynload.h"
+#else
+#include "gnupg-rmd.h"
+#include "gnupg-random.h"
+#endif
+
+#ifndef RAND_MAX /* for SunOS */
+ #define RAND_MAX 32767
+#endif
+
+
+#if SIZEOF_UNSIGNED_LONG == 8
+ #define ADD_VALUE 0xa5a5a5a5a5a5a5a5
+#elif SIZEOF_UNSIGNED_LONG == 4
+ #define ADD_VALUE 0xa5a5a5a5
+#else
+ #error weird size for an unsigned long
+#endif
+
+#define BLOCKLEN 64 /* hash this amount of bytes */
+#define DIGESTLEN 20 /* into a digest of this length (rmd160) */
+/* poolblocks is the number of digests which make up the pool
+ * and poolsize must be a multiple of the digest length
+ * to make the AND operations faster, the size should also be
+ * a multiple of ulong
+ */
+#define POOLBLOCKS 30
+#define POOLSIZE (POOLBLOCKS*DIGESTLEN)
+#if (POOLSIZE % SIZEOF_UNSIGNED_LONG)
+ #error Please make sure that poolsize is a multiple of ulong
+#endif
+#define POOLWORDS (POOLSIZE / SIZEOF_UNSIGNED_LONG)
+
+
+static int is_initialized;
+#define MASK_LEVEL(a) do {if( a > 2 ) a = 2; else if( a < 0 ) a = 0; } while(0)
+static char *rndpool; /* allocated size is POOLSIZE+BLOCKLEN */
+static char *keypool; /* allocated size is POOLSIZE+BLOCKLEN */
+static size_t pool_readpos;
+static size_t pool_writepos;
+static int pool_filled;
+static int pool_balance;
+static int just_mixed;
+static int did_initial_extra_seeding;
+static char *seed_file_name;
+static int allow_seed_file_update;
+
+static int secure_alloc;
+static int quick_test;
+static int faked_rng;
+
+
+#ifndef __HURD__
+static void read_pool( byte *buffer, size_t length, int level );
+#else
+int read_pool( byte *buffer, size_t length, int level );
+#endif
+static void add_randomness( const void *buffer, size_t length, int source );
+static void random_poll(void);
+#ifndef __HURD__
+static void read_random_source( int requester, size_t length, int level);
+#else
+static int read_random_source( int requester, size_t length, int level);
+#endif
+static int gather_faked( void (*add)(const void*, size_t, int), int requester,
+ size_t length, int level );
+
+static struct {
+ ulong mixrnd;
+ ulong mixkey;
+ ulong slowpolls;
+ ulong fastpolls;
+ ulong getbytes1;
+ ulong ngetbytes1;
+ ulong getbytes2;
+ ulong ngetbytes2;
+ ulong addbytes;
+ ulong naddbytes;
+} rndstats;
+
+static void
+initialize(void)
+{
+ /* The data buffer is allocated somewhat larger, so that
+ * we can use this extra space (which is allocated in secure memory)
+ * as a temporary hash buffer */
+ rndpool = secure_alloc ? m_alloc_secure_clear(POOLSIZE+BLOCKLEN)
+ : m_alloc_clear(POOLSIZE+BLOCKLEN);
+ keypool = secure_alloc ? m_alloc_secure_clear(POOLSIZE+BLOCKLEN)
+ : m_alloc_clear(POOLSIZE+BLOCKLEN);
+ is_initialized = 1;
+#ifndef __HURD__
+ cipher_modules_constructor();
+#endif
+}
+
+static void
+burn_stack (int bytes)
+{
+ char buf[128];
+
+ memset (buf, 0, sizeof buf);
+ bytes -= sizeof buf;
+ if (bytes > 0)
+ burn_stack (bytes);
+}
+
+void
+random_dump_stats()
+{
+ fprintf(stderr,
+ "random usage: poolsize=%d mixed=%lu polls=%lu/%lu added=%lu/%lu\n"
+ " outmix=%lu getlvl1=%lu/%lu getlvl2=%lu/%lu\n",
+ POOLSIZE, rndstats.mixrnd, rndstats.slowpolls, rndstats.fastpolls,
+ rndstats.naddbytes, rndstats.addbytes,
+ rndstats.mixkey, rndstats.ngetbytes1, rndstats.getbytes1,
+ rndstats.ngetbytes2, rndstats.getbytes2 );
+}
+
+void
+secure_random_alloc()
+{
+ secure_alloc = 1;
+}
+
+
+int
+quick_random_gen( int onoff )
+{
+ int last;
+
+ read_random_source(0,0,0); /* init */
+ last = quick_test;
+ if( onoff != -1 )
+ quick_test = onoff;
+ return faked_rng? 1 : last;
+}
+
+
+/****************
+ * Fill the buffer with LENGTH bytes of cryptographically strong
+ * random bytes. level 0 is not very strong, 1 is strong enough
+ * for most usage, 2 is good for key generation stuff but may be very slow.
+ */
+void
+randomize_buffer( byte *buffer, size_t length, int level )
+{
+ char *p = get_random_bits( length*8, level, 1 );
+ memcpy( buffer, p, length );
+ m_free(p);
+}
+
+
+int
+random_is_faked()
+{
+ if( !is_initialized )
+ initialize();
+ return faked_rng || quick_test;
+}
+
+/****************
+ * Return a pointer to a randomized buffer of level 0 and LENGTH bits
+ * caller must free the buffer.
+ * Note: The returned value is rounded up to bytes.
+ */
+byte *
+get_random_bits( size_t nbits, int level, int secure )
+{
+ byte *buf, *p;
+ size_t nbytes = (nbits+7)/8;
+
+ if( quick_test && level > 1 )
+ level = 1;
+ MASK_LEVEL(level);
+ if( level == 1 ) {
+ rndstats.getbytes1 += nbytes;
+ rndstats.ngetbytes1++;
+ }
+ else if( level >= 2 ) {
+ rndstats.getbytes2 += nbytes;
+ rndstats.ngetbytes2++;
+ }
+
+ buf = secure && secure_alloc ? m_alloc_secure( nbytes ) : m_alloc( nbytes );
+ for( p = buf; nbytes > 0; ) {
+ size_t n = nbytes > POOLSIZE? POOLSIZE : nbytes;
+#ifdef __HURD__
+ n =
+#endif
+ read_pool( p, n, level );
+ nbytes -= n;
+ p += n;
+
+ }
+ return buf;
+}
+
+
+/****************
+ * Mix the pool
+ */
+static void
+mix_pool(byte *pool)
+{
+ char *hashbuf = pool + POOLSIZE;
+ char *p, *pend;
+ int i, n;
+ RMD160_CONTEXT md;
+
+ rmd160_init( &md );
+ #if DIGESTLEN != 20
+ #error must have a digest length of 20 for ripe-md-160
+ #endif
+ /* loop over the pool */
+ pend = pool + POOLSIZE;
+ memcpy(hashbuf, pend - DIGESTLEN, DIGESTLEN );
+ memcpy(hashbuf+DIGESTLEN, pool, BLOCKLEN-DIGESTLEN);
+ rmd160_mixblock( &md, hashbuf);
+ memcpy(pool, hashbuf, 20 );
+
+ p = pool;
+ for( n=1; n < POOLBLOCKS; n++ ) {
+ memcpy(hashbuf, p, DIGESTLEN );
+
+ p += DIGESTLEN;
+ if( p+DIGESTLEN+BLOCKLEN < pend )
+ memcpy(hashbuf+DIGESTLEN, p+DIGESTLEN, BLOCKLEN-DIGESTLEN);
+ else {
+ char *pp = p+DIGESTLEN;
+ for(i=DIGESTLEN; i < BLOCKLEN; i++ ) {
+ if( pp >= pend )
+ pp = pool;
+ hashbuf[i] = *pp++;
+ }
+ }
+
+ rmd160_mixblock( &md, hashbuf);
+ memcpy(p, hashbuf, 20 );
+ }
+ burn_stack (200); /* for the rmd160_mixblock() */
+}
+
+
+void
+set_random_seed_file( const char *name )
+{
+ if( seed_file_name )
+ BUG();
+ seed_file_name = m_strdup( name );
+}
+
+/****************
+ * Read in a seed form the random_seed file
+ * and return true if this was successful
+ */
+static int
+read_seed_file()
+{
+ int fd;
+ struct stat sb;
+ unsigned char buffer[POOLSIZE];
+ int n;
+
+ if( !seed_file_name )
+ return 0;
+
+ #ifdef HAVE_DOSISH_SYSTEM
+ fd = open( seed_file_name, O_RDONLY | O_BINARY );
+ #else
+ fd = open( seed_file_name, O_RDONLY );
+ #endif
+ if( fd == -1 && errno == ENOENT) {
+ allow_seed_file_update = 1;
+ return 0;
+ }
+
+ if( fd == -1 ) {
+ log_info(_("can't open `%s': %s\n"), seed_file_name, strerror(errno) );
+ return 0;
+ }
+ if( fstat( fd, &sb ) ) {
+ log_info(_("can't stat `%s': %s\n"), seed_file_name, strerror(errno) );
+ close(fd);
+ return 0;
+ }
+ if( !S_ISREG(sb.st_mode) ) {
+ log_info(_("`%s' is not a regular file - ignored\n"), seed_file_name );
+ close(fd);
+ return 0;
+ }
+ if( !sb.st_size ) {
+ log_info(_("note: random_seed file is empty\n") );
+ close(fd);
+ allow_seed_file_update = 1;
+ return 0;
+ }
+ if( sb.st_size != POOLSIZE ) {
+ log_info(_("warning: invalid size of random_seed file - not used\n") );
+ close(fd);
+ return 0;
+ }
+ do {
+ n = read( fd, buffer, POOLSIZE );
+ } while( n == -1 && errno == EINTR );
+ if( n != POOLSIZE ) {
+ log_fatal(_("can't read `%s': %s\n"), seed_file_name,strerror(errno) );
+ close(fd);
+ return 0;
+ }
+
+ close(fd);
+
+ add_randomness( buffer, POOLSIZE, 0 );
+ /* add some minor entropy to the pool now (this will also force a mixing) */
+ { pid_t x = getpid();
+ add_randomness( &x, sizeof(x), 0 );
+ }
+ { time_t x = time(NULL);
+ add_randomness( &x, sizeof(x), 0 );
+ }
+ { clock_t x = clock();
+ add_randomness( &x, sizeof(x), 0 );
+ }
+ /* And read a few bytes from our entropy source. By using
+ * a level of 0 this will not block and might not return anything
+ * with some entropy drivers, however the rndlinux driver will use
+ * /dev/urandom and return some stuff - Do not read to much as we
+ * want to be friendly to the scare system entropy resource. */
+ read_random_source( 0, 16, 0 );
+
+ allow_seed_file_update = 1;
+ return 1;
+}
+
+void
+update_random_seed_file()
+{
+ ulong *sp, *dp;
+ int fd, i;
+
+ if( !seed_file_name || !is_initialized || !pool_filled )
+ return;
+ if( !allow_seed_file_update ) {
+ log_info(_("note: random_seed file not updated\n"));
+ return;
+ }
+
+
+ /* copy the entropy pool to a scratch pool and mix both of them */
+ for(i=0,dp=(ulong*)keypool, sp=(ulong*)rndpool;
+ i < POOLWORDS; i++, dp++, sp++ ) {
+ *dp = *sp + ADD_VALUE;
+ }
+ mix_pool(rndpool); rndstats.mixrnd++;
+ mix_pool(keypool); rndstats.mixkey++;
+
+ #ifdef HAVE_DOSISH_SYSTEM
+ fd = open( seed_file_name, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY,
+ S_IRUSR|S_IWUSR );
+ #else
+ fd = open( seed_file_name, O_WRONLY|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR );
+ #endif
+ if( fd == -1 ) {
+ log_info(_("can't create `%s': %s\n"), seed_file_name, strerror(errno) );
+ return;
+ }
+ do {
+ i = write( fd, keypool, POOLSIZE );
+ } while( i == -1 && errno == EINTR );
+ if( i != POOLSIZE ) {
+ log_info(_("can't write `%s': %s\n"), seed_file_name, strerror(errno) );
+ }
+ if( close(fd) )
+ log_info(_("can't close `%s': %s\n"), seed_file_name, strerror(errno) );
+}
+
+#ifdef __HURD__
+int readable_pool( size_t length, int level )
+{
+ size_t needed = 0;
+ size_t my_balance = pool_balance;
+ size_t available = (gatherwpos - gatherrpos + GATHERBUFSIZE) % GATHERBUFSIZE;
+
+ if (length > POOLSIZE)
+ length = POOLSIZE;
+
+ if (level < 2)
+ return length;
+
+ if( !pool_filled ) {
+ if( read_seed_file() )
+ pool_filled = 1;
+ }
+
+ if (!did_initial_extra_seeding)
+ {
+ /* Take account for initial extra seeding. */
+ needed = length;
+ if (needed < POOLSIZE/2)
+ needed = POOLSIZE/2;
+ my_balance = needed;
+
+ if (!pool_filled && pool_writepos + needed < POOLSIZE)
+ {
+ /* If the pool is not filled yet, we couldn't read the seed
+ file. Too bad. We will now have to take account for so many
+ random_poll()s as fit into the remaining pool. */
+
+ needed += (POOLSIZE - pool_writepos + needed + POOLSIZE/5 - 1) / (POOLSIZE/5);
+ }
+ }
+ else
+ {
+ if (!pool_filled)
+ needed += (POOLSIZE - pool_writepos + needed + POOLSIZE/5 - 1) / (POOLSIZE/5);
+ }
+
+ /* NEEDED contains the bytes needed for initialization, MY_BALANCE the resulting
+ available bytes. */
+ if (available < needed)
+ return 0;
+ return available + my_balance - needed;
+}
+#endif
+
+#ifndef __HURD__
+static void
+#else
+int
+#endif
+read_pool( byte *buffer, size_t length, int level )
+{
+ int i;
+ ulong *sp, *dp;
+
+ if( length > POOLSIZE ) {
+#ifndef __HURD__
+ log_fatal(_("too many random bits requested; the limit is %d\n"),
+ POOLSIZE*8-1 );
+#else
+ length = POOLSIZE;
+#endif
+ }
+
+ if( !pool_filled ) {
+ if( read_seed_file() )
+ pool_filled = 1;
+ }
+
+ /* For level 2 quality (key generation) we alwas make
+ * sure that the pool has been seeded enough initially */
+ if( level == 2 && !did_initial_extra_seeding ) {
+ size_t needed;
+
+ pool_balance = 0;
+ needed = length - pool_balance;
+ if( needed < POOLSIZE/2 )
+ needed = POOLSIZE/2;
+ else if( needed > POOLSIZE )
+ BUG();
+#ifdef __HURD__
+ needed =
+#endif
+ read_random_source( 3, needed, 2 );
+#ifdef __HURD__
+ if (! needed)
+ return 0;
+ /* XXX This will succeed with needed < POOLSIZE/2 even. But
+ erroring out will waste the random we already got. */
+#endif
+ pool_balance += needed;
+ did_initial_extra_seeding=1;
+ }
+
+ /* for level 2 make sure that there is enough random in the pool */
+ if( level == 2 && pool_balance < length ) {
+ size_t needed;
+
+ if( pool_balance < 0 )
+ pool_balance = 0;
+ needed = length - pool_balance;
+ if( needed > POOLSIZE )
+ BUG();
+#ifdef __HURD__
+ needed =
+#endif
+ read_random_source( 3, needed, 2 );
+ pool_balance += needed;
+ }
+
+#ifdef __HURD__
+ /* XXX This makes level 0 and 1 worse than needed at first start up. */
+ if (level == 2)
+#endif
+ /* make sure the pool is filled */
+ while( !pool_filled )
+ random_poll();
+
+ /* do always a fast random poll */
+ fast_random_poll();
+
+ if( !level ) { /* no need for cryptographic strong random */
+ /* create a new pool */
+ for(i=0,dp=(ulong*)keypool, sp=(ulong*)rndpool;
+ i < POOLWORDS; i++, dp++, sp++ )
+ *dp = *sp + ADD_VALUE;
+ /* must mix both pools */
+ mix_pool(rndpool); rndstats.mixrnd++;
+ mix_pool(keypool); rndstats.mixkey++;
+ memcpy( buffer, keypool, length );
+ return length;
+ }
+ else {
+#ifdef __HURD__
+ int amount;
+#endif
+ /* mix the pool (if add_randomness() didn't it) */
+ if( !just_mixed ) {
+ mix_pool(rndpool);
+ rndstats.mixrnd++;
+ }
+ /* create a new pool */
+ for(i=0,dp=(ulong*)keypool, sp=(ulong*)rndpool;
+ i < POOLWORDS; i++, dp++, sp++ )
+ *dp = *sp + ADD_VALUE;
+ /* and mix both pools */
+ mix_pool(rndpool); rndstats.mixrnd++;
+ mix_pool(keypool); rndstats.mixkey++;
+ /* read the required data
+ * we use a readpoiter to read from a different postion each
+ * time */
+#ifdef __HURD__
+ if (level == 2 && length > pool_balance)
+ length = pool_balance;
+ amount = length;
+#endif
+ while( length-- ) {
+ *buffer++ = keypool[pool_readpos++];
+ if( pool_readpos >= POOLSIZE )
+ pool_readpos = 0;
+ pool_balance--;
+ }
+ if( pool_balance < 0 )
+ pool_balance = 0;
+ /* and clear the keypool */
+ memset( keypool, 0, POOLSIZE );
+#ifdef __HURD__
+ return amount;
+#endif
+ }
+}
+
+
+/****************
+ * Add LENGTH bytes of randomness from buffer to the pool.
+ * source may be used to specify the randomness source.
+ * Source is:
+ * 0 - used ony for initialization
+ * 1 - fast random poll function
+ * 2 - normal poll function
+ * 3 - used when level 2 random quality has been requested
+ * to do an extra pool seed.
+ */
+static void
+add_randomness( const void *buffer, size_t length, int source )
+{
+ const byte *p = buffer;
+
+ if( !is_initialized )
+ initialize();
+ rndstats.addbytes += length;
+ rndstats.naddbytes++;
+ while( length-- ) {
+ rndpool[pool_writepos++] = *p++;
+ if( pool_writepos >= POOLSIZE ) {
+ if( source > 1 )
+ pool_filled = 1;
+ pool_writepos = 0;
+ mix_pool(rndpool); rndstats.mixrnd++;
+ just_mixed = !length;
+ }
+ }
+}
+
+
+
+static void
+random_poll()
+{
+ rndstats.slowpolls++;
+ read_random_source( 2, POOLSIZE/5, 1 );
+}
+
+
+void
+fast_random_poll()
+{
+ static void (*fnc)( void (*)(const void*, size_t, int), int) = NULL;
+ static int initialized = 0;
+
+ rndstats.fastpolls++;
+ if( !initialized ) {
+ if( !is_initialized )
+ initialize();
+ initialized = 1;
+ fnc = dynload_getfnc_fast_random_poll();
+ }
+ if( fnc ) {
+ (*fnc)( add_randomness, 1 );
+ return;
+ }
+
+ /* fall back to the generic function */
+ #if HAVE_GETHRTIME
+ { hrtime_t tv;
+ tv = gethrtime();
+ add_randomness( &tv, sizeof(tv), 1 );
+ }
+ #elif HAVE_GETTIMEOFDAY
+ { struct timeval tv;
+ if( gettimeofday( &tv, NULL ) )
+ BUG();
+ add_randomness( &tv.tv_sec, sizeof(tv.tv_sec), 1 );
+ add_randomness( &tv.tv_usec, sizeof(tv.tv_usec), 1 );
+ }
+ #elif HAVE_CLOCK_GETTIME
+ { struct timespec tv;
+ if( clock_gettime( CLOCK_REALTIME, &tv ) == -1 )
+ BUG();
+ add_randomness( &tv.tv_sec, sizeof(tv.tv_sec), 1 );
+ add_randomness( &tv.tv_nsec, sizeof(tv.tv_nsec), 1 );
+ }
+ #else /* use times */
+ #ifndef HAVE_DOSISH_SYSTEM
+ { struct tms buf;
+ times( &buf );
+ add_randomness( &buf, sizeof buf, 1 );
+ }
+ #endif
+ #endif
+ #ifdef HAVE_GETRUSAGE
+ #ifndef RUSAGE_SELF
+ #ifdef __GCC__
+ #warning There is no RUSAGE_SELF on this system
+ #endif
+ #else
+ { struct rusage buf;
+ /* QNX/Neutrino does return ENOSYS - so we just ignore it and
+ * add whatever is in buf. In a chroot environment it might not
+ * work at all (i.e. because /proc/ is not accessible), so we better
+ * ognore all error codes and hope for the best
+ */
+ getrusage( RUSAGE_SELF, &buf );
+
+ add_randomness( &buf, sizeof buf, 1 );
+ memset( &buf, 0, sizeof buf );
+ }
+ #endif
+ #endif
+ /* time and clock are availabe on all systems - so
+ * we better do it just in case one of the above functions
+ * didn't work */
+ { time_t x = time(NULL);
+ add_randomness( &x, sizeof(x), 1 );
+ }
+ { clock_t x = clock();
+ add_randomness( &x, sizeof(x), 1 );
+ }
+}
+
+
+#ifndef __HURD__
+static void
+#else
+static int
+#endif
+read_random_source( int requester, size_t length, int level )
+{
+ static int (*fnc)(void (*)(const void*, size_t, int), int,
+ size_t, int) = NULL;
+#ifdef __HURD__
+ int got;
+#endif
+ if( !fnc ) {
+ if( !is_initialized )
+ initialize();
+ fnc = dynload_getfnc_gather_random();
+ if( !fnc ) {
+ faked_rng = 1;
+ fnc = gather_faked;
+ }
+ if( !requester && !length && !level )
+#ifndef __HURD__
+ return; /* init only */
+#else
+ return 0;
+#endif
+ }
+#ifndef __HURD__
+ if( (*fnc)( add_randomness, requester, length, level ) < 0 )
+ log_fatal("No way to gather entropy for the RNG\n");
+#else
+ got = (*fnc)( add_randomness, requester, length, level );
+ if (got < 0)
+ log_fatal("No way to gather entropy for the RNG\n");
+ return got;
+#endif
+}
+
+
+static int
+gather_faked( void (*add)(const void*, size_t, int), int requester,
+ size_t length, int level )
+{
+ static int initialized=0;
+ size_t n;
+ char *buffer, *p;
+
+ if( !initialized ) {
+ log_info(_("WARNING: using insecure random number generator!!\n"));
+ tty_printf(_("The random number generator is only a kludge to let\n"
+ "it run - it is in no way a strong RNG!\n\n"
+ "DON'T USE ANY DATA GENERATED BY THIS PROGRAM!!\n\n"));
+ initialized=1;
+ #ifdef HAVE_RAND
+ srand(make_timestamp()*getpid());
+ #else
+ srandom(make_timestamp()*getpid());
+ #endif
+ }
+ printf("WAITING FOR %i bytes.\n", length);
+ p = buffer = m_alloc( length );
+ n = length;
+ #ifdef HAVE_RAND
+ while( n-- )
+ *p++ = ((unsigned)(1 + (int) (256.0*rand()/(RAND_MAX+1.0)))-1);
+ #else
+ while( n-- )
+ *p++ = ((unsigned)(1 + (int) (256.0*random()/(RAND_MAX+1.0)))-1);
+ #endif
+ add_randomness( buffer, length, requester );
+ m_free(buffer);
+ return 0; /* okay */
+}
+
diff --git a/random/gnupg-random.h b/random/gnupg-random.h
new file mode 100644
index 00000000..ee18febc
--- /dev/null
+++ b/random/gnupg-random.h
@@ -0,0 +1,47 @@
+/* random.h - random functions
+ * Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
+ *
+ * This file is part of GnuPG.
+ *
+ * GnuPG is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * GnuPG is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+#ifndef G10_RANDOM_H
+#define G10_RANDOM_H
+
+#ifndef __HURD__
+#include "types.h"
+#else
+#include "gnupg-glue.h"
+int read_pool (byte *, size_t, int);
+int readable_pool (size_t, int);
+#endif
+
+/*-- random.c --*/
+void random_dump_stats(void);
+void secure_random_alloc(void);
+void set_random_seed_file(const char *);
+void update_random_seed_file(void);
+int quick_random_gen( int onoff );
+int random_is_faked(void);
+void randomize_buffer( byte *buffer, size_t length, int level );
+byte *get_random_bits( size_t nbits, int level, int secure );
+void fast_random_poll( void );
+
+/*-- rndw32.c --*/
+#ifdef USE_STATIC_RNDW32
+void rndw32_set_dll_name( const char *name );
+#endif
+
+#endif /*G10_RANDOM_H*/
diff --git a/random/gnupg-rmd.h b/random/gnupg-rmd.h
new file mode 100644
index 00000000..2446fc7d
--- /dev/null
+++ b/random/gnupg-rmd.h
@@ -0,0 +1,38 @@
+/* rmd.h - RIPE-MD hash functions
+ * Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
+ *
+ * This file is part of GnuPG.
+ *
+ * GnuPG is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * GnuPG is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+#ifndef G10_RMD_H
+#define G10_RMD_H
+
+#ifdef __HURD__
+#include "gnupg-glue.h"
+#endif
+
+/* we need this here because random.c must have direct access */
+typedef struct {
+ u32 h0,h1,h2,h3,h4;
+ u32 nblocks;
+ byte buf[64];
+ int count;
+} RMD160_CONTEXT;
+
+void rmd160_init( RMD160_CONTEXT *hd );
+void rmd160_mixblock( RMD160_CONTEXT *hd, char *buffer );
+
+#endif /*G10_RMD_H*/
diff --git a/random/gnupg-rmd160.c b/random/gnupg-rmd160.c
new file mode 100644
index 00000000..66107685
--- /dev/null
+++ b/random/gnupg-rmd160.c
@@ -0,0 +1,656 @@
+/* rmd160.c - RIPE-MD160
+ * Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
+ *
+ * This file is part of GnuPG.
+ *
+ * GnuPG is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * GnuPG is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+#ifndef __HURD__
+#include <config.h>
+#endif
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#ifndef __HURD__
+#include "util.h"
+#include "memory.h"
+#include "rmd.h"
+#include "cipher.h" /* only used for the rmd160_hash_buffer() prototype */
+#include "dynload.h"
+
+#include "bithelp.h"
+#else
+#include "gnupg-rmd.h"
+#include "gnupg-bithelp.h"
+#endif
+
+
+/*********************************
+ * RIPEMD-160 is not patented, see (as of 25.10.97)
+ * http://www.esat.kuleuven.ac.be/~bosselae/ripemd160.html
+ * Note that the code uses Little Endian byteorder, which is good for
+ * 386 etc, but we must add some conversion when used on a big endian box.
+ *
+ *
+ * Pseudo-code for RIPEMD-160
+ *
+ * RIPEMD-160 is an iterative hash function that operates on 32-bit words.
+ * The round function takes as input a 5-word chaining variable and a 16-word
+ * message block and maps this to a new chaining variable. All operations are
+ * defined on 32-bit words. Padding is identical to that of MD4.
+ *
+ *
+ * RIPEMD-160: definitions
+ *
+ *
+ * nonlinear functions at bit level: exor, mux, -, mux, -
+ *
+ * f(j, x, y, z) = x XOR y XOR z (0 <= j <= 15)
+ * f(j, x, y, z) = (x AND y) OR (NOT(x) AND z) (16 <= j <= 31)
+ * f(j, x, y, z) = (x OR NOT(y)) XOR z (32 <= j <= 47)
+ * f(j, x, y, z) = (x AND z) OR (y AND NOT(z)) (48 <= j <= 63)
+ * f(j, x, y, z) = x XOR (y OR NOT(z)) (64 <= j <= 79)
+ *
+ *
+ * added constants (hexadecimal)
+ *
+ * K(j) = 0x00000000 (0 <= j <= 15)
+ * K(j) = 0x5A827999 (16 <= j <= 31) int(2**30 x sqrt(2))
+ * K(j) = 0x6ED9EBA1 (32 <= j <= 47) int(2**30 x sqrt(3))
+ * K(j) = 0x8F1BBCDC (48 <= j <= 63) int(2**30 x sqrt(5))
+ * K(j) = 0xA953FD4E (64 <= j <= 79) int(2**30 x sqrt(7))
+ * K'(j) = 0x50A28BE6 (0 <= j <= 15) int(2**30 x cbrt(2))
+ * K'(j) = 0x5C4DD124 (16 <= j <= 31) int(2**30 x cbrt(3))
+ * K'(j) = 0x6D703EF3 (32 <= j <= 47) int(2**30 x cbrt(5))
+ * K'(j) = 0x7A6D76E9 (48 <= j <= 63) int(2**30 x cbrt(7))
+ * K'(j) = 0x00000000 (64 <= j <= 79)
+ *
+ *
+ * selection of message word
+ *
+ * r(j) = j (0 <= j <= 15)
+ * r(16..31) = 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8
+ * r(32..47) = 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12
+ * r(48..63) = 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2
+ * r(64..79) = 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13
+ * r0(0..15) = 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12
+ * r0(16..31)= 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2
+ * r0(32..47)= 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13
+ * r0(48..63)= 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14
+ * r0(64..79)= 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11
+ *
+ *
+ * amount for rotate left (rol)
+ *
+ * s(0..15) = 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8
+ * s(16..31) = 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12
+ * s(32..47) = 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5
+ * s(48..63) = 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12
+ * s(64..79) = 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6
+ * s'(0..15) = 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6
+ * s'(16..31)= 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11
+ * s'(32..47)= 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5
+ * s'(48..63)= 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8
+ * s'(64..79)= 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11
+ *
+ *
+ * initial value (hexadecimal)
+ *
+ * h0 = 0x67452301; h1 = 0xEFCDAB89; h2 = 0x98BADCFE; h3 = 0x10325476;
+ * h4 = 0xC3D2E1F0;
+ *
+ *
+ * RIPEMD-160: pseudo-code
+ *
+ * It is assumed that the message after padding consists of t 16-word blocks
+ * that will be denoted with X[i][j], with 0 <= i <= t-1 and 0 <= j <= 15.
+ * The symbol [+] denotes addition modulo 2**32 and rol_s denotes cyclic left
+ * shift (rotate) over s positions.
+ *
+ *
+ * for i := 0 to t-1 {
+ * A := h0; B := h1; C := h2; D = h3; E = h4;
+ * A' := h0; B' := h1; C' := h2; D' = h3; E' = h4;
+ * for j := 0 to 79 {
+ * T := rol_s(j)(A [+] f(j, B, C, D) [+] X[i][r(j)] [+] K(j)) [+] E;
+ * A := E; E := D; D := rol_10(C); C := B; B := T;
+ * T := rol_s'(j)(A' [+] f(79-j, B', C', D') [+] X[i][r'(j)]
+ [+] K'(j)) [+] E';
+ * A' := E'; E' := D'; D' := rol_10(C'); C' := B'; B' := T;
+ * }
+ * T := h1 [+] C [+] D'; h1 := h2 [+] D [+] E'; h2 := h3 [+] E [+] A';
+ * h3 := h4 [+] A [+] B'; h4 := h0 [+] B [+] C'; h0 := T;
+ * }
+ */
+
+/* Some examples:
+ * "" 9c1185a5c5e9fc54612808977ee8f548b2258d31
+ * "a" 0bdc9d2d256b3ee9daae347be6f4dc835a467ffe
+ * "abc" 8eb208f7e05d987a9b044a8e98c6b087f15a0bfc
+ * "message digest" 5d0689ef49d2fae572b881b123a85ffa21595f36
+ * "a...z" f71c27109c692c1b56bbdceb5b9d2865b3708dbc
+ * "abcdbcde...nopq" 12a053384a9c0c88e405a06c27dcf49ada62eb2b
+ * "A...Za...z0...9" b0e20b6e3116640286ed3a87a5713079b21f5189
+ * 8 times "1234567890" 9b752e45573d4b39f4dbd3323cab82bf63326bfb
+ * 1 million times "a" 52783243c1697bdbe16d37f97f68f08325dc1528
+ */
+
+static void
+burn_stack (int bytes)
+{
+ char buf[150];
+
+ memset (buf, 0, sizeof buf);
+ bytes -= sizeof buf;
+ if (bytes > 0)
+ burn_stack (bytes);
+}
+
+
+
+void
+rmd160_init( RMD160_CONTEXT *hd )
+{
+ hd->h0 = 0x67452301;
+ hd->h1 = 0xEFCDAB89;
+ hd->h2 = 0x98BADCFE;
+ hd->h3 = 0x10325476;
+ hd->h4 = 0xC3D2E1F0;
+ hd->nblocks = 0;
+ hd->count = 0;
+}
+
+
+
+/****************
+ * Transform the message X which consists of 16 32-bit-words
+ */
+static void
+transform( RMD160_CONTEXT *hd, byte *data )
+{
+ u32 a,b,c,d,e,aa,bb,cc,dd,ee,t;
+ #ifdef BIG_ENDIAN_HOST
+ u32 x[16];
+ { int i;
+ byte *p2, *p1;
+ for(i=0, p1=data, p2=(byte*)x; i < 16; i++, p2 += 4 ) {
+ p2[3] = *p1++;
+ p2[2] = *p1++;
+ p2[1] = *p1++;
+ p2[0] = *p1++;
+ }
+ }
+ #else
+ #if 0
+ u32 *x =(u32*)data;
+ #else
+ /* this version is better because it is always aligned;
+ * The performance penalty on a 586-100 is about 6% which
+ * is acceptable - because the data is more local it might
+ * also be possible that this is faster on some machines.
+ * This function (when compiled with -02 on gcc 2.7.2)
+ * executes on a 586-100 (39.73 bogomips) at about 1900kb/sec;
+ * [measured with a 4MB data and "gpgm --print-md rmd160"] */
+ u32 x[16];
+ memcpy( x, data, 64 );
+ #endif
+ #endif
+
+
+#define K0 0x00000000
+#define K1 0x5A827999
+#define K2 0x6ED9EBA1
+#define K3 0x8F1BBCDC
+#define K4 0xA953FD4E
+#define KK0 0x50A28BE6
+#define KK1 0x5C4DD124
+#define KK2 0x6D703EF3
+#define KK3 0x7A6D76E9
+#define KK4 0x00000000
+#define F0(x,y,z) ( (x) ^ (y) ^ (z) )
+#define F1(x,y,z) ( ((x) & (y)) | (~(x) & (z)) )
+#define F2(x,y,z) ( ((x) | ~(y)) ^ (z) )
+#define F3(x,y,z) ( ((x) & (z)) | ((y) & ~(z)) )
+#define F4(x,y,z) ( (x) ^ ((y) | ~(z)) )
+#define R(a,b,c,d,e,f,k,r,s) do { t = a + f(b,c,d) + k + x[r]; \
+ a = rol(t,s) + e; \
+ c = rol(c,10); \
+ } while(0)
+
+ /* left lane */
+ a = hd->h0;
+ b = hd->h1;
+ c = hd->h2;
+ d = hd->h3;
+ e = hd->h4;
+ R( a, b, c, d, e, F0, K0, 0, 11 );
+ R( e, a, b, c, d, F0, K0, 1, 14 );
+ R( d, e, a, b, c, F0, K0, 2, 15 );
+ R( c, d, e, a, b, F0, K0, 3, 12 );
+ R( b, c, d, e, a, F0, K0, 4, 5 );
+ R( a, b, c, d, e, F0, K0, 5, 8 );
+ R( e, a, b, c, d, F0, K0, 6, 7 );
+ R( d, e, a, b, c, F0, K0, 7, 9 );
+ R( c, d, e, a, b, F0, K0, 8, 11 );
+ R( b, c, d, e, a, F0, K0, 9, 13 );
+ R( a, b, c, d, e, F0, K0, 10, 14 );
+ R( e, a, b, c, d, F0, K0, 11, 15 );
+ R( d, e, a, b, c, F0, K0, 12, 6 );
+ R( c, d, e, a, b, F0, K0, 13, 7 );
+ R( b, c, d, e, a, F0, K0, 14, 9 );
+ R( a, b, c, d, e, F0, K0, 15, 8 );
+ R( e, a, b, c, d, F1, K1, 7, 7 );
+ R( d, e, a, b, c, F1, K1, 4, 6 );
+ R( c, d, e, a, b, F1, K1, 13, 8 );
+ R( b, c, d, e, a, F1, K1, 1, 13 );
+ R( a, b, c, d, e, F1, K1, 10, 11 );
+ R( e, a, b, c, d, F1, K1, 6, 9 );
+ R( d, e, a, b, c, F1, K1, 15, 7 );
+ R( c, d, e, a, b, F1, K1, 3, 15 );
+ R( b, c, d, e, a, F1, K1, 12, 7 );
+ R( a, b, c, d, e, F1, K1, 0, 12 );
+ R( e, a, b, c, d, F1, K1, 9, 15 );
+ R( d, e, a, b, c, F1, K1, 5, 9 );
+ R( c, d, e, a, b, F1, K1, 2, 11 );
+ R( b, c, d, e, a, F1, K1, 14, 7 );
+ R( a, b, c, d, e, F1, K1, 11, 13 );
+ R( e, a, b, c, d, F1, K1, 8, 12 );
+ R( d, e, a, b, c, F2, K2, 3, 11 );
+ R( c, d, e, a, b, F2, K2, 10, 13 );
+ R( b, c, d, e, a, F2, K2, 14, 6 );
+ R( a, b, c, d, e, F2, K2, 4, 7 );
+ R( e, a, b, c, d, F2, K2, 9, 14 );
+ R( d, e, a, b, c, F2, K2, 15, 9 );
+ R( c, d, e, a, b, F2, K2, 8, 13 );
+ R( b, c, d, e, a, F2, K2, 1, 15 );
+ R( a, b, c, d, e, F2, K2, 2, 14 );
+ R( e, a, b, c, d, F2, K2, 7, 8 );
+ R( d, e, a, b, c, F2, K2, 0, 13 );
+ R( c, d, e, a, b, F2, K2, 6, 6 );
+ R( b, c, d, e, a, F2, K2, 13, 5 );
+ R( a, b, c, d, e, F2, K2, 11, 12 );
+ R( e, a, b, c, d, F2, K2, 5, 7 );
+ R( d, e, a, b, c, F2, K2, 12, 5 );
+ R( c, d, e, a, b, F3, K3, 1, 11 );
+ R( b, c, d, e, a, F3, K3, 9, 12 );
+ R( a, b, c, d, e, F3, K3, 11, 14 );
+ R( e, a, b, c, d, F3, K3, 10, 15 );
+ R( d, e, a, b, c, F3, K3, 0, 14 );
+ R( c, d, e, a, b, F3, K3, 8, 15 );
+ R( b, c, d, e, a, F3, K3, 12, 9 );
+ R( a, b, c, d, e, F3, K3, 4, 8 );
+ R( e, a, b, c, d, F3, K3, 13, 9 );
+ R( d, e, a, b, c, F3, K3, 3, 14 );
+ R( c, d, e, a, b, F3, K3, 7, 5 );
+ R( b, c, d, e, a, F3, K3, 15, 6 );
+ R( a, b, c, d, e, F3, K3, 14, 8 );
+ R( e, a, b, c, d, F3, K3, 5, 6 );
+ R( d, e, a, b, c, F3, K3, 6, 5 );
+ R( c, d, e, a, b, F3, K3, 2, 12 );
+ R( b, c, d, e, a, F4, K4, 4, 9 );
+ R( a, b, c, d, e, F4, K4, 0, 15 );
+ R( e, a, b, c, d, F4, K4, 5, 5 );
+ R( d, e, a, b, c, F4, K4, 9, 11 );
+ R( c, d, e, a, b, F4, K4, 7, 6 );
+ R( b, c, d, e, a, F4, K4, 12, 8 );
+ R( a, b, c, d, e, F4, K4, 2, 13 );
+ R( e, a, b, c, d, F4, K4, 10, 12 );
+ R( d, e, a, b, c, F4, K4, 14, 5 );
+ R( c, d, e, a, b, F4, K4, 1, 12 );
+ R( b, c, d, e, a, F4, K4, 3, 13 );
+ R( a, b, c, d, e, F4, K4, 8, 14 );
+ R( e, a, b, c, d, F4, K4, 11, 11 );
+ R( d, e, a, b, c, F4, K4, 6, 8 );
+ R( c, d, e, a, b, F4, K4, 15, 5 );
+ R( b, c, d, e, a, F4, K4, 13, 6 );
+
+ aa = a; bb = b; cc = c; dd = d; ee = e;
+
+ /* right lane */
+ a = hd->h0;
+ b = hd->h1;
+ c = hd->h2;
+ d = hd->h3;
+ e = hd->h4;
+ R( a, b, c, d, e, F4, KK0, 5, 8);
+ R( e, a, b, c, d, F4, KK0, 14, 9);
+ R( d, e, a, b, c, F4, KK0, 7, 9);
+ R( c, d, e, a, b, F4, KK0, 0, 11);
+ R( b, c, d, e, a, F4, KK0, 9, 13);
+ R( a, b, c, d, e, F4, KK0, 2, 15);
+ R( e, a, b, c, d, F4, KK0, 11, 15);
+ R( d, e, a, b, c, F4, KK0, 4, 5);
+ R( c, d, e, a, b, F4, KK0, 13, 7);
+ R( b, c, d, e, a, F4, KK0, 6, 7);
+ R( a, b, c, d, e, F4, KK0, 15, 8);
+ R( e, a, b, c, d, F4, KK0, 8, 11);
+ R( d, e, a, b, c, F4, KK0, 1, 14);
+ R( c, d, e, a, b, F4, KK0, 10, 14);
+ R( b, c, d, e, a, F4, KK0, 3, 12);
+ R( a, b, c, d, e, F4, KK0, 12, 6);
+ R( e, a, b, c, d, F3, KK1, 6, 9);
+ R( d, e, a, b, c, F3, KK1, 11, 13);
+ R( c, d, e, a, b, F3, KK1, 3, 15);
+ R( b, c, d, e, a, F3, KK1, 7, 7);
+ R( a, b, c, d, e, F3, KK1, 0, 12);
+ R( e, a, b, c, d, F3, KK1, 13, 8);
+ R( d, e, a, b, c, F3, KK1, 5, 9);
+ R( c, d, e, a, b, F3, KK1, 10, 11);
+ R( b, c, d, e, a, F3, KK1, 14, 7);
+ R( a, b, c, d, e, F3, KK1, 15, 7);
+ R( e, a, b, c, d, F3, KK1, 8, 12);
+ R( d, e, a, b, c, F3, KK1, 12, 7);
+ R( c, d, e, a, b, F3, KK1, 4, 6);
+ R( b, c, d, e, a, F3, KK1, 9, 15);
+ R( a, b, c, d, e, F3, KK1, 1, 13);
+ R( e, a, b, c, d, F3, KK1, 2, 11);
+ R( d, e, a, b, c, F2, KK2, 15, 9);
+ R( c, d, e, a, b, F2, KK2, 5, 7);
+ R( b, c, d, e, a, F2, KK2, 1, 15);
+ R( a, b, c, d, e, F2, KK2, 3, 11);
+ R( e, a, b, c, d, F2, KK2, 7, 8);
+ R( d, e, a, b, c, F2, KK2, 14, 6);
+ R( c, d, e, a, b, F2, KK2, 6, 6);
+ R( b, c, d, e, a, F2, KK2, 9, 14);
+ R( a, b, c, d, e, F2, KK2, 11, 12);
+ R( e, a, b, c, d, F2, KK2, 8, 13);
+ R( d, e, a, b, c, F2, KK2, 12, 5);
+ R( c, d, e, a, b, F2, KK2, 2, 14);
+ R( b, c, d, e, a, F2, KK2, 10, 13);
+ R( a, b, c, d, e, F2, KK2, 0, 13);
+ R( e, a, b, c, d, F2, KK2, 4, 7);
+ R( d, e, a, b, c, F2, KK2, 13, 5);
+ R( c, d, e, a, b, F1, KK3, 8, 15);
+ R( b, c, d, e, a, F1, KK3, 6, 5);
+ R( a, b, c, d, e, F1, KK3, 4, 8);
+ R( e, a, b, c, d, F1, KK3, 1, 11);
+ R( d, e, a, b, c, F1, KK3, 3, 14);
+ R( c, d, e, a, b, F1, KK3, 11, 14);
+ R( b, c, d, e, a, F1, KK3, 15, 6);
+ R( a, b, c, d, e, F1, KK3, 0, 14);
+ R( e, a, b, c, d, F1, KK3, 5, 6);
+ R( d, e, a, b, c, F1, KK3, 12, 9);
+ R( c, d, e, a, b, F1, KK3, 2, 12);
+ R( b, c, d, e, a, F1, KK3, 13, 9);
+ R( a, b, c, d, e, F1, KK3, 9, 12);
+ R( e, a, b, c, d, F1, KK3, 7, 5);
+ R( d, e, a, b, c, F1, KK3, 10, 15);
+ R( c, d, e, a, b, F1, KK3, 14, 8);
+ R( b, c, d, e, a, F0, KK4, 12, 8);
+ R( a, b, c, d, e, F0, KK4, 15, 5);
+ R( e, a, b, c, d, F0, KK4, 10, 12);
+ R( d, e, a, b, c, F0, KK4, 4, 9);
+ R( c, d, e, a, b, F0, KK4, 1, 12);
+ R( b, c, d, e, a, F0, KK4, 5, 5);
+ R( a, b, c, d, e, F0, KK4, 8, 14);
+ R( e, a, b, c, d, F0, KK4, 7, 6);
+ R( d, e, a, b, c, F0, KK4, 6, 8);
+ R( c, d, e, a, b, F0, KK4, 2, 13);
+ R( b, c, d, e, a, F0, KK4, 13, 6);
+ R( a, b, c, d, e, F0, KK4, 14, 5);
+ R( e, a, b, c, d, F0, KK4, 0, 15);
+ R( d, e, a, b, c, F0, KK4, 3, 13);
+ R( c, d, e, a, b, F0, KK4, 9, 11);
+ R( b, c, d, e, a, F0, KK4, 11, 11);
+
+
+ t = hd->h1 + d + cc;
+ hd->h1 = hd->h2 + e + dd;
+ hd->h2 = hd->h3 + a + ee;
+ hd->h3 = hd->h4 + b + aa;
+ hd->h4 = hd->h0 + c + bb;
+ hd->h0 = t;
+}
+
+
+/* Update the message digest with the contents
+ * of INBUF with length INLEN.
+ */
+static void
+rmd160_write( RMD160_CONTEXT *hd, byte *inbuf, size_t inlen)
+{
+ if( hd->count == 64 ) { /* flush the buffer */
+ transform( hd, hd->buf );
+ burn_stack (108+5*sizeof(void*));
+ hd->count = 0;
+ hd->nblocks++;
+ }
+ if( !inbuf )
+ return;
+ if( hd->count ) {
+ for( ; inlen && hd->count < 64; inlen-- )
+ hd->buf[hd->count++] = *inbuf++;
+ rmd160_write( hd, NULL, 0 );
+ if( !inlen )
+ return;
+ }
+
+ while( inlen >= 64 ) {
+ transform( hd, inbuf );
+ hd->count = 0;
+ hd->nblocks++;
+ inlen -= 64;
+ inbuf += 64;
+ }
+ burn_stack (108+5*sizeof(void*));
+ for( ; inlen && hd->count < 64; inlen-- )
+ hd->buf[hd->count++] = *inbuf++;
+}
+
+/****************
+ * Apply the rmd160 transform function on the buffer which must have
+ * a length 64 bytes. Do not use this function together with the
+ * other functions, use rmd160_init to initialize internal variables.
+ * Returns: 16 bytes in buffer with the mixed contentes of buffer.
+ */
+void
+rmd160_mixblock( RMD160_CONTEXT *hd, char *buffer )
+{
+ char *p = buffer;
+ transform( hd, buffer );
+ #define X(a) do { *(u32*)p = hd->h##a ; p += 4; } while(0)
+ X(0);
+ X(1);
+ X(2);
+ X(3);
+ X(4);
+ #undef X
+}
+
+
+/* The routine terminates the computation
+ */
+
+static void
+rmd160_final( RMD160_CONTEXT *hd )
+{
+ u32 t, msb, lsb;
+ byte *p;
+
+ rmd160_write(hd, NULL, 0); /* flush */;
+
+ t = hd->nblocks;
+ /* multiply by 64 to make a byte count */
+ lsb = t << 6;
+ msb = t >> 26;
+ /* add the count */
+ t = lsb;
+ if( (lsb += hd->count) < t )
+ msb++;
+ /* multiply by 8 to make a bit count */
+ t = lsb;
+ lsb <<= 3;
+ msb <<= 3;
+ msb |= t >> 29;
+
+ if( hd->count < 56 ) { /* enough room */
+ hd->buf[hd->count++] = 0x80; /* pad */
+ while( hd->count < 56 )
+ hd->buf[hd->count++] = 0; /* pad */
+ }
+ else { /* need one extra block */
+ hd->buf[hd->count++] = 0x80; /* pad character */
+ while( hd->count < 64 )
+ hd->buf[hd->count++] = 0;
+ rmd160_write(hd, NULL, 0); /* flush */;
+ memset(hd->buf, 0, 56 ); /* fill next block with zeroes */
+ }
+ /* append the 64 bit count */
+ hd->buf[56] = lsb ;
+ hd->buf[57] = lsb >> 8;
+ hd->buf[58] = lsb >> 16;
+ hd->buf[59] = lsb >> 24;
+ hd->buf[60] = msb ;
+ hd->buf[61] = msb >> 8;
+ hd->buf[62] = msb >> 16;
+ hd->buf[63] = msb >> 24;
+ transform( hd, hd->buf );
+ burn_stack (108+5*sizeof(void*));
+
+ p = hd->buf;
+ #ifdef BIG_ENDIAN_HOST
+ #define X(a) do { *p++ = hd->h##a ; *p++ = hd->h##a >> 8; \
+ *p++ = hd->h##a >> 16; *p++ = hd->h##a >> 24; } while(0)
+ #else /* little endian */
+ #define X(a) do { *(u32*)p = hd->h##a ; p += 4; } while(0)
+ #endif
+ X(0);
+ X(1);
+ X(2);
+ X(3);
+ X(4);
+ #undef X
+}
+
+static byte *
+rmd160_read( RMD160_CONTEXT *hd )
+{
+ return hd->buf;
+}
+
+
+
+/****************
+ * Shortcut functions which puts the hash value of the supplied buffer
+ * into outbuf which must have a size of 20 bytes.
+ */
+void
+rmd160_hash_buffer( char *outbuf, const char *buffer, size_t length )
+{
+ RMD160_CONTEXT hd;
+
+ rmd160_init( &hd );
+ rmd160_write( &hd, (byte*)buffer, length );
+ rmd160_final( &hd );
+ memcpy( outbuf, hd.buf, 20 );
+}
+
+
+/****************
+ * Return some information about the algorithm. We need algo here to
+ * distinguish different flavors of the algorithm.
+ * Returns: A pointer to string describing the algorithm or NULL if
+ * the ALGO is invalid.
+ */
+static const char *
+rmd160_get_info( int algo, size_t *contextsize,
+ byte **r_asnoid, int *r_asnlen, int *r_mdlen,
+ void (**r_init)( void *c ),
+ void (**r_write)( void *c, byte *buf, size_t nbytes ),
+ void (**r_final)( void *c ),
+ byte *(**r_read)( void *c )
+ )
+{
+ static byte asn[15] = /* Object ID is 1.3.36.3.2.1 */
+ { 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x24, 0x03,
+ 0x02, 0x01, 0x05, 0x00, 0x04, 0x14 };
+
+ if( algo != 3 )
+ return NULL;
+
+ *contextsize = sizeof(RMD160_CONTEXT);
+ *r_asnoid = asn;
+ *r_asnlen = DIM(asn);
+ *r_mdlen = 20;
+ *(void (**)(RMD160_CONTEXT *))r_init = rmd160_init;
+ *(void (**)(RMD160_CONTEXT *, byte*, size_t))r_write = rmd160_write;
+ *(void (**)(RMD160_CONTEXT *))r_final = rmd160_final;
+ *(byte *(**)(RMD160_CONTEXT *))r_read = rmd160_read;
+
+ return "RIPEMD160";
+}
+
+
+#ifndef IS_MODULE
+static
+#endif
+const char * const gnupgext_version = "RMD160 ($Revision: 1.17.2.4 $)";
+
+static struct {
+ int class;
+ int version;
+ int value;
+ void (*func)(void);
+} func_table[] = {
+ { 10, 1, 0, (void(*)(void))rmd160_get_info },
+ { 11, 1, 3 },
+};
+
+
+#ifndef IS_MODULE
+static
+#endif
+void *
+gnupgext_enum_func( int what, int *sequence, int *class, int *vers )
+{
+ void *ret;
+ int i = *sequence;
+
+ do {
+ if( i >= DIM(func_table) || i < 0 ) {
+ return NULL;
+ }
+ *class = func_table[i].class;
+ *vers = func_table[i].version;
+ switch( *class ) {
+ case 11:
+ case 21:
+ case 31:
+ ret = &func_table[i].value;
+ break;
+ default:
+ ret = func_table[i].func;
+ break;
+ }
+ i++;
+ } while( what && what != *class );
+
+ *sequence = i;
+ return ret;
+}
+
+
+
+#ifndef __HURD__
+#ifndef IS_MODULE
+void
+rmd160_constructor(void)
+{
+ register_internal_cipher_extension( gnupgext_version, gnupgext_enum_func );
+}
+#endif
+#endif
diff --git a/random/random.c b/random/random.c
new file mode 100644
index 00000000..0ae31f5f
--- /dev/null
+++ b/random/random.c
@@ -0,0 +1,624 @@
+/* random.c - A single-file translator providing random data
+ Copyright (C) 1998, 1999, 2001 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+#define _GNU_SOURCE 1
+
+#include <hurd/trivfs.h>
+#include <hurd/startup.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <argp.h>
+#include <argz.h>
+#include <error.h>
+#include <string.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+#include <cthreads.h>
+#include <rwlock.h>
+
+#include <version.h>
+
+#include "random.h"
+#include "gnupg-random.h"
+
+/* Our control port. */
+struct trivfs_control *fsys;
+
+int read_blocked; /* For read and select. */
+struct condition wait; /* For read and select. */
+struct condition select_alert; /* For read and select. */
+
+
+/* The quality of randomness we provide.
+ 0: Very weak randomness based on time() and getrusage().
+ No external random data is used.
+ 1: Pseudo random numbers based on all available real random
+ numbers.
+ 2: Strong random numbers with a somewhat guaranteed entropy.
+*/
+#define DEFAULT_LEVEL 2
+static int level = DEFAULT_LEVEL;
+
+/* Name of file to use as seed. */
+static char *seed_file;
+
+/* The random bytes we collected. */
+char gatherbuf[GATHERBUFSIZE];
+
+/* The current positions in gatherbuf[]. */
+int gatherrpos;
+int gatherwpos;
+
+/* XXX Yuk Yuk. */
+#define POOLSIZE 600
+
+/* Take up to length bytes from gather_random if available. If
+ nothing is available, sleep until something becomes available.
+ Must be called with global_lock held. */
+int
+gather_random( void (*add)(const void*, size_t, int), int requester,
+ size_t length, int level )
+{
+ int avail = (gatherwpos - gatherrpos + GATHERBUFSIZE) % GATHERBUFSIZE;
+ int first = GATHERBUFSIZE - gatherrpos;
+ int second = length - first;
+
+ /* If level is zero, we should not block and not add anything
+ to the pool. */
+ if( !level )
+ return 0;
+
+ /* io_read() should guarantee that there is always data available. */
+ if (level == 2)
+ assert (avail);
+
+ if (length > avail)
+ length = avail;
+
+ if (first > length)
+ first = length;
+ (*add) (&gatherbuf[gatherrpos], first, requester);
+ gatherrpos = (gatherrpos + first) % GATHERBUFSIZE;
+ if (second > 0)
+ {
+ (*add) (&gatherbuf[gatherrpos], second, requester);
+ gatherrpos += second;
+ }
+ return length;
+}
+
+
+const char *argp_program_version = STANDARD_HURD_VERSION (random);
+
+/* This lock protects the GnuPG code. */
+static struct mutex global_lock;
+
+/* Trivfs hooks. */
+int trivfs_fstype = FSTYPE_MISC;
+int trivfs_fsid = 0;
+
+int trivfs_allow_open = O_READ | O_WRITE;
+
+int trivfs_support_read = 1;
+int trivfs_support_write = 1;
+int trivfs_support_exec = 0;
+
+void
+trivfs_modify_stat (struct trivfs_protid *cred, struct stat *st)
+{
+ /* Mark the node as a read-only plain file. */
+ st->st_mode &= ~S_IFMT;
+ st->st_mode |= (S_IFCHR);
+ st->st_size = 0;
+}
+
+error_t
+trivfs_goaway (struct trivfs_control *cntl, int flags)
+{
+ update_random_seed_file ();
+ exit (0);
+}
+
+/* Read data from an IO object. If offset is -1, read from the object
+ maintained file pointer. If the object is not seekable, offset is
+ ignored. The amount desired to be read is in AMOUNT. */
+error_t
+trivfs_S_io_read (struct trivfs_protid *cred,
+ mach_port_t reply, mach_msg_type_name_t reply_type,
+ data_t *data, mach_msg_type_number_t *data_len,
+ loff_t offs, mach_msg_type_number_t amount)
+{
+ /* Deny access if they have bad credentials. */
+ if (! cred)
+ return EOPNOTSUPP;
+ else if (! (cred->po->openmodes & O_READ))
+ return EBADF;
+
+ mutex_lock (&global_lock);
+
+ if (amount > 0)
+ {
+ while (readable_pool (amount, level) == 0)
+ {
+ if (cred->po->openmodes & O_NONBLOCK)
+ {
+ mutex_unlock (&global_lock);
+ return EWOULDBLOCK;
+ }
+ read_blocked = 1;
+ if (hurd_condition_wait (&wait, &global_lock))
+ {
+ mutex_unlock (&global_lock);
+ return EINTR;
+ }
+ /* See term/users.c for possible race? */
+ }
+
+ /* Possibly allocate a new buffer. */
+ if (*data_len < amount)
+ *data = mmap (0, amount, PROT_READ|PROT_WRITE,
+ MAP_ANON, 0, 0);
+
+ amount = read_pool ((byte *) *data, amount, level);
+ }
+ *data_len = amount;
+
+ /* Set atime, see term/users.c */
+
+ mutex_unlock (&global_lock);
+
+ return 0;
+}
+
+/* Write data to an IO object. If offset is -1, write at the object
+ maintained file pointer. If the object is not seekable, offset is
+ ignored. The amount successfully written is returned in amount. A
+ given user should not have more than one outstanding io_write on an
+ object at a time; servers implement congestion control by delaying
+ responses to io_write. Servers may drop data (returning ENOBUFS)
+ if they receive more than one write when not prepared for it. */
+error_t
+trivfs_S_io_write (struct trivfs_protid *cred,
+ mach_port_t reply,
+ mach_msg_type_name_t replytype,
+ data_t data,
+ mach_msg_type_number_t datalen,
+ loff_t offset,
+ mach_msg_type_number_t *amount)
+{
+ int i = 0;
+ /* Deny access if they have bad credentials. */
+ if (! cred)
+ return EOPNOTSUPP;
+ else if (! (cred->po->openmodes & O_WRITE))
+ return EBADF;
+
+ mutex_lock (&global_lock);
+
+ while (i < datalen)
+ {
+ gatherbuf[gatherwpos] = data[i++];
+ gatherwpos = (gatherwpos + 1) % GATHERBUFSIZE;
+ if (gatherrpos == gatherwpos)
+ /* Overrun. */
+ gatherrpos = (gatherrpos + 1) % GATHERBUFSIZE;
+ }
+ *amount = datalen;
+
+ if (datalen > 0 && read_blocked)
+ {
+ read_blocked = 0;
+ condition_broadcast (&wait);
+ }
+
+ mutex_unlock (&global_lock);
+ return 0;
+}
+
+/* Tell how much data can be read from the object without blocking for
+ a "long time" (this should be the same meaning of "long time" used
+ by the nonblocking flag. */
+kern_return_t
+trivfs_S_io_readable (struct trivfs_protid *cred,
+ mach_port_t reply, mach_msg_type_name_t replytype,
+ mach_msg_type_number_t *amount)
+{
+ /* Deny access if they have bad credentials. */
+ if (! cred)
+ return EOPNOTSUPP;
+ else if (! (cred->po->openmodes & O_READ))
+ return EBADF;
+
+ mutex_lock (&global_lock);
+
+ /* XXX: Before initialization, the amount depends on the amount we
+ want to read. Assume some medium value. */
+ *amount = readable_pool (POOLSIZE/2, level);
+
+ mutex_unlock (&global_lock);
+
+ return 0;
+}
+
+/* SELECT_TYPE is the bitwise OR of SELECT_READ, SELECT_WRITE, and SELECT_URG.
+ Block until one of the indicated types of i/o can be done "quickly", and
+ return the types that are then available. ID_TAG is returned as passed; it
+ is just for the convenience of the user in matching up reply messages with
+ specific requests sent. */
+error_t
+trivfs_S_io_select (struct trivfs_protid *cred,
+ mach_port_t reply,
+ mach_msg_type_name_t reply_type,
+ int *type)
+{
+ if (!cred)
+ return EOPNOTSUPP;
+
+ /* We only deal with SELECT_READ and SELECT_WRITE here. */
+ if (*type & ~(SELECT_READ | SELECT_WRITE))
+ return EINVAL;
+
+ if (*type == 0)
+ return 0;
+
+ mutex_lock (&global_lock);
+
+ while (1)
+ {
+ /* XXX Before initialization, readable_pool depends on length. */
+ int avail = readable_pool (POOLSIZE/2, level);
+
+ if (avail != 0 || *type & SELECT_WRITE)
+ {
+ *type = (avail ? SELECT_READ : 0) | (*type & SELECT_WRITE);
+ mutex_unlock (&global_lock);
+ return 0;
+ }
+
+ ports_interrupt_self_on_port_death (cred, reply);
+ read_blocked = 1;
+
+ if (hurd_condition_wait (&select_alert, &global_lock))
+ {
+ *type = 0;
+ mutex_unlock (&global_lock);
+ return EINTR;
+ }
+ }
+}
+
+
+/* Change current read/write offset */
+error_t
+trivfs_S_io_seek (struct trivfs_protid *cred,
+ mach_port_t reply, mach_msg_type_name_t reply_type,
+ loff_t offs, int whence, loff_t *new_offs)
+{
+ if (! cred)
+ return EOPNOTSUPP;
+
+ /* Not seekable. */
+ return ESPIPE;
+}
+
+/* Change the size of the file. If the size increases, new blocks are
+ zero-filled. After successful return, it is safe to reference mapped
+ areas of the file up to NEW_SIZE. */
+error_t
+trivfs_S_file_set_size (struct trivfs_protid *cred,
+ mach_port_t reply, mach_msg_type_name_t reply_type,
+ loff_t size)
+{
+ if (!cred)
+ return EOPNOTSUPP;
+
+ return size == 0 ? 0 : EINVAL;
+}
+
+/* These four routines modify the O_APPEND, O_ASYNC, O_FSYNC, and
+ O_NONBLOCK bits for the IO object. In addition, io_get_openmodes
+ will tell you which of O_READ, O_WRITE, and O_EXEC the object can
+ be used for. The O_ASYNC bit affects icky async I/O; good async
+ I/O is done through io_async which is orthogonal to these calls. */
+error_t
+trivfs_S_io_set_all_openmodes(struct trivfs_protid *cred,
+ mach_port_t reply,
+ mach_msg_type_name_t reply_type,
+ int mode)
+{
+ if (!cred)
+ return EOPNOTSUPP;
+
+ return 0;
+}
+
+error_t
+trivfs_S_io_set_some_openmodes (struct trivfs_protid *cred,
+ mach_port_t reply,
+ mach_msg_type_name_t reply_type,
+ int bits)
+{
+ if (!cred)
+ return EOPNOTSUPP;
+
+ return 0;
+}
+
+error_t
+trivfs_S_io_get_owner (struct trivfs_protid *cred,
+ mach_port_t reply,
+ mach_msg_type_name_t reply_type,
+ pid_t *owner)
+{
+ if (!cred)
+ return EOPNOTSUPP;
+
+ *owner = 0;
+ return 0;
+}
+
+error_t
+trivfs_S_io_mod_owner (struct trivfs_protid *cred,
+ mach_port_t reply, mach_msg_type_name_t reply_type,
+ pid_t owner)
+{
+ if (!cred)
+ return EOPNOTSUPP;
+
+ return EINVAL;
+}
+
+/* Return objects mapping the data underlying this memory object. If
+ the object can be read then memobjrd will be provided; if the
+ object can be written then memobjwr will be provided. For objects
+ where read data and write data are the same, these objects will be
+ equal, otherwise they will be disjoint. Servers are permitted to
+ implement io_map but not io_map_cntl. Some objects do not provide
+ mapping; they will set none of the ports and return an error. Such
+ objects can still be accessed by io_read and io_write. */
+error_t
+trivfs_S_io_map(struct trivfs_protid *cred,
+ mach_port_t reply, mach_msg_type_name_t reply_type,
+ mach_port_t *rdobj,
+ mach_msg_type_name_t *rdtype,
+ mach_port_t *wrobj,
+ mach_msg_type_name_t *wrtype)
+{
+ if (!cred)
+ return EOPNOTSUPP;
+
+ return EINVAL;
+}
+
+
+int
+random_demuxer (mach_msg_header_t *inp,
+ mach_msg_header_t *outp)
+{
+ extern int startup_notify_server (mach_msg_header_t *, mach_msg_header_t *);
+
+ return (trivfs_demuxer (inp, outp)
+ || startup_notify_server (inp, outp));
+}
+
+
+/* Options processing. We accept the same options on the command line
+ and from fsys_set_options. */
+
+static const struct argp_option options[] =
+{
+ {"weak", 'w', 0, 0, "Output weak pseudo random data"},
+ {"fast", 'f', 0, 0, "Output cheap random data fast"},
+ {"secure", 's', 0, 0, "Output cryptographically secure random"},
+ {"seed-file", 'S', "FILE", 0, "Use FILE to remember the seed"},
+ {0}
+};
+
+static error_t
+parse_opt (int opt, char *arg, struct argp_state *state)
+{
+ switch (opt)
+ {
+ default:
+ return ARGP_ERR_UNKNOWN;
+ case ARGP_KEY_INIT:
+ case ARGP_KEY_SUCCESS:
+ case ARGP_KEY_ERROR:
+ break;
+
+ case 'w':
+ {
+ level = 0;
+ break;
+ }
+ case 'f':
+ {
+ level = 1;
+ break;
+ }
+ case 's':
+ {
+ level = 2;
+ break;
+ }
+ case 'S':
+ {
+ seed_file = strdup (arg);
+ set_random_seed_file (arg);
+ }
+ }
+ return 0;
+}
+
+/* This will be called from libtrivfs to help construct the answer
+ to an fsys_get_options RPC. */
+error_t
+trivfs_append_args (struct trivfs_control *fsys,
+ char **argz, size_t *argz_len)
+{
+ error_t err = 0;
+ char *opt;
+
+ mutex_lock (&global_lock);
+ switch (level)
+ {
+ case 0:
+ {
+ opt = "--weak";
+ break;
+ }
+ case 1:
+ {
+ opt = "--fast";
+ break;
+ }
+ default:
+ {
+ opt = "--secure";
+ break;
+ }
+ }
+ if (level != DEFAULT_LEVEL)
+ err = argz_add (argz, argz_len, opt);
+
+ if (!err && seed_file)
+ {
+ if (asprintf (&opt, "--seed-file=%s", seed_file) < 0)
+ err = ENOMEM;
+ else
+ {
+ err = argz_add (argz, argz_len, opt);
+ free (opt);
+ }
+ }
+ mutex_unlock (&global_lock);
+
+ return err;
+}
+
+static struct argp random_argp =
+{ options, parse_opt, 0,
+ "A translator providing random output." };
+
+/* Setting this variable makes libtrivfs use our argp to
+ parse options passed in an fsys_set_options RPC. */
+struct argp *trivfs_runtime_argp = &random_argp;
+
+struct port_class *shutdown_notify_class;
+
+/* The system is going down; destroy all the extant port rights. That
+ will cause net channels and such to close promptly. */
+error_t
+S_startup_dosync (mach_port_t handle)
+{
+ struct port_info *inpi = ports_lookup_port (fsys->pi.bucket, handle,
+ shutdown_notify_class);
+
+ if (!inpi)
+ return EOPNOTSUPP;
+
+ update_random_seed_file ();
+ return 0;
+}
+
+void
+sigterm_handler (int signo)
+{
+ update_random_seed_file ();
+ signal (SIGTERM, SIG_DFL);
+ raise (SIGTERM);
+}
+
+void
+arrange_shutdown_notification ()
+{
+ error_t err;
+ mach_port_t initport, notify;
+ process_t procserver;
+ struct port_info *pi;
+
+ shutdown_notify_class = ports_create_class (0, 0);
+
+ signal (SIGTERM, sigterm_handler);
+
+ /* Arrange to get notified when the system goes down,
+ but if we fail for some reason, just silently give up. No big deal. */
+
+ err = ports_create_port (shutdown_notify_class, fsys->pi.bucket,
+ sizeof (struct port_info), &pi);
+ if (err)
+ return;
+
+ procserver = getproc ();
+ if (!procserver)
+ return;
+
+ err = proc_getmsgport (procserver, 1, &initport);
+ mach_port_deallocate (mach_task_self (), procserver);
+ if (err)
+ return;
+
+ notify = ports_get_send_right (pi);
+ ports_port_deref (pi);
+ startup_request_notification (initport, notify,
+ MACH_MSG_TYPE_MAKE_SEND,
+ program_invocation_short_name);
+ mach_port_deallocate (mach_task_self (), notify);
+ mach_port_deallocate (mach_task_self (), initport);
+}
+
+
+int
+main (int argc, char **argv)
+{
+ error_t err;
+ mach_port_t bootstrap;
+
+ /* Initialize the lock that will protect everything.
+ We must do this before argp_parse, because parse_opt (above) will
+ use the lock. */
+ mutex_init (&global_lock);
+
+ /* The conditions are used to implement proper read/select
+ behaviour. */
+ condition_init (&wait);
+ condition_init (&select_alert);
+ condition_implies (&wait, &select_alert);
+
+ /* We use the same argp for options available at startup
+ as for options we'll accept in an fsys_set_options RPC. */
+ argp_parse (&random_argp, argc, argv, 0, 0, 0);
+
+ task_get_bootstrap_port (mach_task_self (), &bootstrap);
+ if (bootstrap == MACH_PORT_NULL)
+ error (1, 0, "Must be started as a translator");
+
+ /* Reply to our parent */
+ err = trivfs_startup (bootstrap, 0, 0, 0, 0, 0, &fsys);
+ mach_port_deallocate (mach_task_self (), bootstrap);
+ if (err)
+ error (3, err, "trivfs_startup");
+
+ arrange_shutdown_notification ();
+
+ /* Launch. */
+ ports_manage_port_operations_multithread (fsys->pi.bucket, random_demuxer,
+ 10 * 1000, /* idle thread */
+ 10 * 60 * 1000, /* idle server */
+ 0);
+ return 0;
+}
diff --git a/random/random.h b/random/random.h
new file mode 100644
index 00000000..a38a4177
--- /dev/null
+++ b/random/random.h
@@ -0,0 +1,32 @@
+/* random.c - A single-file translator providing random data
+ Copyright (C) 1998, 1999, 2001 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+#ifndef __RANDOM_H__
+#define __RANDOM_H__
+
+/* How many random bytes to gather at most.
+ XXX: Should be at least POOLSIZE. */
+#define GATHERBUFSIZE 32768
+
+/* The random bytes we collected. */
+extern char gatherbuf[GATHERBUFSIZE];
+
+/* The current positions in gatherbuf[]. */
+extern int gatherrpos;
+extern int gatherwpos;
+
+#endif
diff --git a/tests/test-17.c b/tests/test-17.c
new file mode 100644
index 00000000..a8bd1503
--- /dev/null
+++ b/tests/test-17.c
@@ -0,0 +1,57 @@
+/* Test that the key reuse inside libpthread does not cause thread
+ specific values to persist. */
+
+#define _GNU_SOURCE 1
+
+#include <pthread.h>
+#include <stdio.h>
+#include <assert.h>
+#include <errno.h>
+
+void
+work (int iter)
+{
+ error_t err;
+ pthread_key_t key1;
+ pthread_key_t key2;
+ void *value1;
+ void *value2;
+
+ printf ("work/%d: start\n", iter);
+ err = pthread_key_create (&key1, NULL);
+ assert (err == 0);
+ err = pthread_key_create (&key2, NULL);
+ assert (err == 0);
+
+ value1 = pthread_getspecific (key1);
+ value2 = pthread_getspecific (key2);
+ printf ("work/%d: pre-setspecific: %p,%p\n", iter, value1, value2);
+ assert (value1 == NULL);
+ assert (value2 == NULL);
+ err = pthread_setspecific (key1, (void *)(0x100 + iter));
+ assert (err == 0);
+ err = pthread_setspecific (key2, (void *)(0x200 + iter));
+ assert (err == 0);
+
+ value1 = pthread_getspecific (key1);
+ value2 = pthread_getspecific (key2);
+ printf ("work/%d: post-setspecific: %p,%p\n", iter, value1, value2);
+ assert (value1 == (void *)(0x100 + iter));
+ assert (value2 == (void *)(0x200 + iter));
+
+ err = pthread_key_delete (key1);
+ assert (err == 0);
+ err = pthread_key_delete (key2);
+ assert (err == 0);
+}
+
+int
+main (int argc, char *argv[])
+{
+ int i;
+
+ for (i = 0; i < 8; ++i)
+ work (i + 1);
+
+ return 0;
+}
diff --git a/tests/test-__pthread_destroy_specific-skip.c b/tests/test-__pthread_destroy_specific-skip.c
new file mode 100644
index 00000000..b2c4c0bd
--- /dev/null
+++ b/tests/test-__pthread_destroy_specific-skip.c
@@ -0,0 +1,83 @@
+/* Check that __pthread_destroy_specific works correctly if it has to skip
+ unused slots. */
+
+#define _GNU_SOURCE
+
+#include <error.h>
+#include <pthread.h>
+#include <stdio.h>
+
+
+#define N_k 42
+
+static volatile int v;
+
+static void
+d (void *x)
+{
+ int *i = (int *) x;
+
+ if (v != *i)
+ error (1, 0, "FAILED %d %d", v, *i);
+ v += 2;
+
+ printf ("%s %d\n", __FUNCTION__, *i);
+ fflush (stdout);
+}
+
+static void *
+test (void *x)
+{
+ pthread_key_t k[N_k];
+ static int k_v[N_k];
+
+ int err, i;
+
+ for (i = 0; i < N_k; i += 1)
+ {
+ err = pthread_key_create (&k[i], &d);
+ if (err != 0)
+ error (1, err, "pthread_key_create %d", i);
+ }
+
+ for (i = 0; i < N_k; i += 1)
+ {
+ k_v[i] = i;
+ err = pthread_setspecific (k[i], &k_v[i]);
+ if (err != 0)
+ error (1, err, "pthread_setspecific %d", i);
+ }
+
+ /* Delete every even key. */
+ for (i = 0; i < N_k; i += 2)
+ {
+ err = pthread_key_delete (k[i]);
+ if (err != 0)
+ error (1, err, "pthread_key_delete %d", i);
+ }
+
+ v = 1;
+ pthread_exit (NULL);
+
+ return NULL;
+}
+
+
+int main(void)
+{
+ pthread_t tid;
+ int err;
+
+ err = pthread_create (&tid, 0, test, NULL);
+ if (err != 0)
+ error (1, err, "pthread_create");
+
+ err = pthread_join(tid, NULL);
+ if (err)
+ error (1, err, "pthread_join");
+
+ if (v != N_k + 1)
+ error (1, 0, "FAILED END %d %d", v, N_k + 1);
+
+ return 0;
+}
diff --git a/ufs-fsck/Makefile b/ufs-fsck/Makefile
new file mode 100644
index 00000000..a484428e
--- /dev/null
+++ b/ufs-fsck/Makefile
@@ -0,0 +1,35 @@
+#
+# Copyright (C) 1994, 1995, 1996 Free Software Foundation
+# Written by Michael I. Bushnell.
+#
+# This file is part of the GNU Hurd.
+#
+# The GNU Hurd is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2, or (at
+# your option) any later version.
+#
+# The GNU Hurd is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+dir := ufs-fsck
+makemode := utility
+
+SRCS = dir.c main.c pass1.c pass1b.c pass2.c pass3.c pass4.c \
+ pass5.c setup.c utilities.c inode.c
+OBJS = $(subst .c,.o,$(SRCS)) tables.o
+LCLHDRS = fsck.h
+target = fsck.ufs
+installationdir = $(sbindir)
+HURDLIBS=shouldbeinlibc
+
+include ../Makeconf
+
+vpath tables.c $(top_srcdir)/ufs
+
diff --git a/ufs-fsck/dir.c b/ufs-fsck/dir.c
new file mode 100644
index 00000000..85757b16
--- /dev/null
+++ b/ufs-fsck/dir.c
@@ -0,0 +1,567 @@
+/* Directory management subroutines
+ Copyright (C) 1994,96,99,2002 Free Software Foundation, Inc.
+ Written by Michael I. Bushnell.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#include "fsck.h"
+
+/* This routine is used in pass 1 to initialize DIRARRAY and DIRSORTED.
+ Copy information from DP (for number NUMBER) into a newly allocated
+ dirinfo structure and add it to the arrays. */
+void
+record_directory (struct dinode *dp, ino_t number)
+{
+ u_int blks;
+ struct dirinfo *dnp;
+
+ blks = howmany (dp->di_size, sblock->fs_bsize);
+ if (blks > NDADDR)
+ blks = NDADDR + NIADDR;
+ blks *= sizeof (daddr_t);
+ dnp = malloc (sizeof (struct dirinfo) + blks);
+
+ dnp->i_number = number;
+ dnp->i_parent = dnp->i_dotdot = 0;
+ dnp->i_isize = dp->di_size;
+ dnp->i_numblks = blks;
+ bcopy (dp->di_db, dnp->i_blks, blks);
+
+ if (dirarrayused == dirarraysize)
+ {
+ if (dirarraysize == 0)
+ {
+ dirarraysize = 100;
+ dirarray = malloc (dirarraysize * sizeof (struct dirinfo *));
+ dirsorted = malloc (dirarraysize * sizeof (struct dirinfo *));
+ }
+ else
+ {
+ dirarraysize *= 2;
+ dirarray = realloc (dirarray,
+ dirarraysize * sizeof (struct dirinfo *));
+ dirsorted = realloc (dirsorted,
+ dirarraysize * sizeof (struct dirinfo *));
+ }
+ }
+ dirarray[dirarrayused] = dnp;
+ dirsorted[dirarrayused] = dnp;
+ dirarrayused++;
+}
+
+/* Return the cached dirinfo structure for directory INO. */
+struct dirinfo *
+lookup_directory (ino_t ino)
+{
+ int i;
+
+ for (i = 0; i < dirarrayused; i++)
+ if (dirarray[i]->i_number == ino)
+ return dirarray[i];
+
+ errexit ("Cannot find cached directory I=%Ld\n", ino);
+}
+
+/* Check to see if DIR is really a readable directory; if it
+ isn't, then bail with an appropriate message and return 0;
+ else return 1. MSG identifies the action contemplated */
+static int
+validdir (ino_t dir, char *action)
+{
+ switch (inodestate[dir])
+ {
+ case DIRECTORY:
+ case DIRECTORY|DIR_REF:
+ return 1;
+
+ case UNALLOC:
+ warning (1, "CANNOT %s I=%Ld; NOT ALLOCATED", action, dir);
+ return 0;
+
+ case BADDIR:
+ warning (1, "CANNOT %s I=%Ld; BAD BLOCKS", action, dir);
+ return 0;
+
+ case REG:
+ warning (1, "CANNOT %s I=%Ld; NOT DIRECTORY", action, dir);
+ return 0;
+
+ default:
+ errexit ("ILLEGAL STATE");
+ }
+}
+
+/* Search directory DIR for name NAME. If NAME is found, then
+ set *INO to the inode of the entry; otherwise clear INO. Returns 1 if all
+ was normal, or 0 if there was some error doing the search. */
+int
+searchdir (ino_t dir, char *name, ino_t *ino)
+{
+ struct dinode dino;
+ int len;
+
+ /* Scan through one directory block and see if it
+ contains NAME. */
+ void
+ check1block (void *buf)
+ {
+ struct directory_entry *dp;
+
+ for (dp = buf; (void *)dp - buf < DIRBLKSIZ;
+ dp = (struct directory_entry *) ((void *)dp + dp->d_reclen))
+ {
+ if (dp->d_reclen == 0
+ || dp->d_reclen + (void *)dp - buf > DIRBLKSIZ)
+ return;
+
+ if (dp->d_ino == 0 || dp->d_ino > maxino)
+ continue;
+
+ if (DIRECT_NAMLEN (dp) == len && strcmp (dp->d_name, name) == 0)
+ {
+ *ino = dp->d_ino;
+ return;
+ }
+ }
+ }
+
+ /* Read part of a directory and look to see if it contains
+ NAME. Return 1 if we should keep looking at more
+ blocks. */
+ int
+ checkdirblock (daddr_t bno, int nfrags, off_t offset)
+ {
+ void *buf = alloca (nfrags * sblock->fs_fsize);
+ void *bufp;
+
+ readblock (fsbtodb (sblock, bno), buf, nfrags * sblock->fs_fsize);
+ for (bufp = buf;
+ bufp - buf < nfrags * sblock->fs_fsize
+ && offset + (bufp - buf) + DIRBLKSIZ <= dino.di_size;
+ bufp += DIRBLKSIZ)
+ {
+ check1block (bufp);
+ if (*ino)
+ return 0;
+ }
+ return 1;
+ }
+
+ *ino = 0;
+
+ if (!validdir (dir, "READ"))
+ return 0;
+
+ getinode (dir, &dino);
+
+ len = strlen (name);
+ datablocks_iterate (&dino, checkdirblock);
+
+ return 1;
+}
+
+/* Change the existing entry in DIR for name NAME to be
+ inode INO. Return 1 if the entry was found and
+ replaced, else return 0. */
+int
+changeino (ino_t dir, char *name, ino_t ino)
+{
+ struct dinode dino;
+ int len;
+ int madechange;
+
+ /* Scan through a directory block looking for NAME;
+ if we find it then change the inode pointer to point
+ at INO and return 1; if we don't find it then return 0. */
+ int
+ check1block (void *buf)
+ {
+ struct directory_entry *dp;
+
+ for (dp = buf; (void *)dp - buf < DIRBLKSIZ;
+ dp = (struct directory_entry *) ((void *)dp + dp->d_reclen))
+ {
+ if (dp->d_reclen == 0
+ || dp->d_reclen + (void *)dp - buf > DIRBLKSIZ)
+ return 0;
+
+ if (dp->d_ino == 0 || dp->d_ino > maxino)
+ continue;
+
+ if (DIRECT_NAMLEN (dp) == len && strcmp (dp->d_name, name) == 0)
+ {
+ dp->d_ino = ino;
+ madechange = 1;
+ return 1;
+ }
+ }
+ return 0;
+ }
+
+ /* Read part of a directory and look to see if it
+ contains NAME. Return 1 if we should keep looking
+ at more blocks. */
+ int
+ checkdirblock (daddr_t bno, int nfrags, off_t offset)
+ {
+ void *buf = alloca (nfrags * sblock->fs_fsize);
+ void *bufp;
+
+ readblock (fsbtodb (sblock, bno), buf, nfrags * sblock->fs_fsize);
+ for (bufp = buf;
+ bufp - buf < nfrags * sblock->fs_fsize
+ && offset + (bufp - buf) + DIRBLKSIZ <= dino.di_size;
+ bufp += DIRBLKSIZ)
+ {
+ if (check1block (bufp))
+ {
+ writeblock (fsbtodb (sblock, bno), buf,
+ nfrags * sblock->fs_fsize);
+ return 0;
+ }
+ }
+ return 1;
+ }
+
+ if (!validdir (dir, "REWRITE"))
+ return 0;
+
+ getinode (dir, &dino);
+ len = strlen (name);
+ madechange = 0;
+ datablocks_iterate (&dino, checkdirblock);
+ return madechange;
+}
+
+/* Attempt to expand the size of a directory. Return
+ 1 if we succeeded. */
+static int
+expanddir (struct dinode *dp)
+{
+ daddr_t lastbn, newblk;
+ char *cp, buf[sblock->fs_bsize];
+
+ lastbn = lblkno (sblock, dp->di_size);
+ if (blkoff (sblock, dp->di_size) && lastbn >= NDADDR - 1)
+ return 0;
+ else if (!blkoff (sblock, dp->di_size) && lastbn >= NDADDR)
+ return 0;
+ else if (blkoff (sblock, dp->di_size) && !dp->di_db[lastbn])
+ return 0;
+ else if (!blkoff (sblock, dp->di_size) && dp->di_db[lastbn])
+ return 0;
+
+ newblk = allocblk (sblock->fs_frag);
+ if (!newblk)
+ return 0;
+
+ if (blkoff (sblock, dp->di_size))
+ dp->di_db[lastbn + 1] = dp->di_db[lastbn];
+ dp->di_db[lastbn] = newblk;
+ dp->di_size += sblock->fs_bsize;
+ dp->di_blocks += sblock->fs_bsize / DEV_BSIZE;
+
+ for (cp = buf; cp < buf + sblock->fs_bsize; cp += DIRBLKSIZ)
+ {
+ struct directory_entry *dir = (struct directory_entry *) cp;
+ dir->d_ino = 0;
+ dir->d_reclen = DIRBLKSIZ;
+ }
+
+ writeblock (fsbtodb (sblock, newblk), buf, sblock->fs_bsize);
+ return 1;
+}
+
+/* Add a new link into directory DIR with name NAME and target
+ INO. Return 1 if we succeeded and 0 if we failed. It is
+ an error to call this routine if NAME is already present
+ in DIR. */
+int
+makeentry (ino_t dir, ino_t ino, char *name)
+{
+ int len;
+ struct dinode dino;
+ int needed;
+ int madeentry;
+
+ /* Read a directory block and see if it contains room for the
+ new entry. If so, add it and return 1; otherwise return 0. */
+ int
+ check1block (void *buf)
+ {
+ struct directory_entry *dp;
+
+ for (dp = buf; (void *)dp - buf < DIRBLKSIZ;
+ dp = (struct directory_entry *) ((void *)dp + dp->d_reclen))
+ {
+ if (dp->d_reclen == 0
+ || dp->d_reclen + (void *)dp - buf > DIRBLKSIZ)
+ return 0;
+ if (dp->d_ino
+ && dp->d_reclen - DIRSIZ (DIRECT_NAMLEN (dp)) >= needed)
+ {
+ struct directory_entry *newdp;
+ newdp = (struct directory_entry *)
+ ((void *)dp + DIRSIZ (DIRECT_NAMLEN (dp)));
+
+ newdp->d_reclen = dp->d_reclen - DIRSIZ (DIRECT_NAMLEN (dp));
+ DIRECT_NAMLEN (newdp) = len;
+ newdp->d_ino = ino;
+ if (direct_symlink_extension)
+ newdp->d_type = typemap[ino];
+ bcopy (name, newdp->d_name, len + 1);
+
+ dp->d_reclen -= newdp->d_reclen;
+ madeentry = 1;
+ return 1;
+ }
+ else if (!dp->d_ino && dp->d_reclen >= needed)
+ {
+ DIRECT_NAMLEN (dp) = len;
+ dp->d_ino = ino;
+ if (direct_symlink_extension)
+ dp->d_type = typemap[ino];
+ bcopy (name, dp->d_name, len + 1);
+ madeentry = 1;
+ return 1;
+ }
+ }
+ return 0;
+ }
+
+ /* Read part of a directory and look to see if it
+ contains NAME. Return 1 if we should keep looking
+ at more blocks. */
+ int
+ checkdirblock (daddr_t bno, int nfrags, off_t offset)
+ {
+ void *buf = alloca (nfrags * sblock->fs_fsize);
+ void *bufp;
+
+ readblock (fsbtodb (sblock, bno), buf, nfrags * sblock->fs_fsize);
+ for (bufp = buf;
+ bufp - buf < nfrags * sblock->fs_fsize
+ && offset + (bufp - buf) + DIRBLKSIZ <= dino.di_size;
+ bufp += DIRBLKSIZ)
+ {
+ if (check1block (bufp))
+ {
+ writeblock (fsbtodb (sblock, bno), buf,
+ nfrags * sblock->fs_fsize);
+ return 0;
+ }
+ }
+ return 1;
+ }
+
+ if (!validdir (dir, "MODIFY"))
+ return 0;
+
+ getinode (dir, &dino);
+ len = strlen (name);
+ needed = DIRSIZ (len);
+ madeentry = 0;
+ datablocks_iterate (&dino, checkdirblock);
+ if (!madeentry)
+ {
+ /* Attempt to expand the directory. */
+ problem (0, "NO SPACE LEFT IN DIR INO=%Ld", dir);
+ if (preen || reply ("EXPAND"))
+ {
+ if (expanddir (&dino))
+ {
+ write_inode (ino, &dino);
+ datablocks_iterate (&dino, checkdirblock);
+ pfix ("EXPANDED");
+ }
+ else
+ {
+ pfail (0);
+ warning (1, "CANNOT EXPAND DIRECTORY");
+ }
+ }
+ }
+ return madeentry;
+}
+
+/* Create a directory node whose parent is to be PARENT, whose inode
+ is REQUEST, and whose mode is to be MODE. If REQUEST is zero, then
+ allocate any inode. Initialze the contents of the
+ directory. Return the inode of the new directory. */
+ino_t
+allocdir (ino_t parent, ino_t request, mode_t mode)
+{
+ ino_t ino;
+
+ mode |= IFDIR;
+
+ ino = allocino (request, mode);
+ if (!ino)
+ return 0;
+ if (!makeentry (ino, ino, "."))
+ goto bad;
+ if (!makeentry (ino, parent, ".."))
+ goto bad;
+
+ linkfound[ino]++;
+ linkfound[parent]++;
+ return ino;
+
+ bad:
+ freeino (ino);
+ return 0;
+}
+
+/* Link node INO into lost+found. If PARENT is positive then INO is
+ a directory, and PARENT is the number of `..' as found in INO.
+ If PARENT is zero then INO is a directory without any .. entry.
+ If the node could be linked, return 1; else return 0. */
+int
+linkup (ino_t ino, ino_t parent)
+{
+ int search_failed;
+ struct dinode lfdino;
+ char *tempname;
+ ino_t foo;
+
+ if (lfdir == 0)
+ {
+ if (!searchdir (ROOTINO, lfname, &lfdir))
+ {
+ warning (1, "FAILURE SEARCHING FOR `%s'", lfname);
+ return 0;
+ }
+ if (lfdir == 0)
+ {
+ problem (0, "NO `%s' DIRECTORY", lfname);
+ if (preen || reply ("CREATE"))
+ {
+ lfdir = allocdir (ROOTINO, 0, lfmode);
+ if (lfdir != 0)
+ {
+ if (! makeentry (ROOTINO, lfdir, lfname))
+ {
+ freeino (lfdir);
+ linkfound[ROOTINO]--;
+ lfdir = 0;
+ }
+ }
+ }
+ if (lfdir)
+ pfix ("CREATED");
+ else
+ {
+ pfail (0);
+ warning (1, "SORRY, CANNOT CREATE `%s' DIRECTORY", lfname);
+ return 0;
+ }
+ }
+ }
+
+ getinode (lfdir, &lfdino);
+ if ((lfdino.di_model & IFMT) != IFDIR)
+ {
+ ino_t oldlfdir;
+
+ problem (1, "`%s' IS NOT A DIRECTORY", lfname);
+ if (! reply ("REALLOCATE"))
+ return 0;
+
+ oldlfdir = lfdir;
+
+ lfdir = allocdir (ROOTINO, 0, lfmode);
+ if (!lfdir)
+ {
+ warning (1, "SORRY, CANNOT CREATE `%s' DIRECTORY", lfname);
+ return 0;
+ }
+ if (!changeino (ROOTINO, lfname, lfdir))
+ {
+ warning (1, "SORRY, CANNOT CREATE `%s' DIRECTORY", lfname);
+ return 0;
+ }
+
+ /* One less link to the old one */
+ linkfound[oldlfdir]--;
+
+ getinode (lfdir, &lfdino);
+ }
+
+ if (inodestate[lfdir] != DIRECTORY && inodestate[lfdir] != (DIRECTORY|DIR_REF))
+ {
+ warning (1, "SORRY. `%s' DIRECTORY NOT ALLOCATED", lfname);
+ return 0;
+ }
+
+ asprintf (&tempname, "#%Ld", ino);
+ search_failed = !searchdir (lfdir, tempname, &foo);
+ while (foo)
+ {
+ char *newname;
+ asprintf (&newname, "%sa", tempname);
+ free (tempname);
+ tempname = newname;
+ search_failed = !searchdir (lfdir, tempname, &foo);
+ }
+ if (search_failed)
+ {
+ warning (1, "FAILURE SEARCHING FOR `%s' IN `%s'", tempname, lfname);
+ free (tempname);
+ return 0;
+ }
+ if (!makeentry (lfdir, ino, tempname))
+ {
+ free (tempname);
+ warning (1, "SORRY, NO SPACE IN `%s' DIRECTORY", lfname);
+ return 0;
+ }
+ free (tempname);
+ linkfound[ino]++;
+
+ if (parent != -1)
+ {
+ /* Reset `..' in ino */
+ if (parent)
+ {
+ if (!changeino (ino, "..", lfdir))
+ {
+ warning (1, "CANNOT ADJUST `..' LINK I=%Ld", ino);
+ return 0;
+ }
+ /* Forget about link to old parent */
+ linkfound[parent]--;
+ }
+ else if (!makeentry (ino, lfdir, ".."))
+ {
+ warning (1, "CANNOT CREAT `..' LINK I=%Ld", ino);
+ return 0;
+ }
+
+ /* Account for link to lost+found; update inode directly
+ here to avoid confusing warning later. */
+ linkfound[lfdir]++;
+ linkcount[lfdir]++;
+ lfdino.di_nlink++;
+ write_inode (lfdir, &lfdino);
+
+ if (parent)
+ warning (0, "DIR I=%Ld CONNECTED; PARENT WAS I=%Ld", ino, parent);
+ else
+ warning (0, "DIR I=%Ld CONNECTED", ino);
+ }
+ return 1;
+}
diff --git a/ufs-fsck/fsck.h b/ufs-fsck/fsck.h
new file mode 100644
index 00000000..4a5dabf5
--- /dev/null
+++ b/ufs-fsck/fsck.h
@@ -0,0 +1,183 @@
+/*
+ Copyright (C) 1994,95,96,2002 Free Software Foundation, Inc.
+ Written by Michael I. Bushnell.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#include <sys/types.h>
+#include <sys/time.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <dirent.h>
+
+#define swab_disk 0
+
+#include "../ufs/fs.h"
+#include "../ufs/dinode.h"
+#include "../ufs/dir.h"
+
+/* Type of an inode */
+#define UNALLOC 0
+#define REG 1
+#define DIRECTORY 2
+#define BADDIR 3
+
+/* Added to directories in pass 2 */
+#define DIR_REF 4 /* dir has been found in connectivity search */
+
+/* State of each inode (set by pass 1) */
+char *inodestate;
+
+/* Number of links claimed by each inode (set by pass 1) */
+nlink_t *linkcount;
+
+/* Number of links found to each inode (set by pass 2) */
+nlink_t *linkfound;
+
+/* DT_foo type of each inode (set by pass 1) */
+char *typemap;
+
+/* Map of blocks allocated */
+char *blockmap;
+
+/* A string identifying what we're trying to check. */
+extern char *device_name;
+
+
+/* Command line flags */
+int nowrite; /* all questions fail */
+int noquery; /* all questions succeed */
+
+
+enum contret
+{
+ RET_STOP,
+ RET_GOOD,
+ RET_BAD,
+};
+
+
+/* One of these structures is set up for each directory by
+ pass 1 and used by passes 2 and 3. */
+struct dirinfo
+{
+ struct inoinfo *i_nexthash; /* next entry in hash chain */
+ ino_t i_number; /* inode entry of this dir */
+ ino_t i_parent; /* inode entry of parent */
+ ino_t i_dotdot; /* inode number of `..' */
+ ino_t i_dot; /* inode number of `.' */
+ u_int i_isize; /* size of inode */
+ u_int i_numblks; /* size of block array in bytes */
+ daddr_t i_blks[0]; /* array of inode block addresses */
+};
+
+/* Array of all the dirinfo structures in inode number order */
+struct dirinfo **dirarray;
+
+/* Array of all thi dirinfo structures sorted by their first
+ block address */
+struct dirinfo **dirsorted;
+
+int dirarrayused; /* number of directories */
+int dirarraysize; /* alloced size of dirarray/dirsorted */
+
+struct dups {
+ struct dups *next;
+ daddr_t dup;
+};
+struct dups *duplist; /* head of dup list */
+struct dups *muldup; /* end of unique duplicate dup block numbers */
+
+
+extern struct fs *sblock;
+
+extern daddr_t maxfsblock;
+extern int maxino;
+extern int direct_symlink_extension;
+
+extern int newinofmt;
+
+/* Terse automatic mode for noninteractive use; punts on severe problems. */
+extern int preen;
+
+extern int readfd, writefd;
+
+extern int fix_denied;
+
+extern int fsmodified;
+
+extern ino_t lfdir;
+
+/* Total number of files found on the partition. */
+extern long num_files;
+
+extern mode_t lfmode;
+extern char *lfname;
+
+#define NBBY 8
+#define howmany(x,y) (((x)+((y)-1))/(y))
+#define roundup(x, y) ((((x)+((y)-1))/(y))*(y))
+#define isclr(a, i) (((a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0)
+#define isset(a, i) ((a)[(i)/NBBY] & (1<<((i)%NBBY)))
+#define setbit(a,i) ((a)[(i)/NBBY] |= 1<<((i)%NBBY))
+#define clrbit(a,i) ((a)[(i)/NBBY] &= ~(1<<(i)%NBBY))
+#define DEV_BSIZE 512
+
+#define setbmap(blkno) setbit (blockmap, blkno)
+#define testbmap(blkno) isset (blockmap, blkno)
+#define clrbmap(blkno) clrbit (blockmap, blkno)
+
+#define DI_MODE(dp) (((dp)->di_modeh << 16) | (dp)->di_model)
+
+
+
+int setup (char *);
+void pass1 (), pass1b (), pass2 (), pass3 (), pass4 (), pass5 ();
+
+void readblock (daddr_t, void *, size_t);
+void writeblock (daddr_t, void *, size_t);
+
+void getinode (ino_t, struct dinode *);
+void write_inode (ino_t, struct dinode *);
+void clear_inode (ino_t, struct dinode *);
+
+daddr_t allocblk (int);
+int check_range (daddr_t, int);
+
+ino_t allocino (ino_t, mode_t);
+void freeino (ino_t);
+ino_t allocdir (ino_t, ino_t, mode_t);
+
+int makeentry (ino_t, ino_t, char *);
+int changeino (ino_t, char *, ino_t);
+
+int linkup (ino_t, ino_t);
+
+void datablocks_iterate (struct dinode *, int (*)(daddr_t, int, off_t));
+void allblock_iterate (struct dinode *, int (*)(daddr_t, int, off_t));
+
+void record_directory (struct dinode *, ino_t);
+struct dirinfo *lookup_directory (ino_t);
+
+void errexit (char *, ...) __attribute__ ((format (printf, 1, 2), noreturn));
+void warning (int, char *, ...) __attribute__ ((format (printf, 2, 3)));
+void problem (int, char *, ...) __attribute__ ((format (printf, 2, 3)));
+void pinode (int, ino_t, char *fmt, ...) __attribute__ ((format (printf, 3, 4)));
+void pextend (char *, ...) __attribute__ ((format (printf, 1, 2)));
+void pfix (char *fix), pfail (char *reason);
+int reply (char *);
diff --git a/ufs-fsck/inode.c b/ufs-fsck/inode.c
new file mode 100644
index 00000000..df4b880e
--- /dev/null
+++ b/ufs-fsck/inode.c
@@ -0,0 +1,203 @@
+/* Inode allocation, deallocation, etc.
+ Copyright (C) 1994, 1996 Free Software Foundation, Inc.
+ Written by Michael I. Bushnell.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#include "fsck.h"
+
+static void
+inode_iterate (struct dinode *dp,
+ int (*fn) (daddr_t, int, off_t),
+ int doaddrblocks)
+{
+ mode_t mode = dp->di_model & IFMT;
+ int nb, maxb;
+ off_t totaloffset = 0;
+
+ /* Call FN for iblock IBLOCK of level LEVEL and recurse down
+ the indirect block pointers. */
+ int
+ scaniblock (daddr_t iblock, int level)
+ {
+ int cont;
+ daddr_t ptrs[NINDIR(sblock)];
+ int i;
+
+ if (doaddrblocks)
+ {
+ cont = (*fn)(iblock, sblock->fs_frag, totaloffset);
+ if (cont == RET_STOP)
+ return RET_STOP;
+ else if (cont == RET_BAD)
+ return RET_GOOD;
+ }
+
+ readblock (fsbtodb (sblock, iblock), ptrs, sblock->fs_bsize);
+ for (i = 0; i < NINDIR (sblock); i++)
+ {
+ if (!ptrs[i])
+ continue;
+
+ if (level == 0)
+ {
+ cont = (*fn)(ptrs[i], sblock->fs_frag, totaloffset);
+ totaloffset += sblock->fs_bsize;
+ }
+ else
+ cont = scaniblock (ptrs[i], level - 1);
+ if (cont == RET_STOP)
+ return RET_STOP;
+ }
+ return RET_GOOD;
+ }
+
+ if (mode == IFBLK || mode == IFCHR
+ || (mode == IFLNK && sblock->fs_maxsymlinklen != -1
+ && (dp->di_size < sblock->fs_maxsymlinklen
+ || (sblock->fs_maxsymlinklen == 0 && dp->di_blocks == 0))))
+ return;
+
+ maxb = lblkno (sblock, dp->di_size - 1);
+ totaloffset = 0;
+ for (nb = 0; nb < NDADDR; nb++)
+ {
+ int offset;
+ int nfrags;
+
+ if (nb == maxb && (offset = blkoff (sblock, dp->di_size)))
+ nfrags = numfrags (sblock, fragroundup (sblock, offset));
+ else
+ nfrags = sblock->fs_frag;
+
+ if (dp->di_db[nb]
+ && (*fn)(dp->di_db[nb], nfrags, totaloffset) != RET_GOOD)
+ return;
+ totaloffset += nfrags * sizeof (sblock->fs_fsize);
+ }
+
+ for (nb = 0; nb < NIADDR; nb++)
+ if (dp->di_ib[nb] && scaniblock (dp->di_ib[nb], nb) != RET_GOOD)
+ return;
+
+ if (doaddrblocks && dp->di_trans)
+ (*fn)(dp->di_trans, sblock->fs_frag, totaloffset);
+}
+
+void
+datablocks_iterate (struct dinode *dp,
+ int (*fn) (daddr_t, int, off_t))
+{
+ inode_iterate (dp, fn, 0);
+}
+
+void
+allblock_iterate (struct dinode *dp,
+ int (*fn) (daddr_t, int, off_t))
+{
+ inode_iterate (dp, fn, 1);
+}
+
+/* Allocate an inode. If INUM is nonzero, then allocate that
+ node specifically, otherwise allocate any available inode.
+ MODE is the mode of the new file. Return the allocated
+ inode number (or 0 if the allocation failed). */
+ino_t
+allocino (ino_t request, mode_t mode)
+{
+ ino_t ino;
+ struct dinode dino;
+ struct timeval tv;
+
+ if (request)
+ {
+ if (inodestate[request] != UNALLOC)
+ return 0;
+ ino = request;
+ }
+ else
+ {
+ for (ino = ROOTINO; ino < maxino; ino++)
+ if (inodestate[ino] == UNALLOC)
+ break;
+ if (ino == maxino)
+ return 0;
+ }
+
+ if ((mode & IFMT) == IFDIR)
+ inodestate[ino] = DIRECTORY | DIR_REF;
+ else
+ inodestate[ino] = REG;
+
+ getinode (ino, &dino);
+ dino.di_modeh = (mode & 0xffff0000) >> 16;
+ dino.di_model = (mode & 0x0000ffff);
+ gettimeofday (&tv, 0);
+ dino.di_atime.tv_sec = tv.tv_sec;
+ dino.di_atime.tv_nsec = tv.tv_usec * 1000;
+ dino.di_mtime = dino.di_ctime = dino.di_atime;
+ dino.di_size = 0;
+ dino.di_blocks = 0;
+ num_files++;
+ write_inode (ino, &dino);
+ typemap[ino] = IFTODT (mode);
+ return ino;
+}
+
+/* Deallocate inode INUM. */
+void
+freeino (ino_t inum)
+{
+ struct dinode dino;
+
+ int
+ clearblock (daddr_t bno, int nfrags, off_t offset)
+ {
+ int i;
+
+ for (i = 0; i < nfrags; i++)
+ {
+ if (check_range (bno + i, 1))
+ return RET_BAD;
+ if (testbmap (bno + i))
+ {
+ struct dups *dlp;
+ for (dlp = duplist; dlp; dlp = dlp->next)
+ {
+ if (dlp->dup != bno + i)
+ continue;
+ dlp->dup = duplist->dup;
+ dlp = duplist;
+ duplist = duplist->next;
+ free (dlp);
+ break;
+ }
+ if (dlp == 0)
+ clrbmap (bno + i);
+ }
+ }
+ return RET_GOOD;
+ }
+
+ getinode (inum, &dino);
+ allblock_iterate (&dino, clearblock);
+
+ clear_inode (inum, &dino);
+ inodestate[inum] = UNALLOC;
+
+ num_files--;
+}
diff --git a/ufs-fsck/main.c b/ufs-fsck/main.c
new file mode 100644
index 00000000..34c32a67
--- /dev/null
+++ b/ufs-fsck/main.c
@@ -0,0 +1,170 @@
+/* Main program for GNU fsck
+ Copyright (C) 1994, 1996, 1997 Free Software Foundation, Inc.
+ Written by Michael I. Bushnell.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#include <errno.h>
+#include <argp.h>
+#include <hurd.h>
+#include <version.h>
+
+#include "fsck.h"
+
+const char *argp_program_version = STANDARD_HURD_VERSION (fsck.ufs);
+
+char *lfname = "lost+found";
+mode_t lfmode = 0755;
+
+/* Terse automatic mode for noninteractive use; punts on severe problems. */
+int preen = 0;
+
+/* Total number of files found on the partition. */
+long num_files = 0;
+
+static struct argp_option options[] =
+{
+ {"preen", 'p', 0, 0, "Terse automatic mode", 1},
+ {"yes", 'y', 0, 0, "Automatically answer yes to all questions"},
+ {"no", 'n', 0, 0, "Automatically answer no to all questions"},
+ {"lost+found", 'l', "NAME", 0, "The name of the lost+found directory in /"},
+ {"lf-mode", 'm', "MODE", 0, "The mode of the lost+found directory in /"},
+ {0, 0, 0, 0, "In --preen mode, the following also apply:", 2},
+ {"force", 'f', 0, 0, "Check even if clean"},
+ {"silent", 's', 0, 0, "Only print diagostic messages"},
+ {0, 0}
+};
+char *args_doc = "DEVICE";
+
+/* Returns a malloced buffer containing a nice printable size for FRAGS. */
+static char *
+nice_size (long frags)
+{
+ char *rep;
+ char *units = "KMGT", *u = units;
+ float num = ((float)frags * sblock->fs_fsize) / 1024;
+
+ while (num > 1024)
+ {
+ num /= 1024;
+ u++;
+ }
+
+ asprintf (&rep, num >= 1000 ? "%.0f%c" : "%.3g%c", num, *u);
+
+ return rep;
+}
+
+/* Print summary statistics. */
+static void
+show_stats ()
+{
+ long num_ffree = sblock->fs_cstotal.cs_nffree;
+ long num_bfree = sblock->fs_cstotal.cs_nbfree;
+ long tot_ffree = num_ffree + sblock->fs_frag * num_bfree;
+ char *urep = nice_size (sblock->fs_dsize - tot_ffree);
+ char *frep = nice_size (tot_ffree);
+ warning (0, "%ld files, %s used, %s free (%ld.%ld%% fragmentation)",
+ num_files, urep, frep,
+ (num_ffree * 100) / sblock->fs_dsize,
+ (((num_ffree * 1000 + sblock->fs_dsize / 2) / sblock->fs_dsize)
+ % 10));
+ free (urep);
+ free (frep);
+}
+
+int
+main (int argc, char **argv)
+{
+ int silent = 0, force = 0;
+ char *device = 0;
+ error_t parse_opt (int key, char *arg, struct argp_state *state)
+ {
+ switch (key)
+ {
+ case 'p': preen = 1; break;
+ case 'y': noquery = 1; break;
+ case 'n': nowrite = 1; break;
+ case 'l': lfname = arg; break;
+ case 'm': lfmode = strtol (arg, 0, 8); break;
+ case 'f': force = 1; break;
+ case 's': silent = 1; break;
+ case ARGP_KEY_ARG:
+ if (!device)
+ {
+ device = arg;
+ break;
+ }
+ /* Fall through */
+ case ARGP_KEY_NO_ARGS:
+ argp_usage (state);
+ default:
+ return ARGP_ERR_UNKNOWN;
+ }
+ return 0;
+ }
+ struct argp argp = {options, parse_opt, args_doc};
+
+ preen = nowrite = noquery = 0;
+ argp_parse (&argp, argc, argv, 0, 0, 0);
+
+ if (!setup (device))
+ exit (1);
+
+ if (preen && sblock->fs_clean && !force)
+ {
+ if (! silent)
+ warning (0, "FILESYSTEM CLEAN");
+ }
+ else
+ {
+ if (!preen)
+ printf ("** Phase 1 -- Check Blocks and Sizes\n");
+ pass1 ();
+
+ if (duplist)
+ {
+ if (!preen)
+ printf ("** Phase 1b -- Rescan for More Duplicates\n");
+ pass1b ();
+ }
+
+ if (!preen)
+ printf ("** Phase 2 -- Check Pathnames\n");
+ pass2 ();
+
+ if (!preen)
+ printf ("** Phase 3 -- Check Connectivity\n");
+ pass3 ();
+
+ if (!preen)
+ printf ("** Phase 4 -- Check Reference Counts\n");
+ pass4 ();
+
+ if (!preen)
+ printf ("** Phase 5 -- Check Cyl Groups\n");
+ pass5 ();
+
+ if (! silent)
+ show_stats (sblock);
+ }
+
+ if (fsmodified && !preen)
+ printf ("\n***** FILE SYSTEM WAS MODIFIED *****\n");
+
+ exit (fsmodified ? 2 : 0);
+}
diff --git a/ufs-fsck/pass1.c b/ufs-fsck/pass1.c
new file mode 100644
index 00000000..bd41cc62
--- /dev/null
+++ b/ufs-fsck/pass1.c
@@ -0,0 +1,437 @@
+/* Pass one of GNU fsck -- count blocks and verify inodes
+ Copyright (C) 1994,95,96,2002 Free Software Foundation, Inc.
+ Written by Michael I. Bushnell.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+
+
+#include "fsck.h"
+
+static struct dinode zino;
+
+/* Find all the blocks in use by files and filesystem reserved blocks.
+ Set them in the global block map. For each file, if a block is found
+ allocated twice, then record the block and inode in DUPLIST.
+ Initialize INODESTATE, LINKCOUNT, and TYPEMAP. */
+void
+pass1 ()
+{
+ ino_t number;
+ ino_t i;
+ int cg;
+ struct dinode dino;
+ struct dinode *dp = &dino;
+ mode_t mode, type;
+ int ndb;
+ int holdallblocks;
+ int lbn;
+ int nblocks;
+ int blkerror;
+ int nblkrngerrors;
+ int nblkduperrors;
+
+ /* This function is called for each block of DP. Check to see
+ if the block number is valid. If so, set the entry in the
+ block map. If the block map entry is already set, then keep
+ track of this block and see if the user wants to clear the
+ node. Increment NBLOCKS by the number of data blocks held.
+ Set BLKERROR if this block is invalid.
+ Return RET_GOOD, RET_BAD, RET_STOP if the block is good,
+ bad, or if we should entirely stop checking blocks in this
+ inode. */
+ int
+ checkblock (daddr_t bno, int nfrags, off_t offset)
+ {
+#define MAXBAD 10
+ int outofrange;
+ struct dups *dlp, *new;
+ int wasbad = 0;
+
+ /* Check to see if this block is in range */
+ outofrange = check_range (bno, nfrags);
+ if (outofrange)
+ {
+ blkerror = 1;
+ wasbad = 1;
+ if (nblkrngerrors == 0)
+ warning (0, "I=%Ld HAS BAD BLOCKS", number);
+ if (nblkrngerrors++ > MAXBAD)
+ {
+ problem (0, "EXCESSIVE BAD BLKS I=%Ld", number);
+ if (preen || reply ("SKIP"))
+ {
+ pfail ("SKIPPING");
+ return RET_STOP;
+ }
+ }
+ }
+
+ for (; nfrags > 0; bno++, nfrags--)
+ {
+ if (outofrange && check_range (bno, 1))
+ warning (0, "BAD BLOCK %lu", bno);
+ else
+ {
+ if (!testbmap (bno))
+ setbmap (bno);
+ else
+ {
+ blkerror = 1;
+ if (nblkduperrors == 0)
+ warning (0, "I=%Ld HAS DUPLICATE BLOCKS", number);
+ warning (0, "DUPLICATE BLOCK %ld", bno);
+ wasbad = 1;
+ if (nblkduperrors++ > MAXBAD)
+ {
+ problem (0, "EXCESSIVE DUP BLKS I=%Ld", number);
+ if (preen || reply ("SKIP"))
+ {
+ pfail ("SKIPPING");
+ return RET_STOP;
+ }
+ }
+ new = malloc (sizeof (struct dups));
+ new->dup = bno;
+ if (muldup == 0)
+ {
+ duplist = muldup = new;
+ new->next = 0;
+ }
+ else
+ {
+ new->next = muldup->next;
+ muldup->next = new;
+ }
+ for (dlp = duplist; dlp != muldup; dlp = dlp->next)
+ if (dlp->dup == bno)
+ break;
+ if (dlp == muldup && dlp->dup != bno)
+ muldup = new;
+ }
+ }
+ nblocks += sblock->fs_fsize / DEV_BSIZE;
+ }
+ return wasbad ? RET_BAD : RET_GOOD;
+ }
+
+
+ /* Account for blocks used by meta data */
+ for (cg = 0; cg < sblock->fs_ncg; cg++)
+ {
+ daddr_t firstdata, firstcgblock, bno;
+
+ /* Each cylinder group past the first reserves data
+ from its cylinder group copy to (but not including)
+ the first datablock.
+
+ The first, however, reserves from the very front of the
+ cylinder group (thus including the boot block), and it also
+ reserves the data blocks holding the csum information. */
+ firstdata = cgdmin (sblock, cg);
+ if (cg == 0)
+ {
+ firstcgblock = cgbase (sblock, cg);
+ firstdata += howmany (sblock->fs_cssize, sblock->fs_fsize);
+ }
+ else
+ firstcgblock = cgsblock (sblock, cg);
+
+ /* Mark the blocks set */
+ for (bno = firstcgblock; bno < firstdata; bno++)
+ setbmap (bno);
+ }
+
+ /* Loop through each inode, doing initial checks */
+ for (number = 0, cg = 0; cg < sblock->fs_ncg; cg++)
+ for (i = 0; i < sblock->fs_ipg; i++, number++)
+ {
+ /* These record whether we've already complained about extra
+ direct/indirect blocks. */
+ int dbwarn = 0, ibwarn = 0;
+
+/* if (!preen && !(number % 10000))
+ printf ("I=%Ld\n", number); */
+
+ if (number < ROOTINO)
+ continue;
+
+ getinode (number, dp);
+ mode = DI_MODE (dp);
+ type = mode & IFMT;
+
+ /* If the node is not allocated, then make sure it's
+ properly clear */
+ if (type == 0)
+ {
+ if (bcmp (dp->di_db, zino.di_db, NDADDR * sizeof (daddr_t))
+ || bcmp (dp->di_ib, zino.di_ib, NIADDR * sizeof (daddr_t))
+ || dp->di_trans
+ || DI_MODE (dp)
+ || dp->di_size)
+ {
+ problem (0, "PARTIALLY ALLOCATED INODE I=%Ld", number);
+ if (preen || reply ("CLEAR"))
+ {
+ clear_inode (number, dp);
+ pfix ("CLEARED");
+ }
+ }
+ inodestate[number] = UNALLOC;
+ }
+ else
+ {
+ /* Node is allocated. */
+
+ /* Check to see if we think the node should be cleared */
+
+ /* Verify size for basic validity */
+ holdallblocks = 0;
+
+ if (dp->di_size + sblock->fs_bsize - 1 < dp->di_size)
+ {
+ problem (1, "OVERFLOW IN FILE SIZE I=%Ld (SIZE == %lld)", number,
+ dp->di_size);
+ if (reply ("CLEAR"))
+ {
+ clear_inode (number, dp);
+ inodestate[number] = UNALLOC;
+ continue;
+ }
+ inodestate[number] = UNALLOC;
+ warning (0, "WILL TREAT ANY BLOCKS HELD BY I=%Ld AS ALLOCATED",
+ number);
+ holdallblocks = 1;
+ }
+
+ /* Decode type and set NDB
+ also set inodestate correctly. */
+ inodestate[number] = REG;
+ switch (type)
+ {
+ case IFBLK:
+ case IFCHR:
+ ndb = 1;
+ break;
+
+ case IFIFO:
+ case IFSOCK:
+ ndb = 0;
+ break;
+
+ case IFLNK:
+ if (sblock->fs_maxsymlinklen != -1)
+ {
+ /* Check to see if this is a fastlink. The
+ old fast link format has fs_maxsymlinklen
+ of zero and di_blocks zero; the new format has
+ fs_maxsymlinklen set and we ignore di_blocks.
+ So check for either. */
+ if ((sblock->fs_maxsymlinklen
+ && dp->di_size < sblock->fs_maxsymlinklen)
+ || (!sblock->fs_maxsymlinklen && !dp->di_blocks))
+ {
+ /* Fake NDB value so that we will check
+ all the block pointers past the symlink */
+ ndb = howmany (dp->di_size, sizeof (daddr_t));
+ if (ndb > NDADDR)
+ {
+ int j = ndb - NDADDR;
+ for (ndb = 1; j > 1; i--)
+ ndb *= NINDIR (sblock);
+ ndb += NDADDR;
+ }
+ }
+ else
+ ndb = howmany (dp->di_size, sblock->fs_bsize);
+ }
+ else
+ ndb = howmany (dp->di_size, sblock->fs_bsize);
+ break;
+
+ case IFDIR:
+ inodestate[number] = DIRECTORY;
+ /* Fall through */
+ case IFREG:
+ ndb = howmany (dp->di_size, sblock->fs_bsize);
+ break;
+
+ default:
+ problem (1, "UNKNOWN FILE TYPE I=%Ld (MODE=%ol)", number, mode);
+ if (reply ("CLEAR"))
+ {
+ clear_inode (number, dp);
+ inodestate[number] = UNALLOC;
+ continue;
+ }
+ inodestate[number] = UNALLOC;
+ holdallblocks = 1;
+ warning (0, "WILL TREAT ANY BLOCKS HELD BY I=%Ld "
+ "AS ALLOCATED", number);
+ ndb = 0;
+ }
+
+ if (ndb < 0)
+ {
+ problem (1, "BAD FILE SIZE I= %Ld (SIZE == %lld)", number,
+ dp->di_size);
+ if (reply ("CLEAR"))
+ {
+ clear_inode (number, dp);
+ inodestate[number] = UNALLOC;
+ continue;
+ }
+ inodestate[number] = UNALLOC;
+ warning (0, "WILL TREAT ANY BLOCKS HELD BY I=%Ld AS ALLOCATED",
+ number);
+ holdallblocks = 1;
+ }
+
+ /* Make sure that direct and indirect block pointers
+ past the file size are zero. If the size is bogus, then
+ don't bother (they should all be zero, but the user has
+ requested that they be treated as allocated). */
+ if (!holdallblocks)
+ {
+ if (dp->di_size
+ && (type == IFBLK || type == IFCHR
+ || type == IFSOCK || type == IFIFO))
+ {
+ problem (1, "SPECIAL NODE I=%Ld (MODE=%ol) HAS SIZE %lld",
+ number, mode, dp->di_size);
+ if (reply ("TRUNCATE"))
+ {
+ dp->di_size = 0;
+ write_inode (number, dp);
+ }
+ }
+
+ /* If we haven't set NDB speciall above, then it is set from
+ the file size correctly by the size check. */
+
+ /* Check all the direct and indirect blocks that are past the
+ amount necessary to be zero. */
+ for (lbn = ndb; lbn < NDADDR; lbn++)
+ {
+ if (dp->di_db[lbn])
+ {
+ if (!dbwarn)
+ {
+ dbwarn = 1;
+ problem (0, "INODE I=%Ld HAS EXTRA DIRECT BLOCKS",
+ number);
+ if (preen || reply ("DEALLOCATE"))
+ {
+ dp->di_db[lbn] = 0;
+ dbwarn = 2;
+ pfix ("DEALLOCATED");
+ }
+ }
+ else if (dbwarn == 2)
+ dp->di_db[lbn] = 0;
+ }
+ if (dbwarn == 2)
+ write_inode (number, dp);
+ }
+
+ for (lbn = 0, ndb -= NDADDR; ndb > 0; lbn++)
+ ndb /= NINDIR (sblock);
+ for (; lbn < NIADDR; lbn++)
+ {
+ if (dp->di_ib[lbn])
+ {
+ if (ibwarn)
+ {
+ ibwarn = 1;
+ problem (0, "INODE I=%Ld HAS EXTRA INDIRECT BLOCKS",
+ number);
+ if (preen || reply ("DEALLOCATE"))
+ {
+ dp->di_ib[lbn] = 0;
+ ibwarn = 2;
+ pfix ("DEALLOCATED");
+ }
+ }
+ else if (ibwarn == 2)
+ dp->di_ib[lbn] = 0;
+ }
+ if (ibwarn == 2)
+ write_inode (number, dp);
+ }
+ }
+
+ /* If this node is really allocated (as opposed to something
+ that we should clear but the user won't) then set LINKCOUNT
+ and TYPEMAP entries. */
+ if (inodestate[number] != UNALLOC)
+ {
+ linkcount[number] = dp->di_nlink;
+ typemap[number] = IFTODT (mode);
+ }
+
+ /* Iterate over the blocks of the file,
+ calling CHECKBLOCK for each file. */
+ nblocks = 0;
+ blkerror = 0;
+ nblkduperrors = 0;
+ nblkrngerrors = 0;
+ allblock_iterate (dp, checkblock);
+
+ if (blkerror)
+ {
+ if (preen)
+ warning (1, "DUPLICATE or BAD BLOCKS");
+ else
+ {
+ problem (0, "I=%Ld has ", number);
+ if (nblkduperrors)
+ {
+ pextend ("%d DUPLICATE BLOCKS", nblkduperrors);
+ if (nblkrngerrors)
+ pextend (" and ");
+ }
+ if (nblkrngerrors)
+ pextend ("%d BAD BLOCKS", nblkrngerrors);
+ if (reply ("CLEAR"))
+ {
+ clear_inode (number, dp);
+ inodestate[number] = UNALLOC;
+ continue;
+ }
+ else if (inodestate[number] == DIRECTORY)
+ inodestate[number] = BADDIR;
+ }
+ }
+ else if (dp->di_blocks != nblocks)
+ {
+ problem (0, "INCORRECT BLOCK COUNT I=%Ld (%ld should be %d)",
+ number, dp->di_blocks, nblocks);
+ if (preen || reply ("CORRECT"))
+ {
+ dp->di_blocks = nblocks;
+ write_inode (number, dp);
+ pfix ("CORRECTED");
+ }
+ }
+
+ num_files++;
+
+ if (type == IFDIR)
+ record_directory (dp, number);
+ }
+ }
+}
diff --git a/ufs-fsck/pass1b.c b/ufs-fsck/pass1b.c
new file mode 100644
index 00000000..4da86974
--- /dev/null
+++ b/ufs-fsck/pass1b.c
@@ -0,0 +1,90 @@
+/* Pass 1b of fsck -- scan inodes for references to duplicate blocks
+ Copyright (C) 1994,96,2002 Free Software Foundation, Inc.
+ Written by Michael I. Bushnell.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#include "fsck.h"
+
+void
+pass1b ()
+{
+ struct dinode dino;
+ struct dinode *dp = &dino;
+ int cg, i;
+ ino_t number = 0;
+ int dupblk;
+ struct dups *duphead = duplist;
+
+ /* Check each block of file DP; if the block is in the dup block
+ list then add it to the dup block list under this file.
+ Return RET_GOOD or RET_BAD if the block is
+ good or bad, respectively. */
+ int
+ checkblock (daddr_t bno, int nfrags, off_t offset)
+ {
+ struct dups *dlp;
+ int hadbad = 0;
+
+ for (; nfrags > 0; bno++, nfrags--)
+ {
+ if (check_range (bno, 1))
+ return RET_BAD;
+ for (dlp = duphead; dlp; dlp = dlp->next)
+ {
+ if (dlp->dup == bno)
+ {
+ dupblk++;
+ warning (0, "DUPLICATE BLOCK %ld\n", bno);
+ dlp->dup = duphead->dup;
+ duphead->dup = bno;
+ duphead = duphead->next;
+ hadbad = 1;
+ }
+ if (dlp == muldup)
+ break;
+ }
+ }
+ return hadbad ? RET_BAD : RET_GOOD;
+ }
+
+ /* Call CHECKBLOCK for each block of each node, to see if it holds
+ a block already found to be a duplicate. */
+ for (cg = 0; cg < sblock->fs_ncg; cg++)
+ for (i = 0; i < sblock->fs_ipg; i++, number++)
+ {
+ if (number < ROOTINO)
+ continue;
+ if (inodestate[number] != UNALLOC)
+ {
+ getinode (number, dp);
+ dupblk = 0;
+ allblock_iterate (dp, checkblock);
+ if (dupblk)
+ {
+ problem (1, "I=%Ld HAS %d DUPLICATE BLOCKS", number, dupblk);
+ if (reply ("CLEAR"))
+ {
+ clear_inode (number, dp);
+ inodestate[number] = UNALLOC;
+ }
+ else if (inodestate[number] == DIRECTORY)
+ inodestate[number] = BADDIR;
+ }
+ }
+ }
+}
diff --git a/ufs-fsck/pass2.c b/ufs-fsck/pass2.c
new file mode 100644
index 00000000..d95929ef
--- /dev/null
+++ b/ufs-fsck/pass2.c
@@ -0,0 +1,400 @@
+/* Pass 2 of GNU fsck -- examine all directories for validity
+ Copyright (C) 1994,96,2002 Free Software Foundation, Inc.
+ Written by Michael I. Bushnell.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#include "fsck.h"
+#include <assert.h>
+
+/* Verify root inode's allocation and check all directories for
+ viability. Set DIRSORTED array fully and check to make sure
+ each directory has a correct . and .. in it. */
+void
+pass2 ()
+{
+ int nd;
+ struct dirinfo *dnp;
+ struct dinode dino;
+
+ /* Return negative, zero, or positive according to the
+ ordering of the first data block of **DNP1 and **DNP2. */
+ int
+ sortfunc (const void *ptr1, const void *ptr2)
+ {
+ struct dirinfo * const *dnp1 = ptr1;
+ struct dirinfo * const *dnp2 = ptr2;
+ return ((*dnp1)->i_blks[0] - (*dnp2)->i_blks[0]);
+ }
+
+ /* Called for each DIRBLKSIZ chunk of the directory.
+ BUF is the data of the directory block. Return
+ 1 if this block has been modified and should be written
+ to disk; otherwise return 0. */
+ int
+ check1block (void *buf)
+ {
+ struct directory_entry *dp;
+ int mod = 0;
+ u_char namlen;
+ char type;
+ int i;
+
+ for (dp = buf; (void *)dp - buf < DIRBLKSIZ;
+ dp = (struct directory_entry *) ((void *)dp + dp->d_reclen))
+ {
+ /* Check RECLEN for basic validity */
+ if (dp->d_reclen == 0
+ || dp->d_reclen + (void *)dp - buf > DIRBLKSIZ)
+ {
+ /* Perhaps the entire dir block is zero. UFS does that
+ when extending directories. So allow preening
+ to safely patch up all-null dir blocks. */
+ if (dp == buf)
+ {
+ char *bp;
+ for (bp = (char *)buf; bp < (char *)buf + DIRBLKSIZ; bp++)
+ if (*bp)
+ goto reclen_problem;
+
+ problem (0, "NULL BLOCK IN DIRECTORY");
+ if (preen || reply ("PATCH"))
+ {
+ /* Mark this entry free, and return. */
+ dp->d_ino = 0;
+ dp->d_reclen = DIRBLKSIZ;
+ pfix ("PATCHED");
+ return 1;
+ }
+ else
+ return mod;
+ }
+
+ reclen_problem:
+ problem (1, "BAD RECLEN IN DIRECTORY");
+ if (reply ("SALVAGE"))
+ {
+ /* Skip over everything else in this dirblock;
+ mark this entry free. */
+ dp->d_ino = 0;
+ dp->d_reclen = DIRBLKSIZ - ((void *)dp - buf);
+ return 1;
+ }
+ else
+ /* But give up regardless */
+ return mod;
+ }
+
+ /* Check INO */
+ if (dp->d_ino > maxino)
+ {
+ problem (1, "BAD INODE NUMBER IN DIRECTORY");
+ if (reply ("SALVAGE"))
+ {
+ /* Mark this entry clear */
+ dp->d_ino = 0;
+ mod = 1;
+ }
+ }
+
+ if (!dp->d_ino)
+ continue;
+
+ /* Check INO */
+ if (inodestate[dp->d_ino] == UNALLOC)
+ {
+ pinode (0, dnp->i_number, "REF TO UNALLOCATED NODE IN");
+ if (preen || reply ("REMOVE"))
+ {
+ dp->d_ino = 0;
+ mod = 1;
+ pfix ("REMOVED");
+ continue;
+ }
+ }
+
+ /* Check NAMLEN */
+ namlen = DIRECT_NAMLEN (dp);
+ if (namlen > MAXNAMLEN)
+ {
+ problem (1, "BAD NAMLEN IN DIRECTORY");
+ if (reply ("SALVAGE"))
+ {
+ /* Mark this entry clear */
+ dp->d_ino = 0;
+ mod = 1;
+ }
+ }
+ else
+ {
+ /* Check for illegal characters */
+ for (i = 0; i < DIRECT_NAMLEN (dp); i++)
+ if (dp->d_name[i] == '\0' || dp->d_name[i] == '/')
+ {
+ problem (1, "ILLEGAL CHARACTER IN FILE NAME");
+ if (reply ("SALVAGE"))
+ {
+ /* Mark this entry clear */
+ dp->d_ino = 0;
+ mod = 1;
+ break;
+ }
+ }
+ if (dp->d_name[DIRECT_NAMLEN (dp)])
+ {
+ problem (1, "DIRECTORY NAME NOT TERMINATED");
+ if (reply ("SALVAGE"))
+ {
+ /* Mark this entry clear */
+ dp->d_ino = 0;
+ mod = 1;
+ }
+ }
+ }
+
+ if (!dp->d_ino)
+ continue;
+
+ /* Check TYPE */
+ type = DIRECT_TYPE (dp);
+ if (type != DT_UNKNOWN && type != typemap[dp->d_ino])
+ {
+ problem (0, "INCORRECT NODE TYPE IN DIRECTORY");
+ if (preen || reply ("CLEAR"))
+ {
+ pfix ("CLEARED");
+ dp->d_type = 0;
+ mod = 1;
+ }
+ }
+
+ /* Here we should check for duplicate directory entries;
+ that's too much trouble right now. */
+
+ /* Account for the inode in the linkfound map */
+ if (inodestate[dp->d_ino] != UNALLOC)
+ linkfound[dp->d_ino]++;
+
+ if (inodestate[dp->d_ino] == DIRECTORY
+ || inodestate[dp->d_ino] == BADDIR)
+ {
+ if (DIRECT_NAMLEN (dp) == 1 && dp->d_name[0] == '.')
+ dnp->i_dot = dp->d_ino;
+ else if (DIRECT_NAMLEN (dp) == 2
+ && dp->d_name[0] == '.' && dp->d_name[1] == '.')
+ dnp->i_dotdot = dp->d_ino;
+ else
+ {
+ struct dirinfo *targetdir;
+ targetdir = lookup_directory (dp->d_ino);
+ if (targetdir->i_parent)
+ {
+ problem (0, "EXTRANEOUS LINK `%s' TO DIR I=%ld",
+ dp->d_name, dp->d_ino);
+ pextend (" FOUND IN DIR I=%Ld", dnp->i_number);
+ if (preen || reply ("REMOVE"))
+ {
+ dp->d_ino = 0;
+ mod = 1;
+ pfix ("REMOVED");
+ }
+ }
+ else
+ targetdir->i_parent = dnp->i_number;
+ }
+ }
+ }
+ return mod;
+ }
+
+ /* Called for each filesystem block of the directory. Load BNO
+ into core and then call CHECK1BLOCK for each DIRBLKSIZ chunk.
+ OFFSET is the offset this block occupies ithe file.
+ Always return 1. */
+ int
+ checkdirblock (daddr_t bno, int nfrags, off_t offset)
+ {
+ void *buf = alloca (nfrags * sblock->fs_fsize);
+ void *bufp;
+ int rewrite;
+
+ readblock (fsbtodb (sblock, bno), buf, nfrags * sblock->fs_fsize);
+ rewrite = 0;
+ for (bufp = buf;
+ bufp - buf < nfrags * sblock->fs_fsize
+ && offset + (bufp - buf) + DIRBLKSIZ <= dnp->i_isize;
+ bufp += DIRBLKSIZ)
+ {
+ if (check1block (bufp))
+ rewrite = 1;
+ }
+ if (rewrite)
+ writeblock (fsbtodb (sblock, bno), buf, nfrags * sblock->fs_fsize);
+ return 1;
+ }
+
+ switch (inodestate [ROOTINO])
+ {
+ default:
+ errexit ("BAD STATE %d FOR ROOT INODE", (int) (inodestate[ROOTINO]));
+
+ case DIRECTORY:
+ break;
+
+ case UNALLOC:
+ problem (1, "ROOT INODE UNALLOCATED");
+ if (!reply ("ALLOCATE"))
+ errexit ("ABORTING");
+ if (allocdir (ROOTINO, ROOTINO, 0755) != ROOTINO)
+ errexit ("CANNOT ALLOCATE ROOT INODE");
+ break;
+
+ case REG:
+ problem (1, "ROOT INODE NOT DIRECTORY");
+ if (reply ("REALLOCATE"))
+ freeino (ROOTINO);
+ if (allocdir (ROOTINO, ROOTINO, 0755) != ROOTINO)
+ errexit ("CANNOT ALLOCATE ROOT INODE");
+ break;
+
+ case BADDIR:
+ problem (1, "DUPLICATE or BAD BLOCKS IN ROOT INODE");
+ if (reply ("REALLOCATE"))
+ {
+ freeino (ROOTINO);
+ if (allocdir (ROOTINO, ROOTINO, 0755) != ROOTINO)
+ errexit ("CANNOT ALLOCATE ROOT INODE");
+ }
+ if (reply ("CONTINUE") == 0)
+ errexit ("ABORTING");
+ break;
+ }
+
+ /* Sort inpsort */
+ qsort (dirsorted, dirarrayused, sizeof (struct dirinfo *), sortfunc);
+
+ /* Check basic integrity of each directory */
+ for (nd = 0; nd < dirarrayused; nd++)
+ {
+ dnp = dirsorted[nd];
+
+ if (dnp->i_isize == 0)
+ continue;
+ if (dnp->i_isize % DIRBLKSIZ)
+ {
+ problem (0, "DIRECTORY INO=%Ld: LENGTH %d NOT MULTIPLE OF %d",
+ dnp->i_number, dnp->i_isize, DIRBLKSIZ);
+ if (preen || reply ("ADJUST"))
+ {
+ getinode (dnp->i_number, &dino);
+ dino.di_size = roundup (dnp->i_isize, DIRBLKSIZ);
+ write_inode (dnp->i_number, &dino);
+ pfix ("ADJUSTED");
+ }
+ }
+ bzero (&dino, sizeof (struct dinode));
+ dino.di_size = dnp->i_isize;
+ assert (dnp->i_numblks <= (NDADDR + NIADDR) * sizeof (daddr_t));
+ bcopy (dnp->i_blks, dino.di_db, dnp->i_numblks);
+
+ datablocks_iterate (&dino, checkdirblock);
+ }
+
+
+ /* At this point for each directory:
+ If this directory is an entry in another directory, then i_parent is
+ set to that node's number.
+ If this directory has a `..' entry, then i_dotdot is set to that link.
+ Check to see that `..' is set correctly. */
+ for (nd = 0; nd < dirarrayused; nd++)
+ {
+ dnp = dirsorted[nd];
+
+ /* Root is considered to be its own parent even though it isn't
+ listed. */
+ if (dnp->i_number == ROOTINO && !dnp->i_parent)
+ dnp->i_parent = ROOTINO;
+
+ /* Check `.' to make sure it exists and is correct */
+ if (dnp->i_dot == 0)
+ {
+ dnp->i_dot = dnp->i_number;
+ pinode (0, dnp->i_number, "MISSING `.' IN");
+ if ((preen || reply ("FIX"))
+ && makeentry (dnp->i_number, dnp->i_number, "."))
+ {
+ linkfound[dnp->i_number]++;
+ pfix ("FIXED");
+ }
+ else
+ pfail (0);
+ }
+ else if (dnp->i_dot != dnp->i_number)
+ {
+ pinode (0, dnp->i_number, "BAD INODE NUMBER FOR `.' IN");
+ if (preen || reply ("FIX"))
+ {
+ ino_t old_dot = dnp->i_dot;
+ dnp->i_dot = dnp->i_number;
+ if (changeino (dnp->i_number, ".", dnp->i_number))
+ {
+ linkfound[dnp->i_number]++;
+ if (inodestate[old_dot] != UNALLOC)
+ linkfound[old_dot]--;
+ pfix ("FIXED");
+ }
+ else
+ pfail (0);
+ }
+ }
+
+ /* Check `..' to make sure it exists and is correct */
+ if (dnp->i_parent && dnp->i_dotdot == 0)
+ {
+ dnp->i_dotdot = dnp->i_parent;
+ pinode (0, dnp->i_number, "MISSING `..' IN");
+ if ((preen || reply ("FIX"))
+ && makeentry (dnp->i_number, dnp->i_parent, ".."))
+ {
+ linkfound[dnp->i_parent]++;
+ pfix ("FIXED");
+ }
+ else
+ pfail (0);
+ }
+ else if (dnp->i_parent && dnp->i_dotdot != dnp->i_parent)
+ {
+ pinode (0, dnp->i_number, "BAD INODE NUMBER FOR `..' IN");
+ if (preen || reply ("FIX"))
+ {
+ ino_t parent = dnp->i_parent, old_dotdot = dnp->i_dotdot;
+ dnp->i_dotdot = parent;
+ if (changeino (dnp->i_number, "..", parent))
+ /* Adjust what the parent's link count should be; the actual
+ count will be corrected in an later pass. */
+ {
+ linkfound[parent]++;
+ if (inodestate[old_dotdot] != UNALLOC)
+ linkfound[old_dotdot]--;
+ pfix ("FIXED");
+ }
+ else
+ pfail (0);
+ }
+ }
+ }
+}
diff --git a/ufs-fsck/pass3.c b/ufs-fsck/pass3.c
new file mode 100644
index 00000000..fd5ad1b0
--- /dev/null
+++ b/ufs-fsck/pass3.c
@@ -0,0 +1,71 @@
+/* Pass 3 of GNU fsck -- Look for disconnected directories
+ Copyright (C) 1994, 1996 Free Software Foundation, Inc.
+ Written by Michael I. Bushnell.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#include "fsck.h"
+
+void
+pass3 ()
+{
+ struct dirinfo *dnp;
+ int nd;
+ int change;
+
+ /* Mark all the directories that can be found from the root. */
+
+ inodestate[ROOTINO] |= DIR_REF;
+
+ do
+ {
+ change = 0;
+ for (nd = 0; nd < dirarrayused; nd++)
+ {
+ dnp = dirsorted[nd];
+ if (dnp->i_parent
+ && inodestate[dnp->i_parent] == (DIRECTORY | DIR_REF)
+ && inodestate[dnp->i_number] == DIRECTORY)
+ {
+ inodestate[dnp->i_number] |= DIR_REF;
+ change = 1;
+ }
+ }
+ }
+ while (change);
+
+ /* Check for orphaned directories */
+ for (nd = 0; nd < dirarrayused; nd++)
+ {
+ dnp = dirsorted[nd];
+
+ if (dnp->i_parent == 0)
+ {
+ if (inodestate[dnp->i_number] & DIR_REF)
+ errexit ("ORPHANED DIR MARKED WITH CONNECT");
+ pinode (0, dnp->i_number, "UNREF");
+ if ((preen || reply ("RECONNECT"))
+ && linkup (dnp->i_number, dnp->i_dotdot))
+ {
+ dnp->i_parent = dnp->i_dotdot = lfdir;
+ pfix ("RECONNECTED");
+ }
+ else
+ pfail (0);
+ }
+ }
+}
diff --git a/ufs-fsck/pass4.c b/ufs-fsck/pass4.c
new file mode 100644
index 00000000..f8fe9814
--- /dev/null
+++ b/ufs-fsck/pass4.c
@@ -0,0 +1,94 @@
+/* Pass 4 of GNU fsck -- Check reference counts
+ Copyright (C) 1994, 1996 Free Software Foundation, Inc.
+ Written by Michael I. Bushnell.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#include "fsck.h"
+
+void
+pass4()
+{
+ ino_t number;
+ /* True if any reconnect attempt failed, in which case we don't try again. */
+ int reconn_failed = 0;
+
+ for (number = ROOTINO; number < maxino; number++)
+ {
+ if (linkfound[number] && inodestate[number] != UNALLOC)
+ {
+ if (linkcount[number] != linkfound[number])
+ {
+ pinode (0, number,
+ "LINK COUNT %d SHOULD BE %d IN",
+ linkcount[number], linkfound[number]);
+ if (preen || reply ("ADJUST"))
+ {
+ struct dinode dino;
+ getinode (number, &dino);
+ dino.di_nlink = linkfound[number];
+ write_inode (number, &dino);
+ pfix ("ADJUSTED");
+ }
+ }
+ }
+ else if (linkfound[number] && inodestate[number] == UNALLOC)
+ {
+ /* This can't happen because we never count links to unallocated
+ nodes. */
+ errexit ("LINK RECORDED FOR UNALLOCATED NODE");
+ }
+ else if (!linkfound[number] && inodestate[number] != UNALLOC)
+ {
+ /* No links to allocated node. If the size is zero, then
+ we want to clear it; if the size is positive, then we
+ want to reattach in. */
+ struct dinode dino;
+
+ pinode (0, number, "UNREF");
+
+ getinode (number, &dino);
+ if (dino.di_size && !reconn_failed)
+ {
+ /* This can't happen for dirctories because pass 3 should
+ already have reset them up. */
+ if ((DI_MODE (&dino) & IFMT) == IFDIR)
+ errexit ("NO LINKS TO NONZERO DIRECTORY");
+
+ if (preen || reply ("RECONNECT"))
+ reconn_failed = !linkup (number, -1);
+ if (! reconn_failed)
+ pfix ("RECONNECTED");
+ if (preen && reconn_failed)
+ pfail ("RECONNECT FAILED");
+ }
+ if (dino.di_size == 0 || reconn_failed)
+ {
+ if (reconn_failed && !preen)
+ /* If preening, the previous call to problem is still active
+ (more likely the failure was too severe, and exited). */
+ problem (0, "RECONNECT FAILED");
+ if (preen || reply ("CLEAR"))
+ {
+ inodestate[number] = UNALLOC;
+ clear_inode (number, &dino);
+ pfix ("CLEARED");
+ }
+ }
+ }
+ }
+}
diff --git a/ufs-fsck/pass5.c b/ufs-fsck/pass5.c
new file mode 100644
index 00000000..cb426a7d
--- /dev/null
+++ b/ufs-fsck/pass5.c
@@ -0,0 +1,450 @@
+/* Pass 5 of GNU fsck -- check allocation maps and summaries
+ Copyright (C) 1994,96,2001 Free Software Foundation, Inc.
+ Written by Michael I. Bushnell.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#include "fsck.h"
+
+/* From ../ufs/subr.c: */
+
+/*
+ * Update the frsum fields to reflect addition or deletion
+ * of some frags.
+ */
+static void
+ffs_fragacct(fs, fragmap, fraglist, cnt)
+ struct fs *fs;
+ int fragmap;
+ long fraglist[];
+ int cnt;
+{
+ int inblk;
+ register int field, subfield;
+ register int siz, pos;
+
+ inblk = (int)(fragtbl[fs->fs_frag][fragmap]) << 1;
+ fragmap <<= 1;
+ for (siz = 1; siz < fs->fs_frag; siz++) {
+ if ((inblk & (1 << (siz + (fs->fs_frag % NBBY)))) == 0)
+ continue;
+ field = around[siz];
+ subfield = inside[siz];
+ for (pos = siz; pos <= fs->fs_frag; pos++) {
+ if ((fragmap & field) == subfield) {
+ fraglist[siz] += cnt;
+ pos += siz;
+ field <<= siz;
+ subfield <<= siz;
+ }
+ field <<= 1;
+ subfield <<= 1;
+ }
+ }
+}
+
+void
+pass5 ()
+{
+ struct cg *newcg, *cg;
+ struct ocg *newocg;
+ int savednrpos = 0;
+ struct csum cstotal;
+ int i, j;
+ int c;
+ daddr_t d;
+ struct csum *sbcsums;
+
+ int basesize; /* size of cg not counting flexibly sized */
+ int sumsize; /* size of block totals and pos tbl */
+ int mapsize; /* size of inode map + block map */
+
+ int writesb;
+ int writecg;
+ int writecsum;
+
+ writesb = 0;
+ writecsum = 0;
+
+ cg = alloca (sblock->fs_cgsize);
+
+ newcg = alloca (sblock->fs_cgsize);
+ newocg = (struct ocg *)newcg;
+
+ sbcsums = alloca (fragroundup (sblock, sblock->fs_cssize));
+
+ readblock (fsbtodb (sblock, sblock->fs_csaddr), sbcsums,
+ fragroundup (sblock, sblock->fs_cssize));
+
+ /* Construct a CG structure; initialize everything that's the same
+ in each cylinder group. */
+ bzero (newcg, sblock->fs_cgsize);
+ newcg->cg_niblk = sblock->fs_ipg;
+ switch (sblock->fs_postblformat)
+ {
+ case FS_42POSTBLFMT:
+ /* Initialize size information */
+ basesize = (char *)(&newocg->cg_btot[0]) - (char *)(&newocg->cg_link);
+ sumsize = &newocg->cg_iused[0] - (char *)(&newocg->cg_btot[0]);
+ mapsize = (&newocg->cg_free[howmany(sblock->fs_fpg, NBBY)]
+ - (u_char *)&newocg->cg_iused[0]);
+ savednrpos = sblock->fs_nrpos;
+ sblock->fs_nrpos = 8;
+ break;
+
+ case FS_DYNAMICPOSTBLFMT:
+ /* Set fields unique to new cg structure */
+ newcg->cg_btotoff = &newcg->cg_space[0] - (u_char *)(&newcg->cg_link);
+ newcg->cg_boff = newcg->cg_btotoff + sblock->fs_cpg * sizeof (long);
+ newcg->cg_iusedoff = newcg->cg_boff + (sblock->fs_cpg
+ * sblock->fs_nrpos
+ * sizeof (short));
+ newcg->cg_freeoff = newcg->cg_iusedoff + howmany (sblock->fs_ipg, NBBY);
+
+ if (sblock->fs_contigsumsize <= 0)
+ {
+ newcg->cg_nextfreeoff =
+ (newcg->cg_freeoff
+ + howmany (sblock->fs_cpg * sblock->fs_spc / NSPF (sblock),
+ NBBY));
+ }
+ else
+ {
+ newcg->cg_clustersumoff =
+ (newcg->cg_freeoff
+ + howmany (sblock->fs_cpg * sblock->fs_spc / NSPF (sblock), NBBY)
+ - sizeof (long));
+ newcg->cg_clustersumoff =
+ roundup (newcg->cg_clustersumoff, sizeof (long));
+ newcg->cg_clusteroff =
+ (newcg->cg_clustersumoff
+ + (sblock->fs_contigsumsize + 1) * sizeof (long));
+ newcg->cg_nextfreeoff =
+ (newcg->cg_clusteroff
+ + howmany (sblock->fs_cpg * sblock->fs_spc / NSPB (sblock),
+ NBBY));
+ }
+
+ newcg->cg_magic = CG_MAGIC;
+
+ /* Set map sizes */
+ basesize = &newcg->cg_space[0] - (u_char *)(&newcg->cg_link);
+ sumsize = newcg->cg_iusedoff - newcg->cg_btotoff;
+ mapsize = newcg->cg_nextfreeoff - newcg->cg_iusedoff;
+ break;
+
+ default:
+ errexit ("UNKNOWN POSTBL FORMAT");
+ }
+
+ bzero (&cstotal, sizeof (struct csum));
+
+ /* Mark fragments past the end of the filesystem as used. */
+ j = blknum (sblock, sblock->fs_size + sblock->fs_frag - 1);
+ for (i = sblock->fs_size; i < j; i++)
+ setbmap (i);
+
+ /* Now walk through the cylinder groups, checking each one. */
+ for (c = 0; c < sblock->fs_ncg; c++)
+ {
+ int dbase, dmax;
+
+ /* Read the cylinder group structure */
+ readblock (fsbtodb (sblock, cgtod (sblock, c)), cg, sblock->fs_cgsize);
+ writecg = 0;
+
+ if (!cg_chkmagic (cg))
+ warning (1, "CG %d: BAD MAGIC NUMBER", c);
+
+ /* Compute first and last data block addresses in this group */
+ dbase = cgbase (sblock, c);
+ dmax = dbase + sblock->fs_fpg;
+ if (dmax > sblock->fs_size)
+ dmax = sblock->fs_size;
+
+ /* Initialize newcg fully; values from cg for those
+ we can't check. */
+ newcg->cg_time = cg->cg_time;
+ newcg->cg_cgx = c;
+ if (c == sblock->fs_ncg - 1)
+ newcg->cg_ncyl = sblock->fs_ncyl % sblock->fs_cpg;
+ else
+ newcg->cg_ncyl = sblock->fs_cpg;
+ newcg->cg_ndblk = dmax - dbase;
+ if (sblock->fs_contigsumsize > 0)
+ newcg->cg_nclusterblks = newcg->cg_ndblk / sblock->fs_frag;
+ newcg->cg_cs.cs_ndir = 0;
+ newcg->cg_cs.cs_nffree = 0;
+ newcg->cg_cs.cs_nbfree = 0;
+ newcg->cg_cs.cs_nifree = sblock->fs_ipg;
+
+ /* Check these for basic viability; if they are wrong
+ then clear them. */
+ newcg->cg_rotor = cg->cg_rotor;
+ newcg->cg_frotor = cg->cg_frotor;
+ newcg->cg_irotor = cg->cg_irotor;
+ if (newcg->cg_rotor > newcg->cg_ndblk)
+ {
+ problem (0, "ILLEGAL ROTOR VALUE IN CG %d", c);
+ if (preen || reply ("FIX"))
+ {
+ newcg->cg_rotor = 0;
+ cg->cg_rotor = 0;
+ writecg = 1;
+ pfix ("FIXED");
+ }
+ }
+ if (newcg->cg_frotor > newcg->cg_ndblk)
+ {
+ problem (0, "ILLEGAL FROTOR VALUE IN CG %d", c);
+ if (preen || reply ("FIX"))
+ {
+ newcg->cg_frotor = 0;
+ cg->cg_frotor = 0;
+ writecg = 1;
+ pfix ("FIXED");
+ }
+ }
+ if (newcg->cg_irotor > newcg->cg_niblk)
+ {
+ problem (0, "ILLEGAL IROTOR VALUE IN CG %d", c);
+ if (preen || reply ("FIX"))
+ {
+ newcg->cg_irotor = 0;
+ cg->cg_irotor = 0;
+ writecg = 1;
+ pfix ("FIXED");
+ }
+ }
+
+ /* Zero the block maps and summary areas */
+ bzero (&newcg->cg_frsum[0], sizeof newcg->cg_frsum);
+ bzero (&cg_blktot (newcg)[0], sumsize + mapsize);
+ if (sblock->fs_postblformat == FS_42POSTBLFMT)
+ newocg->cg_magic = CG_MAGIC;
+
+ /* Walk through each inode, accounting for it in
+ the inode map and in newcg->cg_cs. */
+ /* In this loop, J is the inode number, and I is the
+ inode number relative to this CG. */
+ j = sblock->fs_ipg * c;
+ for (i = 0; i < sblock->fs_ipg; j++, i++)
+ switch (inodestate[j])
+ {
+ case DIRECTORY:
+ case DIRECTORY | DIR_REF:
+ case BADDIR:
+ newcg->cg_cs.cs_ndir++;
+ /* Fall through... */
+ case REG:
+ newcg->cg_cs.cs_nifree--;
+ setbit (cg_inosused (newcg), i);
+ /* Fall through... */
+ case UNALLOC:
+ break;
+
+ default:
+ errexit ("UNKNOWN STATE I=%d", j);
+ }
+ /* Account for inodes 0 and 1 */
+ if (c == 0)
+ for (i = 0; i < ROOTINO; i++)
+ {
+ setbit (cg_inosused (newcg), i);
+ newcg->cg_cs.cs_nifree--;
+ }
+
+ /* Walk through each data block, accounting for it in
+ the block map and in newcg->cg_cs. */
+ /* In this look, D is the block number and I is the
+ block number relative to this CG. */
+ for (i = 0, d = dbase;
+ d < dmax;
+ d += sblock->fs_frag, i += sblock->fs_frag)
+ {
+ int frags = 0;
+
+ /* Set each free frag of this block in the block map;
+ count how many frags were free. */
+ for (j = 0; j < sblock->fs_frag; j++)
+ {
+ if (testbmap (d + j))
+ continue;
+ setbit (cg_blksfree (newcg), i + j);
+ frags++;
+ }
+
+ /* If all the frags were free, then count this as
+ a free block too. */
+ if (frags == sblock->fs_frag)
+ {
+ newcg->cg_cs.cs_nbfree++;
+ j = cbtocylno (sblock, i);
+ cg_blktot(newcg)[j]++;
+ cg_blks(sblock, newcg, j)[cbtorpos(sblock, i)]++;
+ if (sblock->fs_contigsumsize > 0)
+ setbit (cg_clustersfree (newcg), i / sblock->fs_frag);
+ }
+ else if (frags)
+ {
+ /* Partial; account for the frags. */
+ int blk;
+ newcg->cg_cs.cs_nffree += frags;
+ blk = blkmap (sblock, cg_blksfree (newcg), i);
+ ffs_fragacct (sblock, blk, newcg->cg_frsum, 1);
+ }
+ }
+
+ if (sblock->fs_contigsumsize > 0)
+ {
+ long *sump = cg_clustersum (newcg);
+ u_char *mapp = cg_clustersfree (newcg);
+ int map = *mapp++;
+ int bit = 1;
+ int run = 0;
+
+ for (i = 0; i < newcg->cg_nclusterblks; i++)
+ {
+ if ((map & bit) != 0)
+ run++;
+ else if (run)
+ {
+ if (run > sblock->fs_contigsumsize)
+ run = sblock->fs_contigsumsize;
+ sump[run]++;
+ run = 0;
+ }
+
+ if ((i & (NBBY - 1)) != (NBBY - 1))
+ bit <<= 1;
+ else
+ {
+ map = *mapp++;
+ bit = 1;
+ }
+ }
+ if (run != 0)
+ {
+ if (run > sblock->fs_contigsumsize)
+ run = sblock->fs_contigsumsize;
+ sump[run]++;
+ }
+ }
+
+ /* Add this cylinder group's totals into the superblock's
+ totals. */
+ cstotal.cs_nffree += newcg->cg_cs.cs_nffree;
+ cstotal.cs_nbfree += newcg->cg_cs.cs_nbfree;
+ cstotal.cs_nifree += newcg->cg_cs.cs_nifree;
+ cstotal.cs_ndir += newcg->cg_cs.cs_ndir;
+
+ /* Check counts in superblock */
+ if (bcmp (&newcg->cg_cs, &sbcsums[c], sizeof (struct csum)))
+ {
+ problem (0, "FREE BLK COUNTS FOR CG %d WRONG IN SUPERBLOCK", c);
+ if (preen || reply ("FIX"))
+ {
+ bcopy (&newcg->cg_cs, &sbcsums[c], sizeof (struct csum));
+ writecsum = 1;
+ pfix ("FIXED");
+ }
+ }
+
+ /* Check inode and block maps */
+ if (bcmp (cg_inosused (newcg), cg_inosused (cg), mapsize))
+ {
+ problem (0, "BLKS OR INOS MISSING IN CG %d BIT MAPS", c);
+ if (preen || reply ("FIX"))
+ {
+ bcopy (cg_inosused (newcg), cg_inosused (cg), mapsize);
+ writecg = 1;
+ pfix ("FIXED");
+ }
+ }
+
+ if (bcmp (&cg_blktot(newcg)[0], &cg_blktot(cg)[0], sumsize))
+ {
+ problem (0, "SUMMARY INFORMATION FOR CG %d BAD", c);
+ if (preen || reply ("FIX"))
+ {
+ bcopy (&cg_blktot(newcg)[0], &cg_blktot(cg)[0], sumsize);
+ writecg = 1;
+ pfix ("FIXED");
+ }
+ }
+
+ if (bcmp (newcg, cg, basesize))
+ {
+ problem (0, "CYLINDER GROUP %d BAD", c);
+ if (preen || reply ("FIX"))
+ {
+ bcopy (newcg, cg, basesize);
+ writecg = 1;
+ pfix ("FIXED");
+ }
+ }
+
+ if (writecg)
+ writeblock (fsbtodb (sblock, cgtod (sblock, c)),
+ cg, sblock->fs_cgsize);
+ }
+
+ /* Restore nrpos */
+ if (sblock->fs_postblformat == FS_42POSTBLFMT)
+ sblock->fs_nrpos = savednrpos;
+
+ if (bcmp (&cstotal, &sblock->fs_cstotal, sizeof (struct csum)))
+ {
+ problem (0, "TOTAL FREE BLK COUNTS WRONG IN SUPERBLOCK");
+ if (preen || reply ("FIX"))
+ {
+ bcopy (&cstotal, &sblock->fs_cstotal, sizeof (struct csum));
+ sblock->fs_ronly = 0;
+ sblock->fs_fmod = 0;
+ writesb = 1;
+ pfix ("FIXED");
+ }
+ }
+
+ if (sblock->fs_clean == 0 && !fix_denied)
+ {
+ problem (0, fsmodified ? "FILESYSTEM MODIFIED" : "FILESYSTEM UNCLEAN");
+ if (preen || reply ("MARK CLEAN"))
+ {
+ sblock->fs_clean = 1;
+ writesb = 1;
+ pfix ("MARKED CLEAN");
+ }
+ }
+
+ if (writesb)
+ writeblock (SBLOCK, sblock, SBSIZE);
+
+ if (writecsum)
+ {
+ const int cssize = fragroundup (sblock, sblock->fs_cssize);
+ struct csum *test;
+
+ writeblock (fsbtodb (sblock, sblock->fs_csaddr), sbcsums,
+ fragroundup (sblock, sblock->fs_cssize));
+
+ test = alloca (cssize);
+ readblock (fsbtodb (sblock, sblock->fs_csaddr), test, cssize);
+ if (bcmp (test, sbcsums, cssize))
+ warning (0, "CSUM WRITE INCONSISTENT");
+ }
+}
diff --git a/ufs-fsck/setup.c b/ufs-fsck/setup.c
new file mode 100644
index 00000000..9433bd68
--- /dev/null
+++ b/ufs-fsck/setup.c
@@ -0,0 +1,191 @@
+/*
+ Copyright (C) 1994,96,99,2002 Free Software Foundation, Inc.
+ Written by Michael I. Bushnell.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#include "fsck.h"
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <error.h>
+
+static char sblockbuf[SBSIZE];
+struct fs *sblock = (struct fs *)sblockbuf;
+
+/* A string identifying what we're trying to check. */
+char *device_name = 0;
+
+daddr_t maxfsblock;
+int maxino;
+int direct_symlink_extension;
+
+int newinofmt;
+
+int readfd, writefd;
+
+int fix_denied = 0;
+
+int fsmodified = 0;
+
+ino_t lfdir;
+
+/* Get ready to run on device with pathname DEV. */
+int
+setup (char *dev)
+{
+ struct stat st;
+ int changedsb;
+ size_t bmapsize;
+
+ device_name = dev;
+
+ if (stat (dev, &st) == -1)
+ {
+ error (0, errno, "%s", dev);
+ return 0;
+ }
+ if (!S_ISCHR (st.st_mode) && !S_ISBLK (st.st_mode))
+ {
+ problem (1, "%s is not a character or block device", dev);
+ if (! reply ("CONTINUE"))
+ return 0;
+ }
+ if (preen == 0)
+ printf ("** %s", dev);
+ if (!nowrite)
+ readfd = open (dev, O_RDWR);
+ if (nowrite || readfd == -1)
+ {
+ readfd = open (dev, O_RDONLY);
+ if (readfd == -1)
+ {
+ error (0, errno, "%s", dev);
+ return 0;
+ }
+ writefd = -1;
+ nowrite = 1;
+ if (preen)
+ warning (1, "NO WRITE ACCESS");
+ printf (" (NO WRITE)");
+ }
+ else
+ writefd = readfd;
+
+ if (preen == 0)
+ printf ("\n");
+
+ lfdir = 0;
+
+ /* We don't do the alternate superblock stuff here (yet). */
+ readblock (SBLOCK, sblock, SBSIZE);
+ changedsb = 0;
+
+ if (sblock->fs_magic != FS_MAGIC)
+ {
+ warning (1, "BAD MAGIC NUMBER");
+ return 0;
+ }
+ if (sblock->fs_ncg < 1)
+ {
+ warning (1, "NCG OUT OF RANGE");
+ return 0;
+ }
+ if (sblock->fs_cpg < 1)
+ {
+ warning (1, "CPG OUT OF RANGE");
+ return 0;
+ }
+ if (sblock->fs_ncg * sblock->fs_cpg < sblock->fs_ncyl
+ || (sblock->fs_ncg - 1) * sblock->fs_cpg >= sblock->fs_ncyl)
+ {
+ warning (1, "NCYL INCONSISTENT WITH NCG AND CPG");
+ return 0;
+ }
+ if (sblock->fs_sbsize > SBSIZE)
+ {
+ warning (1, "SBLOCK SIZE PREPONTEROUSLY LARGE");
+ return 0;
+ }
+ if (sblock->fs_optim != FS_OPTTIME && sblock->fs_optim != FS_OPTSPACE)
+ {
+ problem (1, "UNDEFINED OPTIMIZATION IN SUPERBLOCK");
+ if (reply ("SET TO DEFAULT"))
+ {
+ sblock->fs_optim = FS_OPTTIME;
+ changedsb = 1;
+ }
+ }
+ if (sblock->fs_minfree < 0 || sblock->fs_minfree > 99)
+ {
+ problem (0, "IMPOSSIBLE MINFREE=%ld IN SUPERBLOCK", sblock->fs_minfree);
+ if (preen || reply ("SET TO DEFAULT"))
+ {
+ sblock->fs_minfree = 10;
+ changedsb = 1;
+ pfix ("SET TO DEFAULT");
+ }
+ }
+ if (sblock->fs_interleave < 1
+ || sblock->fs_interleave > sblock->fs_nsect)
+ {
+ problem (0, "IMPOSSIBLE INTERLEAVE=%ld IN SUPERBLOCK",
+ sblock->fs_interleave);
+ if (preen || reply ("SET TO DEFAULT"))
+ {
+ sblock->fs_interleave = 1;
+ changedsb = 1;
+ pfix ("SET TO DEFAULT");
+ }
+ }
+ if (sblock->fs_npsect < sblock->fs_nsect
+ || sblock->fs_npsect > sblock->fs_nsect * 2)
+ {
+ problem (0, "IMPOSSIBLE NPSECT=%ld IN SUPERBLOCK", sblock->fs_npsect);
+ if (preen || reply ("SET TO DEFAULT"))
+ {
+ sblock->fs_npsect = sblock->fs_nsect;
+ changedsb = 1;
+ pfix ("SET TO DEFAULT");
+ }
+ }
+ if (sblock->fs_inodefmt >= FS_44INODEFMT)
+ newinofmt = 1;
+ else
+ {
+ sblock->fs_qbmask = ~sblock->fs_bmask;
+ sblock->fs_qfmask = ~sblock->fs_fmask;
+ newinofmt = 0;
+ }
+
+ if (changedsb)
+ writeblock (SBLOCK, sblock, SBSIZE);
+
+ /* Constants */
+ maxfsblock = sblock->fs_size;
+ maxino = sblock->fs_ncg * sblock->fs_ipg;
+ direct_symlink_extension = sblock->fs_maxsymlinklen > 0;
+
+ /* Allocate and initialize maps */
+ bmapsize = roundup (howmany (maxfsblock, NBBY), sizeof (short));
+ blockmap = calloc (bmapsize, sizeof (char));
+ inodestate = calloc (maxino + 1, sizeof (char));
+ typemap = calloc (maxino + 1, sizeof (char));
+ linkcount = calloc (maxino + 1, sizeof (nlink_t));
+ linkfound = calloc (maxino + 1, sizeof (nlink_t));
+ return 1;
+}
diff --git a/ufs-fsck/utilities.c b/ufs-fsck/utilities.c
new file mode 100644
index 00000000..14705f84
--- /dev/null
+++ b/ufs-fsck/utilities.c
@@ -0,0 +1,455 @@
+/* Miscellaneous functions for fsck
+ Copyright (C) 1994,95,96,99,2001,02 Free Software Foundation, Inc.
+ Written by Michael I. Bushnell.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#include "fsck.h"
+#include <fcntl.h>
+#include <sys/file.h>
+#include <unistd.h>
+#include <stdarg.h>
+#include <pwd.h>
+#include <error.h>
+#include <time.h>
+
+static void retch (char *reason);
+
+/* Read disk block ADDR into BUF of SIZE bytes. */
+void
+readblock (daddr_t addr, void *buf, size_t size)
+{
+ if (lseek (readfd, addr * DEV_BSIZE, L_SET) == -1)
+ errexit ("CANNOT SEEK TO BLOCK %ld", addr);
+ if (read (readfd, buf, size) != size)
+ errexit ("CANNOT READ BLOCK %ld", addr);
+}
+
+/* Write disk block BLKNO from BUF of SIZE bytes. */
+void
+writeblock (daddr_t addr, void *buf, size_t size)
+{
+ if (lseek (writefd, addr * DEV_BSIZE, L_SET) == -1)
+ errexit ("CANNOT SEEK TO BLOCK %ld", addr);
+ if (write (writefd, buf, size) != size)
+ errexit ("CANNOT WRITE BLOCK %ld", addr);
+ fsmodified = 1;
+}
+
+/* Last filesystem fragment that we read an inode from */
+static char *lastifrag;
+static daddr_t lastifragaddr;
+
+/* Read inode number INO into DINODE. */
+void
+getinode (ino_t ino, struct dinode *di)
+{
+ daddr_t iblk;
+
+ if (!lastifrag)
+ lastifrag = malloc (sblock->fs_bsize);
+
+ iblk = ino_to_fsba (sblock, ino);
+ if (iblk != lastifragaddr)
+ readblock (fsbtodb (sblock, iblk), lastifrag, sblock->fs_bsize);
+ lastifragaddr = iblk;
+ bcopy (lastifrag + ino_to_fsbo (sblock, ino) * sizeof (struct dinode),
+ di, sizeof (struct dinode));
+}
+
+/* Write inode number INO from DINODE. */
+void
+write_inode (ino_t ino, struct dinode *di)
+{
+ daddr_t iblk;
+
+ iblk = ino_to_fsba (sblock, ino);
+ if (iblk != lastifragaddr)
+ readblock (fsbtodb (sblock, iblk), lastifrag, sblock->fs_bsize);
+ lastifragaddr = iblk;
+ bcopy (di, lastifrag + ino_to_fsbo (sblock, ino) * sizeof (struct dinode),
+ sizeof (struct dinode));
+ writeblock (fsbtodb (sblock, iblk), lastifrag, sblock->fs_bsize);
+}
+
+/* Clear inode number INO and zero DI. */
+void
+clear_inode (ino_t ino, struct dinode *di)
+{
+ bzero (di, sizeof (struct dinode));
+ write_inode (ino, di);
+}
+
+/* Allocate and return a block and account for it in all the block
+ maps locally. Don't trust or change the disk block maps.
+ The block should be NFRAGS fragments long. */
+daddr_t
+allocblk (int nfrags)
+{
+ daddr_t i;
+ int j, k;
+
+ if (nfrags <= 0 || nfrags > sblock->fs_frag)
+ return 0;
+
+ /* Examine each block of the filesystem. */
+ for (i = 0; i < maxfsblock - sblock->fs_frag; i += sblock->fs_frag)
+ {
+ /* For each piece of the block big enough to hold this frag... */
+ for (j = 0; j <= sblock->fs_frag - nfrags; j++)
+ {
+ /* For each frag of this piece... */
+ for (k = 0; k < nfrags; k++)
+ if (testbmap (i + j + k))
+ break;
+
+ /* If one of the frags was allocated... */
+ if (k < nfrags)
+ {
+ /* Skip at least that far (short cut) */
+ j += k;
+ continue;
+ }
+
+ /* It's free (at address i + j) */
+
+ /* Mark the frags allocated in our map */
+ for (k = 0; k < nfrags; k++)
+ setbmap (i + j + k);
+
+ return (i + j);
+ }
+ }
+ return 0;
+}
+
+/* Check if a block starting at BLK and extending for CNT
+ fragments is out of range; if it is, then return 1; otherwise return 0. */
+int
+check_range (daddr_t blk, int cnt)
+{
+ int c;
+
+ if ((unsigned)(blk + cnt) > maxfsblock)
+ return 1;
+
+ c = dtog (sblock, blk);
+ if (blk < cgdmin (sblock, c))
+ {
+ if (blk + cnt > cgsblock (sblock, c))
+ return 1;
+ }
+ else
+ {
+ if (blk + cnt > cgbase (sblock, c + 1))
+ return 1;
+ }
+
+ return 0;
+}
+
+struct problem {
+ char *desc;
+ struct problem *prev;
+};
+
+/* A queue of problems found by fsck that are waiting resolution. The front
+ of the list is the most recent problem found (and presumably since
+ previous problems haven't been resolved yet, they depend on this one being
+ solved for their resolution). */
+static struct problem *problems = 0;
+
+static struct problem *free_problems = 0;
+
+static void
+push_problem (char *fmt, va_list args)
+{
+ struct problem *prob = free_problems;
+
+ if (! prob)
+ prob = malloc (sizeof (struct problem));
+ else
+ problems = prob->prev;
+ if (! prob)
+ retch ("malloc failed");
+
+ if (vasprintf (&prob->desc, fmt, args) < 0)
+ retch ("vasprintf failed");
+
+ prob->prev = problems;
+ problems = prob;
+}
+
+/* Print the most recent problem, and perhaps how it was resolved. */
+static void
+resolve_problem (char *fix)
+{
+ struct problem *prob = problems;
+
+ if (! prob)
+ retch ("no more problems");
+
+ problems = prob->prev;
+ prob->prev = free_problems;
+
+ if (preen && device_name)
+ printf ("%s: %s", device_name, prob->desc);
+ else
+ printf ("%s", prob->desc);
+ if (fix)
+ printf (" (%s)\n", fix);
+ else
+ putchar ('\n');
+ free (prob->desc);
+}
+
+/* Retire all problems as if they failed. We print them in chronological
+ order rather than lifo order, as this is a bit clearer, and we can do it
+ when we know they're all going to fail. */
+static void
+flush_problems ()
+{
+ struct problem *fail (struct problem *prob)
+ {
+ struct problem *last = prob->prev ? fail (prob->prev) : prob;
+ if (preen && device_name)
+ printf ("%s: %s\n", device_name, prob->desc);
+ else
+ puts (prob->desc);
+ free (prob->desc);
+ return last;
+ }
+ if (problems)
+ {
+ fail (problems)->prev = free_problems;
+ free_problems = problems;
+ }
+}
+
+/* Like printf, but exit after printing. */
+void
+errexit (char *fmt, ...)
+{
+ va_list args;
+
+ flush_problems ();
+
+ if (preen && device_name)
+ printf ("%s: ", device_name);
+
+ va_start (args, fmt);
+ vprintf (fmt, args);
+ va_end (args);
+ putchar ('\n');
+
+ exit (8);
+}
+
+static void
+retch (char *reason)
+{
+ flush_problems ();
+ error (99, 0, "(internal error) %s!", reason);
+}
+
+/* Prints all unresolved problems and exits, printing MSG as well. */
+static void
+punt (char *msg)
+{
+ problem (0, "%s", msg);
+ flush_problems ();
+ exit (8);
+}
+
+/* If SEVERE is true, and we're in preen mode, then things are too hair to
+ fix automatically, so tell the user to do it himself and punt. */
+static void
+no_preen (int severe)
+{
+ if (severe && preen)
+ punt ("PLEASE RUN fsck MANUALLY");
+}
+
+/* Store away the given message about a problem found. A call to problem must
+ be matched later with a call to pfix, pfail, or reply; to print more
+ in the same message, intervening calls to pextend can be used. If SEVERE is
+ true, and we're in preen mode, then the program is terminated. */
+void
+problem (int severe, char *fmt, ...)
+{
+ va_list args;
+
+ va_start (args, fmt);
+ push_problem (fmt, args);
+ va_end (args);
+
+ no_preen (severe);
+}
+
+/* Following a call to problem (with perhaps intervening calls to
+ pmore), appends the given message to that message. */
+void
+pextend (char *fmt, ...)
+{
+ va_list args;
+ char *more, *concat;
+ struct problem *prob = problems;
+
+ if (! prob)
+ retch ("No pending problem to add to");
+
+ va_start (args, fmt);
+ if (vasprintf (&more, fmt, args) < 0)
+ retch ("vasprintf failed");
+ va_end (args);
+
+ concat = realloc (prob->desc, strlen (prob->desc) + 1 + strlen (more) + 1);
+ if (! concat)
+ retch ("realloc failed");
+
+ strcpy (concat + strlen (concat), more);
+ prob->desc = concat;
+ free (more);
+}
+
+/* Like problem, but as if immediately followed by pfail. */
+void
+warning (int severe, char *fmt, ...)
+{
+ va_list args;
+
+ va_start (args, fmt);
+ push_problem (fmt, args);
+ va_end (args);
+
+ no_preen (severe);
+
+ resolve_problem (0);
+}
+
+/* Like problem, but appends a helpful description of the given inode number to
+ the message. */
+void
+pinode (int severe, ino_t ino, char *fmt, ...)
+{
+ if (fmt)
+ {
+ va_list args;
+ va_start (args, fmt);
+ push_problem (fmt, args);
+ va_end (args);
+ }
+
+ if (ino < ROOTINO || ino > maxino)
+ pextend (" (BOGUS INODE) I=%Ld", ino);
+ else
+ {
+ char *p;
+ struct dinode dino;
+ struct passwd *pw;
+
+ getinode (ino, &dino);
+
+ pextend (" %s I=%Ld", (DI_MODE (&dino) & IFMT) == IFDIR ? "DIR" : "FILE",
+ ino);
+
+ pw = getpwuid (dino.di_uid);
+ if (pw)
+ pextend (" O=%s", pw->pw_name);
+ else
+ pextend (" O=%lu", dino.di_uid);
+
+ pextend (" M=0%o", DI_MODE (&dino));
+ pextend (" SZ=%llu", dino.di_size);
+ p = ctime (&dino.di_mtime.tv_sec);
+ pextend (" MT=%12.12s %4.4s", &p[4], &p[20]);
+ }
+
+ no_preen (severe);
+}
+
+/* Print a successful resolution to a pending problem. Must follow a call to
+ problem or pextend. */
+void
+pfix (char *fix)
+{
+ if (preen)
+ resolve_problem (fix ?: "FIXED");
+}
+
+/* Print an unsuccessful resolution to a pending problem. Must follow a call
+ to problem or pextend. */
+void
+pfail (char *failure)
+{
+ if (preen)
+ resolve_problem (failure);
+}
+
+/* Ask the user a question; return 1 if the user says yes, and 0
+ if the user says no. This call must follow a call to problem or pextend,
+ which it completes. */
+int
+reply (char *question)
+{
+ int persevere;
+ char c;
+
+ if (preen)
+ retch ("Got to reply() in preen mode");
+
+ /* Emit the problem to which the question pertains. */
+ resolve_problem (0);
+
+ persevere = !strcmp (question, "CONTINUE");
+
+ if (!persevere && (nowrite || writefd < 0))
+ {
+ fix_denied = 1;
+ printf ("%s? no\n\n", question);
+ return 0;
+ }
+ else if (noquery || (persevere && nowrite))
+ {
+ printf ("%s? yes\n\n", question);
+ return 1;
+ }
+ else
+ {
+ do
+ {
+ printf ("%s? [yn] ", question);
+ fflush (stdout);
+ c = getchar ();
+ while (c != '\n' && getchar () != '\n')
+ if (feof (stdin))
+ {
+ fix_denied = 1;
+ return 0;
+ }
+ }
+ while (c != 'y' && c != 'Y' && c != 'n' && c != 'N');
+ putchar ('\n');
+ if (c == 'y' || c == 'Y')
+ return 1;
+ else
+ {
+ fix_denied = 1;
+ return 0;
+ }
+ }
+}
diff --git a/ufs-utils/Makefile b/ufs-utils/Makefile
new file mode 100644
index 00000000..df22440e
--- /dev/null
+++ b/ufs-utils/Makefile
@@ -0,0 +1,38 @@
+#
+# Copyright (C) 1994, 1996, 2008 Free Software Foundation
+# Written by Michael I. Bushnell.
+#
+# This file is part of the GNU Hurd.
+#
+# The GNU Hurd is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2, or (at
+# your option) any later version.
+#
+# The GNU Hurd is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+dir := ufs-utils
+makemode := utilities
+
+targets = mkfs.ufs clri.ufs stati.ufs
+target-suffix = .ufs
+SRCS = mkfs.c clri.c stati.c dlabel.c
+installationdir = $(sbindir)
+
+OBJS = $(SRCS:.c=.o)
+HURDLIBS = store shouldbeinlibc
+
+include ../Makeconf
+
+mkfs.ufs: mkfs.o dlabel.o ../libstore/libstore.a ../libshouldbeinlibc/libshouldbeinlibc.a
+
+$(targets): %.ufs: %.o
+
+
diff --git a/ufs-utils/clri.c b/ufs-utils/clri.c
new file mode 100644
index 00000000..1ad348a1
--- /dev/null
+++ b/ufs-utils/clri.c
@@ -0,0 +1,168 @@
+/*
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Rich $alz of BBN Inc.
+ *
+ * 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.
+ */
+
+#ifndef lint
+static char copyright[] =
+"@(#) Copyright (c) 1990, 1993\n\
+ The Regents of the University of California. All rights reserved.\n";
+
+static char copyright[] __attribute__ ((unused));
+#endif /* not lint */
+
+#ifndef lint
+static char sccsid[] = "@(#)clri.c 8.2 (Berkeley) 9/23/93";
+static char sccsid[] __attribute__ ((unused));
+#endif /* not lint */
+
+/* Modified by Michael I. Bushnell for GNU Hurd. */
+
+#include <sys/param.h>
+#include <sys/time.h>
+
+#include "../ufs/dinode.h"
+#include "../ufs/fs.h"
+
+
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#define MAXPHYS (64 * 1024)
+#define DEV_BSIZE 512
+
+
+int
+main(argc, argv)
+ int argc;
+ char *argv[];
+{
+ register struct fs *sbp;
+ register struct dinode *ip;
+ register int fd;
+ struct dinode ibuf[MAXBSIZE / sizeof (struct dinode)];
+ long generation, bsize;
+ off_t offset;
+ int inonum;
+ char *fs, sblock[SBSIZE];
+
+ if (argc < 3) {
+ (void)fprintf(stderr, "usage: clri filesystem inode ...\n");
+ exit(1);
+ }
+
+ fs = *++argv;
+
+ /* get the superblock. */
+ if ((fd = open(fs, O_RDWR, 0)) < 0)
+ {
+ perror (fs);
+ exit (1);
+ }
+ if (lseek(fd, (off_t)(SBLOCK * DEV_BSIZE), SEEK_SET) < 0)
+ {
+ perror (fs);
+ exit (1);
+ }
+ if (read(fd, sblock, sizeof(sblock)) != sizeof(sblock)) {
+ (void)fprintf(stderr,
+ "clri: %s: can't read the superblock.\n", fs);
+ exit(1);
+ }
+
+ sbp = (struct fs *)sblock;
+ if (sbp->fs_magic != FS_MAGIC) {
+ (void)fprintf(stderr,
+ "clri: %s: superblock magic number 0x%lux, not 0x%x.\n",
+ fs, sbp->fs_magic, FS_MAGIC);
+ exit(1);
+ }
+ bsize = sbp->fs_bsize;
+
+ /* remaining arguments are inode numbers. */
+ while (*++argv) {
+ /* get the inode number. */
+ if ((inonum = atoi(*argv)) <= 0) {
+ (void)fprintf(stderr,
+ "clri: %s is not a valid inode number.\n", *argv);
+ exit(1);
+ }
+ (void)printf("clearing %d\n", inonum);
+
+ /* read in the appropriate block. */
+ offset = ino_to_fsba(sbp, inonum); /* inode to fs blk */
+ offset = fsbtodb(sbp, offset); /* fs blk disk blk */
+ offset *= DEV_BSIZE; /* disk blk to bytes */
+
+ /* seek and read the block */
+ if (lseek(fd, offset, SEEK_SET) < 0)
+ {
+ perror (fs);
+ exit (1);
+ }
+ if (read(fd, ibuf, bsize) != bsize)
+ {
+ perror (fs);
+ exit (1);
+ }
+
+ /* get the inode within the block. */
+ ip = &ibuf[ino_to_fsbo(sbp, inonum)];
+
+ /* clear the inode, and bump the generation count. */
+ generation = ip->di_gen + 1;
+ memset(ip, 0, sizeof(*ip));
+ ip->di_gen = generation;
+
+ /* backup and write the block */
+ if (lseek(fd, (off_t)-bsize, SEEK_CUR) < 0)
+ {
+ perror (fs);
+ exit (1);
+ }
+ if (write(fd, ibuf, bsize) != bsize)
+ {
+ perror (fs);
+ exit (1);
+ }
+ (void)fsync(fd);
+ }
+ (void)close(fd);
+ exit(0);
+}
diff --git a/ufs-utils/dlabel.c b/ufs-utils/dlabel.c
new file mode 100644
index 00000000..355cb3f6
--- /dev/null
+++ b/ufs-utils/dlabel.c
@@ -0,0 +1,91 @@
+/* Get the disklabel from a device node
+
+ Copyright (C) 1996,99,2001 Free Software Foundation, Inc.
+
+ Written by Miles Bader <miles@gnu.org>
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#include <errno.h>
+#include <hurd.h>
+#include <mach.h>
+#include <string.h>
+#include <device/device.h>
+#include <device/disk_status.h>
+#include <hurd/store.h>
+
+/* XXX Ick. */
+#define IOCPARM_MASK 0x1fff/* parameter length, at most 13 bits */
+#define IOC_OUT 0x40000000/* copy out parameters */
+#define _IOC(inout,group,num,len) \
+ (inout | ((len & IOCPARM_MASK) << 16) | ((group) << 8) | (num))
+#define _IOR(g,n,t) _IOC(IOC_OUT,(g), (n), sizeof(t))
+
+static error_t
+fd_get_device (int fd, device_t *device)
+{
+ error_t err;
+ struct store *store;
+ file_t node = getdport (fd);
+
+ if (node == MACH_PORT_NULL)
+ return errno;
+
+ err = store_create (node, 0, 0, &store); /* consumes NODE on success */
+ if (! err)
+ {
+ if (store->class->id != STORAGE_DEVICE
+ /* In addition to requiring a device, we also want the *whole*
+ device -- one contiguous run starting at 0. */
+ || store->num_runs != 1
+ || store->runs[0].start != 0)
+ err = ENODEV;
+ else if (store->port == MACH_PORT_NULL)
+ /* Usually getting a null port back means we didn't have sufficient
+ privileges. */
+ err = EPERM;
+ else
+ {
+ *device = store->port;
+ store->port = MACH_PORT_NULL; /* Steal the port from STORE! */
+ }
+ store_free (store);
+ }
+ else
+ mach_port_deallocate (mach_task_self (), node);
+
+ return err;
+}
+
+error_t
+fd_get_disklabel (int fd, struct disklabel *label)
+{
+ device_t device;
+ error_t err = fd_get_device (fd, &device);
+
+ if (! err)
+ {
+ mach_msg_type_number_t label_len = sizeof *label / sizeof (integer_t);
+
+ err = device_get_status (device, DIOCGDINFO,
+ (dev_status_t)label, &label_len);
+ if (!err && label_len != sizeof *label / sizeof (integer_t))
+ err = ERANGE;
+
+ mach_port_deallocate (mach_task_self (), device);
+ }
+
+ return err;
+}
diff --git a/ufs-utils/mkfs.c b/ufs-utils/mkfs.c
new file mode 100644
index 00000000..aef3ea92
--- /dev/null
+++ b/ufs-utils/mkfs.c
@@ -0,0 +1,1406 @@
+/*
+ * Copyright (c) 1980, 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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.
+ */
+
+#ifndef lint
+/*static char sccsid[] = "from: @(#)mkfs.c 8.3 (Berkeley) 2/3/94";*/
+static char *rcsid = "$Id: mkfs.c,v 1.22 2006/03/14 23:27:50 tschwinge Exp $";
+#endif /* not lint */
+
+#include <unistd.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <argp.h>
+#include <assert.h>
+#include <error.h>
+#include <string.h>
+#include <sys/param.h>
+#include <sys/time.h>
+#include <sys/wait.h>
+#include <sys/resource.h>
+#include "../ufs/dinode.h"
+#include "../ufs/dir.h"
+#include "../ufs/fs.h"
+/* #include <sys/disklabel.h> */
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <dirent.h>
+#include <version.h>
+
+#include <device/device_types.h>
+#include <device/disk_status.h>
+
+#include <hurd.h>
+
+/* Begin misc additions for GNU Hurd */
+
+/* For GNU Hurd: the ufs DIRSIZ macro is different than the BSD
+ 4.4 version that mkfs expects. So we provide here the BSD version. */
+#undef DIRSIZ
+#if (BYTE_ORDER == LITTLE_ENDIAN)
+#define DIRSIZ(oldfmt, dp) \
+ ((oldfmt) ? \
+ ((sizeof (struct directory_entry) - (MAXNAMLEN+1)) + (((dp)->d_type+1 + 3) &~ 3)) : \
+ ((sizeof (struct directory_entry) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3)))
+#else
+#define DIRSIZ(oldfmt, dp) \
+ ((sizeof (struct directory_entry) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3))
+#endif
+
+#define MAXPHYS (64 * 1024)
+
+/* Provide mode from struct dinode * */
+#define DI_MODE(dp) (((dp)->di_modeh << 16) | (dp)->di_model)
+
+#define DEV_BSIZE 512
+
+#define btodb(bytes) ((bytes) / DEV_BSIZE)
+
+/* End additions for GNU Hurd */
+
+#ifndef STANDALONE
+#include <a.out.h>
+#include <stdio.h>
+#include <time.h>
+#endif
+
+/*
+ * make file system for cylinder-group style file systems
+ */
+
+extern error_t fd_get_disklabel (int fd, struct disklabel *lab);
+static void mkfs (), initcg (), fsinit (), setblock ();
+static void iput (), rdfs (), clrblock (), wtfs ();
+static int makedir (), isblock ();
+
+/*
+ * We limit the size of the inode map to be no more than a
+ * third of the cylinder group space, since we must leave at
+ * least an equal amount of space for the block map.
+ *
+ * N.B.: MAXIPG must be a multiple of INOPB(fs).
+ */
+#define MAXIPG(fs) roundup((fs)->fs_bsize * NBBY / 3, INOPB(fs))
+
+#define UMASK 0755
+#define MAXINOPB (MAXBSIZE / sizeof(struct dinode))
+#define POWEROF2(num) (((num) & ((num) - 1)) == 0)
+
+/*
+ * variables set up by front end.
+ */
+#define extern
+extern int Nflag; /* run mkfs without writing file system */
+extern int Oflag; /* format as an 4.3BSD file system */
+extern int fssize; /* file system size */
+extern int ntracks; /* # tracks/cylinder */
+extern int nsectors; /* # sectors/track */
+extern int nphyssectors; /* # sectors/track including spares */
+extern int secpercyl; /* sectors per cylinder */
+extern int sectorsize; /* bytes/sector */
+extern int rpm; /* revolutions/minute of drive */
+extern int interleave; /* hardware sector interleave */
+extern int trackskew; /* sector 0 skew, per track */
+extern int headswitch; /* head switch time, usec */
+extern int trackseek; /* track-to-track seek, usec */
+extern int fsize; /* fragment size */
+extern int bsize; /* block size */
+extern int cpg; /* cylinders/cylinder group */
+extern int cpgflg; /* cylinders/cylinder group flag was given */
+extern int minfree; /* free space threshold */
+extern int opt; /* optimization preference (space or time) */
+extern int density; /* number of bytes per inode */
+extern int maxcontig; /* max contiguous blocks to allocate */
+extern int rotdelay; /* rotational delay between blocks */
+extern int maxbpg; /* maximum blocks per file in a cyl group */
+extern int nrpos; /* # of distinguished rotational positions */
+extern int bbsize; /* boot block size */
+extern int sbsize; /* superblock size */
+#undef extern
+
+union {
+ struct fs fs;
+ char pad[SBSIZE];
+} fsun;
+#define sblock fsun.fs
+struct csum *fscs;
+
+union {
+ struct cg cg;
+ char pad[MAXBSIZE];
+} cgun;
+#define acg cgun.cg
+
+struct dinode zino[MAXBSIZE / sizeof(struct dinode)];
+
+int fsi, fso;
+daddr_t alloc();
+
+const char *argp_program_version = STANDARD_HURD_VERSION (mkfs.ufs);
+
+#define _STRINGIFY(arg) #arg
+#define STRINGIFY(arg) _STRINGIFY (arg)
+
+static const struct argp_option options[] = {
+ {0,0,0,0,0, 1},
+ {"just-print", 'N', 0, 0,
+ "Just print the file system parameters that would be used"},
+ {"old-format", 'O', 0, 0, "Create a 4.3BSD format filesystem"},
+ {"max-contig", 'a', "BLOCKS", 0,
+ "The maximum number of contiguous blocks that will be laid out before"
+ " forcing a rotational delay; the default is no limit"},
+ {"block-size", 'b', "BYTES", 0, "The block size of the file system"},
+ {"group-cylinders", 'c', "N", 0,
+ "The number of cylinders per cylinder group; the default 16"},
+ {"rot-delay", 'd', "MSEC", 0,
+ "The expected time to service a transfer completion interrupt and"
+ " initiate a new transfer on the same disk; the default is 0"},
+ {"max-bpg", 'e', "BLOCKS", 0,
+ "Maximum number of blocks any single file can allocate out of a cylinder"
+ " group before it is forced to begin allocating blocks from another"
+ " cylinder group; the default is about one quarter of the total blocks"
+ " in a cylinder group"},
+ {"frag-size", 'f', "BYTES", 0, "The fragment size"},
+ {"inode-density", 'i', "BYTES", 0,
+ "The density of inodes in the file system, in bytes of data space per"
+ " inode; the default is one inode per 4 filesystem frags"},
+ {"minfree", 'm', "PERCENT", 0,
+ "The percentage of space reserved from normal users; the default is "
+ STRINGIFY (MINFREE) "%"},
+ {"rot-positions", 'n', "N", 0,
+ "The number of distinct rotational positions; the default is 8"},
+ {"optimization", 'o', "METH", 0, "``space'' or ``time''"},
+ {"size", 's', "SECTORS", 0, "The size of the file system"},
+
+ {0,0,0,0,
+ "The following options override the standard sizes for the disk"
+ " geometry; their default values are taken from the disk label:", 2},
+
+ {"sector-size", 'S', "BYTES", 0, "The size of a sector (usually 512)"},
+ {"skew", 'k', "SECTORS", 0, "Sector 0 skew, per track"},
+ {"interleave", 'l', "LOG-PHYS-RATIO", 0, "Hardware sector interleave"},
+ {"rpm", 'r', "RPM", 0, "The speed of the disk in revolutions per minute"},
+ {"tracks", 't', "N", 0, "The number of tracks/cylinder"},
+ {"sectors", 'u', "N", 0,
+ "The number of sectors per track (does not include sectors reserved for"
+ " bad block replacement"},
+ {"spare-sectors", 'p', "N", 0,
+ "Spare sectors (for bad sector replacement) at the end of each track"},
+ {"cyl-spare-sectors", 'x', "N", 0,
+ "Spare sectors (for bad sector replacement) at the end of the last track"
+ " in each cylinder"},
+ {0, 0}
+};
+static char *args_doc = "DEVICE";
+static char *doc = "Write a ufs filesystem image onto DEVICE.";
+
+struct amark { void *addr; struct amark *next; };
+
+static void
+amarks_add (struct amark **amarks, void *addr)
+ {
+ struct amark *up = malloc (sizeof (struct amark));
+ assert (up != 0);
+ up->addr = addr;
+ up->next = *amarks;
+ *amarks = up;
+ }
+static int
+amarks_contains (struct amark *amarks, void *addr)
+ {
+ while (amarks)
+ if (amarks->addr == addr)
+ return 1;
+ else
+ amarks = amarks->next;
+ return 0;
+ }
+
+static const struct disklabel default_disklabel = {
+ d_rpm: 3600,
+ d_interleave: 1,
+ d_secsize: DEV_BSIZE,
+ d_sparespertrack: 0,
+ d_sparespercyl: 0,
+ d_trackskew: 0,
+ d_cylskew: 0,
+ d_headswitch: 0,
+ d_trkseek: 0,
+};
+
+char *device = 0;
+
+#define deverr(code, err, fmt, args...) \
+ error (code, err, "%s: " fmt, device , ##args)
+
+int
+main (int argc, char **argv)
+{
+ int fdo, fdi;
+ struct amark *uparams = 0;
+ error_t label_err = 0;
+ struct disklabel label_buf, *label = 0;
+ int nspares = 0, ncspares = 0;
+
+ /* Parse our options... */
+ error_t parse_opt (int key, char *arg, struct argp_state *state)
+ {
+ switch (key)
+ {
+ case 'N': Nflag = 1; break;
+ case 'O': Oflag = 1; break;
+
+/* Mark &VAR as being a uparam, and set VAR. */
+#define UP_INT(var) { amarks_add (&uparams, &var); var = atoi (arg); }
+
+ case 'a': UP_INT (maxcontig); break;
+ case 'b': UP_INT (bsize); break;
+ case 'c': UP_INT (cpg); cpgflg = 1; break;
+ case 'd': UP_INT (rotdelay); break;
+ case 'e': UP_INT (maxbpg); break;
+ case 'f': UP_INT (fsize); break;
+ case 'i': UP_INT (density); break;
+ case 'm': UP_INT (minfree); break;
+ case 'n': UP_INT (nrpos); break;
+ case 's': UP_INT (fssize); break;
+ case 'S': UP_INT (sectorsize); break;
+ case 'k': UP_INT (trackskew); break;
+ case 'l': UP_INT (interleave); break;
+ case 'r': UP_INT (rpm); break;
+ case 't': UP_INT (ntracks); break;
+ case 'u': UP_INT (nsectors); break;
+ case 'p': UP_INT (nspares); break;
+ case 'x': UP_INT (ncspares); break;
+
+ case 'o':
+ amarks_add (&uparams, &opt);
+ if (strcmp (arg, "time") == 0)
+ opt = FS_OPTTIME;
+ else if (strcmp (arg, "space") == 0)
+ opt = FS_OPTSPACE;
+ else
+ argp_error (state, "%s: Invalid value for --optimization", arg);
+ break;
+
+ case ARGP_KEY_ARG:
+ if (state->arg_num > 0)
+ return ARGP_ERR_UNKNOWN;
+ device = arg;
+ break;
+
+ default:
+ return ARGP_ERR_UNKNOWN;
+ }
+ return 0;
+ }
+ const struct argp argp = { options, parse_opt, args_doc, doc };
+
+ /* Tries to get the disklabel for DEVICE; if it can't, then if PARAM_NAME
+ is 0, returns 0, otherwise an error is printed (using PARAM_NAME) and
+ the program exits. */
+ struct disklabel *dl (char *param_name)
+ {
+ if (! label)
+ {
+ if (! label_err)
+ {
+ label_err = fd_get_disklabel (fdi, &label_buf);
+ if (! label_err)
+ label = &label_buf;
+ }
+ if (label_err && param_name)
+ error (9, label_err,
+ "%s: Can't get disklabel; please specify --%s",
+ device, param_name);
+ }
+ return label;
+ }
+ /* Tries to get the integer field at offset OFFS from the disklabel for
+ DEVICE; if it can't, then if PARAM_NAME is 0, returns the corresponding
+ value from DEFAULT_DISKLABEL, otherwise an error is printed and the
+ program exits. */
+ int dl_int (char *param_name, size_t offs)
+ {
+ struct disklabel *l = dl (param_name);
+ return *(int *)((char *)(l ?: &default_disklabel) + offs);
+ }
+ /* A version of dl_int that takes the field name instead of an offset. */
+#define DL_INT(param_name, field) \
+ dl_int (param_name, offsetof (struct disklabel, field))
+
+ /* Like dl_int, but adjust for any difference in sector size between the
+ disklabel and SECTORSIZE. */
+ int dl_secs (char *param_name, size_t offs)
+ {
+ int val = dl_int (param_name, offs);
+ int dl_ss = DL_INT (0, d_secsize);
+ if (sectorsize < dl_ss)
+ deverr (10, 0,
+ "%d: Sector size is less than device sector size (%d)",
+ sectorsize, dl_ss);
+ else if (sectorsize > dl_ss)
+ if (sectorsize % dl_ss != 0)
+ deverr (11, 0,
+ "%d: Sector size not a multiple of device sector size (%d)",
+ sectorsize, dl_ss);
+ else
+ val /= sectorsize / dl_ss;
+ return val;
+ }
+ /* A version of dl_secs that takes the field name instead of an offset. */
+#define DL_SECS(param_name, field) \
+ dl_secs (param_name, offsetof (struct disklabel, field))
+
+ /* Parse our arguments. */
+ argp_parse (&argp, argc, argv, 0, 0, 0);
+
+ fdi = open (device, O_RDONLY);
+ if (fdi == -1)
+ error (2, errno, "%s", device);
+ fdo = open (device, O_WRONLY);
+ if (fdo == -1)
+ error (3, errno, "%s", device);
+
+ /* If VAR hasn't been set by the user, set it to DEF_VAL. */
+#define DEFAULT(var, def_val) \
+ (amarks_contains (uparams, &var) ? 0 : (((var) = (def_val)), 0))
+
+ DEFAULT (sectorsize, DEV_BSIZE);
+ DEFAULT (fssize,
+ ({ struct stat st;
+ if (fstat (fdi, &st) == -1)
+ deverr (4, errno, "Cannot get size");
+ st.st_size / sectorsize; }));
+ DEFAULT (ntracks, DL_INT ("tracks", d_ntracks));
+ DEFAULT (nsectors, DL_SECS ("sectors", d_nsectors));
+ DEFAULT (nspares, DL_SECS (0, d_sparespertrack));
+ DEFAULT (ncspares, DL_SECS (0, d_sparespercyl));
+
+ if (nspares >= nsectors)
+ deverr (5, 0, "%d: Too many spare sectors per track", nspares);
+ if (ncspares >= nsectors)
+ deverr (5, 0, "%d: Too many spare sectors per cylinder", ncspares);
+ nphyssectors = nsectors + nspares;
+
+ secpercyl = nsectors * ntracks;
+
+ DEFAULT (rpm, DL_INT (0, d_rpm));
+ DEFAULT (interleave, DL_INT (0, d_interleave));
+ DEFAULT (trackskew, DL_SECS (0, d_trackskew));
+ DEFAULT (headswitch, DL_INT (0, d_headswitch));
+ DEFAULT (trackseek, DL_INT (0, d_trkseek));
+
+ DEFAULT (fsize, 1024);
+ DEFAULT (bsize, 8192);
+
+ DEFAULT (cpg, 16);
+ DEFAULT (minfree, MINFREE);
+ DEFAULT (opt, DEFAULTOPT);
+ DEFAULT (density, 4 * fsize);
+/* maxcontig = MAX (1, MIN (MAXPHYS, MAXBSIZE) / bsize - 1); */
+ DEFAULT (maxcontig, 0);
+ DEFAULT (rotdelay, 4);
+#define MAXBLKPG(bsize) ((bsize) / sizeof(daddr_t))
+ DEFAULT (maxbpg, MAXBLKPG (bsize));
+ DEFAULT (nrpos, 8);
+
+ bbsize = BBSIZE;
+ sbsize = SBSIZE;
+
+ mkfs (0, device, fdi, fdo);
+
+ return 0;
+}
+
+void
+mkfs(pp, fsys, fi, fo)
+ struct partition *pp;
+ char *fsys;
+ int fi, fo;
+{
+ register long i, mincpc, mincpg, inospercg;
+ long cylno, rpos, blk, j, warn = 0;
+ long used, mincpgcnt, bpcg;
+ long mapcramped, inodecramped;
+ long postblsize, rotblsize, totalsbsize;
+ time_t utime;
+ quad_t sizepb;
+
+#ifndef STANDALONE
+ time(&utime);
+#endif
+ fsi = fi;
+ fso = fo;
+ if (Oflag) {
+ sblock.fs_inodefmt = FS_42INODEFMT;
+ sblock.fs_maxsymlinklen = 0;
+ } else {
+ sblock.fs_inodefmt = FS_44INODEFMT;
+ sblock.fs_maxsymlinklen = MAXSYMLINKLEN;
+ }
+ /*
+ * Validate the given file system size.
+ * Verify that its last block can actually be accessed.
+ */
+ if (fssize <= 0)
+ deverr (13, 0, "preposterous size %d", fssize);
+ wtfs(fssize - 1, sectorsize, (char *)&sblock);
+ /*
+ * collect and verify the sector and track info
+ */
+ sblock.fs_nsect = nsectors;
+ sblock.fs_ntrak = ntracks;
+ if (sblock.fs_ntrak <= 0)
+ deverr (14, 0, "preposterous ntrak %ld", sblock.fs_ntrak);
+ if (sblock.fs_nsect <= 0)
+ deverr (15, 0, "preposterous nsect %ld", sblock.fs_nsect);
+ /*
+ * collect and verify the block and fragment sizes
+ */
+ sblock.fs_bsize = bsize;
+ sblock.fs_fsize = fsize;
+ if (!POWEROF2(sblock.fs_bsize))
+ deverr (16, 0,
+ "block size must be a power of 2, not %ld",
+ sblock.fs_bsize);
+ if (!POWEROF2(sblock.fs_fsize))
+ deverr (17, 0,
+ "fragment size must be a power of 2, not %ld",
+ sblock.fs_fsize);
+ if (sblock.fs_fsize < sectorsize)
+ deverr (18, 0,
+ "fragment size %ld is too small, minimum is %d",
+ sblock.fs_fsize, sectorsize);
+ if (sblock.fs_bsize < MINBSIZE)
+ deverr (19, 0,
+ "block size %ld is too small, minimum is %d",
+ sblock.fs_bsize, MINBSIZE);
+ if (sblock.fs_bsize < sblock.fs_fsize)
+ deverr (20, 0,
+ "block size (%ld) cannot be smaller than fragment size (%ld)",
+ sblock.fs_bsize, sblock.fs_fsize);
+ sblock.fs_bmask = ~(sblock.fs_bsize - 1);
+ sblock.fs_fmask = ~(sblock.fs_fsize - 1);
+ sblock.fs_qbmask = ~sblock.fs_bmask;
+ sblock.fs_qfmask = ~sblock.fs_fmask;
+ for (sblock.fs_bshift = 0, i = sblock.fs_bsize; i > 1; i >>= 1)
+ sblock.fs_bshift++;
+ for (sblock.fs_fshift = 0, i = sblock.fs_fsize; i > 1; i >>= 1)
+ sblock.fs_fshift++;
+ sblock.fs_frag = numfrags(&sblock, sblock.fs_bsize);
+ for (sblock.fs_fragshift = 0, i = sblock.fs_frag; i > 1; i >>= 1)
+ sblock.fs_fragshift++;
+ if (sblock.fs_frag > MAXFRAG)
+ deverr (21, 0,
+ "fragment size %ld is too small, minimum with block size %ld is %ld",
+ sblock.fs_fsize, sblock.fs_bsize,
+ sblock.fs_bsize / MAXFRAG);
+ sblock.fs_nrpos = nrpos;
+ sblock.fs_nindir = sblock.fs_bsize / sizeof(daddr_t);
+ sblock.fs_inopb = sblock.fs_bsize / sizeof(struct dinode);
+ sblock.fs_nspf = sblock.fs_fsize / sectorsize;
+ for (sblock.fs_fsbtodb = 0, i = NSPF(&sblock); i > 1; i >>= 1)
+ sblock.fs_fsbtodb++;
+ sblock.fs_sblkno =
+ roundup(howmany(bbsize + sbsize, sblock.fs_fsize), sblock.fs_frag);
+ sblock.fs_cblkno = (daddr_t)(sblock.fs_sblkno +
+ roundup(howmany(sbsize, sblock.fs_fsize), sblock.fs_frag));
+ sblock.fs_iblkno = sblock.fs_cblkno + sblock.fs_frag;
+ sblock.fs_cgoffset = roundup(
+ howmany(sblock.fs_nsect, NSPF(&sblock)), sblock.fs_frag);
+ for (sblock.fs_cgmask = 0xffffffff, i = sblock.fs_ntrak; i > 1; i >>= 1)
+ sblock.fs_cgmask <<= 1;
+ if (!POWEROF2(sblock.fs_ntrak))
+ sblock.fs_cgmask <<= 1;
+ sblock.fs_maxfilesize = sblock.fs_bsize * NDADDR - 1;
+ for (sizepb = sblock.fs_bsize, i = 0; i < NIADDR; i++) {
+ sizepb *= NINDIR(&sblock);
+ sblock.fs_maxfilesize += sizepb;
+ }
+ /*
+ * Validate specified/determined secpercyl
+ * and calculate minimum cylinders per group.
+ */
+ sblock.fs_spc = secpercyl;
+ for (sblock.fs_cpc = NSPB(&sblock), i = sblock.fs_spc;
+ sblock.fs_cpc > 1 && (i & 1) == 0;
+ sblock.fs_cpc >>= 1, i >>= 1)
+ /* void */;
+ mincpc = sblock.fs_cpc;
+ bpcg = sblock.fs_spc * sectorsize;
+ inospercg = roundup(bpcg / sizeof(struct dinode), INOPB(&sblock));
+ if (inospercg > MAXIPG(&sblock))
+ inospercg = MAXIPG(&sblock);
+ used = (sblock.fs_iblkno + inospercg / INOPF(&sblock)) * NSPF(&sblock);
+ mincpgcnt = howmany(sblock.fs_cgoffset * (~sblock.fs_cgmask) + used,
+ sblock.fs_spc);
+ mincpg = roundup(mincpgcnt, mincpc);
+ /*
+ * Ensure that cylinder group with mincpg has enough space
+ * for block maps.
+ */
+ sblock.fs_cpg = mincpg;
+ sblock.fs_ipg = inospercg;
+ if (maxcontig > 1)
+ sblock.fs_contigsumsize = MIN(maxcontig, FS_MAXCONTIG);
+ mapcramped = 0;
+ while (CGSIZE(&sblock) > sblock.fs_bsize) {
+ mapcramped = 1;
+ if (sblock.fs_bsize < MAXBSIZE) {
+ sblock.fs_bsize <<= 1;
+ if ((i & 1) == 0) {
+ i >>= 1;
+ } else {
+ sblock.fs_cpc <<= 1;
+ mincpc <<= 1;
+ mincpg = roundup(mincpgcnt, mincpc);
+ sblock.fs_cpg = mincpg;
+ }
+ sblock.fs_frag <<= 1;
+ sblock.fs_fragshift += 1;
+ if (sblock.fs_frag <= MAXFRAG)
+ continue;
+ }
+ if (sblock.fs_fsize == sblock.fs_bsize)
+ deverr (22, 0,
+ "There is no block size that can support this disk");
+ sblock.fs_frag >>= 1;
+ sblock.fs_fragshift -= 1;
+ sblock.fs_fsize <<= 1;
+ sblock.fs_nspf <<= 1;
+ }
+ /*
+ * Ensure that cylinder group with mincpg has enough space for inodes.
+ */
+ inodecramped = 0;
+ used *= sectorsize;
+ inospercg = roundup((mincpg * bpcg - used) / density, INOPB(&sblock));
+ sblock.fs_ipg = inospercg;
+ while (inospercg > MAXIPG(&sblock)) {
+ inodecramped = 1;
+ if (mincpc == 1 || sblock.fs_frag == 1 ||
+ sblock.fs_bsize == MINBSIZE)
+ break;
+ deverr (0, 0,
+ "With a block size of %ld %s %ld", sblock.fs_bsize,
+ "minimum bytes per inode is",
+ (mincpg * bpcg - used) / MAXIPG(&sblock) + 1);
+ sblock.fs_bsize >>= 1;
+ sblock.fs_frag >>= 1;
+ sblock.fs_fragshift -= 1;
+ mincpc >>= 1;
+ sblock.fs_cpg = roundup(mincpgcnt, mincpc);
+ if (CGSIZE(&sblock) > sblock.fs_bsize) {
+ sblock.fs_bsize <<= 1;
+ break;
+ }
+ mincpg = sblock.fs_cpg;
+ inospercg =
+ roundup((mincpg * bpcg - used) / density, INOPB(&sblock));
+ sblock.fs_ipg = inospercg;
+ }
+ if (inodecramped) {
+ if (inospercg > MAXIPG(&sblock))
+ deverr (0, 0, "Minimum bytes per inode is %ld",
+ (mincpg * bpcg - used) / MAXIPG(&sblock) + 1);
+ else if (!mapcramped)
+ deverr (0, 0,
+ "With %d bytes per inode,"
+ " minimum cylinders per group is %ld",
+ density, mincpg);
+ }
+ if (mapcramped)
+ deverr (0, 0,
+ "With %ld sectors per cylinder,"
+ " minimum cylinders per group is %ld",
+ sblock.fs_spc, mincpg);
+ if (inodecramped || mapcramped)
+ if (sblock.fs_bsize != bsize)
+ {
+ deverr (0, 0,
+ "This requires the block size to be changed from %d to %ld",
+ bsize, sblock.fs_bsize);
+ deverr (23, 0,
+ "and the fragment size to be changed from %d to %ld",
+ fsize, sblock.fs_fsize);
+ }
+ else
+ exit(23);
+ /*
+ * Calculate the number of cylinders per group
+ */
+ sblock.fs_cpg = cpg;
+ if (sblock.fs_cpg % mincpc != 0) {
+ deverr (0, 0,
+ "%s groups must have a multiple of %ld cylinders",
+ cpgflg ? "Cylinder" : "Warning: cylinder", mincpc);
+ sblock.fs_cpg = roundup(sblock.fs_cpg, mincpc);
+ if (!cpgflg)
+ cpg = sblock.fs_cpg;
+ }
+ /*
+ * Must ensure there is enough space for inodes.
+ */
+ sblock.fs_ipg = roundup((sblock.fs_cpg * bpcg - used) / density,
+ INOPB(&sblock));
+ while (sblock.fs_ipg > MAXIPG(&sblock)) {
+ inodecramped = 1;
+ sblock.fs_cpg -= mincpc;
+ sblock.fs_ipg = roundup((sblock.fs_cpg * bpcg - used) / density,
+ INOPB(&sblock));
+ }
+ /*
+ * Must ensure there is enough space to hold block map.
+ */
+ while (CGSIZE(&sblock) > sblock.fs_bsize) {
+ mapcramped = 1;
+ sblock.fs_cpg -= mincpc;
+ sblock.fs_ipg = roundup((sblock.fs_cpg * bpcg - used) / density,
+ INOPB(&sblock));
+ }
+ sblock.fs_fpg = (sblock.fs_cpg * sblock.fs_spc) / NSPF(&sblock);
+ if ((sblock.fs_cpg * sblock.fs_spc) % NSPB(&sblock) != 0)
+ deverr (24, 0, "panic (fs_cpg * fs_spc) %% NSPF != 0");
+ if (sblock.fs_cpg < mincpg)
+ deverr (25, 0,
+ "cylinder groups must have at least %ld cylinders", mincpg);
+ else if (sblock.fs_cpg != cpg)
+ {
+ if (cpgflg && !mapcramped && !inodecramped)
+ exit(26);
+ deverr (0, 0,
+ "%s%s cylinders per group to %ld",
+ (cpgflg ? "" : "Warning: "),
+ ((mapcramped && inodecramped)
+ ? "Block size and bytes per inode restrict"
+ : mapcramped ? "Block size restricts"
+ : "Bytes per inode restrict"),
+ sblock.fs_cpg);
+ if (cpgflg)
+ exit(27);
+ }
+ sblock.fs_cgsize = fragroundup(&sblock, CGSIZE(&sblock));
+ /*
+ * Now have size for file system and nsect and ntrak.
+ * Determine number of cylinders and blocks in the file system.
+ */
+ sblock.fs_size = fssize = dbtofsb(&sblock, fssize);
+ sblock.fs_ncyl = fssize * NSPF(&sblock) / sblock.fs_spc;
+ if (fssize * NSPF(&sblock) > sblock.fs_ncyl * sblock.fs_spc) {
+ sblock.fs_ncyl++;
+ warn = 1;
+ }
+ if (sblock.fs_ncyl < 1)
+ deverr (28, 0, "file systems must have at least one cylinder");
+ /*
+ * Determine feasability/values of rotational layout tables.
+ *
+ * The size of the rotational layout tables is limited by the
+ * size of the superblock, SBSIZE. The amount of space available
+ * for tables is calculated as (SBSIZE - sizeof (struct fs)).
+ * The size of these tables is inversely proportional to the block
+ * size of the file system. The size increases if sectors per track
+ * are not powers of two, because more cylinders must be described
+ * by the tables before the rotational pattern repeats (fs_cpc).
+ */
+ sblock.fs_interleave = interleave;
+ sblock.fs_trackskew = trackskew;
+ sblock.fs_npsect = nphyssectors;
+ sblock.fs_postblformat = FS_DYNAMICPOSTBLFMT;
+ sblock.fs_sbsize = fragroundup(&sblock, sizeof(struct fs));
+ if (sblock.fs_ntrak == 1) {
+ sblock.fs_cpc = 0;
+ goto next;
+ }
+ postblsize = sblock.fs_nrpos * sblock.fs_cpc * sizeof(short);
+ rotblsize = sblock.fs_cpc * sblock.fs_spc / NSPB(&sblock);
+ totalsbsize = sizeof(struct fs) + rotblsize;
+ if (sblock.fs_nrpos == 8 && sblock.fs_cpc <= 16) {
+ /* use old static table space */
+ sblock.fs_postbloff = (char *)(&sblock.fs_opostbl[0][0]) -
+ (char *)(&sblock.fs_link);
+ sblock.fs_rotbloff = &sblock.fs_space[0] -
+ (u_char *)(&sblock.fs_link);
+ } else {
+ /* use dynamic table space */
+ sblock.fs_postbloff = &sblock.fs_space[0] -
+ (u_char *)(&sblock.fs_link);
+ sblock.fs_rotbloff = sblock.fs_postbloff + postblsize;
+ totalsbsize += postblsize;
+ }
+ if (totalsbsize > SBSIZE ||
+ sblock.fs_nsect > (1 << NBBY) * NSPB(&sblock))
+ {
+ deverr (0, 0,
+ "Warning: insufficient space in super block for "
+ "rotational layout tables with nsect %ld and ntrak %ld",
+ sblock.fs_nsect, sblock.fs_ntrak);
+ deverr (0, 0, "File system performance may be impaired");
+ sblock.fs_cpc = 0;
+ goto next;
+ }
+ sblock.fs_sbsize = fragroundup(&sblock, totalsbsize);
+ /*
+ * calculate the available blocks for each rotational position
+ */
+ for (cylno = 0; cylno < sblock.fs_cpc; cylno++)
+ for (rpos = 0; rpos < sblock.fs_nrpos; rpos++)
+ fs_postbl(&sblock, cylno)[rpos] = -1;
+ for (i = (rotblsize - 1) * sblock.fs_frag;
+ i >= 0; i -= sblock.fs_frag) {
+ cylno = cbtocylno(&sblock, i);
+ rpos = cbtorpos(&sblock, i);
+ blk = fragstoblks(&sblock, i);
+ if (fs_postbl(&sblock, cylno)[rpos] == -1)
+ fs_rotbl(&sblock)[blk] = 0;
+ else
+ fs_rotbl(&sblock)[blk] =
+ fs_postbl(&sblock, cylno)[rpos] - blk;
+ fs_postbl(&sblock, cylno)[rpos] = blk;
+ }
+next:
+ /*
+ * Compute/validate number of cylinder groups.
+ */
+ sblock.fs_ncg = sblock.fs_ncyl / sblock.fs_cpg;
+ if (sblock.fs_ncyl % sblock.fs_cpg)
+ sblock.fs_ncg++;
+ sblock.fs_dblkno = sblock.fs_iblkno + sblock.fs_ipg / INOPF(&sblock);
+ i = MIN(~sblock.fs_cgmask, sblock.fs_ncg - 1);
+ if (cgdmin(&sblock, i) - cgbase(&sblock, i) >= sblock.fs_fpg)
+ {
+ deverr (0, 0,
+ "Inode blocks/cyl group (%ld) >= data blocks (%ld)",
+ cgdmin(&sblock, i) - cgbase(&sblock, i) / sblock.fs_frag,
+ sblock.fs_fpg / sblock.fs_frag);
+ deverr (29, 0,
+ "number of cylinders per cylinder group (%ld)"
+ " must be increased", sblock.fs_cpg);
+ }
+ j = sblock.fs_ncg - 1;
+ if ((i = fssize - j * sblock.fs_fpg) < sblock.fs_fpg &&
+ cgdmin(&sblock, j) - cgbase(&sblock, j) > i) {
+ if (j == 0)
+ deverr (30, 0,
+ "Filesystem must have at least %ld sectors",
+ NSPF(&sblock)
+ * (cgdmin(&sblock, 0) + 3 * sblock.fs_frag));
+ deverr (0, 0,
+ "Warning: inode blocks/cyl group (%ld) >="
+ " data blocks (%ld) in last cylinder group.",
+ ((cgdmin(&sblock, j) - cgbase(&sblock, j))
+ / sblock.fs_frag),
+ i / sblock.fs_frag);
+ deverr (0, 0,
+ "This implies %ld sector(s) cannot be allocated",
+ i * NSPF(&sblock));
+ sblock.fs_ncg--;
+ sblock.fs_ncyl -= sblock.fs_ncyl % sblock.fs_cpg;
+ sblock.fs_size = fssize = sblock.fs_ncyl * sblock.fs_spc /
+ NSPF(&sblock);
+ warn = 0;
+ }
+ if (warn)
+ deverr (0, 0,
+ "Warning: %ld sector(s) in last cylinder unallocated",
+ sblock.fs_spc
+ - (fssize * NSPF(&sblock) - (sblock.fs_ncyl - 1)
+ * sblock.fs_spc));
+ /*
+ * fill in remaining fields of the super block
+ */
+ sblock.fs_csaddr = cgdmin(&sblock, 0);
+ sblock.fs_cssize =
+ fragroundup(&sblock, sblock.fs_ncg * sizeof(struct csum));
+ i = sblock.fs_bsize / sizeof(struct csum);
+ sblock.fs_csmask = ~(i - 1);
+ for (sblock.fs_csshift = 0; i > 1; i >>= 1)
+ sblock.fs_csshift++;
+ fscs = (struct csum *)calloc(1, sblock.fs_cssize);
+ sblock.fs_magic = FS_MAGIC;
+ sblock.fs_rotdelay = rotdelay;
+ sblock.fs_minfree = minfree;
+ sblock.fs_maxcontig = maxcontig;
+ sblock.fs_headswitch = headswitch;
+ sblock.fs_trkseek = trackseek;
+ sblock.fs_maxbpg = maxbpg;
+ sblock.fs_rps = rpm / 60;
+ sblock.fs_optim = opt;
+ sblock.fs_cgrotor = 0;
+ sblock.fs_cstotal.cs_ndir = 0;
+ sblock.fs_cstotal.cs_nbfree = 0;
+ sblock.fs_cstotal.cs_nifree = 0;
+ sblock.fs_cstotal.cs_nffree = 0;
+ sblock.fs_fmod = 0;
+ sblock.fs_ronly = 0;
+ sblock.fs_clean = 1;
+
+ /*
+ * Dump out summary information about file system.
+ */
+ printf("%s:\n\t%ld sectors in %ld %s of %ld tracks, %ld sectors\n",
+ fsys, sblock.fs_size * NSPF(&sblock), sblock.fs_ncyl,
+ "cylinders", sblock.fs_ntrak, sblock.fs_nsect);
+#define B2MBFACTOR (1 / (1024.0 * 1024.0))
+ printf("\t%.1fMB in %ld cyl groups (%ld c/g, %.2fMB/g, %ld i/g)\n",
+ (float)sblock.fs_size * sblock.fs_fsize * B2MBFACTOR,
+ sblock.fs_ncg, sblock.fs_cpg,
+ (float)sblock.fs_fpg * sblock.fs_fsize * B2MBFACTOR,
+ sblock.fs_ipg);
+#undef B2MBFACTOR
+
+ /*
+ * Now build the cylinders group blocks and
+ * then print out indices of cylinder groups.
+ */
+ printf("\tsuperblock backups at:");
+ for (cylno = 0; cylno < sblock.fs_ncg; cylno++) {
+ initcg(cylno, utime);
+ if (cylno % 8 == 0)
+ printf("\n\t");
+ printf(" %ld,", fsbtodb(&sblock, cgsblock(&sblock, cylno)));
+ }
+ printf("\n");
+ if (Nflag)
+ exit(0);
+ /*
+ * Now construct the initial file system,
+ * then write out the super-block.
+ */
+ fsinit(utime);
+ sblock.fs_time = utime;
+ wtfs((int)SBOFF / sectorsize, sbsize, (char *)&sblock);
+ for (i = 0; i < sblock.fs_cssize; i += sblock.fs_bsize)
+ wtfs(fsbtodb(&sblock, sblock.fs_csaddr + numfrags(&sblock, i)),
+ sblock.fs_cssize - i < sblock.fs_bsize ?
+ sblock.fs_cssize - i : sblock.fs_bsize,
+ ((char *)fscs) + i);
+ /*
+ * Write out the duplicate super blocks
+ */
+ for (cylno = 0; cylno < sblock.fs_ncg; cylno++)
+ wtfs(fsbtodb(&sblock, cgsblock(&sblock, cylno)),
+ sbsize, (char *)&sblock);
+#if 0 /* Not in Hurd (yet) */
+ /*
+ * Update information about this partion in pack
+ * label, to that it may be updated on disk.
+ */
+ pp->p_fstype = FS_BSDFFS;
+ pp->p_fsize = sblock.fs_fsize;
+ pp->p_frag = sblock.fs_frag;
+ pp->p_cpg = sblock.fs_cpg;
+#endif
+}
+
+/*
+ * Initialize a cylinder group.
+ */
+void
+initcg(cylno, utime)
+ int cylno;
+ time_t utime;
+{
+ long i;
+ daddr_t cbase, d, dlower, dupper, dmax, blkno;
+ register struct csum *cs;
+
+ /*
+ * Determine block bounds for cylinder group.
+ * Allow space for super block summary information in first
+ * cylinder group.
+ */
+ cbase = cgbase(&sblock, cylno);
+ dmax = cbase + sblock.fs_fpg;
+ if (dmax > sblock.fs_size)
+ dmax = sblock.fs_size;
+ dlower = cgsblock(&sblock, cylno) - cbase;
+ dupper = cgdmin(&sblock, cylno) - cbase;
+ if (cylno == 0)
+ dupper += howmany(sblock.fs_cssize, sblock.fs_fsize);
+ cs = fscs + cylno;
+ bzero(&acg, sblock.fs_cgsize);
+ acg.cg_time = utime;
+ acg.cg_magic = CG_MAGIC;
+ acg.cg_cgx = cylno;
+ if (cylno == sblock.fs_ncg - 1)
+ acg.cg_ncyl = sblock.fs_ncyl % sblock.fs_cpg;
+ else
+ acg.cg_ncyl = sblock.fs_cpg;
+ acg.cg_niblk = sblock.fs_ipg;
+ acg.cg_ndblk = dmax - cbase;
+ if (sblock.fs_contigsumsize > 0)
+ acg.cg_nclusterblks = acg.cg_ndblk / sblock.fs_frag;
+ acg.cg_btotoff = &acg.cg_space[0] - (u_char *)(&acg.cg_link);
+ acg.cg_boff = acg.cg_btotoff + sblock.fs_cpg * sizeof(long);
+ acg.cg_iusedoff = acg.cg_boff +
+ sblock.fs_cpg * sblock.fs_nrpos * sizeof(short);
+ acg.cg_freeoff = acg.cg_iusedoff + howmany(sblock.fs_ipg, NBBY);
+ if (sblock.fs_contigsumsize <= 0) {
+ acg.cg_nextfreeoff = acg.cg_freeoff +
+ howmany(sblock.fs_cpg * sblock.fs_spc / NSPF(&sblock), NBBY);
+ } else {
+ acg.cg_clustersumoff = acg.cg_freeoff + howmany
+ (sblock.fs_cpg * sblock.fs_spc / NSPF(&sblock), NBBY) -
+ sizeof(long);
+ acg.cg_clustersumoff =
+ roundup(acg.cg_clustersumoff, sizeof(long));
+ acg.cg_clusteroff = acg.cg_clustersumoff +
+ (sblock.fs_contigsumsize + 1) * sizeof(long);
+ acg.cg_nextfreeoff = acg.cg_clusteroff + howmany
+ (sblock.fs_cpg * sblock.fs_spc / NSPB(&sblock), NBBY);
+ }
+ if (acg.cg_nextfreeoff - (long)(&acg.cg_link) > sblock.fs_cgsize)
+ deverr (37, 0, "Panic: cylinder group too big");
+ acg.cg_cs.cs_nifree += sblock.fs_ipg;
+ if (cylno == 0)
+ for (i = 0; i < ROOTINO; i++) {
+ setbit(cg_inosused(&acg), i);
+ acg.cg_cs.cs_nifree--;
+ }
+ for (i = 0; i < sblock.fs_ipg / INOPF(&sblock); i += sblock.fs_frag)
+ wtfs(fsbtodb(&sblock, cgimin(&sblock, cylno) + i),
+ sblock.fs_bsize, (char *)zino);
+ if (cylno > 0) {
+ /*
+ * In cylno 0, beginning space is reserved
+ * for boot and super blocks.
+ */
+ for (d = 0; d < dlower; d += sblock.fs_frag) {
+ blkno = d / sblock.fs_frag;
+ setblock(&sblock, cg_blksfree(&acg), blkno);
+ if (sblock.fs_contigsumsize > 0)
+ setbit(cg_clustersfree(&acg), blkno);
+ acg.cg_cs.cs_nbfree++;
+ cg_blktot(&acg)[cbtocylno(&sblock, d)]++;
+ cg_blks(&sblock, &acg, cbtocylno(&sblock, d))
+ [cbtorpos(&sblock, d)]++;
+ }
+ sblock.fs_dsize += dlower;
+ }
+ sblock.fs_dsize += acg.cg_ndblk - dupper;
+ i = dupper % sblock.fs_frag;
+ if (i) {
+ acg.cg_frsum[sblock.fs_frag - i]++;
+ for (d = dupper + sblock.fs_frag - i; dupper < d; dupper++) {
+ setbit(cg_blksfree(&acg), dupper);
+ acg.cg_cs.cs_nffree++;
+ }
+ }
+ for (d = dupper; d + sblock.fs_frag <= dmax - cbase; ) {
+ blkno = d / sblock.fs_frag;
+ setblock(&sblock, cg_blksfree(&acg), blkno);
+ if (sblock.fs_contigsumsize > 0)
+ setbit(cg_clustersfree(&acg), blkno);
+ acg.cg_cs.cs_nbfree++;
+ cg_blktot(&acg)[cbtocylno(&sblock, d)]++;
+ cg_blks(&sblock, &acg, cbtocylno(&sblock, d))
+ [cbtorpos(&sblock, d)]++;
+ d += sblock.fs_frag;
+ }
+ if (d < dmax - cbase) {
+ acg.cg_frsum[dmax - cbase - d]++;
+ for (; d < dmax - cbase; d++) {
+ setbit(cg_blksfree(&acg), d);
+ acg.cg_cs.cs_nffree++;
+ }
+ }
+ if (sblock.fs_contigsumsize > 0) {
+ long *sump = cg_clustersum(&acg);
+ u_char *mapp = cg_clustersfree(&acg);
+ int map = *mapp++;
+ int bit = 1;
+ int run = 0;
+
+ for (i = 0; i < acg.cg_nclusterblks; i++) {
+ if ((map & bit) != 0) {
+ run++;
+ } else if (run != 0) {
+ if (run > sblock.fs_contigsumsize)
+ run = sblock.fs_contigsumsize;
+ sump[run]++;
+ run = 0;
+ }
+ if ((i & (NBBY - 1)) != (NBBY - 1)) {
+ bit <<= 1;
+ } else {
+ map = *mapp++;
+ bit = 1;
+ }
+ }
+ if (run != 0) {
+ if (run > sblock.fs_contigsumsize)
+ run = sblock.fs_contigsumsize;
+ sump[run]++;
+ }
+ }
+ sblock.fs_cstotal.cs_ndir += acg.cg_cs.cs_ndir;
+ sblock.fs_cstotal.cs_nffree += acg.cg_cs.cs_nffree;
+ sblock.fs_cstotal.cs_nbfree += acg.cg_cs.cs_nbfree;
+ sblock.fs_cstotal.cs_nifree += acg.cg_cs.cs_nifree;
+ *cs = acg.cg_cs;
+ wtfs(fsbtodb(&sblock, cgtod(&sblock, cylno)),
+ sblock.fs_bsize, (char *)&acg);
+}
+
+/*
+ * initialize the file system
+ */
+struct dinode node;
+
+#ifdef LOSTDIR
+#define PREDEFDIR 3
+#else
+#define PREDEFDIR 2
+#endif
+
+struct directory_entry root_dir[] = {
+ { ROOTINO, sizeof(struct directory_entry), DT_DIR, 1, "." },
+ { ROOTINO, sizeof(struct directory_entry), DT_DIR, 2, ".." },
+#ifdef LOSTDIR
+ { LOSTFOUNDINO, sizeof(struct directory_entry), DT_DIR, 10, "lost+found" },
+#endif
+};
+struct odirectory_entry {
+ u_long d_ino;
+ u_short d_reclen;
+ u_short d_namlen;
+ u_char d_name[MAXNAMLEN + 1];
+} oroot_dir[] = {
+ { ROOTINO, sizeof(struct directory_entry), 1, "." },
+ { ROOTINO, sizeof(struct directory_entry), 2, ".." },
+#ifdef LOSTDIR
+ { LOSTFOUNDINO, sizeof(struct directory_entry), 10, "lost+found" },
+#endif
+};
+#ifdef LOSTDIR
+struct directory_entry lost_found_dir[] = {
+ { LOSTFOUNDINO, sizeof(struct directory_entry), DT_DIR, 1, "." },
+ { ROOTINO, sizeof(struct directory_entry), DT_DIR, 2, ".." },
+ { 0, DIRBLKSIZ, 0, 0, 0 },
+};
+struct odirectory_entry olost_found_dir[] = {
+ { LOSTFOUNDINO, sizeof(struct directory_entry), 1, "." },
+ { ROOTINO, sizeof(struct directory_entry), 2, ".." },
+ { 0, DIRBLKSIZ, 0, 0 },
+};
+#endif
+char buf[MAXBSIZE];
+
+void
+fsinit(utime)
+ time_t utime;
+{
+ /*
+ * initialize the node
+ */
+ node.di_atime.tv_sec = utime;
+ node.di_mtime.tv_sec = utime;
+ node.di_ctime.tv_sec = utime;
+#ifdef LOSTDIR
+ /*
+ * create the lost+found directory
+ */
+ if (Oflag) {
+ (void)makedir((struct directory_entry *)olost_found_dir, 2);
+ for (i = DIRBLKSIZ; i < sblock.fs_bsize; i += DIRBLKSIZ)
+ bcopy(&olost_found_dir[2], &buf[i],
+ DIRSIZ(0, &olost_found_dir[2]));
+ } else {
+ (void)makedir(lost_found_dir, 2);
+ for (i = DIRBLKSIZ; i < sblock.fs_bsize; i += DIRBLKSIZ)
+ bcopy(&lost_found_dir[2], &buf[i],
+ DIRSIZ(0, &lost_found_dir[2]));
+ }
+ node.di_model = ifdir | UMASK;
+ node.di_modeh = 0;
+ node.di_nlink = 2;
+ node.di_size = sblock.fs_bsize;
+ node.di_db[0] = alloc(node.di_size, DI_MODE (&node));
+ node.di_blocks = btodb(fragroundup(&sblock, node.di_size));
+ wtfs(fsbtodb(&sblock, node.di_db[0]), node.di_size, buf);
+ iput(&node, LOSTFOUNDINO);
+#endif
+ /*
+ * create the root directory
+ */
+ node.di_model = IFDIR | UMASK;
+ node.di_modeh = 0;
+ node.di_nlink = PREDEFDIR;
+
+ /* Set the uid/gid to non-root if run by a non-root user. This
+ is what mke2fs does in e2fsprogs-1.18 (actually it uses the
+ real IDs iff geteuid()!=0, but that is just wrong). */
+ node.di_uid = geteuid();
+ if (node.di_uid != 0)
+ node.di_gid = getegid();
+
+ if (Oflag)
+ node.di_size = makedir((struct directory_entry *)oroot_dir, PREDEFDIR);
+ else
+ node.di_size = makedir(root_dir, PREDEFDIR);
+ node.di_db[0] = alloc(sblock.fs_fsize, DI_MODE (&node));
+ node.di_blocks = btodb(fragroundup(&sblock, node.di_size));
+ wtfs(fsbtodb(&sblock, node.di_db[0]), sblock.fs_fsize, buf);
+ iput(&node, ROOTINO);
+}
+
+/*
+ * construct a set of directory entries in "buf".
+ * return size of directory.
+ */
+int
+makedir(protodir, entries)
+ register struct directory_entry *protodir;
+ int entries;
+{
+ char *cp;
+ int i, spcleft;
+
+ spcleft = DIRBLKSIZ;
+ for (cp = buf, i = 0; i < entries - 1; i++) {
+ protodir[i].d_reclen = DIRSIZ(0, &protodir[i]);
+ bcopy(&protodir[i], cp, protodir[i].d_reclen);
+ cp += protodir[i].d_reclen;
+ spcleft -= protodir[i].d_reclen;
+ }
+ protodir[i].d_reclen = spcleft;
+ bcopy(&protodir[i], cp, DIRSIZ(0, &protodir[i]));
+ return (DIRBLKSIZ);
+}
+
+/*
+ * allocate a block or frag
+ */
+daddr_t
+alloc(size, mode)
+ int size;
+ int mode;
+{
+ int i, frag;
+ daddr_t d, blkno;
+
+ rdfs(fsbtodb(&sblock, cgtod(&sblock, 0)), sblock.fs_cgsize,
+ (char *)&acg);
+ if (acg.cg_magic != CG_MAGIC) {
+ deverr (0, 0, "cg 0: bad magic number");
+ return (0);
+ }
+ if (acg.cg_cs.cs_nbfree == 0) {
+ deverr (0, 0, "first cylinder group ran out of space");
+ return (0);
+ }
+ for (d = 0; d < acg.cg_ndblk; d += sblock.fs_frag)
+ if (isblock(&sblock, cg_blksfree(&acg), d / sblock.fs_frag))
+ goto goth;
+ deverr (0, 0, "internal error: can't find block in cyl 0");
+ return (0);
+goth:
+ blkno = fragstoblks(&sblock, d);
+ clrblock(&sblock, cg_blksfree(&acg), blkno);
+ if (sblock.fs_contigsumsize > 0)
+ clrbit(cg_clustersfree(&acg), blkno);
+ acg.cg_cs.cs_nbfree--;
+ sblock.fs_cstotal.cs_nbfree--;
+ fscs[0].cs_nbfree--;
+ if (mode & IFDIR) {
+ acg.cg_cs.cs_ndir++;
+ sblock.fs_cstotal.cs_ndir++;
+ fscs[0].cs_ndir++;
+ }
+ cg_blktot(&acg)[cbtocylno(&sblock, d)]--;
+ cg_blks(&sblock, &acg, cbtocylno(&sblock, d))[cbtorpos(&sblock, d)]--;
+ if (size != sblock.fs_bsize) {
+ frag = howmany(size, sblock.fs_fsize);
+ fscs[0].cs_nffree += sblock.fs_frag - frag;
+ sblock.fs_cstotal.cs_nffree += sblock.fs_frag - frag;
+ acg.cg_cs.cs_nffree += sblock.fs_frag - frag;
+ acg.cg_frsum[sblock.fs_frag - frag]++;
+ for (i = frag; i < sblock.fs_frag; i++)
+ setbit(cg_blksfree(&acg), d + i);
+ }
+ wtfs(fsbtodb(&sblock, cgtod(&sblock, 0)), sblock.fs_cgsize,
+ (char *)&acg);
+ return (d);
+}
+
+/*
+ * Allocate an inode on the disk
+ */
+void
+iput(ip, ino)
+ register struct dinode *ip;
+ register ino_t ino;
+{
+ struct dinode buf[MAXINOPB];
+ daddr_t d;
+ int c;
+
+ c = ino_to_cg(&sblock, ino);
+ rdfs(fsbtodb(&sblock, cgtod(&sblock, 0)), sblock.fs_cgsize,
+ (char *)&acg);
+ if (acg.cg_magic != CG_MAGIC)
+ deverr (31, 0, "cg 0: bad magic number");
+ acg.cg_cs.cs_nifree--;
+ setbit(cg_inosused(&acg), ino);
+ wtfs(fsbtodb(&sblock, cgtod(&sblock, 0)), sblock.fs_cgsize,
+ (char *)&acg);
+ sblock.fs_cstotal.cs_nifree--;
+ fscs[0].cs_nifree--;
+ if (ino >= sblock.fs_ipg * sblock.fs_ncg)
+ deverr (32, 0, "fsinit: inode value out of range (%Ld)", ino);
+ d = fsbtodb(&sblock, ino_to_fsba(&sblock, ino));
+ rdfs(d, sblock.fs_bsize, buf);
+ buf[ino_to_fsbo(&sblock, ino)] = *ip;
+ wtfs(d, sblock.fs_bsize, buf);
+}
+
+/*
+ * read a block from the file system
+ */
+void
+rdfs(bno, size, bf)
+ daddr_t bno;
+ int size;
+ char *bf;
+{
+ int n;
+ if (lseek(fsi, (off_t)bno * sectorsize, 0) < 0)
+ deverr (33, errno, "rdfs: %ld: seek error", bno);
+ n = read(fsi, bf, size);
+ if (n != size)
+ deverr (34, errno, "rdfs: %ld: read error", bno);
+}
+
+/*
+ * write a block to the file system
+ */
+void
+wtfs(bno, size, bf)
+ daddr_t bno;
+ int size;
+ char *bf;
+{
+ int n;
+ if (Nflag)
+ return;
+ if (lseek(fso, (off_t)bno * sectorsize, SEEK_SET) < 0)
+ deverr (35, errno, "wtfs: %ld: seek error", bno);
+ n = write(fso, bf, size);
+ if (n != size)
+ deverr (36, errno, "wtfs: %ld: write error", bno);
+}
+
+/*
+ * check if a block is available
+ */
+int
+isblock(fs, cp, h)
+ struct fs *fs;
+ unsigned char *cp;
+ int h;
+{
+ unsigned char mask;
+
+ switch (fs->fs_frag) {
+ case 8:
+ return (cp[h] == 0xff);
+ case 4:
+ mask = 0x0f << ((h & 0x1) << 2);
+ return ((cp[h >> 1] & mask) == mask);
+ case 2:
+ mask = 0x03 << ((h & 0x3) << 1);
+ return ((cp[h >> 2] & mask) == mask);
+ case 1:
+ mask = 0x01 << (h & 0x7);
+ return ((cp[h >> 3] & mask) == mask);
+ default:
+ deverr (0, 0, "isblock bad fs_frag %ld", fs->fs_frag);
+ return (0);
+ }
+}
+
+/*
+ * take a block out of the map
+ */
+void
+clrblock(fs, cp, h)
+ struct fs *fs;
+ unsigned char *cp;
+ int h;
+{
+ switch ((fs)->fs_frag) {
+ case 8:
+ cp[h] = 0;
+ return;
+ case 4:
+ cp[h >> 1] &= ~(0x0f << ((h & 0x1) << 2));
+ return;
+ case 2:
+ cp[h >> 2] &= ~(0x03 << ((h & 0x3) << 1));
+ return;
+ case 1:
+ cp[h >> 3] &= ~(0x01 << (h & 0x7));
+ return;
+ default:
+ deverr (0, 0, "clrblock bad fs_frag %ld", fs->fs_frag);
+ return;
+ }
+}
+
+/*
+ * put a block into the map
+ */
+void
+setblock(fs, cp, h)
+ struct fs *fs;
+ unsigned char *cp;
+ int h;
+{
+ switch (fs->fs_frag) {
+ case 8:
+ cp[h] = 0xff;
+ return;
+ case 4:
+ cp[h >> 1] |= (0x0f << ((h & 0x1) << 2));
+ return;
+ case 2:
+ cp[h >> 2] |= (0x03 << ((h & 0x3) << 1));
+ return;
+ case 1:
+ cp[h >> 3] |= (0x01 << (h & 0x7));
+ return;
+ default:
+ deverr (0, 0, "setblock bad fs_frag %ld", fs->fs_frag);
+ return;
+ }
+}
diff --git a/ufs-utils/newfs.c b/ufs-utils/newfs.c
new file mode 100644
index 00000000..efc7dbea
--- /dev/null
+++ b/ufs-utils/newfs.c
@@ -0,0 +1,705 @@
+/*
+ * Copyright (c) 1983, 1989, 1993, 1994
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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.
+ */
+
+#ifndef lint
+static char copyright[] =
+"@(#) Copyright (c) 1983, 1989, 1993, 1994\n\
+ The Regents of the University of California. All rights reserved.\n";
+#endif /* not lint */
+
+#ifndef lint
+/*static char sccsid[] = "from: @(#)newfs.c 8.8 (Berkeley) 4/18/94";*/
+static char *rcsid = "$Id: newfs.c,v 1.2 1994/09/09 14:11:41 mib Exp $";
+#endif /* not lint */
+
+/*
+ * newfs: friendly front end to mkfs
+ */
+#include <sys/param.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+/* #include <sys/disklabel.h> */
+#include <sys/file.h>
+/* #include <sys/mount.h> */
+
+#include "../ufs/dir.h"
+#include "../ufs/fs.h"
+
+#include <ctype.h>
+#include <errno.h>
+#include <paths.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <syslog.h>
+#include <unistd.h>
+
+#if __STDC__
+#include <stdarg.h>
+#else
+#include <varargs.h>
+#endif
+
+/* #include "mntopts.h" */
+
+/* GNU Hurd additions */
+#define MAXPATHLEN 2048
+
+/* End GNU Hurd additions */
+
+
+#if 0
+struct mntopt mopts[] = {
+ MOPT_STDOPTS,
+ MOPT_ASYNC,
+ { NULL },
+};
+#endif
+
+#if __STDC__
+void fatal(const char *fmt, ...);
+#else
+void fatal();
+#endif
+
+#define COMPAT /* allow non-labeled disks */
+
+/*
+ * The following two constants set the default block and fragment sizes.
+ * Both constants must be a power of 2 and meet the following constraints:
+ * MINBSIZE <= DESBLKSIZE <= MAXBSIZE
+ * sectorsize <= DESFRAGSIZE <= DESBLKSIZE
+ * DESBLKSIZE / DESFRAGSIZE <= 8
+ */
+#define DFL_FRAGSIZE 1024
+#define DFL_BLKSIZE 8192
+
+/*
+ * Cylinder groups may have up to many cylinders. The actual
+ * number used depends upon how much information can be stored
+ * on a single cylinder. The default is to use 16 cylinders
+ * per group.
+ */
+#define DESCPG 16 /* desired fs_cpg */
+
+/*
+ * ROTDELAY gives the minimum number of milliseconds to initiate
+ * another disk transfer on the same cylinder. It is used in
+ * determining the rotationally optimal layout for disk blocks
+ * within a file; the default of fs_rotdelay is 4ms.
+ */
+#define ROTDELAY 4
+
+/*
+ * MAXBLKPG determines the maximum number of data blocks which are
+ * placed in a single cylinder group. The default is one indirect
+ * block worth of data blocks.
+ */
+#define MAXBLKPG(bsize) ((bsize) / sizeof(daddr_t))
+
+/*
+ * Each file system has a number of inodes statically allocated.
+ * We allocate one inode slot per NFPI fragments, expecting this
+ * to be far more than we will ever need.
+ */
+#define NFPI 4
+
+/*
+ * For each cylinder we keep track of the availability of blocks at different
+ * rotational positions, so that we can lay out the data to be picked
+ * up with minimum rotational latency. NRPOS is the default number of
+ * rotational positions that we distinguish. With NRPOS of 8 the resolution
+ * of our summary information is 2ms for a typical 3600 rpm drive.
+ */
+#define NRPOS 8 /* number distinct rotational positions */
+
+
+int mfs; /* run as the memory based filesystem */
+int Nflag; /* run without writing file system */
+int Oflag; /* format as an 4.3BSD file system */
+int fssize; /* file system size */
+int ntracks; /* # tracks/cylinder */
+int nsectors; /* # sectors/track */
+int nphyssectors; /* # sectors/track including spares */
+int secpercyl; /* sectors per cylinder */
+int trackspares = -1; /* spare sectors per track */
+int cylspares = -1; /* spare sectors per cylinder */
+int sectorsize; /* bytes/sector */
+#ifdef tahoe
+int realsectorsize; /* bytes/sector in hardware */
+#endif
+int rpm; /* revolutions/minute of drive */
+int interleave; /* hardware sector interleave */
+int trackskew = -1; /* sector 0 skew, per track */
+int headswitch; /* head switch time, usec */
+int trackseek; /* track-to-track seek, usec */
+int fsize = 0; /* fragment size */
+int bsize = 0; /* block size */
+int cpg = DESCPG; /* cylinders/cylinder group */
+int cpgflg; /* cylinders/cylinder group flag was given */
+int minfree = MINFREE; /* free space threshold */
+int opt = DEFAULTOPT; /* optimization preference (space or time) */
+int density; /* number of bytes per inode */
+int maxcontig = 0; /* max contiguous blocks to allocate */
+int rotdelay = ROTDELAY; /* rotational delay between blocks */
+int maxbpg; /* maximum blocks per file in a cyl group */
+int nrpos = NRPOS; /* # of distinguished rotational positions */
+int bbsize = BBSIZE; /* boot block size */
+int sbsize = SBSIZE; /* superblock size */
+/* int mntflags = MNT_ASYNC;*/ /* flags to be passed to mount */
+u_long memleft; /* virtual memory available */
+caddr_t membase; /* start address of memory based filesystem */
+#ifdef COMPAT
+char *disktype;
+int unlabeled;
+#endif
+
+char device[MAXPATHLEN];
+char *progname;
+
+int
+main(argc, argv)
+ int argc;
+ char *argv[];
+{
+ extern char *optarg;
+ extern int optind;
+ register int ch;
+ register struct partition *pp;
+ register struct disklabel *lp;
+ struct disklabel *getdisklabel();
+/* struct partition oldpartition; */
+ struct stat st;
+ struct statfs *mp;
+ int fsi, fso, len, n;
+ char *cp, *s1, *s2, *special, *opstring, buf[BUFSIZ];
+
+ if (progname = rindex(*argv, '/'))
+ ++progname;
+ else
+ progname = *argv;
+
+#if 0
+ if (strstr(progname, "mfs")) {
+ mfs = 1;
+ Nflag++;
+ }
+#endif
+
+ opstring = mfs ?
+ "NT:a:b:c:d:e:f:i:m:o:s:" :
+ "NOS:T:a:b:c:d:e:f:i:k:l:m:n:o:p:r:s:t:u:x:";
+ while ((ch = getopt(argc, argv, opstring)) != EOF)
+ switch (ch) {
+ case 'N':
+ Nflag = 1;
+ break;
+ case 'O':
+ Oflag = 1;
+ break;
+ case 'S':
+ if ((sectorsize = atoi(optarg)) <= 0)
+ fatal("%s: bad sector size", optarg);
+ break;
+#ifdef COMPAT
+ case 'T':
+ disktype = optarg;
+ break;
+#endif
+ case 'a':
+ if ((maxcontig = atoi(optarg)) <= 0)
+ fatal("%s: bad maximum contiguous blocks\n",
+ optarg);
+ break;
+ case 'b':
+ if ((bsize = atoi(optarg)) < MINBSIZE)
+ fatal("%s: bad block size", optarg);
+ break;
+ case 'c':
+ if ((cpg = atoi(optarg)) <= 0)
+ fatal("%s: bad cylinders/group", optarg);
+ cpgflg++;
+ break;
+ case 'd':
+ if ((rotdelay = atoi(optarg)) < 0)
+ fatal("%s: bad rotational delay\n", optarg);
+ break;
+ case 'e':
+ if ((maxbpg = atoi(optarg)) <= 0)
+ fatal("%s: bad blocks per file in a cylinder group\n",
+ optarg);
+ break;
+ case 'f':
+ if ((fsize = atoi(optarg)) <= 0)
+ fatal("%s: bad fragment size", optarg);
+ break;
+ case 'i':
+ if ((density = atoi(optarg)) <= 0)
+ fatal("%s: bad bytes per inode\n", optarg);
+ break;
+ case 'k':
+ if ((trackskew = atoi(optarg)) < 0)
+ fatal("%s: bad track skew", optarg);
+ break;
+ case 'l':
+ if ((interleave = atoi(optarg)) <= 0)
+ fatal("%s: bad interleave", optarg);
+ break;
+ case 'm':
+ if ((minfree = atoi(optarg)) < 0 || minfree > 99)
+ fatal("%s: bad free space %%\n", optarg);
+ break;
+ case 'n':
+ if ((nrpos = atoi(optarg)) <= 0)
+ fatal("%s: bad rotational layout count\n",
+ optarg);
+ break;
+ case 'o':
+#if 0
+ if (mfs)
+ getmntopts(optarg, mopts, &mntflags);
+ else
+#endif
+ {
+ if (strcmp(optarg, "space") == 0)
+ opt = FS_OPTSPACE;
+ else if (strcmp(optarg, "time") == 0)
+ opt = FS_OPTTIME;
+ else
+ fatal("%s: unknown optimization preference: use `space' or `time'.");
+ }
+ break;
+ case 'p':
+ if ((trackspares = atoi(optarg)) < 0)
+ fatal("%s: bad spare sectors per track",
+ optarg);
+ break;
+ case 'r':
+ if ((rpm = atoi(optarg)) <= 0)
+ fatal("%s: bad revolutions/minute\n", optarg);
+ break;
+ case 's':
+ if ((fssize = atoi(optarg)) <= 0)
+ fatal("%s: bad file system size", optarg);
+ break;
+ case 't':
+ if ((ntracks = atoi(optarg)) <= 0)
+ fatal("%s: bad total tracks", optarg);
+ break;
+ case 'u':
+ if ((nsectors = atoi(optarg)) <= 0)
+ fatal("%s: bad sectors/track", optarg);
+ break;
+ case 'x':
+ if ((cylspares = atoi(optarg)) < 0)
+ fatal("%s: bad spare sectors per cylinder",
+ optarg);
+ break;
+ case '?':
+ default:
+ usage();
+ }
+ argc -= optind;
+ argv += optind;
+
+ if (argc != 2 && (mfs || argc != 1))
+ usage();
+
+ special = argv[0];
+ cp = rindex(special, '/');
+ if (cp == 0) {
+ /*
+ * No path prefix; try /dev/r%s then /dev/%s.
+ */
+ (void)sprintf(device, "%sr%s", _PATH_DEV, special);
+ if (stat(device, &st) == -1)
+ (void)sprintf(device, "%s%s", _PATH_DEV, special);
+ special = device;
+ }
+ if (Nflag) {
+ fso = -1;
+ } else {
+ fso = open(special, O_WRONLY);
+ if (fso < 0)
+ fatal("%s: %s", special, strerror(errno));
+
+#if 0
+ /* Bail if target special is mounted */
+ n = getmntinfo(&mp, MNT_NOWAIT);
+ if (n == 0)
+ fatal("%s: getmntinfo: %s", special, strerror(errno));
+
+ len = sizeof(_PATH_DEV) - 1;
+ s1 = special;
+ if (strncmp(_PATH_DEV, s1, len) == 0)
+ s1 += len;
+
+ while (--n >= 0) {
+ s2 = mp->f_mntfromname;
+ if (strncmp(_PATH_DEV, s2, len) == 0) {
+ s2 += len - 1;
+ *s2 = 'r';
+ }
+ if (strcmp(s1, s2) == 0 || strcmp(s1, &s2[1]) == 0)
+ fatal("%s is mounted on %s",
+ special, mp->f_mntonname);
+ ++mp;
+ }
+#endif
+ }
+#if 0
+ if (mfs && disktype != NULL) {
+ lp = (struct disklabel *)getdiskbyname(disktype);
+ if (lp == NULL)
+ fatal("%s: unknown disk type", disktype);
+ pp = &lp->d_partitions[1];
+ } else {
+ fsi = open(special, O_RDONLY);
+ if (fsi < 0)
+ fatal("%s: %s", special, strerror(errno));
+ if (fstat(fsi, &st) < 0)
+ fatal("%s: %s", special, strerror(errno));
+ if ((st.st_mode & S_IFMT) != S_IFCHR && !mfs)
+ printf("%s: %s: not a character-special device\n",
+ progname, special);
+ cp = index(argv[0], '\0') - 1;
+ if (cp == 0 || (*cp < 'a' || *cp > 'h') && !isdigit(*cp))
+ fatal("%s: can't figure out file system partition",
+ argv[0]);
+#ifdef COMPAT
+ if (!mfs && disktype == NULL)
+ disktype = argv[1];
+#endif
+ lp = getdisklabel(special, fsi);
+ if (isdigit(*cp))
+ pp = &lp->d_partitions[0];
+ else
+ pp = &lp->d_partitions[*cp - 'a'];
+ if (pp->p_size == 0)
+ fatal("%s: `%c' partition is unavailable",
+ argv[0], *cp);
+ if (pp->p_fstype == FS_BOOT)
+ fatal("%s: `%c' partition overlaps boot program",
+ argv[0], *cp);
+ }
+#endif
+ /* GNU Hurd specific here */
+ fsi = open (special, O_RDONLY);
+ if (fsi < 0)
+ fatal("%s: %s", special, strerror(errno));
+ if (fstat(fsi, &st) < 0)
+ fatal("%s: %s", special, strerror(errno));
+ fssize = st.st_size;
+ /* End GNU Hurd specific */
+
+ if (fssize == 0)
+ fssize = pp->p_size;
+ if (fssize > pp->p_size && !mfs)
+ fatal("%s: maximum file system size on the `%c' partition is %d",
+ argv[0], *cp, pp->p_size);
+ if (rpm == 0) {
+ rpm = lp->d_rpm;
+ if (rpm <= 0)
+ rpm = 3600;
+ }
+ if (ntracks == 0) {
+ ntracks = lp->d_ntracks;
+ if (ntracks <= 0)
+ fatal("%s: no default #tracks", argv[0]);
+ }
+ if (nsectors == 0) {
+ nsectors = lp->d_nsectors;
+ if (nsectors <= 0)
+ fatal("%s: no default #sectors/track", argv[0]);
+ }
+ if (sectorsize == 0) {
+ sectorsize = lp->d_secsize;
+ if (sectorsize <= 0)
+ fatal("%s: no default sector size", argv[0]);
+ }
+ if (trackskew == -1) {
+ trackskew = lp->d_trackskew;
+ if (trackskew < 0)
+ trackskew = 0;
+ }
+ if (interleave == 0) {
+ interleave = lp->d_interleave;
+ if (interleave <= 0)
+ interleave = 1;
+ }
+ if (fsize == 0) {
+ fsize = pp->p_fsize;
+ if (fsize <= 0)
+ fsize = MAX(DFL_FRAGSIZE, lp->d_secsize);
+ }
+ if (bsize == 0) {
+ bsize = pp->p_frag * pp->p_fsize;
+ if (bsize <= 0)
+ bsize = MIN(DFL_BLKSIZE, 8 * fsize);
+ }
+ /*
+ * Maxcontig sets the default for the maximum number of blocks
+ * that may be allocated sequentially. With filesystem clustering
+ * it is possible to allocate contiguous blocks up to the maximum
+ * transfer size permitted by the controller or buffering.
+ */
+ if (maxcontig == 0)
+ maxcontig = MAX(1, MIN(MAXPHYS, MAXBSIZE) / bsize - 1);
+ if (density == 0)
+ density = NFPI * fsize;
+ if (minfree < MINFREE && opt != FS_OPTSPACE) {
+ fprintf(stderr, "Warning: changing optimization to space ");
+ fprintf(stderr, "because minfree is less than %d%%\n", MINFREE);
+ opt = FS_OPTSPACE;
+ }
+ if (trackspares == -1) {
+ trackspares = lp->d_sparespertrack;
+ if (trackspares < 0)
+ trackspares = 0;
+ }
+ nphyssectors = nsectors + trackspares;
+ if (cylspares == -1) {
+ cylspares = lp->d_sparespercyl;
+ if (cylspares < 0)
+ cylspares = 0;
+ }
+ secpercyl = nsectors * ntracks - cylspares;
+ if (secpercyl != lp->d_secpercyl)
+ fprintf(stderr, "%s (%d) %s (%lu)\n",
+ "Warning: calculated sectors per cylinder", secpercyl,
+ "disagrees with disk label", lp->d_secpercyl);
+ if (maxbpg == 0)
+ maxbpg = MAXBLKPG(bsize);
+ headswitch = lp->d_headswitch;
+ trackseek = lp->d_trkseek;
+#ifdef notdef /* label may be 0 if faked up by kernel */
+ bbsize = lp->d_bbsize;
+ sbsize = lp->d_sbsize;
+#endif
+ oldpartition = *pp;
+#ifdef tahoe
+ realsectorsize = sectorsize;
+ if (sectorsize != DEV_BSIZE) { /* XXX */
+ int secperblk = DEV_BSIZE / sectorsize;
+
+ sectorsize = DEV_BSIZE;
+ nsectors /= secperblk;
+ nphyssectors /= secperblk;
+ secpercyl /= secperblk;
+ fssize /= secperblk;
+ pp->p_size /= secperblk;
+ }
+#endif
+ mkfs(pp, special, fsi, fso);
+#ifdef tahoe
+ if (realsectorsize != DEV_BSIZE)
+ pp->p_size *= DEV_BSIZE / realsectorsize;
+#endif
+ if (!Nflag && bcmp(pp, &oldpartition, sizeof(oldpartition)))
+ rewritelabel(special, fso, lp);
+ if (!Nflag)
+ close(fso);
+ close(fsi);
+#ifdef MFS
+ if (mfs) {
+ struct mfs_args args;
+
+ sprintf(buf, "mfs:%d", getpid());
+ args.fspec = buf;
+ args.export.ex_root = -2;
+ if (mntflags & MNT_RDONLY)
+ args.export.ex_flags = MNT_EXRDONLY;
+ else
+ args.export.ex_flags = 0;
+ args.base = membase;
+ args.size = fssize * sectorsize;
+ if (mount(MOUNT_MFS, argv[1], mntflags, &args) < 0)
+ fatal("%s: %s", argv[1], strerror(errno));
+ }
+#endif
+ exit(0);
+}
+
+#ifdef COMPAT
+char lmsg[] = "%s: can't read disk label; disk type must be specified";
+#else
+char lmsg[] = "%s: can't read disk label";
+#endif
+
+struct disklabel *
+getdisklabel(s, fd)
+ char *s;
+ int fd;
+{
+ static struct disklabel lab;
+
+ if (ioctl(fd, DIOCGDINFO, (char *)&lab) < 0) {
+#ifdef COMPAT
+ if (disktype) {
+ struct disklabel *lp, *getdiskbyname();
+
+ unlabeled++;
+ lp = getdiskbyname(disktype);
+ if (lp == NULL)
+ fatal("%s: unknown disk type", disktype);
+ return (lp);
+ }
+#endif
+ warn("ioctl (GDINFO)");
+ fatal(lmsg, s);
+ }
+ return (&lab);
+}
+
+rewritelabel(s, fd, lp)
+ char *s;
+ int fd;
+ register struct disklabel *lp;
+{
+#ifdef COMPAT
+ if (unlabeled)
+ return;
+#endif
+ lp->d_checksum = 0;
+ lp->d_checksum = dkcksum(lp);
+ if (ioctl(fd, DIOCWDINFO, (char *)lp) < 0) {
+ warn("ioctl (WDINFO)");
+ fatal("%s: can't rewrite disk label", s);
+ }
+#if vax
+ if (lp->d_type == DTYPE_SMD && lp->d_flags & D_BADSECT) {
+ register i;
+ int cfd;
+ daddr_t alt;
+ char specname[64];
+ char blk[1024];
+ char *cp;
+
+ /*
+ * Make name for 'c' partition.
+ */
+ strcpy(specname, s);
+ cp = specname + strlen(specname) - 1;
+ if (!isdigit(*cp))
+ *cp = 'c';
+ cfd = open(specname, O_WRONLY);
+ if (cfd < 0)
+ fatal("%s: %s", specname, strerror(errno));
+ bzero(blk, sizeof(blk));
+ *(struct disklabel *)(blk + LABELOFFSET) = *lp;
+ alt = lp->d_ncylinders * lp->d_secpercyl - lp->d_nsectors;
+ for (i = 1; i < 11 && i < lp->d_nsectors; i += 2) {
+ if (lseek(cfd, (off_t)(alt + i) * lp->d_secsize,
+ L_SET) == -1)
+ fatal("lseek to badsector area: %s",
+ strerror(errno));
+ if (write(cfd, blk, lp->d_secsize) < lp->d_secsize)
+ warn("alternate label %d write", i/2);
+ }
+ close(cfd);
+ }
+#endif
+}
+
+/*VARARGS*/
+void
+#if __STDC__
+fatal(const char *fmt, ...)
+#else
+fatal(fmt, va_alist)
+ char *fmt;
+ va_dcl
+#endif
+{
+ va_list ap;
+
+#if __STDC__
+ va_start(ap, fmt);
+#else
+ va_start(ap);
+#endif
+ if (fcntl(STDERR_FILENO, F_GETFL) < 0) {
+ openlog(progname, LOG_CONS, LOG_DAEMON);
+ vsyslog(LOG_ERR, fmt, ap);
+ closelog();
+ } else {
+ vwarnx(fmt, ap);
+ }
+ va_end(ap);
+ exit(1);
+ /*NOTREACHED*/
+}
+
+usage()
+{
+ if (mfs) {
+ fprintf(stderr,
+ "usage: %s [ -fsoptions ] special-device mount-point\n",
+ progname);
+ } else
+ fprintf(stderr,
+ "usage: %s [ -fsoptions ] special-device%s\n",
+ progname,
+#ifdef COMPAT
+ " [device-type]");
+#else
+ "");
+#endif
+ fprintf(stderr, "where fsoptions are:\n");
+ fprintf(stderr,
+ "\t-N do not create file system, just print out parameters\n");
+ fprintf(stderr, "\t-O create a 4.3BSD format filesystem\n");
+ fprintf(stderr, "\t-S sector size\n");
+#ifdef COMPAT
+ fprintf(stderr, "\t-T disktype\n");
+#endif
+ fprintf(stderr, "\t-a maximum contiguous blocks\n");
+ fprintf(stderr, "\t-b block size\n");
+ fprintf(stderr, "\t-c cylinders/group\n");
+ fprintf(stderr, "\t-d rotational delay between contiguous blocks\n");
+ fprintf(stderr, "\t-e maximum blocks per file in a cylinder group\n");
+ fprintf(stderr, "\t-f frag size\n");
+ fprintf(stderr, "\t-i number of bytes per inode\n");
+ fprintf(stderr, "\t-k sector 0 skew, per track\n");
+ fprintf(stderr, "\t-l hardware sector interleave\n");
+ fprintf(stderr, "\t-m minimum free space %%\n");
+ fprintf(stderr, "\t-n number of distinguished rotational positions\n");
+ fprintf(stderr, "\t-o optimization preference (`space' or `time')\n");
+ fprintf(stderr, "\t-p spare sectors per track\n");
+ fprintf(stderr, "\t-s file system size (sectors)\n");
+ fprintf(stderr, "\t-r revolutions/minute\n");
+ fprintf(stderr, "\t-t tracks/cylinder\n");
+ fprintf(stderr, "\t-u sectors/track\n");
+ fprintf(stderr, "\t-x spare sectors per cylinder\n");
+ exit(1);
+}
diff --git a/ufs-utils/stati.c b/ufs-utils/stati.c
new file mode 100644
index 00000000..ba545bf2
--- /dev/null
+++ b/ufs-utils/stati.c
@@ -0,0 +1,260 @@
+/*
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Rich $alz of BBN Inc.
+ *
+ * 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.
+ */
+
+#ifndef lint
+static char copyright[] =
+"@(#) Copyright (c) 1990, 1993\n\
+ The Regents of the University of California. All rights reserved.\n";
+
+static char copyright[] __attribute__ ((unused));
+#endif /* not lint */
+
+#ifndef lint
+static char sccsid[] = "@(#)clri.c 8.2 (Berkeley) 9/23/93";
+static char sccsid[] __attribute__ ((unused));
+#endif /* not lint */
+
+/* Modified by Michael I. Bushnell for GNU Hurd. */
+
+#include <sys/param.h>
+#include <sys/time.h>
+#include <sys/stat.h>
+
+#include "../ufs/dinode.h"
+#include "../ufs/fs.h"
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <time.h>
+#include <unistd.h>
+#include <pwd.h>
+#include <grp.h>
+
+#define MAXPHYS (64 * 1024)
+#define DEV_BSIZE 512
+
+/* Returns a nice representation of a file mode in a static buffer. */
+static char *
+mode_rep (unsigned short mode)
+{
+ static char buf[30];
+ char *p = buf;
+
+ void add_perms (int shift, unsigned sid_mask)
+ {
+ unsigned short smode = mode << shift;
+ *p++ = (smode & S_IREAD) ? 'r' : '-';
+ *p++ = (smode & S_IWRITE) ? 'w' : '-';
+ *p++ = (smode & S_IEXEC) ? ((mode & sid_mask) ? 's' : 'x') : '-';
+ }
+
+ switch (mode & S_IFMT)
+ {
+ case S_IFREG: *p++ = '-'; break;
+ case S_IFDIR: *p++ = 'd'; break;
+ case S_IFCHR: *p++ = 'c'; break;
+ case S_IFBLK: *p++ = 'b'; break;
+ case S_IFLNK: *p++ = 'l'; break;
+ case S_IFSOCK:*p++ = 'p'; break;
+ case S_IFIFO: *p++ = 'f'; break;
+ default: *p++ = '?';
+ }
+
+ add_perms (0, S_ISUID);
+ add_perms (3, S_ISGID);
+ add_perms (6, 0);
+
+ snprintf (p, buf + sizeof buf - p, " [0%0o]", mode);
+
+ return buf;
+}
+
+/* Returns a nice representation of a struct timespec in a static buffer. */
+static char *
+timespec_rep (struct timespec *ts)
+{
+ static char buf[200];
+ char *p = buf;
+ if (ts->tv_sec || ts->tv_nsec)
+ {
+ time_t time = ts->tv_sec;
+ strcpy (buf, ctime (&time));
+ p += strlen (buf);
+ if (p[-1] == '\n')
+ p--;
+ *p++ = ' ';
+ }
+ snprintf (p, buf + sizeof buf - p, "[%ld, %ld]", ts->tv_sec, ts->tv_nsec);
+ return buf;
+}
+
+/* Returns a nice representation of a uid in a static buffer. */
+static char *
+uid_rep (uid_t uid)
+{
+ static char buf[200];
+ struct passwd *pw = getpwuid (uid);
+ if (pw)
+ snprintf (buf, sizeof buf, "%d(%s)", uid, pw->pw_name);
+ else
+ snprintf (buf, sizeof buf, "%d", uid);
+ return buf;
+}
+
+/* Returns a nice representation of a gid in a static buffer. */
+static char *
+gid_rep (gid_t gid)
+{
+ static char buf[200];
+ struct group *gr = getgrgid (gid);
+ if (gr)
+ snprintf (buf, sizeof buf, "%d(%s)", gid, gr->gr_name);
+ else
+ snprintf (buf, sizeof buf, "%d", gid);
+ return buf;
+}
+
+int
+main(argc, argv)
+ int argc;
+ char *argv[];
+{
+ register struct fs *sbp;
+ register struct dinode *ip;
+ register int fd;
+ struct dinode ibuf[MAXBSIZE / sizeof (struct dinode)];
+ long bsize;
+ off_t offset;
+ int inonum;
+ char *fs, sblock[SBSIZE];
+
+ if (argc < 3) {
+ (void)fprintf(stderr, "usage: stati filesystem inode ...\n");
+ exit(1);
+ }
+
+ fs = *++argv;
+
+ /* get the superblock. */
+ if ((fd = open(fs, O_RDWR, 0)) < 0)
+ {
+ perror (fs);
+ exit (1);
+ }
+ if (lseek(fd, (off_t)(SBLOCK * DEV_BSIZE), SEEK_SET) < 0)
+ {
+ perror (fs);
+ exit (1);
+ }
+ if (read(fd, sblock, sizeof(sblock)) != sizeof(sblock)) {
+ (void)fprintf(stderr,
+ "stati: %s: can't read the superblock.\n", fs);
+ exit(1);
+ }
+
+ sbp = (struct fs *)sblock;
+ if (sbp->fs_magic != FS_MAGIC) {
+ (void)fprintf(stderr,
+ "stati: %s: superblock magic number 0x%lux, not 0x%x.\n",
+ fs, sbp->fs_magic, FS_MAGIC);
+ exit(1);
+ }
+ bsize = sbp->fs_bsize;
+
+ /* remaining arguments are inode numbers. */
+ while (*++argv) {
+ int i;
+
+ /* get the inode number. */
+ if ((inonum = atoi(*argv)) <= 0) {
+ (void)fprintf(stderr,
+ "stati: %s is not a valid inode number.\n", *argv);
+ exit(1);
+ }
+
+ /* read in the appropriate block. */
+ offset = ino_to_fsba(sbp, inonum); /* inode to fs blk */
+ offset = fsbtodb(sbp, offset); /* fs blk disk blk */
+ offset *= DEV_BSIZE; /* disk blk to bytes */
+
+ /* seek and read the block */
+ if (lseek(fd, offset, SEEK_SET) < 0)
+ {
+ perror (fs);
+ exit (1);
+ }
+ if (read(fd, ibuf, bsize) != bsize)
+ {
+ perror (fs);
+ exit (1);
+ }
+
+ /* get the inode within the block. */
+ ip = &ibuf[ino_to_fsbo(sbp, inonum)];
+
+ if (argc > 3)
+ printf ("inode: %d\n", inonum);
+
+ printf ("mode: %s\n", mode_rep (ip->di_model));
+ printf ("nlink: %d\n", ip->di_nlink);
+ printf ("size: %qd\n", ip->di_size);
+ printf ("atime: %s\n", timespec_rep (&ip->di_atime));
+ printf ("mtime: %s\n", timespec_rep (&ip->di_mtime));
+ printf ("ctime: %s\n", timespec_rep (&ip->di_ctime));
+ printf ("flags: %#lx\n", ip->di_flags);
+ printf ("blocks: %ld\n", ip->di_blocks);
+ printf ("gener: %ld\n", ip->di_gen);
+ printf ("uid: %s\n", uid_rep (ip->di_uid));
+ printf ("gid: %s\n", gid_rep (ip->di_gid));
+ printf ("dblks: ");
+ for (i = 0; i < NDADDR; i++)
+ printf ("%s%ld", (i == 0 ? "" : ", "), ip->di_db[i]);
+ putchar ('\n');
+ printf ("iblks: ");
+ for (i = 0; i < NIADDR; i++)
+ printf ("%s%ld", (i == 0 ? "" : ", "), ip->di_ib[i]);
+ putchar ('\n');
+ printf ("trans: %ld\n", ip->di_trans);
+
+ if (argv[1])
+ putchar ('\n');
+ }
+ (void)close(fd);
+ exit(0);
+}
diff --git a/ufs/Makefile b/ufs/Makefile
new file mode 100644
index 00000000..02cf38ba
--- /dev/null
+++ b/ufs/Makefile
@@ -0,0 +1,32 @@
+# Makefile for ufs
+#
+# Copyright (C) 1994,95,96,99,2000,02 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2, or (at
+# your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+dir := ufs
+makemode := server
+
+target = ufs
+SRCS = alloc.c consts.c dir.c hyper.c inode.c main.c pager.c \
+ sizes.c subr.c tables.c bmap.c pokeloc.c
+LCLHDRS = ufs.h fs.h dinode.h dir.h
+
+OBJS = $(SRCS:.c=.o)
+HURDLIBS = diskfs iohelp fshelp store pager threads ports ihash shouldbeinlibc
+
+include ../Makeconf
+
+ufs.static: $(boot-store-types:%=../libstore/libstore_%.a)
diff --git a/ufs/alloc.c b/ufs/alloc.c
new file mode 100644
index 00000000..d8f92255
--- /dev/null
+++ b/ufs/alloc.c
@@ -0,0 +1,1703 @@
+/* Disk allocation routines
+ Copyright (C) 1993,94,95,96,98,2002 Free Software Foundation, Inc.
+
+This file is part of the GNU Hurd.
+
+The GNU Hurd is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+The GNU Hurd is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with the GNU Hurd; see the file COPYING. If not, write to
+the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+/* Modified from UCB by Michael I. Bushnell. */
+/*
+ * Copyright (c) 1982, 1986, 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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.
+ *
+ * @(#)ffs_alloc.c 8.8 (Berkeley) 2/21/94
+ */
+
+#include "ufs.h"
+#include <stdio.h>
+#include <string.h>
+
+
+/* These don't work *at all* here; don't even try setting them. */
+#undef DIAGNOSTIC
+#undef QUOTA
+
+extern u_long nextgennumber;
+
+spin_lock_t alloclock = SPIN_LOCK_INITIALIZER;
+
+/* Forward declarations */
+static u_long ffs_hashalloc (struct node *, int, long, int,
+ u_long (*)(struct node *, int, daddr_t, int));
+static u_long ffs_alloccg (struct node *, int, daddr_t, int);
+static daddr_t ffs_fragextend (struct node *, int, long, int, int);
+static ino_t ffs_dirpref (struct fs *);
+static u_long ffs_nodealloccg (struct node *, int, daddr_t, int);
+static daddr_t ffs_alloccgblk (struct fs *, struct cg *, daddr_t);
+static daddr_t ffs_mapsearch (struct fs *, struct cg *, daddr_t, int);
+static void ffs_clusteracct (struct fs *, struct cg *, daddr_t, int);
+
+/* Sync all allocation information and nod eNP if diskfs_synchronous. */
+inline void
+alloc_sync (struct node *np)
+{
+ if (diskfs_synchronous)
+ {
+ if (np)
+ diskfs_node_update (np, 1);
+ copy_sblock ();
+ diskfs_set_hypermetadata (1, 0);
+ sync_disk (1);
+ }
+}
+
+/* Byteswap everything in CGP. */
+void
+swab_cg (struct cg *cg)
+{
+ int i, j;
+
+ if (swab_long (cg->cg_magic) == CG_MAGIC
+ || cg->cg_magic == CG_MAGIC)
+ {
+ cg->cg_magic = swab_long (cg->cg_magic);
+ cg->cg_time = swab_long (cg->cg_time);
+ cg->cg_cgx = swab_long (cg->cg_cgx);
+ cg->cg_ncyl = swab_short (cg->cg_ncyl);
+ cg->cg_niblk = swab_short (cg->cg_niblk);
+ cg->cg_cs.cs_ndir = swab_long (cg->cg_cs.cs_ndir);
+ cg->cg_cs.cs_nbfree = swab_long (cg->cg_cs.cs_nbfree);
+ cg->cg_cs.cs_nifree = swab_long (cg->cg_cs.cs_nifree);
+ cg->cg_cs.cs_nffree = swab_long (cg->cg_cs.cs_nffree);
+ cg->cg_rotor = swab_long (cg->cg_rotor);
+ cg->cg_irotor = swab_long (cg->cg_irotor);
+ for (i = 0; i < MAXFRAG; i++)
+ cg->cg_frsum[i] = swab_long (cg->cg_frsum[i]);
+ cg->cg_btotoff = swab_long (cg->cg_btotoff);
+ cg->cg_boff = swab_long (cg->cg_boff);
+ cg->cg_iusedoff = swab_long (cg->cg_iusedoff);
+ cg->cg_freeoff = swab_long (cg->cg_freeoff);
+ cg->cg_nextfreeoff = swab_long (cg->cg_nextfreeoff);
+ cg->cg_clustersumoff = swab_long (cg->cg_clustersumoff);
+ cg->cg_clusteroff = swab_long (cg->cg_clusteroff);
+ cg->cg_nclusterblks = swab_long (cg->cg_nclusterblks);
+
+ /* blktot map */
+ for (i = 0; i < cg->cg_ncyl; i++)
+ cg_blktot(cg)[i] = swab_long (cg_blktot(cg)[i]);
+
+ /* blks map */
+ for (i = 0; i < cg->cg_ncyl; i++)
+ for (j = 0; j < sblock->fs_nrpos; j++)
+ cg_blks(sblock, cg, i)[j] = swab_short (cg_blks (sblock, cg, i)[j]);
+
+ for (i = 0; i < sblock->fs_contigsumsize; i++)
+ cg_clustersum(cg)[i] = swab_long (cg_clustersum(cg)[i]);
+
+ /* inosused, blksfree, and cg_clustersfree are char arrays */
+ }
+ else
+ {
+ /* Old format cylinder group... */
+ struct ocg *ocg = (struct ocg *) cg;
+
+ if (swab_long (ocg->cg_magic) != CG_MAGIC
+ && ocg->cg_magic != CG_MAGIC)
+ return;
+
+ ocg->cg_time = swab_long (ocg->cg_time);
+ ocg->cg_cgx = swab_long (ocg->cg_cgx);
+ ocg->cg_ncyl = swab_short (ocg->cg_ncyl);
+ ocg->cg_niblk = swab_short (ocg->cg_niblk);
+ ocg->cg_ndblk = swab_long (ocg->cg_ndblk);
+ ocg->cg_cs.cs_ndir = swab_long (ocg->cg_cs.cs_ndir);
+ ocg->cg_cs.cs_nbfree = swab_long (ocg->cg_cs.cs_nbfree);
+ ocg->cg_cs.cs_nifree = swab_long (ocg->cg_cs.cs_nifree);
+ ocg->cg_cs.cs_nffree = swab_long (ocg->cg_cs.cs_nffree);
+ ocg->cg_rotor = swab_long (ocg->cg_rotor);
+ ocg->cg_frotor = swab_long (ocg->cg_frotor);
+ ocg->cg_irotor = swab_long (ocg->cg_irotor);
+ for (i = 0; i < 8; i++)
+ ocg->cg_frsum[i] = swab_long (ocg->cg_frsum[i]);
+ for (i = 0; i < 32; i++)
+ ocg->cg_btot[i] = swab_long (ocg->cg_btot[i]);
+ for (i = 0; i < 32; i++)
+ for (j = 0; j < 8; j++)
+ ocg->cg_b[i][j] = swab_short (ocg->cg_b[i][j]);
+ ocg->cg_magic = swab_long (ocg->cg_magic);
+ }
+}
+
+
+/* Read cylinder group indexed CG. Set *CGPP to point at it.
+ Return 1 if caller should call release_cgp when we're done with it;
+ otherwise zero. */
+int
+read_cg (int cg, struct cg **cgpp)
+{
+ struct cg *diskcg = cg_locate (cg);
+
+ if (swab_disk)
+ {
+ *cgpp = malloc (sblock->fs_cgsize);
+ bcopy (diskcg, *cgpp, sblock->fs_cgsize);
+ swab_cg (*cgpp);
+ return 1;
+ }
+ else
+ {
+ *cgpp = diskcg;
+ return 0;
+ }
+}
+
+/* Caller of read_cg is done with cg; write it back to disk (swapping it
+ along the way) and free the memory allocated in read_cg. */
+void
+release_cg (struct cg *cgp)
+{
+ int cgx = cgp->cg_cgx;
+ swab_cg (cgp);
+ bcopy (cgp, cg_locate (cgx), sblock->fs_cgsize);
+ free (cgp);
+}
+
+
+/*
+ * Allocate a block in the file system.
+ *
+ * The size of the requested block is given, which must be some
+ * multiple of fs_fsize and <= fs_bsize.
+ * A preference may be optionally specified. If a preference is given
+ * the following hierarchy is used to allocate a block:
+ * 1) allocate the requested block.
+ * 2) allocate a rotationally optimal block in the same cylinder.
+ * 3) allocate a block in the same cylinder group.
+ * 4) quadradically rehash into other cylinder groups, until an
+ * available block is located.
+ * If no block preference is given the following hierarchy is used
+ * to allocate a block:
+ * 1) allocate a block in the cylinder group that contains the
+ * inode for the file.
+ * 2) quadradically rehash into other cylinder groups, until an
+ * available block is located.
+ */
+error_t
+ffs_alloc(register struct node *np,
+ daddr_t lbn,
+ daddr_t bpref,
+ int size,
+ daddr_t *bnp,
+ struct protid *cred)
+{
+ register struct fs *fs;
+ daddr_t bno;
+ int cg;
+
+ *bnp = 0;
+ fs = sblock;
+#ifdef DIAGNOSTIC
+ if ((u_int)size > fs->fs_bsize || fragoff(fs, size) != 0) {
+ printf("dev = 0x%x, bsize = %d, size = %d, fs = %s\n",
+ ip->i_dev, fs->fs_bsize, size, fs->fs_fsmnt);
+ panic("ffs_alloc: bad size");
+ }
+ assert (cred);
+#endif /* DIAGNOSTIC */
+ spin_lock (&alloclock);
+ if (size == fs->fs_bsize && fs->fs_cstotal.cs_nbfree == 0)
+ goto nospace;
+ if (cred && !idvec_contains (cred->user->uids, 0)
+ && freespace(fs, fs->fs_minfree) <= 0)
+ goto nospace;
+#ifdef QUOTA
+ if (error = chkdq(ip, (long)btodb(size), cred, 0))
+ return (error);
+#endif
+ if (bpref >= fs->fs_size)
+ bpref = 0;
+ if (bpref == 0)
+ cg = ino_to_cg(fs, np->dn->number);
+ else
+ cg = dtog(fs, bpref);
+ bno = (daddr_t)ffs_hashalloc(np, cg, (long)bpref, size,
+ (u_long (*)())ffs_alloccg);
+ if (bno > 0) {
+ spin_unlock (&alloclock);
+ np->dn_stat.st_blocks += btodb(size);
+ np->dn_set_ctime = 1;
+ np->dn_set_mtime = 1;
+ *bnp = bno;
+ alloc_sync (np);
+ return (0);
+ }
+#ifdef QUOTA
+ /*
+ * Restore user's disk quota because allocation failed.
+ */
+ (void) chkdq(ip, (long)-btodb(size), cred, FORCE);
+#endif
+nospace:
+ spin_unlock (&alloclock);
+ printf ("file system full");
+/* ffs_fserr(fs, cred->cr_uid, "file system full"); */
+/* uprintf("\n%s: write failed, file system is full\n", fs->fs_fsmnt); */
+ return (ENOSPC);
+}
+
+/*
+ * Reallocate a fragment to a bigger size
+ *
+ * The number and size of the old block is given, and a preference
+ * and new size is also specified. The allocator attempts to extend
+ * the original block. Failing that, the regular block allocator is
+ * invoked to get an appropriate block.
+ */
+error_t
+ffs_realloccg(register struct node *np,
+ daddr_t lbprev,
+ volatile daddr_t bpref,
+ int osize,
+ int nsize,
+ daddr_t *pbn,
+ struct protid *cred)
+{
+ register struct fs *fs;
+ int cg, error;
+ volatile int request;
+ daddr_t bprev, bno;
+
+ *pbn = 0;
+ fs = sblock;
+#ifdef DIAGNOSTIC
+ if ((u_int)osize > fs->fs_bsize || fragoff(fs, osize) != 0 ||
+ (u_int)nsize > fs->fs_bsize || fragoff(fs, nsize) != 0) {
+ printf(
+ "dev = 0x%x, bsize = %d, osize = %d, nsize = %d, fs = %s\n",
+ ip->i_dev, fs->fs_bsize, osize, nsize, fs->fs_fsmnt);
+ panic("ffs_realloccg: bad size");
+ }
+ if (cred == NOCRED)
+ panic("ffs_realloccg: missing credential\n");
+#endif /* DIAGNOSTIC */
+
+ spin_lock (&alloclock);
+
+ if (!idvec_contains (cred->user->uids, 0)
+ && freespace(fs, fs->fs_minfree) <= 0)
+ goto nospace;
+ error = diskfs_catch_exception ();
+ if (error)
+ return error;
+ bprev = read_disk_entry ((dino (np->dn->number))->di_db[lbprev]);
+ diskfs_end_catch_exception ();
+ assert ("old block not allocated" && bprev);
+
+#if 0 /* Not needed in GNU Hurd ufs */
+ /*
+ * Allocate the extra space in the buffer.
+ */
+ if (error = bread(ITOV(ip), lbprev, osize, NOCRED, &bp)) {
+ brelse(bp);
+ return (error);
+ }
+#ifdef QUOTA
+ if (error = chkdq(ip, (long)btodb(nsize - osize), cred, 0)) {
+ brelse(bp);
+ return (error);
+ }
+#endif
+#endif /* 0 */
+
+ /*
+ * Check for extension in the existing location.
+ */
+ cg = dtog(fs, bprev);
+ bno = ffs_fragextend(np, cg, (long)bprev, osize, nsize);
+ if (bno) {
+ assert (bno == bprev);
+ spin_unlock (&alloclock);
+ np->dn_stat.st_blocks += btodb(nsize - osize);
+ np->dn_set_ctime = 1;
+ np->dn_set_mtime = 1;
+ *pbn = bno;
+#if 0 /* Not done this way in GNU Hurd ufs. */
+ allocbuf(bp, nsize);
+ bp->b_flags |= B_DONE;
+ bzero((char *)bp->b_data + osize, (u_int)nsize - osize);
+ *bpp = bp;
+#endif
+ alloc_sync (np);
+ return (0);
+ }
+ /*
+ * Allocate a new disk location.
+ */
+ if (bpref >= fs->fs_size)
+ bpref = 0;
+ switch ((int)fs->fs_optim) {
+ case FS_OPTSPACE:
+ /*
+ * Allocate an exact sized fragment. Although this makes
+ * best use of space, we will waste time relocating it if
+ * the file continues to grow. If the fragmentation is
+ * less than half of the minimum free reserve, we choose
+ * to begin optimizing for time.
+ */
+ request = nsize;
+ if (fs->fs_minfree < 5 ||
+ fs->fs_cstotal.cs_nffree >
+ fs->fs_dsize * fs->fs_minfree / (2 * 100))
+ break;
+ printf ("%s: optimization changed from SPACE to TIME\n",
+ fs->fs_fsmnt);
+ fs->fs_optim = FS_OPTTIME;
+ break;
+ case FS_OPTTIME:
+ /*
+ * At this point we have discovered a file that is trying to
+ * grow a small fragment to a larger fragment. To save time,
+ * we allocate a full sized block, then free the unused portion.
+ * If the file continues to grow, the `ffs_fragextend' call
+ * above will be able to grow it in place without further
+ * copying. If aberrant programs cause disk fragmentation to
+ * grow within 2% of the free reserve, we choose to begin
+ * optimizing for space.
+ */
+ request = fs->fs_bsize;
+ if (fs->fs_cstotal.cs_nffree <
+ fs->fs_dsize * (fs->fs_minfree - 2) / 100)
+ break;
+ printf ("%s: optimization changed from TIME to SPACE\n",
+ fs->fs_fsmnt);
+ fs->fs_optim = FS_OPTSPACE;
+ break;
+ default:
+ assert (0);
+ /* NOTREACHED */
+ }
+ bno = (daddr_t)ffs_hashalloc(np, cg, (long)bpref, request,
+ (u_long (*)())ffs_alloccg);
+ if (bno > 0) {
+#if 0 /* Not necessary in GNU Hurd ufs */
+ bp->b_blkno = fsbtodb(fs, bno);
+ (void) vnode_pager_uncache(ITOV(ip));
+#endif
+/* Commented out here for Hurd; we don't want to free this until we've
+ saved the old contents. Callers are responsible for freeing the
+ block when they are done with it. */
+/* ffs_blkfree(np, bprev, (long)osize); */
+ if (nsize < request)
+ ffs_blkfree(np, bno + numfrags(fs, nsize),
+ (long)(request - nsize));
+ spin_unlock (&alloclock);
+ np->dn_stat.st_blocks += btodb(nsize - osize);
+ np->dn_set_mtime = 1;
+ np->dn_set_ctime = 1;
+ *pbn = bno;
+#if 0 /* Not done this way in GNU Hurd ufs */
+ allocbuf(bp, nsize);
+ bp->b_flags |= B_DONE;
+ bzero((char *)bp->b_data + osize, (u_int)nsize - osize);
+ *bpp = bp;
+#endif /* 0 */
+ alloc_sync (np);
+ return (0);
+ }
+#ifdef QUOTA
+ /*
+ * Restore user's disk quota because allocation failed.
+ */
+ (void) chkdq(ip, (long)-btodb(nsize - osize), cred, FORCE);
+#endif
+#if 0 /* Not necesarry in GNU Hurd ufs */
+ brelse(bp);
+#endif
+nospace:
+ /*
+ * no space available
+ */
+ spin_unlock (&alloclock);
+ printf ("file system full");
+/* ffs_fserr(fs, cred->cr_uid, "file system full"); */
+/* uprintf("\n%s: write failed, file system is full\n", fs->fs_fsmnt); */
+ return (ENOSPC);
+}
+
+#if 0 /* Not used (yet?) in GNU Hurd ufs */
+/*
+ * Reallocate a sequence of blocks into a contiguous sequence of blocks.
+ *
+ * The vnode and an array of buffer pointers for a range of sequential
+ * logical blocks to be made contiguous is given. The allocator attempts
+ * to find a range of sequential blocks starting as close as possible to
+ * an fs_rotdelay offset from the end of the allocation for the logical
+ * block immediately preceding the current range. If successful, the
+ * physical block numbers in the buffer pointers and in the inode are
+ * changed to reflect the new allocation. If unsuccessful, the allocation
+ * is left unchanged. The success in doing the reallocation is returned.
+ * Note that the error return is not reflected back to the user. Rather
+ * the previous block allocation will be used.
+ */
+#include <sys/sysctl.h>
+int doasyncfree = 1;
+struct ctldebug debug14 = { "doasyncfree", &doasyncfree };
+int
+ffs_reallocblks(ap)
+ struct vop_reallocblks_args /* {
+ struct vnode *a_vp;
+ struct cluster_save *a_buflist;
+ } */ *ap;
+{
+ struct fs *fs;
+ struct inode *ip;
+ struct vnode *vp;
+ struct buf *sbp, *ebp;
+ daddr_t *bap, *sbap, *ebap;
+ struct cluster_save *buflist;
+ daddr_t start_lbn, end_lbn, soff, eoff, newblk, blkno;
+ struct indir start_ap[NIADDR + 1], end_ap[NIADDR + 1], *idp;
+ int i, len, start_lvl, end_lvl, pref, ssize;
+
+ vp = ap->a_vp;
+ ip = VTOI(vp);
+ fs = ip->i_fs;
+ if (fs->fs_contigsumsize <= 0)
+ return (ENOSPC);
+ buflist = ap->a_buflist;
+ len = buflist->bs_nchildren;
+ start_lbn = buflist->bs_children[0]->b_lblkno;
+ end_lbn = start_lbn + len - 1;
+#ifdef DIAGNOSTIC
+ for (i = 1; i < len; i++)
+ if (buflist->bs_children[i]->b_lblkno != start_lbn + i)
+ panic("ffs_reallocblks: non-cluster");
+#endif
+ /*
+ * If the latest allocation is in a new cylinder group, assume that
+ * the filesystem has decided to move and do not force it back to
+ * the previous cylinder group.
+ */
+ if (dtog(fs, dbtofsb(fs, buflist->bs_children[0]->b_blkno)) !=
+ dtog(fs, dbtofsb(fs, buflist->bs_children[len - 1]->b_blkno)))
+ return (ENOSPC);
+ if (ufs_getlbns(vp, start_lbn, start_ap, &start_lvl) ||
+ ufs_getlbns(vp, end_lbn, end_ap, &end_lvl))
+ return (ENOSPC);
+ /*
+ * Get the starting offset and block map for the first block.
+ */
+ if (start_lvl == 0) {
+ sbap = &ip->i_db[0];
+ soff = start_lbn;
+ } else {
+ idp = &start_ap[start_lvl - 1];
+ if (bread(vp, idp->in_lbn, (int)fs->fs_bsize, NOCRED, &sbp)) {
+ brelse(sbp);
+ return (ENOSPC);
+ }
+ sbap = (daddr_t *)sbp->b_data;
+ soff = idp->in_off;
+ }
+ /*
+ * Find the preferred location for the cluster.
+ */
+ pref = ffs_blkpref(ip, start_lbn, soff, sbap);
+ /*
+ * If the block range spans two block maps, get the second map.
+ */
+ if (end_lvl == 0 || (idp = &end_ap[end_lvl - 1])->in_off + 1 >= len) {
+ ssize = len;
+ } else {
+#ifdef DIAGNOSTIC
+ if (start_ap[start_lvl-1].in_lbn == idp->in_lbn)
+ panic("ffs_reallocblk: start == end");
+#endif
+ ssize = len - (idp->in_off + 1);
+ if (bread(vp, idp->in_lbn, (int)fs->fs_bsize, NOCRED, &ebp))
+ goto fail;
+ ebap = (daddr_t *)ebp->b_data;
+ }
+ /*
+ * Search the block map looking for an allocation of the desired size.
+ */
+ if ((newblk = (daddr_t)ffs_hashalloc(ip, dtog(fs, pref), (long)pref,
+ len, (u_long (*)())ffs_clusteralloc)) == 0)
+ goto fail;
+ /*
+ * We have found a new contiguous block.
+ *
+ * First we have to replace the old block pointers with the new
+ * block pointers in the inode and indirect blocks associated
+ * with the file.
+ */
+ blkno = newblk;
+ for (bap = &sbap[soff], i = 0; i < len; i++, blkno += fs->fs_frag) {
+ if (i == ssize)
+ bap = ebap;
+#ifdef DIAGNOSTIC
+ if (buflist->bs_children[i]->b_blkno != fsbtodb(fs, *bap))
+ panic("ffs_reallocblks: alloc mismatch");
+#endif
+ *bap++ = blkno;
+ }
+ /*
+ * Next we must write out the modified inode and indirect blocks.
+ * For strict correctness, the writes should be synchronous since
+ * the old block values may have been written to disk. In practise
+ * they are almost never written, but if we are concerned about
+ * strict correctness, the `doasyncfree' flag should be set to zero.
+ *
+ * The test on `doasyncfree' should be changed to test a flag
+ * that shows whether the associated buffers and inodes have
+ * been written. The flag should be set when the cluster is
+ * started and cleared whenever the buffer or inode is flushed.
+ * We can then check below to see if it is set, and do the
+ * synchronous write only when it has been cleared.
+ */
+ if (sbap != &ip->i_db[0]) {
+ if (doasyncfree)
+ bdwrite(sbp);
+ else
+ bwrite(sbp);
+ } else {
+ ip->i_flag |= IN_CHANGE | IN_UPDATE;
+ if (!doasyncfree)
+ VOP_UPDATE(vp, &time, &time, MNT_WAIT);
+ }
+ if (ssize < len)
+ if (doasyncfree)
+ bdwrite(ebp);
+ else
+ bwrite(ebp);
+ /*
+ * Last, free the old blocks and assign the new blocks to the buffers.
+ */
+ for (blkno = newblk, i = 0; i < len; i++, blkno += fs->fs_frag) {
+ ffs_blkfree(ip, dbtofsb(fs, buflist->bs_children[i]->b_blkno),
+ fs->fs_bsize);
+ buflist->bs_children[i]->b_blkno = fsbtodb(fs, blkno);
+ }
+ return (0);
+
+fail:
+ if (ssize < len)
+ brelse(ebp);
+ if (sbap != &ip->i_db[0])
+ brelse(sbp);
+ return (ENOSPC);
+}
+#endif /* 0 */
+
+/*
+ * Allocate an inode in the file system.
+ *
+ * If allocating a directory, use ffs_dirpref to select the inode.
+ * If allocating in a directory, the following hierarchy is followed:
+ * 1) allocate the preferred inode.
+ * 2) allocate an inode in the same cylinder group.
+ * 3) quadradically rehash into other cylinder groups, until an
+ * available inode is located.
+ * If no inode preference is given the following hierarchy is used
+ * to allocate an inode:
+ * 1) allocate an inode in cylinder group 0.
+ * 2) quadradically rehash into other cylinder groups, until an
+ * available inode is located.
+ */
+/* This is now the diskfs_alloc_node callback from the diskfs library
+ (described in <hurd/diskfs.h>). It used to be ffs_valloc in BSD. */
+error_t
+diskfs_alloc_node (struct node *dir,
+ mode_t mode,
+ struct node **npp)
+{
+ register struct fs *fs;
+ struct node *np;
+ ino_t ino, ipref;
+ int cg, error;
+ int sex;
+
+ fs = sblock;
+
+
+ spin_lock (&alloclock);
+
+ if (fs->fs_cstotal.cs_nifree == 0)
+ {
+ spin_unlock (&alloclock);
+ goto noinodes;
+ }
+
+ if (S_ISDIR (mode))
+ ipref = ffs_dirpref(fs);
+ else
+ ipref = dir->dn->number;
+
+ if (ipref >= fs->fs_ncg * fs->fs_ipg)
+ ipref = 0;
+ cg = ino_to_cg(fs, ipref);
+ ino = (ino_t)ffs_hashalloc(dir, cg, (long)ipref,
+ mode, ffs_nodealloccg);
+ spin_unlock (&alloclock);
+ if (ino == 0)
+ goto noinodes;
+ error = diskfs_cached_lookup (ino, &np);
+ assert ("duplicate allocation" && !np->dn_stat.st_mode);
+ assert (! (np->dn_stat.st_mode & S_IPTRANS));
+ if (np->dn_stat.st_blocks) {
+ printf("free inode %Ld had %Ld blocks\n",
+ ino, np->dn_stat.st_blocks);
+ np->dn_stat.st_blocks = 0;
+ np->dn_set_ctime = 1;
+ }
+ np->dn_stat.st_flags = 0;
+ /*
+ * Set up a new generation number for this inode.
+ */
+ spin_lock (&gennumberlock);
+ sex = diskfs_mtime->seconds;
+ if (++nextgennumber < (u_long)sex)
+ nextgennumber = sex;
+ np->dn_stat.st_gen = nextgennumber;
+ spin_unlock (&gennumberlock);
+
+ *npp = np;
+ alloc_sync (np);
+ return (0);
+noinodes:
+ printf ("out of inodes");
+/* ffs_fserr(fs, ap->a_cred->cr_uid, "out of inodes"); */
+/* uprintf("\n%s: create/symlink failed, no inodes free\n", fs->fs_fsmnt);*/
+ return (ENOSPC);
+}
+
+/*
+ * Find a cylinder to place a directory.
+ *
+ * The policy implemented by this algorithm is to select from
+ * among those cylinder groups with above the average number of
+ * free inodes, the one with the smallest number of directories.
+ */
+static ino_t
+ffs_dirpref(register struct fs *fs)
+{
+ int cg, minndir, mincg, avgifree;
+
+ avgifree = fs->fs_cstotal.cs_nifree / fs->fs_ncg;
+ minndir = fs->fs_ipg;
+ mincg = 0;
+ for (cg = 0; cg < fs->fs_ncg; cg++)
+ if (csum[cg].cs_ndir < minndir &&
+ csum[cg].cs_nifree >= avgifree) {
+ mincg = cg;
+ minndir = csum[cg].cs_ndir;
+ }
+ return ((ino_t)(fs->fs_ipg * mincg));
+}
+
+/*
+ * Select the desired position for the next block in a file. The file is
+ * logically divided into sections. The first section is composed of the
+ * direct blocks. Each additional section contains fs_maxbpg blocks.
+ *
+ * If no blocks have been allocated in the first section, the policy is to
+ * request a block in the same cylinder group as the inode that describes
+ * the file. If no blocks have been allocated in any other section, the
+ * policy is to place the section in a cylinder group with a greater than
+ * average number of free blocks. An appropriate cylinder group is found
+ * by using a rotor that sweeps the cylinder groups. When a new group of
+ * blocks is needed, the sweep begins in the cylinder group following the
+ * cylinder group from which the previous allocation was made. The sweep
+ * continues until a cylinder group with greater than the average number
+ * of free blocks is found. If the allocation is for the first block in an
+ * indirect block, the information on the previous allocation is unavailable;
+ * here a best guess is made based upon the logical block number being
+ * allocated.
+ *
+ * If a section is already partially allocated, the policy is to
+ * contiguously allocate fs_maxcontig blocks. The end of one of these
+ * contiguous blocks and the beginning of the next is physically separated
+ * so that the disk head will be in transit between them for at least
+ * fs_rotdelay milliseconds. This is to allow time for the processor to
+ * schedule another I/O transfer.
+ */
+daddr_t
+ffs_blkpref(struct node *np,
+ daddr_t lbn,
+ int indx,
+ daddr_t *bap)
+{
+ register struct fs *fs;
+ register int cg;
+ int avgbfree, startcg;
+ daddr_t nextblk;
+
+ fs = sblock;
+ spin_lock (&alloclock);
+ if (indx % fs->fs_maxbpg == 0 || bap[indx - 1] == 0) {
+ if (lbn < NDADDR) {
+ cg = ino_to_cg(fs, np->dn->number);
+ spin_unlock (&alloclock);
+ return (fs->fs_fpg * cg + fs->fs_frag);
+ }
+ /*
+ * Find a cylinder with greater than average number of
+ * unused data blocks.
+ */
+ if (indx == 0 || bap[indx - 1] == 0)
+ startcg =
+ (ino_to_cg(fs, np->dn->number)
+ + lbn / fs->fs_maxbpg);
+ else
+ startcg = dtog(fs,
+ read_disk_entry (bap[indx - 1])) + 1;
+ startcg %= fs->fs_ncg;
+ avgbfree = fs->fs_cstotal.cs_nbfree / fs->fs_ncg;
+ for (cg = startcg; cg < fs->fs_ncg; cg++)
+ if (csum[cg].cs_nbfree >= avgbfree) {
+ fs->fs_cgrotor = cg;
+ spin_unlock (&alloclock);
+ return (fs->fs_fpg * cg + fs->fs_frag);
+ }
+ for (cg = 0; cg <= startcg; cg++)
+ if (csum[cg].cs_nbfree >= avgbfree) {
+ fs->fs_cgrotor = cg;
+ spin_unlock (&alloclock);
+ return (fs->fs_fpg * cg + fs->fs_frag);
+ }
+ spin_unlock (&alloclock);
+ return 0;
+ }
+ spin_unlock (&alloclock);
+ /*
+ * One or more previous blocks have been laid out. If less
+ * than fs_maxcontig previous blocks are contiguous, the
+ * next block is requested contiguously, otherwise it is
+ * requested rotationally delayed by fs_rotdelay milliseconds.
+ */
+ nextblk = read_disk_entry (bap[indx - 1]) + fs->fs_frag;
+ if (indx < fs->fs_maxcontig
+ || (read_disk_entry (bap[indx - fs->fs_maxcontig]) +
+ blkstofrags(fs, fs->fs_maxcontig) != nextblk))
+ {
+ return (nextblk);
+ }
+ if (fs->fs_rotdelay != 0)
+ /*
+ * Here we convert ms of delay to frags as:
+ * (frags) = (ms) * (rev/sec) * (sect/rev) /
+ * ((sect/frag) * (ms/sec))
+ * then round up to the next block.
+ */
+ nextblk += roundup(fs->fs_rotdelay * fs->fs_rps * fs->fs_nsect /
+ (NSPF(fs) * 1000), fs->fs_frag);
+ return (nextblk);
+}
+
+/*
+ * Implement the cylinder overflow algorithm.
+ *
+ * The policy implemented by this algorithm is:
+ * 1) allocate the block in its requested cylinder group.
+ * 2) quadradically rehash on the cylinder group number.
+ * 3) brute force search for a free block.
+ */
+/*VARARGS5*/
+static u_long
+ffs_hashalloc(struct node *np,
+ int cg,
+ long pref,
+ int size, /* size for data blocks, mode for inodes */
+ u_long (*allocator)())
+{
+ register struct fs *fs;
+ long result;
+ int i, icg = cg;
+
+ fs = sblock;
+ /*
+ * 1: preferred cylinder group
+ */
+ result = (*allocator)(np, cg, pref, size);
+ if (result)
+ return (result);
+ /*
+ * 2: quadratic rehash
+ */
+ for (i = 1; i < fs->fs_ncg; i *= 2) {
+ cg += i;
+ if (cg >= fs->fs_ncg)
+ cg -= fs->fs_ncg;
+ result = (*allocator)(np, cg, 0, size);
+ if (result)
+ return (result);
+ }
+ /*
+ * 3: brute force search
+ * Note that we start at i == 2, since 0 was checked initially,
+ * and 1 is always checked in the quadratic rehash.
+ */
+ cg = (icg + 2) % fs->fs_ncg;
+ for (i = 2; i < fs->fs_ncg; i++) {
+ result = (*allocator)(np, cg, 0, size);
+ if (result)
+ return (result);
+ cg++;
+ if (cg == fs->fs_ncg)
+ cg = 0;
+ }
+ return 0;
+}
+
+/*
+ * Determine whether a fragment can be extended.
+ *
+ * Check to see if the necessary fragments are available, and
+ * if they are, allocate them.
+ */
+static daddr_t
+ffs_fragextend(struct node *np,
+ int cg,
+ long bprev,
+ int osize,
+ int nsize)
+{
+ register struct fs *fs;
+ struct cg *cgp;
+ long bno;
+ int frags, bbase;
+ int i;
+ int releasecg;
+
+ fs = sblock;
+ if (csum[cg].cs_nffree < numfrags(fs, nsize - osize))
+ return 0;
+ frags = numfrags(fs, nsize);
+ bbase = fragnum(fs, bprev);
+ if (bbase > fragnum(fs, (bprev + frags - 1))) {
+ /* cannot extend across a block boundary */
+ return 0;
+ }
+#if 0 /* Wrong for GNU Hurd ufs */
+ error = bread(ip->i_devvp, fsbtodb(fs, cgtod(fs, cg)),
+ (int)fs->fs_cgsize, NOCRED, &bp);
+ if (error) {
+ brelse(bp);
+ return (NULL);
+ }
+ cgp = (struct cg *)bp->b_data;
+#else
+ releasecg = read_cg (cg, &cgp);
+#endif
+ if (!cg_chkmagic(cgp)) {
+/* brelse(bp); */
+ if (releasecg)
+ release_cg (cgp);
+ return 0;
+ }
+ cgp->cg_time = diskfs_mtime->seconds;
+ bno = dtogd(fs, bprev);
+ for (i = numfrags(fs, osize); i < frags; i++)
+ if (isclr(cg_blksfree(cgp), bno + i)) {
+/* brelse(bp); */
+ if (releasecg)
+ release_cg (cgp);
+ return 0;
+ }
+ /*
+ * the current fragment can be extended
+ * deduct the count on fragment being extended into
+ * increase the count on the remaining fragment (if any)
+ * allocate the extended piece
+ */
+ for (i = frags; i < fs->fs_frag - bbase; i++)
+ if (isclr(cg_blksfree(cgp), bno + i))
+ break;
+ cgp->cg_frsum[i - numfrags(fs, osize)]--;
+ if (i != frags)
+ cgp->cg_frsum[i - frags]++;
+ for (i = numfrags(fs, osize); i < frags; i++) {
+ clrbit(cg_blksfree(cgp), bno + i);
+ cgp->cg_cs.cs_nffree--;
+ fs->fs_cstotal.cs_nffree--;
+ csum[cg].cs_nffree--;
+ }
+ if (releasecg)
+ release_cg (cgp);
+ record_poke (cgp, sblock->fs_cgsize);
+ csum_dirty = 1;
+ sblock_dirty = 1;
+ fs->fs_fmod = 1;
+/* bdwrite(bp); */
+ return (bprev);
+}
+
+/*
+ * Determine whether a block can be allocated.
+ *
+ * Check to see if a block of the appropriate size is available,
+ * and if it is, allocate it.
+ */
+static u_long
+ffs_alloccg(struct node *np,
+ int cg,
+ daddr_t bpref,
+ int size)
+{
+ register struct fs *fs;
+ struct cg *cgp;
+ register int i;
+ int bno, frags, allocsiz;
+ int releasecg;
+
+ fs = sblock;
+ if (csum[cg].cs_nbfree == 0 && size == fs->fs_bsize)
+ return 0;
+#if 0 /* Not this way in GNU Hurd ufs */
+ error = bread(ip->i_devvp, fsbtodb(fs, cgtod(fs, cg)),
+ (int)fs->fs_cgsize, NOCRED, &bp);
+ if (error) {
+ brelse(bp);
+ return (NULL);
+ }
+ cgp = (struct cg *)bp->b_data;
+#else
+ releasecg = read_cg (cg, &cgp);
+#endif
+ if (!cg_chkmagic(cgp) ||
+ (cgp->cg_cs.cs_nbfree == 0 && size == fs->fs_bsize)) {
+/* brelse(bp); */
+ if (releasecg)
+ release_cg (cgp);
+ return 0;
+ }
+ cgp->cg_time = diskfs_mtime->seconds;
+ if (size == fs->fs_bsize) {
+ bno = ffs_alloccgblk(fs, cgp, bpref);
+/* bdwrite(bp); */
+ if (releasecg)
+ release_cg (cgp);
+ return (bno);
+ }
+ /*
+ * check to see if any fragments are already available
+ * allocsiz is the size which will be allocated, hacking
+ * it down to a smaller size if necessary
+ */
+ frags = numfrags(fs, size);
+ for (allocsiz = frags; allocsiz < fs->fs_frag; allocsiz++)
+ if (cgp->cg_frsum[allocsiz] != 0)
+ break;
+ if (allocsiz == fs->fs_frag) {
+ /*
+ * no fragments were available, so a block will be
+ * allocated, and hacked up
+ */
+ if (cgp->cg_cs.cs_nbfree == 0) {
+/* brelse(bp); */
+ if (releasecg)
+ release_cg (cgp);
+ return 0;
+ }
+ bno = ffs_alloccgblk(fs, cgp, bpref);
+ bpref = dtogd(fs, bno);
+ for (i = frags; i < fs->fs_frag; i++)
+ setbit(cg_blksfree(cgp), bpref + i);
+ i = fs->fs_frag - frags;
+ cgp->cg_cs.cs_nffree += i;
+ fs->fs_cstotal.cs_nffree += i;
+ csum[cg].cs_nffree += i;
+ fs->fs_fmod = 1;
+ cgp->cg_frsum[i]++;
+
+ if (releasecg)
+ release_cg (cgp);
+ record_poke (cgp, sblock->fs_cgsize);
+ csum_dirty = 1;
+ sblock_dirty = 1;
+/* bdwrite(bp); */
+ return (bno);
+ }
+ bno = ffs_mapsearch(fs, cgp, bpref, allocsiz);
+ if (bno < 0) {
+/* brelse(bp); */
+ if (releasecg)
+ release_cg (cgp);
+ return 0;
+ }
+ for (i = 0; i < frags; i++)
+ clrbit(cg_blksfree(cgp), bno + i);
+ cgp->cg_cs.cs_nffree -= frags;
+ fs->fs_cstotal.cs_nffree -= frags;
+ csum[cg].cs_nffree -= frags;
+ fs->fs_fmod = 1;
+ cgp->cg_frsum[allocsiz]--;
+ if (frags != allocsiz)
+ cgp->cg_frsum[allocsiz - frags]++;
+ if (releasecg)
+ release_cg (cgp);
+ record_poke (cgp, sblock->fs_cgsize);
+ csum_dirty = 1;
+ sblock_dirty = 1;
+/* bdwrite(bp); */
+ return (cg * fs->fs_fpg + bno);
+}
+
+/*
+ * Allocate a block in a cylinder group.
+ *
+ * This algorithm implements the following policy:
+ * 1) allocate the requested block.
+ * 2) allocate a rotationally optimal block in the same cylinder.
+ * 3) allocate the next available block on the block rotor for the
+ * specified cylinder group.
+ * Note that this routine only allocates fs_bsize blocks; these
+ * blocks may be fragmented by the routine that allocates them.
+ */
+static daddr_t
+ffs_alloccgblk(register struct fs *fs,
+ register struct cg *cgp,
+ daddr_t bpref)
+{
+ daddr_t bno, blkno;
+ int cylno, pos, delta;
+ short *cylbp;
+ register int i;
+
+ if (bpref == 0 || dtog(fs, bpref) != cgp->cg_cgx) {
+ bpref = cgp->cg_rotor;
+ goto norot;
+ }
+ bpref = blknum(fs, bpref);
+ bpref = dtogd(fs, bpref);
+ /*
+ * if the requested block is available, use it
+ */
+ if (ffs_isblock(fs, cg_blksfree(cgp), fragstoblks(fs, bpref))) {
+ bno = bpref;
+ goto gotit;
+ }
+ /*
+ * check for a block available on the same cylinder
+ */
+ cylno = cbtocylno(fs, bpref);
+ if (cg_blktot(cgp)[cylno] == 0)
+ goto norot;
+ if (fs->fs_cpc == 0) {
+ /*
+ * Block layout information is not available.
+ * Leaving bpref unchanged means we take the
+ * next available free block following the one
+ * we just allocated. Hopefully this will at
+ * least hit a track cache on drives of unknown
+ * geometry (e.g. SCSI).
+ */
+ goto norot;
+ }
+ /*
+ * check the summary information to see if a block is
+ * available in the requested cylinder starting at the
+ * requested rotational position and proceeding around.
+ */
+ cylbp = cg_blks(fs, cgp, cylno);
+ pos = cbtorpos(fs, bpref);
+ for (i = pos; i < fs->fs_nrpos; i++)
+ if (cylbp[i] > 0)
+ break;
+ if (i == fs->fs_nrpos)
+ for (i = 0; i < pos; i++)
+ if (cylbp[i] > 0)
+ break;
+ if (cylbp[i] > 0) {
+ /*
+ * found a rotational position, now find the actual
+ * block. A panic if none is actually there.
+ */
+ pos = cylno % fs->fs_cpc;
+ bno = (cylno - pos) * fs->fs_spc / NSPB(fs);
+ assert (fs_postbl(fs, pos)[i] != -1);
+ for (i = fs_postbl(fs, pos)[i];; ) {
+ if (ffs_isblock(fs, cg_blksfree(cgp), bno + i)) {
+ bno = blkstofrags(fs, (bno + i));
+ goto gotit;
+ }
+ delta = fs_rotbl(fs)[i];
+ if (delta <= 0 ||
+ delta + i > fragstoblks(fs, fs->fs_fpg))
+ break;
+ i += delta;
+ }
+ printf("pos = %d, i = %d, fs = %s\n", pos, i, fs->fs_fsmnt);
+ assert (0);
+ }
+norot:
+ /*
+ * no blocks in the requested cylinder, so take next
+ * available one in this cylinder group.
+ */
+ bno = ffs_mapsearch(fs, cgp, bpref, (int)fs->fs_frag);
+ if (bno < 0)
+ return 0;
+ cgp->cg_rotor = bno;
+gotit:
+ blkno = fragstoblks(fs, bno);
+ ffs_clrblock(fs, cg_blksfree(cgp), (long)blkno);
+ ffs_clusteracct(fs, cgp, blkno, -1);
+ cgp->cg_cs.cs_nbfree--;
+ fs->fs_cstotal.cs_nbfree--;
+ csum[cgp->cg_cgx].cs_nbfree--;
+ cylno = cbtocylno(fs, bno);
+ cg_blks(fs, cgp, cylno)[cbtorpos(fs, bno)]--;
+ cg_blktot(cgp)[cylno]--;
+ fs->fs_fmod = 1;
+ record_poke (cgp, sblock->fs_cgsize);
+ csum_dirty = 1;
+ sblock_dirty = 1;
+ return (cgp->cg_cgx * fs->fs_fpg + bno);
+}
+
+#if 0 /* Not needed in GNU Hurd ufs (yet?) */
+/*
+ * Determine whether a cluster can be allocated.
+ *
+ * We do not currently check for optimal rotational layout if there
+ * are multiple choices in the same cylinder group. Instead we just
+ * take the first one that we find following bpref.
+ */
+static daddr_t
+ffs_clusteralloc(ip, cg, bpref, len)
+ struct inode *ip;
+ int cg;
+ daddr_t bpref;
+ int len;
+{
+ register struct fs *fs;
+ register struct cg *cgp;
+ struct buf *bp;
+ int i, run, bno, bit, map;
+ u_char *mapp;
+
+ fs = ip->i_fs;
+ if (fs->fs_cs(fs, cg).cs_nbfree < len)
+ return (NULL);
+ if (bread(ip->i_devvp, fsbtodb(fs, cgtod(fs, cg)), (int)fs->fs_cgsize,
+ NOCRED, &bp))
+ goto fail;
+ cgp = (struct cg *)bp->b_data;
+ if (!cg_chkmagic(cgp))
+ goto fail;
+ /*
+ * Check to see if a cluster of the needed size (or bigger) is
+ * available in this cylinder group.
+ */
+ for (i = len; i <= fs->fs_contigsumsize; i++)
+ if (cg_clustersum(cgp)[i] > 0)
+ break;
+ if (i > fs->fs_contigsumsize)
+ goto fail;
+ /*
+ * Search the cluster map to find a big enough cluster.
+ * We take the first one that we find, even if it is larger
+ * than we need as we prefer to get one close to the previous
+ * block allocation. We do not search before the current
+ * preference point as we do not want to allocate a block
+ * that is allocated before the previous one (as we will
+ * then have to wait for another pass of the elevator
+ * algorithm before it will be read). We prefer to fail and
+ * be recalled to try an allocation in the next cylinder group.
+ */
+ if (dtog(fs, bpref) != cg)
+ bpref = 0;
+ else
+ bpref = fragstoblks(fs, dtogd(fs, blknum(fs, bpref)));
+ mapp = &cg_clustersfree(cgp)[bpref / NBBY];
+ map = *mapp++;
+ bit = 1 << (bpref % NBBY);
+ for (run = 0, i = bpref; i < cgp->cg_nclusterblks; i++) {
+ if ((map & bit) == 0) {
+ run = 0;
+ } else {
+ run++;
+ if (run == len)
+ break;
+ }
+ if ((i & (NBBY - 1)) != (NBBY - 1)) {
+ bit <<= 1;
+ } else {
+ map = *mapp++;
+ bit = 1;
+ }
+ }
+ if (i == cgp->cg_nclusterblks)
+ goto fail;
+ /*
+ * Allocate the cluster that we have found.
+ */
+ bno = cg * fs->fs_fpg + blkstofrags(fs, i - run + 1);
+ len = blkstofrags(fs, len);
+ for (i = 0; i < len; i += fs->fs_frag)
+ if (ffs_alloccgblk(fs, cgp, bno + i) != bno + i)
+ panic("ffs_clusteralloc: lost block");
+ brelse(bp);
+ return (bno);
+
+fail:
+ brelse(bp);
+ return (0);
+}
+#endif
+
+/*
+ * Determine whether an inode can be allocated.
+ *
+ * Check to see if an inode is available, and if it is,
+ * allocate it using the following policy:
+ * 1) allocate the requested inode.
+ * 2) allocate the next available inode after the requested
+ * inode in the specified cylinder group.
+ */
+static u_long
+ffs_nodealloccg(struct node *np,
+ int cg,
+ daddr_t ipref,
+ int mode)
+{
+ register struct fs *fs;
+ struct cg *cgp;
+ int start, len, loc, map, i;
+ int releasecg;
+
+ fs = sblock;
+ if (csum[cg].cs_nifree == 0)
+ return 0;
+#if 0 /* Not this way in GNU Hurd ufs */
+ error = bread(ip->i_devvp, fsbtodb(fs, cgtod(fs, cg)),
+ (int)fs->fs_cgsize, NOCRED, &bp);
+ if (error) {
+ brelse(bp);
+ return (NULL);
+ }
+ cgp = (struct cg *)bp->b_data;
+#else
+ releasecg = read_cg (cg, &cgp);
+#endif
+ if (!cg_chkmagic(cgp) || cgp->cg_cs.cs_nifree == 0) {
+/* brelse(bp); */
+ if (releasecg)
+ release_cg (cgp);
+ return 0;
+ }
+ cgp->cg_time = diskfs_mtime->seconds;
+ if (ipref) {
+ ipref %= fs->fs_ipg;
+ if (isclr(cg_inosused(cgp), ipref))
+ goto gotit;
+ }
+ start = cgp->cg_irotor / NBBY;
+ len = howmany(fs->fs_ipg - cgp->cg_irotor, NBBY);
+ loc = skpc(0xff, len, &cg_inosused(cgp)[start]);
+ if (loc == 0) {
+ len = start + 1;
+ start = 0;
+ loc = skpc(0xff, len, &cg_inosused(cgp)[0]);
+ assert (loc != 0);
+ }
+ i = start + len - loc;
+ map = cg_inosused(cgp)[i];
+ ipref = i * NBBY;
+ for (i = 1; i < (1 << NBBY); i <<= 1, ipref++) {
+ if ((map & i) == 0) {
+ cgp->cg_irotor = ipref;
+ goto gotit;
+ }
+ }
+ assert (0);
+ /* NOTREACHED */
+gotit:
+ setbit(cg_inosused(cgp), ipref);
+ cgp->cg_cs.cs_nifree--;
+ fs->fs_cstotal.cs_nifree--;
+ csum[cg].cs_nifree--;
+ fs->fs_fmod = 1;
+ if ((mode & IFMT) == IFDIR) {
+ cgp->cg_cs.cs_ndir++;
+ fs->fs_cstotal.cs_ndir++;
+ csum[cg].cs_ndir++;
+ }
+ if (releasecg)
+ release_cg (cgp);
+ record_poke (cgp, sblock->fs_cgsize);
+ csum_dirty = 1;
+ sblock_dirty = 1;
+/* bdwrite(bp); */
+ return (cg * fs->fs_ipg + ipref);
+}
+
+/*
+ * Free a block or fragment.
+ *
+ * The specified block or fragment is placed back in the
+ * free map. If a fragment is deallocated, a possible
+ * block reassembly is checked.
+ */
+void
+ffs_blkfree(register struct node *np,
+ daddr_t bno,
+ long size)
+{
+ register struct fs *fs;
+ struct cg *cgp;
+ daddr_t blkno;
+ int i, cg, blk, frags, bbase;
+ int releasecg;
+
+ fs = sblock;
+ assert ((u_int)size <= fs->fs_bsize && !fragoff (fs, size));
+ cg = dtog(fs, bno);
+ if ((u_int)bno >= fs->fs_size) {
+ printf("bad block %ld, ino %Ld\n", bno, np->dn->number);
+/* ffs_fserr(fs, ip->i_uid, "bad block"); */
+ return;
+ }
+#if 0 /* Not this way in GNU Hurd ufs */
+ error = bread(ip->i_devvp, fsbtodb(fs, cgtod(fs, cg)),
+ (int)fs->fs_cgsize, NOCRED, &bp);
+ if (error) {
+ brelse(bp);
+ return;
+ }
+ cgp = (struct cg *)bp->b_data;
+#else
+ releasecg = read_cg (cg, &cgp);
+#endif
+ if (!cg_chkmagic(cgp)) {
+/* brelse(bp); */
+ if (releasecg)
+ release_cg (cgp);
+ return;
+ }
+ cgp->cg_time = diskfs_mtime->seconds;
+ bno = dtogd(fs, bno);
+ if (size == fs->fs_bsize) {
+ blkno = fragstoblks(fs, bno);
+ assert (!ffs_isblock(fs, cg_blksfree (cgp), blkno));
+ ffs_setblock(fs, cg_blksfree(cgp), blkno);
+ ffs_clusteracct(fs, cgp, blkno, 1);
+ cgp->cg_cs.cs_nbfree++;
+ fs->fs_cstotal.cs_nbfree++;
+ csum[cg].cs_nbfree++;
+ i = cbtocylno(fs, bno);
+ cg_blks(fs, cgp, i)[cbtorpos(fs, bno)]++;
+ cg_blktot(cgp)[i]++;
+ } else {
+ bbase = bno - fragnum(fs, bno);
+ /*
+ * decrement the counts associated with the old frags
+ */
+ blk = blkmap(fs, cg_blksfree(cgp), bbase);
+ ffs_fragacct(fs, blk, cgp->cg_frsum, -1);
+ /*
+ * deallocate the fragment
+ */
+ frags = numfrags(fs, size);
+ for (i = 0; i < frags; i++) {
+ assert (!isset (cg_blksfree(cgp), bno + i));
+ setbit(cg_blksfree(cgp), bno + i);
+ }
+ cgp->cg_cs.cs_nffree += i;
+ fs->fs_cstotal.cs_nffree += i;
+ csum[cg].cs_nffree += i;
+ /*
+ * add back in counts associated with the new frags
+ */
+ blk = blkmap(fs, cg_blksfree(cgp), bbase);
+ ffs_fragacct(fs, blk, cgp->cg_frsum, 1);
+ /*
+ * if a complete block has been reassembled, account for it
+ */
+ blkno = fragstoblks(fs, bbase);
+ if (ffs_isblock(fs, cg_blksfree(cgp), blkno)) {
+ cgp->cg_cs.cs_nffree -= fs->fs_frag;
+ fs->fs_cstotal.cs_nffree -= fs->fs_frag;
+ csum[cg].cs_nffree -= fs->fs_frag;
+ ffs_clusteracct(fs, cgp, blkno, 1);
+ cgp->cg_cs.cs_nbfree++;
+ fs->fs_cstotal.cs_nbfree++;
+ csum[cg].cs_nbfree++;
+ i = cbtocylno(fs, bbase);
+ cg_blks(fs, cgp, i)[cbtorpos(fs, bbase)]++;
+ cg_blktot(cgp)[i]++;
+ }
+ }
+ if (releasecg)
+ release_cg (cgp);
+ record_poke (cgp, sblock->fs_cgsize);
+ csum_dirty = 1;
+ sblock_dirty = 1;
+ fs->fs_fmod = 1;
+ alloc_sync (np);
+/* bdwrite(bp); */
+}
+
+/*
+ * Free an inode.
+ *
+ * The specified inode is placed back in the free map.
+ */
+/* Implement diskfs call back diskfs_free_node (described in
+ <hurd/diskfs.h>. This was called ffs_vfree in BSD. */
+void
+diskfs_free_node (struct node *np, mode_t mode)
+{
+ register struct fs *fs;
+ struct cg *cgp;
+ ino_t ino = np->dn->number;
+ int cg;
+ int releasecg;
+
+ fs = sblock;
+ assert (ino < fs->fs_ipg * fs->fs_ncg);
+ cg = ino_to_cg(fs, ino);
+#if 0 /* Not this way in GNU Hurd ufs */
+ error = bread(pip->i_devvp, fsbtodb(fs, cgtod(fs, cg)),
+ (int)fs->fs_cgsize, NOCRED, &bp);
+ if (error) {
+ brelse(bp);
+ return (0);
+ }
+ cgp = (struct cg *)bp->b_data;
+#else
+ releasecg = read_cg (cg, &cgp);
+#endif
+ if (!cg_chkmagic(cgp)) {
+/* brelse(bp); */
+ if (releasecg)
+ release_cg (cgp);
+ return;
+ }
+ cgp->cg_time = diskfs_mtime->seconds;
+ ino %= fs->fs_ipg;
+ if (isclr(cg_inosused(cgp), ino)) {
+/* printf("dev = 0x%x, ino = %Ld, fs = %s\n",
+ pip->i_dev, ino, fs->fs_fsmnt); */
+ assert (diskfs_readonly);
+ }
+ clrbit(cg_inosused(cgp), ino);
+ if (ino < cgp->cg_irotor)
+ cgp->cg_irotor = ino;
+ cgp->cg_cs.cs_nifree++;
+ fs->fs_cstotal.cs_nifree++;
+ csum[cg].cs_nifree++;
+ if ((mode & IFMT) == IFDIR) {
+ cgp->cg_cs.cs_ndir--;
+ fs->fs_cstotal.cs_ndir--;
+ csum[cg].cs_ndir--;
+ }
+ if (releasecg)
+ release_cg (cgp);
+ record_poke (cgp, sblock->fs_cgsize);
+ csum_dirty = 1;
+ sblock_dirty = 1;
+ fs->fs_fmod = 1;
+ alloc_sync (np);
+/* bdwrite(bp); */
+}
+
+/*
+ * Find a block of the specified size in the specified cylinder group.
+ *
+ * It is a panic if a request is made to find a block if none are
+ * available.
+ */
+static daddr_t
+ffs_mapsearch(register struct fs *fs,
+ register struct cg *cgp,
+ daddr_t bpref,
+ int allocsiz)
+{
+ daddr_t bno;
+ int start, len, loc, i;
+ int blk, field, subfield, pos;
+
+ /*
+ * find the fragment by searching through the free block
+ * map for an appropriate bit pattern
+ */
+ if (bpref)
+ start = dtogd(fs, bpref) / NBBY;
+ else
+ start = cgp->cg_frotor / NBBY;
+ len = howmany(fs->fs_fpg, NBBY) - start;
+ loc = scanc((u_int)len, (u_char *)&cg_blksfree(cgp)[start],
+ (u_char *)fragtbl[fs->fs_frag],
+ (u_char)(1 << (allocsiz - 1 + (fs->fs_frag % NBBY))));
+ if (loc == 0) {
+ len = start + 1;
+ start = 0;
+ loc = scanc((u_int)len, (u_char *)&cg_blksfree(cgp)[0],
+ (u_char *)fragtbl[fs->fs_frag],
+ (u_char)(1 << (allocsiz - 1 + (fs->fs_frag % NBBY))));
+ assert (loc);
+
+ }
+ bno = (start + len - loc) * NBBY;
+ cgp->cg_frotor = bno;
+ /*
+ * found the byte in the map
+ * sift through the bits to find the selected frag
+ */
+ for (i = bno + NBBY; bno < i; bno += fs->fs_frag) {
+ blk = blkmap(fs, cg_blksfree(cgp), bno);
+ blk <<= 1;
+ field = around[allocsiz];
+ subfield = inside[allocsiz];
+ for (pos = 0; pos <= fs->fs_frag - allocsiz; pos++) {
+ if ((blk & field) == subfield)
+ return (bno + pos);
+ field <<= 1;
+ subfield <<= 1;
+ }
+ }
+ assert (0);
+ return (-1);
+}
+
+/*
+ * Update the cluster map because of an allocation or free.
+ *
+ * Cnt == 1 means free; cnt == -1 means allocating.
+ */
+static void
+ffs_clusteracct(struct fs *fs,
+ struct cg *cgp,
+ daddr_t blkno,
+ int cnt)
+{
+ long *sump;
+ u_char *freemapp, *mapp;
+ int i, start, end, forw, back, map, bit;
+
+ if (fs->fs_contigsumsize <= 0)
+ return;
+ freemapp = cg_clustersfree(cgp);
+ sump = cg_clustersum(cgp);
+ /*
+ * Allocate or clear the actual block.
+ */
+ if (cnt > 0)
+ setbit(freemapp, blkno);
+ else
+ clrbit(freemapp, blkno);
+ /*
+ * Find the size of the cluster going forward.
+ */
+ start = blkno + 1;
+ end = start + fs->fs_contigsumsize;
+ if (end >= cgp->cg_nclusterblks)
+ end = cgp->cg_nclusterblks;
+ mapp = &freemapp[start / NBBY];
+ map = *mapp++;
+ bit = 1 << (start % NBBY);
+ for (i = start; i < end; i++) {
+ if ((map & bit) == 0)
+ break;
+ if ((i & (NBBY - 1)) != (NBBY - 1)) {
+ bit <<= 1;
+ } else {
+ map = *mapp++;
+ bit = 1;
+ }
+ }
+ forw = i - start;
+ /*
+ * Find the size of the cluster going backward.
+ */
+ start = blkno - 1;
+ end = start - fs->fs_contigsumsize;
+ if (end < 0)
+ end = -1;
+ mapp = &freemapp[start / NBBY];
+ map = *mapp--;
+ bit = 1 << (start % NBBY);
+ for (i = start; i > end; i--) {
+ if ((map & bit) == 0)
+ break;
+ if ((i & (NBBY - 1)) != 0) {
+ bit >>= 1;
+ } else {
+ map = *mapp--;
+ bit = 1 << (NBBY - 1);
+ }
+ }
+ back = start - i;
+ /*
+ * Account for old cluster and the possibly new forward and
+ * back clusters.
+ */
+ i = back + forw + 1;
+ if (i > fs->fs_contigsumsize)
+ i = fs->fs_contigsumsize;
+ sump[i] += cnt;
+ if (back > 0)
+ sump[back] -= cnt;
+ if (forw > 0)
+ sump[forw] -= cnt;
+}
+
+#if 0
+/*
+ * Fserr prints the name of a file system with an error diagnostic.
+ *
+ * The form of the error message is:
+ * fs: error message
+ */
+static void
+ffs_fserr(fs, uid, cp)
+ struct fs *fs;
+ u_int uid;
+ char *cp;
+{
+
+ log(LOG_ERR, "uid %d on %s: %s\n", uid, fs->fs_fsmnt, cp);
+}
+#endif
diff --git a/ufs/bmap.c b/ufs/bmap.c
new file mode 100644
index 00000000..1a138f39
--- /dev/null
+++ b/ufs/bmap.c
@@ -0,0 +1,120 @@
+/* Interpretation of indirect block structure
+ Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc.
+ Written by Michael I. Bushnell.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#include "ufs.h"
+
+/* For logical block number LBN of file NP, look it the block address,
+ giving the "path" of indirect blocks to the file, starting
+ with the least indirect. Fill *INDIRS with information for
+ the block. */
+error_t
+fetch_indir_spec (struct node *np, volatile daddr_t lbn,
+ struct iblock_spec *indirs)
+{
+ struct dinode *di = dino (np->dn->number);
+ error_t err;
+ daddr_t *siblock;
+
+ err = diskfs_catch_exception ();
+ if (err)
+ return err;
+
+ indirs[0].offset = -2;
+ indirs[1].offset = -2;
+ indirs[2].offset = -2;
+ indirs[3].offset = -2;
+
+ if (lbn < NDADDR)
+ {
+ if (lbn >= 0)
+ {
+ indirs[0].bno = read_disk_entry (di->di_db[lbn]);
+ indirs[0].offset = -1;
+ }
+
+ diskfs_end_catch_exception ();
+ return 0;
+ }
+
+ lbn -= NDADDR;
+
+ indirs[0].offset = lbn % NINDIR (sblock);
+
+ if (lbn / NINDIR (sblock))
+ {
+ /* We will use the double indirect block */
+ int ibn;
+ daddr_t *diblock;
+
+ ibn = lbn / NINDIR (sblock) - 1;
+
+ indirs[1].offset = ibn % NINDIR (sblock);
+
+ /* We don't support triple indirect blocks, but this
+ is where we'd do it. */
+ assert (!(ibn / NINDIR (sblock)));
+
+ indirs[2].offset = -1;
+ indirs[2].bno = read_disk_entry (di->di_ib[INDIR_DOUBLE]);
+
+ if (indirs[2].bno)
+ {
+ diblock = indir_block (indirs[2].bno);
+ indirs[1].bno = read_disk_entry (diblock[indirs[1].offset]);
+ }
+ else
+ indirs[1].bno = 0;
+ }
+ else
+ {
+ indirs[1].offset = -1;
+ indirs[1].bno = read_disk_entry (di->di_ib[INDIR_SINGLE]);
+ }
+
+ if (indirs[1].bno)
+ {
+ siblock = indir_block (indirs[1].bno);
+ indirs[0].bno = read_disk_entry (siblock[indirs[0].offset]);
+ }
+ else
+ indirs[0].bno = 0;
+
+ diskfs_end_catch_exception ();
+ return 0;
+}
+
+
+/* Mark indirect block BNO as dirty on node NP's list. NP must
+ be locked. */
+void
+mark_indir_dirty (struct node *np, daddr_t bno)
+{
+ struct dirty_indir *d;
+
+ for (d = np->dn->dirty; d; d = d->next)
+ if (d->bno == bno)
+ return;
+
+ d = malloc (sizeof (struct dirty_indir));
+ d->bno = bno;
+ d->next = np->dn->dirty;
+ np->dn->dirty = d;
+}
+
diff --git a/ufs/consts.c b/ufs/consts.c
new file mode 100644
index 00000000..69221233
--- /dev/null
+++ b/ufs/consts.c
@@ -0,0 +1,33 @@
+/* Various constants wanted by the diskfs library
+ Copyright (C) 1994, 1995, 1996, 1999 Free Software Foundation
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#include "ufs.h"
+#include "dir.h"
+#include <version.h>
+
+int diskfs_link_max = LINK_MAX;
+int diskfs_name_max = MAXNAMLEN;
+int diskfs_maxsymlinks = 8;
+int diskfs_shortcut_symlink = 1;
+int diskfs_shortcut_chrdev = 1;
+int diskfs_shortcut_blkdev = 1;
+int diskfs_shortcut_fifo = 1;
+int diskfs_shortcut_ifsock = 1;
+char *diskfs_server_name = "ufs";
+char *diskfs_server_version = HURD_VERSION;
+char *diskfs_extra_version = "GNU Hurd";
+int diskfs_synchronous = 0;
diff --git a/ufs/dinode.h b/ufs/dinode.h
new file mode 100644
index 00000000..00be0d94
--- /dev/null
+++ b/ufs/dinode.h
@@ -0,0 +1,137 @@
+/*
+ Copyright (C) 1994 Free Software Foundation
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+/*
+ * Copyright (c) 1982, 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * 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.
+ *
+ * @(#)dinode.h 8.3 (Berkeley) 1/21/94
+ */
+
+/*
+ * The root inode is the root of the file system. Inode 0 can't be used for
+ * normal purposes and historically bad blocks were linked to inode 1, thus
+ * the root inode is 2. (Inode 1 is no longer used for this purpose, however
+ * numerous dump tapes make this assumption, so we are stuck with it).
+ */
+#define ROOTINO ((ino_t)2)
+
+/*
+ * A dinode contains all the meta-data associated with a UFS file.
+ * This structure defines the on-disk format of a dinode.
+ */
+
+#define NDADDR 12 /* Direct addresses in inode. */
+#define NIADDR 3 /* Indirect addresses in inode. */
+
+/* Maximum value of di_nlink field. */
+#define LINK_MAX 32767
+
+/* Indexes into di_ib */
+#define INDIR_SINGLE 0
+#define INDIR_DOUBLE 1
+#define INDIR_TRIPLE 2 /* NOT SUPPORTED */
+
+struct dinode {
+ u_short di_model; /* 0: IFMT and permissions. */
+ short di_nlink; /* 2: File link count. */
+ union
+ {
+ u_long diu_author; /* 4: File author */
+ u_short diu_oldids[2]; /* Old format uid and gid */
+ } di_u;
+ u_quad_t di_size; /* 8: File byte count. */
+ struct timespec di_atime; /* 16: Last access time. */
+ struct timespec di_mtime; /* 24: Last modified time. */
+ struct timespec di_ctime; /* 32: Last inode change time. */
+ daddr_t di_db[NDADDR]; /* 40: Direct disk blocks. */
+ daddr_t di_ib[NIADDR]; /* 88: Indirect disk blocks. */
+ u_long di_flags; /* 100: Status flags (chflags). */
+ long di_blocks; /* 104: Blocks actually held. */
+ long di_gen; /* 108: Generation number. */
+ u_long di_uid; /* 112: File owner. */
+ u_long di_gid; /* 116: File group. */
+ u_short di_modeh; /* 120: Mode high bits */
+ u_short di_spare; /* 122: unused */
+ long di_trans; /* 124: filesystem translator */
+};
+
+#define di_author di_u.diu_author /* GNU extension */
+#define di_ouid di_u.diu_oldids[0]
+#define di_ogid di_u.diu_oldids[1]
+
+/*
+ * The di_db fields may be overlaid with other information for
+ * file types that do not have associated disk storage. Block
+ * and character devices overlay the first data block with their
+ * dev_t value. Short symbolic links place their path in the
+ * di_db area.
+ */
+#define di_rdev di_db[0]
+#define di_shortlink di_db
+#define MAXSYMLINKLEN ((NDADDR + NIADDR) * sizeof(daddr_t))
+
+/* File modes. */
+#define IEXEC 0000100 /* Executable. */
+#define IWRITE 0000200 /* Writeable. */
+#define IREAD 0000400 /* Readable. */
+#define ISVTX 0001000 /* Sticky bit. */
+#define ISGID 0002000 /* Set-gid. */
+#define ISUID 0004000 /* Set-uid. */
+
+/* File types. */
+#define IFMT 0170000 /* Mask of file type. */
+#define IFIFO 0010000 /* Named pipe (fifo). */
+#define IFCHR 0020000 /* Character device. */
+#define IFDIR 0040000 /* Directory file. */
+#define IFBLK 0060000 /* Block device. */
+#define IFREG 0100000 /* Regular file. */
+#define IFLNK 0120000 /* Symbolic link. */
+#define IFSOCK 0140000 /* UNIX domain socket. */
diff --git a/ufs/dir.c b/ufs/dir.c
new file mode 100644
index 00000000..3c5f152a
--- /dev/null
+++ b/ufs/dir.c
@@ -0,0 +1,988 @@
+/* Directory management routines
+
+ Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2002, 2007
+ Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#include "ufs.h"
+#include "dir.h"
+
+#include <string.h>
+#include <stdio.h>
+#include <dirent.h>
+
+#undef d_ino
+
+enum slot_status
+{
+ /* This means we haven't yet found room for a new entry. */
+ LOOKING,
+
+ /* This means that the specified entry is free and should be used. */
+ TAKE,
+
+ /* This means that the specified entry has enough room at the end
+ to hold the new entry. */
+ SHRINK,
+
+ /* This means that there is enough space in the block, but not in
+ any one single entry, so they all have to be shifted to make
+ room. */
+ COMPRESS,
+
+ /* This means that the directory will have to be grown to hold the
+ entry. */
+ EXTEND,
+
+ /* For removal and rename, this means that this is the location
+ of the entry found. */
+ HERE_TIS,
+};
+
+struct dirstat
+{
+ /* Type of followp operation expected */
+ enum lookup_type type;
+
+ /* One of the statuses above */
+ enum slot_status stat;
+
+ /* Mapped address and length of directory */
+ vm_address_t mapbuf;
+ vm_size_t mapextent;
+
+ /* Index of this directory block. */
+ int idx;
+
+ /* For stat COMPRESS, this is the address (inside mapbuf)
+ of the first direct in the directory block to be compressed. */
+ /* For stat HERE_TIS, SHRINK, and TAKE, this is the entry referenced. */
+ struct directory_entry *entry;
+
+ /* For stat HERE_TIS, type REMOVE, this is the address of the immediately
+ previous direct in this directory block, or zero if this is the first. */
+ struct directory_entry *preventry;
+
+ /* For stat COMPRESS, this is the number of bytes needed to be copied
+ in order to undertake the compression. */
+ size_t nbytes;
+};
+
+const size_t diskfs_dirstat_size = sizeof (struct dirstat);
+
+/* Initialize DS such that diskfs_drop_dirstat will ignore it. */
+void
+diskfs_null_dirstat (struct dirstat *ds)
+{
+ ds->type = LOOKUP;
+}
+
+static error_t
+dirscanblock (vm_address_t blockoff, struct node *dp, int idx,
+ const char *name, int namelen, enum lookup_type type,
+ struct dirstat *ds, ino_t *inum);
+
+/* Implement the diskfs_lookup from the diskfs library. See
+ <hurd/diskfs.h> for the interface specification. */
+error_t
+diskfs_lookup_hard (struct node *dp, const char *name, enum lookup_type type,
+ struct node **npp, struct dirstat *ds, struct protid *cred)
+{
+ error_t err;
+ ino_t inum;
+ int namelen;
+ int spec_dotdot;
+ struct node *np = 0;
+ int retry_dotdot = 0;
+ memory_object_t memobj;
+ vm_prot_t prot =
+ (type == LOOKUP) ? VM_PROT_READ : (VM_PROT_READ | VM_PROT_WRITE);
+ vm_address_t buf = 0;
+ vm_size_t buflen = 0;
+ int blockaddr;
+ int idx, lastidx;
+ int looped;
+
+ if ((type == REMOVE) || (type == RENAME))
+ assert (npp);
+
+ if (npp)
+ *npp = 0;
+
+ spec_dotdot = type & SPEC_DOTDOT;
+ type &= ~SPEC_DOTDOT;
+
+ namelen = strlen (name);
+
+ if (namelen > MAXNAMLEN)
+ {
+ if (ds)
+ diskfs_null_dirstat (ds);
+ return ENAMETOOLONG;
+ }
+
+ try_again:
+ if (ds)
+ {
+ ds->type = LOOKUP;
+ ds->mapbuf = 0;
+ ds->mapextent = 0;
+ }
+ if (buf)
+ {
+ munmap ((caddr_t) buf, buflen);
+ buf = 0;
+ }
+ if (ds && (type == CREATE || type == RENAME))
+ ds->stat = LOOKING;
+
+ /* Map in the directory contents. */
+ memobj = diskfs_get_filemap (dp, prot);
+
+ if (memobj == MACH_PORT_NULL)
+ return errno;
+
+ buf = 0;
+ /* We allow extra space in case we have to do an EXTEND. */
+ buflen = round_page (dp->dn_stat.st_size + DIRBLKSIZ);
+ err = vm_map (mach_task_self (),
+ &buf, buflen, 0, 1, memobj, 0, 0, prot, prot, 0);
+ mach_port_deallocate (mach_task_self (), memobj);
+
+ inum = 0;
+
+ diskfs_set_node_atime (dp);
+
+ /* Start the lookup at DP->dn->dir_idx. */
+ idx = dp->dn->dir_idx;
+ if (idx * DIRBLKSIZ > dp->dn_stat.st_size)
+ idx = 0; /* just in case */
+ blockaddr = buf + idx * DIRBLKSIZ;
+ looped = (idx == 0);
+ lastidx = idx;
+ if (lastidx == 0)
+ lastidx = dp->dn_stat.st_size / DIRBLKSIZ;
+
+ while (!looped || idx < lastidx)
+ {
+ err = dirscanblock (blockaddr, dp, idx, name, namelen, type, ds, &inum);
+ if (!err)
+ {
+ dp->dn->dir_idx = idx;
+ break;
+ }
+ if (err != ENOENT)
+ {
+ munmap ((caddr_t) buf, buflen);
+ return err;
+ }
+
+ blockaddr += DIRBLKSIZ;
+ idx++;
+ if (blockaddr - buf >= dp->dn_stat.st_size && !looped)
+ {
+ /* We've gotten to the end; start back at the beginning */
+ looped = 1;
+ blockaddr = buf;
+ idx = 0;
+ }
+ }
+
+ diskfs_set_node_atime (dp);
+ if (diskfs_synchronous)
+ diskfs_node_update (dp, 1);
+
+ /* If err is set here, it's ENOENT, and we don't want to
+ think about that as an error yet. */
+ err = 0;
+
+ if (inum && npp)
+ {
+ if (namelen != 2 || name[0] != '.' || name[1] != '.')
+ {
+ if (inum == dp->dn->number)
+ {
+ np = dp;
+ diskfs_nref (np);
+ }
+ else
+ {
+ err = diskfs_cached_lookup (inum, &np);
+ if (err)
+ goto out;
+ }
+ }
+
+ /* We are looking up .. */
+ /* Check to see if this is the root of the filesystem. */
+ else if (dp->dn->number == 2)
+ {
+ err = EAGAIN;
+ goto out;
+ }
+
+ /* We can't just do diskfs_cached_lookup, because we would then deadlock.
+ So we do this. Ick. */
+ else if (retry_dotdot)
+ {
+ /* Check to see that we got the same answer as last time. */
+ if (inum != retry_dotdot)
+ {
+ /* Drop what we *thought* was .. (but isn't any more) and
+ try *again*. */
+ diskfs_nput (np);
+ mutex_unlock (&dp->lock);
+ err = diskfs_cached_lookup (inum, &np);
+ mutex_lock (&dp->lock);
+ if (err)
+ goto out;
+ retry_dotdot = inum;
+ goto try_again;
+ }
+ /* Otherwise, we got it fine and np is already set properly. */
+ }
+ else if (!spec_dotdot)
+ {
+ /* Lock them in the proper order, and then
+ repeat the directory scan to see if this is still
+ right. */
+ mutex_unlock (&dp->lock);
+ err = diskfs_cached_lookup (inum, &np);
+ mutex_lock (&dp->lock);
+ if (err)
+ goto out;
+ retry_dotdot = inum;
+ goto try_again;
+ }
+
+ /* Here below are the spec dotdot cases. */
+ else if (type == RENAME || type == REMOVE)
+ np = ifind (inum);
+
+ else if (type == LOOKUP)
+ {
+ diskfs_nput (dp);
+ err = diskfs_cached_lookup (inum, &np);
+ if (err)
+ goto out;
+ }
+ else
+ assert (0);
+ }
+
+ if ((type == CREATE || type == RENAME) && !inum && ds && ds->stat == LOOKING)
+ {
+ /* We didn't find any room, so mark ds to extend the dir */
+ ds->type = CREATE;
+ ds->stat = EXTEND;
+ ds->idx = dp->dn_stat.st_size / DIRBLKSIZ;
+ }
+
+ /* Return to the user; if we can't, release the reference
+ (and lock) we acquired above. */
+ out:
+ /* Deallocate or save the mapping. */
+ if ((err && err != ENOENT)
+ || !ds
+ || ds->type == LOOKUP)
+ {
+ munmap ((caddr_t) buf, buflen);
+ if (ds)
+ ds->type = LOOKUP; /* set to be ignored by drop_dirstat */
+ }
+ else
+ {
+ ds->mapbuf = buf;
+ ds->mapextent = buflen;
+ }
+
+ if (np)
+ {
+ assert (npp);
+ if (err)
+ {
+ if (!spec_dotdot)
+ {
+ /* Normal case */
+ if (np == dp)
+ diskfs_nrele (np);
+ else
+ diskfs_nput (np);
+ }
+ else if (type == RENAME || type == REMOVE)
+ /* We just did ifind to get np; that allocates
+ no new references, so we don't have anything to do */
+ ;
+ else if (type == LOOKUP)
+ /* We did diskfs_cached_lookup */
+ diskfs_nput (np);
+ }
+ else
+ *npp = np;
+ }
+
+ return err ? : inum ? 0 : ENOENT;
+}
+
+/* Scan block at address BLKADDR (of node DP; block index IDX), for
+ name NAME of length NAMELEN. Args TYPE, DS are as for
+ diskfs_lookup. If found, set *INUM to the inode number, else
+ return ENOENT. */
+static error_t
+dirscanblock (vm_address_t blockaddr, struct node *dp, int idx,
+ const char *name, int namelen, enum lookup_type type,
+ struct dirstat *ds, ino_t *inum)
+{
+ int nfree = 0;
+ int needed = 0;
+ vm_address_t currentoff, prevoff;
+ struct directory_entry *entry = 0;
+ int nentries = 0;
+ size_t nbytes = 0;
+ int looking = 0;
+ int countcopies = 0;
+ int consider_compress = 0;
+
+ if (ds && (ds->stat == LOOKING
+ || ds->stat == COMPRESS))
+ {
+ looking = 1;
+ countcopies = 1;
+ needed = DIRSIZ (namelen);
+ }
+
+ for (currentoff = blockaddr, prevoff = 0;
+ currentoff < blockaddr + DIRBLKSIZ;
+ prevoff = currentoff, currentoff += read_disk_entry (entry->d_reclen))
+ {
+ entry = (struct directory_entry *)currentoff;
+
+ if (!entry->d_reclen
+ || read_disk_entry (entry->d_reclen) % 4
+ || DIRECT_NAMLEN (entry) > MAXNAMLEN
+ || (currentoff + read_disk_entry (entry->d_reclen)
+ > blockaddr + DIRBLKSIZ)
+ || entry->d_name[DIRECT_NAMLEN (entry)]
+ || DIRSIZ (DIRECT_NAMLEN (entry)) > read_disk_entry (entry->d_reclen)
+ || memchr (entry->d_name, '\0', DIRECT_NAMLEN (entry)))
+ {
+ fprintf (stderr, "Bad directory entry: inode: %Ld offset: %zd\n",
+ dp->dn->number, currentoff - blockaddr + idx * DIRBLKSIZ);
+ return ENOENT;
+ }
+
+ if (looking || countcopies)
+ {
+ int thisfree;
+
+ /* Count how much free space this entry has in it. */
+ if (entry->d_ino == 0)
+ thisfree = read_disk_entry (entry->d_reclen);
+ else
+ thisfree = (read_disk_entry (entry->d_reclen)
+ - DIRSIZ (DIRECT_NAMLEN (entry)));
+
+ /* If this isn't at the front of the block, then it will
+ have to be copied if we do a compression; count the
+ number of bytes there too. */
+ if (countcopies && currentoff != blockaddr)
+ nbytes += DIRSIZ (DIRECT_NAMLEN (entry));
+
+ if (ds->stat == COMPRESS && nbytes > ds->nbytes)
+ /* The previously found compress is better than
+ this one, so don't bother counting any more. */
+ countcopies = 0;
+
+ if (thisfree >= needed)
+ {
+ ds->type = CREATE;
+ ds->stat = read_disk_entry (entry->d_ino) == 0 ? TAKE : SHRINK;
+ ds->entry = entry;
+ ds->idx = idx;
+ looking = countcopies = 0;
+ }
+ else
+ {
+ nfree += thisfree;
+ if (nfree >= needed)
+ consider_compress = 1;
+ }
+ }
+
+ if (entry->d_ino)
+ nentries++;
+
+ if (DIRECT_NAMLEN (entry) == namelen
+ && entry->d_name[0] == name[0]
+ && entry->d_ino
+ && !bcmp (entry->d_name, name, namelen))
+ break;
+ }
+
+ if (consider_compress
+ && (ds->type == LOOKING
+ || (ds->type == COMPRESS && ds->nbytes > nbytes)))
+ {
+ ds->type = CREATE;
+ ds->stat = COMPRESS;
+ ds->entry = (struct directory_entry *) blockaddr;
+ ds->idx = idx;
+ ds->nbytes = nbytes;
+ }
+
+ if (currentoff >= blockaddr + DIRBLKSIZ)
+ {
+ int i;
+ /* The name is not in this block. */
+
+ /* Because we scanned the entire block, we should write
+ down how many entries there were. */
+ if (!dp->dn->dirents)
+ {
+ dp->dn->dirents = malloc ((dp->dn_stat.st_size / DIRBLKSIZ)
+ * sizeof (int));
+ for (i = 0; i < dp->dn_stat.st_size/DIRBLKSIZ; i++)
+ dp->dn->dirents[i] = -1;
+ }
+ /* Make sure the count is correct if there is one now. */
+ assert (dp->dn->dirents[idx] == -1
+ || dp->dn->dirents[idx] == nentries);
+ dp->dn->dirents[idx] = nentries;
+
+ return ENOENT;
+ }
+
+ /* We have found the required name. */
+
+ if (ds && type == CREATE)
+ ds->type = LOOKUP; /* it's invalid now */
+ else if (ds && (type == REMOVE || type == RENAME))
+ {
+ ds->type = type;
+ ds->stat = HERE_TIS;
+ ds->entry = entry;
+ ds->idx = idx;
+ ds->preventry = (struct directory_entry *) prevoff;
+ }
+
+ *inum = read_disk_entry (entry->d_ino);
+ return 0;
+}
+
+/* Following a lookup call for CREATE, this adds a node to a directory.
+ DP is the directory to be modified; NAME is the name to be entered;
+ NP is the node being linked in; DS is the cached information returned
+ by lookup; CRED describes the user making the call. This call may
+ only be made if the directory has been held locked continuously since
+ the preceding lookup call, and only if that call returned ENOENT. */
+error_t
+diskfs_direnter_hard(struct node *dp,
+ const char *name,
+ struct node *np,
+ struct dirstat *ds,
+ struct protid *cred)
+{
+ struct directory_entry *new;
+ int namelen = strlen (name);
+ int needed = DIRSIZ (namelen);
+ int oldneeded;
+ vm_address_t fromoff, tooff;
+ int totfreed;
+ error_t err;
+ size_t oldsize = 0;
+
+ assert (ds->type == CREATE);
+
+ dp->dn_set_mtime = 1;
+
+ switch (ds->stat)
+ {
+ case TAKE:
+ /* We are supposed to consume this slot. */
+ assert (ds->entry->d_ino == 0
+ && read_disk_entry (ds->entry->d_reclen) >= needed);
+
+ write_disk_entry (ds->entry->d_ino, np->dn->number);
+ DIRECT_NAMLEN (ds->entry) = namelen;
+ if (direct_symlink_extension)
+ ds->entry->d_type = IFTODT (np->dn_stat.st_mode);
+ bcopy (name, ds->entry->d_name, namelen + 1);
+
+ break;
+
+ case SHRINK:
+ /* We are supposed to take the extra space at the end
+ of this slot. */
+ oldneeded = DIRSIZ (DIRECT_NAMLEN (ds->entry));
+ assert (read_disk_entry (ds->entry->d_reclen) - oldneeded >= needed);
+
+ new = (struct directory_entry *) ((vm_address_t) ds->entry + oldneeded);
+
+ write_disk_entry (new->d_ino, np->dn->number);
+ write_disk_entry (new->d_reclen,
+ read_disk_entry (ds->entry->d_reclen) - oldneeded);
+ DIRECT_NAMLEN (new) = namelen;
+ if (direct_symlink_extension)
+ new->d_type = IFTODT (np->dn_stat.st_mode);
+ bcopy (name, new->d_name, namelen + 1);
+
+ write_disk_entry (ds->entry->d_reclen, oldneeded);
+
+ break;
+
+ case COMPRESS:
+ /* We are supposed to move all the entries to the
+ front of the block, giving each the minimum
+ necessary room. This should free up enough space
+ for the new entry. */
+ fromoff = tooff = (vm_address_t) ds->entry;
+
+ while (fromoff < (vm_address_t) ds->entry + DIRBLKSIZ)
+ {
+ struct directory_entry *from = (struct directory_entry *)fromoff;
+ struct directory_entry *to = (struct directory_entry *) tooff;
+ int fromreclen = read_disk_entry (from->d_reclen);
+
+ if (from->d_ino != 0)
+ {
+ assert (fromoff >= tooff);
+
+ bcopy (from, to, fromreclen);
+ write_disk_entry (to->d_reclen, DIRSIZ (DIRECT_NAMLEN (to)));
+
+ tooff += read_disk_entry (to->d_reclen);
+ }
+ fromoff += fromreclen;
+ }
+
+ totfreed = (vm_address_t) ds->entry + DIRBLKSIZ - tooff;
+ assert (totfreed >= needed);
+
+ new = (struct directory_entry *) tooff;
+ write_disk_entry (new->d_ino, np->dn->number);
+ write_disk_entry (new->d_reclen, totfreed);
+ DIRECT_NAMLEN (new) = namelen;
+ if (direct_symlink_extension)
+ new->d_type = IFTODT (np->dn_stat.st_mode);
+ bcopy (name, new->d_name, namelen + 1);
+ break;
+
+ case EXTEND:
+ /* Extend the file. */
+ assert (needed <= DIRBLKSIZ);
+
+ oldsize = dp->dn_stat.st_size;
+ if ((off_t)(oldsize + DIRBLKSIZ) != dp->dn_stat.st_size + DIRBLKSIZ)
+ {
+ /* We can't possibly map the whole directory in. */
+ munmap ((caddr_t) ds->mapbuf, ds->mapextent);
+ return EOVERFLOW;
+ }
+ while (oldsize + DIRBLKSIZ > dp->allocsize)
+ {
+ err = diskfs_grow (dp, oldsize + DIRBLKSIZ, cred);
+ if (err)
+ {
+ munmap ((caddr_t) ds->mapbuf, ds->mapextent);
+ return err;
+ }
+ }
+
+ new = (struct directory_entry *) (ds->mapbuf + oldsize);
+
+ dp->dn_stat.st_size = oldsize + DIRBLKSIZ;
+ dp->dn_set_ctime = 1;
+
+ write_disk_entry (new->d_ino, np->dn->number);
+ write_disk_entry (new->d_reclen, DIRBLKSIZ);
+ DIRECT_NAMLEN (new) = namelen;
+ if (direct_symlink_extension)
+ new->d_type = IFTODT (np->dn_stat.st_mode);
+ bcopy (name, new->d_name, namelen + 1);
+ break;
+
+ default:
+ assert (0);
+ }
+
+ dp->dn_set_mtime = 1;
+
+ munmap ((caddr_t) ds->mapbuf, ds->mapextent);
+
+ if (ds->stat != EXTEND)
+ {
+ /* If we are keeping count of this block, then keep the count up
+ to date. */
+ if (dp->dn->dirents && dp->dn->dirents[ds->idx] != -1)
+ dp->dn->dirents[ds->idx]++;
+ }
+ else
+ {
+ int i;
+ /* It's cheap, so start a count here even if we aren't counting
+ anything at all. */
+ if (dp->dn->dirents)
+ {
+ dp->dn->dirents = realloc (dp->dn->dirents,
+ (dp->dn_stat.st_size / DIRBLKSIZ
+ * sizeof (int)));
+ for (i = oldsize / DIRBLKSIZ;
+ i < dp->dn_stat.st_size / DIRBLKSIZ;
+ i++)
+ dp->dn->dirents[i] = -1;
+
+ dp->dn->dirents[ds->idx] = 1;
+ }
+ else
+ {
+ dp->dn->dirents = malloc (dp->dn_stat.st_size / DIRBLKSIZ
+ * sizeof (int));
+ for (i = 0; i < dp->dn_stat.st_size / DIRBLKSIZ; i++)
+ dp->dn->dirents[i] = -1;
+ dp->dn->dirents[ds->idx] = 1;
+ }
+ }
+
+ diskfs_file_update (dp, 1);
+
+ return 0;
+}
+
+/* Following a lookup call for REMOVE, this removes the link from the
+ directory. DP is the directory being changed and DS is the cached
+ information returned from lookup. This call is only valid if the
+ directory has been locked continuously since the call to lookup, and
+ only if that call succeeded. */
+error_t
+diskfs_dirremove_hard(struct node *dp,
+ struct dirstat *ds)
+{
+ assert (ds->type == REMOVE);
+ assert (ds->stat == HERE_TIS);
+
+ dp->dn_set_mtime = 1;
+
+ if (ds->preventry == 0)
+ ds->entry->d_ino = 0;
+ else
+ {
+ assert ((vm_address_t) ds->entry - (vm_address_t) ds->preventry
+ == read_disk_entry (ds->preventry->d_reclen));
+ write_disk_entry (ds->preventry->d_reclen,
+ (read_disk_entry (ds->preventry->d_reclen)
+ + read_disk_entry (ds->entry->d_reclen)));
+ }
+
+ dp->dn_set_mtime = 1;
+
+ munmap ((caddr_t) ds->mapbuf, ds->mapextent);
+
+ /* If we are keeping count of this block, then keep the count up
+ to date. */
+ if (dp->dn->dirents && dp->dn->dirents[ds->idx] != -1)
+ dp->dn->dirents[ds->idx]--;
+
+ diskfs_file_update (dp, 1);
+
+ return 0;
+}
+
+
+/* Following a lookup call for RENAME, this changes the inode number
+ on a directory entry. DP is the directory being changed; NP is
+ the new node being linked in; DP is the cached information returned
+ by lookup. This call is only valid if the directory has been locked
+ continuously since the call to lookup, and only if that call
+ succeeded. */
+error_t
+diskfs_dirrewrite_hard(struct node *dp,
+ struct node *np,
+ struct dirstat *ds)
+{
+ assert (ds->type == RENAME);
+ assert (ds->stat == HERE_TIS);
+
+ dp->dn_set_mtime = 1;
+ write_disk_entry (ds->entry->d_ino, np->dn->number);
+ if (direct_symlink_extension)
+ ds->entry->d_type = IFTODT (np->dn_stat.st_mode);
+ dp->dn_set_mtime = 1;
+
+ munmap ((caddr_t) ds->mapbuf, ds->mapextent);
+
+ diskfs_file_update (dp, 1);
+
+ return 0;
+}
+
+/* Tell if DP is an empty directory (has only "." and ".." entries). */
+/* This routine must be called from inside a catch_exception (). */
+int
+diskfs_dirempty(struct node *dp,
+ struct protid *cred)
+{
+ struct directory_entry *entry;
+ vm_address_t buf, curoff;
+ memory_object_t memobj;
+ error_t err;
+
+ memobj = diskfs_get_filemap (dp, VM_PROT_READ);
+
+ if (memobj == MACH_PORT_NULL)
+ /* XXX should reflect error properly */
+ return 0;
+
+ buf = 0;
+
+ err = vm_map (mach_task_self (), &buf, dp->dn_stat.st_size, 0,
+ 1, memobj, 0, 0, VM_PROT_READ, VM_PROT_READ, 0);
+ mach_port_deallocate (mach_task_self (), memobj);
+ assert (!err);
+
+ diskfs_set_node_atime (dp);
+
+ for (curoff = buf;
+ curoff < buf + dp->dn_stat.st_size;
+ curoff += read_disk_entry (entry->d_reclen))
+ {
+ entry = (struct directory_entry *) curoff;
+
+ if (entry->d_ino != 0
+ && (DIRECT_NAMLEN (entry) > 2
+ || entry->d_name[0] != '.'
+ || (entry->d_name[1] != '.'
+ && entry->d_name[1] != '\0')))
+ {
+ munmap ((caddr_t) buf, dp->dn_stat.st_size);
+ diskfs_set_node_atime (dp);
+ if (diskfs_synchronous)
+ diskfs_node_update (dp, 1);
+ return 0;
+ }
+ }
+ diskfs_set_node_atime (dp);
+ if (diskfs_synchronous)
+ diskfs_node_update (dp, 1);
+ munmap ((caddr_t) buf, dp->dn_stat.st_size);
+ return 1;
+}
+
+/* Make DS an invalid dirstat. */
+error_t
+diskfs_drop_dirstat (struct node *dp, struct dirstat *ds)
+{
+ if (ds->type != LOOKUP)
+ {
+ assert (ds->mapbuf);
+ munmap ((caddr_t) ds->mapbuf, ds->mapextent);
+ ds->type = LOOKUP;
+ }
+ return 0;
+}
+
+
+/* Count the entries in directory block NB for directory DP and
+ write the answer down in its dirents array. As a side affect
+ fill BUF with the block. */
+static error_t
+count_dirents (struct node *dp, int nb, char *buf)
+{
+ size_t amt;
+ char *offinblk;
+ struct directory_entry *entry;
+ int count = 0;
+ error_t err;
+
+ assert (dp->dn->dirents);
+ assert ((nb + 1) * DIRBLKSIZ <= dp->dn_stat.st_size);
+
+ err = diskfs_node_rdwr (dp, buf, nb * DIRBLKSIZ, DIRBLKSIZ, 0, 0, &amt);
+ if (err)
+ return err;
+ assert (amt == DIRBLKSIZ);
+
+ for (offinblk = buf;
+ offinblk < buf + DIRBLKSIZ;
+ offinblk += read_disk_entry (entry->d_reclen))
+ {
+ entry = (struct directory_entry *) offinblk;
+ if (entry->d_ino)
+ count++;
+ }
+
+ assert (dp->dn->dirents[nb] == -1 || dp->dn->dirents[nb] == count);
+ dp->dn->dirents[nb] = count;
+ return 0;
+}
+
+/* Implement the disikfs_get_directs callback as described in
+ <hurd/diskfs.h>. */
+error_t
+diskfs_get_directs (struct node *dp,
+ int entry,
+ int nentries,
+ char **data,
+ size_t *datacnt,
+ vm_size_t bufsiz,
+ int *amt)
+{
+ int blkno;
+ int nblks;
+ int curentry;
+ char buf[DIRBLKSIZ];
+ char *bufp;
+ int bufvalid;
+ error_t err;
+ int i;
+ char *datap;
+ struct directory_entry *entryp;
+ int allocsize;
+ size_t checklen;
+ struct dirent *userp;
+
+ nblks = dp->dn_stat.st_size/DIRBLKSIZ;
+
+ if (!dp->dn->dirents)
+ {
+ dp->dn->dirents = malloc (nblks * sizeof (int));
+ for (i = 0; i < nblks; i++)
+ dp->dn->dirents[i] = -1;
+ }
+
+ /* Scan through the entries to find ENTRY. If we encounter
+ a -1 in the process then stop to fill it. When we run
+ off the end, ENTRY is too big. */
+ curentry = 0;
+ bufvalid = 0;
+ for (blkno = 0; blkno < nblks; blkno++)
+ {
+ if (dp->dn->dirents[blkno] == -1)
+ {
+ err = count_dirents (dp, blkno, buf);
+ if (err)
+ return err;
+ bufvalid = 1;
+ }
+
+ if (curentry + dp->dn->dirents[blkno] > entry)
+ /* ENTRY starts in this block. */
+ break;
+
+ curentry += dp->dn->dirents[blkno];
+
+ bufvalid = 0;
+ }
+
+ if (blkno == nblks)
+ {
+ /* We reached the end of the directory without seeing ENTRY.
+ This is treated as an EOF condition, meaning we return
+ success with empty results. */
+ *datacnt = 0;
+ *amt = 0;
+ return 0;
+ }
+
+ /* Allocate enough space to hold the maximum we might return */
+ if (!bufsiz || bufsiz > dp->dn_stat.st_size)
+ allocsize = round_page (dp->dn_stat.st_size);
+ else
+ allocsize = round_page (bufsiz);
+
+ if (allocsize > *datacnt)
+ *data = mmap (0, allocsize, PROT_READ|PROT_WRITE, MAP_ANON, 0, 0);
+
+ /* Set bufp appropriately */
+ bufp = buf;
+ if (curentry != entry)
+ {
+ /* Look through the block to find out where to start,
+ setting bufp appropriately. */
+ if (!bufvalid)
+ {
+ err = diskfs_node_rdwr (dp, buf, blkno * DIRBLKSIZ, DIRBLKSIZ,
+ 0, 0, &checklen);
+ if (err)
+ return err;
+ assert (checklen == DIRBLKSIZ);
+ bufvalid = 1;
+ }
+ for (i = 0, bufp = buf;
+ i < entry - curentry && bufp - buf < DIRBLKSIZ;
+ (bufp
+ += read_disk_entry (((struct directory_entry *)bufp)->d_reclen)),
+ i++)
+ ;
+ /* Make sure we didn't run off the end. */
+ assert (bufp - buf < DIRBLKSIZ);
+ }
+
+ i = 0;
+ datap = *data;
+
+ /* Copy the entries, one at a time. */
+ while (((nentries == -1) || (i < nentries))
+ && (!bufsiz || (datap - *data < bufsiz) )
+ && blkno < nblks)
+ {
+ if (!bufvalid)
+ {
+ err = diskfs_node_rdwr (dp, buf, blkno * DIRBLKSIZ, DIRBLKSIZ,
+ 0, 0, &checklen);
+ if (err)
+ return err;
+ assert (checklen == DIRBLKSIZ);
+ bufvalid = 1;
+ bufp = buf;
+ }
+
+ entryp = (struct directory_entry *)bufp;
+
+ if (entryp->d_ino)
+ {
+ userp = (struct dirent *) datap;
+
+ userp->d_fileno = read_disk_entry (entryp->d_ino);
+ userp->d_reclen = DIRSIZ (DIRECT_NAMLEN (entryp));
+ userp->d_namlen = DIRECT_NAMLEN (entryp);
+ bcopy (entryp->d_name, userp->d_name, DIRECT_NAMLEN (entryp) + 1);
+ userp->d_type = DT_UNKNOWN; /* until fixed */
+ i++;
+ datap += DIRSIZ (DIRECT_NAMLEN (entryp));
+ }
+
+ bufp += read_disk_entry (entryp->d_reclen);
+ if (bufp - buf == DIRBLKSIZ)
+ {
+ blkno++;
+ bufvalid = 0;
+ }
+ }
+
+ /* We've copied all we can. If we allocated our own array
+ but didn't fill all of it, then free whatever memory we didn't use. */
+ if (allocsize > *datacnt)
+ {
+ if (round_page (datap - *data) < allocsize)
+ munmap (*data + round_page (datap - *data),
+ allocsize - round_page (datap - *data));
+ }
+
+ /* Set variables for return */
+ *datacnt = datap - *data;
+ *amt = i;
+ return 0;
+}
diff --git a/ufs/dir.h b/ufs/dir.h
new file mode 100644
index 00000000..5730ef44
--- /dev/null
+++ b/ufs/dir.h
@@ -0,0 +1,163 @@
+/* Modified from BSD by Michael I. Bushnell for GNU Hurd ufs server. */
+/*
+ * Copyright (c) 1982, 1986, 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * 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.
+ *
+ * @(#)dir.h 8.2 (Berkeley) 1/21/94
+ */
+
+#ifndef _DIR_H_
+#define _DIR_H_
+
+#include <endian.h>
+
+/*
+ * A directory consists of some number of blocks of DIRBLKSIZ
+ * bytes, where DIRBLKSIZ is chosen such that it can be transferred
+ * to disk in a single atomic operation (e.g. 512 bytes on most machines).
+ *
+ * Each DIRBLKSIZ byte block contains some number of directory entry
+ * structures, which are of variable length. Each directory entry has
+ * a struct direct at the front of it, containing its inode number,
+ * the length of the entry, and the length of the name contained in
+ * the entry. These are followed by the name padded to a 4 byte boundary
+ * with null bytes. All names are guaranteed null terminated.
+ * The maximum length of a name in a directory is MAXNAMLEN.
+ *
+ * The macro DIRSIZ(fmt, dp) gives the amount of space required to represent
+ * a directory entry. Free space in a directory is represented by
+ * entries which have dp->d_reclen > DIRSIZ(fmt, dp). All DIRBLKSIZ bytes
+ * in a directory block are claimed by the directory entries. This
+ * usually results in the last entry in a directory having a large
+ * dp->d_reclen. When entries are deleted from a directory, the
+ * space is returned to the previous entry in the same directory
+ * block by increasing its dp->d_reclen. If the first entry of
+ * a directory block is free, then its dp->d_ino is set to 0.
+ * Entries other than the first in a directory do not normally have
+ * dp->d_ino set to 0.
+ */
+#define DIRBLKSIZ DEV_BSIZE
+#undef MAXNAMLEN
+#define MAXNAMLEN 255
+
+/* Don't call this struct DIRECT because the library defines that
+ (sometimes) in a possible different way. */
+
+struct directory_entry {
+ u_long d_ino; /* inode number of entry */
+ u_short d_reclen; /* length of this record */
+ u_char d_type; /* file type, see below */
+ u_char d_namlen; /* length of string in d_name */
+ char d_name[MAXNAMLEN + 1]; /* name with length <= MAXNAMLEN */
+};
+
+/* Return the type from a struct directory_entry, paying attention to whether
+ this filesystem supports the type extension */
+#define DIRECT_TYPE(dp) (direct_symlink_extension ? (dp)->d_type : DT_UNKNOWN)
+
+/* Return the namlen from a struct direct, paying attention to whether
+ this filesystem supports the type extension */
+#if (BYTE_ORDER == LITTLE_ENDIAN)
+#define DIRECT_NAMLEN(dp) (*(direct_symlink_extension || swab_disk \
+ ? &(dp)->d_namlen \
+ : &(dp)->d_type))
+#else
+#define DIRECT_NAMLEN(dp) (*(!direct_symlink_extension && swab_disk \
+ ? &(dp)->d_type \
+ : &(dp)->d_namlen))
+#endif
+
+/*
+ * The DIRSIZ macro gives the minimum record length which will hold
+ * the directory entry. This requires the amount of space in struct direct
+ * without the d_name field, plus enough space for the name with a terminating
+ * null byte (dp->d_namlen+1), rounded up to a 4 byte boundary.
+ */
+/* In BSD this macro takes a struct direct. Modified by MIB here to
+ take the namelen (as computed by strlen). */
+#define DIRSIZ(namelen) \
+ ((sizeof (struct directory_entry) - (MAXNAMLEN+1)) + (((namelen)+1 + 3) &~ 3))
+
+#if 0 /* This is the BSD definition */
+#if (BYTE_ORDER == LITTLE_ENDIAN)
+#define DIRSIZ(oldfmt, dp) \
+ ((oldfmt) ? \
+ ((sizeof (struct direct) - (MAXNAMLEN+1)) + (((dp)->d_type+1 + 3) &~ 3)) : \
+ ((sizeof (struct direct) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3)))
+#else
+#define DIRSIZ(oldfmt, dp) \
+ ((sizeof (struct direct) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3))
+#endif
+#endif /* 0 */
+
+#define OLDDIRFMT 1
+#define NEWDIRFMT 0
+
+#if 0 /* Not used in GNU */
+/*
+ * Template for manipulating directories.
+ * Should use struct direct's, but the name field
+ * is MAXNAMLEN - 1, and this just won't do.
+ */
+struct dirtemplate {
+ u_long dot_ino;
+ short dot_reclen;
+ u_char dot_type;
+ u_char dot_namlen;
+ char dot_name[4]; /* must be multiple of 4 */
+ u_long dotdot_ino;
+ short dotdot_reclen;
+ u_char dotdot_type;
+ u_char dotdot_namlen;
+ char dotdot_name[4]; /* ditto */
+};
+
+/*
+ * This is the old format of directories, sanz type element.
+ */
+struct odirtemplate {
+ u_long dot_ino;
+ short dot_reclen;
+ u_short dot_namlen;
+ char dot_name[4]; /* must be multiple of 4 */
+ u_long dotdot_ino;
+ short dotdot_reclen;
+ u_short dotdot_namlen;
+ char dotdot_name[4]; /* ditto */
+};
+#endif /* 0 */
+
+#endif /* !_DIR_H_ */
diff --git a/ufs/fs.h b/ufs/fs.h
new file mode 100644
index 00000000..a2a3cc9b
--- /dev/null
+++ b/ufs/fs.h
@@ -0,0 +1,509 @@
+/*
+ * Copyright (c) 1982, 1986, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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.
+ *
+ * @(#)fs.h 8.7 (Berkeley) 4/19/94
+ */
+
+/*
+ * Each disk drive contains some number of file systems.
+ * A file system consists of a number of cylinder groups.
+ * Each cylinder group has inodes and data.
+ *
+ * A file system is described by its super-block, which in turn
+ * describes the cylinder groups. The super-block is critical
+ * data and is replicated in each cylinder group to protect against
+ * catastrophic loss. This is done at `newfs' time and the critical
+ * super-block data does not change, so the copies need not be
+ * referenced further unless disaster strikes.
+ *
+ * For file system fs, the offsets of the various blocks of interest
+ * are given in the super block as:
+ * [fs->fs_sblkno] Super-block
+ * [fs->fs_cblkno] Cylinder group block
+ * [fs->fs_iblkno] Inode blocks
+ * [fs->fs_dblkno] Data blocks
+ * The beginning of cylinder group cg in fs, is given by
+ * the ``cgbase(fs, cg)'' macro.
+ *
+ * The first boot and super blocks are given in absolute disk addresses.
+ * The byte-offset forms are preferred, as they don't imply a sector size.
+ */
+#define BBSIZE 8192
+#define SBSIZE 8192
+#define BBOFF ((off_t)(0))
+#define SBOFF ((off_t)(BBOFF + BBSIZE))
+#define BBLOCK ((daddr_t)(0))
+#define SBLOCK ((daddr_t)(BBLOCK + BBSIZE / DEV_BSIZE))
+
+/*
+ * Addresses stored in inodes are capable of addressing fragments
+ * of `blocks'. File system blocks of at most size MAXBSIZE can
+ * be optionally broken into 2, 4, or 8 pieces, each of which is
+ * addressible; these pieces may be DEV_BSIZE, or some multiple of
+ * a DEV_BSIZE unit.
+ *
+ * Large files consist of exclusively large data blocks. To avoid
+ * undue wasted disk space, the last data block of a small file may be
+ * allocated as only as many fragments of a large block as are
+ * necessary. The file system format retains only a single pointer
+ * to such a fragment, which is a piece of a single large block that
+ * has been divided. The size of such a fragment is determinable from
+ * information in the inode, using the ``blksize(fs, ip, lbn)'' macro.
+ *
+ * The file system records space availability at the fragment level;
+ * to determine block availability, aligned fragments are examined.
+ */
+
+/*
+ * The file system is made out of blocks of at most MAXBSIZE units, with
+ * smaller units (fragments) only in the last direct block. MAXBSIZE
+ * primarily determines the size of buffers in the buffer pool. It may be
+ * made larger without any effect on existing file systems; however making
+ * it smaller make make some file systems unmountable.
+ */
+#define MAXBSIZE MAXPHYS
+#define MAXFRAG 8
+
+/*
+ * MINBSIZE is the smallest allowable block size.
+ * In order to insure that it is possible to create files of size
+ * 2^32 with only two levels of indirection, MINBSIZE is set to 4096.
+ * MINBSIZE must be big enough to hold a cylinder group block,
+ * thus changes to (struct cg) must keep its size within MINBSIZE.
+ * Note that super blocks are always of size SBSIZE,
+ * and that both SBSIZE and MAXBSIZE must be >= MINBSIZE.
+ */
+#define MINBSIZE 4096
+
+/*
+ * The path name on which the file system is mounted is maintained
+ * in fs_fsmnt. MAXMNTLEN defines the amount of space allocated in
+ * the super block for this name.
+ * The limit on the amount of summary information per file system
+ * is defined by MAXCSBUFS. It is currently parameterized for a
+ * maximum of two million cylinders.
+ */
+#define MAXMNTLEN 512
+#define MAXCSBUFS 32
+
+/*
+ * A summary of contiguous blocks of various sizes is maintained
+ * in each cylinder group. Normally this is set by the initial
+ * value of fs_maxcontig. To conserve space, a maximum summary size
+ * is set by FS_MAXCONTIG.
+ */
+#define FS_MAXCONTIG 16
+
+/*
+ * MINFREE gives the minimum acceptable percentage of file system
+ * blocks which may be free. If the freelist drops below this level
+ * only the superuser may continue to allocate blocks. This may
+ * be set to 0 if no reserve of free blocks is deemed necessary,
+ * however throughput drops by fifty percent if the file system
+ * is run at between 95% and 100% full; thus the minimum default
+ * value of fs_minfree is 5%. However, to get good clustering
+ * performance, 10% is a better choice. hence we use 10% as our
+ * default value. With 10% free space, fragmentation is not a
+ * problem, so we choose to optimize for time.
+ */
+#define MINFREE 5
+#define DEFAULTOPT FS_OPTTIME
+
+/*
+ * Per cylinder group information; summarized in blocks allocated
+ * from first cylinder group data blocks. These blocks have to be
+ * read in from fs_csaddr (size fs_cssize) in addition to the
+ * super block.
+ *
+ * N.B. sizeof(struct csum) must be a power of two in order for
+ * the ``fs_cs'' macro to work (see below).
+ */
+struct csum {
+ long cs_ndir; /* number of directories */
+ long cs_nbfree; /* number of free blocks */
+ long cs_nifree; /* number of free inodes */
+ long cs_nffree; /* number of free frags */
+};
+
+/*
+ * Super block for a file system.
+ */
+struct fs {
+ struct fs *fs_link; /* linked list of file systems */
+ struct fs *fs_rlink; /* used for incore super blocks */
+ daddr_t fs_sblkno; /* addr of super-block in filesys */
+ daddr_t fs_cblkno; /* offset of cyl-block in filesys */
+ daddr_t fs_iblkno; /* offset of inode-blocks in filesys */
+ daddr_t fs_dblkno; /* offset of first data after cg */
+ long fs_cgoffset; /* cylinder group offset in cylinder */
+ long fs_cgmask; /* used to calc mod fs_ntrak */
+ time_t fs_time; /* last time written */
+ long fs_size; /* number of blocks in fs */
+ long fs_dsize; /* number of data blocks in fs */
+ long fs_ncg; /* number of cylinder groups */
+ long fs_bsize; /* size of basic blocks in fs */
+ long fs_fsize; /* size of frag blocks in fs */
+ long fs_frag; /* number of frags in a block in fs */
+/* these are configuration parameters */
+ long fs_minfree; /* minimum percentage of free blocks */
+ long fs_rotdelay; /* num of ms for optimal next block */
+ long fs_rps; /* disk revolutions per second */
+/* these fields can be computed from the others */
+ long fs_bmask; /* ``blkoff'' calc of blk offsets */
+ long fs_fmask; /* ``fragoff'' calc of frag offsets */
+ long fs_bshift; /* ``lblkno'' calc of logical blkno */
+ long fs_fshift; /* ``numfrags'' calc number of frags */
+/* these are configuration parameters */
+ long fs_maxcontig; /* max number of contiguous blks */
+ long fs_maxbpg; /* max number of blks per cyl group */
+/* these fields can be computed from the others */
+ long fs_fragshift; /* block to frag shift */
+ long fs_fsbtodb; /* fsbtodb and dbtofsb shift constant */
+ long fs_sbsize; /* actual size of super block */
+ long fs_csmask; /* csum block offset */
+ long fs_csshift; /* csum block number */
+ long fs_nindir; /* value of NINDIR */
+ long fs_inopb; /* value of INOPB */
+ long fs_nspf; /* value of NSPF */
+/* yet another configuration parameter */
+ long fs_optim; /* optimization preference, see below */
+/* these fields are derived from the hardware */
+ long fs_npsect; /* # sectors/track including spares */
+ long fs_interleave; /* hardware sector interleave */
+ long fs_trackskew; /* sector 0 skew, per track */
+ long fs_headswitch; /* head switch time, usec */
+ long fs_trkseek; /* track-to-track seek, usec */
+/* sizes determined by number of cylinder groups and their sizes */
+ daddr_t fs_csaddr; /* blk addr of cyl grp summary area */
+ long fs_cssize; /* size of cyl grp summary area */
+ long fs_cgsize; /* cylinder group size */
+/* these fields are derived from the hardware */
+ long fs_ntrak; /* tracks per cylinder */
+ long fs_nsect; /* sectors per track */
+ long fs_spc; /* sectors per cylinder */
+/* this comes from the disk driver partitioning */
+ long fs_ncyl; /* cylinders in file system */
+/* these fields can be computed from the others */
+ long fs_cpg; /* cylinders per group */
+ long fs_ipg; /* inodes per group */
+ long fs_fpg; /* blocks per group * fs_frag */
+/* this data must be re-computed after crashes */
+ struct csum fs_cstotal; /* cylinder summary information */
+/* these fields are cleared at mount time */
+ char fs_fmod; /* super block modified flag */
+ char fs_clean; /* file system is clean flag */
+ char fs_ronly; /* mounted read-only flag */
+ char fs_flags; /* currently unused flag */
+ char fs_fsmnt[MAXMNTLEN]; /* name mounted on */
+/* these fields retain the current block allocation info */
+ long fs_cgrotor; /* last cg searched */
+ struct csum *fs_csp[MAXCSBUFS];/* list of fs_cs info buffers */
+ long fs_cpc; /* cyl per cycle in postbl */
+ short fs_opostbl[16][8]; /* old rotation block list head */
+ long fs_sparecon[50]; /* reserved for future constants */
+ long fs_contigsumsize; /* size of cluster summary array */
+ long fs_maxsymlinklen; /* max length of an internal symlink */
+ long fs_inodefmt; /* format of on-disk inodes */
+ u_quad_t fs_maxfilesize; /* maximum representable file size */
+ quad_t fs_qbmask; /* ~fs_bmask - for use with quad size */
+ quad_t fs_qfmask; /* ~fs_fmask - for use with quad size */
+ long fs_state; /* validate fs_clean field */
+ long fs_postblformat; /* format of positional layout tables */
+ long fs_nrpos; /* number of rotational positions */
+ long fs_postbloff; /* (short) rotation block list head */
+ long fs_rotbloff; /* (u_char) blocks for each rotation */
+ long fs_magic; /* magic number */
+ u_char fs_space[1]; /* list of blocks for each rotation */
+/* actually longer */
+};
+/*
+ * Filesystem idetification
+ */
+#define FS_MAGIC 0x011954 /* the fast filesystem magic number */
+#define FS_OKAY 0x7c269d38 /* superblock checksum */
+#define FS_42INODEFMT -1 /* 4.2BSD inode format */
+#define FS_44INODEFMT 2 /* 4.4BSD inode format */
+/*
+ * Preference for optimization.
+ */
+#define FS_OPTTIME 0 /* minimize allocation time */
+#define FS_OPTSPACE 1 /* minimize disk fragmentation */
+
+/*
+ * Rotational layout table format types
+ */
+#define FS_42POSTBLFMT -1 /* 4.2BSD rotational table format */
+#define FS_DYNAMICPOSTBLFMT 1 /* dynamic rotational table format */
+/*
+ * Macros for access to superblock array structures
+ */
+#define fs_postbl(fs, cylno) \
+ (((fs)->fs_postblformat == FS_42POSTBLFMT) \
+ ? ((fs)->fs_opostbl[cylno]) \
+ : ((short *)((char *)(fs) + (fs)->fs_postbloff) + (cylno) * (fs)->fs_nrpos))
+#define fs_rotbl(fs) \
+ (((fs)->fs_postblformat == FS_42POSTBLFMT) \
+ ? ((fs)->fs_space) \
+ : ((u_char *)((char *)(fs) + (fs)->fs_rotbloff)))
+
+/*
+ * The size of a cylinder group is calculated by CGSIZE. The maximum size
+ * is limited by the fact that cylinder groups are at most one block.
+ * Its size is derived from the size of the maps maintained in the
+ * cylinder group and the (struct cg) size.
+ */
+#define CGSIZE(fs) \
+ /* base cg */ (sizeof(struct cg) + sizeof(long) + \
+ /* blktot size */ (fs)->fs_cpg * sizeof(long) + \
+ /* blks size */ (fs)->fs_cpg * (fs)->fs_nrpos * sizeof(short) + \
+ /* inode map */ howmany((fs)->fs_ipg, NBBY) + \
+ /* block map */ howmany((fs)->fs_cpg * (fs)->fs_spc / NSPF(fs), NBBY) +\
+ /* if present */ ((fs)->fs_contigsumsize <= 0 ? 0 : \
+ /* cluster sum */ (fs)->fs_contigsumsize * sizeof(long) + \
+ /* cluster map */ howmany((fs)->fs_cpg * (fs)->fs_spc / NSPB(fs), NBBY)))
+
+#if 0 /* Wrong for GNU Hurd ufs; we don't use fs_csp at all. */
+/*
+ * Convert cylinder group to base address of its global summary info.
+ *
+ * N.B. This macro assumes that sizeof(struct csum) is a power of two.
+ */
+#define fs_cs(fs, indx) \
+ fs_csp[(indx) >> (fs)->fs_csshift][(indx) & ~(fs)->fs_csmask]
+#else
+/* Global variable csum is declared in ufs.h; use it instead
+ of fs_cs stuff. */
+#define fs_cs(fs, indx) this will generate a syntax error.
+#endif
+
+/*
+ * Cylinder group block for a file system.
+ */
+#define CG_MAGIC 0x090255
+struct cg {
+ struct cg *cg_link; /* linked list of cyl groups */
+ long cg_magic; /* magic number */
+ time_t cg_time; /* time last written */
+ long cg_cgx; /* we are the cgx'th cylinder group */
+ short cg_ncyl; /* number of cyl's this cg */
+ short cg_niblk; /* number of inode blocks this cg */
+ long cg_ndblk; /* number of data blocks this cg */
+ struct csum cg_cs; /* cylinder summary information */
+ long cg_rotor; /* position of last used block */
+ long cg_frotor; /* position of last used frag */
+ long cg_irotor; /* position of last used inode */
+ long cg_frsum[MAXFRAG]; /* counts of available frags */
+ long cg_btotoff; /* (long) block totals per cylinder */
+ long cg_boff; /* (short) free block positions */
+ long cg_iusedoff; /* (char) used inode map */
+ long cg_freeoff; /* (u_char) free block map */
+ long cg_nextfreeoff; /* (u_char) next available space */
+ long cg_clustersumoff; /* (long) counts of avail clusters */
+ long cg_clusteroff; /* (char) free cluster map */
+ long cg_nclusterblks; /* number of clusters this cg */
+ long cg_sparecon[13]; /* reserved for future use */
+ u_char cg_space[1]; /* space for cylinder group maps */
+/* actually longer */
+};
+/*
+ * Macros for access to cylinder group array structures
+ */
+#define cg_blktot(cgp) \
+ (((cgp)->cg_magic != CG_MAGIC) \
+ ? (((struct ocg *)(cgp))->cg_btot) \
+ : ((long *)((char *)(cgp) + (cgp)->cg_btotoff)))
+#define cg_blks(fs, cgp, cylno) \
+ (((cgp)->cg_magic != CG_MAGIC) \
+ ? (((struct ocg *)(cgp))->cg_b[cylno]) \
+ : ((short *)((char *)(cgp) + (cgp)->cg_boff) + (cylno) * (fs)->fs_nrpos))
+#define cg_inosused(cgp) \
+ (((cgp)->cg_magic != CG_MAGIC) \
+ ? (((struct ocg *)(cgp))->cg_iused) \
+ : ((char *)((char *)(cgp) + (cgp)->cg_iusedoff)))
+#define cg_blksfree(cgp) \
+ (((cgp)->cg_magic != CG_MAGIC) \
+ ? (((struct ocg *)(cgp))->cg_free) \
+ : ((u_char *)((char *)(cgp) + (cgp)->cg_freeoff)))
+#define cg_chkmagic(cgp) \
+ ((cgp)->cg_magic == CG_MAGIC || ((struct ocg *)(cgp))->cg_magic == CG_MAGIC)
+#define cg_clustersfree(cgp) \
+ ((u_char *)((char *)(cgp) + (cgp)->cg_clusteroff))
+#define cg_clustersum(cgp) \
+ ((long *)((char *)(cgp) + (cgp)->cg_clustersumoff))
+
+/*
+ * The following structure is defined
+ * for compatibility with old file systems.
+ */
+struct ocg {
+ struct ocg *cg_link; /* linked list of cyl groups */
+ struct ocg *cg_rlink; /* used for incore cyl groups */
+ time_t cg_time; /* time last written */
+ long cg_cgx; /* we are the cgx'th cylinder group */
+ short cg_ncyl; /* number of cyl's this cg */
+ short cg_niblk; /* number of inode blocks this cg */
+ long cg_ndblk; /* number of data blocks this cg */
+ struct csum cg_cs; /* cylinder summary information */
+ long cg_rotor; /* position of last used block */
+ long cg_frotor; /* position of last used frag */
+ long cg_irotor; /* position of last used inode */
+ long cg_frsum[8]; /* counts of available frags */
+ long cg_btot[32]; /* block totals per cylinder */
+ short cg_b[32][8]; /* positions of free blocks */
+ char cg_iused[256]; /* used inode map */
+ long cg_magic; /* magic number */
+ u_char cg_free[1]; /* free block map */
+/* actually longer */
+};
+
+/*
+ * Turn file system block numbers into disk block addresses.
+ * This maps file system blocks to device size blocks.
+ */
+#define fsbtodb(fs, b) ((b) << (fs)->fs_fsbtodb)
+#define dbtofsb(fs, b) ((b) >> (fs)->fs_fsbtodb)
+
+/*
+ * Cylinder group macros to locate things in cylinder groups.
+ * They calc file system addresses of cylinder group data structures.
+ */
+#define cgbase(fs, c) ((daddr_t)((fs)->fs_fpg * (c)))
+#define cgdmin(fs, c) (cgstart(fs, c) + (fs)->fs_dblkno) /* 1st data */
+#define cgimin(fs, c) (cgstart(fs, c) + (fs)->fs_iblkno) /* inode blk */
+#define cgsblock(fs, c) (cgstart(fs, c) + (fs)->fs_sblkno) /* super blk */
+#define cgtod(fs, c) (cgstart(fs, c) + (fs)->fs_cblkno) /* cg block */
+#define cgstart(fs, c) \
+ (cgbase(fs, c) + (fs)->fs_cgoffset * ((c) & ~((fs)->fs_cgmask)))
+
+/*
+ * Macros for handling inode numbers:
+ * inode number to file system block offset.
+ * inode number to cylinder group number.
+ * inode number to file system block address.
+ */
+#define ino_to_cg(fs, x) ((x) / (fs)->fs_ipg)
+#define ino_to_fsba(fs, x) \
+ ((daddr_t)(cgimin(fs, ino_to_cg(fs, x)) + \
+ (blkstofrags((fs), (((x) % (fs)->fs_ipg) / INOPB(fs))))))
+#define ino_to_fsbo(fs, x) ((x) % INOPB(fs))
+
+/*
+ * Give cylinder group number for a file system block.
+ * Give cylinder group block number for a file system block.
+ */
+#define dtog(fs, d) ((d) / (fs)->fs_fpg)
+#define dtogd(fs, d) ((d) % (fs)->fs_fpg)
+
+/*
+ * Extract the bits for a block from a map.
+ * Compute the cylinder and rotational position of a cyl block addr.
+ */
+#define blkmap(fs, map, loc) \
+ (((map)[(loc) / NBBY] >> ((loc) % NBBY)) & (0xff >> (NBBY - (fs)->fs_frag)))
+#define cbtocylno(fs, bno) \
+ ((bno) * NSPF(fs) / (fs)->fs_spc)
+#define cbtorpos(fs, bno) \
+ (((bno) * NSPF(fs) % (fs)->fs_spc / (fs)->fs_nsect * (fs)->fs_trackskew + \
+ (bno) * NSPF(fs) % (fs)->fs_spc % (fs)->fs_nsect * (fs)->fs_interleave) % \
+ (fs)->fs_nsect * (fs)->fs_nrpos / (fs)->fs_npsect)
+
+/*
+ * The following macros optimize certain frequently calculated
+ * quantities by using shifts and masks in place of divisions
+ * modulos and multiplications.
+ */
+#define blkoff(fs, loc) /* calculates (loc % fs->fs_bsize) */ \
+ ((loc) & (fs)->fs_qbmask)
+#define fragoff(fs, loc) /* calculates (loc % fs->fs_fsize) */ \
+ ((loc) & (fs)->fs_qfmask)
+#define lblktosize(fs, blk) /* calculates (blk * fs->fs_bsize) */ \
+ ((blk) << (fs)->fs_bshift)
+#define lblkno(fs, loc) /* calculates (loc / fs->fs_bsize) */ \
+ ((loc) >> (fs)->fs_bshift)
+#define numfrags(fs, loc) /* calculates (loc / fs->fs_fsize) */ \
+ ((loc) >> (fs)->fs_fshift)
+#define blkroundup(fs, size) /* calculates roundup(size, fs->fs_bsize) */ \
+ (((size) + (fs)->fs_qbmask) & (fs)->fs_bmask)
+#define fragroundup(fs, size) /* calculates roundup(size, fs->fs_fsize) */ \
+ (((size) + (fs)->fs_qfmask) & (fs)->fs_fmask)
+#define fragstoblks(fs, frags) /* calculates (frags / fs->fs_frag) */ \
+ ((frags) >> (fs)->fs_fragshift)
+#define blkstofrags(fs, blks) /* calculates (blks * fs->fs_frag) */ \
+ ((blks) << (fs)->fs_fragshift)
+#define fragnum(fs, fsb) /* calculates (fsb % fs->fs_frag) */ \
+ ((fsb) & ((fs)->fs_frag - 1))
+#define blknum(fs, fsb) /* calculates rounddown(fsb, fs->fs_frag) */ \
+ ((fsb) &~ ((fs)->fs_frag - 1))
+
+/*
+ * Determine the number of available frags given a
+ * percentage to hold in reserve
+ */
+#define freespace(fs, percentreserved) \
+ (blkstofrags((fs), (fs)->fs_cstotal.cs_nbfree) + \
+ (fs)->fs_cstotal.cs_nffree - ((fs)->fs_dsize * (percentreserved) / 100))
+
+/*
+ * Determining the size of a file block in the file system.
+ */
+/* Changed from BSD to use allocsize instead of i_size. */
+#define blksize(fs, np, lbn) \
+ (((lbn) >= NDADDR || (np)->allocsize >= ((lbn) + 1) << (fs)->fs_bshift) \
+ ? (fs)->fs_bsize \
+ : (fragroundup(fs, blkoff(fs, (np)->allocsize))))
+
+#if 0 /* Don't use this */
+#define dblksize(fs, dip, lbn) \
+ (((lbn) >= NDADDR || (dip)->di_size >= ((lbn) + 1) << (fs)->fs_bshift) \
+ ? (fs)->fs_bsize \
+ : (fragroundup(fs, blkoff(fs, (dip)->di_size))))
+#endif
+
+/*
+ * Number of disk sectors per block; assumes DEV_BSIZE byte sector size.
+ */
+#define NSPB(fs) ((fs)->fs_nspf << (fs)->fs_fragshift)
+#define NSPF(fs) ((fs)->fs_nspf)
+
+/*
+ * INOPB is the number of inodes in a secondary storage block.
+ */
+#define INOPB(fs) ((fs)->fs_inopb)
+#define INOPF(fs) ((fs)->fs_inopb >> (fs)->fs_fragshift)
+
+/*
+ * NINDIR is the number of indirects in a file system block.
+ */
+#define NINDIR(fs) ((fs)->fs_nindir)
+
+extern int inside[], around[];
+extern u_char *fragtbl[];
diff --git a/ufs/hyper.c b/ufs/hyper.c
new file mode 100644
index 00000000..ece327a2
--- /dev/null
+++ b/ufs/hyper.c
@@ -0,0 +1,414 @@
+/* Fetching and storing the hypermetadata (superblock and cg summary info).
+ Copyright (C) 1994, 95, 96, 97, 98, 1999 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#include "ufs.h"
+#include <string.h>
+#include <stdio.h>
+#include <error.h>
+#include <hurd/store.h>
+
+static int ufs_clean; /* fs clean before we started writing? */
+
+static int oldformat;
+
+void *zeroblock;
+
+struct fs *sblock;
+struct csum *csum;
+
+void
+swab_sblock (struct fs *sblock)
+{
+ int i, j;
+
+ sblock->fs_sblkno = swab_long (sblock->fs_sblkno);
+ sblock->fs_cblkno = swab_long (sblock->fs_cblkno);
+ sblock->fs_iblkno = swab_long (sblock->fs_iblkno);
+ sblock->fs_dblkno = swab_long (sblock->fs_dblkno);
+ sblock->fs_cgoffset = swab_long (sblock->fs_cgoffset);
+ sblock->fs_cgmask = swab_long (sblock->fs_cgmask);
+ sblock->fs_time = swab_long (sblock->fs_time);
+ sblock->fs_size = swab_long (sblock->fs_size);
+ sblock->fs_dsize = swab_long (sblock->fs_dsize);
+ sblock->fs_ncg = swab_long (sblock->fs_ncg);
+ sblock->fs_bsize = swab_long (sblock->fs_bsize);
+ sblock->fs_fsize = swab_long (sblock->fs_fsize);
+ sblock->fs_frag = swab_long (sblock->fs_frag);
+ sblock->fs_minfree = swab_long (sblock->fs_minfree);
+ sblock->fs_rotdelay = swab_long (sblock->fs_rotdelay);
+ sblock->fs_rps = swab_long (sblock->fs_rps);
+ sblock->fs_bmask = swab_long (sblock->fs_bmask);
+ sblock->fs_fmask = swab_long (sblock->fs_fmask);
+ sblock->fs_bshift = swab_long (sblock->fs_bshift);
+ sblock->fs_fshift = swab_long (sblock->fs_fshift);
+ sblock->fs_maxcontig = swab_long (sblock->fs_maxcontig);
+ sblock->fs_maxbpg = swab_long (sblock->fs_maxbpg);
+ sblock->fs_fragshift = swab_long (sblock->fs_fragshift);
+ sblock->fs_fsbtodb = swab_long (sblock->fs_fsbtodb);
+ sblock->fs_sbsize = swab_long (sblock->fs_sbsize);
+ sblock->fs_csmask = swab_long (sblock->fs_csmask);
+ sblock->fs_csshift = swab_long (sblock->fs_csshift);
+ sblock->fs_nindir = swab_long (sblock->fs_nindir);
+ sblock->fs_inopb = swab_long (sblock->fs_inopb);
+ sblock->fs_nspf = swab_long (sblock->fs_nspf);
+ sblock->fs_optim = swab_long (sblock->fs_optim);
+ sblock->fs_npsect = swab_long (sblock->fs_npsect);
+ sblock->fs_interleave = swab_long (sblock->fs_interleave);
+ sblock->fs_trackskew = swab_long (sblock->fs_trackskew);
+ sblock->fs_headswitch = swab_long (sblock->fs_headswitch);
+ sblock->fs_trkseek = swab_long (sblock->fs_trkseek);
+ sblock->fs_csaddr = swab_long (sblock->fs_csaddr);
+ sblock->fs_cssize = swab_long (sblock->fs_cssize);
+ sblock->fs_cgsize = swab_long (sblock->fs_cgsize);
+ sblock->fs_ntrak = swab_long (sblock->fs_ntrak);
+ sblock->fs_nsect = swab_long (sblock->fs_nsect);
+ sblock->fs_spc = swab_long (sblock->fs_spc);
+ sblock->fs_ncyl = swab_long (sblock->fs_ncyl);
+ sblock->fs_cpg = swab_long (sblock->fs_cpg);
+ sblock->fs_ipg = swab_long (sblock->fs_ipg);
+ sblock->fs_fpg = swab_long (sblock->fs_fpg);
+ sblock->fs_cstotal.cs_ndir = swab_long (sblock->fs_cstotal.cs_ndir);
+ sblock->fs_cstotal.cs_nbfree = swab_long (sblock->fs_cstotal.cs_nbfree);
+ sblock->fs_cstotal.cs_nifree = swab_long (sblock->fs_cstotal.cs_nifree);
+ sblock->fs_cstotal.cs_nffree = swab_long (sblock->fs_cstotal.cs_nffree);
+ /* fs_fmod, fs_clean, fs_ronly, fs_flags, fs_fsmnt are all char */
+ sblock->fs_cgrotor = swab_long (sblock->fs_cgrotor);
+ sblock->fs_cpc = swab_long (sblock->fs_cpc);
+ sblock->fs_contigsumsize = swab_long (sblock->fs_contigsumsize);
+ sblock->fs_maxsymlinklen = swab_long (sblock->fs_maxsymlinklen);
+ sblock->fs_inodefmt = swab_long (sblock->fs_inodefmt);
+ sblock->fs_maxfilesize = swab_long_long (sblock->fs_maxfilesize);
+ sblock->fs_qbmask = swab_long_long (sblock->fs_qbmask);
+ sblock->fs_state = swab_long (sblock->fs_state);
+ sblock->fs_postblformat = swab_long (sblock->fs_postblformat);
+ sblock->fs_nrpos = swab_long (sblock->fs_nrpos);
+ sblock->fs_postbloff = swab_long (sblock->fs_postbloff);
+ sblock->fs_rotbloff = swab_long (sblock->fs_rotbloff);
+ sblock->fs_magic = swab_long (sblock->fs_magic);
+
+ /* Tables */
+ if (sblock->fs_postblformat == FS_42POSTBLFMT)
+ for (i = 0; i < 16; i++)
+ for (j = 0; j < 8; j++)
+ sblock->fs_opostbl[i][j] = swab_short (sblock->fs_opostbl[i][j]);
+ else
+ for (i = 0; i < sblock->fs_cpc; i++)
+ for (j = 0; j < sblock->fs_nrpos; j++)
+ fs_postbl(sblock, j)[i]
+ = swab_short (fs_postbl (sblock, j)[i]);
+
+ /* The rot table is all chars */
+}
+
+void
+swab_csums (struct csum *csum)
+{
+ int i;
+
+ for (i = 0; i < sblock->fs_ncg; i++)
+ {
+ csum[i].cs_ndir = swab_long (csum[i].cs_ndir);
+ csum[i].cs_nbfree = swab_long (csum[i].cs_nbfree);
+ csum[i].cs_nifree = swab_long (csum[i].cs_nifree);
+ csum[i].cs_nffree = swab_long (csum[i].cs_nffree);
+ }
+}
+
+void
+get_hypermetadata (void)
+{
+ error_t err;
+
+ if (!sblock)
+ sblock = malloc (SBSIZE);
+
+ /* Free previous values. */
+ if (zeroblock)
+ munmap ((caddr_t) zeroblock, sblock->fs_bsize);
+ if (csum)
+ free (csum);
+
+ err = diskfs_catch_exception ();
+ assert_perror (err);
+ bcopy (disk_image + SBOFF, sblock, SBSIZE);
+ diskfs_end_catch_exception ();
+
+ if ((swab_long (sblock->fs_magic)) == FS_MAGIC)
+ {
+ swab_disk = 1;
+ swab_sblock (sblock);
+ }
+ else
+ swab_disk = 0;
+
+ if (sblock->fs_magic != FS_MAGIC)
+ {
+ fprintf (stderr, "Bad magic number %#lx (should be %#x)\n",
+ sblock->fs_magic, FS_MAGIC);
+ exit (1);
+ }
+ if (sblock->fs_bsize > 8192)
+ {
+ fprintf (stderr, "Block size %ld is too big (max is 8192 bytes)\n",
+ sblock->fs_bsize);
+ exit (1);
+ }
+ if (sblock->fs_bsize < sizeof (struct fs))
+ {
+ fprintf (stderr, "Block size %ld is too small (min is %Zd bytes)\n",
+ sblock->fs_bsize, sizeof (struct fs));
+ exit (1);
+ }
+
+ if (sblock->fs_maxsymlinklen > (long)MAXSYMLINKLEN)
+ {
+ fprintf (stderr, "Max shortcut symlinklen %ld is too big (max is %ld)\n",
+ sblock->fs_maxsymlinklen, (long)MAXSYMLINKLEN);
+ exit (1);
+ }
+
+ assert ((__vm_page_size % DEV_BSIZE) == 0);
+ assert ((sblock->fs_bsize % DEV_BSIZE) == 0);
+ assert (__vm_page_size <= sblock->fs_bsize);
+
+ /* Examine the clean bit and force read-only if unclean. */
+ ufs_clean = sblock->fs_clean;
+ if (! ufs_clean)
+ {
+ error (0, 0,
+ "%s: warning: FILESYSTEM NOT UNMOUNTED CLEANLY; PLEASE fsck",
+ diskfs_disk_name);
+ if (! diskfs_readonly)
+ {
+ diskfs_readonly = 1;
+ error (0, 0,
+ "%s: MOUNTED READ-ONLY; MUST USE `fsysopts --writable'",
+ diskfs_disk_name);
+ }
+ }
+
+ /* If this is an old filesystem, then we have some more
+ work to do; some crucial constants might not be set; we
+ are therefore forced to set them here. */
+
+ if (sblock->fs_npsect < sblock->fs_nsect)
+ sblock->fs_npsect = sblock->fs_nsect;
+
+ if (sblock->fs_interleave < 1)
+ sblock->fs_interleave = 1;
+
+ if (sblock->fs_postblformat == FS_42POSTBLFMT)
+ sblock->fs_nrpos = 8;
+
+ if (sblock->fs_inodefmt < FS_44INODEFMT)
+ {
+ quad_t sizepb = sblock->fs_bsize;
+ int i;
+
+ oldformat = 1;
+ sblock->fs_maxfilesize = sblock->fs_bsize * NDADDR - 1;
+ for (i = 0; i < NIADDR; i++)
+ {
+ sizepb *= NINDIR (sblock);
+ sblock->fs_maxfilesize += sizepb;
+ }
+ sblock->fs_qbmask = ~sblock->fs_bmask;
+ sblock->fs_qfmask = ~sblock->fs_fmask;
+ }
+
+ /* Find out if we support the 4.4 symlink/dirtype extension */
+ if (sblock->fs_maxsymlinklen > 0)
+ direct_symlink_extension = 1;
+ else
+ direct_symlink_extension = 0;
+
+ csum = malloc (fsaddr (sblock, howmany (sblock->fs_cssize,
+ sblock->fs_fsize)));
+
+ assert (!diskfs_catch_exception ());
+ bcopy (disk_image + fsaddr (sblock, sblock->fs_csaddr),
+ csum,
+ fsaddr (sblock, howmany (sblock->fs_cssize, sblock->fs_fsize)));
+ diskfs_end_catch_exception ();
+
+ if (swab_disk)
+ swab_csums (csum);
+
+ if (store->size < sblock->fs_size * sblock->fs_fsize)
+ {
+ fprintf (stderr,
+ "Disk size (%Ld) less than necessary "
+ "(superblock says we need %ld)\n",
+ store->size, sblock->fs_size * sblock->fs_fsize);
+ exit (1);
+ }
+
+ zeroblock = mmap (0, sblock->fs_bsize, PROT_READ|PROT_WRITE, MAP_ANON, 0, 0);
+
+ /* If the filesystem has new features in it, don't pay attention to
+ the user's request not to use them. */
+ if ((sblock->fs_inodefmt == FS_44INODEFMT
+ || direct_symlink_extension)
+ && compat_mode == COMPAT_BSD42)
+ {
+ compat_mode = COMPAT_BSD44;
+ error (0, 0,
+ "4.2 compat mode requested on 4.4 fs--switched to 4.4 mode");
+ }
+}
+
+/* Write the csum data. This isn't backed by a pager because it is
+ taken from ordinary data blocks and might not be an even number
+ of pages; in that case writing it through the pager would nuke whatever
+ pages came after it on the disk and were backed by file pagers. */
+error_t
+diskfs_set_hypermetadata (int wait, int clean)
+{
+ error_t err;
+
+ spin_lock (&alloclock);
+
+ if (csum_dirty)
+ {
+ /* Copy into a page-aligned buffer to avoid bugs in kernel device
+ code. */
+ void *buf = 0;
+ size_t read = 0;
+ size_t bufsize = round_page (fragroundup (sblock, sblock->fs_cssize));
+
+ err = store_read (store,
+ fsbtodb (sblock, sblock->fs_csaddr)
+ << log2_dev_blocks_per_dev_bsize,
+ bufsize, &buf, &read);
+ if (err)
+ return err;
+ else if (read != bufsize)
+ err = EIO;
+ else
+ {
+ size_t wrote;
+ bcopy (csum, buf, sblock->fs_cssize);
+ if (swab_disk)
+ swab_csums ((struct csum *)buf);
+ err = store_write (store,
+ fsbtodb (sblock, sblock->fs_csaddr)
+ << log2_dev_blocks_per_dev_bsize,
+ buf, bufsize, &wrote);
+ if (!err && wrote != bufsize)
+ err = EIO;
+ }
+
+ munmap (buf, read);
+
+ if (err)
+ {
+ spin_unlock (&alloclock);
+ return err;
+ }
+
+ csum_dirty = 0;
+ }
+
+ if (clean && ufs_clean && !sblock->fs_clean)
+ {
+ /* The filesystem is clean, so set the clean flag. */
+ sblock->fs_clean = 1;
+ sblock_dirty = 1;
+ }
+ else if (!clean && sblock->fs_clean)
+ {
+ /* Clear the clean flag */
+ sblock->fs_clean = 0;
+ sblock_dirty = 1;
+ wait = 1; /* must be synchronous */
+ }
+
+ spin_unlock (&alloclock);
+
+ /* Update the superblock if necessary (clean bit was just set). */
+ copy_sblock ();
+
+ sync_disk (wait);
+ return 0;
+}
+
+/* Copy the sblock into the disk */
+void
+copy_sblock ()
+{
+ error_t err;
+
+ err = diskfs_catch_exception ();
+ assert_perror (err);
+
+ spin_lock (&alloclock);
+
+ if (sblock_dirty)
+ {
+ assert (! diskfs_readonly);
+
+ if (sblock->fs_postblformat == FS_42POSTBLFMT
+ || oldformat
+ || swab_disk)
+ {
+ char sblockcopy[SBSIZE];
+ struct fs *sbcopy = (struct fs *)sblockcopy;
+ bcopy (sblock, sblockcopy, SBSIZE);
+ if (sblock->fs_postblformat == FS_42POSTBLFMT)
+ sbcopy->fs_nrpos = -1;
+ if (oldformat)
+ {
+ sbcopy->fs_maxfilesize = -1;
+ sbcopy->fs_qbmask = -1;
+ sbcopy->fs_qfmask = -1;
+ }
+ if (swab_disk)
+ swab_sblock (sbcopy);
+ bcopy (sbcopy, disk_image + SBOFF, SBSIZE);
+ }
+ else
+ bcopy (sblock, disk_image + SBOFF, SBSIZE);
+ record_poke (disk_image + SBOFF, SBSIZE);
+ sblock_dirty = 0;
+ }
+
+ spin_unlock (&alloclock);
+
+ diskfs_end_catch_exception ();
+}
+
+void
+diskfs_readonly_changed (int readonly)
+{
+ (*(readonly ? store_set_flags : store_clear_flags)) (store, STORE_READONLY);
+
+ mprotect (disk_image, store->size, PROT_READ | (readonly ? 0 : PROT_WRITE));
+
+ if (readonly)
+ {
+ /* We know we are sync'd now. The superblock is marked as dirty
+ because we cleared the clean flag immediately after sync'ing.
+ But now we want to leave it marked clean and not touch it further. */
+ sblock_dirty = 0;
+ return;
+ }
+
+ strcpy (sblock->fs_fsmnt, "Hurd /"); /* XXX */
+
+ if (!sblock->fs_clean)
+ error (0, 0, "WARNING: UNCLEANED FILESYSTEM NOW WRITABLE");
+}
diff --git a/ufs/inode.c b/ufs/inode.c
new file mode 100644
index 00000000..77a45edb
--- /dev/null
+++ b/ufs/inode.c
@@ -0,0 +1,703 @@
+/* Inode management routines
+
+ Copyright (C) 1994, 1995, 1996, 1997, 1998, 2000, 2001, 2002, 2007
+ Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#include "ufs.h"
+#include <string.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <netinet/in.h>
+#include <fcntl.h>
+#include <hurd/store.h>
+
+#define INOHSZ 512
+#if ((INOHSZ&(INOHSZ-1)) == 0)
+#define INOHASH(ino) ((ino)&(INOHSZ-1))
+#else
+#define INOHASH(ino) (((unsigned)(ino))%INOHSZ)
+#endif
+
+static struct node *nodehash[INOHSZ];
+static error_t read_disknode (struct node *np);
+
+spin_lock_t gennumberlock = SPIN_LOCK_INITIALIZER;
+
+/* Initialize the inode hash table. */
+void
+inode_init ()
+{
+ int n;
+ for (n = 0; n < INOHSZ; n++)
+ nodehash[n] = 0;
+}
+
+/* Fetch inode INUM, set *NPP to the node structure;
+ gain one user reference and lock the node. */
+error_t
+diskfs_cached_lookup (ino_t inum, struct node **npp)
+{
+ struct disknode *dn;
+ struct node *np;
+ error_t err;
+
+ spin_lock (&diskfs_node_refcnt_lock);
+ for (np = nodehash[INOHASH(inum)]; np; np = np->dn->hnext)
+ {
+ if (np->dn->number != inum)
+ continue;
+
+ np->references++;
+ spin_unlock (&diskfs_node_refcnt_lock);
+ mutex_lock (&np->lock);
+ *npp = np;
+ return 0;
+ }
+
+ dn = malloc (sizeof (struct disknode));
+
+ dn->number = inum;
+ dn->dirents = 0;
+ dn->dir_idx = 0;
+
+ rwlock_init (&dn->allocptrlock);
+ dn->dirty = 0;
+ dn->fileinfo = 0;
+
+ np = diskfs_make_node (dn);
+ np->cache_id = inum;
+
+ mutex_lock (&np->lock);
+ dn->hnext = nodehash[INOHASH(inum)];
+ if (dn->hnext)
+ dn->hnext->dn->hprevp = &dn->hnext;
+ dn->hprevp = &nodehash[INOHASH(inum)];
+ nodehash[INOHASH(inum)] = np;
+ spin_unlock (&diskfs_node_refcnt_lock);
+
+ err = read_disknode (np);
+
+ if (!diskfs_check_readonly () && !np->dn_stat.st_gen)
+ {
+ spin_lock (&gennumberlock);
+ if (++nextgennumber < diskfs_mtime->seconds)
+ nextgennumber = diskfs_mtime->seconds;
+ np->dn_stat.st_gen = nextgennumber;
+ spin_unlock (&gennumberlock);
+ np->dn_set_ctime = 1;
+ }
+
+ if (err)
+ return err;
+ else
+ {
+ *npp = np;
+ return 0;
+ }
+}
+
+/* Lookup node INUM (which must have a reference already) and return it
+ without allocating any new references. */
+struct node *
+ifind (ino_t inum)
+{
+ struct node *np;
+
+ spin_lock (&diskfs_node_refcnt_lock);
+ for (np = nodehash[INOHASH(inum)]; np; np = np->dn->hnext)
+ {
+ if (np->dn->number != inum)
+ continue;
+
+ assert (np->references);
+ spin_unlock (&diskfs_node_refcnt_lock);
+ return np;
+ }
+ assert (0);
+}
+
+/* The last reference to a node has gone away; drop
+ it from the hash table and clean all state in the dn structure. */
+void
+diskfs_node_norefs (struct node *np)
+{
+ *np->dn->hprevp = np->dn->hnext;
+ if (np->dn->hnext)
+ np->dn->hnext->dn->hprevp = np->dn->hprevp;
+ if (np->dn->dirents)
+ free (np->dn->dirents);
+ assert (!np->dn->fileinfo);
+ free (np->dn);
+ free (np);
+}
+
+/* The last hard reference to a node has gone away; arrange to have
+ all the weak references dropped that can be. */
+void
+diskfs_try_dropping_softrefs (struct node *np)
+{
+ drop_pager_softrefs (np);
+}
+
+/* The last hard reference to a node has gone away. */
+void
+diskfs_lost_hardrefs (struct node *np)
+{
+#ifdef notanymore
+ struct port_info *pi;
+ struct pager *p;
+
+ /* Check and see if there is a pager which has only
+ one reference (ours). If so, then drop that reference,
+ breaking the cycle. The complexity in this routine
+ is all due to this cycle. */
+
+ if (np->dn->fileinfo)
+ {
+ spin_lock (&_libports_portrefcntlock);
+ pi = (struct port_info *) np->dn->fileinfo->p;
+ if (pi->refcnt == 1)
+ {
+
+ /* The only way to get a new reference to the pager
+ in this state is to call diskfs_get_filemap; this
+ can't happen as long as we hold NP locked. So
+ we can safely unlock _libports_portrefcntlock for
+ the following call. */
+ spin_unlock (&_libports_portrefcntlock);
+
+ /* Right now the node is locked with no hard refs;
+ this is an anomalous situation. Before messing with
+ the reference count on the file pager, we have to
+ give ourselves a reference back so that we are really
+ allowed to hold the lock. Then we can do the
+ unreference. */
+ p = np->dn->fileinfo->p;
+ np->dn->fileinfo = 0;
+ diskfs_nref (np);
+ pager_unreference (p);
+
+ assert (np->references == 1 && np->light_references == 0);
+
+ /* This will do the real deallocate. Whew. */
+ diskfs_nput (np);
+ }
+ else
+ spin_unlock (&_libports_portrefcntlock);
+ }
+#endif
+}
+
+/* A new hard reference to a node has been created; it's now OK to
+ have unused weak references. */
+void
+diskfs_new_hardrefs (struct node *np)
+{
+ allow_pager_softrefs (np);
+}
+
+/* Read stat information out of the dinode. */
+static error_t
+read_disknode (struct node *np)
+{
+ struct stat *st = &np->dn_stat;
+ struct dinode *di = dino (np->dn->number);
+ error_t err;
+
+ err = diskfs_catch_exception ();
+ if (err)
+ return err;
+
+ st->st_fstype = FSTYPE_UFS;
+ st->st_fsid = getpid (); /* This call is very cheap. */
+ st->st_ino = np->dn->number;
+ st->st_gen = read_disk_entry (di->di_gen);
+ st->st_rdev = read_disk_entry(di->di_rdev);
+ st->st_mode = (((read_disk_entry (di->di_model)
+ | (read_disk_entry (di->di_modeh) << 16))
+ & ~S_ITRANS)
+ | (di->di_trans ? S_IPTRANS : 0));
+ st->st_nlink = read_disk_entry (di->di_nlink);
+ st->st_size = read_disk_entry (di->di_size);
+ st->st_atim.tv_sec = read_disk_entry (di->di_atime.tv_sec);
+ st->st_atim.tv_nsec = read_disk_entry (di->di_atime.tv_nsec);
+ st->st_mtim.tv_sec = read_disk_entry (di->di_mtime.tv_sec);
+ st->st_mtim.tv_nsec = read_disk_entry (di->di_mtime.tv_nsec);
+ st->st_ctim.tv_sec = read_disk_entry (di->di_ctime.tv_sec);
+ st->st_ctim.tv_nsec = read_disk_entry (di->di_ctime.tv_nsec);
+ st->st_blksize = sblock->fs_bsize;
+ st->st_blocks = read_disk_entry (di->di_blocks);
+ st->st_flags = read_disk_entry (di->di_flags);
+
+ if (sblock->fs_inodefmt < FS_44INODEFMT)
+ {
+ st->st_uid = read_disk_entry (di->di_ouid);
+ st->st_gid = read_disk_entry (di->di_ogid);
+ st->st_author = st->st_uid;
+ np->author_tracks_uid = 1;
+ }
+ else
+ {
+ st->st_uid = read_disk_entry (di->di_uid);
+ st->st_gid = read_disk_entry (di->di_gid);
+ st->st_author = read_disk_entry (di->di_author);
+ if (st->st_author == -1)
+ st->st_author = st->st_uid;
+ }
+
+ diskfs_end_catch_exception ();
+ if (!S_ISBLK (st->st_mode) && !S_ISCHR (st->st_mode))
+ st->st_rdev = 0;
+
+ if (S_ISLNK (st->st_mode)
+ && direct_symlink_extension
+ && st->st_size < sblock->fs_maxsymlinklen)
+ np->allocsize = 0;
+ else
+ {
+ if (lblkno (sblock, np->dn_stat.st_size) < NDADDR)
+ np->allocsize = fragroundup (sblock, st->st_size);
+ else
+ np->allocsize = blkroundup (sblock, st->st_size);
+ }
+
+ return 0;
+}
+
+error_t diskfs_node_reload (struct node *node)
+{
+ if (node->dn->dirents)
+ {
+ free (node->dn->dirents);
+ node->dn->dirents = 0;
+ }
+ flush_node_pager (node);
+ read_disknode (node);
+ return 0;
+}
+
+/* Return 0 if NP's author can be changed to AUTHOR; otherwise return an
+ error code. */
+error_t
+diskfs_validate_author_change (struct node *np, uid_t author)
+{
+ if (compat_mode == COMPAT_GNU)
+ return 0;
+ else
+ /* For non-hurd filesystems, the author & owner are the same. */
+ return (author == np->dn_stat.st_uid) ? 0 : EINVAL;
+}
+
+static void
+write_node (struct node *np)
+{
+ struct stat *st = &np->dn_stat;
+ struct dinode *di = dino (np->dn->number);
+ error_t err;
+
+ if (np->dn_stat_dirty)
+ {
+ assert (!diskfs_readonly);
+
+ err = diskfs_catch_exception ();
+ if (err)
+ return;
+
+ write_disk_entry (di->di_gen, st->st_gen);
+
+ if (S_ISBLK (st->st_mode) || S_ISCHR (st->st_mode))
+ write_disk_entry (di->di_rdev, st->st_rdev);
+
+ /* We happen to know that the stat mode bits are the same
+ as the ufs mode bits. */
+
+ if (compat_mode == COMPAT_GNU)
+ {
+ mode_t mode = st->st_mode & ~S_ITRANS;
+ write_disk_entry (di->di_model, mode & 0xffff);
+ write_disk_entry (di->di_modeh, (mode >> 16) & 0xffff);
+ }
+ else
+ {
+ write_disk_entry (di->di_model, st->st_mode & 0xffff & ~S_ITRANS);
+ di->di_modeh = 0;
+ }
+
+ if (compat_mode != COMPAT_BSD42)
+ {
+ write_disk_entry (di->di_uid, st->st_uid);
+ write_disk_entry (di->di_gid, st->st_gid);
+ }
+
+ if (sblock->fs_inodefmt < FS_44INODEFMT)
+ {
+ write_disk_entry (di->di_ouid, st->st_uid & 0xffff);
+ write_disk_entry (di->di_ogid, st->st_gid & 0xffff);
+ }
+ else if (compat_mode == COMPAT_GNU)
+ write_disk_entry (di->di_author, st->st_author);
+
+ write_disk_entry (di->di_nlink, st->st_nlink);
+ write_disk_entry (di->di_size, st->st_size);
+ write_disk_entry (di->di_atime.tv_sec, st->st_atim.tv_sec);
+ write_disk_entry (di->di_atime.tv_nsec, st->st_atim.tv_nsec);
+ write_disk_entry (di->di_mtime.tv_sec, st->st_mtim.tv_sec);
+ write_disk_entry (di->di_mtime.tv_nsec, st->st_mtim.tv_nsec);
+ write_disk_entry (di->di_ctime.tv_sec, st->st_ctim.tv_sec);
+ write_disk_entry (di->di_ctime.tv_nsec, st->st_ctim.tv_nsec);
+ write_disk_entry (di->di_blocks, st->st_blocks);
+ write_disk_entry (di->di_flags, st->st_flags);
+
+ diskfs_end_catch_exception ();
+ np->dn_stat_dirty = 0;
+ record_poke (di, sizeof (struct dinode));
+ }
+}
+
+/* See if we should create a symlink by writing it directly into
+ the block pointer array. Returning EINVAL tells diskfs to do it
+ the usual way. */
+static error_t
+create_symlink_hook (struct node *np, const char *target)
+{
+ int len = strlen (target);
+ error_t err;
+ struct dinode *di;
+
+ if (!direct_symlink_extension)
+ return EINVAL;
+
+ assert (compat_mode != COMPAT_BSD42);
+
+ if (len >= sblock->fs_maxsymlinklen)
+ return EINVAL;
+
+ err = diskfs_catch_exception ();
+ if (err)
+ return err;
+
+ di = dino (np->dn->number);
+ bcopy (target, di->di_shortlink, len);
+ np->dn_stat.st_size = len;
+ np->dn_set_ctime = 1;
+ np->dn_set_mtime = 1;
+ record_poke (di, sizeof (struct dinode));
+
+ diskfs_end_catch_exception ();
+ return 0;
+}
+error_t (*diskfs_create_symlink_hook)(struct node *, const char *)
+ = create_symlink_hook;
+
+/* Check if this symlink is stored directly in the block pointer array.
+ Returning EINVAL tells diskfs to do it the usual way. */
+static error_t
+read_symlink_hook (struct node *np,
+ char *buf)
+{
+ error_t err;
+
+ if (!direct_symlink_extension
+ || np->dn_stat.st_size >= sblock->fs_maxsymlinklen)
+ return EINVAL;
+
+ err = diskfs_catch_exception ();
+ if (err)
+ return err;
+
+ bcopy ((dino (np->dn->number))->di_shortlink, buf, np->dn_stat.st_size);
+
+ diskfs_set_node_atime (np);
+
+ diskfs_end_catch_exception ();
+ return 0;
+}
+error_t (*diskfs_read_symlink_hook)(struct node *, char *)
+ = read_symlink_hook;
+
+error_t
+diskfs_node_iterate (error_t (*fun)(struct node *))
+{
+ struct node *np;
+ struct item {struct item *next; struct node *np;} *list = 0;
+ struct item *i;
+ error_t err;
+ int n;
+
+ /* Acquire a reference on all the nodes in the hash table
+ and enter them into a list on the stack. */
+ spin_lock (&diskfs_node_refcnt_lock);
+ for (n = 0; n < INOHSZ; n++)
+ for (np = nodehash[n]; np; np = np->dn->hnext)
+ {
+ np->references++;
+ i = alloca (sizeof (struct item));
+ i->next = list;
+ i->np = np;
+ list = i;
+ }
+ spin_unlock (&diskfs_node_refcnt_lock);
+
+ err = 0;
+ for (i = list; i; i = i->next)
+ {
+ if (!err)
+ {
+ mutex_lock (&i->np->lock);
+ err = (*fun)(i->np);
+ mutex_unlock (&i->np->lock);
+ }
+ diskfs_nrele (i->np);
+ }
+ return err;
+}
+
+/* Write all active disknodes into the dinode pager. */
+void
+write_all_disknodes ()
+{
+ error_t
+ helper (struct node *np)
+ {
+ diskfs_set_node_times (np);
+ write_node (np);
+ return 0;
+ }
+
+ diskfs_node_iterate (helper);
+}
+
+void
+diskfs_write_disknode (struct node *np, int wait)
+{
+ write_node (np);
+ if (wait)
+ sync_dinode (np->dn->number, 1);
+}
+
+/* Implement the diskfs_set_statfs callback from the diskfs library;
+ see <hurd/diskfs.h> for the interface description. */
+error_t
+diskfs_set_statfs (struct statfs *st)
+{
+ st->f_type = FSTYPE_UFS;
+ st->f_bsize = sblock->fs_fsize;
+ st->f_blocks = sblock->fs_dsize;
+ st->f_bfree = (sblock->fs_cstotal.cs_nbfree * sblock->fs_frag
+ + sblock->fs_cstotal.cs_nffree);
+ st->f_bavail = ((sblock->fs_dsize * (100 - sblock->fs_minfree) / 100)
+ - (sblock->fs_dsize - st->f_bfree));
+ if (st->f_bfree < ((sblock->fs_dsize * (100 - sblock->fs_minfree) / 100)))
+ st->f_bavail = 0;
+ st->f_files = sblock->fs_ncg * sblock->fs_ipg - 2; /* not 0 or 1 */
+ st->f_ffree = sblock->fs_cstotal.cs_nifree;
+ st->f_fsid = getpid ();
+ st->f_namelen = 0;
+ st->f_favail = st->f_ffree;
+ st->f_frsize = sblock->fs_fsize;
+ return 0;
+}
+
+/* Implement the diskfs_set_translator callback from the diskfs
+ library; see <hurd/diskfs.h> for the interface description. */
+error_t
+diskfs_set_translator (struct node *np, const char *name, u_int namelen,
+ struct protid *cred)
+{
+ daddr_t blkno;
+ error_t err;
+ char buf[sblock->fs_bsize];
+ struct dinode *di;
+
+ if (compat_mode != COMPAT_GNU)
+ return EOPNOTSUPP;
+
+ if (namelen + sizeof (u_int) > sblock->fs_bsize)
+ return ENAMETOOLONG;
+
+ err = diskfs_catch_exception ();
+ if (err)
+ return err;
+
+ di = dino (np->dn->number);
+ blkno = read_disk_entry (di->di_trans);
+
+ if (namelen && !blkno)
+ {
+ /* Allocate block for translator */
+ err = ffs_alloc (np, 0, 0, sblock->fs_bsize, &blkno, cred);
+ if (err)
+ {
+ diskfs_end_catch_exception ();
+ return err;
+ }
+ write_disk_entry (di->di_trans, blkno);
+ record_poke (di, sizeof (struct dinode));
+ np->dn_set_ctime = 1;
+ }
+ else if (!namelen && blkno)
+ {
+ /* Clear block for translator going away. */
+ ffs_blkfree (np, blkno, sblock->fs_bsize);
+ di->di_trans = 0;
+ record_poke (di, sizeof (struct dinode));
+ np->dn_stat.st_blocks -= btodb (sblock->fs_bsize);
+ np->dn_stat.st_mode &= ~S_IPTRANS;
+ np->dn_set_ctime = 1;
+ }
+
+ if (namelen)
+ {
+ bcopy (&namelen, buf, sizeof (u_int));
+ bcopy (name, buf + sizeof (u_int), namelen);
+
+ bcopy (buf, disk_image + fsaddr (sblock, blkno), sblock->fs_bsize);
+ sync_disk_blocks (blkno, sblock->fs_bsize, 1);
+
+ np->dn_stat.st_mode |= S_IPTRANS;
+ np->dn_set_ctime = 1;
+ }
+
+ diskfs_end_catch_exception ();
+ return err;
+}
+
+/* Implement the diskfs_get_translator callback from the diskfs library.
+ See <hurd/diskfs.h> for the interface description. */
+error_t
+diskfs_get_translator (struct node *np, char **namep, u_int *namelen)
+{
+ error_t err;
+ daddr_t blkno;
+ u_int datalen;
+ const void *transloc;
+
+ err = diskfs_catch_exception ();
+ if (err)
+ return err;
+
+ blkno = read_disk_entry ((dino (np->dn->number))->di_trans);
+ assert (blkno);
+ transloc = disk_image + fsaddr (sblock, blkno);
+
+ datalen = *(u_int *)transloc;
+ if (datalen > sblock->fs_bsize - sizeof (u_int))
+ err = EFTYPE;
+ else
+ {
+ *namep = malloc (datalen);
+ if (*namep == NULL)
+ err = ENOMEM;
+ memcpy (*namep, transloc + sizeof (u_int), datalen);
+ }
+
+ diskfs_end_catch_exception ();
+
+ *namelen = datalen;
+ return 0;
+}
+
+/* Called when all hard ports have gone away. */
+void
+diskfs_shutdown_soft_ports ()
+{
+ /* Should initiate termination of internally held pager ports
+ (the only things that should be soft) XXX */
+}
+
+/* Return a description of the storage of the file. */
+/* In STORAGE_DATA are the following, in network byte order:
+
+ Inode number (4 bytes)
+ disk address of transator spec (4 bytes)
+ disk address of inode structure (4 bytes)
+ offset into inode block holding inode (4 bytes) */
+error_t
+diskfs_S_file_get_storage_info (struct protid *cred,
+ mach_port_t **ports,
+ mach_msg_type_name_t *ports_type,
+ mach_msg_type_number_t *num_ports,
+ int **ints, mach_msg_type_number_t *num_ints,
+ off_t **offsets,
+ mach_msg_type_number_t *num_offsets,
+ char **data, mach_msg_type_number_t *data_len)
+{
+ error_t err;
+ struct node *np;
+ struct store *file_store;
+ struct store_run runs[NDADDR];
+ size_t num_runs = 0;
+
+ if (! cred)
+ return EOPNOTSUPP;
+
+ np = cred->po->np;
+ mutex_lock (&np->lock);
+
+ /* See if this file fits in the direct block pointers. If not, punt
+ for now. (Reading indir blocks is a pain, and I'm postponing
+ pain.) XXX */
+ if (np->allocsize > NDADDR * sblock->fs_bsize)
+ {
+ mutex_unlock (&np->lock);
+ return EINVAL;
+ }
+
+ err = diskfs_catch_exception ();
+ if (! err)
+ if (!direct_symlink_extension
+ || np->dn_stat.st_size >= sblock->fs_maxsymlinklen
+ || !S_ISLNK (np->dn_stat.st_mode))
+ /* Copy the block pointers */
+ {
+ int i;
+ struct store_run *run = runs;
+ struct dinode *di = dino (np->dn->number);
+
+ for (i = 0; i < NDADDR; i++)
+ {
+ store_offset_t start = fsbtodb (sblock, read_disk_entry (di->di_db[i]));
+ store_offset_t length =
+ (((i + 1) * sblock->fs_bsize > np->allocsize)
+ ? np->allocsize - i * sblock->fs_bsize
+ : sblock->fs_bsize);
+ start <<= log2_dev_blocks_per_dev_bsize;
+ length <<= log2_dev_blocks_per_dev_bsize;
+ if (num_runs == 0 || run->start + run->length != start)
+ *run++ = (struct store_run){ start, length };
+ else
+ run->length += length;
+ }
+ }
+ diskfs_end_catch_exception ();
+
+ mutex_unlock (&np->lock);
+
+ if (! err)
+ err = store_clone (store, &file_store);
+ if (! err)
+ {
+ err = store_remap (file_store, runs, num_runs, &file_store);
+ if (! err)
+ err = store_return (file_store, ports, num_ports, ints, num_ints,
+ offsets, num_offsets, data, data_len);
+ store_free (file_store);
+ }
+ *ports_type = MACH_MSG_TYPE_COPY_SEND;
+
+ return err;
+}
diff --git a/ufs/main.c b/ufs/main.c
new file mode 100644
index 00000000..242107f4
--- /dev/null
+++ b/ufs/main.c
@@ -0,0 +1,210 @@
+/*
+ Copyright (C) 1994,95,96,97,98,99,2002 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+
+#include "ufs.h"
+#include <stdarg.h>
+#include <stdio.h>
+#include <error.h>
+#include <device/device.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <argz.h>
+#include <argp.h>
+#include <hurd/store.h>
+
+struct node *diskfs_root_node;
+
+struct store *store = 0;
+struct store_parsed *store_parsed = 0;
+
+char *diskfs_disk_name = 0;
+
+/* Number of device blocks per DEV_BSIZE block. */
+unsigned log2_dev_blocks_per_dev_bsize = 0;
+
+/* Set diskfs_root_node to the root inode. */
+static void
+warp_root (void)
+{
+ error_t err;
+ err = diskfs_cached_lookup (2, &diskfs_root_node);
+ assert (!err);
+ mutex_unlock (&diskfs_root_node->lock);
+}
+
+/* XXX */
+struct mutex printf_lock = MUTEX_INITIALIZER;
+int printf (const char *fmt, ...)
+{
+ va_list arg;
+ int done;
+ va_start (arg, fmt);
+ mutex_lock (&printf_lock);
+ done = vprintf (fmt, arg);
+ mutex_unlock (&printf_lock);
+ va_end (arg);
+ return done;
+}
+
+int diskfs_readonly;
+
+/* Ufs-specific options. XXX this should be moved so it can be done at
+ runtime as well as startup. */
+static const struct argp_option
+options[] =
+{
+ {"compat", 'C', "FMT", 0,
+ "FMT may be GNU, 4.4, or 4.2, and determines which filesystem extensions"
+ " are written onto the disk (default is GNU)"},
+ {0}
+};
+
+/* Parse a ufs-specific command line option. */
+static error_t
+parse_opt (int key, char *arg, struct argp_state *state)
+{
+ switch (key)
+ {
+ enum compat_mode mode;
+
+ case 'C':
+ if (strcasecmp (arg, "gnu") == 0)
+ mode = COMPAT_GNU;
+ else if (strcmp (arg, "4.4") == 0)
+ mode = COMPAT_BSD44;
+ else if (strcmp (arg, "4.2") == 0)
+ {
+ if (sblock
+ && (sblock->fs_inodefmt == FS_44INODEFMT
+ || direct_symlink_extension))
+ {
+ argp_failure (state, 0, 0,
+ "4.2 compat mode requested on 4.4 fs");
+ return EINVAL;
+ }
+ mode = COMPAT_BSD42;
+ }
+ else
+ {
+ argp_error (state, "%s: Unknown compatibility mode", arg);
+ return EINVAL;
+ }
+
+ state->hook = (void *)mode; /* Save it for the end. */
+ break;
+
+ case ARGP_KEY_INIT:
+ state->child_inputs[0] = state->input;
+ state->hook = (void *)compat_mode; break;
+ case ARGP_KEY_SUCCESS:
+ compat_mode = (enum compat_mode)state->hook; break;
+
+ default:
+ return ARGP_ERR_UNKNOWN;
+ }
+ return 0;
+}
+
+/* Add our startup arguments to the standard diskfs set. */
+static const struct argp_child startup_children[] =
+ {{&diskfs_store_startup_argp}, {0}};
+static struct argp startup_argp = {options, parse_opt, 0, 0, startup_children};
+
+/* Similarly at runtime. */
+static const struct argp_child runtime_children[] =
+ {{&diskfs_std_runtime_argp}, {0}};
+static struct argp runtime_argp = {options, parse_opt, 0, 0, runtime_children};
+
+struct argp *diskfs_runtime_argp = (struct argp *)&runtime_argp;
+
+/* Override the standard diskfs routine so we can add our own output. */
+error_t
+diskfs_append_args (char **argz, size_t *argz_len)
+{
+ error_t err;
+
+ /* Get the standard things. */
+ err = diskfs_append_std_options (argz, argz_len);
+
+ if (!err && compat_mode != COMPAT_GNU)
+ err = argz_add (argz, argz_len,
+ ((compat_mode == COMPAT_BSD42)
+ ? "--compat=4.2"
+ : "--compat=4.4"));
+
+ if (! err)
+ err = store_parsed_append_args (store_parsed, argz, argz_len);
+
+ return err;
+}
+
+int
+main (int argc, char **argv)
+{
+ mach_port_t bootstrap;
+
+ /* Initialize the diskfs library, parse arguments, and open the store.
+ This starts the first diskfs thread for us. */
+ store = diskfs_init_main (&startup_argp, argc, argv,
+ &store_parsed, &bootstrap);
+
+ if (store->block_size > DEV_BSIZE)
+ error (4, 0, "%s: Bad device block size %zd (should be <= %d)",
+ diskfs_disk_name, store->block_size, DEV_BSIZE);
+ if (store->size < SBSIZE + SBOFF)
+ error (5, 0, "%s: Disk too small (%Ld bytes)", diskfs_disk_name,
+ store->size);
+
+ log2_dev_blocks_per_dev_bsize = 0;
+ while ((1 << log2_dev_blocks_per_dev_bsize) < DEV_BSIZE)
+ log2_dev_blocks_per_dev_bsize++;
+ log2_dev_blocks_per_dev_bsize -= store->log2_block_size;
+
+ /* Map the entire disk. */
+ create_disk_pager ();
+
+ get_hypermetadata ();
+
+ inode_init ();
+
+ /* Find our root node. */
+ warp_root ();
+
+ /* Now that we are all set up to handle requests, and diskfs_root_node is
+ set properly, it is safe to export our fsys control port to the
+ outside world. */
+ diskfs_startup_diskfs (bootstrap, 0);
+
+ /* SET HOST NAME */
+
+ /* And this thread is done with its work. */
+ cthread_exit (0);
+
+ return 0;
+}
+
+error_t
+diskfs_reload_global_state ()
+{
+ flush_pokes ();
+ pager_flush (diskfs_disk_pager, 1);
+ get_hypermetadata ();
+ return 0;
+}
diff --git a/ufs/pager.c b/ufs/pager.c
new file mode 100644
index 00000000..3038932d
--- /dev/null
+++ b/ufs/pager.c
@@ -0,0 +1,806 @@
+/* Pager for ufs
+ Copyright (C) 1994, 1995, 1996, 1997, 1999 Free Software Foundation
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#include "ufs.h"
+#include <strings.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <hurd/store.h>
+
+spin_lock_t node2pagelock = SPIN_LOCK_INITIALIZER;
+
+spin_lock_t unlocked_pagein_lock = SPIN_LOCK_INITIALIZER;
+
+#ifdef DONT_CACHE_MEMORY_OBJECTS
+#define MAY_CACHE 0
+#else
+#define MAY_CACHE 1
+#endif
+
+struct port_bucket *pager_bucket;
+
+/* Mapped image of the disk. */
+void *disk_image;
+
+/* Find the location on disk of page OFFSET in pager UPI. Return the
+ disk address (in disk block) in *ADDR. If *NPLOCK is set on
+ return, then release that mutex after I/O on the data has
+ completed. Set DISKSIZE to be the amount of valid data on disk.
+ (If this is an unallocated block, then set *ADDR to zero.)
+ ISREAD is non-zero iff this is for a pagein. */
+static error_t
+find_address (struct user_pager_info *upi,
+ vm_address_t offset,
+ daddr_t *addr,
+ int *disksize,
+ struct rwlock **nplock,
+ int isread)
+{
+ error_t err;
+ struct rwlock *lock;
+
+ assert (upi->type == DISK || upi->type == FILE_DATA);
+
+ if (upi->type == DISK)
+ {
+ *disksize = __vm_page_size;
+ *addr = offset / DEV_BSIZE;
+ *nplock = 0;
+ return 0;
+ }
+ else
+ {
+ struct iblock_spec indirs[NIADDR + 1];
+ struct node *np;
+
+ np = upi->np;
+
+ if (isread)
+ {
+ try_again:
+
+ /* If we should allow an unlocked pagein, do so. (This
+ still has a slight race; there could be a pageout in progress
+ which is blocked on NP->np->allocptrlock itself. In that
+ case the pagein that should proceed unimpeded is blocked
+ in the pager library waiting for the pageout to complete.
+ I think this is sufficiently rare to put it off for the time
+ being.) */
+
+ spin_lock (&unlocked_pagein_lock);
+ if (offset >= upi->allow_unlocked_pagein
+ && (offset + vm_page_size
+ <= upi->allow_unlocked_pagein + upi->unlocked_pagein_length))
+ {
+ spin_unlock (&unlocked_pagein_lock);
+ *nplock = 0;
+ goto have_lock;
+ }
+ spin_unlock (&unlocked_pagein_lock);
+
+ /* Block on the rwlock if necessary; but when we wake up,
+ don't acquire it; check again from the top.
+ This is mutated inline from rwlock.h. */
+ lock = &np->dn->allocptrlock;
+ mutex_lock (&lock->master);
+ if (lock->readers == -1 || lock->writers_waiting)
+ {
+ lock->readers_waiting++;
+ condition_wait (&lock->wakeup, &lock->master);
+ lock->readers_waiting--;
+ mutex_unlock (&lock->master);
+ goto try_again;
+ }
+ lock->readers++;
+ mutex_unlock (&lock->master);
+ *nplock = lock;
+ }
+ else
+ {
+ rwlock_reader_lock (&np->dn->allocptrlock);
+ *nplock = &np->dn->allocptrlock;
+ }
+
+ have_lock:
+
+ if (offset >= np->allocsize)
+ {
+ if (*nplock)
+ rwlock_reader_unlock (*nplock);
+ if (isread)
+ return EIO;
+ else
+ {
+ *addr = 0;
+ *disksize = 0;
+ return 0;
+ }
+ }
+
+ if (offset + __vm_page_size > np->allocsize)
+ *disksize = np->allocsize - offset;
+ else
+ *disksize = __vm_page_size;
+
+ err = fetch_indir_spec (np, lblkno (sblock, offset), indirs);
+ if (err && *nplock)
+ rwlock_reader_unlock (*nplock);
+ else
+ {
+ if (indirs[0].bno)
+ *addr = (fsbtodb (sblock, indirs[0].bno)
+ + blkoff (sblock, offset) / DEV_BSIZE);
+ else
+ *addr = 0;
+ }
+
+ return err;
+ }
+}
+
+
+/* Implement the pager_read_page callback from the pager library. See
+ <hurd/pager.h> for the interface description. */
+error_t
+pager_read_page (struct user_pager_info *pager,
+ vm_offset_t page,
+ vm_address_t *buf,
+ int *writelock)
+{
+ error_t err;
+ struct rwlock *nplock;
+ daddr_t addr;
+ int disksize;
+
+ err = find_address (pager, page, &addr, &disksize, &nplock, 1);
+ if (err)
+ return err;
+
+ if (addr)
+ {
+ size_t read = 0;
+ err = store_read (store, addr << log2_dev_blocks_per_dev_bsize,
+ disksize, (void **)buf, &read);
+ if (read != disksize)
+ err = EIO;
+ if (!err && disksize != __vm_page_size)
+ bzero ((void *)(*buf + disksize), __vm_page_size - disksize);
+ *writelock = 0;
+ }
+ else
+ {
+#if 0
+ printf ("Write-locked pagein Object %#x\tOffset %#x\n", pager, page);
+ fflush (stdout);
+#endif
+ *buf = (vm_address_t) mmap (0, vm_page_size, PROT_READ|PROT_WRITE,
+ MAP_ANON, 0, 0);
+ *writelock = 1;
+ }
+
+ if (nplock)
+ rwlock_reader_unlock (nplock);
+
+ return err;
+}
+
+/* Implement the pager_write_page callback from the pager library. See
+ <hurd/pager.h> for the interface description. */
+error_t
+pager_write_page (struct user_pager_info *pager,
+ vm_offset_t page,
+ vm_address_t buf)
+{
+ daddr_t addr;
+ int disksize;
+ struct rwlock *nplock;
+ error_t err;
+
+ err = find_address (pager, page, &addr, &disksize, &nplock, 0);
+ if (err)
+ return err;
+
+ if (addr)
+ {
+ size_t wrote;
+ err = store_write (store, addr << log2_dev_blocks_per_dev_bsize,
+ (void *)buf, disksize, &wrote);
+ if (wrote != disksize)
+ err = EIO;
+ }
+ else
+ err = 0;
+
+ if (nplock)
+ rwlock_reader_unlock (nplock);
+
+ return err;
+}
+
+/* Implement the pager_unlock_page callback from the pager library. See
+ <hurd/pager.h> for the interface description. */
+error_t
+pager_unlock_page (struct user_pager_info *pager,
+ vm_offset_t address)
+{
+ struct node *np;
+ error_t err;
+ struct iblock_spec indirs[NIADDR + 1];
+ daddr_t bno;
+ struct disknode *dn;
+ struct dinode *di;
+
+ /* Zero an sblock->fs_bsize piece of disk starting at BNO,
+ synchronously. We do this on newly allocated indirect
+ blocks before setting the pointer to them to ensure that an
+ indirect block absolutely never points to garbage. */
+ void zero_disk_block (int bno)
+ {
+ bzero (indir_block (bno), sblock->fs_bsize);
+ sync_disk_blocks (bno, sblock->fs_bsize, 1);
+ };
+
+ /* Problem--where to get cred values for allocation here? */
+
+#if 0
+ printf ("Unlock page request, Object %#x\tOffset %#x...", pager, address);
+ fflush (stdout);
+#endif
+
+ if (pager->type == DISK)
+ return 0;
+
+ np = pager->np;
+ dn = np->dn;
+ di = dino (dn->number);
+
+ rwlock_writer_lock (&dn->allocptrlock);
+
+ /* If this is the last block, we don't let it get unlocked. */
+ if (address + __vm_page_size
+ > blkroundup (sblock, np->allocsize) - sblock->fs_bsize)
+ {
+ printf ("attempt to unlock at last block denied\n");
+ fflush (stdout);
+ rwlock_writer_unlock (&dn->allocptrlock);
+ return EIO;
+ }
+
+ err = fetch_indir_spec (np, lblkno (sblock, address), indirs);
+ if (err)
+ {
+ rwlock_writer_unlock (&dn->allocptrlock);
+ return EIO;
+ }
+
+ err = diskfs_catch_exception ();
+ if (err)
+ {
+ rwlock_writer_unlock (&dn->allocptrlock);
+ return EIO;
+ }
+
+ /* See if we need a triple indirect block; fail if we do. */
+ assert (indirs[0].offset == -1
+ || indirs[1].offset == -1
+ || indirs[2].offset == -1);
+
+ /* Check to see if this block is allocated. */
+ if (indirs[0].bno == 0)
+ {
+ size_t wrote;
+
+ if (indirs[0].offset == -1)
+ {
+ err = ffs_alloc (np, lblkno (sblock, address),
+ ffs_blkpref (np, lblkno (sblock, address),
+ lblkno (sblock, address), di->di_db),
+ sblock->fs_bsize, &bno, 0);
+ if (err)
+ goto out;
+
+ assert (lblkno (sblock, address) < NDADDR);
+ err = store_write (store,
+ fsbtodb (sblock, bno)
+ << log2_dev_blocks_per_dev_bsize,
+ zeroblock, sblock->fs_bsize, &wrote);
+ if (!err && wrote != sblock->fs_bsize)
+ err = EIO;
+ if (err)
+ goto out;
+
+ indirs[0].bno = bno;
+ write_disk_entry (di->di_db[lblkno (sblock, address)], bno);
+ record_poke (di, sizeof (struct dinode));
+ }
+ else
+ {
+ daddr_t *siblock;
+
+ /* We need to set siblock to the single indirect block
+ array; see if the single indirect block is allocated. */
+ if (indirs[1].bno == 0)
+ {
+ if (indirs[1].offset == -1)
+ {
+ err = ffs_alloc (np, lblkno (sblock, address),
+ ffs_blkpref (np, lblkno (sblock, address),
+ INDIR_SINGLE, di->di_ib),
+ sblock->fs_bsize, &bno, 0);
+ if (err)
+ goto out;
+ zero_disk_block (bno);
+ indirs[1].bno = bno;
+ write_disk_entry (di->di_ib[INDIR_SINGLE], bno);
+ record_poke (di, sizeof (struct dinode));
+ }
+ else
+ {
+ daddr_t *diblock;
+
+ /* We need to set diblock to the double indirect
+ block array; see if the double indirect block is
+ allocated. */
+ if (indirs[2].bno == 0)
+ {
+ /* This assert because triple indirection is
+ not supported. */
+ assert (indirs[2].offset == -1);
+
+ err = ffs_alloc (np, lblkno (sblock, address),
+ ffs_blkpref (np, lblkno (sblock,
+ address),
+ INDIR_DOUBLE, di->di_ib),
+ sblock->fs_bsize, &bno, 0);
+ if (err)
+ goto out;
+ zero_disk_block (bno);
+ indirs[2].bno = bno;
+ write_disk_entry (di->di_ib[INDIR_DOUBLE], bno);
+ record_poke (di, sizeof (struct dinode));
+ }
+
+ diblock = indir_block (indirs[2].bno);
+ mark_indir_dirty (np, indirs[2].bno);
+
+ /* Now we can allocate the single indirect block */
+
+ err = ffs_alloc (np, lblkno (sblock, address),
+ ffs_blkpref (np, lblkno (sblock, address),
+ indirs[1].offset, diblock),
+ sblock->fs_bsize, &bno, 0);
+ if (err)
+ goto out;
+ zero_disk_block (bno);
+ indirs[1].bno = bno;
+ write_disk_entry (diblock[indirs[1].offset], bno);
+ record_poke (diblock, sblock->fs_bsize);
+ }
+ }
+
+ siblock = indir_block (indirs[1].bno);
+ mark_indir_dirty (np, indirs[1].bno);
+
+ /* Now we can allocate the data block. */
+
+ err = ffs_alloc (np, lblkno (sblock, address),
+ ffs_blkpref (np, lblkno (sblock, address),
+ indirs[0].offset, siblock),
+ sblock->fs_bsize, &bno, 0);
+ if (err)
+ goto out;
+
+ err = store_write (store,
+ fsbtodb (sblock, bno)
+ << log2_dev_blocks_per_dev_bsize,
+ zeroblock, sblock->fs_bsize, &wrote);
+ if (!err && wrote != sblock->fs_bsize)
+ err = EIO;
+ if (err)
+ goto out;
+
+ indirs[0].bno = bno;
+ write_disk_entry (siblock[indirs[0].offset], bno);
+ record_poke (siblock, sblock->fs_bsize);
+ }
+ }
+
+ out:
+ diskfs_end_catch_exception ();
+ rwlock_writer_unlock (&dn->allocptrlock);
+ return err;
+}
+
+/* Implement the pager_report_extent callback from the pager library. See
+ <hurd/pager.h> for the interface description. */
+inline error_t
+pager_report_extent (struct user_pager_info *pager,
+ vm_address_t *offset,
+ vm_size_t *size)
+{
+ assert (pager->type == DISK || pager->type == FILE_DATA);
+
+ *offset = 0;
+
+ if (pager->type == DISK)
+ *size = store->size;
+ else
+ *size = pager->np->allocsize;
+
+ return 0;
+}
+
+/* Implement the pager_clear_user_data callback from the pager library.
+ See <hurd/pager.h> for the interface description. */
+void
+pager_clear_user_data (struct user_pager_info *upi)
+{
+ /* XXX Do the right thing for the disk pager here too. */
+ if (upi->type == FILE_DATA)
+ {
+ spin_lock (&node2pagelock);
+ if (upi->np->dn->fileinfo == upi)
+ upi->np->dn->fileinfo = 0;
+ spin_unlock (&node2pagelock);
+ diskfs_nrele_light (upi->np);
+ }
+ free (upi);
+}
+
+void
+pager_dropweak (struct user_pager_info *upi __attribute__ ((unused)))
+{
+}
+
+
+
+/* Create the DISK pager. */
+void
+create_disk_pager (void)
+{
+ struct user_pager_info *upi = malloc (sizeof (struct user_pager_info));
+
+ upi->type = DISK;
+ upi->np = 0;
+ pager_bucket = ports_create_bucket ();
+ diskfs_start_disk_pager (upi, pager_bucket, MAY_CACHE, store->size,
+ &disk_image);
+ upi->p = diskfs_disk_pager;
+}
+
+/* This syncs a single file (NP) to disk. Wait for all I/O to complete
+ if WAIT is set. NP->lock must be held. */
+void
+diskfs_file_update (struct node *np,
+ int wait)
+{
+ struct dirty_indir *d, *tmp;
+ struct user_pager_info *upi;
+
+ spin_lock (&node2pagelock);
+ upi = np->dn->fileinfo;
+ if (upi)
+ ports_port_ref (upi->p);
+ spin_unlock (&node2pagelock);
+
+ if (upi)
+ {
+ pager_sync (upi->p, wait);
+ ports_port_deref (upi->p);
+ }
+
+ for (d = np->dn->dirty; d; d = tmp)
+ {
+ sync_disk_blocks (d->bno, sblock->fs_bsize, wait);
+ tmp = d->next;
+ free (d);
+ }
+ np->dn->dirty = 0;
+
+ diskfs_node_update (np, wait);
+}
+
+/* Invalidate any pager data associated with NODE. */
+void
+flush_node_pager (struct node *node)
+{
+ struct user_pager_info *upi;
+ struct disknode *dn = node->dn;
+ struct dirty_indir *dirty = dn->dirty;
+
+ spin_lock (&node2pagelock);
+ upi = dn->fileinfo;
+ if (upi)
+ ports_port_ref (upi->p);
+ spin_unlock (&node2pagelock);
+
+ if (upi)
+ {
+ pager_flush (upi->p, 1);
+ ports_port_deref (upi->p);
+ }
+
+ dn->dirty = 0;
+
+ while (dirty)
+ {
+ struct dirty_indir *next = dirty->next;
+ free (dirty);
+ dirty = next;
+ }
+}
+
+/* Call this to create a FILE_DATA pager and return a send right.
+ NP must be locked. PROT is the max protection desired. */
+mach_port_t
+diskfs_get_filemap (struct node *np, vm_prot_t prot)
+{
+ struct user_pager_info *upi;
+ mach_port_t right;
+
+ assert (S_ISDIR (np->dn_stat.st_mode)
+ || S_ISREG (np->dn_stat.st_mode)
+ || (S_ISLNK (np->dn_stat.st_mode)
+ && (!direct_symlink_extension
+ || np->dn_stat.st_size >= sblock->fs_maxsymlinklen)));
+
+ spin_lock (&node2pagelock);
+ do
+ if (!np->dn->fileinfo)
+ {
+ upi = malloc (sizeof (struct user_pager_info));
+ upi->type = FILE_DATA;
+ upi->np = np;
+ upi->max_prot = prot;
+ upi->allow_unlocked_pagein = 0;
+ upi->unlocked_pagein_length = 0;
+ diskfs_nref_light (np);
+ upi->p = pager_create (upi, pager_bucket,
+ MAY_CACHE, MEMORY_OBJECT_COPY_DELAY);
+ if (upi->p == 0)
+ {
+ diskfs_nrele_light (np);
+ free (upi);
+ spin_unlock (&node2pagelock);
+ return MACH_PORT_NULL;
+ }
+ np->dn->fileinfo = upi;
+ right = pager_get_port (np->dn->fileinfo->p);
+ ports_port_deref (np->dn->fileinfo->p);
+ }
+ else
+ {
+ np->dn->fileinfo->max_prot |= prot;
+
+ /* Because NP->dn->fileinfo->p is not a real reference,
+ this might be nearly deallocated. If that's so, then
+ the port right will be null. In that case, clear here
+ and loop. The deallocation will complete separately. */
+ right = pager_get_port (np->dn->fileinfo->p);
+ if (right == MACH_PORT_NULL)
+ np->dn->fileinfo = 0;
+ }
+ while (right == MACH_PORT_NULL);
+
+ spin_unlock (&node2pagelock);
+
+ mach_port_insert_right (mach_task_self (), right, right,
+ MACH_MSG_TYPE_MAKE_SEND);
+
+ return right;
+}
+
+/* Call this when we should turn off caching so that unused memory object
+ ports get freed. */
+void
+drop_pager_softrefs (struct node *np)
+{
+ struct user_pager_info *upi;
+
+ spin_lock (&node2pagelock);
+ upi = np->dn->fileinfo;
+ if (upi)
+ ports_port_ref (upi->p);
+ spin_unlock (&node2pagelock);
+
+ if (MAY_CACHE && upi)
+ pager_change_attributes (upi->p, 0, MEMORY_OBJECT_COPY_DELAY, 0);
+ if (upi)
+ ports_port_deref (upi->p);
+}
+
+/* Call this when we should turn on caching because it's no longer
+ important for unused memory object ports to get freed. */
+void
+allow_pager_softrefs (struct node *np)
+{
+ struct user_pager_info *upi;
+
+ spin_lock (&node2pagelock);
+ upi = np->dn->fileinfo;
+ if (upi)
+ ports_port_ref (upi->p);
+ spin_unlock (&node2pagelock);
+
+ if (MAY_CACHE && upi)
+ pager_change_attributes (upi->p, 1, MEMORY_OBJECT_COPY_DELAY, 0);
+ if (upi)
+ ports_port_deref (upi->p);
+}
+
+static void
+block_caching ()
+{
+ error_t block_cache (void *arg)
+ {
+ struct pager *p = arg;
+
+ pager_change_attributes (p, 0, MEMORY_OBJECT_COPY_DELAY, 1);
+ return 0;
+ }
+
+ /* Loop through the pagers and turn off caching one by one,
+ synchronously. That should cause termination of each pager. */
+ ports_bucket_iterate (pager_bucket, block_cache);
+}
+
+static void
+enable_caching ()
+{
+ error_t enable_cache (void *arg)
+ {
+ struct pager *p = arg;
+ struct user_pager_info *upi = pager_get_upi (p);
+
+ pager_change_attributes (p, 1, MEMORY_OBJECT_COPY_DELAY, 0);
+
+ /* It's possible that we didn't have caching on before, because
+ the user here is the only reference to the underlying node
+ (actually, that's quite likely inside this particular
+ routine), and if that node has no links. So dinkle the node
+ ref counting scheme here, which will cause caching to be
+ turned off, if that's really necessary. */
+ if (upi->type == FILE_DATA)
+ {
+ diskfs_nref (upi->np);
+ diskfs_nrele (upi->np);
+ }
+
+ return 0;
+ }
+
+ ports_bucket_iterate (pager_bucket, enable_cache);
+}
+
+/* Tell diskfs if there are pagers exported, and if none, then
+ prevent any new ones from showing up. */
+int
+diskfs_pager_users ()
+{
+ int npagers = ports_count_bucket (pager_bucket);
+
+ if (npagers <= 1)
+ return 0;
+
+ if (MAY_CACHE)
+ {
+ block_caching ();
+
+ /* Give it a second; the kernel doesn't actually shutdown
+ immediately. XXX */
+ sleep (1);
+
+ npagers = ports_count_bucket (pager_bucket);
+ if (npagers <= 1)
+ return 0;
+
+ /* Darn, there are actual honest users. Turn caching back on,
+ and return failure. */
+ enable_caching ();
+ }
+
+ ports_enable_bucket (pager_bucket);
+
+ return 1;
+}
+
+/* Return the bitwise or of the maximum prot parameter (the second arg to
+ diskfs_get_filemap) for all active user pagers. */
+vm_prot_t
+diskfs_max_user_pager_prot ()
+{
+ vm_prot_t max_prot = 0;
+ int npagers = ports_count_bucket (pager_bucket);
+
+ if (npagers > 1)
+ /* More than just the disk pager. */
+ {
+ error_t add_pager_max_prot (void *v_p)
+ {
+ struct pager *p = v_p;
+ struct user_pager_info *upi = pager_get_upi (p);
+ if (upi->type == FILE_DATA)
+ max_prot |= upi->max_prot;
+ /* Stop iterating if MAX_PROT is as filled as it's going to get. */
+ return max_prot == (VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE);
+ }
+
+ block_caching (); /* Make any silly pagers go away. */
+
+ /* Give it a second; the kernel doesn't actually shutdown
+ immediately. XXX */
+ sleep (1);
+
+ ports_bucket_iterate (pager_bucket, add_pager_max_prot);
+
+ enable_caching ();
+ }
+
+ ports_enable_bucket (pager_bucket);
+
+ return max_prot;
+}
+
+/* Call this to find out the struct pager * corresponding to the
+ FILE_DATA pager of inode IP. This should be used *only* as a subsequent
+ argument to register_memory_fault_area, and will be deleted when
+ the kernel interface is fixed. NP must be locked. */
+struct pager *
+diskfs_get_filemap_pager_struct (struct node *np)
+{
+ /* This is safe because fileinfo can't be cleared; there must be
+ an active mapping for this to be called. */
+ return np->dn->fileinfo->p;
+}
+
+/* Shutdown all the pagers. */
+void
+diskfs_shutdown_pager ()
+{
+ error_t shutdown_one (void *arg)
+ {
+ struct pager *p = arg;
+ /* Don't ever shut down the disk pager. */
+ if (p != diskfs_disk_pager)
+ pager_shutdown (p);
+ return 0;
+ }
+
+ copy_sblock ();
+ write_all_disknodes ();
+ ports_bucket_iterate (pager_bucket, shutdown_one);
+ sync_disk (1);
+}
+
+/* Sync all the pagers. */
+void
+diskfs_sync_everything (int wait)
+{
+ error_t sync_one (void *arg)
+ {
+ struct pager *p = arg;
+ /* Make sure the disk pager is done last. */
+ if (p != diskfs_disk_pager)
+ pager_sync (p, wait);
+ return 0;
+ }
+
+ copy_sblock ();
+ write_all_disknodes ();
+ ports_bucket_iterate (pager_bucket, sync_one);
+ sync_disk (wait);
+}
diff --git a/ufs/pokeloc.c b/ufs/pokeloc.c
new file mode 100644
index 00000000..267aa106
--- /dev/null
+++ b/ufs/pokeloc.c
@@ -0,0 +1,85 @@
+/* Remember where we've written the disk to speed up sync
+ Copyright (C) 1994, 1996 Free Software Foundation, Inc.
+ Written by Michael I. Bushnell.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#include "ufs.h"
+
+struct pokeloc
+{
+ vm_offset_t offset;
+ vm_size_t length;
+ struct pokeloc *next;
+};
+
+struct pokeloc *pokelist;
+spin_lock_t pokelistlock = SPIN_LOCK_INITIALIZER;
+
+/* Remember that data here on the disk has been modified. */
+void
+record_poke (void *loc, vm_size_t length)
+{
+ struct pokeloc *pl = malloc (sizeof (struct pokeloc));
+ vm_offset_t offset;
+
+ offset = loc - disk_image;
+ pl->offset = trunc_page (offset);
+ pl->length = round_page (offset + length) - pl->offset;
+
+ spin_lock (&pokelistlock);
+ pl->next = pokelist;
+ pokelist = pl;
+ spin_unlock (&pokelistlock);
+}
+
+/* Get rid of any outstanding pokes. */
+void
+flush_pokes ()
+{
+ struct pokeloc *pl;
+
+ spin_lock (&pokelistlock);
+ pl = pokelist;
+ pokelist = 0;
+ spin_unlock (&pokelistlock);
+
+ while (pl)
+ {
+ struct pokeloc *next = pl->next;
+ free (pl);
+ pl = next;
+ }
+}
+
+/* Sync all the modified pieces of disk */
+void
+sync_disk (int wait)
+{
+ struct pokeloc *pl, *tmp;
+
+ spin_lock (&pokelistlock);
+ for (pl = pokelist; pl; pl = tmp)
+ {
+ pager_sync_some (diskfs_disk_pager, pl->offset, pl->length, wait);
+ tmp = pl->next;
+ free (pl);
+ }
+ pokelist = 0;
+ spin_unlock (&pokelistlock);
+}
+
diff --git a/ufs/sizes.c b/ufs/sizes.c
new file mode 100644
index 00000000..58cbfc98
--- /dev/null
+++ b/ufs/sizes.c
@@ -0,0 +1,719 @@
+/* File growth and truncation
+ Copyright (C) 1993, 1994, 1995, 1996, 1997, 1999 Free Software Foundation
+
+This file is part of the GNU Hurd.
+
+The GNU Hurd is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+The GNU Hurd is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with the GNU Hurd; see the file COPYING. If not, write to
+the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+/* Written by Michael I. Bushnell. */
+
+#include "ufs.h"
+#include <string.h>
+
+#ifdef DONT_CACHE_MEMORY_OBJECTS
+#define MAY_CACHE 0
+#else
+#define MAY_CACHE 1
+#endif
+
+static int indir_release (struct node *np, daddr_t bno, int level);
+static void poke_pages (memory_object_t, vm_offset_t, vm_offset_t);
+
+/* Implement the diskfs_truncate callback; sse <hurd/diskfs.h> for the
+ interface description. */
+error_t
+diskfs_truncate (struct node *np,
+ off_t length)
+{
+ int offset;
+ struct dinode *di = dino (np->dn->number);
+ volatile int blocksfreed = 0;
+ error_t err;
+ int i;
+ struct iblock_spec indirs[NIADDR + 1];
+ volatile daddr_t lbn;
+ struct user_pager_info *upi;
+
+ if (length >= np->dn_stat.st_size)
+ return 0;
+
+ diskfs_check_readonly ();
+ assert (!diskfs_readonly);
+
+ /* First check to see if this is a kludged symlink; if so
+ this is special. */
+ if (direct_symlink_extension && S_ISLNK (np->dn_stat.st_mode)
+ && np->dn_stat.st_size < sblock->fs_maxsymlinklen)
+ {
+ error_t err;
+
+ err = diskfs_catch_exception ();
+ if (err)
+ return err;
+ bzero ((char *)di->di_shortlink + length, np->dn_stat.st_size - length);
+ record_poke (di, sizeof (struct dinode));
+ diskfs_end_catch_exception ();
+ np->dn_stat.st_size = length;
+ np->dn_set_ctime = np->dn_set_mtime = 1;
+ diskfs_node_update (np, 1);
+ return 0;
+ }
+
+ /* If the file is not being trucated to a block boundary,
+ the zero the partial bit in the new last block. */
+ offset = blkoff (sblock, length);
+ if (offset)
+ {
+ int bsize; /* size of new last block */
+ int savesize = np->allocsize;
+
+ np->allocsize = length; /* temporary */
+ bsize = blksize (sblock, np, lblkno (sblock, length));
+ np->allocsize = savesize;
+ diskfs_node_rdwr (np, zeroblock, length, bsize - offset, 1, 0, 0);
+ diskfs_file_update (np, 1);
+ }
+
+ /* Now flush all the data past the new size from the kernel.
+ Also force any delayed copies of this data to take place
+ immediately. (We are implicitly changing the data to zeros
+ and doing it without the kernel's immediate knowledge;
+ accordingl we must help out the kernel thusly.) */
+ spin_lock (&node2pagelock);
+ upi = np->dn->fileinfo;
+ if (upi)
+ ports_port_ref (upi->p);
+ spin_unlock (&node2pagelock);
+
+ if (upi)
+ {
+ mach_port_t obj;
+
+ pager_change_attributes (upi->p, MAY_CACHE,
+ MEMORY_OBJECT_COPY_NONE, 1);
+ obj = diskfs_get_filemap (np, VM_PROT_READ | VM_PROT_WRITE);
+ if (obj != MACH_PORT_NULL)
+ {
+ /* XXX should cope with errors from diskfs_get_filemap */
+ poke_pages (obj, round_page (length), round_page (np->allocsize));
+ mach_port_deallocate (mach_task_self (), obj);
+ pager_flush_some (upi->p, round_page (length),
+ np->allocsize - length, 1);
+ }
+ ports_port_deref (upi->p);
+ }
+
+ rwlock_writer_lock (&np->dn->allocptrlock);
+
+ /* Update the size on disk; fsck will finish freeing blocks if necessary
+ should we crash. */
+ np->dn_stat.st_size = length;
+ np->dn_set_mtime = 1;
+ np->dn_set_ctime = 1;
+ diskfs_node_update (np, 1);
+
+ /* Find out the location information for the last block to
+ be retained */
+ lbn = lblkno (sblock, length - 1);
+ err = fetch_indir_spec (np, lbn, indirs);
+ /* err XXX */
+
+ /* We don't support triple indirs */
+ assert (indirs[3].offset == -2);
+
+ err = diskfs_catch_exception ();
+ /* err XXX */
+
+ /* BSD carefully finds out how far to clear; it's vastly simpler
+ to just clear everything after the new last block. */
+
+ /* Free direct blocks */
+ if (indirs[0].offset < 0)
+ {
+ /* ...mapped from the inode. */
+ for (i = lbn + 1; i < NDADDR; i++)
+ if (di->di_db[i])
+ {
+ long bsize = blksize (sblock, np, i);
+ ffs_blkfree (np, read_disk_entry (di->di_db[i]), bsize);
+ di->di_db[i] = 0;
+ blocksfreed += btodb (bsize);
+ }
+ }
+ else
+ {
+ /* ... or mapped from sindir */
+ if (indirs[1].bno)
+ {
+ daddr_t *sindir = indir_block (indirs[1].bno);
+ for (i = indirs[0].offset + 1; i < NINDIR (sblock); i++)
+ if (sindir[i])
+ {
+ ffs_blkfree (np, read_disk_entry (sindir[i]),
+ sblock->fs_bsize);
+ sindir[i] = 0;
+ blocksfreed += btodb (sblock->fs_bsize);
+ }
+ record_poke (sindir, sblock->fs_bsize);
+ }
+ }
+
+ /* Free single indirect blocks */
+ if (indirs[1].offset < 0)
+ {
+ /* ...mapped from the inode */
+ if (di->di_ib[INDIR_SINGLE] && indirs[1].offset == -2)
+ {
+ blocksfreed += indir_release (np,
+ read_disk_entry (di->di_ib
+ [INDIR_SINGLE]),
+ INDIR_SINGLE);
+ di->di_ib[INDIR_SINGLE] = 0;
+ }
+ }
+ else
+ {
+ /* ...or mapped from dindir */
+ if (indirs[2].bno)
+ {
+ daddr_t *dindir = indir_block (indirs[2].bno);
+ for (i = indirs[1].offset + 1; i < NINDIR (sblock); i++)
+ if (dindir[i])
+ {
+ blocksfreed += indir_release (np,
+ read_disk_entry (dindir[i]),
+ INDIR_SINGLE);
+ dindir[i] = 0;
+ }
+ record_poke (dindir, sblock->fs_bsize);
+ }
+ }
+
+ /* Free double indirect block */
+ assert (indirs[2].offset < 0); /* which must be mapped from the inode */
+ if (indirs[2].offset == -2)
+ {
+ if (di->di_ib[INDIR_DOUBLE])
+ {
+ blocksfreed += indir_release (np,
+ read_disk_entry (di->di_ib
+ [INDIR_DOUBLE]),
+ INDIR_DOUBLE);
+ di->di_ib[INDIR_DOUBLE] = 0;
+ }
+ }
+
+ /* Finally, check to see if the new last direct block is
+ changing size; if so release any frags necessary. */
+ if (lbn >= 0 && lbn < NDADDR && di->di_db[lbn])
+ {
+ long oldspace, newspace;
+ daddr_t bn;
+
+ bn = read_disk_entry (di->di_db[lbn]);
+ oldspace = blksize (sblock, np, lbn);
+ np->allocsize = fragroundup (sblock, length);
+ newspace = blksize (sblock, np, lbn);
+
+ assert (newspace);
+
+ if (oldspace - newspace)
+ {
+ bn += numfrags (sblock, newspace);
+ ffs_blkfree (np, bn, oldspace - newspace);
+ blocksfreed += btodb (oldspace - newspace);
+ }
+ }
+ else
+ {
+ if (lbn > NDADDR)
+ np->allocsize = blkroundup (sblock, length);
+ else
+ np->allocsize = fragroundup (sblock, length);
+ }
+
+ record_poke (di, sizeof (struct dinode));
+
+ np->dn_stat.st_blocks -= blocksfreed;
+ np->dn_set_ctime = 1;
+ diskfs_node_update (np, 1);
+
+ rwlock_writer_unlock (&np->dn->allocptrlock);
+
+ /* At this point the last block (as defined by np->allocsize)
+ might not be allocated. We need to allocate it to maintain
+ the rule that the last block of a file is always allocated. */
+
+ if (np->allocsize && indirs[0].bno == 0)
+ {
+ /* The strategy is to reduce LBN until we get one that's allocated;
+ then reduce allocsize accordingly, then call diskfs_grow. */
+
+ do
+ err = fetch_indir_spec (np, --lbn, indirs);
+ /* err XXX */
+ while (indirs[0].bno == 0 && lbn >= 0);
+
+ assert ((lbn + 1) * sblock->fs_bsize < np->allocsize);
+ np->allocsize = (lbn + 1) * sblock->fs_bsize;
+
+ diskfs_grow (np, length, 0);
+ }
+
+ diskfs_end_catch_exception ();
+
+ /* Now we can permit delayed copies again. */
+ spin_lock (&node2pagelock);
+ upi = np->dn->fileinfo;
+ if (upi)
+ ports_port_ref (upi->p);
+ spin_unlock (&node2pagelock);
+ if (upi)
+ {
+ pager_change_attributes (upi->p, MAY_CACHE,
+ MEMORY_OBJECT_COPY_DELAY, 0);
+ ports_port_deref (upi->p);
+ }
+
+ return err;
+}
+
+/* Free indirect block BNO of level LEVEL; recursing if necessary
+ to free other indirect blocks. Return the number of disk
+ blocks freed. */
+static int
+indir_release (struct node *np, daddr_t bno, int level)
+{
+ int count = 0;
+ daddr_t *addrs;
+ int i;
+ struct dirty_indir *d, *prev, *next;
+
+ assert (bno);
+
+ addrs = indir_block (bno);
+ for (i = 0; i < NINDIR (sblock); i++)
+ if (addrs[i])
+ {
+ if (level == INDIR_SINGLE)
+ {
+ ffs_blkfree (np, read_disk_entry (addrs[i]), sblock->fs_bsize);
+ count += btodb (sblock->fs_bsize);
+ }
+ else
+ count += indir_release (np, read_disk_entry (addrs[i]), level - 1);
+ }
+
+ /* Subtlety: this block is no longer necessary; the information
+ the kernel has cached corresponding to ADDRS is now unimportant.
+ Consider that if this block is allocated to a file, it will then
+ be double cached and the kernel might decide to write out
+ the disk_image version of the block. So we have to flush
+ the block from the kernel's memory, making sure we do it
+ synchronously--and BEFORE we attach it to the free list
+ with ffs_blkfree. */
+ pager_flush_some (diskfs_disk_pager, fsaddr (sblock, bno), sblock->fs_bsize, 1);
+
+ /* We should also take this block off the inode's list of
+ dirty indirect blocks if it's there. */
+ prev = 0;
+ d = np->dn->dirty;
+ while (d)
+ {
+ next = d->next;
+ if (d->bno == bno)
+ {
+ if (prev)
+ prev->next = next;
+ else
+ np->dn->dirty = next;
+ free (d);
+ }
+ else
+ {
+ prev = d;
+ next = d->next;
+ }
+ d = next;
+ }
+
+ /* Free designated block */
+ ffs_blkfree (np, bno, sblock->fs_bsize);
+ count += btodb (sblock->fs_bsize);
+
+ return count;
+}
+
+
+/* Offer data at BUF from START of LEN bytes of file NP. */
+void
+offer_data (struct node *np,
+ off_t start,
+ size_t len,
+ vm_address_t buf)
+{
+ vm_address_t addr;
+
+ len = round_page (len);
+
+ assert (start % vm_page_size == 0);
+
+ assert (np->dn->fileinfo);
+ for (addr = start; addr < start + len; addr += vm_page_size)
+ pager_offer_page (np->dn->fileinfo->p, 1, 0, addr, buf + (addr - start));
+}
+
+/* Logical block LBN of node NP has been extended with ffs_realloccg.
+ It used to be allocated at OLD_PBN and is now at NEW_PBN. The old
+ size was OLD_SIZE; it is now NEW_SIZE bytes long. Arrange for the data
+ on disk to be kept consistent, and free the old block if it has moved.
+ Return one iff we've actually moved data around on disk. */
+int
+block_extended (struct node *np,
+ daddr_t lbn,
+ daddr_t old_pbn,
+ daddr_t new_pbn,
+ size_t old_size,
+ size_t new_size)
+{
+ /* Make sure that any pages of this block which just became allocated
+ don't get paged in from disk. */
+ if (round_page (old_size) < round_page (new_size))
+ offer_data (np, lbn * sblock->fs_bsize + round_page (old_size),
+ round_page (new_size) - round_page (old_size),
+ (vm_address_t)zeroblock);
+
+ if (old_pbn != new_pbn)
+ {
+ memory_object_t mapobj;
+ error_t err;
+ vm_address_t mapaddr;
+ volatile int *pokeaddr;
+
+ /* Map in this part of the file */
+ mapobj = diskfs_get_filemap (np, VM_PROT_WRITE | VM_PROT_READ);
+
+ /* XXX Should cope with errors from diskfs_get_filemap and back
+ out the operation here. */
+ assert (mapobj);
+
+ err = vm_map (mach_task_self (), &mapaddr, round_page (old_size), 0, 1,
+ mapobj, lbn * sblock->fs_bsize, 0,
+ VM_PROT_READ|VM_PROT_WRITE, VM_PROT_READ|VM_PROT_WRITE, 0);
+ assert_perror (err);
+
+ /* Allow these pageins to occur even though we're holding the lock */
+ spin_lock (&unlocked_pagein_lock);
+ np->dn->fileinfo->allow_unlocked_pagein = lbn * sblock->fs_bsize;
+ np->dn->fileinfo->unlocked_pagein_length = round_page (old_size);
+ spin_unlock (&unlocked_pagein_lock);
+
+ /* Make sure all waiting pageins see this change. */
+ mutex_lock (&np->dn->allocptrlock.master);
+ condition_broadcast (&np->dn->allocptrlock.wakeup);
+ mutex_unlock (&np->dn->allocptrlock.master);
+
+ /* Force the pages in core and make sure they are dirty */
+ for (pokeaddr = (int *)mapaddr;
+ pokeaddr < (int *) (mapaddr + round_page (old_size));
+ pokeaddr += vm_page_size / sizeof (*pokeaddr))
+ *pokeaddr = *pokeaddr;
+
+ /* Turn off the special pagein permission */
+ spin_lock (&unlocked_pagein_lock);
+ np->dn->fileinfo->allow_unlocked_pagein = 0;
+ np->dn->fileinfo->unlocked_pagein_length = 0;
+ spin_unlock (&unlocked_pagein_lock);
+
+ /* Undo mapping */
+ mach_port_deallocate (mach_task_self (), mapobj);
+ munmap ((caddr_t) mapaddr, round_page (old_size));
+
+ /* Now it's OK to free the old block */
+ ffs_blkfree (np, old_pbn, old_size);
+
+ /* Tell caller that we've moved data */
+ return 1;
+ }
+ else
+ return 0;
+}
+
+
+/* Implement the diskfs_grow callback; see <hurd/diskfs.h> for the
+ interface description. */
+error_t
+diskfs_grow (struct node *np,
+ off_t end,
+ struct protid *cred)
+{
+ daddr_t lbn, olbn;
+ int size, osize;
+ error_t err;
+ struct dinode *di = dino (np->dn->number);
+ mach_port_t pagerpt;
+ int need_sync = 0;
+
+ /* Zero an sblock->fs_bsize piece of disk starting at BNO,
+ synchronously. We do this on newly allocated indirect
+ blocks before setting the pointer to them to ensure that an
+ indirect block absolutely never points to garbage. */
+ void zero_disk_block (int bno)
+ {
+ bzero (indir_block (bno), sblock->fs_bsize);
+ sync_disk_blocks (bno, sblock->fs_bsize, 1);
+ };
+
+ /* Check to see if we don't actually have to do anything */
+ if (end <= np->allocsize)
+ return 0;
+
+ diskfs_check_readonly ();
+ assert (!diskfs_readonly);
+
+ /* This reference will ensure that NP->dn->fileinfo stays allocated. */
+ pagerpt = diskfs_get_filemap (np, VM_PROT_WRITE|VM_PROT_READ);
+
+ if (pagerpt == MACH_PORT_NULL)
+ return errno;
+
+ /* The new last block of the file. */
+ lbn = lblkno (sblock, end - 1);
+
+ /* This is the size of that block if it is in the NDADDR array. */
+ size = fragroundup (sblock, blkoff (sblock, end));
+ if (size == 0)
+ size = sblock->fs_bsize;
+
+ rwlock_writer_lock (&np->dn->allocptrlock);
+
+ /* The old last block of the file. */
+ olbn = lblkno (sblock, np->allocsize - 1);
+
+ /* This is the size of that block if it is in the NDADDR array. */
+ osize = fragroundup (sblock, blkoff (sblock, np->allocsize));
+ if (osize == 0)
+ osize = sblock->fs_bsize;
+
+ /* If this end point is a new block and the file currently
+ has a fragment, then expand the fragment to a full block. */
+ if (np->allocsize && olbn < NDADDR && olbn < lbn)
+ {
+ if (osize < sblock->fs_bsize)
+ {
+ daddr_t old_pbn, bno;
+ err = ffs_realloccg (np, olbn,
+ ffs_blkpref (np, lbn, lbn, di->di_db),
+ osize, sblock->fs_bsize, &bno, cred);
+ if (err)
+ goto out;
+
+ old_pbn = read_disk_entry (di->di_db[olbn]);
+
+ need_sync = block_extended (np, olbn, old_pbn, bno,
+ osize, sblock->fs_bsize);
+
+ write_disk_entry (di->di_db[olbn], bno);
+ record_poke (di, sizeof (struct dinode));
+ np->dn_set_ctime = 1;
+ }
+ }
+
+ if (lbn < NDADDR)
+ {
+ daddr_t bno, old_pbn = read_disk_entry (di->di_db[lbn]);
+
+ if (old_pbn != 0)
+ {
+ /* The last block is already allocated. Therefore we
+ must be expanding the fragment. Make sure that's really
+ what we're up to. */
+ assert (size > osize);
+ assert (lbn == olbn);
+
+ err = ffs_realloccg (np, lbn,
+ ffs_blkpref (np, lbn, lbn, di->di_db),
+ osize, size, &bno, cred);
+ if (err)
+ goto out;
+
+ need_sync = block_extended (np, lbn, old_pbn, bno, osize, size);
+
+ write_disk_entry (di->di_db[lbn], bno);
+ record_poke (di, sizeof (struct dinode));
+ np->dn_set_ctime = 1;
+ }
+ else
+ {
+ /* Allocate a new last block. */
+ err = ffs_alloc (np, lbn,
+ ffs_blkpref (np, lbn, lbn, di->di_db),
+ size, &bno, cred);
+ if (err)
+ goto out;
+
+
+ offer_data (np, lbn * sblock->fs_bsize, size,
+ (vm_address_t)zeroblock);
+ write_disk_entry (di->di_db[lbn], bno);
+ record_poke (di, sizeof (struct dinode));
+ np->dn_set_ctime = 1;
+ }
+ }
+ else
+ {
+ struct iblock_spec indirs[NIADDR + 1];
+ daddr_t *siblock;
+ daddr_t bno;
+
+ /* Count the number of levels of indirection. */
+ err = fetch_indir_spec (np, lbn, indirs);
+ if (err)
+ goto out;
+
+ /* Make sure we didn't miss the NDADDR case
+ above somehow. */
+ assert (indirs[0].offset != -1);
+
+ /* See if we need a triple indirect block; fail if so. */
+ assert (indirs[1].offset == -1 || indirs[2].offset == -1);
+
+ /* Check to see if this block is allocated. If it is
+ that's an error. */
+ assert (indirs[0].bno == 0);
+
+ /* We need to set SIBLOCK to the single indirect block
+ array; see if the single indirect block is allocated. */
+ if (indirs[1].bno == 0)
+ {
+ /* Allocate it. */
+ if (indirs[1].offset == -1)
+ {
+ err = ffs_alloc (np, lbn,
+ ffs_blkpref (np, lbn, INDIR_SINGLE, di->di_ib),
+ sblock->fs_bsize, &bno, 0);
+ if (err)
+ goto out;
+ zero_disk_block (bno);
+ indirs[1].bno = bno;
+ write_disk_entry (di->di_ib[INDIR_SINGLE], bno);
+ record_poke (di, sizeof (struct dinode));
+ }
+ else
+ {
+ daddr_t *diblock;
+
+ /* We need to set diblock to the double indirect block
+ array; see if the double indirect block is allocated. */
+ if (indirs[2].bno == 0)
+ {
+ /* This assert because triple indirection is not
+ supported. */
+ assert (indirs[2].offset == -1);
+ err = ffs_alloc (np, lbn,
+ ffs_blkpref (np, lbn,
+ INDIR_DOUBLE, di->di_ib),
+ sblock->fs_bsize, &bno, 0);
+ if (err)
+ goto out;
+ zero_disk_block (bno);
+ indirs[2].bno = bno;
+ write_disk_entry (di->di_ib[INDIR_DOUBLE], bno);
+ record_poke (di, sizeof (struct dinode));
+ }
+
+ diblock = indir_block (indirs[2].bno);
+ mark_indir_dirty (np, indirs[2].bno);
+
+ /* Now we can allocate the single indirect block */
+ err = ffs_alloc (np, lbn,
+ ffs_blkpref (np, lbn,
+ indirs[1].offset, diblock),
+ sblock->fs_bsize, &bno, 0);
+ if (err)
+ goto out;
+ zero_disk_block (bno);
+ indirs[1].bno = bno;
+ write_disk_entry (diblock[indirs[1].offset], bno);
+ record_poke (diblock, sblock->fs_bsize);
+ }
+ }
+
+ siblock = indir_block (indirs[1].bno);
+ mark_indir_dirty (np, indirs[1].bno);
+
+ /* Now we can allocate the data block. */
+ err = ffs_alloc (np, lbn,
+ ffs_blkpref (np, lbn, indirs[0].offset, siblock),
+ sblock->fs_bsize, &bno, 0);
+ if (err)
+ goto out;
+ offer_data (np, lbn * sblock->fs_bsize, sblock->fs_bsize,
+ (vm_address_t)zeroblock);
+ indirs[0].bno = bno;
+ write_disk_entry (siblock[indirs[0].offset], bno);
+ record_poke (siblock, sblock->fs_bsize);
+ }
+
+ out:
+ mach_port_deallocate (mach_task_self (), pagerpt);
+ if (!err)
+ {
+ int newallocsize;
+ if (lbn < NDADDR)
+ newallocsize = lbn * sblock->fs_bsize + size;
+ else
+ newallocsize = (lbn + 1) * sblock->fs_bsize;
+ assert (newallocsize > np->allocsize);
+ np->allocsize = newallocsize;
+ }
+
+ rwlock_writer_unlock (&np->dn->allocptrlock);
+
+ if (need_sync)
+ diskfs_file_update (np, 1);
+
+ return err;
+}
+
+/* Write something to each page from START to END inclusive of memory
+ object OBJ, but make sure the data doesns't actually change. */
+static void
+poke_pages (memory_object_t obj,
+ vm_offset_t start,
+ vm_offset_t end)
+{
+ vm_address_t addr, poke;
+ vm_size_t len;
+ error_t err;
+
+ while (start < end)
+ {
+ len = 8 * vm_page_size;
+ if (len > end - start)
+ len = end - start;
+ addr = 0;
+ err = vm_map (mach_task_self (), &addr, len, 0, 1, obj, start, 0,
+ VM_PROT_WRITE|VM_PROT_READ, VM_PROT_READ|VM_PROT_WRITE, 0);
+ if (!err)
+ {
+ for (poke = addr; poke < addr + len; poke += vm_page_size)
+ *(volatile int *)poke = *(volatile int *)poke;
+ munmap ((caddr_t) addr, len);
+ }
+ start += len;
+ }
+}
+
diff --git a/ufs/subr.c b/ufs/subr.c
new file mode 100644
index 00000000..2b356ddc
--- /dev/null
+++ b/ufs/subr.c
@@ -0,0 +1,264 @@
+/*
+ * Copyright (c) 1982, 1986, 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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.
+ *
+ * @(#)ffs_subr.c 8.2 (Berkeley) 9/21/93
+ */
+
+#include "ufs.h"
+
+#if 0 /* Not needed in GNU Hurd ufs. */
+/*
+ * Return buffer with the contents of block "offset" from the beginning of
+ * directory "ip". If "res" is non-zero, fill it in with a pointer to the
+ * remaining space in the directory.
+ */
+int
+ffs_blkatoff(ap)
+ struct vop_blkatoff_args /* {
+ struct vnode *a_vp;
+ off_t a_offset;
+ char **a_res;
+ struct buf **a_bpp;
+ } */ *ap;
+{
+ struct inode *ip;
+ register struct fs *fs;
+ struct buf *bp;
+ daddr_t lbn;
+ int bsize, error;
+
+ ip = VTOI(ap->a_vp);
+ fs = ip->i_fs;
+ lbn = lblkno(fs, ap->a_offset);
+ bsize = blksize(fs, ip, lbn);
+
+ *ap->a_bpp = NULL;
+ if (error = bread(ap->a_vp, lbn, bsize, NOCRED, &bp)) {
+ brelse(bp);
+ return (error);
+ }
+ if (ap->a_res)
+ *ap->a_res = (char *)bp->b_data + blkoff(fs, ap->a_offset);
+ *ap->a_bpp = bp;
+ return (0);
+}
+#endif /* 0 */
+
+/*
+ * Update the frsum fields to reflect addition or deletion
+ * of some frags.
+ */
+void
+ffs_fragacct(fs, fragmap, fraglist, cnt)
+ struct fs *fs;
+ int fragmap;
+ long fraglist[];
+ int cnt;
+{
+ int inblk;
+ register int field, subfield;
+ register int siz, pos;
+
+ inblk = (int)(fragtbl[fs->fs_frag][fragmap]) << 1;
+ fragmap <<= 1;
+ for (siz = 1; siz < fs->fs_frag; siz++) {
+ if ((inblk & (1 << (siz + (fs->fs_frag % NBBY)))) == 0)
+ continue;
+ field = around[siz];
+ subfield = inside[siz];
+ for (pos = siz; pos <= fs->fs_frag; pos++) {
+ if ((fragmap & field) == subfield) {
+ fraglist[siz] += cnt;
+ pos += siz;
+ field <<= siz;
+ subfield <<= siz;
+ }
+ field <<= 1;
+ subfield <<= 1;
+ }
+ }
+}
+
+#if 0 /* Not needed in GNU Hurd ufs. */
+void
+ffs_checkoverlap(bp, ip)
+ struct buf *bp;
+ struct inode *ip;
+{
+ register struct buf *ebp, *ep;
+ register daddr_t start, last;
+ struct vnode *vp;
+
+ ebp = &buf[nbuf];
+ start = bp->b_blkno;
+ last = start + btodb(bp->b_bcount) - 1;
+ for (ep = buf; ep < ebp; ep++) {
+ if (ep == bp || (ep->b_flags & B_INVAL) ||
+ ep->b_vp == NULLVP)
+ continue;
+ if (VOP_BMAP(ep->b_vp, (daddr_t)0, &vp, (daddr_t)0, NULL))
+ continue;
+ if (vp != ip->i_devvp)
+ continue;
+ /* look for overlap */
+ if (ep->b_bcount == 0 || ep->b_blkno > last ||
+ ep->b_blkno + btodb(ep->b_bcount) <= start)
+ continue;
+ vprint("Disk overlap", vp);
+ (void)printf("\tstart %d, end %d overlap start %d, end %d\n",
+ start, last, ep->b_blkno,
+ ep->b_blkno + btodb(ep->b_bcount) - 1);
+ panic("Disk buffer overlap");
+ }
+}
+#endif /* 0 */
+
+/*
+ * block operations
+ *
+ * check if a block is available
+ */
+int
+ffs_isblock(fs, cp, h)
+ struct fs *fs;
+ unsigned char *cp;
+ daddr_t h;
+{
+ unsigned char mask;
+
+ switch ((int)fs->fs_frag) {
+ case 8:
+ return (cp[h] == 0xff);
+ case 4:
+ mask = 0x0f << ((h & 0x1) << 2);
+ return ((cp[h >> 1] & mask) == mask);
+ case 2:
+ mask = 0x03 << ((h & 0x3) << 1);
+ return ((cp[h >> 2] & mask) == mask);
+ case 1:
+ mask = 0x01 << (h & 0x7);
+ return ((cp[h >> 3] & mask) == mask);
+ default:
+ assert (0);
+ }
+}
+
+/*
+ * take a block out of the map
+ */
+void
+ffs_clrblock(fs, cp, h)
+ struct fs *fs;
+ u_char *cp;
+ daddr_t h;
+{
+
+ switch ((int)fs->fs_frag) {
+ case 8:
+ cp[h] = 0;
+ return;
+ case 4:
+ cp[h >> 1] &= ~(0x0f << ((h & 0x1) << 2));
+ return;
+ case 2:
+ cp[h >> 2] &= ~(0x03 << ((h & 0x3) << 1));
+ return;
+ case 1:
+ cp[h >> 3] &= ~(0x01 << (h & 0x7));
+ return;
+ default:
+ assert (0);
+ }
+}
+
+/*
+ * put a block into the map
+ */
+void
+ffs_setblock(fs, cp, h)
+ struct fs *fs;
+ unsigned char *cp;
+ daddr_t h;
+{
+
+ switch ((int)fs->fs_frag) {
+
+ case 8:
+ cp[h] = 0xff;
+ return;
+ case 4:
+ cp[h >> 1] |= (0x0f << ((h & 0x1) << 2));
+ return;
+ case 2:
+ cp[h >> 2] |= (0x03 << ((h & 0x3) << 1));
+ return;
+ case 1:
+ cp[h >> 3] |= (0x01 << (h & 0x7));
+ return;
+ default:
+ assert (0);
+ }
+}
+
+/* Taken from 4.4 BSD sys/libkern/skpc.c:
+ @(#)skpc.c 8.1 (Berkeley) 6/10/93
+*/
+int
+skpc(mask0, size, cp0)
+ int mask0;
+ int size;
+ char *cp0;
+{
+ register u_char *cp, *end, mask;
+
+ mask = mask0;
+ cp = (u_char *)cp0;
+ for (end = &cp[size]; cp < end && *cp == mask; ++cp);
+ return (end - cp);
+}
+
+/* Taken from 4.4 BSD sys/libkern/scanc.c:
+ @(#)scanc.c 8.1 (Berkeley) 6/10/93
+*/
+int
+scanc(size, cp, table, mask0)
+ u_int size;
+ register u_char *cp, table[];
+ int mask0;
+{
+ register u_char *end;
+ register u_char mask;
+
+ mask = mask0;
+ for (end = &cp[size]; cp < end && (table[*cp] & mask) == 0; ++cp);
+ return (end - cp);
+}
diff --git a/ufs/tables.c b/ufs/tables.c
new file mode 100644
index 00000000..d345b9e4
--- /dev/null
+++ b/ufs/tables.c
@@ -0,0 +1,138 @@
+/* Modified from BSD for GNU Hurd ufs server by Michael I. Bushnell. */
+/*
+ * Copyright (c) 1982, 1986, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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.
+ *
+ * @(#)ffs_tables.c 8.1 (Berkeley) 6/11/93
+ */
+
+#include <sys/types.h>
+#include "fs.h"
+
+/*
+ * Bit patterns for identifying fragments in the block map
+ * used as ((map & around) == inside)
+ */
+int around[9] = {
+ 0x3, 0x7, 0xf, 0x1f, 0x3f, 0x7f, 0xff, 0x1ff, 0x3ff
+};
+int inside[9] = {
+ 0x0, 0x2, 0x6, 0xe, 0x1e, 0x3e, 0x7e, 0xfe, 0x1fe
+};
+
+/*
+ * Given a block map bit pattern, the frag tables tell whether a
+ * particular size fragment is available.
+ *
+ * used as:
+ * if ((1 << (size - 1)) & fragtbl[fs->fs_frag][map] {
+ * at least one fragment of the indicated size is available
+ * }
+ *
+ * These tables are used by the scanc instruction on the VAX to
+ * quickly find an appropriate fragment.
+ */
+u_char fragtbl124[256] = {
+ 0x00, 0x16, 0x16, 0x2a, 0x16, 0x16, 0x26, 0x4e,
+ 0x16, 0x16, 0x16, 0x3e, 0x2a, 0x3e, 0x4e, 0x8a,
+ 0x16, 0x16, 0x16, 0x3e, 0x16, 0x16, 0x36, 0x5e,
+ 0x16, 0x16, 0x16, 0x3e, 0x3e, 0x3e, 0x5e, 0x9e,
+ 0x16, 0x16, 0x16, 0x3e, 0x16, 0x16, 0x36, 0x5e,
+ 0x16, 0x16, 0x16, 0x3e, 0x3e, 0x3e, 0x5e, 0x9e,
+ 0x2a, 0x3e, 0x3e, 0x2a, 0x3e, 0x3e, 0x2e, 0x6e,
+ 0x3e, 0x3e, 0x3e, 0x3e, 0x2a, 0x3e, 0x6e, 0xaa,
+ 0x16, 0x16, 0x16, 0x3e, 0x16, 0x16, 0x36, 0x5e,
+ 0x16, 0x16, 0x16, 0x3e, 0x3e, 0x3e, 0x5e, 0x9e,
+ 0x16, 0x16, 0x16, 0x3e, 0x16, 0x16, 0x36, 0x5e,
+ 0x16, 0x16, 0x16, 0x3e, 0x3e, 0x3e, 0x5e, 0x9e,
+ 0x26, 0x36, 0x36, 0x2e, 0x36, 0x36, 0x26, 0x6e,
+ 0x36, 0x36, 0x36, 0x3e, 0x2e, 0x3e, 0x6e, 0xae,
+ 0x4e, 0x5e, 0x5e, 0x6e, 0x5e, 0x5e, 0x6e, 0x4e,
+ 0x5e, 0x5e, 0x5e, 0x7e, 0x6e, 0x7e, 0x4e, 0xce,
+ 0x16, 0x16, 0x16, 0x3e, 0x16, 0x16, 0x36, 0x5e,
+ 0x16, 0x16, 0x16, 0x3e, 0x3e, 0x3e, 0x5e, 0x9e,
+ 0x16, 0x16, 0x16, 0x3e, 0x16, 0x16, 0x36, 0x5e,
+ 0x16, 0x16, 0x16, 0x3e, 0x3e, 0x3e, 0x5e, 0x9e,
+ 0x16, 0x16, 0x16, 0x3e, 0x16, 0x16, 0x36, 0x5e,
+ 0x16, 0x16, 0x16, 0x3e, 0x3e, 0x3e, 0x5e, 0x9e,
+ 0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x7e,
+ 0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x7e, 0xbe,
+ 0x2a, 0x3e, 0x3e, 0x2a, 0x3e, 0x3e, 0x2e, 0x6e,
+ 0x3e, 0x3e, 0x3e, 0x3e, 0x2a, 0x3e, 0x6e, 0xaa,
+ 0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x7e,
+ 0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x7e, 0xbe,
+ 0x4e, 0x5e, 0x5e, 0x6e, 0x5e, 0x5e, 0x6e, 0x4e,
+ 0x5e, 0x5e, 0x5e, 0x7e, 0x6e, 0x7e, 0x4e, 0xce,
+ 0x8a, 0x9e, 0x9e, 0xaa, 0x9e, 0x9e, 0xae, 0xce,
+ 0x9e, 0x9e, 0x9e, 0xbe, 0xaa, 0xbe, 0xce, 0x8a,
+};
+
+u_char fragtbl8[256] = {
+ 0x00, 0x01, 0x01, 0x02, 0x01, 0x01, 0x02, 0x04,
+ 0x01, 0x01, 0x01, 0x03, 0x02, 0x03, 0x04, 0x08,
+ 0x01, 0x01, 0x01, 0x03, 0x01, 0x01, 0x03, 0x05,
+ 0x02, 0x03, 0x03, 0x02, 0x04, 0x05, 0x08, 0x10,
+ 0x01, 0x01, 0x01, 0x03, 0x01, 0x01, 0x03, 0x05,
+ 0x01, 0x01, 0x01, 0x03, 0x03, 0x03, 0x05, 0x09,
+ 0x02, 0x03, 0x03, 0x02, 0x03, 0x03, 0x02, 0x06,
+ 0x04, 0x05, 0x05, 0x06, 0x08, 0x09, 0x10, 0x20,
+ 0x01, 0x01, 0x01, 0x03, 0x01, 0x01, 0x03, 0x05,
+ 0x01, 0x01, 0x01, 0x03, 0x03, 0x03, 0x05, 0x09,
+ 0x01, 0x01, 0x01, 0x03, 0x01, 0x01, 0x03, 0x05,
+ 0x03, 0x03, 0x03, 0x03, 0x05, 0x05, 0x09, 0x11,
+ 0x02, 0x03, 0x03, 0x02, 0x03, 0x03, 0x02, 0x06,
+ 0x03, 0x03, 0x03, 0x03, 0x02, 0x03, 0x06, 0x0a,
+ 0x04, 0x05, 0x05, 0x06, 0x05, 0x05, 0x06, 0x04,
+ 0x08, 0x09, 0x09, 0x0a, 0x10, 0x11, 0x20, 0x40,
+ 0x01, 0x01, 0x01, 0x03, 0x01, 0x01, 0x03, 0x05,
+ 0x01, 0x01, 0x01, 0x03, 0x03, 0x03, 0x05, 0x09,
+ 0x01, 0x01, 0x01, 0x03, 0x01, 0x01, 0x03, 0x05,
+ 0x03, 0x03, 0x03, 0x03, 0x05, 0x05, 0x09, 0x11,
+ 0x01, 0x01, 0x01, 0x03, 0x01, 0x01, 0x03, 0x05,
+ 0x01, 0x01, 0x01, 0x03, 0x03, 0x03, 0x05, 0x09,
+ 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x07,
+ 0x05, 0x05, 0x05, 0x07, 0x09, 0x09, 0x11, 0x21,
+ 0x02, 0x03, 0x03, 0x02, 0x03, 0x03, 0x02, 0x06,
+ 0x03, 0x03, 0x03, 0x03, 0x02, 0x03, 0x06, 0x0a,
+ 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x07,
+ 0x02, 0x03, 0x03, 0x02, 0x06, 0x07, 0x0a, 0x12,
+ 0x04, 0x05, 0x05, 0x06, 0x05, 0x05, 0x06, 0x04,
+ 0x05, 0x05, 0x05, 0x07, 0x06, 0x07, 0x04, 0x0c,
+ 0x08, 0x09, 0x09, 0x0a, 0x09, 0x09, 0x0a, 0x0c,
+ 0x10, 0x11, 0x11, 0x12, 0x20, 0x21, 0x40, 0x80,
+};
+
+/*
+ * The actual fragtbl array.
+ */
+u_char *fragtbl[MAXFRAG + 1] = {
+ 0, fragtbl124, fragtbl124, 0, fragtbl124, 0, 0, 0, fragtbl8,
+};
diff --git a/ufs/ufs.h b/ufs/ufs.h
new file mode 100644
index 00000000..5d823ebc
--- /dev/null
+++ b/ufs/ufs.h
@@ -0,0 +1,289 @@
+/*
+ Copyright (C) 1994, 1995, 1996, 1997, 1999 Free Software Foundation
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#include <mach.h>
+#include <hurd.h>
+#include <sys/mman.h>
+#include <hurd/ports.h>
+#include <hurd/pager.h>
+#include <hurd/fshelp.h>
+#include <hurd/iohelp.h>
+#include <hurd/diskfs.h>
+#include <sys/mman.h>
+#include <assert.h>
+#include "fs.h"
+#include "dinode.h"
+
+/* Define this if memory objects should not be cached by the kernel.
+ Normally, don't define it, but defining it causes a much greater rate
+ of paging requests, which may be helpful in catching bugs. */
+
+/* #undef DONT_CACHE_MEMORY_OBJECTS */
+
+struct disknode
+{
+ ino_t number;
+
+ int dir_idx;
+
+ /* For a directory, this array holds the number of directory entries in
+ each DIRBLKSIZE piece of the directory. */
+ int *dirents;
+
+ /* Links on hash list. */
+ struct node *hnext, **hprevp;
+
+ struct rwlock allocptrlock;
+
+ struct dirty_indir *dirty;
+
+ struct user_pager_info *fileinfo;
+};
+
+/* Identifies a particular block and where it's found
+ when interpreting indirect block structure. */
+struct iblock_spec
+{
+ /* Disk address of block */
+ daddr_t bno;
+
+ /* Offset in next block up; -1 if it's in the inode itself. */
+ int offset;
+};
+
+/* Identifies an indirect block owned by this file which
+ might be dirty. */
+struct dirty_indir
+{
+ daddr_t bno; /* Disk address of block. */
+ struct dirty_indir *next;
+};
+
+struct user_pager_info
+{
+ struct node *np;
+ enum pager_type
+ {
+ DISK,
+ FILE_DATA,
+ } type;
+ struct pager *p;
+ vm_prot_t max_prot;
+
+ vm_offset_t allow_unlocked_pagein;
+ vm_size_t unlocked_pagein_length;
+};
+
+#include <hurd/diskfs-pager.h>
+
+/* The physical media. */
+extern struct store *store;
+/* What the user specified. */
+extern struct store_parsed *store_parsed;
+
+/* Mapped image of the disk. */
+extern void *disk_image;
+
+extern void *zeroblock;
+
+extern struct fs *sblock;
+extern struct csum *csum;
+int sblock_dirty;
+int csum_dirty;
+
+spin_lock_t node2pagelock;
+
+spin_lock_t alloclock;
+
+spin_lock_t gennumberlock;
+u_long nextgennumber;
+
+spin_lock_t unlocked_pagein_lock;
+
+/* The compat_mode specifies whether or not we write
+ extensions onto the disk. */
+enum compat_mode
+{
+ COMPAT_GNU = 0,
+ COMPAT_BSD42 = 1,
+ COMPAT_BSD44 = 2,
+} compat_mode;
+
+/* If this is set, then this filesystem has two extensions:
+ 1) directory entries include the type field.
+ 2) symlink targets might be written directly in the di_db field
+ of the dinode. */
+int direct_symlink_extension;
+
+/* If this is set, then the disk is byteswapped from native order. */
+int swab_disk;
+
+/* Number of device blocks per DEV_BSIZE block. */
+unsigned log2_dev_blocks_per_dev_bsize;
+
+/* Handy macros */
+#define DEV_BSIZE 512
+#define NBBY 8
+#define btodb(n) ((n) / DEV_BSIZE)
+#define howmany(x,y) (((x)+((y)-1))/(y))
+#define roundup(x, y) ((((x)+((y)-1))/(y))*(y))
+#define isclr(a, i) (((a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0)
+#define isset(a, i) ((a)[(i)/NBBY] & (1<<((i)%NBBY)))
+#define setbit(a,i) ((a)[(i)/NBBY] |= 1<<((i)%NBBY))
+#define clrbit(a,i) ((a)[(i)/NBBY] &= ~(1<<(i)%NBBY))
+#define fsaddr(fs,n) (fsbtodb(fs,n)*DEV_BSIZE)
+
+
+/* Functions for looking inside disk_image */
+
+/* Convert an inode number to the dinode on disk. */
+extern inline struct dinode *
+dino (ino_t inum)
+{
+ return (struct dinode *)
+ (disk_image
+ + fsaddr (sblock, ino_to_fsba (sblock, inum))
+ + ino_to_fsbo (sblock, inum) * sizeof (struct dinode));
+}
+
+/* Convert a indirect block number to a daddr_t table. */
+extern inline daddr_t *
+indir_block (daddr_t bno)
+{
+ return (daddr_t *) (disk_image + fsaddr (sblock, bno));
+}
+
+/* Convert a cg number to the cylinder group. */
+extern inline struct cg *
+cg_locate (int ncg)
+{
+ return (struct cg *) (disk_image + fsaddr (sblock, cgtod (sblock, ncg)));
+}
+
+/* Sync part of the disk */
+extern inline void
+sync_disk_blocks (daddr_t blkno, size_t nbytes, int wait)
+{
+ pager_sync_some (diskfs_disk_pager, fsaddr (sblock, blkno), nbytes, wait);
+}
+
+/* Sync an disk inode */
+extern inline void
+sync_dinode (int inum, int wait)
+{
+ sync_disk_blocks (ino_to_fsba (sblock, inum), sblock->fs_fsize, wait);
+}
+
+
+/* Functions for byte swapping */
+extern inline short
+swab_short (short arg)
+{
+ return (((arg & 0xff) << 8)
+ | ((arg & 0xff00) >> 8));
+}
+
+extern inline long
+swab_long (long arg)
+{
+ return (((long) swab_short (arg & 0xffff) << 16)
+ | swab_short ((arg & 0xffff0000) >> 16));
+}
+
+extern inline long long
+swab_long_long (long long arg)
+{
+ return (((long long) swab_long (arg & 0xffffffff) << 32)
+ | swab_long ((arg & 0xffffffff00000000LL) >> 32));
+}
+
+/* Return ENTRY, after byteswapping it if necessary */
+#define read_disk_entry(entry) \
+({ \
+ typeof (entry) ret; \
+ if (!swab_disk || sizeof (entry) == 1) \
+ ret = (entry); \
+ else if (sizeof (entry) == 2) \
+ ret = swab_short (entry); \
+ else if (sizeof (entry) == 4) \
+ ret = swab_long (entry); \
+ else \
+ abort (); \
+ ret; \
+})
+
+/* Execute A = B, but byteswap it along the way if necessary */
+#define write_disk_entry(a,b) \
+({ \
+ if (!swab_disk || sizeof (a) == 1) \
+ ((a) = (b)); \
+ else if (sizeof (a) == 2) \
+ ((a) = (swab_short (b))); \
+ else if (sizeof (a) == 4) \
+ ((a) = (swab_long (b))); \
+ else \
+ abort (); \
+})
+
+
+
+
+
+/* From alloc.c: */
+error_t ffs_alloc (struct node *, daddr_t, daddr_t, int, daddr_t *,
+ struct protid *);
+void ffs_blkfree(struct node *, daddr_t bno, long size);
+daddr_t ffs_blkpref (struct node *, daddr_t, int, daddr_t *);
+error_t ffs_realloccg(struct node *, daddr_t, daddr_t,
+ int, int, daddr_t *, struct protid *);
+
+/* From bmap.c */
+error_t fetch_indir_spec (struct node *, daddr_t, struct iblock_spec *);
+void mark_indir_dirty (struct node *, daddr_t);
+
+/* From hyper.c: */
+void get_hypermetadata (void);
+void copy_sblock (void);
+
+/* From inode.c: */
+struct node *ifind (ino_t ino);
+void inode_init (void);
+void write_all_disknodes (void);
+
+/* From pager.c: */
+void create_disk_pager (void);
+void din_map (struct node *);
+void sin_map (struct node *);
+void sin_remap (struct node *, int);
+void sin_unmap (struct node *);
+void din_unmap (struct node *);
+void drop_pager_softrefs (struct node *);
+void allow_pager_softrefs (struct node *);
+void flush_node_pager (struct node *);
+
+/* From subr.c: */
+void ffs_fragacct (struct fs *, int, long [], int);
+int ffs_isblock(struct fs *, u_char *, daddr_t);
+void ffs_clrblock(struct fs *, u_char *, daddr_t);
+void ffs_setblock (struct fs *, u_char *, daddr_t);
+int skpc (int, int, char *);
+int scanc (u_int, u_char *, u_char [], int);
+
+/* From pokeloc.c: */
+void record_poke (void *, vm_size_t);
+void sync_disk (int);
+void flush_pokes ();