Skip to content

Commit db8b631

Browse files
committed
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>
1 parent 7332297 commit db8b631

8 files changed

Lines changed: 55 additions & 30 deletions

File tree

‎fs/cifs/cifsglob.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,11 +323,11 @@ struct smb_version_operations {
323323
int (*async_writev)(struct cifs_writedata *,
324324
void (*release)(struct kref *));
325325
/* sync read from the server */
326-
int (*sync_read)(const unsigned int, struct cifsFileInfo *,
326+
int (*sync_read)(const unsigned int, struct cifs_fid *,
327327
struct cifs_io_parms *, unsigned int *, char **,
328328
int *);
329329
/* sync write to the server */
330-
int (*sync_write)(const unsigned int, struct cifsFileInfo *,
330+
int (*sync_write)(const unsigned int, struct cifs_fid *,
331331
struct cifs_io_parms *, unsigned int *, struct kvec *,
332332
unsigned long);
333333
/* open dir, start readdir */

‎fs/cifs/connect.c‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3239,10 +3239,20 @@ void cifs_setup_cifs_sb(struct smb_vol *pvolume_info,
32393239
}
32403240
if (pvolume_info->mfsymlinks) {
32413241
if (pvolume_info->sfu_emul) {
3242-
cifs_dbg(VFS, "mount option mfsymlinks ignored if sfu mount option is used\n");
3243-
} else {
3244-
cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_MF_SYMLINKS;
3242+
/*
3243+
* Our SFU ("Services for Unix" emulation does not allow
3244+
* creating symlinks but does allow reading existing SFU
3245+
* symlinks (it does allow both creating and reading SFU
3246+
* style mknod and FIFOs though). When "mfsymlinks" and
3247+
* "sfu" are both enabled at the same time, it allows
3248+
* reading both types of symlinks, but will only create
3249+
* them with mfsymlinks format. This allows better
3250+
* Apple compatibility (probably better for Samba too)
3251+
* while still recognizing old Windows style symlinks.
3252+
*/
3253+
cifs_dbg(VFS, "mount options mfsymlinks and sfu both enabled\n");
32453254
}
3255+
cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_MF_SYMLINKS;
32463256
}
32473257

32483258
if ((pvolume_info->cifs_acl) && (pvolume_info->dynperm))

‎fs/cifs/dir.c‎

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -577,12 +577,13 @@ int cifs_mknod(struct inode *inode, struct dentry *direntry, umode_t mode,
577577
struct cifs_io_parms io_parms;
578578
char *full_path = NULL;
579579
struct inode *newinode = NULL;
580-
int oplock = 0;
580+
__u32 oplock = 0;
581581
struct cifs_fid fid;
582582
struct cifs_open_parms oparms;
583583
FILE_ALL_INFO *buf = NULL;
584584
unsigned int bytes_written;
585585
struct win_dev *pdev;
586+
struct kvec iov[2];
586587

587588
if (!old_valid_dev(device_number))
588589
return -EINVAL;
@@ -658,7 +659,11 @@ int cifs_mknod(struct inode *inode, struct dentry *direntry, umode_t mode,
658659
oparms.fid = &fid;
659660
oparms.reconnect = false;
660661

661-
rc = CIFS_open(xid, &oparms, &oplock, buf);
662+
if (tcon->ses->server->oplocks)
663+
oplock = REQ_OPLOCK;
664+
else
665+
oplock = 0;
666+
rc = tcon->ses->server->ops->open(xid, &oparms, &oplock, buf);
662667
if (rc)
663668
goto mknod_out;
664669

@@ -668,25 +673,26 @@ int cifs_mknod(struct inode *inode, struct dentry *direntry, umode_t mode,
668673
*/
669674

670675
pdev = (struct win_dev *)buf;
671-
io_parms.netfid = fid.netfid;
672676
io_parms.pid = current->tgid;
673677
io_parms.tcon = tcon;
674678
io_parms.offset = 0;
675679
io_parms.length = sizeof(struct win_dev);
680+
iov[1].iov_base = buf;
681+
iov[1].iov_len = sizeof(struct win_dev);
676682
if (S_ISCHR(mode)) {
677683
memcpy(pdev->type, "IntxCHR", 8);
678684
pdev->major = cpu_to_le64(MAJOR(device_number));
679685
pdev->minor = cpu_to_le64(MINOR(device_number));
680-
rc = CIFSSMBWrite(xid, &io_parms, &bytes_written, (char *)pdev,
681-
NULL, 0);
686+
rc = tcon->ses->server->ops->sync_write(xid, &fid, &io_parms,
687+
&bytes_written, iov, 1);
682688
} else if (S_ISBLK(mode)) {
683689
memcpy(pdev->type, "IntxBLK", 8);
684690
pdev->major = cpu_to_le64(MAJOR(device_number));
685691
pdev->minor = cpu_to_le64(MINOR(device_number));
686-
rc = CIFSSMBWrite(xid, &io_parms, &bytes_written, (char *)pdev,
687-
NULL, 0);
692+
rc = tcon->ses->server->ops->sync_write(xid, &fid, &io_parms,
693+
&bytes_written, iov, 1);
688694
} /* else if (S_ISFIFO) */
689-
CIFSSMBClose(xid, tcon, fid.netfid);
695+
tcon->ses->server->ops->close(xid, tcon, &fid);
690696
d_drop(direntry);
691697

692698
/* FIXME: add code here to set EAs */

‎fs/cifs/file.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1687,8 +1687,8 @@ cifs_write(struct cifsFileInfo *open_file, __u32 pid, const char *write_data,
16871687
io_parms.tcon = tcon;
16881688
io_parms.offset = *offset;
16891689
io_parms.length = len;
1690-
rc = server->ops->sync_write(xid, open_file, &io_parms,
1691-
&bytes_written, iov, 1);
1690+
rc = server->ops->sync_write(xid, &open_file->fid,
1691+
&io_parms, &bytes_written, iov, 1);
16921692
}
16931693
if (rc || (bytes_written == 0)) {
16941694
if (total_written)
@@ -3206,7 +3206,7 @@ cifs_read(struct file *file, char *read_data, size_t read_size, loff_t *offset)
32063206
io_parms.tcon = tcon;
32073207
io_parms.offset = *offset;
32083208
io_parms.length = current_read_size;
3209-
rc = server->ops->sync_read(xid, open_file, &io_parms,
3209+
rc = server->ops->sync_read(xid, &open_file->fid, &io_parms,
32103210
&bytes_read, &cur_offset,
32113211
&buf_type);
32123212
} while (rc == -EAGAIN);

‎fs/cifs/inode.c‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ cifs_sfu_type(struct cifs_fattr *fattr, const char *path,
412412
struct cifs_sb_info *cifs_sb, unsigned int xid)
413413
{
414414
int rc;
415-
int oplock = 0;
415+
__u32 oplock;
416416
struct tcon_link *tlink;
417417
struct cifs_tcon *tcon;
418418
struct cifs_fid fid;
@@ -451,8 +451,13 @@ cifs_sfu_type(struct cifs_fattr *fattr, const char *path,
451451
oparms.fid = &fid;
452452
oparms.reconnect = false;
453453

454-
rc = CIFS_open(xid, &oparms, &oplock, NULL);
454+
if (tcon->ses->server->oplocks)
455+
oplock = REQ_OPLOCK;
456+
else
457+
oplock = 0;
458+
rc = tcon->ses->server->ops->open(xid, &oparms, &oplock, NULL);
455459
if (rc) {
460+
cifs_dbg(FYI, "check sfu type of %s, open rc = %d\n", path, rc);
456461
cifs_put_tlink(tlink);
457462
return rc;
458463
}
@@ -464,7 +469,8 @@ cifs_sfu_type(struct cifs_fattr *fattr, const char *path,
464469
io_parms.offset = 0;
465470
io_parms.length = 24;
466471

467-
rc = CIFSSMBRead(xid, &io_parms, &bytes_read, &pbuf, &buf_type);
472+
rc = tcon->ses->server->ops->sync_read(xid, &fid, &io_parms,
473+
&bytes_read, &pbuf, &buf_type);
468474
if ((rc == 0) && (bytes_read >= 8)) {
469475
if (memcmp("IntxBLK", pbuf, 8) == 0) {
470476
cifs_dbg(FYI, "Block device\n");
@@ -504,7 +510,8 @@ cifs_sfu_type(struct cifs_fattr *fattr, const char *path,
504510
fattr->cf_dtype = DT_REG;
505511
rc = -EOPNOTSUPP; /* or some unknown SFU type */
506512
}
507-
CIFSSMBClose(xid, tcon, fid.netfid);
513+
514+
tcon->ses->server->ops->close(xid, tcon, &fid);
508515
cifs_put_tlink(tlink);
509516
return rc;
510517
}

‎fs/cifs/smb1ops.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -749,21 +749,21 @@ cifs_flush_file(const unsigned int xid, struct cifs_tcon *tcon,
749749
}
750750

751751
static int
752-
cifs_sync_read(const unsigned int xid, struct cifsFileInfo *cfile,
752+
cifs_sync_read(const unsigned int xid, struct cifs_fid *pfid,
753753
struct cifs_io_parms *parms, unsigned int *bytes_read,
754754
char **buf, int *buf_type)
755755
{
756-
parms->netfid = cfile->fid.netfid;
756+
parms->netfid = pfid->netfid;
757757
return CIFSSMBRead(xid, parms, bytes_read, buf, buf_type);
758758
}
759759

760760
static int
761-
cifs_sync_write(const unsigned int xid, struct cifsFileInfo *cfile,
761+
cifs_sync_write(const unsigned int xid, struct cifs_fid *pfid,
762762
struct cifs_io_parms *parms, unsigned int *written,
763763
struct kvec *iov, unsigned long nr_segs)
764764
{
765765

766-
parms->netfid = cfile->fid.netfid;
766+
parms->netfid = pfid->netfid;
767767
return CIFSSMBWrite2(xid, parms, written, iov, nr_segs);
768768
}
769769

‎fs/cifs/smb2ops.c‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -711,23 +711,23 @@ smb2_read_data_length(char *buf)
711711

712712

713713
static int
714-
smb2_sync_read(const unsigned int xid, struct cifsFileInfo *cfile,
714+
smb2_sync_read(const unsigned int xid, struct cifs_fid *pfid,
715715
struct cifs_io_parms *parms, unsigned int *bytes_read,
716716
char **buf, int *buf_type)
717717
{
718-
parms->persistent_fid = cfile->fid.persistent_fid;
719-
parms->volatile_fid = cfile->fid.volatile_fid;
718+
parms->persistent_fid = pfid->persistent_fid;
719+
parms->volatile_fid = pfid->volatile_fid;
720720
return SMB2_read(xid, parms, bytes_read, buf, buf_type);
721721
}
722722

723723
static int
724-
smb2_sync_write(const unsigned int xid, struct cifsFileInfo *cfile,
724+
smb2_sync_write(const unsigned int xid, struct cifs_fid *pfid,
725725
struct cifs_io_parms *parms, unsigned int *written,
726726
struct kvec *iov, unsigned long nr_segs)
727727
{
728728

729-
parms->persistent_fid = cfile->fid.persistent_fid;
730-
parms->volatile_fid = cfile->fid.volatile_fid;
729+
parms->persistent_fid = pfid->persistent_fid;
730+
parms->volatile_fid = pfid->volatile_fid;
731731
return SMB2_write(xid, parms, written, iov, nr_segs);
732732
}
733733

‎fs/cifs/smb2pdu.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,6 +1098,8 @@ SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms, __le16 *path,
10981098

10991099
if (oparms->create_options & CREATE_OPTION_READONLY)
11001100
file_attributes |= ATTR_READONLY;
1101+
if (oparms->create_options & CREATE_OPTION_SPECIAL)
1102+
file_attributes |= ATTR_SYSTEM;
11011103

11021104
req->ImpersonationLevel = IL_IMPERSONATION;
11031105
req->DesiredAccess = cpu_to_le32(oparms->desired_access);

0 commit comments

Comments
 (0)