]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbstatus: add file_id information about open files to json output
authorJule Anger <janger@samba.org>
Wed, 30 Mar 2022 13:14:13 +0000 (15:14 +0200)
committerJule Anger <janger@samba.org>
Mon, 8 Aug 2022 12:56:29 +0000 (12:56 +0000)
Adds a dictionary with file_id information (devid, inode and extid) for
each locked file.

Signed-off-by: Jule Anger <janger@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source3/utils/status.c
source3/utils/status_json.c
source3/utils/status_json.h
source3/utils/status_json_dummy.c

index 1b9729e562a782f32496e1e67d98f9ea311171b4..7b1a5057f8fbb7693dd2f63f8c72f85e1251e1b2 100644 (file)
@@ -315,6 +315,7 @@ static int print_share_mode(struct file_id fid,
                } else {
                        print_share_mode_json(state,
                                              d,
+                                             fid,
                                              filename);
                }
        }
index a11024e7d4b32c8a1025c2639435dacc301baffc..441f51fa1e45728d2ed447170a6c99dbddab84c4 100644 (file)
@@ -360,8 +360,45 @@ failure:
        return -1;
 }
 
+
+static int add_fileid_to_json(struct json_object *parent_json,
+                             struct file_id fid)
+{
+       struct json_object fid_json;
+       int result;
+
+       fid_json = json_new_object();
+       if (json_is_invalid(&fid_json)) {
+               goto failure;
+       }
+
+       result = json_add_int(&fid_json, "devid", fid.devid);
+       if (result < 0) {
+               goto failure;
+       }
+       result = json_add_int(&fid_json, "inode", fid.inode);
+       if (result < 0) {
+               goto failure;
+       }
+       result = json_add_int(&fid_json, "extid", fid.extid);
+       if (result < 0) {
+               goto failure;
+       }
+
+       result = json_add_object(parent_json, "fileid", &fid_json);
+       if (result < 0) {
+               goto failure;
+       }
+
+       return 0;
+failure:
+       json_free(&fid_json);
+       return -1;
+}
+
 int print_share_mode_json(struct traverse_state *state,
                          const struct share_mode_data *d,
+                         struct file_id fid,
                          const char *filename)
 {
        struct json_object locks_json;
@@ -397,6 +434,10 @@ int print_share_mode_json(struct traverse_state *state,
        if (result < 0) {
                goto failure;
        }
+       result = add_fileid_to_json(&file_json, fid);
+       if (result < 0) {
+               goto failure;
+       }
        result = json_add_int(&file_json, "num_pending_deletes", d->num_delete_tokens);
        if (result < 0) {
                goto failure;
index 44b339914ac6870ef10e0a3db8ebe8e474b0369c..bd9c2611d26d44f0aca6720852a28aef1c4be933 100644 (file)
@@ -46,6 +46,7 @@ int traverse_sessionid_json(struct traverse_state *state,
 
 int print_share_mode_json(struct traverse_state *state,
                          const struct share_mode_data *d,
+                         struct file_id fid,
                          const char *filename);
 
 #endif
index 96b6bc6b569277589b701daed36a5d569907087c..c53c329c837df48519e3bcaec59c39bbe816eb5c 100644 (file)
@@ -60,6 +60,7 @@ int traverse_sessionid_json(struct traverse_state *state,
 
 int print_share_mode_json(struct traverse_state *state,
                          const struct share_mode_data *d,
+                         struct file_id fid,
                          const char *filename)
 {
        return 0;