N_("@S metadata_csum_seed is not necessary without metadata_csum."),
PROMPT_FIX, PR_PREEN_OK | PR_NO_OK},
+ /* Error initializing quota context */
+ { PR_0_QUOTA_INIT_CTX,
+ N_("Error initializing quota context in support library: %m\n"),
+ PROMPT_NULL, PR_FATAL },
+
/* Pass 1 errors */
/* Pass 1: Checking inodes, blocks, and sizes */
N_("Error flushing writes to storage device: %m\n"),
PROMPT_NULL, PR_FATAL },
+ /* Error writing quota information */
+ { PR_6_WRITE_QUOTAS,
+ N_("Error writing quota info for quota type %N: %m\n"),
+ PROMPT_NULL, 0 },
+
{ 0 }
};
/* metadata_csum_seed means nothing without metadata_csum */
#define PR_0_CSUM_SEED_WITHOUT_META_CSUM 0x00004B
+/* Error initializing quota context */
+#define PR_0_QUOTA_INIT_CTX 0x00004C
+
+
/*
* Pass 1 errors
*/
/* Error flushing writes to storage device */
#define PR_6_IO_FLUSH 0x060005
+/* Error updating quota information */
+#define PR_6_WRITE_QUOTAS 0x060006
+
+
/*
* Function declarations
*/
qtype_bits |= 1 << qtype;
}
- quota_init_context(&ctx->qctx, ctx->fs, qtype_bits);
+ clear_problem_context(&pctx);
+ pctx.errcode = quota_init_context(&ctx->qctx, ctx->fs,
+ qtype_bits);
+ if (pctx.errcode) {
+ fix_problem(ctx, PR_0_QUOTA_INIT_CTX, &pctx);
+ fatal_error(ctx, 0);
+ }
}
run_result = e2fsck_run(ctx);
retval = quota_compare_and_update(ctx->qctx, qtype,
&needs_writeout);
if ((retval || needs_writeout) &&
- fix_problem(ctx, PR_6_UPDATE_QUOTAS, &pctx))
- quota_write_inode(ctx->qctx, 1 << qtype);
+ fix_problem(ctx, PR_6_UPDATE_QUOTAS, &pctx)) {
+ pctx.errcode = quota_write_inode(ctx->qctx,
+ 1 << qtype);
+ if (pctx.errcode)
+ (void) fix_problem(ctx,
+ PR_6_WRITE_QUOTAS, &pctx);
+ }
}
quota_release_context(&ctx->qctx);
}
fprintf(stderr, "[DEBUG] %s:%d:%s:: " format "\n", \
__FILE__, __LINE__, __func__, ## arg)
#else
-# define log_debug(format, ...)
+# define log_debug(...)
#endif
#endif /* __QUOTA_COMMON_H__ */
retval = ext2fs_read_bitmaps(fs);
if (retval) {
- log_err("Couldn't read bitmaps: %s", error_message(retval));
+ log_debug("Couldn't read bitmaps: %s", error_message(retval));
return retval;
}
+
qf_ino = *quota_sb_inump(fs->super, qtype);
- if (qf_ino < EXT2_FIRST_INODE(fs->super)) {
- quota_inode_truncate(fs, qf_ino);
- } else {
+ if (qf_ino == 0)
+ return 0;
+ retval = quota_inode_truncate(fs, qf_ino);
+ if (retval)
+ return retval;
+ if (qf_ino >= EXT2_FIRST_INODE(fs->super)) {
struct ext2_inode inode;
- quota_inode_truncate(fs, qf_ino);
retval = ext2fs_read_inode(fs, qf_ino, &inode);
if (!retval) {
memset(&inode, 0, sizeof(struct ext2_inode));
fs->flags &= ~EXT2_FLAG_SUPER_ONLY;
retval = ext2fs_write_bitmaps(fs);
if (retval) {
- log_err("Couldn't write bitmaps: %s", error_message(retval));
+ log_debug("Couldn't write bitmaps: %s", error_message(retval));
return retval;
}
return 0;
fs = qctx->fs;
retval = ext2fs_get_mem(sizeof(struct quota_handle), &h);
if (retval) {
- log_err("Unable to allocate quota handle: %s",
+ log_debug("Unable to allocate quota handle: %s",
error_message(retval));
goto out;
}
retval = ext2fs_read_bitmaps(fs);
if (retval) {
- log_err("Couldn't read bitmaps: %s", error_message(retval));
+ log_debug("Couldn't read bitmaps: %s", error_message(retval));
goto out;
}
retval = quota_file_create(h, fs, qtype, fmt);
if (retval < 0) {
- log_err("Cannot initialize io on quotafile");
+ log_debug("Cannot initialize io on quotafile");
continue;
}
strerror(errno));
if (h->qh_qf.e2_file)
ext2fs_file_close(h->qh_qf.e2_file);
- quota_inode_truncate(fs, h->qh_qf.ino);
+ (void) quota_inode_truncate(fs, h->qh_qf.ino);
continue;
}
retval = ext2fs_write_bitmaps(fs);
if (retval) {
- log_err("Couldn't write bitmaps: %s", error_message(retval));
+ log_debug("Couldn't write bitmaps: %s", error_message(retval));
goto out;
}
out:
static inline qid_t get_qid(struct ext2_inode_large *inode, enum quota_type qtype)
{
- int inode_size;
+ unsigned int inode_size;
switch (qtype) {
case USRQUOTA:
err = ext2fs_get_mem(sizeof(struct quota_ctx), &ctx);
if (err) {
- log_err("Failed to allocate quota context");
+ log_debug("Failed to allocate quota context");
return err;
}
continue;
err = ext2fs_get_mem(sizeof(dict_t), &dict);
if (err) {
- log_err("Failed to allocate dictionary");
+ log_debug("Failed to allocate dictionary");
quota_release_context(&ctx);
return err;
}
err = ext2fs_get_mem(sizeof(struct quota_handle), &qh);
if (err) {
- log_err("Unable to allocate quota handle");
+ log_debug("Unable to allocate quota handle");
return err;
}
err = quota_file_open(qctx, qh, qf_ino, qtype, -1, 0);
if (err) {
- log_err("Open quota file failed");
+ log_debug("Open quota file failed");
goto out;
}
err = quota_file_close(qctx, qh);
if (err) {
- log_err("Cannot finish IO on new quotafile: %s",
+ log_debug("Cannot finish IO on new quotafile: %s",
strerror(errno));
if (qh->qh_qf.e2_file)
ext2fs_file_close(qh->qh_qf.e2_file);
err = quota_file_open(qctx, &qh, 0, qtype, -1, 0);
if (err) {
- log_err("Open quota file failed");
+ log_debug("Open quota file failed");
goto out;
}
scan_data.usage_is_inconsistent = 0;
err = qh.qh_ops->scan_dquots(&qh, scan_dquots_callback, &scan_data);
if (err) {
- log_err("Error scanning dquots");
+ log_debug("Error scanning dquots");
goto out_close_qh;
}
out_close_qh:
err = quota_file_close(qctx, &qh);
if (err) {
- log_err("Cannot close quotafile: %s", error_message(errno));
+ log_debug("Cannot close quotafile: %s", error_message(errno));
if (qh.qh_qf.e2_file)
ext2fs_file_close(qh.qh_qf.e2_file);
}
if (!magic_handle)
return 0;
- dl_magic_open = dlsym(magic_handle, "magic_open");
- dl_magic_file = dlsym(magic_handle, "magic_file");
- dl_magic_load = dlsym(magic_handle, "magic_load");
- dl_magic_close = dlsym(magic_handle, "magic_close");
+ dl_magic_open = (magic_t (*)(int))
+ dlsym(magic_handle, "magic_open");
+ dl_magic_file = (const char *(*)(magic_t, const char *))
+ dlsym(magic_handle, "magic_file");
+ dl_magic_load = (int (*)(magic_t, const char *))
+ dlsym(magic_handle, "magic_load");
+ dl_magic_close = (void (*)(magic_t))
+ dlsym(magic_handle, "magic_close");
}
if (!dl_magic_open || !dl_magic_file ||
}
errcode_t
-profile_init(const char **files, profile_t *ret_profile)
+profile_init(const char * const *files, profile_t *ret_profile)
{
- const char **fs;
+ const char * const *fs;
profile_t profile;
prf_file_t new_file, *last;
errcode_t retval = 0;
#endif /* __cplusplus */
long profile_init
- (const char * *files, profile_t *ret_profile);
+ (const char * const *files, profile_t *ret_profile);
void profile_release
(profile_t profile);
#include <et/com_err.h>
#include "profile.h"
+#include "profile_helpers.h"
#include "prof_err.h"
/*
/* cap the array */
filenames[i] = 0;
- retval = profile_init((const char **) filenames,
+ retval = profile_init((const char * const *) filenames,
ret_profile);
/* count back down and free the entries */
return err;
}
- if (EXT2_I_SIZE(&inode))
- quota_inode_truncate(fs, ino);
+ if (EXT2_I_SIZE(&inode)) {
+ err = quota_inode_truncate(fs, ino);
+ if (err)
+ return err;
+ }
memset(&inode, 0, sizeof(struct ext2_inode));
ext2fs_iblk_set(fs, &inode, 0);
enum quota_type qtype, int fmt)
{
ext2_file_t e2_file;
- int err;
+ errcode_t err;
ext2_ino_t qf_inum = 0;
if (fmt == -1)
err = ext2fs_new_inode(fs, EXT2_ROOT_INO, LINUX_S_IFREG | 0600,
0, &qf_inum);
if (err)
- return -1;
+ return err;
ext2fs_inode_alloc_stats2(fs, qf_inum, +1, 0);
ext2fs_mark_ib_dirty(fs);
} else if (qf_inum == 0) {
- return -1;
+ return EXT2_ET_BAD_INODE_NUM;
}
err = ext2fs_read_bitmaps(fs);
log_debug("Creating quota ino=%lu, type=%d", qf_inum, type);
err = ext2fs_file_open(fs, qf_inum, h->qh_file_flags, &e2_file);
if (err) {
- log_err("ext2fs_file_open failed: %d", err);
+ log_err("ext2fs_file_open failed: %ld", err);
goto out_err;
}
h->qh_qf.e2_file = e2_file;
if (h->qh_ops->new_io && (h->qh_ops->new_io(h) < 0)) {
log_err("qh_ops->new_io failed");
+ err = EIO;
goto out_err1;
}
if (qf_inum)
quota_inode_truncate(fs, qf_inum);
- return -1;
+ return err;
}
/*
/* Is given dquot empty? */
int qtree_entry_unused(struct qtree_mem_dqinfo *info, char *disk)
{
- int i;
+ unsigned int i;
for (i = 0; i < info->dqi_entry_size; i++)
if (disk[i])
static unsigned int find_set_bits(char *bmp, int blocks)
{
- unsigned int i, used = 0;
+ unsigned int used = 0;
+ int i;
for (i = 0; i < blocks; i++)
if (get_bit(bmp, i))
static int create_quota_inodes(ext2_filsys fs)
{
quota_ctx_t qctx;
+ errcode_t retval;
- quota_init_context(&qctx, fs, QUOTA_ALL_BIT);
+ retval = quota_init_context(&qctx, fs, QUOTA_ALL_BIT);
+ if (retval) {
+ com_err(program_name, retval,
+ _("while initializing quota context"));
+ exit(1);
+ }
quota_compute_usage(qctx);
- quota_write_inode(qctx, quotatype_bits);
+ retval = quota_write_inode(qctx, quotatype_bits);
+ if (retval) {
+ com_err(program_name, retval,
+ _("while writing quota inodes"));
+ exit(1);
+ }
quota_release_context(&qctx);
return 0;
static void handle_quota_options(ext2_filsys fs)
{
+ errcode_t retval;
quota_ctx_t qctx;
ext2_ino_t qf_ino;
enum quota_type qtype;
/* Nothing to do. */
return;
- quota_init_context(&qctx, fs, QUOTA_ALL_BIT);
+ retval = quota_init_context(&qctx, fs, QUOTA_ALL_BIT);
+ if (retval) {
+ com_err(program_name, retval,
+ _("while initializing quota context in support library"));
+ exit(1);
+ }
for (qtype = 0 ; qtype < MAXQUOTAS; qtype++) {
if (quota_enable[qtype] == QOPT_ENABLE) {
enable = 1;
for (qtype = 0 ; qtype < MAXQUOTAS; qtype++) {
if (quota_enable[qtype] == QOPT_ENABLE &&
*quota_sb_inump(fs->super, qtype) == 0) {
- if ((qf_ino = quota_file_exists(fs, qtype)) > 0)
- quota_update_limits(qctx, qf_ino, qtype);
- quota_write_inode(qctx, 1 << qtype);
+ if ((qf_ino = quota_file_exists(fs, qtype)) > 0) {
+ retval = quota_update_limits(qctx, qf_ino,
+ qtype);
+ if (retval) {
+ com_err(program_name, retval,
+ _("while updating quota limits (%d)"),
+ qtype);
+ exit(1);
+ }
+ }
+ retval = quota_write_inode(qctx, 1 << qtype);
+ if (retval) {
+ com_err(program_name, retval,
+ _("while writing quota file (%d)"),
+ qtype);
+ exit(1);
+ }
} else if (quota_enable[qtype] == QOPT_DISABLE) {
- quota_remove_inode(fs, qtype);
+ retval = quota_remove_inode(fs, qtype);
+ if (retval) {
+ com_err(program_name, retval,
+ _("while removing quota file (%d)"),
+ qtype);
+ exit(1);
+ }
}
}