1110File Space Bitmap Block损坏能修复吗3

本文详细记录了一次修复Oracle数据库中损坏的位图区块的过程。通过在线模式使用DBMS_SPACE_ADMIN.TABLESPACE_REBUILD_BITMAPS过程成功修复了损坏,并验证了修复后的数据一致性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

[20161110]File Space Bitmap Block损坏能修复吗3.txt

--今天仔细检查才发现我原来的链接存在问题,http://blog.itpub.net/267265/viewspace-2128025/
--我使用错函数了,
execute dbms_space_admin.tablespace_dump_bitmaps('TEA');

--应该使用:
execute dbms_space_admin.TABLESPACE_REBUILD_BITMAPS('TEA');

--都是copy and paste的错,也怪自己不仔细看。重新测试看看。

1.环境:
SCOTT@book> @ &r/ver1
PORT_STRING                    VERSION        BANNER
------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/Linux 2.4.xx            11.2.0.4.0     Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

CREATE TABLESPACE SUGAR DATAFILE
  '/mnt/ramdisk/book/sugar01.dbf' SIZE 40M AUTOEXTEND ON NEXT 16M MAXSIZE UNLIMITED
LOGGING
ONLINE
EXTENT MANAGEMENT LOCAL AUTOALLOCATE
BLOCKSIZE 8K
SEGMENT SPACE MANAGEMENT AUTO
FLASHBACK ON;

create table t1 tablespace sugar as select rownum id ,lpad('A',32,'A') name from dual connect by level<=1e5;
--建立大小5M的表。

create table t2 tablespace sugar as select rownum id ,lpad('B',32,'B') name from dual connect by level<=2e5;
create table t3 tablespace sugar as select rownum id ,lpad('C',32,'C') name from dual connect by level<=2e5;
alter system checkpoint;

2.破坏位图区。

SYS@book> alter tablespace sugar offline ;
Tablespace altered.

--安全期间,做一个备份:
$ cp /mnt/ramdisk/book/sugar01.dbf /u01/backup/sugar01.dbf_20161110
--正常数据文件第0块OS。第1块是文件头,第2块是位图头块,第3-127块是位图区。
--我文件很小,估计在3块里面:8192*3=24576

$ bvi -b 24576 -s 8192 /mnt/ramdisk/book/sugar01.dbf
--应该能看到许多F,表示已经使用,随便输入一些垃圾数据。我的测试全部设置为0。

RMAN> validate datafile 6;

Starting validate at 2016-11-10 11:27:40
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=80 device type=DISK
channel ORA_DISK_1: starting validation of datafile
channel ORA_DISK_1: specifying datafile(s) for validation
input datafile file number=00006 name=/mnt/ramdisk/book/sugar01.dbf
channel ORA_DISK_1: validation complete, elapsed time: 00:00:01
List of Datafiles
=================
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
6    FAILED 0              1945         5120            6239125
  File Name: /mnt/ramdisk/book/sugar01.dbf
  Block Type Blocks Failing Blocks Processed
  ---------- -------------- ----------------
  Data       0              2974
  Index      0              0
  Other      1              201

validate found one or more corrupt blocks
See trace file /u01/app/oracle/diag/rdbms/book/book/trace/book_ora_65118.trc for details
Finished validate at 2016-11-10 11:27:42

3.继续测试:
SCOTT@book> alter tablespace sugar online ;
Tablespace altered.

--居然可以online。

SCOTT@book> select * from t1 where rownum=1;
ID NAME
--- --------------------------------
  1 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

SCOTT@book> select * from t2 where rownum=1;
ID NAME
-- --------------------------------
1 BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB

SCOTT@book> select * from t3 where rownum=1;
ID NAME
-- --------------------------------
1 CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC

--DML没有问题,增加新表报错。

