 int cifs_rmdir(struct inode *inode, struct dentry *direntry) { int rc = 0; int xid; struct cifs_sb_info *cifs_sb; struct cifsTconInfo *pTcon; char *full_path = NULL; struct cifsInodeInfo *cifsInode;  cFYI(1, ("cifs_rmdir, inode = 0x%p with ", inode));  xid = GetXid();  cifs_sb = CIFS_SB(inode->i_sb); pTcon = cifs_sb->tcon;  down(&inode->i_sb->s_vfs_rename_sem); full_path = build_path_from_dentry(direntry); up(&inode->i_sb->s_vfs_rename_sem); if (full_path == NULL) { FreeXid(xid); return -ENOMEM; }  rc = CIFSSMBRmDir(xid, pTcon, full_path, cifs_sb->local_nls, cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);  if (!rc) { inode->i_nlink--; i_size_write(direntry->d_inode,0); direntry->d_inode->i_nlink = 0; }  cifsInode = CIFS_I(direntry->d_inode); cifsInode->time = 0;	/* force revalidate to go get info when needed */ direntry->d_inode->i_ctime = inode->i_ctime = inode->i_mtime = current_fs_time(inode->i_sb);  kfree(full_path); FreeXid(xid); return rc; }  int cifs_rename(struct inode *source_inode, struct dentry *source_direntry, struct inode *target_inode, struct dentry *target_direntry) { char *fromName; char *toName; struct cifs_sb_info *cifs_sb_source; struct cifs_sb_info *cifs_sb_target; struct cifsTconInfo *pTcon; int xid; int rc = 0;  xid = GetXid();  cifs_sb_target = CIFS_SB(target_inode->i_sb); cifs_sb_source = CIFS_SB(source_inode->i_sb); pTcon = cifs_sb_source->tcon;  if (pTcon != cifs_sb_target->tcon) { FreeXid(xid); return -EXDEV;	/* BB actually could be allowed if same server, but different share. Might eventually add support for this */ }  /* we already  have the rename sem so we do not need to grab it again here to protect the path integrity */ fromName = build_path_from_dentry(source_direntry); toName = build_path_from_dentry(target_direntry); if ((fromName == NULL) || (toName == NULL)) { rc = -ENOMEM; goto cifs_rename_exit; }  rc = CIFSSMBRename(xid, pTcon, fromName, toName, cifs_sb_source->local_nls, cifs_sb_source->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); if (rc == -EEXIST) { /* check if they are the same file because rename of hardlinked files is a noop */ FILE_UNIX_BASIC_INFO *info_buf_source; FILE_UNIX_BASIC_INFO *info_buf_target;  info_buf_source = kmalloc(2 * sizeof(FILE_UNIX_BASIC_INFO), GFP_KERNEL); if (info_buf_source != NULL) { info_buf_target = info_buf_source + 1; rc = CIFSSMBUnixQPathInfo(xid, pTcon, fromName, info_buf_source, cifs_sb_source->local_nls, cifs_sb_source->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); if (rc == 0) { rc = CIFSSMBUnixQPathInfo(xid, pTcon, toName, info_buf_target, cifs_sb_target->local_nls, /* remap based on source sb */ cifs_sb_source->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); } if ((rc == 0) && (info_buf_source->UniqueId == info_buf_target->UniqueId)) { /* do not rename since the files are hardlinked which is a noop */ } else { /* we either can not tell the files are hardlinked (as with Windows servers) or files are not hardlinked so delete the target manually before renaming to follow POSIX rather than Windows semantics */ cifs_unlink(target_inode, target_direntry); rc = CIFSSMBRename(xid, pTcon, fromName, toName, cifs_sb_source->local_nls, cifs_sb_source->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); } kfree(info_buf_source); } /* if we can not get memory just leave rc as EEXIST */ }  if (rc) { cFYI(1, ("rename rc %d", rc)); }  if ((rc == -EIO) || (rc == -EEXIST)) { int oplock = FALSE; __u16 netfid;  /* BB FIXME Is Generic Read correct for rename? */ /* if renaming directory - we should not say CREATE_NOT_DIR, need to test renaming open directory, also GENERIC_READ might not right be right access to request */ rc = CIFSSMBOpen(xid, pTcon, fromName, FILE_OPEN, GENERIC_READ, CREATE_NOT_DIR, &netfid, &oplock, NULL, cifs_sb_source->local_nls, cifs_sb_source->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); if (rc==0) { CIFSSMBRenameOpenFile(xid, pTcon, netfid, toName, cifs_sb_source->local_nls, cifs_sb_source->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); CIFSSMBClose(xid, pTcon, netfid); } }  cifs_rename_exit: kfree(fromName); kfree(toName); FreeXid(xid); return rc; }  int cifs_revalidate(struct dentry *direntry) { int xid; int rc = 0; char *full_path; struct cifs_sb_info *cifs_sb; struct cifsInodeInfo *cifsInode; loff_t local_size; struct timespec local_mtime; int invalidate_inode = FALSE;  if (direntry->d_inode == NULL) return -ENOENT;  cifsInode = CIFS_I(direntry->d_inode);  if (cifsInode == NULL) return -ENOENT;  /* no sense revalidating inode info on file that no one can write */ if (CIFS_I(direntry->d_inode)->clientCanCacheRead) return rc;  xid = GetXid();  cifs_sb = CIFS_SB(direntry->d_sb);  /* can not safely grab the rename sem here if rename calls revalidate since that would deadlock */ full_path = build_path_from_dentry(direntry); if (full_path == NULL) { FreeXid(xid); return -ENOMEM; } cFYI(1, ("Revalidate: %s inode 0x%p count %d dentry: 0x%p d_time %ld " "jiffies %ld", full_path, direntry->d_inode, direntry->d_inode->i_count.counter, direntry, direntry->d_time, jiffies));  if (cifsInode->time == 0) { /* was set to zero previously to force revalidate */ } else if (time_before(jiffies, cifsInode->time + HZ) && lookupCacheEnabled) { if ((S_ISREG(direntry->d_inode->i_mode) == 0) || (direntry->d_inode->i_nlink == 1)) { kfree(full_path); FreeXid(xid); return rc; } else { cFYI(1, ("Have to revalidate file due to hardlinks")); } }  /* save mtime and size */ local_mtime = direntry->d_inode->i_mtime; local_size = direntry->d_inode->i_size;  if (cifs_sb->tcon->ses->capabilities & CAP_UNIX) { rc = cifs_get_inode_info_unix(&direntry->d_inode, full_path, direntry->d_sb,xid); if (rc) { cFYI(1, ("error on getting revalidate info %d", rc)); /*			if (rc != -ENOENT) rc = 0; */	/* BB should we cache info on certain errors? */ } } else { rc = cifs_get_inode_info(&direntry->d_inode, full_path, NULL, direntry->d_sb,xid); if (rc) { cFYI(1, ("error on getting revalidate info %d", rc)); /*			if (rc != -ENOENT) rc = 0; */	/* BB should we cache info on certain errors? */ } } /* should we remap certain errors, access denied?, to zero */  /* if not oplocked, we invalidate inode pages if mtime or file size had changed on server */  if (timespec_equal(&local_mtime,&direntry->d_inode->i_mtime) && (local_size == direntry->d_inode->i_size)) { cFYI(1, ("cifs_revalidate - inode unchanged")); } else { /* file may have changed on server */ if (cifsInode->clientCanCacheRead) { /* no need to invalidate inode pages since we were the only ones who could have modified the file and the server copy is staler than ours */ } else { invalidate_inode = TRUE; } }  /* can not grab this sem since kernel filesys locking documentation indicates i_sem may be taken by the kernel on lookup and rename which could deadlock if we grab the i_sem here as well */ /*	down(&direntry->d_inode->i_sem);*/ /* need to write out dirty pages here  */ if (direntry->d_inode->i_mapping) { /* do we need to lock inode until after invalidate completes below? */ filemap_fdatawrite(direntry->d_inode->i_mapping); } if (invalidate_inode) { /* shrink_dcache not necessary now that cifs dentry ops are exported for negative dentries */ /*		if(S_ISDIR(direntry->d_inode->i_mode)) shrink_dcache_parent(direntry); */ if (S_ISREG(direntry->d_inode->i_mode)) { if (direntry->d_inode->i_mapping) filemap_fdatawait(direntry->d_inode->i_mapping); /* may eventually have to do this for open files too */ if (list_empty(&(cifsInode->openFileList))) { /* changed on server - flush read ahead pages */ cFYI(1, ("Invalidating read ahead data on " "closed file")); invalidate_remote_inode(direntry->d_inode); } } } /*	up(&direntry->d_inode->i_sem); */  kfree(full_path); FreeXid(xid); return rc; }  int cifs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat) { int err = cifs_revalidate(dentry); if (!err) generic_fillattr(dentry->d_inode, stat); return err; }  static int cifs_truncate_page(struct address_space *mapping, loff_t from) { pgoff_t index = from >> PAGE_CACHE_SHIFT; unsigned offset = from & (PAGE_CACHE_SIZE - 1); struct page *page; char *kaddr; int rc = 0;  page = grab_cache_page(mapping, index); if (!page) return -ENOMEM;  kaddr = kmap_atomic(page, KM_USER0); memset(kaddr + offset, 0, PAGE_CACHE_SIZE - offset); flush_dcache_page(page); kunmap_atomic(kaddr, KM_USER0); unlock_page(page); page_cache_release(page); return rc; }  int cifs_setattr(struct dentry *direntry, struct iattr *attrs) { int xid; struct cifs_sb_info *cifs_sb; struct cifsTconInfo *pTcon; char *full_path = NULL; int rc = -EACCES; struct cifsFileInfo *open_file = NULL; FILE_BASIC_INFO time_buf; int set_time = FALSE; __u64 mode = 0xFFFFFFFFFFFFFFFFULL; __u64 uid = 0xFFFFFFFFFFFFFFFFULL; __u64 gid = 0xFFFFFFFFFFFFFFFFULL; struct cifsInodeInfo *cifsInode;  xid = GetXid();  cFYI(1, ("In cifs_setattr, name = %s attrs->iavalid 0x%x ", direntry->d_name.name, attrs->ia_valid));  cifs_sb = CIFS_SB(direntry->d_inode->i_sb); pTcon = cifs_sb->tcon;  if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_PERM == 0) { /* check if we have permission to change attrs */ rc = inode_change_ok(direntry->d_inode, attrs); if(rc < 0) { FreeXid(xid); return rc; } else rc = 0; }  down(&direntry->d_sb->s_vfs_rename_sem); full_path = build_path_from_dentry(direntry); up(&direntry->d_sb->s_vfs_rename_sem); if (full_path == NULL) { FreeXid(xid); return -ENOMEM; } cifsInode = CIFS_I(direntry->d_inode);  /* BB check if we need to refresh inode from server now ? BB */  /* need to flush data before changing file size on server */ filemap_fdatawrite(direntry->d_inode->i_mapping); filemap_fdatawait(direntry->d_inode->i_mapping);  if (attrs->ia_valid & ATTR_SIZE) { /* To avoid spurious oplock breaks from server, in the case of inodes that we already have open, avoid doing path based setting of file size if we can do it by handle. This keeps our caching token (oplock) and avoids timeouts when the local oplock break takes longer to flush writebehind data than the SMB timeout for the SetPathInfo request would allow */ open_file = find_writable_file(cifsInode); if (open_file) { __u16 nfid = open_file->netfid; __u32 npid = open_file->pid; rc = CIFSSMBSetFileSize(xid, pTcon, attrs->ia_size, nfid, npid, FALSE); atomic_dec(&open_file->wrtPending); cFYI(1,("SetFSize for attrs rc = %d", rc)); if(rc == -EINVAL) { int bytes_written; rc = CIFSSMBWrite(xid, pTcon, nfid, 0, attrs->ia_size, &bytes_written, NULL, NULL, 1 /* 45 seconds */); cFYI(1,("Wrt seteof rc %d", rc)); } } else rc = -EINVAL;  if (rc != 0) { /* Set file size by pathname rather than by handle either because no valid, writeable file handle for it was found or because there was an error setting it by handle */ rc = CIFSSMBSetEOF(xid, pTcon, full_path, attrs->ia_size, FALSE, cifs_sb->local_nls, cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); cFYI(1, ("SetEOF by path (setattrs) rc = %d", rc)); if(rc == -EINVAL) { __u16 netfid; int oplock = FALSE;  rc = SMBLegacyOpen(xid, pTcon, full_path, FILE_OPEN, SYNCHRONIZE | FILE_WRITE_ATTRIBUTES, CREATE_NOT_DIR, &netfid, &oplock, NULL, cifs_sb->local_nls, cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); if (rc==0) { int bytes_written; rc = CIFSSMBWrite(xid, pTcon, netfid, 0, attrs->ia_size, &bytes_written, NULL, NULL, 1 /* 45 sec */); cFYI(1,("wrt seteof rc %d",rc)); CIFSSMBClose(xid, pTcon, netfid); }  } }  /* Server is ok setting allocation size implicitly - no need to call: CIFSSMBSetEOF(xid, pTcon, full_path, attrs->ia_size, TRUE, cifs_sb->local_nls); */  if (rc == 0) { rc = vmtruncate(direntry->d_inode, attrs->ia_size); cifs_truncate_page(direntry->d_inode->i_mapping, direntry->d_inode->i_size); } else goto cifs_setattr_exit; } if (attrs->ia_valid & ATTR_UID) { cFYI(1, ("UID changed to %d", attrs->ia_uid)); uid = attrs->ia_uid; } if (attrs->ia_valid & ATTR_GID) { cFYI(1, ("GID changed to %d", attrs->ia_gid)); gid = attrs->ia_gid; }  time_buf.Attributes = 0; if (attrs->ia_valid & ATTR_MODE) { cFYI(1, ("Mode changed to 0x%x", attrs->ia_mode)); mode = attrs->ia_mode; }  if ((cifs_sb->tcon->ses->capabilities & CAP_UNIX) && (attrs->ia_valid & (ATTR_MODE | ATTR_GID | ATTR_UID))) rc = CIFSSMBUnixSetPerms(xid, pTcon, full_path, mode, uid, gid, 0 /* dev_t */, cifs_sb->local_nls, cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); else if (attrs->ia_valid & ATTR_MODE) { rc = 0; if ((mode & S_IWUGO) == 0) /* not writeable */ { if ((cifsInode->cifsAttrs & ATTR_READONLY) == 0) time_buf.Attributes = cpu_to_le32(cifsInode->cifsAttrs | ATTR_READONLY); } else if ((mode & S_IWUGO) == S_IWUGO) { if (cifsInode->cifsAttrs & ATTR_READONLY) time_buf.Attributes = cpu_to_le32(cifsInode->cifsAttrs & (~ATTR_READONLY)); } /* BB to be implemented - via Windows security descriptors or streams */ /* CIFSSMBWinSetPerms(xid, pTcon, full_path, mode, uid, gid, cifs_sb->local_nls); */ }  if (attrs->ia_valid & ATTR_ATIME) { set_time = TRUE; time_buf.LastAccessTime = cpu_to_le64(cifs_UnixTimeToNT(attrs->ia_atime)); } else time_buf.LastAccessTime = 0;  if (attrs->ia_valid & ATTR_MTIME) { set_time = TRUE; time_buf.LastWriteTime = cpu_to_le64(cifs_UnixTimeToNT(attrs->ia_mtime)); } else time_buf.LastWriteTime = 0; /* Do not set ctime explicitly unless other time stamps are changed explicitly (i.e. by utime() since we would then have a mix of client and server times */  if (set_time && (attrs->ia_valid & ATTR_CTIME)) { set_time = TRUE; /* Although Samba throws this field away it may be useful to Windows - but we do not want to set ctime unless some other timestamp is changing */ cFYI(1, ("CIFS - CTIME changed ")); time_buf.ChangeTime = cpu_to_le64(cifs_UnixTimeToNT(attrs->ia_ctime)); } else time_buf.ChangeTime = 0;  if (set_time || time_buf.Attributes) { time_buf.CreationTime = 0;	/* do not change */ /* In the future we should experiment - try setting timestamps via Handle (SetFileInfo) instead of by path */ if (!(pTcon->ses->flags & CIFS_SES_NT4)) rc = CIFSSMBSetTimes(xid, pTcon, full_path, &time_buf, cifs_sb->local_nls, cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); else rc = -EOPNOTSUPP;  if (rc == -EOPNOTSUPP) { int oplock = FALSE; __u16 netfid;  cFYI(1, ("calling SetFileInfo since SetPathInfo for " "times not supported by this server")); /* BB we could scan to see if we already have it open and pass in pid of opener to function */ rc = CIFSSMBOpen(xid, pTcon, full_path, FILE_OPEN, SYNCHRONIZE | FILE_WRITE_ATTRIBUTES, CREATE_NOT_DIR, &netfid, &oplock, NULL, cifs_sb->local_nls, cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); if (rc==0) { rc = CIFSSMBSetFileTimes(xid, pTcon, &time_buf, netfid); CIFSSMBClose(xid, pTcon, netfid); } else { /* BB For even older servers we could convert time_buf into old DOS style which uses two second granularity */  /* rc = CIFSSMBSetTimesLegacy(xid, pTcon, full_path, &time_buf, cifs_sb->local_nls); */ } } /* Even if error on time set, no sense failing the call if the server would set the time to a reasonable value anyway, and this check ensures that we are not being called from sys_utimes in which case we ought to fail the call back to the user when the server rejects the call */ if((rc) && (attrs->ia_valid && (ATTR_MODE | ATTR_GID | ATTR_UID | ATTR_SIZE))) rc = 0; }  /* do not need local check to inode_check_ok since the server does that */ if (!rc) rc = inode_setattr(direntry->d_inode, attrs); cifs_setattr_exit: kfree(full_path); FreeXid(xid); return rc; }  void cifs_delete_inode(struct inode *inode) { cFYI(1, ("In cifs_delete_inode, inode = 0x%p ", inode)); /* may have to add back in if and when safe distributed caching of directories added e.g. via FindNotify */ } 
