[CIFS] convert usage of implicit booleans to bool
[safe/jmp/linux-2.6] / fs / cifs / dir.c
index eeab602..6ed7759 100644 (file)
@@ -3,7 +3,7 @@
  *
  *   vfs operations that deal with dentries
  *
- *   Copyright (C) International Business Machines  Corp., 2002,2005
+ *   Copyright (C) International Business Machines  Corp., 2002,2008
  *   Author(s): Steve French (sfrench@us.ibm.com)
  *
  *   This library is free software; you can redistribute it and/or modify
@@ -111,16 +111,6 @@ cifs_bp_rename_retry:
        return full_path;
 }
 
-/* char * build_wildcard_path_from_dentry(struct dentry *direntry)
-{
-       if(full_path == NULL)
-               return full_path;
-
-       full_path[namelen] = '\\';
-       full_path[namelen+1] = '*';
-       full_path[namelen+2] = 0;
-BB remove above eight lines BB */
-
 /* Inode operations in similar order to how they appear in Linux file fs.h */
 
 int
@@ -135,12 +125,12 @@ cifs_create(struct inode *inode, struct dentry *direntry, int mode,
        struct cifs_sb_info *cifs_sb;
        struct cifsTconInfo *pTcon;
        char *full_path = NULL;
-       FILE_ALL_INFO * buf = NULL;
+       FILE_ALL_INFO *buf = NULL;
        struct inode *newinode = NULL;
-       struct cifsFileInfo * pCifsFile = NULL;
-       struct cifsInodeInfo * pCifsInode;
+       struct cifsFileInfo *pCifsFile = NULL;
+       struct cifsInodeInfo *pCifsInode;
        int disposition = FILE_OVERWRITE_IF;
-       int write_only = FALSE;
+       bool write_only = false;
 
        xid = GetXid();
 
@@ -162,7 +152,7 @@ cifs_create(struct inode *inode, struct dentry *direntry, int mode,
                if (oflags & FMODE_WRITE) {
                        desiredAccess |= GENERIC_WRITE;
                        if (!(oflags & FMODE_READ))
-                               write_only = TRUE;
+                               write_only = true;
                }
 
                if ((oflags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))
@@ -171,9 +161,8 @@ cifs_create(struct inode *inode, struct dentry *direntry, int mode,
                        disposition = FILE_OVERWRITE_IF;
                else if ((oflags & O_CREAT) == O_CREAT)
                        disposition = FILE_OPEN_IF;
-               else {
+               else
                        cFYI(1, ("Create flag not set in create function"));
-               }
        }
 
        /* BB add processing to set equivalent of mode - e.g. via CreateX with
@@ -207,8 +196,8 @@ cifs_create(struct inode *inode, struct dentry *direntry, int mode,
        } else {
                /* If Open reported that we actually created a file
                then we now have to set the mode if possible */
-               if ((cifs_sb->tcon->ses->capabilities & CAP_UNIX) &&
-                       (oplock & CIFS_CREATE_ACTION))
+               if ((pTcon->unix_ext) && (oplock & CIFS_CREATE_ACTION)) {
+                       mode &= ~current->fs->umask;
                        if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID) {
                                CIFSSMBUnixSetPerms(xid, pTcon, full_path, mode,
                                        (__u64)current->fsuid,
@@ -226,7 +215,7 @@ cifs_create(struct inode *inode, struct dentry *direntry, int mode,
                                        cifs_sb->mnt_cifs_flags &
                                                CIFS_MOUNT_MAP_SPECIAL_CHR);
                        }
-               else {
+               else {
                        /* BB implement mode setting via Windows security
                           descriptors e.g. */
                        /* CIFSSMBWinSetPerms(xid,pTcon,path,mode,-1,-1,nls);*/
@@ -234,13 +223,14 @@ cifs_create(struct inode *inode, struct dentry *direntry, int mode,
                        /* Could set r/o dos attribute if mode & 0222 == 0 */
                }
 
-       /* BB server might mask mode so we have to query for Unix case*/
-               if (pTcon->ses->capabilities & CAP_UNIX)
+               /* server might mask mode so we have to query for it */
+               if (pTcon->unix_ext)
                        rc = cifs_get_inode_info_unix(&newinode, full_path,
                                                 inode->i_sb, xid);
                else {
                        rc = cifs_get_inode_info(&newinode, full_path,
-                                                buf, inode->i_sb, xid);
+                                                buf, inode->i_sb, xid,
+                                                &fileHandle);
                        if (newinode) {
                                newinode->i_mode = mode;
                                if ((oplock & CIFS_CREATE_ACTION) &&
@@ -263,20 +253,21 @@ cifs_create(struct inode *inode, struct dentry *direntry, int mode,
                                direntry->d_op = &cifs_dentry_ops;
                        d_instantiate(direntry, newinode);
                }
-               if ((nd->flags & LOOKUP_OPEN) == FALSE) {
+               if ((nd == NULL /* nfsd case - nfs srv does not set nd */) ||
+                       (!(nd->flags & LOOKUP_OPEN))) {
                        /* mknod case - do not leave file open */
                        CIFSSMBClose(xid, pTcon, fileHandle);
                } else if (newinode) {
                        pCifsFile =
-                          kzalloc(sizeof (struct cifsFileInfo), GFP_KERNEL);
-                       
+                          kzalloc(sizeof(struct cifsFileInfo), GFP_KERNEL);
+
                        if (pCifsFile == NULL)
                                goto cifs_create_out;
                        pCifsFile->netfid = fileHandle;
                        pCifsFile->pid = current->tgid;
                        pCifsFile->pInode = newinode;
-                       pCifsFile->invalidHandle = FALSE;
-                       pCifsFile->closePend     = FALSE;
+                       pCifsFile->invalidHandle = false;
+                       pCifsFile->closePend     = false;
                        init_MUTEX(&pCifsFile->fh_sem);
                        mutex_init(&pCifsFile->lock_mutex);
                        INIT_LIST_HEAD(&pCifsFile->llist);
@@ -289,7 +280,7 @@ cifs_create(struct inode *inode, struct dentry *direntry, int mode,
                        pCifsInode = CIFS_I(newinode);
                        if (pCifsInode) {
                                /* if readable file instance put first in list*/
-                               if (write_only == TRUE) {
+                               if (write_only) {
                                        list_add_tail(&pCifsFile->flist,
                                                &pCifsInode->openFileList);
                                } else {
@@ -297,12 +288,12 @@ cifs_create(struct inode *inode, struct dentry *direntry, int mode,
                                                &pCifsInode->openFileList);
                                }
                                if ((oplock & 0xF) == OPLOCK_EXCLUSIVE) {
-                                       pCifsInode->clientCanCacheAll = TRUE;
-                                       pCifsInode->clientCanCacheRead = TRUE;
-                                       cFYI(1,("Exclusive Oplock for inode %p",
+                                       pCifsInode->clientCanCacheAll = true;
+                                       pCifsInode->clientCanCacheRead = true;
+                                       cFYI(1, ("Exclusive Oplock inode %p",
                                                newinode));
                                } else if ((oplock & 0xF) == OPLOCK_READ)
-                                       pCifsInode->clientCanCacheRead = TRUE;
+                                       pCifsInode->clientCanCacheRead = true;
                        }
                        write_unlock(&GlobalSMBSeslock);
                }
@@ -322,7 +313,7 @@ int cifs_mknod(struct inode *inode, struct dentry *direntry, int mode,
        struct cifs_sb_info *cifs_sb;
        struct cifsTconInfo *pTcon;
        char *full_path = NULL;
-       struct inode * newinode = NULL;
+       struct inode *newinode = NULL;
 
        if (!old_valid_dev(device_number))
                return -EINVAL;
@@ -335,7 +326,8 @@ int cifs_mknod(struct inode *inode, struct dentry *direntry, int mode,
        full_path = build_path_from_dentry(direntry);
        if (full_path == NULL)
                rc = -ENOMEM;
-       else if (pTcon->ses->capabilities & CAP_UNIX) {
+       else if (pTcon->unix_ext) {
+               mode &= ~current->fs->umask;
                if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID) {
                        rc = CIFSSMBUnixSetPerms(xid, pTcon, full_path,
                                mode, (__u64)current->fsuid,
@@ -365,7 +357,7 @@ int cifs_mknod(struct inode *inode, struct dentry *direntry, int mode,
                if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL) {
                        int oplock = 0;
                        u16 fileHandle;
-                       FILE_ALL_INFO * buf;
+                       FILE_ALL_INFO *buf;
 
                        cFYI(1, ("sfu compat create special file"));
 
@@ -395,7 +387,7 @@ int cifs_mknod(struct inode *inode, struct dentry *direntry, int mode,
                                /* BB Do not bother to decode buf since no
                                   local inode yet to put timestamps in,
                                   but we can reuse it safely */
-                               int bytes_written;
+                               unsigned int bytes_written;
                                struct win_dev *pdev;
                                pdev = (struct win_dev *)buf;
                                if (S_ISCHR(mode)) {
@@ -448,8 +440,7 @@ cifs_lookup(struct inode *parent_dir_inode, struct dentry *direntry,
 
        xid = GetXid();
 
-       cFYI(1,
-            (" parent inode = 0x%p name is: %s and dentry = 0x%p",
+       cFYI(1, (" parent inode = 0x%p name is: %s and dentry = 0x%p",
              parent_dir_inode, direntry->d_name.name, direntry));
 
        /* check whether path exists */
@@ -488,12 +479,12 @@ cifs_lookup(struct inode *parent_dir_inode, struct dentry *direntry,
        cFYI(1,
             (" Full path: %s inode = 0x%p", full_path, direntry->d_inode));
 
-       if (pTcon->ses->capabilities & CAP_UNIX)
+       if (pTcon->unix_ext)
                rc = cifs_get_inode_info_unix(&newInode, full_path,
                                              parent_dir_inode->i_sb, xid);
        else
                rc = cifs_get_inode_info(&newInode, full_path, NULL,
-                                        parent_dir_inode->i_sb, xid);
+                                        parent_dir_inode->i_sb, xid, NULL);
 
        if ((rc == 0) && (newInode != NULL)) {
                if (pTcon->nocase)
@@ -516,12 +507,10 @@ cifs_lookup(struct inode *parent_dir_inode, struct dentry *direntry,
                d_add(direntry, NULL);
        /*      if it was once a directory (but how can we tell?) we could do
                shrink_dcache_parent(direntry); */
-       } else {
-               cERROR(1,("Error 0x%x on cifs_get_inode_info in lookup of %s",
-                          rc, full_path));
-               /* BB special case check for Access Denied - watch security
-               exposure of returning dir info implicitly via different rc
-               if file exists or not but no access BB */
+       } else if (rc != -EACCES) {
+               cERROR(1, ("Unexpected lookup error %d", rc));
+               /* We special case check for Access Denied - since that
+               is a common return code */
        }
 
        kfree(full_path);
@@ -535,9 +524,8 @@ cifs_d_revalidate(struct dentry *direntry, struct nameidata *nd)
        int isValid = 1;
 
        if (direntry->d_inode) {
-               if (cifs_revalidate(direntry)) {
+               if (cifs_revalidate(direntry))
                        return 0;
-               }
        } else {
                cFYI(1, ("neg dentry 0x%p name = %s",
                         direntry, direntry->d_name.name));
@@ -592,7 +580,7 @@ static int cifs_ci_compare(struct dentry *dentry, struct qstr *a,
                 * case take precedence.  If a is not a negative dentry, this
                 * should have no side effects
                 */
-               memcpy((unsigned char *)a->name, b->name, a->len);
+               memcpy(a->name, b->name, a->len);
                return 0;
        }
        return 1;