[RFC] proposed libc interface and man page for listmount

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Attaching the proposed man page for listing mounts (based on the new
listmount() syscall).

The raw interface is:

       syscall(__NR_listmount, const struct mnt_id_req __user *, req,
                  u64 __user *, buf, size_t, bufsize, unsigned int, flags);

The proposed libc API is.

       struct listmount *listmount_start(uint64_t mnt_id, unsigned int flags);
       uint64_t listmount_next(struct listmount *lm);
       void listmount_end(struct listmount *lm);

I'm on the opinion that no wrapper is needed for the raw syscall, just
like there isn't one for getdents(2).

Comments?

Thanks,
Miklos

Sample implementation:
--------------------------------

#define LM_BUFSIZE 4096

struct listmount {
        size_t num;
        size_t pos;
        uint64_t mnt_id;
        unsigned int flags;
        uint64_t buf[LM_BUFSIZE];
};

static int do_listmount(struct listmount *lm)
{
        struct mnt_id_req req = {
                .mnt_id = lm->mnt_id,
                .param = lm->buf[LM_BUFSIZE - 1],
        };
        long res;

        res = syscall(__NR_listmount, &req, lm->buf, LM_BUFSIZE, lm->flags);
        if (res != -1) {
                lm->num = res;
                lm->pos = 0;
        }
        return res;
}

struct listmount *listmount_start(uint64_t mnt_id, unsigned int flags)
{
        int res;
        struct listmount *lm = calloc(1, sizeof(*lm));

        if (lm) {
                lm->mnt_id = mnt_id;
                lm->flags = flags;
                res = do_listmount(lm);
                if (res == -1) {
                        free(lm);
                        lm = NULL;
                }
        }

        return lm;
}

uint64_t listmount_next(struct listmount *lm)
{
        int res;

        if (lm->pos == LM_BUFSIZE) {
                res = do_listmount(lm);
                if (res == -1)
                        return 0;
        }

        /* End of list? */
        if (lm->pos == lm->num)
                return 0;

        return lm->buf[lm->pos++];
}

void listmount_end(struct listmount *lm)
{
        free(lm);
}

Attachment: listmount_start.3
Description: Unix manual page


[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux