Skip to content
This repository was archived by the owner on Jan 14, 2026. It is now read-only.

Commit cd4a606

Browse files
committed
fmt
1 parent c2659cb commit cd4a606

14 files changed

Lines changed: 181 additions & 142 deletions

File tree

docs/users/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
この章では、LiteCoreにおけるユーザーシステムの概要について説明します。
2+
3+
## 概要
4+
ユーザーシステムは、System, Admin, Userの3つのユーザーモードで構成されており、それぞれ異なる権限レベルを持っています。Systemモードは最も高い権限を持ち、システム全体の管理を行います。Adminモードは、System以下Admin以上です。Userモードは一般的なユーザー操作を担当します。
5+
6+
各ユーザーには、users/ユーザー名 ディレクトリが割り当てられます。ただし、Systemユーザーには専用のディレクトリはありません。Adminユーザーには admin ディレクトリが割り当てられ、Userユーザーには username1, username2, ... といったディレクトリが割り当てられます。
7+
8+
ユーザーの権限ごとに可能な操作は以下の通りです:
9+
- Systemユーザー: システム全体の管理、ユーザーアカウントの作成・削除など、すべての操作。
10+
- Adminユーザー: ユーザーアカウントの管理や、危険な操作(システムファイルの編集・削除など)。
11+
- Userユーザー: 自身のファイルの作成・編集・削除、アプリケーションの実行など。
12+
ユーザーシステムは、セキュリティと管理の観点から重要な役割を果たしており、適切な権限管理が求められます。
13+
14+
各ユーザーのログイン情報は、/data/passファイルに保存されます。このファイルには、ユーザー名、パスワード(ハッシュ化された形式)、権限の情報が含まれています。
15+
passファイルのフォーマットは以下の通りです:
16+
```
17+
username:hashed_pass:permission_level
18+
```
19+
20+
ここで、usernameはユーザー名、hashed_passはハッシュ化されたパスワード、permission_levelはユーザーの権限レベル(System, Admin, User)を示します。
21+
22+
ユーザーは、ログイン時にユーザー名とパスワードを入力し、システムはpassファイルを参照して認証を行います。認証に成功すると、対応するユーザーディレクトリにアクセスできるようになります。
23+
24+
/data/passファイルの管理は、AdminユーザーおよびSystemユーザーのみが行うことができます。

src/include/driver/timer/apic.h

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,32 @@
88
#define APIC_BASE_DEFAULT 0xFEE00000
99

1010
/* APIC レジスタオフセット */
11-
#define APIC_ID 0x020 /* Local APIC ID */
12-
#define APIC_VERSION 0x030 /* Local APIC Version */
13-
#define APIC_TPR 0x080 /* Task Priority Register */
14-
#define APIC_EOI 0x0B0 /* End Of Interrupt */
15-
#define APIC_LDR 0x0D0 /* Logical Destination Register */
16-
#define APIC_DFR 0x0E0 /* Destination Format Register */
17-
#define APIC_SPURIOUS 0x0F0 /* Spurious Interrupt Vector Register */
18-
#define APIC_ESR 0x280 /* Error Status Register */
19-
#define APIC_TIMER_LVT 0x320 /* LVT Timer Register */
20-
#define APIC_TIMER_INIT 0x380 /* Timer Initial Count */
21-
#define APIC_TIMER_CURRENT 0x390 /* Timer Current Count */
22-
#define APIC_TIMER_DIV 0x3E0 /* Timer Divide Configuration */
11+
#define APIC_ID 0x020 /* Local APIC ID */
12+
#define APIC_VERSION 0x030 /* Local APIC Version */
13+
#define APIC_TPR 0x080 /* Task Priority Register */
14+
#define APIC_EOI 0x0B0 /* End Of Interrupt */
15+
#define APIC_LDR 0x0D0 /* Logical Destination Register */
16+
#define APIC_DFR 0x0E0 /* Destination Format Register */
17+
#define APIC_SPURIOUS 0x0F0 /* Spurious Interrupt Vector Register */
18+
#define APIC_ESR 0x280 /* Error Status Register */
19+
#define APIC_TIMER_LVT 0x320 /* LVT Timer Register */
20+
#define APIC_TIMER_INIT 0x380 /* Timer Initial Count */
21+
#define APIC_TIMER_CURRENT 0x390 /* Timer Current Count */
22+
#define APIC_TIMER_DIV 0x3E0 /* Timer Divide Configuration */
2323

