/* * Set file attributes. */ int vboxfs_setattr(char *path, struct sffs_attr *attr) { vboxfs_objinfo_t info; vboxfs_handle_t h; int r; /* * Setting the size of a path cannot be combined with other attribute * modifications, because we cannot fail atomically. */ if (attr->a_mask & SFFS_ATTR_SIZE) { assert(attr->a_mask == SFFS_ATTR_SIZE); return set_size(path, attr->a_size); } /* * By passing a pointer to an object information structure, we open the * file for attribute manipulation. Note that this call will open the * file as a regular file. This works on directories as well. */ if ((r = vboxfs_open_file(path, O_WRONLY, 0, &h, &info)) != OK) return r; info.attr.add = VBOXFS_OBJATTR_ADD_NONE; /* Update the file's permissions if requested. */ if (attr->a_mask & SFFS_ATTR_MODE) info.attr.mode = VBOXFS_SET_MODE(info.attr.mode & S_IFMT, attr->a_mode); /* * Update various file times if requested. Not all changes may * be honered. A zero time indicates no change. */ info.atime = (attr->a_mask & SFFS_ATTR_ATIME) ? set_time(&attr->a_atime) : 0; info.mtime = (attr->a_mask & SFFS_ATTR_MTIME) ? set_time(&attr->a_mtime) : 0; info.ctime = (attr->a_mask & SFFS_ATTR_CTIME) ? set_time(&attr->a_ctime) : 0; info.crtime = (attr->a_mask & SFFS_ATTR_CRTIME) ? set_time(&attr->a_crtime) : 0; r = vboxfs_getset_info(h, VBOXFS_INFO_SET | VBOXFS_INFO_FILE, &info, sizeof(info)); vboxfs_close_file(h); return r; }
/* * Query volume information. */ int vboxfs_query_vol(const char *path, vboxfs_volinfo_t *volinfo) { vboxfs_handle_t h; int r; if ((r = vboxfs_open_file(path, O_RDONLY, 0, &h, NULL)) != OK) return r; r = vboxfs_getset_info(h, VBOXFS_INFO_GET | VBOXFS_INFO_VOLUME, volinfo, sizeof(*volinfo)); vboxfs_close_file(h); return r; }
/* * Create a directory. */ int vboxfs_mkdir(char *path, int mode) { vboxfs_handle_t h; int r; assert(S_ISDIR(mode)); if ((r = vboxfs_open_file(path, O_CREAT | O_EXCL | O_WRONLY, mode, &h, NULL)) != OK) return r; vboxfs_close_file(h); return r; }
/* * Set file size. */ static int set_size(char *path, u64_t size) { vboxfs_objinfo_t info; vboxfs_handle_t h; int r; if ((r = vboxfs_open_file(path, O_WRONLY, S_IFREG, &h, NULL)) != OK) return r; memset(&info, 0, sizeof(info)); info.size = size; r = vboxfs_getset_info(h, VBOXFS_INFO_SET | VBOXFS_INFO_SIZE, &info, sizeof(info)); vboxfs_close_file(h); return r; }