nfs 掛載目錄 root 許可權不夠 ?

season0891發表於2012-01-18
測試中出現的問題:
1、無法在開發板上刪除透過nfs共享的資料夾
解決方法:加入no_root_squash引數後解決問題
nfs 共享時是否加入了no_root_squash 這樣在客戶機掛載時就有root 許可權.
如果沒有的話,客戶機掛載時就沒有root 許可權,只有noboday ,這時需要伺服器就要設定對應讀寫許可權了.
例如 一個目 /home
對應許可權 drwxr-xr-x home
下層目錄 ls /home
drwx------ 26 wang wang 4096 12月 3 12:48 wang
user wang uid=500,gid=500
example 1
nfs server /etc/exports
/home *(rw,sync)
我們在客戶
mount ip:/home /mnt
user root
cd /mnt
mkdir 1
mkdir: 無法建立目錄‘1’: 許可權不夠
此時root 的身份已經為noboday,雖然共享許可權為rw,但是隻能r
example 2
nfs server /etc/exports
/home *(rw,sync,all_squash,anonuid=500.anongid=500)
我們在客戶
mount ip:/home /mnt
user root
cd /mnt
mkdir 1
mkdir: 無法建立目錄‘1’: 許可權不夠
cd /mnt/wang
mkdir 1
ls -l
drwxr-xr-x 2 wang wang 4096 12月 12 23:45 1
此時root 的身份已經為wang,雖然共享許可權為rw,但是隻能在/mnt/wang 下面,這種情況很象你上面的相象
example 3
nfs server /etc/exports
/home *(rw,sync,no_root_squash)
我們在客戶
mount ip:/home /mnt
user root
cd /mnt
mkdir 1
ls -l
drwxr-xr-x 2 root root 4096 12月 12 23:49 1
此時root 的身份已經為root,可以在共享目錄裡面進行任何操作
2、insmod核心模組時出現錯誤:

[root@(none) ramdisk]# insmod ok.o
insmod: unresolved symbol __put_user_bad
解決方法:編譯模組的時候是用最佳化選項O2解決問題!
源程式:



#ifndef __KERNEL__
#define __KERNEL__
#endif
#ifndef MODULE
#define MODULE
#endif
#include linux/module.h>
#include linux/kernel.h>
#include linux/fs.h>
#include asm/uaccess.h>
#includelinux/types.h>
#includeasm/hardware.h> //沒有的 話導至 devfs_handle_t 找不到
#define SUCCESS 0
#define DEVICE_NAME "chardev"
#define BUF_LEN 80 /* Max length of the message from the device */
static devfs_handle_t dev_handle;
int Major; /* Major number assigned to our device driver */
int Device_Open = 0; /* Is device open? Used to prevent multiple */
char msg[BUF_LEN]; /* The msg the device will give when asked */
char *msg_Ptr;
int lj_open(struct inode *inode, struct file *file)
{
static int counter = 0;
if (Device_Open) return -EBUSY;
Device_Open++;
sprintf(msg,"I already told you %d times Hello world!\n", counter++);
msg_Ptr = msg;
printk("device_open call\n");
return SUCCESS;
}
int lj_release(struct inode *inode, struct file *file)
{
Device_Open --; /* We're now ready for our next caller */
printk("device_release call\n");
return 0;
}
ssize_t lj_read(struct file *filp,
char *buffer, /* The buffer to fill with data */
size_t length, /* The length of the buffer */
loff_t *offset) /* Our offset in the file */
{
int bytes_read = 0;
if (*msg_Ptr == 0)
return 0;
while (length && *msg_Ptr)
{
put_user(*(msg_Ptr++), buffer++);
length--;
bytes_read++;
}

return bytes_read;
}
ssize_t lj_write(struct file *filp,
const char *buff,
size_t len,
loff_t *off)
{
printk ("Sorry, this operation isn't supported.\n");
return -EINVAL;
}
static struct file_operations keybd_fops =
{
read:lj_read, //注意此處是:而不是= //.read=lj_read 才是=
write:lj_write,
open:lj_open,
release:lj_release,
};
int init_module(void)
{

Major = register_chrdev(240, DEVICE_NAME, &keybd_fops);
dev_handle = devfs_register(NULL,DEVICE_NAME, DEVFS_FL_DEFAULT,
240,0,S_IFCHR|S_IRUSR|S_IWUSR,&keybd_fops,NULL);
//註冊字元驅動 第一個引數是主裝置號 如果第一個引數是0 表示由核心自動分配
//第二個是裝置名 可以在/proc/devices裡面看到
//第三個是對此裝置的操作函式 具體操作可以看file_operations結構定義 在linux/fs.h裡面
if (Major 0) {
printk ("Registering the character device failed with %d\n", Major);
return Major;
}
Major = 240;
printk("I was assigned major number %d. To talk to\n", Major);
printk("Remove the device file and module when done.\n");
return 0;
}
void cleanup_module(void)
{
int ret = unregister_chrdev(Major, DEVICE_NAME);
devfs_unregister(dev_handle);
printk("bye \n");
if (ret 0) printk("Error in unregister_chrdev: %d\n", ret);
}
//測試方法
//echo"hello"> /dev/chardev
//cat /dev/chardev >hello

//然後看hello裡的內容

come from:

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/90618/viewspace-715072/,如需轉載,請註明出處,否則將追究法律責任。

相關文章