Ядро выдает ошибку при записи в файл символьного устройства в 4.9.82-ti-r102 debian 9.3

В те дни, когда вам не хочется бороться с кавычками, используйте другой символ, например Unicode U+2019, вместо 'для апострофов.

Нажмите и удерживайте Ctrl + Shift и введите u2019, и этот символ появится(э... в зависимости от вашей локали? ).

% alias shopt='echo You’re looking for setopt. This is a Z shell, woman, not Bash.'
% shopt -s dotglob
You’re looking for setopt. This is a Z shell, woman, not Bash. -s dotglob

Такое использование(U+2019 )правильно, потому что этот символ официально предназначен для использования в качестве апострофа.Стандарт Unicode версии 10.0явно рекомендует такое использование. Стандарт признает, что'(U+0027 )обычно используется в качестве апострофа из-за его присутствия в ASCII и на клавиатурах, и, похоже, допускает это. Но затем он утверждает, что(U+2019 )является предпочтительным для апострофов, используемых в качестве знаков препинания (, и приводит в качестве примера сокращение ). Единственные апострофы, для которых(U+2019 )не являются предпочтительными, — это те, которые используются в качестве диакритических знаков, а не знаков препинания; их лучше писатьʼ(U+02BC ). Из Апострофы(с. 276 )в п. 6.2 стандарта:

Apostrophes

U+0027 APOSTROPHE is the most commonly used character for apostrophe. For historical reasons, U+0027 is a particularly overloaded character. In ASCII, it is used to represent a punctuation mark (such as right single quotation mark, left single quotation mark, apostrophe punctuation, vertical line, or prime) or a modifier letter (such as apostrophe modifier or acute accent). Punctuation marks generally break words; modifier letters generally are considered part of a word.

When text is set, U+2019 RIGHT SINGLE QUOTATION MARK is preferred as apostrophe, but only U+0027 is present on most keyboards. Software commonly offers a facility for automatically converting the U+0027 APOSTROPHE to a contextually selected curly quotation glyph. In these systems, a U+0027 in the data stream is always represented as a straight vertical line and can never represent a curly apostrophe or a right quotation mark.

Letter Apostrophe. U+02BC MODIFIER LETTER APOSTROPHE is preferred where the apostrophe is to represent a modifier letter (for example, in transliterations to indicate a glottal stop). In the latter case, it is also referred to as a letter apostrophe.

Punctuation Apostrophe. U+2019 RIGHT SINGLE QUOTATION MARK is preferred where the character is to represent a punctuation mark, as for contractions: “We’ve been here before.” In this latter case, U+2019 is also referred to as a punctuation apostrophe.

An implementation cannot assume that users’ text always adheres to the distinction between these characters. The text may come from different sources, including mapping from other character sets that do not make this distinction between the letter apostrophe and the punctuation apostrophe/right single quotation mark. In that case, all of them will generally be represented by U+2019.

The semantics of U+2019 are therefore context dependent. For example, if surrounded by letters or digits on both sides, it behaves as an in-text punctuation character and does not separate words or lines.

1
28.02.2020, 10:26
1 ответ

Как я уже говорил... Проблема в функции writeвашего драйвера char. Точнее, вы обращаетесь к буферу напрямую из пользовательского пространства. Вы не должны этого делать -, у ядра есть специальный API для этого. См. например это сообщение StackOverflow по теме.

В вашем конкретном случае вы должны удалить sprintfи использовать copy_from_userдля копирования данных из буфера пространства пользователя в буфер драйвера. Нечто подобное решает проблему с моей черной доской :

.
static ssize_t writeDev(struct file *file, const char __user *buf, size_t len, loff_t *offset)
{
    printk("Write to device buf: 0x%p: len = %d, offset = %lld\n", buf, len, *offset);

    if (copy_from_user(message, buf, len)) {
        printk("Unable to read buffer from user\n");
        return -EFAULT;
    }   

    return len;
}
0
28.04.2021, 23:22

Теги

Похожие вопросы