设为首页收藏本站邀请注册
开启左侧

[暑假补课]OS第四次实验资料-文件系统验证

[复制链接]
1688 43
这次是个验证性的实验,PPT里有详细的步骤了~
哦。。对了。。有个能实现实验步骤的程序老师似乎木有给。
游客,如果您要查看本帖隐藏内容请回复
已有3人评分学分 理由
service + 6
紫凝雪儿 + 6
admin + 6 感谢您为软院筒子们提供有用信息!

查看全部评分 总评分:学分 +18 

举报 使用道具

回复 论坛版权

43 个评论

小木公  【荣耀黄金I】  发表于 2012-8-15 20:45:50  | 显示全部楼层
本帖最后由 小木公 于 2012-8-15 20:47 编辑

代码在此-opengroup
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <linux/ext2_fs.h>

#define BASE_OFFSET 1024
#define USB_DEVICE "/dev/sda1"
#define BLOCK_OFFSET(block) (BASE_OFFSET + (block - 1) * block_size)
#define FILTER_BIT(byte, i) ((byte >> i) & 0x01)

static unsigned int block_size = 0;

/*
* Please IMPLEMENT THIS: this function will print out a portion of the group
* descriptor pointed to by group to the console. This function is called in
* open_usb with the first group descriptor.
*/
void print_group_desc(struct ext2_group_desc* group);

/*
* The actual function to open and read raw bytes off the USB stick.
* Takes a pointer to a superblock structure, fills it with the bytes
* from the USB drive and returns the file descriptor (which is actually
* just an int)
*/
int open_usb(struct ext2_super_block* super);



int main(void){
  struct ext2_super_block usb_block;
  int file_descriptor;

  file_descriptor = open_usb(&usb_block);

  return 0;
}

/*
* Implement this function.
*/
void print_group_desc(struct ext2_group_desc* group){

  /*
   * Print out: blocks bitmap block, inodes bitmap block, inodes table block,
   * free blocks count, free inodes count, and the directories count. Your
   * output should be "<field>\t:<value>\n".
   */
}

int open_usb(struct ext2_super_block* super){
  int fd;
  struct ext2_group_desc* group = malloc(sizeof(struct ext2_group_desc));

  /* open USB device */
  fd = open(USB_DEVICE, O_RDONLY); //opening the device for reading
  if(fd < 0){ //some kind of error occurred
    perror(USB_DEVICE);
    exit(1); //we give up at this point
  }

  /* Now we read in Mr. Superblock */
  /* seeking across the 'disk' to the superblock location */
  lseek(fd, BASE_OFFSET, SEEK_SET);
  /*actually reading in the bytes */
  read(fd, super, sizeof(struct ext2_super_block));

  /* Some sanity checks */
  /* Make sure we're reading an EXT2 filesystem */
  if(super->s_magic != EXT2_SUPER_MAGIC){
    fprintf(stderr, "Not an Ext2 filesystem!\n");
    exit(1);
  }

  block_size = 1024 << super->s_log_block_size;

  /*Now on to reading the group descriptors */
  int num_groups =
        (super->s_blocks_count + super->s_blocks_per_group - 1) /
                super->s_blocks_per_group;

  /* seek to the first descriptor */
  lseek(fd,
        BASE_OFFSET + block_size,
        SEEK_SET);
  /* read it in */
  read(fd, group, sizeof(struct ext2_group_desc));
  /* print it! */
  print_group_desc(group);

  /* closing the USB device */
  close(fd);

  return fd;
}
已有2人评分学分 理由
紫凝雪儿 + 12 感谢您为软院筒子们提供有用信息!
callmesb + 9 感谢您为软院筒子们提供有用信息!

查看全部评分 总评分:学分 +21 

小木公  【荣耀黄金I】  发表于 2012-8-15 20:49:05  | 显示全部楼层
opensuper
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <linux/ext2_fs.h>

#define BASE_OFFSET 1024
#define USB_DEVICE "/dev/sda1"
#define BLOCK_OFFSET(block) (BASE_OFFSET + (block - 1) * block_size)
#define FILTER_BIT(byte, i) ((byte >> i) & 0x01)

