From bd59f504e6806dac5b3c1bd9c626de085987f1e0 Mon Sep 17 00:00:00 2001 From: Veaceslav Falico Date: Fri, 12 Jan 2018 19:26:18 +0800 Subject: [PATCH] 9pfs: stat_to_qid: use device id as input to qid.path Currently, only the inode number of a file is being used as input to the qid.path field. The 9p RFC specifies that the path needs to be unique per file in the directory hierarchy, however on the host side the inode alone does not suffice to uniquely identify a file, as another file on a different device may have the same inode number. To avoid qid path collisions, we take the device id as input as well. Signed-off-by: Veaceslav Falico Signed-off-by: Antonios Motakis --- hw/9pfs/9p.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index 393a2b2..a810d13 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -583,11 +583,7 @@ static void virtfs_reset(V9fsPDU *pdu) /* This is the algorithm from ufs in spfs */ static void stat_to_qid(const struct stat *stbuf, V9fsQID *qidp) { - size_t size; - - memset(&qidp->path, 0, sizeof(qidp->path)); - size = MIN(sizeof(stbuf->st_ino), sizeof(qidp->path)); - memcpy(&qidp->path, &stbuf->st_ino, size); + qidp->path = stbuf->st_ino ^ ((int64_t)stbuf->st_dev << 16); qidp->version = stbuf->st_mtime ^ (stbuf->st_size << 8); qidp->type = 0; if (S_ISDIR(stbuf->st_mode)) { -- 1.8.3.1