Blame view
fs/hpfs/file.c
4.24 KB
1da177e4c Linux-2.6.12-rc2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
/* * 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) { |
9a311b96c hpfs: remove the BKL |
15 |
hpfs_lock(inode->i_sb); |
1da177e4c Linux-2.6.12-rc2 |
16 |
hpfs_write_if_changed(inode); |
9a311b96c hpfs: remove the BKL |
17 |
hpfs_unlock(inode->i_sb); |
1da177e4c Linux-2.6.12-rc2 |
18 19 |
return 0; } |
02c24a821 fs: push i_mutex ... |
20 |
int hpfs_file_fsync(struct file *file, loff_t start, loff_t end, int datasync) |
1da177e4c Linux-2.6.12-rc2 |
21 |
{ |
bc8728ee5 HPFS: Implement f... |
22 |
struct inode *inode = file->f_mapping->host; |
02c24a821 fs: push i_mutex ... |
23 24 25 26 27 |
int ret; ret = filemap_write_and_wait_range(file->f_mapping, start, end); if (ret) return ret; |
bc8728ee5 HPFS: Implement f... |
28 |
return sync_blockdev(inode->i_sb->s_bdev); |
1da177e4c Linux-2.6.12-rc2 |
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
} /* * 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*/; |
7dd29d8d8 HPFS: Introduce a... |
55 |
hpfs_lock_assert(i->i_sb); |
1da177e4c Linux-2.6.12-rc2 |
56 57 58 59 60 61 |
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; |
1da177e4c Linux-2.6.12-rc2 |
62 63 64 65 |
} static int hpfs_get_block(struct inode *inode, sector_t iblock, struct buffer_head *bh_result, int create) { |
7dd29d8d8 HPFS: Introduce a... |
66 |
int r; |
1da177e4c Linux-2.6.12-rc2 |
67 |
secno s; |
7dd29d8d8 HPFS: Introduce a... |
68 |
hpfs_lock(inode->i_sb); |
1da177e4c Linux-2.6.12-rc2 |
69 70 71 |
s = hpfs_bmap(inode, iblock); if (s) { map_bh(bh_result, inode->i_sb, s); |
7dd29d8d8 HPFS: Introduce a... |
72 |
goto ret_0; |
1da177e4c Linux-2.6.12-rc2 |
73 |
} |
7dd29d8d8 HPFS: Introduce a... |
74 |
if (!create) goto ret_0; |
1da177e4c Linux-2.6.12-rc2 |
75 76 |
if (iblock<<9 != hpfs_i(inode)->mmu_private) { BUG(); |
7dd29d8d8 HPFS: Introduce a... |
77 78 |
r = -EIO; goto ret_r; |
1da177e4c Linux-2.6.12-rc2 |
79 80 81 |
} 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); |
7dd29d8d8 HPFS: Introduce a... |
82 83 |
r = -ENOSPC; goto ret_r; |
1da177e4c Linux-2.6.12-rc2 |
84 85 86 87 88 |
} inode->i_blocks++; hpfs_i(inode)->mmu_private += 512; set_buffer_new(bh_result); map_bh(bh_result, inode->i_sb, s); |
7dd29d8d8 HPFS: Introduce a... |
89 90 91 92 93 |
ret_0: r = 0; ret_r: hpfs_unlock(inode->i_sb); return r; |
1da177e4c Linux-2.6.12-rc2 |
94 95 96 97 98 99 |
} static int hpfs_writepage(struct page *page, struct writeback_control *wbc) { return block_write_full_page(page,hpfs_get_block, wbc); } |
d6091b720 hpfs: convert to ... |
100 |
|
1da177e4c Linux-2.6.12-rc2 |
101 102 103 104 |
static int hpfs_readpage(struct file *file, struct page *page) { return block_read_full_page(page,hpfs_get_block); } |
d6091b720 hpfs: convert to ... |
105 106 107 108 |
static int hpfs_write_begin(struct file *file, struct address_space *mapping, loff_t pos, unsigned len, unsigned flags, struct page **pagep, void **fsdata) |
1da177e4c Linux-2.6.12-rc2 |
109 |
{ |
282dc1788 get rid of cont_w... |
110 |
int ret; |
d6091b720 hpfs: convert to ... |
111 |
*pagep = NULL; |
282dc1788 get rid of cont_w... |
112 |
ret = cont_write_begin(file, mapping, pos, len, flags, pagep, fsdata, |
d6091b720 hpfs: convert to ... |
113 114 |
hpfs_get_block, &hpfs_i(mapping->host)->mmu_private); |
282dc1788 get rid of cont_w... |
115 116 117 118 119 120 121 |
if (unlikely(ret)) { loff_t isize = mapping->host->i_size; if (pos + len > isize) vmtruncate(mapping->host, isize); } return ret; |
1da177e4c Linux-2.6.12-rc2 |
122 |
} |
d6091b720 hpfs: convert to ... |
123 |
|
1da177e4c Linux-2.6.12-rc2 |
124 125 126 127 |
static sector_t _hpfs_bmap(struct address_space *mapping, sector_t block) { return generic_block_bmap(mapping,block,hpfs_get_block); } |
d6091b720 hpfs: convert to ... |
128 |
|
f5e54d6e5 [PATCH] mark addr... |
129 |
const struct address_space_operations hpfs_aops = { |
1da177e4c Linux-2.6.12-rc2 |
130 131 |
.readpage = hpfs_readpage, .writepage = hpfs_writepage, |
d6091b720 hpfs: convert to ... |
132 133 |
.write_begin = hpfs_write_begin, .write_end = generic_write_end, |
1da177e4c Linux-2.6.12-rc2 |
134 135 136 137 138 139 140 |
.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; |
543ade1fc [PATCH] Streamlin... |
141 |
retval = do_sync_write(file, buf, count, ppos); |
7dd29d8d8 HPFS: Introduce a... |
142 143 |
if (retval > 0) { hpfs_lock(file->f_path.dentry->d_sb); |
575800b3c [PATCH] struct pa... |
144 |
hpfs_i(file->f_path.dentry->d_inode)->i_dirty = 1; |
7dd29d8d8 HPFS: Introduce a... |
145 146 |
hpfs_unlock(file->f_path.dentry->d_sb); } |
1da177e4c Linux-2.6.12-rc2 |
147 148 |
return retval; } |
4b6f5d20b [PATCH] Make most... |
149 |
const struct file_operations hpfs_file_ops = |
1da177e4c Linux-2.6.12-rc2 |
150 151 |
{ .llseek = generic_file_llseek, |
543ade1fc [PATCH] Streamlin... |
152 153 |
.read = do_sync_read, .aio_read = generic_file_aio_read, |
1da177e4c Linux-2.6.12-rc2 |
154 |
.write = hpfs_file_write, |
543ade1fc [PATCH] Streamlin... |
155 |
.aio_write = generic_file_aio_write, |
1da177e4c Linux-2.6.12-rc2 |
156 157 158 |
.mmap = generic_file_mmap, .release = hpfs_file_release, .fsync = hpfs_file_fsync, |
5ffc4ef45 sendfile: remove ... |
159 |
.splice_read = generic_file_splice_read, |
1da177e4c Linux-2.6.12-rc2 |
160 |
}; |
92e1d5be9 [PATCH] mark stru... |
161 |
const struct inode_operations hpfs_file_iops = |
1da177e4c Linux-2.6.12-rc2 |
162 163 |
{ .truncate = hpfs_truncate, |
ca30bc995 [PATCH] hpfs: cle... |
164 |
.setattr = hpfs_setattr, |
1da177e4c Linux-2.6.12-rc2 |
165 |
}; |