Npfcall* diod_getattr(Npfid *fid, u64 request_mask) { Fid *f = fid->aux; Npfcall *ret; Npqid qid; struct stat sb; if ((f->flags & DIOD_FID_FLAGS_MOUNTPT)) { if (_statmnt (path_s (f->path), &sb) < 0) { np_uerror (errno); goto error_quiet; } } else { if (lstat (path_s (f->path), &sb) < 0) { np_uerror (errno); goto error_quiet; } } diod_ustat2qid (&sb, &qid); if (!(ret = np_create_rgetattr(request_mask, &qid, sb.st_mode, sb.st_uid, sb.st_gid, sb.st_nlink, sb.st_rdev, sb.st_size, sb.st_blksize, sb.st_blocks, sb.st_atim.tv_sec, sb.st_atim.tv_nsec, sb.st_mtim.tv_sec, sb.st_mtim.tv_nsec, sb.st_ctim.tv_sec, sb.st_ctim.tv_nsec, 0, 0, 0, 0))) { np_uerror (ENOMEM); goto error; } return ret; error: errn (np_rerror (), "diod_getattr %s@%s:%s", fid->user->uname, np_conn_get_client_id (fid->conn), path_s (f->path)); error_quiet: return NULL; }
Npfcall* diod_getattr(Npfid *fid, u64 request_mask) { Fid *f = fid->aux; Npfcall *ret = NULL; Npqid qid; if (_fidstat (f) < 0) goto error_quiet; _ustat2qid (&f->stat, &qid); if (!(ret = np_create_rgetattr(request_mask, &qid, f->stat.st_mode, f->stat.st_uid, f->stat.st_gid, f->stat.st_nlink, f->stat.st_rdev, f->stat.st_size, f->stat.st_blksize, f->stat.st_blocks, f->stat.st_atim.tv_sec, f->stat.st_atim.tv_nsec, f->stat.st_mtim.tv_sec, f->stat.st_mtim.tv_nsec, f->stat.st_ctim.tv_sec, f->stat.st_ctim.tv_nsec, 0, 0, 0, 0))) { np_uerror (ENOMEM); goto error; } return ret; error: errn (np_rerror (), "diod_getattr %s@%s:%s", fid->user->uname, np_conn_get_client_id (fid->conn), f->path); error_quiet: if (ret) free (ret); return NULL; }
static void test_rgetattr (void) { Npfcall *fc, *fc2; struct p9_qid qid = { 1, 2, 3 }; if (!(fc = np_create_rgetattr (1, &qid, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21))) msg_exit ("out of memory"); fc2 = _rcv_buf (fc, P9_RGETATTR, __FUNCTION__); assert (fc->u.rgetattr.valid == fc2->u.rgetattr.valid); assert (fc->u.rgetattr.qid.type == fc2->u.rgetattr.qid.type); assert (fc->u.rgetattr.qid.version == fc2->u.rgetattr.qid.version); assert (fc->u.rgetattr.qid.path == fc2->u.rgetattr.qid.path); assert (fc->u.rgetattr.mode == fc2->u.rgetattr.mode); assert (fc->u.rgetattr.uid == fc2->u.rgetattr.uid); assert (fc->u.rgetattr.gid == fc2->u.rgetattr.gid); assert (fc->u.rgetattr.nlink == fc2->u.rgetattr.nlink); assert (fc->u.rgetattr.rdev == fc2->u.rgetattr.rdev); assert (fc->u.rgetattr.size == fc2->u.rgetattr.size); assert (fc->u.rgetattr.blksize == fc2->u.rgetattr.blksize); assert (fc->u.rgetattr.blocks == fc2->u.rgetattr.blocks); assert (fc->u.rgetattr.atime_sec == fc2->u.rgetattr.atime_sec); assert (fc->u.rgetattr.atime_nsec == fc2->u.rgetattr.atime_nsec); assert (fc->u.rgetattr.mtime_sec == fc2->u.rgetattr.mtime_sec); assert (fc->u.rgetattr.mtime_nsec == fc2->u.rgetattr.mtime_nsec); assert (fc->u.rgetattr.ctime_sec == fc2->u.rgetattr.ctime_sec); assert (fc->u.rgetattr.ctime_nsec == fc2->u.rgetattr.ctime_nsec); assert (fc->u.rgetattr.btime_sec == fc2->u.rgetattr.btime_sec); assert (fc->u.rgetattr.btime_nsec == fc2->u.rgetattr.btime_nsec); assert (fc->u.rgetattr.gen == fc2->u.rgetattr.gen); assert (fc->u.rgetattr.data_version == fc2->u.rgetattr.data_version); free (fc); free (fc2); }