MCPcopy Create free account
hub / github.com/F-Stack/f-stack / fdcopy

Function fdcopy

freebsd/kern/kern_descrip.c:2329–2359  ·  view source on GitHub ↗

* Copy a filedesc structure. A NULL pointer in returns a NULL reference, * this is to ease callers, not catch errors. */

Source from the content-addressed store, hash-verified

2327 * this is to ease callers, not catch errors.
2328 */
2329struct filedesc *
2330fdcopy(struct filedesc *fdp)
2331{
2332 struct filedesc *newfdp;
2333 struct filedescent *nfde, *ofde;
2334 int i, lastfile;
2335
2336 MPASS(fdp != NULL);
2337
2338 newfdp = fdinit(fdp, true, &lastfile);
2339 /* copy all passable descriptors (i.e. not kqueue) */
2340 newfdp->fd_freefile = -1;
2341 for (i = 0; i <= lastfile; ++i) {
2342 ofde = &fdp->fd_ofiles[i];
2343 if (ofde->fde_file == NULL ||
2344 (ofde->fde_file->f_ops->fo_flags & DFLAG_PASSABLE) == 0 ||
2345 !fhold(ofde->fde_file)) {
2346 if (newfdp->fd_freefile == -1)
2347 newfdp->fd_freefile = i;
2348 continue;
2349 }
2350 nfde = &newfdp->fd_ofiles[i];
2351 *nfde = *ofde;
2352 filecaps_copy(&ofde->fde_caps, &nfde->fde_caps, true);
2353 fdused_init(newfdp, i);
2354 }
2355 if (newfdp->fd_freefile == -1)
2356 newfdp->fd_freefile = i;
2357 FILEDESC_SUNLOCK(fdp);
2358 return (newfdp);
2359}
2360
2361/*
2362 * Copy a pwddesc structure.

Callers 3

do_forkFunction · 0.85
fdunshareFunction · 0.85
ff_adapt_user_proc_addFunction · 0.85

Calls 4

fdinitFunction · 0.85
fholdFunction · 0.85
filecaps_copyFunction · 0.85
fdused_initFunction · 0.85

Tested by

no test coverage detected