<commit_before>use core::{mem, str};

use arch::interrupt::irq::{ACKS, COUNTS, acknowledge};
use context;
use syscall::{Error, Result};
use super::Scheme;

pub struct IrqScheme;

impl Scheme for IrqScheme {
    fn open(&mut self, path: &[u8], _flags: usize) -> Result<usize> {
        let path_str = str::from_utf8(path).or(Err(Error::NoEntry))?;

        let id = path_str.parse::<usize>().or(Err(Error::NoEntry))?;

        if id < COUNTS.lock().len() {
            Ok(id)
        } else {
            Err(Error::NoEntry)
        }
    }

    fn dup(&mut self, file: usize) -> Result<usize> {
        Err(Error::NotPermitted)
    }

    fn read(&mut self, file: usize, buffer: &mut [u8]) -> Result<usize> {
        // Ensures that the length of the buffer is larger than the size of a usize
        if buffer.len() >= mem::size_of::<usize>() {
            let ack = ACKS.lock()[file];
            let current = COUNTS.lock()[file];
            if ack != current {
                // Safe if the length of the buffer is larger than the size of a usize
                assert!(buffer.len() >= mem::size_of::<usize>());<commit_msg>PS/2 driver convert to char<commit_after>use core::{mem, str};

use arch::interrupt::irq::{ACKS, COUNTS, acknowledge};
use syscall::{Error, Result};
use super::Scheme;

pub struct IrqScheme;

impl Scheme for IrqScheme {
    fn open(&mut self, path: &[u8], _flags: usize) -> Result<usize> {
        let path_str = str::from_utf8(path).or(Err(Error::NoEntry))?;

        let id = path_str.parse::<usize>().or(Err(Error::NoEntry))?;

        if id < COUNTS.lock().len() {
            Ok(id)
        } else {
            Err(Error::NoEntry)
        }
    }

    fn dup(&mut self, file: usize) -> Result<usize> {
        Err(Error::NotPermitted)
    }

    fn read(&mut self, file: usize, buffer: &mut [u8]) -> Result<usize> {
        // Ensures that the length of the buffer is larger than the size of a usize
        if buffer.len() >= mem::size_of::<usize>() {
            let ack = ACKS.lock()[file];
            let current = COUNTS.lock()[file];
            if ack != current {
                // Safe if the length of the buffer is larger than the size of a usize
                assert!(buffer.len() >= mem::size_of::<usize>());
{'fraction_non_alphanumeric': 0.15745245466607696, 'fraction_numerical': 0.0030959752321981426, 'mean_word_length': 2.4693251533742333, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2677830', 'n_tokens_mistral': 731, 'n_tokens_neox': 726, 'n_words': 203}