/* -*- linux-c -*- --------------------------------------------------------- *
|
/* -*- linux-c -*- --------------------------------------------------------- *
|
*
|
*
|
* linux/fs/autofs/root.c
|
* linux/fs/autofs/root.c
|
*
|
*
|
* Copyright 1997 Transmeta Corporation -- All Rights Reserved
|
* Copyright 1997 Transmeta Corporation -- All Rights Reserved
|
*
|
*
|
* This file is part of the Linux kernel and is made available under
|
* This file is part of the Linux kernel and is made available under
|
* the terms of the GNU General Public License, version 2, or at your
|
* the terms of the GNU General Public License, version 2, or at your
|
* option, any later version, incorporated herein by reference.
|
* option, any later version, incorporated herein by reference.
|
*
|
*
|
* ------------------------------------------------------------------------- */
|
* ------------------------------------------------------------------------- */
|
|
|
#include <linux/errno.h>
|
#include <linux/errno.h>
|
#include <linux/stat.h>
|
#include <linux/stat.h>
|
#include <linux/param.h>
|
#include <linux/param.h>
|
#include "autofs_i.h"
|
#include "autofs_i.h"
|
|
|
static int autofs_root_readdir(struct inode *,struct file *,void *,filldir_t);
|
static int autofs_root_readdir(struct inode *,struct file *,void *,filldir_t);
|
static int autofs_root_lookup(struct inode *,const char *,int,struct inode **);
|
static int autofs_root_lookup(struct inode *,const char *,int,struct inode **);
|
static int autofs_root_symlink(struct inode *,const char *,int,const char *);
|
static int autofs_root_symlink(struct inode *,const char *,int,const char *);
|
static int autofs_root_unlink(struct inode *,const char *,int);
|
static int autofs_root_unlink(struct inode *,const char *,int);
|
static int autofs_root_rmdir(struct inode *,const char *,int);
|
static int autofs_root_rmdir(struct inode *,const char *,int);
|
static int autofs_root_mkdir(struct inode *,const char *,int,int);
|
static int autofs_root_mkdir(struct inode *,const char *,int,int);
|
static int autofs_root_ioctl(struct inode *, struct file *,unsigned int,unsigned long);
|
static int autofs_root_ioctl(struct inode *, struct file *,unsigned int,unsigned long);
|
|
|
static struct file_operations autofs_root_operations = {
|
static struct file_operations autofs_root_operations = {
|
NULL, /* lseek */
|
NULL, /* lseek */
|
NULL, /* read */
|
NULL, /* read */
|
NULL, /* write */
|
NULL, /* write */
|
autofs_root_readdir, /* readdir */
|
autofs_root_readdir, /* readdir */
|
NULL, /* select */
|
NULL, /* select */
|
autofs_root_ioctl, /* ioctl */
|
autofs_root_ioctl, /* ioctl */
|
NULL, /* mmap */
|
NULL, /* mmap */
|
NULL, /* open */
|
NULL, /* open */
|
NULL, /* release */
|
NULL, /* release */
|
NULL /* fsync */
|
NULL /* fsync */
|
};
|
};
|
|
|
struct inode_operations autofs_root_inode_operations = {
|
struct inode_operations autofs_root_inode_operations = {
|
&autofs_root_operations, /* file operations */
|
&autofs_root_operations, /* file operations */
|
NULL, /* create */
|
NULL, /* create */
|
autofs_root_lookup, /* lookup */
|
autofs_root_lookup, /* lookup */
|
NULL, /* link */
|
NULL, /* link */
|
autofs_root_unlink, /* unlink */
|
autofs_root_unlink, /* unlink */
|
autofs_root_symlink, /* symlink */
|
autofs_root_symlink, /* symlink */
|
autofs_root_mkdir, /* mkdir */
|
autofs_root_mkdir, /* mkdir */
|
autofs_root_rmdir, /* rmdir */
|
autofs_root_rmdir, /* rmdir */
|
NULL, /* mknod */
|
NULL, /* mknod */
|
NULL, /* rename */
|
NULL, /* rename */
|
NULL, /* readlink */
|
NULL, /* readlink */
|
NULL, /* follow_link */
|
NULL, /* follow_link */
|
NULL, /* readpage */
|
NULL, /* readpage */
|
NULL, /* writepage */
|
NULL, /* writepage */
|
NULL, /* bmap */
|
NULL, /* bmap */
|
NULL, /* truncate */
|
NULL, /* truncate */
|
NULL /* permission */
|
NULL /* permission */
|
};
|
};
|
|
|
static int autofs_root_readdir(struct inode *inode, struct file *filp,
|
static int autofs_root_readdir(struct inode *inode, struct file *filp,
|
void *dirent, filldir_t filldir)
|
void *dirent, filldir_t filldir)
|
{
|
{
|
struct autofs_dir_ent *ent;
|
struct autofs_dir_ent *ent;
|
struct autofs_dirhash *dirhash;
|
struct autofs_dirhash *dirhash;
|
off_t onr, nr;
|
off_t onr, nr;
|
|
|
if (!inode || !S_ISDIR(inode->i_mode))
|
if (!inode || !S_ISDIR(inode->i_mode))
|
return -ENOTDIR;
|
return -ENOTDIR;
|
|
|
dirhash = &((struct autofs_sb_info *)inode->i_sb->u.generic_sbp)->dirhash;
|
dirhash = &((struct autofs_sb_info *)inode->i_sb->u.generic_sbp)->dirhash;
|
nr = filp->f_pos;
|
nr = filp->f_pos;
|
|
|
switch(nr)
|
switch(nr)
|
{
|
{
|
case 0:
|
case 0:
|
if (filldir(dirent, ".", 1, nr, inode->i_ino) < 0)
|
if (filldir(dirent, ".", 1, nr, inode->i_ino) < 0)
|
return 0;
|
return 0;
|
filp->f_pos = ++nr;
|
filp->f_pos = ++nr;
|
/* fall through */
|
/* fall through */
|
case 1:
|
case 1:
|
if (filldir(dirent, "..", 2, nr, inode->i_ino) < 0)
|
if (filldir(dirent, "..", 2, nr, inode->i_ino) < 0)
|
return 0;
|
return 0;
|
filp->f_pos = ++nr;
|
filp->f_pos = ++nr;
|
/* fall through */
|
/* fall through */
|
default:
|
default:
|
while ( onr = nr, ent = autofs_hash_enum(dirhash,&nr) ) {
|
while ( onr = nr, ent = autofs_hash_enum(dirhash,&nr) ) {
|
if (filldir(dirent,ent->name,ent->len,onr,ent->ino) < 0)
|
if (filldir(dirent,ent->name,ent->len,onr,ent->ino) < 0)
|
return 0;
|
return 0;
|
filp->f_pos = nr;
|
filp->f_pos = nr;
|
}
|
}
|
break;
|
break;
|
}
|
}
|
|
|
return 0;
|
return 0;
|
}
|
}
|
|
|
static int autofs_root_lookup(struct inode *dir, const char *name, int len,
|
static int autofs_root_lookup(struct inode *dir, const char *name, int len,
|
struct inode **result)
|
struct inode **result)
|
{
|
{
|
struct autofs_sb_info *sbi;
|
struct autofs_sb_info *sbi;
|
struct autofs_dir_ent *ent;
|
struct autofs_dir_ent *ent;
|
struct inode *res;
|
struct inode *res;
|
autofs_hash_t hash;
|
autofs_hash_t hash;
|
int status, oz_mode;
|
int status, oz_mode;
|
|
|
DPRINTK(("autofs_root_lookup: name = "));
|
DPRINTK(("autofs_root_lookup: name = "));
|
autofs_say(name,len);
|
autofs_say(name,len);
|
|
|
*result = NULL;
|
*result = NULL;
|
if (!dir)
|
if (!dir)
|
return -ENOENT;
|
return -ENOENT;
|
|
|
if (len > NAME_MAX)
|
if (len > NAME_MAX)
|
return -ENOENT;
|
return -ENOENT;
|
|
|
if (!S_ISDIR(dir->i_mode)) {
|
if (!S_ISDIR(dir->i_mode)) {
|
iput(dir);
|
iput(dir);
|
return -ENOTDIR;
|
return -ENOTDIR;
|
}
|
}
|
|
|
/* Handle special cases: . and ..; since this is a root directory,
|
/* Handle special cases: . and ..; since this is a root directory,
|
they both point to the inode itself */
|
they both point to the inode itself */
|
*result = dir;
|
*result = dir;
|
if (!len)
|
if (!len)
|
return 0;
|
return 0;
|
if (name[0] == '.') {
|
if (name[0] == '.') {
|
if (len == 1)
|
if (len == 1)
|
return 0;
|
return 0;
|
if (name[1] == '.' && len == 2)
|
if (name[1] == '.' && len == 2)
|
return 0;
|
return 0;
|
}
|
}
|
|
|
*result = res = NULL;
|
*result = res = NULL;
|
sbi = (struct autofs_sb_info *) dir->i_sb->u.generic_sbp;
|
sbi = (struct autofs_sb_info *) dir->i_sb->u.generic_sbp;
|
|
|
hash = autofs_hash(name,len);
|
hash = autofs_hash(name,len);
|
|
|
oz_mode = autofs_oz_mode(sbi);
|
oz_mode = autofs_oz_mode(sbi);
|
DPRINTK(("autofs_lookup: pid = %u, pgrp = %u, catatonic = %d, oz_mode = %d\n", current->pid, current->pgrp, sbi->catatonic, oz_mode));
|
DPRINTK(("autofs_lookup: pid = %u, pgrp = %u, catatonic = %d, oz_mode = %d\n", current->pid, current->pgrp, sbi->catatonic, oz_mode));
|
|
|
do {
|
do {
|
while ( !(ent = autofs_hash_lookup(&sbi->dirhash,hash,name,len)) ) {
|
while ( !(ent = autofs_hash_lookup(&sbi->dirhash,hash,name,len)) ) {
|
DPRINTK(("lookup failed, pid = %u, pgrp = %u\n", current->pid, current->pgrp));
|
DPRINTK(("lookup failed, pid = %u, pgrp = %u\n", current->pid, current->pgrp));
|
|
|
if ( oz_mode ) {
|
if ( oz_mode ) {
|
iput(dir);
|
iput(dir);
|
return -ENOENT;
|
return -ENOENT;
|
} else {
|
} else {
|
status = autofs_wait(sbi,hash,name,len);
|
status = autofs_wait(sbi,hash,name,len);
|
DPRINTK(("autofs_wait returned %d\n", status));
|
DPRINTK(("autofs_wait returned %d\n", status));
|
if ( status ) {
|
if ( status ) {
|
iput(dir);
|
iput(dir);
|
return status;
|
return status;
|
}
|
}
|
}
|
}
|
}
|
}
|
|
|
DPRINTK(("lookup successful, inode = %08x\n", (unsigned int)ent->ino));
|
DPRINTK(("lookup successful, inode = %08x\n", (unsigned int)ent->ino));
|
|
|
if (!(res = iget(dir->i_sb,ent->ino))) {
|
if (!(res = iget(dir->i_sb,ent->ino))) {
|
printk("autofs: iget returned null!\n");
|
printk("autofs: iget returned null!\n");
|
iput(dir);
|
iput(dir);
|
return -EACCES;
|
return -EACCES;
|
}
|
}
|
|
|
if ( !oz_mode && S_ISDIR(res->i_mode) && res->i_sb == dir->i_sb ) {
|
if ( !oz_mode && S_ISDIR(res->i_mode) && res->i_sb == dir->i_sb ) {
|
/* Not a mount point yet, call 1-800-DAEMON */
|
/* Not a mount point yet, call 1-800-DAEMON */
|
DPRINTK(("autofs: waiting on non-mountpoint dir, inode = %lu, pid = %u, pgrp = %u\n", res->i_ino, current->pid, current->pgrp));
|
DPRINTK(("autofs: waiting on non-mountpoint dir, inode = %lu, pid = %u, pgrp = %u\n", res->i_ino, current->pid, current->pgrp));
|
iput(res);
|
iput(res);
|
res = NULL;
|
res = NULL;
|
status = autofs_wait(sbi,hash,name,len);
|
status = autofs_wait(sbi,hash,name,len);
|
if ( status ) {
|
if ( status ) {
|
iput(dir);
|
iput(dir);
|
return status;
|
return status;
|
}
|
}
|
}
|
}
|
} while(!res);
|
} while(!res);
|
autofs_update_usage(&sbi->dirhash,ent);
|
autofs_update_usage(&sbi->dirhash,ent);
|
|
|
*result = res;
|
*result = res;
|
iput(dir);
|
iput(dir);
|
return 0;
|
return 0;
|
}
|
}
|
|
|
static int autofs_root_symlink(struct inode *dir, const char *name, int len, const char *symname)
|
static int autofs_root_symlink(struct inode *dir, const char *name, int len, const char *symname)
|
{
|
{
|
struct autofs_sb_info *sbi = (struct autofs_sb_info *) dir->i_sb->u.generic_sbp;
|
struct autofs_sb_info *sbi = (struct autofs_sb_info *) dir->i_sb->u.generic_sbp;
|
struct autofs_dirhash *dh = &sbi->dirhash;
|
struct autofs_dirhash *dh = &sbi->dirhash;
|
autofs_hash_t hash = autofs_hash(name,len);
|
autofs_hash_t hash = autofs_hash(name,len);
|
struct autofs_dir_ent *ent;
|
struct autofs_dir_ent *ent;
|
unsigned int n;
|
unsigned int n;
|
int slsize;
|
int slsize;
|
struct autofs_symlink *sl;
|
struct autofs_symlink *sl;
|
|
|
DPRINTK(("autofs_root_symlink: %s <- ", symname));
|
DPRINTK(("autofs_root_symlink: %s <- ", symname));
|
autofs_say(name,len);
|
autofs_say(name,len);
|
|
|
if ( !autofs_oz_mode(sbi) ) {
|
if ( !autofs_oz_mode(sbi) ) {
|
iput(dir);
|
iput(dir);
|
return -EPERM;
|
return -EPERM;
|
}
|
}
|
if ( len > NAME_MAX)
|
if ( len > NAME_MAX)
|
return -ENAMETOOLONG;
|
return -ENAMETOOLONG;
|
|
|
if ( autofs_hash_lookup(dh,hash,name,len) ) {
|
if ( autofs_hash_lookup(dh,hash,name,len) ) {
|
iput(dir);
|
iput(dir);
|
return -EEXIST;
|
return -EEXIST;
|
}
|
}
|
n = find_first_zero_bit(sbi->symlink_bitmap,AUTOFS_MAX_SYMLINKS);
|
n = find_first_zero_bit(sbi->symlink_bitmap,AUTOFS_MAX_SYMLINKS);
|
if ( n >= AUTOFS_MAX_SYMLINKS ) {
|
if ( n >= AUTOFS_MAX_SYMLINKS ) {
|
iput(dir);
|
iput(dir);
|
return -ENOSPC;
|
return -ENOSPC;
|
}
|
}
|
set_bit(n,sbi->symlink_bitmap);
|
set_bit(n,sbi->symlink_bitmap);
|
sl = &sbi->symlink[n];
|
sl = &sbi->symlink[n];
|
sl->len = strlen(symname);
|
sl->len = strlen(symname);
|
sl->data = kmalloc(slsize = sl->len+1, GFP_KERNEL);
|
sl->data = kmalloc(slsize = sl->len+1, GFP_KERNEL);
|
if ( !sl->data ) {
|
if ( !sl->data ) {
|
clear_bit(n,sbi->symlink_bitmap);
|
clear_bit(n,sbi->symlink_bitmap);
|
iput(dir);
|
iput(dir);
|
return -ENOSPC;
|
return -ENOSPC;
|
}
|
}
|
ent = kmalloc(sizeof(struct autofs_dir_ent), GFP_KERNEL);
|
ent = kmalloc(sizeof(struct autofs_dir_ent), GFP_KERNEL);
|
if ( !ent ) {
|
if ( !ent ) {
|
kfree(sl->data);
|
kfree(sl->data);
|
clear_bit(n,sbi->symlink_bitmap);
|
clear_bit(n,sbi->symlink_bitmap);
|
iput(dir);
|
iput(dir);
|
return -ENOSPC;
|
return -ENOSPC;
|
}
|
}
|
ent->name = kmalloc(len, GFP_KERNEL);
|
ent->name = kmalloc(len, GFP_KERNEL);
|
if ( !ent->name ) {
|
if ( !ent->name ) {
|
kfree(sl->data);
|
kfree(sl->data);
|
kfree(ent);
|
kfree(ent);
|
clear_bit(n,sbi->symlink_bitmap);
|
clear_bit(n,sbi->symlink_bitmap);
|
iput(dir);
|
iput(dir);
|
return -ENOSPC;
|
return -ENOSPC;
|
}
|
}
|
memcpy(sl->data,symname,slsize);
|
memcpy(sl->data,symname,slsize);
|
sl->mtime = CURRENT_TIME;
|
sl->mtime = CURRENT_TIME;
|
|
|
ent->ino = AUTOFS_FIRST_SYMLINK + n;
|
ent->ino = AUTOFS_FIRST_SYMLINK + n;
|
ent->hash = hash;
|
ent->hash = hash;
|
memcpy(ent->name,name,ent->len = len);
|
memcpy(ent->name,name,ent->len = len);
|
|
|
autofs_hash_insert(dh,ent);
|
autofs_hash_insert(dh,ent);
|
iput(dir);
|
iput(dir);
|
|
|
return 0;
|
return 0;
|
}
|
}
|
|
|
static int autofs_root_unlink(struct inode *dir, const char *name, int len)
|
static int autofs_root_unlink(struct inode *dir, const char *name, int len)
|
{
|
{
|
struct autofs_sb_info *sbi = (struct autofs_sb_info *) dir->i_sb->u.generic_sbp;
|
struct autofs_sb_info *sbi = (struct autofs_sb_info *) dir->i_sb->u.generic_sbp;
|
struct autofs_dirhash *dh = &sbi->dirhash;
|
struct autofs_dirhash *dh = &sbi->dirhash;
|
autofs_hash_t hash = autofs_hash(name,len);
|
autofs_hash_t hash = autofs_hash(name,len);
|
struct autofs_dir_ent *ent;
|
struct autofs_dir_ent *ent;
|
unsigned int n;
|
unsigned int n;
|
|
|
iput(dir); /* Nothing below can sleep */
|
iput(dir); /* Nothing below can sleep */
|
|
|
if ( !autofs_oz_mode(sbi) )
|
if ( !autofs_oz_mode(sbi) )
|
return -EPERM;
|
return -EPERM;
|
|
|
if(len > NAME_MAX)
|
if(len > NAME_MAX)
|
return -ENAMETOOLONG;
|
return -ENAMETOOLONG;
|
|
|
ent = autofs_hash_lookup(dh,hash,name,len);
|
ent = autofs_hash_lookup(dh,hash,name,len);
|
if ( !ent )
|
if ( !ent )
|
return -ENOENT;
|
return -ENOENT;
|
|
|
n = ent->ino - AUTOFS_FIRST_SYMLINK;
|
n = ent->ino - AUTOFS_FIRST_SYMLINK;
|
if ( n >= AUTOFS_MAX_SYMLINKS || !test_bit(n,sbi->symlink_bitmap) )
|
if ( n >= AUTOFS_MAX_SYMLINKS || !test_bit(n,sbi->symlink_bitmap) )
|
return -EINVAL; /* Not a symlink inode, can't unlink */
|
return -EINVAL; /* Not a symlink inode, can't unlink */
|
|
|
autofs_hash_delete(ent);
|
autofs_hash_delete(ent);
|
clear_bit(n,sbi->symlink_bitmap);
|
clear_bit(n,sbi->symlink_bitmap);
|
kfree(sbi->symlink[n].data);
|
kfree(sbi->symlink[n].data);
|
|
|
return 0;
|
return 0;
|
}
|
}
|
|
|
static int autofs_root_rmdir(struct inode *dir, const char *name, int len)
|
static int autofs_root_rmdir(struct inode *dir, const char *name, int len)
|
{
|
{
|
struct autofs_sb_info *sbi = (struct autofs_sb_info *) dir->i_sb->u.generic_sbp;
|
struct autofs_sb_info *sbi = (struct autofs_sb_info *) dir->i_sb->u.generic_sbp;
|
struct autofs_dirhash *dh = &sbi->dirhash;
|
struct autofs_dirhash *dh = &sbi->dirhash;
|
autofs_hash_t hash = autofs_hash(name,len);
|
autofs_hash_t hash = autofs_hash(name,len);
|
struct autofs_dir_ent *ent;
|
struct autofs_dir_ent *ent;
|
|
|
if ( !autofs_oz_mode(sbi) ) {
|
if ( !autofs_oz_mode(sbi) ) {
|
iput(dir);
|
iput(dir);
|
return -EPERM;
|
return -EPERM;
|
}
|
}
|
ent = autofs_hash_lookup(dh,hash,name,len);
|
ent = autofs_hash_lookup(dh,hash,name,len);
|
if ( !ent ) {
|
if ( !ent ) {
|
iput(dir);
|
iput(dir);
|
return -ENOENT;
|
return -ENOENT;
|
}
|
}
|
if ( (unsigned int)ent->ino < AUTOFS_FIRST_DIR_INO ) {
|
if ( (unsigned int)ent->ino < AUTOFS_FIRST_DIR_INO ) {
|
iput(dir);
|
iput(dir);
|
return -ENOTDIR; /* Not a directory */
|
return -ENOTDIR; /* Not a directory */
|
}
|
}
|
autofs_hash_delete(ent);
|
autofs_hash_delete(ent);
|
dir->i_nlink--;
|
dir->i_nlink--;
|
iput(dir);
|
iput(dir);
|
|
|
return 0;
|
return 0;
|
}
|
}
|
|
|
static int autofs_root_mkdir(struct inode *dir, const char *name, int len, int mode)
|
static int autofs_root_mkdir(struct inode *dir, const char *name, int len, int mode)
|
{
|
{
|
struct autofs_sb_info *sbi = (struct autofs_sb_info *) dir->i_sb->u.generic_sbp;
|
struct autofs_sb_info *sbi = (struct autofs_sb_info *) dir->i_sb->u.generic_sbp;
|
struct autofs_dirhash *dh = &sbi->dirhash;
|
struct autofs_dirhash *dh = &sbi->dirhash;
|
autofs_hash_t hash = autofs_hash(name,len);
|
autofs_hash_t hash = autofs_hash(name,len);
|
struct autofs_dir_ent *ent;
|
struct autofs_dir_ent *ent;
|
|
|
if ( !autofs_oz_mode(sbi) ) {
|
if ( !autofs_oz_mode(sbi) ) {
|
iput(dir);
|
iput(dir);
|
return -EPERM;
|
return -EPERM;
|
}
|
}
|
ent = autofs_hash_lookup(dh,hash,name,len);
|
ent = autofs_hash_lookup(dh,hash,name,len);
|
if ( ent ) {
|
if ( ent ) {
|
iput(dir);
|
iput(dir);
|
return -EEXIST;
|
return -EEXIST;
|
}
|
}
|
if ( sbi->next_dir_ino < AUTOFS_FIRST_DIR_INO ) {
|
if ( sbi->next_dir_ino < AUTOFS_FIRST_DIR_INO ) {
|
printk("autofs: Out of inode numbers -- what the heck did you do??\n");
|
printk("autofs: Out of inode numbers -- what the heck did you do??\n");
|
iput(dir);
|
iput(dir);
|
return -ENOSPC;
|
return -ENOSPC;
|
}
|
}
|
ent = kmalloc(sizeof(struct autofs_dir_ent), GFP_KERNEL);
|
ent = kmalloc(sizeof(struct autofs_dir_ent), GFP_KERNEL);
|
if ( !ent ) {
|
if ( !ent ) {
|
iput(dir);
|
iput(dir);
|
return -ENOSPC;
|
return -ENOSPC;
|
}
|
}
|
ent->name = kmalloc(len, GFP_KERNEL);
|
ent->name = kmalloc(len, GFP_KERNEL);
|
if ( !ent->name ) {
|
if ( !ent->name ) {
|
kfree(ent);
|
kfree(ent);
|
iput(dir);
|
iput(dir);
|
return -ENOSPC;
|
return -ENOSPC;
|
}
|
}
|
ent->hash = hash;
|
ent->hash = hash;
|
memcpy(ent->name, name, ent->len = len);
|
memcpy(ent->name, name, ent->len = len);
|
ent->ino = sbi->next_dir_ino++;
|
ent->ino = sbi->next_dir_ino++;
|
autofs_hash_insert(dh,ent);
|
autofs_hash_insert(dh,ent);
|
dir->i_nlink++;
|
dir->i_nlink++;
|
iput(dir);
|
iput(dir);
|
|
|
return 0;
|
return 0;
|
}
|
}
|
|
|
/* Get/set timeout ioctl() operation */
|
/* Get/set timeout ioctl() operation */
|
static inline int autofs_get_set_timeout(struct autofs_sb_info *sbi,
|
static inline int autofs_get_set_timeout(struct autofs_sb_info *sbi,
|
unsigned long *p)
|
unsigned long *p)
|
{
|
{
|
int rv;
|
int rv;
|
unsigned long ntimeout;
|
unsigned long ntimeout;
|
|
|
#if LINUX_VERSION_CODE < kver(2,1,0)
|
#if LINUX_VERSION_CODE < kver(2,1,0)
|
if ( (rv = verify_area(VERIFY_WRITE, p, sizeof(unsigned long))) )
|
if ( (rv = verify_area(VERIFY_WRITE, p, sizeof(unsigned long))) )
|
return rv;
|
return rv;
|
ntimeout = get_user(p);
|
ntimeout = get_user(p);
|
put_user(sbi->exp_timeout/HZ, p);
|
put_user(sbi->exp_timeout/HZ, p);
|
#else
|
#else
|
if ( (rv = get_user(ntimeout, p)) ||
|
if ( (rv = get_user(ntimeout, p)) ||
|
(rv = put_user(sbi->exp_timeout/HZ, p)) )
|
(rv = put_user(sbi->exp_timeout/HZ, p)) )
|
return rv;
|
return rv;
|
#endif
|
#endif
|
|
|
if ( ntimeout > ULONG_MAX/HZ )
|
if ( ntimeout > ULONG_MAX/HZ )
|
sbi->exp_timeout = 0;
|
sbi->exp_timeout = 0;
|
else
|
else
|
sbi->exp_timeout = ntimeout * HZ;
|
sbi->exp_timeout = ntimeout * HZ;
|
|
|
return 0;
|
return 0;
|
}
|
}
|
|
|
/* Return protocol version */
|
/* Return protocol version */
|
static inline int autofs_get_protover(int *p)
|
static inline int autofs_get_protover(int *p)
|
{
|
{
|
#if LINUX_VERSION_CODE < kver(2,1,0)
|
#if LINUX_VERSION_CODE < kver(2,1,0)
|
int rv;
|
int rv;
|
if ( (rv = verify_area(VERIFY_WRITE, p, sizeof(int))) )
|
if ( (rv = verify_area(VERIFY_WRITE, p, sizeof(int))) )
|
return rv;
|
return rv;
|
put_user(AUTOFS_PROTO_VERSION, p);
|
put_user(AUTOFS_PROTO_VERSION, p);
|
return 0;
|
return 0;
|
#else
|
#else
|
return put_user(AUTOFS_PROTO_VERSION, p);
|
return put_user(AUTOFS_PROTO_VERSION, p);
|
#endif
|
#endif
|
}
|
}
|
|
|
/* Perform an expiry operation */
|
/* Perform an expiry operation */
|
static inline int autofs_expire_run(struct autofs_sb_info *sbi,
|
static inline int autofs_expire_run(struct autofs_sb_info *sbi,
|
struct autofs_packet_expire *pkt_p)
|
struct autofs_packet_expire *pkt_p)
|
{
|
{
|
struct autofs_dir_ent *ent;
|
struct autofs_dir_ent *ent;
|
struct autofs_packet_expire pkt;
|
struct autofs_packet_expire pkt;
|
struct autofs_dirhash *dh = &(sbi->dirhash);
|
struct autofs_dirhash *dh = &(sbi->dirhash);
|
|
|
memset(&pkt,0,sizeof pkt);
|
memset(&pkt,0,sizeof pkt);
|
|
|
pkt.hdr.proto_version = AUTOFS_PROTO_VERSION;
|
pkt.hdr.proto_version = AUTOFS_PROTO_VERSION;
|
pkt.hdr.type = autofs_ptype_expire;
|
pkt.hdr.type = autofs_ptype_expire;
|
|
|
if ( !sbi->exp_timeout ||
|
if ( !sbi->exp_timeout ||
|
!(ent = autofs_expire(dh,sbi->exp_timeout)) )
|
!(ent = autofs_expire(dh,sbi->exp_timeout)) )
|
return -EAGAIN;
|
return -EAGAIN;
|
|
|
pkt.len = ent->len;
|
pkt.len = ent->len;
|
memcpy(pkt.name, ent->name, pkt.len);
|
memcpy(pkt.name, ent->name, pkt.len);
|
pkt.name[pkt.len] = '\0';
|
pkt.name[pkt.len] = '\0';
|
|
|
if ( copy_to_user(pkt_p, &pkt, sizeof(struct autofs_packet_expire)) )
|
if ( copy_to_user(pkt_p, &pkt, sizeof(struct autofs_packet_expire)) )
|
return -EFAULT;
|
return -EFAULT;
|
|
|
autofs_update_usage(dh,ent);
|
autofs_update_usage(dh,ent);
|
|
|
return 0;
|
return 0;
|
}
|
}
|
|
|
/*
|
/*
|
* ioctl()'s on the root directory is the chief method for the daemon to
|
* ioctl()'s on the root directory is the chief method for the daemon to
|
* generate kernel reactions
|
* generate kernel reactions
|
*/
|
*/
|
static int autofs_root_ioctl(struct inode *inode, struct file *filp,
|
static int autofs_root_ioctl(struct inode *inode, struct file *filp,
|
unsigned int cmd, unsigned long arg)
|
unsigned int cmd, unsigned long arg)
|
{
|
{
|
struct autofs_sb_info *sbi =
|
struct autofs_sb_info *sbi =
|
(struct autofs_sb_info *)inode->i_sb->u.generic_sbp;
|
(struct autofs_sb_info *)inode->i_sb->u.generic_sbp;
|
|
|
DPRINTK(("autofs_ioctl: cmd = 0x%08x, arg = 0x%08lx, sbi = %p, pgrp = %u\n",cmd,arg,sbi,current->pgrp));
|
DPRINTK(("autofs_ioctl: cmd = 0x%08x, arg = 0x%08lx, sbi = %p, pgrp = %u\n",cmd,arg,sbi,current->pgrp));
|
|
|
if ( _IOC_TYPE(cmd) != _IOC_TYPE(AUTOFS_IOC_FIRST) ||
|
if ( _IOC_TYPE(cmd) != _IOC_TYPE(AUTOFS_IOC_FIRST) ||
|
_IOC_NR(cmd) - _IOC_NR(AUTOFS_IOC_FIRST) >= AUTOFS_IOC_COUNT )
|
_IOC_NR(cmd) - _IOC_NR(AUTOFS_IOC_FIRST) >= AUTOFS_IOC_COUNT )
|
return -ENOTTY;
|
return -ENOTTY;
|
|
|
if ( !autofs_oz_mode(sbi) && !fsuser() )
|
if ( !autofs_oz_mode(sbi) && !fsuser() )
|
return -EPERM;
|
return -EPERM;
|
|
|
switch(cmd) {
|
switch(cmd) {
|
case AUTOFS_IOC_READY: /* Wait queue: go ahead and retry */
|
case AUTOFS_IOC_READY: /* Wait queue: go ahead and retry */
|
return autofs_wait_release(sbi,arg,0);
|
return autofs_wait_release(sbi,arg,0);
|
case AUTOFS_IOC_FAIL: /* Wait queue: fail with ENOENT */
|
case AUTOFS_IOC_FAIL: /* Wait queue: fail with ENOENT */
|
return autofs_wait_release(sbi,arg,-ENOENT);
|
return autofs_wait_release(sbi,arg,-ENOENT);
|
case AUTOFS_IOC_CATATONIC: /* Enter catatonic mode (daemon shutdown) */
|
case AUTOFS_IOC_CATATONIC: /* Enter catatonic mode (daemon shutdown) */
|
autofs_catatonic_mode(sbi);
|
autofs_catatonic_mode(sbi);
|
return 0;
|
return 0;
|
case AUTOFS_IOC_PROTOVER: /* Get protocol version */
|
case AUTOFS_IOC_PROTOVER: /* Get protocol version */
|
return autofs_get_protover((int *)arg);
|
return autofs_get_protover((int *)arg);
|
case AUTOFS_IOC_SETTIMEOUT:
|
case AUTOFS_IOC_SETTIMEOUT:
|
return autofs_get_set_timeout(sbi,(unsigned long *)arg);
|
return autofs_get_set_timeout(sbi,(unsigned long *)arg);
|
case AUTOFS_IOC_EXPIRE:
|
case AUTOFS_IOC_EXPIRE:
|
return autofs_expire_run(sbi,(struct autofs_packet_expire *)arg);
|
return autofs_expire_run(sbi,(struct autofs_packet_expire *)arg);
|
default:
|
default:
|
return -ENOSYS;
|
return -ENOSYS;
|
}
|
}
|
}
|
}
|
|
|