[bug #29809] creating a firmlink loop results in memory exhaustion

2010-05-06 Thread Justus Winter

URL:
  

 Summary: creating a firmlink loop results in memory
exhaustion
 Project: The GNU Hurd
Submitted by: teythoon
Submitted on: Thu 06 May 2010 05:09:09 PM GMT
Category: Hurd
Severity: 3 - Normal
Priority: 5 - Normal
  Item Group: None
  Status: None
 Privacy: Public
 Assigned to: None
 Originator Name: 
Originator Email: 
 Open/Closed: Open
 Discussion Lock: Any
 Reproducibility: Every Time
  Size (loc): None
 Planned Release: None
  Effort: 0.00
Wiki-like text discussion box: 

___

Details:

cd /tmp ; touch bla ; settrans -f bla /hurd/firmlink bla ; ls bla

* wait some time, play around with vmstat or the like
* and the pager will start to flood the console with

(default pager): dropping data_request because of previous paging errors





___

Reply to this item at:

  

___
  Message sent via/by Savannah
  http://savannah.gnu.org/





[bug #29809] creating a firmlink loop results in memory exhaustion

2010-05-06 Thread Justus Winter

Follow-up Comment #1, bug #29809 (project hurd):

As suggested by antrik in #hurd here is a log of the port usage of both
ext2fs and firmlink (both eat up more and more memory) measured once every
second using portinfo $PID | wc --lines:

r...@hurdbox:~# ps ax | egrep '(ext2fs|firmlink)'
root 3  - Ro0:05.51 ext2fs --readonly
--multiboot-command-line=root
root   345  - R 0:00.47 /hurd/firmlink foo
root   348 p0 S 0:00.01 egrep (ext2fs|firmlink)
r...@hurdbox:~# ./port_count 3 345
  0: 23276 22956 
  1: 27901 27541 
  2: 32182 31846 
  3: 36311 36066 
  4: 40491 40276 
  5: 44646 44376 
  6: 48641 48461 
  7: 52716 52501 
  8: 56652 56461 
  9: 60601 60426 
 10: 64521 64341 
 11: 68506 68356 
 12: 72436 72346 
 13: 76449 76386 


___

Reply to this item at:

  

___
  Message sent via/by Savannah
  http://savannah.gnu.org/





Debian GNU/Hurd installation wizard and live cd

2010-05-08 Thread Justus Winter
Hey everyone :)

I just wanted to say hello and to inform you about two young pet
projects of mine, an installation wizard in the spirit of the OpenBSD
installer and a script to master live cds from existing systems.

I've created one live cd that is able to install a Debian GNU/Hurd
system. It can install grub2 and includes all the debian archives
necessary to complete the installation.

The image is available as an xz-compressed iso image under [0]. You can
download it via http or BitTorrent (hopefully).

The installer lives in an mercurial repository under [1], there is a
local checkout on that server so you can browse the most recent version
there.

The live cd master script can be found in [2] in the near future. For
now I documented my setup in the readme file. Getting the live cd right
took quite some time and I remastered the cd on my linux box to save
time and now I need to integrate all those little things I changed back
into the script and verify that it actually works.

Btw, I know about the plan to get the debian-installer running on the
Hurd and I don't want compete with it. But it always bugged me that one
needed one operating system to install another one and the lessons
learned with both the installer and the live cd will greatly benefit
debian-installer as well imho.

Well, that's it, I'd love to get some feedback and don't spare me some
doh! moments ;)

Justus

0: http://teythoon.cryptobitch.de/hurd/livecd/
1: http://teythoon.cryptobitch.de/hurd/hurd-installer/
2: http://teythoon.cryptobitch.de/hurd/hurd-livecd/


signature.asc
Description: PGP signature


Re: Debian GNU/Hurd installation wizard and live cd

2010-05-09 Thread Justus Winter
On Mon, 10 May 2010 00:20:43 +0200
Samuel Thibault  wrote:

> Justus Winter, le Sun 09 May 2010 00:01:12 +0200, a écrit :
> > Btw, I know about the plan to get the debian-installer running on
> > the Hurd and I don't want compete with it. But it always bugged me
> > that one needed one operating system to install another one and the
> > lessons learned with both the installer and the live cd will
> > greatly benefit debian-installer as well imho.
> 
> Mmm, just to make sure you know it: the plan is to use a Hurd system
> for the hurd-i386 debian installer.
Well, sure, I assumed that much. I was referring to the two stage
crosshurd method.

Justus


signature.asc
Description: PGP signature


Re: Short circuiting data_unlock in ext2fs

2010-05-11 Thread Justus Winter
On Tue, 11 May 2010 19:19:01 +0200
Sergio Lopez  wrote:

> Hi,
> 
> I think short circuiting data_unlock requests in ext2fs (by allocating
> the page in file_pager_read_page and returning it unlocked) could
> improve file growing performance a bit.
> 
> I've tested it in qemu (with kvm), using "dd" to sequentially write
> blocks to a file, obtaining an improvement of 10%. I'd like to test it
> in real hardware, but currently I don't have a spare machine to do
> that. If someone can try it (it's a small patch, and it just requires
> to rebuild ext2fs), please let us know the results.

Okay, I ran the attached script with both the vanilla ext2fs (source
taken from the most recent debian package) and the one with your patch
both compiled on my machine.

The script executes two tests, creating a 51mb file using dd and
untarring the hurd source (~17mb) on a newly created fs on an 17gb
partition. The box is an athlon 1500+ iirc. From the dmesg:

r...@ganymede:/home/teythoon/bin# grep -A4 ^ide: /var/log/dmesg
ide: SiS 5513 (dual FIFO) DMA Bus Mastering IDE 
Controller on PCI bus 0 function 21
ide0: BM-DMA at 0xff00-0xff07
ide1: BM-DMA at 0xff08-0xff0f
hd0: WDC WD400EB-75CPF0, 38166MB w/2048kB Cache, CHS=4865/255/63

And here are the results:

Benchmarking /home/teythoon/ext2fs.vanilla...
Running 'dd if=/dev/zero of=/mnt/sink bs=1M count=51'...
2.28 2.27 2.28 2.30 2.30 Average: 2.286
Running 'tar xf /tmp/ramdisk/hurd_20090404.orig.tar.gz -C /mnt'...
23.23 23.15 23.26 23.02 23.13 Average: 23.158
Benchmarking /home/teythoon/ext2fs.sc_unlock...
Running 'dd if=/dev/zero of=/mnt/sink bs=1M count=51'...
2.32 2.06 2.33 2.09 2.36 Average: 2.232
Running 'tar xf /tmp/ramdisk/hurd_20090404.orig.tar.gz -C /mnt'...
23.00 23.15 23.08 22.84 22.73 Average: 22.96

If there's anything wrong with my benchmarking method or if you want me
to increase the amount of data written or the number of runs, please
let me know.

Justus


benchmark
Description: Binary data


signature.asc
Description: PGP signature


Re: Short circuiting data_unlock in ext2fs

2010-05-11 Thread Justus Winter
On Wed, 12 May 2010 06:19:29 +0200
Justus Winter <4win...@informatik.uni-hamburg.de> wrote:
> And here are the results:
> 
> Benchmarking /home/teythoon/ext2fs.vanilla...
> Running 'dd if=/dev/zero of=/mnt/sink bs=1M count=51'...
> 2.28 2.27 2.28 2.30 2.30 Average: 2.286
> Running 'tar xf /tmp/ramdisk/hurd_20090404.orig.tar.gz -C /mnt'...
> 23.23 23.15 23.26 23.02 23.13 Average: 23.158
> Benchmarking /home/teythoon/ext2fs.sc_unlock...
> Running 'dd if=/dev/zero of=/mnt/sink bs=1M count=51'...
> 2.32 2.06 2.33 2.09 2.36 Average: 2.232
> Running 'tar xf /tmp/ramdisk/hurd_20090404.orig.tar.gz -C /mnt'...
> 23.00 23.15 23.08 22.84 22.73 Average: 22.96
> 
> If there's anything wrong with my benchmarking method or if you want
> me to increase the amount of data written or the number of runs,
> please let me know.

Since the performance of my hard drive is of little interest here, I
ran the script again, once with the call to sync removed and once with
a storeio based ramdisk as backend:

Benchmarking /home/teythoon/ext2fs.vanilla...
Running 'dd if=/dev/zero of=/mnt/sink bs=1M count=51'...
2.05 2.29 2.07 2.25 2.19 Average: 2.17
Running 'tar xf /tmp/ramdisk/hurd_20090404.orig.tar.gz -C /mnt'...
24.08 23.22 22.94 23.56 22.89 Average: 23.338
Benchmarking /home/teythoon/ext2fs.sc_unlock...
Running 'dd if=/dev/zero of=/mnt/sink bs=1M count=51'...
2.32 2.00 2.40 2.05 2.30 Average: 2.214
Running 'tar xf /tmp/ramdisk/hurd_20090404.orig.tar.gz -C /mnt'...
22.74 22.94 23.26 23.41 23.06 Average: 23.082

Benchmarking /home/teythoon/ext2fs.vanilla.static...
Running 'dd if=/dev/zero of=/mnt/sink bs=1M count=51'...
2.60 2.48 2.56 2.52 2.55 Average: 2.542
Running 'tar xf /tmp/ramdisk/hurd_20090404.orig.tar.gz -C /mnt'...
18.70 18.70 18.67 18.78 18.75 Average: 18.72
Benchmarking /home/teythoon/ext2fs.sc_unlock.static...
Running 'dd if=/dev/zero of=/mnt/sink bs=1M count=51'...
2.30 2.35 2.30 2.30 2.30 Average: 2.31
Running 'tar xf /tmp/ramdisk/hurd_20090404.orig.tar.gz -C /mnt'...
18.73 18.74 18.78 18.75 18.80 Average: 18.76

Somehow I expected the performance of the storeio backed filesystem to
be somewhat better...

Justus


signature.asc
Description: PGP signature


Re: Short circuiting data_unlock in ext2fs

2010-05-12 Thread Justus Winter
On Wed, 12 May 2010 12:14:06 +0200
Sergio Lopez  wrote:
> Thanks for taking some time to test this. If possible, I'd like to see
> the results of "dd" writting longer files to disk. Also, the
> information that "dd" prints at the end of the proccess could be
> useful too.

Okay, I removed the tar test and the translators are started with
--no-sync. A log with the output from dd is attached.

r...@ganymede:/home/teythoon# bin/benchmark ext2fs.vanilla ext2fs.sc_unlock
Benchmarking ext2fs.vanilla...
Running 'dd if=/dev/zero of=/mnt/sink bs=1M count=204'...
12.60 16.64 12.48 16.69 12.63 16.72 12.71 16.76 12.89 16.80 Average: 14.692
Benchmarking ext2fs.sc_unlock...
Running 'dd if=/dev/zero of=/mnt/sink bs=1M count=204'...
11.85 15.72 12.02 15.72 12.06 15.73 12.19 16.29 12.39 16.26 Average: 14.023

Justus


log
Description: Binary data


signature.asc
Description: PGP signature


Re: Debian GNU/Hurd installation wizard and live cd

2010-07-09 Thread Justus Winter
Hey Arne :)

> On Sunday 09 May 2010 16:19:32 Arne Babenhauserheide wrote:
> > Am Sonntag, 9. Mai 2010, 00:01:12 schrieb Justus Winter:
> > > I just wanted to say hello and to inform you about two young pet
> > > projects of mine, an installation wizard in the spirit of the
> > > OpenBSD installer and a script to master live cds from existing
> > > systems.
> 
> > didn’t doublecheck them; the install script is very readable!), I
> > couldn’t yet try them, though.
> 
> I now got to testing it.
Cool, you are the first person of who tried the installer and gave me
some feedback :)

> Sadly install2 breaks for me in qemu with 
> 
> mkfs.ext2: Unknown code P 6 while trying to determine filesystem
> siz
> 
> (install works fine)
>
> Is there a simple way to fix that? 
Hm, I just retried the installation in kvm and creating the filesystem
worked for me. Just to be sure, did you restart the system to make
gnumach reread the partition table? I'm not sure how to debug this
further, I'd go with trying to manually create the filesystem, double
check the partition table and maybe boot grml or the like and see
whether mkfs.ext2 running on linux likes it.

While playing around with the image I noticed that the bittorrent
tracker I used went offline (thanks Hollywood >,<) so I'll publish a
new torrent file with updated tracker information.

I also thought about mastering a new live cd containing updated
packages and other goodies (like the debian-ports signing key from the
official archives :) but on the other hand I'm not sure if it's worth
the trouble seeing that Jérémies work on the d-i seems to be
progressing nicely and quite frankly I got almost no feedback despite
being mentioned on last months newsletter (thanks for that ;).

(btw, the installation just finished in my kvm instance and yielded
a booting debian system.)

Cheers,
Justus


signature.asc
Description: PGP signature


Re: Porting Debian Packages

2012-01-18 Thread Justus Winter
Hi Tanguy :)

In-Reply-To: 

Quoting Tanguy LE CARROUR (2012-01-18 10:19:14)
>For sure, once it builds on Linux I have to try it on Hurd.
>But the build process take longer in my qemu. And I'm used to use pbuild which
>is also a bit of an overhead.
>
>[...]
>
>I do the same but all network related processes are wy slower! 
>"apt-get update" take ages! Same when I went to download a package
>dependencies!
>
>Anyway I have first to get comfortable with the "fix/build/create
>patch" process before moving to a "currently slower" environment!

Running kvm/qemu with -drive [...],cache=writeback results in an
enormous speedup. I found the hint in the gnu hurd wiki, but
unfortunately it is unavailable today.

Justus



Re: [GSoC] Virtualization Using Hurd Mechanisms

2012-04-12 Thread Justus Winter
Quoting Pierre Thierry (2012-04-12 11:47:23)
>Hi all,
>
>this year I applied for a slot in Google's Summer of Code on the
>Hurd[1], to tackle virtualization à la Hurd. As I currently have no
>other commitments during the summer, I will be able work on this
>project between half-time and full-time, during the whole summer.
>
>  1. 
> http://google-melange.appspot.com/gsoc/proposal/review/google/gsoc2012/nowhereman/1
>
>As I describe it in my application, I'll start from user stories (or
>scenarii). I have a few in mind, but if you have your own ideas, I'll
>take them gladly; the more the merrier, and foremost, the more stories
>I get, the least I risk missing an important piece of requirement for
>the tool.

I'd love to see your tool being implemented as a libvirt backend.

Justus



Re: Hurd GSoC 2013 projects

2013-06-01 Thread Justus Winter
Hi everyone :)

Quoting Thomas Schwinge (2013-06-01 11:00:40)
> First, congratulations again for getting your applications accepted!  In
> no particular order: 陆岳 (Yue Lu) »Improve the GDB Port for GNU Hurd«,
> ;

Hi Yue Lu, as someone who was frustrated by gdb on the Hurd in the
past, your project is highly appreciated. May I ask how you like to be
addressed? I'm fuzzy about what your first and what you second name
is...

> Fotis Koutoulakis »Porting the GCC go language frontend on the GNU/HURD
> kernel«,
> ;

Hi Fotis, this is very nice. I grew quite fond of Go and will use it
for my project as well. I have written a model checker in Go and look
forward to use it on Hurd. If it would be possible to write
translators in Go this would enable one to write say a translator that
enforces a security policy and have that policy code verified. FWIW
the code is at https://bitbucket.org/teythoon/vgo

> Copyright assignment. [...]

Will do that.

> Weekly reports.

Check.

> Next steps.  It's now the community bonding period, in which you're to
> continue interacting with the projects' community, and slowly begin
> working towards your GSoC projects (subject to first finishing your
> university work, of course).

Anything Debian-specific stuff I can do to bond more strongly with
Debian?

> For example, now it's high time to make
> sure that you have the development environment/infrastructure for working
> on your GSoC project: a suitably powered machine, etc.

I took the opportunity to upgrade my main machine. SSD arrived today
and since I'm going to work a lot with Qemu, this machine could use
the two extra gigs of ram that are laying around here but that I
cannot install in the current mainboad b/c it's so tiny. Replacement
mainboard is due to arrive here this week.

> Justus, anything you need?

Yes. Maybe. I read about the UDD and [0] suggests that one could
access from wagner (alioth). I thought about querying it for relevant
bug reports. Is that worth doing? If so, how do I get an account on
this machine?

Viele Gruesse,
Justus



pbuilder problems

2013-06-08 Thread Justus Winter
Hi :)

I'm trying to setup pbuilder on one of my virtual Hurd
systems. Problem is that debootstrap eventually dies:

 /var/cache/apt/archives/readline-common_6.2+dfsg-0.1_all.deb
 /var/cache/apt/archives/xz-utils_5.1.1alpha+20120614-2_hurd-i386.deb
(Reading database ... 6919 files and directories currently installed.)
Unpacking apt (from .../apt_0.9.8.2_hurd-i386.deb) ...
dpkg: error processing /var/cache/apt/archives/apt_0.9.8.2_hurd-i386.deb 
(--unpack):
 unable to install new version of `./usr/lib/apt': Resource temporarily 
unavailable
dpkg-deb: error: subprocess paste was killed by signal (Broken pipe)
Unpacking libapt-pkg4.12:hurd-i386 (from 
.../libapt-pkg4.12_0.9.8.2_hurd-i386.deb) ...
dpkg: error processing 
/var/cache/apt/archives/libapt-pkg4.12_0.9.8.2_hurd-i386.deb (--unpack):
 unable to install new version of `./usr/share/locale/cy': Resource temporarily 
unavailable
dpkg-deb: error: subprocess paste was killed by signal (Broken pipe)
[.. more errors like this..]

I suspect that something funny goes on in the rootfs translator (it's
an one filesystem setup, maybe I should create another filesystem to
protect the rootfs), b/c I end up with an mostly empty /dev:

% ls /dev
cons fd null vcs

Not sure if anything else got corrupted, I noticed the /dev issue b/c
it renders the system unbootable. Fortunately reinstalling the hurd
package fixes this. I've been able to reproduce this whole issue once.

Then again, it could be some mach issue b/c the network connection
also dies shortly after the this and the system is in a bad
shape. E. g. ls /proc shows /proc/meminfo, but opening that file fails
with no such file.

The Debian/Hurd system is an up-to-date debian/sid
debian-ports/unreleased system. It has 512 megs of RAM and 300 megs
swap, all of which is unused. vmstat shows 200 megs of free RAM
*now*. The system is still running and accessible via console. Any
hints how to debug this further would be appreciated.

Fwiw the host is Debian/Linux wheezy, virtualization is
libvirt/kvm. kvm invocation:

/usr/bin/kvm -S -M pc-1.1 -cpu 
Opteron_G3,+ibs,+osvw,+3dnowprefetch,+cr8legacy,+extapic,+cmp_legacy,+3dnow,+3dnowext,+pdpe1gb,+fxsr_opt,+mmxext,+ht,+vme
 -enable-kvm -m 512 -smp 1,sockets=1,cores=1,threads=1 -name hurdbox -uuid 
207e086a-7ab4-e39d-6655-effed9ec2280 -no-user-config -nodefaults -chardev 
socket,id=charmonitor,path=/var/lib/libvirt/qemu/hurdbox.monitor,server,nowait 
-mon chardev=charmonitor,id=monitor,mode=control -rtc base=utc -no-shutdown 
-device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 -drive 
file=/media/sdb2/libvirt-pool/hurdbox.img,if=none,id=drive-ide0-0-0,format=qcow2,cache=writeback
 -device ide-hd,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0,bootindex=2 
-drive if=none,id=drive-ide0-1-0,readonly=on,format=raw -device 
ide-cd,bus=ide.1,unit=0,drive=drive-ide0-1-0,id=ide0-1-0,bootindex=1 -netdev 
tap,fd=20,id=hostnet0 -device 
rtl8139,netdev=hostnet0,id=net0,mac=52:54:00:6b:6d:f7,bus=pci.0,addr=0x3 
-chardev pty,id=charserial0 -device isa-serial,chardev=charserial0,id=serial0 
-vnc 127.0.0.1:0 -k en-us -vga cirrus -device 
intel-hda,id=sound0,bus=pci.0,addr=0x4 -device 
hda-duplex,id=sound0-codec0,bus=sound0.0,cad=0 -device 
virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x5

Am I missing something?

Cheers,
Justus



Re: pbuilder problems

2013-06-08 Thread Justus Winter
Quoting Samuel Thibault (2013-06-08 13:34:18)
> Justus Winter, le Sat 08 Jun 2013 13:27:07 +0200, a écrit :
> > I'm trying to setup pbuilder on one of my virtual Hurd
> > systems. Problem is that debootstrap eventually dies:
> 
> I don't think pbuilder has ever been made to work on hurd-i386. There
> are quite a few things to do for a chroot, see
> http://www.gnu.org/software/hurd/hurd/running/chroot

I see. This separate translator the page is talking about, does it
have to be a filesystem or would any translator do the trick? remap
mentions something about chroots, is it meant for this? If so, could
you elaborate on its use? I've tried remapping some directories, it
did not work for me.

I'm thinking about making a chroot wrapper or hooking into pbuilder,
I'd love to use it to build packages.

> > I suspect that something funny goes on in the rootfs translator (it's
> > an one filesystem setup, maybe I should create another filesystem to
> > protect the rootfs), b/c I end up with an mostly empty /dev:
> 
> Yes, apparently deboostrap or pbuilder tries to remove the chroot, but
> without taking care that dev in the chroot was actually linked to /dev,
> and thus empties /dev.
> 
> > Not sure if anything else got corrupted,
> 
> Possibly /servers too.
> 
> > Fortunately reinstalling the hurd
> > package fixes this.
> 
> dpkg-reconfigure hurd, or simply running /usr/lib/hurd/setup-translators 
> should work too.

It did. Thanks.

Justus



trouble building hurd debian package, alioth confusion

2013-06-09 Thread Justus Winter
Hi,

I cannot rebuild the hurd package (both the one from sid & from
alioth). Before digging deeper into this, I just wanted to ask if I'm
missing something obvious here:

[...]
make -C libshouldbeinlibc all
make[3]: Entering directory 
`/media/scratch/teythoon/packages/hurd-pkg/build/libshouldbeinlibc'
gcc -std=gnu99 -fgnu89-inline -Wall -g -O3  -g -O2 -fstack-protector 
--param=ssp-buffer-size=4 -Wformat -Werror=format-security -I. 
-I../../libshouldbeinlibc -I.. -I../.. -I../include -I../../include 
-D_GNU_SOURCE -D_IO_MTSAFE_IO -D_FILE_OFFSET_BITS=64  -D_FORTIFY_SOURCE=2 
-DPACKAGE_NAME=\"GNU\ Hurd\" -DPACKAGE_TARNAME=\"hurd\" 
-DPACKAGE_VERSION=\"0.3\" -DPACKAGE_STRING=\"GNU\ Hurd\ 0.3\" 
-DPACKAGE_BUGREPORT=\"bug-hurd@gnu.org\" 
-DPACKAGE_URL=\"http://www.gnu.org/software/hurd/\"; -DHAVE_MIG_RETCODE=1 
-DHAVE_GETGROUPLIST=1 -DHAVE_USELOCALE=1 -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 
-DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 
-DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 
-DHAVE_PARTED_PARTED_H=1 -DHAVE_LIBPARTED=1 -DHAVE_LIBUUID=1 -DHAVE_LIBDL=1 
-DYYTEXT_POINTER=1 -DX11_PREFIX=\"/usr\"  -c -o exec-reauth.o 
../../libshouldbeinlibc/exec-reauth.c
In file included from ../../libshouldbeinlibc/exec-reauth.c:24:0:
/usr/include/hurd/io.h:422:2: error: unknown type name ‘timespec_t’
/usr/include/hurd/io.h:845:2: error: unknown type name ‘timespec_t’
make[3]: *** [exec-reauth.o] Error 1
make[3]: Leaving directory 
`/media/scratch/teythoon/packages/hurd-pkg/build/libshouldbeinlibc'
make[2]: *** [libshouldbeinlibc] Error 2
make[2]: Leaving directory `/media/scratch/teythoon/packages/hurd-pkg/build'
dh_auto_build: make -j1 returned exit code 2
make[1]: *** [override_dh_auto_build] Error 2
make[1]: Leaving directory `/media/scratch/teythoon/packages/hurd-pkg'
make: *** [binary] Error 2

Also aiui, the hurd package is maintained on alioth under
git.debian.org/git/pkg-hurd/hurd.git, right? Alioth allows me to
create a repo for this project, but in the alioth ui under SCM it
lists a different path:

git.debian.org/git/pkg-hurd/pkg-hurd.git

But that repo is empty, why would I want to clone this? I'm somewhat
confused...

Cheers,
Justus



Re: trouble building hurd debian package, alioth confusion

