| 1 |
/* |
| 2 |
* Copyright (C) 2006 by Latchesar Ionkov <[email protected]> |
| 3 |
* Copyright (C) 2010-2014 by Lawrence Livermore National Security, LLC |
| 4 |
* |
| 5 |
* Permission is hereby granted, free of charge, to any person obtaining a |
| 6 |
* copy of this software and associated documentation files (the "Software"), |
| 7 |
* to deal in the Software without restriction, including without limitation |
| 8 |
* the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 9 |
* and/or sell copies of the Software, and to permit persons to whom the |
| 10 |
* Software is furnished to do so, subject to the following conditions: |
| 11 |
* |
| 12 |
* The above copyright notice and this permission notice (including the next |
| 13 |
* paragraph) shall be included in all copies or substantial portions of the |
| 14 |
* Software. |
| 15 |
* |
| 16 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 |
* PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 20 |
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 21 |
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 22 |
* DEALINGS IN THE SOFTWARE. |
| 23 |
*/ |
| 24 |
|
| 25 |
#if HAVE_CONFIG_H |
| 26 |
#include "config.h" |
| 27 |
#endif |
| 28 |
#include <unistd.h> |
| 29 |
#include <sys/types.h> |
| 30 |
#include <sys/stat.h> |
| 31 |
#include <stdlib.h> |
| 32 |
#include <stdio.h> |
| 33 |
#include <string.h> |
| 34 |
#include <stdarg.h> |
| 35 |
#include <unistd.h> |
| 36 |
#include <pthread.h> |
| 37 |
#include <errno.h> |
| 38 |
#include <stdint.h> |
| 39 |
#include <inttypes.h> |
| 40 |
#include <libgen.h> |
| 41 |
|
| 42 |
#include "9p.h" |
| 43 |
#include "npfs.h" |
| 44 |
#include "npclient.h" |
| 45 |
#include "npcimpl.h" |
| 46 |
|
| 47 |
int |
| 48 |
npc_getattr (Npcfid *fid, u64 request_mask, u64 *valid, struct p9_qid *qid, |
| 49 |
u32 *mode, u32 *uid, u32 *gid, u64 *nlink, u64 *rdev, u64 *size, |
| 50 |
u64 *blksize, u64 *blocks, u64 *atime_sec, u64 *atime_nsec, |
| 51 |
u64 *mtime_sec, u64 *mtime_nsec, u64 *ctime_sec, u64 *ctime_nsec, |
| 52 |
u64 *btime_sec, u64 *btime_nsec, u64 *gen, u64 *data_version) |
| 53 |
{ |
| 54 |
Npfcall *tc = NULL, *rc = NULL; |
| 55 |
int ret = -1; |
| 56 |
|
| 57 |
if (!(tc = np_create_tgetattr (fid->fid, request_mask))) { |
| 58 |
np_uerror (ENOMEM); |
| 59 |
goto done; |
| 60 |
} |
| 61 |
if (fid->fsys->rpc(fid->fsys, tc, &rc) < 0) |
| 62 |
goto done; |
| 63 |
*valid = rc->u.rgetattr.valid; |
| 64 |
*qid = rc->u.rgetattr.qid; |
| 65 |
*mode = rc->u.rgetattr.mode; |
| 66 |
*uid = rc->u.rgetattr.uid; |
| 67 |
*gid = rc->u.rgetattr.gid; |
| 68 |
*nlink = rc->u.rgetattr.nlink; |
| 69 |
*rdev = rc->u.rgetattr.rdev; |
| 70 |
*size = rc->u.rgetattr.size; |
| 71 |
*blksize = rc->u.rgetattr.blksize; |
| 72 |
*blocks = rc->u.rgetattr.blocks; |
| 73 |
*atime_sec = rc->u.rgetattr.atime_sec; |
| 74 |
*atime_nsec = rc->u.rgetattr.atime_nsec; |
| 75 |
*mtime_sec = rc->u.rgetattr.mtime_sec; |
| 76 |
*mtime_nsec = rc->u.rgetattr.mtime_nsec; |
| 77 |
*ctime_sec = rc->u.rgetattr.ctime_sec; |
| 78 |
*ctime_nsec = rc->u.rgetattr.ctime_nsec; |
| 79 |
*btime_sec = rc->u.rgetattr.btime_sec; |
| 80 |
*btime_nsec = rc->u.rgetattr.btime_nsec; |
| 81 |
*gen = rc->u.rgetattr.gen; |
| 82 |
*data_version = rc->u.rgetattr.data_version; |
| 83 |
ret = 0; |
| 84 |
done: |
| 85 |
if (tc) |
| 86 |
free(tc); |
| 87 |
if (rc) |
| 88 |
free(rc); |
| 89 |
return ret; |
| 90 |
} |
| 91 |
|
| 92 |
int |
| 93 |
npc_fstat (Npcfid *fid, struct stat *sb) |
| 94 |
{ |
| 95 |
int ret = -1; |
| 96 |
u64 valid; |
| 97 |
struct p9_qid qid; |
| 98 |
u32 mode, uid, gid; |
| 99 |
u64 nlink, rdev, size, blksize, blocks; |
| 100 |
u64 atime_sec, atime_nsec; |
| 101 |
u64 mtime_sec, mtime_nsec; |
| 102 |
u64 ctime_sec, ctime_nsec; |
| 103 |
u64 btime_sec, btime_nsec; |
| 104 |
u64 gen, data_version; |
| 105 |
|
| 106 |
ret = npc_getattr (fid, P9_STAT_BASIC, &valid, &qid, |
| 107 |
&mode, &uid, &gid, &nlink, &rdev, &size, |
| 108 |
&blksize, &blocks, &atime_sec, &atime_nsec, |
| 109 |
&mtime_sec, &mtime_nsec, &ctime_sec, &ctime_nsec, |
| 110 |
&btime_sec, &btime_nsec, &gen, &data_version); |
| 111 |
if (ret == 0) { |
| 112 |
sb->st_dev = 0; |
| 113 |
sb->st_ino = qid.path; |
| 114 |
sb->st_mode = mode; |
| 115 |
sb->st_uid = uid; |
| 116 |
sb->st_gid = gid; |
| 117 |
sb->st_nlink = nlink; |
| 118 |
sb->st_rdev = rdev; |
| 119 |
sb->st_size = size; |
| 120 |
sb->st_blksize = blksize; |
| 121 |
sb->st_blocks = blocks; |
| 122 |
sb->st_atime = atime_sec; |
| 123 |
sb->st_atim.tv_nsec = atime_nsec; |
| 124 |
sb->st_mtime = mtime_sec; |
| 125 |
sb->st_mtim.tv_nsec = mtime_nsec; |
| 126 |
sb->st_ctime = ctime_sec; |
| 127 |
sb->st_ctim.tv_nsec = ctime_nsec; |
| 128 |
} |
| 129 |
return ret; |
| 130 |
} |
| 131 |
|
| 132 |
int |
| 133 |
npc_stat (Npcfid *root, char *path, struct stat *sb) |
| 134 |
{ |
| 135 |
Npcfid *fid; |
| 136 |
|
| 137 |
if (!(fid = npc_walk (root, path))) |
| 138 |
return -1; |
| 139 |
if (npc_fstat (fid, sb) < 0) { |
| 140 |
int saved_err = np_rerror (); |
| 141 |
(void)npc_clunk (fid); |
| 142 |
np_uerror (saved_err); |
| 143 |
return -1; |
| 144 |
} |
| 145 |
if (npc_clunk (fid) < 0) |
| 146 |
return -1; |
| 147 |
return 0; |
| 148 |
} |