diff options
author | Artem Bityutskiy <Artem.Bityutskiy@nokia.com> | 2010-01-05 09:48:40 -0500 |
---|---|---|
committer | Artem Bityutskiy <Artem.Bityutskiy@nokia.com> | 2010-02-01 08:16:36 -0500 |
commit | f9b0080e10e0ce3b8acbe91ae6a50da4f2ed7339 (patch) | |
tree | 7f9f45f0e689b1e3a84bdf944c166ce206563caf /drivers/mtd | |
parent | 9e0c7ef3f6c95357ce359a4f9223f0dfcd21cef7 (diff) |
UBI: support attaching by MTD character device name
This patch adds a capability to attach MTD devices by their character
device paths. For example, one can do:
$ modprobe ubi mtd=/dev/mtd0
to attach /dev/mtd0.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Diffstat (limited to 'drivers/mtd')
-rw-r--r-- | drivers/mtd/ubi/build.c | 66 |
1 files changed, 55 insertions, 11 deletions
diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c index eb8f19f87c68..99ff57d3ac68 100644 --- a/drivers/mtd/ubi/build.c +++ b/drivers/mtd/ubi/build.c | |||
@@ -37,6 +37,7 @@ | |||
37 | #include <linux/module.h> | 37 | #include <linux/module.h> |
38 | #include <linux/moduleparam.h> | 38 | #include <linux/moduleparam.h> |
39 | #include <linux/stringify.h> | 39 | #include <linux/stringify.h> |
40 | #include <linux/namei.h> | ||
40 | #include <linux/stat.h> | 41 | #include <linux/stat.h> |
41 | #include <linux/miscdevice.h> | 42 | #include <linux/miscdevice.h> |
42 | #include <linux/log2.h> | 43 | #include <linux/log2.h> |
@@ -50,7 +51,8 @@ | |||
50 | 51 | ||
51 | /** | 52 | /** |
52 | * struct mtd_dev_param - MTD device parameter description data structure. | 53 | * struct mtd_dev_param - MTD device parameter description data structure. |
53 | * @name: MTD device name or number string | 54 | * @name: MTD character device node path, MTD device name, or MTD device number |
55 | * string | ||
54 | * @vid_hdr_offs: VID header offset | 56 | * @vid_hdr_offs: VID header offset |
55 | */ | 57 | */ |
56 | struct mtd_dev_param { | 58 | struct mtd_dev_param { |
@@ -1116,13 +1118,50 @@ int ubi_detach_mtd_dev(int ubi_num, int anyway) | |||
1116 | } | 1118 | } |
1117 | 1119 | ||
1118 | /** | 1120 | /** |
1119 | * find_mtd_device - open an MTD device by its name or number. | 1121 | * open_mtd_by_chdev - open an MTD device by its character device node path. |
1120 | * @mtd_dev: name or number of the device | 1122 | * @mtd_dev: MTD character device node path |
1123 | * | ||
1124 | * This helper function opens an MTD device by its character node device path. | ||
1125 | * Returns MTD device description object in case of success and a negative | ||
1126 | * error code in case of failure. | ||
1127 | */ | ||
1128 | static struct mtd_info * __init open_mtd_by_chdev(const char *mtd_dev) | ||
1129 | { | ||
1130 | int err, major, minor, mode; | ||
1131 | struct path path; | ||
1132 | |||
1133 | /* Probably this is an MTD character device node path */ | ||
1134 | err = kern_path(mtd_dev, LOOKUP_FOLLOW, &path); | ||
1135 | if (err) | ||
1136 | return ERR_PTR(err); | ||
1137 | |||
1138 | /* MTD device number is defined by the major / minor numbers */ | ||
1139 | major = imajor(path.dentry->d_inode); | ||
1140 | minor = iminor(path.dentry->d_inode); | ||
1141 | mode = path.dentry->d_inode->i_mode; | ||
1142 | path_put(&path); | ||
1143 | if (major != MTD_CHAR_MAJOR || !S_ISCHR(mode)) | ||
1144 | return ERR_PTR(-EINVAL); | ||
1145 | |||
1146 | if (minor & 1) | ||
1147 | /* | ||
1148 | * Just do not think the "/dev/mtdrX" devices support is need, | ||
1149 | * so do not support them to avoid doing extra work. | ||
1150 | */ | ||
1151 | return ERR_PTR(-EINVAL); | ||
1152 | |||
1153 | return get_mtd_device(NULL, minor / 2); | ||
1154 | } | ||
1155 | |||
1156 | /** | ||
1157 | * open_mtd_device - open MTD device by name, character device path, or number. | ||
1158 | * @mtd_dev: name, character device node path, or MTD device device number | ||
1121 | * | 1159 | * |
1122 | * This function tries to open and MTD device described by @mtd_dev string, | 1160 | * This function tries to open and MTD device described by @mtd_dev string, |
1123 | * which is first treated as an ASCII number, and if it is not true, it is | 1161 | * which is first treated as ASCII MTD device number, and if it is not true, it |
1124 | * treated as MTD device name. Returns MTD device description object in case of | 1162 | * is treated as MTD device name, and if that is also not true, it is treated |
1125 | * success and a negative error code in case of failure. | 1163 | * as MTD character device node path. Returns MTD device description object in |
1164 | * case of success and a negative error code in case of failure. | ||
1126 | */ | 1165 | */ |
1127 | static struct mtd_info * __init open_mtd_device(const char *mtd_dev) | 1166 | static struct mtd_info * __init open_mtd_device(const char *mtd_dev) |
1128 | { | 1167 | { |
@@ -1137,6 +1176,9 @@ static struct mtd_info * __init open_mtd_device(const char *mtd_dev) | |||
1137 | * MTD device name. | 1176 | * MTD device name. |
1138 | */ | 1177 | */ |
1139 | mtd = get_mtd_device_nm(mtd_dev); | 1178 | mtd = get_mtd_device_nm(mtd_dev); |
1179 | if (IS_ERR(mtd) && PTR_ERR(mtd) == -ENODEV) | ||
1180 | /* Probably this is an MTD character device node path */ | ||
1181 | mtd = open_mtd_by_chdev(mtd_dev); | ||
1140 | } else | 1182 | } else |
1141 | mtd = get_mtd_device(NULL, mtd_num); | 1183 | mtd = get_mtd_device(NULL, mtd_num); |
1142 | 1184 | ||
@@ -1352,13 +1394,15 @@ static int __init ubi_mtd_param_parse(const char *val, struct kernel_param *kp) | |||
1352 | 1394 | ||
1353 | module_param_call(mtd, ubi_mtd_param_parse, NULL, NULL, 000); | 1395 | module_param_call(mtd, ubi_mtd_param_parse, NULL, NULL, 000); |
1354 | MODULE_PARM_DESC(mtd, "MTD devices to attach. Parameter format: " | 1396 | MODULE_PARM_DESC(mtd, "MTD devices to attach. Parameter format: " |
1355 | "mtd=<name|num>[,<vid_hdr_offs>].\n" | 1397 | "mtd=<name|num|path>[,<vid_hdr_offs>].\n" |
1356 | "Multiple \"mtd\" parameters may be specified.\n" | 1398 | "Multiple \"mtd\" parameters may be specified.\n" |
1357 | "MTD devices may be specified by their number or name.\n" | 1399 | "MTD devices may be specified by their number, name, or " |
1400 | "path to the MTD character device node.\n" | ||
1358 | "Optional \"vid_hdr_offs\" parameter specifies UBI VID " | 1401 | "Optional \"vid_hdr_offs\" parameter specifies UBI VID " |
1359 | "header position and data starting position to be used " | 1402 | "header position to be used by UBI.\n" |
1360 | "by UBI.\n" | 1403 | "Example 1: mtd=/dev/mtd0 - attach MTD device " |
1361 | "Example: mtd=content,1984 mtd=4 - attach MTD device" | 1404 | "/dev/mtd0.\n" |
1405 | "Example 2: mtd=content,1984 mtd=4 - attach MTD device " | ||
1362 | "with name \"content\" using VID header offset 1984, and " | 1406 | "with name \"content\" using VID header offset 1984, and " |
1363 | "MTD device number 4 with default VID header offset."); | 1407 | "MTD device number 4 with default VID header offset."); |
1364 | 1408 | ||