frefid_t glk_fileref_create_temp(glui32 usage, glui32 rock) { frefid_t fref = create_by_name(usage, tmpnam(NULL), rock); nanoglk_log("glk_fileref_create_temp(%d, %d) => %p", usage, rock, fref); fref->disprock = nanoglk_call_regi_obj(fref, gidisp_Class_Fileref); return fref; }
/** * securityfs_create_file - create a file in the securityfs filesystem * * @name: a pointer to a string containing the name of the file to create. * @mode: the permission that the file should have * @parent: a pointer to the parent dentry for this file. This should be a * directory dentry if set. If this paramater is NULL, then the * file will be created in the root of the securityfs filesystem. * @data: a pointer to something that the caller will want to get to later * on. The inode.u.generic_ip pointer will point to this value on * the open() call. * @fops: a pointer to a struct file_operations that should be used for * this file. * * This is the basic "create a file" function for securityfs. It allows for a * wide range of flexibility in createing a file, or a directory (if you * want to create a directory, the securityfs_create_dir() function is * recommended to be used instead.) * * This function will return a pointer to a dentry if it succeeds. This * pointer must be passed to the securityfs_remove() function when the file is * to be removed (no automatic cleanup happens if your module is unloaded, * you are responsible here.) If an error occurs, NULL will be returned. * * If securityfs is not enabled in the kernel, the value -ENODEV will be * returned. It is not wise to check for this value, but rather, check for * NULL or !NULL instead as to eliminate the need for #ifdef in the calling * code. */ struct dentry *securityfs_create_file(const char *name, mode_t mode, struct dentry *parent, void *data, struct file_operations *fops) { struct dentry *dentry = NULL; int error; pr_debug("securityfs: creating file '%s'\n",name); error = simple_pin_fs("securityfs", &mount, &mount_count); if (error) { dentry = ERR_PTR(error); goto exit; } error = create_by_name(name, mode, parent, &dentry); if (error) { dentry = ERR_PTR(error); simple_release_fs(&mount, &mount_count); goto exit; } if (dentry->d_inode) { if (fops) dentry->d_inode->i_fop = fops; if (data) dentry->d_inode->u.generic_ip = data; } exit: return dentry; }
frefid_t glk_fileref_create_by_name(glui32 usage, char *name, glui32 rock) { frefid_t fref = create_by_name(usage, name, rock); nanoglk_log("glk_fileref_create_by_name(%d, '%s', %d) => %p", usage, name, rock, fref); fref->disprock = nanoglk_call_regi_obj(fref, gidisp_Class_Fileref); return fref; }
frefid_t glk_fileref_create_from_fileref(glui32 usage, frefid_t fref, glui32 rock) { frefid_t nfref = create_by_name(usage, fref->name, rock); nanoglk_log("glk_fileref_create_from_fileref(%d, %p, %d) => %p", usage, fref, rock, nfref); fref->disprock = nanoglk_call_regi_obj(fref, gidisp_Class_Fileref); return nfref; }