status_t vfs_bootstrap_file_systems(void) { status_t status; // bootstrap the root filesystem status = _kern_mount("/", NULL, "rootfs", 0, NULL, 0); if (status < B_OK) panic("error mounting rootfs!\n"); _kern_setcwd(-1, "/"); // bootstrap the devfs _kern_create_dir(-1, "/dev", 0755); status = _kern_mount("/dev", NULL, "devfs", 0, NULL, 0); if (status < B_OK) panic("error mounting devfs\n"); // create directory for the boot volume _kern_create_dir(-1, "/boot", 0755); // create some standard links on the rootfs for (int32 i = 0; sPredefinedLinks[i].path != NULL; i++) { _kern_create_symlink(-1, sPredefinedLinks[i].path, sPredefinedLinks[i].target, 0); // we don't care if it will succeed or not } return B_OK; }
static int fuse_symlink(const char* from, const char* to) { PRINTD("##symlink\n"); return _ERR(_kern_create_symlink(-1, to, from, FSSH_S_IRWXU | FSSH_S_IRWXG | FSSH_S_IRWXO)); }
/*! \brief Creates a new symbolic link. If an entry with the supplied name does already exist, the method fails. \param path the new symbolic link's path name. May be relative to this directory or absolute. \param linkToPath the path the symbolic link shall point to. \param dir a pointer to a BSymLink to be initialized to the newly created symbolic link. May be \c NULL. \return - \c B_OK: Everything went fine. - \c B_BAD_VALUE: \c NULL \a path or \a linkToPath. - \c B_ENTRY_NOT_FOUND: \a path does not refer to a possible entry. - \c B_PERMISSION_DENIED: Directory permissions didn't allow operation. - \c B_NO_MEMORY: Insufficient memory for operation. - \c B_LINK_LIMIT: Indicates a cyclic loop within the file system. - \c B_BUSY: A node was busy. - \c B_FILE_ERROR: A general file error. - \c B_FILE_EXISTS: An entry with that name does already exist. - \c B_NO_MORE_FDS: The application has run out of file descriptors. */ status_t BDirectory::CreateSymLink(const char* path, const char* linkToPath, BSymLink* link) { if (!path || !linkToPath) return B_BAD_VALUE; // create the symlink status_t error = _kern_create_symlink(fDirFd, path, linkToPath, (S_IRWXU | S_IRWXG | S_IRWXO) & ~__gUmask); if (error != B_OK) return error; if (link == NULL) return B_OK; // init the supplied BSymLink if (InitCheck() != B_OK || BPrivate::Storage::is_absolute_path(path)) return link->SetTo(path); return link->SetTo(this, path); }
void vfs_mount_boot_file_system(kernel_args* args) { PartitionStack partitions; status_t status = get_boot_partitions(args, partitions); if (status < B_OK) { panic("get_boot_partitions failed!"); } if (partitions.IsEmpty()) { panic("did not find any boot partitions!"); } KPartition* bootPartition; while (partitions.Pop(&bootPartition)) { KPath path; if (bootPartition->GetPath(&path) != B_OK) panic("could not get boot device!\n"); const char* fsName = NULL; bool readOnly = false; if (strcmp(bootPartition->ContentType(), "ISO9660 File System") == 0) { fsName = "iso9660:write_overlay:attribute_overlay"; readOnly = true; } else if (bootPartition->IsReadOnly() && strcmp(bootPartition->ContentType(), "Be File System") == 0) { fsName = "bfs:write_overlay"; readOnly = true; } TRACE(("trying to mount boot partition: %s\n", path.Path())); gBootDevice = _kern_mount("/boot", path.Path(), fsName, 0, NULL, 0); if (gBootDevice >= B_OK) { gReadOnlyBootDevice = readOnly; break; } } if (gBootDevice < B_OK) panic("could not mount boot device!\n"); // create link for the name of the boot device fs_info info; if (_kern_read_fs_info(gBootDevice, &info) == B_OK) { char path[B_FILE_NAME_LENGTH + 1]; snprintf(path, sizeof(path), "/%s", info.volume_name); _kern_create_symlink(-1, path, "/boot", 0); } // Do post-boot-volume module initialization. The module code wants to know // whether the module images the boot loader has pre-loaded are the same as // on the boot volume. That is the case when booting from hard disk or CD, // but not via network. int32 bootMethodType = args->boot_volume.GetInt32(BOOT_METHOD, BOOT_METHOD_DEFAULT); bool bootingFromBootLoaderVolume = bootMethodType == BOOT_METHOD_HARD_DISK || bootMethodType == BOOT_METHOD_CD; module_init_post_boot_device(bootingFromBootLoaderVolume); file_cache_init_post_boot_device(); // search for other disk systems KDiskDeviceManager *manager = KDiskDeviceManager::Default(); manager->RescanDiskSystems(); manager->StartMonitoring(); }
static fssh_status_t command_ln(int argc, const char* const* argv) { bool force = false; bool symbolic = false; bool dereference = true; // parse parameters int argi = 1; for (argi = 1; argi < argc; argi++) { const char *arg = argv[argi]; if (arg[0] != '-') break; if (arg[1] == '\0') { fprintf(stderr, "Error: Invalid option \"-\"\n"); return FSSH_B_BAD_VALUE; } for (int i = 1; arg[i]; i++) { switch (arg[i]) { case 'f': force = true; break; case 's': symbolic = true; break; case 'n': dereference = false; break; default: fprintf(stderr, "Error: Unknown option \"-%c\"\n", arg[i]); return FSSH_B_BAD_VALUE; } } } if (argc - argi != 2) { fprintf(stderr, "Usage: %s [Options] <source> <target>\n", argv[0]); return FSSH_B_BAD_VALUE; } const char *source = argv[argi]; const char *target = argv[argi + 1]; // check, if the the target is an existing directory struct fssh_stat st; char targetBuffer[FSSH_B_PATH_NAME_LENGTH]; fssh_status_t error = _kern_read_stat(-1, target, dereference, &st, sizeof(st)); if (error == FSSH_B_OK) { if (FSSH_S_ISDIR(st.fssh_st_mode)) { // get source leaf char leaf[FSSH_B_FILE_NAME_LENGTH]; error = get_last_path_component(source, leaf, sizeof(leaf)); if (error != FSSH_B_OK) { fprintf(stderr, "Error: Failed to get leaf name of source " "path: %s\n", fssh_strerror(error)); return error; } // compose a new path int len = strlen(target) + 1 + strlen(leaf); if (len > (int)sizeof(targetBuffer)) { fprintf(stderr, "Error: Resulting target path is too long.\n"); return FSSH_B_BAD_VALUE; } strcpy(targetBuffer, target); strcat(targetBuffer, "/"); strcat(targetBuffer, leaf); target = targetBuffer; } } // check, if the target exists error = _kern_read_stat(-1, target, false, &st, sizeof(st)); if (error == FSSH_B_OK) { if (!force) { fprintf(stderr, "Error: Can't create link. \"%s\" is in the way.\n", target); return FSSH_B_FILE_EXISTS; } // unlink the entry error = _kern_unlink(-1, target); if (error != FSSH_B_OK) { fprintf(stderr, "Error: Failed to remove \"%s\" to make way for " "link: %s\n", target, fssh_strerror(error)); return error; } } // finally create the link if (symbolic) { error = _kern_create_symlink(-1, target, source, FSSH_S_IRWXU | FSSH_S_IRWXG | FSSH_S_IRWXO); } else error = _kern_create_link(target, source); if (error != FSSH_B_OK) { fprintf(stderr, "Error: Failed to create link: %s\n", fssh_strerror(error)); } return error; }