2013-06-09 Thread Justus Winter
Quoting Richard Braun (2013-06-09 17:14:36)
> On Sun, Jun 09, 2013 at 03:26:22PM +0200, Justus Winter wrote:
> > I cannot rebuild the hurd package (both the one from sid & from
> > alioth). Before digging deeper into this, I just wanted to ask if I'm
> > missing something obvious here:
> > 
> > [...]
> > make -C libshouldbeinlibc all
> > make[3]: Entering directory 
> > `/media/scratch/teythoon/packages/hurd-pkg/build/libshouldbeinlibc'
> > gcc -std=gnu99 -fgnu89-inline -Wall -g -O3  -g -O2 -fstack-protector 
> > --param=ssp-buffer-size=4 -Wformat -Werror=format-security -I. 
> > -I../../libshouldbeinlibc -I.. -I../.. -I../include -I../../include 
> > -D_GNU_SOURCE -D_IO_MTSAFE_IO -D_FILE_OFFSET_BITS=64  -D_FORTIFY_SOURCE=2 
> > -DPACKAGE_NAME=\"GNU\ Hurd\" -DPACKAGE_TARNAME=\"hurd\" 
> > -DPACKAGE_VERSION=\"0.3\" -DPACKAGE_STRING=\"GNU\ Hurd\ 0.3\" 
> > -DPACKAGE_BUGREPORT=\"bug-hurd@gnu.org\" 
> > -DPACKAGE_URL=\"http://www.gnu.org/software/hurd/\"; -DHAVE_MIG_RETCODE=1 
> > -DHAVE_GETGROUPLIST=1 -DHAVE_USELOCALE=1 -DSTDC_HEADERS=1 
> > -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 
> > -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 
> > -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_PARTED_PARTED_H=1 
> > -DHAVE_LIBPARTED=1 -DHAVE_LIBUUID=1 -DHAVE_LIBDL=1 -DYYTEXT_POINTER=1 
> > -DX11_PREFIX=\"/usr\"  -c -o exec-reauth.o 
> > ../../libshouldbeinlibc/exec-reauth.c
> > In file included from ../../libshouldbeinlibc/exec-reauth.c:24:0:
> > /usr/include/hurd/io.h:422:2: error: unknown type name ‘timespec_t’
> > /usr/include/hurd/io.h:845:2: error: unknown type name ‘timespec_t’
> > make[3]: *** [exec-reauth.o] Error 1
> > make[3]: Leaving directory 
> > `/media/scratch/teythoon/packages/hurd-pkg/build/libshouldbeinlibc'
> > make[2]: *** [libshouldbeinlibc] Error 2
> > make[2]: Leaving directory `/media/scratch/teythoon/packages/hurd-pkg/build'
> > dh_auto_build: make -j1 returned exit code 2
> > make[1]: *** [override_dh_auto_build] Error 2
> > make[1]: Leaving directory `/media/scratch/teythoon/packages/hurd-pkg'
> > make: *** [binary] Error 2
> 
> You need more recent sources, i.e. those from debian-ports.

Ok. That explains why I have been able to build hurd using the
upstream git, but that lacks the debian packaging bits. So where can I
get them from? debian-ports does not seem to serve any sources, and I
was hoping to find a scm somewhere.

% curl -s 
ftp://ftp.debian-ports.org/debian/dists/unreleased/main/source/Sources.bz2 | 
bzcat | wc --bytes
0

Justus



Re: trouble building hurd debian package, alioth confusion

2013-06-10 Thread Justus Winter
Quoting Svante Signell (2013-06-09 20:10:59)
> On Sun, 2013-06-09 at 18:56 +0200, Svante Signell wrote:
> > On Sun, 2013-06-09 at 17:48 +0200, Justus Winter wrote
> ..
> > apt-get source --download-only eglibc=2.13-38
> > dget \
> > ftp://ftp.debian-ports.org/debian/pool-hurd-i386/main/e/eglibc/eglibc_2.13-39+hurd.3.dsc
> 
> I forgot
> dget \
> ftp://ftp.debian-ports.org/debian/pool-hurd-i386/main/h/hurd/hurd_20130501-1.dsc
> (hurd_20130501.orig.tar.gz is already at the same address)

Awesome, didn't know this one. Still I was hoping to get a git repo
since that way I could plug it into my package building solution.

Building went fine until:

make -C doc install
make[3]: Entering directory `/home/teythoon/hurd/hurd-20130501/build/doc'
mkdir /home/teythoon/hurd/hurd-20130501/debian/tmp/share/info
echo '@set VERSION 0.3' > version.texi.new
/bin/sh ../../move-if-change version.texi.new version.texi
touch stamp-version
makeinfo -I . -I ../../doc ../../doc/hurd.texi
../../doc/hurd.texi:130: @setchapternewpage arg must be `on', `off' or `odd', 
not `none'
../../doc/hurd.texi:1464: warning: @deftypefun should only appear at a line 
beginning
../../doc/hurd.texi:332: warning: node `Bootstrap' is next for `Introduction' 
in menu but not in sectioning
../../doc/hurd.texi:522: warning: node `Introduction' is prev for `Bootstrap' 
in menu but not in sectioning
make[3]: *** [hurd.info] Error 1
make[3]: Leaving directory `/home/teythoon/hurd/hurd-20130501/build/doc'
make[2]: *** [doc-install] Error 2

Thoughts?

> Maybe something for the web pages until these versions are available in
> Debian main (if ever)

Any reason not to serve source packages from debian-ports.org?

Justus


signature.asc
Description: signature


Re: trouble building hurd debian package, alioth confusion

2013-06-10 Thread Justus Winter
Quoting Emilio Pozuelo Monfort (2013-06-10 16:28:06)
> On 10/06/13 16:10, Justus Winter wrote:
> > Awesome, didn't know this one. Still I was hoping to get a git repo
> > since that way I could plug it into my package building solution.
> 
> The debian packaging with the upstream sources + patches are in a git repo:
> 
> emilio@titan:~$ apt-cache showsrc hurd | grep Vcs
> Vcs-Browser: http://anonscm.debian.org/gitweb/?p=pkg-hurd/hurd.git
> Vcs-Git: git://anonscm.debian.org/pkg-hurd/hurd.git

Yes, I found this. But I'm pretty sure that this did not work. I
referred to this as ,,from alioth'' in my first post, I should have
been more clear...

Justus


signature.asc
Description: signature


Re: trouble building hurd debian package, alioth confusion

2013-06-10 Thread Justus Winter
Quoting Richard Braun (2013-06-10 16:28:40)
> On Mon, Jun 10, 2013 at 04:10:57PM +0200, Justus Winter wrote:
> > Awesome, didn't know this one. Still I was hoping to get a git repo
> > since that way I could plug it into my package building solution.
> 
> There are debian repositories for GNU Mach and the Hurd :
> 
> git://anonscm.debian.org/pkg-hurd/gnumach.git
> git://anonscm.debian.org/pkg-hurd/hurd.git

Yes, but that one is too old and...

> [...]
> You need even more recent Hurd sources. See this URL for the patch :
> http://git.savannah.gnu.org/cgit/hurd/hurd.git/commit/?id=45193362a810024ab4810470fcd00e16123d5aaf

... that one lacks the packaging bits. But surely this will end up in
git://anonscm.debian.org/pkg-hurd/hurd.git soonish, so I'll just wait
a little.

Justus


signature.asc
Description: signature


Re: Hurd GSoC 2013 projects

2013-06-11 Thread Justus Winter
Quoting Justus Winter (2013-06-01 21:12:36)
> > Copyright assignment. [...]
> 
> Will do that.

I did that, haven't heard anything yet. I'm not complaining, just
stating facts.

> > Weekly reports.
> 
> Check.

I setup a blog at https://teythoon.cryptobitch.de/

I read http://wiki.debian.org/PlanetDebian and understood the
rules. It mentions that Debian developers can add feeds to the planet
and non dd may ask any dd to do that for them.

Samuel or anyone else in a position to do that, would you please add
https://teythoon.cryptobitch.de/rss.xml to the planet?

> > For example, now it's high time to make
> > sure that you have the development environment/infrastructure for working
> > on your GSoC project: a suitably powered machine, etc.
> 
> I took the opportunity to upgrade my main machine. SSD arrived today
> and since I'm going to work a lot with Qemu, this machine could use
> the two extra gigs of ram that are laying around here but that I
> cannot install in the current mainboad b/c it's so tiny. Replacement
> mainboard is due to arrive here this week.

The mainboard arrived and works, my main machine has 4 gigs of ram
now.

> > Justus, anything you need?
> 
> Yes. Maybe. I read about the UDD and [0] suggests that one could
> access from wagner (alioth). I thought about querying it for relevant
> bug reports. Is that worth doing? If so, how do I get an account on
> this machine?

Now that I'm part of the hurd-pkg project, I can ssh to
wagner. Nice. I might play around with UDD, will keep you posted.

I've setup a continuous build solution on one of my Hurd VMs and
prepared a package repository. I'll post details once I have some
packages to share.

I built hurd, sysvinit and ifupdown and dived into the interesting
world of literate programming. I think I'm well prepared.

Misc:

* I haven't heard from google wrt to tax papers. Is that normal?

* I received a message that I was subscribed to an internal student
  google group list thingy with my university email address. That's
  fine, but the message also said that I won't be receiving any mails
  and have to use the google groups web interface instead, but I
  cannot access this list with my google account b/c the other address
  is registered. I'm not sure what to do about that...

Justus


signature.asc
Description: signature


Re: Hurd GSoC 2013 projects

2013-06-19 Thread Justus Winter
Hi Samuel,

Quoting Justus Winter (2013-06-16 22:37:43)
> Quoting Samuel Thibault (2013-06-16 22:33:16)
> > Hello,
> > 
> > Justus Winter, le Tue 11 Jun 2013 18:31:01 +0200, a écrit :
> > > Samuel or anyone else in a position to do that, would you please add
> > > https://teythoon.cryptobitch.de/rss.xml to the planet?
> > 
> > I have done so.
> 
> Cool, thanks.

Sorry to bother you again. Since my name did not appear on the feeds
subscription list I suspect that either a) the planet software does
not support https at all or b) it does not support SNI that is used by
the server.

As SNI is causing all kinds of problems with non-webbrowser http
clients (and I'm planning on hosting an apt-repository there) the
server is now also serving plain http.

Could you adjust the url to http://teythoon.cryptobitch.de/rss.xml to
see if this fixes this?

Thanks,
Justus



Re: Hurd GSoC 2013 projects

2013-06-20 Thread Justus Winter
Quoting Samuel Thibault (2013-06-18 22:43:33)
> Hello,
> 
> AIUI, SoC has begun yesterday, we should probably settle for a weekly
> meeting?

Agreed. Let's dudle it:

https://dudle.mafiasi.de/Hurd_GSoC_weekly_meeting/

Feel free to modify the poll, you can add more timeslots for
example. Times are given as GMT+2 (central european summer time, I
think that is where most of us are in). Lu, please state your time
constraints, I'm not sure which time zone you are in.

Justus



Re: GDB/GCC/Hurd GSoC 2013 projects

2013-06-23 Thread Justus Winter
Quoting Thomas Schwinge (2013-06-20 12:52:20)
> I propose the following scheme: effective now, GSoC students send a
> weekly report at the end of each week (so, on Friday, or on the weekend
> -- as an exception at the very latest one hour before the following
> regular IRC meeting), and regular IRC meetings are held each Monday,
> during the GSoC students' day-time, that is, between 7 UTC and 12 UTC
> (translating to 9 UTC+2 and 14 UTC+2, and 15 UTC+8 and 20 UTC+8).

Works for me. See you tomorrow :)

Justus



/hurd/init and /hurd/proc

2013-06-25 Thread Justus Winter
Hi,

I'd like to get some input. For context, please read Guillems message
http://lists.gnu.org/archive/html/bug-hurd/2006-02/msg00081.html and
Marcus critique
http://lists.gnu.org/archive/html/bug-hurd/2006-02/msg00082.html

Looking at his patch and having seen some mach message passing code in
the last few days, I'm confident that I could implement either
option. But first I'd like to suggest a third.

3) /hurd/init could be merged into the proc server.

/hurd/init does lot's of process related stuff, like starting
essential servers (like the proc server, and then *later* correcting
the proc servers state with respect to the essential servers started
by init using some specialized messages), keeping track of processes
that are essential and those worthy of being notified of a system
shutdown. Currently it also collects orphaned processes, though that
job is best left to sysvinit in the future.

This special interface they both use and the fact that init does lot's
of process related things might be an indication that the seperation
does more harm than good. It seems to make the code more complex, and
fixing the issue of killing essential processes will probably involve
adding more specialized messages that are only used by those two
processes. Is there a benefit of having them separated?

This would also have the nice side effect of freeing up pid 1 for
sysvinit.

About the pid 1 issue, I thought about patching the proc server to
reserve pid 1 for sysvinit and just make our init pid 4 or
something. Pino mentioned something about hardcoded assumptions of
which hurd server has which pid. Where would I find such assumptions
documented? Or could you provide anything from the top of your head?

But then again, this feels wrong and hacky. Since I learned about the
kill(0, x) issue and thought about what our init is currently doing, I
kind of lean towards merging proc and init and simplifying the code
and fixing both problems in the process.

Cheers,
Justus



some work on procfs

2013-06-27 Thread Justus Winter
Hi,

currently procfs doesn't allow one to alter the options at runtime
using fsys_set_options. This is necessary to make mount -oremount
work. I also noticed that fsys_get_options would only return the
translators name, but not its options, so I've implemented this as
well.

FWIW this is meant to be applied on top of procfs as found in the hurd
packaging git with the patches in debian/patches applied. Please let
me know if that is inappropriate.

Comments are welcome :)

Cheers,
Justus




[PATCH 1/6] procfs: fix the error handling in argp_parser

2013-06-27 Thread Justus Winter
Do not exit using error (1, ..) but gracefully handle the error using
argp_error.

* procfs/main.c (argp_parser): Proper error handling.
---
 procfs/main.c |   12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/procfs/main.c b/procfs/main.c
index 3a976cc..e7f8574 100644
--- a/procfs/main.c
+++ b/procfs/main.c
@@ -48,13 +48,13 @@ argp_parser (int key, char *arg, struct argp_state *state)
 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");
+   argp_error (state, "--clk-tck: HZ should be a positive integer");
   break;
 
 case 's':
   opt_stat_mode = strtol (arg, &endp, 8);
   if (*endp || ! *arg || opt_stat_mode & ~0)
-   error (1, 0, "--stat-mode: MODE should be an octal mode");
+   argp_error (state, "--stat-mode: MODE should be an octal mode");
   break;
 
 case 'S':
@@ -62,7 +62,7 @@ argp_parser (int key, char *arg, struct argp_state *state)
 {
  opt_fake_self = strtol (arg, &endp, 0);
  if (*endp || ! *arg)
-   error (1, 0, "--fake-self: PID must be an integer");
+   argp_error (state, "--fake-self: PID must be an integer");
}
   else
opt_fake_self = 1;
@@ -71,7 +71,7 @@ argp_parser (int key, char *arg, struct argp_state *state)
 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");
+   argp_error (state, "--kernel-process: PID must be a positive integer");
   break;
 
 case 'c':
@@ -90,8 +90,8 @@ argp_parser (int key, char *arg, struct argp_state *state)
 
   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.");
+   argp_error (state, "--anonymous-owner: USER should be the "
+   "a user name or a numeric UID.");
   break;
   }
 
-- 
1.7.10.4




[PATCH 2/6] procfs: keep old config values if the parsing fails

2013-06-27 Thread Justus Winter
Previously if strtol failed the previous configuration value would get
overwritten. Prevent this by storing the result in a temporary
variable and update the configuration if the argument was parsed
correctly and passed the sanity checks.

* procfs/main.c (argp_parser): Keep old configuration in case a
malformed value is encountered.
---
 procfs/main.c |   27 +++
 1 file changed, 19 insertions(+), 8 deletions(-)

diff --git a/procfs/main.c b/procfs/main.c
index e7f8574..f472f04 100644
--- a/procfs/main.c
+++ b/procfs/main.c
@@ -42,36 +42,45 @@ argp_parser (int key, char *arg, struct argp_state *state)
 {
   struct passwd *pw;
   char *endp;
+  long int v;
 
   switch (key)
   {
 case 'h':
-  opt_clk_tck = strtol (arg, &endp, 0);
-  if (*endp || ! *arg || opt_clk_tck <= 0)
+  v = strtol (arg, &endp, 0);
+  if (*endp || ! *arg || v <= 0)
argp_error (state, "--clk-tck: HZ should be a positive integer");
+  else
+   opt_clk_tck = v;
   break;
 
 case 's':
-  opt_stat_mode = strtol (arg, &endp, 8);
-  if (*endp || ! *arg || opt_stat_mode & ~0)
+  v = strtol (arg, &endp, 8);
+  if (*endp || ! *arg || (mode_t) v & ~0)
argp_error (state, "--stat-mode: MODE should be an octal mode");
+  else
+   opt_stat_mode = v;
   break;
 
 case 'S':
   if (arg)
 {
- opt_fake_self = strtol (arg, &endp, 0);
+ v = strtol (arg, &endp, 0);
  if (*endp || ! *arg)
argp_error (state, "--fake-self: PID must be an integer");
+ else
+   opt_fake_self = v;
}
   else
opt_fake_self = 1;
   break;
 
 case 'k':
-  opt_kernel_pid = strtol (arg, &endp, 0);
+  v = strtol (arg, &endp, 0);
   if (*endp || ! *arg || (signed) opt_kernel_pid < 0)
argp_error (state, "--kernel-process: PID must be a positive integer");
+  else
+   opt_kernel_pid = v;
   break;
 
 case 'c':
@@ -88,10 +97,12 @@ argp_parser (int key, char *arg, struct argp_state *state)
  break;
}
 
-  opt_anon_owner = strtol (arg, &endp, 0);
-  if (*endp || ! *arg || (signed) opt_anon_owner < 0)
+  v = strtol (arg, &endp, 0);
+  if (*endp || ! *arg || v < 0)
argp_error (state, "--anonymous-owner: USER should be the "
"a user name or a numeric UID.");
+  else
+   opt_anon_owner = v;
   break;
   }
 
-- 
1.7.10.4




[PATCH 3/6] procfs: enable fsys_set_options

2013-06-27 Thread Justus Winter
Make procfs translators handle fsys_set_options requests by pointing
netfs_runtime_argp to our argp struct.

* procfs/main.c (netfs_runtime_argp): New variable.
---
 procfs/main.c |3 +++
 1 file changed, 3 insertions(+)

diff --git a/procfs/main.c b/procfs/main.c
index f472f04..6251c83 100644
--- a/procfs/main.c
+++ b/procfs/main.c
@@ -146,6 +146,9 @@ struct argp argp = {
   },
 };
 
+/* Used by netfs_set_options to handle runtime option parsing.  */
+struct argp *netfs_runtime_argp = &argp;
+
 error_t
 root_make_node (struct ps_context *pc, struct node **np)
 {
-- 
1.7.10.4




[PATCH 4/6] procfs: handle the --update parameter

2013-06-27 Thread Justus Winter
Split the argument handling into a common part and one for
fsys_update_options. Handle the --update parameter; for procfs this is
a no-op.

* procfs/main.c (common_options): New variable.
(runtime_argp_parser): Handle --update.
(startup_argp): New variable.
(netfs_runtime_argp_): New variable.
---
 procfs/main.c |   93 -
 1 file changed, 65 insertions(+), 28 deletions(-)

diff --git a/procfs/main.c b/procfs/main.c
index 6251c83..859b9db 100644
--- a/procfs/main.c
+++ b/procfs/main.c
@@ -109,45 +109,82 @@ argp_parser (int key, char *arg, struct argp_state *state)
   return 0;
 }
 
+struct argp_option common_options[] = {
+  { "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)" },
+  {}
+};
+
 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)" },
+  .options = common_options,
+  .parser = argp_parser,
+  .doc = "A virtual filesystem emulating the Linux procfs.",
+  .children = (struct argp_child []) {
+{ &netfs_std_startup_argp, },
 {}
   },
+};
+
+static error_t
+runtime_argp_parser (int key, char *arg, struct argp_state *state)
+{
+  switch (key)
+  {
+case 'u':
+  /* do nothing */
+  break;
+
+default:
+  return ARGP_ERR_UNKNOWN;
+  }
+
+  return 0;
+}
+
+struct argp runtime_argp = {
+  .options = (struct argp_option []) {
+{ "update", 'u', NULL, 0, "remount; for procfs this does nothing" },
+{},
+  },
+  .parser = runtime_argp_parser,
+};
+
+struct argp netfs_runtime_argp_ = {
+  .options = common_options,
   .parser = argp_parser,
   .doc = "A virtual filesystem emulating the Linux procfs.",
   .children = (struct argp_child []) {
-{ &netfs_std_startup_argp, },
+{ &runtime_argp, },
+{ &netfs_std_runtime_argp, },
 {}
   },
 };
 
 /* Used by netfs_set_options to handle runtime option parsing.  */
-struct argp *netfs_runtime_argp = &argp;
+struct argp *netfs_runtime_argp = &netfs_runtime_argp_;
 
 error_t
 root_make_node (struct ps_context *pc, struct node **np)
-- 
1.7.10.4




[PATCH 5/6] procfs: define macros for the default argument values

2013-06-27 Thread Justus Winter
Define a macro for the default value of each command line
parameter. This allows one to generate a minimal response to
fsys_get_options requests.

* procfs/main.c: New macro definitions for default values.
---
 procfs/main.c |   17 -
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/procfs/main.c b/procfs/main.c
index 859b9db..4c8440d 100644
--- a/procfs/main.c
+++ b/procfs/main.c
@@ -37,6 +37,13 @@ pid_t opt_fake_self;
 pid_t opt_kernel_pid;
 uid_t opt_anon_owner;
 
+/* Default values */
+#define OPT_CLK_TCKsysconf(_SC_CLK_TCK)
+#define OPT_STAT_MODE  0400
+#define OPT_FAKE_SELF  -1
+#define OPT_KERNEL_PID 2
+#define OPT_ANON_OWNER 0
+
 static error_t
 argp_parser (int key, char *arg, struct argp_state *state)
 {
@@ -211,11 +218,11 @@ int main (int argc, char **argv)
   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;
+  opt_clk_tck = OPT_CLK_TCK;
+  opt_stat_mode = OPT_STAT_MODE;
+  opt_fake_self = OPT_FAKE_SELF;
+  opt_kernel_pid = OPT_KERNEL_PID;
+  opt_anon_owner = OPT_ANON_OWNER;
   err = argp_parse (&argp, argc, argv, 0, 0, 0);
   if (err)
 error (1, err, "Could not parse command line");
-- 
1.7.10.4




[PATCH 6/6] procfs: provide a more meaningful response to fsys_get_options

2013-06-27 Thread Justus Winter
Implement our own netfs_append_args function that provides the
appropriate command line flags if the current values differ from the
default values.

* procfs/main.c (netfs_append_args): New function.
---
 procfs/main.c |   42 ++
 1 file changed, 42 insertions(+)

diff --git a/procfs/main.c b/procfs/main.c
index 4c8440d..b89a7dc 100644
--- a/procfs/main.c
+++ b/procfs/main.c
@@ -22,6 +22,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include "procfs.h"
@@ -193,6 +194,47 @@ struct argp netfs_runtime_argp_ = {
 /* Used by netfs_set_options to handle runtime option parsing.  */
 struct argp *netfs_runtime_argp = &netfs_runtime_argp_;
 
+/* Return an argz string describing the current options.  Fill *ARGZ
+   with a pointer to newly malloced storage holding the list and *LEN
+   to the length of that storage.  */
+error_t
+netfs_append_args (char **argz, size_t *argz_len)
+{
+  char buf[80];
+  error_t err = 0;
+
+#define FOPT(opt, default, fmt, args...) \
+  do { \
+if (! err && opt != default) \
+  { \
+   snprintf (buf, sizeof buf, fmt, ## args); \
+   err = argz_add (argz, argz_len, buf); \
+  } \
+  } while (0)
+
+  FOPT (opt_clk_tck, OPT_CLK_TCK,
+"--clk-tck=%d", opt_clk_tck);
+
+  FOPT (opt_stat_mode, OPT_STAT_MODE,
+"--stat-mode=%o", opt_stat_mode);
+
+  FOPT (opt_fake_self, OPT_FAKE_SELF,
+"--fake-self=%d", opt_fake_self);
+
+  FOPT (opt_anon_owner, OPT_ANON_OWNER,
+"--anonymous-owner=%d", opt_anon_owner);
+
+  FOPT (opt_kernel_pid, OPT_KERNEL_PID,
+"--kernel-process=%d", opt_kernel_pid);
+
+#undef FOPT
+
+  if (! err)
+err = netfs_append_std_options (argz, argz_len);
+
+  return err;
+}
+
 error_t
 root_make_node (struct ps_context *pc, struct node **np)
 {
-- 
1.7.10.4




[PATCH] tmpfs: fix parsing of fsys_set_options requests

2013-06-27 Thread Justus Winter
Formerly setting the options using fsys_set_options did not work
because runtime_argp.options was set to 0. This fixes "remounting" of
tmpfs translators.

* tmpfs/tmpfs.c (runtime_argp): Use options as option list.
---
 tmpfs/tmpfs.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tmpfs/tmpfs.c b/tmpfs/tmpfs.c
index 36fa133..7da3dd5 100644
--- a/tmpfs/tmpfs.c
+++ b/tmpfs/tmpfs.c
@@ -327,7 +327,7 @@ m or M for megabytes, g or G for gigabytes.",
 /* Similarly at runtime.  */
 static const struct argp_child runtime_children[] =
   {{&diskfs_std_runtime_argp}, {0}};
-static struct argp runtime_argp = {0, parse_opt, 0, 0, runtime_children};
+static struct argp runtime_argp = {options, parse_opt, 0, 0, runtime_children};
 
 struct argp *diskfs_runtime_argp = (struct argp *)&runtime_argp;
 
-- 
1.7.10.4




[PATCH 1/6] procfs: fix the error handling in argp_parser

2013-06-28 Thread Justus Winter
Do not exit using error (1, ..) but gracefully handle the error using
argp_error. Also fix a typo ("the a user") while touching these lines.

* procfs/main.c (argp_parser): Proper error handling.
(argp_parser): Fix typo.
---
 procfs/main.c |   12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/procfs/main.c b/procfs/main.c
index 3a976cc..f33ace9 100644
--- a/procfs/main.c
+++ b/procfs/main.c
@@ -48,13 +48,13 @@ argp_parser (int key, char *arg, struct argp_state *state)
 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");
+   argp_error (state, "--clk-tck: HZ should be a positive integer");
   break;
 
 case 's':
   opt_stat_mode = strtol (arg, &endp, 8);
   if (*endp || ! *arg || opt_stat_mode & ~0)
-   error (1, 0, "--stat-mode: MODE should be an octal mode");
+   argp_error (state, "--stat-mode: MODE should be an octal mode");
   break;
 
 case 'S':
@@ -62,7 +62,7 @@ argp_parser (int key, char *arg, struct argp_state *state)
 {
  opt_fake_self = strtol (arg, &endp, 0);
  if (*endp || ! *arg)
-   error (1, 0, "--fake-self: PID must be an integer");
+   argp_error (state, "--fake-self: PID must be an integer");
}
   else
opt_fake_self = 1;
@@ -71,7 +71,7 @@ argp_parser (int key, char *arg, struct argp_state *state)
 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");
+   argp_error (state, "--kernel-process: PID must be a positive integer");
   break;
 
 case 'c':
@@ -90,8 +90,8 @@ argp_parser (int key, char *arg, struct argp_state *state)
 
   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.");
+   argp_error (state, "--anonymous-owner: USER should be "
+   "a user name or a numeric UID.");
   break;
   }
 
-- 
1.7.10.4




[PATCH 3/6] procfs: enable fsys_set_options

2013-06-28 Thread Justus Winter
Make procfs translators handle fsys_set_options requests by pointing
netfs_runtime_argp to our argp struct.

* procfs/main.c (netfs_runtime_argp): New variable.
---
 procfs/main.c |3 +++
 1 file changed, 3 insertions(+)

diff --git a/procfs/main.c b/procfs/main.c
index 0892d36..1b19c01 100644
--- a/procfs/main.c
+++ b/procfs/main.c
@@ -146,6 +146,9 @@ struct argp argp = {
   },
 };
 
+/* Used by netfs_set_options to handle runtime option parsing.  */
+struct argp *netfs_runtime_argp = &argp;
+
 error_t
 root_make_node (struct ps_context *pc, struct node **np)
 {
-- 
1.7.10.4




[PATCH 2/6] procfs: keep old config values if the parsing fails

2013-06-28 Thread Justus Winter
Previously if strtol failed the previous configuration value would get
overwritten. Prevent this by storing the result in a temporary
variable and update the configuration if the argument was parsed
correctly and passed the sanity checks.

* procfs/main.c (argp_parser): Keep old configuration in case a
malformed value is encountered.
---
 procfs/main.c |   27 +++
 1 file changed, 19 insertions(+), 8 deletions(-)

diff --git a/procfs/main.c b/procfs/main.c
index f33ace9..0892d36 100644
--- a/procfs/main.c
+++ b/procfs/main.c
@@ -42,36 +42,45 @@ argp_parser (int key, char *arg, struct argp_state *state)
 {
   struct passwd *pw;
   char *endp;
+  long int v;
 
   switch (key)
   {
 case 'h':
-  opt_clk_tck = strtol (arg, &endp, 0);
-  if (*endp || ! *arg || opt_clk_tck <= 0)
+  v = strtol (arg, &endp, 0);
+  if (*endp || ! *arg || v <= 0)
argp_error (state, "--clk-tck: HZ should be a positive integer");
+  else
+   opt_clk_tck = v;
   break;
 
 case 's':
-  opt_stat_mode = strtol (arg, &endp, 8);
-  if (*endp || ! *arg || opt_stat_mode & ~0)
+  v = strtol (arg, &endp, 8);
+  if (*endp || ! *arg || (mode_t) v & ~0)
argp_error (state, "--stat-mode: MODE should be an octal mode");
+  else
+   opt_stat_mode = v;
   break;
 
 case 'S':
   if (arg)
 {
- opt_fake_self = strtol (arg, &endp, 0);
+ v = strtol (arg, &endp, 0);
  if (*endp || ! *arg)
argp_error (state, "--fake-self: PID must be an integer");
+ else
+   opt_fake_self = v;
}
   else
opt_fake_self = 1;
   break;
 
 case 'k':
-  opt_kernel_pid = strtol (arg, &endp, 0);
+  v = strtol (arg, &endp, 0);
   if (*endp || ! *arg || (signed) opt_kernel_pid < 0)
argp_error (state, "--kernel-process: PID must be a positive integer");
+  else
+   opt_kernel_pid = v;
   break;
 
 case 'c':
@@ -88,10 +97,12 @@ argp_parser (int key, char *arg, struct argp_state *state)
  break;
}
 
-  opt_anon_owner = strtol (arg, &endp, 0);
-  if (*endp || ! *arg || (signed) opt_anon_owner < 0)
+  v = strtol (arg, &endp, 0);
+  if (*endp || ! *arg || v < 0)
argp_error (state, "--anonymous-owner: USER should be "
"a user name or a numeric UID.");
+  else
+   opt_anon_owner = v;
   break;
   }
 
-- 
1.7.10.4




[PATCH 4/6] procfs: handle the --update parameter

2013-06-28 Thread Justus Winter
Split the argument handling into a common part and one for
fsys_update_options. Handle the --update parameter; for procfs this is
a no-op.

* procfs/main.c (common_options): New variable.
(runtime_argp_parser): Handle --update.
(startup_argp): New variable.
(netfs_runtime_argp_): New variable.
---
 procfs/main.c |   93 -
 1 file changed, 65 insertions(+), 28 deletions(-)

diff --git a/procfs/main.c b/procfs/main.c
index 1b19c01..ba74e87 100644
--- a/procfs/main.c
+++ b/procfs/main.c
@@ -109,45 +109,82 @@ argp_parser (int key, char *arg, struct argp_state *state)
   return 0;
 }
 
+struct argp_option common_options[] = {
+  { "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)" },
+  {}
+};
+
 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)" },
+  .options = common_options,
+  .parser = argp_parser,
+  .doc = "A virtual filesystem emulating the Linux procfs.",
+  .children = (struct argp_child []) {
+{ &netfs_std_startup_argp, },
 {}
   },
+};
+
+static error_t
+runtime_argp_parser (int key, char *arg, struct argp_state *state)
+{
+  switch (key)
+  {
+case 'u':
+  /* do nothing */
+  break;
+
+default:
+  return ARGP_ERR_UNKNOWN;
+  }
+
+  return 0;
+}
+
+struct argp runtime_argp = {
+  .options = (struct argp_option []) {
+{ "update", 'u', NULL, 0, "remount; for procfs this does nothing" },
+{},
+  },
+  .parser = runtime_argp_parser,
+};
+
+struct argp netfs_runtime_argp_ = {
+  .options = common_options,
   .parser = argp_parser,
   .doc = "A virtual filesystem emulating the Linux procfs.",
   .children = (struct argp_child []) {
-{ &netfs_std_startup_argp, },
+{ &runtime_argp, },
+{ &netfs_std_runtime_argp, },
 {}
   },
 };
 
 /* Used by netfs_set_options to handle runtime option parsing.  */
-struct argp *netfs_runtime_argp = &argp;
+struct argp *netfs_runtime_argp = &netfs_runtime_argp_;
 
 error_t
 root_make_node (struct ps_context *pc, struct node **np)
-- 
1.7.10.4




[PATCH 5/6] procfs: define macros for the default argument values

2013-06-28 Thread Justus Winter
Define a macro for the default value of each command line
parameter. This allows one to generate a minimal response to
fsys_get_options requests.

* procfs/main.c: New macro definitions for default values.
---
 procfs/main.c |   17 -
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/procfs/main.c b/procfs/main.c
index ba74e87..3e53307 100644
--- a/procfs/main.c
+++ b/procfs/main.c
@@ -37,6 +37,13 @@ pid_t opt_fake_self;
 pid_t opt_kernel_pid;
 uid_t opt_anon_owner;
 
+/* Default values */
+#define OPT_CLK_TCKsysconf(_SC_CLK_TCK)
+#define OPT_STAT_MODE  0400
+#define OPT_FAKE_SELF  -1
+#define OPT_KERNEL_PID 2
+#define OPT_ANON_OWNER 0
+
 static error_t
 argp_parser (int key, char *arg, struct argp_state *state)
 {
@@ -211,11 +218,11 @@ int main (int argc, char **argv)
   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;
+  opt_clk_tck = OPT_CLK_TCK;
+  opt_stat_mode = OPT_STAT_MODE;
+  opt_fake_self = OPT_FAKE_SELF;
+  opt_kernel_pid = OPT_KERNEL_PID;
+  opt_anon_owner = OPT_ANON_OWNER;
   err = argp_parse (&argp, argc, argv, 0, 0, 0);
   if (err)
 error (1, err, "Could not parse command line");
-- 
1.7.10.4




[PATCH 6/6] procfs: provide a more meaningful response to fsys_get_options

2013-06-28 Thread Justus Winter
Implement our own netfs_append_args function that provides the
appropriate command line flags if the current values differ from the
default values.

* procfs/main.c (netfs_append_args): New function.
---
 procfs/main.c |   42 ++
 1 file changed, 42 insertions(+)

diff --git a/procfs/main.c b/procfs/main.c
index 3e53307..bcf9590 100644
--- a/procfs/main.c
+++ b/procfs/main.c
@@ -22,6 +22,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include "procfs.h"
@@ -193,6 +194,47 @@ struct argp netfs_runtime_argp_ = {
 /* Used by netfs_set_options to handle runtime option parsing.  */
 struct argp *netfs_runtime_argp = &netfs_runtime_argp_;
 
+/* Return an argz string describing the current options.  Fill *ARGZ
+   with a pointer to newly malloced storage holding the list and *LEN
+   to the length of that storage.  */
+error_t
+netfs_append_args (char **argz, size_t *argz_len)
+{
+  char buf[80];
+  error_t err = 0;
+
+#define FOPT(opt, default, fmt, args...) \
+  do { \
+if (! err && opt != default) \
+  { \
+   snprintf (buf, sizeof buf, fmt, ## args); \
+   err = argz_add (argz, argz_len, buf); \
+  } \
+  } while (0)
+
+  FOPT (opt_clk_tck, OPT_CLK_TCK,
+"--clk-tck=%d", opt_clk_tck);
+
+  FOPT (opt_stat_mode, OPT_STAT_MODE,
+"--stat-mode=%o", opt_stat_mode);
+
+  FOPT (opt_fake_self, OPT_FAKE_SELF,
+"--fake-self=%d", opt_fake_self);
+
+  FOPT (opt_anon_owner, OPT_ANON_OWNER,
+"--anonymous-owner=%d", opt_anon_owner);
+
+  FOPT (opt_kernel_pid, OPT_KERNEL_PID,
+"--kernel-process=%d", opt_kernel_pid);
+
+#undef FOPT
+
+  if (! err)
+err = netfs_append_std_options (argz, argz_len);
+
+  return err;
+}
+
 error_t
 root_make_node (struct ps_context *pc, struct node **np)
 {
-- 
1.7.10.4




patches for our mount utility

2013-06-28 Thread Justus Winter
Hi :)

this is a patch series making our mount more compatible with Linux
mount. The most interesting one is patch 3, it fixes an issue with
file_name_lookup_carefully, but but I'm not sure whether I
accidentally broke something.

Justus




[PATCH 1/4] mount: add -n and --no-mtab arguments

2013-06-28 Thread Justus Winter
Add -n and --no-mtab arguments. As we do not write an mtab file, this
is a trivial patch that just ignores this argument to be more
compatible with Linux mount.

* utils/mount.c (argp_opts): Add -n and --no-mtab.
(parse_opt): Do nothing on 'n'.
---
 utils/mount.c |5 +
 1 file changed, 5 insertions(+)

diff --git a/utils/mount.c b/utils/mount.c
index 8b059c2..ea30f7a 100644
--- a/utils/mount.c
+++ b/utils/mount.c
@@ -54,6 +54,7 @@ static const struct argp_option argp_opts[] =
   {"update", 'u', 0, 0, "Flush any meta-data cached in core"},
   {"remount", 0, 0, OPTION_ALIAS},
   {"verbose", 'v', 0, 0, "Give more detailed information"},
+  {"no-mtab", 'n', 0, 0, "Do not update /etc/mtab"},
   {0, 0}
 };
 
@@ -110,6 +111,10 @@ parse_opt (int key, char *arg, struct argp_state *state)
}
   break;
 
+case 'n':
+  /* do nothing */
+  break;
+
 case ARGP_KEY_ARG:
   if (mountpoint == 0) /* One arg: mountpoint */
mountpoint = arg;
-- 
1.7.10.4




[PATCH 4/4] mount: add -f and --fake arguments

2013-06-28 Thread Justus Winter
Add -f and --fake arguments. This makes our mount more compatible with
Linux mount.

* utils/mount.c (argp_opts): Add -f and --fake.
(do_mount): Fake the translator startup if --fake is given.
---
 utils/mount.c |   29 -
 1 file changed, 28 insertions(+), 1 deletion(-)

diff --git a/utils/mount.c b/utils/mount.c
index f1d5750..f8928f1 100644
--- a/utils/mount.c
+++ b/utils/mount.c
@@ -24,6 +24,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -34,6 +35,7 @@
 static char *fstype = DEFAULT_FSTYPE;
 static char *device, *mountpoint;
 static int verbose;
+static int fake;
 static char *options;
 static size_t options_len;
 static mach_msg_timeout_t timeout;
@@ -55,6 +57,7 @@ static const struct argp_option argp_opts[] =
   {"remount", 0, 0, OPTION_ALIAS},
   {"verbose", 'v', 0, 0, "Give more detailed information"},
   {"no-mtab", 'n', 0, 0, "Do not update /etc/mtab"},
+  {"fake", 'f', 0, 0, "Do not actually mount, just pretend"},
   {0, 0}
 };
 
@@ -115,6 +118,10 @@ parse_opt (int key, char *arg, struct argp_state *state)
   /* do nothing */
   break;
 
+case 'f':
+  fake = 1;
+  break;
+
 case ARGP_KEY_ARG:
   if (mountpoint == 0) /* One arg: mountpoint */
mountpoint = arg;
@@ -312,7 +319,10 @@ do_mount (struct fs *fs, int remount)
  return 0;
}
 
-  if (mounted != MACH_PORT_NULL)
+  /* Do not fail if there is an active translator if --fake is
+ given. This mimics Linux mount utility more closely which
+ just looks into the mtab file. */
+  if (mounted != MACH_PORT_NULL && !fake)
{
  error (0, 0, "%s already mounted", fs->mntent.mnt_fsname);
  return EBUSY;
@@ -342,6 +352,23 @@ do_mount (struct fs *fs, int remount)
 
   /* Now we have a translator command line argz in FSOPTS.  */
 
+  if (fake) {
+/* Fake the translator startup. */
+mach_port_t underlying;
+mach_msg_type_name_t underlying_type;
+err = open_node (O_READ, &underlying, &underlying_type, 0, NULL);
+if (err)
+  error (1, errno, "cannot mount on %s", fs->mntent.mnt_dir);
+
+mach_port_deallocate (mach_task_self (), underlying);
+
+/* See if the translator is at least executable. */
+if (access(type->program, X_OK) == -1)
+  error (1, errno, "can not execute %s", type->program);
+
+return 0;
+  }
+
   explain ("settrans -a");
   err = fshelp_start_translator (open_node, NULL, fsopts,
 fsopts, fsopts_len, timeout,
-- 
1.7.10.4




[PATCH 3/4] mount: fix mount -oremount with one parameter

2013-06-28 Thread Justus Winter
This fixes mount -oremount when just given the mountpoint, e. g.:

 % mount -oremount,ro /tmp

* util/mount.c (main): Add a one-argument form for remount.
---
 utils/mount.c |   29 +++--
 1 file changed, 23 insertions(+), 6 deletions(-)

diff --git a/utils/mount.c b/utils/mount.c
index ea30f7a..f1d5750 100644
--- a/utils/mount.c
+++ b/utils/mount.c
@@ -526,6 +526,12 @@ main (int argc, char **argv)
 
   fstab = fstab_argp_create (&fstab_params, SEARCH_FMTS, sizeof SEARCH_FMTS);
 
+  /* This is a convenient way of checking for any `remount' options.  */
+  remount = 0;
+  err = argz_replace (&options, &options_len, "remount", "update", &remount);
+  if (err)
+error (3, ENOMEM, "collecting mount options");
+
   if (device)  /* two-argument form */
 {
   struct mntent m =
@@ -548,6 +554,23 @@ main (int argc, char **argv)
   if (err)
error (2, err, "%s", mountpoint);
 }