static unsigned int block_size = 0;

/*
* Please IMPLEMENT THIS! This function will print out a portion of the
* superblock to the console. It is called in main after reading in the super
* block from the disk.
*/
void print_super_block(struct ext2_super_block* super);

/*
* The actual function to open and read raw bytes off the USB stick.
* Takes a pointer to a superblock structure, fills it with the bytes
* from the USB drive and returns the file descriptor (which is actually
* just an int)
*/
int open_usb(struct ext2_super_block* super);

int main(void){
  struct ext2_super_block usb_block;
  int file_descriptor;

  file_descriptor = open_usb(&usb_block);
  print_super_block(&usb_block);

  return 0;
}

/*
* Implement this method!
*/
void print_super_block(struct ext2_super_block* super){

  /*
   * Print out the inodes count, blocks count, free blocks count, free inodes
   * count, the first data block, block size, blocks per group, inodes per
   * group, and the size of the inode structure. The output should be
   * "<field>\t:<value>\n".
   */
}

int open_usb(struct ext2_super_block* super){
  int fd;
  struct ext2_group_desc* group = malloc(sizeof(struct ext2_group_desc));

  /* open USB device */
  fd = open(USB_DEVICE, O_RDONLY); //opening the device for reading
  if(fd < 0){ //some kind of error occurred
    perror(USB_DEVICE);
    exit(1); //we give up at this point
  }

  /* Now we read in Mr. Superblock */
  /* seeking across the 'disk' to the superblock location */
  lseek(fd, BASE_OFFSET, SEEK_SET);
  /*actually reading in the bytes */
  read(fd, super, sizeof(struct ext2_super_block));

  /* Some sanity checks */
  /* Make sure we're reading an EXT2 filesystem */
  if(super->s_magic != EXT2_SUPER_MAGIC){
    fprintf(stderr, "Not an Ext2 filesystem!\n");
    exit(1);
  }

  block_size = 1024 << super->s_log_block_size;

  /* closing the USB device */
  close(fd);

  return fd;
}
P.S.去年的代码,需要略作修改~
admin  管理员 Lv.23  发表于 2012-8-15 20:28:24  | 显示全部楼层
没补课的同学可以参考~
小木公  【荣耀黄金I】  发表于 2012-8-15 20:29:30  | 显示全部楼层
似乎是好东西啊
beckham467  【秩序白银I】  发表于 2012-8-15 20:29:41  | 显示全部楼层
ing........
0x710dddd  【倔强青铜I】  发表于 2012-8-15 20:32:24  来自手机  | 显示全部楼层
看看看看学习学习学习
rocklee  【荣耀黄金I】  发表于 2012-8-15 20:32:39  | 显示全部楼层
看到楼主名字,顿觉霸气侧漏。。。
sunhongbo  【永恒钻石II】  发表于 2012-8-15 20:38:24  | 显示全部楼层
顶一个,必须的。。
andylove  【荣耀黄金I】  发表于 2012-8-15 20:40:30  | 显示全部楼层
没补课的路过
刘世伟  【秩序白银II】  发表于 2012-8-15 20:49:02  | 显示全部楼层
感激不尽!
m68300981  【倔强青铜I】  发表于 2012-8-15 21:00:39  | 显示全部楼层
顶一下啊啊啊啊啊啊啊啊啊啊啊啊啊啊
冰封飞飞  【秩序白银II】  发表于 2012-8-15 21:21:55  | 显示全部楼层
学习一下~~
fghhslk  前辈版主  发表于 2012-8-15 21:59:31  | 显示全部楼层
。。。

点评

.........  详情 回复 发表于 2012-8-15 22:47
callmesb  前辈版主  发表于 2012-8-15 22:47:53  | 显示全部楼层
fghhslk 发表于 2012-8-15 21:59
。。。

