Skip to content
This repository was archived by the owner on May 9, 2022. It is now read-only.

VFS API#2

Closed
kivikakk wants to merge 4 commits intofeatures/linuxprototypefrom
vfs-api
Closed

VFS API#2
kivikakk wants to merge 4 commits intofeatures/linuxprototypefrom
vfs-api

Conversation

@kivikakk
Copy link

@kivikakk kivikakk commented Feb 25, 2019

👋 @chrisd8088

Here's a first pass at implementing the VFS API entirely in C#. There's a companion PR at github/libprojfs#53 which adds one entry point we need.

What do you think? The translation ended up being fairly straightforward after reviewing the P/Invoke docs.

@kivikakk
Copy link
Author

It should be noted, I'm opening this against the github fork of VFSForGit (and not upstream) so we can mull over this before deciding whether or not to bother our counterparts at Microsoft with it.

Copy link

@chrisd8088 chrisd8088 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lovely and amazing! 😲 :shipit:

const ulong BufSize = 4096;
byte[] targetBuffer = new byte[BufSize];
long bytesRead = ReadLink(fullPathInMirror, targetBuffer, BufSize);
long bytesRead = Syscall.readlink(fullPathInMirror, targetBuffer);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's nice!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pulled Mono.Posix in in microsoft#800, and it would be remiss not to use it where appropriate!

using (var stream = System.IO.File.OpenText(string.Format("/proc/{0}/cmdline", pid)))
{
string[] parts = stream.ReadToEnd().Split('\0');
return parts.Length > 0 ? parts[0] : string.Empty;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oooh, that's nice too!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out I actually miss working on C# 😅 (It didn't help that last time I was using it for work, it was -- in part -- on services integrating with SharePoint. Y I K E S.)

// TODO(Linux): set value from that defined in Linux library header
public const int PlaceholderIdLength = 128;

public const ulong PROJFS_CLOSE_WRITE = 0x00000008;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With these values and the one above, I wonder if we could do something like is done in GenerateGitVersionConstants.sh -- i.e., either extract these values from the C header file using sed, grep, etc., or build a small C program which includes the header and when run spits out the values, which we then put into a small C# ProjFS.Linux.Constants.cs file or something. Does that seem out of bounds?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, that seems very apt. We might have to do it with a C program because of definitions like:

#define himask(x)    (((uint64_t)x) << 32)
…
#define PROJFS_CREATE_SELF   himask(0x0001)  /* File was created */

I'll have a think about this, but yes, you're quite right -- this is fragile and we can do better.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once I work this out, I'll open a PR against the Microsoft upstream repo and invite review from our friends there, as well as yours again on the newest changes.

@kivikakk kivikakk closed this Feb 26, 2019
chrisd8088 added a commit that referenced this pull request Mar 13, 2019
chrisd8088 added a commit that referenced this pull request Mar 13, 2019
kivikakk pushed a commit that referenced this pull request Mar 14, 2019
chrisd8088 added a commit that referenced this pull request Mar 14, 2019
chrisd8088 added a commit that referenced this pull request Mar 22, 2019
chrisd8088 added a commit that referenced this pull request Mar 22, 2019
chrisd8088 added a commit that referenced this pull request Jul 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants