aboutsummaryrefslogtreecommitdiff
path: root/fs/hpfs/file.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 15:20:36 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 15:20:36 -0700
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /fs/hpfs/file.c
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'fs/hpfs/file.c')
-rw-r--r--fs/hpfs/file.c140
1 files changed, 140 insertions, 0 deletions
diff --git a/fs/hpfs/file.c b/fs/hpfs/file.c
new file mode 100644
index 00000000000..ab144dabd87
--- /dev/null
+++ b/fs/hpfs/file.c
@@ -0,0 +1,140 @@
+/*
+ * linux/fs/hpfs/file.c
+ *
+ * Mikulas Patocka (mikulas@artax.karlin.mff.cuni.cz), 1998-1999
+ *
+ * file VFS functions
+ */
+
+#include "hpfs_fn.h"
+
+#define BLOCKS(size) (((size) + 511) >> 9)
+
+static int hpfs_file_release(struct inode *inode, struct file *file)
+{
+ lock_kernel();
+ hpfs_write_if_changed(inode);
+ unlock_kernel();
+ return 0;
+}
+
+int hpfs_file_fsync(struct file *file, struct dentry *dentry, int datasync)
+{
+ /*return file_fsync(file, dentry);*/
+ return 0; /* Don't fsync :-) */
+}
+
+/*
+ * generic_file_read often calls bmap with non-existing sector,
+ * so we must ignore such errors.
+ */
+
+static secno hpfs_bmap(struct inode *inode, unsigned file_secno)
+{
+ struct hpfs_inode_info *hpfs_inode = hpfs_i(inode);
+ unsigned n, disk_secno;
+ struct fnode *fnode;
+ struct buffer_head *bh;
+ if (BLOCKS(hpfs_i(inode)->mmu_private) <= file_secno) return 0;
+ n = file_secno - hpfs_inode->i_file_sec;
+ if (n < hpfs_inode->i_n_secs) return hpfs_inode->i_disk_sec + n;
+ if (!(fnode = hpfs_map_fnode(inode->i_sb, inode->i_ino, &bh))) return 0;
+ disk_secno = hpfs_bplus_lookup(inode->i_sb, inode, &fnode->btree, file_secno, bh);
+ if (disk_secno == -1) return 0;
+ if (hpfs_chk_sectors(inode->i_sb, disk_secno, 1, "bmap")) return 0;
+ return disk_secno;
+}
+
+static void hpfs_truncate(struct inode *i)
+{
+ if (IS_IMMUTABLE(i)) return /*-EPERM*/;
+ lock_kernel();
+ hpfs_i(i)->i_n_secs = 0;
+ i->i_blocks = 1 + ((i->i_size + 511) >> 9);
+ hpfs_i(i)->mmu_private = i->i_size;
+ hpfs_truncate_btree(i->i_sb, i->i_ino, 1, ((i->i_size + 511) >> 9));
+ hpfs_write_inode(i);
+ hpfs_i(i)->i_n_secs = 0;
+ unlock_kernel();
+}
+
+static int hpfs_get_block(struct inode *inode, sector_t iblock, struct buffer_head *bh_result, int create)
+{
+ secno s;
+ s = hpfs_bmap(inode, iblock);
+ if (s) {
+ map_bh(bh_result, inode->i_sb, s);
+ return 0;
+ }
+ if (!create) return 0;
+ if (iblock<<9 != hpfs_i(inode)->mmu_private) {
+ BUG();
+ return -EIO;
+ }
+ if ((s = hpfs_add_sector_to_btree(inode->i_sb, inode->i_ino, 1, inode->i_blocks - 1)) == -1) {
+ hpfs_truncate_btree(inode->i_sb, inode->i_ino, 1, inode->i_blocks - 1);
+ return -ENOSPC;
+ }
+ inode->i_blocks++;
+ hpfs_i(inode)->mmu_private += 512;
+ set_buffer_new(bh_result);
+ map_bh(bh_result, inode->i_sb, s);
+ return 0;
+}
+
+static int hpfs_writepage(struct page *page, struct writeback_control *wbc)
+{
+ return block_write_full_page(page,hpfs_get_block, wbc);
+}
+static int hpfs_readpage(struct file *file, struct page *page)
+{
+ return block_read_full_page(page,hpfs_get_block);
+}
+static int hpfs_prepare_write(struct file *file, struct page *page, unsigned from, unsigned to)
+{
+ return cont_prepare_write(page,from,to,hpfs_get_block,
+ &hpfs_i(page->mapping->host)->mmu_private);
+}
+static sector_t _hpfs_bmap(struct address_space *mapping, sector_t block)
+{
+ return generic_block_bmap(mapping,block,hpfs_get_block);
+}
+struct address_space_operations hpfs_aops = {
+ .readpage = hpfs_readpage,
+ .writepage = hpfs_writepage,
+ .sync_page = block_sync_page,
+ .prepare_write = hpfs_prepare_write,
+ .commit_write = generic_commit_write,
+ .bmap = _hpfs_bmap
+};
+
+static ssize_t hpfs_file_write(struct file *file, const char __user *buf,
+ size_t count, loff_t *ppos)
+{
+ ssize_t retval;
+
+ retval = generic_file_write(file, buf, count, ppos);
+ if (retval > 0) {
+ struct inode *inode = file->f_dentry->d_inode;
+ inode->i_mtime = CURRENT_TIME_SEC;
+ hpfs_i(inode)->i_dirty = 1;
+ }
+ return retval;
+}
+
+struct file_operations hpfs_file_ops =
+{
+ .llseek = generic_file_llseek,
+ .read = generic_file_read,
+ .write = hpfs_file_write,
+ .mmap = generic_file_mmap,
+ .release = hpfs_file_release,
+ .fsync = hpfs_file_fsync,
+ .sendfile = generic_file_sendfile,
+};
+
+struct inode_operations hpfs_file_iops =
+{
+ .truncate = hpfs_truncate,
+ .setattr = hpfs_notify_change,
+};