From 43ec8734f2ecd0a345e831f45fd3dfb077426811 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Wed, 3 Jan 2001 14:56:46 +0000 Subject: [PATCH] ChangeLog, ext2fs.h, ismounted.c: ismounted.c: add ext2fs_check_mount_point() function, which will optionally return the mount point of a device if mounted ChangeLog, closefs.c, ext2fs.h: ext2fs.h, closefs.c (ext2fs_flush): Add new flag, EXT2_FLAG_SUPER_ONLY, which the close routines to only update the superblock, and not the group descriptors. --- lib/ext2fs/ChangeLog | 11 +++++++++++ lib/ext2fs/closefs.c | 2 ++ lib/ext2fs/ext2fs.h | 3 +++ lib/ext2fs/ismounted.c | 47 ++++++++++++++++++++++++++++++++++++++++------- 4 files changed, 56 insertions(+), 7 deletions(-) diff --git a/lib/ext2fs/ChangeLog b/lib/ext2fs/ChangeLog index 64261c2..f89bdd9 100644 --- a/lib/ext2fs/ChangeLog +++ b/lib/ext2fs/ChangeLog @@ -1,3 +1,14 @@ +2001-01-03 + + * ext2fs.h, closefs.c (ext2fs_flush): Add new flag, + EXT2_FLAG_SUPER_ONLY, which the close routines to only + update the superblock, and not the group descriptors. + +2000-12-30 Andreas Dilger + + * ismounted.c: add ext2fs_check_mount_point() function, which will + optionally return the mount point of a device if mounted + 2000-12-14 Andreas Dilger * mkjournal.c: rename ext2fs_add_journal_fs() to the more descriptive diff --git a/lib/ext2fs/closefs.c b/lib/ext2fs/closefs.c index e12f57f..9e12550 100644 --- a/lib/ext2fs/closefs.c +++ b/lib/ext2fs/closefs.c @@ -209,6 +209,8 @@ errcode_t ext2fs_flush(ext2_filsys fs) if (retval) goto errout; } + if (fs->flags & EXT2_FLAG_SUPER_ONLY) + goto next_group; group_ptr = (char *) group_shadow; for (j=0; j < fs->desc_blocks; j++) { retval = io_channel_write_blk(fs->io, diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h index be2c534..c4b53d7 100644 --- a/lib/ext2fs/ext2fs.h +++ b/lib/ext2fs/ext2fs.h @@ -171,6 +171,7 @@ typedef struct ext2_file *ext2_file_t; #define EXT2_FLAG_SWAP_BYTES_WRITE 0x100 #define EXT2_FLAG_MASTER_SB_ONLY 0x200 #define EXT2_FLAG_FORCE 0x400 +#define EXT2_FLAG_SUPER_ONLY 0x800 /* * Special flag in the ext2 inode i_flag field that means that this is @@ -687,6 +688,8 @@ errcode_t ext2fs_icount_validate(ext2_icount_t icount, FILE *); /* ismounted.c */ extern errcode_t ext2fs_check_if_mounted(const char *file, int *mount_flags); +extern errcode_t ext2fs_check_mount_point(const char *device, int *mount_flags, + char *mtpt, int mtlen); /* namei.c */ extern errcode_t ext2fs_lookup(ext2_filsys fs, ino_t dir, const char *name, diff --git a/lib/ext2fs/ismounted.c b/lib/ext2fs/ismounted.c index fc66d48..95bf953 100644 --- a/lib/ext2fs/ismounted.c +++ b/lib/ext2fs/ismounted.c @@ -39,10 +39,12 @@ #ifdef HAVE_MNTENT_H /* - * XXX we only check to see if the mount is readonly when it's the - * root filesystem. + * XXX we assume that /etc/mtab is located on the root filesystem, and + * we only check to see if the mount is readonly for the root + * filesystem. */ -static errcode_t check_mntent(const char *file, int *mount_flags) +static errcode_t check_mntent(const char *file, int *mount_flags, + char *mtpt, int mtlen) { FILE * f; struct mntent * mnt; @@ -68,12 +70,15 @@ static errcode_t check_mntent(const char *file, int *mount_flags) } else close(fd); } + if (mtpt) + strncpy(mtpt, mnt->mnt_dir, mtlen); return 0; } #endif #ifdef HAVE_GETMNTINFO -static errcode_t check_getmntinfo(const char *file, int *mount_flags) +static errcode_t check_getmntinfo(const char *file, int *mount_flags, + char *mtpt, int mtlen) { struct statfs *mp; int len, n; @@ -102,12 +107,40 @@ static errcode_t check_getmntinfo(const char *file, int *mount_flags) } ++mp; } + if (mtpt) + strncpy(mtpt, mp->f_mntonname, mtlen); return 0; } #endif /* HAVE_GETMNTINFO */ /* - * Is_mounted is set to 1 if the device is mounted, 0 otherwise + * ext2fs_check_mount_point() returns 1 if the device is mounted, 0 + * otherwise. If mtpt is non-NULL, the directory where the device is + * mounted is copied to where mtpt is pointing, up to mtlen + * characters. + */ +#ifdef __TURBOC__ +#pragma argsused +#endif +errcode_t ext2fs_check_mount_point(const char *device, int *mount_flags, + char *mtpt, int mtlen) +{ +#ifdef HAVE_MNTENT_H + return check_mntent(device, mount_flags, mtpt, mtlen); +#else +#ifdef HAVE_GETMNTINFO + return check_getmntinfo(device, mount_flags, mtpt, mtlen); +#else + *mount_flags = 0; + return 0; +#endif /* HAVE_GETMNTINFO */ +#endif /* HAVE_MNTENT_H */ +} + +/* + * ext2fs_check_if_mounted() sets the mount_flags EXT2_MF_MOUNTED and + * EXT2_MF_READONLY + * */ #ifdef __TURBOC__ #pragma argsused @@ -115,10 +148,10 @@ static errcode_t check_getmntinfo(const char *file, int *mount_flags) errcode_t ext2fs_check_if_mounted(const char *file, int *mount_flags) { #ifdef HAVE_MNTENT_H - return check_mntent(file, mount_flags); + return check_mntent(file, mount_flags, NULL, 0); #else #ifdef HAVE_GETMNTINFO - return check_getmntinfo(file, mount_flags); + return check_getmntinfo(file, mount_flags, NULL, 0); #else *mount_flags = 0; return 0; -- 1.8.3.1