#include <endian.h>
#include <error.h>
#include <pmap.h>
-#include <arch/bitmask.h>
+#include <bitmask.h>
/* These structs are declared again and initialized farther down */
struct page_map_operations ext2_pm_op;
/* One-time init for all ext2 instances */
void ext2_init(void)
{
- ext2_i_kcache = kmem_cache_create("ext2_i_info", sizeof(struct ext2_i_info),
- __alignof__(struct ext2_i_info), 0, 0, 0);
+ ext2_i_kcache = kmem_cache_create("ext2_i_info",
+ sizeof(struct ext2_i_info),
+ __alignof__(struct ext2_i_info), 0,
+ NULL, 0, 0, NULL);
}
/* Block management */
* the 2x and 3x walks are jacked up. */
void ext2_print_ino_blocks(struct inode *inode)
{
- printk("Inode %08p, Size: %d, 512B 'blocks': %d\n-------------\n", inode,
+ printk("Inode %p, Size: %d, 512B 'blocks': %d\n-------------\n", inode,
inode->i_size, inode->i_blocks);
for (int i = 0; i < inode->i_blocks * (inode->i_sb->s_blocksize / 512); i++)
printk("# %03d, Block %03d\n", i, ext2_find_inoblock(inode, i));
blksize = 1024 << le32_to_cpu(e2sb->s_log_block_size);
blks_per_group = le32_to_cpu(e2sb->s_blocks_per_group);
num_blk_group = num_blks / blks_per_group + (num_blks % blks_per_group ? 1 : 0);
-
+
if (print) {
printk("EXT2 info:\n-------------------------\n");
printk("Total Inodes: %8d\n", le32_to_cpu(e2sb->s_inodes_cnt));
printk("Volume name: %s\n", e2sb->s_volume_name);
printk("\nBlock Group Info:\n----------------------\n");
}
-
+
for (int i = 0; i < num_blk_group; i++) {
sum_blks += le16_to_cpu(bg[i].bg_free_blocks_cnt);
sum_inodes += le16_to_cpu(bg[i].bg_free_inodes_cnt);
if (print) {
- printk("*** BG %d at %08p\n", i, &bg[i]);
+ printk("*** BG %d at %p\n", i, &bg[i]);
printk("Block bitmap:%8d\n", le32_to_cpu(bg[i].bg_block_bitmap));
printk("Inode bitmap:%8d\n", le32_to_cpu(bg[i].bg_inode_bitmap));
printk("Inode table: %8d\n", le32_to_cpu(bg[i].bg_inode_table));
printk("Used Dirs: %8d\n", le16_to_cpu(bg[i].bg_used_dirs_cnt));
}
}
-
+
/* Sanity Assertions. A good ext2 will always pass these. */
inodes_per_grp = le32_to_cpu(e2sb->s_inodes_per_group);
blks_per_group = le32_to_cpu(e2sb->s_blocks_per_group);
struct block_request *breq;
void *eobh;
- assert(page->pg_flags & PG_BUFFER);
+ atomic_or(&page->pg_flags, PG_BUFFER);
retval = ext2_mappage(pm, page);
if (retval)
return retval;
breq->flags = BREQ_READ;
breq->callback = generic_breq_done;
breq->data = 0;
+ sem_init_irqsave(&breq->sem, 0);
breq->bhs = breq->local_bhs;
breq->nr_bhs = 0;
/* Pack the BH pointers in the block request */
} else {
memset(bh->bh_buffer, 0, pm->pm_host->i_sb->s_blocksize);
bh->bh_flags |= BH_DIRTY;
- bh->bh_page->pg_flags |= PG_DIRTY;
+ atomic_or(&bh->bh_page->pg_flags, PG_DIRTY);
}
}
retval = bdev_submit_request(bdev, breq);
if (eof_off)
memset(eof_off + page2kva(page), 0, PGSIZE - eof_off);
/* Now the page is up to date */
- page->pg_flags |= PG_UPTODATE;
+ atomic_or(&page->pg_flags, PG_UPTODATE);
/* Useful debugging. Put one higher up if the page is not getting mapped */
//print_pageinfo(page);
return 0;
}
+int ext2_writepage(struct page_map *pm, struct page *page)
+{
+ return -1;
+}
+
/* Super Operations */
/* Creates and initializes a new inode. FS specific, yet inode-generic fields
/* These should return true if foreach_dirent should stop working on the
* dirents. */
-typedef bool (*each_func_t) (struct ext2_dirent *dir_i, void *a1, void *a2,
- void *a3);
+typedef bool (*each_func_t) (struct ext2_dirent *dir_i, long a1, long a2,
+ long a3);
/* Loads the buffer and performs my_work on each dirent, stopping and returning
* 0 if one of the calls succeeded, or returning the dir block num of what would
* be the next dir block otherwise (aka, how many blocks we went through). */
static uint32_t ext2_foreach_dirent(struct inode *dir, each_func_t my_work,
- void *a1, void *a2, void *a3)
+ long a1, long a2, long a3)
{
struct ext2_dirent *dir_buf, *dir_i;
uint32_t dir_block = 0;
return 0;
}
-/* Helper for writing the contents of a dentry to a disk dirent */
+/* Helper for writing the contents of a dentry to a disk dirent. Zeroes the
+ * contents of the dirent so that we don't write random data to disk. */
static void ext2_write_dirent(struct ext2_dirent *e2dir, struct dentry *dentry,
unsigned int rec_len)
{
+ memset(e2dir, 0, sizeof(*e2dir));
e2dir->dir_inode = cpu_to_le32(dentry->d_inode->i_ino);
e2dir->dir_reclen = cpu_to_le16(rec_len);
e2dir->dir_namelen = dentry->d_name.len;
e2dir->dir_filetype = EXT2_FT_UNKNOWN;
}
assert(dentry->d_name.len <= 255);
- strncpy((char*)e2dir->dir_name, dentry->d_name.name, dentry->d_name.len);
+ strlcpy((char*)e2dir->dir_name, dentry->d_name.name,
+ sizeof(e2dir->dir_name));
}
/* Helper for ext2_create(). This tries to squeeze a dirent in the slack space
* after an existing dirent, returning TRUE if it succeeded (to break out). */
-static bool create_each_func(struct ext2_dirent *dir_i, void *a1, void *a2,
- void *a3)
+static bool create_each_func(struct ext2_dirent *dir_i, long a1, long a2,
+ long a3)
{
struct dentry *dentry = (struct dentry*)a1;
unsigned int our_rec_len = (unsigned int)a2;
struct ext2_i_info *e2ii;
uint32_t dir_block;
unsigned int our_rec_len;
- /* TODO: figure out the real time! (Nanwan's birthday, bitches!) */
- time_t now = 1242129600;
struct ext2_dirent *new_dirent;
/* Set basic inode stuff for files, get a disk inode, etc */
SET_FTYPE(inode->i_mode, __S_IFREG);
inode->i_fop = &ext2_f_op_file;
inode->i_ino = ext2_alloc_diskinode(inode, dir_bg);
- inode->i_atime.tv_sec = now;
- inode->i_atime.tv_nsec = 0;
- inode->i_ctime.tv_sec = now;
- inode->i_ctime.tv_nsec = 0;
- inode->i_mtime.tv_sec = now;
- inode->i_mtime.tv_nsec = 0;
/* Initialize disk inode (this will be different for short symlinks) */
disk_inode = ext2_get_diskinode(inode);
ext2_init_diskinode(disk_inode, inode);
assert(our_rec_len <= 8 + 256);
/* Consider caching the start point for future dirent ops. Or even using
* the indexed directory.... */
- dir_block = ext2_foreach_dirent(dir, create_each_func, dentry,
- (void*)our_rec_len, (void*)mode);
+ dir_block = ext2_foreach_dirent(dir, create_each_func, (long)dentry,
+ (long)our_rec_len, (long)mode);
/* If this returned a block number, we didn't find room in any of the
* existing directory blocks, so we need to make a new one, stick it in the
* dir inode, and stick our dirent at the beginning. The reclen is the
/* If we match, this loads the inode for the dentry and returns true (so we
* break out) */
-static bool lookup_each_func(struct ext2_dirent *dir_i, void *a1, void *a2,
- void *a3)
+static bool lookup_each_func(struct ext2_dirent *dir_i, long a1, long a2,
+ long a3)
{
struct dentry *dentry = (struct dentry*)a1;
/* Test if we're the one (TODO: use d_compare). Note, dir_name is not
if (!strncmp((char*)dir_i->dir_name, dentry->d_name.name,
dir_i->dir_namelen) &&
(dentry->d_name.name[dir_i->dir_namelen] == '\0')) {
- load_inode(dentry, le32_to_cpu(dir_i->dir_inode));
+ load_inode(dentry, (long)le32_to_cpu(dir_i->dir_inode));
/* TODO: (HASH) add dentry to dcache (maybe the caller should) */
return TRUE;
}
{
assert(S_ISDIR(dir->i_mode));
struct ext2_dirent *dir_buf, *dir_i;
- if (!ext2_foreach_dirent(dir, lookup_each_func, dentry, 0, 0))
+ if (!ext2_foreach_dirent(dir, lookup_each_func, (long)dentry, 0, 0))
return dentry;
- printd("EXT2: Not Found, %s\n", dentry->d_name.name);
+ printd("EXT2: Not Found, %s\n", dentry->d_name.name);
return 0;
}
struct inode *inode = dentry->d_inode;
SET_FTYPE(inode->i_mode, __S_IFLNK);
inode->i_fop = &ext2_f_op_sym;
- strncpy(string, symname, len);
- string[len] = '\0'; /* symname should be \0d anyway, but just in case */
+ strlcpy(string, symname, len + 1);
#endif
return 0;
}
return -1;
}
-/* Produces the hash to lookup this dentry from the dcache */
-int ext2_d_hash(struct dentry *dentry, struct qstr *name)
-{
- return -1;
-}
-
/* Compares name1 and name2. name1 should be a member of dir. */
int ext2_d_compare(struct dentry *dir, struct qstr *name1, struct qstr *name2)
{ // default, string comp (case sensitive)
/* Updates the file pointer. TODO: think about locking, and putting this in the
* VFS. */
#include <syscall.h> /* just for set_errno, may go away later */
-off_t ext2_llseek(struct file *file, off_t offset, int whence)
+int ext2_llseek(struct file *file, off64_t offset, off64_t *ret, int whence)
{
- off_t temp_off = 0;
+ off64_t temp_off = 0;
switch (whence) {
case SEEK_SET:
temp_off = offset;
return -1;
}
file->f_pos = temp_off;
- return temp_off;
+ *ret = temp_off;
+ return 0;
}
/* Fills in the next directory entry (dirent), starting with d_off. Like with
int block = dirent->d_off / dir->f_dentry->d_sb->s_blocksize;
blk_buf = ext2_get_ino_metablock(dir->f_dentry->d_inode, block);
assert(blk_buf);
- off_t f_off = dirent->d_off % dir->f_dentry->d_sb->s_blocksize;
+ off64_t f_off = dirent->d_off % dir->f_dentry->d_sb->s_blocksize;
/* Copy out the dirent info */
struct ext2_dirent *e2dir = (struct ext2_dirent*)(blk_buf + f_off);
dirent->d_ino = le32_to_cpu(e2dir->dir_inode);
panic("Something is jacked with the dirent going beyond the dir/file");
/* note, dir_namelen doesn't include the \0 */
dirent->d_reclen = e2dir->dir_namelen;
- strncpy(dirent->d_name, (char*)e2dir->dir_name, e2dir->dir_namelen);
assert(e2dir->dir_namelen <= MAX_FILENAME_SZ);
- dirent->d_name[e2dir->dir_namelen] = '\0';
+ strlcpy(dirent->d_name, (char*)e2dir->dir_name, e2dir->dir_namelen + 1);
ext2_put_metablock(dir->f_dentry->d_sb, blk_buf);
-
+
/* At the end of the directory, sort of. ext2 often preallocates blocks, so
* this will cause us to walk along til the end, which isn't quite right. */
if (dir->f_dentry->d_inode->i_size == dirent->d_off)
/* Reads count bytes from a file, starting from (and modifiying) offset, and
* putting the bytes into buffers described by vector */
ssize_t ext2_readv(struct file *file, const struct iovec *vector,
- unsigned long count, off_t *offset)
+ unsigned long count, off64_t *offset)
{
return -1;
}
/* Writes count bytes to a file, starting from (and modifiying) offset, and
* taking the bytes from buffers described by vector */
ssize_t ext2_writev(struct file *file, const struct iovec *vector,
- unsigned long count, off_t *offset)
+ unsigned long count, off64_t *offset)
{
return -1;
}
/* Write the contents of file to the page. Will sort the params later */
ssize_t ext2_sendpage(struct file *file, struct page *page, int offset,
- size_t size, off_t pos, int more)
+ size_t size, off64_t pos, int more)
{
return -1;
}
/* Redeclaration and initialization of the FS ops structures */
struct page_map_operations ext2_pm_op = {
ext2_readpage,
+ ext2_writepage,
};
struct super_operations ext2_s_op = {
struct dentry_operations ext2_d_op = {
ext2_d_revalidate,
- ext2_d_hash,
+ generic_dentry_hash,
ext2_d_compare,
ext2_d_delete,
ext2_d_release,