Lines Matching refs:head

201  * @head:   Pointer to "struct tomoyo_io_buffer".
205 static bool tomoyo_flush(struct tomoyo_io_buffer *head)
207 while (head->r.w_pos) {
208 const char *w = head->r.w[0];
212 if (len > head->read_user_buf_avail)
213 len = head->read_user_buf_avail;
216 if (copy_to_user(head->read_user_buf, w, len))
218 head->read_user_buf_avail -= len;
219 head->read_user_buf += len;
222 head->r.w[0] = w;
226 if (head->poll) {
227 if (!head->read_user_buf_avail ||
228 copy_to_user(head->read_user_buf, "", 1))
230 head->read_user_buf_avail--;
231 head->read_user_buf++;
233 head->r.w_pos--;
234 for (len = 0; len < head->r.w_pos; len++)
235 head->r.w[len] = head->r.w[len + 1];
237 head->r.avail = 0;
244 * @head: Pointer to "struct tomoyo_io_buffer".
247 * Note that @string has to be kept valid until @head is kfree()d.
251 static void tomoyo_set_string(struct tomoyo_io_buffer *head, const char *string)
253 if (head->r.w_pos < TOMOYO_MAX_IO_READ_QUEUE) {
254 head->r.w[head->r.w_pos++] = string;
255 tomoyo_flush(head);
260 static void tomoyo_io_printf(struct tomoyo_io_buffer *head, const char *fmt,
266 * @head: Pointer to "struct tomoyo_io_buffer".
269 static void tomoyo_io_printf(struct tomoyo_io_buffer *head, const char *fmt,
274 size_t pos = head->r.avail;
275 int size = head->readbuf_size - pos;
280 len = vsnprintf(head->read_buf + pos, size, fmt, args) + 1;
282 if (pos + len >= head->readbuf_size) {
286 head->r.avail += len;
287 tomoyo_set_string(head, head->read_buf + pos);
293 * @head: Pointer to "struct tomoyo_io_buffer".
297 static void tomoyo_set_space(struct tomoyo_io_buffer *head)
299 tomoyo_set_string(head, " ");
305 * @head: Pointer to "struct tomoyo_io_buffer".
309 static bool tomoyo_set_lf(struct tomoyo_io_buffer *head)
311 tomoyo_set_string(head, "\n");
312 return !head->r.w_pos;
318 * @head: Pointer to "struct tomoyo_io_buffer".
322 static void tomoyo_set_slash(struct tomoyo_io_buffer *head)
324 tomoyo_set_string(head, "/");
357 * @head: Pointer to "struct tomoyo_io_buffer".
361 static void tomoyo_print_namespace(struct tomoyo_io_buffer *head)
365 tomoyo_set_string(head,
366 container_of(head->r.ns,
369 tomoyo_set_space(head);
375 * @head: Pointer to "struct tomoyo_io_buffer".
378 static void tomoyo_print_name_union(struct tomoyo_io_buffer *head,
381 tomoyo_set_space(head);
383 tomoyo_set_string(head, "@");
384 tomoyo_set_string(head, ptr->group->group_name->name);
386 tomoyo_set_string(head, ptr->filename->name);
393 * @head: Pointer to "struct tomoyo_io_buffer".
398 static void tomoyo_print_name_union_quoted(struct tomoyo_io_buffer *head,
402 tomoyo_set_string(head, "@");
403 tomoyo_set_string(head, ptr->group->group_name->name);
405 tomoyo_set_string(head, "\"");
406 tomoyo_set_string(head, ptr->filename->name);
407 tomoyo_set_string(head, "\"");
414 * @head: Pointer to "struct tomoyo_io_buffer".
420 (struct tomoyo_io_buffer *head, const struct tomoyo_number_union *ptr)
423 tomoyo_set_string(head, "@");
424 tomoyo_set_string(head, ptr->group->group_name->name);
455 tomoyo_io_printf(head, "%s", buffer);
462 * @head: Pointer to "struct tomoyo_io_buffer".
467 static void tomoyo_print_number_union(struct tomoyo_io_buffer *head,
470 tomoyo_set_space(head);
471 tomoyo_print_number_union_nospace(head, ptr);
662 * @head: Pointer to "struct tomoyo_io_buffer".
666 static int tomoyo_write_profile(struct tomoyo_io_buffer *head)
668 char *data = head->write_buf;
673 if (sscanf(data, "PROFILE_VERSION=%u", &head->w.ns->profile_version)
680 profile = tomoyo_assign_profile(head->w.ns, i);
714 * @head: Pointer to "struct tomoyo_io_buffer".
721 static void tomoyo_print_config(struct tomoyo_io_buffer *head, const u8 config)
723 tomoyo_io_printf(head, "={ mode=%s grant_log=%s reject_log=%s }\n",
732 * @head: Pointer to "struct tomoyo_io_buffer".
736 static void tomoyo_read_profile(struct tomoyo_io_buffer *head)
740 container_of(head->r.ns, typeof(*ns), namespace_list);
743 if (head->r.eof)
746 index = head->r.index;
748 switch (head->r.step) {
750 tomoyo_print_namespace(head);
751 tomoyo_io_printf(head, "PROFILE_VERSION=%u\n",
753 head->r.step++;
756 for ( ; head->r.index < TOMOYO_MAX_PROFILES;
757 head->r.index++)
758 if (ns->profile_ptr[head->r.index])
760 if (head->r.index == TOMOYO_MAX_PROFILES) {
761 head->r.eof = true;
764 head->r.step++;
772 tomoyo_print_namespace(head);
773 tomoyo_io_printf(head, "%u-COMMENT=", index);
774 tomoyo_set_string(head, comment ? comment->name : "");
775 tomoyo_set_lf(head);
776 tomoyo_print_namespace(head);
777 tomoyo_io_printf(head, "%u-PREFERENCE={ ", index);
779 tomoyo_io_printf(head, "%s=%u ",
782 tomoyo_set_string(head, "}\n");
783 head->r.step++;
788 tomoyo_print_namespace(head);
789 tomoyo_io_printf(head, "%u-%s", index, "CONFIG");
790 tomoyo_print_config(head, profile->default_config);
791 head->r.bit = 0;
792 head->r.step++;
796 for ( ; head->r.bit < TOMOYO_MAX_MAC_INDEX
797 + TOMOYO_MAX_MAC_CATEGORY_INDEX; head->r.bit++) {
798 const u8 i = head->r.bit;
803 tomoyo_print_namespace(head);
805 tomoyo_io_printf(head, "%u-CONFIG::%s::%s",
811 tomoyo_io_printf(head, "%u-CONFIG::%s", index,
813 tomoyo_print_config(head, config);
814 head->r.bit++;
817 if (head->r.bit == TOMOYO_MAX_MAC_INDEX
819 head->r.index++;
820 head->r.step = 1;
824 if (tomoyo_flush(head))
839 return container_of(a, struct tomoyo_manager, head)->manager ==
840 container_of(b, struct tomoyo_manager, head)->manager;
869 error = tomoyo_update_policy(&e.head, sizeof(e), &param,
879 * @head: Pointer to "struct tomoyo_io_buffer".
885 static int tomoyo_write_manager(struct tomoyo_io_buffer *head)
887 char *data = head->write_buf;
890 tomoyo_manage_by_non_root = !head->w.is_delete;
893 return tomoyo_update_manager_entry(data, head->w.is_delete);
899 * @head: Pointer to "struct tomoyo_io_buffer".
903 static void tomoyo_read_manager(struct tomoyo_io_buffer *head)
905 if (head->r.eof)
907 list_for_each_cookie(head->r.acl, &tomoyo_kernel_namespace.policy_list[TOMOYO_ID_MANAGER]) {
909 list_entry(head->r.acl, typeof(*ptr), head.list);
911 if (ptr->head.is_deleted)
913 if (!tomoyo_flush(head))
915 tomoyo_set_string(head, ptr->manager->name);
916 tomoyo_set_lf(head);
918 head->r.eof = true;
946 list_for_each_entry_rcu(ptr, &tomoyo_kernel_namespace.policy_list[TOMOYO_ID_MANAGER], head.list,
948 if (!ptr->head.is_deleted &&
975 * @head: Pointer to "struct tomoyo_io_buffer".
982 static bool tomoyo_select_domain(struct tomoyo_io_buffer *head,
1011 head->w.domain = domain;
1012 /* Accessing read_buf is safe because head->io_sem is held. */
1013 if (!head->read_buf)
1015 memset(&head->r, 0, sizeof(head->r));
1016 head->r.print_this_domain_only = true;
1018 head->r.domain = &domain->list;
1020 head->r.eof = true;
1021 tomoyo_io_printf(head, "# select %s\n", data);
1023 tomoyo_io_printf(head, "# This is a deleted domain.\n");
1038 const struct tomoyo_task_acl *p1 = container_of(a, typeof(*p1), head);
1039 const struct tomoyo_task_acl *p2 = container_of(b, typeof(*p2), head);
1059 .head.type = TOMOYO_TYPE_MANUAL_TASK_ACL,
1064 error = tomoyo_update_domain(&e.head, sizeof(e), param,
1158 * @head: Pointer to "struct tomoyo_io_buffer".
1164 static int tomoyo_write_domain(struct tomoyo_io_buffer *head)
1166 char *data = head->write_buf;
1168 struct tomoyo_domain_info *domain = head->w.domain;
1169 const bool is_delete = head->w.is_delete;
1183 head->w.domain = domain;
1219 * @head: Pointer to "struct tomoyo_io_buffer".
1224 static bool tomoyo_print_condition(struct tomoyo_io_buffer *head,
1227 switch (head->r.cond_step) {
1229 head->r.cond_index = 0;
1230 head->r.cond_step++;
1232 tomoyo_set_space(head);
1233 tomoyo_set_string(head, cond->transit->name);
1252 for (skip = 0; skip < head->r.cond_index; skip++) {
1277 while (head->r.cond_index < condc) {
1282 if (!tomoyo_flush(head))
1285 head->r.cond_index++;
1286 tomoyo_set_space(head);
1289 tomoyo_io_printf(head,
1292 tomoyo_set_string(head,
1294 tomoyo_set_string(head, "\"");
1298 tomoyo_set_string(head,
1300 tomoyo_set_string(head,
1302 tomoyo_io_printf(head, "\"]%s=", envp->is_not ? "!" : "");
1304 tomoyo_set_string(head, "\"");
1305 tomoyo_set_string(head, envp->value->name);
1306 tomoyo_set_string(head, "\"");
1308 tomoyo_set_string(head,
1315 (head, numbers_p++);
1318 tomoyo_set_string(head,
1322 tomoyo_set_string(head, match ? "=" : "!=");
1326 (head, names_p++);
1330 (head, numbers_p++);
1333 tomoyo_set_string(head,
1339 head->r.cond_step++;
1342 if (!tomoyo_flush(head))
1344 head->r.cond_step++;
1348 tomoyo_io_printf(head, " grant_log=%s",
1351 tomoyo_set_lf(head);
1360 * @head: Pointer to "struct tomoyo_io_buffer".
1365 static void tomoyo_set_group(struct tomoyo_io_buffer *head,
1368 if (head->type == TOMOYO_EXCEPTIONPOLICY) {
1369 tomoyo_print_namespace(head);
1370 tomoyo_io_printf(head, "acl_group %u ",
1371 head->r.acl_group_index);
1373 tomoyo_set_string(head, category);
1379 * @head: Pointer to "struct tomoyo_io_buffer".
1384 static bool tomoyo_print_entry(struct tomoyo_io_buffer *head,
1391 if (head->r.print_cond_part)
1395 if (!tomoyo_flush(head))
1399 container_of(acl, typeof(*ptr), head);
1405 if (head->r.print_transition_related_only &&
1409 tomoyo_set_group(head, "file ");
1412 tomoyo_set_slash(head);
1414 tomoyo_set_string(head, tomoyo_path_keyword[bit]);
1418 tomoyo_print_name_union(head, &ptr->name);
1421 container_of(acl, typeof(*ptr), head);
1423 tomoyo_set_group(head, "task ");
1424 tomoyo_set_string(head, "manual_domain_transition ");
1425 tomoyo_set_string(head, ptr->domainname->name);
1426 } else if (head->r.print_transition_related_only) {
1430 container_of(acl, typeof(*ptr), head);
1437 tomoyo_set_group(head, "file ");
1440 tomoyo_set_slash(head);
1442 tomoyo_set_string(head, tomoyo_mac_keywords
1447 tomoyo_print_name_union(head, &ptr->name1);
1448 tomoyo_print_name_union(head, &ptr->name2);
1451 container_of(acl, typeof(*ptr), head);
1458 tomoyo_set_group(head, "file ");
1461 tomoyo_set_slash(head);
1463 tomoyo_set_string(head, tomoyo_mac_keywords
1468 tomoyo_print_name_union(head, &ptr->name);
1469 tomoyo_print_number_union(head, &ptr->number);
1472 container_of(acl, typeof(*ptr), head);
1479 tomoyo_set_group(head, "file ");
1482 tomoyo_set_slash(head);
1484 tomoyo_set_string(head, tomoyo_mac_keywords
1489 tomoyo_print_name_union(head, &ptr->name);
1490 tomoyo_print_number_union(head, &ptr->mode);
1491 tomoyo_print_number_union(head, &ptr->major);
1492 tomoyo_print_number_union(head, &ptr->minor);
1495 container_of(acl, typeof(*ptr), head);
1502 tomoyo_set_group(head, "network inet ");
1503 tomoyo_set_string(head, tomoyo_proto_keyword
1505 tomoyo_set_space(head);
1508 tomoyo_set_slash(head);
1510 tomoyo_set_string(head, tomoyo_socket_keyword[bit]);
1514 tomoyo_set_space(head);
1516 tomoyo_set_string(head, "@");
1517 tomoyo_set_string(head, ptr->address.group->group_name
1523 tomoyo_io_printf(head, "%s", buf);
1525 tomoyo_print_number_union(head, &ptr->port);
1528 container_of(acl, typeof(*ptr), head);
1535 tomoyo_set_group(head, "network unix ");
1536 tomoyo_set_string(head, tomoyo_proto_keyword
1538 tomoyo_set_space(head);
1541 tomoyo_set_slash(head);
1543 tomoyo_set_string(head, tomoyo_socket_keyword[bit]);
1547 tomoyo_print_name_union(head, &ptr->name);
1550 container_of(acl, typeof(*ptr), head);
1552 tomoyo_set_group(head, "file mount");
1553 tomoyo_print_name_union(head, &ptr->dev_name);
1554 tomoyo_print_name_union(head, &ptr->dir_name);
1555 tomoyo_print_name_union(head, &ptr->fs_type);
1556 tomoyo_print_number_union(head, &ptr->flags);
1559 container_of(acl, typeof(*ptr), head);
1561 tomoyo_set_group(head, "misc env ");
1562 tomoyo_set_string(head, ptr->env->name);
1565 head->r.print_cond_part = true;
1566 head->r.cond_step = 0;
1567 if (!tomoyo_flush(head))
1570 if (!tomoyo_print_condition(head, acl->cond))
1572 head->r.print_cond_part = false;
1574 tomoyo_set_lf(head);
1582 * @head: Pointer to "struct tomoyo_io_buffer".
1589 static bool tomoyo_read_domain2(struct tomoyo_io_buffer *head,
1592 list_for_each_cookie(head->r.acl, list) {
1594 list_entry(head->r.acl, typeof(*ptr), list);
1596 if (!tomoyo_print_entry(head, ptr))
1599 head->r.acl = NULL;
1606 * @head: Pointer to "struct tomoyo_io_buffer".
1610 static void tomoyo_read_domain(struct tomoyo_io_buffer *head)
1612 if (head->r.eof)
1614 list_for_each_cookie(head->r.domain, &tomoyo_domain_list) {
1616 list_entry(head->r.domain, typeof(*domain), list);
1619 switch (head->r.step) {
1622 !head->r.print_this_domain_only)
1625 tomoyo_set_string(head, domain->domainname->name);
1626 tomoyo_set_lf(head);
1627 tomoyo_io_printf(head, "use_profile %u\n",
1631 tomoyo_set_string(head, tomoyo_dif[i]);
1632 head->r.index = 0;
1633 head->r.step++;
1636 while (head->r.index < TOMOYO_MAX_ACL_GROUPS) {
1637 i = head->r.index++;
1640 tomoyo_io_printf(head, "use_group %u\n", i);
1641 if (!tomoyo_flush(head))
1644 head->r.index = 0;
1645 head->r.step++;
1646 tomoyo_set_lf(head);
1649 if (!tomoyo_read_domain2(head, &domain->acl_info_list))
1651 head->r.step++;
1652 if (!tomoyo_set_lf(head))
1656 head->r.step = 0;
1657 if (head->r.print_this_domain_only)
1662 head->r.eof = true;
1668 * @head: Pointer to "struct tomoyo_io_buffer".
1672 static int tomoyo_write_pid(struct tomoyo_io_buffer *head)
1674 head->r.eof = false;
1681 * @head: Pointer to "struct tomoyo_io_buffer".
1688 static void tomoyo_read_pid(struct tomoyo_io_buffer *head)
1690 char *buf = head->write_buf;
1696 /* Accessing write_buf is safe because head->io_sem is held. */
1698 head->r.eof = true;
1701 if (head->r.w_pos || head->r.eof)
1703 head->r.eof = true;
1718 tomoyo_io_printf(head, "%u %u ", pid, domain->profile);
1719 tomoyo_set_string(head, domain->domainname->name);
1742 * @head: Pointer to "struct tomoyo_io_buffer".
1748 static int tomoyo_write_exception(struct tomoyo_io_buffer *head)
1750 const bool is_delete = head->w.is_delete;
1752 .ns = head->w.ns,
1754 .data = head->write_buf,
1773 (head->w.ns, &head->w.ns->acl_group[group],
1782 * @head: Pointer to "struct tomoyo_io_buffer".
1789 static bool tomoyo_read_group(struct tomoyo_io_buffer *head, const int idx)
1792 container_of(head->r.ns, typeof(*ns), namespace_list);
1795 list_for_each_cookie(head->r.group, list) {
1797 list_entry(head->r.group, typeof(*group), head.list);
1799 list_for_each_cookie(head->r.acl, &group->member_list) {
1801 list_entry(head->r.acl, typeof(*ptr), list);
1805 if (!tomoyo_flush(head))
1807 tomoyo_print_namespace(head);
1808 tomoyo_set_string(head, tomoyo_group_name[idx]);
1809 tomoyo_set_string(head, group->group_name->name);
1811 tomoyo_set_space(head);
1812 tomoyo_set_string(head, container_of
1814 head)->member_name->name);
1816 tomoyo_print_number_union(head, &container_of
1819 head)->number);
1824 head);
1828 tomoyo_io_printf(head, " %s", buffer);
1830 tomoyo_set_lf(head);
1832 head->r.acl = NULL;
1834 head->r.group = NULL;
1841 * @head: Pointer to "struct tomoyo_io_buffer".
1848 static bool tomoyo_read_policy(struct tomoyo_io_buffer *head, const int idx)
1851 container_of(head->r.ns, typeof(*ns), namespace_list);
1854 list_for_each_cookie(head->r.acl, list) {
1856 container_of(head->r.acl, typeof(*acl), list);
1859 if (!tomoyo_flush(head))
1865 container_of(acl, typeof(*ptr), head);
1867 tomoyo_print_namespace(head);
1868 tomoyo_set_string(head, tomoyo_transition_type
1870 tomoyo_set_string(head, ptr->program ?
1872 tomoyo_set_string(head, " from ");
1873 tomoyo_set_string(head, ptr->domainname ?
1881 container_of(acl, typeof(*ptr), head);
1883 tomoyo_print_namespace(head);
1884 tomoyo_set_string(head, "aggregator ");
1885 tomoyo_set_string(head,
1887 tomoyo_set_space(head);
1888 tomoyo_set_string(head,
1895 tomoyo_set_lf(head);
1897 head->r.acl = NULL;
1904 * @head: Pointer to "struct tomoyo_io_buffer".
1908 static void tomoyo_read_exception(struct tomoyo_io_buffer *head)
1911 container_of(head->r.ns, typeof(*ns), namespace_list);
1913 if (head->r.eof)
1915 while (head->r.step < TOMOYO_MAX_POLICY &&
1916 tomoyo_read_policy(head, head->r.step))
1917 head->r.step++;
1918 if (head->r.step < TOMOYO_MAX_POLICY)
1920 while (head->r.step < TOMOYO_MAX_POLICY + TOMOYO_MAX_GROUP &&
1921 tomoyo_read_group(head, head->r.step - TOMOYO_MAX_POLICY))
1922 head->r.step++;
1923 if (head->r.step < TOMOYO_MAX_POLICY + TOMOYO_MAX_GROUP)
1925 while (head->r.step < TOMOYO_MAX_POLICY + TOMOYO_MAX_GROUP
1927 head->r.acl_group_index = head->r.step - TOMOYO_MAX_POLICY
1929 if (!tomoyo_read_domain2(head, &ns->acl_group
1930 [head->r.acl_group_index]))
1932 head->r.step++;
1934 head->r.eof = true;
2192 * @head: Pointer to "struct tomoyo_io_buffer".
2194 static void tomoyo_read_query(struct tomoyo_io_buffer *head)
2201 if (head->r.w_pos)
2203 kfree(head->read_buf);
2204 head->read_buf = NULL;
2209 if (pos++ != head->r.query_index)
2216 head->r.query_index = 0;
2227 if (pos++ != head->r.query_index)
2240 head->read_buf = buf;
2241 head->r.w[head->r.w_pos++] = buf;
2242 head->r.query_index++;
2251 * @head: Pointer to "struct tomoyo_io_buffer".
2255 static int tomoyo_write_answer(struct tomoyo_io_buffer *head)
2257 char *data = head->write_buf;
2290 * @head: Pointer to "struct tomoyo_io_buffer".
2294 static void tomoyo_read_version(struct tomoyo_io_buffer *head)
2296 if (!head->r.eof) {
2297 tomoyo_io_printf(head, "2.6.0");
2298 head->r.eof = true;
2338 * @head: Pointer to "struct tomoyo_io_buffer".
2342 static void tomoyo_read_stat(struct tomoyo_io_buffer *head)
2347 if (head->r.eof)
2350 tomoyo_io_printf(head, "Policy %-30s %10u",
2357 tomoyo_io_printf(head, " (Last: %04u/%02u/%02u %02u:%02u:%02u)",
2361 tomoyo_set_lf(head);
2367 tomoyo_io_printf(head, "Memory used by %-22s %10u",
2371 tomoyo_io_printf(head, " (Quota: %10u)", used);
2372 tomoyo_set_lf(head);
2374 tomoyo_io_printf(head, "Total memory used: %10u\n",
2376 head->r.eof = true;
2382 * @head: Pointer to "struct tomoyo_io_buffer".
2386 static int tomoyo_write_stat(struct tomoyo_io_buffer *head)
2388 char *data = head->write_buf;
2408 struct tomoyo_io_buffer *head = kzalloc(sizeof(*head), GFP_NOFS);
2410 if (!head)
2412 mutex_init(&head->io_sem);
2413 head->type = type;
2417 head->write = tomoyo_write_domain;
2418 head->read = tomoyo_read_domain;
2422 head->write = tomoyo_write_exception;
2423 head->read = tomoyo_read_exception;
2427 head->poll = tomoyo_poll_log;
2428 head->read = tomoyo_read_log;
2432 head->write = tomoyo_write_pid;
2433 head->read = tomoyo_read_pid;
2437 head->read = tomoyo_read_version;
2438 head->readbuf_size = 128;
2442 head->write = tomoyo_write_stat;
2443 head->read = tomoyo_read_stat;
2444 head->readbuf_size = 1024;
2448 head->write = tomoyo_write_profile;
2449 head->read = tomoyo_read_profile;
2452 head->poll = tomoyo_poll_query;
2453 head->write = tomoyo_write_answer;
2454 head->read = tomoyo_read_query;
2458 head->write = tomoyo_write_manager;
2459 head->read = tomoyo_read_manager;
2467 head->read = NULL;
2468 head->poll = NULL;
2469 } else if (!head->poll) {
2471 if (!head->readbuf_size)
2472 head->readbuf_size = 4096 * 2;
2473 head->read_buf = kzalloc(head->readbuf_size, GFP_NOFS);
2474 if (!head->read_buf) {
2475 kfree(head);
2484 head->write = NULL;
2485 } else if (head->write) {
2486 head->writebuf_size = 4096 * 2;
2487 head->write_buf = kzalloc(head->writebuf_size, GFP_NOFS);
2488 if (!head->write_buf) {
2489 kfree(head->read_buf);
2490 kfree(head);
2502 file->private_data = head;
2503 tomoyo_notify_gc(head, true);
2518 struct tomoyo_io_buffer *head = file->private_data;
2520 if (head->poll)
2521 return head->poll(file, wait) | EPOLLOUT | EPOLLWRNORM;
2528 * @head: Pointer to "struct tomoyo_io_buffer".
2532 static inline void tomoyo_set_namespace_cursor(struct tomoyo_io_buffer *head)
2536 if (head->type != TOMOYO_EXCEPTIONPOLICY &&
2537 head->type != TOMOYO_PROFILE)
2543 ns = head->r.ns;
2544 if (!ns || (head->r.eof && ns->next != &tomoyo_namespace_list)) {
2546 memset(&head->r, 0, sizeof(head->r));
2547 head->r.ns = ns ? ns->next : tomoyo_namespace_list.next;
2554 * @head: Pointer to "struct tomoyo_io_buffer".
2558 static inline bool tomoyo_has_more_namespace(struct tomoyo_io_buffer *head)
2560 return (head->type == TOMOYO_EXCEPTIONPOLICY ||
2561 head->type == TOMOYO_PROFILE) && head->r.eof &&
2562 head->r.ns->next != &tomoyo_namespace_list;
2568 * @head: Pointer to "struct tomoyo_io_buffer".
2574 ssize_t tomoyo_read_control(struct tomoyo_io_buffer *head, char __user *buffer,
2580 if (!head->read)
2582 if (mutex_lock_interruptible(&head->io_sem))
2584 head->read_user_buf = buffer;
2585 head->read_user_buf_avail = buffer_len;
2587 if (tomoyo_flush(head))
2590 tomoyo_set_namespace_cursor(head);
2591 head->read(head);
2592 } while (tomoyo_flush(head) &&
2593 tomoyo_has_more_namespace(head));
2595 len = head->read_user_buf - buffer;
2596 mutex_unlock(&head->io_sem);
2603 * @head: Pointer to "struct tomoyo_io_buffer".
2610 static int tomoyo_parse_policy(struct tomoyo_io_buffer *head, char *line)
2613 head->w.is_delete = !strncmp(line, "delete ", 7);
2614 if (head->w.is_delete)
2617 if (head->type == TOMOYO_EXCEPTIONPOLICY ||
2618 head->type == TOMOYO_PROFILE) {
2624 head->w.ns = tomoyo_assign_namespace(line);
2627 head->w.ns = NULL;
2629 head->w.ns = &tomoyo_kernel_namespace;
2631 if (!head->w.ns)
2635 return head->write(head);
2641 * @head: Pointer to "struct tomoyo_io_buffer".
2647 ssize_t tomoyo_write_control(struct tomoyo_io_buffer *head,
2655 if (!head->write)
2657 if (mutex_lock_interruptible(&head->io_sem))
2659 cp0 = head->write_buf;
2660 head->read_user_buf_avail = 0;
2666 if (head->w.avail >= head->writebuf_size - 1) {
2667 const int len = head->writebuf_size * 2;
2674 memmove(cp, cp0, head->w.avail);
2676 head->write_buf = cp;
2678 head->writebuf_size = len;
2686 cp0[head->w.avail++] = c;
2689 cp0[head->w.avail - 1] = '\0';
2690 head->w.avail = 0;
2693 head->w.ns = &tomoyo_kernel_namespace;
2694 head->w.domain = NULL;
2695 memset(&head->r, 0, sizeof(head->r));
2699 switch (head->type) {
2704 if (tomoyo_select_domain(head, cp0))
2709 head->r.print_transition_related_only = true;
2719 switch (tomoyo_parse_policy(head, cp0)) {
2724 switch (head->type) {
2740 mutex_unlock(&head->io_sem);
2747 * @head: Pointer to "struct tomoyo_io_buffer".
2749 void tomoyo_close_control(struct tomoyo_io_buffer *head)
2755 if (head->type == TOMOYO_QUERY &&
2758 tomoyo_notify_gc(head, false);
2826 struct tomoyo_io_buffer head = { };
2832 head.type = TOMOYO_PROFILE;
2833 head.write = tomoyo_write_profile;
2837 head.type = TOMOYO_EXCEPTIONPOLICY;
2838 head.write = tomoyo_write_exception;
2842 head.type = TOMOYO_DOMAINPOLICY;
2843 head.write = tomoyo_write_domain;
2847 head.type = TOMOYO_MANAGER;
2848 head.write = tomoyo_write_manager;
2852 head.type = TOMOYO_STAT;
2853 head.write = tomoyo_write_stat;
2863 head.write_buf = start;
2864 tomoyo_parse_policy(&head, start);