Skip to content

Commit 571781e

Browse files
namjaejeonsmfrench
authored andcommitted
ksmbd: provide zero as a unique ID to the Mac client
The Mac SMB client code seems to expect the on-disk file identifier to have the semantics of HFS+ Catalog Node Identifier (CNID). ksmbd provides the inode number as a unique ID to the client, but in the case of subvolumes of btrfs, there are cases where different files have the same inode number, so the mac smb client treats it as an error. There is a report that a similar problem occurs when the share is ZFS. Returning UniqueId of zero will make the Mac client to stop using and trusting the file id returned from the server. Reported-by: Justin Turner Arthur <[email protected]> Signed-off-by: Namjae Jeon <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent d91c075 commit 571781e

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

fs/smb/server/connection.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ struct ksmbd_conn {
108108
__le16 signing_algorithm;
109109
bool binding;
110110
atomic_t refcnt;
111+
bool is_aapl;
111112
};
112113

113114
struct ksmbd_conn_ops {

fs/smb/server/smb2pdu.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3539,6 +3539,15 @@ int smb2_open(struct ksmbd_work *work)
35393539
ksmbd_debug(SMB, "get query on disk id context\n");
35403540
query_disk_id = 1;
35413541
}
3542+
3543+
if (conn->is_aapl == false) {
3544+
context = smb2_find_context_vals(req, SMB2_CREATE_AAPL, 4);
3545+
if (IS_ERR(context)) {
3546+
rc = PTR_ERR(context);
3547+
goto err_out1;
3548+
} else if (context)
3549+
conn->is_aapl = true;
3550+
}
35423551
}
35433552

35443553
rc = ksmbd_vfs_getattr(&path, &stat);
@@ -3978,7 +3987,10 @@ static int smb2_populate_readdir_entry(struct ksmbd_conn *conn, int info_level,
39783987
if (dinfo->EaSize)
39793988
dinfo->ExtFileAttributes = FILE_ATTRIBUTE_REPARSE_POINT_LE;
39803989
dinfo->Reserved = 0;
3981-
dinfo->UniqueId = cpu_to_le64(ksmbd_kstat->kstat->ino);
3990+
if (conn->is_aapl)
3991+
dinfo->UniqueId = 0;
3992+
else
3993+
dinfo->UniqueId = cpu_to_le64(ksmbd_kstat->kstat->ino);
39823994
if (d_info->hide_dot_file && d_info->name[0] == '.')
39833995
dinfo->ExtFileAttributes |= FILE_ATTRIBUTE_HIDDEN_LE;
39843996
memcpy(dinfo->FileName, conv_name, conv_len);
@@ -3995,7 +4007,10 @@ static int smb2_populate_readdir_entry(struct ksmbd_conn *conn, int info_level,
39954007
smb2_get_reparse_tag_special_file(ksmbd_kstat->kstat->mode);
39964008
if (fibdinfo->EaSize)
39974009
fibdinfo->ExtFileAttributes = FILE_ATTRIBUTE_REPARSE_POINT_LE;
3998-
fibdinfo->UniqueId = cpu_to_le64(ksmbd_kstat->kstat->ino);
4010+
if (conn->is_aapl)
4011+
fibdinfo->UniqueId = 0;
4012+
else
4013+
fibdinfo->UniqueId = cpu_to_le64(ksmbd_kstat->kstat->ino);
39994014
fibdinfo->ShortNameLength = 0;
40004015
fibdinfo->Reserved = 0;
40014016
fibdinfo->Reserved2 = cpu_to_le16(0);

fs/smb/server/smb2pdu.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ struct preauth_integrity_info {
6363

6464
#define SMB2_SESSION_TIMEOUT (10 * HZ)
6565

66+
/* Apple Defined Contexts */
67+
#define SMB2_CREATE_AAPL "AAPL"
68+
6669
struct create_durable_req_v2 {
6770
struct create_context_hdr ccontext;
6871
__u8 Name[8];

0 commit comments

Comments
 (0)