Changeset d9fae235 in mainline for uspace/app/init/init.c
- Timestamp:
- 2010-04-17T01:28:38Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 9d6bfa5
- Parents:
- 9256ad29
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/init/init.c
r9256ad29 rd9fae235 48 48 #include <str.h> 49 49 #include <devmap.h> 50 #include <str_error.h> 50 51 #include "init.h" 51 52 53 #define ROOT_DEVICE "bd/initrd" 54 #define ROOT_MOUNT_POINT "/" 55 56 #define DEVFS_FS_TYPE "devfs" 52 57 #define DEVFS_MOUNT_POINT "/dev" 58 59 #define SCRATCH_FS_TYPE "tmpfs" 60 #define SCRATCH_MOUNT_POINT "/scratch" 61 62 #define DATA_FS_TYPE "fat" 63 #define DATA_DEVICE "bd/disk0" 64 #define DATA_MOUNT_POINT "/data" 53 65 54 66 #define SRV_CONSOLE "/srv/console" … … 57 69 static void info_print(void) 58 70 { 59 printf(NAME ": HelenOS init\n"); 71 printf("%s: HelenOS init\n", NAME); 72 } 73 74 static bool mount_report(const char *desc, const char *mntpt, 75 const char *fstype, const char *dev, int rc) 76 { 77 switch (rc) { 78 case EOK: 79 if (dev != NULL) 80 printf("%s: %s mounted on %s (%s at %s)\n", NAME, desc, mntpt, 81 fstype, dev); 82 else 83 printf("%s: %s mounted on %s (%s)\n", NAME, desc, mntpt, fstype); 84 break; 85 case EBUSY: 86 printf("%s: %s already mounted on %s\n", NAME, desc, mntpt); 87 return false; 88 case ELIMIT: 89 printf("%s: %s limit exceeded\n", NAME, desc); 90 return false; 91 case ENOENT: 92 printf("%s: %s unknown type (%s)\n", NAME, desc, fstype); 93 return false; 94 default: 95 printf("%s: %s not mounted on %s (%s)\n", NAME, desc, mntpt, 96 str_error(rc)); 97 return false; 98 } 99 100 return true; 60 101 } 61 102 … … 63 104 { 64 105 const char *opts = ""; 65 const char *root_dev = "bd/initrd";66 106 67 107 if (str_cmp(fstype, "tmpfs") == 0) 68 108 opts = "restore"; 69 109 70 int rc = mount(fstype, "/", root_dev, opts, IPC_FLAG_BLOCKING); 71 72 switch (rc) { 73 case EOK: 74 printf(NAME ": Root filesystem mounted, %s at %s\n", 75 fstype, root_dev); 76 break; 77 case EBUSY: 78 printf(NAME ": Root filesystem already mounted\n"); 79 return false; 80 case ELIMIT: 81 printf(NAME ": Unable to mount root filesystem\n"); 82 return false; 83 case ENOENT: 84 printf(NAME ": Unknown filesystem type (%s)\n", fstype); 85 return false; 86 default: 87 printf(NAME ": Error mounting root filesystem (%d)\n", rc); 88 return false; 89 } 90 91 return true; 110 int rc = mount(fstype, ROOT_MOUNT_POINT, ROOT_DEVICE, opts, 111 IPC_FLAG_BLOCKING); 112 return mount_report("Root filesystem", ROOT_MOUNT_POINT, fstype, 113 ROOT_DEVICE, rc); 92 114 } 93 115 94 116 static bool mount_devfs(void) 95 117 { 96 int rc = mount("devfs", DEVFS_MOUNT_POINT, "", "", IPC_FLAG_BLOCKING); 97 98 switch (rc) { 99 case EOK: 100 printf(NAME ": Device filesystem mounted\n"); 101 break; 102 case EBUSY: 103 printf(NAME ": Device filesystem already mounted\n"); 104 return false; 105 case ELIMIT: 106 printf(NAME ": Unable to mount device filesystem\n"); 107 return false; 108 case ENOENT: 109 printf(NAME ": Unknown filesystem type (devfs)\n"); 110 return false; 111 default: 112 printf(NAME ": Error mounting device filesystem (%d)\n", rc); 113 return false; 114 } 115 116 return true; 118 int rc = mount(DEVFS_FS_TYPE, DEVFS_MOUNT_POINT, "", "", 119 IPC_FLAG_BLOCKING); 120 return mount_report("Device filesystem", DEVFS_MOUNT_POINT, DEVFS_FS_TYPE, 121 NULL, rc); 117 122 } 118 123 … … 125 130 return; 126 131 127 printf( NAME ": Spawning %s\n", fname);132 printf("%s: Spawning %s\n", NAME, fname); 128 133 129 134 argv[0] = fname; 130 135 argv[1] = NULL; 131 136 132 if (!task_spawn(fname, argv)) 133 printf(NAME ": Error spawning %s\n", fname); 137 int err; 138 if (!task_spawn(fname, argv, &err)) 139 printf("%s: Error spawning %s (%s)\n", NAME, fname, 140 str_error(err)); 134 141 } 135 142 … … 145 152 return; 146 153 147 printf( NAME ": Starting %s\n", fname);154 printf("%s: Starting %s\n", NAME, fname); 148 155 149 156 argv[0] = fname; 150 157 argv[1] = NULL; 151 158 152 id = task_spawn(fname, argv );159 id = task_spawn(fname, argv, &retval); 153 160 if (!id) { 154 printf(NAME ": Error spawning %s\n", fname); 161 printf("%s: Error spawning %s (%s)\n", NAME, fname, 162 str_error(retval)); 155 163 return; 156 164 } 157 165 158 166 rc = task_wait(id, &texit, &retval); 159 167 if (rc != EOK) { 160 printf(NAME ": Error waiting for %s\n", fname); 168 printf("%s: Error waiting for %s (%s(\n", NAME, fname, 169 str_error(retval)); 161 170 return; 162 171 } 163 172 164 173 if ((texit != TASK_EXIT_NORMAL) || (retval != 0)) { 165 printf( NAME ": Server %s failed to start (returned %d)\n",166 fname, retval);174 printf("%s: Server %s failed to start (%s)\n", NAME, 175 fname, str_error(retval)); 167 176 } 168 177 } … … 176 185 snprintf(hid_in, DEVMAP_NAME_MAXLEN, "%s/%s", DEVFS_MOUNT_POINT, dev); 177 186 178 printf( NAME ": Spawning %s with %s\n", SRV_CONSOLE, hid_in);187 printf("%s: Spawning %s %s\n", NAME, SRV_CONSOLE, hid_in); 179 188 180 189 /* Wait for the input device to be ready */ … … 187 196 argv[2] = NULL; 188 197 189 if (!task_spawn(SRV_CONSOLE, argv)) 190 printf(NAME ": Error spawning %s with %s\n", SRV_CONSOLE, hid_in); 198 if (!task_spawn(SRV_CONSOLE, argv, &rc)) 199 printf("%s: Error spawning %s %s (%s)\n", NAME, SRV_CONSOLE, 200 hid_in, str_error(rc)); 191 201 } else 192 printf(NAME ": Error waiting on %s\n", hid_in); 202 printf("%s: Error waiting on %s (%s)\n", NAME, hid_in, 203 str_error(rc)); 193 204 } 194 205 … … 201 212 snprintf(term, DEVMAP_NAME_MAXLEN, "%s/%s", DEVFS_MOUNT_POINT, dev); 202 213 203 printf( NAME ": Spawning %s with %s %s\n", APP_GETTERM, term, app);214 printf("%s: Spawning %s %s %s\n", NAME, APP_GETTERM, term, app); 204 215 205 216 /* Wait for the terminal device to be ready */ … … 213 224 argv[3] = NULL; 214 225 215 if (!task_spawn(APP_GETTERM, argv ))216 printf( NAME ": Error spawning %s with %s %s\n", APP_GETTERM,217 term, app );226 if (!task_spawn(APP_GETTERM, argv, &rc)) 227 printf("%s: Error spawning %s %s %s (%s)\n", NAME, APP_GETTERM, 228 term, app, str_error(rc)); 218 229 } else 219 printf(NAME ": Error waiting on %s\n", term); 220 } 221 222 static void mount_scratch(void) 223 { 224 int rc; 225 226 printf("Trying to mount null/0 on /scratch... "); 227 fflush(stdout); 228 229 rc = mount("tmpfs", "/scratch", "null/0", "", 0); 230 if (rc == EOK) 231 printf("OK\n"); 232 else 233 printf("Failed\n"); 234 } 235 236 static void mount_data(void) 237 { 238 int rc; 239 240 printf("Trying to mount bd/disk0 on /data... "); 241 fflush(stdout); 242 243 rc = mount("fat", "/data", "bd/disk0", "wtcache", 0); 244 if (rc == EOK) 245 printf("OK\n"); 246 else 247 printf("Failed\n"); 230 printf("%s: Error waiting on %s (%s)\n", NAME, term, 231 str_error(rc)); 232 } 233 234 static bool mount_scratch(void) 235 { 236 int rc = mount(SCRATCH_FS_TYPE, SCRATCH_MOUNT_POINT, "", "", 0); 237 return mount_report("Scratch filesystem", SCRATCH_MOUNT_POINT, 238 SCRATCH_FS_TYPE, NULL, rc); 239 } 240 241 static bool mount_data(void) 242 { 243 int rc = mount(DATA_FS_TYPE, DATA_MOUNT_POINT, DATA_DEVICE, "wtcache", 0); 244 return mount_report("Data filesystem", DATA_MOUNT_POINT, DATA_FS_TYPE, 245 DATA_DEVICE, rc); 248 246 } 249 247 … … 253 251 254 252 if (!mount_root(STRING(RDFMT))) { 255 printf( NAME ": Exiting\n");253 printf("%s: Exiting\n", NAME); 256 254 return -1; 257 255 } 258 256 259 257 /* Make sure tmpfs is running. */ 260 258 if (str_cmp(STRING(RDFMT), "tmpfs") != 0) { … … 266 264 267 265 if (!mount_devfs()) { 268 printf( NAME ": Exiting\n");266 printf("%s: Exiting\n", NAME); 269 267 return -2; 270 268 } 271 269 272 270 mount_scratch(); 273 271 … … 278 276 srv_start("/srv/adb_ms"); 279 277 srv_start("/srv/char_ms"); 280 278 281 279 spawn("/srv/fb"); 282 280 spawn("/srv/kbd"); … … 284 282 285 283 spawn("/srv/clip"); 286 284 287 285 /* 288 286 * Start these synchronously so that mount_data() can be … … 295 293 (void) srv_start; 296 294 #endif 297 295 298 296 #ifdef CONFIG_MOUNT_DATA 299 297 mount_data(); … … 301 299 (void) mount_data; 302 300 #endif 303 301 304 302 getterm("term/vc0", "/app/bdsh"); 305 303 getterm("term/vc1", "/app/bdsh"); … … 309 307 getterm("term/vc5", "/app/bdsh"); 310 308 getterm("term/vc6", "/app/klog"); 311 309 312 310 return 0; 313 311 }
Note:
See TracChangeset
for help on using the changeset viewer.