int cifs_mkdir(struct inode *inode, struct dentry *direntry, int mode){	int rc = 0;	int xid;	struct cifs_sb_info *cifs_sb;	struct cifsTconInfo *pTcon;	char *full_path = NULL;	struct inode *newinode = NULL;	cFYI(1, ("In cifs_mkdir, mode = 0x%x inode = 0x%p ", mode, inode));	xid = GetXid();	cifs_sb = CIFS_SB(inode->i_sb);	pTcon = cifs_sb->tcon;	down(&inode->i_sb->s_vfs_rename_sem);	full_path = build_path_from_dentry(direntry);	up(&inode->i_sb->s_vfs_rename_sem);	if (full_path == NULL) {		FreeXid(xid);		return -ENOMEM;	}	/* BB add setting the equivalent of mode via CreateX w/ACLs */	rc = CIFSSMBMkDir(xid, pTcon, full_path, cifs_sb->local_nls,			  cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);	if (rc) {		cFYI(1, ("cifs_mkdir returned 0x%x ", rc));		d_drop(direntry);	} else {		inode->i_nlink++;		if (pTcon->ses->capabilities & CAP_UNIX)			rc = cifs_get_inode_info_unix(&newinode, full_path,						      inode->i_sb,xid);		else			rc = cifs_get_inode_info(&newinode, full_path, NULL,						 inode->i_sb,xid);		if (pTcon->nocase)			direntry->d_op = &cifs_ci_dentry_ops;		else			direntry->d_op = &cifs_dentry_ops;		d_instantiate(direntry, newinode);		if (direntry->d_inode)			direntry->d_inode->i_nlink = 2;		if (cifs_sb->tcon->ses->capabilities & CAP_UNIX)			if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID) {				CIFSSMBUnixSetPerms(xid, pTcon, full_path,						    mode,						    (__u64)current->euid,						    (__u64)current->egid,						    0 /* dev_t */,						    cifs_sb->local_nls,						    cifs_sb->mnt_cifs_flags &						    CIFS_MOUNT_MAP_SPECIAL_CHR);			} else {				CIFSSMBUnixSetPerms(xid, pTcon, full_path,						    mode, (__u64)-1,						    (__u64)-1, 0 /* dev_t */,						    cifs_sb->local_nls,						    cifs_sb->mnt_cifs_flags & 						    CIFS_MOUNT_MAP_SPECIAL_CHR);			}		else {			/* BB to be implemented via Windows secrty descriptors			   eg CIFSSMBWinSetPerms(xid, pTcon, full_path, mode,						 -1, -1, local_nls); */		}	}	kfree(full_path);	FreeXid(xid);	return rc;}
4520	/local/tlutelli/issta_data/temp/c/2005_temp/2005/4520/6473a559c336d5c407f9df412ca2f55357767ff8/inode.c/clean/fs/cifs/inode.c