All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: ericvh@gmail.com, aliguori@us.ibm.com, aneesh.kumar@linux.vnet.ibm.com
Subject: [Qemu-devel] [PATCH -V4 07/21] virtio-9p: Add stat and mode related helper functions.
Date: Fri,  9 Apr 2010 17:13:10 +0530	[thread overview]
Message-ID: <1270813404-23004-8-git-send-email-aneesh.kumar@linux.vnet.ibm.com> (raw)
In-Reply-To: <1270813404-23004-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com>

From: Anthony Liguori <aliguori@us.ibm.com>

Add helpers to obtain file stat and mode details.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
---
 hw/virtio-9p.c |  186 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 186 insertions(+), 0 deletions(-)

diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c
index 7db157a..4b3ce2f 100644
--- a/hw/virtio-9p.c
+++ b/hw/virtio-9p.c
@@ -582,6 +582,188 @@ static void complete_pdu(V9fsState *s, V9fsPDU *pdu, ssize_t len)
     free_pdu(s, pdu);
 }
 
+static mode_t v9mode_to_mode(uint32_t mode, V9fsString *extension)
+{
+    mode_t ret;
+
+    ret = mode & 0777;
+    if (mode & P9_STAT_MODE_DIR) {
+        ret |= S_IFDIR;
+    }
+
+    if (dotu) {
+        if (mode & P9_STAT_MODE_SYMLINK) {
+            ret |= S_IFLNK;
+        }
+        if (mode & P9_STAT_MODE_SOCKET) {
+            ret |= S_IFSOCK;
+        }
+        if (mode & P9_STAT_MODE_NAMED_PIPE) {
+            ret |= S_IFIFO;
+        }
+        if (mode & P9_STAT_MODE_DEVICE) {
+            if (extension && extension->data[0] == 'c') {
+                ret |= S_IFCHR;
+            } else {
+                ret |= S_IFBLK;
+            }
+        }
+    }
+
+    if (!(ret&~0777)) {
+        ret |= S_IFREG;
+    }
+
+    if (mode & P9_STAT_MODE_SETUID) {
+        ret |= S_ISUID;
+    }
+    if (mode & P9_STAT_MODE_SETGID) {
+        ret |= S_ISGID;
+    }
+    if (mode & P9_STAT_MODE_SETVTX) {
+        ret |= S_ISVTX;
+    }
+
+    return ret;
+}
+
+static int donttouch_stat(V9fsStat *stat)
+{
+    if (stat->type == -1 &&
+        stat->dev == -1 &&
+        stat->qid.type == -1 &&
+        stat->qid.version == -1 &&
+        stat->qid.path == -1 &&
+        stat->mode == -1 &&
+        stat->atime == -1 &&
+        stat->mtime == -1 &&
+        stat->length == -1 &&
+        !stat->name.size &&
+        !stat->uid.size &&
+        !stat->gid.size &&
+        !stat->muid.size &&
+        stat->n_uid == -1 &&
+        stat->n_gid == -1 &&
+        stat->n_muid == -1) {
+        return 1;
+    }
+
+    return 0;
+}
+
+static void v9fs_stat_free(V9fsStat *stat)
+{
+    v9fs_string_free(&stat->name);
+    v9fs_string_free(&stat->uid);
+    v9fs_string_free(&stat->gid);
+    v9fs_string_free(&stat->muid);
+    v9fs_string_free(&stat->extension);
+}
+
+static uint32_t stat_to_v9mode(const struct stat *stbuf)
+{
+    uint32_t mode;
+
+    mode = stbuf->st_mode & 0777;
+    if (S_ISDIR(stbuf->st_mode)) {
+        mode |= P9_STAT_MODE_DIR;
+    }
+
+    if (dotu) {
+        if (S_ISLNK(stbuf->st_mode)) {
+            mode |= P9_STAT_MODE_SYMLINK;
+        }
+
+        if (S_ISSOCK(stbuf->st_mode)) {
+            mode |= P9_STAT_MODE_SOCKET;
+        }
+
+        if (S_ISFIFO(stbuf->st_mode)) {
+            mode |= P9_STAT_MODE_NAMED_PIPE;
+        }
+
+        if (S_ISBLK(stbuf->st_mode) || S_ISCHR(stbuf->st_mode)) {
+            mode |= P9_STAT_MODE_DEVICE;
+        }
+
+        if (stbuf->st_mode & S_ISUID) {
+            mode |= P9_STAT_MODE_SETUID;
+        }
+
+        if (stbuf->st_mode & S_ISGID) {
+            mode |= P9_STAT_MODE_SETGID;
+        }
+
+        if (stbuf->st_mode & S_ISVTX) {
+            mode |= P9_STAT_MODE_SETVTX;
+        }
+    }
+
+    return mode;
+}
+
+static int stat_to_v9stat(V9fsState *s, V9fsString *name,
+                            const struct stat *stbuf,
+                            V9fsStat *v9stat)
+{
+    int err;
+    const char *str;
+
+    memset(v9stat, 0, sizeof(*v9stat));
+
+    stat_to_qid(stbuf, &v9stat->qid);
+    v9stat->mode = stat_to_v9mode(stbuf);
+    v9stat->atime = stbuf->st_atime;
+    v9stat->mtime = stbuf->st_mtime;
+    v9stat->length = stbuf->st_size;
+
+    v9fs_string_null(&v9stat->uid);
+    v9fs_string_null(&v9stat->gid);
+    v9fs_string_null(&v9stat->muid);
+
+    if (dotu) {
+        v9stat->n_uid = stbuf->st_uid;
+        v9stat->n_gid = stbuf->st_gid;
+        v9stat->n_muid = 0;
+
+        v9fs_string_null(&v9stat->extension);
+
+        if (v9stat->mode & P9_STAT_MODE_SYMLINK) {
+            err = v9fs_do_readlink(s, name, &v9stat->extension);
+            if (err == -1) {
+                err = -errno;
+                return err;
+            }
+            v9stat->extension.data[err] = 0;
+            v9stat->extension.size = err;
+        } else if (v9stat->mode & P9_STAT_MODE_DEVICE) {
+            v9fs_string_sprintf(&v9stat->extension, "%c %u %u",
+                    S_ISCHR(stbuf->st_mode) ? 'c' : 'b',
+                    major(stbuf->st_rdev), minor(stbuf->st_rdev));
+        } else if (S_ISDIR(stbuf->st_mode) || S_ISREG(stbuf->st_mode)) {
+            v9fs_string_sprintf(&v9stat->extension, "%s %u",
+                    "HARDLINKCOUNT", stbuf->st_nlink);
+        }
+    }
+
+    str = strrchr(name->data, '/');
+    if (str) {
+        str += 1;
+    } else {
+        str = name->data;
+    }
+
+    v9fs_string_sprintf(&v9stat->name, "%s", str);
+
+    v9stat->size = 61 +
+        v9fs_string_size(&v9stat->name) +
+        v9fs_string_size(&v9stat->uid) +
+        v9fs_string_size(&v9stat->gid) +
+        v9fs_string_size(&v9stat->muid) +
+        v9fs_string_size(&v9stat->extension);
+    return 0;
+}
+
 static void v9fs_dummy(V9fsState *s, V9fsPDU *pdu)
 {
     /* Note: The following have been added to prevent GCC from complaining
@@ -602,6 +784,10 @@ static void v9fs_dummy(V9fsState *s, V9fsPDU *pdu)
     (void) alloc_fid;
     (void) free_fid;
     (void) fid_to_qid;
+    (void) v9mode_to_mode;
+    (void) donttouch_stat;
+    (void) v9fs_stat_free;
+    (void) stat_to_v9stat;
 }
 
 static void v9fs_version(V9fsState *s, V9fsPDU *pdu)
-- 
1.7.0.4.360.g11766c

  parent reply	other threads:[~2010-04-09 11:43 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-09 11:43 [Qemu-devel] [PATCH -V4 00/21] virtio-9p: paravirtual file system passthrough Aneesh Kumar K.V
2010-04-09 11:43 ` [Qemu-devel] [PATCH -V4 01/21] virtio-9p: Create a commandline option -fsdev Aneesh Kumar K.V
2010-04-09 11:43 ` [Qemu-devel] [PATCH -V4 02/21] virtio-9p: Add a virtio 9p device to qemu Aneesh Kumar K.V
2010-04-09 11:43 ` [Qemu-devel] [PATCH -V4 03/21] virtio-9p: pdu processing support Aneesh Kumar K.V
2010-04-09 11:43 ` [Qemu-devel] [PATCH -V4 04/21] virtio-9p: Add string manipulation support Aneesh Kumar K.V
2010-04-09 11:43 ` [Qemu-devel] [PATCH -V4 05/21] virtio-9p: Add minimal set of FileOperations Aneesh Kumar K.V
2010-04-09 11:43 ` [Qemu-devel] [PATCH -V4 06/21] virtio-9p: Add fid and qid management support Aneesh Kumar K.V
2010-04-09 11:43 ` Aneesh Kumar K.V [this message]
2010-04-09 11:43 ` [Qemu-devel] [PATCH -V4 08/21] virtio-9p: Add sg helper functions Aneesh Kumar K.V
2010-04-09 11:43 ` [Qemu-devel] [PATCH -V4 09/21] virtio-9p: Add P9_TVERSION support Aneesh Kumar K.V
2010-04-09 11:43 ` [Qemu-devel] [PATCH -V4 10/21] virtio-9p: Add P9_TATTACH support Aneesh Kumar K.V
2010-04-09 11:43 ` [Qemu-devel] [PATCH -V4 11/21] virtio-9p: Add P9_TSTAT support Aneesh Kumar K.V
2010-04-09 11:43 ` [Qemu-devel] [PATCH -V4 12/21] virtio-9p: Add P9_TWALK support Aneesh Kumar K.V
2010-04-09 11:43 ` [Qemu-devel] [PATCH -V4 13/21] virtio-9p: Add P9_TOPEN support Aneesh Kumar K.V
2010-04-09 11:43 ` [Qemu-devel] [PATCH -V4 14/21] virtio-9p: Add P9_TREAD support Aneesh Kumar K.V
2010-04-09 11:43 ` [Qemu-devel] [PATCH -V4 15/21] virtio-9p: Add P9_TCLUNK support Aneesh Kumar K.V
2010-04-09 11:43 ` [Qemu-devel] [PATCH -V4 16/21] virtio-9p: Add P9_TWRITE support Aneesh Kumar K.V
2010-04-09 11:43 ` [Qemu-devel] [PATCH -V4 17/21] virtio-9p: Add P9_TCREATE support Aneesh Kumar K.V
2010-04-09 11:43 ` [Qemu-devel] [PATCH -V4 18/21] virtio-9p: Add P9_TWSTAT support Aneesh Kumar K.V
2010-04-09 11:43 ` [Qemu-devel] [PATCH -V4 19/21] virtio-9p: Add P9_TREMOVE support Aneesh Kumar K.V
2010-04-09 11:43 ` [Qemu-devel] [PATCH -V4 20/21] virtio-9p: Add P9_TFLUSH support Aneesh Kumar K.V
2010-04-09 11:43 ` [Qemu-devel] [PATCH -V4 21/21] virtio-9p: Create a syntactic shortcut for the file-system pass-thru Aneesh Kumar K.V

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1270813404-23004-8-git-send-email-aneesh.kumar@linux.vnet.ibm.com \
    --to=aneesh.kumar@linux.vnet.ibm.com \
    --cc=aliguori@us.ibm.com \
    --cc=ericvh@gmail.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.