Browse Source

[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 years ago
parent
commit
57fa0db03f
2 changed files with 29 additions and 10 deletions
  1. 28
    10
      src/core/image.c
  2. 1
    0
      src/include/ipxe/image.h

+ 28
- 10
src/core/image.c View File

88
  * @ret image		Executable image
88
  * @ret image		Executable image
89
  */
89
  */
90
 struct image * alloc_image ( struct uri *uri ) {
90
 struct image * alloc_image ( struct uri *uri ) {
91
-	const char *name;
92
 	struct image *image;
91
 	struct image *image;
93
 	int rc;
92
 	int rc;
94
 
93
 
99
 
98
 
100
 	/* Initialise image */
99
 	/* Initialise image */
101
 	ref_init ( &image->refcnt, free_image );
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
 	return image;
104
 	return image;
112
 
105
 
113
- err_set_name:
106
+ err_set_uri:
114
 	image_put ( image );
107
 	image_put ( image );
115
  err_alloc:
108
  err_alloc:
116
 	return NULL;
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
  * Set image name
138
  * Set image name
121
  *
139
  *

+ 1
- 0
src/include/ipxe/image.h View File

158
 }
158
 }
159
 
159
 
160
 extern struct image * alloc_image ( struct uri *uri );
160
 extern struct image * alloc_image ( struct uri *uri );
161
+extern int image_set_uri ( struct image *image, struct uri *uri );
161
 extern int image_set_name ( struct image *image, const char *name );
162
 extern int image_set_name ( struct image *image, const char *name );
162
 extern int image_set_cmdline ( struct image *image, const char *cmdline );
163
 extern int image_set_cmdline ( struct image *image, const char *cmdline );
163
 extern int register_image ( struct image *image );
164
 extern int register_image ( struct image *image );

Loading…
Cancel
Save