Lines Matching refs:fs
44 errcode_t ext2fs_mmp_read(ext2_filsys fs, blk64_t mmp_blk, void *buf) in ext2fs_mmp_read() argument
50 if ((mmp_blk <= fs->super->s_first_data_block) || in ext2fs_mmp_read()
51 (mmp_blk >= ext2fs_blocks_count(fs->super))) in ext2fs_mmp_read()
59 if (fs->mmp_fd <= 0) { in ext2fs_mmp_read()
60 fs->mmp_fd = open(fs->device_name, O_RDWR | O_DIRECT); in ext2fs_mmp_read()
61 if (fs->mmp_fd < 0) { in ext2fs_mmp_read()
67 if (fs->mmp_cmp == NULL) { in ext2fs_mmp_read()
68 int align = ext2fs_get_dio_alignment(fs->mmp_fd); in ext2fs_mmp_read()
70 retval = ext2fs_get_memalign(fs->blocksize, align, in ext2fs_mmp_read()
71 &fs->mmp_cmp); in ext2fs_mmp_read()
76 if ((blk64_t) ext2fs_llseek(fs->mmp_fd, mmp_blk * fs->blocksize, in ext2fs_mmp_read()
78 mmp_blk * fs->blocksize) { in ext2fs_mmp_read()
83 if (read(fs->mmp_fd, fs->mmp_cmp, fs->blocksize) != fs->blocksize) { in ext2fs_mmp_read()
88 mmp_cmp = fs->mmp_cmp; in ext2fs_mmp_read()
90 if (!(fs->flags & EXT2_FLAG_IGNORE_CSUM_ERRORS) && in ext2fs_mmp_read()
91 !ext2fs_mmp_csum_verify(fs, mmp_cmp)) in ext2fs_mmp_read()
98 if (buf != NULL && buf != fs->mmp_cmp) in ext2fs_mmp_read()
99 memcpy(buf, fs->mmp_cmp, fs->blocksize); in ext2fs_mmp_read()
113 errcode_t ext2fs_mmp_write(ext2_filsys fs, blk64_t mmp_blk, void *buf) in ext2fs_mmp_write() argument
122 fs->mmp_last_written = tv.tv_sec; in ext2fs_mmp_write()
124 if (fs->super->s_mmp_block < fs->super->s_first_data_block || in ext2fs_mmp_write()
125 fs->super->s_mmp_block > ext2fs_blocks_count(fs->super)) in ext2fs_mmp_write()
132 retval = ext2fs_mmp_csum_set(fs, mmp_s); in ext2fs_mmp_write()
138 retval = io_channel_write_blk64(fs->io, mmp_blk, -(int)sizeof(struct mmp_struct), buf); in ext2fs_mmp_write()
145 io_channel_flush(fs->io); in ext2fs_mmp_write()
182 static errcode_t ext2fs_mmp_reset(ext2_filsys fs) in ext2fs_mmp_reset() argument
187 if (fs->mmp_buf == NULL) { in ext2fs_mmp_reset()
188 retval = ext2fs_get_mem(fs->blocksize, &fs->mmp_buf); in ext2fs_mmp_reset()
193 memset(fs->mmp_buf, 0, fs->blocksize); in ext2fs_mmp_reset()
194 mmp_s = fs->mmp_buf; in ext2fs_mmp_reset()
204 strncpy(mmp_s->mmp_bdevname, fs->device_name, in ext2fs_mmp_reset()
207 mmp_s->mmp_check_interval = fs->super->s_mmp_update_interval; in ext2fs_mmp_reset()
211 retval = ext2fs_mmp_write(fs, fs->super->s_mmp_block, fs->mmp_buf); in ext2fs_mmp_reset()
217 errcode_t ext2fs_mmp_update(ext2_filsys fs) in ext2fs_mmp_update() argument
219 return ext2fs_mmp_update2(fs, 0); in ext2fs_mmp_update()
222 errcode_t ext2fs_mmp_clear(ext2_filsys fs) in ext2fs_mmp_clear() argument
227 if (!(fs->flags & EXT2_FLAG_RW)) in ext2fs_mmp_clear()
230 retval = ext2fs_mmp_reset(fs); in ext2fs_mmp_clear()
238 errcode_t ext2fs_mmp_init(ext2_filsys fs) in ext2fs_mmp_init() argument
241 struct ext2_super_block *sb = fs->super; in ext2fs_mmp_init()
251 if (fs->mmp_buf == NULL) { in ext2fs_mmp_init()
252 retval = ext2fs_get_mem(fs->blocksize, &fs->mmp_buf); in ext2fs_mmp_init()
257 retval = ext2fs_alloc_block2(fs, 0, fs->mmp_buf, &mmp_block); in ext2fs_mmp_init()
263 retval = ext2fs_mmp_reset(fs); in ext2fs_mmp_init()
281 errcode_t ext2fs_mmp_start(ext2_filsys fs) in ext2fs_mmp_start() argument
289 if (fs->mmp_buf == NULL) { in ext2fs_mmp_start()
290 retval = ext2fs_get_mem(fs->blocksize, &fs->mmp_buf); in ext2fs_mmp_start()
295 retval = ext2fs_mmp_read(fs, fs->super->s_mmp_block, fs->mmp_buf); in ext2fs_mmp_start()
299 mmp_s = fs->mmp_buf; in ext2fs_mmp_start()
301 mmp_check_interval = fs->super->s_mmp_update_interval; in ext2fs_mmp_start()
327 retval = ext2fs_mmp_read(fs, fs->super->s_mmp_block, fs->mmp_buf); in ext2fs_mmp_start()
337 if (!(fs->flags & EXT2_FLAG_RW)) in ext2fs_mmp_start()
346 strncpy(mmp_s->mmp_bdevname, fs->device_name, in ext2fs_mmp_start()
349 retval = ext2fs_mmp_write(fs, fs->super->s_mmp_block, fs->mmp_buf); in ext2fs_mmp_start()
355 retval = ext2fs_mmp_read(fs, fs->super->s_mmp_block, fs->mmp_buf); in ext2fs_mmp_start()
365 retval = ext2fs_mmp_write(fs, fs->super->s_mmp_block, fs->mmp_buf); in ext2fs_mmp_start()
384 errcode_t ext2fs_mmp_stop(ext2_filsys fs) in ext2fs_mmp_stop() argument
390 if (!ext2fs_has_feature_mmp(fs->super) || in ext2fs_mmp_stop()
391 !(fs->flags & EXT2_FLAG_RW) || (fs->flags & EXT2_FLAG_SKIP_MMP)) in ext2fs_mmp_stop()
394 retval = ext2fs_mmp_read(fs, fs->super->s_mmp_block, fs->mmp_buf); in ext2fs_mmp_stop()
399 mmp = fs->mmp_buf; in ext2fs_mmp_stop()
400 mmp_cmp = fs->mmp_cmp; in ext2fs_mmp_stop()
407 retval = ext2fs_mmp_write(fs, fs->super->s_mmp_block, fs->mmp_cmp); in ext2fs_mmp_stop()
410 if (fs->mmp_fd > 0) { in ext2fs_mmp_stop()
411 close(fs->mmp_fd); in ext2fs_mmp_stop()
412 fs->mmp_fd = -1; in ext2fs_mmp_stop()
417 if (!ext2fs_has_feature_mmp(fs->super) || in ext2fs_mmp_stop()
418 !(fs->flags & EXT2_FLAG_RW) || (fs->flags & EXT2_FLAG_SKIP_MMP)) in ext2fs_mmp_stop()
430 errcode_t ext2fs_mmp_update2(ext2_filsys fs, int immediately) in ext2fs_mmp_update2() argument
437 if (!ext2fs_has_feature_mmp(fs->super) || in ext2fs_mmp_update2()
438 !(fs->flags & EXT2_FLAG_RW) || (fs->flags & EXT2_FLAG_SKIP_MMP)) in ext2fs_mmp_update2()
443 tv.tv_sec - fs->mmp_last_written < EXT2_MIN_MMP_UPDATE_INTERVAL) in ext2fs_mmp_update2()
446 retval = ext2fs_mmp_read(fs, fs->super->s_mmp_block, NULL); in ext2fs_mmp_update2()
450 mmp = fs->mmp_buf; in ext2fs_mmp_update2()
451 mmp_cmp = fs->mmp_cmp; in ext2fs_mmp_update2()
458 retval = ext2fs_mmp_write(fs, fs->super->s_mmp_block, fs->mmp_buf); in ext2fs_mmp_update2()
463 if (!ext2fs_has_feature_mmp(fs->super) || in ext2fs_mmp_update2()
464 !(fs->flags & EXT2_FLAG_RW) || (fs->flags & EXT2_FLAG_SKIP_MMP)) in ext2fs_mmp_update2()