forked from Minki/linux
Allow mknod and mkfifo on SMB2/SMB3 mounts
The "sfu" mount option did not work on SMB2/SMB3 mounts. With these changes when the "sfu" mount option is passed in on an smb2/smb2.1/smb3 mount the client can emulate (and recognize) fifo and device (character and device files). In addition the "sfu" mount option should not conflict with "mfsymlinks" (symlink emulation) as we will never create "sfu" style symlinks, but using "sfu" mount option will allow us to recognize existing symlinks, created with Microsoft "Services for Unix" (SFU and SUA). To enable the "sfu" mount option for SMB2/SMB3 the calling syntax of the generic cifs/smb2/smb3 sync_read and sync_write protocol dependent function needed to be changed (we don't have a file struct in all cases), but this actually ended up simplifying the code a little. Signed-off-by: Steve French <smfrench@gmail.com>
This commit is contained in:
parent
7332297909
commit
db8b631d4b
@ -323,11 +323,11 @@ struct smb_version_operations {
|
||||
int (*async_writev)(struct cifs_writedata *,
|
||||
void (*release)(struct kref *));
|
||||
/* sync read from the server */
|
||||
int (*sync_read)(const unsigned int, struct cifsFileInfo *,
|
||||
int (*sync_read)(const unsigned int, struct cifs_fid *,
|
||||
struct cifs_io_parms *, unsigned int *, char **,
|
||||
int *);
|
||||
/* sync write to the server */
|
||||
int (*sync_write)(const unsigned int, struct cifsFileInfo *,
|
||||
int (*sync_write)(const unsigned int, struct cifs_fid *,
|
||||
struct cifs_io_parms *, unsigned int *, struct kvec *,
|
||||
unsigned long);
|
||||
/* open dir, start readdir */
|
||||
|
@ -3239,10 +3239,20 @@ void cifs_setup_cifs_sb(struct smb_vol *pvolume_info,
|
||||
}
|
||||
if (pvolume_info->mfsymlinks) {
|
||||
if (pvolume_info->sfu_emul) {
|
||||
cifs_dbg(VFS, "mount option mfsymlinks ignored if sfu mount option is used\n");
|
||||
} else {
|
||||
cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_MF_SYMLINKS;
|
||||
/*
|
||||
* Our SFU ("Services for Unix" emulation does not allow
|
||||
* creating symlinks but does allow reading existing SFU
|
||||
* symlinks (it does allow both creating and reading SFU
|
||||
* style mknod and FIFOs though). When "mfsymlinks" and
|
||||
* "sfu" are both enabled at the same time, it allows
|
||||
* reading both types of symlinks, but will only create
|
||||
* them with mfsymlinks format. This allows better
|
||||
* Apple compatibility (probably better for Samba too)
|
||||
* while still recognizing old Windows style symlinks.
|
||||
*/
|
||||
cifs_dbg(VFS, "mount options mfsymlinks and sfu both enabled\n");
|
||||
}
|
||||
cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_MF_SYMLINKS;
|
||||
}
|
||||
|
||||
if ((pvolume_info->cifs_acl) && (pvolume_info->dynperm))
|
||||
|
@ -577,12 +577,13 @@ int cifs_mknod(struct inode *inode, struct dentry *direntry, umode_t mode,
|
||||
struct cifs_io_parms io_parms;
|
||||
char *full_path = NULL;
|
||||
struct inode *newinode = NULL;
|
||||
int oplock = 0;
|
||||
__u32 oplock = 0;
|
||||
struct cifs_fid fid;
|
||||
struct cifs_open_parms oparms;
|
||||
FILE_ALL_INFO *buf = NULL;
|
||||
unsigned int bytes_written;
|
||||
struct win_dev *pdev;
|
||||
struct kvec iov[2];
|
||||
|
||||
if (!old_valid_dev(device_number))
|
||||
return -EINVAL;
|
||||
@ -658,7 +659,11 @@ int cifs_mknod(struct inode *inode, struct dentry *direntry, umode_t mode,
|
||||
oparms.fid = &fid;
|
||||
oparms.reconnect = false;
|
||||
|
||||
rc = CIFS_open(xid, &oparms, &oplock, buf);
|
||||
if (tcon->ses->server->oplocks)
|
||||
oplock = REQ_OPLOCK;
|
||||
else
|
||||
oplock = 0;
|
||||
rc = tcon->ses->server->ops->open(xid, &oparms, &oplock, buf);
|
||||
if (rc)
|
||||
goto mknod_out;
|
||||
|
||||
@ -668,25 +673,26 @@ int cifs_mknod(struct inode *inode, struct dentry *direntry, umode_t mode,
|
||||
*/
|
||||
|
||||
pdev = (struct win_dev *)buf;
|
||||
io_parms.netfid = fid.netfid;
|
||||
io_parms.pid = current->tgid;
|
||||
io_parms.tcon = tcon;
|
||||
io_parms.offset = 0;
|
||||
io_parms.length = sizeof(struct win_dev);
|
||||
iov[1].iov_base = buf;
|
||||
iov[1].iov_len = sizeof(struct win_dev);
|
||||
if (S_ISCHR(mode)) {
|
||||
memcpy(pdev->type, "IntxCHR", 8);
|
||||
pdev->major = cpu_to_le64(MAJOR(device_number));
|
||||
pdev->minor = cpu_to_le64(MINOR(device_number));
|
||||
rc = CIFSSMBWrite(xid, &io_parms, &bytes_written, (char *)pdev,
|
||||
NULL, 0);
|
||||
rc = tcon->ses->server->ops->sync_write(xid, &fid, &io_parms,
|
||||
&bytes_written, iov, 1);
|
||||
} else if (S_ISBLK(mode)) {
|
||||
memcpy(pdev->type, "IntxBLK", 8);
|
||||
pdev->major = cpu_to_le64(MAJOR(device_number));
|
||||
pdev->minor = cpu_to_le64(MINOR(device_number));
|
||||
rc = CIFSSMBWrite(xid, &io_parms, &bytes_written, (char *)pdev,
|
||||
NULL, 0);
|
||||
rc = tcon->ses->server->ops->sync_write(xid, &fid, &io_parms,
|
||||
&bytes_written, iov, 1);
|
||||
} /* else if (S_ISFIFO) */
|
||||
CIFSSMBClose(xid, tcon, fid.netfid);
|
||||
tcon->ses->server->ops->close(xid, tcon, &fid);
|
||||
d_drop(direntry);
|
||||
|
||||
/* FIXME: add code here to set EAs */
|
||||
|
@ -1687,8 +1687,8 @@ cifs_write(struct cifsFileInfo *open_file, __u32 pid, const char *write_data,
|
||||
io_parms.tcon = tcon;
|
||||
io_parms.offset = *offset;
|
||||
io_parms.length = len;
|
||||
rc = server->ops->sync_write(xid, open_file, &io_parms,
|
||||
&bytes_written, iov, 1);
|
||||
rc = server->ops->sync_write(xid, &open_file->fid,
|
||||
&io_parms, &bytes_written, iov, 1);
|
||||
}
|
||||
if (rc || (bytes_written == 0)) {
|
||||
if (total_written)
|
||||
@ -3206,7 +3206,7 @@ cifs_read(struct file *file, char *read_data, size_t read_size, loff_t *offset)
|
||||
io_parms.tcon = tcon;
|
||||
io_parms.offset = *offset;
|
||||
io_parms.length = current_read_size;
|
||||
rc = server->ops->sync_read(xid, open_file, &io_parms,
|
||||
rc = server->ops->sync_read(xid, &open_file->fid, &io_parms,
|
||||
&bytes_read, &cur_offset,
|
||||
&buf_type);
|
||||
} while (rc == -EAGAIN);
|
||||
|
@ -412,7 +412,7 @@ cifs_sfu_type(struct cifs_fattr *fattr, const char *path,
|
||||
struct cifs_sb_info *cifs_sb, unsigned int xid)
|
||||
{
|
||||
int rc;
|
||||
int oplock = 0;
|
||||
__u32 oplock;
|
||||
struct tcon_link *tlink;
|
||||
struct cifs_tcon *tcon;
|
||||
struct cifs_fid fid;
|
||||
@ -451,8 +451,13 @@ cifs_sfu_type(struct cifs_fattr *fattr, const char *path,
|
||||
oparms.fid = &fid;
|
||||
oparms.reconnect = false;
|
||||
|
||||
rc = CIFS_open(xid, &oparms, &oplock, NULL);
|
||||
if (tcon->ses->server->oplocks)
|
||||
oplock = REQ_OPLOCK;
|
||||
else
|
||||
oplock = 0;
|
||||
rc = tcon->ses->server->ops->open(xid, &oparms, &oplock, NULL);
|
||||
if (rc) {
|
||||
cifs_dbg(FYI, "check sfu type of %s, open rc = %d\n", path, rc);
|
||||
cifs_put_tlink(tlink);
|
||||
return rc;
|
||||
}
|
||||
@ -464,7 +469,8 @@ cifs_sfu_type(struct cifs_fattr *fattr, const char *path,
|
||||
io_parms.offset = 0;
|
||||
io_parms.length = 24;
|
||||
|
||||
rc = CIFSSMBRead(xid, &io_parms, &bytes_read, &pbuf, &buf_type);
|
||||
rc = tcon->ses->server->ops->sync_read(xid, &fid, &io_parms,
|
||||
&bytes_read, &pbuf, &buf_type);
|
||||
if ((rc == 0) && (bytes_read >= 8)) {
|
||||
if (memcmp("IntxBLK", pbuf, 8) == 0) {
|
||||
cifs_dbg(FYI, "Block device\n");
|
||||
@ -504,7 +510,8 @@ cifs_sfu_type(struct cifs_fattr *fattr, const char *path,
|
||||
fattr->cf_dtype = DT_REG;
|
||||
rc = -EOPNOTSUPP; /* or some unknown SFU type */
|
||||
}
|
||||
CIFSSMBClose(xid, tcon, fid.netfid);
|
||||
|
||||
tcon->ses->server->ops->close(xid, tcon, &fid);
|
||||
cifs_put_tlink(tlink);
|
||||
return rc;
|
||||
}
|
||||
|
@ -749,21 +749,21 @@ cifs_flush_file(const unsigned int xid, struct cifs_tcon *tcon,
|
||||
}
|
||||
|
||||
static int
|
||||
cifs_sync_read(const unsigned int xid, struct cifsFileInfo *cfile,
|
||||
cifs_sync_read(const unsigned int xid, struct cifs_fid *pfid,
|
||||
struct cifs_io_parms *parms, unsigned int *bytes_read,
|
||||
char **buf, int *buf_type)
|
||||
{
|
||||
parms->netfid = cfile->fid.netfid;
|
||||
parms->netfid = pfid->netfid;
|
||||
return CIFSSMBRead(xid, parms, bytes_read, buf, buf_type);
|
||||
}
|
||||
|
||||
static int
|
||||
cifs_sync_write(const unsigned int xid, struct cifsFileInfo *cfile,
|
||||
cifs_sync_write(const unsigned int xid, struct cifs_fid *pfid,
|
||||
struct cifs_io_parms *parms, unsigned int *written,
|
||||
struct kvec *iov, unsigned long nr_segs)
|
||||
{
|
||||
|
||||
parms->netfid = cfile->fid.netfid;
|
||||
parms->netfid = pfid->netfid;
|
||||
return CIFSSMBWrite2(xid, parms, written, iov, nr_segs);
|
||||
}
|
||||
|
||||
|
@ -711,23 +711,23 @@ smb2_read_data_length(char *buf)
|
||||
|
||||
|
||||
static int
|
||||
smb2_sync_read(const unsigned int xid, struct cifsFileInfo *cfile,
|
||||
smb2_sync_read(const unsigned int xid, struct cifs_fid *pfid,
|
||||
struct cifs_io_parms *parms, unsigned int *bytes_read,
|
||||
char **buf, int *buf_type)
|
||||
{
|
||||
parms->persistent_fid = cfile->fid.persistent_fid;
|
||||
parms->volatile_fid = cfile->fid.volatile_fid;
|
||||
parms->persistent_fid = pfid->persistent_fid;
|
||||
parms->volatile_fid = pfid->volatile_fid;
|
||||
return SMB2_read(xid, parms, bytes_read, buf, buf_type);
|
||||
}
|
||||
|
||||
static int
|
||||
smb2_sync_write(const unsigned int xid, struct cifsFileInfo *cfile,
|
||||
smb2_sync_write(const unsigned int xid, struct cifs_fid *pfid,
|
||||
struct cifs_io_parms *parms, unsigned int *written,
|
||||
struct kvec *iov, unsigned long nr_segs)
|
||||
{
|
||||
|
||||
parms->persistent_fid = cfile->fid.persistent_fid;
|
||||
parms->volatile_fid = cfile->fid.volatile_fid;
|
||||
parms->persistent_fid = pfid->persistent_fid;
|
||||
parms->volatile_fid = pfid->volatile_fid;
|
||||
return SMB2_write(xid, parms, written, iov, nr_segs);
|
||||
}
|
||||
|
||||
|
@ -1098,6 +1098,8 @@ SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms, __le16 *path,
|
||||
|
||||
if (oparms->create_options & CREATE_OPTION_READONLY)
|
||||
file_attributes |= ATTR_READONLY;
|
||||
if (oparms->create_options & CREATE_OPTION_SPECIAL)
|
||||
file_attributes |= ATTR_SYSTEM;
|
||||
|
||||
req->ImpersonationLevel = IL_IMPERSONATION;
|
||||
req->DesiredAccess = cpu_to_le32(oparms->desired_access);
|
||||
|
Loading…
Reference in New Issue
Block a user