浏览代码

[image] Provide image_set_uri() to modify an image's URI

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 9 年前
父节点
当前提交
57fa0db03f
共有 2 个文件被更改,包括 29 次插入10 次删除
  1. 28
    10
      src/core/image.c
  2. 1
    0
      src/include/ipxe/image.h

+ 28
- 10
src/core/image.c 查看文件

@@ -88,7 +88,6 @@ static void free_image ( struct refcnt *refcnt ) {
88 88
  * @ret image		Executable image
89 89
  */
90 90
 struct image * alloc_image ( struct uri *uri ) {
91
-	const char *name;
92 91
 	struct image *image;
93 92
 	int rc;
94 93
 
@@ -99,23 +98,42 @@ struct image * alloc_image ( struct uri *uri ) {
99 98
 
100 99
 	/* Initialise image */
101 100
 	ref_init ( &image->refcnt, free_image );
102
-	if ( uri ) {
103
-		image->uri = uri_get ( uri );
104
-		if ( uri->path ) {
105
-			name = basename ( ( char * ) uri->path );
106
-			if ( ( rc = image_set_name ( image, name ) ) != 0 )
107
-				goto err_set_name;
108
-		}
109
-	}
101
+	if ( uri && ( ( rc = image_set_uri ( image, uri ) ) != 0 ) )
102
+		goto err_set_uri;
110 103
 
111 104
 	return image;
112 105
 
113
- err_set_name:
106
+ err_set_uri:
114 107
 	image_put ( image );
115 108
  err_alloc:
116 109
 	return NULL;
117 110
 }
118 111
 
112
+/**
113
+ * Set image URI
114
+ *
115
+ * @v image		Image
116
+ * @v uri		New image URI
117
+ * @ret rc		Return status code
118
+ */
119
+int image_set_uri ( struct image *image, struct uri *uri ) {
120
+	const char *name;
121
+	int rc;
122
+
123
+	/* Set name, if image does not already have one */
124
+	if ( uri->path && ( ! ( image->name && image->name[0] ) ) ) {
125
+		name = basename ( ( char * ) uri->path );
126
+		if ( ( rc = image_set_name ( image, name ) ) != 0 )
127
+			return rc;
128
+	}
129
+
130
+	/* Update image URI */
131
+	uri_put ( image->uri );
132
+	image->uri = uri_get ( uri );
133
+
134
+	return 0;
135
+}
136
+
119 137
 /**
120 138
  * Set image name
121 139
  *

+ 1
- 0
src/include/ipxe/image.h 查看文件

@@ -158,6 +158,7 @@ static inline struct image * first_image ( void ) {
158 158
 }
159 159
 
160 160
 extern struct image * alloc_image ( struct uri *uri );
161
+extern int image_set_uri ( struct image *image, struct uri *uri );
161 162
 extern int image_set_name ( struct image *image, const char *name );
162 163
 extern int image_set_cmdline ( struct image *image, const char *cmdline );
163 164
 extern int register_image ( struct image *image );

正在加载...
取消
保存