C 如何使用VTS返回错误装载上的清除错误?
当尝试装载带有一组参数的文件系统时(在装载时使用选项-o),如果用户没有正确使用预定义参数,我们希望让它完全失败。目前,当我们不挂载文件系统并让main返回0时,我们会收到这个令人讨厌的错误消息。如果参数不正确,我们基本上不希望挂载文件系统 现状 mount-t filesystemtest-o testarguments none/mnt/filesystemtest 论点无效 RS:初始化期间已退出服务“fs_00021” 文件系统测试109710 0xab6e 0x65f1 0x618d 0x6203 0x98ba 0x1010 对RS的请求失败:未知错误(错误302) 装载:无法运行/bin/sercie up/sbin/filesystemtest-标签“fs_00021”-args” 装载:无法在/mnt/filesystemtest/上装载任何内容:未知错误 首选情况 mount-t filesystemtest-o testarguments none/mnt/filesystemtest 论点无效 基本上,我们不想知道如何返回一个干净的错误消息,当不调用开始时,如下面所示。下面的示例不是我们的实际代码,也没有实际使用参数,但作为示例,应该有一种方法使这段代码始终失败。(很抱歉):C 如何使用VTS返回错误装载上的清除错误?,c,minix,C,Minix,当尝试装载带有一组参数的文件系统时(在装载时使用选项-o),如果用户没有正确使用预定义参数,我们希望让它完全失败。目前,当我们不挂载文件系统并让main返回0时,我们会收到这个令人讨厌的错误消息。如果参数不正确,我们基本上不希望挂载文件系统 现状 mount-t filesystemtest-o testarguments none/mnt/filesystemtest 论点无效 RS:初始化期间已退出服务“fs_00021” 文件系统测试109710 0xab6e 0x65f1 0x618d
#包括
#包括
#包括
#包括
#包括
静态void my_init_hook(void)
{
/*这个钩子将在初始化之后被调用一次。
*/
结构inode_stat file_stat;
结构inode*inode;
/*我们在根目录中创建一个常规文件
*每个人都可读,并且由root所有。其大小由for返回
*示例stat()将为零,但这并不意味着它为空。
*对于具有动态生成内容的文件,文件大小为
*通常设置为零。
*/
文件_stat.mode=S_IFREG | 0444;
文件_stat.uid=0;
文件_stat.gid=0;
文件_stat.size=0;
文件_stat.dev=否_dev;
/*现在创建实际的文件。它称为“测试”,没有
*索引号。其回调数据值设置为1,允许
*稍后用这个号码识别。
*/
inode=add_inode(get_root_inode(),“test”,NO_INDEX,&file_stat,0,
(cbdata_t)1);
断言(inode!=NULL);
}
静态int my_read_hook(结构索引节点*索引节点、偏移量、字符**ptr、,
尺寸(长度、中心数据、中心数据)
{
/*每次读取常规文件时都会调用此钩子
*它可以动态生成我们文件的内容。
*/
静态字符数据[26];
常量字符*str;
现在是时候了;
/*我们只有一个文件。如果有更多文件,cbdata可能会有所帮助
*区分它们。
*/
断言((int)cbdata==1);
/*将文件内容生成到“数据”缓冲区中。我们可以
*直接使用ctime()的返回值,但这会导致
*糟糕的例子。
*/
时间(现在);
str=ctime(&now);
strcpy(数据,str);
/*如果偏移量超出字符串的末尾,则返回EOF*/
如果(偏移量>strlen(数据)){
*len=0;
返回OK;
}
/*否则,将指针返回到“data”中。如有必要,请绑定
*返回字符串其余部分的长度。请注意
*“数据”必须是静态的,因为它将在此函数之后使用
*返回。
*/
*ptr=数据+偏移量;
if(*len>strlen(数据)-偏移量)
*len=strlen(数据)-偏移量;
返回OK;
}
/*带有回调挂钩的表*/
结构fs_hooks my_hooks={
我的第一钩,
空,/*清除钩*/
空,/*lookup\u hook*/
NULL,/*getdents\u hook*/
我的书钩,
空,/*rdlink\u钩子*/
NULL/*消息钩子*/
};
int main(int argc,char*argv[])
{
/*上面的调用永远不会返回。这只是让编译器感到高兴*/
如果(argc==1){
//我们希望它现在就失败!!!!
printf(“参数无效。(用-o传递选项)”;
}
否则{
结构inode_stat root_stat;
/*填写要用于根索引节点的详细信息。它将是一个
*目录,任何人都可以阅读和搜索,并且归root所有。
*/
root_stat.mode=S_IFDIR | 0555;
root_stat.uid=0;
root_stat.gid=0;
root_stat.size=0;
root_stat.dev=NO_dev;
/*现在开始,预先分配10个索引节点,这比我们要做的要多
*需要此示例。未使用索引项。
*/
开始(我的钩子,10和根统计,0);
}
返回0;
}
#include <minix/drivers.h>
#include <minix/vtreefs.h>
#include <sys/stat.h>
#include <time.h>
#include <assert.h>
static void my_init_hook(void)
{
/* This hook will be called once, after VTreeFS has initialized.
*/
struct inode_stat file_stat;
struct inode *inode;
/* We create one regular file in the root directory. The file is
* readable by everyone, and owned by root. Its size as returned by for
* example stat() will be zero, but that does not mean it is empty.
* For files with dynamically generated content, the file size is
* typically set to zero.
*/
file_stat.mode = S_IFREG | 0444;
file_stat.uid = 0;
file_stat.gid = 0;
file_stat.size = 0;
file_stat.dev = NO_DEV;
/* Now create the actual file. It is called "test" and does not have an
* index number. Its callback data value is set to 1, allowing it to be
* identified with this number later.
*/
inode = add_inode(get_root_inode(), "test", NO_INDEX, &file_stat, 0,
(cbdata_t) 1);
assert(inode != NULL);
}
static int my_read_hook(struct inode *inode, off_t offset, char **ptr,
size_t *len, cbdata_t cbdata)
{
/* This hook will be called every time a regular file is read. We use
* it to dyanmically generate the contents of our file.
*/
static char data[26];
const char *str;
time_t now;
/* We have only a single file. With more files, cbdata may help
* distinguishing between them.
*/
assert((int) cbdata == 1);
/* Generate the contents of the file into the 'data' buffer. We could
* use the return value of ctime() directly, but that would make for a
* lousy example.
*/
time(&now);
str = ctime(&now);
strcpy(data, str);
/* If the offset is beyond the end of the string, return EOF. */
if (offset > strlen(data)) {
*len = 0;
return OK;
}
/* Otherwise, return a pointer into 'data'. If necessary, bound the
* returned length to the length of the rest of the string. Note that
* 'data' has to be static, because it will be used after this function
* returns.
*/
*ptr = data + offset;
if (*len > strlen(data) - offset)
*len = strlen(data) - offset;
return OK;
}
/* The table with callback hooks. */
struct fs_hooks my_hooks = {
my_init_hook,
NULL, /* cleanup_hook */
NULL, /* lookup_hook */
NULL, /* getdents_hook */
my_read_hook,
NULL, /* rdlink_hook */
NULL /* message_hook */
};
int main(int argc, char* argv[])
{
/* The call above never returns. This just keeps the compiler happy. */
if (argc == 1) {
// We want it to fail right now!!!!
printf("Arguments invalid. (pass option with -o)");
}
else {
struct inode_stat root_stat;
/* Fill in the details to be used for the root inode. It will be a
* directory, readable and searchable by anyone, and owned by root.
*/
root_stat.mode = S_IFDIR | 0555;
root_stat.uid = 0;
root_stat.gid = 0;
root_stat.size = 0;
root_stat.dev = NO_DEV;
/* Now start VTreeFS. Preallocate 10 inodes, which is more than we'll
* need for this example. No indexed entries are used.
*/
start_vtreefs(&my_hooks, 10, &root_stat, 0);
}
return 0;
}