SCOTT@book> create table t4 tablespace sugar as select rownum id ,lpad('D',32,'D') name from dual connect by level<=10;
create table t4 tablespace sugar as select rownum id ,lpad('D',32,'D') name from dual connect by level<=10
                                                                                 *
ERROR at line 1:
ORA-00600: internal error code, arguments: [KSLFDNG2], [0x0859218E0], [0], [0x084B84748], [0x000000000], [], [], [], [], [], [], []


--既然可以online,执行如下看看。

SYS@book> execute dbms_space_admin.TABLESPACE_REBUILD_BITMAPS('SUGAR');
PL/SQL procedure successfully completed.

--BTW,offline不行:
SYS@book> alter tablespace sugar offline ;

Tablespace altered.

SYS@book> execute dbms_space_admin.TABLESPACE_REBUILD_BITMAPS('SUGAR');
BEGIN dbms_space_admin.TABLESPACE_REBUILD_BITMAPS('SUGAR'); END;

*
ERROR at line 1:
ORA-03219: Tablespace 'SUGAR' is dictionary-managed, offline or temporary
ORA-06512: at "SYS.DBMS_SPACE_ADMIN", line 120
ORA-06512: at line 1

$ bvi -b 24576 -s 8192 /mnt/ramdisk/book/sugar01.dbf
00006000  1E A2 00 00 03 00 80 01 06 35 5F 00 00 00 02 04 44 41 00 00 06 00 00 00 80 00 00 00 00 00 00 00 .........5_.....DA..............
00006020  00 F8 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF FF FF FF FF FF FF FF ................................
00006040  FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ................................
00006060  FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ................................
00006080  FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ................................
000060A0  FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ................................
000060C0  FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ................................
000060E0  FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ................................
00006100  FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ................................
00006120  FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ................................
00006140  FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ................................
00006160  FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ................................
00006180  FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ................................
000061A0  FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ................................
000061C0  FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ................................
000061E0  FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ................................
00006200  FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ................................
00006220  FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ................................
00006240  FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ................................
00006260  FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ................................

3.再测试是否可以建立表:

SCOTT@book> create table t4 tablespace sugar as select rownum id ,lpad('D',32,'D') name from dual connect by level<=10;
Table created.

SCOTT@book> column PARTITION_NAME noprint
SCOTT@book> select * from dba_extents where owner=user and segment_name in ('T3','T4');
OWNER  SEGMENT_NAME SEGMENT_TYPE TABLESPACE_NAME  EXTENT_ID    FILE_ID   BLOCK_ID      BYTES BLOCKS RELATIVE_FNO
------ ------------ ------------ --------------- ---------- ---------- ---------- ---------- ------ ------------
SCOTT  T3           TABLE        SUGAR                    0          6       2048      65536      8            6
SCOTT  T3           TABLE        SUGAR                    1          6       2056      65536      8            6
SCOTT  T3           TABLE        SUGAR                    2          6       2064      65536      8            6
SCOTT  T3           TABLE        SUGAR                    3          6       2072      65536      8            6
SCOTT  T3           TABLE        SUGAR                    4          6       2080      65536      8            6
SCOTT  T3           TABLE        SUGAR                    5          6       2088      65536      8            6
SCOTT  T3           TABLE        SUGAR                    6          6       2096      65536      8            6
SCOTT  T3           TABLE        SUGAR                    7          6       2104      65536      8            6
SCOTT  T3           TABLE        SUGAR                    8          6       2112      65536      8            6
SCOTT  T3           TABLE        SUGAR                    9          6       2120      65536      8            6
SCOTT  T3           TABLE        SUGAR                   10          6       2128      65536      8            6
SCOTT  T3           TABLE        SUGAR                   11          6       2136      65536      8            6
SCOTT  T3           TABLE        SUGAR                   12          6       2144      65536      8            6
SCOTT  T3           TABLE        SUGAR                   13          6       2152      65536      8            6
SCOTT  T3           TABLE        SUGAR                   14          6       2160      65536      8            6
SCOTT  T3           TABLE        SUGAR                   15          6       2168      65536      8            6
SCOTT  T3           TABLE        SUGAR                   16          6       2176    1048576    128            6
SCOTT  T3           TABLE        SUGAR                   17          6       2304    1048576    128            6
SCOTT  T3           TABLE        SUGAR                   18          6       2432    1048576    128            6
SCOTT  T3           TABLE        SUGAR                   19          6       2560    1048576    128            6
SCOTT  T3           TABLE        SUGAR                   20          6       2688    1048576    128            6
SCOTT  T3           TABLE        SUGAR                   21          6       2816    1048576    128            6
SCOTT  T3           TABLE        SUGAR                   22          6       2944    1048576    128            6
SCOTT  T3           TABLE        SUGAR                   23          6       3072    1048576    128            6
SCOTT  T3           TABLE        SUGAR                   24          6       3200    1048576    128            6
SCOTT  T4           TABLE        SUGAR                    0          6       3328      65536      8            6
26 rows selected.