2424
/* APIC Timer モード */
25-
#define APIC_TIMER_MODE_ONESHOT 0x00000000
25+
#define APIC_TIMER_MODE_ONESHOT 0x00000000
2626
#define APIC_TIMER_MODE_PERIODIC 0x00020000
2727
#define APIC_TIMER_MODE_TSCDEADLINE 0x00040000
2828

2929
/* APIC Timer 分周比 */
30-
#define APIC_TIMER_DIV_1 0x0B
31-
#define APIC_TIMER_DIV_2 0x00
32-
#define APIC_TIMER_DIV_4 0x01
33-
#define APIC_TIMER_DIV_8 0x02
34-
#define APIC_TIMER_DIV_16 0x03
35-
#define APIC_TIMER_DIV_32 0x08
36-
#define APIC_TIMER_DIV_64 0x09
30+
#define APIC_TIMER_DIV_1 0x0B
31+
#define APIC_TIMER_DIV_2 0x00
32+
#define APIC_TIMER_DIV_4 0x01
33+
#define APIC_TIMER_DIV_8 0x02
34+
#define APIC_TIMER_DIV_16 0x03
35+
#define APIC_TIMER_DIV_32 0x08
36+
#define APIC_TIMER_DIV_64 0x09
3737
#define APIC_TIMER_DIV_128 0x0A
3838

3939
int apic_timer_init(void);