+  else if (mountpoint && remount)  /* one-argument remount */
+{
+  struct mntent m =
+  {
+   mnt_fsname: mountpoint, /* since we cannot know the device,
+  using mountpoint here leads to more
+  helpful error messages */
+   mnt_dir: mountpoint,
+   mnt_type: fstype,
+   mnt_opts: 0,
+   mnt_freq: 0, mnt_passno: 0
+  };
+
+  err = fstab_add_mntent (fstab, &m, &fs);
+  if (err)
+   error (2, err, "%s", mountpoint);
+}
   else if (mountpoint) /* one-argument form */
 {
   fs = fstab_find (fstab, mountpoint);
@@ -557,12 +580,6 @@ main (int argc, char **argv)
   else
 fs = 0;
 
-  /* This is a convenient way of checking for any `remount' options.  */
-  remount = 0;
-  err = argz_replace (&options, &options_len, "remount", "update", &remount);
-  if (err)
-error (3, ENOMEM, "collecting mount options");
-
   if (fs != 0)
 err = do_mount (fs, remount);
   else
-- 
1.7.10.4




[PATCH 2/4] sutils: fix file_name_lookup_carefully

2013-06-28 Thread Justus Winter
file_name_lookup_carefully is like file_name_lookup but tries hard to
avoid starting any passive translators while doing the lookup. The
callback contains code to get a new handle to the root if it
encounters a translator, but this code was not being executed if the
node had no record of an passive translator, just an active one.

Fix the callback by dropping the test for a passive translator. AIUI
the current check for a passive translator makes no sense, as the code
is supposed to fail on encountering a passive translator.

This fixes lookups inside translators that have no passive
translator. For example if /run is a tmpfs started only as active
translator, touch /run/lock && mount tmpfs -t tmpfs /run/lock -o
size=5M would fail.

* sutils/clookup.c (lookup): Drop the test for an passive translator.
---
 sutils/clookup.c |   50 ++
 1 file changed, 18 insertions(+), 32 deletions(-)

diff --git a/sutils/clookup.c b/sutils/clookup.c
index 0107799..0232b63 100644
--- a/sutils/clookup.c
+++ b/sutils/clookup.c
@@ -83,43 +83,29 @@ file_name_lookup_carefully (const char *name, int flags, 
mode_t mode)
   is), we have to simulate the above lookup being done without
   O_NOTRANS.  Do this being careful not to start any translators.  */
{
- char _ptrans[1024], *ptrans = _ptrans;
- size_t ptrans_len = sizeof _ptrans;
+ /* See if there's an active translator.  */
+ fsys_t fsys;  /* Active translator control port.  */
 
- err = file_get_translator (*node, &ptrans, &ptrans_len);
+ err = file_get_translator_cntl (*node, &fsys);
  if (! err)
-   /* Has a passive translator, see if there's an active one too.  */
+   /* There is!  Get its root node to use as the actual file.  */
{
- fsys_t fsys;  /* Active translator control port.  */
-
- if (ptrans != _ptrans)
-   /* Deallocate out-of-line memory from file_get_translator.  */
-   munmap (ptrans, ptrans_len);
-
- err = file_get_translator_cntl (*node, &fsys);
+ file_t unauth_dir; /* DIR unauthenticated.  */
+ err = io_restrict_auth (dir, &unauth_dir, 0, 0, 0, 0);
  if (! err)
-   /* There is!  Get its root node to use as the actual file.  */
-   {
- file_t unauth_dir; /* DIR unauthenticated.  */
- err = io_restrict_auth (dir, &unauth_dir, 0, 0, 0, 0);
- if (! err)
-   {
- file_t old_node = *node;
- err = fsys_getroot (fsys,
- unauth_dir, MACH_MSG_TYPE_COPY_SEND,
- uids, num_uids, gids, num_gids,
- flags & ~O_NOTRANS, retry,
- retry_name, node);
- mach_port_deallocate (mach_task_self (), unauth_dir);
- if (! err)
-   mach_port_deallocate (mach_task_self (), old_node);
-   }
- mach_port_deallocate (mach_task_self (), fsys);
-   }
+   {
+ file_t old_node = *node;
+ err = fsys_getroot (fsys,
+ unauth_dir, MACH_MSG_TYPE_COPY_SEND,
+ uids, num_uids, gids, num_gids,
+ flags & ~O_NOTRANS, retry,
+ retry_name, node);
+ mach_port_deallocate (mach_task_self (), unauth_dir);
+ if (! err)
+   mach_port_deallocate (mach_task_self (), old_node);
+   }
+ mach_port_deallocate (mach_task_self (), fsys);
}
- else if (err == EINVAL)
-   /* No passive translator.  */
-   err = 0;
 
  if (!err && tail)
/* Append TAIL to RETRY_NAME.  */
-- 
1.7.10.4




Re: [PATCH 1/6] procfs: fix the error handling in argp_parser

2013-06-29 Thread Justus Winter
Quoting Samuel Thibault (2013-06-29 22:11:21)
> Justus Winter, le Fri 28 Jun 2013 18:37:40 +0200, a écrit :
> > Do not exit using error (1, ..) but gracefully handle the error using
> > argp_error. Also fix a typo ("the a user") while touching these lines.
> > 
> > * procfs/main.c (argp_parser): Proper error handling.
> > (argp_parser): Fix typo.
> 
> Applied, thanks.
> 
> Oops, I realize I've forgotten to set --author, sorry about that.
> Producing patches that I can just give to git-am would have helped
> avoiding it :)

How?

Justus


signature.asc
Description: signature


[PATCH 2/4] sutils: fix a compiler warning

2013-07-01 Thread Justus Winter
Fix a compiler warning by dropping the const qualifier. It is not
appropriate to qualify pointers to dynamically allocated memory as
const.

* sutils/fstab.c (real_name): Drop const qualifier.
---
 sutils/fstab.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sutils/fstab.c b/sutils/fstab.c
index e241de6..ca5c4a5 100644
--- a/sutils/fstab.c
+++ b/sutils/fstab.c
@@ -498,7 +498,7 @@ inline struct fs *
 fstab_find (const struct fstab *fstab, const char *name)
 {
   struct fs *ret;
-  const char *real_name;
+  char *real_name;
 
   ret = fstab_find_device (fstab, name);
   if (ret)
-- 
1.7.10.4




[PATCH 3/4] mount: implement -O, --test-opts

2013-07-01 Thread Justus Winter
--test-opts in combination with --all mounts only those filesystems
with options matching the given set of options.

Note that the semantic of the inverting "no" prefix differs from
--types: While --types=nonfs,ufs means neither nfs nor ufs,
--test-opts=nofoo,bar means not foo, but bar.

* utils/mount.c (test_opts): New variable.
(test_opts_len): Likewise.
(parse_opt): Handle -O, --test-opts.
(match_options): New function.
(main): Use match_options as filter.
---
 utils/mount.c |   62 +++--
 1 file changed, 60 insertions(+), 2 deletions(-)

diff --git a/utils/mount.c b/utils/mount.c
index f8928f1..07077a5 100644
--- a/utils/mount.c
+++ b/utils/mount.c
@@ -39,6 +39,8 @@ static int fake;
 static char *options;
 static size_t options_len;
 static mach_msg_timeout_t timeout;
+static char *test_opts;
+static size_t test_opts_len;
 
 static enum { mount, query } mode;
 static enum { qf_standard, qf_fstab, qf_translator } query_format;
@@ -57,6 +59,8 @@ static const struct argp_option argp_opts[] =
   {"remount", 0, 0, OPTION_ALIAS},
   {"verbose", 'v', 0, 0, "Give more detailed information"},
   {"no-mtab", 'n', 0, 0, "Do not update /etc/mtab"},
+  {"test-opts", 'O', "OPTIONS", 0,
+   "Only mount fstab entries matching the given set of options"},
   {"fake", 'f', 0, 0, "Do not actually mount, just pretend"},
   {0, 0}
 };
@@ -122,6 +126,12 @@ parse_opt (int key, char *arg, struct argp_state *state)
   fake = 1;
   break;
 
+case 'O':
+  err = argz_create_sep (arg, ',', &test_opts, &test_opts_len);
+  if (err)
+   argp_failure (state, 100, ENOMEM, "%s", arg);
+  break;
+
 case ARGP_KEY_ARG:
   if (mountpoint == 0) /* One arg: mountpoint */
mountpoint = arg;
@@ -192,6 +202,49 @@ static const struct argp_child argp_kids[] =
   { 0 } };
 static struct argp argp = { argp_opts, parse_opt, args_doc, doc, argp_kids };
 
+/* Check whether the given mount entry matches the given set of
+   options.
+
+   Returns 0 if foo is in the options vector but nofoo is in test_opts.
+   Returns 0 if foo is in test_opts but foo is not in the options vector. */
+int
+match_options (struct mntent *mntent)
+{
+  char *opts;
+  size_t opts_len;
+
+  error_t err = argz_create_sep (mntent->mnt_opts, ',', &opts, &opts_len);
+  if (err)
+error (3, err, "parsing mount options failed");
+
+  for (char *test = test_opts;
+   test; test = argz_next (test_opts, test_opts_len, test))
+{
+  char *needle = test;
+  int inverse = strncmp("no", needle, 2) == 0;
+  if (inverse)
+needle += 2;
+
+  int match = 0;
+  for (char *opt = opts; opt; opt = argz_next (opts, opts_len, opt))
+{
+  if (strcmp (opt, needle) == 0) {
+if (inverse)
+  return 0; /* foo in opts, nofoo in test_opts. */
+
+/* foo in opts, foo in test_opts, record match. */
+match = 1;
+  }
+}
+
+  if (! inverse && ! match)
+return 0; /* No foo in opts, but foo in test_opts. */
+}
+
+  /* If no conflicting test_opt was encountered, return success. */
+  return 1;
+}
+
 /* Mount one filesystem.  */
 static error_t
 do_mount (struct fs *fs, int remount)
@@ -615,8 +668,13 @@ main (int argc, char **argv)
   case mount:
for (fs = fstab->entries; fs; fs = fs->next)
  {
-   if (fstab_params.do_all && hasmntopt (&fs->mntent, MNTOPT_NOAUTO))
- continue;
+   if (fstab_params.do_all) {
+  if (hasmntopt (&fs->mntent, MNTOPT_NOAUTO))
+continue;
+
+  if (! match_options (&fs->mntent))
+continue;
+}
err |= do_mount (fs, remount);
  }
break;
-- 
1.7.10.4




[PATCH 4/4] mount: ignore mounted filesystems if --all is given

2013-07-01 Thread Justus Winter
Linux' mount utility ignores mounted filesystems if mount --all is
invoked. This patch makes our mount do the same.

utils/mount.c (main): Ignore mounted filesystems if --all is given.
---
 utils/mount.c |9 +
 1 file changed, 9 insertions(+)

diff --git a/utils/mount.c b/utils/mount.c
index 07077a5..c3e3475 100644
--- a/utils/mount.c
+++ b/utils/mount.c
@@ -674,6 +674,15 @@ main (int argc, char **argv)
 
   if (! match_options (&fs->mntent))
 continue;
+
+  fsys_t mounted;
+  err = fs_fsys (fs, &mounted);
+  if (err)
+  error (0, err, "cannot determine if %s is already mounted",
+ fs->mntent.mnt_fsname);
+
+  if (mounted != MACH_PORT_NULL)
+continue;
 }
err |= do_mount (fs, remount);
  }
-- 
1.7.10.4




[PATCH 1/4] sutils: fix the semantic of -t, --types in fstab.c

2013-07-01 Thread Justus Winter
The mount utility on both Linux and FreeBSD allows one to either
specify a whitelist or a blacklist of filesystem types to consider for
--all. Prefixing the list with "no" indicates that the list is a
blacklist. Furthermore, Linux' mount utility ignores a "no" prefix on
any entry in the given list.

Previously the Hurd variant first applied whitelist containing all
positive values given and then filtered the resulting list using all
negative values. But this makes little sense because each entry only
has one value for the filesystem type (mnt_type) and all values are
mutually exclusive.

This patch adjusts the fstab handling code so that our mount utility
behaves like the Linux mount utility. This code is used by both mount
and fsck. The same argumentation applies to fsck as well.

Like implemented in Linux mount, any "no" prefix is ignored to retain
compatibility with the old behavior.

* sutils/fstab.c (fstab_argp_create): Fix semantic of --types.
---
 sutils/fstab.c |  103 +++-
 1 file changed, 27 insertions(+), 76 deletions(-)

diff --git a/sutils/fstab.c b/sutils/fstab.c
index b66e519..e241de6 100644
--- a/sutils/fstab.c
+++ b/sutils/fstab.c
@@ -880,90 +880,41 @@ fstab_argp_create (struct fstab_argp_params *params,
check = fstab;
   else
{
- struct fs *fs;
- const char *tn;
- unsigned int nonexclude_types;
-
  err = fstab_create (types, &check);
  if (err)
error (105, err, "fstab_create");
 
- /* For each excluded type (i.e. `-t notype'), clobber the
-fstype entry's program with an empty string to mark it.  */
- nonexclude_types = 0;
- for (tn = params->types; tn;
-  tn = argz_next (params->types, params->types_len, tn))
-   {
- if (!strncasecmp (tn, "no", 2))
-   {
- struct fstype *type;
- err = fstypes_get (types, &tn[2], &type);
- if (err)
-   error (106, err, "fstypes_get");
- free (type->program);
- type->program = strdup ("");
-   }
- else
-   ++nonexclude_types;
-   }
-
- if (nonexclude_types != 0)
-   {
- const char *tn;
- struct fstypes *wanttypes;
-
- /* We will copy the types we want to include into a fresh
-list in WANTTYPES.  Since we specify no search formats,
-`fstypes_get' applied to WANTTYPES can only create
-elements with a null `program' field.  */
- err = fstypes_create (0, 0, &wanttypes);
- if (err)
-   error (102, err, "fstypes_create");
-
- for (tn = params->types; tn;
-  tn = argz_next (params->types, params->types_len, tn))
-   if (strncasecmp (tn, "no", 2))
- {
-   struct fstype *type;
-   err = fstypes_get (types, tn, &type);
-   if (err)
- error (106, err, "fstypes_get");
-   if (type->program == 0)
- error (0, 0,
-"requested filesystem type `%s' unknown", tn);
-   else
- {
-   struct fstype *newtype = malloc (sizeof *newtype);
-   newtype->name = strdup (type->name);
-   newtype->program = strdup (type->program);
-   newtype->next = wanttypes->entries;
-   wanttypes->entries = newtype;
- }
- }
-
- /* fstypes_free (types); */
- types = wanttypes;
-   }
+  int blacklist = strncasecmp (params->types, "no", 2) == 0;
+  if (blacklist)
+params->types += 2; /* Skip no. */
 
+ struct fs *fs;
  for (fs = fstab->entries; fs; fs = fs->next)
{
- const char *ptn;
- struct fstype *type;
-
- err = fs_type (fs, &type);
- if (err || nonexclude_types)
-   {
- err = fstypes_get (types, fs->mntent.mnt_type, &type);
- if (err)
-   error (106, err, "fstypes_get");
- if (params->types != 0)
-   continue;
-   }
- if (nonexclude_types && type->program == 0)
-   continue;   /* Freshly created, was not in WANTTYPES.  */
- if (type->program != 0 && type->program[0] == '\0')
-   continue;   /* This type is marked as excluded.  */
+  if (strcmp (fs->mntent.mnt_type, MNTTYPE_SWAP) == 0)
+continue; /* Ignore swap entries. */
+
+  const char *tn;
+  int matched = 0;
+  for (tn = params->types; tn;
+   tn = argz_n

[PATCH] libfshelp: add missing import

2013-07-03 Thread Justus Winter
Add missing import of alloca.h.

* libfshelp/set-options.c: Add missing import.
---
 libfshelp/set-options.c |1 +
 1 file changed, 1 insertion(+)

diff --git a/libfshelp/set-options.c b/libfshelp/set-options.c
index 13e4001..77cdba1 100644
--- a/libfshelp/set-options.c
+++ b/libfshelp/set-options.c
@@ -23,6 +23,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "fshelp.h"
 
-- 
1.7.10.4




RFC: get_translator_info, needed for a mtab translator

2013-07-03 Thread Justus Winter
Hi,

we discussed in #hurd that I'd send my mtab prototype quite early so
that we can discuss the rpc procedure and the integration in lib*fs
and libfshelp. Please let me know what you think.

For testing purposes there's a mtab tool included in utils/mtab.c:

% find tmp
tmp
tmp/foo
tmp/foo/bar
% utils/mtab tmp
none tmp ../tmpfs/tmpfs writable,no-inherit-dir-group,no-sync 0 0
none tmp/foo ../tmpfs/tmpfs writable,no-inherit-dir-group,no-sync 0 0
none tmp/foo/bar ../tmpfs/tmpfs writable,no-inherit-dir-group,no-sync 0 0

Justus




[PATCH] get_translator_info wip

2013-07-03 Thread Justus Winter
---
 hurd/fsys.defs   |8 ++
 libdiskfs/Makefile   |3 +-
 libdiskfs/dir-lookup.c   |5 +
 libdiskfs/diskfs.h   |3 +
 libdiskfs/file-set-trans.c   |4 +
 libdiskfs/fsys-get-translator-info.c |   61 +++
 libdiskfs/fsys-getroot.c |3 +-
 libdiskfs/peropen-make.c |8 ++
 libdiskfs/peropen-rele.c |1 +
 libfshelp/Makefile   |3 +-
 libfshelp/fshelp.h   |   12 +++
 libfshelp/translator-list.c  |   87 
 utils/Makefile   |8 +-
 utils/mtab.c |  187 ++
 14 files changed, 388 insertions(+), 5 deletions(-)
 create mode 100644 libdiskfs/fsys-get-translator-info.c
 create mode 100644 libfshelp/translator-list.c
 create mode 100644 utils/mtab.c

diff --git a/hurd/fsys.defs b/hurd/fsys.defs
index 979a6cf..f816da0 100644
--- a/hurd/fsys.defs
+++ b/hurd/fsys.defs
@@ -127,3 +127,11 @@ routine fsys_get_options (
server: fsys_t;
RPT
out options: data_t, dealloc);
+
+/* Return the options describing the operation of the receiving
+   filesystem (sutiable for fsys_set_options).  */
+routine fsys_get_translator_info (
+   server: fsys_t;
+   RPT
+out source: string_t;
+out children: data_t);
diff --git a/libdiskfs/Makefile b/libdiskfs/Makefile
index c6b5c3f..2bfb1bf 100644
--- a/libdiskfs/Makefile
+++ b/libdiskfs/Makefile
@@ -34,7 +34,8 @@ IOSRCS= io-async-icky.c io-async.c io-duplicate.c 
io-get-conch.c io-revoke.c \
io-reauthenticate.c io-rel-conch.c io-restrict-auth.c io-seek.c \
io-select.c io-stat.c io-stubs.c io-write.c io-version.c io-sigio.c
 FSYSSRCS=fsys-getroot.c fsys-goaway.c fsys-startup.c fsys-getfile.c \
-   fsys-options.c fsys-syncfs.c fsys-forward.c
+   fsys-options.c fsys-syncfs.c fsys-forward.c \
+   fsys-get-translator-info.c
 IFSOCKSRCS=ifsock.c
 OTHERSRCS = conch-fetch.c conch-set.c dir-clear.c dir-init.c dir-renamed.c \
extern-inline.c \
diff --git a/libdiskfs/dir-lookup.c b/libdiskfs/dir-lookup.c
index 923be03..31142ef 100644
--- a/libdiskfs/dir-lookup.c
+++ b/libdiskfs/dir-lookup.c
@@ -82,6 +82,11 @@ diskfs_S_dir_lookup (struct protid *dircred,
   goto gotit;
 }
 
+  free (dircred->po->path);
+  dircred->po->path = strdup(path); /* XXX is this the right place? */
+  if (! dircred->po->path)
+return ENOMEM;
+
   dnp = dircred->po->np;
 
   pthread_mutex_lock (&dnp->lock);
diff --git a/libdiskfs/diskfs.h b/libdiskfs/diskfs.h
index 0f9c1d3..2489517 100644
--- a/libdiskfs/diskfs.h
+++ b/libdiskfs/diskfs.h
@@ -69,6 +69,9 @@ struct peropen
   mach_port_t shadow_root_parent;
   /* If in a shadow tree, its root node in this translator.  */
   struct node *shadow_root;
+
+  /* Path relative to the root of the translator. */
+  char *path;
 };
 
 /* A unique one of these exists for each node currently in use (and
diff --git a/libdiskfs/file-set-trans.c b/libdiskfs/file-set-trans.c
index 3798001..acd47bb 100644
--- a/libdiskfs/file-set-trans.c
+++ b/libdiskfs/file-set-trans.c
@@ -206,5 +206,9 @@ diskfs_S_file_set_translator (struct protid *cred,
 }
 
   pthread_mutex_unlock (&np->lock);
+
+  if (! error && cred->po->path)
+error = fshelp_add_translator (cred->po->path);
+
   return error;
 }
diff --git a/libdiskfs/fsys-get-translator-info.c 
b/libdiskfs/fsys-get-translator-info.c
new file mode 100644
index 000..d882397
--- /dev/null
+++ b/libdiskfs/fsys-get-translator-info.c
@@ -0,0 +1,61 @@
+/* fsys_get_translator_info
+
+   Copyright (C) 2013 Free Software Foundation, Inc.
+
+   Written by Justus Winter <4win...@informatik.uni-hamburg.de>
+
+   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.  */
+
+#include "priv.h"
+#include "fsys_S.h"
+
+/* Ask SERVER to provide fsys translation service for us.  REQUESTOR is
+   the bootstrap port supplied to the original translator, and ARGV are
+   the command line arguments.  If the recipient accepts the request, he
+   (or some delegate) should send fsys_startup to REQUESTOR to start the
+ 

[PATCH] mount: handle -t auto

2013-07-04 Thread Justus Winter
Use libblkid to detect the filesystem type if "auto" is given as
type. Remove the translator localization from main, this is also done
in do_mount and any errors are propagated properly. This way "auto" is
handled correctly if given on the command line or used as filesystem
type in the fstab.

* utils/mount.c (DEFAULT_FSTYPE): Use "auto" as default type.
(do_mount): Detect type using libblkid.
(main): Drop translator localization.
---
 utils/Makefile |1 +
 utils/mount.c  |   27 +++
 2 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/utils/Makefile b/utils/Makefile
index 8a998f3..5130ca0 100644
--- a/utils/Makefile
+++ b/utils/Makefile
@@ -38,6 +38,7 @@ LDLIBS += -lpthread
 login-LDLIBS = -lutil $(LIBCRYPT)
 addauth-LDLIBS = $(LIBCRYPT)
 setauth-LDLIBS = $(LIBCRYPT)
+mount-LDLIBS = -lblkid
 
 INSTALL-login-ops = -o root -m 4755
 INSTALL-ids-ops = -o root -m 4755
diff --git a/utils/mount.c b/utils/mount.c
index c3e3475..dc9f658 100644
--- a/utils/mount.c
+++ b/utils/mount.c
@@ -28,9 +28,10 @@
 #include 
 #include 
 #include 
+#include 
 
 #define SEARCH_FMTS_HURD "%sfs\0" _HURD "%s"
-#define DEFAULT_FSTYPE "ext2"
+#define DEFAULT_FSTYPE "auto"
 
 static char *fstype = DEFAULT_FSTYPE;
 static char *device, *mountpoint;
@@ -381,6 +382,23 @@ do_mount (struct fs *fs, int remount)
  return EBUSY;
}
 
+  if (strcmp (fs->mntent.mnt_type, "auto") == 0)
+{
+  char *type =
+blkid_get_tag_value (NULL, "TYPE", fs->mntent.mnt_fsname);
+  if (! type)
+{
+  error (0, 0, "failed to detect file system type");
+  return EFTYPE;
+}
+  else
+{
+  fs->mntent.mnt_type = strdup (type);
+  if (! fs->mntent.mnt_type)
+error (3, ENOMEM, "failed to allocate memory");
+}
+}
+
   err = fs_type (fs, &type);
   if (err)
{
@@ -622,13 +640,6 @@ main (int argc, char **argv)
mnt_opts: 0,
mnt_freq: 0, mnt_passno: 0
   };
-  struct fstype *fst;
-
-  err = fstypes_get (fstab->types, fstype, &fst);
-  if (err)
-   error (106, err, "cannot initialize type %s", fstype);
-  if (fst->program == 0)
-   error (2, 0, "filesystem type %s not recognized", fstype);
 
   err = fstab_add_mntent (fstab, &m, &fs);
   if (err)
-- 
1.7.10.4




Re: RFC: get_translator_info, needed for a mtab translator

2013-07-04 Thread Justus Winter
Quoting Justus Winter (2013-07-03 23:11:57)
> Hi,
> 
> we discussed in #hurd that I'd send my mtab prototype quite early so
> that we can discuss the rpc procedure [...]

Looking at libshouldbeinlibc/fsysops.c:fsys_get_readonly (fsys_t fsys, int 
*readonly)

I'm thinking that this might be an opportunity to get rid of the
heuristic in that function. The comment explains the issue:

/* Ask FSYS whether it's readonly, returning the result in READONLY; we don't
   really have a good method for this, other than asking for it's options and
   looking for `--readonly' or `--writable'.  If we see neither, return
   EOPNOTSUPP.  */

Thoughts?
Justus



Updated patches for mount, add umount

2013-07-04 Thread Justus Winter
Hi,

this is a patch series with all the non-trivial changes I posted this
week. This obsoletes:

1372686414-25363-1-git-send-email-4win...@informatik.uni-hamburg.de
1372930812-22762-1-git-send-email-4win...@informatik.uni-hamburg.de

This also adds a umount utility that should implement all of the
functionality used by Debians initscript package. Note that without a
mtab or /proc/mounts file the umount utility is not very useful, but I
used it successfully in combination with my mtab prototype to umount
nested tmpfs translators.

Cheers,
Justus




[PATCH 3/6] mount: ignore mounted filesystems if --all is given

2013-07-04 Thread Justus Winter
Linux' mount utility ignores mounted filesystems if mount --all is
invoked. This patch makes our mount do the same.

utils/mount.c (main): Ignore mounted filesystems if --all is given.
---
 utils/mount.c |9 +
 1 file changed, 9 insertions(+)

diff --git a/utils/mount.c b/utils/mount.c
index 73a7539..77b2138 100644
--- a/utils/mount.c
+++ b/utils/mount.c
@@ -631,6 +631,15 @@ main (int argc, char **argv)
 
   if (! match_options (&fs->mntent))
 continue;
+
+  fsys_t mounted;
+  err = fs_fsys (fs, &mounted);
+  if (err)
+  error (0, err, "cannot determine if %s is already mounted",
+ fs->mntent.mnt_fsname);
+
+  if (mounted != MACH_PORT_NULL)
+continue;
 }
err |= do_mount (fs, remount);
  }
-- 
1.7.10.4




[PATCH 4/6] mount: handle -t auto

2013-07-04 Thread Justus Winter
Use libblkid to detect the filesystem type if "auto" is given as
type. Remove the translator localization from main, this is also done
in do_mount and any errors are propagated properly. This way "auto" is
handled correctly if given on the command line or used as filesystem
type in the fstab.

* utils/mount.c (DEFAULT_FSTYPE): Use "auto" as default type.
(do_mount): Detect type using libblkid.
(main): Drop translator localization.
---
 utils/Makefile |1 +
 utils/mount.c  |   27 +++
 2 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/utils/Makefile b/utils/Makefile
index 6975fb5..207c904 100644
--- a/utils/Makefile
+++ b/utils/Makefile
@@ -37,6 +37,7 @@ LDLIBS += -lpthread
 login-LDLIBS = -lutil $(LIBCRYPT)
 addauth-LDLIBS = $(LIBCRYPT)
 setauth-LDLIBS = $(LIBCRYPT)
+mount-LDLIBS = -lblkid
 
 INSTALL-login-ops = -o root -m 4755
 INSTALL-ids-ops = -o root -m 4755
diff --git a/utils/mount.c b/utils/mount.c
index 77b2138..5863f96 100644
--- a/utils/mount.c
+++ b/utils/mount.c
@@ -28,11 +28,12 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "match-options.h"
 
 #define SEARCH_FMTS_HURD "%sfs\0" _HURD "%s"
-#define DEFAULT_FSTYPE "ext2"
+#define DEFAULT_FSTYPE "auto"
 
 static char *fstype = DEFAULT_FSTYPE;
 static char *device, *mountpoint;
@@ -338,6 +339,23 @@ do_mount (struct fs *fs, int remount)
  return EBUSY;
}
 
+  if (strcmp (fs->mntent.mnt_type, "auto") == 0)
+{
+  char *type =
+blkid_get_tag_value (NULL, "TYPE", fs->mntent.mnt_fsname);
+  if (! type)
+{
+  error (0, 0, "failed to detect file system type");
+  return EFTYPE;
+}
+  else
+{
+  fs->mntent.mnt_type = strdup (type);
+  if (! fs->mntent.mnt_type)
+error (3, ENOMEM, "failed to allocate memory");
+}
+}
+
   err = fs_type (fs, &type);
   if (err)
{
@@ -579,13 +597,6 @@ main (int argc, char **argv)
mnt_opts: 0,
mnt_freq: 0, mnt_passno: 0
   };
-  struct fstype *fst;
-
-  err = fstypes_get (fstab->types, fstype, &fst);
-  if (err)
-   error (106, err, "cannot initialize type %s", fstype);
-  if (fst->program == 0)
-   error (2, 0, "filesystem type %s not recognized", fstype);
 
   err = fstab_add_mntent (fstab, &m, &fs);
   if (err)
-- 
1.7.10.4




[PATCH 5/6] sutils: allow multiple entries for the device "none"

2013-07-04 Thread Justus Winter
Previously it was not possible to add two mount entries with the same
device information to an fstab structure. This is easily fixed by
breaking the assumption, that there is only one possible mount entry
for the "none" device as used by many purely virtual file systems.

* utils/fstab.c (fstab_find_device): Return NULL if name is "none".
---
 sutils/fstab.c |   12 ++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/sutils/fstab.c b/sutils/fstab.c
index e241de6..d3b8b6f 100644
--- a/sutils/fstab.c
+++ b/sutils/fstab.c
@@ -457,11 +457,19 @@ fs_remount (struct fs *fs)
   return err;
 }
 
-/* Returns the FS entry in FSTAB with the device field NAME (there can only
-   be one such entry).  */
+/* Returns the FS entry in FSTAB with the device field NAME.
+
+   In general there can only be one such entry. This holds not true
+   for virtual file systems that use "none" as device name.
+
+   If name is "none", NULL is returned. This also makes it possible to
+   add more than one entry for the device "none". */
 inline struct fs *
 fstab_find_device (const struct fstab *fstab, const char *name)
 {
+  if (strcmp (name, "none") == 0)
+return NULL;
+
   struct fs *fs;
   for (fs = fstab->entries; fs; fs = fs->next)
 if (strcmp (fs->mntent.mnt_fsname, name) == 0)
-- 
1.7.10.4




[PATCH 2/6] mount: implement -O, --test-opts

2013-07-04 Thread Justus Winter
--test-opts in combination with --all mounts only those filesystems
with options matching the given set of options.

Note that the semantic of the inverting "no" prefix differs from
--types: While --types=nonfs,ufs means neither nfs nor ufs,
--test-opts=nofoo,bar means not foo, but bar.

* utils/match-options.h: New file.
* utils/match-options.c: Likewise.
(test_opts): New variable.
(test_opts_len): Likewise.
(match_options): New function.
* utils/mount.c (parse_opt): Handle -O, --test-opts.
(main): Use match_options as filter.
---
 utils/Makefile|5 ++--
 utils/match-options.c |   68 +
 utils/match-options.h |   33 
 utils/mount.c |   19 --
 4 files changed, 121 insertions(+), 4 deletions(-)
 create mode 100644 utils/match-options.c
 create mode 100644 utils/match-options.h

diff --git a/utils/Makefile b/utils/Makefile
index e3bed0b..6975fb5 100644
--- a/utils/Makefile
+++ b/utils/Makefile
@@ -28,7 +28,8 @@ SRCS = shd.c ps.c settrans.c syncfs.c showtrans.c addauth.c 
rmauth.c \
uptime.sh psout.c ids.c vmstat.c portinfo.c devprobe.c vminfo.c \
parse.c frobauth.c frobauth-mod.c setauth.c pids.c nonsugid.c \
unsu.c ftpcp.c ftpdir.c storeread.c storecat.c msgport.c \
-   rpctrace.c mount.c gcore.c fakeauth.c fakeroot.sh remap.sh
+   rpctrace.c mount.c gcore.c fakeauth.c fakeroot.sh remap.sh \
+   match-options.c
 
 OBJS = $(filter-out %.sh,$(SRCS:.c=.o))
 HURDLIBS = ps ihash store fshelp ports ftpconn shouldbeinlibc
@@ -72,7 +73,7 @@ fakeauth-CPPFLAGS = -I$(srcdir)/../auth
 authServer-CPPFLAGS = -I$(srcdir)/../auth
 auth_requestUser-CPPFLAGS = -I$(srcdir)/../auth
 
-mount: ../sutils/fstab.o ../sutils/clookup.o \
+mount: ../sutils/fstab.o ../sutils/clookup.o match-options.o \
$(foreach L,fshelp ports,../lib$L/lib$L.a)
 ../sutils/fstab.o ../sutils/clookup.o: FORCE
$(MAKE) -C $(@D) $(@F)
diff --git a/utils/match-options.c b/utils/match-options.c
new file mode 100644
index 000..11fc9dc
--- /dev/null
+++ b/utils/match-options.c
@@ -0,0 +1,68 @@
+/* Common functionality for the --test-opts flag of mount and umount.
+
+   Copyright (C) 2013 Free Software Foundation, Inc.
+   Written by Justus Winter <4win...@informatik.uni-hamburg.de>
+
+   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 
+#include 
+#include 
+#include 
+
+#include "match-options.h"
+
+char *test_opts;
+size_t test_opts_len;
+
+int
+match_options (struct mntent *mntent)
+{
+  char *opts;
+  size_t opts_len;
+
+  error_t err = argz_create_sep (mntent->mnt_opts, ',', &opts, &opts_len);
+  if (err)
+error (3, err, "parsing mount options failed");
+
+  for (char *test = test_opts;
+   test; test = argz_next (test_opts, test_opts_len, test))
+{
+  char *needle = test;
+  int inverse = strncmp("no", needle, 2) == 0;
+  if (inverse)
+needle += 2;
+
+  int match = 0;
+  for (char *opt = opts; opt; opt = argz_next (opts, opts_len, opt))
+{
+  if (strcmp (opt, needle) == 0) {
+if (inverse)
+  return 0; /* foo in opts, nofoo in test_opts. */
+
+/* foo in opts, foo in test_opts, record match. */
+match = 1;
+  }
+}
+
+  if (! inverse && ! match)
+return 0; /* No foo in opts, but foo in test_opts. */
+}
+
+  /* If no conflicting test_opt was encountered, return success. */
+  return 1;
+}
diff --git a/utils/match-options.h b/utils/match-options.h
new file mode 100644
index 000..ea7ae70
--- /dev/null
+++ b/utils/match-options.h
@@ -0,0 +1,33 @@
+/* Common functionality for the --test-opts flag of mount and umount.
+
+   Copyright (C) 2013 Free Software Foundation, Inc.
+   Written by Justus Winter <4win...@informatik.uni-hamburg.de>
+
+   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 WA

[PATCH 6/6] umount: add a umount utility

2013-07-04 Thread Justus Winter
This adds a umount utility that implements most of the functions that
the Linux umount utility provides, especially that subset that is used
by the Debian package initscripts.

* utils/umount.c: New file.
---
 utils/Makefile |   10 +-
 utils/umount.c |  308 
 2 files changed, 314 insertions(+), 4 deletions(-)
 create mode 100644 utils/umount.c

diff --git a/utils/Makefile b/utils/Makefile
index 207c904..4fe2dc2 100644
--- a/utils/Makefile
+++ b/utils/Makefile
@@ -21,7 +21,9 @@ makemode := utilities
 targets = shd ps settrans showtrans syncfs fsysopts \
storeinfo login w uptime ids loginpr sush vmstat portinfo \
devprobe vminfo addauth rmauth unsu setauth ftpcp ftpdir storecat \
-   storeread msgport rpctrace mount gcore fakeauth fakeroot remap
+   storeread msgport rpctrace mount gcore fakeauth fakeroot remap \
+   umount
+
 special-targets = loginpr sush uptime fakeroot remap
 SRCS = shd.c ps.c settrans.c syncfs.c showtrans.c addauth.c rmauth.c \
fsysopts.c storeinfo.c login.c loginpr.sh sush.sh w.c \
@@ -29,7 +31,7 @@ SRCS = shd.c ps.c settrans.c syncfs.c showtrans.c addauth.c 
rmauth.c \
parse.c frobauth.c frobauth-mod.c setauth.c pids.c nonsugid.c \
unsu.c ftpcp.c ftpdir.c storeread.c storecat.c msgport.c \
rpctrace.c mount.c gcore.c fakeauth.c fakeroot.sh remap.sh \
-   match-options.c
+   match-options.c umount.c
 
 OBJS = $(filter-out %.sh,$(SRCS:.c=.o))
 HURDLIBS = ps ihash store fshelp ports ftpconn shouldbeinlibc
@@ -58,7 +60,7 @@ ftpcp ftpdir: ../libftpconn/libftpconn.a
 settrans: ../libfshelp/libfshelp.a ../libports/libports.a
 ps w ids settrans syncfs showtrans fsysopts storeinfo login vmstat portinfo \
   devprobe vminfo addauth rmauth setauth unsu ftpcp ftpdir storeread \
-  storecat msgport mount: \
+  storecat msgport mount umount: \
../libshouldbeinlibc/libshouldbeinlibc.a
 
 $(filter-out $(special-targets), $(targets)): %: %.o
@@ -74,7 +76,7 @@ fakeauth-CPPFLAGS = -I$(srcdir)/../auth
 authServer-CPPFLAGS = -I$(srcdir)/../auth
 auth_requestUser-CPPFLAGS = -I$(srcdir)/../auth
 
-mount: ../sutils/fstab.o ../sutils/clookup.o match-options.o \
+mount umount: ../sutils/fstab.o ../sutils/clookup.o match-options.o \
$(foreach L,fshelp ports,../lib$L/lib$L.a)
 ../sutils/fstab.o ../sutils/clookup.o: FORCE
$(MAKE) -C $(@D) $(@F)
diff --git a/utils/umount.c b/utils/umount.c
new file mode 100644
index 000..707f058
--- /dev/null
+++ b/utils/umount.c
@@ -0,0 +1,308 @@
+/* Roughly Unix/Linux-compatible `umount' frontend for Hurd translators.
+
+   Copyright (C) 2013 Free Software Foundation, Inc.
+   Written by Justus Winter <4win...@informatik.uni-hamburg.de>
+
+   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 "../sutils/fstab.h"
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "match-options.h"
+
+/* XXX fix libc */
+#undef _PATH_MOUNTED
+#define _PATH_MOUNTED "/etc/mtab"
+
+static char *targets;
+static size_t targets_len;
+static int readonly;
+static int verbose;
+static int passive_flags = FS_TRANS_SET;
+static int active_flags = FS_TRANS_SET;
+static int goaway_flags;
+static int fake;
+
+static struct fstab_argp_params fstab_params;
+
+#define FAKE_KEY 0x80 /* !isascii (FAKE_KEY), so no short option. */
+
+static const struct argp_option argp_opts[] =
+{
+  {"fake", FAKE_KEY, 0, 0, "Do not actually umount, just pretend"},
+  {"force", 'f', 0, 0, "Force umount by killing the translator"},
+  {"no-mtab", 'n', 0, 0, "Do not update /etc/mtab"},
+  {"read-only", 'r', 0, 0, "If unmounting fails, try to remount read-only"},
+  {"nosync", 'S', 0, 0, "Don't sync a translator before killing it"},
+  {"test-opts", 'O', "OPTIONS", 0,
+   "Only mount fstab entries matching the given set of options"},
+  {"verbose", 'v', 0, 0, "Give more detailed information"},
+  {},
+};
+
+static error_t
+parse_opt (int key, char *arg, struct argp_state

[PATCH 1/6] sutils: fix the semantic of -t, --types in fstab.c

2013-07-04 Thread Justus Winter
The mount utility on both Linux and FreeBSD allows one to either
specify a whitelist or a blacklist of filesystem types to consider for
--all. Prefixing the list with "no" indicates that the list is a
blacklist. Furthermore, Linux' mount utility ignores a "no" prefix on
any entry in the given list.

Previously the Hurd variant first applied whitelist containing all
positive values given and then filtered the resulting list using all
negative values. But this makes little sense because each entry only
has one value for the filesystem type (mnt_type) and all values are
mutually exclusive.

This patch adjusts the fstab handling code so that our mount utility
behaves like the Linux mount utility. This code is used by both mount
and fsck. The same argumentation applies to fsck as well.

Like implemented in Linux mount, any "no" prefix is ignored to retain
compatibility with the old behavior.

* sutils/fstab.c (fstab_argp_create): Fix semantic of --types.
---
 sutils/fstab.c |  103 +++-
 1 file changed, 27 insertions(+), 76 deletions(-)

diff --git a/sutils/fstab.c b/sutils/fstab.c
index b66e519..e241de6 100644
--- a/sutils/fstab.c
+++ b/sutils/fstab.c
@@ -880,90 +880,41 @@ fstab_argp_create (struct fstab_argp_params *params,
check = fstab;
   else
{
- struct fs *fs;
- const char *tn;
- unsigned int nonexclude_types;
-
  err = fstab_create (types, &check);
  if (err)
error (105, err, "fstab_create");
 
- /* For each excluded type (i.e. `-t notype'), clobber the
-fstype entry's program with an empty string to mark it.  */
- nonexclude_types = 0;
- for (tn = params->types; tn;
-  tn = argz_next (params->types, params->types_len, tn))
-   {
- if (!strncasecmp (tn, "no", 2))
-   {
- struct fstype *type;
- err = fstypes_get (types, &tn[2], &type);
- if (err)
-   error (106, err, "fstypes_get");
- free (type->program);
- type->program = strdup ("");
-   }
- else
-   ++nonexclude_types;
-   }
-
- if (nonexclude_types != 0)
-   {
- const char *tn;
- struct fstypes *wanttypes;
-
- /* We will copy the types we want to include into a fresh
-list in WANTTYPES.  Since we specify no search formats,
-`fstypes_get' applied to WANTTYPES can only create
-elements with a null `program' field.  */
- err = fstypes_create (0, 0, &wanttypes);
- if (err)
-   error (102, err, "fstypes_create");
-
- for (tn = params->types; tn;
-  tn = argz_next (params->types, params->types_len, tn))
-   if (strncasecmp (tn, "no", 2))
- {
-   struct fstype *type;
-   err = fstypes_get (types, tn, &type);
-   if (err)
- error (106, err, "fstypes_get");
-   if (type->program == 0)
- error (0, 0,
-"requested filesystem type `%s' unknown", tn);
-   else
- {
-   struct fstype *newtype = malloc (sizeof *newtype);
-   newtype->name = strdup (type->name);
-   newtype->program = strdup (type->program);
-   newtype->next = wanttypes->entries;
-   wanttypes->entries = newtype;
- }
- }
-
- /* fstypes_free (types); */
- types = wanttypes;
-   }
+  int blacklist = strncasecmp (params->types, "no", 2) == 0;
+  if (blacklist)
+params->types += 2; /* Skip no. */
 
+ struct fs *fs;
  for (fs = fstab->entries; fs; fs = fs->next)
{
- const char *ptn;
- struct fstype *type;
-
- err = fs_type (fs, &type);
- if (err || nonexclude_types)
-   {
- err = fstypes_get (types, fs->mntent.mnt_type, &type);
- if (err)
-   error (106, err, "fstypes_get");
- if (params->types != 0)
-   continue;
-   }
- if (nonexclude_types && type->program == 0)
-   continue;   /* Freshly created, was not in WANTTYPES.  */
- if (type->program != 0 && type->program[0] == '\0')
-   continue;   /* This type is marked as excluded.  */
+  if (strcmp (fs->mntent.mnt_type, MNTTYPE_SWAP) == 0)
+continue; /* Ignore swap entries. */
+
+  const char *tn;
+  int matched = 0;
+  for (tn = params->types; tn;
+   tn = argz_n

Re: Updated patches for mount, add umount

2013-07-04 Thread Justus Winter
Quoting Samuel Thibault (2013-07-04 22:55:51)
> Justus Winter, le Thu 04 Jul 2013 18:45:35 +0200, a écrit :
> > Note that without a
> > mtab or /proc/mounts file the umount utility is not very useful,
> 
> Mmm? In theory it should easily be able to unmount anything by just
> providing the mount point, shouldn't it?

Yes, that's the half of umount that would work. But umount also allows
one to specify the device instead of the mount point and I do not see
how to properly implement this without someone (like the mtab
translator) providing the mapping from devices to mount points and
vice versa.

Justus


signature.asc
Description: signature


Re: Updated patches for mount, add umount

2013-07-04 Thread Justus Winter
Quoting Samuel Thibault (2013-07-04 23:53:38)
> Justus Winter, le Thu 04 Jul 2013 23:30:49 +0200, a écrit :
> > Quoting Samuel Thibault (2013-07-04 22:55:51)
> > > Justus Winter, le Thu 04 Jul 2013 18:45:35 +0200, a écrit :
> > > > Note that without a
> > > > mtab or /proc/mounts file the umount utility is not very useful,
> > > 
> > > Mmm? In theory it should easily be able to unmount anything by just
> > > providing the mount point, shouldn't it?
> > 
> > Yes, that's the half of umount that would work.
> 
> Ok, good.

No, because one cannot tell if a given path is a mount point or the
device without consulting the mtab file.

I meant that it would be theoretically be possible to build a umount
that does roughly half of what umount usually does and that half would
be equivalent to settrans -gp /foo. But this umount is fully featured
and does require a mtab file to do anything. Afaict that's how umount
is supposed to work.

Justus


signature.asc
Description: signature


Re: [PATCH] Gracefully handle errors using argp_error().

2013-07-05 Thread Justus Winter
Hi :),

Quoting Cyril Roelandt (2013-07-05 01:25:26)
> Hello!
> 
> After seeing this patch from Justus Winter:
> 
> http://lists.gnu.org/archive/html/bug-hurd/2013-06/msg00120.html
> 
> I wrote a Coccinelle script that finds similar errors:

Coccinelle is quite awesome :) we should try to find port leaks with
it...

> 
> [...]
> - error(...,
> + argp_error(state,
  ^ coding convention says there should be a space there

> E);
> ...>
> }
> 
> 
> I found 4 programs that could be improved by gracefully handling errors 
> using argp_error: notice (hurd-extras), mboxfs (hurd-extras), tarfs 
> (incubator) and unionfs. The patches are attached.

In your patches the variable state is misspelled sate. How did that
happen? Your script doesn't seem to include the typo.

Cheers,
Justus


signature.asc
Description: signature


[PATCH] swapon: add -v, --verbose argument

2013-07-05 Thread Justus Winter
This patch adds a --verbose argument to swapon and swapoff to make it
more compatible with the corresponding Linux' utilities. Note that our
swapon is verbose by default and has a --quiet argument to make it
quiet, so a --verbose argument on it's own does nothing at all.

* sutils/swapon.c (main): Handle -v argument.
---
 sutils/swapon.c |5 +
 1 file changed, 5 insertions(+)

diff --git a/sutils/swapon.c b/sutils/swapon.c
index 03b17de..2403f1c 100644
--- a/sutils/swapon.c
+++ b/sutils/swapon.c
@@ -56,6 +56,7 @@ static struct argp_option options[] =
"Require a Linux swap signature page"},
   {"silent", 'q', 0,  0, "Print only diagnostic messages"},
   {"quiet",  'q', 0,  OPTION_ALIAS | OPTION_HIDDEN },
+  {"verbose",'v', 0,  0, "Be verbose"},
   {0, 0}
 };
 static char *args_doc = "DEVICE...";
@@ -490,6 +491,10 @@ main (int argc, char *argv[])
  quiet = 1;
  break;
 
+   case 'v':
+ quiet = 0;
+ break;
+
case ARGP_KEY_ARG:
 #ifdef SWAPOFF
 #define ONOFF 0
-- 
1.7.10.4




Re: [PATCH] Gracefully handle errors using argp_error().

2013-07-05 Thread Justus Winter
Quoting Cyril Roelandt (2013-07-05 10:35:18)
> On 07/05/2013 09:33 AM, Justus Winter wrote:
> > In your patches the variable state is misspelled sate. How did that
> > happen? Your script doesn't seem to include the typo.
> 
> Because the variable is actually named "sate" in the code :) Look at 
> mboxfs/mboxfs.c, for instance.

Right >,< never mind ;)

Justus



Updated patch series for mount, umount

2013-07-05 Thread Justus Winter
This is the same series as send in [0], but the umount patch has been
updated. Among minor stylistic changes it makes umount assume that a
given argument is the mount point if looking it up as device or mount
point in the mtab file fails. This makes the umount utility somewhat
useful even on systems that lack an mtab file.

Justus




[PATCH 3/6] mount: ignore mounted filesystems if --all is given

2013-07-05 Thread Justus Winter
Linux' mount utility ignores mounted filesystems if mount --all is
invoked. This patch makes our mount do the same.

utils/mount.c (main): Ignore mounted filesystems if --all is given.
---
 utils/mount.c |9 +
 1 file changed, 9 insertions(+)

diff --git a/utils/mount.c b/utils/mount.c
index 73a7539..77b2138 100644
--- a/utils/mount.c
+++ b/utils/mount.c
@@ -631,6 +631,15 @@ main (int argc, char **argv)
 
   if (! match_options (&fs->mntent))
 continue;
+
+  fsys_t mounted;
+  err = fs_fsys (fs, &mounted);
+  if (err)
+  error (0, err, "cannot determine if %s is already mounted",
+ fs->mntent.mnt_fsname);
+
+  if (mounted != MACH_PORT_NULL)
+continue;
 }
err |= do_mount (fs, remount);
  }
-- 
1.7.10.4




[PATCH 4/6] mount: handle -t auto

2013-07-05 Thread Justus Winter
Use libblkid to detect the filesystem type if "auto" is given as
type. Remove the translator localization from main, this is also done
in do_mount and any errors are propagated properly. This way "auto" is
handled correctly if given on the command line or used as filesystem
type in the fstab.

* utils/mount.c (DEFAULT_FSTYPE): Use "auto" as default type.
(do_mount): Detect type using libblkid.
(main): Drop translator localization.
---
 utils/Makefile |1 +
 utils/mount.c  |   27 +++
 2 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/utils/Makefile b/utils/Makefile
index 6975fb5..207c904 100644
--- a/utils/Makefile
+++ b/utils/Makefile
@@ -37,6 +37,7 @@ LDLIBS += -lpthread
 login-LDLIBS = -lutil $(LIBCRYPT)
 addauth-LDLIBS = $(LIBCRYPT)
 setauth-LDLIBS = $(LIBCRYPT)
+mount-LDLIBS = -lblkid
 
 INSTALL-login-ops = -o root -m 4755
 INSTALL-ids-ops = -o root -m 4755
diff --git a/utils/mount.c b/utils/mount.c
index 77b2138..5863f96 100644
--- a/utils/mount.c
+++ b/utils/mount.c
@@ -28,11 +28,12 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "match-options.h"
 
 #define SEARCH_FMTS_HURD "%sfs\0" _HURD "%s"
-#define DEFAULT_FSTYPE "ext2"
+#define DEFAULT_FSTYPE "auto"
 
 static char *fstype = DEFAULT_FSTYPE;
 static char *device, *mountpoint;
@@ -338,6 +339,23 @@ do_mount (struct fs *fs, int remount)
  return EBUSY;
}
 
+  if (strcmp (fs->mntent.mnt_type, "auto") == 0)
+{
+  char *type =
+blkid_get_tag_value (NULL, "TYPE", fs->mntent.mnt_fsname);
+  if (! type)
+{
+  error (0, 0, "failed to detect file system type");
+  return EFTYPE;
+}
+  else
+{
+  fs->mntent.mnt_type = strdup (type);
+  if (! fs->mntent.mnt_type)
+error (3, ENOMEM, "failed to allocate memory");
+}
+}
+
   err = fs_type (fs, &type);
   if (err)
{
@@ -579,13 +597,6 @@ main (int argc, char **argv)
mnt_opts: 0,
mnt_freq: 0, mnt_passno: 0
   };
-  struct fstype *fst;
-
-  err = fstypes_get (fstab->types, fstype, &fst);
-  if (err)
-   error (106, err, "cannot initialize type %s", fstype);
-  if (fst->program == 0)
-   error (2, 0, "filesystem type %s not recognized", fstype);
 
   err = fstab_add_mntent (fstab, &m, &fs);
   if (err)
-- 
1.7.10.4




[PATCH 5/6] sutils: allow multiple entries for the device "none"

2013-07-05 Thread Justus Winter
Previously it was not possible to add two mount entries with the same
device information to an fstab structure. This is easily fixed by
breaking the assumption, that there is only one possible mount entry
for the "none" device as used by many purely virtual file systems.

* utils/fstab.c (fstab_find_device): Return NULL if name is "none".
---
 sutils/fstab.c |   12 ++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/sutils/fstab.c b/sutils/fstab.c
index e241de6..d3b8b6f 100644
--- a/sutils/fstab.c
+++ b/sutils/fstab.c
@@ -457,11 +457,19 @@ fs_remount (struct fs *fs)
   return err;
 }
 
