libpmount-0.0.16/0000755000000000000000000000000011715030551010473 5ustar libpmount-0.0.16/Makefile0000644000000000000000000000240711671052163012142 0ustar # # libpmount Makefile # CFLAGS = -Wall -g MK_CFLAGS = -D_REENTRANT -DUSE_LOOP LIBNAME = libpmount SOVERSION = 0.0 SONAME = $(LIBNAME).so.$(SOVERSION) STNAME = $(LIBNAME).a SRCS = $(addprefix src/,kerndep.c mtab.c pmount.c) SH_OBJS = $(SRCS:.c=.lo) ST_OBJS = $(SRCS:.c=.o) %.lo: %.c $(CC) $(CPPFLAGS) $(CFLAGS) $(MK_CFLAGS) -fPIC -c -o $@ $< %.o: %.c $(CC) $(CPPFLAGS) $(CFLAGS) $(MK_CFLAGS) -c -o $@ $< build: $(SONAME) $(STNAME) $(STNAME): $(ST_OBJS) $(AR) cru $@ $^ $(SONAME): $(SH_OBJS) $(CC) -shared \ $(LDFLAGS) \ -Wl,-z,defs \ -Wl,-soname -Wl,$(SONAME) \ -Wl,--version-script=libpmount.map \ -o $@ $^ check: build # check if we are root, and it's not fake if test `id -u` = 0 && test -z "$(FAKEROOTKEY)"; then \ $(MAKE) -C tests; \ else \ echo "Not running as root, skipping checks."; \ fi install: build mkdir -p $(DESTDIR)/usr/include mkdir -p $(DESTDIR)/usr/lib mkdir -p $(DESTDIR)/lib install -m644 src/pmount.h $(DESTDIR)/usr/include/ install -s -m755 $(SONAME) $(DESTDIR)/lib/ install -m755 $(STNAME) $(DESTDIR)/usr/lib/ ln -s /lib/$(LIBNAME).so.0 $(DESTDIR)/usr/lib/$(LIBNAME).so ln -s $(SONAME) $(DESTDIR)/lib/$(LIBNAME).so.0 clean: $(RM) $(ST_OBJS) $(RM) $(SH_OBJS) $(RM) $(SONAME) $(RM) $(STNAME) $(MAKE) -C tests $@ libpmount-0.0.16/README0000644000000000000000000000007511174207656011370 0ustar List of supported filesystems: ext2fs iso9660 procfs_linux libpmount-0.0.16/debian/0000755000000000000000000000000011715030551011715 5ustar libpmount-0.0.16/debian/libpmount-dev.install0000644000000000000000000000005511174207656016105 0ustar usr/include/* usr/lib/lib*.a usr/lib/lib*.so libpmount-0.0.16/debian/control0000644000000000000000000000254211572232457013335 0ustar Source: libpmount Priority: optional Section: libs Maintainer: Guillem Jover Vcs-Browser: http://git.hadrons.org/?p=libpmount.git Vcs-Git: git://git.hadrons.org/git/libpmount.git Build-Depends: dpkg-dev (>= 1.15.7), debhelper (>= 7) Standards-Version: 3.9.2 Package: libpmount-dev Section: libdevel Architecture: any Depends: libpmount0.0 (= ${binary:Version}), ${misc:Depends} Description: portable mount library - development files This library implements functions pmount() and pumount() as wrappers to the real mount/unmount unportable interfaces on each platform. . Its goal is to provide a consistent interface application programmers can rely on for mounting and umounting filesystems without having to address kernel-related portability problems. . This package contains the static object and header files of libpmount. Package: libpmount0.0 Architecture: any Depends: ${shlibs:Depends}, ${misc:Depends} Description: portable mount library - shared library This library implements functions pmount() and pumount() as wrappers to the real mount/unmount unportable interfaces on each platform. . Its goal is to provide a consistent interface application programmers can rely on for mounting and umounting filesystems without having to address kernel-related portability problems. . This package contains the libpmount shared object. libpmount-0.0.16/debian/libpmount0.0.install0000644000000000000000000000001611174207656015544 0ustar lib/lib*.so.* libpmount-0.0.16/debian/libpmount0.0.symbols0000644000000000000000000000010411571113635015556 0ustar libpmount.so.0.0 libpmount0.0 #MINVER# (symver)LIBPMOUNT_0.0 0.0.7 libpmount-0.0.16/debian/source/0000755000000000000000000000000011370033062013212 5ustar libpmount-0.0.16/debian/source/format0000644000000000000000000000001511370033062014421 0ustar 3.0 (native) libpmount-0.0.16/debian/compat0000644000000000000000000000000211174207656013126 0ustar 7 libpmount-0.0.16/debian/rules0000755000000000000000000000217211572232457013011 0ustar #!/usr/bin/make -f # Sample debian/rules that uses debhelper. # GNU copyright 1997 to 1999 by Joey Hess. # Uncomment this to turn on verbose mode. #export DH_VERBOSE=1 CPPFLAGS := $(shell dpkg-buildflags --get CPPFLAGS) CFLAGS := -Wall $(shell dpkg-buildflags --get CFLAGS) LDFLAGS := $(shell dpkg-buildflags --get LDFLAGS) build-indep: build-arch: dh_testdir $(MAKE) build \ CPPFLAGS="$(CPPFLAGS)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" build: build-indep build-arch clean: dh_testdir dh_testroot $(MAKE) clean dh_clean install-arch: build-arch dh_testdir dh_testroot dh_prep dh_installdirs $(MAKE) install DESTDIR="$(CURDIR)/debian/tmp" .PHONY: build-indep build-arch build install-arch clean binary-indep: # Nothing to do binary-arch: install-arch dh_testdir dh_testroot dh_installchangelogs -s dh_installdocs -s dh_installexamples -s dh_install -s dh_installman -s dh_link -s dh_strip -s dh_compress -s dh_fixperms -s dh_makeshlibs -s -V dh_installdeb -s dh_shlibdeps -s dh_gencontrol -s dh_md5sums -s dh_builddeb -s binary: binary-indep binary-arch .PHONY: binary-indep binary-arch binary libpmount-0.0.16/debian/changelog0000644000000000000000000001327311715030505013574 0ustar libpmount (0.0.16) unstable; urgency=low * Do not use MNT_NODEV which was removed on kFreeBSD 7.0. Closes: #659280 -- Guillem Jover Thu, 09 Feb 2012 21:49:07 +0100 libpmount (0.0.15) unstable; urgency=low * Use a format string on fprintf() instead of directly using a string variable to fix build with -Werror=format-security. Closes: #643432 * Always check asprintf() return code. -- Guillem Jover Wed, 28 Sep 2011 19:39:11 +0200 libpmount (0.0.14) unstable; urgency=low * Switch the symbols file to use symver tags instead of symbol patterns. * Now using Standards-Version 3.9.2 (no changes needed). * Use dpkg-buildflags to set CPPFLAGS, CFLAGS and LDFLAGS. * Rename build target to build-arch, add build-indep and build targets, the latter depending on build-indep and build-arch. Rename install to install-arch. -- Guillem Jover Fri, 03 Jun 2011 21:19:40 +0200 libpmount (0.0.13) unstable; urgency=low * Switch to source format “3.0 (native)”. * Now using Standards-Version 3.8.4 (no changes needed). * Add ${misc:Depends} to all Depends fields. * Remove duplicate from source Section field in libpmount0.0 binary stanza. * Add Vcs-Browser and Vcs-Git fields. -- Guillem Jover Tue, 04 May 2010 17:06:11 +0200 libpmount (0.0.12) unstable; urgency=low * Workaround debhelper compat v7 bug (#534565) in dh_install which makes files end up under /debian/tmp/ in the binary package, by not passing --sourcedir to dh_install. * Pass -s to arch dependent debhelper commands. * Now using Standards-Version 3.8.2 (no changes needed). * Remove dependencies from binary-indep target. * Remove redundant build dependency from binary-arch target. -- Guillem Jover Thu, 25 Jun 2009 14:03:34 +0200 libpmount (0.0.11) unstable; urgency=low * Switch to debhelper compatibility level 7. * Use dh_prep instead of “dh_clean -k”. * Now using Standards-Version 3.8.0 (no changes needed). * Cleanup debian/copyright: - Use UTF-8 copyright symbol. - Lower case «Maintained by». - Refer to LGPL 2.1 instead of LGPL 2. - Refer to LGPL-2.1 from common-licenses instead of just LGPL. - Mention “library” instead of “package” in license snippet. * Get the default shlibs file dependency by not giving any argument to dh_makeshlibs -V option. * Add a symbols file for libpmount0.0. -- Guillem Jover Sun, 22 Feb 2009 04:37:46 +0200 libpmount (0.0.10) unstable; urgency=low * Do not strip the shared library in Makefile. (Closes: #437397) * Now using Standards-Version 3.7.3 (no changes needed). -- Guillem Jover Mon, 19 May 2008 06:09:07 +0300 libpmount (0.0.9) unstable; urgency=low * Use dh_install instead of dh_movefiles. - Rename libpmount-dev.files to libmount-dev.install - Rename libpmount0.0.files to libpmount0.0.install. * Remove commented out dh_installdebconf, dh_installinit and dh_installinfo. * Do not ignore make errors from on clean target. * Use dpkg-parsechangelog instead of manually parsing the changelog to get the current upstream version. * Use binary:Version instead of deprecated Source-Version substvar. * Do not remove non-existent stamp files. * Remove useless libpmount0.0.shlibs file. -- Guillem Jover Tue, 07 Aug 2007 02:25:30 +0300 libpmount (0.0.8) unstable; urgency=low * Now using Standards-Version 3.7.2 (no changes needed). * Switched to debhelper compat level 5. * Update FSF's address. -- Guillem Jover Sun, 6 Aug 2006 03:44:52 +0300 libpmount (0.0.7) unstable; urgency=low * Reintroduce missing symbols. (Closes: #323338) * Fix testsuite generation and generalize them by moving away from shell script files to a proper Makefile and a C source file. (Closes: #323339) * Use loop devices on linux if trying to mount a file image. * Make static internal functions __findloop, __getloop and __clrloop. * Switched to versioned symbols. * Now using Standards-Version 3.6.2 (no changes needed). -- Guillem Jover Sun, 21 Aug 2005 09:37:41 +0300 libpmount (0.0.6) unstable; urgency=low * New Maintainer. * Rewrite package short description. * Clean debian/copyright. * Clean debian/rules. * Now using Standards-Version 3.6.1 (no changes needed). * Rewrite bashfile to Makefile. * Remove Build-Depends on Essential e2fsprogs package. -- Guillem Jover Sun, 5 Jun 2005 16:42:48 +0300 libpmount (0.0.5) unstable; urgency=low * rules: Disable testsuite. (Closes: #291269) -- Robert Millan Thu, 20 Jan 2005 00:23:52 +0100 libpmount (0.0.4) unstable; urgency=low * Disabled code (needs more debugging): - src/*: Handle options field in mtab. - src/*: When asked to mount real files, attempt to use loop devices. * Updated kFreeBSD support. -- Robert Millan Fri, 16 Jul 2004 12:00:47 +0200 libpmount (0.0.3) unstable; urgency=low * src/*: Implement mtab handling. * bashfile: Build with -Werror. * debian/rules: Generate $version automagicaly. -- Robert Millan Wed, 14 Jul 2004 18:51:01 +0200 libpmount (0.0.2) unstable; urgency=low * bashfile: Fix library building for compliance with Policy sections 8 and 10.2 (Closes: #257907) * bashfile: Implement target dependencies. * debian/control (Build-Depends): Nuked linux-gnu | kfreebsd-gnu. -- Robert Millan Tue, 6 Jul 2004 18:54:21 +0200 libpmount (0.0.1) unstable; urgency=low * Initial Release. (Closes: #255716) -- Robert Millan Mon, 21 Jun 2004 14:15:24 +0200 libpmount-0.0.16/debian/copyright0000644000000000000000000000213311572232457013661 0ustar This package was debianized by Robert Millan on Mon, 21 Jun 2004 14:15:24 +0200. Now maintained by Guillem Jover . Copyright Holder: Copyright © 2004 Robert Millan License: This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA On Debian systems, the complete text of the GNU Lesser General Public License can be found in '/usr/share/common-licenses/LGPL-2.1'. libpmount-0.0.16/libpmount.map0000644000000000000000000000010611174207656013213 0ustar LIBPMOUNT_0.0 { global: pmount; pumount; local: *; }; libpmount-0.0.16/src/0000755000000000000000000000000011715026662011272 5ustar libpmount-0.0.16/src/kerndep.c0000644000000000000000000000023011174207656013064 0ustar #if defined(__linux__) # include "linux.c" #elif defined(__FreeBSD_kernel__) || defined(__FreeBSD__) # include "kfreebsd.c" #else # error portme #endif libpmount-0.0.16/src/pmount.h0000644000000000000000000000237411572232457012775 0ustar /* * Copyright © 2004 Robert Millan * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * */ #ifndef PMOUNT_H #define PMOUNT_H /* custom error codes */ #define PMOUNT_UNKNOWNFS 1 #define PMOUNT_NOTME 2 /* mapping of mount flags */ #define PMOUNT_REMOUNT 1 #define PMOUNT_READONLY 2 #define PMOUNT_NOSUID 4 #define PMOUNT_NOEXEC 8 #define PMOUNT_NODEV 16 #define PMOUNT_SYNCHRONOUS 32 /* mapping of umount flags */ #define PUMOUNT_FORCE 1 int pmount(char *fstype, char *mntdir, int mntflags, void *data); int pumount(char *mntdir, int mntflags); #endif libpmount-0.0.16/src/main.h0000644000000000000000000000214011572232457012366 0ustar /* * Copyright © 2004 Robert Millan * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * */ #include "pmount.h" #define __PMOUNT_LOOPBACK 1 int __pmount(char *fstype, char *mntdir, int mntflags, void *data); int __pumount(char *mntdir, int mntflags, char *looped_file); int __mtab_add(char *line); int __mtab_del(char *mntdir); char *__mtab_getline(char *mntdir); char *__mtab_getword(char *line, int i); libpmount-0.0.16/src/mtab.c0000644000000000000000000001020111640655467012363 0ustar /* * Copyright © 2004 Robert Millan * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * */ #define _GNU_SOURCE 1 #include #include #include #include #include #include #include "main.h" #ifndef _PATH_MOUNTED # warning _PATH_MONTED is undefined. Using "/etc/mtab". # define _PATH_MOUNTED "/etc/mtab" #endif /* Add a line to mtab. Returns 0 on success. */ int __mtab_add(char *line) { FILE *mtab; mtab = fopen(_PATH_MOUNTED, "a"); if (mtab == NULL) { perror("fopen"); return PMOUNT_NOTME; } fprintf (mtab, "%s", line); if (fclose (mtab) != 0) { perror ("fclose"); return PMOUNT_NOTME; } return 0; } /* Parses mtab and deletes the line that refers to the mount dir 'mntdir'. We assume there can't be two lines with same 'mntdir' string. Returns 0 is successful. */ int __mtab_del (char *mntdir) { FILE *mtab_r, *mtab_w; char line[8192]; /* Yeah; I know this is lame, but it works. Patches welcome. */ char *ret; int rc; if (rename (_PATH_MOUNTED, _PATH_MOUNTED "~") == -1) if (errno != ENOENT) { perror ("rename"); return PMOUNT_NOTME; } mtab_r = fopen (_PATH_MOUNTED "~", "r"); if (mtab_r == NULL) { perror ("fopen"); return PMOUNT_NOTME; } mtab_w = fopen (_PATH_MOUNTED, "w"); if (mtab_w == NULL) { perror ("fopen"); return PMOUNT_NOTME; } rc = asprintf (&mntdir, " %s ", mntdir); if (rc < 0) { perror ("asprintf"); return PMOUNT_NOTME; } while (1) { ret = fgets (line, sizeof(line), mtab_r); if (ret == NULL) { if (errno == 0) break; perror ("fgets"); return PMOUNT_NOTME; } if (strstr (line, mntdir) == NULL) fprintf (mtab_w, "%s", ret); } free (mntdir); if (fclose (mtab_r) != 0) { perror ("fclose"); return PMOUNT_NOTME; } if (fclose (mtab_w) != 0) { perror ("fclose"); return PMOUNT_NOTME; } if (unlink (_PATH_MOUNTED "~") != 0) { perror ("unlink"); return PMOUNT_NOTME; } return 0; } /* Searches mtab for a line using 'mntdir'. If successful, returns the whole line. Otherwise, returns NULL. */ char * __mtab_getline (char *mntdir) { FILE *mtab; char line[8192]; /* Yeah; I know this is lame, but it works. Patches welcome. */ char *ret; mtab = fopen (_PATH_MOUNTED, "r"); if (mtab == NULL) { perror ("fopen"); return NULL; } if (asprintf (&mntdir, " %s ", mntdir) < 0) { perror ("asprintf"); return NULL; } while (1) { ret = fgets (line, sizeof(line), mtab); if (ret == NULL) { if (errno == 0) break; perror ("fgets"); return NULL; } if (strstr (line, mntdir) != NULL) break; } free (mntdir); if (fclose (mtab) != 0) { perror ("fclose"); return NULL; } return ret; } /* Returns word number 'i' in 'line'. In case of failure, returns NULL. */ char * __mtab_getword (char *line, int i) { char *tmp; for (; i > 0 ; i--) /* Find next space. */ line = (strchr (line, ' ') + 1); /* Trim everything after last space. */ tmp = strchr (line, ' '); line[tmp - line] = '\0'; /* Sanity check */ if (strlen (line) != (tmp - line)) return NULL; return line; } libpmount-0.0.16/src/kfreebsd.c0000644000000000000000000001334711715025341013224 0ustar /* * Copyright © 2004 Robert Millan * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * * * Copyright © 1992, 1993, 1994 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include #include #include #include #include #include #include #include #include #include #include #include "pmount.h" #include #include static int __iso_get_ssector(const char *dev) { struct ioc_toc_header h; struct ioc_read_toc_entry t; struct cd_toc_entry toc_buffer[100]; int fd, ntocentries, i; fd = open(dev, O_RDONLY); if (fd == -1) return -1; if (ioctl(fd, CDIOREADTOCHEADER, &h) == -1) { close(fd); return -1; } ntocentries = h.ending_track - h.starting_track + 1; if (ntocentries > 100) { /* unreasonable, only 100 allowed */ close (fd); return -1; } t.address_format = CD_LBA_FORMAT; t.starting_track = 0; t.data_len = ntocentries * sizeof (struct cd_toc_entry); t.data = toc_buffer; if (ioctl(fd, CDIOREADTOCENTRYS, (char *) &t) == -1) { close(fd); return -1; } close(fd); for (i = ntocentries - 1; i >= 0; i--) if ((toc_buffer[i].control & 4) != 0) /* found a data track */ break; if (i < 0) return -1; return ntohl(toc_buffer[i].addr.lba); } int __pmount(char *fstype, char *mntdir, int mntflags, void *data) { char *my_fstype = fstype; void *my_data = NULL; int my_mntflags = 0; struct iso_args args; if ((mntflags & PMOUNT_REMOUNT) != 0) my_mntflags |= MNT_UPDATE; if ((mntflags & PMOUNT_READONLY) != 0) my_mntflags |= MNT_RDONLY; if ((mntflags & PMOUNT_NOSUID) != 0) my_mntflags |= MNT_NOSUID; if ((mntflags & PMOUNT_NOEXEC) != 0) my_mntflags |= MNT_NOEXEC; if ((mntflags & PMOUNT_SYNCHRONOUS) != 0) my_mntflags |= MNT_SYNCHRONOUS; if (!strcmp(fstype, "ext2fs")) { my_data = data; } else if (!strcmp(fstype, "procfs_linux")) { my_fstype = "linprocfs"; my_data = data; } else if (!strcmp(fstype, "iso9660")) { my_fstype = "cd9660"; memset(&args, 0, sizeof args); args.ssector = -1; args.cs_disk = NULL; args.cs_local = NULL; /* * ISO 9660 file systems are not writeable. */ mntflags |= MNT_RDONLY; args.export.ex_flags = MNT_EXRDONLY; args.fspec = (char *) data; args.export.ex_root = -2; args.flags = 0; if (args.ssector == -1) { /* * The start of the session has not been specified on * the command line. If we can successfully read the * TOC of a CD-ROM, use the last data track we find. * Otherwise, just use 0, in order to mount the very * first session. This is compatible with the * historic behaviour of mount_cd9660(8). If the user * has specified -s above, we don't get here * and leave the user's will. */ args.ssector = __iso_get_ssector((char *)data); if (args.ssector == -1) { /* could not determine starting sector, using very first session */ args.ssector = 0; } } my_data = (void *)&args; } else if (!strcmp (fstype, "nfs")) { my_data = NULL; /* FIXME */ } else return PMOUNT_UNKNOWNFS; return syscall(SYS_mount, my_fstype, mntdir, mntflags, my_data); } int __pumount (char *mntdir, int mntflags) { int my_mntflags = 0; if ((mntflags & PUMOUNT_FORCE) != 0) my_mntflags |= MNT_FORCE; return syscall(SYS_unmount, mntdir, my_mntflags); } libpmount-0.0.16/src/linux.c0000644000000000000000000001447111640655467012614 0ustar /* * Copyright © 2004 Robert Millan * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * */ #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include "main.h" /* If 'file' is NULL, find a free device. Otherwise find a device that is already set for 'file'. In either case, on failure return NULL. */ static char * __findloop (char *file) { char *loop; int i, fd, ret; struct loop_info loopinfo; struct stat st; for (i = 0; i <= 15; i++) { int rc; if (i <= 7) rc = asprintf (&loop, "/dev/loop%d", i); else rc = asprintf (&loop, "/dev/loop/%d", i - 8); if (rc < 0) break; /* Make sure this is a loop device */ if (stat (loop, &st) != 0) break; if (S_ISBLK (st.st_mode) == 0) break; if (major (st.st_rdev) != 7) break; fd = open (loop, O_RDONLY); if (fd < 0) break; ret = ioctl (fd, LOOP_GET_STATUS, &loopinfo); close (fd); if (ret == 0) { #ifdef verbose fprintf (stderr, "__findloop: Device %s is in use\n", loop); #endif if (file != NULL) { if (!strcmp (file, loopinfo.lo_name)) { #ifdef verbose fprintf (stderr, "__findloop: We were looking for file %s" ", which seems to match device %s\n", file, loop); #endif return loop; } } } else if ((file == NULL) && (errno == ENXIO)) { #ifdef verbose fprintf (stderr, "__findloop: We were looking for a free device, " "and %s is.\n", loop); #endif return loop; } } free (loop); /* We failed. Let's return NULL. */ return NULL; } /* Finds a free loop device, and sets it for 'file'. If 'file' is already set as loop device, __setloop will re-use that device. Returns the loop device name is successful, NULL otherwise. */ static char * __getloop (char *file) { char *device; int fd_file, fd_device, ret; struct loop_info loopinfo; device = __findloop (file); if (device != NULL) return device; device = __findloop (NULL); if (device == NULL) return NULL; #ifdef verbose fprintf (stderr, "__getloop: Setting up %s in %s\n", file, device); #endif fd_file = open (file, O_RDONLY | O_WRONLY); fd_device = open (device, O_RDONLY); ret = ioctl (fd_device, LOOP_SET_FD, fd_file); close (fd_file); if (ret == -1) { close (fd_device); return NULL; } #ifdef verbose fprintf (stderr, "__getloop: LOOP_SET_FD succeeded (%d).\n", ret); #endif memset (&loopinfo, 0, sizeof (loopinfo)); if (strlen (file) <= LO_NAME_SIZE) strncpy (loopinfo.lo_name, file, LO_NAME_SIZE); else return NULL; /* Fuck it. Filename is too long! */ ret = ioctl (fd_device, LOOP_SET_STATUS, &loopinfo); close (fd_device); if (ret == -1) return NULL; #ifdef verbose fprintf (stderr, "__getloop: LOOP_SET_STATUS succeeded (%d).\n", ret); #endif return device; } /* Unsets the device found to be using 'file'. In case of failure, or if none found, return -1. */ static int __clrloop (char *file) { char *device; int fd, ret; device = __findloop (file); if (device == NULL) return -1; fd = open (device, O_RDONLY); free (device); ret = ioctl (fd, LOOP_CLR_FD, 0); close (fd); return ret; } int __pmount (char *fstype, char *mntdir, int mntflags, void *data) { char *my_fstype = fstype; void *my_data = NULL; int my_mntflags = 0; char *device = NULL; if ((mntflags & PMOUNT_REMOUNT) != 0) my_mntflags |= MS_REMOUNT; if ((mntflags & PMOUNT_READONLY) != 0) my_mntflags |= MS_RDONLY; if ((mntflags & PMOUNT_NOSUID) != 0) my_mntflags |= MS_NOSUID; if ((mntflags & PMOUNT_NOEXEC) != 0) my_mntflags |= MS_NOEXEC; if ((mntflags & PMOUNT_NODEV) != 0) my_mntflags |= MS_NODEV; if ((mntflags & PMOUNT_SYNCHRONOUS) != 0) my_mntflags |= MS_SYNCHRONOUS; if (!strcmp (fstype, "iso9660")) { device = (char *) data; } else if (!strcmp (fstype, "ext2fs")) { my_fstype = "ext2"; device = (char *) data; } else if (!strcmp (fstype, "procfs_linux")) { my_fstype = "proc"; device = (char *) data; } else if (!strcmp (fstype, "nfs")) { my_data = NULL; /* FIXME */ } else return PMOUNT_UNKNOWNFS; #ifdef verbose fprintf (stderr, "__pmount: Let's mount %s on %s.\n", device, mntdir); #endif if (mount (device, mntdir, my_fstype, my_mntflags, my_data) == -1) { #ifdef USE_LOOP if (errno == ENOTBLK) { device = __getloop (device); if (mount (device, mntdir, my_fstype, my_mntflags, my_data) == -1) return -1; else return __PMOUNT_LOOPBACK; } else #endif return -1; } errno = 0; return 0; } int __pumount (char *mntdir, int mntflags, char *looped_file) { int my_mntflags = 0; if ((mntflags & PUMOUNT_FORCE) != 0) my_mntflags |= MNT_FORCE; if (umount2 (mntdir, my_mntflags) == -1) return -1; #ifdef USE_LOOP if (looped_file != NULL) { #ifdef verbose fprintf (stderr, "__pumount: pumount told me the loop is %s\n", looped_file); #endif if (__clrloop (looped_file) == -1); return -1; } #ifdef verbose else { fprintf (stderr, "__pumount: pumount told me there's no such loop.\n"); } #endif #endif errno = 0; return 0; } libpmount-0.0.16/src/pmount.c0000644000000000000000000000605711640655467013000 0ustar /* * Copyright © 2004 Robert Millan * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * */ #define _GNU_SOURCE 1 #include #include #include #include #include #include #include "main.h" int pmount(char *fstype, char *mntdir, int mntflags, void *data) { #ifdef USE_MTAB char *options, *line; int rc; #endif int ret; ret = __pmount(fstype, mntdir, mntflags, data); if (ret == -1) return -1; #ifdef USE_MTAB /* We were able to mount, but maybe we are not root. On systems where non-root users can mount (e.g. GNU) we only keep track of filesystems mounted by root. */ if (geteuid() != 0) { errno = 0; return 0; } /* Generate an options substring */ if ((mntflags & PMOUNT_READONLY) == 0) options = strdup("rw"); else options = strdup("ro"); if ((mntflags & PMOUNT_NOSUID) == 0) rc = asprintf(&options, "%s,suid", options); else rc = asprintf(&options, "%s,nosuid", options); if (rc < 0) return -1; if (ret == __PMOUNT_LOOPBACK) rc = asprintf(&options, "%s,loop", options); if (rc < 0) return -1; /* For non-device filesystems we list "null" as device. FIXME: This check only addresses virtual filesystems like procfs_*, but network filesystems will initialise 'data' when implemented. */ if (data == NULL) data = (void *)"null"; rc = asprintf(&line, "%s %s %s %s %d %d\n", (char *)data, mntdir, fstype, options, 0, 0); if (rc < 0) return -1; free(options); ret = __mtab_add(line); free(line); if (ret == -1) return -1; #endif errno = 0; return 0; } int pumount(char *mntdir, int mntflags) { #ifdef USE_MTAB char *line, *file, *opts; line = __mtab_getline(mntdir); opts = __mtab_getword(line, 3); #ifdef verbose fprintf(stderr, "pumount: I'm going to umount \"%s\"\n", line); #endif if (strstr(opts, ",loop") == NULL) file = NULL; else file = __mtab_getword(line, 0); #ifdef verbose if (file == NULL) fprintf(stderr, "pumount: There was no loop device.\n"); else fprintf(stderr, "pumount: Seems like file %s was looped.\n", file); #endif #else #define file NULL #endif if (__pumount(mntdir, mntflags, file) != 0) return -1; #ifdef USE_MTAB if (geteuid() == 0) if (__mtab_del(mntdir) == -1) return -1; #endif errno = 0; return 0; } libpmount-0.0.16/tests/0000755000000000000000000000000011572232457011647 5ustar libpmount-0.0.16/tests/Makefile0000644000000000000000000000077311572232457013316 0ustar # # libpmount tests # export PATH := /sbin:/usr/sbin:$(PATH) MK_CFLAGS = -I../src -L.. -lpmount tests: ext2fs.img isofs.img ext2fs isofs: test.c $(CC) $< -o $@ $(CFLAGS) $(MK_CFLAGS) -DFSNAME="\"$@\"" ext2fs.img: ext2fs dd if=/dev/zero of=$<.img bs=1024k count=1 mke2fs -F $<.img mkdir -p $<.mnt ./$< isofs.img: isofs dd if=/dev/zero of=$<.dummy bs=1024k count=1 mkisofs -o $<.img -r $<.dummy mkdir -p $<.mnt ./$< clean: $(RM) ext2fs isofs $(RM) *.bin *.img *.dummy rmdir -p *.mnt || true libpmount-0.0.16/tests/test.c0000644000000000000000000000063011572232457012771 0ustar #include #include #define FSIMAGE FSNAME ".img" #define FSMOUNT FSNAME ".mnt" int main() { int error; error = pmount(FSNAME, FSMOUNT, PMOUNT_READONLY, FSIMAGE); if (error == -1) { perror("pmount failed"); return 1; } error = pumount(FSMOUNT, 0); if (error == -1) { perror("WARNING: pmount succeeded, but pumount failed"); return 1; } return 0; }