Yay, cron! Yay boobs! :3

  • tetris11@feddit.uk
    link
    fedilink
    English
    arrow-up
    16
    ·
    edit-2
    8 days ago

    For anyone wanting a real boob device on their machine, save these two files:

    testdev.c
    #include <linux/module.h>
    #include <linux/cdev.h>
    #include <linux/version.h>
    static dev_t boobs_devt; static struct cdev boobs_cdev; static struct class *boobs_class;
    static char current_cupsize = 'A';
    
    static void write_stderr(const char *msg){
        loff_t pos = 0;
        struct file *f = filp_open("/dev/stderr", O_WRONLY, 0);
        if (!IS_ERR(f)) {
            kernel_write(f, msg, strlen(msg), &pos); kernel_write(f, "\n", 1, &pos); filp_close(f, NULL);
        }
    }
    static ssize_t cupsize_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count){
        char input = buf[0];
        const char *msgs[] = {"A is humble", "B is best", "C is cute",
                              "D is duress", "E is excellent", "F is full",
                              "G is excessive, seek help immediately"};
        if (input >= 'A' && input <= 'G') {
            current_cupsize = input;
            write_stderr(msgs[input - 'A']);
        } else {write_stderr("unrecognized letter");}
        return count;
    }
    static ssize_t cupsize_show(struct device *dev, struct device_attribute *attr, char *buf){
      return sysfs_emit(buf, "%c\n", current_cupsize);
    }
    static DEVICE_ATTR_RW(cupsize);
    static struct attribute *boobs_attrs[] = {&dev_attr_cupsize.attr, NULL,};
    static const struct file_operations fops = {.owner = THIS_MODULE};
    ATTRIBUTE_GROUPS(boobs);
    static int __init boobs_init(void){
        alloc_chrdev_region(&boobs_devt, 0, 1, "boobs"); cdev_init(&boobs_cdev, &fops); cdev_add(&boobs_cdev, boobs_devt, 1);
        boobs_class = class_create("devices");  /* kernel > 6.4, use class_create(THIS_MODULE, "devices"); otherwise */
        device_create_with_groups(boobs_class, NULL, boobs_devt, NULL, boobs_groups, "boobs");
        return 0;
    }
    
    static void __exit boobs_exit(void)
    {
      device_destroy(boobs_class, boobs_devt); class_destroy(boobs_class);
      cdev_del(&boobs_cdev); unregister_chrdev_region(boobs_devt, 1);
    }
    
    module_init(boobs_init);module_exit(boobs_exit); MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("");
    
    Makefile
    obj-m += testdev.o
    all:
    	$(MAKE) -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
    clean:
    	$(MAKE) -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
    

    and then install via

    sudo rmmod testdev 2>/dev/null; make && sudo insmod testdev.ko
    

    and then test via:

    ## A / B / C / D / E / F / G -- I don't actually know cup sizes
    echo "G" | sudo tee /sys/class/devices/boobs/cupsize
    
    • Miisha@lemmy.blahaj.zonedeleted by creatorOP
      link
      fedilink
      English
      arrow-up
      13
      ·
      8 days ago

      Omg WHAT. You made an actual Linux kernel character device…for a silly boob joke? Damn…
      I appreciate the commitment. I appreciate the fact that I can read C and that I get the silly little jokes. Omfg, this might be the most amazing thing this whole week.
      I love you, random stranger. If I could give you money for this, I actually would, not even joking. This made me irrationally happy. Thank you so much for making this! ❤️