-/* Returns the FS entry in FSTAB with the device field NAME (there can only
-   be one such entry).  */
+/* Returns the FS entry in FSTAB with the device field NAME.
+
+   In general there can only be one such entry. This holds not true
+   for virtual file systems that use "none" as device name.
+
+   If name is "none", NULL is returned. This also makes it possible to
+   add more than one entry for the device "none". */
 inline struct fs *
 fstab_find_device (const struct fstab *fstab, const char *name)
 {
+  if (strcmp (name, "none") == 0)
+return NULL;
+
   struct fs *fs;
   for (fs = fstab->entries; fs; fs = fs->next)
 if (strcmp (fs->mntent.mnt_fsname, name) == 0)
-- 
1.7.10.4




[PATCH 1/6] sutils: fix the semantic of -t, --types in fstab.c

2013-07-05 Thread Justus Winter
The mount utility on both Linux and FreeBSD allows one to either
specify a whitelist or a blacklist of filesystem types to consider for
--all. Prefixing the list with "no" indicates that the list is a
blacklist. Furthermore, Linux' mount utility ignores a "no" prefix on
any entry in the given list.

Previously the Hurd variant first applied whitelist containing all
positive values given and then filtered the resulting list using all
negative values. But this makes little sense because each entry only
has one value for the filesystem type (mnt_type) and all values are
mutually exclusive.

This patch adjusts the fstab handling code so that our mount utility
behaves like the Linux mount utility. This code is used by both mount
and fsck. The same argumentation applies to fsck as well.

Like implemented in Linux mount, any "no" prefix is ignored to retain
compatibility with the old behavior.

* sutils/fstab.c (fstab_argp_create): Fix semantic of --types.
---
 sutils/fstab.c |  103 +++-
 1 file changed, 27 insertions(+), 76 deletions(-)

diff --git a/sutils/fstab.c b/sutils/fstab.c
index b66e519..e241de6 100644
--- a/sutils/fstab.c
+++ b/sutils/fstab.c
@@ -880,90 +880,41 @@ fstab_argp_create (struct fstab_argp_params *params,
check = fstab;
   else
{
- struct fs *fs;
- const char *tn;
- unsigned int nonexclude_types;
-
  err = fstab_create (types, &check);
  if (err)
error (105, err, "fstab_create");
 
- /* For each excluded type (i.e. `-t notype'), clobber the
-fstype entry's program with an empty string to mark it.  */
- nonexclude_types = 0;
- for (tn = params->types; tn;
-  tn = argz_next (params->types, params->types_len, tn))
-   {
- if (!strncasecmp (tn, "no", 2))
-   {
- struct fstype *type;
- err = fstypes_get (types, &tn[2], &type);
- if (err)
-   error (106, err, "fstypes_get");
- free (type->program);
- type->program = strdup ("");
-   }
- else
-   ++nonexclude_types;
-   }
-
- if (nonexclude_types != 0)
-   {
- const char *tn;
- struct fstypes *wanttypes;
-
- /* We will copy the types we want to include into a fresh
-list in WANTTYPES.  Since we specify no search formats,
-`fstypes_get' applied to WANTTYPES can only create
-elements with a null `program' field.  */
- err = fstypes_create (0, 0, &wanttypes);
- if (err)
-   error (102, err, "fstypes_create");
-
- for (tn = params->types; tn;
-  tn = argz_next (params->types, params->types_len, tn))
-   if (strncasecmp (tn, "no", 2))
- {
-   struct fstype *type;
-   err = fstypes_get (types, tn, &type);
-   if (err)
- error (106, err, "fstypes_get");
-   if (type->program == 0)
- error (0, 0,
-"requested filesystem type `%s' unknown", tn);
-   else
- {
-   struct fstype *newtype = malloc (sizeof *newtype);
-   newtype->name = strdup (type->name);
-   newtype->program = strdup (type->program);
-   newtype->next = wanttypes->entries;
-   wanttypes->entries = newtype;
- }
- }
-
- /* fstypes_free (types); */
- types = wanttypes;
-   }
+  int blacklist = strncasecmp (params->types, "no", 2) == 0;
+  if (blacklist)
+params->types += 2; /* Skip no. */
 
+ struct fs *fs;
  for (fs = fstab->entries; fs; fs = fs->next)
{
- const char *ptn;
- struct fstype *type;
-
- err = fs_type (fs, &type);
- if (err || nonexclude_types)
-   {
- err = fstypes_get (types, fs->mntent.mnt_type, &type);
- if (err)
-   error (106, err, "fstypes_get");
- if (params->types != 0)
-   continue;
-   }
- if (nonexclude_types && type->program == 0)
-   continue;   /* Freshly created, was not in WANTTYPES.  */
- if (type->program != 0 && type->program[0] == '\0')
-   continue;   /* This type is marked as excluded.  */
+  if (strcmp (fs->mntent.mnt_type, MNTTYPE_SWAP) == 0)
+continue; /* Ignore swap entries. */
+
+  const char *tn;
+  int matched = 0;
+  for (tn = params->types; tn;
+   tn = argz_n

[PATCH 6/6] umount: add a umount utility

2013-07-05 Thread Justus Winter
This adds a umount utility that implements most of the functions that
the Linux umount utility provides, especially that subset that is used
by the Debian package initscripts.

* utils/umount.c: New file.
---
 utils/Makefile |   10 +-
 utils/umount.c |  319 
 2 files changed, 325 insertions(+), 4 deletions(-)
 create mode 100644 utils/umount.c

diff --git a/utils/Makefile b/utils/Makefile
index 207c904..4fe2dc2 100644
--- a/utils/Makefile
+++ b/utils/Makefile
@@ -21,7 +21,9 @@ makemode := utilities
 targets = shd ps settrans showtrans syncfs fsysopts \
storeinfo login w uptime ids loginpr sush vmstat portinfo \
devprobe vminfo addauth rmauth unsu setauth ftpcp ftpdir storecat \
-   storeread msgport rpctrace mount gcore fakeauth fakeroot remap
+   storeread msgport rpctrace mount gcore fakeauth fakeroot remap \
+   umount
+
 special-targets = loginpr sush uptime fakeroot remap
 SRCS = shd.c ps.c settrans.c syncfs.c showtrans.c addauth.c rmauth.c \
fsysopts.c storeinfo.c login.c loginpr.sh sush.sh w.c \
@@ -29,7 +31,7 @@ SRCS = shd.c ps.c settrans.c syncfs.c showtrans.c addauth.c 
rmauth.c \
parse.c frobauth.c frobauth-mod.c setauth.c pids.c nonsugid.c \
unsu.c ftpcp.c ftpdir.c storeread.c storecat.c msgport.c \
rpctrace.c mount.c gcore.c fakeauth.c fakeroot.sh remap.sh \
-   match-options.c
+   match-options.c umount.c
 
 OBJS = $(filter-out %.sh,$(SRCS:.c=.o))
 HURDLIBS = ps ihash store fshelp ports ftpconn shouldbeinlibc
@@ -58,7 +60,7 @@ ftpcp ftpdir: ../libftpconn/libftpconn.a
 settrans: ../libfshelp/libfshelp.a ../libports/libports.a
 ps w ids settrans syncfs showtrans fsysopts storeinfo login vmstat portinfo \
   devprobe vminfo addauth rmauth setauth unsu ftpcp ftpdir storeread \
-  storecat msgport mount: \
+  storecat msgport mount umount: \
../libshouldbeinlibc/libshouldbeinlibc.a
 
 $(filter-out $(special-targets), $(targets)): %: %.o
@@ -74,7 +76,7 @@ fakeauth-CPPFLAGS = -I$(srcdir)/../auth
 authServer-CPPFLAGS = -I$(srcdir)/../auth
 auth_requestUser-CPPFLAGS = -I$(srcdir)/../auth
 
-mount: ../sutils/fstab.o ../sutils/clookup.o match-options.o \
+mount umount: ../sutils/fstab.o ../sutils/clookup.o match-options.o \
$(foreach L,fshelp ports,../lib$L/lib$L.a)
 ../sutils/fstab.o ../sutils/clookup.o: FORCE
$(MAKE) -C $(@D) $(@F)
diff --git a/utils/umount.c b/utils/umount.c
new file mode 100644
index 000..64e6ee2
--- /dev/null
+++ b/utils/umount.c
@@ -0,0 +1,319 @@
+/* Roughly Unix/Linux-compatible `umount' frontend for Hurd translators.
+
+   Copyright (C) 2013 Free Software Foundation, Inc.
+   Written by Justus Winter <4win...@informatik.uni-hamburg.de>
+
+   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 "../sutils/fstab.h"
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "match-options.h"
+
+/* XXX fix libc */
+#undef _PATH_MOUNTED
+#define _PATH_MOUNTED "/etc/mtab"
+
+static char *targets;
+static size_t targets_len;
+static int readonly;
+static int verbose;
+static int passive_flags = FS_TRANS_SET;
+static int active_flags = FS_TRANS_SET;
+static int goaway_flags;
+static int fake;
+
+static struct fstab_argp_params fstab_params;
+
+#define FAKE_KEY 0x80 /* !isascii (FAKE_KEY), so no short option. */
+
+static const struct argp_option argp_opts[] =
+{
+  {"fake", FAKE_KEY, 0, 0, "Do not actually umount, just pretend"},
+  {"force", 'f', 0, 0, "Force umount by killing the translator"},
+  {"no-mtab", 'n', 0, 0, "Do not update /etc/mtab"},
+  {"read-only", 'r', 0, 0, "If unmounting fails, try to remount read-only"},
+  {"nosync", 'S', 0, 0, "Don't sync a translator before killing it"},
+  {"test-opts", 'O', "OPTIONS", 0,
+   "Only mount fstab entries matching the given set of options"},
+  {"verbose", 'v', 0, 0, "Give more detailed information"},
+  {},
+};
+
+static error_t
+parse_opt (int key, char *arg, struct argp_state

[PATCH 2/6] mount: implement -O, --test-opts

2013-07-05 Thread Justus Winter
--test-opts in combination with --all mounts only those filesystems
with options matching the given set of options.

Note that the semantic of the inverting "no" prefix differs from
--types: While --types=nonfs,ufs means neither nfs nor ufs,
--test-opts=nofoo,bar means not foo, but bar.

* utils/match-options.h: New file.
* utils/match-options.c: Likewise.
(test_opts): New variable.
(test_opts_len): Likewise.
(match_options): New function.
* utils/mount.c (parse_opt): Handle -O, --test-opts.
(main): Use match_options as filter.
---
 utils/Makefile|5 ++--
 utils/match-options.c |   68 +
 utils/match-options.h |   33 
 utils/mount.c |   19 --
 4 files changed, 121 insertions(+), 4 deletions(-)
 create mode 100644 utils/match-options.c
 create mode 100644 utils/match-options.h

diff --git a/utils/Makefile b/utils/Makefile
index e3bed0b..6975fb5 100644
--- a/utils/Makefile
+++ b/utils/Makefile
@@ -28,7 +28,8 @@ SRCS = shd.c ps.c settrans.c syncfs.c showtrans.c addauth.c 
rmauth.c \
uptime.sh psout.c ids.c vmstat.c portinfo.c devprobe.c vminfo.c \
parse.c frobauth.c frobauth-mod.c setauth.c pids.c nonsugid.c \
unsu.c ftpcp.c ftpdir.c storeread.c storecat.c msgport.c \
-   rpctrace.c mount.c gcore.c fakeauth.c fakeroot.sh remap.sh
+   rpctrace.c mount.c gcore.c fakeauth.c fakeroot.sh remap.sh \
+   match-options.c
 
 OBJS = $(filter-out %.sh,$(SRCS:.c=.o))
 HURDLIBS = ps ihash store fshelp ports ftpconn shouldbeinlibc
@@ -72,7 +73,7 @@ fakeauth-CPPFLAGS = -I$(srcdir)/../auth
 authServer-CPPFLAGS = -I$(srcdir)/../auth
 auth_requestUser-CPPFLAGS = -I$(srcdir)/../auth
 
-mount: ../sutils/fstab.o ../sutils/clookup.o \
+mount: ../sutils/fstab.o ../sutils/clookup.o match-options.o \
$(foreach L,fshelp ports,../lib$L/lib$L.a)
 ../sutils/fstab.o ../sutils/clookup.o: FORCE
$(MAKE) -C $(@D) $(@F)
diff --git a/utils/match-options.c b/utils/match-options.c
new file mode 100644
index 000..11fc9dc
--- /dev/null
+++ b/utils/match-options.c
@@ -0,0 +1,68 @@
+/* Common functionality for the --test-opts flag of mount and umount.
+
+   Copyright (C) 2013 Free Software Foundation, Inc.
+   Written by Justus Winter <4win...@informatik.uni-hamburg.de>
+
+   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 
+#include 
+#include 
+#include 
+
+#include "match-options.h"
+
+char *test_opts;
+size_t test_opts_len;
+
+int
+match_options (struct mntent *mntent)
+{
+  char *opts;
+  size_t opts_len;
+
+  error_t err = argz_create_sep (mntent->mnt_opts, ',', &opts, &opts_len);
+  if (err)
+error (3, err, "parsing mount options failed");
+
+  for (char *test = test_opts;
+   test; test = argz_next (test_opts, test_opts_len, test))
+{
+  char *needle = test;
+  int inverse = strncmp("no", needle, 2) == 0;
+  if (inverse)
+needle += 2;
+
+  int match = 0;
+  for (char *opt = opts; opt; opt = argz_next (opts, opts_len, opt))
+{
+  if (strcmp (opt, needle) == 0) {
+if (inverse)
+  return 0; /* foo in opts, nofoo in test_opts. */
+
+/* foo in opts, foo in test_opts, record match. */
+match = 1;
+  }
+}
+
+  if (! inverse && ! match)
+return 0; /* No foo in opts, but foo in test_opts. */
+}
+
+  /* If no conflicting test_opt was encountered, return success. */
+  return 1;
+}
diff --git a/utils/match-options.h b/utils/match-options.h
new file mode 100644
index 000..ea7ae70
--- /dev/null
+++ b/utils/match-options.h
@@ -0,0 +1,33 @@
+/* Common functionality for the --test-opts flag of mount and umount.
+
+   Copyright (C) 2013 Free Software Foundation, Inc.
+   Written by Justus Winter <4win...@informatik.uni-hamburg.de>
+
+   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 WA

[PATCH] procfs: Ignore arguments for compatibility with Linux' procfs.

2013-07-08 Thread Justus Winter
Ignore the --nodev, --noexec and --nosuid arguments.

* procfs/main.c (argp_parser): Ignore some arguments for compatibility.
---
 procfs/main.c |   22 ++
 1 file changed, 22 insertions(+)

diff --git a/procfs/main.c b/procfs/main.c
index bcf9590..727fea6 100644
--- a/procfs/main.c
+++ b/procfs/main.c
@@ -45,6 +45,10 @@ uid_t opt_anon_owner;
 #define OPT_KERNEL_PID 2
 #define OPT_ANON_OWNER 0
 
+#define NODEV_KEY  0x80 /* !isascii (NODEV_KEY), so no short option. */
+#define NOEXEC_KEY 0x81 /* Likewise. */
+#define NOSUID_KEY 0x82 /* Likewise. */
+
 static error_t
 argp_parser (int key, char *arg, struct argp_state *state)
 {
@@ -112,6 +116,18 @@ argp_parser (int key, char *arg, struct argp_state *state)
   else
opt_anon_owner = v;
   break;
+
+case NODEV_KEY:
+  /* Ignored for compatibility with Linux' procfs. */
+  ;;
+
+case NOEXEC_KEY:
+  /* Ignored for compatibility with Linux' procfs. */
+  ;;
+
+case NOSUID_KEY:
+  /* Ignored for compatibility with Linux' procfs. */
+  ;;
   }
 
   return 0;
@@ -143,6 +159,12 @@ struct argp_option common_options[] = {
   "Be aware that USER will be granted access to the environment and "
   "other sensitive information about the processes in question.  "
   "(default: use uid 0)" },
+  { "nodev", NODEV_KEY, NULL, 0,
+  "Ignored for compatibility with Linux' procfs." },
+  { "noexec", NOEXEC_KEY, NULL, 0,
+  "Ignored for compatibility with Linux' procfs." },
+  { "nosuid", NOSUID_KEY, NULL, 0,
+  "Ignored for compatibility with Linux' procfs." },
   {}
 };
 
-- 
1.7.10.4




[PATCH] Include the umount utility in hurd and hurd-udeb.

2013-07-08 Thread Justus Winter
---
 debian/hurd-udeb.install.in |1 +
 debian/hurd.install.in  |1 +
 2 files changed, 2 insertions(+)

diff --git a/debian/hurd-udeb.install.in b/debian/hurd-udeb.install.in
index 4618f10..9b2601e 100644
--- a/debian/hurd-udeb.install.in
+++ b/debian/hurd-udeb.install.in
@@ -39,6 +39,7 @@ debian/tmp/bin/storecat
 debian/tmp/bin/storeread
 debian/tmp/bin/msgport
 debian/tmp/bin/mount
+debian/tmp/bin/umount
 debian/tmp/dev/MAKEDEV
 debian/tmp/hurd/auth
 debian/tmp/hurd/console
diff --git a/debian/hurd.install.in b/debian/hurd.install.in
index 41e39f5..eb16d79 100644
--- a/debian/hurd.install.in
+++ b/debian/hurd.install.in
@@ -51,6 +51,7 @@ debian/tmp/bin/storeread
 debian/tmp/bin/msgport
 debian/tmp/bin/rpctrace
 debian/tmp/bin/mount
+debian/tmp/bin/umount
 debian/tmp/bin/gcore
 debian/tmp/bin/fakeauth
 debian/tmp/usr/bin/fakeroot-hurd
-- 
1.7.10.4




[PATCH 2/8] initscripts: add -ocompatible to procfs mounts on Hurd

2013-07-09 Thread Justus Winter
---
 debian/changelog   |1 +
 debian/src/initscripts/lib/init/mount-functions.sh |3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/debian/changelog b/debian/changelog
index a1da0fb..1ff8750 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -52,6 +52,7 @@ sysvinit (2.88dsf-42) UNRELEASED; urgency=low
 
   [ Justus Winter ]
   * mount-functions.sh: Hurd has a tmpfs translator now, remove workaround.
+  * mount-functions.sh: Add -ocompatible to procfs mounts on Hurd.
 
  -- Roger Leigh   Sat, 04 May 2013 13:13:51 +0100
 
diff --git a/debian/src/initscripts/lib/init/mount-functions.sh 
b/debian/src/initscripts/lib/init/mount-functions.sh
index 5126780..8bb3031 100644
--- a/debian/src/initscripts/lib/init/mount-functions.sh
+++ b/debian/src/initscripts/lib/init/mount-functions.sh
@@ -176,7 +176,8 @@ domount () {
 
if [ "$PRIFSTYPE" = proc ]; then
case "$KERNEL" in
-   Linux|GNU) FSTYPE=proc ;;
+   Linux) FSTYPE=proc ;;
+   GNU)   FSTYPE=proc; FS_OPTS="-ocompatible" ;;
*FreeBSD)  FSTYPE=linprocfs ;;
*) FSTYPE=procfs ;;
esac
-- 
1.7.10.4




[PATCH 1/8] initscripts: hurd has a proper tmpfs now, remove workaround

2013-07-09 Thread Justus Winter
---
 debian/changelog   |3 +++
 debian/src/initscripts/lib/init/mount-functions.sh |1 -
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/debian/changelog b/debian/changelog
index 7c92f0f..a1da0fb 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -50,6 +50,9 @@ sysvinit (2.88dsf-42) UNRELEASED; urgency=low
   * Redirect error output from 'initctl version', suppressing warnings when
 upstart is installed but not running.  Closes: #685779.
 
+  [ Justus Winter ]
+  * mount-functions.sh: Hurd has a tmpfs translator now, remove workaround.
+
  -- Roger Leigh   Sat, 04 May 2013 13:13:51 +0100
 
 sysvinit (2.88dsf-41+jessie1) experimental; urgency=low
diff --git a/debian/src/initscripts/lib/init/mount-functions.sh 
b/debian/src/initscripts/lib/init/mount-functions.sh
index 9fd369b..5126780 100644
--- a/debian/src/initscripts/lib/init/mount-functions.sh
+++ b/debian/src/initscripts/lib/init/mount-functions.sh
@@ -190,7 +190,6 @@ domount () {
elif [ "$PRIFSTYPE" = tmpfs ]; then
# always accept tmpfs, to mount /run before /proc
case "$KERNEL" in
-   GNU)FSTYPE=none ;; # for now
*)  FSTYPE=$PRIFSTYPE ;;
esac
elif grep -E -qs "$PRIFSTYPE\$" /proc/filesystems; then
-- 
1.7.10.4




patches for sysvinit, debian repository for testing

2013-07-09 Thread Justus Winter
Hi,

this is a patch series for the sysvinit package. Comments are
welcome. Patches seven and eight are somewhat questionable, but I'd
propose the first six for inclusion. Any hints how to send patches to
the sysvinit maintainers? Attached to a bug report maybe?

I uploaded patched sysvinit packages to my debian repository for
testing. It's here:

deb http://teythoon.cryptobitch.de/gsoc/heap/debian unstable main

Please use unstable for now. For your convenience there's a seed
tarball containing appropriate sources.list.d snippets and the
repository key:

http://teythoon.cryptobitch.de/gsoc/heap/debian/seed.tar.xz

Currently /hurd/console is not started (I'll add a init script for
that later), but for now you have to start a getty on the console:

7:2345:respawn:/sbin/getty 38400 console

The patched initscripts contains the runsystem.sysv file and uses the
Debian alternatives system to replace the .gnu variant. It also
switches to the appropriate halt and reboot utilities. If you install
the package, you must use halt-hurd or reboot-hurd to halt or reboot
the system. Running halt or reboot is not harmful though, it just
doesn't work.

Cheers,
Justus




[PATCH 3/8] initscripts: use pidof -s /sbin/init for robustness

2013-07-09 Thread Justus Winter
pidof -s returns the first matching process. Since readdir(2) on
procfs returns the processes in ascending order, this returns the
first process. This is more robust if there is more than one
/sbin/init process.

Currently on Hurd there are two /sbin/init processes. Clearly this
needs some investigation. But as far as I can tell this could also
happen if INITDEBUG is defined as /sbin/init then forks a child that
can be ptrace(2)d on a vanilla Linux kernel.
---
 debian/changelog  |1 +
 debian/src/initscripts/etc/init.d/mountall.sh |2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/debian/changelog b/debian/changelog
index 1ff8750..7d9aa05 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -53,6 +53,7 @@ sysvinit (2.88dsf-42) UNRELEASED; urgency=low
   [ Justus Winter ]
   * mount-functions.sh: Hurd has a tmpfs translator now, remove workaround.
   * mount-functions.sh: Add -ocompatible to procfs mounts on Hurd.
+  * mountall.sh: Use pidof -s /sbin/init for robustness.
 
  -- Roger Leigh   Sat, 04 May 2013 13:13:51 +0100
 
diff --git a/debian/src/initscripts/etc/init.d/mountall.sh 
b/debian/src/initscripts/etc/init.d/mountall.sh
index 5f913cd..392eeec 100755
--- a/debian/src/initscripts/etc/init.d/mountall.sh
+++ b/debian/src/initscripts/etc/init.d/mountall.sh
@@ -55,7 +55,7 @@ do_start() {
mknod -m 600 "$INITCTL" p
 
# Reopen control channel.
-   PID="$(pidof /sbin/init || echo 1)"
+   PID="$(pidof -s /sbin/init || echo 1)"
[ -n "$PID" ] && kill -s USR1 "$PID"
fi
 
-- 
1.7.10.4




[PATCH 7/8] sendsigs, killprocs: Disable on Hurd. killall5 kills essential processes.

2013-07-09 Thread Justus Winter
Temporary workaround until
http://lists.gnu.org/archive/html/bug-hurd/2006-02/msg00081.html is
addressed.
---
 debian/changelog|5 +
 debian/src/initscripts/etc/init.d/killprocs |5 +
 debian/src/initscripts/etc/init.d/sendsigs  |5 +
 3 files changed, 15 insertions(+)

diff --git a/debian/changelog b/debian/changelog
index 50944ca..108c41a 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -62,6 +62,11 @@ sysvinit (2.88dsf-42) UNRELEASED; urgency=low
 simply does not apply to the Hurd system.
   * killall5.c: Use sysconf(_SC_SYMLOOP_MAX) instead of MAXSYMLINKS.
 Fixes build on Hurd.
+  * sendsigs: Disable script on Hurd. killall5 kills essential processes.
+Temporary workaround until
+http://lists.gnu.org/archive/html/bug-hurd/2006-02/msg00081.html
+is addressed.
+  * killprocs: Likewise.
 
  -- Roger Leigh   Sat, 04 May 2013 13:13:51 +0100
 
diff --git a/debian/src/initscripts/etc/init.d/killprocs 
b/debian/src/initscripts/etc/init.d/killprocs
index 6cb5b91..7712e98 100755
--- a/debian/src/initscripts/etc/init.d/killprocs
+++ b/debian/src/initscripts/etc/init.d/killprocs
@@ -46,6 +46,11 @@ do_start () {
 
 case "$1" in
   start)
+   # Do not run killall5 on Hurd.
+   if [ "$(uname)" = GNU ]; then
+   exit 0
+   fi
+
do_start
;;
   restart|reload|force-reload)
diff --git a/debian/src/initscripts/etc/init.d/sendsigs 
b/debian/src/initscripts/etc/init.d/sendsigs
index 04bd03c..85047c6 100755
--- a/debian/src/initscripts/etc/init.d/sendsigs
+++ b/debian/src/initscripts/etc/init.d/sendsigs
@@ -115,6 +115,11 @@ case "$1" in
exit 3
;;
   stop)
+   # Do not run killall5 on Hurd.
+   if [ "$(uname)" = GNU ]; then
+   exit 0
+   fi
+
do_stop
;;
   *)
-- 
1.7.10.4




[PATCH 4/8] initscripts: add runsystem.sysv

2013-07-09 Thread Justus Winter
runsystem.sysv does some very early initialization of Hurd and execs
/sbin/init to start the system using sysvinit. Hurd uses the
alternatives system to choose which runsystem to use and traditionally
shipped a custom init solution. Add runsystem.sysv using
update-alternatives in initscripts.postinst. Since the choice of
runsystems also dictate which halt and reboot to use, add those
utilities as slaves to the runsystem alternative and display
instructions on how to reboot or halt the system if installing the
initscript package switches the runsystem.
---
 debian/changelog   |4 +
 debian/control |3 +-
 debian/initscripts.postinst|   25 ++
 debian/rules   |3 +
 debian/src/initscripts/etc/hurd/runsystem.sysv |  102 
 5 files changed, 136 insertions(+), 1 deletion(-)
 create mode 100644 debian/src/initscripts/etc/hurd/runsystem.sysv

diff --git a/debian/changelog b/debian/changelog
index 7d9aa05..743e77e 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -54,6 +54,10 @@ sysvinit (2.88dsf-42) UNRELEASED; urgency=low
   * mount-functions.sh: Hurd has a tmpfs translator now, remove workaround.
   * mount-functions.sh: Add -ocompatible to procfs mounts on Hurd.
   * mountall.sh: Use pidof -s /sbin/init for robustness.
+  * Add runsystem.sysv that starts a Hurd system using sysvinit.
+  * debian/control: Depend on a recent hurd package on hurd-any. The
+initscripts require some functionality that has been implemented
+only recently.
 
  -- Roger Leigh   Sat, 04 May 2013 13:13:51 +0100
 
diff --git a/debian/control b/debian/control
index f9b9700..19064ef 100644
--- a/debian/control
+++ b/debian/control
@@ -75,7 +75,8 @@ Depends:
  debianutils (>= 4),
  lsb-base (>= 3.2-14),
  sysvinit-utils (>= 2.86.ds1-64), sysv-rc | file-rc,
- coreutils (>= 5.93)
+ coreutils (>= 5.93),
+ hurd (>= 20130707-1) [hurd-any]
 Recommends: psmisc, e2fsprogs
 Conflicts:
  libdevmapper1.02.1 (<< 2:1.02.24-1),
diff --git a/debian/initscripts.postinst b/debian/initscripts.postinst
index 0e140cf..82d9abf 100755
--- a/debian/initscripts.postinst
+++ b/debian/initscripts.postinst
@@ -219,6 +219,31 @@ then
fi
 fi
 
+#
+# Install runsystem.sysv on Hurd.
+#
+if [ "$(uname -s)" = GNU ]
+then
+   get_runsystem() {
+   update-alternatives --query runsystem \
+   | sed -n -e '/^Value:/s|.*\.||p'
+   }
+
+   current="$(get_runsystem)"
+   update-alternatives --quiet \
+   --install /etc/hurd/runsystem runsystem \
+   /etc/hurd/runsystem.sysv 30 \
+   --slave /sbin/halt halt /sbin/halt-sysv \
+   --slave /sbin/reboot reboot /sbin/reboot-sysv
+   new="$(get_runsystem)"
+
+   if [ "$current" != "$new" ]; then
+   echo "Switching from runsystem.$current to runsystem.$new."
+   echo "You must use halt-$current or reboot-$current to halt or"
+   echo "reboot the system."
+   fi
+fi
+
 # Ensure we have a random seed on first boot.
 if [ "$PREV_VER" = "" ]; then
if which invoke-rc.d >/dev/null 2>&1
diff --git a/debian/rules b/debian/rules
index a28631f..1006921 100755
--- a/debian/rules
+++ b/debian/rules
@@ -127,6 +127,9 @@ ifeq ($(DEB_HOST_ARCH_OS), hurd)
mv $(sysvtmp)/sbin/halt $(sysvtmp)/sbin/halt-sysv
rm $(sysvtmp)/sbin/reboot
ln -s halt-sysv $(sysvtmp)/sbin/reboot-sysv
+   $(INSTALL) -d $(inittmp)/etc/hurd
+   $(INSTALL) debian/src/initscripts/etc/hurd/runsystem.sysv \
+   $(inittmp)/etc/hurd
 endif
 
 override_dh_installdeb-indep:
diff --git a/debian/src/initscripts/etc/hurd/runsystem.sysv 
b/debian/src/initscripts/etc/hurd/runsystem.sysv
new file mode 100644
index 000..b95c2d0
--- /dev/null
+++ b/debian/src/initscripts/etc/hurd/runsystem.sysv
@@ -0,0 +1,102 @@
+#!/bin/sh
+#
+# This program is run by /hurd/init at boot time after the essential
+# servers are up, and is responsible for running the "userland" parts of a
+# normal system.  This includes running the single-user shell as well as a
+# multi-user system.  This program is expected never to exit.
+#
+
+
+###
+### Where to find programs, etc.
+###
+
+PATH=/bin:/sbin:/usr/bin:/usr/sbin
+export PATH
+
+# If we lose badly, try to exec each of these in turn.
+fallback_shells='/bin/sh /bin/bash /bin/csh /bin/ash /bin/shd'
+
+# Shell used for normal single-user startup.
+SHELL=/bin/sh
+
+###
+
+
+# If we get a SIGLOST, attempt to reopen the console in case
+# our console ports were revoked.  This lets us print messages.
+reopen_console ()
+{
+  exec 1>/dev/console 2>&1 || exit 3
+}
+trap 'reopen_console' 32 # SIGLOST = server died on GNU
+
+
+# Call this when we are losing badly enough that we want to punt normal
+# startup entirely.  We exec a single-user shell, so we will not come back
+# here.  The only way to get to multi-user from that shell will be
+# ex

[PATCH 5/8] initscripts: Disable rootcheck on Hurd

2013-07-09 Thread Justus Winter
The concept of device ids simply does not apply to the Hurd
system. Note that fsck is still run, rootcheck refers to the check
whether the root device in /etc/fstab matches the actual device.
---
 debian/changelog   |2 ++
 debian/src/initscripts/etc/init.d/checkroot.sh |5 -
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/debian/changelog b/debian/changelog
index 743e77e..e77bd4e 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -58,6 +58,8 @@ sysvinit (2.88dsf-42) UNRELEASED; urgency=low
   * debian/control: Depend on a recent hurd package on hurd-any. The
 initscripts require some functionality that has been implemented
 only recently.
+  * checkroot.sh: Disable rootcheck on Hurd. The concept of device ids
+simply does not apply to the Hurd system.
 
  -- Roger Leigh   Sat, 04 May 2013 13:13:51 +0100
 
