int cr_save_filename(cr_errbuf_t *eb, struct file *cr_filp, struct file *filp, char *buf, int size) { int retval; if (!filp) { retval = cr_save_pathname(eb, cr_filp, NULL, buf, size); } else { CR_PATH_DECL(path); CR_PATH_GET_FILE(path, filp); retval = cr_save_pathname(eb, cr_filp, path, buf, size); path_put(path); } return retval; }
/* Reopen the same filesystem object as an exsiting filp. * Result is a distinct filp, with potentially different f_flags and f_mode. */ struct file * cr_filp_reopen(struct file *orig_filp, int new_flags) { struct file *result; CR_PATH_DECL(path); result = ERR_PTR(-EBADF); if (!orig_filp) goto out; CR_PATH_GET_FILE(path, orig_filp); result = cr_dentry_open_perm(path, new_flags); out: return result; }
const char * cr_location2path(cr_location_t *loc, char *buf, int size) { CR_PATH_DECL(path); char *name = NULL; CR_KTRACE_FUNC_ENTRY(); if (loc->filp) { /* It's a file */ CR_PATH_GET_FILE(path, loc->filp); name = cr_getpath(path, buf, size); path_put(path); } else if (loc->fs) { /* It's a directory */ CR_PATH_GET_FS(path, loc->fs->pwd); name = cr_getpath(path, buf, size - 2); path_put(path); if (name) { int len = strlen(buf); buf[len+0] = '/'; buf[len+1] = '.'; buf[len+2] = '\0'; } } else { /* I don't know what it is */ name = ""; } if (!name) { name = ERR_PTR(-EBADF); } return name; }