[20161111File Space Bitmap Block修复机制

本文详细探讨了Oracle数据库中FileSpaceBitmapBlock的修复机制。通过实验验证了当位图区被全部设置为1后,如何通过dbms_space_admin.TABLESPACE_REBUILD_BITMAPS过程进行修复。文章还分析了修复过程中涉及的后台操作和技术细节。

[20161111]File Space Bitmap Block修复机制.txt

--前几天在测试File Space Bitmap Block时执行了,execute dbms_space_admin.TABLESPACE_REBUILD_BITMAPS('SUGAR')
--这样位图区全部设置为1,显示都是F。它的修复机制不是非常清楚,今天做一些深入的探究。

--继续重复昨天的测试。

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> execute dbms_space_admin.tablespace_dump_bitmaps('SUGAR');
PL/SQL procedure successfully completed.

Header Control:
RelFno: 6, Unit: 8, Size: 5120, Flag: 9
AutoExtend: YES, Increment: 2048, MaxSize: 4194302
Initial Area: 126, Tail: 5119, First: 400, Free: 224
Deallocation scn: 925704.0
Header Opcode:
Save: No Pending Op
File Space Bitmap Block:
BitMap Control:
RelFno: 6, BeginBlock: 128, Flag: 0, First: 400, Free: 63088
FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF FFFF000000000000 0000000000000000
0000000000000000 0000000000000000 0000000000000000 0000000000000000
0000000000000000 0000000000000000 0000000000000000 0000000000000000
0000000000000000 0000000000000000 0000000000000000 0000000000000000
0000000000000000 0000000000000000 0000000000000000 0000000000000000

$ bvi -b 24576 -s 8192 /mnt/ramdisk/book/sugar01.dbf
00006000  1E A2 00 00 03 00 80 01 25 DC 5F 00 00 00 01 04 5B B1 00 00 06 00 00 00 80 00 00 00 00 00 00 00 ........%._.....[...............
00006020  90 01 00 00 70 F6 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 ....p...........................
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 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................................
00006080  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................................
000060A0  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................................
000060C0  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................................

-- 偏移 60 后仅仅 10个 FF。

--关闭数据库重新启动,并且dba 6,3 全部FF变为00.注意其他不动,注意要重新计算检查和。

BBED> sum
Check value for File 6, Block 3:
current = 0xb15b, required = 0x4ea4

BBED> sum apply dba 6,3
Warning: contents of previous BIFILE will be lost. Proceed? (Y/N) y
Check value for File 6, Block 3:
current = 0x4ea4, required = 0x4ea4

--启动数据库。
SYS@book> @ &r/bh 6 3
no rows selected

--可以发现现在该数据块没有在数据缓存中。

3.分析执行过程:

SYS@book> @ &r/spid

       SID    SERIAL# SPID       PID  P_SERIAL# C50
---------- ---------- ------ ------- ---------- --------------------------------------------------
       232          7 5574        21          4 alter system kill session '232,7' immediate;


--打开另外终端执行:
$ strace -f -p 5574 -o /tmp/map.txt

--切换回去:
SYS@book> execute dbms_space_admin.TABLESPACE_REBUILD_BITMAPS('SUGAR');
PL/SQL procedure successfully completed.

$ bvi -b 24576 -s 8192 /mnt/ramdisk/book/sugar01.dbf
00006000  1E A2 00 00 03 00 80 01 B7 D6 5F 00 00 00 02 04 44 41 00 00 06 00 00 00 80 00 00 00 00 00 00 00 .........._.....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 ................................
00006280  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 ................................
000062A0  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 ................................
000062C0  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 ................................
000062E0  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 ................................

--你可以发现数据文件的位图区块里面全是F。表示已经使用,而实际上你检查对应的内存块:

SYS@book> @ &r/bh 6 3
HLADDR              DBARFIL     DBABLK      CLASS CLASS_TYPE         STATE             TCH CR_SCN_BAS CR_SCN_WRP CR_UBA_FIL CR_UBA_BLK CR_UBA_SEQ BA               OBJECT_NAME
---------------- ---------- ---------- ---------- ------------------ ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------------- --------------------
0000000084B84748          6          3         12 bitmap index block free                0          0          0          0          0          0 00000000756A8000
0000000084B84748          6          3         12 bitmap index block xcur                1          0          0          0          0          0 00000000756AA000

--STATE=xcur BA=00000000756AA000
--你可以发现FF从32+24=56 开始,56 = 0x38

SYS@book> oradebug setmypid
Statement processed.

SYS@book> oradebug peek 0x00000000756AA000 16
[0756AA000, 0756AA010) = 0000A21E 01800003 005FDC25 00010000

--00006000  1E A2 00 00 03 00 80 01 B7 D6 5F 00 00 00 02 04 44 41 00 00 06 00 00 00 80 00 00 00 00 00 00 00 .........._.....DA..............
                        ~~~~~~~~~~~
--大小头对调可以发现的dba地址一致。

SYS@book> oradebug peek 0x00000000756AA038 16
[0756AA038, 0756AA048) = FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF
--全是FF

SYS@book> oradebug peek 0x00000000756AA060 16
[0756AA060, 0756AA070) = FFFFFFFF FFFFFFFF 0000FFFF 00000000

SYS@book> oradebug peek 0x00000000756AA100 16
[0756AA100, 0756AA110) = 00000000 00000000 00000000 00000000

--而偏移量0x100= 256,全都是00.也就是内存中的数据块是正确,由此可以推出他的恢复机制,先修改数据块设置FF,读取到缓存中然
--后扫描分析数据块,在内存数据块中标识那些块使用了。

--如果你发出alter system checkpoint,这样内存的信息写到数据文件中,结果就是正确的。

SYS@book> alter system checkpoint;
System altered.

SYS@book> @ &r/bh 6 3
old  23:   dbarfil = &1 and
new  23:   dbarfil = 6 and
old  24:   dbablk = &2
new  24:   dbablk = 3
HLADDR              DBARFIL     DBABLK      CLASS CLASS_TYPE         STATE             TCH CR_SCN_BAS CR_SCN_WRP CR_UBA_FIL CR_UBA_BLK CR_UBA_SEQ BA               OBJECT_NAME
---------------- ---------- ---------- ---------- ------------------ ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------------- --------------------
0000000084B84748          6          3         12 bitmap index block free                0          0          0          0          0          0 00000000756A8000
0000000084B84748          6          3         12 bitmap index block xcur                1          0          0          0          0          0 00000000756AA000

$ bvi -b 24576 -s 8192 /mnt/ramdisk/book/sugar01.dbf
00006000  1E A2 00 00 03 00 80 01 25 DC 5F 00 00 00 01 04 5B B1 00 00 06 00 00 00 80 00 00 00 00 00 00 00 ........%._.....[...............
00006020  90 01 00 00 70 F6 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 ....p...........................
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 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................................
00006080  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................................
000060A0  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................................
000060C0  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................................
000060E0  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................................

--可以发现已经修复了。根本不需要担心开始全部写入FF,标识全部使用,实际上内存对应的数据块是正确的。

4.深入分析:

--检查跟踪文件
# ls -l /proc/5574/fd
total 0
lr-x------ 1 oracle oinstall 64 2016-11-11 10:52:23 0 -> /dev/null
l-wx------ 1 oracle oinstall 64 2016-11-11 10:52:23 1 -> /dev/null
l-wx------ 1 oracle oinstall 64 2016-11-11 10:52:23 12 -> pipe:[19152388]
l-wx------ 1 oracle oinstall 64 2016-11-11 10:52:23 2 -> /dev/null
lrwx------ 1 oracle oinstall 64 2016-11-11 10:54:01 256 -> /mnt/ramdisk/book/sugar01.dbf
lrwx------ 1 oracle oinstall 64 2016-11-11 10:54:01 258 -> /mnt/ramdisk/book/system01.dbf
lr-x------ 1 oracle oinstall 64 2016-11-11 10:52:23 3 -> /dev/null
lr-x------ 1 oracle oinstall 64 2016-11-11 10:52:23 4 -> /u01/app/oracle/product/11.2.0.4/dbhome_1/rdbms/mesg/oraus.msb
lr-x------ 1 oracle oinstall 64 2016-11-11 10:52:23 5 -> /proc/5574/fd
lr-x------ 1 oracle oinstall 64 2016-11-11 10:52:23 6 -> /dev/zero
lrwx------ 1 oracle oinstall 64 2016-11-11 10:52:23 7 -> /u01/app/oracle/admin/book/adump/book_ora_5574_20161111105146035812143795.aud
lr-x------ 1 oracle oinstall 64 2016-11-11 10:52:23 9 -> pipe:[19152387]

$ grep write /tmp/map.txt
5197  write(12, "\0\265\0\0\6\0\0\0\0\0\10\6\0\274\333_\0\0\0\0\0\10\0\0\0\0\0\0\0\0\0\0"..., 181) = 181
5197  write(12, "\0\21\0\0\6\0\0\0\0\0\t\1\0\0\0\0\0", 17) = 17
--写很少,不知道什么回事。

$ grep pread /tmp/map.txt
5197  pread(258, "\6\242\0\0008\17@\0\271v\16\0\0\0\1\6v\225\0\0\1\0\0\0\10\0\0\0\270v\16\0"..., 32768, 31916032) = 32768
5197  pread(258, "\6\242\0\0\363\26@\0\2544\0\0\0\0\2\4\36\202\0\0\1\0\0\0\10\0\0\0\2544\0\0"..., 24576, 48128000) = 24576
5197  pread(258, "\6\242\0\0\361\35@\0\353@\0\0\0\0\2\4\r\301\0\0\1\0\0\0\10\0\0\0\353@\0\0"..., 8192, 62791680) = 8192
5197  pread(258, "\6\242\0\0s5@\0\231@\3\0\0\0\3\4\211\305\0\0\1\0\6\0\10\0\0\0\231@\3\0"..., 8192, 112091136) = 8192
5197  pread(258, "\6\242\0\0u5@\0\255\266\1\0\0\0\1\6\215\221\0\0\1\0\0\0\10\0\0\0\237\266\1\0"..., 16384, 112107520) = 16384
5197  pread(258, "\6\242\0\0pm@\0\313\327\2\0\0\0\1\6\205_\0\0\1\0 \0\10\0\0\0x\327\2\0"..., 8192, 229507072) = 8192
5197  pread(258, "\6\242\0\0rm@\0\261\341\2\0\0\0\1\6\317}\0\0\1\0\24\0\10\0\0\0006\341\2\0"..., 8192, 229523456) = 8192
5197  pread(258, "\6\242\0\0\246!A\0r+\16\0\0\0\1\6F\323\0\0\1\0\33\0\10\0\0\0\274*\16\0"..., 8192, 607436800) = 8192
5197  pread(258, "\6\242\0\0\252!A\0\223\26\17\0\0\0\1\6s\322\0\0\1\0@\0\10\0\0\0\222\26\17\0"..., 8192, 607469568) = 8192
5197  pread(258, "\6\242\0\0\254!A\0\264m\16\0\0\0\2\4k\6\0\0\1\0@\0\10\0\0\0\264m\16\0"..., 40960, 607485952) = 40960
5197  pread(263, "#\242\0\0\202\0\200\1-\320_\0\0\0\1\4\321\361\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 8192, 1064960) = 8192
5197  pread(263, "#\242\0\0\2\3\200\1v\320_\0\0\0\1\4\322\361\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 8192, 6307840) = 8192
5197  pread(263, "#\242\0\0\2\10\200\1\270\320_\0\0\0\1\4\321\361\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 8192, 16793600) = 8192
5197  pread(258, "\6\242\0\0\265!A\0l\224\16\0\0\0\3\0040\324\0\0\1\0\0\0\10\0\0\0l\224\16\0"..., 16384, 607559680) = 16384
5197  pread(263, "#\242\0\0\202\0\200\1-\320_\0\0\0\1\4\321\361\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 8192, 1064960) = 8192
5197  pread(258, "\6\242\0\0\36\v@\0\244\"\3\0\0\0\1\6\322\333\0\0\1\0\0\0\274\1\0\0\241\"\3\0"..., 8192, 23314432) = 8192
5197  pread(258, "\6\242\0\0\37\v@\0\244\"\3\0\0\0\1\6A\301\0\0\1\0\0\0\274\1\0\0\242\"\3\0"..., 8192, 23322624) = 8192
5197  pread(258, "\6\242\0\0\305\3@\0\2228\17\0\0\0\1\6\211+\0\0\2\0\0\0y\0\0\0\2168\17\0"..., 8192, 7905280) = 8192
5197  pread(258, "\6\242\0\0\253\3@\0\2228\17\0\0\0\1\6\375\316\0\0\1\0\36\0v\0\0\0\2168\17\0"..., 8192, 7692288) = 8192
5197  pread(263, "#\242\0\0\2\3\200\1v\320_\0\0\0\1\4\322\361\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 8192, 6307840) = 8192
5197  pread(263, "#\242\0\0\2\10\200\1\270\320_\0\0\0\1\4\321\361\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 8192, 16793600) = 8192

--先分析263句柄的情况:
$ grep pread /tmp/map.txt | grep '263,'
5197  pread(263, "#\242\0\0\202\0\200\1-\320_\0\0\0\1\4\321\361\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 8192, 1064960) = 8192
5197  pread(263, "#\242\0\0\2\3\200\1v\320_\0\0\0\1\4\322\361\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 8192, 6307840) = 8192
5197  pread(263, "#\242\0\0\2\10\200\1\270\320_\0\0\0\1\4\321\361\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 8192, 16793600) = 8192
5197  pread(263, "#\242\0\0\202\0\200\1-\320_\0\0\0\1\4\321\361\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 8192, 1064960) = 8192
5197  pread(263, "#\242\0\0\2\3\200\1v\320_\0\0\0\1\4\322\361\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 8192, 6307840) = 8192
5197  pread(263, "#\242\0\0\2\10\200\1\270\320_\0\0\0\1\4\321\361\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 8192, 16793600) = 8192

--1064960/8192=130
--6307840/8192=770
--16793600/8192=2050

SYS@book> select segment_name,header_file,header_block from dba_segments where owner='SCOTT' and header_file=6;
SEGMENT_NAME         HEADER_FILE HEADER_BLOCK
-------------------- ----------- ------------
T3                             6         2050
T2                             6          770
T1                             6          130

--正好是表T1,T2,T3的块头。也就是通过扫描表头,确定那些段使用了,回填位图区的信息。

5.做一个极端测试:

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

SYS@book> shutdown abort
ORACLE instance shut down.

$ bvi -b 24576 -s 8192 /mnt/ramdisk/book/sugar01.dbf
00006000  1E A2 00 00 03 00 80 01 32 F5 5F 00 00 00 02 04 44 41 00 00 06 00 00 00 80 00 00 00 00 00 00 00 ........2._.....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 ................................

--可以发现是FF。然后重新启动数据库到mount状态。

SYS@book> startup mount
ORACLE instance started.

Total System Global Area  634732544 bytes
Fixed Size                  2255792 bytes
Variable Size             197133392 bytes
Database Buffers          427819008 bytes
Redo Buffers                7524352 bytes
Database mounted.

RMAN> backup datafile 6 format '/u01/backup/d6_1.bak' ;
Starting backup at 2016-11-11 11:11:08
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=1 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00006 name=/mnt/ramdisk/book/sugar01.dbf
channel ORA_DISK_1: starting piece 1 at 2016-11-11 11:11:09
channel ORA_DISK_1: finished piece 1 at 2016-11-11 11:11:10
piece handle=/u01/backup/d6_1.bak tag=TAG20161111T111109 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2016-11-11 11:11:10

$ ls -l /u01/backup/d6_1.bak
-rw-r----- 1 oracle oinstall 26066944 2016-11-11 11:11:09 /u01/backup/d6_1.bak

$ ls -lh /u01/backup/d6_1.bak
-rw-r----- 1 oracle oinstall 25M 2016-11-11 11:11:09 /u01/backup/d6_1.bak

--大小26066944/1024/1024=24.859375M,可以发现备份并不依赖这个位图区扫描。

SYS@book> alter database open ;
Database altered.

SYS@book> @ &r/bh 6 3
HLADDR              DBARFIL     DBABLK      CLASS CLASS_TYPE         STATE             TCH CR_SCN_BAS CR_SCN_WRP CR_UBA_FIL CR_UBA_BLK CR_UBA_SEQ BA               OBJECT_NAME
---------------- ---------- ---------- ---------- ------------------ ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------------- --------------------
0000000084B84748          6          3         12 bitmap index block xcur                0          0          0          0          0          0 000000007A3C4000

SYS@book> alter system checkpoint;
System altered.

00006000  1E A2 00 00 03 00 80 01 32 F5 5F 00 00 00 02 04 44 41 00 00 06 00 00 00 80 00 00 00 00 00 00 00 ........2._.....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 ................................
--可以发现并没有修复位图区。

SYS@book> alter system checkpoint;
System altered.

SYS@book> oradebug setmypid
Statement processed.

SYS@book> oradebug peek 0x000000007A3C4100 16
[07A3C4100, 07A3C4110) = FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF

--从这里看也可以证明没有修复。

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

--建表发现错误。

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

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

--OK,现在建表成功。

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                   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
...
SCOTT  T4           TABLE        SUGAR                   17          6       3584    1048576        128            6
SCOTT  T4           TABLE        SUGAR                   18          6       3712    1048576        128            6
SCOTT  T4           TABLE        SUGAR                   19          6       3840    1048576        128            6
45 rows selected.

--t3,T4的空间是连续的。

--看来做后台数据维护最大的敌人是死机或者掉电。

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/267265/viewspace-2128290/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/267265/viewspace-2128290/

题目:本设计使用C语言模拟一个单用户的二级文件管理系统,支持文件与目录的创建、删除、读写等操作,并实现文件的物理存储与目录管理。 实现要求: (1)在磁盘上建立一个文件模拟磁盘分区。 (2)空闲空间管理可使用位示图,存储分配可采用链接等方法。 (3)支持一级或二级目录结构,每项含文件名、地址、长度等。 (4)支持命令操作:login、dir、create、delete、open、close、read、write、exit (5)可扩展实现文件夹的增删功能(可部分实现) #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX_BLOCKS 1024 // 磁盘总块数 #define BLOCK_SIZE 512 // 块大小 #define DISK_FILE "disk.bin"// 虚拟磁盘文件名 #define MAX_FILES 100 // 最大文件数 #define MAX_OPEN_FILES 10 // 最多打开文件数 // 文件控制块 FCB typedef struct { char name[64]; // 文件名 int start_block; // 起始块号 int length; // 占用块数 } FileControlBlock; // 全局变量 FileControlBlock root_dir[MAX_FILES]; // 根目录表 int bitmap[MAX_BLOCKS] = {0}; // 位示图 FILE *disk_file; // 磁盘文件指针 int logged_in = 0; // 登录状态 int open_files[MAX_OPEN_FILES][2]; // [fd][index, pos] // 初始化磁盘 void init_disk() { disk_file = fopen(DISK_FILE, "rb+"); if (!disk_file) { disk_file = fopen(DISK_FILE, "wb+"); char zero[BLOCK_SIZE] = {0}; for (int i = 0; i < MAX_BLOCKS; ++i) fwrite(zero, BLOCK_SIZE, 1, disk_file); } } // 初始化根目录 void init_root_directory() { for (int i = 0; i < MAX_FILES; ++i) { root_dir[i].name[0] = '\0'; root_dir[i].start_block = -1; root_dir[i].length = 0; } for (int i = 0; i < MAX_OPEN_FILES; ++i) open_files[i][0] = open_files[i][1] = -1; } // 读取一个块 void read_block(int block_num, void* buffer) { fseek(disk_file, block_num * BLOCK_SIZE, SEEK_SET); fread(buffer, BLOCK_SIZE, 1, disk_file); } // 写入一个块 void write_block(int block_num, const void* buffer) { fseek(disk_file, block_num * BLOCK_SIZE, SEEK_SET); fwrite(buffer, BLOCK_SIZE, 1, disk_file); } // 分配一个空闲块 int allocate_block() { for (int i = 0; i < MAX_BLOCKS; ++i) { if (!bitmap[i]) { bitmap[i] = 1; return i; } } return -1; } // 释放一个块 void free_block(int block_num) { if (block_num >= 0 && block_num < MAX_BLOCKS) bitmap[block_num] = 0; } // 查找文件是否存在 int find_file(const char* filename) { for (int i = 0; i < MAX_FILES; ++i) { if (root_dir[i].start_block != -1 && strcmp(root_dir[i].name, filename) == 0) return i; } return -1; } // 获取一个可用的 fd int get_free_fd() { for (int i = 0; i < MAX_OPEN_FILES; ++i) if (open_files[i][0] == -1) return i; return -1; } // login 命令 void cmd_login() { if (logged_in) { printf("Already logged in.\n"); return; } printf("Login successful.\n"); logged_in = 1; } // dir 命令 void cmd_dir() { if (!logged_in) { printf("Please login first.\n"); return; } printf("Directory:\n"); for (int i = 0; i < MAX_FILES; ++i) { if (root_dir[i].start_block != -1 && root_dir[i].name[0] != '\0') printf("- %s (%d blocks)\n", root_dir[i].name, root_dir[i].length); } } // create 命令 void cmd_create(const char* filename) { if (!logged_in) { printf("Please login first.\n"); return; } if (find_file(filename) != -1) { printf("File already exists.\n"); return; } int index = -1; for (int i = 0; i < MAX_FILES; ++i) { if (root_dir[i].start_block == -1) { index = i; break; } } if (index == -1) { printf("Directory full.\n"); return; } int block = allocate_block(); if (block == -1) { printf("Disk full.\n"); return; } strcpy(root_dir[index].name, filename); root_dir[index].start_block = block; root_dir[index].length = 1; char zero[BLOCK_SIZE] = {0}; write_block(block, zero); printf("File created: %s\n", filename); } // delete 命令 void cmd_delete(const char* filename) { if (!logged_in) { printf("Please login first.\n"); return; } int index = find_file(filename); if (index == -1) { printf("File not found.\n"); return; } FileControlBlock fcb = root_dir[index]; for (int i = 0; i < fcb.length; ++i) free_block(fcb.start_block + i); root_dir[index].start_block = -1; root_dir[index].length = 0; root_dir[index].name[0] = '\0'; printf("File deleted: %s\n", filename); } // open 命令 void cmd_open(const char* filename) { if (!logged_in) { printf("Please login first.\n"); return; } int index = find_file(filename); if (index == -1) { printf("File not found.\n"); return; } int fd = get_free_fd(); if (fd == -1) { printf("Too many open files.\n"); return; } open_files[fd][0] = index; open_files[fd][1] = 0; printf("File opened with fd=%d\n", fd); } // close 命令 void cmd_close(int fd) { if (fd < 0 || fd >= MAX_OPEN_FILES || open_files[fd][0] == -1) { printf("Invalid file descriptor.\n"); return; } open_files[fd][0] = -1; printf("File closed.\n"); } // seek 命令 void cmd_seek(int fd, int offset) { if (fd < 0 || fd >= MAX_OPEN_FILES || open_files[fd][0] == -1) { printf("Invalid file descriptor.\n"); return; } open_files[fd][1] = offset; printf("File pointer set to %d\n", offset); } // read 命令 void cmd_read(int fd, int size) { if (fd < 0 || fd >= MAX_OPEN_FILES || open_files[fd][0] == -1) { printf("Invalid file descriptor.\n"); return; } int index = open_files[fd][0]; int pos = open_files[fd][1]; FileControlBlock fcb = root_dir[index]; char result[size + 1]; memset(result, 0, sizeof(result)); int total_read = 0; int current_block = pos / BLOCK_SIZE; int offset = pos % BLOCK_SIZE; while (total_read < size && current_block < fcb.length) { char buffer[BLOCK_SIZE]; read_block(fcb.start_block + current_block, buffer); int available = BLOCK_SIZE - offset; int to_copy = (available < size - total_read) ? available : (size - total_read); memcpy(result + total_read, buffer + offset, to_copy); total_read += to_copy; current_block++; offset = 0; } result[total_read] = '\0'; open_files[fd][1] = pos + total_read; printf("Read: %s\n", result); } // write 命令 void cmd_write(int fd, const char* data) { if (fd < 0 || fd >= MAX_OPEN_FILES || open_files[fd][0] == -1) { printf("Invalid file descriptor.\n"); return; } int index = open_files[fd][0]; int pos = open_files[fd][1]; FileControlBlock* fcb = &root_dir[index]; int len = strlen(data); int written = 0; while (written < len) { int block_index = pos / BLOCK_SIZE; int offset = pos % BLOCK_SIZE; if (block_index >= fcb->length) { int new_block = allocate_block(); if (new_block == -1) { printf("Disk full. Cannot write more.\n"); break; } fcb->length++; write_block(new_block, "\0\0\0"); } char buffer[BLOCK_SIZE]; int block = fcb->start_block + block_index; read_block(block, buffer); int space = BLOCK_SIZE - offset; int to_write = (len - written < space) ? len - written : space; memcpy(buffer + offset, data + written, to_write); write_block(block, buffer); written += to_write; pos += to_write; } open_files[fd][1] = pos; printf("Written %d bytes.\n", written); } // 主函数 int main() { init_disk(); init_root_directory(); char line[256], cmd[64]; while (1) { printf("> "); if (!fgets(line, sizeof(line), stdin)) break; sscanf(line, "%s", cmd); if (strcmp(cmd, "login") == 0) { cmd_login(); } else if (strcmp(cmd, "dir") == 0) { cmd_dir(); } else if (strcmp(cmd, "create") == 0) { char filename[64]; sscanf(line, "%*s %s", filename); cmd_create(filename); } else if (strcmp(cmd, "delete") == 0) { char filename[64]; sscanf(line, "%*s %s", filename); cmd_delete(filename); } else if (strcmp(cmd, "open") == 0) { char filename[64]; sscanf(line, "%*s %s", filename); cmd_open(filename); } else if (strcmp(cmd, "close") == 0) { int fd; sscanf(line, "%*s %d", &fd); cmd_close(fd); } else if (strcmp(cmd, "read") == 0) { int fd, size; sscanf(line, "%*s %d %d", &fd, &size); cmd_read(fd, size); } else if (strcmp(cmd, "write") == 0) { int fd; char data[256]; sscanf(line, "%*s %d %[^\n]", &fd, data); cmd_write(fd, data); } else if (strcmp(cmd, "seek") == 0) { int fd, offset; sscanf(line, "%*s %d %d", &fd, &offset); cmd_seek(fd, offset); } else if (strcmp(cmd, "exit") == 0) { break; } else { printf("Unknown command.\n"); } } fclose(disk_file); return 0; } 这段代码的运行结果如下 > login Login successful. > create a.txt File created: a.txt > open a.txt File opened with fd=0 > write 0 1 Written 1 bytes. > read 0 1 Read: > delete a.txt File deleted: a.txt > 请修复代码中的错误
05-27
#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] = '\0'; 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")] = '\0'; printf("Password: "); if (!fgets(password, MAX_NAME_LEN, stdin)) return false; password[strcspn(password, "\n")] = '\0'; 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 == '\0') { 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 == '\0') { 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 == '\0') { 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) != 'y') { while ((c = getchar()) != '\n' && 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 == '\0') { 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
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值