--你可以发现空间并没有浪费。这样看来File Space Bitmap Block损坏很好修复。
RMAN> validate datafile 6;

Starting validate at 2016-11-10 11:38:36
using channel ORA_DISK_1
channel ORA_DISK_1: starting validation of datafile
channel ORA_DISK_1: specifying datafile(s) for validation
input datafile file number=00006 name=/mnt/ramdisk/book/sugar01.dbf
channel ORA_DISK_1: validation complete, elapsed time: 00:00:01
List of Datafiles
=================
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
6    OK     0              1941         5120            6239531
  File Name: /mnt/ramdisk/book/sugar01.dbf
  Block Type Blocks Failing Blocks Processed
  ---------- -------------- ----------------
  Data       0              2975
  Index      0              0
  Other      0              204

Finished validate at 2016-11-10 11:38:37
--一切OK。

4.补充看看其他参数:
SYS@book> @ &r/desc_proc sys dbms_space_admin TABLESPACE_REBUILD_BITMAPS
INPUT OWNER PACKAGE_NAME OBJECT_NAME
sample : @desc_proc sys dbms_stats gather_%_stats


OWNER      PACKAGE_NAME         OBJECT_NAME                      SEQUENCE ARGUMENT_NAME        DATA_TYPE            IN_OUT    DATA_TYPE            DEFAULTED
---------- -------------------- ------------------------------ ---------- -------------------- -------------------- --------- -------------------- ----------
SYS        DBMS_SPACE_ADMIN     TABLESPACE_REBUILD_BITMAPS              1 TABLESPACE_NAME      VARCHAR2             IN        VARCHAR2             N
                                                                        2 BITMAP_RELATIVE_FILE BINARY_INTEGER       IN        BINARY_INTEGER       Y
                                                                        3 BITMAP_BLOCK         BINARY_INTEGER       IN        BINARY_INTEGER       Y


--还可以指定特定的位图块,看看。

SYS@book> execute dbms_space_admin.TABLESPACE_REBUILD_BITMAPS('SUGAR',BITMAP_RELATIVE_FILE=>6,BITMAP_BLOCK=>4);
BEGIN dbms_space_admin.TABLESPACE_REBUILD_BITMAPS('SUGAR',BITMAP_RELATIVE_FILE=>6,BITMAP_BLOCK=>4); END;

*
ERROR at line 1:
ORA-03220: DBMS_ADMIN_PACKAGE required parameter is NULL or missing
ORA-06512: at "SYS.DBMS_SPACE_ADMIN", line 120
ORA-06512: at line 1


--参考官方文档:http://docs.oracle.com/cd/B19306_01/appdev.102/b14258/d_spadmn.htm#i1003484

TABLESPACE_REBUILD_BITMAPS Procedure

This procedure rebuilds the appropriate bitmaps. If no bitmap block DBA is specified, then it rebuilds all bitmaps for
the given tablespace.

