}
EXPORT_SYMBOL(d_mark_tmpfile);
-void d_mark_tmpfile_name(struct file *file, const struct qstr *name)
+int d_mark_tmpfile_name(struct file *file, const struct qstr *name)
{
struct dentry *dentry = file->f_path.dentry;
char *dname = dentry->d_shortname.string;
- BUG_ON(dname_external(dentry));
- BUG_ON(d_really_is_positive(dentry));
- BUG_ON(!d_unlinked(dentry));
- BUG_ON(name->len > DNAME_INLINE_LEN - 1);
+ if (unlikely(dname_external(dentry) ||
+ d_really_is_positive(dentry) ||
+ !d_unlinked(dentry)))
+ return -EINVAL;
+ if (unlikely(name->len > DNAME_INLINE_LEN - 1))
+ return -ENAMETOOLONG;
+
spin_lock(&dentry->d_parent->d_lock);
spin_lock_nested(&dentry->d_lock, DENTRY_D_LOCK_NESTED);
dentry->__d_name.len = name->len;
dname[name->len] = '\0';
spin_unlock(&dentry->d_lock);
spin_unlock(&dentry->d_parent->d_lock);
+ return 0;
}
EXPORT_SYMBOL(d_mark_tmpfile_name);
#define _CIFSFS_H
#include <linux/hash.h>
+#include <linux/dcache.h>
#define ROOT_I 2
char *cifs_silly_fullpath(struct dentry *dentry);
-#define CIFS_TMPNAME_PREFIX ".__smbfile_tmp"
-#define CIFS_TMPNAME_PREFIX_LEN ((int)sizeof(CIFS_TMPNAME_PREFIX) - 1)
-#define CIFS_TMPNAME_COUNTER_LEN ((int)sizeof(cifs_tmpcounter) * 2)
-#define CIFS_TMPNAME_LEN \
- (CIFS_TMPNAME_PREFIX_LEN + CIFS_TMPNAME_COUNTER_LEN)
-
-#define CIFS_SILLYNAME_PREFIX ".__smbfile_silly"
-#define CIFS_SILLYNAME_PREFIX_LEN ((int)sizeof(CIFS_SILLYNAME_PREFIX) - 1)
-#define CIFS_SILLYNAME_COUNTER_LEN ((int)sizeof(cifs_sillycounter) * 2)
-#define CIFS_SILLYNAME_LEN \
- (CIFS_SILLYNAME_PREFIX_LEN + CIFS_SILLYNAME_COUNTER_LEN)
+#define CIFS_TMPNAME_PREFIX ".__smbfile_tmp"
+#define CIFS_TMPNAME_LEN (DNAME_INLINE_LEN - 1)
+
+#define CIFS_SILLYNAME_PREFIX ".__smbfile_silly"
+#define CIFS_SILLYNAME_LEN (DNAME_INLINE_LEN - 1)
#ifdef CONFIG_CIFS_NFSD_EXPORT
extern const struct export_operations cifs_export_ops;
{
struct dentry *dentry = file->f_path.dentry;
struct cifs_sb_info *cifs_sb = CIFS_SB(dir);
+ size_t namesize = CIFS_TMPNAME_LEN + 1;
char *path __free(kfree) = NULL, *name;
unsigned int oflags = file->f_flags;
- size_t size = CIFS_TMPNAME_LEN + 1;
int retries = 0, max_retries = 16;
struct TCP_Server_Info *server;
struct cifs_pending_open open;
struct inode *inode;
unsigned int xid;
__u32 oplock;
+ int namelen;
int rc;
if (unlikely(cifs_forced_shutdown(cifs_sb)))
server->ops->new_lease_key(&fid);
cifs_add_pending_open(&fid, tlink, &open);
- path = alloc_parent_path(dentry, size - 1);
+ path = alloc_parent_path(dentry, namesize - 1);
if (IS_ERR(path)) {
cifs_del_pending_open(&open);
rc = PTR_ERR(path);
name = path + strlen(path);
do {
- scnprintf(name, size,
- CIFS_TMPNAME_PREFIX "%0*x",
- CIFS_TMPNAME_COUNTER_LEN,
- atomic_inc_return(&cifs_tmpcounter));
+ /* Append tmpfile name to @path */
+ namelen = scnprintf(name, namesize, CIFS_TMPNAME_PREFIX "%x",
+ atomic_inc_return(&cifs_tmpcounter));
rc = __cifs_do_create(dir, dentry, path, xid, tlink, oflags,
mode, &oplock, &fid, NULL, &inode);
if (!rc) {
+ rc = d_mark_tmpfile_name(file, &QSTR_LEN(name, namelen));
+ if (rc) {
+ cifs_dbg(VFS | ONCE, "%s: failed to set filename in dentry: %d\n",
+ __func__, rc);
+ rc = -EISDIR;
+ iput(inode);
+ goto err_open;
+ }
set_nlink(inode, 0);
mark_inode_dirty(inode);
- d_mark_tmpfile_name(file, &QSTR_LEN(name, size - 1));
d_instantiate(dentry, inode);
break;
}
do {
dput(sdentry);
- scnprintf(name, namesize,
- CIFS_SILLYNAME_PREFIX "%0*x",
- CIFS_SILLYNAME_COUNTER_LEN,
+ scnprintf(name, namesize, CIFS_SILLYNAME_PREFIX "%x",
atomic_inc_return(&cifs_sillycounter));
sdentry = lookup_noperm(&QSTR(name), dentry->d_parent);
if (IS_ERR(sdentry))