src/kernel/device/keyboard.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ void keyboard_init(void) {
165165

166166
void keyboard_poll(void) {
167167
kbd_isr(0, NULL);
168-
168+
169169
// シリアル入力もポーリング
170170
char c;
171171
while ((c = serial_getc_nonblock()) != 0) {

src/kernel/driver/timer/apic.c

Lines changed: 53 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,17 @@ static int apic_initialized = 0;
2121
* @brief APICレジスタを読み取る
2222
*/
2323
static inline uint32_t apic_read(uint32_t reg) {
24-
if (!apic_base) return 0;
24+
if (!apic_base)
25+
return 0;
2526
return *(volatile uint32_t *)((uint8_t *)apic_base + reg);
2627
}
2728

2829
/**
2930
* @brief APICレジスタに書き込む
3031
*/
3132
static inline void apic_write(uint32_t reg, uint32_t value) {
32-
if (!apic_base) return;
33+
if (!apic_base)
34+
return;
3335
*(volatile uint32_t *)((uint8_t *)apic_base + reg) = value;
3436
}
3537

@@ -38,16 +40,14 @@ static inline void apic_write(uint32_t reg, uint32_t value) {
3840
*/
3941
static int check_apic_support(void) {
4042
uint32_t eax, edx;
41-
43+
4244
/* CPUID 機能 1: プロセッサ情報と機能ビット */
43-
__asm__ volatile(
44-
"movl $1, %%eax\n"
45-
"cpuid\n"
46-
: "=a"(eax), "=d"(edx)
47-
:
48-
: "ebx", "ecx"
49-
);
50-
45+
__asm__ volatile("movl $1, %%eax\n"
46+
"cpuid\n"
47+
: "=a"(eax), "=d"(edx)
48+
:
49+
: "ebx", "ecx");
50+
5151
/* EDXのビット9がAPICサポートを示す */
5252
return (edx & (1 << 9)) ? 1 : 0;
5353
}
@@ -57,16 +57,14 @@ static int check_apic_support(void) {
5757
*/
5858
static uint32_t get_apic_base(void) {
5959
uint32_t eax, edx;
60-
60+
6161
/* MSR 0x1B (IA32_APIC_BASE) を読み取る */
62-
__asm__ volatile(
63-
"movl $0x1B, %%ecx\n"
64-
"rdmsr\n"
65-
: "=a"(eax), "=d"(edx)
66-
:
67-
: "ecx"
68-
);
69-
62+
__asm__ volatile("movl $0x1B, %%ecx\n"
63+
"rdmsr\n"
64+
: "=a"(eax), "=d"(edx)
65+
:
66+
: "ecx");
67+
7068
/* 下位12bitをマスクしてベースアドレスを取得 */
7169
return eax & 0xFFFFF000;
7270
}
@@ -79,14 +77,16 @@ static uint32_t get_apic_base(void) {
7977
/**
8078
* @brief ACPI PM Timerの周波数(固定)
8179
*/
82-
#define ACPI_PM_TIMER_FREQ 3579545 /* 3.579545 MHz */
80+
#define ACPI_PM_TIMER_FREQ 3579545 /* 3.579545 MHz */
8381

8482
/**
8583
* @brief ACPI PM Timerから現在のカウント値を読み取る
8684
*/
8785
static inline uint32_t read_acpi_pm_timer(void) {
8886
uint32_t value;
89-
__asm__ volatile("inl %1, %0" : "=a"(value) : "d"((uint16_t)ACPI_PM_TIMER_PORT));
87+
__asm__ volatile("inl %1, %0"
88+
: "=a"(value)
89+
: "d"((uint16_t)ACPI_PM_TIMER_PORT));
9090
return value & 0x00FFFFFF;
9191
}
9292

@@ -95,15 +95,16 @@ static inline uint32_t read_acpi_pm_timer(void) {
9595
*/
9696
static uint32_t calibrate_apic_timer(void) {
9797
uint32_t target_ticks = ACPI_PM_TIMER_FREQ / 100; /* 10ms */
98-
98+
9999
/* APIC Timer を分周比16、最大値で開始 */
100100
apic_write(APIC_TIMER_DIV, APIC_TIMER_DIV_16);
101101
apic_write(APIC_TIMER_INIT, 0xFFFFFFFF);
102-
102+
103103
/* ACPI PM Timerの開始値を読み取る */
104104
uint32_t pm_start = read_acpi_pm_timer();
105-
uint32_t pm_end = (pm_start + target_ticks) & 0x00FFFFFF; /* 24bitでラップアラウンド */
106-
105+
uint32_t pm_end = (pm_start + target_ticks) &
106+
0x00FFFFFF; /* 24bitでラップアラウンド */
107+
107108
/* ACPI PM Timerが目標値に達するまで待機 */
108109
uint32_t pm_current;
109110
if (pm_end > pm_start) {
@@ -117,18 +118,19 @@ static uint32_t calibrate_apic_timer(void) {
117118
pm_current = read_acpi_pm_timer();
118119
} while (pm_current >= pm_start || pm_current < pm_end);
119120
}
120-
121+
121122
/* APICタイマーのカウントを読み取り */
122123
uint32_t apic_elapsed = 0xFFFFFFFF - apic_read(APIC_TIMER_CURRENT);
123-
124+
124125
uint32_t freq = apic_elapsed * 100;
125-
126+
126127
if (freq < 100000 || freq > 100000000) {
127128
/* 異常値の場合はデフォ値 */
128-
printk("APIC Timer: Calibration failed (freq=%u), using default\n", freq);
129+
printk("APIC Timer: Calibration failed (freq=%u), using default\n",
130+
freq);
129131
return 2000000; /* 2 MHz */
130132
}
131-
133+
132134
return freq;
133135
}
134136

@@ -144,7 +146,7 @@ int apic_timer_init(void) {
144146
printk("APIC Timer: CPU does not support APIC\n");
145147
return -1;
146148
}
147-
149+
148150
/* APICベースアドレスを取得 */
149151
uint32_t base_addr = get_apic_base();
150152
apic_base = (volatile uint32_t *)base_addr;
@@ -155,7 +157,7 @@ int apic_timer_init(void) {
155157
/* APICを有効化 (Spurious Interrupt Vector Register) */
156158
uint32_t spurious = apic_read(APIC_SPURIOUS);
157159
spurious |= (1 << 8); /* APIC Software Enable */
158-
spurious |= 0xFF; /* Spurious Vector = 0xFF */
160+
spurious |= 0xFF; /* Spurious Vector = 0xFF */
159161
apic_write(APIC_SPURIOUS, spurious);
160162

161163
#ifdef INIT_MSG
@@ -164,13 +166,13 @@ int apic_timer_init(void) {
164166
#endif
165167
apic_timer_frequency = calibrate_apic_timer();
166168
#ifdef INIT_MSG
167-
printk("APIC Timer: Frequency = %u Hz (%u MHz)\n",
168-
apic_timer_frequency, apic_timer_frequency / 1000000);
169+
printk("APIC Timer: Frequency = %u Hz (%u MHz)\n", apic_timer_frequency,
170+
apic_timer_frequency / 1000000);
169171
#endif
170-
172+
171173
/* タイマーをPeriodic モードで設定 */
172174
apic_write(APIC_TIMER_DIV, APIC_TIMER_DIV_16); /* 分周比16 */
173-
175+
174176
/* ベクタ番号48、Periodicモード、割り込みマスクなし */
175177
uint32_t lvt = APIC_TIMER_MODE_PERIODIC | 48;
176178
apic_write(APIC_TIMER_LVT, lvt);
@@ -182,7 +184,8 @@ int apic_timer_init(void) {
182184
apic_write(APIC_TIMER_INIT, init_count);
183185

184186
#ifdef INIT_MSG
185-
printk("APIC Timer: Running at 1000 Hz (initial count = %u)\n", init_count);
187+
printk("APIC Timer: Running at 1000 Hz (initial count = %u)\n",
188+
init_count);
186189
#endif
187190
boot_tick_count = 0;
188191
current_tick_count = 0;
@@ -210,11 +213,12 @@ int apic_timer_available(void) {
210213
void apic_timer_tick(uint32_t irq, void *context) {
211214
(void)irq;
212215
(void)context;
213-
214-
if (!apic_initialized) return;
215-
216+
217+
if (!apic_initialized)
218+
return;
219+
216220
current_tick_count++;
217-
221+
218222
/* EOI (End of Interrupt) を送信 */
219223
if (apic_base) {
220224
apic_write(APIC_EOI, 0);
@@ -228,10 +232,10 @@ uint64_t apic_get_uptime_us(void) {
228232
if (!apic_initialized) {
229233
return 0;
230234
}
231-
235+
232236
/* current_tick_count は1msごとに増加 */
233237
uint64_t ticks = current_tick_count - boot_tick_count;
234-
238+
235239
/* ティック数をマイクロ秒に変換 (1 tick = 1ms = 1000us) */
236240
return ticks * 1000ULL;
237241
}
@@ -243,7 +247,7 @@ uint64_t apic_get_uptime_ms(void) {
243247
if (!apic_initialized) {
244248
return 0;
245249
}
246-
250+
247251
/* current_tick_count は1msごとに増加 */
248252
return current_tick_count - boot_tick_count;
249253
}
@@ -259,11 +263,12 @@ uint32_t apic_timer_get_frequency(void) {
259263
* @brief 指定マイクロ秒だけ遅延
260264
*/
261265
void apic_timer_delay_us(uint32_t us) {
262-
if (!apic_initialized) return;
263-
266+
if (!apic_initialized)
267+
return;
268+
264269
uint64_t start = apic_get_uptime_us();
265270
uint64_t target = start + us;
266-
271+
267272
while (apic_get_uptime_us() < target) {
268273
__asm__ volatile("pause");
269274
}

src/kernel/driver/timer/timer.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,22 @@
22
#include <interrupt/irq.h>
33
#include <util/console.h>
44

5-
65
/**
76
* @brief 指定されたマイクロ秒だけ待つ
87
* @param us 待機時間(マイクロ秒)
98
* @return 0 成功, -1 APICタイマー未初期化
109
*/
1110
int kwait(uint32_t us) {
12-
if (!apic_timer_available()) {
13-
return -1;
14-
}
11+
if (!apic_timer_available()) {
12+
return -1;
13+
}
14+
15+
uint64_t start = apic_get_uptime_us();
16+
uint64_t target = start + us;
17+
18+
while (apic_get_uptime_us() < target) {
19+
interrupt_dispatch_all();
20+
}
1521

16-
uint64_t start = apic_get_uptime_us();
17-
uint64_t target = start + us;
18-
19-
while (apic_get_uptime_us() < target) {
20-
interrupt_dispatch_all();
21-
}
22-
23-
return 0;
22+
return 0;
2423
}

src/kernel/fs/ext/ext2.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,8 @@ int ext2_list_dir(struct ext2_super *sb, struct ext2_inode *dir_inode) {
885885
/* ブロックデータを読み取る(キャッシュ対応) */
886886
uint8_t block_data[4096]; /* 最大ブロックサイズ */
887887
if (sb->cache) {
888-
if (block_cache_read(sb->cache, block_num, block_data) != 0)
888+
if (block_cache_read(sb->cache, block_num,
889+
block_data) != 0)
889890
break;
890891
} else {
891892
uint32_t block_offset = block_num * sb->block_size;
@@ -933,8 +934,8 @@ int ext2_list_dir(struct ext2_super *sb, struct ext2_inode *dir_inode) {
933934
file_size = file_inode.i_size;
934935
}
935936

936-
printk(" %-20s [%-7s] size: %u\n",
937-
name, type_str, inode, file_size);
937+
printk(" %-20s [%-7s] size: %u\n", name,
938+
type_str, inode, file_size);
938939
}
939940

940941
offset += rec_len;

src/kernel/interrupt/idt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ void irq_handler_c(uint32_t vec) {
7777
if (vec >= 32 && vec < 32 + 16) {
7878
uint32_t irq = vec - 32;
7979
interrupt_raise((irq << 16) | 0u);
80-
80+
8181
if (irq >= 8)
8282
outb(PIC2_COMMAND, 0x20);
8383
outb(PIC1_COMMAND, 0x20);

0 commit comments

Comments
 (0)