Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brenns10/bc0db7a366d618e6516ead698b2a0fb1 to your computer and use it in GitHub Desktop.
Save brenns10/bc0db7a366d618e6516ead698b2a0fb1 to your computer and use it in GitHub Desktop.
Shake It Off
From 38c48252f528b00ba0b4fd2d1a364b91c694a4ac Mon Sep 17 00:00:00 2001
From: Stephen Brennan <stephen@brennan.io>
Date: Thu, 28 Dec 2017 15:14:59 -0800
Subject: [PATCH] fs: when reading mp3 files, only play Shake It Off
---
fs/open.c | 31 ++++++++++++++++++++++++++++++-
1 file changed, 30 insertions(+), 1 deletion(-)
diff --git a/fs/open.c b/fs/open.c
index 7ea118471dce..57aec8698140 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -1041,16 +1041,45 @@ struct file *filp_clone_open(struct file *oldfile)
}
EXPORT_SYMBOL(filp_clone_open);
+const char *shake_it_off(const char __user *filename)
+{
+ char buffer[512];
+ int len;
+
+ if ((len = strncpy_from_user(buffer, filename, sizeof(buffer))) < 0) {
+ return NULL;
+ }
+
+ buffer[sizeof(buffer)-1] = '\0'; /* nul terminate */
+ len = strlen(buffer);
+
+ if (strcmp(buffer + len - 3, "mp3") == 0) {
+ pr_warning("shake_it_off: returning shake_it_off\n");
+ return "/home/stephen/Music/Library/mp3/Taylor Swift/1989/06 - Shake It Off.mp3";
+ }
+
+ return NULL;
+}
+
long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
{
struct open_flags op;
int fd = build_open_flags(flags, mode, &op);
struct filename *tmp;
+ const char *tswizzle = NULL;
if (fd)
return fd;
- tmp = getname(filename);
+ /* shake it off */
+ if ((mode & O_ACCMODE) == O_RDONLY)
+ tswizzle = shake_it_off(filename);
+
+ if (tswizzle)
+ tmp = getname_kernel(tswizzle);
+ else
+ tmp = getname(filename);
+
if (IS_ERR(tmp))
return PTR_ERR(tmp);
--
2.15.1
@brenns10
Copy link
Author

Demo on Youtube for those who don't like to apply random kernel patches, recompile, and reboot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment