uipc_mqueue.c (03f70aec67ab9e8449013f5c1b1e2d4e87acdd69) | uipc_mqueue.c (ba0360b135145f77a5b12dc6c446dd5ee8d10335) |
---|---|
1/*- 2 * Copyright (c) 2005 David Xu <davidxu@freebsd.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 204 unchanged lines hidden (view full) --- 213static struct vop_vector mqfs_vnodeops; 214static struct fileops mqueueops; 215 216/* 217 * Directory structure construction and manipulation 218 */ 219#ifdef notyet 220static struct mqfs_node *mqfs_create_dir(struct mqfs_node *parent, | 1/*- 2 * Copyright (c) 2005 David Xu <davidxu@freebsd.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 204 unchanged lines hidden (view full) --- 213static struct vop_vector mqfs_vnodeops; 214static struct fileops mqueueops; 215 216/* 217 * Directory structure construction and manipulation 218 */ 219#ifdef notyet 220static struct mqfs_node *mqfs_create_dir(struct mqfs_node *parent, |
221 const char *name, int namelen); | 221 const char *name, int namelen, struct ucred *cred, int mode); |
222static struct mqfs_node *mqfs_create_link(struct mqfs_node *parent, | 222static struct mqfs_node *mqfs_create_link(struct mqfs_node *parent, |
223 const char *name, int namelen); | 223 const char *name, int namelen, struct ucred *cred, int mode); |
224#endif 225 226static struct mqfs_node *mqfs_create_file(struct mqfs_node *parent, | 224#endif 225 226static struct mqfs_node *mqfs_create_file(struct mqfs_node *parent, |
227 const char *name, int namelen); | 227 const char *name, int namelen, struct ucred *cred, int mode); |
228static int mqfs_destroy(struct mqfs_node *mn); 229static void mqfs_fileno_alloc(struct mqfs_info *mi, struct mqfs_node *mn); 230static void mqfs_fileno_free(struct mqfs_info *mi, struct mqfs_node *mn); 231static int mqfs_allocv(struct mount *mp, struct vnode **vpp, struct mqfs_node *pn); 232 233/* 234 * Message queue construction and maniplation 235 */ --- 166 unchanged lines hidden (view full) --- 402 node->mn_parent = parent; 403 LIST_INIT(&node->mn_children); 404 LIST_INIT(&node->mn_vnodes); 405 LIST_INSERT_HEAD(&parent->mn_children, node, mn_sibling); 406 mqnode_addref(parent); 407 return (0); 408} 409 | 228static int mqfs_destroy(struct mqfs_node *mn); 229static void mqfs_fileno_alloc(struct mqfs_info *mi, struct mqfs_node *mn); 230static void mqfs_fileno_free(struct mqfs_info *mi, struct mqfs_node *mn); 231static int mqfs_allocv(struct mount *mp, struct vnode **vpp, struct mqfs_node *pn); 232 233/* 234 * Message queue construction and maniplation 235 */ --- 166 unchanged lines hidden (view full) --- 402 node->mn_parent = parent; 403 LIST_INIT(&node->mn_children); 404 LIST_INIT(&node->mn_vnodes); 405 LIST_INSERT_HEAD(&parent->mn_children, node, mn_sibling); 406 mqnode_addref(parent); 407 return (0); 408} 409 |
410static struct mqfs_node * 411mqfs_create_node(const char *name, int namelen, struct ucred *cred, int mode, 412 int nodetype) 413{ 414 struct mqfs_node *node; 415 416 node = mqnode_alloc(); 417 strncpy(node->mn_name, name, namelen); 418 node->mn_type = nodetype; 419 node->mn_refcount = 1; 420 getnanotime(&node->mn_birth); 421 node->mn_ctime = node->mn_atime = node->mn_mtime 422 = node->mn_birth; 423 node->mn_uid = cred->cr_uid; 424 node->mn_gid = cred->cr_gid; 425 node->mn_mode = mode; 426 return (node); 427} 428 |
|
410/* | 429/* |
430 * Create a file 431 */ 432static struct mqfs_node * 433mqfs_create_file(struct mqfs_node *parent, const char *name, int namelen, 434 struct ucred *cred, int mode) 435{ 436 struct mqfs_node *node; 437 438 node = mqfs_create_node(name, namelen, cred, mode, mqfstype_file); 439 if (mqfs_add_node(parent, node) != 0) { 440 mqnode_free(node); 441 return (NULL); 442 } 443 return (node); 444} 445 446/* |
|
411 * Add . and .. to a directory 412 */ 413static int 414mqfs_fixup_dir(struct mqfs_node *parent) 415{ 416 struct mqfs_node *dir; 417 418 dir = mqnode_alloc(); --- 19 unchanged lines hidden (view full) --- 438} 439 440#ifdef notyet 441 442/* 443 * Create a directory 444 */ 445static struct mqfs_node * | 447 * Add . and .. to a directory 448 */ 449static int 450mqfs_fixup_dir(struct mqfs_node *parent) 451{ 452 struct mqfs_node *dir; 453 454 dir = mqnode_alloc(); --- 19 unchanged lines hidden (view full) --- 474} 475 476#ifdef notyet 477 478/* 479 * Create a directory 480 */ 481static struct mqfs_node * |
446mqfs_create_dir(struct mqfs_node *parent, const char *name, int namelen) | 482mqfs_create_dir(struct mqfs_node *parent, const char *name, int namelen, 483 struct ucred *cred, int mode) |
447{ | 484{ |
448 struct mqfs_node *dir; | 485 struct mqfs_node *node; |
449 | 486 |
450 dir = mqnode_alloc(); 451 strncpy(dir->mn_name, name, namelen); 452 dir->mn_type = mqfstype_dir; 453 dir->mn_refcount = 1; 454 if (mqfs_add_node(parent, dir) != 0) { 455 mqnode_free(dir); | 487 node = mqfs_create_node(name, namelen, cred, mode, mqfstype_dir); 488 if (mqfs_add_node(parent, node) != 0) { 489 mqnode_free(node); |
456 return (NULL); 457 } 458 | 490 return (NULL); 491 } 492 |
459 if (mqfs_fixup_dir(dir) != 0) { 460 mqfs_destroy(dir); | 493 if (mqfs_fixup_dir(node) != 0) { 494 mqfs_destroy(node); |
461 return (NULL); 462 } | 495 return (NULL); 496 } |
463 464 return (dir); | 497 return (node); |
465} 466 467/* 468 * Create a symlink 469 */ 470static struct mqfs_node * | 498} 499 500/* 501 * Create a symlink 502 */ 503static struct mqfs_node * |
471mqfs_create_link(struct mqfs_node *parent, const char *name, int namelen) | 504mqfs_create_link(struct mqfs_node *parent, const char *name, int namelen, 505 struct ucred *cred, int mode) |
472{ 473 struct mqfs_node *node; 474 | 506{ 507 struct mqfs_node *node; 508 |
475 node = mqfs_create_file(parent, name, namelen); 476 if (node == NULL) 477 return (NULL); 478 node->mn_type = mqfstype_symlink; 479 return (node); 480} 481 482#endif 483 484/* 485 * Create a file 486 */ 487static struct mqfs_node * 488mqfs_create_file(struct mqfs_node *parent, const char *name, int namelen) 489{ 490 struct mqfs_node *node; 491 492 node = mqnode_alloc(); 493 strncpy(node->mn_name, name, namelen); 494 node->mn_type = mqfstype_file; 495 node->mn_refcount = 1; 496 | 509 node = mqfs_create_node(name, namelen, cred, mode, mqfstype_symlink); |
497 if (mqfs_add_node(parent, node) != 0) { 498 mqnode_free(node); 499 return (NULL); 500 } 501 return (node); 502} 503 | 510 if (mqfs_add_node(parent, node) != 0) { 511 mqnode_free(node); 512 return (NULL); 513 } 514 return (node); 515} 516 |
517#endif 518 |
|
504/* 505 * Destroy a node or a tree of nodes 506 */ 507static int 508mqfs_destroy(struct mqfs_node *node) 509{ 510 struct mqfs_node *parent; 511 --- 104 unchanged lines hidden (view full) --- 616 mvdata_zone = uma_zcreate("mvdata", 617 sizeof(struct mqfs_vdata), NULL, NULL, NULL, 618 NULL, UMA_ALIGN_PTR, 0); 619 mqnoti_zone = uma_zcreate("mqnotifier", sizeof(struct mqueue_notifier), 620 NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0); 621 mi = &mqfs_data; 622 sx_init(&mi->mi_lock, "mqfs lock"); 623 /* set up the root diretory */ | 519/* 520 * Destroy a node or a tree of nodes 521 */ 522static int 523mqfs_destroy(struct mqfs_node *node) 524{ 525 struct mqfs_node *parent; 526 --- 104 unchanged lines hidden (view full) --- 631 mvdata_zone = uma_zcreate("mvdata", 632 sizeof(struct mqfs_vdata), NULL, NULL, NULL, 633 NULL, UMA_ALIGN_PTR, 0); 634 mqnoti_zone = uma_zcreate("mqnotifier", sizeof(struct mqueue_notifier), 635 NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0); 636 mi = &mqfs_data; 637 sx_init(&mi->mi_lock, "mqfs lock"); 638 /* set up the root diretory */ |
624 root = mqnode_alloc(); 625 root->mn_type = mqfstype_root; 626 root->mn_refcount = 1; 627 root->mn_name[0] = '/'; | 639 root = mqfs_create_node("/", 1, curthread->td_ucred, 01777, 640 mqfstype_root); |
628 root->mn_info = mi; 629 LIST_INIT(&root->mn_children); 630 LIST_INIT(&root->mn_vnodes); | 641 root->mn_info = mi; 642 LIST_INIT(&root->mn_children); 643 LIST_INIT(&root->mn_vnodes); |
631 root->mn_mode = 01777; | |
632 mi->mi_root = root; 633 mqfs_fileno_init(mi); 634 mqfs_fileno_alloc(mi, root); 635 mqfs_fixup_dir(root); 636 exit_tag = EVENTHANDLER_REGISTER(process_exit, mq_proc_exit, NULL, 637 EVENTHANDLER_PRI_ANY); 638 mq_fdclose = mqueue_fdclose; 639 p31b_setcfg(CTL_P1003_1B_MESSAGE_PASSING, _POSIX_MESSAGE_PASSING); --- 267 unchanged lines hidden (view full) --- 907 mqueue_free(mq); 908 sx_xunlock(&mqfs->mi_lock); 909 return (EEXIST); 910 } 911#else 912 if ((cnp->cn_flags & HASBUF) == 0) 913 panic("%s: no name", __func__); 914#endif | 644 mi->mi_root = root; 645 mqfs_fileno_init(mi); 646 mqfs_fileno_alloc(mi, root); 647 mqfs_fixup_dir(root); 648 exit_tag = EVENTHANDLER_REGISTER(process_exit, mq_proc_exit, NULL, 649 EVENTHANDLER_PRI_ANY); 650 mq_fdclose = mqueue_fdclose; 651 p31b_setcfg(CTL_P1003_1B_MESSAGE_PASSING, _POSIX_MESSAGE_PASSING); --- 267 unchanged lines hidden (view full) --- 919 mqueue_free(mq); 920 sx_xunlock(&mqfs->mi_lock); 921 return (EEXIST); 922 } 923#else 924 if ((cnp->cn_flags & HASBUF) == 0) 925 panic("%s: no name", __func__); 926#endif |
915 pn = mqfs_create_file(pd, cnp->cn_nameptr, cnp->cn_namelen); 916 pn->mn_mode = ap->a_vap->va_mode; 917 pn->mn_uid = cnp->cn_cred->cr_uid; 918 pn->mn_gid = cnp->cn_cred->cr_gid; 919 pn->mn_data = mq; 920 getnanotime(&pn->mn_birth); 921 pn->mn_ctime = pn->mn_atime = pn->mn_mtime = pn->mn_birth; 922 /* node attribute */ 923 error = mqfs_allocv(ap->a_dvp->v_mount, ap->a_vpp, pn); | 927 pn = mqfs_create_file(pd, cnp->cn_nameptr, cnp->cn_namelen, 928 cnp->cn_cred, ap->a_vap->va_mode); 929 if (pn == NULL) 930 error = ENOSPC; 931 else { 932 error = mqfs_allocv(ap->a_dvp->v_mount, ap->a_vpp, pn); 933 if (error) 934 mqfs_destroy(pn); 935 else 936 pn->mn_data = mq; 937 } |
924 sx_xunlock(&mqfs->mi_lock); | 938 sx_xunlock(&mqfs->mi_lock); |
939 if (error) 940 mqueue_free(mq); |
|
925 return (error); 926} 927 928/* 929 * Remove an entry 930 */ 931static 932int do_unlink(struct mqfs_node *pn, struct ucred *ucred) --- 461 unchanged lines hidden (view full) --- 1394 if (pn != NULL) { 1395 sx_xunlock(&mqfs->mi_lock); 1396 return (EEXIST); 1397 } 1398#else 1399 if ((cnp->cn_flags & HASBUF) == 0) 1400 panic("%s: no name", __func__); 1401#endif | 941 return (error); 942} 943 944/* 945 * Remove an entry 946 */ 947static 948int do_unlink(struct mqfs_node *pn, struct ucred *ucred) --- 461 unchanged lines hidden (view full) --- 1410 if (pn != NULL) { 1411 sx_xunlock(&mqfs->mi_lock); 1412 return (EEXIST); 1413 } 1414#else 1415 if ((cnp->cn_flags & HASBUF) == 0) 1416 panic("%s: no name", __func__); 1417#endif |
1402 pn = mqfs_create_dir(pd, cnp->cn_nameptr, cnp->cn_namelen); 1403 pn->mn_mode = ap->a_vap->va_mode; 1404 pn->mn_uid = cnp->cn_cred->cr_uid; 1405 pn->mn_gid = cnp->cn_cred->cr_gid; 1406 getnanotime(&pn->mn_birth); 1407 pn->mn_ctime = pn->mn_atime = pn->mn_mtime = pn->mn_birth; 1408 /* node attribute */ 1409 error = mqfs_allocv(ap->a_dvp->v_mount, ap->a_vpp, pn); | 1418 pn = mqfs_create_dir(pd, cnp->cn_nameptr, cnp->cn_namelen, 1419 ap->a_vap->cn_cred, ap->a_vap->va_mode); 1420 if (pn == NULL) 1421 error = ENOSPC; 1422 else 1423 error = mqfs_allocv(ap->a_dvp->v_mount, ap->a_vpp, pn); |
1410 sx_xunlock(&mqfs->mi_lock); 1411 return (error); 1412} 1413 1414#if 0 1415struct vop_rmdir_args { 1416 struct vnode *a_dvp; 1417 struct vnode *a_vp; --- 513 unchanged lines hidden (view full) --- 1931 if (!(flags & O_CREAT)) { 1932 error = ENOENT; 1933 } else { 1934 mq = mqueue_alloc(pattr); 1935 if (mq == NULL) { 1936 error = ENFILE; 1937 } else { 1938 pn = mqfs_create_file(mqfs_data.mi_root, | 1424 sx_xunlock(&mqfs->mi_lock); 1425 return (error); 1426} 1427 1428#if 0 1429struct vop_rmdir_args { 1430 struct vnode *a_dvp; 1431 struct vnode *a_vp; --- 513 unchanged lines hidden (view full) --- 1945 if (!(flags & O_CREAT)) { 1946 error = ENOENT; 1947 } else { 1948 mq = mqueue_alloc(pattr); 1949 if (mq == NULL) { 1950 error = ENFILE; 1951 } else { 1952 pn = mqfs_create_file(mqfs_data.mi_root, |
1939 path + 1, len - 1); | 1953 path + 1, len - 1, td->td_ucred, 1954 cmode); |
1940 if (pn == NULL) { 1941 error = ENOSPC; 1942 mqueue_free(mq); 1943 } 1944 } 1945 } 1946 1947 if (error == 0) { 1948 pn->mn_data = mq; | 1955 if (pn == NULL) { 1956 error = ENOSPC; 1957 mqueue_free(mq); 1958 } 1959 } 1960 } 1961 1962 if (error == 0) { 1963 pn->mn_data = mq; |
1949 getnanotime(&pn->mn_birth); 1950 pn->mn_ctime = pn->mn_atime = pn->mn_mtime 1951 = pn->mn_birth; 1952 pn->mn_uid = td->td_ucred->cr_uid; 1953 pn->mn_gid = td->td_ucred->cr_gid; 1954 pn->mn_mode = cmode; | |
1955 } 1956 } else { 1957 if ((flags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL)) { 1958 error = EEXIST; 1959 } else { 1960 int acc_mode = 0; 1961 1962 if (flags & FREAD) --- 511 unchanged lines hidden --- | 1964 } 1965 } else { 1966 if ((flags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL)) { 1967 error = EEXIST; 1968 } else { 1969 int acc_mode = 0; 1970 1971 if (flags & FREAD) --- 511 unchanged lines hidden --- |