Lines Matching refs:head

209  * @head:   Pointer to "struct tomoyo_io_buffer".
213 static bool tomoyo_flush(struct tomoyo_io_buffer *head)
215 while (head->r.w_pos) {
216 const char *w = head->r.w[0];
220 if (len > head->read_user_buf_avail)
221 len = head->read_user_buf_avail;
224 if (copy_to_user(head->read_user_buf, w, len))
226 head->read_user_buf_avail -= len;
227 head->read_user_buf += len;
230 head->r.w[0] = w;
234 if (head->poll) {
235 if (!head->read_user_buf_avail ||
236 copy_to_user(head->read_user_buf, "", 1))
238 head->read_user_buf_avail--;
239 head->read_user_buf++;
241 head->r.w_pos--;
242 for (len = 0; len < head->r.w_pos; len++)
243 head->r.w[len] = head->r.w[len + 1];
245 head->r.avail = 0;
252 * @head: Pointer to "struct tomoyo_io_buffer".
255 * Note that @string has to be kept valid until @head is kfree()d.
259 static void tomoyo_set_string(struct tomoyo_io_buffer *head, const char *string)
261 if (head->r.w_pos < TOMOYO_MAX_IO_READ_QUEUE) {
262 head->r.w[head->r.w_pos++] = string;
263 tomoyo_flush(head);
268 static void tomoyo_io_printf(struct tomoyo_io_buffer *head, const char *fmt,
274 * @head: Pointer to "struct tomoyo_io_buffer".
277 static void tomoyo_io_printf(struct tomoyo_io_buffer *head, const char *fmt,
282 size_t pos = head->r.avail;
283 int size = head->readbuf_size - pos;
288 len = vsnprintf(head->read_buf + pos, size, fmt, args) + 1;
290 if (pos + len >= head->readbuf_size) {
294 head->r.avail += len;
295 tomoyo_set_string(head, head->read_buf + pos);
301 * @head: Pointer to "struct tomoyo_io_buffer".
305 static void tomoyo_set_space(struct tomoyo_io_buffer *head)
307 tomoyo_set_string(head, " ");
313 * @head: Pointer to "struct tomoyo_io_buffer".
317 static bool tomoyo_set_lf(struct tomoyo_io_buffer *head)
319 tomoyo_set_string(head, "\n");
320 return !head->r.w_pos;
326 * @head: Pointer to "struct tomoyo_io_buffer".
330 static void tomoyo_set_slash(struct tomoyo_io_buffer *head)
332 tomoyo_set_string(head, "/");
365 * @head: Pointer to "struct tomoyo_io_buffer".
369 static void tomoyo_print_namespace(struct tomoyo_io_buffer *head)
373 tomoyo_set_string(head,
374 container_of(head->r.ns,
377 tomoyo_set_space(head);
383 * @head: Pointer to "struct tomoyo_io_buffer".
386 static void tomoyo_print_name_union(struct tomoyo_io_buffer *head,
389 tomoyo_set_space(head);
391 tomoyo_set_string(head, "@");
392 tomoyo_set_string(head, ptr->group->group_name->name);
394 tomoyo_set_string(head, ptr->filename->name);
401 * @head: Pointer to "struct tomoyo_io_buffer".
406 static void tomoyo_print_name_union_quoted(struct tomoyo_io_buffer *head,
410 tomoyo_set_string(head, "@");
411 tomoyo_set_string(head, ptr->group->group_name->name);
413 tomoyo_set_string(head, "\"");
414 tomoyo_set_string(head, ptr->filename->name);
415 tomoyo_set_string(head, "\"");
422 * @head: Pointer to "struct tomoyo_io_buffer".
428 (struct tomoyo_io_buffer *head, const struct tomoyo_number_union *ptr)
431 tomoyo_set_string(head, "@");
432 tomoyo_set_string(head, ptr->group->group_name->name);
463 tomoyo_io_printf(head, "%s", buffer);
470 * @head: Pointer to "struct tomoyo_io_buffer".
475 static void tomoyo_print_number_union(struct tomoyo_io_buffer *head,
478 tomoyo_set_space(head);
479 tomoyo_print_number_union_nospace(head, ptr);
670 * @head: Pointer to "struct tomoyo_io_buffer".
674 static int tomoyo_write_profile(struct tomoyo_io_buffer *head)
676 char *data = head->write_buf;
681 if (sscanf(data, "PROFILE_VERSION=%u", &head->w.ns->profile_version)
688 profile = tomoyo_assign_profile(head->w.ns, i);
722 * @head: Pointer to "struct tomoyo_io_buffer".
729 static void tomoyo_print_config(struct tomoyo_io_buffer *head, const u8 config)
731 tomoyo_io_printf(head, "={ mode=%s grant_log=%s reject_log=%s }\n",
740 * @head: Pointer to "struct tomoyo_io_buffer".
744 static void tomoyo_read_profile(struct tomoyo_io_buffer *head)
748 container_of(head->r.ns, typeof(*ns), namespace_list);
751 if (head->r.eof)
754 index = head->r.index;
756 switch (head->r.step) {
758 tomoyo_print_namespace(head);
759 tomoyo_io_printf(head, "PROFILE_VERSION=%u\n",
761 head->r.step++;
764 for ( ; head->r.index < TOMOYO_MAX_PROFILES;
765 head->r.index++)
766 if (ns->profile_ptr[head->r.index])
768 if (head->r.index == TOMOYO_MAX_PROFILES) {
769 head->r.eof = true;
772 head->r.step++;
780 tomoyo_print_namespace(head);
781 tomoyo_io_printf(head, "%u-COMMENT=", index);
782 tomoyo_set_string(head, comment ? comment->name : "");
783 tomoyo_set_lf(head);
784 tomoyo_print_namespace(head);
785 tomoyo_io_printf(head, "%u-PREFERENCE={ ", index);
787 tomoyo_io_printf(head, "%s=%u ",
790 tomoyo_set_string(head, "}\n");
791 head->r.step++;
796 tomoyo_print_namespace(head);
797 tomoyo_io_printf(head, "%u-%s", index, "CONFIG");
798 tomoyo_print_config(head, profile->default_config);
799 head->r.bit = 0;
800 head->r.step++;
804 for ( ; head->r.bit < TOMOYO_MAX_MAC_INDEX
805 + TOMOYO_MAX_MAC_CATEGORY_INDEX; head->r.bit++) {
806 const u8 i = head->r.bit;
811 tomoyo_print_namespace(head);
813 tomoyo_io_printf(head, "%u-CONFIG::%s::%s",
819 tomoyo_io_printf(head, "%u-CONFIG::%s", index,
821 tomoyo_print_config(head, config);
822 head->r.bit++;
825 if (head->r.bit == TOMOYO_MAX_MAC_INDEX
827 head->r.index++;
828 head->r.step = 1;
832 if (tomoyo_flush(head))
847 return container_of(a, struct tomoyo_manager, head)->manager ==
848 container_of(b, struct tomoyo_manager, head)->manager;
877 error = tomoyo_update_policy(&e.head, sizeof(e), &param,
887 * @head: Pointer to "struct tomoyo_io_buffer".
893 static int tomoyo_write_manager(struct tomoyo_io_buffer *head)
895 char *data = head->write_buf;
898 tomoyo_manage_by_non_root = !head->w.is_delete;
901 return tomoyo_update_manager_entry(data, head->w.is_delete);
907 * @head: Pointer to "struct tomoyo_io_buffer".
911 static void tomoyo_read_manager(struct tomoyo_io_buffer *head)
913 if (head->r.eof)
915 list_for_each_cookie(head->r.acl, &tomoyo_kernel_namespace.policy_list[TOMOYO_ID_MANAGER]) {
917 list_entry(head->r.acl, typeof(*ptr), head.list);
919 if (ptr->head.is_deleted)
921 if (!tomoyo_flush(head))
923 tomoyo_set_string(head, ptr->manager->name);
924 tomoyo_set_lf(head);
926 head->r.eof = true;
954 list_for_each_entry_rcu(ptr, &tomoyo_kernel_namespace.policy_list[TOMOYO_ID_MANAGER], head.list,
956 if (!ptr->head.is_deleted &&
983 * @head: Pointer to "struct tomoyo_io_buffer".
990 static bool tomoyo_select_domain(struct tomoyo_io_buffer *head,
1019 head->w.domain = domain;
1020 /* Accessing read_buf is safe because head->io_sem is held. */
1021 if (!head->read_buf)
1023 memset(&head->r, 0, sizeof(head->r));
1024 head->r.print_this_domain_only = true;
1026 head->r.domain = &domain->list;
1028 head->r.eof = true;
1029 tomoyo_io_printf(head, "# select %s\n", data);
1031 tomoyo_io_printf(head, "# This is a deleted domain.\n");
1046 const struct tomoyo_task_acl *p1 = container_of(a, typeof(*p1), head);
1047 const struct tomoyo_task_acl *p2 = container_of(b, typeof(*p2), head);
1067 .head.type = TOMOYO_TYPE_MANUAL_TASK_ACL,
1072 error = tomoyo_update_domain(&e.head, sizeof(e), param,
1166 * @head: Pointer to "struct tomoyo_io_buffer".
1172 static int tomoyo_write_domain(struct tomoyo_io_buffer *head)
1174 char *data = head->write_buf;
1176 struct tomoyo_domain_info *domain = head->w.domain;
1177 const bool is_delete = head->w.is_delete;
1191 head->w.domain = domain;
1227 * @head: Pointer to "struct tomoyo_io_buffer".
1232 static bool tomoyo_print_condition(struct tomoyo_io_buffer *head,
1235 switch (head->r.cond_step) {
1237 head->r.cond_index = 0;
1238 head->r.cond_step++;
1240 tomoyo_set_space(head);
1241 tomoyo_set_string(head, cond->transit->name);
1260 for (skip = 0; skip < head->r.cond_index; skip++) {
1285 while (head->r.cond_index < condc) {
1290 if (!tomoyo_flush(head))
1293 head->r.cond_index++;
1294 tomoyo_set_space(head);
1297 tomoyo_io_printf(head,
1300 tomoyo_set_string(head,
1302 tomoyo_set_string(head, "\"");
1306 tomoyo_set_string(head,
1308 tomoyo_set_string(head,
1310 tomoyo_io_printf(head, "\"]%s=", envp->is_not ? "!" : "");
1312 tomoyo_set_string(head, "\"");
1313 tomoyo_set_string(head, envp->value->name);
1314 tomoyo_set_string(head, "\"");
1316 tomoyo_set_string(head,
1323 (head, numbers_p++);
1326 tomoyo_set_string(head,
1330 tomoyo_set_string(head, match ? "=" : "!=");
1334 (head, names_p++);
1338 (head, numbers_p++);
1341 tomoyo_set_string(head,
1347 head->r.cond_step++;
1350 if (!tomoyo_flush(head))
1352 head->r.cond_step++;
1356 tomoyo_io_printf(head, " grant_log=%s",
1359 tomoyo_set_lf(head);
1368 * @head: Pointer to "struct tomoyo_io_buffer".
1373 static void tomoyo_set_group(struct tomoyo_io_buffer *head,
1376 if (head->type == TOMOYO_EXCEPTIONPOLICY) {
1377 tomoyo_print_namespace(head);
1378 tomoyo_io_printf(head, "acl_group %u ",
1379 head->r.acl_group_index);
1381 tomoyo_set_string(head, category);
1387 * @head: Pointer to "struct tomoyo_io_buffer".
1392 static bool tomoyo_print_entry(struct tomoyo_io_buffer *head,
1399 if (head->r.print_cond_part)
1403 if (!tomoyo_flush(head))
1407 container_of(acl, typeof(*ptr), head);
1413 if (head->r.print_transition_related_only &&
1417 tomoyo_set_group(head, "file ");
1420 tomoyo_set_slash(head);
1422 tomoyo_set_string(head, tomoyo_path_keyword[bit]);
1426 tomoyo_print_name_union(head, &ptr->name);
1429 container_of(acl, typeof(*ptr), head);
1431 tomoyo_set_group(head, "task ");
1432 tomoyo_set_string(head, "manual_domain_transition ");
1433 tomoyo_set_string(head, ptr->domainname->name);
1434 } else if (head->r.print_transition_related_only) {
1438 container_of(acl, typeof(*ptr), head);
1445 tomoyo_set_group(head, "file ");
1448 tomoyo_set_slash(head);
1450 tomoyo_set_string(head, tomoyo_mac_keywords
1455 tomoyo_print_name_union(head, &ptr->name1);
1456 tomoyo_print_name_union(head, &ptr->name2);
1459 container_of(acl, typeof(*ptr), head);
1466 tomoyo_set_group(head, "file ");
1469 tomoyo_set_slash(head);
1471 tomoyo_set_string(head, tomoyo_mac_keywords
1476 tomoyo_print_name_union(head, &ptr->name);
1477 tomoyo_print_number_union(head, &ptr->number);
1480 container_of(acl, typeof(*ptr), head);
1487 tomoyo_set_group(head, "file ");
1490 tomoyo_set_slash(head);
1492 tomoyo_set_string(head, tomoyo_mac_keywords
1497 tomoyo_print_name_union(head, &ptr->name);
1498 tomoyo_print_number_union(head, &ptr->mode);
1499 tomoyo_print_number_union(head, &ptr->major);
1500 tomoyo_print_number_union(head, &ptr->minor);
1503 container_of(acl, typeof(*ptr), head);
1510 tomoyo_set_group(head, "network inet ");
1511 tomoyo_set_string(head, tomoyo_proto_keyword
1513 tomoyo_set_space(head);
1516 tomoyo_set_slash(head);
1518 tomoyo_set_string(head, tomoyo_socket_keyword[bit]);
1522 tomoyo_set_space(head);
1524 tomoyo_set_string(head, "@");
1525 tomoyo_set_string(head, ptr->address.group->group_name
1531 tomoyo_io_printf(head, "%s", buf);
1533 tomoyo_print_number_union(head, &ptr->port);
1536 container_of(acl, typeof(*ptr), head);
1543 tomoyo_set_group(head, "network unix ");
1544 tomoyo_set_string(head, tomoyo_proto_keyword
1546 tomoyo_set_space(head);
1549 tomoyo_set_slash(head);
1551 tomoyo_set_string(head, tomoyo_socket_keyword[bit]);
1555 tomoyo_print_name_union(head, &ptr->name);
1558 container_of(acl, typeof(*ptr), head);
1560 tomoyo_set_group(head, "file mount");
1561 tomoyo_print_name_union(head, &ptr->dev_name);
1562 tomoyo_print_name_union(head, &ptr->dir_name);
1563 tomoyo_print_name_union(head, &ptr->fs_type);
1564 tomoyo_print_number_union(head, &ptr->flags);
1567 container_of(acl, typeof(*ptr), head);
1569 tomoyo_set_group(head, "misc env ");
1570 tomoyo_set_string(head, ptr->env->name);
1573 head->r.print_cond_part = true;
1574 head->r.cond_step = 0;
1575 if (!tomoyo_flush(head))
1578 if (!tomoyo_print_condition(head, acl->cond))
1580 head->r.print_cond_part = false;
1582 tomoyo_set_lf(head);
1590 * @head: Pointer to "struct tomoyo_io_buffer".
1597 static bool tomoyo_read_domain2(struct tomoyo_io_buffer *head,
1600 list_for_each_cookie(head->r.acl, list) {
1602 list_entry(head->r.acl, typeof(*ptr), list);
1604 if (!tomoyo_print_entry(head, ptr))
1607 head->r.acl = NULL;
1614 * @head: Pointer to "struct tomoyo_io_buffer".
1618 static void tomoyo_read_domain(struct tomoyo_io_buffer *head)
1620 if (head->r.eof)
1622 list_for_each_cookie(head->r.domain, &tomoyo_domain_list) {
1624 list_entry(head->r.domain, typeof(*domain), list);
1627 switch (head->r.step) {
1630 !head->r.print_this_domain_only)
1633 tomoyo_set_string(head, domain->domainname->name);
1634 tomoyo_set_lf(head);
1635 tomoyo_io_printf(head, "use_profile %u\n",
1639 tomoyo_set_string(head, tomoyo_dif[i]);
1640 head->r.index = 0;
1641 head->r.step++;
1644 while (head->r.index < TOMOYO_MAX_ACL_GROUPS) {
1645 i = head->r.index++;
1648 tomoyo_io_printf(head, "use_group %u\n", i);
1649 if (!tomoyo_flush(head))
1652 head->r.index = 0;
1653 head->r.step++;
1654 tomoyo_set_lf(head);
1657 if (!tomoyo_read_domain2(head, &domain->acl_info_list))
1659 head->r.step++;
1660 if (!tomoyo_set_lf(head))
1664 head->r.step = 0;
1665 if (head->r.print_this_domain_only)
1670 head->r.eof = true;
1676 * @head: Pointer to "struct tomoyo_io_buffer".
1680 static int tomoyo_write_pid(struct tomoyo_io_buffer *head)
1682 head->r.eof = false;
1689 * @head: Pointer to "struct tomoyo_io_buffer".
1696 static void tomoyo_read_pid(struct tomoyo_io_buffer *head)
1698 char *buf = head->write_buf;
1704 /* Accessing write_buf is safe because head->io_sem is held. */
1706 head->r.eof = true;
1709 if (head->r.w_pos || head->r.eof)
1711 head->r.eof = true;
1726 tomoyo_io_printf(head, "%u %u ", pid, domain->profile);
1727 tomoyo_set_string(head, domain->domainname->name);
1750 * @head: Pointer to "struct tomoyo_io_buffer".
1756 static int tomoyo_write_exception(struct tomoyo_io_buffer *head)
1758 const bool is_delete = head->w.is_delete;
1760 .ns = head->w.ns,
1762 .data = head->write_buf,
1781 (head->w.ns, &head->w.ns->acl_group[group],
1790 * @head: Pointer to "struct tomoyo_io_buffer".
1797 static bool tomoyo_read_group(struct tomoyo_io_buffer *head, const int idx)
1800 container_of(head->r.ns, typeof(*ns), namespace_list);
1803 list_for_each_cookie(head->r.group, list) {
1805 list_entry(head->r.group, typeof(*group), head.list);
1807 list_for_each_cookie(head->r.acl, &group->member_list) {
1809 list_entry(head->r.acl, typeof(*ptr), list);
1813 if (!tomoyo_flush(head))
1815 tomoyo_print_namespace(head);
1816 tomoyo_set_string(head, tomoyo_group_name[idx]);
1817 tomoyo_set_string(head, group->group_name->name);
1819 tomoyo_set_space(head);
1820 tomoyo_set_string(head, container_of
1822 head)->member_name->name);
1824 tomoyo_print_number_union(head, &container_of
1827 head)->number);
1832 head);
1836 tomoyo_io_printf(head, " %s", buffer);
1838 tomoyo_set_lf(head);
1840 head->r.acl = NULL;
1842 head->r.group = NULL;
1849 * @head: Pointer to "struct tomoyo_io_buffer".
1856 static bool tomoyo_read_policy(struct tomoyo_io_buffer *head, const int idx)
1859 container_of(head->r.ns, typeof(*ns), namespace_list);
1862 list_for_each_cookie(head->r.acl, list) {
1864 container_of(head->r.acl, typeof(*acl), list);
1867 if (!tomoyo_flush(head))
1873 container_of(acl, typeof(*ptr), head);
1875 tomoyo_print_namespace(head);
1876 tomoyo_set_string(head, tomoyo_transition_type
1878 tomoyo_set_string(head, ptr->program ?
1880 tomoyo_set_string(head, " from ");
1881 tomoyo_set_string(head, ptr->domainname ?
1889 container_of(acl, typeof(*ptr), head);
1891 tomoyo_print_namespace(head);
1892 tomoyo_set_string(head, "aggregator ");
1893 tomoyo_set_string(head,
1895 tomoyo_set_space(head);
1896 tomoyo_set_string(head,
1903 tomoyo_set_lf(head);
1905 head->r.acl = NULL;
1912 * @head: Pointer to "struct tomoyo_io_buffer".
1916 static void tomoyo_read_exception(struct tomoyo_io_buffer *head)
1919 container_of(head->r.ns, typeof(*ns), namespace_list);
1921 if (head->r.eof)
1923 while (head->r.step < TOMOYO_MAX_POLICY &&
1924 tomoyo_read_policy(head, head->r.step))
1925 head->r.step++;
1926 if (head->r.step < TOMOYO_MAX_POLICY)
1928 while (head->r.step < TOMOYO_MAX_POLICY + TOMOYO_MAX_GROUP &&
1929 tomoyo_read_group(head, head->r.step - TOMOYO_MAX_POLICY))
1930 head->r.step++;
1931 if (head->r.step < TOMOYO_MAX_POLICY + TOMOYO_MAX_GROUP)
1933 while (head->r.step < TOMOYO_MAX_POLICY + TOMOYO_MAX_GROUP
1935 head->r.acl_group_index = head->r.step - TOMOYO_MAX_POLICY
1937 if (!tomoyo_read_domain2(head, &ns->acl_group
1938 [head->r.acl_group_index]))
1940 head->r.step++;
1942 head->r.eof = true;
2200 * @head: Pointer to "struct tomoyo_io_buffer".
2202 static void tomoyo_read_query(struct tomoyo_io_buffer *head)
2209 if (head->r.w_pos)
2211 kfree(head->read_buf);
2212 head->read_buf = NULL;
2217 if (pos++ != head->r.query_index)
2224 head->r.query_index = 0;
2235 if (pos++ != head->r.query_index)
2248 head->read_buf = buf;
2249 head->r.w[head->r.w_pos++] = buf;
2250 head->r.query_index++;
2259 * @head: Pointer to "struct tomoyo_io_buffer".
2263 static int tomoyo_write_answer(struct tomoyo_io_buffer *head)
2265 char *data = head->write_buf;
2298 * @head: Pointer to "struct tomoyo_io_buffer".
2302 static void tomoyo_read_version(struct tomoyo_io_buffer *head)
2304 if (!head->r.eof) {
2305 tomoyo_io_printf(head, "2.6.0");
2306 head->r.eof = true;
2346 * @head: Pointer to "struct tomoyo_io_buffer".
2350 static void tomoyo_read_stat(struct tomoyo_io_buffer *head)
2355 if (head->r.eof)
2358 tomoyo_io_printf(head, "Policy %-30s %10u",
2365 tomoyo_io_printf(head, " (Last: %04u/%02u/%02u %02u:%02u:%02u)",
2369 tomoyo_set_lf(head);
2375 tomoyo_io_printf(head, "Memory used by %-22s %10u",
2379 tomoyo_io_printf(head, " (Quota: %10u)", used);
2380 tomoyo_set_lf(head);
2382 tomoyo_io_printf(head, "Total memory used: %10u\n",
2384 head->r.eof = true;
2390 * @head: Pointer to "struct tomoyo_io_buffer".
2394 static int tomoyo_write_stat(struct tomoyo_io_buffer *head)
2396 char *data = head->write_buf;
2416 struct tomoyo_io_buffer *head = kzalloc(sizeof(*head), GFP_NOFS);
2418 if (!head)
2420 mutex_init(&head->io_sem);
2421 head->type = type;
2425 head->write = tomoyo_write_domain;
2426 head->read = tomoyo_read_domain;
2430 head->write = tomoyo_write_exception;
2431 head->read = tomoyo_read_exception;
2435 head->poll = tomoyo_poll_log;
2436 head->read = tomoyo_read_log;
2440 head->write = tomoyo_write_pid;
2441 head->read = tomoyo_read_pid;
2445 head->read = tomoyo_read_version;
2446 head->readbuf_size = 128;
2450 head->write = tomoyo_write_stat;
2451 head->read = tomoyo_read_stat;
2452 head->readbuf_size = 1024;
2456 head->write = tomoyo_write_profile;
2457 head->read = tomoyo_read_profile;
2460 head->poll = tomoyo_poll_query;
2461 head->write = tomoyo_write_answer;
2462 head->read = tomoyo_read_query;
2466 head->write = tomoyo_write_manager;
2467 head->read = tomoyo_read_manager;
2475 head->read = NULL;
2476 head->poll = NULL;
2477 } else if (!head->poll) {
2479 if (!head->readbuf_size)
2480 head->readbuf_size = 4096 * 2;
2481 head->read_buf = kzalloc(head->readbuf_size, GFP_NOFS);
2482 if (!head->read_buf) {
2483 kfree(head);
2492 head->write = NULL;
2493 } else if (head->write) {
2494 head->writebuf_size = 4096 * 2;
2495 head->write_buf = kzalloc(head->writebuf_size, GFP_NOFS);
2496 if (!head->write_buf) {
2497 kfree(head->read_buf);
2498 kfree(head);
2510 file->private_data = head;
2511 tomoyo_notify_gc(head, true);
2526 struct tomoyo_io_buffer *head = file->private_data;
2528 if (head->poll)
2529 return head->poll(file, wait) | EPOLLOUT | EPOLLWRNORM;
2536 * @head: Pointer to "struct tomoyo_io_buffer".
2540 static inline void tomoyo_set_namespace_cursor(struct tomoyo_io_buffer *head)
2544 if (head->type != TOMOYO_EXCEPTIONPOLICY &&
2545 head->type != TOMOYO_PROFILE)
2551 ns = head->r.ns;
2552 if (!ns || (head->r.eof && ns->next != &tomoyo_namespace_list)) {
2554 memset(&head->r, 0, sizeof(head->r));
2555 head->r.ns = ns ? ns->next : tomoyo_namespace_list.next;
2562 * @head: Pointer to "struct tomoyo_io_buffer".
2566 static inline bool tomoyo_has_more_namespace(struct tomoyo_io_buffer *head)
2568 return (head->type == TOMOYO_EXCEPTIONPOLICY ||
2569 head->type == TOMOYO_PROFILE) && head->r.eof &&
2570 head->r.ns->next != &tomoyo_namespace_list;
2576 * @head: Pointer to "struct tomoyo_io_buffer".
2582 ssize_t tomoyo_read_control(struct tomoyo_io_buffer *head, char __user *buffer,
2588 if (!head->read)
2590 if (mutex_lock_interruptible(&head->io_sem))
2592 head->read_user_buf = buffer;
2593 head->read_user_buf_avail = buffer_len;
2595 if (tomoyo_flush(head))
2598 tomoyo_set_namespace_cursor(head);
2599 head->read(head);
2600 } while (tomoyo_flush(head) &&
2601 tomoyo_has_more_namespace(head));
2603 len = head->read_user_buf - buffer;
2604 mutex_unlock(&head->io_sem);
2611 * @head: Poiter to "struct tomoyo_io_buffer".
2618 static int tomoyo_parse_policy(struct tomoyo_io_buffer *head, char *line)
2621 head->w.is_delete = !strncmp(line, "delete ", 7);
2622 if (head->w.is_delete)
2625 if (head->type == TOMOYO_EXCEPTIONPOLICY ||
2626 head->type == TOMOYO_PROFILE) {
2632 head->w.ns = tomoyo_assign_namespace(line);
2635 head->w.ns = NULL;
2637 head->w.ns = &tomoyo_kernel_namespace;
2639 if (!head->w.ns)
2643 return head->write(head);
2649 * @head: Pointer to "struct tomoyo_io_buffer".
2655 ssize_t tomoyo_write_control(struct tomoyo_io_buffer *head,
2660 char *cp0 = head->write_buf;
2663 if (!head->write)
2665 if (mutex_lock_interruptible(&head->io_sem))
2667 head->read_user_buf_avail = 0;
2673 if (head->w.avail >= head->writebuf_size - 1) {
2674 const int len = head->writebuf_size * 2;
2681 memmove(cp, cp0, head->w.avail);
2683 head->write_buf = cp;
2685 head->writebuf_size = len;
2693 cp0[head->w.avail++] = c;
2696 cp0[head->w.avail - 1] = '\0';
2697 head->w.avail = 0;
2700 head->w.ns = &tomoyo_kernel_namespace;
2701 head->w.domain = NULL;
2702 memset(&head->r, 0, sizeof(head->r));
2706 switch (head->type) {
2711 if (tomoyo_select_domain(head, cp0))
2716 head->r.print_transition_related_only = true;
2726 switch (tomoyo_parse_policy(head, cp0)) {
2731 switch (head->type) {
2747 mutex_unlock(&head->io_sem);
2754 * @head: Pointer to "struct tomoyo_io_buffer".
2756 void tomoyo_close_control(struct tomoyo_io_buffer *head)
2762 if (head->type == TOMOYO_QUERY &&
2765 tomoyo_notify_gc(head, false);
2833 struct tomoyo_io_buffer head = { };
2839 head.type = TOMOYO_PROFILE;
2840 head.write = tomoyo_write_profile;
2844 head.type = TOMOYO_EXCEPTIONPOLICY;
2845 head.write = tomoyo_write_exception;
2849 head.type = TOMOYO_DOMAINPOLICY;
2850 head.write = tomoyo_write_domain;
2854 head.type = TOMOYO_MANAGER;
2855 head.write = tomoyo_write_manager;
2859 head.type = TOMOYO_STAT;
2860 head.write = tomoyo_write_stat;
2870 head.write_buf = start;
2871 tomoyo_parse_policy(&head, start);