IOCTL

ioctl:
https://elixir.bootlin.com/linux/v5.7.2/source/arch/alpha/include/uapi/asm/ioctl.h#L49.

If you are adding new ioctl’s to the kernel, you should use the _IOmacros defined in <linux/ioctl.h>:

‘Write’ and ‘read’ are from the user’s point of view, just like the
system calls ‘write’ and ‘read’.

_IO an ioctl with no parameters
_IOW an ioctl with write parameters (copy_from_user)
_IOR an ioctl with read parameters (copy_to_user)
_IOWR an ioctl with both write and read parameters.

Following this convention is good because:

(1) Keeping the ioctl’s globally unique helps error checking:
if a program calls an ioctl on the wrong device, it will get an error rather than some unexpected behaviour.

(2) The ‘strace’ build procedure automatically finds ioctl numbers defined with _IO, _IOW, _IOR, or _IOWR.

(3) ‘strace’ can decode numbers back into useful names when the numbers are unique.

(4) People looking for ioctls can grep for them more easily when this convention is used to define the ioctl numbers.

(5) When following the convention, the driver code can use generic code to copy the parameters between user and kernel space.

To decode a hex IOCTL code:

Most architectures use this generic format, but check
include/ARCH/ioctl.h for specifics
, e.g. powerpc
uses 3 bits to encode read/write and 13 bits for size.

bits meaning
31-30
00 - no parameters: uses _IO macro
10 - read: _IOR
01 - write: _IOW
11 - read/write: _IOWR

29-16
size of arguments

15-8
ascii character supposedly
unique to each driver

7-0
function #

So for example 0x82187201 is a read with arg length of 0x218,
character ‘r’ function 1. Grepping the source reveals this is:

#define VFAT_IOCTL_READDIR_BOTH _IOR(‘r’, 1, struct dirent [2])

引用文本内容摘自:KERNEL\linux-5.2.13\Documentation\ioctl

下载方式:https://pan.quark.cn/s/26794c3ef0f7 本文阐述了在Django框架中如何适当地展示HTML内容的方法。 在Web应用程序的开发过程中,常常需要向用户展示HTML格式的数据。 然而,在Django的模板系统中,为了防御跨站脚本攻击(XSS),系统会默认对HTML中的特殊字符进行转义处理。 这意味着,如果直接在模板代码中插入包含HTML标签的字符串,Django会自动将其转化为文本形式,而不是渲染为真正的HTML组件。 为了解决这个问题,首先必须熟悉Django模板引擎的安全特性。 Django为了防止不良用户借助HTML标签注入有害脚本,会自动对模板中输出的变量实施转义措施。 具体而言,模板引擎会将特殊符号(例如`<`、`>`、`&`等)转变为对应的HTML实体,因此,在浏览器中呈现的将是纯文本而非可执行的代码。 尽管如此,在某些特定情形下,我们确实需要在页面上呈现真实的HTML内容,这就需要借助特定的模板标签或过滤器来调控转义行为。 在提供的示例中,开发者期望输出的字符串`<h1>helloworld</h1>`能被正确地作为HTML元素展示在页面上,而不是被转义为文本`<h1>helloworld</h1>`。 为实现这一目标,作者提出了两种解决方案:1. 应用Django的`safe`过滤器。 当确认输出的内容是安全的且不会引发XSS攻击时,可以在模板中这样使用变量:```django<p>{{ data|safe }}</p>```通过这种方式,Django将不会对`data`变量的值进行HTML转义,而是直接将其当作HTML输出。 2. 使用`autoescape`标签。 在模板中,可以通过`autoesc...
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值