1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
/*
* mount_generic.c
*
* Module for Linux automountd to mount filesystems for which no special
* magic is required
*
*/
#include <stdio.h>
#include <malloc.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <syslog.h>
#include <string.h>
#include <sys/param.h>
#include <sys/types.h>
#include <sys/stat.h>
#define MODULE_MOUNT
#include "automount.h"
#define MODPREFIX "mount(generic): "
int mount_version = AUTOFS_MOUNT_VERSION; /* Required by protocol */
int mount_init(void **context)
{
return 0;
}
int mount_mount(char *root, char *name, int name_len, char *what,
char *fstype, char *options, void *context)
{
char *fullpath;
int err;
fullpath = alloca(strlen(root)+name_len+2);
if ( !fullpath ) {
syslog(LOG_ERR, MODPREFIX "alloca: %m");
return 1;
}
sprintf(fullpath, "%s/%s", root, name);
syslog(LOG_DEBUG, MODPREFIX "calling mkdir %s", fullpath);
if ( mkdir(fullpath, 0555) && errno != EEXIST ) {
syslog(LOG_NOTICE, MODPREFIX "mkdir %s failed: %m", name);
return 1;
}
if ( options ) {
syslog(LOG_DEBUG, MODPREFIX "calling mount -t %s -o %s %s %s",
fstype, options, what, fullpath);
err = spawnl(LOG_NOTICE, _PATH_MOUNT, _PATH_MOUNT, "-t", fstype,
"-o", options, what, fullpath, NULL);
} else {
syslog(LOG_DEBUG, MODPREFIX "calling mount -t %s %s %s",
fstype, what, fullpath);
err = spawnl(LOG_NOTICE, _PATH_MOUNT, _PATH_MOUNT, "-t", fstype,
what, fullpath, NULL);
}
if ( err ) {
rmdir(fullpath);
syslog(LOG_NOTICE, MODPREFIX "failed to mount %s (type %s) on %s",
what, fstype, fullpath);
return 1;
} else {
syslog(LOG_DEBUG, MODPREFIX "mounted %s type %s on %s",
what, fstype, fullpath);
return 0;
}
}
int mount_done(void *context)
{
return 0;
}
|