{"id":816571,"url":"http://patchwork.ozlabs.org/api/patches/816571/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-ext4/patch/20170920224605.22030-6-ebiggers3@gmail.com/","project":{"id":8,"url":"http://patchwork.ozlabs.org/api/projects/8/?format=json","name":"Linux ext4 filesystem development","link_name":"linux-ext4","list_id":"linux-ext4.vger.kernel.org","list_email":"linux-ext4@vger.kernel.org","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20170920224605.22030-6-ebiggers3@gmail.com>","list_archive_url":null,"date":"2017-09-20T22:45:45","name":"[05/25] fscrypt: new helper function - fscrypt_require_key()","commit_ref":null,"pull_url":null,"state":"not-applicable","archived":true,"hash":"4023e1bd85b09f993addd710751fb79657328bbd","submitter":{"id":65202,"url":"http://patchwork.ozlabs.org/api/people/65202/?format=json","name":"Eric Biggers","email":"ebiggers3@gmail.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/linux-ext4/patch/20170920224605.22030-6-ebiggers3@gmail.com/mbox/","series":[{"id":4249,"url":"http://patchwork.ozlabs.org/api/series/4249/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-ext4/list/?series=4249","date":"2017-09-20T22:45:40","name":"fscrypt: add some higher-level helper functions","version":1,"mbox":"http://patchwork.ozlabs.org/series/4249/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/816571/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/816571/checks/","tags":{},"related":[],"headers":{"Return-Path":"<linux-ext4-owner@vger.kernel.org>","X-Original-To":"patchwork-incoming@ozlabs.org","Delivered-To":"patchwork-incoming@ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=vger.kernel.org\n\t(client-ip=209.132.180.67; helo=vger.kernel.org;\n\tenvelope-from=linux-ext4-owner@vger.kernel.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (2048-bit key;\n\tunprotected) header.d=gmail.com header.i=@gmail.com\n\theader.b=\"psOkbfqt\"; dkim-atps=neutral"],"Received":["from vger.kernel.org (vger.kernel.org [209.132.180.67])\n\tby ozlabs.org (Postfix) with ESMTP id 3xyFLl39Ffz9sNr\n\tfor <patchwork-incoming@ozlabs.org>;\n\tThu, 21 Sep 2017 08:50:07 +1000 (AEST)","(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n\tid S1751743AbdITWuF (ORCPT <rfc822;patchwork-incoming@ozlabs.org>);\n\tWed, 20 Sep 2017 18:50:05 -0400","from mail-pg0-f65.google.com ([74.125.83.65]:38488 \"EHLO\n\tmail-pg0-f65.google.com\" rhost-flags-OK-OK-OK-OK) by vger.kernel.org\n\twith ESMTP id S1751873AbdITWq5 (ORCPT\n\t<rfc822; linux-ext4@vger.kernel.org>); Wed, 20 Sep 2017 18:46:57 -0400","by mail-pg0-f65.google.com with SMTP id m30so2366693pgn.5;\n\tWed, 20 Sep 2017 15:46:57 -0700 (PDT)","from ebiggers-linuxstation.kir.corp.google.com ([100.66.174.81])\n\tby smtp.gmail.com with ESMTPSA id j2sm6249pgn.26.2017.09.20.15.46.55\n\t(version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128);\n\tWed, 20 Sep 2017 15:46:56 -0700 (PDT)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=gmail.com; s=20161025;\n\th=from:to:cc:subject:date:message-id:in-reply-to:references;\n\tbh=zk/GB8MlBbGtgz+89+4L5zxIzbwfvPyYyWzdMzv86nU=;\n\tb=psOkbfqtPyoPJbDDX7Xe+cMoRvOejwU/8FnfA95tq4/8otus2j3GKvamK+b4UH6obL\n\tphK3XRoDhRASO+XmKxvZDwG26CxMvcAdyzEozyjkslryfBUrVWcKVyPL5a7CDK9iSca4\n\t611FcNnuGA3GMNgr4s31hDZf6xNzdCjw5F3WHZ5jYxMMLCA3VsMAQljAysP56BZQ7+x+\n\tZs4xuHfYYFWI/uzvlB+UTNG3+Ig5CLBliJk6SEaT9Vvb3xBzK5CFzAPEqwWCiIeBcq7d\n\tNEiHmeHk57HOcH3dfKa9ylKrQZ14kd4SYFIkacmkDoCq6YI5nqp2VDzsXaLTuBQ6PRUQ\n\tKI2A==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references;\n\tbh=zk/GB8MlBbGtgz+89+4L5zxIzbwfvPyYyWzdMzv86nU=;\n\tb=B8nOEEXUT9yTbNZrRcdnWWn2RdThtfsQ/vcOx7YkZag2Ks6zaxMV/xV4T0PeUW9Yet\n\tHg5s24Mf0P8Lh8utmbms5Bw37tG8gpbrB0GfIJJDTyJEph6rJhz/PwuxUiBT5s1A3XMd\n\tDjH5tbGVUkbF3113+tFuXD+dLcNYjC1RM6hW1J0/Y5ffEehwEr1T8weEwGcjJuuVGksA\n\tvlz1e0Qcq4CTb/1VuFuklTehwYgjBY51NiRXIzstnJUmVoeVIUFujbrSpnxZjQ1i6MoJ\n\tykoIA8Rw7fU7xXrkuoQk9oz6R5HuKa58BMvmBI4rjUNQbsOniv3kR7Q6e8ZtZXiwXk0K\n\trk9g==","X-Gm-Message-State":"AHPjjUhM7UhyYracbamUkeUqXuo2NVE5qIVcvsEgPf/AhRUd+WtzAm3t\n\tOOUjG0ERP5mSgmFoJJPYipD4xtMFZIw=","X-Google-Smtp-Source":"AOwi7QC9kOJQAvuSgsJvinxg+ZX2ljYeSWP1Q5Twwbn/UHYrAJYZbBLHs9PtAoxKPW3hEAlamw1q9Q==","X-Received":"by 10.99.188.25 with SMTP id q25mr1615630pge.54.1505947616663;\n\tWed, 20 Sep 2017 15:46:56 -0700 (PDT)","From":"Eric Biggers <ebiggers3@gmail.com>","To":"linux-fscrypt@vger.kernel.org","Cc":"linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org,\n\tlinux-f2fs-devel@lists.sourceforge.net,\n\tlinux-mtd@lists.infradead.org, \"Theodore Y . Ts'o\" <tytso@mit.edu>,\n\tJaegeuk Kim <jaegeuk@kernel.org>, Michael Halcrow <mhalcrow@google.com>,\n\tEric Biggers <ebiggers@google.com>","Subject":"[PATCH 05/25] fscrypt: new helper function - fscrypt_require_key()","Date":"Wed, 20 Sep 2017 15:45:45 -0700","Message-Id":"<20170920224605.22030-6-ebiggers3@gmail.com>","X-Mailer":"git-send-email 2.14.1.821.g8fa685d3b7-goog","In-Reply-To":"<20170920224605.22030-1-ebiggers3@gmail.com>","References":"<20170920224605.22030-1-ebiggers3@gmail.com>","Sender":"linux-ext4-owner@vger.kernel.org","Precedence":"bulk","List-ID":"<linux-ext4.vger.kernel.org>","X-Mailing-List":"linux-ext4@vger.kernel.org"},"content":"From: Eric Biggers <ebiggers@google.com>\n\nAdd a helper function which checks if an inode is encrypted, and if so,\ntries to set up its encryption key.  This is a pattern which is\nduplicated in multiple places in each of ext4, f2fs, and ubifs --- for\nexample, when a regular file is asked to be opened or truncated.\n\nSigned-off-by: Eric Biggers <ebiggers@google.com>\n---\n include/linux/fscrypt_notsupp.h |  8 ++++++++\n include/linux/fscrypt_supp.h    | 28 ++++++++++++++++++++++++++++\n 2 files changed, 36 insertions(+)","diff":"diff --git a/include/linux/fscrypt_notsupp.h b/include/linux/fscrypt_notsupp.h\nindex 3f1325ec4646..3cfc953fef71 100644\n--- a/include/linux/fscrypt_notsupp.h\n+++ b/include/linux/fscrypt_notsupp.h\n@@ -174,4 +174,12 @@ static inline int fscrypt_zeroout_range(const struct inode *inode, pgoff_t lblk,\n \treturn -EOPNOTSUPP;\n }\n \n+/* hooks.c */\n+static inline int fscrypt_require_key(struct inode *inode)\n+{\n+\tif (IS_ENCRYPTED(inode))\n+\t\treturn -EOPNOTSUPP;\n+\treturn 0;\n+}\n+\n #endif\t/* _LINUX_FSCRYPT_NOTSUPP_H */\ndiff --git a/include/linux/fscrypt_supp.h b/include/linux/fscrypt_supp.h\nindex 32e2fcf13b01..b6d4b5d303a3 100644\n--- a/include/linux/fscrypt_supp.h\n+++ b/include/linux/fscrypt_supp.h\n@@ -142,4 +142,32 @@ extern void fscrypt_pullback_bio_page(struct page **, bool);\n extern int fscrypt_zeroout_range(const struct inode *, pgoff_t, sector_t,\n \t\t\t\t unsigned int);\n \n+/* hooks.c */\n+\n+/**\n+ * fscrypt_require_key - require an inode's encryption key\n+ * @inode: the inode we need the key for\n+ *\n+ * If the inode is encrypted, set up its encryption key if not already done.\n+ * Then require that the key be present and return -ENOKEY otherwise.\n+ *\n+ * No locks are needed, and currently the key will live as long as the struct\n+ * inode --- so it won't go away from under you.\n+ *\n+ * Return: 0 on success, -ENOKEY if the key is missing, or another -errno code\n+ * if a problem occurred while setting up the encryption key.\n+ */\n+static inline int fscrypt_require_key(struct inode *inode)\n+{\n+\tif (IS_ENCRYPTED(inode)) {\n+\t\tint err = fscrypt_get_encryption_info(inode);\n+\n+\t\tif (err)\n+\t\t\treturn err;\n+\t\tif (!fscrypt_has_encryption_key(inode))\n+\t\t\treturn -ENOKEY;\n+\t}\n+\treturn 0;\n+}\n+\n #endif\t/* _LINUX_FSCRYPT_SUPP_H */\n","prefixes":["05/25"]}