libquota: remove get_qf_name()

The get_qf_name() function used PATH_MAX, which is non-portable.
Worse, it blindly assumed that PATH_MAX was the size of the buffer
passed to it --- which in the one and only place where it was used in
libquota, was a buffer declared to a fixed size 256 bytes.

Fix this by simply getting rid of the function altogether.

Cc: Aditya Kali <adityakali@google.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
bitmap-optimize
Theodore Ts'o 2011-10-04 11:38:47 -04:00
parent edbfd75d8f
commit 36e4e21f51
5 changed files with 8 additions and 22 deletions

View File

@ -38,7 +38,8 @@ static void move_quota_inode(ext2_filsys fs, ext2_ino_t from_ino,
ext2fs_write_new_inode(fs, to_ino, &inode);
/* unlink the old inode */
get_qf_name(qtype, QFMT_VFS_V1, qf_name);
snprintf(qf_name, sizeof(qf_name), "aquota.%s",
qtype ? "group" : "user");
ext2fs_unlink(fs, EXT2_ROOT_INO, qf_name, from_ino, 0);
ext2fs_inode_alloc_stats(fs, from_ino, -1);
}

View File

@ -65,16 +65,16 @@ int is_quota_on(ext2_filsys fs, int type)
* Returns 0 if not able to find the quota file, otherwise returns its
* inode number.
*/
int quota_file_exists(ext2_filsys fs, int qtype, int fmt)
int quota_file_exists(ext2_filsys fs, int qtype)
{
char qf_name[256];
errcode_t ret;
ext2_ino_t ino;
if (qtype >= MAXQUOTAS || fmt > QFMT_VFS_V1)
if (qtype >= MAXQUOTAS)
return -EINVAL;
get_qf_name(qtype, fmt, qf_name);
snprintf(qf_name, sizeof(qf_name), "aquota.%s", type2name(qtype));
ret = ext2fs_lookup(fs, EXT2_ROOT_INO, qf_name, strlen(qf_name), 0,
&ino);

View File

@ -55,10 +55,7 @@ void release_quota_context(quota_ctx_t *qctx);
errcode_t remove_quota_inode(ext2_filsys fs, int qtype);
int is_quota_on(ext2_filsys fs, int type);
int quota_file_exists(ext2_filsys fs, int qtype, int fmt);
int quota_file_exists(ext2_filsys fs, int qtype);
void set_sb_quota_inum(ext2_filsys fs, ext2_ino_t ino, int qtype);
/* in quotaio.c */
const char *get_qf_name(int type, int fmt, char *buf);
#endif /* __QUOTA_QUOTAIO_H__ */

View File

@ -49,18 +49,6 @@ const char *type2name(int type)
return extensions[type];
}
/**
* Creates a quota file name for given type and format.
*/
const char *get_qf_name(int type, int fmt, char *buf)
{
BUG_ON(!buf);
snprintf(buf, PATH_MAX, "%s.%s",
basenames[fmt], extensions[type]);
return buf;
}
/*
* Set grace time if needed
*/

View File

@ -710,7 +710,7 @@ void handle_quota_options(ext2_filsys fs)
init_quota_context(&qctx, fs, -1);
if (usrquota == QOPT_ENABLE && !fs->super->s_usr_quota_inum) {
if ((qf_ino = quota_file_exists(fs, USRQUOTA, QFMT_VFS_V1)) > 0)
if ((qf_ino = quota_file_exists(fs, USRQUOTA)) > 0)
set_sb_quota_inum(fs, qf_ino, USRQUOTA);
else
write_quota_inode(qctx, USRQUOTA);
@ -719,7 +719,7 @@ void handle_quota_options(ext2_filsys fs)
}
if (grpquota == QOPT_ENABLE && !fs->super->s_grp_quota_inum) {
if ((qf_ino = quota_file_exists(fs, GRPQUOTA, QFMT_VFS_V1)) > 0)
if ((qf_ino = quota_file_exists(fs, GRPQUOTA)) > 0)
set_sb_quota_inum(fs, qf_ino, GRPQUOTA);
else
write_quota_inode(qctx, GRPQUOTA);