Mageia Bugzilla – Attachment 2803 Details for
Bug 6323
firmware are not loaded due to relying on shell
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
New Account
|
Forgot Password
C firmware loader, based on hotplug2 code
hotplug.c (text/plain), 2.29 KB, created by
Thierry Vignaud
on 2012-09-16 18:16:36 CEST
(
hide
)
Description:
C firmware loader, based on hotplug2 code
Filename:
MIME Type:
Creator:
Thierry Vignaud
Created:
2012-09-16 18:16:36 CEST
Size:
2.29 KB
patch
obsolete
>/* > * Firmware loader > * Base on hotplug2 code (GPL v2) (http://code.google.com/p/hotplug2/) > * Copyright stepan@davidovic.cz, iSteve <isteve@bofh.cz> Tomas Janousek <tomi@nomi.cz> > */ > >#include <sys/types.h> >#include <sys/param.h> >#include <unistd.h> >#include <stdio.h> >#include <stdlib.h> > >/** > * Function supplementing 'echo > file' > * > * @1 File to be written to > * @2 Data to be written > * @3 Data size > * > * Returns: 0 on success, -1 on failure. > */ >static int echo_to_file(const char *filename, const char *data, size_t size) { > FILE *fp; > size_t written; > > fp = fopen(filename, "w"); > if (fp == NULL) > return -1; > written = fwrite(data, size, 1, fp); > fclose(fp); > > return (written == size) ? 0 : -1; >} > > >int main(int argc, char **argv) { > char buffer[1024]; > char *devpath; > char *firmware; > char firmware_path[PATH_MAX]; > char sysfs_path_loading[PATH_MAX]; > char sysfs_path_data[PATH_MAX]; > int rv; > FILE *infp, *outfp; > size_t inlen, outlen; > > devpath = getenv("DEVPATH"); > if (devpath == NULL) > return -1; > > firmware = getenv("FIRMWARE"); > if (firmware == NULL) > return -1; > > if (snprintf(sysfs_path_loading, PATH_MAX, "/sysfs%s/loading", devpath) >= PATH_MAX) > return -1; > if (snprintf(sysfs_path_data, PATH_MAX, "/sysfs%s/data", devpath) >= PATH_MAX) > return -1; > if (snprintf(firmware_path, PATH_MAX, "%s/%s", argv[0], firmware) >= PATH_MAX) > return -1; > > echo_to_file(sysfs_path_loading, "1\n", 2); > > infp = fopen(firmware_path, "r"); > if (infp == NULL) { > echo_to_file(sysfs_path_loading, "0\n", 2); > return -1; > } > outfp = fopen(sysfs_path_data, "w"); > if (outfp == NULL) { > fclose(infp); > echo_to_file(sysfs_path_loading, "0\n", 2); > return -1; > } > > rv = 0; > while ((inlen = fread(buffer, 1, 1024, infp)) > 0) { > outlen = fwrite(buffer, 1, inlen, outfp); > if (outlen != inlen) { > rv = -1; > break; > } > } > > fclose(infp); > return rv; >}
/* * Firmware loader * Base on hotplug2 code (GPL v2) (http://code.google.com/p/hotplug2/) * Copyright stepan@davidovic.cz, iSteve <isteve@bofh.cz> Tomas Janousek <tomi@nomi.cz> */ #include <sys/types.h> #include <sys/param.h> #include <unistd.h> #include <stdio.h> #include <stdlib.h> /** * Function supplementing 'echo > file' * * @1 File to be written to * @2 Data to be written * @3 Data size * * Returns: 0 on success, -1 on failure. */ static int echo_to_file(const char *filename, const char *data, size_t size) { FILE *fp; size_t written; fp = fopen(filename, "w"); if (fp == NULL) return -1; written = fwrite(data, size, 1, fp); fclose(fp); return (written == size) ? 0 : -1; } int main(int argc, char **argv) { char buffer[1024]; char *devpath; char *firmware; char firmware_path[PATH_MAX]; char sysfs_path_loading[PATH_MAX]; char sysfs_path_data[PATH_MAX]; int rv; FILE *infp, *outfp; size_t inlen, outlen; devpath = getenv("DEVPATH"); if (devpath == NULL) return -1; firmware = getenv("FIRMWARE"); if (firmware == NULL) return -1; if (snprintf(sysfs_path_loading, PATH_MAX, "/sysfs%s/loading", devpath) >= PATH_MAX) return -1; if (snprintf(sysfs_path_data, PATH_MAX, "/sysfs%s/data", devpath) >= PATH_MAX) return -1; if (snprintf(firmware_path, PATH_MAX, "%s/%s", argv[0], firmware) >= PATH_MAX) return -1; echo_to_file(sysfs_path_loading, "1\n", 2); infp = fopen(firmware_path, "r"); if (infp == NULL) { echo_to_file(sysfs_path_loading, "0\n", 2); return -1; } outfp = fopen(sysfs_path_data, "w"); if (outfp == NULL) { fclose(infp); echo_to_file(sysfs_path_loading, "0\n", 2); return -1; } rv = 0; while ((inlen = fread(buffer, 1, 1024, infp)) > 0) { outlen = fwrite(buffer, 1, inlen, outfp); if (outlen != inlen) { rv = -1; break; } } fclose(infp); return rv; }
View Attachment As Raw
Actions:
View
Attachments on
bug 6323
: 2803 |
2807
|
2808