segment 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. .TH SEGMENT 3
  2. .SH NAME
  3. segment \- long lived memory segments
  4. .SH SYNOPSIS
  5. .nf
  6. .B bind '#g' /mnt/segment
  7. .BI #g/ seg1
  8. .BI #g/ seg1 /ctl
  9. .BI #g/ seg1 /data
  10. .BI #g/ seg2
  11. .BI #g/ seg2 /ctl
  12. .BI #g/ seg2 /data
  13. ...
  14. .fi
  15. .SH DESCRIPTION
  16. .PP
  17. The
  18. .I segment
  19. device provides a 2-level file system representing
  20. long-lived sharable segments that processes may
  21. .IR segattach (2).
  22. The name of the directory is the
  23. .I class
  24. argument to
  25. .IR segattach .
  26. .PP
  27. New segments are created under the top level
  28. using
  29. .B create
  30. (see
  31. .IR open (2)).
  32. The
  33. .B DMDIR
  34. bit must be set in the permissions.
  35. .IR Remove (2)'ing
  36. the directory makes the segment no longer
  37. available for
  38. .IR segattach .
  39. However, the segment will continue to exist until all
  40. processes using it either exit or
  41. .I segdetach
  42. it.
  43. .PP
  44. Within each segment directory are two files,
  45. .B data
  46. and
  47. .BR ctl .
  48. Reading and writing
  49. .B data
  50. affects the contents of the segment.
  51. Reading and writing
  52. .B ctl
  53. retrieves and sets the segment's properties.
  54. .PP
  55. There is only one control message, which sets the segment's
  56. virtual address and length in bytes:
  57. .EX
  58. va \fIaddress length\fP
  59. .EE
  60. .I Address
  61. is automatically rounded down to a page boundary and
  62. .I length
  63. is rounded up to end the segment at a page boundary.
  64. The segment will reside at the same virtual address in
  65. all processes sharing it.
  66. When the segment
  67. is attached using
  68. .IR segattach,
  69. the address and length arguments are ignored in the call;
  70. they are defined only by the
  71. .B va
  72. control message.
  73. Once the address and length are set, they cannot be reset.
  74. .PP
  75. Reading the control file
  76. returns a message of the same format with the segment's actual
  77. start address and length.
  78. .PP
  79. Opening
  80. .B data
  81. or reading
  82. .B ctl
  83. before setting the virtual address yields the error
  84. ``segment not yet allocated''.
  85. .PP
  86. The permissions check when
  87. .IR segattach ing
  88. is equivalent to the one performed when opening
  89. .B data
  90. with mode ORDWR.
  91. .SH EXAMPLE
  92. .PP
  93. Create a one megabyte segment at address 0x10000000:
  94. .EX
  95. % bind '#g' /mnt/segment
  96. % mkdir /mnt/segment/example
  97. % echo 'va 0x10000000 0x100000' > /mnt/segment/example/ctl
  98. .EE
  99. .PP
  100. Put the string ``hi mom'' at the start of the segment:
  101. .EX
  102. % echo -n hi mom > /mnt/segment/example/data
  103. .EE
  104. .PP
  105. Attach the segment to a process:
  106. .EX
  107. {
  108. ulong va;
  109. va = segattach(0, "example", 0, 0);
  110. }
  111. .EE
  112. .SH "SEE ALSO
  113. .IR segattach (2)
  114. .SH SOURCE
  115. .B /sys/src/9/port/devsegment.c