Revision faa44e3d

b/fsdev/file-op-9p.h
97 97
    void *opaque;
98 98
} FileOperations;
99 99

  
100
static inline const char *rpath(FsContext *ctx, const char *path)
101
{
102
    /* FIXME: so wrong... */
103
    static char buffer[4096];
104
    snprintf(buffer, sizeof(buffer), "%s/%s", ctx->fs_root, path);
105
    return buffer;
106
}
107 100
#endif
b/hw/9pfs/virtio-9p-local.c
25 25
static int local_lstat(FsContext *fs_ctx, const char *path, struct stat *stbuf)
26 26
{
27 27
    int err;
28
    err =  lstat(rpath(fs_ctx, path), stbuf);
28
    char buffer[PATH_MAX];
29
    err =  lstat(rpath(fs_ctx, path, buffer), stbuf);
29 30
    if (err) {
30 31
        return err;
31 32
    }
......
35 36
        gid_t tmp_gid;
36 37
        mode_t tmp_mode;
37 38
        dev_t tmp_dev;
38
        if (getxattr(rpath(fs_ctx, path), "user.virtfs.uid", &tmp_uid,
39
        if (getxattr(rpath(fs_ctx, path, buffer), "user.virtfs.uid", &tmp_uid,
39 40
                    sizeof(uid_t)) > 0) {
40 41
            stbuf->st_uid = tmp_uid;
41 42
        }
42
        if (getxattr(rpath(fs_ctx, path), "user.virtfs.gid", &tmp_gid,
43
        if (getxattr(rpath(fs_ctx, path, buffer), "user.virtfs.gid", &tmp_gid,
43 44
                    sizeof(gid_t)) > 0) {
44 45
            stbuf->st_gid = tmp_gid;
45 46
        }
46
        if (getxattr(rpath(fs_ctx, path), "user.virtfs.mode", &tmp_mode,
47
                    sizeof(mode_t)) > 0) {
47
        if (getxattr(rpath(fs_ctx, path, buffer), "user.virtfs.mode",
48
                    &tmp_mode, sizeof(mode_t)) > 0) {
48 49
            stbuf->st_mode = tmp_mode;
49 50
        }
50
        if (getxattr(rpath(fs_ctx, path), "user.virtfs.rdev", &tmp_dev,
51
        if (getxattr(rpath(fs_ctx, path, buffer), "user.virtfs.rdev", &tmp_dev,
51 52
                        sizeof(dev_t)) > 0) {
52 53
                stbuf->st_rdev = tmp_dev;
53 54
        }
......
92 93
static int local_post_create_passthrough(FsContext *fs_ctx, const char *path,
93 94
        FsCred *credp)
94 95
{
95
    if (chmod(rpath(fs_ctx, path), credp->fc_mode & 07777) < 0) {
96
    char buffer[PATH_MAX];
97
    if (chmod(rpath(fs_ctx, path, buffer), credp->fc_mode & 07777) < 0) {
96 98
        return -1;
97 99
    }
98
    if (lchown(rpath(fs_ctx, path), credp->fc_uid, credp->fc_gid) < 0) {
100
    if (lchown(rpath(fs_ctx, path, buffer), credp->fc_uid,
101
                credp->fc_gid) < 0) {
99 102
        /*
100 103
         * If we fail to change ownership and if we are
101 104
         * using security model none. Ignore the error
......
111 114
        char *buf, size_t bufsz)
112 115
{
113 116
    ssize_t tsize = -1;
117
    char buffer[PATH_MAX];
114 118
    if (fs_ctx->fs_sm == SM_MAPPED) {
115 119
        int fd;
116
        fd = open(rpath(fs_ctx, path), O_RDONLY);
120
        fd = open(rpath(fs_ctx, path, buffer), O_RDONLY);
117 121
        if (fd == -1) {
118 122
            return -1;
119 123
        }
......
124 128
        return tsize;
125 129
    } else if ((fs_ctx->fs_sm == SM_PASSTHROUGH) ||
126 130
               (fs_ctx->fs_sm == SM_NONE)) {
127
        tsize = readlink(rpath(fs_ctx, path), buf, bufsz);
131
        tsize = readlink(rpath(fs_ctx, path, buffer), buf, bufsz);
128 132
    }
129 133
    return tsize;
130 134
}
......
141 145

  
142 146
static int local_open(FsContext *ctx, const char *path, int flags)
143 147
{
144
    return open(rpath(ctx, path), flags);
148
    char buffer[PATH_MAX];
149
    return open(rpath(ctx, path, buffer), flags);
145 150
}
146 151

  
147 152
static DIR *local_opendir(FsContext *ctx, const char *path)
148 153
{
149
    return opendir(rpath(ctx, path));
154
    char buffer[PATH_MAX];
155
    return opendir(rpath(ctx, path, buffer));
150 156
}
151 157

  
152 158
static void local_rewinddir(FsContext *ctx, DIR *dir)
......
201 207

  
202 208
static int local_chmod(FsContext *fs_ctx, const char *path, FsCred *credp)
203 209
{
210
    char buffer[PATH_MAX];
204 211
    if (fs_ctx->fs_sm == SM_MAPPED) {
205
        return local_set_xattr(rpath(fs_ctx, path), credp);
212
        return local_set_xattr(rpath(fs_ctx, path, buffer), credp);
206 213
    } else if ((fs_ctx->fs_sm == SM_PASSTHROUGH) ||
207 214
               (fs_ctx->fs_sm == SM_NONE)) {
208
        return chmod(rpath(fs_ctx, path), credp->fc_mode);
215
        return chmod(rpath(fs_ctx, path, buffer), credp->fc_mode);
209 216
    }
210 217
    return -1;
211 218
}
......
214 221
{
215 222
    int err = -1;
216 223
    int serrno = 0;
224
    char buffer[PATH_MAX];
217 225

  
218 226
    /* Determine the security model */
219 227
    if (fs_ctx->fs_sm == SM_MAPPED) {
220
        err = mknod(rpath(fs_ctx, path), SM_LOCAL_MODE_BITS|S_IFREG, 0);
228
        err = mknod(rpath(fs_ctx, path, buffer),
229
                SM_LOCAL_MODE_BITS|S_IFREG, 0);
221 230
        if (err == -1) {
222 231
            return err;
223 232
        }
224
        local_set_xattr(rpath(fs_ctx, path), credp);
233
        local_set_xattr(rpath(fs_ctx, path, buffer), credp);
225 234
        if (err == -1) {
226 235
            serrno = errno;
227 236
            goto err_end;
228 237
        }
229 238
    } else if ((fs_ctx->fs_sm == SM_PASSTHROUGH) ||
230 239
               (fs_ctx->fs_sm == SM_NONE)) {
231
        err = mknod(rpath(fs_ctx, path), credp->fc_mode, credp->fc_rdev);
240
        err = mknod(rpath(fs_ctx, path, buffer), credp->fc_mode,
241
                credp->fc_rdev);
232 242
        if (err == -1) {
233 243
            return err;
234 244
        }
......
241 251
    return err;
242 252

  
243 253
err_end:
244
    remove(rpath(fs_ctx, path));
254
    remove(rpath(fs_ctx, path, buffer));
245 255
    errno = serrno;
246 256
    return err;
247 257
}
......
250 260
{
251 261
    int err = -1;
252 262
    int serrno = 0;
263
    char buffer[PATH_MAX];
253 264

  
254 265
    /* Determine the security model */
255 266
    if (fs_ctx->fs_sm == SM_MAPPED) {
256
        err = mkdir(rpath(fs_ctx, path), SM_LOCAL_DIR_MODE_BITS);
267
        err = mkdir(rpath(fs_ctx, path, buffer), SM_LOCAL_DIR_MODE_BITS);
257 268
        if (err == -1) {
258 269
            return err;
259 270
        }
260 271
        credp->fc_mode = credp->fc_mode|S_IFDIR;
261
        err = local_set_xattr(rpath(fs_ctx, path), credp);
272
        err = local_set_xattr(rpath(fs_ctx, path, buffer), credp);
262 273
        if (err == -1) {
263 274
            serrno = errno;
264 275
            goto err_end;
265 276
        }
266 277
    } else if ((fs_ctx->fs_sm == SM_PASSTHROUGH) ||
267 278
               (fs_ctx->fs_sm == SM_NONE)) {
268
        err = mkdir(rpath(fs_ctx, path), credp->fc_mode);
279
        err = mkdir(rpath(fs_ctx, path, buffer), credp->fc_mode);
269 280
        if (err == -1) {
270 281
            return err;
271 282
        }
......
278 289
    return err;
279 290

  
280 291
err_end:
281
    remove(rpath(fs_ctx, path));
292
    remove(rpath(fs_ctx, path, buffer));
282 293
    errno = serrno;
283 294
    return err;
284 295
}
......
319 330
    int fd = -1;
320 331
    int err = -1;
321 332
    int serrno = 0;
333
    char buffer[PATH_MAX];
322 334

  
323 335
    /* Determine the security model */
324 336
    if (fs_ctx->fs_sm == SM_MAPPED) {
325
        fd = open(rpath(fs_ctx, path), flags, SM_LOCAL_MODE_BITS);
337
        fd = open(rpath(fs_ctx, path, buffer), flags, SM_LOCAL_MODE_BITS);
326 338
        if (fd == -1) {
327 339
            return fd;
328 340
        }
329 341
        credp->fc_mode = credp->fc_mode|S_IFREG;
330 342
        /* Set cleint credentials in xattr */
331
        err = local_set_xattr(rpath(fs_ctx, path), credp);
343
        err = local_set_xattr(rpath(fs_ctx, path, buffer), credp);
332 344
        if (err == -1) {
333 345
            serrno = errno;
334 346
            goto err_end;
335 347
        }
336 348
    } else if ((fs_ctx->fs_sm == SM_PASSTHROUGH) ||
337 349
               (fs_ctx->fs_sm == SM_NONE)) {
338
        fd = open(rpath(fs_ctx, path), flags, credp->fc_mode);
350
        fd = open(rpath(fs_ctx, path, buffer), flags, credp->fc_mode);
339 351
        if (fd == -1) {
340 352
            return fd;
341 353
        }
......
349 361

  
350 362
err_end:
351 363
    close(fd);
352
    remove(rpath(fs_ctx, path));
364
    remove(rpath(fs_ctx, path, buffer));
353 365
    errno = serrno;
354 366
    return err;
355 367
}
......
360 372
{
361 373
    int err = -1;
362 374
    int serrno = 0;
375
    char buffer[PATH_MAX];
363 376

  
364 377
    /* Determine the security model */
365 378
    if (fs_ctx->fs_sm == SM_MAPPED) {
366 379
        int fd;
367 380
        ssize_t oldpath_size, write_size;
368
        fd = open(rpath(fs_ctx, newpath), O_CREAT|O_EXCL|O_RDWR,
381
        fd = open(rpath(fs_ctx, newpath, buffer), O_CREAT|O_EXCL|O_RDWR,
369 382
                SM_LOCAL_MODE_BITS);
370 383
        if (fd == -1) {
371 384
            return fd;
......
385 398
        close(fd);
386 399
        /* Set cleint credentials in symlink's xattr */
387 400
        credp->fc_mode = credp->fc_mode|S_IFLNK;
388
        err = local_set_xattr(rpath(fs_ctx, newpath), credp);
401
        err = local_set_xattr(rpath(fs_ctx, newpath, buffer), credp);
389 402
        if (err == -1) {
390 403
            serrno = errno;
391 404
            goto err_end;
392 405
        }
393 406
    } else if ((fs_ctx->fs_sm == SM_PASSTHROUGH) ||
394 407
               (fs_ctx->fs_sm == SM_NONE)) {
395
        err = symlink(oldpath, rpath(fs_ctx, newpath));
408
        err = symlink(oldpath, rpath(fs_ctx, newpath, buffer));
396 409
        if (err) {
397 410
            return err;
398 411
        }
399
        err = lchown(rpath(fs_ctx, newpath), credp->fc_uid, credp->fc_gid);
412
        err = lchown(rpath(fs_ctx, newpath, buffer), credp->fc_uid,
413
                credp->fc_gid);
400 414
        if (err == -1) {
401 415
            /*
402 416
             * If we fail to change ownership and if we are
......
412 426
    return err;
413 427

  
414 428
err_end:
415
    remove(rpath(fs_ctx, newpath));
429
    remove(rpath(fs_ctx, newpath, buffer));
416 430
    errno = serrno;
417 431
    return err;
418 432
}
419 433

  
420 434
static int local_link(FsContext *ctx, const char *oldpath, const char *newpath)
421 435
{
422
    char *tmp = qemu_strdup(rpath(ctx, oldpath));
423
    int err, serrno = 0;
436
    char buffer[PATH_MAX], buffer1[PATH_MAX];
424 437

  
425
    if (tmp == NULL) {
426
        return -ENOMEM;
427
    }
428

  
429
    err = link(tmp, rpath(ctx, newpath));
430
    if (err == -1) {
431
        serrno = errno;
432
    }
433

  
434
    qemu_free(tmp);
435

  
436
    if (err == -1) {
437
        errno = serrno;
438
    }
439

  
440
    return err;
438
    return link(rpath(ctx, oldpath, buffer), rpath(ctx, newpath, buffer1));
441 439
}
442 440

  
443 441
static int local_truncate(FsContext *ctx, const char *path, off_t size)
444 442
{
445
    return truncate(rpath(ctx, path), size);
443
    char buffer[PATH_MAX];
444
    return truncate(rpath(ctx, path, buffer), size);
446 445
}
447 446

  
448 447
static int local_rename(FsContext *ctx, const char *oldpath,
449 448
                        const char *newpath)
450 449
{
451
    char *tmp;
452
    int err;
453

  
454
    tmp = qemu_strdup(rpath(ctx, oldpath));
455

  
456
    err = rename(tmp, rpath(ctx, newpath));
457
    if (err == -1) {
458
        int serrno = errno;
459
        qemu_free(tmp);
460
        errno = serrno;
461
    } else {
462
        qemu_free(tmp);
463
    }
464

  
465
    return err;
450
    char buffer[PATH_MAX], buffer1[PATH_MAX];
466 451

  
452
    return rename(rpath(ctx, oldpath, buffer), rpath(ctx, newpath, buffer1));
467 453
}
468 454

  
469 455
static int local_chown(FsContext *fs_ctx, const char *path, FsCred *credp)
470 456
{
457
    char buffer[PATH_MAX];
471 458
    if ((credp->fc_uid == -1 && credp->fc_gid == -1) ||
472 459
            (fs_ctx->fs_sm == SM_PASSTHROUGH)) {
473
        return lchown(rpath(fs_ctx, path), credp->fc_uid, credp->fc_gid);
460
        return lchown(rpath(fs_ctx, path, buffer), credp->fc_uid,
461
                credp->fc_gid);
474 462
    } else if (fs_ctx->fs_sm == SM_MAPPED) {
475
        return local_set_xattr(rpath(fs_ctx, path), credp);
463
        return local_set_xattr(rpath(fs_ctx, path, buffer), credp);
476 464
    } else if ((fs_ctx->fs_sm == SM_PASSTHROUGH) ||
477 465
               (fs_ctx->fs_sm == SM_NONE)) {
478
        return lchown(rpath(fs_ctx, path), credp->fc_uid, credp->fc_gid);
466
        return lchown(rpath(fs_ctx, path, buffer), credp->fc_uid,
467
                credp->fc_gid);
479 468
    }
480 469
    return -1;
481 470
}
......
483 472
static int local_utimensat(FsContext *s, const char *path,
484 473
                           const struct timespec *buf)
485 474
{
486
    return qemu_utimensat(AT_FDCWD, rpath(s, path), buf, AT_SYMLINK_NOFOLLOW);
475
    char buffer[PATH_MAX];
476
    return qemu_utimensat(AT_FDCWD, rpath(s, path, buffer), buf,
477
            AT_SYMLINK_NOFOLLOW);
487 478
}
488 479

  
489 480
static int local_remove(FsContext *ctx, const char *path)
490 481
{
491
    return remove(rpath(ctx, path));
482
    char buffer[PATH_MAX];
483
    return remove(rpath(ctx, path, buffer));
492 484
}
493 485

  
494 486
static int local_fsync(FsContext *ctx, int fd, int datasync)
......
502 494

  
503 495
static int local_statfs(FsContext *s, const char *path, struct statfs *stbuf)
504 496
{
505
   return statfs(rpath(s, path), stbuf);
497
    char buffer[PATH_MAX];
498
   return statfs(rpath(s, path, buffer), stbuf);
506 499
}
507 500

  
508 501
static ssize_t local_lgetxattr(FsContext *ctx, const char *path,
b/hw/9pfs/virtio-9p-posix-acl.c
26 26
static ssize_t mp_pacl_getxattr(FsContext *ctx, const char *path,
27 27
                                const char *name, void *value, size_t size)
28 28
{
29
    return lgetxattr(rpath(ctx, path), MAP_ACL_ACCESS, value, size);
29
    char buffer[PATH_MAX];
30
    return lgetxattr(rpath(ctx, path, buffer), MAP_ACL_ACCESS, value, size);
30 31
}
31 32

  
32 33
static ssize_t mp_pacl_listxattr(FsContext *ctx, const char *path,
......
50 51
static int mp_pacl_setxattr(FsContext *ctx, const char *path, const char *name,
51 52
                            void *value, size_t size, int flags)
52 53
{
53
    return lsetxattr(rpath(ctx, path), MAP_ACL_ACCESS, value, size, flags);
54
    char buffer[PATH_MAX];
55
    return lsetxattr(rpath(ctx, path, buffer), MAP_ACL_ACCESS, value,
56
            size, flags);
54 57
}
55 58

  
56 59
static int mp_pacl_removexattr(FsContext *ctx,
57 60
                               const char *path, const char *name)
58 61
{
59 62
    int ret;
60
    ret  = lremovexattr(rpath(ctx, path), MAP_ACL_ACCESS);
63
    char buffer[PATH_MAX];
64
    ret  = lremovexattr(rpath(ctx, path, buffer), MAP_ACL_ACCESS);
61 65
    if (ret == -1 && errno == ENODATA) {
62 66
        /*
63 67
         * We don't get ENODATA error when trying to remove a
......
73 77
static ssize_t mp_dacl_getxattr(FsContext *ctx, const char *path,
74 78
                                const char *name, void *value, size_t size)
75 79
{
76
    return lgetxattr(rpath(ctx, path), MAP_ACL_DEFAULT, value, size);
80
    char buffer[PATH_MAX];
81
    return lgetxattr(rpath(ctx, path, buffer), MAP_ACL_DEFAULT, value, size);
77 82
}
78 83

  
79 84
static ssize_t mp_dacl_listxattr(FsContext *ctx, const char *path,
......
97 102
static int mp_dacl_setxattr(FsContext *ctx, const char *path, const char *name,
98 103
                            void *value, size_t size, int flags)
99 104
{
100
    return lsetxattr(rpath(ctx, path), MAP_ACL_DEFAULT, value, size, flags);
105
    char buffer[PATH_MAX];
106
    return lsetxattr(rpath(ctx, path, buffer), MAP_ACL_DEFAULT, value,
107
            size, flags);
101 108
}
102 109

  
103 110
static int mp_dacl_removexattr(FsContext *ctx,
104 111
                               const char *path, const char *name)
105 112
{
106 113
    int ret;
107
    ret  = lremovexattr(rpath(ctx, path), MAP_ACL_DEFAULT);
114
    char buffer[PATH_MAX];
115
    ret  = lremovexattr(rpath(ctx, path, buffer), MAP_ACL_DEFAULT);
108 116
    if (ret == -1 && errno == ENODATA) {
109 117
        /*
110 118
         * We don't get ENODATA error when trying to remove a
b/hw/9pfs/virtio-9p-xattr-user.c
21 21
static ssize_t mp_user_getxattr(FsContext *ctx, const char *path,
22 22
                                const char *name, void *value, size_t size)
23 23
{
24
    char buffer[PATH_MAX];
24 25
    if (strncmp(name, "user.virtfs.", 12) == 0) {
25 26
        /*
26 27
         * Don't allow fetch of user.virtfs namesapce
......
29 30
        errno = ENOATTR;
30 31
        return -1;
31 32
    }
32
    return lgetxattr(rpath(ctx, path), name, value, size);
33
    return lgetxattr(rpath(ctx, path, buffer), name, value, size);
33 34
}
34 35

  
35 36
static ssize_t mp_user_listxattr(FsContext *ctx, const char *path,
......
67 68
static int mp_user_setxattr(FsContext *ctx, const char *path, const char *name,
68 69
                            void *value, size_t size, int flags)
69 70
{
71
    char buffer[PATH_MAX];
70 72
    if (strncmp(name, "user.virtfs.", 12) == 0) {
71 73
        /*
72 74
         * Don't allow fetch of user.virtfs namesapce
......
75 77
        errno = EACCES;
76 78
        return -1;
77 79
    }
78
    return lsetxattr(rpath(ctx, path), name, value, size, flags);
80
    return lsetxattr(rpath(ctx, path, buffer), name, value, size, flags);
79 81
}
80 82

  
81 83
static int mp_user_removexattr(FsContext *ctx,
82 84
                               const char *path, const char *name)
83 85
{
86
    char buffer[PATH_MAX];
84 87
    if (strncmp(name, "user.virtfs.", 12) == 0) {
85 88
        /*
86 89
         * Don't allow fetch of user.virtfs namesapce
......
89 92
        errno = EACCES;
90 93
        return -1;
91 94
    }
92
    return lremovexattr(rpath(ctx, path), name);
95
    return lremovexattr(rpath(ctx, path, buffer), name);
93 96
}
94 97

  
95 98
XattrOperations mapped_user_xattr = {
b/hw/9pfs/virtio-9p-xattr.c
66 66
                        void *value, size_t vsize)
67 67
{
68 68
    ssize_t size = 0;
69
    char buffer[PATH_MAX];
69 70
    void *ovalue = value;
70 71
    XattrOperations *xops;
71 72
    char *orig_value, *orig_value_start;
72 73
    ssize_t xattr_len, parsed_len = 0, attr_len;
73 74

  
74 75
    /* Get the actual len */
75
    xattr_len = llistxattr(rpath(ctx, path), value, 0);
76
    xattr_len = llistxattr(rpath(ctx, path, buffer), value, 0);
76 77
    if (xattr_len <= 0) {
77 78
        return xattr_len;
78 79
    }
79 80

  
80 81
    /* Now fetch the xattr and find the actual size */
81 82
    orig_value = qemu_malloc(xattr_len);
82
    xattr_len = llistxattr(rpath(ctx, path), orig_value, xattr_len);
83
    xattr_len = llistxattr(rpath(ctx, path, buffer), orig_value, xattr_len);
83 84

  
84 85
    /* store the orig pointer */
85 86
    orig_value_start = orig_value;
b/hw/9pfs/virtio-9p-xattr.h
54 54
static inline ssize_t pt_getxattr(FsContext *ctx, const char *path,
55 55
                                  const char *name, void *value, size_t size)
56 56
{
57
    return lgetxattr(rpath(ctx, path), name, value, size);
57
    char buffer[PATH_MAX];
58
    return lgetxattr(rpath(ctx, path, buffer), name, value, size);
58 59
}
59 60

  
60 61
static inline int pt_setxattr(FsContext *ctx, const char *path,
61 62
                              const char *name, void *value,
62 63
                              size_t size, int flags)
63 64
{
64
    return lsetxattr(rpath(ctx, path), name, value, size, flags);
65
    char buffer[PATH_MAX];
66
    return lsetxattr(rpath(ctx, path, buffer), name, value, size, flags);
65 67
}
66 68

  
67 69
static inline int pt_removexattr(FsContext *ctx,
68 70
                                 const char *path, const char *name)
69 71
{
70
    return lremovexattr(rpath(ctx, path), name);
72
    char buffer[PATH_MAX];
73
    return lremovexattr(rpath(ctx, path, buffer), name);
71 74
}
72 75

  
73 76
static inline ssize_t notsup_getxattr(FsContext *ctx, const char *path,
b/hw/9pfs/virtio-9p.h
101 101
#define P9_NOTAG    (u16)(~0)
102 102
#define P9_NOFID    (u32)(~0)
103 103
#define P9_MAXWELEM 16
104
static inline const char *rpath(FsContext *ctx, const char *path, char *buffer)
105
{
106
    snprintf(buffer, PATH_MAX, "%s/%s", ctx->fs_root, path);
107
    return buffer;
108
}
104 109

  
105 110
/*
106 111
 * ample room for Twrite/Rread header

Also available in: Unified diff