static void test_rmknod (void) { Npfcall *fc, *fc2; struct p9_qid qid = { 1, 2, 3 }; if (!(fc = np_create_rmknod (&qid))) msg_exit ("out of memory"); fc2 = _rcv_buf (fc, P9_RMKNOD, __FUNCTION__); assert (fc->u.rmknod.qid.type == fc2->u.rmknod.qid.type); assert (fc->u.rmknod.qid.version == fc2->u.rmknod.qid.version); assert (fc->u.rmknod.qid.path == fc2->u.rmknod.qid.path); free (fc); free (fc2); }
Npfcall* diod_mknod(Npfid *fid, Npstr *name, u32 mode, u32 major, u32 minor, u32 gid) { Npsrv *srv = fid->conn->srv; Npfcall *ret; Fid *f = fid->aux; Path npath = NULL; Npqid qid; struct stat sb; if ((f->flags & DIOD_FID_FLAGS_ROFS)) { np_uerror (EROFS); goto error_quiet; } if (!(npath = path_append (srv, f->path, name))) { np_uerror (ENOMEM); goto error; } if (mknod (path_s (npath), mode, makedev (major, minor)) < 0 || lstat (path_s (npath), &sb) < 0) { np_uerror (errno); goto error_quiet; } diod_ustat2qid (&sb, &qid); if (!((ret = np_create_rmknod (&qid)))) { (void)unlink (path_s (npath)); np_uerror (ENOMEM); goto error; } path_decref (srv, npath); return ret; error: errn (np_rerror (), "diod_mknod %s@%s:%s/%.*s", fid->user->uname, np_conn_get_client_id (fid->conn), path_s (f->path), name->len, name->str); error_quiet: if (npath) path_decref (srv, npath); return NULL; }
Npfcall* diod_mknod(Npfid *fid, Npstr *name, u32 mode, u32 major, u32 minor, u32 gid) { Npfcall *ret; Fid *f = fid->aux; char *npath = NULL; Npqid qid; struct stat sb; if ((f->xflags & XFLAGS_RO)) { np_uerror (EROFS); goto error_quiet; } if (!(npath = _mkpath(f->path, name))) { np_uerror (ENOMEM); goto error; } if (mknod (npath, mode, makedev (major, minor)) < 0 || lstat (npath, &sb) < 0) { np_uerror (errno); goto error_quiet; } _ustat2qid (&sb, &qid); if (!((ret = np_create_rmknod (&qid)))) { (void)unlink (npath); np_uerror (ENOMEM); goto error; } free (npath); return ret; error: errn (np_rerror (), "diod_mknod %s@%s:%s/%.*s", fid->user->uname, np_conn_get_client_id (fid->conn), f->path, name->len, name->str); error_quiet: if (npath) free (npath); return NULL; }