Lines Matching defs:vnode

169 static void get_device_name(struct devfs_vnode* vnode, char* buffer,
197 get_parent_id(struct devfs_vnode* vnode)
199 if (vnode->parent != NULL)
200 return vnode->parent->id;
247 init_directory_vnode(struct devfs_vnode* vnode, int permissions)
249 vnode->stream.type = S_IFDIR | permissions;
250 mutex_init(&vnode->stream.u.dir.scan_lock, "devfs scan");
251 vnode->stream.u.dir.dir_head = NULL;
252 list_init(&vnode->stream.u.dir.cookies);
259 struct devfs_vnode* vnode;
261 vnode = (struct devfs_vnode*)malloc(sizeof(struct devfs_vnode));
262 if (vnode == NULL)
265 memset(vnode, 0, sizeof(struct devfs_vnode));
266 vnode->id = fs->next_vnode_id++;
268 vnode->name = strdup(name);
269 if (vnode->name == NULL) {
270 free(vnode);
274 vnode->creation_time = vnode->modification_time = current_timespec();
275 vnode->uid = geteuid();
276 vnode->gid = parent ? parent->gid : getegid();
279 return vnode;
284 devfs_delete_vnode(struct devfs* fs, struct devfs_vnode* vnode,
289 if (!forceDelete && ((S_ISDIR(vnode->stream.type)
290 && vnode->stream.u.dir.dir_head != NULL)
291 || vnode->dir_next != NULL))
295 fs->vnode_hash->Remove(vnode);
297 if (S_ISCHR(vnode->stream.type)) {
298 if (vnode->stream.u.dev.partition == NULL) {
300 vnode->stream.u.dev.device->Removed();
305 put_vnode(fs->volume, vnode->stream.u.dev.partition->raw_device->id);
307 } else if (S_ISDIR(vnode->stream.type)) {
308 mutex_destroy(&vnode->stream.u.dir.scan_lock);
311 free(vnode->name);
312 free(vnode);
318 /*! Makes sure none of the dircookies point to the vnode passed in */
320 update_dir_cookies(struct devfs_vnode* dir, struct devfs_vnode* vnode)
326 if (cookie->current == vnode)
327 cookie->current = vnode->dir_next;
335 struct devfs_vnode* vnode;
345 for (vnode = dir->stream.u.dir.dir_head; vnode; vnode = vnode->dir_next) {
346 //TRACE(("devfs_find_in_dir: looking at entry '%s'\n", vnode->name));
347 if (strcmp(vnode->name, path) == 0) {
348 //TRACE(("devfs_find_in_dir: found it at %p\n", vnode));
349 return vnode;
357 devfs_insert_in_dir(struct devfs_vnode* dir, struct devfs_vnode* vnode,
367 while (node && strcmp(node->name, vnode->name) < 0) {
372 // the new vnode is the first entry in the list
373 vnode->dir_next = dir->stream.u.dir.dir_head;
374 dir->stream.u.dir.dir_head = vnode;
377 vnode->dir_next = last->dir_next;
378 last->dir_next = vnode;
381 vnode->parent = dir;
385 notify_entry_created(sDeviceFileSystem->id, dir->id, vnode->name,
386 vnode->id);
398 struct devfs_vnode* vnode = dir->stream.u.dir.dir_head;
401 for (; vnode != NULL; lastNode = vnode, vnode = vnode->dir_next) {
402 if (vnode == removeNode) {
403 // make sure no dircookies point to this vnode
404 update_dir_cookies(dir, vnode);
407 lastNode->dir_next = vnode->dir_next;
409 dir->stream.u.dir.dir_head = vnode->dir_next;
410 vnode->dir_next = NULL;
414 notify_entry_removed(sDeviceFileSystem->id, dir->id, vnode->name,
415 vnode->id);
466 // now create the partition vnode
602 struct devfs_vnode* vnode = NULL;
618 vnode = devfs_find_in_dir(dir, &temp[last]);
619 if (vnode) {
620 if (S_ISDIR(vnode->stream.type)) {
622 dir = vnode;
630 vnode = devfs_create_vnode(fs, dir, &temp[last]);
631 if (!vnode) {
638 init_directory_vnode(vnode, 0755);
639 publish_node(sDeviceFileSystem, dir, vnode);
642 dir = vnode;
667 struct devfs_vnode* vnode = NULL;
686 vnode = devfs_find_in_dir(dir, &temp[last]);
687 if (vnode) {
691 if (S_ISDIR(vnode->stream.type)) {
693 dir = vnode;
703 vnode = devfs_create_vnode(fs, dir, &temp[last]);
704 if (!vnode) {
710 // set up the new vnode
713 init_directory_vnode(vnode, 0755);
714 publish_node(fs, dir, vnode);
719 // vnode so that the calling function can insert it after all
721 // is sent out for a vnode that is not yet fully valid.
722 *_node = vnode;
728 dir = vnode;
785 get_device_name(struct devfs_vnode* vnode, char* buffer, size_t size)
789 struct devfs_vnode* leaf = vnode;
794 for (; vnode->parent && vnode->parent != vnode; vnode = vnode->parent) {
795 offset += strlen(vnode->name) + 1;
800 for (vnode = leaf; vnode->parent && vnode->parent != vnode;
801 vnode = vnode->parent) {
802 size_t length = strlen(vnode->name);
806 strcpy(buffer + start, vnode->name);
807 if (vnode != leaf)
824 struct devfs_vnode* vnode = (struct devfs_vnode*)parse_expression(argv[1]);
825 if (vnode == NULL) {
830 kprintf("DEVFS NODE: %p\n", vnode);
831 kprintf(" id: %" B_PRIdINO "\n", vnode->id);
832 kprintf(" name: \"%s\"\n", vnode->name);
833 kprintf(" type: %x\n", vnode->stream.type);
834 kprintf(" parent: %p\n", vnode->parent);
835 kprintf(" dir next: %p\n", vnode->dir_next);
837 if (S_ISDIR(vnode->stream.type)) {
838 kprintf(" dir scanned: %" B_PRId32 "\n", vnode->stream.u.dir.scanned);
841 devfs_vnode* children = vnode->stream.u.dir.dir_head;
846 } else if (S_ISLNK(vnode->stream.type)) {
847 kprintf(" symlink to: %s\n", vnode->stream.u.symlink.path);
849 kprintf(" device: %p\n", vnode->stream.u.dev.device);
850 kprintf(" partition: %p\n", vnode->stream.u.dev.partition);
851 if (vnode->stream.u.dev.partition != NULL) {
852 partition_info& info = vnode->stream.u.dev.partition->info;
854 vnode->stream.u.dev.partition->raw_device);
862 (addr_t)vnode->stream.u.dev.partition->raw_device);
898 struct devfs_vnode* vnode;
930 // create a vnode
931 vnode = devfs_create_vnode(fs, NULL, "");
932 if (vnode == NULL) {
938 vnode->parent = vnode;
941 init_directory_vnode(vnode, 0755);
942 fs->root_vnode = vnode;
944 fs->vnode_hash->Insert(vnode);
945 publish_vnode(volume, vnode->id, vnode, &kVnodeOps, vnode->stream.type, 0);
947 *_rootNodeID = vnode->id;
965 struct devfs_vnode* vnode;
977 vnode = i.Next();
978 devfs_delete_vnode(fs, vnode, true);
1003 struct devfs_vnode* vnode;
1017 vnode = devfs_find_in_dir(dir, name);
1018 if (vnode == NULL) {
1024 status = get_vnode(fs->volume, vnode->id, NULL);
1028 *_id = vnode->id;
1038 struct devfs_vnode* vnode = (struct devfs_vnode*)_vnode->private_node;
1040 TRACE(("devfs_get_vnode_name: vnode = %p\n", vnode));
1042 strlcpy(buffer, vnode->name, bufferSize);
1053 TRACE(("devfs_get_vnode: asking for vnode id = %" B_PRIdINO
1054 ", vnode = %p, r %d\n", id, _vnode, reenter));
1058 struct devfs_vnode* vnode = fs->vnode_hash->Lookup(id);
1059 if (vnode == NULL)
1062 TRACE(("devfs_get_vnode: looked it up at %p\n", vnode));
1064 _vnode->private_node = vnode;
1066 *_type = vnode->stream.type;
1076 struct devfs_vnode* vnode = (struct devfs_vnode*)_vnode->private_node;
1078 TRACE(("devfs_put_vnode: entry on vnode %p, id = %" B_PRIdINO
1079 ", reenter %d\n", vnode, vnode->id, reenter));
1090 struct devfs_vnode* vnode = (struct devfs_vnode*)_v->private_node;
1093 vnode, vnode->id, reenter));
1097 if (vnode->dir_next) {
1099 panic("devfs_removevnode: vnode %p asked to be removed is present in dir\n", vnode);
1102 devfs_delete_vnode(fs, vnode, false);
1112 struct devfs_vnode* vnode = (struct devfs_vnode*)_vnode->private_node;
1120 TRACE(("devfs_open: vnode %p, openMode 0x%x, cookie %p\n", vnode, openMode,
1125 if (S_ISCHR(vnode->stream.type)) {
1126 BaseDevice* device = vnode->stream.u.dev.device;
1134 get_device_name(vnode, path, sizeof(path));
1153 struct devfs_vnode* vnode = (struct devfs_vnode*)_vnode->private_node;
1156 TRACE(("devfs_close: entry vnode %p, cookie %p\n", vnode, cookie));
1158 if (S_ISCHR(vnode->stream.type)) {
1160 return vnode->stream.u.dev.device->Close(cookie->device_cookie);
1170 struct devfs_vnode* vnode = (struct devfs_vnode*)_vnode->private_node;
1173 TRACE(("devfs_freecookie: entry vnode %p, cookie %p\n", vnode, cookie));
1175 if (S_ISCHR(vnode->stream.type)) {
1177 vnode->stream.u.dev.device->Free(cookie->device_cookie);
1178 vnode->stream.u.dev.device->UninitDevice();
1215 struct devfs_vnode* vnode = (struct devfs_vnode*)_vnode->private_node;
1218 //TRACE(("devfs_read: vnode %p, cookie %p, pos %lld, len %p\n",
1219 // vnode, cookie, pos, _length));
1221 if (!S_ISCHR(vnode->stream.type))
1227 if (vnode->stream.u.dev.partition != NULL) {
1228 if (pos >= vnode->stream.u.dev.partition->info.size)
1231 translate_partition_access(vnode->stream.u.dev.partition, pos,
1239 return vnode->stream.u.dev.device->Read(cookie->device_cookie, pos, buffer,
1248 struct devfs_vnode* vnode = (struct devfs_vnode*)_vnode->private_node;
1251 //TRACE(("devfs_write: vnode %p, cookie %p, pos %lld, len %p\n",
1252 // vnode, cookie, pos, _length));
1254 if (!S_ISCHR(vnode->stream.type))
1260 if (vnode->stream.u.dev.partition != NULL) {
1261 if (pos >= vnode->stream.u.dev.partition->info.size)
1264 translate_partition_access(vnode->stream.u.dev.partition, pos,
1271 return vnode->stream.u.dev.device->Write(cookie->device_cookie, pos, buffer,
1283 struct devfs_vnode* vnode = devfs_find_in_dir(dir, name);
1284 if (vnode != NULL) {
1288 vnode = devfs_create_vnode(fs, dir, name);
1289 if (vnode == NULL) {
1294 init_directory_vnode(vnode, perms);
1295 publish_node(sDeviceFileSystem, dir, vnode);
1305 struct devfs_vnode* vnode = (struct devfs_vnode*)_vnode->private_node;
1308 TRACE(("devfs_open_dir: vnode %p\n", vnode));
1310 if (!S_ISDIR(vnode->stream.type))
1318 scan_for_drivers_if_needed(vnode);
1322 cookie->current = vnode->stream.u.dir.dir_head;
1325 list_add_item(&vnode->stream.u.dir.cookies, cookie);
1335 struct devfs_vnode* vnode = (struct devfs_vnode*)_vnode->private_node;
1339 TRACE(("devfs_free_dir_cookie: entry vnode %p, cookie %p\n", vnode, cookie));
1343 list_remove_item(&vnode->stream.u.dir.cookies, cookie);
1353 struct devfs_vnode* vnode = (devfs_vnode*)_vnode->private_node;
1362 TRACE(("devfs_read_dir: vnode %p, cookie %p, buffer %p, size %ld\n",
1365 if (!S_ISDIR(vnode->stream.type))
1372 childNode = vnode;
1374 nextChildNode = vnode->stream.u.dir.dir_head;
1378 childNode = vnode->parent;
1380 nextChildNode = vnode->stream.u.dir.dir_head;
1420 struct devfs_vnode* vnode = (struct devfs_vnode*)_vnode->private_node;
1424 TRACE(("devfs_rewind_dir: vnode %p, cookie %p\n", vnode, cookie));
1426 if (!S_ISDIR(vnode->stream.type))
1431 cookie->current = vnode->stream.u.dir.dir_head;
1445 struct devfs_vnode* vnode = (struct devfs_vnode*)_vnode->private_node;
1448 TRACE(("devfs_ioctl: vnode %p, cookie %p, op %" B_PRIu32
1450 vnode, cookie, op, buffer, length));
1454 if (S_ISCHR(vnode->stream.type)) {
1459 = vnode->stream.u.dev.partition;
1464 status_t status = vnode->stream.u.dev.device->Control(
1483 = vnode->stream.u.dev.partition;
1526 status = vnode->stream.u.dev.device->Control(
1540 = vnode->stream.u.dev.partition;
1541 if (!S_ISCHR(vnode->stream.type)
1560 get_device_name(vnode, path + 5, sizeof(path) - 5);
1580 return vnode->stream.u.dev.device->Control(cookie->device_cookie,
1592 struct devfs_vnode* vnode = (struct devfs_vnode*)_vnode->private_node;
1597 if (!S_ISCHR(vnode->stream.type))
1600 return vnode->stream.u.dev.device->Control(cookie->device_cookie,
1609 struct devfs_vnode* vnode = (struct devfs_vnode*)_vnode->private_node;
1612 if (!S_ISCHR(vnode->stream.type))
1616 if (!vnode->stream.u.dev.device->HasSelect()) {
1623 return vnode->stream.u.dev.device->Select(cookie->device_cookie, event,
1632 struct devfs_vnode* vnode = (struct devfs_vnode*)_vnode->private_node;
1635 if (!S_ISCHR(vnode->stream.type))
1639 if (!vnode->stream.u.dev.device->HasDeselect())
1642 return vnode->stream.u.dev.device->Deselect(cookie->device_cookie, event,
1651 struct devfs_vnode* vnode = (devfs_vnode*)_vnode->private_node;
1653 //TRACE(("devfs_canpage: vnode %p\n", vnode));
1655 if (!S_ISCHR(vnode->stream.type)
1656 || vnode->stream.u.dev.device->Node() == NULL
1660 return vnode->stream.u.dev.device->HasRead()
1661 || vnode->stream.u.dev.device->HasIO();
1672 struct devfs_vnode* vnode = (devfs_vnode*)_vnode->private_node;
1675 //TRACE(("devfs_read_pages: vnode %p, vecs %p, count = %lu, pos = %lld, size = %lu\n", vnode, vecs, count, pos, *_numBytes));
1677 if (!S_ISCHR(vnode->stream.type)
1678 || (!vnode->stream.u.dev.device->HasRead()
1679 && !vnode->stream.u.dev.device->HasIO())
1686 if (vnode->stream.u.dev.partition != NULL) {
1687 if (pos >= vnode->stream.u.dev.partition->info.size)
1690 translate_partition_access(vnode->stream.u.dev.partition, pos,
1694 if (vnode->stream.u.dev.device->HasIO()) {
1708 error = vnode->stream.u.dev.device->Read(cookie->device_cookie, pos,
1731 struct devfs_vnode* vnode = (devfs_vnode*)_vnode->private_node;
1734 //TRACE(("devfs_write_pages: vnode %p, vecs %p, count = %lu, pos = %lld, size = %lu\n", vnode, vecs, count, pos, *_numBytes));
1736 if (!S_ISCHR(vnode->stream.type)
1737 || (!vnode->stream.u.dev.device->HasWrite()
1738 && !vnode->stream.u.dev.device->HasIO())
1745 if (vnode->stream.u.dev.partition != NULL) {
1746 if (pos >= vnode->stream.u.dev.partition->info.size)
1749 translate_partition_access(vnode->stream.u.dev.partition, pos,
1753 if (vnode->stream.u.dev.device->HasIO()) {
1767 error = vnode->stream.u.dev.device->Write(cookie->device_cookie, pos,
1792 devfs_vnode* vnode = (devfs_vnode*)_vnode->private_node;
1795 if (!S_ISCHR(vnode->stream.type) || cookie == NULL) {
1800 if (!vnode->stream.u.dev.device->HasIO())
1803 if (vnode->stream.u.dev.partition != NULL) {
1805 > vnode->stream.u.dev.partition->info.size) {
1809 translate_partition_access(vnode->stream.u.dev.partition, request);
1812 return vnode->stream.u.dev.device->IO(cookie->device_cookie, request);
1819 struct devfs_vnode* vnode = (struct devfs_vnode*)_vnode->private_node;
1821 TRACE(("devfs_read_stat: vnode %p (%" B_PRIdINO "), stat %p\n",
1822 vnode, vnode->id, stat));
1824 stat->st_ino = vnode->id;
1825 stat->st_rdev = vnode->id;
1827 stat->st_mode = vnode->stream.type;
1833 stat->st_uid = vnode->uid;
1834 stat->st_gid = vnode->gid;
1837 stat->st_mtim = stat->st_ctim = vnode->modification_time;
1838 stat->st_crtim = vnode->creation_time;
1842 if (S_ISCHR(vnode->stream.type)) {
1846 if (vnode->stream.u.dev.partition != NULL) {
1847 stat->st_size = vnode->stream.u.dev.partition->info.size;
1849 } else if (vnode->stream.u.dev.info->control(cookie->device_cookie,
1858 stat->st_mode = S_IFBLK | (vnode->stream.type & S_IUMSK);
1859 } else if (S_ISLNK(vnode->stream.type)) {
1860 stat->st_size = vnode->stream.u.symlink.length;
1872 struct devfs_vnode* vnode = (struct devfs_vnode*)_vnode->private_node;
1874 TRACE(("devfs_write_stat: vnode %p (0x%" B_PRIdINO "), stat %p\n",
1875 vnode, vnode->id, stat));
1884 vnode->stream.type = (vnode->stream.type & ~S_IUMSK)
1889 vnode->uid = stat->st_uid;
1891 vnode->gid = stat->st_gid;
1894 vnode->modification_time = stat->st_mtim;
1896 vnode->creation_time = stat->st_crtim;
1898 notify_stat_changed(fs->id, get_parent_id(vnode), vnode->id, statMask);