这次是个验证性的实验,PPT里有详细的步骤了~
哦。。对了。。有个能实现实验步骤的程序老师似乎木有给。
游客,如果您要查看本帖隐藏内容请回复

评分

参与人数 3学分 +18 收起 理由
service + 6
紫凝雪儿 + 6
admin + 6 感谢您为软院筒子们提供有用信息!

查看全部评分

共收到 43 条回复
小木公 · #9 · 2012-8-15 20:45:50  回复 支持 1 反对
本帖最后由 小木公 于 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学分 +21 收起 理由
紫凝雪儿 + 12 感谢您为软院筒子们提供有用信息!
callmesb + 9 感谢您为软院筒子们提供有用信息!

查看全部评分

小木公 · #11 · 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 · #2 · 2012-8-15 20:28:24  回复 支持 反对
没补课的同学可以参考~
小木公 · #3 · 2012-8-15 20:29:30  回复 支持 反对
似乎是好东西啊
beckham467 · #4 · 2012-8-15 20:29:41  回复 支持 反对
ing........
0x710dddd · #5 · 2012-8-15 20:32:24  回复 支持 反对
看看看看学习学习学习
rocklee · #6 · 2012-8-15 20:32:39  回复 支持 反对
看到楼主名字,顿觉霸气侧漏。。。
sunhongbo · #7 · 2012-8-15 20:38:24  回复 支持 反对
顶一个,必须的。。
andylove · #8 · 2012-8-15 20:40:30  回复 支持 反对
没补课的路过
刘世伟 · #10 · 2012-8-15 20:49:02  回复 支持 反对
感激不尽!
m68300981 · #12 · 2012-8-15 21:00:39  回复 支持 反对
顶一下啊啊啊啊啊啊啊啊啊啊啊啊啊啊
冰封飞飞 · #13 · 2012-8-15 21:21:55  回复 支持 反对
学习一下~~
fghhslk · #14 · 2012-8-15 21:59:31  回复 支持 反对
。。。

点评

.........  详情 回复 发表于 2012-8-15 22:47
callmesb · #15 · 2012-8-15 22:47:53  回复 支持 反对
fghhslk 发表于 2012-8-15 21:59
。。。

.........
ngddjl · #16 · 2012-8-15 23:49:17  回复 支持 反对
学习一下~   
镕羽 · #17 · 2012-8-16 00:19:37  回复 支持 反对
看看学习了
wkmatt · #18 · 2012-8-16 01:34:09  回复 支持 反对
木补课的瞅瞅!
来自:软院网·中科大 Android客户端来自: Android客户端
fwsir · #19 · 2012-8-16 07:05:49  回复 支持 反对
seeeeeeeeee
tutuhuagong · #20 · 2012-8-16 09:40:24  回复 支持 反对
thank u for sharing.
wjx45007 · #21 · 2012-8-16 10:11:30  回复 支持 反对
THX~
o小酒窝o · #22 · 2012-8-16 10:53:41  回复 支持 反对
楼主辛苦啦
Miller · #23 · 2012-8-16 22:32:15  回复 支持 反对
什么东东
mumufengling · #24 · 2012-8-16 22:49:06  回复 支持 反对
看看!谢谢楼主啦!
ssc · #25 · 2012-8-17 17:29:41  回复 支持 反对
以前没弄过。。。。
汪晨阳189 · #26 · 2012-8-25 21:46:20  回复 支持 反对
我来看看哦
mcoursework · #27 · 2012-8-26 12:26:33  回复 支持 反对
         LZ赞一个
renzhefengshen · #28 · 2012-8-29 21:40:48  回复 支持 反对
看看啊,好好学习学习
kimitaozi · #29 · 2012-9-8 19:21:22  回复 支持 反对
thank you!

在下鸠摩智 · #30 · 2013-7-4 21:56:14  回复
多谢楼主!
sky8023 · #31 · 2013-8-3 22:42:34  回复 支持 反对
好东西,顶啊,谢谢
异见天空 · #32 · 2013-8-24 23:01:11  回复 支持 反对
撒旦法反倒是是的
leeger8580 · #33 · 2013-8-24 23:40:17  回复 支持 反对
看看是不是好东西
sxxzjm · #34 · 2017-7-18 10:19:35  回复 支持 反对
kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
贝壳 · #35 · 2017-7-27 07:17:15  回复 支持 反对
看看快快快坎坎坷坷啦啦啦
夏小乔 · #36 · 2017-8-2 20:03:17  回复
顶一个。。。
心如止水2017 · #37 · 2017-8-2 20:21:23  回复
谢谢分享!
车欠耳完 · #38 · 2017-8-2 20:49:42  回复 支持 反对
法律程序、今年第三次
exexeet · #39 · 2017-8-13 11:20:37  回复 支持 反对
反反复复付付付付付付付付付付付付付付付付
Ymengchun · #40 · 2018-5-15 10:55:36  回复 支持 反对

看看看看学习学习学习
ruanyuan · #41 · 2018-5-28 22:48:54  回复 支持 反对
谢谢谢谢谢谢
zch · #42 · 2018-7-3 10:40:11  回复 支持 反对
厉害了,路过看看
heyang5188 · #43 · 2019-1-10 16:57:41  回复 支持 反对
qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq
yt1997 · #44 · 2019-1-11 19:34:06  回复 支持 反对
顶一下啦啦啦啦啦啦啦啦啦
回帖
B Color Image Link Quote Code Smilies
Command + Enter
快速回复 返回顶部 返回列表