summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlasdair Kergon <agk@redhat.com>2006-02-03 14:23:22 +0000
committerAlasdair Kergon <agk@redhat.com>2006-02-03 14:23:22 +0000
commited036598a9d37d1f1f24a1e91e7f2adf463ff9eb (patch)
treedf9573f7bf5834639c91dcd2c43c622b257961bc
parent160bb70cdfb1a6cc59a0d3e6386da13c6aadf9af (diff)
downloadlvm2-ed036598a9d37d1f1f24a1e91e7f2adf463ff9eb.tar.gz
Add exported functions to set uid, gid and mode. [Bastian Blank]v1_02_03old-v1_02_03
-rw-r--r--WHATS_NEW_DM1
-rw-r--r--libdm/.exported_symbols3
-rw-r--r--libdm/ioctl/libdm-iface.c3
-rw-r--r--libdm/libdevmapper.h3
-rw-r--r--libdm/libdm-common.c21
-rw-r--r--tools/dmsetup.c31
6 files changed, 61 insertions, 1 deletions
diff --git a/WHATS_NEW_DM b/WHATS_NEW_DM
index 13ff87640..f599a57df 100644
--- a/WHATS_NEW_DM
+++ b/WHATS_NEW_DM
@@ -1,5 +1,6 @@
Version 1.02.03 -
============================
+ Add exported functions to set uid, gid and mode.
Rename _log to dm_log and export.
Add dm_tree_skip_lockfs.
Fix dm_strdup debug definition.
diff --git a/libdm/.exported_symbols b/libdm/.exported_symbols
index a513d6b06..9b398f207 100644
--- a/libdm/.exported_symbols
+++ b/libdm/.exported_symbols
@@ -23,6 +23,9 @@ dm_task_set_major
dm_task_set_minor
dm_task_set_sector
dm_task_set_message
+dm_task_set_uid
+dm_task_set_gid
+dm_task_set_mode
dm_task_suppress_identical_reload
dm_task_add_target
dm_task_no_open_count
diff --git a/libdm/ioctl/libdm-iface.c b/libdm/ioctl/libdm-iface.c
index 79f9d6fe5..31359b976 100644
--- a/libdm/ioctl/libdm-iface.c
+++ b/libdm/ioctl/libdm-iface.c
@@ -1311,6 +1311,9 @@ static int _create_and_load_v4(struct dm_task *dmt)
task->major = dmt->major;
task->minor = dmt->minor;
+ task->uid = dmt->uid;
+ task->gid = dmt->gid;
+ task->mode = dmt->mode;
r = dm_task_run(task);
dm_task_destroy(task);
diff --git a/libdm/libdevmapper.h b/libdm/libdevmapper.h
index e19c1f9b2..543cb7d43 100644
--- a/libdm/libdevmapper.h
+++ b/libdm/libdevmapper.h
@@ -141,6 +141,9 @@ int dm_task_set_ro(struct dm_task *dmt);
int dm_task_set_newname(struct dm_task *dmt, const char *newname);
int dm_task_set_minor(struct dm_task *dmt, int minor);
int dm_task_set_major(struct dm_task *dmt, int major);
+int dm_task_set_uid(struct dm_task *dmt, uid_t uid);
+int dm_task_set_gid(struct dm_task *dmt, gid_t gid);
+int dm_task_set_mode(struct dm_task *dmt, mode_t mode);
int dm_task_set_event_nr(struct dm_task *dmt, uint32_t event_nr);
int dm_task_set_message(struct dm_task *dmt, const char *message);
int dm_task_set_sector(struct dm_task *dmt, uint64_t sector);
diff --git a/libdm/libdm-common.c b/libdm/libdm-common.c
index df4eb78ad..c27c077e9 100644
--- a/libdm/libdm-common.c
+++ b/libdm/libdm-common.c
@@ -181,6 +181,27 @@ int dm_task_set_minor(struct dm_task *dmt, int minor)
return 1;
}
+int dm_task_set_uid(struct dm_task *dmt, uid_t uid)
+{
+ dmt->uid = uid;
+
+ return 1;
+}
+
+int dm_task_set_gid(struct dm_task *dmt, gid_t gid)
+{
+ dmt->gid = gid;
+
+ return 1;
+}
+
+int dm_task_set_mode(struct dm_task *dmt, mode_t mode)
+{
+ dmt->mode = mode;
+
+ return 1;
+}
+
int dm_task_add_target(struct dm_task *dmt, uint64_t start, uint64_t size,
const char *ttype, const char *params)
{
diff --git a/tools/dmsetup.c b/tools/dmsetup.c
index 90c4b4619..60421f868 100644
--- a/tools/dmsetup.c
+++ b/tools/dmsetup.c
@@ -86,8 +86,10 @@ enum {
READ_ONLY = 0,
COLS_ARG,
EXEC_ARG,
+ GID_ARG,
MAJOR_ARG,
MINOR_ARG,
+ MODE_ARG,
NOHEADINGS_ARG,
NOLOCKFS_ARG,
NOOPENCOUNT_ARG,
@@ -95,6 +97,7 @@ enum {
OPTIONS_ARG,
TARGET_ARG,
TREE_ARG,
+ UID_ARG,
UUID_ARG,
VERBOSE_ARG,
VERSION_ARG,
@@ -390,6 +393,15 @@ static int _create(int argc, char **argv, void *data)
if (_switches[MINOR_ARG] && !dm_task_set_minor(dmt, _values[MINOR_ARG]))
goto out;
+ if (_switches[UID_ARG] && !dm_task_set_uid(dmt, _values[UID_ARG]))
+ goto out;
+
+ if (_switches[GID_ARG] && !dm_task_set_gid(dmt, _values[GID_ARG]))
+ goto out;
+
+ if (_switches[MODE_ARG] && !dm_task_set_mode(dmt, _values[MODE_ARG]))
+ goto out;
+
if (_switches[NOOPENCOUNT_ARG] && !dm_task_no_open_count(dmt))
goto out;
@@ -1293,6 +1305,7 @@ struct command {
static struct command _commands[] = {
{"create", "<dev_name> [-j|--major <major> -m|--minor <minor>]\n"
+ "\t [-U|--uid <uid>] [-G|--gid <gid>] [-M|--mode <octal_mode>]\n"
"\t [-u|uuid <uuid>] [--notable] [<table_file>]",
1, 2, _create},
{"remove", "<device>", 0, 1, _remove},
@@ -1419,8 +1432,10 @@ static int _process_switches(int *argc, char ***argv)
{"readonly", 0, &ind, READ_ONLY},
{"columns", 0, &ind, COLS_ARG},
{"exec", 1, &ind, EXEC_ARG},
+ {"gid", 1, &ind, GID_ARG},
{"major", 1, &ind, MAJOR_ARG},
{"minor", 1, &ind, MINOR_ARG},
+ {"mode", 1, &ind, MODE_ARG},
{"noheadings", 0, &ind, NOHEADINGS_ARG},
{"nolockfs", 0, &ind, NOLOCKFS_ARG},
{"noopencount", 0, &ind, NOOPENCOUNT_ARG},
@@ -1428,6 +1443,7 @@ static int _process_switches(int *argc, char ***argv)
{"options", 1, &ind, OPTIONS_ARG},
{"target", 1, &ind, TARGET_ARG},
{"tree", 0, &ind, TREE_ARG},
+ {"uid", 1, &ind, UID_ARG},
{"uuid", 1, &ind, UUID_ARG},
{"verbose", 1, &ind, VERBOSE_ARG},
{"version", 0, &ind, VERSION_ARG},
@@ -1479,7 +1495,7 @@ static int _process_switches(int *argc, char ***argv)
optarg = 0;
optind = OPTIND_INIT;
- while ((ind = -1, c = GETOPTLONG_FN(*argc, *argv, "cCj:m:no:ru:v",
+ while ((ind = -1, c = GETOPTLONG_FN(*argc, *argv, "cCGj:m:Mno:ru:Uv",
long_options, NULL)) != -1) {
if (c == 'c' || c == 'C' || ind == COLS_ARG)
_switches[COLS_ARG]++;
@@ -1505,6 +1521,19 @@ static int _process_switches(int *argc, char ***argv)
_switches[UUID_ARG]++;
_uuid = optarg;
}
+ if (c == 'G' || ind == GID_ARG) {
+ _switches[GID_ARG]++;
+ _values[GID_ARG] = atoi(optarg);
+ }
+ if (c == 'U' || ind == UID_ARG) {
+ _switches[UID_ARG]++;
+ _values[UID_ARG] = atoi(optarg);
+ }
+ if (c == 'M' || ind == MODE_ARG) {
+ _switches[MODE_ARG]++;
+ /* FIXME Accept modes as per chmod */
+ _values[MODE_ARG] = (int) strtol(optarg, NULL, 8);
+ }
if ((ind == EXEC_ARG)) {
_switches[EXEC_ARG]++;
_command = optarg;