.........
ngddjl  【秩序白银II】  发表于 2012-8-15 23:49:17  | 显示全部楼层
学习一下~   
镕羽  【秩序白银II】  发表于 2012-8-16 00:19:37  | 显示全部楼层
看看学习了
wkmatt  【荣耀黄金I】  发表于 2012-8-16 01:34:09  来自手机  | 显示全部楼层
木补课的瞅瞅!
来自:软院网·中科大 Android客户端来自: Android客户端
fwsir  【秩序白银II】  发表于 2012-8-16 07:05:49  | 显示全部楼层
seeeeeeeeee
tutuhuagong  【倔强青铜II】  发表于 2012-8-16 09:40:24  | 显示全部楼层
thank u for sharing.
wjx45007  【倔强青铜I】  发表于 2012-8-16 10:11:30  | 显示全部楼层
THX~
o小酒窝o  【秩序白银II】  发表于 2012-8-16 10:53:41  | 显示全部楼层
楼主辛苦啦
Miller  【尊贵铂金II】  发表于 2012-8-16 22:32:15  | 显示全部楼层
什么东东
mumufengling  【倔强青铜I】  发表于 2012-8-16 22:49:06  | 显示全部楼层
看看!谢谢楼主啦!
ssc  【秩序白银II】  发表于 2012-8-17 17:29:41  | 显示全部楼层
以前没弄过。。。。
汪晨阳189  【倔强青铜I】  发表于 2012-8-25 21:46:20  | 显示全部楼层
我来看看哦
mcoursework  【倔强青铜I】  发表于 2012-8-26 12:26:33  | 显示全部楼层
         LZ赞一个
renzhefengshen  【秩序白银II】  发表于 2012-8-29 21:40:48  | 显示全部楼层
看看啊,好好学习学习
kimitaozi  【秩序白银II】  发表于 2012-9-8 19:21:22  | 显示全部楼层
thank you!

在下鸠摩智  【荣耀黄金I】  发表于 2013-7-4 21:56:14  | 显示全部楼层
多谢楼主!

举报 使用道具

回复
sky8023  【荣耀黄金II】  发表于 2013-8-3 22:42:34  | 显示全部楼层
好东西,顶啊,谢谢
异见天空  【荣耀黄金II】  发表于 2013-8-24 23:01:11  | 显示全部楼层
撒旦法反倒是是的
leeger8580  【秩序白银II】  发表于 2013-8-24 23:40:17  | 显示全部楼层
看看是不是好东西
sxxzjm  【倔强青铜II】  发表于 2017-7-18 10:19:35  | 显示全部楼层
kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
贝壳  【倔强青铜II】  发表于 2017-7-27 07:17:15  | 显示全部楼层
看看快快快坎坎坷坷啦啦啦
来自安卓客户端来自安卓客户端
夏小乔  【倔强青铜I】  发表于 2017-8-2 20:03:17  | 显示全部楼层
顶一个。。。

举报 使用道具

回复
心如止水2017  【倔强青铜II】  发表于 2017-8-2 20:21:23  | 显示全部楼层
谢谢分享!

举报 使用道具

回复
车欠耳完  【倔强青铜II】  发表于 2017-8-2 20:49:42  | 显示全部楼层
法律程序、今年第三次
exexeet  【倔强青铜II】  发表于 2017-8-13 11:20:37  | 显示全部楼层
反反复复付付付付付付付付付付付付付付付付
Ymengchun  【秩序白银II】  发表于 2018-5-15 10:55:36  | 显示全部楼层

看看看看学习学习学习
ruanyuan  【倔强青铜II】  发表于 2018-5-28 22:48:54  | 显示全部楼层
谢谢谢谢谢谢
zch  【倔强青铜I】  发表于 2018-7-3 10:40:11  | 显示全部楼层
厉害了,路过看看
来自安卓客户端来自安卓客户端
heyang5188  【倔强青铜II】  发表于 6 天前  | 显示全部楼层
qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq
yt1997  【倔强青铜II】  发表于 5 天前  | 显示全部楼层
顶一下啦啦啦啦啦啦啦啦啦
来自安卓客户端来自安卓客户端
*滑动验证:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

2019软院考研宝典(复试篇)
科大软院那些事儿
软院网那些事儿
APP
软院网客户端
公众号
Google

图文热点

更多

社区学堂

更多

客服中心

关注我们

  • 软院网客户端
  • 关注官方微信
快速回复 返回顶部 返回列表