diff --git a/debian/src/initscripts/etc/init.d/checkroot.sh 
b/debian/src/initscripts/etc/init.d/checkroot.sh
index 3bf506b..97c7e85 100755
--- a/debian/src/initscripts/etc/init.d/checkroot.sh
+++ b/debian/src/initscripts/etc/init.d/checkroot.sh
@@ -84,7 +84,10 @@ do_start () {
# If not we try to use the /dev/root alias device, and if that
# fails we create a temporary node in /run.
#
-   if [ "$rootcheck" = yes ]
+   # Skip this on on Hurd. The concept of device ids simply does
+   # not apply to the Hurd system.
+   KERNEL="$(uname)"
+   if [ "$rootcheck" = yes ] && [ "$KERNEL" != GNU ]
then
ddev="$(mountpoint -qx $rootdev)"
rdev="$(mountpoint -d /)"
-- 
1.7.10.4




[PATCH 6/8] killall5.c: Use sysconf(_SC_SYMLOOP_MAX) instead of MAXSYMLINKS.

2013-07-09 Thread Justus Winter
Fixes build on Hurd.
---
 debian/changelog |2 ++
 src/killall5.c   |2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/debian/changelog b/debian/changelog
index e77bd4e..50944ca 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -60,6 +60,8 @@ sysvinit (2.88dsf-42) UNRELEASED; urgency=low
 only recently.
   * checkroot.sh: Disable rootcheck on Hurd. The concept of device ids
 simply does not apply to the Hurd system.
+  * killall5.c: Use sysconf(_SC_SYMLOOP_MAX) instead of MAXSYMLINKS.
+Fixes build on Hurd.
 
  -- Roger Leigh   Sat, 04 May 2013 13:13:51 +0100
 
diff --git a/src/killall5.c b/src/killall5.c
index 5937d98..02ac88f 100644
--- a/src/killall5.c
+++ b/src/killall5.c
@@ -373,7 +373,7 @@ int check4nfs(const char * path, char * real)
 {
char buf[PATH_MAX+1];
const char *curr;
-   int deep = MAXSYMLINKS;
+   int deep = sysconf(_SC_SYMLOOP_MAX);
 
if (!nlist) return 0;
 
-- 
1.7.10.4




[PATCH 8/8] sysvinit: Fix getty path in /etc/inittab on Hurd.

2013-07-09 Thread Justus Winter
This is essentially the same as
89f6476d8979174f395a1bf784486254464c349d but fixes the existing
/etc/inittab file in the postinstall script.
---
 debian/changelog |1 +
 debian/sysvinit.postinst |4 
 2 files changed, 5 insertions(+)

diff --git a/debian/changelog b/debian/changelog
index 108c41a..dfc4603 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -67,6 +67,7 @@ sysvinit (2.88dsf-42) UNRELEASED; urgency=low
 http://lists.gnu.org/archive/html/bug-hurd/2006-02/msg00081.html
 is addressed.
   * killprocs: Likewise.
+  * sysvinit.postinst: Fix getty path in /etc/inittab on Hurd.
 
  -- Roger Leigh   Sat, 04 May 2013 13:13:51 +0100
 
diff --git a/debian/sysvinit.postinst b/debian/sysvinit.postinst
index 1750412..061f53b 100755
--- a/debian/sysvinit.postinst
+++ b/debian/sysvinit.postinst
@@ -85,6 +85,10 @@ then
cp -p /usr/share/sysvinit/inittab /etc/inittab
 fi
 
+if [ "$(uname)" = GNU ]; then
+sed -i -e 's|/libexec/getty|/sbin/getty|' /etc/inittab
+fi
+
 restart=yes
 
 chroot=0
-- 
1.7.10.4




Re: [PATCH 8/8] sysvinit: Fix getty path in /etc/inittab on Hurd.

2013-07-09 Thread Justus Winter
Quoting Ivan Shmakov (2013-07-09 12:59:01)
> >>>>> Justus Winter <4win...@informatik.uni-hamburg.de> writes:
> 
>  > This is essentially the same as
>  > 89f6476d8979174f395a1bf784486254464c349d but fixes the existing
>  > /etc/inittab file in the postinstall script.
> 
> […]
> 
>  > +  * sysvinit.postinst: Fix getty path in /etc/inittab on Hurd.
> 
> Please note that the GNU Coding Standards recommend to use the
> “file name” term here instead:
> 
> --cut: https://www.gnu.org/prep/standards/standards.html --
> Please do not use the term “pathname” that is used in Unix
> documentation; use “file name” (two words) instead.  We use the term
> “path” only for search paths, which are lists of directory names.
> --cut: https://www.gnu.org/prep/standards/standards.html --
> 
> (The last component of a file name — that is, a file name
> without the leading directories — could then presumably be
> called “base name.”)
> 
> […]

Noted, thanks.

>  > +if [ "$(uname)" = GNU ]; then
>  > +sed -i -e 's|/libexec/getty|/sbin/getty|' /etc/inittab
> 
> I don’t seem to understand.  Shouldn’t it be the other way
> around?
> 
> But overall, I doubt that this change is necessary.  If the
> package is being upgraded, the chances are that this defect was
> already corrected by the user.  And for the new installations,
> wasn't this issue already fixed?

Yes, it is fixed for new installations. However, the inittab as
shipped with the package is only installed as /etc/inittab if this
file is non-existant. As the inittab file was formerly not used on
Hurd systems, it is likely that users that are upgrading are not aware
of this issue, and not fixing that renders the system somewhat
unusable. I'm aware that sed'ing around in the file is probably
inappropriate, maybe we should just display a message instead?

Justus


signature.asc
Description: signature


Re: [PATCH] procfs: Ignore arguments for compatibility with Linux' procfs.

2013-07-09 Thread Justus Winter
Quoting Pino Toscano (2013-07-09 10:52:56)
> Hi,
> 
> Alle martedì 9 luglio 2013, Justus Winter ha scritto:
> > Ignore the --nodev, --noexec and --nosuid arguments.
> 
> Why nodev? The only consumer of it seems to be sysvinit, which has been 
> patched to not pass nodev also on Hurd (in addition to kFreeBSD) when 
> mounting /proc.

Not as far as I can see. mountkernfs.sh contains:

domount "$MNTMODE" proc "" /proc proc "-onodev,noexec,nosuid"

Argument #6 is CALLER_OPTS and that is not modified, so this is also
used on kFreeBSD.

Justus


signature.asc
Description: signature


Re: Passive translators

2013-07-09 Thread Justus Winter
Hi Thomas :)

Quoting Thomas Schwinge (2013-07-09 15:40:18)
> Hi!
> 
> On Tue, 09 Jul 2013 15:00:00 +0200, Justus Winter 
> <4win...@informatik.uni-hamburg.de> wrote:
> > Quoting Pino Toscano (2013-07-09 10:52:56)
> > > Alle martedì 9 luglio 2013, Justus Winter ha scritto:
> > > > Ignore the --nodev, --noexec and --nosuid arguments.
> > > 
> > > Why nodev? The only consumer of it seems to be sysvinit, which has been 
> > > patched to not pass nodev also on Hurd (in addition to kFreeBSD) when 
> > > mounting /proc.
> > 
> > Not as far as I can see. mountkernfs.sh contains:
> > 
> > domount "$MNTMODE" proc "" /proc proc "-onodev,noexec,nosuid"
> > 
> > Argument #6 is CALLER_OPTS and that is not modified, so this is also
> > used on kFreeBSD.
> 
> I have a general question here.  We used to have such "mounts" being done
> by means of passive translator settings, on /proc, for example.  It now
> appears that you're re-working this to use the "active mount command" of
> standard Unix (so, setting an active translator on /proc at each system
> boot)?  Is the passive translator setting meant to go away then?
> 
> The same question came up in my mind already when I saw your /etc/fstab
> patches go by; currently we use /etc/fstab only for fsck purposes.
> 
> I'm not convinced one approach is better than the other.  The passive
> translator setting was a novel feature of the Hurd, given that it has no
> direct equivalent (letting the registry in /etc/fstab aside) in Unix, and
> Debian by default is such a Unix system, so Debian GNU/Hurd -- so far --
> was different from that.  On the other hand, a passive translator setting
> also is not quite what you'd get in a persistent system (which, I guess,
> may partly have influenced this Hurd design decision?),
> <http://en.wikipedia.org/wiki/Persistence_%28computer_science%29>.  As we
> know, passive translators do have their issues, too, for example as
> described in »3.5 Passive Translators and Naming« in
> <http://www.gnu.org/software/hurd/hurd/critique.html>, or
> <http://www.gnu.org/software/hurd/open_issues/translators_set_up_by_untrusted_users.html>
> also has some discussion about passive translators.
> 
> Is this enough to generally declare passive translators "obsolete"?

Well, I can only speak for myself, but I'm not declaring anything as
obsolete, I'm just making sure that the Debian way of configuring the
system also applies to Debian/Hurd. This includes honoring the fstab
and later on also interfaces(5). If anyone wants to use passive
translators instead, she can still do so.

That being said I do not like Hurds passive translator concept that
much. True persistence would be awesome though...

> Aside from the presumed elegancy aspect of the first approach, whether
> the "system default configuration" in /servers/ is done by means of
> passive translator settings on the respective nodes, or by active
> translators that are started at system boot based on information present
> in /etc/ configuration files, seems basically just like a detail question
> (at least when leaving the idea aside that passive translators are only
> activated on demand, and thus consume no resources by default).

It is elegant alright, but needs support from the filesystem, right?
I.e. no passive translators unless the filesystem translator has a
means of storing them. Also with respect to not using resources, that
is also true for translators that are unused and paged out, and any
process traversing the filesystem will start all passive translators,
like say updatedb.

> Is Debian GNU/Hurd going to replace all usage of passive translators with
> active ones, set at system boot, or a mixture of passive and active (by
> design), or a mixture of passive and active for the time being (because
> some things currently can't sensibly be implemented by using active
> translators only, such as the mishmash in /dev/ -- which eventually was
> meant to be replaced by a "super devfs translator", which likely will
> have issues on its own)?
> 
> 
> Grüße,
>  Thomas

Cheers,
Justus



[PATCH 01/17] libdiskfs: fix consistency check

2013-07-11 Thread Justus Winter
passive is not a zero terminated string but a char * combined with a
length. If passivelen == 0, passive may very well be not NULL, and
dereferencing that pointer might not be safe. At the very least the
consistency check is wrong. Fix that by checking passivelen instead of
passive.

* libdiskfs/file-set-trans.c (diskfs_S_file_set_translator): Fix sanity check.
---
 libdiskfs/file-set-trans.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libdiskfs/file-set-trans.c b/libdiskfs/file-set-trans.c
index 3798001..49303e7 100644
--- a/libdiskfs/file-set-trans.c
+++ b/libdiskfs/file-set-trans.c
@@ -43,7 +43,7 @@ diskfs_S_file_set_translator (struct protid *cred,
   if ((passive_flags & FS_TRANS_SET) && diskfs_check_readonly ())
 return EROFS;
 
-  if (passive && passive[passivelen - 1])
+  if (passivelen && passive[passivelen - 1])
 return EINVAL;
 
   np = cred->po->np;
-- 
1.7.10.4




get_translator_{children,source} (v2)

2013-07-11 Thread Justus Winter
Hi,

this is an updated and broken up version of my mtab prototype.

[PATCH 01/17] libdiskfs: fix consistency check
[PATCH 02/17] libnetfs: fix consistency check

These are bug fixes. Please have a look.

[PATCH 03/17] libdiskfs: track file name in struct peropen
[PATCH 04/17] libnetfs: track file name in struct peropen

Samuel wrote:
> Concerning storing the path, it's a bit sad to have to do that, and
> it'll become wrong if one moves the mount points.  Another way would
> be to make the client figure it out by itself from a port to the
> mount point, much like glibc/sysdeps/mach/hurd/getcwd.c. It'll be
> slower, but should be safer.

I agree that it's sad to do it like this, but I'm not convinced there
is another way currently. I looked at getcwd(3) but the situation
there is different, because getcwd(3) starts with a file_t referencing
a directory.

We discussed this in #hurd. Richard mentioned that moving mount points
might not be a problem. He tried this on Linux and it returns EBUSY
there. I tried this on the Hurd and moving a translator with a process
inside worked fine there. Richard said that it would probably be best
to also prevent this because (I quote from memory here, please correct
me if I'm wrong) there are two nodes stacked onto another and moving
them requires the greatest care.

POSIX says:
> The rename() and renameat() functions shall fail if:
> [...]
> [EBUSY]
> The directory named by old or new is currently in use by the
> system or another process, and the implementation considers this
> an error.

This needs further discussion.

[PATCH 05/17] libfshelp: add translator-list.c
[PATCH 06/17] libdiskfs: add fsys_get_children
[PATCH 07/17] libnetfs: add fsys_get_children
[PATCH 08/17] libtrivfs: add fsys_get_children
[PATCH 09/17] trans/symlink.c: add fsys_get_children
[PATCH 10/17] hurd: add fsys_get_children

Keep a list of translators (lib{fshelp,diskfs,netfs}), stub out the
functions (libtrivfs, symlink), add procedure.

[PATCH 11/17] libdiskfs: add fsys_get_source
[PATCH 12/17] libnetfs: add fsys_get_source
[PATCH 13/17] libtrivfs: add fsys_get_source
[PATCH 14/17] trans/symlink.c: add fsys_get_source
[PATCH 15/17] hurd: add fsys_get_source

Add server function (lib{disk,net,triv}fs) and make them
user-overridable, stub out the functions (symlink), add procedure.

[PATCH 16/17] XXX this looks wrong to me, please have a look

This looks wrong. And does not work for me, that's why the
fsys_get_children patches contain a call to
mach_port_request_notification.

[PATCH 17/17] add mtab prototype

This turned into an libtrivfs-based translator. It's still a bit
rough, but as far as I can see it leaks neither memory nor ports.

% settrans -cga tmp tmpfs/tmpfs --mode=1777 10M
% settrans -cga tmp/foo tmpfs/tmpfs --mode=1777 11M
% settrans -cga mtab trans/mtab tmp
% cat mtab
none tmp tmpfs/tmpfs writable,no-inherit-dir-group,no-sync,size=10M 0 0
none tmp/foo tmpfs/tmpfs writable,no-inherit-dir-group,no-sync,size=11M 0 0
% settrans -g tmp/foo
pthread_create: Resource temporarily unavailable
% cat mtab
none tmp ./tmpfs/tmpfs writable,no-inherit-dir-group,no-sync,size=10M 0 0

(What's up with pthread_create? Is that the dying translator?)

Cheers,
Justus



[PATCH 09/17] trans/symlink.c: add fsys_get_children

2013-07-11 Thread Justus Winter
---
 trans/symlink.c |8 
 1 file changed, 8 insertions(+)

diff --git a/trans/symlink.c b/trans/symlink.c
index 03b5100..5e9e09a 100644
--- a/trans/symlink.c
+++ b/trans/symlink.c
@@ -221,3 +221,11 @@ S_fsys_forward (mach_port_t server, mach_port_t requestor,
 {
   return EOPNOTSUPP;
 }
+
+error_t
+S_fsys_get_children (mach_port_t server,
+ char **children,
+ mach_msg_type_number_t *children_len)
+{
+  return EOPNOTSUPP;
+}
-- 
1.7.10.4




[PATCH 10/17] hurd: add fsys_get_children

2013-07-11 Thread Justus Winter
---
 hurd/fsys.defs |8 
 1 file changed, 8 insertions(+)

diff --git a/hurd/fsys.defs b/hurd/fsys.defs
index 979a6cf..4b649d9 100644
--- a/hurd/fsys.defs
+++ b/hurd/fsys.defs
@@ -127,3 +127,11 @@ routine fsys_get_options (
server: fsys_t;
RPT
out options: data_t, dealloc);
+
+/* Return any passive and active translators bound to nodes of the
+   receiving filesystem. children is a argz vector containing file
+   names relative to the root of the receiving translator.  */
+routine fsys_get_children (
+   server: fsys_t;
+   RPT
+out children: data_t);
-- 
1.7.10.4




[PATCH 02/17] libnetfs: fix consistency check

2013-07-11 Thread Justus Winter
passive is not a zero terminated string but a char * combined with a
length. If passivelen == 0, passive may very well be not NULL, and
dereferencing that pointer might not be safe. At the very least the
consistency check is wrong. Fix that by checking passivelen instead of
passive.

* libnetfs/file-set-trans.c (netfs_S_file_set_translator): Fix sanity check.
---
 libnetfs/file-set-translator.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libnetfs/file-set-translator.c b/libnetfs/file-set-translator.c
index 4c29d95..b107ccd 100644
--- a/libnetfs/file-set-translator.c
+++ b/libnetfs/file-set-translator.c
@@ -39,7 +39,7 @@ netfs_S_file_set_translator (struct protid *user,
   if (!(passive_flags & FS_TRANS_SET) && !(active_flags & FS_TRANS_SET))
 return 0;
 
-  if (passive && passive[passivelen - 1])
+  if (passivelen && passive[passivelen - 1])
 return EINVAL;
 
   np = user->po->np;
-- 
1.7.10.4




[PATCH 05/17] libfshelp: add translator-list.c

2013-07-11 Thread Justus Winter
---
 libfshelp/Makefile  |3 +-
 libfshelp/fshelp.h  |   18 ++
 libfshelp/translator-list.c |  143 +++
 3 files changed, 163 insertions(+), 1 deletion(-)
 create mode 100644 libfshelp/translator-list.c

diff --git a/libfshelp/Makefile b/libfshelp/Makefile
index 4de3837..6ba6a14 100644
--- a/libfshelp/Makefile
+++ b/libfshelp/Makefile
@@ -20,6 +20,7 @@ makemode := library
 
 libname = libfshelp
 SRCS = lock-acquire.c lock-init.c \
+   translator-list.c \
start-translator-long.c start-translator.c \
fetch-root.c transbox-init.c set-active.c fetch-control.c \
drop-transbox.c translated.c \
@@ -32,7 +33,7 @@ SRCS =lock-acquire.c lock-init.c \
touch.c
 installhdrs = fshelp.h
 
-HURDLIBS = shouldbeinlibc iohelp ports
+HURDLIBS = shouldbeinlibc iohelp ports ihash
 LDLIBS += -lpthread
 OBJS = $(subst .c,.o,$(SRCS))
 
diff --git a/libfshelp/fshelp.h b/libfshelp/fshelp.h
index cf39fbc..7da28ff 100644
--- a/libfshelp/fshelp.h
+++ b/libfshelp/fshelp.h
@@ -32,6 +32,24 @@
 #include 
 
 
+/* XXX */
+/* XXX */
+
+/* XXX  */
+error_t
+fshelp_set_translator (const char *name,
+   int passive_flags, int active_flags,
+   boolean_t passive, mach_port_t active);
+
+/* XXX  */
+error_t
+fshelp_remove_active_translator (mach_port_t active);
+
+/* XXX */
+error_t
+fshelp_get_translators (char **translators, size_t *translators_len);
+
+
 /* Passive translator linkage */
 /* These routines are self-contained and start passive translators,
returning the control port.  They do not require multi threading
diff --git a/libfshelp/translator-list.c b/libfshelp/translator-list.c
new file mode 100644
index 000..4489e30
--- /dev/null
+++ b/libfshelp/translator-list.c
@@ -0,0 +1,143 @@
+/*
+   Copyright (C) 2013 Free Software Foundation
+   Written by Justus Winter <4win...@informatik.uni-hamburg.de>
+
+   This file is part of the GNU Hurd.
+
+   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 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+struct translator
+{
+  char *name;
+  boolean_t passive;
+  mach_port_t active;
+};
+
+/* XXX */
+static struct hurd_ihash translator_ihash
+  = HURD_IHASH_INITIALIZER (HURD_IHASH_NO_LOCP);
+
+static pthread_mutex_t translator_ihash_lock = PTHREAD_MUTEX_INITIALIZER;
+
+/* XXX */
+static void
+translator_ihash_cleanup (void *element, void *arg)
+{
+  /* XXX deallocate port? */
+  free (element);
+}
+
+error_t
+fshelp_set_translator (const char *name,
+   int passive_flags, int active_flags,
+   boolean_t passive, mach_port_t active)
+{
+  error_t err = 0;
+  pthread_mutex_lock (&translator_ihash_lock);
+
+  if (! translator_ihash.cleanup)
+hurd_ihash_set_cleanup (&translator_ihash, translator_ihash_cleanup, NULL);
+
+  struct translator *t = NULL;
+  HURD_IHASH_ITERATE (&translator_ihash, value)
+{
+  t = value;
+  if (strcmp (name, t->name) == 0)
+goto update; /* Entry exists. */
+}
+
+  t = malloc (sizeof (struct translator));
+  if (! t)
+return ENOMEM;
+
+  t->passive = FALSE;
+  t->active = MACH_PORT_NULL;
+  t->name = strdup (name);
+  if (! t->name)
+{
+  err = errno;
+  free (t);
+  goto out;
+}
+
+  err = hurd_ihash_add (&translator_ihash, (hurd_ihash_key_t) t, t);
+  if (err)
+goto out;
+
+ update:
+  if (active_flags & FS_TRANS_SET)
+t->active = active;
+
+  if (passive_flags & FS_TRANS_SET)
+t->passive = passive;
+
+  if (! t->passive && ! t->active)
+hurd_ihash_remove (&translator_ihash, (hurd_ihash_key_t) t);
+
+ out:
+  pthread_mutex_unlock (&translator_ihash_lock);
+  return err;
+}
+
+error_t
+fshelp_remove_active_translator (mach_port_t active)
+{
+  error_t err = 0;
+  pthread_mutex_lock (&translator_ihash_lock);
+
+  struct translator *t = NULL;
+  HURD_IHASH_ITERATE (&translator_ihash, value)
+{
+  struct translator *v = value;
+  if (active == v->active)
+{
+  t = v;
+  break;
+}
+}
+
+  if (t)
+hurd_ihash_remove (&translator_ihash, (hurd_ihash_key_t) t);
+
+  pthread_mutex_unlock (&translator_i

[PATCH 14/17] trans/symlink.c: add fsys_get_source

2013-07-11 Thread Justus Winter
---
 trans/symlink.c |7 +++
 1 file changed, 7 insertions(+)

diff --git a/trans/symlink.c b/trans/symlink.c
index 5e9e09a..946c950 100644
--- a/trans/symlink.c
+++ b/trans/symlink.c
@@ -229,3 +229,10 @@ S_fsys_get_children (mach_port_t server,
 {
   return EOPNOTSUPP;
 }
+
+error_t
+S_fsys_get_source (mach_port_t server,
+   char *source)
+{
+  return EOPNOTSUPP;
+}
-- 
1.7.10.4




[PATCH 03/17] libdiskfs: track file name in struct peropen

2013-07-11 Thread Justus Winter
---
 libdiskfs/dir-lookup.c   |5 +
 libdiskfs/diskfs.h   |3 +++
 libdiskfs/fsys-getroot.c |3 ++-
 libdiskfs/peropen-make.c |8 
 libdiskfs/peropen-rele.c |1 +
 5 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/libdiskfs/dir-lookup.c b/libdiskfs/dir-lookup.c
index 923be03..4532d40 100644
--- a/libdiskfs/dir-lookup.c
+++ b/libdiskfs/dir-lookup.c
@@ -82,6 +82,11 @@ diskfs_S_dir_lookup (struct protid *dircred,
   goto gotit;
 }
 
+  free (dircred->po->path);
+  dircred->po->path = strdup (path); /* XXX is this the right place? */
+  if (! dircred->po->path)
+return ENOMEM;
+
   dnp = dircred->po->np;
 
   pthread_mutex_lock (&dnp->lock);
diff --git a/libdiskfs/diskfs.h b/libdiskfs/diskfs.h
index 0f9c1d3..2489517 100644
--- a/libdiskfs/diskfs.h
+++ b/libdiskfs/diskfs.h
@@ -69,6 +69,9 @@ struct peropen
   mach_port_t shadow_root_parent;
   /* If in a shadow tree, its root node in this translator.  */
   struct node *shadow_root;
+
+  /* Path relative to the root of the translator. */
+  char *path;
 };
 
 /* A unique one of these exists for each node currently in use (and
diff --git a/libdiskfs/fsys-getroot.c b/libdiskfs/fsys-getroot.c
index 2e11da4..39973a8 100644
--- a/libdiskfs/fsys-getroot.c
+++ b/libdiskfs/fsys-getroot.c
@@ -51,7 +51,8 @@ diskfs_S_fsys_getroot (fsys_t controlport,
   {
 root_parent: dotdot,
 shadow_root_parent: MACH_PORT_NULL,
-shadow_root: _diskfs_chroot_directory ? diskfs_root_node : NULL /* XXX */
+shadow_root: _diskfs_chroot_directory ? diskfs_root_node : NULL, /* XXX */
+path: NULL,
   };
 
   if (!pt)
diff --git a/libdiskfs/peropen-make.c b/libdiskfs/peropen-make.c
index d37516c..d0ac698 100644
--- a/libdiskfs/peropen-make.c
+++ b/libdiskfs/peropen-make.c
@@ -34,6 +34,7 @@ diskfs_make_peropen (struct node *np, int flags, struct 
peropen *context,
   po->refcnt = 0;
   po->openstat = flags;
   po->np = np;
+  po->path = NULL;
 
   if (context)
 {
@@ -50,6 +51,13 @@ diskfs_make_peropen (struct node *np, int flags, struct 
peropen *context,
   if (po->shadow_root_parent != MACH_PORT_NULL)
mach_port_mod_refs (mach_task_self (), po->shadow_root_parent, 
MACH_PORT_RIGHT_SEND, 1);
+
+  if (context->path)
+{
+  po->path = strdup (context->path);
+  if (! po->path)
+return ENOMEM;
+}
 }
   else
 {
diff --git a/libdiskfs/peropen-rele.c b/libdiskfs/peropen-rele.c
index 08276ec..d3f7492 100644
--- a/libdiskfs/peropen-rele.c
+++ b/libdiskfs/peropen-rele.c
@@ -45,5 +45,6 @@ diskfs_release_peropen (struct peropen *po)
 
   diskfs_nput (po->np);
 
+  free (po->path);
   free (po);
 }
-- 
1.7.10.4




[PATCH 11/17] libdiskfs: add fsys_get_source

2013-07-11 Thread Justus Winter
---
 libdiskfs/Makefile  |4 ++--
 libdiskfs/diskfs.h  |6 ++
 libdiskfs/fsys-get-source.c |   35 +++
 libdiskfs/get-source.c  |   29 +
 4 files changed, 72 insertions(+), 2 deletions(-)
 create mode 100644 libdiskfs/fsys-get-source.c
 create mode 100644 libdiskfs/get-source.c

diff --git a/libdiskfs/Makefile b/libdiskfs/Makefile
index 1a0edd0..03c2e2b 100644
--- a/libdiskfs/Makefile
+++ b/libdiskfs/Makefile
@@ -35,7 +35,7 @@ IOSRCS= io-async-icky.c io-async.c io-duplicate.c 
io-get-conch.c io-revoke.c \
io-select.c io-stat.c io-stubs.c io-write.c io-version.c io-sigio.c
 FSYSSRCS=fsys-getroot.c fsys-goaway.c fsys-startup.c fsys-getfile.c \
fsys-options.c fsys-syncfs.c fsys-forward.c \
-   fsys-get-children.c
+   fsys-get-children.c fsys-get-source.c
 IFSOCKSRCS=ifsock.c
 OTHERSRCS = conch-fetch.c conch-set.c dir-clear.c dir-init.c dir-renamed.c \
extern-inline.c \
@@ -52,7 +52,7 @@ OTHERSRCS = conch-fetch.c conch-set.c dir-clear.c dir-init.c 
dir-renamed.c \
remount.c console.c disk-pager.c \
name-cache.c direnter.c dirrewrite.c dirremove.c lookup.c dead-name.c \
validate-mode.c validate-group.c validate-author.c validate-flags.c \
-   validate-rdev.c validate-owner.c extra-version.c
+   validate-rdev.c validate-owner.c extra-version.c get-source.c
 SRCS = $(OTHERSRCS) $(FSSRCS) $(IOSRCS) $(FSYSSRCS) $(IFSOCKSRCS)
 installhdrs = diskfs.h diskfs-pager.h
 
diff --git a/libdiskfs/diskfs.h b/libdiskfs/diskfs.h
index 2489517..6466987 100644
--- a/libdiskfs/diskfs.h
+++ b/libdiskfs/diskfs.h
@@ -567,6 +567,12 @@ error_t (*diskfs_create_symlink_hook)(struct node *np, 
const char *target);
isn't set, then the normal method (reading from the file data) is
used.  If it returns any other error, it is returned to the user. */
 error_t (*diskfs_read_symlink_hook)(struct node *np, char *target);
+
+/* The user may define this function.  The function must set source to
+   the source device of the filesystem. The function may return an
+   EOPNOTSUPP to indicate that the concept of a source device is not
+   applicable. The default function always returns EOPNOTSUPP. */
+error_t diskfs_get_source (char *source);
 
 /* The library exports the following functions for general use */
 
diff --git a/libdiskfs/fsys-get-source.c b/libdiskfs/fsys-get-source.c
new file mode 100644
index 000..e7e0e78
--- /dev/null
+++ b/libdiskfs/fsys-get-source.c
@@ -0,0 +1,35 @@
+/* fsys_get_source
+
+   Copyright (C) 2013 Free Software Foundation, Inc.
+
+   Written by Justus Winter <4win...@informatik.uni-hamburg.de>
+
+   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.  */
+
+#include "priv.h"
+#include "fsys_S.h"
+
+/* Return information about the source of the receiving
+   filesystem.  */
+error_t
+diskfs_S_fsys_get_source (mach_port_t server,
+  mach_port_t reply,
+  mach_msg_type_name_t replyPoly,
+  char *source)
+{
+  return diskfs_get_source (source);
+}
diff --git a/libdiskfs/get-source.c b/libdiskfs/get-source.c
new file mode 100644
index 000..bad6ff1
--- /dev/null
+++ b/libdiskfs/get-source.c
@@ -0,0 +1,29 @@
+/* Default version of diskfs_get_source
+   Copyright (C) 2013 Free Software Foundation, Inc.
+
+   Written by Justus Winter <4win...@informatik.uni-hamburg.de>
+
+
+   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., 59 Temple Place - Suite 330, Boston, MA  02111, USA. */
+
+#include "priv.h"
+
+error_t
+diskfs_ge

[PATCH 04/17] libnetfs: track file name in struct peropen

2013-07-11 Thread Justus Winter
---
 libnetfs/dir-lookup.c  |5 +
 libnetfs/fsys-getroot.c|6 +-
 libnetfs/make-peropen.c|8 
 libnetfs/netfs.h   |2 ++
 libnetfs/release-peropen.c |1 +
 5 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/libnetfs/dir-lookup.c b/libnetfs/dir-lookup.c
index f1b6438..2ce8cda 100644
--- a/libnetfs/dir-lookup.c
+++ b/libnetfs/dir-lookup.c
@@ -74,6 +74,11 @@ netfs_S_dir_lookup (struct protid *diruser,
   goto gotit;
 }
 
+  free (diruser->po->path);
+  diruser->po->path = strdup (filename); /* XXX is this the right place? */
+  if (! diruser->po->path)
+return ENOMEM;
+
   dnp = diruser->po->np;
   pthread_mutex_lock (&dnp->lock);
 
diff --git a/libnetfs/fsys-getroot.c b/libnetfs/fsys-getroot.c
index a1dd5e5..0d80111 100644
--- a/libnetfs/fsys-getroot.c
+++ b/libnetfs/fsys-getroot.c
@@ -43,7 +43,11 @@ netfs_S_fsys_getroot (mach_port_t cntl,
   error_t err;
   struct protid *newpi;
   mode_t type;
-  struct peropen peropen_context = { root_parent: dotdot };
+  struct peropen peropen_context =
+{
+  root_parent: dotdot,
+  path: NULL,
+};
 
   if (!pt)
 return EOPNOTSUPP;
diff --git a/libnetfs/make-peropen.c b/libnetfs/make-peropen.c
index 92f58da..0d46ea3 100644
--- a/libnetfs/make-peropen.c
+++ b/libnetfs/make-peropen.c
@@ -31,6 +31,7 @@ netfs_make_peropen (struct node *np, int flags, struct 
peropen *context)
   po->refcnt = 0;
   po->openstat = flags;
   po->np = np;
+  po->path = NULL;
 
   if (context)
 {
@@ -47,6 +48,13 @@ netfs_make_peropen (struct node *np, int flags, struct 
peropen *context)
   if (po->shadow_root_parent != MACH_PORT_NULL)
mach_port_mod_refs (mach_task_self (), po->shadow_root_parent,
MACH_PORT_RIGHT_SEND, 1);
+
+  if (context->path)
+{
+  po->path = strdup (context->path);
+  if (! po->path)
+return ENOMEM;
+}
 }
 
   netfs_nref (np);
diff --git a/libnetfs/netfs.h b/libnetfs/netfs.h
index d1ebed0..2b9454a 100644
--- a/libnetfs/netfs.h
+++ b/libnetfs/netfs.h
@@ -63,6 +63,8 @@ struct peropen
   mach_port_t shadow_root_parent;
   /* If in a shadow tree, its root node in this translator.  */
   struct node *shadow_root;
+
+  char *path;
 };
 
 /* A unique one of these exists for each node currently in use. */
diff --git a/libnetfs/release-peropen.c b/libnetfs/release-peropen.c
index 3e65099..d4d3574 100644
--- a/libnetfs/release-peropen.c
+++ b/libnetfs/release-peropen.c
@@ -41,6 +41,7 @@ netfs_release_peropen (struct peropen *po)
 
   netfs_nput (po->np);
 
+  free (po->path);
   free (po);
 }
 }
-- 
1.7.10.4




[PATCH 12/17] libnetfs: add fsys_get_source

2013-07-11 Thread Justus Winter
---
 libnetfs/Makefile  |4 ++--
 libnetfs/fsys-get-source.c |   35 +++
 libnetfs/get-source.c  |   28 
 libnetfs/netfs.h   |6 ++
 4 files changed, 71 insertions(+), 2 deletions(-)
 create mode 100644 libnetfs/fsys-get-source.c
 create mode 100644 libnetfs/get-source.c

diff --git a/libnetfs/Makefile b/libnetfs/Makefile
index 4ac1350..d5301b6 100644
--- a/libnetfs/Makefile
+++ b/libnetfs/Makefile
@@ -34,7 +34,7 @@ FSSRCS= dir-link.c dir-lookup.c dir-mkdir.c dir-mkfile.c \
file-get-translator.c file-getcontrol.c file-getlinknode.c \
file-lock-stat.c file-lock.c file-set-size.c \
file-set-translator.c file-statfs.c file-sync.c file-syncfs.c \
-   file-utimes.c file-reparent.c fsstubs.c
+   file-utimes.c file-reparent.c fsstubs.c get-source.c
 
 IOSRCS=io-read.c io-readable.c io-seek.c io-write.c io-stat.c 
io-async.c \
io-set-all-openmodes.c io-get-openmodes.c io-set-some-openmodes.c \
@@ -44,7 +44,7 @@ IOSRCS=   io-read.c io-readable.c io-seek.c io-write.c 
io-stat.c io-async.c \
io-version.c
 
 FSYSSRCS= fsys-syncfs.c fsys-getroot.c fsys-get-options.c fsys-set-options.c \
-   fsys-goaway.c fsysstubs.c fsys-get-children.c
+   fsys-goaway.c fsysstubs.c fsys-get-children.c fsys-get-source.c
 
 IFSOCKSRCS=
 OTHERSRCS= drop-node.c init-init.c make-node.c make-peropen.c make-protid.c   \
diff --git a/libnetfs/fsys-get-source.c b/libnetfs/fsys-get-source.c
new file mode 100644
index 000..37bd0cc
--- /dev/null
+++ b/libnetfs/fsys-get-source.c
@@ -0,0 +1,35 @@
+/* fsys_get_source
+
+   Copyright (C) 2013 Free Software Foundation, Inc.
+
+   Written by Justus Winter <4win...@informatik.uni-hamburg.de>
+
+   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.  */
+
+#include "priv.h"
+#include "fsys_S.h"
+
+/* Return information about the source of the receiving
+   filesystem.  */
+error_t
+netfs_S_fsys_get_source (mach_port_t server,
+  mach_port_t reply,
+  mach_msg_type_name_t replyPoly,
+  char *source)
+{
+  return netfs_get_source (source);
+}
diff --git a/libnetfs/get-source.c b/libnetfs/get-source.c
new file mode 100644
index 000..68d5c89
--- /dev/null
+++ b/libnetfs/get-source.c
@@ -0,0 +1,28 @@
+/* Default version of netfs_get_source
+   Copyright (C) 2013 Free Software Foundation, Inc.
+
+   Written by Justus Winter <4win...@informatik.uni-hamburg.de>
+
+   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., 59 Temple Place - Suite 330, Boston, MA  02111, USA. */
+
+#include "priv.h"
+
+error_t
+netfs_get_source (char *source)
+{
+  return EOPNOTSUPP;
+}
diff --git a/libnetfs/netfs.h b/libnetfs/netfs.h
index 2b9454a..7cd57ed 100644
--- a/libnetfs/netfs.h
+++ b/libnetfs/netfs.h
@@ -313,6 +313,12 @@ error_t netfs_file_get_storage_info (struct iouser *cred,
 mach_msg_type_number_t *num_offsets,
 char **data,
 mach_msg_type_number_t *data_len);
+
+/* The user may define this function.  The function must set source to
+   the source device of the filesystem. The function may return an
+   EOPNOTSUPP to indicate that the concept of a source device is not
+   applicable. The default function always returns EOPNOTSUPP. */
+error_t netfs_get_source (char *source);
 
 /* Option parsing */
 
-- 
1.7.10.4




[PATCH 08/17] libtrivfs: add fsys_get_children

2013-07-11 Thread Justus Winter
---
 libtrivfs/Makefile|3 ++-
 libtrivfs/fsys-get-children.c |   36 
 2 files changed, 38 insertions(+), 1 deletion(-)
 create mode 100644 libtrivfs/fsys-get-children.c

diff --git a/libtrivfs/Makefile b/libtrivfs/Makefile
index 1c6fd5e..3163777 100644
--- a/libtrivfs/Makefile
+++ b/libtrivfs/Makefile
@@ -34,7 +34,8 @@ IOSRCS=io-async-icky.c io-async.c io-duplicate.c io-map.c 
io-modes-get.c \
io-stat.c io-stubs.c io-write.c io-version.c io-identity.c
 
 FSYSSRCS=fsys-getroot.c fsys-goaway.c fsys-stubs.c fsys-syncfs.c \
-   fsys-forward.c fsys-set-options.c fsys-get-options.c
+   fsys-forward.c fsys-set-options.c fsys-get-options.c \
+   fsys-get-children.c
 
 OTHERSRCS=demuxer.c protid-clean.c protid-dup.c cntl-create.c \
cntl-clean.c migsupport.c times.c startup.c open.c \
diff --git a/libtrivfs/fsys-get-children.c b/libtrivfs/fsys-get-children.c
new file mode 100644
index 000..aa9135f
--- /dev/null
+++ b/libtrivfs/fsys-get-children.c
@@ -0,0 +1,36 @@
+/* fsys_get_children
+
+   Copyright (C) 2013 Free Software Foundation, Inc.
+
+   Written by Justus Winter <4win...@informatik.uni-hamburg.de>
+
+   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.  */
+
+#include "priv.h"
+
+/* Return any passive and active translators bound to nodes of the
+   receiving filesystem. children is a argz vector containing file
+   names relative to the root of the receiving translator.  */
+error_t
+trivfs_S_fsys_get_children (trivfs_control_t server,
+mach_port_t reply,
+mach_msg_type_name_t replyPoly,
+char **children,
+mach_msg_type_number_t *children_len)
+{
+  return EOPNOTSUPP;
+}
-- 
1.7.10.4




[PATCH 06/17] libdiskfs: add fsys_get_children

2013-07-11 Thread Justus Winter
---
 libdiskfs/Makefile|3 ++-
 libdiskfs/dead-name.c |4 +++-
 libdiskfs/file-set-trans.c|   19 +++
 libdiskfs/fsys-get-children.c |   51 +
 4 files changed, 75 insertions(+), 2 deletions(-)
 create mode 100644 libdiskfs/fsys-get-children.c

diff --git a/libdiskfs/Makefile b/libdiskfs/Makefile
index 3c8de4c..1a0edd0 100644
--- a/libdiskfs/Makefile
+++ b/libdiskfs/Makefile
@@ -34,7 +34,8 @@ IOSRCS= io-async-icky.c io-async.c io-duplicate.c 
io-get-conch.c io-revoke.c \
io-reauthenticate.c io-rel-conch.c io-restrict-auth.c io-seek.c \
io-select.c io-stat.c io-stubs.c io-write.c io-version.c io-sigio.c
 FSYSSRCS=fsys-getroot.c fsys-goaway.c fsys-startup.c fsys-getfile.c \
-   fsys-options.c fsys-syncfs.c fsys-forward.c
+   fsys-options.c fsys-syncfs.c fsys-forward.c \
+   fsys-get-children.c
 IFSOCKSRCS=ifsock.c
 OTHERSRCS = conch-fetch.c conch-set.c dir-clear.c dir-init.c dir-renamed.c \
extern-inline.c \
diff --git a/libdiskfs/dead-name.c b/libdiskfs/dead-name.c
index 760b36f..6ca208e 100644
--- a/libdiskfs/dead-name.c
+++ b/libdiskfs/dead-name.c
@@ -40,6 +40,8 @@ ports_dead_name (void *notify, mach_port_t dead_name)
   else
pthread_mutex_unlock (&np->lock);
 }
-  
+
+  fshelp_remove_active_translator (dead_name);
+
   ports_interrupt_notified_rpcs (notify, dead_name, MACH_NOTIFY_DEAD_NAME);
 }
diff --git a/libdiskfs/file-set-trans.c b/libdiskfs/file-set-trans.c
index 49303e7..5366880 100644
--- a/libdiskfs/file-set-trans.c
+++ b/libdiskfs/file-set-trans.c
@@ -18,6 +18,7 @@
 #include "priv.h"
 #include "fs_S.h"
 #include 
+#include 
 #include 
 
 /* Implement file_set_translator as described in . */
@@ -206,5 +207,23 @@ diskfs_S_file_set_translator (struct protid *cred,
 }
 
   pthread_mutex_unlock (&np->lock);
+
+  if (! error && cred->po->path)
+{
+  error = fshelp_set_translator (cred->po->path,
+ passive_flags, active_flags,
+ !!passivelen, active);
+}
+
+  if (! error && active != MACH_PORT_NULL)
+{
+  mach_port_t old;
+  error = mach_port_request_notification (mach_task_self (), active,
+  MACH_NOTIFY_DEAD_NAME, 0,
+  cred->pi.port_right,
+  MACH_MSG_TYPE_MAKE_SEND_ONCE,
+  &old);
+}
+
   return error;
 }
diff --git a/libdiskfs/fsys-get-children.c b/libdiskfs/fsys-get-children.c
new file mode 100644
index 000..9d4c4b3
--- /dev/null
+++ b/libdiskfs/fsys-get-children.c
@@ -0,0 +1,51 @@
+/* fsys_get_children
+
+   Copyright (C) 2013 Free Software Foundation, Inc.
+
+   Written by Justus Winter <4win...@informatik.uni-hamburg.de>
+
+   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.  */
+
+#include "priv.h"
+#include "fsys_S.h"
+
+/* Return any passive and active translators bound to nodes of the
+   receiving filesystem. children is a argz vector containing file
+   names relative to the root of the receiving translator.  */
+error_t
+diskfs_S_fsys_get_children (mach_port_t server,
+mach_port_t reply,
+mach_msg_type_name_t replyPoly,
+char **children,
+mach_msg_type_number_t *children_len)
+{
+  error_t err;
+
+  char *c = NULL;
+  size_t c_len = 0;
+
+  err = fshelp_get_translators (&c, &c_len);
+  if (err)
+goto errout;
+
+  err = iohelp_return_malloced_buffer (c, c_len, children, children_len);
+  c = NULL; /* c was freed by iohelp_return_malloced_buffer. */
+
+ errout:
+  free (c);
+  return err;
+}
-- 
1.7.10.4




[PATCH 07/17] libnetfs: add fsys_get_children

2013-07-11 Thread Justus Winter
---
 libnetfs/Makefile  |2 +-
 libnetfs/file-set-translator.c |   19 ++
 libnetfs/fsys-get-children.c   |   53 
 3 files changed, 73 insertions(+), 1 deletion(-)
 create mode 100644 libnetfs/fsys-get-children.c

diff --git a/libnetfs/Makefile b/libnetfs/Makefile
index 24b5aca..4ac1350 100644
--- a/libnetfs/Makefile
+++ b/libnetfs/Makefile
@@ -44,7 +44,7 @@ IOSRCS=   io-read.c io-readable.c io-seek.c io-write.c 
io-stat.c io-async.c \
io-version.c
 
 FSYSSRCS= fsys-syncfs.c fsys-getroot.c fsys-get-options.c fsys-set-options.c \
-   fsys-goaway.c fsysstubs.c
+   fsys-goaway.c fsysstubs.c fsys-get-children.c
 
 IFSOCKSRCS=
 OTHERSRCS= drop-node.c init-init.c make-node.c make-peropen.c make-protid.c   \
diff --git a/libnetfs/file-set-translator.c b/libnetfs/file-set-translator.c
index b107ccd..887b4f5 100644
--- a/libnetfs/file-set-translator.c
+++ b/libnetfs/file-set-translator.c
@@ -20,6 +20,7 @@
 
 #include "netfs.h"
 #include 
+#include 
 #include 
 
 error_t
@@ -175,6 +176,24 @@ netfs_S_file_set_translator (struct protid *user,
}
 }
 
+  if (! err && user->po->path)
+{
+  err = fshelp_set_translator (user->po->path,
+   passive_flags, active_flags,
+   !!passivelen, active);
+}
+
+  if (! err && active != MACH_PORT_NULL)
+{
+  /* XXX noone acts on dead name notifications yet */
+  mach_port_t old;
+  err = mach_port_request_notification (mach_task_self (), active,
+MACH_NOTIFY_DEAD_NAME, 0,
+user->pi.port_right,
+MACH_MSG_TYPE_MAKE_SEND_ONCE,
+&old);
+}
+
  out:
   pthread_mutex_unlock (&np->lock);
   return err;
diff --git a/libnetfs/fsys-get-children.c b/libnetfs/fsys-get-children.c
new file mode 100644
index 000..d1c9143
--- /dev/null
+++ b/libnetfs/fsys-get-children.c
@@ -0,0 +1,53 @@
+/* fsys_get_children
+
+   Copyright (C) 2013 Free Software Foundation, Inc.
+
+   Written by Justus Winter <4win...@informatik.uni-hamburg.de>
+
+   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.  */
+
+#include "priv.h"
+
+/* Return any passive and active translators bound to nodes of the
+   receiving filesystem. children is a argz vector containing file
+   names relative to the root of the receiving translator.  */
+error_t
+netfs_S_fsys_get_children (mach_port_t server,
+mach_port_t reply,
+mach_msg_type_name_t replyPoly,
+char **children,
+mach_msg_type_number_t *children_len)
+{
+  error_t err;
+
+  char *c = NULL;
+  size_t c_len = 0;
+
+  err = fshelp_get_translators (&c, &c_len);
+  if (err)
+goto errout;
+
+  err = iohelp_return_malloced_buffer (c, c_len, children, children_len);
+  if (err)
+goto errout;
+
+  c = NULL; /* c was freed by iohelp_return_malloced_buffer. */
+
+ errout:
+  free (c);
+  return err;
+}
-- 
1.7.10.4




[PATCH 17/17] add mtab prototype

2013-07-11 Thread Justus Winter
---
 trans/Makefile |8 +-
 trans/mtab.c   |  541 
 2 files changed, 546 insertions(+), 3 deletions(-)
 create mode 100644 trans/mtab.c

diff --git a/trans/Makefile b/trans/Makefile
index b3210b6..6eb51d0 100644
--- a/trans/Makefile
+++ b/trans/Makefile
@@ -20,14 +20,15 @@ dir := trans
 makemode := servers
 
 targets = symlink firmlink ifsock magic null fifo new-fifo fwd crash \
- password hello hello-mt streamio fakeroot proxy-defpager remap
+ password hello hello-mt streamio fakeroot proxy-defpager remap \
+ mtab
 SRCS = ifsock.c symlink.c magic.c null.c fifo.c new-fifo.c fwd.c \
crash.c firmlink.c password.c hello.c hello-mt.c streamio.c \
-   fakeroot.c proxy-defpager.c remap.c
+   fakeroot.c proxy-defpager.c remap.c mtab.c
 OBJS = $(SRCS:.c=.o) fsysServer.o ifsockServer.o passwordServer.o \
crashServer.o crash_replyUser.o msgServer.o \
default_pagerServer.o default_pagerUser.o \
-   device_replyServer.o elfcore.o
+   device_replyServer.o elfcore.o fsysUser.o
 HURDLIBS = ports netfs trivfs iohelp fshelp pipe ihash shouldbeinlibc
 LDLIBS += -lpthread
 password-LDLIBS = $(LIBCRYPT)
@@ -51,6 +52,7 @@ magic: ../libiohelp/libiohelp.a
 hello: ../libtrivfs/libtrivfs.a ../libfshelp/libfshelp.a 
../libports/libports.a ../libihash/libihash.a
 fakeroot: ../libnetfs/libnetfs.a ../libfshelp/libfshelp.a 
../libiohelp/libiohelp.a ../libports/libports.a ../libihash/libihash.a
 remap: ../libtrivfs/libtrivfs.a ../libfshelp/libfshelp.a 
../libports/libports.a ../libihash/libihash.a
+mtab: ../libtrivfs/libtrivfs.a ../libfshelp/libfshelp.a ../libports/libports.a 
../libihash/libihash.a fsysUser.o
 $(targets): ../libshouldbeinlibc/libshouldbeinlibc.a
 
 $(targets): %: %.o
diff --git a/trans/mtab.c b/trans/mtab.c
new file mode 100644
index 000..f47d03d
--- /dev/null
+++ b/trans/mtab.c
@@ -0,0 +1,541 @@
+/* This is an mtab translator.
+
+   Copyright (C) 2013 Free Software Foundation, Inc.
+
+   Written by Justus Winter <4win...@informatik.uni-hamburg.de>
+
+   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 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "fsys_U.h"
+
+static char *path = NULL;
+static int insecure = 0;
+
+/* XXX */
+struct mtab
+{
+  char *contents;
+  size_t contents_len;
+  off_t offs;
+};
+
+const char *argp_program_version = STANDARD_HURD_VERSION (mtab);
+
+static const struct argp_option options[] =
+{
+  {"insecure", 'I', 0, 0, "Follow translators not started by root"},
+  {}
+};
+
+/* Parse a command line option.  */
+error_t parse_opt (int key, char *arg, struct argp_state *state)
+{
+  switch (key)
+{
+case 'I':
+  insecure = 1;
+  break;
+
+case ARGP_KEY_ARG:
+  path = arg;
+  break;
+
+case ARGP_KEY_NO_ARGS:
+  argp_usage (state);
+  return EINVAL;
+
+default:
+  return ARGP_ERR_UNKNOWN;
+}
+  return 0;
+}
+
+static struct argp argp =
+  {
+options,
+parse_opt,
+"TARGET",
+"A translator providing mtab compatible information about active "
+"and passive translators below TARGET.",
+  };
+
+/* 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;
+
+  if (insecure)
+{
+  err = argz_add (argz, argz_len, path);
+  if (err)
+return err;
+}
+
+  err = argz_add (argz, argz_len, path);
+  return err;
+}
+
+/* Setting this variable makes libtrivfs use our argp to
+   parse options passed in an fsys_set_options RPC.  */
+struct argp *trivfs_runtime_argp = &argp;
+
+error_t
+mtab_populate (struct mtab *mtab, const char *path, int insecure);
+
+error_t
+argz_add_device (char **options, size_t *options_len, const char *device);
+
+error_t
+map_device_to_path (const char *device, char **path);
+
+int
+main (int argc, char *argv[])
+{
+  error_t err;
+
+  err = argp_parse (&argp, argc, argv, ARGP_IN_ORDER, 0, 0);
+  if (err)
+error (1, err, "argument parsing");

  1   2   3   4   5   6   7   8   9   10   >