简单的文件系统 [英] simple file system

查看:67
本文介绍了简单的文件系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用c编写一个简单的文件系统。它将包含512字节的
帧,并且将具有超级块等。


从外部它将在UNIX中显示为单个文件。我想

创建文件并在我写完

超级块之前先填充垃圾。


我的第一个问题是:创建文件的最佳方法是什么?用垃圾填写

吧?


谢谢


Greg

解决方案




Greg写道:

我正在写使用c的简单文件系统。它将包含512字节的
帧,并且将具有超级块等。

从外部它将在UNIX中显示为单个文件。我想在创建
超级块之前先创建文件并用垃圾填充它。

我的第一个问题是:创建文件的最佳方法是什么?用垃圾填满它?




什么样的垃圾?它是否是一些伪随机的东西或

它可能是这个

新闻组中最臭名昭着的海报或一些垃圾模式如垃圾!的垃圾邮件。或者......?


我建议你看一下来自

标准库的fopen(),fclose(),fwrite()。

OTOH,因为你想给世界一个新的文件系统,这可能是你不想做的事情。对于特定系统的快速解决方案可能需要离开标准C的领域。


IMO,如果你详细说明你的意思,那将是一件好事。最好的方式

和垃圾。

干杯

Michael

-

电子邮件:我的是一个gmx点地址。




" Greg" < DJ ********* @ snowboard.com>在消息中写道

news:7e ************************* @ posting.google.co m ... < blockquote class =post_quotes>我正在尝试使用c编写一个简单的文件系统。它将包含512字节的
帧,并且将具有超级块等。

从外部它将在UNIX中显示为单个文件。我想在创建
超级块之前先创建文件并用垃圾填充它。

我的第一个问题是:创建文件的最佳方法是什么?用垃圾填满它?


FILE *

open_garbage(const char * filename,size_t size)

{

FILE * fp = fopen(filename," w");


for(i = 0; NULL!= fp&& i< size; i ++)

{

if(EOF == fputc(random()* 0x0100 / RAND_MAX,fp))

{

fclose(fp) );

fp = NULL;

}

}


return fp;

}

谢谢




我很高兴。




" Greg" < DJ ********* @ snowboard.com>在消息中写道

news:7e ************************* @ posting.google.co m ... < blockquote class =post_quotes>我正在尝试使用c编写一个简单的文件系统。它将包含512字节的
帧,并且将具有超级块等。

从外部它将在UNIX中显示为单个文件。我想在创建
超级块之前先创建文件并用垃圾填充它。

我的第一个问题是:创建文件的最佳方法是什么?用垃圾填写它?




dd if = / dev / zero of = myfile.dat bs = 1024 count = 1024

此命令将创建1 MB文件。所有内容都为零。

你可以使用/ dev / mem作为垃圾数据或任何其他设备的输入文件u

喜欢...


-Neo


I am trying to write a simple file system using c. It will consist of
frames of 512 bytes, and will have a superblock etc.

From the outside it will appear as a single file in UNIX. I want to
create the file and fill it with garbage at first before I write the
superblock.

My first question is: what is the best way to create a file and fill
it with garbage?

Thanks

Greg

解决方案



Greg wrote:

I am trying to write a simple file system using c. It will consist of
frames of 512 bytes, and will have a superblock etc.

From the outside it will appear as a single file in UNIX. I want to
create the file and fill it with garbage at first before I write the
superblock.

My first question is: what is the best way to create a file and fill
it with garbage?



What kind of garbage? Has it to be some pseudorandom stuff or
can it be the ramblings of the most infamous posters of this
newsgroup or some garbage pattern like "Garbage!" or ...?

I would suggest a look at fopen(), fclose(), fwrite() from
the standard library.
OTOH, as you want to give the world a new file system, this may
be exactly what you don''t want to do. Fast solutions for your
specific system may necessitate leaving the realms of standard C.

IMO, it would be good if you elaborate what you mean by "best way"
and "garbage".
Cheers
Michael
--
E-Mail: Mine is a gmx dot de address.



"Greg" <dj*********@snowboard.com> wrote in message
news:7e*************************@posting.google.co m...

I am trying to write a simple file system using c. It will consist of
frames of 512 bytes, and will have a superblock etc.

From the outside it will appear as a single file in UNIX. I want to
create the file and fill it with garbage at first before I write the
superblock.

My first question is: what is the best way to create a file and fill
it with garbage?
FILE*
open_garbage(const char* filename, size_t size)
{
FILE* fp = fopen(filename, "w");

for(i=0; NULL != fp && i<size; i++)
{
if(EOF == fputc(random() * 0x0100 / RAND_MAX, fp))
{
fclose(fp);
fp = NULL;
}
}

return fp;
}
Thanks



My pleasure.



"Greg" <dj*********@snowboard.com> wrote in message
news:7e*************************@posting.google.co m...

I am trying to write a simple file system using c. It will consist of
frames of 512 bytes, and will have a superblock etc.

From the outside it will appear as a single file in UNIX. I want to
create the file and fill it with garbage at first before I write the
superblock.

My first question is: what is the best way to create a file and fill
it with garbage?



dd if=/dev/zero of=myfile.dat bs=1024 count=1024
this command will create a 1 MB file. all contents with zero.
U can use /dev/mem as input file for some junk data or any other device u
like...

-Neo


这篇关于简单的文件系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