📄 diskdata_distribution.c
字号:
#include <stdio.h>#include <stdlib.h>#include <sys/types.h>#include <ustat.h>#include <sys/stat.h>#include <fcntl.h>#include <unistd.h>#define BUFFERSZE (64*512)int main(void){ int file = 0, exit_wait, disk = 0, i = 0; char buffer[10] = {0}; char disk_buffer[BUFFERSZE] = {0}, *disk_buf_pointer; char char_separate; struct stat stat_buf; struct ustat ustat_buf; disk_buf_pointer = disk_buffer; file = open("test.txt", O_RDONLY); disk = open("/dev/rdsk/c1d0s0", O_RDONLY); printf("The file descriptor returned is %d\n", file); printf("The disk device returned is %d\n", disk); if ((file == -1)||(disk == -1)) { printf("The file opening failed. File is %d, disk is %d\n", file, disk); exit(0); } if (fstat(file, &stat_buf) == -1) { printf("The function fstat error.\n"); exit(0); } printf("The Inode number of file test.txt is %d\n", stat_buf.st_ino); printf("The device number is %x\n", stat_buf.st_dev); if (ustat(stat_buf.st_dev, &ustat_buf) == -1) { printf("The function ufstat error.\n"); exit(0); } printf("The file system name is %s\n", ustat_buf.f_fname); read(file, (void*)buffer, 9); read(disk, (void*)disk_buf_pointer, BUFFERSZE); for (; i < BUFFERSZE; i++) { if (!(i % 16)) putchar('\n'); if (!(i % 512)) printf("====================================================================\n"); char_separate = disk_buffer[i]; printf("%2x %c\t", char_separate, char_separate); } putchar('\n'); (char *)buffer [9] = 0; printf("The data read from the file is %s\n", buffer); //scanf("%d", &exit_wait); close (disk); close (file); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -