fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / fs / smbfs / proc.c
index 8096d74..feac460 100644 (file)
@@ -8,6 +8,7 @@
  */
 
 #include <linux/types.h>
+#include <linux/capability.h>
 #include <linux/errno.h>
 #include <linux/slab.h>
 #include <linux/fs.h>
@@ -74,7 +75,7 @@ smb_proc_setattr_core(struct smb_sb_info *server, struct dentry *dentry,
 static int
 smb_proc_setattr_ext(struct smb_sb_info *server,
                     struct inode *inode, struct smb_fattr *fattr);
-int
+static int
 smb_proc_query_cifsunix(struct smb_sb_info *server);
 static void
 install_ops(struct smb_ops *dst, struct smb_ops *src);
@@ -872,11 +873,11 @@ smb_newconn(struct smb_sb_info *server, struct smb_conn_opt *opt)
        filp = fget(opt->fd);
        if (!filp)
                goto out;
-       if (!smb_valid_socket(filp->f_dentry->d_inode))
+       if (!smb_valid_socket(filp->f_path.dentry->d_inode))
                goto out_putf;
 
        server->sock_file = filp;
-       server->conn_pid = current->pid;
+       server->conn_pid = get_pid(task_pid(current));
        server->opt = *opt;
        server->generation += 1;
        server->state = CONN_VALID;
@@ -897,7 +898,7 @@ smb_newconn(struct smb_sb_info *server, struct smb_conn_opt *opt)
        /*
         * Store the server in sock user_data (Only used by sunrpc)
         */
-       sk = SOCKET_I(filp->f_dentry->d_inode)->sk;
+       sk = SOCKET_I(filp->f_path.dentry->d_inode)->sk;
        sk->sk_user_data = server;
 
        /* chain into the data_ready callback */
@@ -970,8 +971,8 @@ smb_newconn(struct smb_sb_info *server, struct smb_conn_opt *opt)
        }
 
        VERBOSE("protocol=%d, max_xmit=%d, pid=%d capabilities=0x%x\n",
-               server->opt.protocol, server->opt.max_xmit, server->conn_pid,
-               server->opt.capabilities);
+               server->opt.protocol, server->opt.max_xmit,
+               pid_nr(server->conn_pid), server->opt.capabilities);
 
        /* FIXME: this really should be done by smbmount. */
        if (server->opt.max_xmit > SMB_MAX_PACKET_SIZE) {
@@ -1427,9 +1428,9 @@ smb_proc_readX_data(struct smb_request *req)
         * So we must first calculate the amount of padding used by the server.
         */
        data_off -= hdrlen;
-       if (data_off > SMB_READX_MAX_PAD) {
-               PARANOIA("offset is larger than max pad!\n");
-               PARANOIA("%d > %d\n", data_off, SMB_READX_MAX_PAD);
+       if (data_off > SMB_READX_MAX_PAD || data_off < 0) {
+               PARANOIA("offset is larger than SMB_READX_MAX_PAD or negative!\n");
+               PARANOIA("%d > %d || %d < 0\n", data_off, SMB_READX_MAX_PAD, data_off);
                req->rq_rlen = req->rq_bufsize + 1;
                return;
        }
@@ -1825,7 +1826,6 @@ smb_init_dirent(struct smb_sb_info *server, struct smb_fattr *fattr)
        fattr->f_nlink = 1;
        fattr->f_uid = server->mnt->uid;
        fattr->f_gid = server->mnt->gid;
-       fattr->f_blksize = SMB_ST_BLKSIZE;
        fattr->f_unix = 0;
 }
 
@@ -1852,12 +1852,13 @@ smb_finish_dirent(struct smb_sb_info *server, struct smb_fattr *fattr)
 }
 
 void
-smb_init_root_dirent(struct smb_sb_info *server, struct smb_fattr *fattr)
+smb_init_root_dirent(struct smb_sb_info *server, struct smb_fattr *fattr,
+                    struct super_block *sb)
 {
        smb_init_dirent(server, fattr);
        fattr->attr = aDIR;
        fattr->f_ino = 2; /* traditional root inode number */
-       fattr->f_mtime = CURRENT_TIME;
+       fattr->f_mtime = current_fs_time(sb);
        smb_finish_dirent(server, fattr);
 }
 
@@ -1938,7 +1939,7 @@ static int
 smb_proc_readdir_short(struct file *filp, void *dirent, filldir_t filldir,
                       struct smb_cache_control *ctl)
 {
-       struct dentry *dir = filp->f_dentry;
+       struct dentry *dir = filp->f_path.dentry;
        struct smb_sb_info *server = server_from_dentry(dir);
        struct qstr qname;
        struct smb_fattr fattr;
@@ -2074,8 +2075,10 @@ out:
        return result;
 }
 
