feat: add given files

Signed-off-by: Julien CLEMENT <julien.clement@epita.fr>
This commit is contained in:
juju committed 2021-07-12 15:57:08 +02:00
commit 7178dbb6a7
151 files changed
+13845

No files matched your search

+87
View File
@@ -0,0 +1,87 @@
#ifndef ATAPI_H_
#define ATAPI_H_
# include <k/compiler.h>
# include <k/types.h>
/* Device Control Registers */
# define PRIMARY_DCR 0x3F6
# define SECONDARY_DCR 0x376
/* DCR bits */
# define INTERRUPT_DISABLE (1 << 1)
# define SRST (1 << 2)
/* Drive selection bytes */
# define ATA_PORT_MASTER 0x00
# define ATA_PORT_SLAVE 0x10
/* ATA bus IO ports */
# define PRIMARY_REG 0x1F0
# define SECONDARY_REG 0x170
/* ATA I/O registers */
# define ATA_REG_DATA(PORT) (PORT)
# define ATA_REG_FEATURES(PORT) ((PORT) + 1)
# define ATA_REG_ERROR_INFO(PORT) ((PORT) + 1)
# define ATA_REG_SECTOR_COUNT(PORT) ((PORT) + 2)
# define ATA_REG_SECTOR_NB(PORT) ((PORT) + 3)
# define ATA_REG_LBA_LO(PORT) ((PORT) + 3)
# define ATA_REG_CYLINDER_LOW(PORT) ((PORT) + 4)
# define ATA_REG_LBA_MI(PORT) ((PORT) + 4)
# define ATA_REG_CYLINDER_HIGH(PORT) ((PORT) + 5)
# define ATA_REG_LBA_HI(PORT) ((PORT) + 5)
# define ATA_REG_DRIVE(PORT) ((PORT) + 6)
# define ATA_REG_HEAD(PORT) ((PORT) + 6)
# define ATA_REG_COMMAND(PORT) ((PORT) + 7)
# define ATA_REG_STATUS(PORT) ((PORT) + 7)
/* Status bits */
# define ERR (1 << 0)
# define DRQ (1 << 3)
# define SRV (1 << 4)
# define DF (1 << 5)
# define RDY (1 << 6)
# define BSY (1 << 7)
# define ABRT (1 << 2)
/* ATAPI signature */
# define ATAPI_SIG_SC 0x01
# define ATAPI_SIG_LBA_LO 0x01
# define ATAPI_SIG_LBA_MI 0x14
# define ATAPI_SIG_LBA_HI 0xEB
/* ATA commands */
# define IDENTIFY_PACKET_DEVICE 0xA1
# define PACKET 0xA0
/* SCSI commands */
# define READ_12 0xA8
# define DPO (1 << 4)
# define ATAPI_BLK_CACHE_SZ 256
# define CD_BLOCK_SZ 2048
# define PACKET_SZ 12
# define PACKET_AWAIT_COMMAND 1
# define PACKET_DATA_TRANSMIT 2
# define PACKET_COMMAND_COMPLETE 3
struct SCSI_packet {
u8 op_code;
u8 flags_lo;
u8 lba_hi;
u8 lba_mihi;
u8 lba_milo;
u8 lba_lo;
u8 transfer_length_hi;
u8 transfer_length_mihi;
u8 transfer_length_milo;
u8 transfer_length_lo;
u8 flags_hi;
u8 control;
} __packed;
#endif /* !ATAPI_H_ */
+39
View File
@@ -0,0 +1,39 @@
#ifndef BLOCKDEV_H_
#define BLOCKDEV_H_
# include <assert.h>
# include <k/types.h>
struct blockdev;
struct blk_ops {
void *(*read)(struct blockdev *, size_t);
void (*free_blk)(struct blockdev *, void *);
};
struct blockdev {
size_t blk_size;
struct blk_ops *ops;
void *blocks;
};
static inline void *block_read(struct blockdev *bd, size_t lba)
{
assert(bd);
assert(bd->ops);
assert(bd->ops->read);
return bd->ops->read(bd, lba);
}
static inline void block_free(struct blockdev *bd, void *ptr)
{
assert(bd);
assert(bd->ops);
assert(bd->ops->free_blk);
bd->ops->free_blk(bd, ptr);
}
#endif /* BLOCKDEV_H_ */
+8
View File
@@ -0,0 +1,8 @@
#ifndef COMPILER_H
#define COMPILER_H
#define array_size(arr) (sizeof(arr) / sizeof(*arr))
#define __packed __attribute__((__packed__))
#define align_up(addr, bytes) (((addr) + (bytes) - 1) & ~((bytes) - 1))
#endif
+138
View File
@@ -0,0 +1,138 @@
/*
* This file is part of my_read_iso.
*
* my_read_iso is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* my_read_iso is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with my_read_iso; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Copyright Alexandre Becoulet, 2003
* contact : alexandre.becoulet@epita.fr
*/
#ifndef ISO9660_H
# define ISO9660_H
# define __packed __attribute__((__packed__))
/* Structures used for twin values */
struct endian32 {
u32 le; /* little endian value */
u32 be; /* big endian value */
} __packed;
struct endian16 {
u16 le; /* little endian value */
u16 be; /* big endian value */
} __packed;
# define ISO_BLOCK_SIZE 2048
/* ISO9660 Path table structure */
struct iso_path_table_le {
u8 idf_len; /* Identifier name length */
u8 ext_size; /* Extended attribute record length */
u32 data_blk; /* File data block index */
u16 parent_dir; /* Number of the parent dir */
char idf[0]; /* directory name */
} __packed;
/* ISO9660 directory structure */
# define MAX_DIR_DEPTH 8
# define ISO_DATE_LEN 7
enum iso_file_type {
ISO_FILE_HIDDEN = 1, /* File is Hidden */
ISO_FILE_ISDIR = 2, /* Entry is a Directory */
ISO_FILE_ASSOCIAT = 4, /* Entry is an Associated */
ISO_FILE_USEEXT = 8,
/* Information is structured according to the extended attribute record */
ISO_FILE_USEPERM = 16,
/* Permissions are specified in the extended attribute record */
ISO_FILE_MULTIDIR = 128 /* File has more than one directory record */
};
struct iso_dir {
u8 dir_size; /* Length of directory record */
u8 ext_size; /* Extended attribute record length */
struct endian32 data_blk; /* File data block index */
struct endian32 file_size; /* File size */
char date[ISO_DATE_LEN];
u8 type; /* File type (enum iso_file_type) */
/* only valid if the file is recorded in interleave mode */
u8 unit_size; /* File Unit Size */
u8 gap_size; /* Interleave Gap Size */
struct endian16 vol_seq;
u8 idf_len;
char idf[0]; /* file name */
} __packed;
/* ISO9660 Primary volume descriptor structure */
# define ISO_PRIM_VOLDESC_BLOCK 16
# define ISO_SYSIDF_LEN 32
# define ISO_VOLIDF_LEN 32
# define ISO_VOLSET_LEN 128
# define ISO_PUBIDF_LEN 128
# define ISO_DPREP_LEN 128
# define ISO_APP_LEN 128
# define ISO_CPRFIL_LEN 37
# define ISO_ABSFIL_LEN 37
# define ISO_BIBFIL_LEN 37
# define ISO_LDATE_LEN 17
struct iso_prim_voldesc {
u8 vol_desc_type; /* Volume Descriptor Type (1) */
char std_identifier[5]; /* Standard Identifier (CD001) */
u8 vol_desc_version; /* Volume Descriptor Version (1) */
u8 unused1; /* Unused Field */
char syidf[ISO_SYSIDF_LEN]; /* System Identifier */
char vol_idf[ISO_VOLIDF_LEN]; /* Volume Identifier */
u8 unused2[8]; /* Unused Field */
struct endian32 vol_blk_count;
/* Number of logical blocks in the Volume (LE)*/
u8 unused4[32]; /* Unused Field */
struct endian16 vol_set_size; /* The Volume Set size of the Volume */
struct endian16 vol_seq_num; /* The number of the volume in the Set */
struct endian16 vol_blk_size; /* The size in bytes of a Logical Block */
struct endian32 path_table_size; /* Length in bytes of the path table */
u32 le_path_table_blk; /* LittleEndian path table block index */
u32 le_opath_table_blk;
/* LittleEndian optional path table block index */
u32 be_path_table_blk; /* BigEndian path table block index */
u32 be_opath_table_blk; /* BigEndian optional path table block index */
struct iso_dir root_dir; /* Root directory entry */
u8 unused5[34 - sizeof (struct iso_dir)];/* padding */
char volset_idf[ISO_VOLSET_LEN]; /* Name of the multiple volume set */
char pub_idf[ISO_PUBIDF_LEN]; /* Publisher name */
char dprep_idf[ISO_DPREP_LEN]; /* Data preparer name */
char app_idf[ISO_APP_LEN]; /* Application name */
char copyright_file[ISO_CPRFIL_LEN]; /* Copyright file name in root dir */
char abstract_file[ISO_ABSFIL_LEN]; /* Abstract file name in root dir */
char bibli_file[ISO_BIBFIL_LEN]; /* Bibliographic file name in root dir */
char date_creat[ISO_LDATE_LEN]; /* Creation date */
char date_modif[ISO_LDATE_LEN]; /* Modification date */
char date_expir[ISO_LDATE_LEN]; /* Expiration date */
char date_effect[ISO_LDATE_LEN]; /* Effective date */
u8 filestrutc_version; /* File Structure Version (1) */
} __packed;
#endif /* !ISO9660_H */
+92
View File
@@ -0,0 +1,92 @@
#ifndef K_KFS_H
#define K_KFS_H
#include <k/types.h>
#define KFS_MAGIC 0xd35f9caa
#define KFS_MIN_BLK_SZ 512
#define KFS_BLK_SZ 4096
#define KFS_BLK_DATA_SZ (KFS_BLK_SZ - 3 * 4)
#define KFS_DIRECT_BLK 10
#define KFS_INDIRECT_BLK 16
#define KFS_INDIRECT_BLK_CNT 16
#define KFS_FNAME_SZ 32
#define KFS_NAME_SZ 32
#define __packed __attribute__((__packed__))
struct kfs_block {
u32 idx;
u32 usage;
u32 cksum;
u8 data[KFS_BLK_DATA_SZ];
} __packed;
struct kfs_iblock {
u32 idx;
u32 blk_cnt;
u32 blks[KFS_INDIRECT_BLK_CNT];
u32 cksum;
} __packed;
struct kfs_inode {
u32 inumber;
char filename[KFS_FNAME_SZ];
u32 file_sz;
u32 idx;
u32 blk_cnt;
u32 next_inode;
u32 d_blk_cnt;
u32 i_blk_cnt;
u32 d_blks[KFS_DIRECT_BLK];
u32 i_blks[KFS_INDIRECT_BLK];
u32 cksum;
} __packed;
struct kfs_blk {
union {
struct kfs_block blk;
struct kfs_iblock iblk;
struct kfs_inode ino;
u8 whole_blk[KFS_BLK_SZ];
};
};
struct kfs_superblock {
u32 magic;
char name[KFS_NAME_SZ];
s32 ctime;
u32 blk_cnt;
u32 inode_cnt;
u32 inode_idx;
u32 cksum;
} __packed;
#define ADLER32_MOD 65521
/**
* @brief Adler32 checksum.
*/
static inline unsigned int kfs_checksum(const void *data, size_t size)
{
unsigned int a = 1;
unsigned int b = 0;
size_t i = 0;
const u8 *buf = data;
while (i < size) {
a += buf[i++];
b += a;
}
return ((b % ADLER32_MOD) << 16) | (a % ADLER32_MOD);
}
#endif
+154
View File
@@ -0,0 +1,154 @@
/*
* Copyright (c) LSE
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY LSE AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL LSE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef K_KSTD_H_
#define K_KSTD_H_
#include <k/types.h>
typedef s32 ssize_t;
typedef s32 off_t;
struct melody {
unsigned long freq;
unsigned long duration;
};
/*
** constants
*/
/* console */
enum e_cons_codes {
CONS_ESCAPE = 255,
CONS_CLEAR = 1,
CONS_COLOR = 2,
CONS_SETX = 3,
CONS_SETY = 4,
CONS_BLACK = 0,
CONS_BLUE = 1,
CONS_GREEN = 2,
CONS_CYAN = 3,
CONS_RED = 4,
CONS_MAGENTA = 5,
CONS_YELLOW = 6,
CONS_WHITE = 7,
CONS_BLINK = (1 << 7),
CONS_LIGHT = (1 << 3)
};
#define CONS_FRONT(Color) (Color)
#define CONS_BACK(Color) (Color << 4)
/* keyboard */
enum e_kbd_codes {
KEY_ESC = 1,
KEY_F1 = 59,
KEY_F2 = 60,
KEY_F3 = 61,
KEY_F4 = 62,
KEY_F5 = 63,
KEY_F6 = 64,
KEY_F7 = 65,
KEY_F8 = 66,
KEY_f9 = 67,
KEY_F10 = 68,
KEY_F11 = 87,
KEY_F12 = 88,
KEY_1 = 2,
KEY_2 = 3,
KEY_3 = 4,
KEY_4 = 5,
KEY_5 = 6,
KEY_6 = 7,
KEY_7 = 8,
KEY_8 = 9,
KEY_9 = 10,
KEY_0 = 11,
KEY_TAB = 15,
KEY_MAJLOCK = 58,
KEY_LSHIFT = 42,
KEY_RSHIFT = 54,
KEY_ALT = 56,
KEY_SPACE = 57,
KEY_CTRL = 29,
KEY_ENTER = 28,
KEY_BACKSPACE = 14,
KEY_LEFT = 75,
KEY_RIGHT = 77,
KEY_UP = 72,
KEY_DOWN = 80,
KEY_PAUSE = 69,
KEY_SYST = 55,
KEY_INSER = 82,
KEY_SUPPR = 83,
};
enum e_k_mode {
KEY_PRESSED,
KEY_RELEASED,
};
/* mouse */
enum e_mouse_codes {
BUTTON_LEFT = 1,
BUTTON_RIGHT = 2
};
/* misc */
#define O_RDONLY 0
#define SEEK_SET 0
#define SEEK_CUR 1
#define SEEK_END 2
#define VIDEO_GRAPHIC 0
#define VIDEO_TEXT 1
/*
** syscalls
*/
#define SYSCALL_WRITE 1
#define SYSCALL_SBRK 2
#define SYSCALL_GETKEY 3
#define SYSCALL_GETTICK 4
#define SYSCALL_OPEN 5
#define SYSCALL_READ 6
#define SYSCALL_SEEK 7
#define SYSCALL_CLOSE 8
#define SYSCALL_SETVIDEO 9
#define SYSCALL_SWAP_FRONTBUFFER 10
#define SYSCALL_PLAYSOUND 11
#define SYSCALL_SETPALETTE 12
#define SYSCALL_GETMOUSE 13
#define NR_SYSCALL (SYSCALL_GETMOUSE + 1)
#define ENOMEM 1 /* Not enough space */
#define ENOENT 2 /* No such file or directory */
#define EIO 3 /* I/O error */
#define EINVAL 4 /* Invalid argument */
#define ENOSYS 5 /* Invalid system call number */
#define EBADF 6 /* fd is not an open file descriptor */
#define EAGAIN 7 /* Temporary unavailable */
#endif /* !KSTD_H_ */
+15
View File
@@ -0,0 +1,15 @@
#ifndef K_TYPES_H
#define K_TYPES_H
#include <stddef.h>
typedef unsigned char u8;
typedef signed char s8;
typedef unsigned short u16;
typedef signed short s16;
typedef unsigned int u32;
typedef signed int s32;
typedef unsigned long long u64;
typedef signed long long s64;
#endif
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.