mirror of
https://github.com/psankar/simplefs.git
synced 2025-07-24 22:44:45 +02:00
Lindent sources
This commit is contained in:
parent
b5aa56df68
commit
3ad58de506
@ -67,7 +67,8 @@ int main(int argc, char *argv[])
|
||||
ret = write(fd, (char *)&root_inode, sizeof(root_inode));
|
||||
|
||||
if (ret != sizeof(root_inode)) {
|
||||
printf("The inode store was not written properly. Retry your mkfs\n");
|
||||
printf
|
||||
("The inode store was not written properly. Retry your mkfs\n");
|
||||
ret = -1;
|
||||
goto exit;
|
||||
}
|
||||
@ -80,23 +81,28 @@ int main(int argc, char *argv[])
|
||||
ret = write(fd, (char *)&welcomefile_inode, sizeof(root_inode));
|
||||
|
||||
if (ret != sizeof(root_inode)) {
|
||||
printf("The welcomefile inode was not written properly. Retry your mkfs\n");
|
||||
printf
|
||||
("The welcomefile inode was not written properly. Retry your mkfs\n");
|
||||
ret = -1;
|
||||
goto exit;
|
||||
}
|
||||
printf("welcomefile inode written succesfully\n");
|
||||
|
||||
nbytes = SIMPLEFS_DEFAULT_BLOCK_SIZE - sizeof(root_inode) - sizeof(welcomefile_inode);
|
||||
nbytes =
|
||||
SIMPLEFS_DEFAULT_BLOCK_SIZE - sizeof(root_inode) -
|
||||
sizeof(welcomefile_inode);
|
||||
block_padding = malloc(nbytes);
|
||||
|
||||
|
||||
ret = write(fd, block_padding, nbytes);
|
||||
|
||||
if (ret != nbytes) {
|
||||
printf("The padding bytes are not written properly. Retry your mkfs\n");
|
||||
printf
|
||||
("The padding bytes are not written properly. Retry your mkfs\n");
|
||||
ret = -1;
|
||||
goto exit;
|
||||
}
|
||||
printf("inode store padding bytes (after the two inodes) written sucessfully\n");
|
||||
printf
|
||||
("inode store padding bytes (after the two inodes) written sucessfully\n");
|
||||
|
||||
strcpy(record.filename, welcomefile_name);
|
||||
record.inode_no = WELCOMEFILE_INODE_NUMBER;
|
||||
@ -104,22 +110,26 @@ int main(int argc, char *argv[])
|
||||
|
||||
ret = write(fd, (char *)&record, nbytes);
|
||||
if (ret != nbytes) {
|
||||
printf("Writing the rootdirectory datablock (name+inode_no pair for welcomefile) has failed\n");
|
||||
printf
|
||||
("Writing the rootdirectory datablock (name+inode_no pair for welcomefile) has failed\n");
|
||||
ret = -1;
|
||||
goto exit;
|
||||
}
|
||||
printf("root directory datablocks (name+inode_no pair for welcomefile) written succesfully\n");
|
||||
printf
|
||||
("root directory datablocks (name+inode_no pair for welcomefile) written succesfully\n");
|
||||
|
||||
nbytes = SIMPLEFS_DEFAULT_BLOCK_SIZE - sizeof(record);
|
||||
block_padding = realloc(block_padding, nbytes);
|
||||
|
||||
ret = write(fd, block_padding, nbytes);
|
||||
if (ret != nbytes) {
|
||||
printf("Writing the padding for rootdirectory children datablock has failed\n");
|
||||
printf
|
||||
("Writing the padding for rootdirectory children datablock has failed\n");
|
||||
ret = -1;
|
||||
goto exit;
|
||||
}
|
||||
printf("padding after the rootdirectory children written succesfully\n");
|
||||
printf
|
||||
("padding after the rootdirectory children written succesfully\n");
|
||||
|
||||
nbytes = sizeof(welcomefile_body);
|
||||
ret = write(fd, welcomefile_body, nbytes);
|
||||
|
38
simple.c
38
simple.c
@ -33,18 +33,20 @@ static int simplefs_readdir(struct file *filp, void *dirent, filldir_t filldir)
|
||||
sfs_inode = SIMPLEFS_INODE(inode);
|
||||
|
||||
if (unlikely(!S_ISDIR(sfs_inode->mode))) {
|
||||
printk(KERN_ERR "inode %llu not a directory", sfs_inode->inode_no);
|
||||
printk(KERN_ERR "inode %llu not a directory",
|
||||
sfs_inode->inode_no);
|
||||
return -ENOTDIR;
|
||||
}
|
||||
|
||||
bh = (struct buffer_head *)sb_bread(sb, sfs_inode->data_block_number);
|
||||
|
||||
record = (struct simplefs_dir_record *) bh->b_data;
|
||||
for (i=0; i < sfs_inode->dir_children_count; i++) {
|
||||
filldir(dirent, record->filename, SIMPLEFS_FILENAME_MAXLEN, pos, record->inode_no, DT_UNKNOWN);
|
||||
record = (struct simplefs_dir_record *)bh->b_data;
|
||||
for (i = 0; i < sfs_inode->dir_children_count; i++) {
|
||||
filldir(dirent, record->filename, SIMPLEFS_FILENAME_MAXLEN, pos,
|
||||
record->inode_no, DT_UNKNOWN);
|
||||
filp->f_pos += sizeof(struct simplefs_dir_record);
|
||||
pos += sizeof(struct simplefs_dir_record);
|
||||
record ++;
|
||||
record++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -52,7 +54,8 @@ static int simplefs_readdir(struct file *filp, void *dirent, filldir_t filldir)
|
||||
|
||||
/* This functions returns a simplefs_inode with the given inode_no
|
||||
* from the inode store, if it exists. */
|
||||
struct simplefs_inode * simplefs_get_inode(struct super_block *sb, uint64_t inode_no)
|
||||
struct simplefs_inode *simplefs_get_inode(struct super_block *sb,
|
||||
uint64_t inode_no)
|
||||
{
|
||||
struct simplefs_super_block *sfs_sb = SIMPLEFS_SB(sb);
|
||||
struct simplefs_inode *sfs_inode = NULL;
|
||||
@ -63,10 +66,11 @@ struct simplefs_inode * simplefs_get_inode(struct super_block *sb, uint64_t inod
|
||||
/* The inode store can be read once and kept in memory permanently while mounting.
|
||||
* But such a model will not be scalable in a filesystem with
|
||||
* millions or billions of files (inodes) */
|
||||
bh = (struct buffer_head *)sb_bread(sb, SIMPLEFS_INODESTORE_BLOCK_NUMBER);
|
||||
sfs_inode = (struct simplefs_inode *) bh->b_data;
|
||||
bh = (struct buffer_head *)sb_bread(sb,
|
||||
SIMPLEFS_INODESTORE_BLOCK_NUMBER);
|
||||
sfs_inode = (struct simplefs_inode *)bh->b_data;
|
||||
|
||||
for (i=0;i < sfs_sb->inodes_count; i++) {
|
||||
for (i = 0; i < sfs_sb->inodes_count; i++) {
|
||||
if (sfs_inode->inode_no == inode_no) {
|
||||
/* FIXME: bh->b_data is probably leaking */
|
||||
return sfs_inode;
|
||||
@ -99,8 +103,8 @@ struct dentry *simplefs_lookup(struct inode *parent_inode,
|
||||
int i;
|
||||
|
||||
bh = (struct buffer_head *)sb_bread(sb, parent->data_block_number);
|
||||
record = (struct simplefs_dir_record *) bh->b_data;
|
||||
for (i=0; i < parent->dir_children_count; i++) {
|
||||
record = (struct simplefs_dir_record *)bh->b_data;
|
||||
for (i = 0; i < parent->dir_children_count; i++) {
|
||||
if (!strcmp(record->filename, child_dentry->d_name.name)) {
|
||||
|
||||
struct inode *inode;
|
||||
@ -118,7 +122,8 @@ struct dentry *simplefs_lookup(struct inode *parent_inode,
|
||||
inode->i_fop = &simplefs_dir_operations;
|
||||
|
||||
/* FIXME: We should store these times to disk and retrieve them */
|
||||
inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
|
||||
inode->i_atime = inode->i_mtime = inode->i_ctime =
|
||||
CURRENT_TIME;
|
||||
|
||||
inode->i_private = sfs_inode;
|
||||
|
||||
@ -138,7 +143,8 @@ int simplefs_fill_super(struct super_block *sb, void *data, int silent)
|
||||
struct buffer_head *bh;
|
||||
struct simplefs_super_block *sb_disk;
|
||||
|
||||
bh = (struct buffer_head *)sb_bread(sb, SIMPLEFS_SUPERBLOCK_BLOCK_NUMBER);
|
||||
bh = (struct buffer_head *)sb_bread(sb,
|
||||
SIMPLEFS_SUPERBLOCK_BLOCK_NUMBER);
|
||||
|
||||
sb_disk = (struct simplefs_super_block *)bh->b_data;
|
||||
/* FIXME: bh->b_data is probably leaking */
|
||||
@ -174,9 +180,11 @@ int simplefs_fill_super(struct super_block *sb, void *data, int silent)
|
||||
root_inode->i_sb = sb;
|
||||
root_inode->i_op = &simplefs_inode_ops;
|
||||
root_inode->i_fop = &simplefs_dir_operations;
|
||||
root_inode->i_atime = root_inode->i_mtime = root_inode->i_ctime = CURRENT_TIME;
|
||||
root_inode->i_atime = root_inode->i_mtime = root_inode->i_ctime =
|
||||
CURRENT_TIME;
|
||||
|
||||
root_inode->i_private = simplefs_get_inode(sb, SIMPLEFS_ROOTDIR_INODE_NUMBER);
|
||||
root_inode->i_private =
|
||||
simplefs_get_inode(sb, SIMPLEFS_ROOTDIR_INODE_NUMBER);
|
||||
|
||||
sb->s_root = d_make_root(root_inode);
|
||||
if (!sb->s_root)
|
||||
|
Loading…
x
Reference in New Issue
Block a user