-void smb_decode_unix_basic(struct smb_fattr *fattr, char *p)
+static void smb_decode_unix_basic(struct smb_fattr *fattr, struct smb_sb_info *server, char *p)
 {
+       u64 size, disk_bytes;
+
        /* FIXME: verify nls support. all is sent as utf8? */
 
        fattr->f_unix = 1;
@@ -2093,13 +2096,33 @@ void smb_decode_unix_basic(struct smb_fattr *fattr, char *p)
        /* 84 L permissions */
        /* 92 L link count */
 
-       fattr->f_size = LVAL(p, 0);
-       fattr->f_blocks = LVAL(p, 8);
+       size = LVAL(p, 0);
+       disk_bytes = LVAL(p, 8);
+
+       /*
+        * Some samba versions round up on-disk byte usage
+        * to 1MB boundaries, making it useless. When seeing
+        * that, use the size instead.
+        */
+       if (!(disk_bytes & 0xfffff))
+               disk_bytes = size+511;
+
+       fattr->f_size = size;
+       fattr->f_blocks = disk_bytes >> 9;
        fattr->f_ctime = smb_ntutc2unixutc(LVAL(p, 16));
        fattr->f_atime = smb_ntutc2unixutc(LVAL(p, 24));
        fattr->f_mtime = smb_ntutc2unixutc(LVAL(p, 32));
-       fattr->f_uid = LVAL(p, 40); 
-       fattr->f_gid = LVAL(p, 48); 
+
+       if (server->mnt->flags & SMB_MOUNT_UID)
+               fattr->f_uid = server->mnt->uid;
+       else
+               fattr->f_uid = LVAL(p, 40);
+
+       if (server->mnt->flags & SMB_MOUNT_GID)
+               fattr->f_gid = server->mnt->gid;
+       else
+               fattr->f_gid = LVAL(p, 48);
+
        fattr->f_mode |= smb_filetype_to_mode(WVAL(p, 56));
 
        if (S_ISBLK(fattr->f_mode) || S_ISCHR(fattr->f_mode)) {
@@ -2108,10 +2131,20 @@ void smb_decode_unix_basic(struct smb_fattr *fattr, char *p)
 
                fattr->f_rdev = MKDEV(major & 0xffffffff, minor & 0xffffffff);
                if (MAJOR(fattr->f_rdev) != (major & 0xffffffff) ||
-                   MINOR(fattr->f_rdev) != (minor & 0xffffffff))
+               MINOR(fattr->f_rdev) != (minor & 0xffffffff))
                        fattr->f_rdev = 0;
        }
+
        fattr->f_mode |= LVAL(p, 84);
+
+       if ( (server->mnt->flags & SMB_MOUNT_DMODE) &&
+            (S_ISDIR(fattr->f_mode)) )
+               fattr->f_mode = (server->mnt->dir_mode & S_IRWXUGO) | S_IFDIR;
+       else if ( (server->mnt->flags & SMB_MOUNT_FMODE) &&
+                 !(S_ISDIR(fattr->f_mode)) )
+               fattr->f_mode = (server->mnt->file_mode & S_IRWXUGO) |
+                               (fattr->f_mode & S_IFMT);
+
 }
 
 /*
@@ -2197,7 +2230,7 @@ smb_decode_long_dirent(struct smb_sb_info *server, char *p, int level,
                /* FIXME: should we check the length?? */
 
                p += 8;
-               smb_decode_unix_basic(fattr, p);
+               smb_decode_unix_basic(fattr, server, p);
                VERBOSE("info SMB_FIND_FILE_UNIX at %p, len=%d, name=%.*s\n",
                        p, len, len, qname->name);
                break;
@@ -2258,7 +2291,7 @@ static int
 smb_proc_readdir_long(struct file *filp, void *dirent, filldir_t filldir,
                      struct smb_cache_control *ctl)
 {
-       struct dentry *dir = filp->f_dentry;
+       struct dentry *dir = filp->f_path.dentry;
        struct smb_sb_info *server = server_from_dentry(dir);
        struct qstr qname;
        struct smb_fattr fattr;
@@ -2364,8 +2397,7 @@ smb_proc_readdir_long(struct file *filp, void *dirent, filldir_t filldir,
                if (req->rq_rcls == ERRSRV && req->rq_err == ERRerror) {
                        /* a damn Win95 bug - sometimes it clags if you 
                           ask it too fast */
-                       current->state = TASK_INTERRUPTIBLE;
-                       schedule_timeout(HZ/5);
+                       schedule_timeout_interruptible(msecs_to_jiffies(200));
                        continue;
                 }
 
@@ -2756,7 +2788,7 @@ smb_proc_getattr_unix(struct smb_sb_info *server, struct dentry *dir,
        if (result < 0)
                goto out_free;
 
-       smb_decode_unix_basic(attr, req->rq_data);
+       smb_decode_unix_basic(attr, server, req->rq_data);
 
 out_free:
        smb_rput(req);
@@ -2827,7 +2859,7 @@ static int
 smb_proc_readdir_null(struct file *filp, void *dirent, filldir_t filldir,
                      struct smb_cache_control *ctl)
 {
-       struct smb_sb_info *server = server_from_dentry(filp->f_dentry);
+       struct smb_sb_info *server = server_from_dentry(filp->f_path.dentry);
 
        if (smb_proc_ops_wait(server) < 0)
                return -EIO;
@@ -3081,7 +3113,7 @@ smb_proc_setattr_unix(struct dentry *d, struct iattr *attr,
        LSET(data, 32, SMB_TIME_NO_CHANGE);
        LSET(data, 40, SMB_UID_NO_CHANGE);
        LSET(data, 48, SMB_GID_NO_CHANGE);
-       LSET(data, 56, smb_filetype_from_mode(attr->ia_mode));
+       DSET(data, 56, smb_filetype_from_mode(attr->ia_mode));
        LSET(data, 60, major);
        LSET(data, 68, minor);
        LSET(data, 76, 0);
@@ -3193,9 +3225,9 @@ smb_proc_settime(struct dentry *dentry, struct smb_fattr *fattr)
 }
 
 int
-smb_proc_dskattr(struct super_block *sb, struct kstatfs *attr)
+smb_proc_dskattr(struct dentry *dentry, struct kstatfs *attr)
 {
-       struct smb_sb_info *server = SMB_SB(sb);
+       struct smb_sb_info *server = SMB_SB(dentry->d_sb);
        int result;
        char *p;
        long unit;
@@ -3359,7 +3391,7 @@ out:
        return result;
 }
 
-int
+static int
 smb_proc_query_cifsunix(struct smb_sb_info *server)
 {
        int result;