The procedure cannot be used on the SYSTEM tablespace.

Syntax

DBMS_SPACE_ADMIN.TABLESPACE_REBUILD_BITMAPS (
   tablespace_name         IN    VARCHAR2,
   bitmap_relative_file    IN    POSITIVE   DEFAULT NULL,
   bitmap_block            IN    POSITIVE   DEFAULT NULL);

Parameters

Table 99-13 TABLESPACE_REBUILD_BITMAPS Procedure Parameters

Parameter               Description
----------------------------------------------------------
tablespace_name       Name of tablespace.
bitmap_relative_file  Relative file number of bitmap block to rebuild.
bitmap_block          Block number of bitmap block to rebuild.

Usage Notes

Note:
Only full rebuild is supported.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Examples

The following example rebuilds bitmaps for all the files in the USERS tablespace.

EXECUTE DBMS_SPACE_ADMIN.TABLESPACE_REBUILD_BITMAPS('USERS');

--我的测试视乎不能使用后面的参数。

#include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> #include <sys/stat.h> #include <locale.h> #include <stdbool.h> #include <ctype.h> #define MAX_NAME_LEN 256 #define MAX_CHILDREN 100 #define MAX_USERS 10 #define BLOCK_SIZE 512 #define BLOCK_NUM 1024 #define MAX_CMD_LEN 256 #define MAX_PATH_LEN 4096 #define BITMAP_SIZE (BLOCK_NUM / 8) typedef enum { FILE_TYPE, DIRECTORY_TYPE } FileType; typedef struct FileNode FileNode; typedef struct SystemState SystemState; struct FileNode { char name[MAX_NAME_LEN]; FileType type; FileNode* children[MAX_CHILDREN]; int child_count; time_t create_time; unsigned char protect; int size; int start_block; }; typedef struct { char username[MAX_NAME_LEN]; char password[MAX_NAME_LEN]; FileNode* root; FileNode* current; } UserDirectory; typedef struct { UserDirectory users[MAX_USERS]; int user_count; unsigned char bitmap[BITMAP_SIZE]; } MasterFileDirectory; struct SystemState { MasterFileDirectory mfd; char current_user[MAX_NAME_LEN]; FileNode* current_dir; FILE* disk_fp; }; /* 前置声明所有函数 */ void init_filesystem(SystemState* state); void cleanup_filesystem(SystemState* state); bool login(SystemState* state); void cd_command(SystemState* state, const char* arg); void dir_command(SystemState* state, const char* arg); void mkdir_command(SystemState* state, const char* arg); void rmdir_command(SystemState* state, const char* arg); void edit_command(SystemState* state, const char* arg); void delfile_command(SystemState* state, const char* arg); void show_help(void); FileNode* create_node(const char* name, FileType type); void destroy_node(FileNode* node); void add_child(FileNode* parent, FileNode* child); FileNode* find_child(const FileNode* parent, const char* name); void remove_child(FileNode* parent, const char* name); int find_free_block(SystemState* state); /********************* * 核心功能实现 *********************/ FileNode* create_node(const char* name, FileType type) { FileNode* node = (FileNode*)malloc(sizeof(FileNode)); if (!node) return NULL; strncpy(node->name, name, MAX_NAME_LEN - 1); node->name[MAX_NAME_LEN - 1] = &#39;\0&#39;; node->type = type; node->child_count = 0; node->create_time = time(NULL); node->protect = (type == DIRECTORY_TYPE) ? 0b111 : 0b110; node->size = 0; node->start_block = -1; return node; } void destroy_node(FileNode* node) { if (!node) return; for (int i = 0; i < node->child_count; i++) { destroy_node(node->children[i]); } free(node); } void add_child(FileNode* parent, FileNode* child) { if (parent && child && parent->child_count < MAX_CHILDREN) { parent->children[parent->child_count++] = child; } } FileNode* find_child(const FileNode* parent, const char* name) { if (!parent || !name) return NULL; for (int i = 0; i < parent->child_count; i++) { if (strcmp(parent->children[i]->name, name) == 0) { return parent->children[i]; } } return NULL; } /********************* * 系统初始化与清理 *********************/ void init_filesystem(SystemState* state) { state->disk_fp = fopen("virtual_disk.img", "wb+"); if (!state->disk_fp) { perror("Failed to open disk file"); exit(EXIT_FAILURE); } memset(&state->mfd, 0, sizeof(MasterFileDirectory)); for (int i = 0; i < 2; i++) state->mfd.bitmap[i / 8] |= (1 << (i % 8)); UserDirectory* user = &state->mfd.users[0]; strncpy(user->username, "jiu", MAX_NAME_LEN); strncpy(user->password, "123", MAX_NAME_LEN); user->root = create_node("/", DIRECTORY_TYPE); user->current = user->root; state->mfd.user_count = 1; state->current_dir = user->root; strncpy(state->current_user, "jiu", MAX_NAME_LEN); fwrite(&state->mfd, sizeof(MasterFileDirectory), 1, state->disk_fp); fflush(state->disk_fp); } void cleanup_filesystem(SystemState* state) { if (state) { for (int i = 0; i < state->mfd.user_count; i++) { destroy_node(state->mfd.users[i].root); } fclose(state->disk_fp); } } /********************* * 命令实现 *********************/ bool login(SystemState* state) { char username[MAX_NAME_LEN]; char password[MAX_NAME_LEN]; printf("Username: "); if (!fgets(username, MAX_NAME_LEN, stdin)) return false; username[strcspn(username, "\n")] = &#39;\0&#39;; printf("Password: "); if (!fgets(password, MAX_NAME_LEN, stdin)) return false; password[strcspn(password, "\n")] = &#39;\0&#39;; for (int i = 0; i < state->mfd.user_count; i++) { if (strcmp(state->mfd.users[i].username, username) == 0 && strcmp(state->mfd.users[i].password, password) == 0) { state->current_dir = state->mfd.users[i].current; strncpy(state->current_user, username, MAX_NAME_LEN); return true; } } return false; } int find_free_block(SystemState* state) { for (int i = 0; i < BLOCK_NUM; i++) { if (!(state->mfd.bitmap[i / 8] & (1 << (i % 8)))) { state->mfd.bitmap[i / 8] |= (1 << (i % 8)); return i; } } return -1; } void mkdir_command(SystemState* state, const char* dirname) { if (!dirname || *dirname == &#39;\0&#39;) { printf("Usage: mkdir <directory-name>\n"); return; } if (strlen(dirname) >= MAX_NAME_LEN) { printf("Directory name too long (max %d chars)\n", MAX_NAME_LEN-1); return; } if (find_child(state->current_dir, dirname)) { printf("Directory already exists: %s\n", dirname); return; } FileNode* new_dir = create_node(dirname, DIRECTORY_TYPE); if (!new_dir) { printf("Memory allocation failed\n"); return; } add_child(state->current_dir, new_dir); printf("Created directory: %s\n", dirname); } void remove_child(FileNode* parent, const char* name) { if (!parent || !name) return; for (int i = 0; i < parent->child_count; i++) { if (strcmp(parent->children[i]->name, name) == 0) { destroy_node(parent->children[i]); for (int j = i; j < parent->child_count - 1; j++) { parent->children[j] = parent->children[j + 1]; } parent->child_count--; return; } } } void rmdir_command(SystemState* state, const char* dirname) { if (!dirname || *dirname == &#39;\0&#39;) { printf("Usage: rmdir <directory-name>\n"); return; } FileNode* target = find_child(state->current_dir, dirname); if (!target) { printf("Directory not found: %s\n", dirname); return; } if (target->type != DIRECTORY_TYPE) { printf("Not a directory: %s\n", dirname); return; } if (target->child_count > 0) { printf("Directory not empty: %s\n", dirname); return; } remove_child(state->current_dir, dirname); printf("Removed directory: %s\n", dirname); } void edit_command(SystemState* state, const char* filename) { if (!filename || *filename == &#39;\0&#39;) { printf("Usage: edit <filename>\n"); return; } FileNode* existing = find_child(state->current_dir, filename); if (existing) { if (existing->type == DIRECTORY_TYPE) { printf("Cannot edit directory: %s\n", filename); return; } printf("File already exists. Overwrite? (y/n) "); int c = getchar(); if (tolower(c) != &#39;y&#39;) { while ((c = getchar()) != &#39;\n&#39; && c != EOF); return; } remove_child(state->current_dir, filename); } int block = find_free_block(state); if (block == -1) { printf("No free disk space\n"); return; } FileNode* new_file = create_node(filename, FILE_TYPE); if (!new_file) { state->mfd.bitmap[block / 8] &= ~(1 << (block % 8)); printf("Memory allocation failed\n"); return; } new_file->start_block = block; new_file->size = BLOCK_SIZE; add_child(state->current_dir, new_file); printf("Created file: %s (block %d)\n", filename, block); } void delfile_command(SystemState* state, const char* filename) { if (!filename || *filename == &#39;\0&#39;) { printf("Usage: delfile <filename>\n"); return; } FileNode* target = find_child(state->current_dir, filename); if (!target) { printf("File not found: %s\n", filename); return; } if (target->type != FILE_TYPE) { printf("Not a file: %s\n", filename); return; } if (target->start_block != -1) { state->mfd.bitmap[target->start_block / 8] &= ~(1 << (target->start_block % 8)); } remove_child(state->current_dir, filename); printf("Deleted file: %s\n", filename); } /********************* * 主程序 *********************/ int main() { SystemState state = {0}; init_filesystem(&state); char input[MAX_CMD_LEN]; char cmd[MAX_NAME_LEN]; char arg[MAX_NAME_LEN]; show_help(); while (true) { printf("\n%s:%s> ", state.current_user, state.current_dir->name); if (!fgets(input, MAX_CMD_LEN, stdin)) break; int args = sscanf(input, "%255s %255s", cmd, arg); if (args == 0) continue; if (strcmp(cmd, "login") == 0) { printf(login(&state) ? "Login successful\n" : "Login failed\n"); } else if (strcmp(cmd, "cd") == 0) { cd_command(&state, args >= 2 ? arg : NULL); } else if (strcmp(cmd, "dir") == 0) { dir_command(&state, args >= 2 ? arg : NULL); } else if (strcmp(cmd, "mkdir") == 0 && args >= 2) { mkdir_command(&state, arg); } else if (strcmp(cmd, "rmdir") == 0 && args >= 2) { rmdir_command(&state, arg); } else if (strcmp(cmd, "edit") == 0 && args >= 2) { edit_command(&state, arg); } else if (strcmp(cmd, "delfile") == 0 && args >= 2) { delfile_command(&state, arg); } else if (strcmp(cmd, "exit") == 0) { printf("Exiting system...\n"); break; } else { printf("Unknown command: %s\n", cmd); show_help(); } } cleanup_filesystem(&state); return 0; } void show_help(void) { printf("\nAvailable commands:\n"); printf("login - User login\n"); printf("cd [path] - Change directory\n"); printf("dir [path] - List directory contents\n"); printf("mkdir <dir> - Create directory\n"); printf("rmdir <dir> - Remove empty directory\n"); printf("edit <file> - Create/edit file\n"); printf("delfile <file> - Delete file\n"); printf("exit - Exit system\n"); } main函数中调用了cd_command和dir_command,且之前声明过这两个函数,但是没有提供这两个函数的实际实现,帮我实现这两个函数。给出修改后的代码
05-28
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值